Implemented the mp_config stubs.

Fixed a small error with menus (wrong font size was being used in
RenderMenuElement -- was visible with custom maps with long names).
This commit is contained in:
Steven Fuller 2001-12-11 00:53:34 +00:00 committed by Patryk Obara
parent 5e99463577
commit 84e9c736f3
3 changed files with 100 additions and 114 deletions

View file

@ -988,7 +988,6 @@ static void SetupNewMenu(enum AVPMENU_ID menuID)
break; break;
} }
case AVPMENU_MULTIPLAYER_LOADCONFIG : case AVPMENU_MULTIPLAYER_LOADCONFIG :
{ {
extern AVPMENU_ELEMENT* AvPMenu_Multiplayer_LoadConfig; extern AVPMENU_ELEMENT* AvPMenu_Multiplayer_LoadConfig;
@ -3213,16 +3212,19 @@ static void InteractWithMenuElement(enum AVPMENU_ELEMENT_INTERACTION_ID interact
} }
int LengthOfMenuText(char *textPtr);
int LengthOfSmallMenuText(char *textPtr);
static void RenderMenuElement(AVPMENU_ELEMENT *elementPtr, int e, int y) static void RenderMenuElement(AVPMENU_ELEMENT *elementPtr, int e, int y)
{ {
int (*RenderText)(char *textPtr, int x, int y, int alpha, enum AVPMENUFORMAT_ID format); int (*RenderText)(char *textPtr, int x, int y, int alpha, enum AVPMENUFORMAT_ID format);
int (*RenderText_Coloured)(char *textPtr, int x, int y, int alpha, enum AVPMENUFORMAT_ID format, int r, int g, int b); int (*RenderText_Coloured)(char *textPtr, int x, int y, int alpha, enum AVPMENUFORMAT_ID format, int r, int g, int b);
int (*MenuTextLength)(char *textPtr);
if (AvPMenus.FontToUse==AVPMENU_FONT_BIG) if (AvPMenus.FontToUse==AVPMENU_FONT_BIG)
{ {
RenderText = RenderMenuText; RenderText = RenderMenuText;
MenuTextLength = LengthOfMenuText;
} }
else else
{ {
@ -3237,6 +3239,7 @@ static void RenderMenuElement(AVPMENU_ELEMENT *elementPtr, int e, int y)
RenderText = RenderSmallMenuText; RenderText = RenderSmallMenuText;
RenderText_Coloured = RenderSmallMenuText_Coloured; RenderText_Coloured = RenderSmallMenuText_Coloured;
} }
MenuTextLength = LengthOfSmallMenuText;
} }
switch(elementPtr->ElementID) switch(elementPtr->ElementID)
@ -3339,9 +3342,9 @@ static void RenderMenuElement(AVPMENU_ELEMENT *elementPtr, int e, int y)
} }
else else
{ {
int length = LengthOfMenuText(textPtr); int length = MenuTextLength(textPtr);
if (length>ScreenDescriptorBlock.SDB_Width-MENU_CENTREX-MENU_ELEMENT_SPACING*2) if (length>(ScreenDescriptorBlock.SDB_Width-MENU_CENTREX-MENU_ELEMENT_SPACING*2))
{ {
RenderText RenderText
( (

View file

@ -15,6 +15,12 @@
#define UseLocalAssert Yes #define UseLocalAssert Yes
#include "ourasert.h" #include "ourasert.h"
#include <glob.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
extern "C" extern "C"
{ {
extern void SetDefaultMultiplayerConfig(); extern void SetDefaultMultiplayerConfig();
@ -24,7 +30,7 @@ extern char MP_Config_Description[];
#define MP_CONFIG_DIR "MPConfig" #define MP_CONFIG_DIR "MPConfig"
#define MP_CONFIG_WILDCARD "MPConfig/*.cfg" #define MP_CONFIG_WILDCARD "MPConfig/*.cfg"
#define SKIRMISH_CONFIG_WILDCARD "MPConfig/.skirmish_cfg" #define SKIRMISH_CONFIG_WILDCARD "MPConfig/*.skirmish_cfg"
static List<char*> ConfigurationFilenameList; static List<char*> ConfigurationFilenameList;
static List<char*> ConfigurationLocalisedFilenameList; static List<char*> ConfigurationLocalisedFilenameList;
@ -57,17 +63,9 @@ BOOL BuildLoadMPConfigMenu()
load_name=SKIRMISH_CONFIG_WILDCARD; load_name=SKIRMISH_CONFIG_WILDCARD;
} }
fprintf(stderr, "STUB: BuildLoadMPConfigMenu()\n"); glob_t globbuf;
#if 0 if (glob(load_name, 0, NULL, &globbuf))
// allow a wildcard search
WIN32_FIND_DATA wfd;
HANDLE hFindFile = ::FindFirstFile(load_name,&wfd);
if (INVALID_HANDLE_VALUE == hFindFile)
{
return FALSE; return FALSE;
}
// get any path in the load_name // get any path in the load_name
int nPathLen = 0; int nPathLen = 0;
@ -86,21 +84,24 @@ BOOL BuildLoadMPConfigMenu()
if (nLen > nPathLen) nPathLen = nLen; if (nLen > nPathLen) nPathLen = nLen;
} }
do for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
{ struct stat buf;
if
( if (stat(globbuf.gl_pathv[i], &buf) == -1)
!(wfd.dwFileAttributes & continue;
(FILE_ATTRIBUTE_DIRECTORY
|FILE_ATTRIBUTE_SYSTEM if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0)) {
|FILE_ATTRIBUTE_HIDDEN)) char *filename = strrchr(globbuf.gl_pathv[i], '/');
// not a directory, hidden or system file if (filename)
) filename++;
{ else
char* name=new char[strlen(wfd.cFileName)+1]; filename = globbuf.gl_pathv[i];
strcpy(name,wfd.cFileName);
char* dotpos=strchr(name,'.'); char* name=new char[strlen(filename)+1];
strcpy(name,filename);
char* dotpos=strrchr(name,'.');
if(dotpos) *dotpos=0; if(dotpos) *dotpos=0;
ConfigurationFilenameList.add_entry(name); ConfigurationFilenameList.add_entry(name);
BOOL localisedFilename=FALSE; BOOL localisedFilename=FALSE;
@ -119,19 +120,10 @@ BOOL BuildLoadMPConfigMenu()
{ {
ConfigurationLocalisedFilenameList.add_entry(name); ConfigurationLocalisedFilenameList.add_entry(name);
} }
} }
}while (::FindNextFile(hFindFile,&wfd));
if (ERROR_NO_MORE_FILES != GetLastError())
{
printf("Error finding next file\n");
} }
::FindClose(hFindFile); globfree(&globbuf);
#endif
//delete the old menu //delete the old menu
if(AvPMenu_Multiplayer_LoadConfig) delete AvPMenu_Multiplayer_LoadConfig; if(AvPMenu_Multiplayer_LoadConfig) delete AvPMenu_Multiplayer_LoadConfig;
@ -234,8 +226,6 @@ void LoadMultiplayerConfigurationByIndex(int index)
void LoadMultiplayerConfiguration(const char* name) void LoadMultiplayerConfiguration(const char* name)
{ {
FILE* file; FILE* file;
char filename[200]; char filename[200];
if(netGameData.skirmishMode) if(netGameData.skirmishMode)
@ -247,8 +237,6 @@ void LoadMultiplayerConfiguration(const char* name)
if(!file) return; if(!file) return;
//set defaults first , in case there are entries not set by this file //set defaults first , in case there are entries not set by this file
SetDefaultMultiplayerConfig(); SetDefaultMultiplayerConfig();
@ -477,18 +465,11 @@ BOOL BuildLoadIPAddressMenu()
//do a search for all the addresses in the address directory //do a search for all the addresses in the address directory
fprintf(stderr, "STUB: BuildLoadIPAddressMenu()\n"); glob_t globbuf;
#if 0
const char* load_name=IP_ADDRESS_WILDCARD; const char* load_name=IP_ADDRESS_WILDCARD;
// allow a wildcard search
WIN32_FIND_DATA wfd;
HANDLE hFindFile = ::FindFirstFile(load_name,&wfd); if (glob(load_name, 0, NULL, &globbuf))
if (INVALID_HANDLE_VALUE == hFindFile)
{
return FALSE; return FALSE;
}
// get any path in the load_name // get any path in the load_name
int nPathLen = 0; int nPathLen = 0;
@ -507,30 +488,28 @@ BOOL BuildLoadIPAddressMenu()
if (nLen > nPathLen) nPathLen = nLen; if (nLen > nPathLen) nPathLen = nLen;
} }
do for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
{ struct stat buf;
if
( if (stat(globbuf.gl_pathv[i], &buf) == -1)
!(wfd.dwFileAttributes & continue;
(FILE_ATTRIBUTE_DIRECTORY
|FILE_ATTRIBUTE_SYSTEM if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0)) {
|FILE_ATTRIBUTE_HIDDEN)) char *filename = strrchr(globbuf.gl_pathv[i], '/');
// not a directory, hidden or system file if (filename)
) filename++;
{ else
char* name=new char[strlen(wfd.cFileName)+1]; filename = globbuf.gl_pathv[i];
strcpy(name,wfd.cFileName);
char* name=new char[strlen(filename)+1];
strcpy(name,filename);
char* dotpos=strchr(name,'.'); char* dotpos=strchr(name,'.');
if(dotpos) *dotpos=0; if(dotpos) *dotpos=0;
IPAddFilenameList.add_entry(name); IPAddFilenameList.add_entry(name);
} }
}
}while (::FindNextFile(hFindFile,&wfd)); globfree(&globbuf);
::FindClose(hFindFile);
#endif
//delete the old menu //delete the old menu
if(AvPMenu_Multiplayer_LoadIPAddress) delete [] AvPMenu_Multiplayer_LoadIPAddress; if(AvPMenu_Multiplayer_LoadIPAddress) delete [] AvPMenu_Multiplayer_LoadIPAddress;
@ -572,7 +551,6 @@ void SaveIPAddress(const char* name,const char* address)
fwrite(address,1,strlen(address)+1,file); fwrite(address,1,strlen(address)+1,file);
fclose(file); fclose(file);
} }
void LoadIPAddress(const char* name) void LoadIPAddress(const char* name)
@ -614,53 +592,48 @@ List<char*> CustomLevelNameList;
void BuildMultiplayerLevelNameArray() void BuildMultiplayerLevelNameArray()
{ {
char buffer[256]; char buffer[256];
//only want to do this once //only want to do this once
if(MultiplayerLevelNames) return; if(MultiplayerLevelNames) return;
//first do a search for custom level rifs //first do a search for custom level rifs
// allow a wildcard search // allow a wildcard search
fprintf(stderr, "STUB: BuildMultiplayerLevelNameArray()\n"); const char* load_name="avp_rifs/custom/*.rif";
#if 0
WIN32_FIND_DATA wfd;
const char* load_name="avp_rifs\\custom\\*.rif";
HANDLE hFindFile = ::FindFirstFile(load_name,&wfd); glob_t globbuf;
if (INVALID_HANDLE_VALUE != hFindFile) if (glob(load_name, 0, NULL, &globbuf) == 0) {
{
char* custom_string = GetTextString(TEXTSTRING_CUSTOM_LEVEL); char* custom_string = GetTextString(TEXTSTRING_CUSTOM_LEVEL);
do int cs_len = strlen(custom_string);
{
if
(
!(wfd.dwFileAttributes &
(FILE_ATTRIBUTE_DIRECTORY
|FILE_ATTRIBUTE_SYSTEM
|FILE_ATTRIBUTE_HIDDEN))
// not a directory, hidden or system file
)
{
strcpy(buffer,wfd.cFileName);
char* dotpos=strchr(buffer,'.');
if(dotpos) *dotpos=0;
strcat(buffer," (");
strcat(buffer,custom_string);
strcat(buffer,")");
char* name=new char[strlen(buffer)+1]; for (unsigned int i = 0; i < globbuf.gl_pathc; i++) {
strcpy(name,buffer); struct stat buf;
if (stat(globbuf.gl_pathv[i], &buf) == -1)
continue;
if (S_ISREG(buf.st_mode) && (access(globbuf.gl_pathv[i], R_OK) == 0)) {
char *filename = strrchr(globbuf.gl_pathv[i], '/');
if (filename)
filename++;
else
filename = globbuf.gl_pathv[i];
char* name=new char[strlen(filename)+cs_len+3+1];
strcpy(name, filename);
char* dotpos=strrchr(name,'.');
if(dotpos) *dotpos=0;
strcat(name," (");
strcat(name,custom_string);
strcat(name,")");
CustomLevelNameList.add_entry(name); CustomLevelNameList.add_entry(name);
} }
}
}while (::FindNextFile(hFindFile,&wfd)); globfree(&globbuf);
::FindClose(hFindFile);
} }
#endif
NumCustomLevels = CustomLevelNameList.size(); NumCustomLevels = CustomLevelNameList.size();
@ -760,7 +733,6 @@ void BuildMultiplayerLevelNameArray()
} }
elementPtr->b.MaxSliderValue = NumMultiplayerLevels-1; elementPtr->b.MaxSliderValue = NumMultiplayerLevels-1;
elementPtr->d.TextSliderStringPointer = MultiplayerLevelNames; elementPtr->d.TextSliderStringPointer = MultiplayerLevelNames;
} }
@ -860,7 +832,6 @@ int GetLocalMultiplayerLevelIndex(int index,char* customLevelName,int gameType)
} }
return -1; return -1;
} }
}; };

View file

@ -388,6 +388,18 @@ int LengthOfMenuText(char *textPtr)
return width; return width;
} }
int LengthOfSmallMenuText(char *textPtr)
{
int width = 0;
while (textPtr && *textPtr) {
width += AAFontWidths[(unsigned int) *textPtr];
textPtr++;
}
return width;
}
int RenderMenuText(char *textPtr, int sx, int sy, int alpha, enum AVPMENUFORMAT_ID format) int RenderMenuText(char *textPtr, int sx, int sy, int alpha, enum AVPMENUFORMAT_ID format)
{ {
int width; int width;