2018-01-05 19:21:07 +02:00
|
|
|
/*
|
|
|
|
* OptionsTab.cpp, part of VCMI engine
|
|
|
|
*
|
|
|
|
* Authors: listed in file AUTHORS in main folder
|
|
|
|
*
|
|
|
|
* License: GNU General Public License v2.0 or later
|
|
|
|
* Full text of license available in license.txt file, in main folder
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
#include "StdInc.h"
|
2023-05-20 17:28:35 +02:00
|
|
|
#include "OptionsTab.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
#include "CSelectionBase.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
|
|
|
#include "../CServerHandler.h"
|
2023-08-20 13:05:25 +02:00
|
|
|
#include "../CMusicHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-08-12 02:41:48 +02:00
|
|
|
#include "../gui/Shortcut.h"
|
2023-05-16 14:10:26 +02:00
|
|
|
#include "../gui/WindowHandler.h"
|
2023-07-31 18:50:55 +02:00
|
|
|
#include "../render/Graphics.h"
|
|
|
|
#include "../render/IFont.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/CComponent.h"
|
2023-08-25 18:20:26 +02:00
|
|
|
#include "../widgets/ComboBox.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
2023-08-14 22:22:43 +02:00
|
|
|
#include "../widgets/Images.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/MiscWidgets.h"
|
|
|
|
#include "../widgets/ObjectLists.h"
|
2023-05-30 16:31:45 +02:00
|
|
|
#include "../widgets/Slider.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../windows/GUIClasses.h"
|
|
|
|
#include "../windows/InfoWindows.h"
|
2023-09-17 00:32:10 +02:00
|
|
|
#include "../windows/CHeroOverview.h"
|
2023-08-13 19:23:27 +02:00
|
|
|
#include "../eventsSDL/InputHandler.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-23 17:29:50 +02:00
|
|
|
#include "../../lib/filesystem/Filesystem.h"
|
2023-10-23 15:38:05 +02:00
|
|
|
#include "../../lib/networkPacks/PacksForLobby.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
#include "../../lib/CGeneralTextHandler.h"
|
|
|
|
#include "../../lib/CArtHandler.h"
|
|
|
|
#include "../../lib/CTownHandler.h"
|
|
|
|
#include "../../lib/CHeroHandler.h"
|
|
|
|
#include "../../lib/mapping/CMapInfo.h"
|
2023-05-24 01:05:59 +02:00
|
|
|
#include "../../lib/mapping/CMapHeader.h"
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2021-11-08 18:49:04 +02:00
|
|
|
OptionsTab::OptionsTab() : humanPlayers(0)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
recActions = 0;
|
2023-08-26 01:14:01 +02:00
|
|
|
|
2023-08-25 18:20:26 +02:00
|
|
|
addCallback("setTimerPreset", [&](int index){
|
|
|
|
if(!variables["timerPresets"].isNull())
|
|
|
|
{
|
|
|
|
auto tpreset = variables["timerPresets"].Vector().at(index).Vector();
|
|
|
|
TurnTimerInfo tinfo;
|
|
|
|
tinfo.baseTimer = tpreset.at(0).Integer() * 1000;
|
|
|
|
tinfo.turnTimer = tpreset.at(1).Integer() * 1000;
|
|
|
|
tinfo.battleTimer = tpreset.at(2).Integer() * 1000;
|
|
|
|
tinfo.creatureTimer = tpreset.at(3).Integer() * 1000;
|
|
|
|
CSH->setTurnTimerInfo(tinfo);
|
|
|
|
}
|
|
|
|
});
|
2023-09-22 20:41:32 +02:00
|
|
|
|
|
|
|
addCallback("setSimturnDuration", [&](int index){
|
|
|
|
SimturnsInfo info;
|
|
|
|
info.optionalTurns = index;
|
|
|
|
CSH->setSimturnsInfo(info);
|
|
|
|
});
|
2023-08-25 18:20:26 +02:00
|
|
|
|
2023-08-27 19:39:45 +02:00
|
|
|
//helper function to parse string containing time to integer reflecting time in seconds
|
|
|
|
//assumed that input string can be modified by user, function shall support user's intention
|
|
|
|
// normal: 2:00, 12:30
|
|
|
|
// adding symbol: 2:005 -> 2:05, 2:305 -> 23:05,
|
|
|
|
// adding symbol (>60 seconds): 12:095 -> 129:05
|
|
|
|
// removing symbol: 129:0 -> 12:09, 2:0 -> 0:20, 0:2 -> 0:02
|
|
|
|
auto parseTimerString = [](const std::string & str) -> int
|
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
auto sc = str.find(":");
|
|
|
|
if(sc == std::string::npos)
|
2023-08-26 12:01:19 +02:00
|
|
|
return str.empty() ? 0 : std::stoi(str);
|
2023-08-26 01:14:01 +02:00
|
|
|
|
|
|
|
auto l = str.substr(0, sc);
|
|
|
|
auto r = str.substr(sc + 1, std::string::npos);
|
|
|
|
if(r.length() == 3) //symbol added
|
|
|
|
{
|
|
|
|
l.push_back(r.front());
|
|
|
|
r.erase(r.begin());
|
|
|
|
}
|
|
|
|
else if(r.length() == 1) //symbol removed
|
2023-08-25 18:20:26 +02:00
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
r.insert(r.begin(), l.back());
|
|
|
|
l.pop_back();
|
2023-08-25 18:20:26 +02:00
|
|
|
}
|
2023-08-26 12:01:19 +02:00
|
|
|
else if(r.empty())
|
|
|
|
r = "0";
|
2023-08-26 01:14:01 +02:00
|
|
|
|
|
|
|
int sec = std::stoi(r);
|
|
|
|
if(sec >= 60)
|
|
|
|
{
|
|
|
|
if(l.empty()) //9:00 -> 0:09
|
|
|
|
return sec / 10;
|
|
|
|
|
|
|
|
l.push_back(r.front()); //0:090 -> 9:00
|
|
|
|
r.erase(r.begin());
|
|
|
|
}
|
|
|
|
else if(l.empty())
|
|
|
|
return sec;
|
|
|
|
|
|
|
|
return std::stoi(l) * 60 + std::stoi(r);
|
2023-08-25 18:20:26 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
addCallback("parseAndSetTimer_base", [parseTimerString](const std::string & str){
|
|
|
|
int time = parseTimerString(str) * 1000;
|
|
|
|
if(time >= 0)
|
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
TurnTimerInfo tinfo = SEL->getStartInfo()->turnTimerInfo;
|
2023-08-25 18:20:26 +02:00
|
|
|
tinfo.baseTimer = time;
|
|
|
|
CSH->setTurnTimerInfo(tinfo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addCallback("parseAndSetTimer_turn", [parseTimerString](const std::string & str){
|
|
|
|
int time = parseTimerString(str) * 1000;
|
|
|
|
if(time >= 0)
|
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
TurnTimerInfo tinfo = SEL->getStartInfo()->turnTimerInfo;
|
2023-08-25 18:20:26 +02:00
|
|
|
tinfo.turnTimer = time;
|
|
|
|
CSH->setTurnTimerInfo(tinfo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addCallback("parseAndSetTimer_battle", [parseTimerString](const std::string & str){
|
|
|
|
int time = parseTimerString(str) * 1000;
|
|
|
|
if(time >= 0)
|
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
TurnTimerInfo tinfo = SEL->getStartInfo()->turnTimerInfo;
|
2023-08-25 18:20:26 +02:00
|
|
|
tinfo.battleTimer = time;
|
|
|
|
CSH->setTurnTimerInfo(tinfo);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
addCallback("parseAndSetTimer_creature", [parseTimerString](const std::string & str){
|
|
|
|
int time = parseTimerString(str) * 1000;
|
|
|
|
if(time >= 0)
|
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
TurnTimerInfo tinfo = SEL->getStartInfo()->turnTimerInfo;
|
2023-08-25 18:20:26 +02:00
|
|
|
tinfo.creatureTimer = time;
|
|
|
|
CSH->setTurnTimerInfo(tinfo);
|
|
|
|
}
|
|
|
|
});
|
2023-08-23 17:29:50 +02:00
|
|
|
|
2023-09-01 23:26:14 +02:00
|
|
|
const JsonNode config(JsonPath::builtin("config/widgets/optionsTab.json"));
|
2023-08-23 17:29:50 +02:00
|
|
|
build(config);
|
|
|
|
|
2023-08-25 18:20:26 +02:00
|
|
|
//set timers combo box callbacks
|
|
|
|
if(auto w = widget<ComboBox>("timerModeSwitch"))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-25 18:20:26 +02:00
|
|
|
w->onConstructItems = [&](std::vector<const void *> & curItems){
|
|
|
|
if(variables["timers"].isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(auto & p : variables["timers"].Vector())
|
|
|
|
{
|
|
|
|
curItems.push_back(&p);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
w->onSetItem = [&](const void * item){
|
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
if(auto * tObj = reinterpret_cast<const JsonNode *>(item))
|
|
|
|
{
|
|
|
|
for(auto wname : (*tObj)["hideWidgets"].Vector())
|
2023-08-26 01:14:01 +02:00
|
|
|
{
|
2023-08-25 18:20:26 +02:00
|
|
|
if(auto w = widget<CIntObject>(wname.String()))
|
|
|
|
w->setEnabled(false);
|
2023-08-26 01:14:01 +02:00
|
|
|
}
|
2023-08-25 18:20:26 +02:00
|
|
|
for(auto wname : (*tObj)["showWidgets"].Vector())
|
2023-08-26 01:14:01 +02:00
|
|
|
{
|
2023-08-25 18:20:26 +02:00
|
|
|
if(auto w = widget<CIntObject>(wname.String()))
|
|
|
|
w->setEnabled(true);
|
2023-08-26 01:14:01 +02:00
|
|
|
}
|
|
|
|
if((*tObj)["default"].isVector())
|
|
|
|
{
|
|
|
|
TurnTimerInfo tinfo;
|
|
|
|
tinfo.baseTimer = (*tObj)["default"].Vector().at(0).Integer() * 1000;
|
|
|
|
tinfo.turnTimer = (*tObj)["default"].Vector().at(1).Integer() * 1000;
|
|
|
|
tinfo.battleTimer = (*tObj)["default"].Vector().at(2).Integer() * 1000;
|
|
|
|
tinfo.creatureTimer = (*tObj)["default"].Vector().at(3).Integer() * 1000;
|
|
|
|
CSH->setTurnTimerInfo(tinfo);
|
|
|
|
}
|
2023-08-25 18:20:26 +02:00
|
|
|
}
|
|
|
|
redraw();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
w->getItemText = [this](int idx, const void * item){
|
|
|
|
if(item)
|
|
|
|
{
|
|
|
|
if(auto * tObj = reinterpret_cast<const JsonNode *>(item))
|
|
|
|
return readText((*tObj)["text"]);
|
|
|
|
}
|
|
|
|
return std::string("");
|
|
|
|
};
|
|
|
|
|
|
|
|
w->setItem(0);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::recreate()
|
|
|
|
{
|
|
|
|
entries.clear();
|
2021-11-08 18:49:04 +02:00
|
|
|
humanPlayers = 0;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-29 02:04:32 +02:00
|
|
|
for (auto selectionWindow : GH.windows().findWindows<SelectionWindow>())
|
|
|
|
{
|
|
|
|
selectionWindow->reopen();
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
for(auto & pInfo : SEL->getStartInfo()->playerInfos)
|
|
|
|
{
|
2021-11-08 18:49:04 +02:00
|
|
|
if(pInfo.second.isControlledByHuman())
|
|
|
|
humanPlayers++;
|
|
|
|
|
|
|
|
entries.insert(std::make_pair(pInfo.first, std::make_shared<PlayerOptionsEntry>(pInfo.second, * this)));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-09-22 20:41:32 +02:00
|
|
|
|
|
|
|
//Simultaneous turns
|
|
|
|
if(auto turnSlider = widget<CSlider>("labelSimturnsDurationValue"))
|
|
|
|
turnSlider->scrollTo(SEL->getStartInfo()->simturnsInfo.optionalTurns);
|
|
|
|
|
|
|
|
if(auto w = widget<CLabel>("labelSimturnsDurationValue"))
|
|
|
|
{
|
|
|
|
MetaString message;
|
|
|
|
message.appendRawString("Simturns: up to %d days");
|
|
|
|
message.replaceNumber(SEL->getStartInfo()->simturnsInfo.optionalTurns);
|
|
|
|
w->setText(message.toString());
|
|
|
|
}
|
2023-08-26 01:14:01 +02:00
|
|
|
|
|
|
|
const auto & turnTimerRemote = SEL->getStartInfo()->turnTimerInfo;
|
|
|
|
|
|
|
|
//classic timer
|
2023-08-23 17:29:50 +02:00
|
|
|
if(auto turnSlider = widget<CSlider>("sliderTurnDuration"))
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-08-26 01:14:01 +02:00
|
|
|
if(!variables["timerPresets"].isNull() && !turnTimerRemote.battleTimer && !turnTimerRemote.creatureTimer && !turnTimerRemote.baseTimer)
|
2023-08-25 18:20:26 +02:00
|
|
|
{
|
|
|
|
for(int idx = 0; idx < variables["timerPresets"].Vector().size(); ++idx)
|
|
|
|
{
|
|
|
|
auto & tpreset = variables["timerPresets"].Vector()[idx];
|
2023-08-26 01:14:01 +02:00
|
|
|
if(tpreset.Vector().at(1).Integer() == turnTimerRemote.turnTimer / 1000)
|
2023-08-25 18:20:26 +02:00
|
|
|
{
|
|
|
|
turnSlider->scrollTo(idx);
|
|
|
|
if(auto w = widget<CLabel>("labelTurnDurationValue"))
|
|
|
|
w->setText(CGI->generaltexth->turnDurations[idx]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-08-26 01:14:01 +02:00
|
|
|
|
|
|
|
//chess timer
|
|
|
|
auto timeToString = [](int time) -> std::string
|
|
|
|
{
|
|
|
|
std::stringstream ss;
|
|
|
|
ss << time / 1000 / 60 << ":" << std::setw(2) << std::setfill('0') << time / 1000 % 60;
|
|
|
|
return ss.str();
|
|
|
|
};
|
|
|
|
|
|
|
|
if(auto ww = widget<CTextInput>("chessFieldBase"))
|
|
|
|
ww->setText(timeToString(turnTimerRemote.baseTimer), false);
|
|
|
|
if(auto ww = widget<CTextInput>("chessFieldTurn"))
|
|
|
|
ww->setText(timeToString(turnTimerRemote.turnTimer), false);
|
|
|
|
if(auto ww = widget<CTextInput>("chessFieldBattle"))
|
|
|
|
ww->setText(timeToString(turnTimerRemote.battleTimer), false);
|
|
|
|
if(auto ww = widget<CTextInput>("chessFieldCreature"))
|
|
|
|
ww->setText(timeToString(turnTimerRemote.creatureTimer), false);
|
|
|
|
|
|
|
|
if(auto w = widget<ComboBox>("timerModeSwitch"))
|
|
|
|
{
|
|
|
|
if(turnTimerRemote.battleTimer || turnTimerRemote.creatureTimer || turnTimerRemote.baseTimer)
|
|
|
|
{
|
|
|
|
if(auto turnSlider = widget<CSlider>("sliderTurnDuration"))
|
|
|
|
if(turnSlider->isActive())
|
|
|
|
w->setItem(1);
|
|
|
|
}
|
|
|
|
}
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-12 13:19:58 +02:00
|
|
|
size_t OptionsTab::CPlayerSettingsHelper::getImageIndex(bool big)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
enum EBonusSelection //frames of bonuses file
|
|
|
|
{
|
|
|
|
WOOD_ORE = 0, CRYSTAL = 1, GEM = 2,
|
|
|
|
MERCURY = 3, SULFUR = 5, GOLD = 8,
|
|
|
|
ARTIFACT = 9, RANDOM = 10,
|
|
|
|
WOOD = 0, ORE = 0, MITHRIL = 10, // resources unavailable in bonuses file
|
|
|
|
|
|
|
|
TOWN_RANDOM = 38, TOWN_NONE = 39, // Special frames in ITPA
|
2023-09-28 18:43:04 +02:00
|
|
|
HERO_RANDOM = 156, HERO_NONE = 157 // Special frames in PortraitsSmall
|
2018-01-05 19:21:07 +02:00
|
|
|
};
|
2023-09-28 18:43:04 +02:00
|
|
|
auto factionIndex = playerSettings.getCastleValidated();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
case TOWN:
|
2023-09-28 18:43:04 +02:00
|
|
|
{
|
|
|
|
if (playerSettings.castle == FactionID::NONE)
|
2018-01-05 19:21:07 +02:00
|
|
|
return TOWN_NONE;
|
2023-09-28 18:43:04 +02:00
|
|
|
|
|
|
|
if (playerSettings.castle == FactionID::RANDOM)
|
2018-01-05 19:21:07 +02:00
|
|
|
return TOWN_RANDOM;
|
2023-09-28 18:43:04 +02:00
|
|
|
|
|
|
|
return (*CGI->townh)[factionIndex]->town->clientInfo.icons[true][false] + (big ? 0 : 2);
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
case HERO:
|
2023-09-28 18:43:04 +02:00
|
|
|
{
|
|
|
|
if (playerSettings.hero == HeroTypeID::NONE)
|
2018-01-05 19:21:07 +02:00
|
|
|
return HERO_NONE;
|
2023-09-28 18:43:04 +02:00
|
|
|
|
|
|
|
if (playerSettings.hero == HeroTypeID::RANDOM)
|
2018-01-05 19:21:07 +02:00
|
|
|
return HERO_RANDOM;
|
2023-09-28 18:43:04 +02:00
|
|
|
|
|
|
|
if(playerSettings.heroPortrait != HeroTypeID::NONE)
|
|
|
|
return playerSettings.heroPortrait;
|
|
|
|
|
|
|
|
auto index = playerSettings.getHeroValidated();
|
|
|
|
return (*CGI->heroh)[index]->imageIndex;
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
case BONUS:
|
|
|
|
{
|
2023-09-17 00:32:10 +02:00
|
|
|
switch(playerSettings.bonus)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RANDOM:
|
2018-01-05 19:21:07 +02:00
|
|
|
return RANDOM;
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::ARTIFACT:
|
2018-01-05 19:21:07 +02:00
|
|
|
return ARTIFACT;
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::GOLD:
|
2018-01-05 19:21:07 +02:00
|
|
|
return GOLD;
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RESOURCE:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
switch((*CGI->townh)[factionIndex]->town->primaryRes.toEnum())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::WOOD_AND_ORE:
|
2018-01-05 19:21:07 +02:00
|
|
|
return WOOD_ORE;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::WOOD:
|
2018-01-05 19:21:07 +02:00
|
|
|
return WOOD;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::MERCURY:
|
2018-01-05 19:21:07 +02:00
|
|
|
return MERCURY;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::ORE:
|
2018-01-05 19:21:07 +02:00
|
|
|
return ORE;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::SULFUR:
|
2018-01-05 19:21:07 +02:00
|
|
|
return SULFUR;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::CRYSTAL:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CRYSTAL;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::GEMS:
|
2018-01-05 19:21:07 +02:00
|
|
|
return GEM;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::GOLD:
|
2018-01-05 19:21:07 +02:00
|
|
|
return GOLD;
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::MITHRIL:
|
2018-01-05 19:21:07 +02:00
|
|
|
return MITHRIL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath OptionsTab::CPlayerSettingsHelper::getImageName(bool big)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
case OptionsTab::TOWN:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin(big ? "ITPt": "ITPA");
|
2018-01-05 19:21:07 +02:00
|
|
|
case OptionsTab::HERO:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin(big ? "PortraitsLarge": "PortraitsSmall");
|
2018-01-05 19:21:07 +02:00
|
|
|
case OptionsTab::BONUS:
|
2023-08-23 14:07:50 +02:00
|
|
|
return AnimationPath::builtin("SCNRSTAR");
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-08-23 14:07:50 +02:00
|
|
|
return {};
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string OptionsTab::CPlayerSettingsHelper::getName()
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
case TOWN:
|
2021-01-06 16:19:59 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
if (playerSettings.castle == FactionID::NONE)
|
|
|
|
return CGI->generaltexth->allTexts[523];
|
|
|
|
|
|
|
|
if (playerSettings.castle == FactionID::RANDOM)
|
|
|
|
return CGI->generaltexth->allTexts[522];
|
|
|
|
|
|
|
|
auto factionIndex = playerSettings.getCastleValidated();
|
2023-01-04 15:17:50 +02:00
|
|
|
return (*CGI->townh)[factionIndex]->getNameTranslated();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-09-28 18:43:04 +02:00
|
|
|
case HERO:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
if (playerSettings.hero == HeroTypeID::NONE)
|
|
|
|
return CGI->generaltexth->allTexts[523];
|
|
|
|
|
|
|
|
if (playerSettings.hero == HeroTypeID::RANDOM)
|
|
|
|
return CGI->generaltexth->allTexts[522];
|
|
|
|
|
2023-09-28 00:04:05 +02:00
|
|
|
if(!playerSettings.heroNameTextId.empty())
|
|
|
|
return playerSettings.heroNameTextId;
|
2023-09-28 18:43:04 +02:00
|
|
|
auto index = playerSettings.getHeroValidated();
|
2023-01-02 13:27:03 +02:00
|
|
|
return (*CGI->heroh)[index]->getNameTranslated();
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
2023-09-28 18:43:04 +02:00
|
|
|
case BONUS:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
if (playerSettings.bonus == PlayerStartingBonus::RANDOM)
|
|
|
|
return CGI->generaltexth->allTexts[522];
|
|
|
|
|
|
|
|
return CGI->generaltexth->arraytxt[214 + static_cast<int>(playerSettings.bonus)];
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
std::string OptionsTab::CPlayerSettingsHelper::getTitle()
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
case OptionsTab::TOWN:
|
2023-09-28 18:43:04 +02:00
|
|
|
return playerSettings.castle.isValid() ? CGI->generaltexth->allTexts[80] : CGI->generaltexth->allTexts[103];
|
2018-01-05 19:21:07 +02:00
|
|
|
case OptionsTab::HERO:
|
2023-09-28 18:43:04 +02:00
|
|
|
return playerSettings.hero.isValid() ? CGI->generaltexth->allTexts[77] : CGI->generaltexth->allTexts[101];
|
2018-01-05 19:21:07 +02:00
|
|
|
case OptionsTab::BONUS:
|
|
|
|
{
|
2023-09-17 00:32:10 +02:00
|
|
|
switch(playerSettings.bonus)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RANDOM:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[86]; //{Random Bonus}
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::ARTIFACT:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[83]; //{Artifact Bonus}
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::GOLD:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[84]; //{Gold Bonus}
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RESOURCE:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[85]; //{Resource Bonus}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
std::string OptionsTab::CPlayerSettingsHelper::getSubtitle()
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
auto factionIndex = playerSettings.getCastleValidated();
|
|
|
|
auto heroIndex = playerSettings.getHeroValidated();
|
2021-01-06 16:19:59 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
case TOWN:
|
|
|
|
return getName();
|
|
|
|
case HERO:
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
if(playerSettings.hero.isValid())
|
2023-01-02 13:27:03 +02:00
|
|
|
return getName() + " - " + (*CGI->heroh)[heroIndex]->heroClass->getNameTranslated();
|
2018-01-05 19:21:07 +02:00
|
|
|
return getName();
|
|
|
|
}
|
|
|
|
|
|
|
|
case BONUS:
|
|
|
|
{
|
2023-09-17 00:32:10 +02:00
|
|
|
switch(playerSettings.bonus)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::GOLD:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[87]; //500-1000
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RESOURCE:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
switch((*CGI->townh)[factionIndex]->town->primaryRes.toEnum())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::MERCURY:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[694];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::SULFUR:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[695];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::CRYSTAL:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[692];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::GEMS:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[693];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::WOOD_AND_ORE:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[89]; //At the start of the game, 5-10 wood and 5-10 ore are added to your Kingdom's resource pool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string OptionsTab::CPlayerSettingsHelper::getDescription()
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
auto factionIndex = playerSettings.getCastleValidated();
|
2021-01-06 16:19:59 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
case TOWN:
|
|
|
|
return CGI->generaltexth->allTexts[104];
|
|
|
|
case HERO:
|
|
|
|
return CGI->generaltexth->allTexts[102];
|
|
|
|
case BONUS:
|
|
|
|
{
|
2023-09-17 00:32:10 +02:00
|
|
|
switch(playerSettings.bonus)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RANDOM:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[94]; //Gold, wood and ore, or an artifact is randomly chosen as your starting bonus
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::ARTIFACT:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[90]; //An artifact is randomly chosen and equipped to your starting hero
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::GOLD:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[92]; //At the start of the game, 500-1000 gold is added to your Kingdom's resource pool
|
2023-09-28 18:43:04 +02:00
|
|
|
case PlayerStartingBonus::RESOURCE:
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
switch((*CGI->townh)[factionIndex]->town->primaryRes.toEnum())
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::MERCURY:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[690];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::SULFUR:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[691];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::CRYSTAL:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[688];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::GEMS:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[689];
|
2023-04-05 02:26:29 +02:00
|
|
|
case EGameResID::WOOD_AND_ORE:
|
2018-01-05 19:21:07 +02:00
|
|
|
return CGI->generaltexth->allTexts[93]; //At the start of the game, 5-10 wood and 5-10 ore are added to your Kingdom's resource pool
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
OptionsTab::CPlayerOptionTooltipBox::CPlayerOptionTooltipBox(CPlayerSettingsHelper & helper)
|
|
|
|
: CWindowObject(BORDERED | RCLICK_POPUP), CPlayerSettingsHelper(helper)
|
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(selectionType)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
case TOWN:
|
|
|
|
genTownWindow();
|
|
|
|
break;
|
|
|
|
case HERO:
|
|
|
|
genHeroWindow();
|
|
|
|
break;
|
|
|
|
case BONUS:
|
|
|
|
genBonusWindow();
|
|
|
|
break;
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
center();
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::CPlayerOptionTooltipBox::genHeader()
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
backgroundTexture = std::make_shared<CFilledTexture>(ImagePath::builtin("DIBOXBCK"), pos);
|
2018-01-05 19:21:07 +02:00
|
|
|
updateShadow();
|
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
labelTitle = std::make_shared<CLabel>(pos.w / 2 + 8, 21, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, getTitle());
|
|
|
|
labelSubTitle = std::make_shared<CLabel>(pos.w / 2, 88, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, getSubtitle());
|
2018-01-05 19:21:07 +02:00
|
|
|
image = std::make_shared<CAnimImage>(getImageName(), getImageIndex(), 0, pos.w / 2 - 24, 45);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::CPlayerOptionTooltipBox::genTownWindow()
|
|
|
|
{
|
|
|
|
pos = Rect(0, 0, 228, 290);
|
|
|
|
genHeader();
|
2022-11-26 23:12:20 +02:00
|
|
|
labelAssociatedCreatures = std::make_shared<CLabel>(pos.w / 2 + 8, 122, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[79]);
|
2023-09-28 18:43:04 +02:00
|
|
|
auto factionIndex = playerSettings.getCastleValidated();
|
2018-04-07 13:34:11 +02:00
|
|
|
std::vector<std::shared_ptr<CComponent>> components;
|
Entities redesign and a few ERM features
* Made most Handlers derived from CHandlerBase and moved service API there.
* Declared existing Entity APIs.
* Added basic script context caching
* Started Lua script module
* Started Lua spell effect API
* Started script state persistence
* Started battle info callback binding
* CommitPackage removed
* Extracted spells::Caster to own header; Expanded Spell API.
* implemented !!MC:S, !!FU:E, !!FU:P, !!MA, !!VR:H, !!VR:C
* !!BU:C, !!BU:E, !!BU:G, !!BU:M implemented
* Allow use of "MC:S@varName@" to declare normal variable (technically v-variable with string key)
* Re-enabled VERM macros.
* !?GM0 added
* !?TM implemented
* Added !!MF:N
* Started !?OB, !!BM, !!HE, !!OW, !!UN
* Added basic support of w-variables
* Added support for ERM indirect variables
* Made !?FU regular trigger
* !!re (ERA loop receiver) implemented
* Fixed ERM receivers with zero args.
2018-03-17 16:58:30 +02:00
|
|
|
const CTown * town = (*CGI->townh)[factionIndex]->town;
|
2021-01-06 16:19:59 +02:00
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
for(auto & elem : town->creatures)
|
|
|
|
{
|
|
|
|
if(!elem.empty())
|
2018-04-07 13:34:11 +02:00
|
|
|
components.push_back(std::make_shared<CComponent>(CComponent::creature, elem.front(), 0, CComponent::tiny));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
boxAssociatedCreatures = std::make_shared<CComponentBox>(components, Rect(10, 140, pos.w - 20, 140));
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::CPlayerOptionTooltipBox::genHeroWindow()
|
|
|
|
{
|
|
|
|
pos = Rect(0, 0, 292, 226);
|
|
|
|
genHeader();
|
2022-11-26 23:12:20 +02:00
|
|
|
labelHeroSpeciality = std::make_shared<CLabel>(pos.w / 2 + 4, 117, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[78]);
|
2023-09-28 18:43:04 +02:00
|
|
|
auto heroIndex = playerSettings.getHeroValidated();
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
imageSpeciality = std::make_shared<CAnimImage>(AnimationPath::builtin("UN44"), (*CGI->heroh)[heroIndex]->imageIndex, 0, pos.w / 2 - 22, 134);
|
2023-01-02 13:27:03 +02:00
|
|
|
labelSpecialityName = std::make_shared<CLabel>(pos.w / 2, 188, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, (*CGI->heroh)[heroIndex]->getSpecialtyNameTranslated());
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::CPlayerOptionTooltipBox::genBonusWindow()
|
|
|
|
{
|
|
|
|
pos = Rect(0, 0, 228, 162);
|
|
|
|
genHeader();
|
|
|
|
|
2022-11-26 23:12:20 +02:00
|
|
|
textBonusDescription = std::make_shared<CTextBox>(getDescription(), Rect(10, 100, pos.w - 20, 70), 0, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
OptionsTab::SelectionWindow::SelectionWindow(PlayerColor _color, SelType _type)
|
2023-08-12 02:41:48 +02:00
|
|
|
: CWindowObject(BORDERED)
|
|
|
|
{
|
|
|
|
addUsedEvents(LCLICK | SHOW_POPUP);
|
|
|
|
|
2023-08-12 17:46:35 +02:00
|
|
|
color = _color;
|
2023-08-13 19:23:27 +02:00
|
|
|
type = _type;
|
2023-08-12 16:49:42 +02:00
|
|
|
|
2023-08-14 00:40:12 +02:00
|
|
|
initialFaction = SEL->getStartInfo()->playerInfos.find(color)->second.castle;
|
2023-08-12 17:46:35 +02:00
|
|
|
initialHero = SEL->getStartInfo()->playerInfos.find(color)->second.hero;
|
|
|
|
initialBonus = SEL->getStartInfo()->playerInfos.find(color)->second.bonus;
|
2023-08-14 00:40:12 +02:00
|
|
|
selectedFaction = initialFaction;
|
2023-08-12 20:31:00 +02:00
|
|
|
selectedHero = initialHero;
|
|
|
|
selectedBonus = initialBonus;
|
2023-09-28 18:43:04 +02:00
|
|
|
allowedFactions = SEL->getPlayerInfo(color).allowedFactions;
|
2023-08-12 21:50:40 +02:00
|
|
|
std::vector<bool> allowedHeroesFlag = SEL->getMapInfo()->mapHeader->allowedHeroes;
|
|
|
|
for(int i = 0; i < allowedHeroesFlag.size(); i++)
|
|
|
|
if(allowedHeroesFlag[i])
|
|
|
|
allowedHeroes.insert(HeroTypeID(i));
|
|
|
|
|
2023-08-29 00:14:49 +02:00
|
|
|
for(auto & player : SEL->getStartInfo()->playerInfos)
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
if(player.first != color && (int)player.second.hero > HeroTypeID::RANDOM)
|
2023-08-29 21:08:18 +02:00
|
|
|
unusableHeroes.insert(player.second.hero);
|
2023-08-29 00:14:49 +02:00
|
|
|
}
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
allowedBonus.push_back(PlayerStartingBonus::RANDOM);
|
|
|
|
|
|
|
|
if(initialHero != HeroTypeID::NONE|| SEL->getPlayerInfo(color).heroesNames.size() > 0)
|
|
|
|
allowedBonus.push_back(PlayerStartingBonus::ARTIFACT);
|
|
|
|
|
|
|
|
allowedBonus.push_back(PlayerStartingBonus::GOLD);
|
|
|
|
|
|
|
|
if(initialFaction.isValid())
|
|
|
|
allowedBonus.push_back(PlayerStartingBonus::RESOURCE);
|
2023-08-13 19:23:27 +02:00
|
|
|
|
|
|
|
recreate();
|
2023-08-13 15:09:48 +02:00
|
|
|
}
|
2023-08-12 21:50:40 +02:00
|
|
|
|
2023-08-13 15:09:48 +02:00
|
|
|
int OptionsTab::SelectionWindow::calcLines(FactionID faction)
|
|
|
|
{
|
2023-08-13 20:21:09 +02:00
|
|
|
double additionalItems = 1; // random
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(!faction.isValid())
|
2023-08-13 22:58:49 +02:00
|
|
|
return std::ceil(((double)allowedFactions.size() + additionalItems) / elementsPerLine);
|
2023-08-12 17:46:35 +02:00
|
|
|
|
2023-08-13 15:09:48 +02:00
|
|
|
int count = 0;
|
|
|
|
for(auto & elemh : allowedHeroes)
|
|
|
|
{
|
|
|
|
CHero * type = VLC->heroh->objects[elemh];
|
|
|
|
if(type->heroClass->faction == faction)
|
|
|
|
count++;
|
|
|
|
}
|
2023-08-12 02:41:48 +02:00
|
|
|
|
2023-08-13 22:58:49 +02:00
|
|
|
return std::ceil(std::max((double)count + additionalItems, (double)allowedFactions.size() + additionalItems) / (double)elementsPerLine);
|
2023-08-12 02:41:48 +02:00
|
|
|
}
|
|
|
|
|
2023-08-12 16:49:42 +02:00
|
|
|
void OptionsTab::SelectionWindow::apply()
|
|
|
|
{
|
|
|
|
if(GH.windows().isTopWindow(this))
|
|
|
|
{
|
2023-08-13 19:23:27 +02:00
|
|
|
GH.input().hapticFeedback();
|
2023-08-20 13:05:25 +02:00
|
|
|
CCS->soundh->playSound(soundBase::button);
|
2023-08-13 19:23:27 +02:00
|
|
|
|
2023-08-12 16:49:42 +02:00
|
|
|
close();
|
2023-08-12 17:46:35 +02:00
|
|
|
|
2023-08-12 18:20:44 +02:00
|
|
|
setSelection();
|
2023-08-12 16:49:42 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-12 18:20:44 +02:00
|
|
|
void OptionsTab::SelectionWindow::setSelection()
|
|
|
|
{
|
2023-08-14 00:40:12 +02:00
|
|
|
if(selectedFaction != initialFaction)
|
|
|
|
CSH->setPlayerOption(LobbyChangePlayerOption::TOWN_ID, selectedFaction, color);
|
2023-08-12 19:33:25 +02:00
|
|
|
|
2023-08-14 00:16:53 +02:00
|
|
|
if(selectedHero != initialHero)
|
|
|
|
CSH->setPlayerOption(LobbyChangePlayerOption::HERO_ID, selectedHero, color);
|
2023-08-12 19:33:25 +02:00
|
|
|
|
2023-08-14 00:16:53 +02:00
|
|
|
if(selectedBonus != initialBonus)
|
2023-09-28 18:43:04 +02:00
|
|
|
CSH->setPlayerOption(LobbyChangePlayerOption::BONUS_ID, static_cast<int>(selectedBonus), color);
|
2023-08-12 18:20:44 +02:00
|
|
|
}
|
|
|
|
|
2023-08-29 02:04:32 +02:00
|
|
|
void OptionsTab::SelectionWindow::reopen()
|
|
|
|
{
|
|
|
|
std::shared_ptr<SelectionWindow> window = std::shared_ptr<SelectionWindow>(new SelectionWindow(color, type));
|
|
|
|
close();
|
|
|
|
GH.windows().pushWindow(window);
|
|
|
|
}
|
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
void OptionsTab::SelectionWindow::recreate()
|
2023-08-12 16:49:42 +02:00
|
|
|
{
|
2023-08-12 18:20:44 +02:00
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
2023-08-13 22:58:49 +02:00
|
|
|
|
|
|
|
int amountLines = 1;
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::BONUS)
|
2023-08-13 22:58:49 +02:00
|
|
|
elementsPerLine = allowedBonus.size();
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// try to make squarish
|
|
|
|
if(type == SelType::TOWN)
|
|
|
|
elementsPerLine = floor(sqrt(allowedFactions.size()));
|
|
|
|
if(type == SelType::HERO)
|
|
|
|
{
|
|
|
|
int count = 0;
|
|
|
|
for(auto & elem : allowedHeroes)
|
|
|
|
{
|
|
|
|
CHero * type = VLC->heroh->objects[elem];
|
2023-08-14 00:40:12 +02:00
|
|
|
if(type->heroClass->faction == selectedFaction)
|
2023-08-13 22:58:49 +02:00
|
|
|
{
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
elementsPerLine = floor(sqrt(count));
|
|
|
|
}
|
2023-08-13 15:09:48 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
amountLines = calcLines((type > SelType::TOWN) ? selectedFaction : FactionID::RANDOM);
|
2023-08-13 22:58:49 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 17:54:53 +02:00
|
|
|
int x = (elementsPerLine) * (ICON_BIG_WIDTH-1);
|
|
|
|
int y = (amountLines) * (ICON_BIG_HEIGHT-1);
|
2023-08-13 15:09:48 +02:00
|
|
|
|
|
|
|
pos = Rect(0, 0, x, y);
|
|
|
|
|
2023-08-23 14:07:50 +02:00
|
|
|
backgroundTexture = std::make_shared<FilledTexturePlayerColored>(ImagePath::builtin("DiBoxBck"), pos);
|
2023-08-14 22:22:43 +02:00
|
|
|
backgroundTexture->playerColored(PlayerColor(1));
|
2023-08-13 15:09:48 +02:00
|
|
|
updateShadow();
|
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::TOWN)
|
2023-08-14 00:40:12 +02:00
|
|
|
genContentFactions();
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::HERO)
|
2023-08-13 15:09:48 +02:00
|
|
|
genContentHeroes();
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::BONUS)
|
2023-08-13 15:09:48 +02:00
|
|
|
genContentBonus();
|
2023-08-13 19:23:27 +02:00
|
|
|
genContentGrid(amountLines);
|
2023-08-12 16:49:42 +02:00
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
center();
|
2023-08-12 22:59:45 +02:00
|
|
|
}
|
|
|
|
|
2023-08-13 22:58:49 +02:00
|
|
|
void OptionsTab::SelectionWindow::drawOutlinedText(int x, int y, ColorRGBA color, std::string text)
|
|
|
|
{
|
|
|
|
components.push_back(std::make_shared<CLabel>(x-1, y, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
|
|
|
components.push_back(std::make_shared<CLabel>(x+1, y, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
|
|
|
components.push_back(std::make_shared<CLabel>(x, y-1, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
|
|
|
components.push_back(std::make_shared<CLabel>(x, y+1, FONT_TINY, ETextAlignment::CENTER, Colors::BLACK, text));
|
|
|
|
components.push_back(std::make_shared<CLabel>(x, y, FONT_TINY, ETextAlignment::CENTER, color, text));
|
|
|
|
}
|
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
void OptionsTab::SelectionWindow::genContentGrid(int lines)
|
2023-08-12 22:59:45 +02:00
|
|
|
{
|
2023-08-17 17:29:31 +02:00
|
|
|
for(int y = 0; y < lines; y++)
|
2023-08-12 22:59:45 +02:00
|
|
|
{
|
2023-08-17 17:29:31 +02:00
|
|
|
for(int x = 0; x < elementsPerLine; x++)
|
2023-08-12 22:59:45 +02:00
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
components.push_back(std::make_shared<CPicture>(ImagePath::builtin("lobby/townBorderBig"), x * (ICON_BIG_WIDTH-1), y * (ICON_BIG_HEIGHT-1)));
|
2023-08-12 22:59:45 +02:00
|
|
|
}
|
|
|
|
}
|
2023-08-12 15:19:40 +02:00
|
|
|
}
|
|
|
|
|
2023-08-14 00:40:12 +02:00
|
|
|
void OptionsTab::SelectionWindow::genContentFactions()
|
2023-08-12 02:41:48 +02:00
|
|
|
{
|
2023-08-13 20:21:09 +02:00
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
// random
|
|
|
|
PlayerSettings set = PlayerSettings();
|
2023-09-28 18:43:04 +02:00
|
|
|
set.castle = FactionID::RANDOM;
|
2023-08-13 20:21:09 +02:00
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
|
2023-08-17 17:54:53 +02:00
|
|
|
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, 6, (ICON_SMALL_HEIGHT/2)));
|
2023-09-28 18:43:04 +02:00
|
|
|
drawOutlinedText(TEXT_POS_X, TEXT_POS_Y, (selectedFaction == FactionID::RANDOM) ? Colors::YELLOW : Colors::WHITE, helper.getName());
|
|
|
|
if(selectedFaction == FactionID::RANDOM)
|
2023-08-23 14:07:50 +02:00
|
|
|
components.push_back(std::make_shared<CPicture>(ImagePath::builtin("lobby/townBorderSmallActivated"), 6, (ICON_SMALL_HEIGHT/2)));
|
2023-08-13 19:23:27 +02:00
|
|
|
|
2023-08-12 17:46:35 +02:00
|
|
|
for(auto & elem : allowedFactions)
|
2023-08-12 02:41:48 +02:00
|
|
|
{
|
2023-08-13 22:58:49 +02:00
|
|
|
int x = i % elementsPerLine;
|
|
|
|
int y = i / elementsPerLine;
|
2023-08-12 02:41:48 +02:00
|
|
|
|
|
|
|
PlayerSettings set = PlayerSettings();
|
|
|
|
set.castle = elem;
|
|
|
|
|
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
|
|
|
|
|
2023-08-17 17:54:53 +02:00
|
|
|
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(true), helper.getImageIndex(true), 0, x * (ICON_BIG_WIDTH-1), y * (ICON_BIG_HEIGHT-1)));
|
2023-08-23 14:07:50 +02:00
|
|
|
components.push_back(std::make_shared<CPicture>(ImagePath::builtin(selectedFaction == elem ? "lobby/townBorderBigActivated" : "lobby/townBorderBig"), x * (ICON_BIG_WIDTH-1), y * (ICON_BIG_HEIGHT-1)));
|
2023-08-17 17:54:53 +02:00
|
|
|
drawOutlinedText(x * (ICON_BIG_WIDTH-1) + TEXT_POS_X, y * (ICON_BIG_HEIGHT-1) + TEXT_POS_Y, (selectedFaction == elem) ? Colors::YELLOW : Colors::WHITE, helper.getName());
|
2023-08-12 02:41:48 +02:00
|
|
|
factions.push_back(elem);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-12 16:49:42 +02:00
|
|
|
void OptionsTab::SelectionWindow::genContentHeroes()
|
2023-08-12 02:41:48 +02:00
|
|
|
{
|
2023-08-13 20:21:09 +02:00
|
|
|
int i = 1;
|
|
|
|
|
|
|
|
// random
|
|
|
|
PlayerSettings set = PlayerSettings();
|
2023-09-28 18:43:04 +02:00
|
|
|
set.hero = HeroTypeID::RANDOM;
|
2023-08-13 20:21:09 +02:00
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
|
2023-08-17 17:54:53 +02:00
|
|
|
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, 6, (ICON_SMALL_HEIGHT/2)));
|
2023-09-28 18:43:04 +02:00
|
|
|
drawOutlinedText(TEXT_POS_X, TEXT_POS_Y, (selectedHero == HeroTypeID::RANDOM) ? Colors::YELLOW : Colors::WHITE, helper.getName());
|
|
|
|
if(selectedHero == HeroTypeID::RANDOM)
|
2023-08-23 14:07:50 +02:00
|
|
|
components.push_back(std::make_shared<CPicture>(ImagePath::builtin("lobby/townBorderSmallActivated"), 6, (ICON_SMALL_HEIGHT/2)));
|
2023-08-13 19:23:27 +02:00
|
|
|
|
2023-08-12 13:19:58 +02:00
|
|
|
for(auto & elem : allowedHeroes)
|
|
|
|
{
|
2023-08-12 15:05:26 +02:00
|
|
|
CHero * type = VLC->heroh->objects[elem];
|
2023-08-12 13:19:58 +02:00
|
|
|
|
2023-08-14 00:40:12 +02:00
|
|
|
if(type->heroClass->faction == selectedFaction)
|
2023-08-12 15:05:26 +02:00
|
|
|
{
|
2023-08-12 13:19:58 +02:00
|
|
|
|
2023-08-13 22:58:49 +02:00
|
|
|
int x = i % elementsPerLine;
|
|
|
|
int y = i / elementsPerLine;
|
2023-08-12 13:19:58 +02:00
|
|
|
|
2023-08-12 15:05:26 +02:00
|
|
|
PlayerSettings set = PlayerSettings();
|
|
|
|
set.hero = elem;
|
|
|
|
|
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
|
|
|
|
|
2023-08-17 17:54:53 +02:00
|
|
|
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(true), helper.getImageIndex(true), 0, x * (ICON_BIG_WIDTH-1), y * (ICON_BIG_HEIGHT-1)));
|
|
|
|
drawOutlinedText(x * (ICON_BIG_WIDTH-1) + TEXT_POS_X, y * (ICON_BIG_HEIGHT-1) + TEXT_POS_Y, (selectedHero == elem) ? Colors::YELLOW : Colors::WHITE, helper.getName());
|
2023-08-23 14:07:50 +02:00
|
|
|
ImagePath image = ImagePath::builtin("lobby/townBorderBig");
|
2023-08-29 00:14:49 +02:00
|
|
|
if(selectedHero == elem)
|
2023-08-23 14:07:50 +02:00
|
|
|
image = ImagePath::builtin("lobby/townBorderBigActivated");
|
2023-08-29 21:08:18 +02:00
|
|
|
if(unusableHeroes.count(elem))
|
2023-08-23 14:07:50 +02:00
|
|
|
image = ImagePath::builtin("lobby/townBorderBigGrayedOut");
|
2023-08-29 00:14:49 +02:00
|
|
|
components.push_back(std::make_shared<CPicture>(image, x * (ICON_BIG_WIDTH-1), y * (ICON_BIG_HEIGHT-1)));
|
2023-08-12 15:05:26 +02:00
|
|
|
heroes.push_back(elem);
|
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-08-12 16:49:42 +02:00
|
|
|
void OptionsTab::SelectionWindow::genContentBonus()
|
2023-08-12 15:05:26 +02:00
|
|
|
{
|
|
|
|
PlayerSettings set = PlayerSettings();
|
|
|
|
|
|
|
|
int i = 0;
|
2023-08-13 19:23:27 +02:00
|
|
|
for(auto elem : allowedBonus)
|
2023-08-12 15:05:26 +02:00
|
|
|
{
|
2023-08-13 19:23:27 +02:00
|
|
|
int x = i;
|
|
|
|
int y = 0;
|
2023-08-12 15:05:26 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
set.bonus = elem;
|
2023-08-12 15:05:26 +02:00
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::BONUS);
|
2023-08-17 17:54:53 +02:00
|
|
|
components.push_back(std::make_shared<CAnimImage>(helper.getImageName(), helper.getImageIndex(), 0, x * (ICON_BIG_WIDTH-1) + 6, y * (ICON_BIG_HEIGHT-1) + (ICON_SMALL_HEIGHT/2)));
|
|
|
|
drawOutlinedText(x * (ICON_BIG_WIDTH-1) + TEXT_POS_X, y * (ICON_BIG_HEIGHT-1) + TEXT_POS_Y, Colors::WHITE , helper.getName());
|
2023-08-12 22:59:45 +02:00
|
|
|
if(selectedBonus == elem)
|
2023-08-14 00:40:12 +02:00
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
components.push_back(std::make_shared<CPicture>(ImagePath::builtin("lobby/townBorderSmallActivated"), x * (ICON_BIG_WIDTH-1) + 6, y * (ICON_BIG_HEIGHT-1) + (ICON_SMALL_HEIGHT/2)));
|
2023-08-17 17:54:53 +02:00
|
|
|
drawOutlinedText(x * (ICON_BIG_WIDTH-1) + TEXT_POS_X, y * (ICON_BIG_HEIGHT-1) + TEXT_POS_Y, Colors::YELLOW , helper.getName());
|
2023-08-14 00:40:12 +02:00
|
|
|
}
|
2023-08-12 13:19:58 +02:00
|
|
|
|
|
|
|
i++;
|
|
|
|
}
|
2023-08-12 02:41:48 +02:00
|
|
|
}
|
|
|
|
|
2023-08-13 19:23:27 +02:00
|
|
|
int OptionsTab::SelectionWindow::getElement(const Point & cursorPosition)
|
2023-08-12 02:41:48 +02:00
|
|
|
{
|
2023-08-17 17:54:53 +02:00
|
|
|
int x = (cursorPosition.x - pos.x) / (ICON_BIG_WIDTH-1);
|
|
|
|
int y = (cursorPosition.y - pos.y) / (ICON_BIG_HEIGHT-1);
|
2023-08-12 02:41:48 +02:00
|
|
|
|
2023-08-13 22:58:49 +02:00
|
|
|
return x + y * elementsPerLine;
|
2023-08-12 02:41:48 +02:00
|
|
|
}
|
|
|
|
|
2023-08-17 20:34:31 +02:00
|
|
|
void OptionsTab::SelectionWindow::setElement(int elem, bool doApply)
|
2023-08-12 02:41:48 +02:00
|
|
|
{
|
|
|
|
PlayerSettings set = PlayerSettings();
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::TOWN)
|
2023-08-12 15:05:26 +02:00
|
|
|
{
|
2023-08-14 00:16:53 +02:00
|
|
|
if(elem > 0)
|
|
|
|
{
|
|
|
|
elem--;
|
|
|
|
if(elem >= factions.size())
|
|
|
|
return;
|
|
|
|
set.castle = factions[elem];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
set.castle = FactionID::RANDOM;
|
2023-08-14 00:16:53 +02:00
|
|
|
}
|
2023-09-28 18:43:04 +02:00
|
|
|
if(set.castle != FactionID::NONE)
|
2023-08-13 19:23:27 +02:00
|
|
|
{
|
2023-08-17 20:34:31 +02:00
|
|
|
if(!doApply)
|
2023-08-17 18:15:42 +02:00
|
|
|
{
|
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::TOWN);
|
|
|
|
GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
|
|
|
|
}
|
2023-08-18 00:15:47 +02:00
|
|
|
else
|
|
|
|
selectedFaction = set.castle;
|
2023-08-13 19:23:27 +02:00
|
|
|
}
|
2023-08-12 15:05:26 +02:00
|
|
|
}
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::HERO)
|
2023-08-12 15:05:26 +02:00
|
|
|
{
|
2023-08-14 00:16:53 +02:00
|
|
|
if(elem > 0)
|
|
|
|
{
|
|
|
|
elem--;
|
|
|
|
if(elem >= heroes.size())
|
|
|
|
return;
|
|
|
|
set.hero = heroes[elem];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
set.hero = HeroTypeID::RANDOM;
|
2023-08-14 00:16:53 +02:00
|
|
|
}
|
2023-08-29 00:14:49 +02:00
|
|
|
|
2023-08-29 21:08:18 +02:00
|
|
|
if(doApply && unusableHeroes.count(heroes[elem]))
|
2023-08-29 00:14:49 +02:00
|
|
|
return;
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(set.hero != HeroTypeID::NONE)
|
2023-08-13 19:23:27 +02:00
|
|
|
{
|
2023-08-17 20:34:31 +02:00
|
|
|
if(!doApply)
|
2023-08-17 18:15:42 +02:00
|
|
|
{
|
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::HERO);
|
2023-09-28 18:43:04 +02:00
|
|
|
if(settings["general"]["enableUiEnhancements"].Bool() && helper.playerSettings.hero.isValid() && helper.playerSettings.heroNameTextId.empty())
|
2023-09-17 00:32:10 +02:00
|
|
|
GH.windows().createAndPushWindow<CHeroOverview>(helper.playerSettings.hero);
|
|
|
|
else
|
|
|
|
GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
|
2023-08-17 18:15:42 +02:00
|
|
|
}
|
2023-08-18 00:15:47 +02:00
|
|
|
else
|
|
|
|
selectedHero = set.hero;
|
2023-08-13 19:23:27 +02:00
|
|
|
}
|
2023-08-12 15:05:26 +02:00
|
|
|
}
|
2023-08-13 19:23:27 +02:00
|
|
|
if(type == SelType::BONUS)
|
2023-08-12 15:05:26 +02:00
|
|
|
{
|
2023-08-13 19:23:27 +02:00
|
|
|
if(elem >= 4)
|
|
|
|
return;
|
2023-09-28 18:43:04 +02:00
|
|
|
set.bonus = static_cast<PlayerStartingBonus>(allowedBonus[elem]);
|
|
|
|
|
|
|
|
if(!doApply)
|
2023-08-13 19:23:27 +02:00
|
|
|
{
|
2023-09-28 18:43:04 +02:00
|
|
|
CPlayerSettingsHelper helper = CPlayerSettingsHelper(set, SelType::BONUS);
|
|
|
|
GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(helper);
|
2023-08-13 19:23:27 +02:00
|
|
|
}
|
2023-09-28 18:43:04 +02:00
|
|
|
else
|
|
|
|
selectedBonus = set.bonus;
|
2023-08-12 15:05:26 +02:00
|
|
|
}
|
2023-08-17 18:15:42 +02:00
|
|
|
|
2023-08-17 20:34:31 +02:00
|
|
|
if(doApply)
|
2023-08-17 18:15:42 +02:00
|
|
|
apply();
|
|
|
|
}
|
|
|
|
|
2023-08-20 13:05:25 +02:00
|
|
|
bool OptionsTab::SelectionWindow::receiveEvent(const Point & position, int eventType) const
|
|
|
|
{
|
|
|
|
return true; // capture click also outside of window
|
|
|
|
}
|
|
|
|
|
2023-08-17 18:15:42 +02:00
|
|
|
void OptionsTab::SelectionWindow::clickReleased(const Point & cursorPosition)
|
|
|
|
{
|
2023-08-20 13:05:25 +02:00
|
|
|
if(!pos.isInside(cursorPosition))
|
|
|
|
{
|
|
|
|
close();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-08-17 18:15:42 +02:00
|
|
|
int elem = getElement(cursorPosition);
|
|
|
|
|
|
|
|
setElement(elem, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::SelectionWindow::showPopupWindow(const Point & cursorPosition)
|
|
|
|
{
|
2023-08-20 13:05:25 +02:00
|
|
|
if(!pos.isInside(cursorPosition))
|
|
|
|
return;
|
|
|
|
|
2023-08-17 18:15:42 +02:00
|
|
|
int elem = getElement(cursorPosition);
|
|
|
|
|
|
|
|
setElement(elem, false);
|
2023-08-12 02:41:48 +02:00
|
|
|
}
|
|
|
|
|
2023-09-17 00:32:10 +02:00
|
|
|
OptionsTab::SelectedBox::SelectedBox(Point position, PlayerSettings & playerSettings, SelType type)
|
2023-08-12 02:41:48 +02:00
|
|
|
: Scrollable(LCLICK | SHOW_POPUP, position, Orientation::HORIZONTAL)
|
2023-09-17 00:32:10 +02:00
|
|
|
, CPlayerSettingsHelper(playerSettings, type)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
|
|
|
|
|
|
|
|
image = std::make_shared<CAnimImage>(getImageName(), getImageIndex());
|
2022-11-26 23:12:20 +02:00
|
|
|
subtitle = std::make_shared<CLabel>(23, 39, FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, getName());
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
pos = image->pos;
|
2023-05-30 17:53:51 +02:00
|
|
|
|
|
|
|
setPanningStep(pos.w);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::SelectedBox::update()
|
|
|
|
{
|
|
|
|
image->setFrame(getImageIndex());
|
|
|
|
subtitle->setText(getName());
|
|
|
|
}
|
|
|
|
|
2023-07-08 13:33:04 +02:00
|
|
|
void OptionsTab::SelectedBox::showPopupWindow(const Point & cursorPosition)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2023-06-11 17:20:10 +02:00
|
|
|
// cases when we do not need to display a message
|
2023-09-28 18:43:04 +02:00
|
|
|
if(playerSettings.castle == FactionID::NONE && CPlayerSettingsHelper::selectionType == TOWN)
|
2023-06-11 17:20:10 +02:00
|
|
|
return;
|
2023-09-28 18:43:04 +02:00
|
|
|
if(playerSettings.hero == HeroTypeID::NONE && !SEL->getPlayerInfo(playerSettings.color).hasCustomMainHero() && CPlayerSettingsHelper::selectionType == HERO)
|
2023-06-11 17:20:10 +02:00
|
|
|
return;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(settings["general"]["enableUiEnhancements"].Bool() && CPlayerSettingsHelper::selectionType == HERO && playerSettings.hero.isValid() && playerSettings.heroNameTextId.empty())
|
2023-09-17 00:32:10 +02:00
|
|
|
GH.windows().createAndPushWindow<CHeroOverview>(playerSettings.hero);
|
|
|
|
else
|
|
|
|
GH.windows().createAndPushWindow<CPlayerOptionTooltipBox>(*this);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-08-12 02:41:48 +02:00
|
|
|
void OptionsTab::SelectedBox::clickReleased(const Point & cursorPosition)
|
|
|
|
{
|
2023-10-21 19:10:02 +02:00
|
|
|
if(SEL->screenType != ESelectionScreen::newGame)
|
|
|
|
return;
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
PlayerInfo pi = SEL->getPlayerInfo(playerSettings.color);
|
2023-09-17 00:32:10 +02:00
|
|
|
const bool foreignPlayer = CSH->isGuest() && !CSH->isMyColor(playerSettings.color);
|
2023-08-13 19:23:27 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(selectionType == SelType::TOWN && ((pi.allowedFactions.size() < 2 && !pi.isFactionRandom) || foreignPlayer))
|
2023-08-13 19:23:27 +02:00
|
|
|
return;
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(selectionType == SelType::HERO && ((pi.defaultHero() == HeroTypeID::NONE || !playerSettings.castle.isValid() || foreignPlayer)))
|
2023-08-13 19:23:27 +02:00
|
|
|
return;
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(selectionType == SelType::BONUS && foreignPlayer)
|
2023-08-13 19:23:27 +02:00
|
|
|
return;
|
|
|
|
|
|
|
|
GH.input().hapticFeedback();
|
2023-09-28 18:43:04 +02:00
|
|
|
GH.windows().createAndPushWindow<SelectionWindow>(playerSettings.color, selectionType);
|
2023-08-12 02:41:48 +02:00
|
|
|
}
|
|
|
|
|
2023-05-30 17:53:51 +02:00
|
|
|
void OptionsTab::SelectedBox::scrollBy(int distance)
|
2023-05-27 16:30:12 +02:00
|
|
|
{
|
2023-05-30 17:53:51 +02:00
|
|
|
// FIXME: currently options tab is completely recreacted from scratch whenever we receive any information from server
|
|
|
|
// because of that, panning event gets interrupted (due to destruction of element)
|
|
|
|
// so, currently, gesture will always move selection only by 1, and then wait for recreation from server info
|
2023-05-29 18:02:23 +02:00
|
|
|
distance = std::clamp(distance, -1, 1);
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
switch(CPlayerSettingsHelper::selectionType)
|
2023-05-27 16:30:12 +02:00
|
|
|
{
|
|
|
|
case TOWN:
|
2023-09-17 00:32:10 +02:00
|
|
|
CSH->setPlayerOption(LobbyChangePlayerOption::TOWN, distance, playerSettings.color);
|
2023-05-27 16:30:12 +02:00
|
|
|
break;
|
|
|
|
case HERO:
|
2023-09-17 00:32:10 +02:00
|
|
|
CSH->setPlayerOption(LobbyChangePlayerOption::HERO, distance, playerSettings.color);
|
2023-05-27 16:30:12 +02:00
|
|
|
break;
|
|
|
|
case BONUS:
|
2023-09-17 00:32:10 +02:00
|
|
|
CSH->setPlayerOption(LobbyChangePlayerOption::BONUS, distance, playerSettings.color);
|
2023-05-27 16:30:12 +02:00
|
|
|
break;
|
|
|
|
}
|
2023-05-29 18:02:23 +02:00
|
|
|
|
2023-05-30 17:53:51 +02:00
|
|
|
setScrollingEnabled(false);
|
2023-05-29 18:02:23 +02:00
|
|
|
}
|
|
|
|
|
2021-11-08 18:49:04 +02:00
|
|
|
OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, const OptionsTab & parent)
|
2023-10-14 12:08:38 +02:00
|
|
|
: CIntObject(LCLICK | KEYBOARD | TEXTINPUT)
|
2023-10-13 23:04:35 +02:00
|
|
|
, pi(std::make_unique<PlayerInfo>(SEL->getPlayerInfo(S.color)))
|
2023-05-20 17:28:35 +02:00
|
|
|
, s(std::make_unique<PlayerSettings>(S))
|
|
|
|
, parentTab(parent)
|
2023-10-14 13:34:39 +02:00
|
|
|
, name(S.name)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
OBJ_CONSTRUCTION;
|
|
|
|
defActions |= SHARE_POS;
|
|
|
|
|
|
|
|
int serial = 0;
|
2023-09-28 18:43:04 +02:00
|
|
|
for(PlayerColor g = PlayerColor(0); g < s->color; ++g)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
auto itred = SEL->getPlayerInfo(g);
|
|
|
|
if(itred.canComputerPlay || itred.canHumanPlay)
|
|
|
|
serial++;
|
|
|
|
}
|
|
|
|
|
|
|
|
pos.x += 54;
|
2023-08-23 17:29:50 +02:00
|
|
|
pos.y += 128 + serial * 50;
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
assert(CSH->mi && CSH->mi->mapHeader);
|
2023-09-28 18:43:04 +02:00
|
|
|
const PlayerInfo & p = SEL->getPlayerInfo(s->color);
|
2018-01-05 19:21:07 +02:00
|
|
|
assert(p.canComputerPlay || p.canHumanPlay); //someone must be able to control this player
|
|
|
|
if(p.canHumanPlay && p.canComputerPlay)
|
|
|
|
whoCanPlay = HUMAN_OR_CPU;
|
|
|
|
else if(p.canComputerPlay)
|
|
|
|
whoCanPlay = CPU;
|
|
|
|
else
|
|
|
|
whoCanPlay = HUMAN;
|
|
|
|
|
2022-11-28 21:20:46 +02:00
|
|
|
static const std::array<std::string, PlayerColor::PLAYER_LIMIT_I> flags =
|
|
|
|
{{
|
2018-01-05 19:21:07 +02:00
|
|
|
"AOFLGBR.DEF", "AOFLGBB.DEF", "AOFLGBY.DEF", "AOFLGBG.DEF",
|
|
|
|
"AOFLGBO.DEF", "AOFLGBP.DEF", "AOFLGBT.DEF", "AOFLGBS.DEF"
|
2022-11-28 21:20:46 +02:00
|
|
|
}};
|
|
|
|
static const std::array<std::string, PlayerColor::PLAYER_LIMIT_I> bgs =
|
|
|
|
{{
|
2018-01-05 19:21:07 +02:00
|
|
|
"ADOPRPNL.bmp", "ADOPBPNL.bmp", "ADOPYPNL.bmp", "ADOPGPNL.bmp",
|
|
|
|
"ADOPOPNL.bmp", "ADOPPPNL.bmp", "ADOPTPNL.bmp", "ADOPSPNL.bmp"
|
2022-11-28 21:20:46 +02:00
|
|
|
}};
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
background = std::make_shared<CPicture>(ImagePath::builtin(bgs[s->color]), 0, 0);
|
2023-10-14 13:34:39 +02:00
|
|
|
if(s->isControlledByAI() || CSH->isGuest())
|
|
|
|
labelPlayerName = std::make_shared<CLabel>(55, 10, EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, name);
|
2023-10-13 23:04:35 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
labelPlayerNameEdit = std::make_shared<CTextInput>(Rect(6, 3, 95, 15), EFonts::FONT_SMALL, nullptr, false);
|
2023-10-14 13:34:39 +02:00
|
|
|
labelPlayerNameEdit->setText(name);
|
2023-10-13 23:04:35 +02:00
|
|
|
}
|
2022-11-26 23:12:20 +02:00
|
|
|
labelWhoCanPlay = std::make_shared<CMultiLineLabel>(Rect(6, 23, 45, (int)graphics->fonts[EFonts::FONT_TINY]->getLineHeight()*2), EFonts::FONT_TINY, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->arraytxt[206 + whoCanPlay]);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
|
|
|
if(SEL->screenType == ESelectionScreen::newGame)
|
|
|
|
{
|
2023-08-23 14:07:50 +02:00
|
|
|
buttonTownLeft = std::make_shared<CButton>(Point(107, 5), AnimationPath::builtin("ADOPLFA.DEF"), CGI->generaltexth->zelp[132], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::TOWN, -1, s->color));
|
|
|
|
buttonTownRight = std::make_shared<CButton>(Point(168, 5), AnimationPath::builtin("ADOPRTA.DEF"), CGI->generaltexth->zelp[133], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::TOWN, +1, s->color));
|
|
|
|
buttonHeroLeft = std::make_shared<CButton>(Point(183, 5), AnimationPath::builtin("ADOPLFA.DEF"), CGI->generaltexth->zelp[148], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::HERO, -1, s->color));
|
|
|
|
buttonHeroRight = std::make_shared<CButton>(Point(244, 5), AnimationPath::builtin("ADOPRTA.DEF"), CGI->generaltexth->zelp[149], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::HERO, +1, s->color));
|
|
|
|
buttonBonusLeft = std::make_shared<CButton>(Point(259, 5), AnimationPath::builtin("ADOPLFA.DEF"), CGI->generaltexth->zelp[164], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::BONUS, -1, s->color));
|
|
|
|
buttonBonusRight = std::make_shared<CButton>(Point(320, 5), AnimationPath::builtin("ADOPRTA.DEF"), CGI->generaltexth->zelp[165], std::bind(&IServerAPI::setPlayerOption, CSH, LobbyChangePlayerOption::BONUS, +1, s->color));
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
hideUnavailableButtons();
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if(SEL->screenType != ESelectionScreen::scenarioInfo && SEL->getPlayerInfo(s->color).canHumanPlay)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
2021-11-08 18:49:04 +02:00
|
|
|
flag = std::make_shared<CButton>(
|
|
|
|
Point(-43, 2),
|
2023-08-23 14:07:50 +02:00
|
|
|
AnimationPath::builtin(flags[s->color.getNum()]),
|
2021-11-08 18:49:04 +02:00
|
|
|
CGI->generaltexth->zelp[180],
|
2023-05-20 17:28:35 +02:00
|
|
|
std::bind(&OptionsTab::onSetPlayerClicked, &parentTab, *s)
|
2021-11-08 18:49:04 +02:00
|
|
|
);
|
2018-01-05 19:21:07 +02:00
|
|
|
flag->hoverable = true;
|
|
|
|
flag->block(CSH->isGuest());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
flag = nullptr;
|
|
|
|
|
2023-05-20 17:28:35 +02:00
|
|
|
town = std::make_shared<SelectedBox>(Point(119, 2), *s, TOWN);
|
|
|
|
hero = std::make_shared<SelectedBox>(Point(195, 2), *s, HERO);
|
|
|
|
bonus = std::make_shared<SelectedBox>(Point(271, 2), *s, BONUS);
|
2018-01-05 19:21:07 +02:00
|
|
|
}
|
|
|
|
|
2023-10-13 23:04:35 +02:00
|
|
|
bool OptionsTab::PlayerOptionsEntry::captureThisKey(EShortcut key)
|
|
|
|
{
|
|
|
|
return labelPlayerNameEdit && labelPlayerNameEdit->hasFocus() && key == EShortcut::GLOBAL_ACCEPT;
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::PlayerOptionsEntry::keyPressed(EShortcut key)
|
|
|
|
{
|
2023-10-14 13:34:39 +02:00
|
|
|
if(labelPlayerNameEdit && key == EShortcut::GLOBAL_ACCEPT)
|
2023-10-16 21:28:44 +02:00
|
|
|
updateName();
|
2023-10-13 23:04:35 +02:00
|
|
|
}
|
|
|
|
|
2023-10-14 12:08:38 +02:00
|
|
|
bool OptionsTab::PlayerOptionsEntry::receiveEvent(const Point & position, int eventType) const
|
|
|
|
{
|
|
|
|
return eventType == AEventsReceiver::LCLICK; // capture all left clicks (not only within control)
|
|
|
|
}
|
|
|
|
|
|
|
|
void OptionsTab::PlayerOptionsEntry::clickReleased(const Point & cursorPosition)
|
|
|
|
{
|
2023-10-14 13:34:39 +02:00
|
|
|
if(labelPlayerNameEdit && !labelPlayerNameEdit->pos.isInside(cursorPosition))
|
2023-10-16 21:28:44 +02:00
|
|
|
updateName();
|
2023-10-14 12:08:38 +02:00
|
|
|
}
|
|
|
|
|
2023-10-16 21:24:59 +02:00
|
|
|
void OptionsTab::PlayerOptionsEntry::updateName() {
|
2023-10-14 13:34:39 +02:00
|
|
|
if(labelPlayerNameEdit->getText() != name)
|
2023-10-14 12:08:38 +02:00
|
|
|
{
|
|
|
|
CSH->setPlayerName(s->color, labelPlayerNameEdit->getText());
|
2023-10-14 13:34:39 +02:00
|
|
|
if(CSH->isMyColor(s->color))
|
|
|
|
{
|
|
|
|
Settings set = settings.write["general"]["playerName"];
|
|
|
|
set->String() = labelPlayerNameEdit->getText();
|
|
|
|
}
|
2023-10-14 12:08:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
labelPlayerNameEdit->removeFocus();
|
2023-10-14 13:34:39 +02:00
|
|
|
name = labelPlayerNameEdit->getText();
|
2023-10-14 12:08:38 +02:00
|
|
|
}
|
|
|
|
|
2021-11-08 18:49:04 +02:00
|
|
|
void OptionsTab::onSetPlayerClicked(const PlayerSettings & ps) const
|
|
|
|
{
|
2023-04-13 00:01:13 +02:00
|
|
|
if(ps.isControlledByAI() || humanPlayers > 0)
|
2021-11-08 18:49:04 +02:00
|
|
|
CSH->setPlayer(ps.color);
|
|
|
|
}
|
|
|
|
|
2018-01-05 19:21:07 +02:00
|
|
|
void OptionsTab::PlayerOptionsEntry::hideUnavailableButtons()
|
|
|
|
{
|
|
|
|
if(!buttonTownLeft)
|
|
|
|
return;
|
|
|
|
|
2023-05-20 17:28:35 +02:00
|
|
|
const bool foreignPlayer = CSH->isGuest() && !CSH->isMyColor(s->color);
|
2018-01-05 19:21:07 +02:00
|
|
|
|
2023-05-20 17:28:35 +02:00
|
|
|
if((pi->allowedFactions.size() < 2 && !pi->isFactionRandom) || foreignPlayer)
|
2018-01-05 19:21:07 +02:00
|
|
|
{
|
|
|
|
buttonTownLeft->disable();
|
|
|
|
buttonTownRight->disable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttonTownLeft->enable();
|
|
|
|
buttonTownRight->enable();
|
|
|
|
}
|
|
|
|
|
2023-09-28 18:43:04 +02:00
|
|
|
if((pi->defaultHero() != HeroTypeID::RANDOM || !s->castle.isValid()) //fixed hero
|
2018-01-05 19:21:07 +02:00
|
|
|
|| foreignPlayer) //or not our player
|
|
|
|
{
|
|
|
|
buttonHeroLeft->disable();
|
|
|
|
buttonHeroRight->disable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttonHeroLeft->enable();
|
|
|
|
buttonHeroRight->enable();
|
|
|
|
}
|
|
|
|
|
|
|
|
if(foreignPlayer)
|
|
|
|
{
|
|
|
|
buttonBonusLeft->disable();
|
|
|
|
buttonBonusRight->disable();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buttonBonusLeft->enable();
|
|
|
|
buttonBonusRight->enable();
|
|
|
|
}
|
2023-08-19 21:35:44 +02:00
|
|
|
}
|