mirror of
https://github.com/vcmi/vcmi.git
synced 2024-12-24 22:14:36 +02:00
Interface builder for random map tab
This commit is contained in:
parent
ed70c69a2b
commit
0104c77d61
@ -15,6 +15,7 @@ set(client_SRCS
|
||||
gui/Geometries.cpp
|
||||
gui/SDL_Extensions.cpp
|
||||
gui/NotificationHandler.cpp
|
||||
gui/InterfaceBuilder.cpp
|
||||
|
||||
widgets/AdventureMapClasses.cpp
|
||||
widgets/Buttons.cpp
|
||||
@ -90,6 +91,7 @@ set(client_HEADERS
|
||||
gui/SDL_Extensions.h
|
||||
gui/SDL_Pixels.h
|
||||
gui/NotificationHandler.h
|
||||
gui/InterfaceBuilder.h
|
||||
|
||||
widgets/AdventureMapClasses.h
|
||||
widgets/Buttons.h
|
||||
|
208
client/gui/InterfaceBuilder.cpp
Normal file
208
client/gui/InterfaceBuilder.cpp
Normal file
@ -0,0 +1,208 @@
|
||||
/*
|
||||
* InterfaceBuilder.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"
|
||||
|
||||
#include "InterfaceBuilder.h"
|
||||
|
||||
#include "../CGameInfo.h"
|
||||
#include "../gui/CAnimation.h"
|
||||
#include "../gui/CGuiHandler.h"
|
||||
#include "../widgets/CComponent.h"
|
||||
#include "../widgets/Buttons.h"
|
||||
#include "../widgets/MiscWidgets.h"
|
||||
#include "../widgets/ObjectLists.h"
|
||||
#include "../widgets/TextControls.h"
|
||||
#include "../windows/GUIClasses.h"
|
||||
#include "../windows/InfoWindows.h"
|
||||
|
||||
#include "../../lib/CGeneralTextHandler.h"
|
||||
|
||||
|
||||
InterfaceBuilder::InterfaceBuilder(const JsonNode & config):
|
||||
CIntObject()
|
||||
{
|
||||
init(config);
|
||||
}
|
||||
|
||||
InterfaceBuilder::InterfaceBuilder():
|
||||
CIntObject()
|
||||
{
|
||||
}
|
||||
|
||||
void InterfaceBuilder::addCallback(const std::string & callbackName, std::function<void(int)> callback)
|
||||
{
|
||||
callbacks[callbackName] = callback;
|
||||
}
|
||||
|
||||
const std::shared_ptr<CIntObject> InterfaceBuilder::widget(const std::string & name) const
|
||||
{
|
||||
return widgets.at(name);
|
||||
}
|
||||
|
||||
void InterfaceBuilder::init(const JsonNode &config)
|
||||
{
|
||||
OBJ_CONSTRUCTION;
|
||||
int unnamedObjectId = 0;
|
||||
const std::string unnamedObjectPrefix = "__widget_";
|
||||
|
||||
for(const auto & item : config["items"].Vector())
|
||||
{
|
||||
std::string name = item["name"].isNull()
|
||||
? unnamedObjectPrefix + std::to_string(unnamedObjectId++)
|
||||
: item["name"].String();
|
||||
widgets[name] = buildWidget(item);
|
||||
}
|
||||
}
|
||||
|
||||
std::string InterfaceBuilder::buildText(const JsonNode & config) const
|
||||
{
|
||||
if(config.isNull())
|
||||
return "";
|
||||
|
||||
if(config.isNumber())
|
||||
{
|
||||
return CGI->generaltexth->allTexts[config.Integer()];
|
||||
}
|
||||
return config.String();
|
||||
}
|
||||
|
||||
std::shared_ptr<CIntObject> InterfaceBuilder::buildWidget(const JsonNode & config)
|
||||
{
|
||||
assert(!config.isNull());
|
||||
auto type = config["type"].String();
|
||||
|
||||
int x = 0, y = 0;
|
||||
if(!config["position"].isNull())
|
||||
{
|
||||
x = config["position"]["x"].Integer();
|
||||
y = config["position"]["y"].Integer();
|
||||
}
|
||||
|
||||
std::string image, text = buildText(config["text"]);
|
||||
auto alignment = EAlignment::CENTER;
|
||||
auto color = Colors::DEFAULT_KEY_COLOR;
|
||||
auto font = EFonts::FONT_TIMES;
|
||||
|
||||
if(!config["image"].isNull())
|
||||
image = config["image"].String();
|
||||
if(!config["alignment"].isNull())
|
||||
{
|
||||
if(config["alignment"].String() == "left")
|
||||
alignment = EAlignment::TOPLEFT;
|
||||
if(config["alignment"].String() == "center")
|
||||
alignment = EAlignment::CENTER;
|
||||
if(config["alignment"].String() == "right")
|
||||
alignment = EAlignment::BOTTOMRIGHT;
|
||||
}
|
||||
if(!config["color"].isNull())
|
||||
{
|
||||
if(config["color"].String() == "yellow")
|
||||
color = Colors::YELLOW;
|
||||
if(config["color"].String() == "white")
|
||||
color = Colors::WHITE;
|
||||
if(config["color"].String() == "gold")
|
||||
color = Colors::METALLIC_GOLD;
|
||||
if(config["color"].String() == "green")
|
||||
color = Colors::GREEN;
|
||||
if(config["color"].String() == "orange")
|
||||
color = Colors::ORANGE;
|
||||
if(config["color"].String() == "bright-yellow")
|
||||
color = Colors::BRIGHT_YELLOW;
|
||||
}
|
||||
if(!config["font"].isNull())
|
||||
{
|
||||
if(config["font"].String() == "big")
|
||||
font = EFonts::FONT_BIG;
|
||||
if(config["font"].String() == "medium")
|
||||
font = EFonts::FONT_MEDIUM;
|
||||
if(config["font"].String() == "small")
|
||||
font = EFonts::FONT_SMALL;
|
||||
if(config["font"].String() == "tiny")
|
||||
font = EFonts::FONT_TINY;
|
||||
}
|
||||
|
||||
|
||||
if(type == "picture")
|
||||
{
|
||||
return std::make_shared<CPicture>(image, x, y);
|
||||
}
|
||||
if(type == "label")
|
||||
{
|
||||
return std::make_shared<CLabel>(x, y, font, alignment, color, text);
|
||||
}
|
||||
if(type == "toggleGroup")
|
||||
{
|
||||
auto group = std::make_shared<CToggleGroup>(0);
|
||||
group->pos.x += x;
|
||||
group->pos.y += y;
|
||||
if(!config["items"].isNull())
|
||||
{
|
||||
SObjectConstruction obj__i(group.get());
|
||||
int itemIdx = -1;
|
||||
for(const auto & item : config["items"].Vector())
|
||||
{
|
||||
itemIdx = item["index"].isNull() ? itemIdx + 1 : item["index"].Integer();
|
||||
group->addToggle(itemIdx, std::dynamic_pointer_cast<CToggleBase>(buildWidget(item)));
|
||||
}
|
||||
}
|
||||
if(!config["selected"].isNull())
|
||||
group->setSelected(config["selected"].Integer());
|
||||
if(!config["callback"].isNull())
|
||||
group->addCallback(callbacks[config["callback"].String()]);
|
||||
return group;
|
||||
}
|
||||
if(type == "toggleButton")
|
||||
{
|
||||
std::pair<std::string, std::string> zelp;
|
||||
if(!config["zelp"].isNull())
|
||||
zelp = CGI->generaltexth->zelp[config["zelp"].Integer()];
|
||||
auto button = std::make_shared<CToggleButton>(Point(x, y), image, zelp);
|
||||
if(!config["selected"].isNull())
|
||||
button->setSelected(config["selected"].Bool());
|
||||
if(!config["imageOrder"].isNull())
|
||||
{
|
||||
auto imgOrder = config["imageOrder"].Vector();
|
||||
assert(imgOrder.size() >= 4);
|
||||
button->setImageOrder(imgOrder[0].Integer(), imgOrder[1].Integer(), imgOrder[2].Integer(), imgOrder[3].Integer());
|
||||
}
|
||||
if(!config["callback"].isNull())
|
||||
button->addCallback(callbacks[config["callback"].String()]);
|
||||
return button;
|
||||
}
|
||||
if(type == "button")
|
||||
{
|
||||
std::pair<std::string, std::string> zelp;
|
||||
if(!config["zelp"].isNull())
|
||||
zelp = CGI->generaltexth->zelp[config["zelp"].Integer()];
|
||||
auto button = std::make_shared<CButton>(Point(x, y), image, zelp);
|
||||
return button;
|
||||
}
|
||||
if(type == "labelGroup")
|
||||
{
|
||||
auto group = std::make_shared<CLabelGroup>(font, alignment, color);
|
||||
if(!config["items"].isNull())
|
||||
{
|
||||
for(const auto & item : config["items"].Vector())
|
||||
{
|
||||
if(!item["position"].isNull())
|
||||
{
|
||||
x = item["position"]["x"].Integer();
|
||||
y = item["position"]["y"].Integer();
|
||||
}
|
||||
if(!item["text"].isNull())
|
||||
text = buildText(item["text"]);
|
||||
group->add(x, y, text);
|
||||
}
|
||||
}
|
||||
return group;
|
||||
}
|
||||
return std::shared_ptr<CIntObject>(nullptr);
|
||||
}
|
39
client/gui/InterfaceBuilder.h
Normal file
39
client/gui/InterfaceBuilder.h
Normal file
@ -0,0 +1,39 @@
|
||||
/*
|
||||
* InterfaceBuilder.h, 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
|
||||
*
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CIntObject.h"
|
||||
|
||||
#include "../../lib/JsonNode.h"
|
||||
|
||||
class InterfaceBuilder: public CIntObject
|
||||
{
|
||||
public:
|
||||
InterfaceBuilder();
|
||||
InterfaceBuilder(const JsonNode & config);
|
||||
|
||||
protected:
|
||||
//must be called after adding callbacks
|
||||
void init(const JsonNode & config);
|
||||
|
||||
void addCallback(const std::string & callbackName, std::function<void(int)> callback);
|
||||
|
||||
const std::shared_ptr<CIntObject> widget(const std::string &) const;
|
||||
|
||||
private:
|
||||
|
||||
std::map<std::string, std::shared_ptr<CIntObject>> widgets;
|
||||
std::map<std::string, std::function<void(int)>> callbacks;
|
||||
|
||||
std::shared_ptr<CIntObject> buildWidget(const JsonNode & config);
|
||||
|
||||
std::string buildText(const JsonNode & param) const;
|
||||
};
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* NotificationHandler.cpp, part of VCMI engine
|
||||
* NotificationHandler.h, part of VCMI engine
|
||||
*
|
||||
* Authors: listed in file AUTHORS in main folder
|
||||
*
|
||||
|
@ -27,127 +27,72 @@
|
||||
#include "../../lib/CGeneralTextHandler.h"
|
||||
#include "../../lib/mapping/CMapInfo.h"
|
||||
#include "../../lib/rmg/CMapGenOptions.h"
|
||||
#include "../../lib/CModHandler.h"
|
||||
|
||||
RandomMapTab::RandomMapTab()
|
||||
RandomMapTab::RandomMapTab():
|
||||
InterfaceBuilder()
|
||||
{
|
||||
recActions = 0;
|
||||
mapGenOptions = std::make_shared<CMapGenOptions>();
|
||||
OBJ_CONSTRUCTION;
|
||||
background = std::make_shared<CPicture>("RANMAPBK", 0, 6);
|
||||
|
||||
labelHeadlineBig = std::make_shared<CLabel>(222, 36, FONT_BIG, EAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[738]);
|
||||
labelHeadlineSmall = std::make_shared<CLabel>(222, 56, FONT_SMALL, EAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[739]);
|
||||
|
||||
labelMapSize = std::make_shared<CLabel>(104, 97, FONT_SMALL, EAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[752]);
|
||||
groupMapSize = std::make_shared<CToggleGroup>(0);
|
||||
groupMapSize->pos.y += 81;
|
||||
groupMapSize->pos.x += 158;
|
||||
const std::vector<std::string> mapSizeBtns = {"RANSIZS", "RANSIZM", "RANSIZL", "RANSIZX"};
|
||||
addButtonsToGroup(groupMapSize.get(), mapSizeBtns, 0, 3, 47, 198);
|
||||
groupMapSize->setSelected(1);
|
||||
groupMapSize->addCallback([&](int btnId)
|
||||
|
||||
const JsonNode config(ResourceID("config/windows.json"));
|
||||
addCallback("toggleMapSize", [&](int btnId)
|
||||
{
|
||||
auto mapSizeVal = getPossibleMapSizes();
|
||||
mapGenOptions->setWidth(mapSizeVal[btnId]);
|
||||
mapGenOptions->setHeight(mapSizeVal[btnId]);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
buttonTwoLevels = std::make_shared<CToggleButton>(Point(346, 81), "RANUNDR", CGI->generaltexth->zelp[202]);
|
||||
buttonTwoLevels->setSelected(true);
|
||||
buttonTwoLevels->addCallback([&](bool on)
|
||||
addCallback("toggleTwoLevels", [&](bool on)
|
||||
{
|
||||
mapGenOptions->setHasTwoLevels(on);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
labelGroupForOptions = std::make_shared<CLabelGroup>(FONT_SMALL, EAlignment::TOPLEFT, Colors::WHITE);
|
||||
// Create number defs list
|
||||
std::vector<std::string> numberDefs;
|
||||
for(int i = 0; i <= 8; ++i)
|
||||
{
|
||||
numberDefs.push_back("RANNUM" + boost::lexical_cast<std::string>(i));
|
||||
}
|
||||
|
||||
const int NUMBERS_WIDTH = 32;
|
||||
const int BTNS_GROUP_LEFT_MARGIN = 67;
|
||||
labelGroupForOptions->add(68, 133, CGI->generaltexth->allTexts[753]);
|
||||
groupMaxPlayers = std::make_shared<CToggleGroup>(0);
|
||||
groupMaxPlayers->pos.y += 153;
|
||||
groupMaxPlayers->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||
addButtonsWithRandToGroup(groupMaxPlayers.get(), numberDefs, 1, 8, NUMBERS_WIDTH, 204, 212);
|
||||
groupMaxPlayers->addCallback([&](int btnId)
|
||||
|
||||
addCallback("setPlayersCount", [&](int btnId)
|
||||
{
|
||||
mapGenOptions->setPlayerCount(btnId);
|
||||
deactivateButtonsFrom(groupMaxTeams.get(), btnId);
|
||||
|
||||
deactivateButtonsFrom(dynamic_pointer_cast<CToggleGroup>(widget("groupMaxTeams")).get(), btnId);
|
||||
|
||||
// deactive some CompOnlyPlayers buttons to prevent total number of players exceeds PlayerColor::PLAYER_LIMIT_I
|
||||
deactivateButtonsFrom(groupCompOnlyPlayers.get(), PlayerColor::PLAYER_LIMIT_I - btnId + 1);
|
||||
deactivateButtonsFrom(dynamic_pointer_cast<CToggleGroup>(widget("groupCompOnlyPlayers")).get(), PlayerColor::PLAYER_LIMIT_I - btnId + 1);
|
||||
|
||||
validatePlayersCnt(btnId);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
labelGroupForOptions->add(68, 199, CGI->generaltexth->allTexts[754]);
|
||||
groupMaxTeams = std::make_shared<CToggleGroup>(0);
|
||||
groupMaxTeams->pos.y += 219;
|
||||
groupMaxTeams->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||
addButtonsWithRandToGroup(groupMaxTeams.get(), numberDefs, 0, 7, NUMBERS_WIDTH, 214, 222);
|
||||
groupMaxTeams->addCallback([&](int btnId)
|
||||
|
||||
addCallback("setTeamsCount", [&](int btnId)
|
||||
{
|
||||
mapGenOptions->setTeamCount(btnId);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
labelGroupForOptions->add(68, 265, CGI->generaltexth->allTexts[755]);
|
||||
groupCompOnlyPlayers = std::make_shared<CToggleGroup>(0);
|
||||
groupCompOnlyPlayers->pos.y += 285;
|
||||
groupCompOnlyPlayers->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||
addButtonsWithRandToGroup(groupCompOnlyPlayers.get(), numberDefs, 0, 7, NUMBERS_WIDTH, 224, 232);
|
||||
groupCompOnlyPlayers->addCallback([&](int btnId)
|
||||
|
||||
addCallback("setCompOnlyPlayers", [&](int btnId)
|
||||
{
|
||||
mapGenOptions->setCompOnlyPlayerCount(btnId);
|
||||
|
||||
|
||||
// deactive some MaxPlayers buttons to prevent total number of players exceeds PlayerColor::PLAYER_LIMIT_I
|
||||
deactivateButtonsFrom(groupMaxPlayers.get(), PlayerColor::PLAYER_LIMIT_I - btnId + 1);
|
||||
deactivateButtonsFrom(dynamic_pointer_cast<CToggleGroup>(widget("groupMaxPlayers")).get(), PlayerColor::PLAYER_LIMIT_I - btnId + 1);
|
||||
|
||||
deactivateButtonsFrom(groupCompOnlyTeams.get(), (btnId == 0 ? 1 : btnId));
|
||||
deactivateButtonsFrom(dynamic_pointer_cast<CToggleGroup>(widget("groupCompOnlyTeams")).get(), (btnId == 0 ? 1 : btnId));
|
||||
validateCompOnlyPlayersCnt(btnId);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
labelGroupForOptions->add(68, 331, CGI->generaltexth->allTexts[756]);
|
||||
groupCompOnlyTeams = std::make_shared<CToggleGroup>(0);
|
||||
groupCompOnlyTeams->pos.y += 351;
|
||||
groupCompOnlyTeams->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||
addButtonsWithRandToGroup(groupCompOnlyTeams.get(), numberDefs, 0, 6, NUMBERS_WIDTH, 234, 241);
|
||||
deactivateButtonsFrom(groupCompOnlyTeams.get(), 1);
|
||||
groupCompOnlyTeams->addCallback([&](int btnId)
|
||||
|
||||
addCallback("setCompOnlyTeams", [&](int btnId)
|
||||
{
|
||||
mapGenOptions->setCompOnlyTeamCount(btnId);
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
labelGroupForOptions->add(68, 398, CGI->generaltexth->allTexts[757]);
|
||||
const int WIDE_BTN_WIDTH = 85;
|
||||
groupWaterContent = std::make_shared<CToggleGroup>(0);
|
||||
groupWaterContent->pos.y += 419;
|
||||
groupWaterContent->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||
const std::vector<std::string> waterContentBtns = {"RANNONE", "RANNORM", "RANISLD"};
|
||||
addButtonsWithRandToGroup(groupWaterContent.get(), waterContentBtns, 0, 2, WIDE_BTN_WIDTH, 243, 246);
|
||||
groupWaterContent->addCallback([&](int btnId)
|
||||
|
||||
addCallback("setWaterContent", [&](int btnId)
|
||||
{
|
||||
mapGenOptions->setWaterContent(static_cast<EWaterContent::EWaterContent>(btnId));
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
labelGroupForOptions->add(68, 465, CGI->generaltexth->allTexts[758]);
|
||||
groupMonsterStrength = std::make_shared<CToggleGroup>(0);
|
||||
groupMonsterStrength->pos.y += 485;
|
||||
groupMonsterStrength->pos.x += BTNS_GROUP_LEFT_MARGIN;
|
||||
const std::vector<std::string> monsterStrengthBtns = {"RANWEAK", "RANNORM", "RANSTRG"};
|
||||
addButtonsWithRandToGroup(groupMonsterStrength.get(), monsterStrengthBtns, 2, 4, WIDE_BTN_WIDTH, 248, 251, EMonsterStrength::RANDOM, false);
|
||||
groupMonsterStrength->addCallback([&](int btnId)
|
||||
|
||||
addCallback("setMonsterStrenght", [&](int btnId)
|
||||
{
|
||||
if(btnId < 0)
|
||||
mapGenOptions->setMonsterStrength(EMonsterStrength::RANDOM);
|
||||
@ -155,9 +100,9 @@ RandomMapTab::RandomMapTab()
|
||||
mapGenOptions->setMonsterStrength(static_cast<EMonsterStrength::EMonsterStrength>(btnId)); //value 2 to 4
|
||||
updateMapInfoByHost();
|
||||
});
|
||||
|
||||
buttonShowRandomMaps = std::make_shared<CButton>(Point(54, 535), "RANSHOW", CGI->generaltexth->zelp[252]);
|
||||
|
||||
|
||||
init(config["randomMapTab"]);
|
||||
|
||||
updateMapInfoByHost();
|
||||
}
|
||||
|
||||
@ -216,39 +161,14 @@ void RandomMapTab::updateMapInfoByHost()
|
||||
|
||||
void RandomMapTab::setMapGenOptions(std::shared_ptr<CMapGenOptions> opts)
|
||||
{
|
||||
groupMapSize->setSelected(vstd::find_pos(getPossibleMapSizes(), opts->getWidth()));
|
||||
buttonTwoLevels->setSelected(opts->getHasTwoLevels());
|
||||
groupMaxPlayers->setSelected(opts->getPlayerCount());
|
||||
groupMaxTeams->setSelected(opts->getTeamCount());
|
||||
groupCompOnlyPlayers->setSelected(opts->getCompOnlyPlayerCount());
|
||||
groupCompOnlyTeams->setSelected(opts->getCompOnlyTeamCount());
|
||||
groupWaterContent->setSelected(opts->getWaterContent());
|
||||
groupMonsterStrength->setSelected(opts->getMonsterStrength());
|
||||
}
|
||||
|
||||
void RandomMapTab::addButtonsWithRandToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int nStart, int nEnd, int btnWidth, int helpStartIndex, int helpRandIndex, int randIndex, bool animIdfromBtnId) const
|
||||
{
|
||||
addButtonsToGroup(group, defs, nStart, nEnd, btnWidth, helpStartIndex, animIdfromBtnId);
|
||||
|
||||
// Buttons are relative to button group, TODO better solution?
|
||||
SObjectConstruction obj__i(group);
|
||||
const std::string RANDOM_DEF = "RANRAND";
|
||||
group->addToggle(randIndex, std::make_shared<CToggleButton>(Point(256, 0), RANDOM_DEF, CGI->generaltexth->zelp[helpRandIndex]));
|
||||
group->setSelected(randIndex);
|
||||
}
|
||||
|
||||
void RandomMapTab::addButtonsToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int nStart, int nEnd, int btnWidth, int helpStartIndex, bool animIdfromBtnId) const
|
||||
{
|
||||
// Buttons are relative to button group, TODO better solution?
|
||||
SObjectConstruction obj__i(group);
|
||||
int cnt = nEnd - nStart + 1;
|
||||
for(int i = 0; i < cnt; ++i)
|
||||
{
|
||||
auto button = std::make_shared<CToggleButton>(Point(i * btnWidth, 0), animIdfromBtnId ? defs[i + nStart] : defs[i], CGI->generaltexth->zelp[helpStartIndex + i]);
|
||||
// For blocked state we should use pressed image actually
|
||||
button->setImageOrder(0, 1, 1, 3);
|
||||
group->addToggle(i + nStart, button);
|
||||
}
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupMapSize"))->setSelected(vstd::find_pos(getPossibleMapSizes(), opts->getWidth()));
|
||||
dynamic_pointer_cast<CToggleButton>(widget("buttonTwoLevels"))->setSelected(opts->getHasTwoLevels());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupMaxPlayers"))->setSelected(opts->getPlayerCount());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupMaxTeams"))->setSelected(opts->getTeamCount());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupCompOnlyPlayers"))->setSelected(opts->getCompOnlyPlayerCount());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupCompOnlyTeams"))->setSelected(opts->getCompOnlyTeamCount());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupWaterContent"))->setSelected(opts->getWaterContent());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupMonsterStrength"))->setSelected(opts->getMonsterStrength());
|
||||
}
|
||||
|
||||
void RandomMapTab::deactivateButtonsFrom(CToggleGroup * group, int startId)
|
||||
@ -280,13 +200,13 @@ void RandomMapTab::validatePlayersCnt(int playersCnt)
|
||||
if(mapGenOptions->getTeamCount() >= playersCnt)
|
||||
{
|
||||
mapGenOptions->setTeamCount(playersCnt - 1);
|
||||
groupMaxTeams->setSelected(mapGenOptions->getTeamCount());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupMaxTeams"))->setSelected(mapGenOptions->getTeamCount());
|
||||
}
|
||||
// total players should not exceed PlayerColor::PLAYER_LIMIT_I (8 in homm3)
|
||||
if(mapGenOptions->getCompOnlyPlayerCount() + playersCnt > PlayerColor::PLAYER_LIMIT_I)
|
||||
{
|
||||
mapGenOptions->setCompOnlyPlayerCount(PlayerColor::PLAYER_LIMIT_I - playersCnt);
|
||||
groupCompOnlyPlayers->setSelected(mapGenOptions->getCompOnlyPlayerCount());
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupCompOnlyPlayers"))->setSelected(mapGenOptions->getCompOnlyPlayerCount());
|
||||
}
|
||||
|
||||
validateCompOnlyPlayersCnt(mapGenOptions->getCompOnlyPlayerCount());
|
||||
@ -304,7 +224,7 @@ void RandomMapTab::validateCompOnlyPlayersCnt(int compOnlyPlayersCnt)
|
||||
int compOnlyTeamCount = compOnlyPlayersCnt == 0 ? 0 : compOnlyPlayersCnt - 1;
|
||||
mapGenOptions->setCompOnlyTeamCount(compOnlyTeamCount);
|
||||
updateMapInfoByHost();
|
||||
groupCompOnlyTeams->setSelected(compOnlyTeamCount);
|
||||
dynamic_pointer_cast<CToggleGroup>(widget("groupCompOnlyTeams"))->setSelected(compOnlyTeamCount);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -13,6 +13,7 @@
|
||||
|
||||
#include "../../lib/FunctionList.h"
|
||||
#include "../../lib/GameConstants.h"
|
||||
#include "../gui/InterfaceBuilder.h"
|
||||
|
||||
VCMI_LIB_NAMESPACE_BEGIN
|
||||
|
||||
@ -24,7 +25,7 @@ class CToggleButton;
|
||||
class CLabel;
|
||||
class CLabelGroup;
|
||||
|
||||
class RandomMapTab : public CIntObject
|
||||
class RandomMapTab : public InterfaceBuilder
|
||||
{
|
||||
public:
|
||||
RandomMapTab();
|
||||
@ -35,30 +36,11 @@ public:
|
||||
CFunctionList<void(std::shared_ptr<CMapInfo>, std::shared_ptr<CMapGenOptions>)> mapInfoChanged;
|
||||
|
||||
private:
|
||||
void addButtonsWithRandToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex, int helpRandIndex, int randIndex = -1, bool animIdfromBtnId = true) const;
|
||||
void addButtonsToGroup(CToggleGroup * group, const std::vector<std::string> & defs, int startIndex, int endIndex, int btnWidth, int helpStartIndex, bool animIdfromBtnId = true) const;
|
||||
void deactivateButtonsFrom(CToggleGroup * group, int startId);
|
||||
void validatePlayersCnt(int playersCnt);
|
||||
void validateCompOnlyPlayersCnt(int compOnlyPlayersCnt);
|
||||
std::vector<int> getPossibleMapSizes();
|
||||
|
||||
|
||||
std::shared_ptr<CPicture> background;
|
||||
std::shared_ptr<CLabel> labelHeadlineBig;
|
||||
std::shared_ptr<CLabel> labelHeadlineSmall;
|
||||
|
||||
std::shared_ptr<CLabel> labelMapSize;
|
||||
std::shared_ptr<CToggleGroup> groupMapSize;
|
||||
std::shared_ptr<CToggleButton> buttonTwoLevels;
|
||||
|
||||
std::shared_ptr<CLabelGroup> labelGroupForOptions;
|
||||
std::shared_ptr<CToggleGroup> groupMaxPlayers;
|
||||
std::shared_ptr<CToggleGroup> groupMaxTeams;
|
||||
std::shared_ptr<CToggleGroup> groupCompOnlyPlayers;
|
||||
std::shared_ptr<CToggleGroup> groupCompOnlyTeams;
|
||||
std::shared_ptr<CToggleGroup> groupWaterContent;
|
||||
std::shared_ptr<CToggleGroup> groupMonsterStrength;
|
||||
std::shared_ptr<CButton> buttonShowRandomMaps;
|
||||
std::shared_ptr<CMapGenOptions> mapGenOptions;
|
||||
std::shared_ptr<CMapInfo> mapInfo;
|
||||
};
|
||||
|
513
config/windows.json
Normal file
513
config/windows.json
Normal file
@ -0,0 +1,513 @@
|
||||
{
|
||||
"randomMapTab":
|
||||
{
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"name": "background",
|
||||
"type": "picture",
|
||||
"image": "RANMAPBK",
|
||||
"position": {"x": 0, "y": 6}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "labelHeadlineBig",
|
||||
"type": "label",
|
||||
"font": "big",
|
||||
"alignment": "center",
|
||||
"color": "yellow",
|
||||
"text": 738,
|
||||
"position": {"x": 222, "y": 36}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "labelHeadlineSmall",
|
||||
"type": "label",
|
||||
"font": "small",
|
||||
"alignment": "center",
|
||||
"color": "white",
|
||||
"text": 739,
|
||||
"position": {"x": 222, "y": 56}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "labelMapSize",
|
||||
"type": "label",
|
||||
"font": "small",
|
||||
"alignment": "center",
|
||||
"color": "white",
|
||||
"text": 752,
|
||||
"position": {"x": 104, "y": 97}
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupMapSize",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 158, "y": 81},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 0,
|
||||
"type": "toggleButton",
|
||||
"image": "RANSIZS",
|
||||
"zelp": 198,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0},
|
||||
},
|
||||
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANSIZM",
|
||||
"zelp": 199,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 47, "y": 0},
|
||||
},
|
||||
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANSIZL",
|
||||
"zelp": 200,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 94, "y": 0},
|
||||
},
|
||||
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANSIZX",
|
||||
"zelp": 201,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 141, "y": 0}
|
||||
}
|
||||
],
|
||||
"selected": 1,
|
||||
"callback": "toggleMapSize"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "buttonTwoLevels",
|
||||
"type": "toggleButton",
|
||||
"image": "RANUNDR",
|
||||
"position": {"x": 346, "y": 81},
|
||||
"selected": true,
|
||||
"callback": "toggleTwoLevels"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupMaxPlayers",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 67, "y": 153},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 1,
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM1",
|
||||
"zelp": 204,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM2",
|
||||
"zelp": 205,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 32, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM3",
|
||||
"zelp": 206,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 64, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM4",
|
||||
"zelp": 207,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 96, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM5",
|
||||
"zelp": 208,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 128, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM6",
|
||||
"zelp": 209,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 160, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM7",
|
||||
"zelp": 210,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 192, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM8",
|
||||
"zelp": 211,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 224, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": -1,
|
||||
"type": "toggleButton",
|
||||
"image": "RANRAND",
|
||||
"zelp": 212,
|
||||
"position": {"x": 256, "y": 0},
|
||||
}
|
||||
],
|
||||
"selected": 7,
|
||||
"callback": "setPlayersCount"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupMaxTeams",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 67, "y": 219},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 0,
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM0",
|
||||
"zelp": 214,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM1",
|
||||
"zelp": 215,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 32, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM2",
|
||||
"zelp": 216,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 64, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM3",
|
||||
"zelp": 217,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 96, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM4",
|
||||
"zelp": 218,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 128, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM5",
|
||||
"zelp": 219,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 160, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM6",
|
||||
"zelp": 220,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 192, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM7",
|
||||
"zelp": 221,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 224, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": -1,
|
||||
"type": "toggleButton",
|
||||
"image": "RANRAND",
|
||||
"zelp": 222,
|
||||
"position": {"x": 256, "y": 0},
|
||||
}
|
||||
],
|
||||
"selected": 7,
|
||||
"callback": "setTeamsCount"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupCompOnlyPlayers",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 67, "y": 285},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 0,
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM0",
|
||||
"zelp": 224,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM1",
|
||||
"zelp": 225,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 32, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM2",
|
||||
"zelp": 226,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 64, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM3",
|
||||
"zelp": 227,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 96, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM4",
|
||||
"zelp": 228,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 128, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM5",
|
||||
"zelp": 229,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 160, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM6",
|
||||
"zelp": 230,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 192, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM7",
|
||||
"zelp": 231,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 224, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": -1,
|
||||
"type": "toggleButton",
|
||||
"image": "RANRAND",
|
||||
"zelp": 232,
|
||||
"position": {"x": 256, "y": 0},
|
||||
}
|
||||
],
|
||||
"selected": 7,
|
||||
"callback": "setCompOnlyPlayers"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupCompOnlyTeams",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 67, "y": 351},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 0,
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM0",
|
||||
"zelp": 234,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM1",
|
||||
"zelp": 235,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 32, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM2",
|
||||
"zelp": 236,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 64, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM3",
|
||||
"zelp": 237,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 96, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM4",
|
||||
"zelp": 238,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 128, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM5",
|
||||
"zelp": 239,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 160, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNUM6",
|
||||
"zelp": 240,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 192, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": -1,
|
||||
"type": "toggleButton",
|
||||
"image": "RANRAND",
|
||||
"zelp": 241,
|
||||
"position": {"x": 256, "y": 0},
|
||||
}
|
||||
],
|
||||
"selected": 7,
|
||||
"callback": "setCompOnlyTeams"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupWaterContent",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 67, "y": 419},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 0,
|
||||
"type": "toggleButton",
|
||||
"image": "RANNONE",
|
||||
"zelp": 243,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANNORM",
|
||||
"zelp": 244,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 85, "y": 0}
|
||||
},
|
||||
{
|
||||
"type": "toggleButton",
|
||||
"image": "RANISLD",
|
||||
"zelp": 245,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 170, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": -1,
|
||||
"type": "toggleButton",
|
||||
"image": "RANRAND",
|
||||
"zelp": 246,
|
||||
"position": {"x": 256, "y": 0},
|
||||
}
|
||||
],
|
||||
"selected": 3,
|
||||
"callback": "setWaterContent"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "groupMonsterStrength",
|
||||
"type": "toggleGroup",
|
||||
"position": {"x": 67, "y": 485},
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"index": 2,
|
||||
"type": "toggleButton",
|
||||
"image": "RANWEAK",
|
||||
"zelp": 248,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 0, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": 3,
|
||||
"type": "toggleButton",
|
||||
"image": "RANNORM",
|
||||
"zelp": 249,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 85, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": 4,
|
||||
"type": "toggleButton",
|
||||
"image": "RANSTRG",
|
||||
"zelp": 250,
|
||||
"imageOrder": [0, 1, 1, 3],
|
||||
"position": {"x": 170, "y": 0}
|
||||
},
|
||||
{
|
||||
"index": -2,
|
||||
"type": "toggleButton",
|
||||
"image": "RANRAND",
|
||||
"zelp": 251,
|
||||
"position": {"x": 256, "y": 0},
|
||||
}
|
||||
],
|
||||
"selected": 3,
|
||||
"callback": "setMonsterStrenght"
|
||||
},
|
||||
|
||||
{
|
||||
"name": "buttonShowRandomMaps",
|
||||
"type": "button",
|
||||
"position": {"x": 54, "y": 535},
|
||||
"image": "RANSHOW",
|
||||
"zelp": 252
|
||||
},
|
||||
|
||||
{
|
||||
"type": "labelGroup",
|
||||
"font": "small",
|
||||
"alignment": "left",
|
||||
"color": "white",
|
||||
"items":
|
||||
[
|
||||
{
|
||||
"position": {"x": 68, "y": 133},
|
||||
"text": 753
|
||||
},
|
||||
{
|
||||
"position": {"x": 68, "y": 199},
|
||||
"text": 754
|
||||
},
|
||||
{
|
||||
"position": {"x": 68, "y": 265},
|
||||
"text": 755
|
||||
},
|
||||
{
|
||||
"position": {"x": 68, "y": 331},
|
||||
"text": 756
|
||||
},
|
||||
{
|
||||
"position": {"x": 68, "y": 398},
|
||||
"text": 757
|
||||
},
|
||||
{
|
||||
"position": {"x": 68, "y": 465},
|
||||
"text": 758
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user