mirror of
https://github.com/vcmi/vcmi.git
synced 2025-11-23 22:37:55 +02:00
Make options tab configurable
This commit is contained in:
@@ -17,6 +17,8 @@
|
|||||||
#include "../gui/CGuiHandler.h"
|
#include "../gui/CGuiHandler.h"
|
||||||
#include "../gui/ShortcutHandler.h"
|
#include "../gui/ShortcutHandler.h"
|
||||||
#include "../gui/Shortcut.h"
|
#include "../gui/Shortcut.h"
|
||||||
|
#include "../render/Graphics.h"
|
||||||
|
#include "../render/IFont.h"
|
||||||
#include "../widgets/CComponent.h"
|
#include "../widgets/CComponent.h"
|
||||||
#include "../widgets/Buttons.h"
|
#include "../widgets/Buttons.h"
|
||||||
#include "../widgets/MiscWidgets.h"
|
#include "../widgets/MiscWidgets.h"
|
||||||
@@ -43,6 +45,7 @@ InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset)
|
|||||||
REGISTER_BUILDER("texture", &InterfaceObjectConfigurable::buildTexture);
|
REGISTER_BUILDER("texture", &InterfaceObjectConfigurable::buildTexture);
|
||||||
REGISTER_BUILDER("animation", &InterfaceObjectConfigurable::buildAnimation);
|
REGISTER_BUILDER("animation", &InterfaceObjectConfigurable::buildAnimation);
|
||||||
REGISTER_BUILDER("label", &InterfaceObjectConfigurable::buildLabel);
|
REGISTER_BUILDER("label", &InterfaceObjectConfigurable::buildLabel);
|
||||||
|
REGISTER_BUILDER("multiLineLabel", &InterfaceObjectConfigurable::buildMultiLineLabel);
|
||||||
REGISTER_BUILDER("toggleGroup", &InterfaceObjectConfigurable::buildToggleGroup);
|
REGISTER_BUILDER("toggleGroup", &InterfaceObjectConfigurable::buildToggleGroup);
|
||||||
REGISTER_BUILDER("toggleButton", &InterfaceObjectConfigurable::buildToggleButton);
|
REGISTER_BUILDER("toggleButton", &InterfaceObjectConfigurable::buildToggleButton);
|
||||||
REGISTER_BUILDER("button", &InterfaceObjectConfigurable::buildButton);
|
REGISTER_BUILDER("button", &InterfaceObjectConfigurable::buildButton);
|
||||||
@@ -301,6 +304,20 @@ std::shared_ptr<CLabel> InterfaceObjectConfigurable::buildLabel(const JsonNode &
|
|||||||
return std::make_shared<CLabel>(position.x, position.y, font, alignment, color, text);
|
return std::make_shared<CLabel>(position.x, position.y, font, alignment, color, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::shared_ptr<CMultiLineLabel> InterfaceObjectConfigurable::buildMultiLineLabel(const JsonNode & config) const
|
||||||
|
{
|
||||||
|
logGlobal->debug("Building widget CMultiLineLabel");
|
||||||
|
auto font = readFont(config["font"]);
|
||||||
|
auto alignment = readTextAlignment(config["alignment"]);
|
||||||
|
auto color = readColor(config["color"]);
|
||||||
|
auto text = readText(config["text"]);
|
||||||
|
Rect rect = readRect(config["rect"]);
|
||||||
|
if(!config["adoptHeight"].isNull() && config["adoptHeight"].Bool())
|
||||||
|
rect.h = graphics->fonts[font]->getLineHeight() * 2;
|
||||||
|
return std::make_shared<CMultiLineLabel>(rect, font, alignment, color, text);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
std::shared_ptr<CToggleGroup> InterfaceObjectConfigurable::buildToggleGroup(const JsonNode & config) const
|
std::shared_ptr<CToggleGroup> InterfaceObjectConfigurable::buildToggleGroup(const JsonNode & config) const
|
||||||
{
|
{
|
||||||
logGlobal->debug("Building widget CToggleGroup");
|
logGlobal->debug("Building widget CToggleGroup");
|
||||||
@@ -466,11 +483,14 @@ std::shared_ptr<CSlider> InterfaceObjectConfigurable::buildSlider(const JsonNode
|
|||||||
const auto & result =
|
const auto & result =
|
||||||
std::make_shared<CSlider>(position, length, callbacks.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal ? Orientation::HORIZONTAL : Orientation::VERTICAL, style);
|
std::make_shared<CSlider>(position, length, callbacks.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal ? Orientation::HORIZONTAL : Orientation::VERTICAL, style);
|
||||||
|
|
||||||
if (!config["scrollBounds"].isNull())
|
if(!config["scrollBounds"].isNull())
|
||||||
{
|
{
|
||||||
Rect bounds = readRect(config["scrollBounds"]);
|
Rect bounds = readRect(config["scrollBounds"]);
|
||||||
result->setScrollBounds(bounds);
|
result->setScrollBounds(bounds);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!config["panningStep"].isNull())
|
||||||
|
result->setPanningStep(config["panningStep"].Integer());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -18,6 +18,7 @@
|
|||||||
|
|
||||||
class CPicture;
|
class CPicture;
|
||||||
class CLabel;
|
class CLabel;
|
||||||
|
class CMultiLineLabel;
|
||||||
class CToggleGroup;
|
class CToggleGroup;
|
||||||
class CToggleButton;
|
class CToggleButton;
|
||||||
class CButton;
|
class CButton;
|
||||||
@@ -88,6 +89,7 @@ protected:
|
|||||||
//basic widgets
|
//basic widgets
|
||||||
std::shared_ptr<CPicture> buildPicture(const JsonNode &) const;
|
std::shared_ptr<CPicture> buildPicture(const JsonNode &) const;
|
||||||
std::shared_ptr<CLabel> buildLabel(const JsonNode &) const;
|
std::shared_ptr<CLabel> buildLabel(const JsonNode &) const;
|
||||||
|
std::shared_ptr<CMultiLineLabel> buildMultiLineLabel(const JsonNode &) const;
|
||||||
std::shared_ptr<CToggleGroup> buildToggleGroup(const JsonNode &) const;
|
std::shared_ptr<CToggleGroup> buildToggleGroup(const JsonNode &) const;
|
||||||
std::shared_ptr<CToggleButton> buildToggleButton(const JsonNode &) const;
|
std::shared_ptr<CToggleButton> buildToggleButton(const JsonNode &) const;
|
||||||
std::shared_ptr<CButton> buildButton(const JsonNode &) const;
|
std::shared_ptr<CButton> buildButton(const JsonNode &) const;
|
||||||
|
|||||||
@@ -31,6 +31,7 @@
|
|||||||
#include "../windows/InfoWindows.h"
|
#include "../windows/InfoWindows.h"
|
||||||
#include "../eventsSDL/InputHandler.h"
|
#include "../eventsSDL/InputHandler.h"
|
||||||
|
|
||||||
|
#include "../../lib/filesystem/Filesystem.h"
|
||||||
#include "../../lib/NetPacksLobby.h"
|
#include "../../lib/NetPacksLobby.h"
|
||||||
#include "../../lib/CGeneralTextHandler.h"
|
#include "../../lib/CGeneralTextHandler.h"
|
||||||
#include "../../lib/CArtHandler.h"
|
#include "../../lib/CArtHandler.h"
|
||||||
@@ -42,23 +43,20 @@
|
|||||||
OptionsTab::OptionsTab() : humanPlayers(0)
|
OptionsTab::OptionsTab() : humanPlayers(0)
|
||||||
{
|
{
|
||||||
recActions = 0;
|
recActions = 0;
|
||||||
OBJ_CONSTRUCTION;
|
|
||||||
background = std::make_shared<CPicture>("ADVOPTBK", 0, 6);
|
addCallback("setTurnLength", std::bind(&IServerAPI::setTurnLength, CSH, _1));
|
||||||
pos = background->pos;
|
|
||||||
labelTitle = std::make_shared<CLabel>(222, 30, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[515]);
|
const JsonNode config(ResourceID("config/widgets/optionsTab.json"));
|
||||||
labelSubTitle = std::make_shared<CMultiLineLabel>(Rect(60, 44, 320, (int)graphics->fonts[EFonts::FONT_SMALL]->getLineHeight()*2), EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE, CGI->generaltexth->allTexts[516]);
|
build(config);
|
||||||
|
|
||||||
labelPlayerNameAndHandicap = std::make_shared<CMultiLineLabel>(Rect(58, 86, 100, (int)graphics->fonts[EFonts::FONT_SMALL]->getLineHeight()*2), EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[517]);
|
|
||||||
labelStartingTown = std::make_shared<CMultiLineLabel>(Rect(163, 86, 70, (int)graphics->fonts[EFonts::FONT_SMALL]->getLineHeight()*2), EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[518]);
|
|
||||||
labelStartingHero = std::make_shared<CMultiLineLabel>(Rect(239, 86, 70, (int)graphics->fonts[EFonts::FONT_SMALL]->getLineHeight()*2), EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[519]);
|
|
||||||
labelStartingBonus = std::make_shared<CMultiLineLabel>(Rect(315, 86, 70, (int)graphics->fonts[EFonts::FONT_SMALL]->getLineHeight()*2), EFonts::FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[520]);
|
|
||||||
if(SEL->screenType == ESelectionScreen::newGame || SEL->screenType == ESelectionScreen::loadGame || SEL->screenType == ESelectionScreen::scenarioInfo)
|
if(SEL->screenType == ESelectionScreen::newGame || SEL->screenType == ESelectionScreen::loadGame || SEL->screenType == ESelectionScreen::scenarioInfo)
|
||||||
{
|
{
|
||||||
sliderTurnDuration = std::make_shared<CSlider>(Point(55, 551), 194, std::bind(&IServerAPI::setTurnLength, CSH, _1), 1, (int)GameConstants::POSSIBLE_TURNTIME.size(), (int)GameConstants::POSSIBLE_TURNTIME.size(), Orientation::HORIZONTAL, CSlider::BLUE);
|
if(auto w = widget<CSlider>("sliderTurnDuration"))
|
||||||
sliderTurnDuration->setScrollBounds(Rect(-3, -25, 337, 43));
|
w->deactivate();
|
||||||
sliderTurnDuration->setPanningStep(20);
|
if(auto w = widget<CLabel>("labelPlayerTurnDuration"))
|
||||||
labelPlayerTurnDuration = std::make_shared<CLabel>(222, 538, FONT_SMALL, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[521]);
|
w->deactivate();
|
||||||
labelTurnDurationValue = std::make_shared<CLabel>(319, 559, FONT_SMALL, ETextAlignment::CENTER, Colors::WHITE);
|
if(auto w = widget<CLabel>("labelTurnDurationValue"))
|
||||||
|
w->deactivate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,10 +74,11 @@ void OptionsTab::recreate()
|
|||||||
entries.insert(std::make_pair(pInfo.first, std::make_shared<PlayerOptionsEntry>(pInfo.second, * this)));
|
entries.insert(std::make_pair(pInfo.first, std::make_shared<PlayerOptionsEntry>(pInfo.second, * this)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if(sliderTurnDuration)
|
if(auto turnSlider = widget<CSlider>("sliderTurnDuration"))
|
||||||
{
|
{
|
||||||
sliderTurnDuration->scrollTo(vstd::find_pos(GameConstants::POSSIBLE_TURNTIME, SEL->getStartInfo()->turnTimerInfo.turnTimer / (60 * 1000)));
|
turnSlider->scrollTo(vstd::find_pos(GameConstants::POSSIBLE_TURNTIME, SEL->getStartInfo()->turnTimerInfo.turnTimer / (60 * 1000)));
|
||||||
labelTurnDurationValue->setText(CGI->generaltexth->turnDurations[sliderTurnDuration->getValue()]);
|
if(auto w = widget<CLabel>("labelTurnDurationValue"))
|
||||||
|
w->setText(CGI->generaltexth->turnDurations[turnSlider->getValue()]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -851,7 +850,7 @@ OptionsTab::PlayerOptionsEntry::PlayerOptionsEntry(const PlayerSettings & S, con
|
|||||||
}
|
}
|
||||||
|
|
||||||
pos.x += 54;
|
pos.x += 54;
|
||||||
pos.y += 122 + serial * 50;
|
pos.y += 128 + serial * 50;
|
||||||
|
|
||||||
assert(CSH->mi && CSH->mi->mapHeader);
|
assert(CSH->mi && CSH->mi->mapHeader);
|
||||||
const PlayerInfo & p = SEL->getPlayerInfo(s->color.getNum());
|
const PlayerInfo & p = SEL->getPlayerInfo(s->color.getNum());
|
||||||
|
|||||||
@@ -10,15 +10,14 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "../windows/CWindowObject.h"
|
#include "../windows/CWindowObject.h"
|
||||||
|
#include "../widgets/Scrollable.h"
|
||||||
|
#include "../gui/InterfaceObjectConfigurable.h"
|
||||||
|
|
||||||
VCMI_LIB_NAMESPACE_BEGIN
|
VCMI_LIB_NAMESPACE_BEGIN
|
||||||
struct PlayerSettings;
|
struct PlayerSettings;
|
||||||
struct PlayerInfo;
|
struct PlayerInfo;
|
||||||
VCMI_LIB_NAMESPACE_END
|
VCMI_LIB_NAMESPACE_END
|
||||||
|
|
||||||
#include "../widgets/Scrollable.h"
|
|
||||||
|
|
||||||
class CSlider;
|
|
||||||
class CLabel;
|
class CLabel;
|
||||||
class CMultiLineLabel;
|
class CMultiLineLabel;
|
||||||
class CFilledTexture;
|
class CFilledTexture;
|
||||||
@@ -30,21 +29,19 @@ class CButton;
|
|||||||
class FilledTexturePlayerColored;
|
class FilledTexturePlayerColored;
|
||||||
|
|
||||||
/// The options tab which is shown at the map selection phase.
|
/// The options tab which is shown at the map selection phase.
|
||||||
class OptionsTab : public CIntObject
|
class OptionsTab : public InterfaceObjectConfigurable
|
||||||
{
|
{
|
||||||
std::shared_ptr<CPicture> background;
|
struct PlayerOptionsEntry;
|
||||||
std::shared_ptr<CLabel> labelTitle;
|
|
||||||
std::shared_ptr<CMultiLineLabel> labelSubTitle;
|
|
||||||
std::shared_ptr<CMultiLineLabel> labelPlayerNameAndHandicap;
|
|
||||||
std::shared_ptr<CMultiLineLabel> labelStartingTown;
|
|
||||||
std::shared_ptr<CMultiLineLabel> labelStartingHero;
|
|
||||||
std::shared_ptr<CMultiLineLabel> labelStartingBonus;
|
|
||||||
|
|
||||||
std::shared_ptr<CLabel> labelPlayerTurnDuration;
|
|
||||||
std::shared_ptr<CLabel> labelTurnDurationValue;
|
|
||||||
ui8 humanPlayers;
|
ui8 humanPlayers;
|
||||||
|
std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
OptionsTab();
|
||||||
|
void recreate();
|
||||||
|
void onSetPlayerClicked(const PlayerSettings & ps) const;
|
||||||
|
|
||||||
enum SelType
|
enum SelType
|
||||||
{
|
{
|
||||||
TOWN,
|
TOWN,
|
||||||
@@ -52,6 +49,8 @@ public:
|
|||||||
BONUS
|
BONUS
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
|
||||||
struct CPlayerSettingsHelper
|
struct CPlayerSettingsHelper
|
||||||
{
|
{
|
||||||
const PlayerSettings & settings;
|
const PlayerSettings & settings;
|
||||||
@@ -187,11 +186,4 @@ public:
|
|||||||
private:
|
private:
|
||||||
const OptionsTab & parentTab;
|
const OptionsTab & parentTab;
|
||||||
};
|
};
|
||||||
|
|
||||||
std::shared_ptr<CSlider> sliderTurnDuration;
|
|
||||||
std::map<PlayerColor, std::shared_ptr<PlayerOptionsEntry>> entries;
|
|
||||||
|
|
||||||
OptionsTab();
|
|
||||||
void recreate();
|
|
||||||
void onSetPlayerClicked(const PlayerSettings & ps) const;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ RandomMapTab::RandomMapTab():
|
|||||||
recActions = 0;
|
recActions = 0;
|
||||||
mapGenOptions = std::make_shared<CMapGenOptions>();
|
mapGenOptions = std::make_shared<CMapGenOptions>();
|
||||||
|
|
||||||
const JsonNode config(ResourceID("config/widgets/randomMapTab.json"));
|
|
||||||
addCallback("toggleMapSize", [&](int btnId)
|
addCallback("toggleMapSize", [&](int btnId)
|
||||||
{
|
{
|
||||||
auto mapSizeVal = getPossibleMapSizes();
|
auto mapSizeVal = getPossibleMapSizes();
|
||||||
@@ -123,6 +122,7 @@ RandomMapTab::RandomMapTab():
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const JsonNode config(ResourceID("config/widgets/randomMapTab.json"));
|
||||||
build(config);
|
build(config);
|
||||||
|
|
||||||
updateMapInfoByHost();
|
updateMapInfoByHost();
|
||||||
|
|||||||
112
config/widgets/optionsTab.json
Normal file
112
config/widgets/optionsTab.json
Normal file
@@ -0,0 +1,112 @@
|
|||||||
|
{
|
||||||
|
"items":
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"name": "background",
|
||||||
|
"type": "picture",
|
||||||
|
"image": "ADVOPTBK",
|
||||||
|
"position": {"x": 0, "y": 6}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelTitle",
|
||||||
|
"type": "label",
|
||||||
|
"font": "big",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "yellow",
|
||||||
|
"text": "core.genrltxt.515",
|
||||||
|
"position": {"x": 222, "y": 36}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelSubTitle",
|
||||||
|
"type": "multiLineLabel",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "white",
|
||||||
|
"text": "core.genrltxt.516",
|
||||||
|
"rect": {"x": 60, "y": 50, "w": 320, "h": 0},
|
||||||
|
"adoptHeight": true
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelPlayerNameAndHandicap",
|
||||||
|
"type": "multiLineLabel",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "yellow",
|
||||||
|
"text": "core.genrltxt.517",
|
||||||
|
"rect": {"x": 58, "y": 92, "w": 100, "h": 0},
|
||||||
|
"adoptHeight": true
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelStartingTown",
|
||||||
|
"type": "multiLineLabel",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "yellow",
|
||||||
|
"text": "core.genrltxt.518",
|
||||||
|
"rect": {"x": 163, "y": 92, "w": 70, "h": 0},
|
||||||
|
"adoptHeight": true
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelStartingHero",
|
||||||
|
"type": "multiLineLabel",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "yellow",
|
||||||
|
"text": "core.genrltxt.519",
|
||||||
|
"rect": {"x": 239, "y": 92, "w": 70, "h": 0},
|
||||||
|
"adoptHeight": true
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelStartingBonus",
|
||||||
|
"type": "multiLineLabel",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "yellow",
|
||||||
|
"text": "core.genrltxt.520",
|
||||||
|
"rect": {"x": 315, "y": 92, "w": 70, "h": 0},
|
||||||
|
"adoptHeight": true
|
||||||
|
},
|
||||||
|
|
||||||
|
// timer
|
||||||
|
{
|
||||||
|
"name": "labelPlayerTurnDuration",
|
||||||
|
"type": "label",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "yellow",
|
||||||
|
"text": "core.genrltxt.521",
|
||||||
|
"position": {"x": 222, "y": 544}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "labelTurnDurationValue",
|
||||||
|
"type": "label",
|
||||||
|
"font": "small",
|
||||||
|
"alignment": "center",
|
||||||
|
"color": "white",
|
||||||
|
"text": "",
|
||||||
|
"position": {"x": 319, "y": 565}
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
"name": "sliderTurnDuration",
|
||||||
|
"type": "slider",
|
||||||
|
"orientation": "horizontal",
|
||||||
|
"position": {"x": 55, "y": 557},
|
||||||
|
"size": 194,
|
||||||
|
"callback": "setTurnLength",
|
||||||
|
"itemsVisible": 1,
|
||||||
|
"itemsTotal": 11,
|
||||||
|
"selected": 11,
|
||||||
|
"style": "blue",
|
||||||
|
"scrollBounds": {"x": -3, "y": -25, "w": 337, "h": 43},
|
||||||
|
"panningStep": 20
|
||||||
|
},
|
||||||
|
]
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user