mirror of
https://github.com/glest/glest-source.git
synced 2025-08-11 19:04:00 +02:00
Fixes problem when choosing the faction of an AI (#186)
* Fixes problem when choosing the faction of an AI (fixes #184)
This commit is contained in:
@@ -10,6 +10,7 @@ which includes the _MegaGlest_ commit log.
|
|||||||
|
|
||||||
* [Andy Alt](https://github.com/andy5995)
|
* [Andy Alt](https://github.com/andy5995)
|
||||||
* [James Sherratt](https://github.com/Jammyjamjamman)
|
* [James Sherratt](https://github.com/Jammyjamjamman)
|
||||||
|
* [João Marcos](https://github.com/JoaoMarcosCSilva)
|
||||||
|
|
||||||
### php || mysql
|
### php || mysql
|
||||||
|
|
||||||
|
@@ -370,7 +370,7 @@ namespace Glest {
|
|||||||
static const int defH;
|
static const int defH;
|
||||||
static const int defW;
|
static const int defW;
|
||||||
|
|
||||||
private:
|
protected:
|
||||||
GraphicButton graphButton1, graphButton2;
|
GraphicButton graphButton1, graphButton2;
|
||||||
vector<string> items;
|
vector<string> items;
|
||||||
vector<string> translated_items;
|
vector<string> translated_items;
|
||||||
|
@@ -68,7 +68,116 @@ namespace Glest {
|
|||||||
s = formatString(s);
|
s = formatString(s);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// =====================================================
|
||||||
|
// class GraphicListBoxFactions
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
GraphicListBoxFactions::GraphicListBoxFactions(const std::string &containerName, const std::string &objName) : GraphicListBox::GraphicListBox(containerName, objName) {}
|
||||||
|
|
||||||
|
void GraphicListBoxFactions::addInformation(MenuStateCustomGame *menu, int index) {
|
||||||
|
this->menu = menu;
|
||||||
|
this->index = index;
|
||||||
|
}
|
||||||
|
bool GraphicListBoxFactions::mouseClick(int x, int y, string advanceToItemStartingWith) {
|
||||||
|
if (this->getVisible() == false) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!items.empty()) {
|
||||||
|
|
||||||
|
bool b1 = graphButton1.mouseClick(x, y);
|
||||||
|
bool b2 = graphButton2.mouseClick(x, y);
|
||||||
|
|
||||||
|
int superj = selectedItemIndex;
|
||||||
|
|
||||||
|
if (b1) {
|
||||||
|
bool bFound = false;
|
||||||
|
if (advanceToItemStartingWith != "") {
|
||||||
|
for (int i = selectedItemIndex - 1; i >= 0; --i) {
|
||||||
|
string item = items[i];
|
||||||
|
if ((int)translated_items.size() > i) item = translated_items[i];
|
||||||
|
if (StartsWith(toLower(item), toLower(advanceToItemStartingWith)) == true) {
|
||||||
|
bFound = true;
|
||||||
|
selectedItemIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bFound == false) {
|
||||||
|
for (int i = (int)items.size() - 1; i >= selectedItemIndex; --i) {
|
||||||
|
string item = items[i];
|
||||||
|
if ((int)translated_items.size() > i) item = translated_items[i];
|
||||||
|
if (StartsWith(toLower(item), toLower(advanceToItemStartingWith)) == true) {
|
||||||
|
bFound = true;
|
||||||
|
selectedItemIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bFound == false) {
|
||||||
|
--selectedItemIndex %= items.size();
|
||||||
|
|
||||||
|
int type = 0;
|
||||||
|
std::string faction = "";
|
||||||
|
if (menu != NULL) {
|
||||||
|
type = (menu->listBoxControls)[index].getSelectedItemIndex();
|
||||||
|
faction = menu->factionFiles[getSelectedItemIndex()];
|
||||||
|
}
|
||||||
|
if (menu != NULL
|
||||||
|
&& faction == formatString(GameConstants::OBSERVER_SLOTNAME)
|
||||||
|
&& (type == ctCpuEasy || type == ctCpu || type == ctCpuUltra || type == ctCpuZeta)) {
|
||||||
|
--selectedItemIndex %= items.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
else if (b2) {
|
||||||
|
bool bFound = false;
|
||||||
|
if (advanceToItemStartingWith != "") {
|
||||||
|
for (int i = selectedItemIndex + 1; i < (int)items.size(); ++i) {
|
||||||
|
string item = items[i];
|
||||||
|
if ((int)translated_items.size() > i) item = translated_items[i];
|
||||||
|
if (StartsWith(toLower(item), toLower(advanceToItemStartingWith)) == true) {
|
||||||
|
bFound = true;
|
||||||
|
selectedItemIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bFound == false) {
|
||||||
|
for (int i = 0; i <= selectedItemIndex; ++i) {
|
||||||
|
string item = items[i];
|
||||||
|
if ((int)translated_items.size() > i) item = translated_items[i];
|
||||||
|
if (StartsWith(toLower(item), toLower(advanceToItemStartingWith)) == true) {
|
||||||
|
bFound = true;
|
||||||
|
selectedItemIndex = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (bFound == false) {
|
||||||
|
++selectedItemIndex %= items.size();
|
||||||
|
|
||||||
|
int type = 0;
|
||||||
|
std::string faction = "";
|
||||||
|
if (menu != NULL) {
|
||||||
|
type = (menu->listBoxControls)[index].getSelectedItemIndex();
|
||||||
|
faction = menu->factionFiles[getSelectedItemIndex()];
|
||||||
|
}
|
||||||
|
if (menu != NULL
|
||||||
|
&& faction == formatString(GameConstants::OBSERVER_SLOTNAME)
|
||||||
|
&& (type == ctCpuEasy || type == ctCpu || type == ctCpuUltra || type == ctCpuZeta)) {
|
||||||
|
++selectedItemIndex %= items.size();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
setText(getSelectedItem());
|
||||||
|
return b1 || b2;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class MenuStateCustomGame
|
// class MenuStateCustomGame
|
||||||
// =====================================================
|
// =====================================================
|
||||||
@@ -1979,7 +2088,7 @@ namespace Glest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//printf("checkControTypeClicked = %d selectedControlItemIndex = %d i = %d\n",checkControTypeClicked,selectedControlItemIndex,i);
|
//printf("checkControTypeClicked = %d selectedControlItemIndex = %d i = %d\n",checkControTypeClicked,selectedControlItemIndex,i);
|
||||||
|
listBoxFactions[i].addInformation(this, i);
|
||||||
if (selectedControlItemIndex != ctHuman &&
|
if (selectedControlItemIndex != ctHuman &&
|
||||||
checkControTypeClicked == true &&
|
checkControTypeClicked == true &&
|
||||||
listBoxControls[i].mouseClick(x, y)) {
|
listBoxControls[i].mouseClick(x, y)) {
|
||||||
@@ -5795,6 +5904,7 @@ namespace Glest {
|
|||||||
//printf("DONE Setting scenario faction i = %d [ %s]\n",i,scenarioInfo.factionTypeNames[i].c_str());
|
//printf("DONE Setting scenario faction i = %d [ %s]\n",i,scenarioInfo.factionTypeNames[i].c_str());
|
||||||
|
|
||||||
// Disallow CPU players to be observers
|
// Disallow CPU players to be observers
|
||||||
|
listBoxFactions[i].addInformation(this, i);
|
||||||
if (factionFiles
|
if (factionFiles
|
||||||
[listBoxFactions[i].getSelectedItemIndex()] ==
|
[listBoxFactions[i].getSelectedItemIndex()] ==
|
||||||
formatString(GameConstants::OBSERVER_SLOTNAME)
|
formatString(GameConstants::OBSERVER_SLOTNAME)
|
||||||
|
@@ -46,19 +46,33 @@ namespace Glest {
|
|||||||
class SwitchSetupRequest;
|
class SwitchSetupRequest;
|
||||||
class ServerInterface;
|
class ServerInterface;
|
||||||
class TechTree;
|
class TechTree;
|
||||||
|
class MenuStateCustomGame;
|
||||||
|
|
||||||
enum ParentMenuState {
|
enum ParentMenuState {
|
||||||
pNewGame,
|
pNewGame,
|
||||||
pMasterServer,
|
pMasterServer,
|
||||||
pLanGame
|
pLanGame
|
||||||
};
|
};
|
||||||
|
// =====================================================
|
||||||
|
// class GraphicListBoxFactions
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class GraphicListBoxFactions : public GraphicListBox {
|
||||||
|
private:
|
||||||
|
MenuStateCustomGame * menu;
|
||||||
|
int index;
|
||||||
|
public:
|
||||||
|
GraphicListBoxFactions(const std::string &containerName = "", const std::string &objName = "");
|
||||||
|
void addInformation(MenuStateCustomGame* m, int i);
|
||||||
|
bool mouseClick(int x, int y, string advanceToItemStartingWith);
|
||||||
|
};
|
||||||
// ===============================
|
// ===============================
|
||||||
// class MenuStateCustomGame
|
// class MenuStateCustomGame
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
||||||
class MenuStateCustomGame :
|
class MenuStateCustomGame :
|
||||||
public MenuState, public SimpleTaskCallbackInterface {
|
public MenuState, public SimpleTaskCallbackInterface {
|
||||||
|
friend class GraphicListBoxFactions;
|
||||||
private:
|
private:
|
||||||
GraphicButton buttonReturn;
|
GraphicButton buttonReturn;
|
||||||
GraphicButton buttonPlayNow;
|
GraphicButton buttonPlayNow;
|
||||||
@@ -93,7 +107,7 @@ namespace Glest {
|
|||||||
GraphicListBox listBoxControls[GameConstants::maxPlayers];
|
GraphicListBox listBoxControls[GameConstants::maxPlayers];
|
||||||
GraphicButton buttonBlockPlayers[GameConstants::maxPlayers];
|
GraphicButton buttonBlockPlayers[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers];
|
GraphicListBox listBoxRMultiplier[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxFactions[GameConstants::maxPlayers];
|
GraphicListBoxFactions listBoxFactions[GameConstants::maxPlayers];
|
||||||
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
GraphicListBox listBoxTeams[GameConstants::maxPlayers];
|
||||||
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
GraphicLabel labelNetStatus[GameConstants::maxPlayers];
|
||||||
MapInfo mapInfo;
|
MapInfo mapInfo;
|
||||||
|
Reference in New Issue
Block a user