Enhanced GfuiMenuScreenClass to wrap most of the guimenu API (makes menus code shorter and clearer)

Improved carinfo singleton pattern implementation + method names consistency

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2591 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: 5abca61f1467714a7784c075c2f474a8b3e7fa64
Former-commit-id: 1fb1f8b148be656d6b35fe57fcb4d4d0ea3513d4
This commit is contained in:
pouillot 2010-08-03 17:21:45 +00:00
parent 6c76718752
commit 9aaf988694
5 changed files with 90 additions and 81 deletions

View file

@ -35,14 +35,14 @@ void CarSettingsMenu::onActCB(void *P)
}
void CarSettingsMenu::CarPickCB(tChoiceInfo *pChoices)
void CarSettingsMenu::CarPickCB(tComboBoxInfo *pInfo)
{
m_strCar = pChoices->vecChoices[pChoices->nPos];
m_strCar = pInfo->vecChoices[pInfo->nPos];
}
void CarSettingsMenu::onAcceptCB(void *p)
{
CarData *pData = GetCarInfo()->GetCarDataFromRealName(m_strCar.c_str());
CarData *pData = CarInfo::self()->GetCarDataFromRealName(m_strCar);
GetNetwork()->SetCarInfo(pData->strName.c_str());
GfuiScreenActivate(pPrevMenu);
}
@ -52,6 +52,11 @@ void CarSettingsMenu::onCancelCB(void *p)
GfuiScreenActivate(pPrevMenu);
}
CarSettingsMenu::CarSettingsMenu()
: GfuiMenuScreen("carselectionmenu.xml")
{
}
bool CarSettingsMenu::Init(void* pMenu,const char *pszCar)
{
std::string strCarCat;
@ -59,41 +64,41 @@ bool CarSettingsMenu::Init(void* pMenu,const char *pszCar)
GetNetwork()->GetHostSettings(strCarCat,bCollisions);
pPrevMenu = pMenu;
m_pMenuHandle = GfuiScreenCreateEx(NULL,NULL,onActCB,
NULL, (tfuiCallback)NULL,
1);
void* pMenuHandle = GfuiScreenCreateEx(NULL,NULL,onActCB,
NULL, (tfuiCallback)NULL,
1);
SetMenuHandle(pMenuHandle);
void *param = LoadMenuXML("carselectionmenu.xml");
CreateStaticControls(param,m_pMenuHandle);
OpenXMLDescriptor();
int carCatId = CreateComboboxControl(m_pMenuHandle,param,"modelcombo",CarPickCB);
int skinId = CreateComboboxControl(m_pMenuHandle,param,"skincombo",NULL);
int carImageId = CreateStaticImageControl(m_pMenuHandle,param,"carpreviewimage");
int progressId = CreateProgressbarControl(m_pMenuHandle,param,"topspeedprogress");
int accelerationId = CreateProgressbarControl(m_pMenuHandle,param,"accelerationprogress");
int handlingId = CreateProgressbarControl(m_pMenuHandle,param,"handlingprogress");
int brakingId = CreateProgressbarControl(m_pMenuHandle,param,"brakingprogress");
CreateStaticControls();
std::vector<std::string> vecCars;
GetCarInfo()->GetCarsInCategoryRealName(strCarCat.c_str(),vecCars);
int carCatId = CreateComboboxControl("modelcombo",NULL,CarPickCB);
int skinId = CreateComboboxControl("skincombo",NULL,NULL);
int carImageId = CreateStaticImageControl("carpreviewimage");
int progressId = CreateProgressbarControl("topspeedprogress");
int accelerationId = CreateProgressbarControl("accelerationprogress");
int handlingId = CreateProgressbarControl("handlingprogress");
int brakingId = CreateProgressbarControl("brakingprogress");
const std::vector<std::string> vecCarRealNames =
CarInfo::self()->GetCarRealNamesInCategory(strCarCat);
m_strCar = pszCar;
int carIndex = 0;
for (unsigned i=0;i<vecCars.size();i++)
for (unsigned i=0;i<vecCarRealNames.size();i++)
{
GfuiComboboxAddText(m_pMenuHandle,carCatId,vecCars[i].c_str());
if (vecCars[i] == m_strCar)
GfuiComboboxAddText(pMenuHandle,carCatId,vecCarRealNames[i].c_str());
if (vecCarRealNames[i] == m_strCar)
carIndex = i;
}
GfuiComboboxSetSelectedIndex(m_pMenuHandle,carCatId,carIndex);
GfuiComboboxSetSelectedIndex(pMenuHandle,carCatId,carIndex);
CreateButtonControl(m_pMenuHandle,param,"accept",NULL,onAcceptCB);
CreateButtonControl(m_pMenuHandle,param,"cancel",NULL,onCancelCB);
CreateButtonControl("accept",NULL,onAcceptCB);
CreateButtonControl("cancel",NULL,onCancelCB);
GfParmReleaseHandle(param);
GfuiScreenActivate(m_pMenuHandle);
OpenXMLDescriptor();
return true;
}

View file

@ -28,7 +28,7 @@ class CONFSCREENS_API CarSettingsMenu : public GfuiMenuScreen
{
public:
CarSettingsMenu(){};
CarSettingsMenu();
bool Init(void *pPrevMenu,const char *pzaCar);
void Activate(void* p);
protected:
@ -36,7 +36,7 @@ protected:
static void onActCB(void *p);
static void onAcceptCB(void *p);
static void onCancelCB(void *p);
static void CarPickCB(tChoiceInfo * pInfo);
static void CarPickCB(tComboBoxInfo * pInfo);
static std::string m_strCar;
};

View file

@ -30,30 +30,30 @@ This file deals with network host settings
static void *pPrevMenu = NULL;
std::string HostSettingsMenu::m_strCarCat;
bool HostSettingsMenu::m_bCollisions;
bool HostSettingsMenu::m_bHumanHost;
bool HostSettingsMenu::m_bCollisions = true;
bool HostSettingsMenu::m_bHumanHost = true;
void HostSettingsMenu::onActCB(void *p)
{
}
void HostSettingsMenu::CarControlCB(tChoiceInfo *pChoices)
void HostSettingsMenu::CarControlCB(tComboBoxInfo *pInfo)
{
m_strCarCat = pChoices->vecChoices[pChoices->nPos];
m_strCarCat = pInfo->vecChoices[pInfo->nPos];
}
void HostSettingsMenu::CarCollideCB(tChoiceInfo *pChoices)
void HostSettingsMenu::CarCollideCB(tComboBoxInfo *pInfo)
{
if (pChoices->vecChoices[pChoices->nPos] == "Off")
if (pInfo->vecChoices[pInfo->nPos] == "Off")
m_bCollisions = false;
else
m_bCollisions = true;
}
void HostSettingsMenu::humanhostCB(tChoiceInfo *pChoices)
void HostSettingsMenu::humanHostCB(tComboBoxInfo *pInfo)
{
if (pChoices->vecChoices[pChoices->nPos] == "Yes")
if (pInfo->vecChoices[pInfo->nPos] == "Yes")
m_bHumanHost = true;
else
m_bHumanHost = false;
@ -76,49 +76,53 @@ void HostSettingsMenu::onCancelCB(void *p)
GfuiScreenActivate(pPrevMenu);
}
HostSettingsMenu::HostSettingsMenu()
: GfuiMenuScreen("hostsettingsmenu.xml")
{
}
bool HostSettingsMenu::Init(void* pMenu)
{
GetNetwork()->GetHostSettings(m_strCarCat,m_bCollisions);
pPrevMenu = pMenu;
m_pMenuHandle = GfuiScreenCreateEx(NULL,NULL,onActCB,
NULL, (tfuiCallback)NULL,
1);
void* pMenuHandle = GfuiScreenCreateEx(NULL,NULL,onActCB,
NULL, (tfuiCallback)NULL,
1);
SetMenuHandle(pMenuHandle);
void *param = LoadMenuXML("hostsettingsmenu.xml");
CreateStaticControls(param,m_pMenuHandle);
OpenXMLDescriptor();
int carCatId = CreateComboboxControl(m_pMenuHandle,param,"carcatcombobox",CarControlCB);
std::vector<std::string> vecCategories;
GetCarInfo()->GetCategories(vecCategories);
CreateStaticControls();
int carCatId = CreateComboboxControl("carcatcombobox",NULL,CarControlCB);
const std::vector<std::string> vecCategories = CarInfo::self()->GetCategoryNames();
int CatIndex = 0;
for (unsigned int i=0;i<vecCategories.size();i++)
{
GfuiComboboxAddText(m_pMenuHandle,carCatId,vecCategories[i].c_str());
GfuiComboboxAddText(pMenuHandle,carCatId,vecCategories[i].c_str());
if (m_strCarCat == vecCategories[i])
CatIndex = i;
}
GfuiComboboxSetSelectedIndex(m_pMenuHandle,carCatId,CatIndex);
GfuiComboboxSetSelectedIndex(pMenuHandle,carCatId,CatIndex);
int collId = CreateComboboxControl(m_pMenuHandle,param,"carcollidecombobox",CarCollideCB);
GfuiComboboxAddText(m_pMenuHandle,collId,"On");
GfuiComboboxAddText(m_pMenuHandle,collId,"Off");
int collId = CreateComboboxControl("carcollidecombobox",NULL,CarCollideCB);
GfuiComboboxAddText(pMenuHandle,collId,"On");
GfuiComboboxAddText(pMenuHandle,collId,"Off");
int humanHostId = CreateComboboxControl(m_pMenuHandle,param,"hosthumanplayercombobox",humanhostCB);
GfuiComboboxAddText(m_pMenuHandle,humanHostId,"Yes");
GfuiComboboxAddText(m_pMenuHandle,humanHostId,"No");
int humanHostId = CreateComboboxControl("hosthumanplayercombobox",NULL,humanHostCB);
GfuiComboboxAddText(pMenuHandle,humanHostId,"Yes");
GfuiComboboxAddText(pMenuHandle,humanHostId,"No");
GfuiComboboxSetSelectedIndex(m_pMenuHandle,humanHostId,0);
GfuiComboboxSetSelectedIndex(pMenuHandle,humanHostId,0);
CreateButtonControl(m_pMenuHandle,param,"accept",NULL,onAcceptCB);
CreateButtonControl(m_pMenuHandle,param,"cancel",NULL,onCancelCB);
CreateButtonControl("accept",NULL,onAcceptCB);
CreateButtonControl("cancel",NULL,onCancelCB);
GfParmReleaseHandle(param);
GfuiScreenActivate(m_pMenuHandle);
CloseXMLDescriptor();
return true;
}

View file

@ -27,20 +27,21 @@
class CONFSCREENS_API HostSettingsMenu : public GfuiMenuScreen
{
public:
HostSettingsMenu(){ m_bCollisions = true;};
HostSettingsMenu();
bool Init(void *pPrevMenu);
void Activate(void* p);
protected:
//callback functions must be static
static void onActCB(void *p);
static void onAcceptCB(void *p);
static void onCancelCB(void *p);
static void CarControlCB(tChoiceInfo * pInfo);
static void CarCollideCB(tChoiceInfo * pInfo);
static void humanhostCB(tChoiceInfo *pChoices);
static void CarControlCB(tComboBoxInfo * pInfo);
static void CarCollideCB(tComboBoxInfo * pInfo);
static void humanHostCB(tComboBoxInfo *pChoices);
static void onPlayerReady(void *p);
protected:
static std::string m_strCarCat;
static bool m_bCollisions;
static bool m_bHumanHost;

View file

@ -130,11 +130,11 @@ void EnableMenuHostButtons(bool bChecked)
}
void onHostPlayerReady(bool bChecked)
void onHostPlayerReady(tCheckBoxInfo* pInfo)
{
SetReadyStatus(GetNetwork()->GetDriverIdx()-1,bChecked);
GetNetwork()->SetDriverReady(bChecked);
EnableMenuHostButtons(bChecked);
SetReadyStatus(GetNetwork()->GetDriverIdx()-1,pInfo->bChecked);
GetNetwork()->SetDriverReady(pInfo->bChecked);
EnableMenuHostButtons(pInfo->bChecked);
}
void EnableMenuClientButtons(bool bChecked)
@ -152,11 +152,11 @@ void EnableMenuClientButtons(bool bChecked)
}
}
void onClientPlayerReady(bool bChecked)
void onClientPlayerReady(tCheckBoxInfo* pInfo)
{
SetReadyStatus(GetNetwork()->GetDriverIdx()-1,bChecked);
GetNetwork()->SetDriverReady(bChecked);
EnableMenuClientButtons(bChecked);
SetReadyStatus(GetNetwork()->GetDriverIdx()-1,pInfo->bChecked);
GetNetwork()->SetDriverReady(pInfo->bChecked);
EnableMenuClientButtons(pInfo->bChecked);
}
std::string
@ -285,7 +285,7 @@ UpdateNetworkPlayers()
const char* name = GfParmGetStr(pMod, ppname, RM_ATTR_NAME, "");
const char* car = GfParmGetStr(pMod, ppname, "car name", "");
std::string strRealCar = GetCarInfo()->GetRealCarName(car);
std::string strRealCar = CarInfo::self()->GetCarRealName(car);
int readyindex = 0;
MutexData *pNData = GetNetwork()->LockNetworkData();
@ -383,8 +383,8 @@ void CheckDriversCategory()
if (strCarCat =="All")
return;
std::vector<std::string> vecCars;
GetCarInfo()->GetCarsInCategory(strCarCat.c_str(),vecCars);
const std::vector<std::string> vecCars =
CarInfo::self()->GetCarNamesInCategory(strCarCat);
//Make sure all cars are in the correct category or force change of car
Driver *pDrivers = NULL;
@ -394,8 +394,8 @@ void CheckDriversCategory()
count = pSData->m_vecNetworkPlayers.size();
for (unsigned int i=0;i<count;i++)
{
CarData * pData = GetCarInfo()->GetCarData(pSData->m_vecNetworkPlayers[i].car);
if (pData->strCategory!=strCarCat)
CarData * pData = CarInfo::self()->GetCarData(pSData->m_vecNetworkPlayers[i].car);
if (pData->strCategoryName!=strCarCat)
{
//Pick first car in categroy
strncpy(pSData->m_vecNetworkPlayers[i].car,vecCars[0].c_str(),64);
@ -615,8 +615,7 @@ reNetworkHostMenu(void * /* dummy */)
GfuiMenuDefaultKeysAdd(racemanMenuHdle);
std::vector<std::string> vecCat;
GetCarInfo()->GetCategories(vecCat);
std::vector<std::string> vecCat = CarInfo::self()->GetCategoryNames();
vecCat.push_back("All Cars");
@ -647,7 +646,7 @@ reNetworkHostMenu(void * /* dummy */)
GfuiLabelSetText(racemanMenuHdle,g_carNames[i],"");
}
g_ReadyCheckboxId = CreateCheckboxControl(racemanMenuHdle,mparam,"playerreadycheckbox",onHostPlayerReady);
g_ReadyCheckboxId = CreateCheckboxControl(racemanMenuHdle,mparam,"playerreadycheckbox",NULL,onHostPlayerReady);
g_HostSettingsButtonId = CreateButtonControl(racemanMenuHdle,mparam,"networkhostsettings",racemanMenuHdle,reNetworkHostSettingsMenu);
g_RaceSetupId = CreateButtonControl(racemanMenuHdle,mparam,"racesetup",racemanMenuHdle,ReConfigureMenu);
g_CarSetupButtonId = CreateButtonControl(racemanMenuHdle,mparam,"car",racemanMenuHdle,reCarSettingsMenu);
@ -756,7 +755,7 @@ reNetworkClientConnectMenu(void * /* dummy */)
GfuiLabelSetText(racemanMenuHdle,g_carNames[i],"");
}
g_ReadyCheckboxId = CreateCheckboxControl(racemanMenuHdle,mparam,"playerreadycheckbox",onClientPlayerReady);
g_ReadyCheckboxId = CreateCheckboxControl(racemanMenuHdle,mparam,"playerreadycheckbox",NULL,onClientPlayerReady);
g_CarSetupButtonId = CreateButtonControl(racemanMenuHdle,mparam,"car",racemanMenuHdle,reCarSettingsMenu);
g_DisconnectButtonId = CreateButtonControl(racemanMenuHdle,mparam,"disconnect",NULL,reNetworkClientDisconnect);