1
0
mirror of https://github.com/vcmi/vcmi.git synced 2024-12-24 22:14:36 +02:00

Conversion of battle settings to configurable interface

This commit is contained in:
Dydzio 2023-02-12 13:51:57 +01:00
parent 319d05b94f
commit ee186f3839
3 changed files with 104 additions and 68 deletions

View File

@ -25,78 +25,24 @@ BattleOptionsWindow::BattleOptionsWindow(BattleInterface * owner):
OBJ_CONSTRUCTION_CAPTURING_ALL_NO_DISPOSE;
const JsonNode config(ResourceID("config/widgets/battleOptionsWindow.json"));
addCallback("viewGridChanged", std::bind(&BattleOptionsWindow::viewGridChangedCallback, this, _1, owner));
addCallback("movementShadowChanged", std::bind(&BattleOptionsWindow::movementShadowChangedCallback, this, _1, owner));
addCallback("mouseShadowChanged", std::bind(&BattleOptionsWindow::mouseShadowChangedCallback, this, _1));
addCallback("animationSpeedChanged", std::bind(&BattleOptionsWindow::animationSpeedChangedCallback, this, _1));
build(config);
auto viewGrid = std::make_shared<CToggleButton>(Point(25, 56), "sysopchk.def", CGI->generaltexth->zelp[427], [=](bool on)
{
Settings cellBorders = settings.write["battle"]["cellBorders"];
cellBorders->Bool() = on;
if(owner)
owner->redrawBattlefield();
});
viewGrid->setSelected(settings["battle"]["cellBorders"].Bool());
toggles.push_back(viewGrid);
std::shared_ptr<CToggleGroup> animationSpeedToggle = widget<CToggleGroup>("animationSpeedPicker");
animationSpeedToggle->setSelected(getAnimSpeed());
auto movementShadow = std::make_shared<CToggleButton>(Point(25, 89), "sysopchk.def", CGI->generaltexth->zelp[428], [=](bool on)
{
Settings stackRange = settings.write["battle"]["stackRange"];
stackRange->Bool() = on;
if(owner)
owner->redrawBattlefield();
});
movementShadow->setSelected(settings["battle"]["stackRange"].Bool());
toggles.push_back(movementShadow);
auto mouseShadow = std::make_shared<CToggleButton>(Point(25, 122), "sysopchk.def", CGI->generaltexth->zelp[429], [&](bool on)
{
Settings shadow = settings.write["battle"]["mouseShadow"];
shadow->Bool() = on;
});
mouseShadow->setSelected(settings["battle"]["mouseShadow"].Bool());
toggles.push_back(mouseShadow);
std::shared_ptr<CToggleButton> viewGridCheckbox = widget<CToggleButton>("viewGridCheckbox");
viewGridCheckbox->setSelected((bool)settings["battle"]["cellBorders"].Bool());
animSpeeds = std::make_shared<CToggleGroup>([&](int value)
{
Settings speed = settings.write["battle"]["speedFactor"];
speed->Float() = float(value);
});
std::shared_ptr<CToggleButton> movementShadowCheckbox = widget<CToggleButton>("movementShadowCheckbox");
movementShadowCheckbox->setSelected((bool)settings["battle"]["stackRange"].Bool());
std::shared_ptr<CToggleButton> toggle;
toggle = std::make_shared<CToggleButton>(Point( 28, 225), "sysopb9.def", CGI->generaltexth->zelp[422]);
animSpeeds->addToggle(1, toggle);
toggle = std::make_shared<CToggleButton>(Point( 92, 225), "sysob10.def", CGI->generaltexth->zelp[423]);
animSpeeds->addToggle(2, toggle);
toggle = std::make_shared<CToggleButton>(Point(156, 225), "sysob11.def", CGI->generaltexth->zelp[424]);
animSpeeds->addToggle(3, toggle);
animSpeeds->setSelected(getAnimSpeed());
//creating labels
labels.push_back(std::make_shared<CLabel>(242, 32, FONT_BIG, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[392]));//window title
labels.push_back(std::make_shared<CLabel>(122, 214, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[393]));//animation speed
labels.push_back(std::make_shared<CLabel>(122, 293, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[394]));//music volume
labels.push_back(std::make_shared<CLabel>(122, 359, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[395]));//effects' volume
labels.push_back(std::make_shared<CLabel>(353, 66, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[396]));//auto - combat options
labels.push_back(std::make_shared<CLabel>(353, 265, FONT_MEDIUM, ETextAlignment::CENTER, Colors::YELLOW, CGI->generaltexth->allTexts[397]));//creature info
//auto - combat options
labels.push_back(std::make_shared<CLabel>(283, 86, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[398]));//creatures
labels.push_back(std::make_shared<CLabel>(283, 116, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[399]));//spells
labels.push_back(std::make_shared<CLabel>(283, 146, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[400]));//catapult
labels.push_back(std::make_shared<CLabel>(283, 176, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[151]));//ballista
labels.push_back(std::make_shared<CLabel>(283, 206, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[401]));//first aid tent
//creature info
labels.push_back(std::make_shared<CLabel>(283, 285, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[402]));//all stats
labels.push_back(std::make_shared<CLabel>(283, 315, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[403]));//spells only
//general options
labels.push_back(std::make_shared<CLabel>(61, 57, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[404]));
labels.push_back(std::make_shared<CLabel>(61, 90, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[405]));
labels.push_back(std::make_shared<CLabel>(61, 123, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[406]));
labels.push_back(std::make_shared<CLabel>(61, 156, FONT_MEDIUM, ETextAlignment::TOPLEFT, Colors::WHITE, CGI->generaltexth->allTexts[407]));
std::shared_ptr<CToggleButton> mouseShadowCheckbox = widget<CToggleButton>("mouseShadowCheckbox");
mouseShadowCheckbox->setSelected((bool)settings["battle"]["mouseShadow"].Bool());
}
int BattleOptionsWindow::getAnimSpeed() const
@ -105,4 +51,33 @@ int BattleOptionsWindow::getAnimSpeed() const
return static_cast<int>(std::round(settings["session"]["spectate-battle-speed"].Float()));
return static_cast<int>(std::round(settings["battle"]["speedFactor"].Float()));
}
}
void BattleOptionsWindow::viewGridChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
Settings cellBorders = settings.write["battle"]["cellBorders"];
cellBorders->Bool() = value;
if(parentBattleInterface)
parentBattleInterface->redrawBattlefield();
}
void BattleOptionsWindow::movementShadowChangedCallback(bool value, BattleInterface * parentBattleInterface)
{
Settings stackRange = settings.write["battle"]["stackRange"];
stackRange->Bool() = value;
if(parentBattleInterface)
parentBattleInterface->redrawBattlefield();
}
void BattleOptionsWindow::mouseShadowChangedCallback(bool value)
{
Settings shadow = settings.write["battle"]["mouseShadow"];
shadow->Bool() = value;
}
void BattleOptionsWindow::animationSpeedChangedCallback(int value)
{
Settings speed = settings.write["battle"]["speedFactor"];
speed->Float() = float(value);
}

View File

@ -16,10 +16,13 @@ class BattleOptionsWindow : public InterfaceObjectConfigurable
{
private:
std::shared_ptr<CToggleGroup> animSpeeds;
std::vector<std::shared_ptr<CLabel>> labels;
std::vector<std::shared_ptr<CToggleButton>> toggles;
int getAnimSpeed() const;
void viewGridChangedCallback(bool value, BattleInterface * parentBattleInterface = nullptr);
void movementShadowChangedCallback(bool value, BattleInterface * parentBattleInterface = nullptr);
void mouseShadowChangedCallback(bool value);
void animationSpeedChangedCallback(int value);
public:
BattleOptionsWindow(BattleInterface * owner = nullptr);
};

View File

@ -157,6 +157,64 @@
"color": "white",
"text": "core.genrltxt.407",
"position": {"x": 61, "y": 156}
},
{
"name": "viewGridCheckbox",
"type": "toggleButton",
"image": "sysopchk.def",
"help": "core.help.427",
"position": {"x": 25, "y": 56},
"callback": "viewGridChanged"
},
{
"name": "movementShadowCheckbox",
"type": "toggleButton",
"image": "sysopchk.def",
"help": "core.help.428",
"position": {"x": 25, "y": 89},
"callback": "movementShadowChanged"
},
{
"name": "mouseShadowCheckbox",
"type": "toggleButton",
"image": "sysopchk.def",
"help": "core.help.429",
"position": {"x": 25, "y": 122},
"callback": "mouseShadowChanged"
},
{
"name": "animationSpeedPicker",
"type": "toggleGroup",
"position": {"x": 28, "y": 225},
"items":
[
{
"index": 1,
"type": "toggleButton",
"image": "sysopb9",
"help": "core.help.422",
"position": {"x": 0, "y": 0}
},
{
"index": 2,
"type": "toggleButton",
"image": "sysob10",
"help": "core.help.423",
"position": {"x": 64, "y": 0}
},
{
"index": 3,
"type": "toggleButton",
"image": "sysob11",
"help": "core.help.424",
"position": {"x": 128, "y": 0}
}
],
"callback": "animationSpeedChanged"
}
]
}