2022-12-12 09:48:39 +02:00
|
|
|
/*
|
|
|
|
* 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 "InterfaceObjectConfigurable.h"
|
|
|
|
|
|
|
|
#include "../CGameInfo.h"
|
2023-01-04 16:40:15 +02:00
|
|
|
#include "../CPlayerInterface.h"
|
2022-12-12 09:48:39 +02:00
|
|
|
#include "../gui/CGuiHandler.h"
|
2023-04-27 19:21:06 +02:00
|
|
|
#include "../gui/ShortcutHandler.h"
|
|
|
|
#include "../gui/Shortcut.h"
|
2023-08-23 17:29:50 +02:00
|
|
|
#include "../render/Graphics.h"
|
|
|
|
#include "../render/IFont.h"
|
2024-09-23 17:43:11 +02:00
|
|
|
#include "../render/IRenderHandler.h"
|
2022-12-12 09:48:39 +02:00
|
|
|
#include "../widgets/CComponent.h"
|
2023-08-25 12:07:38 +02:00
|
|
|
#include "../widgets/ComboBox.h"
|
2022-12-12 09:48:39 +02:00
|
|
|
#include "../widgets/Buttons.h"
|
2024-05-12 12:24:13 +02:00
|
|
|
#include "../widgets/CTextInput.h"
|
2024-01-18 16:23:12 +02:00
|
|
|
#include "../widgets/GraphicalPrimitiveCanvas.h"
|
2022-12-12 09:48:39 +02:00
|
|
|
#include "../widgets/ObjectLists.h"
|
2023-05-30 16:31:45 +02:00
|
|
|
#include "../widgets/Slider.h"
|
2022-12-12 09:48:39 +02:00
|
|
|
#include "../widgets/TextControls.h"
|
|
|
|
#include "../windows/GUIClasses.h"
|
|
|
|
#include "../windows/InfoWindows.h"
|
|
|
|
|
2024-02-11 23:09:01 +02:00
|
|
|
#include "../../lib/constants/StringConstants.h"
|
|
|
|
#include "../../lib/json/JsonUtils.h"
|
2024-07-20 14:55:17 +02:00
|
|
|
#include "../../lib/texts/CGeneralTextHandler.h"
|
2023-08-23 14:07:50 +02:00
|
|
|
#include "../../lib/filesystem/ResourcePath.h"
|
2022-12-12 09:48:39 +02:00
|
|
|
|
2022-12-16 00:15:53 +02:00
|
|
|
InterfaceObjectConfigurable::InterfaceObjectConfigurable(const JsonNode & config, int used, Point offset):
|
2022-12-21 22:54:06 +02:00
|
|
|
InterfaceObjectConfigurable(used, offset)
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-25 12:22:07 +02:00
|
|
|
build(config);
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-12-16 00:15:53 +02:00
|
|
|
InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset):
|
|
|
|
CIntObject(used, offset)
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-22 00:05:29 +02:00
|
|
|
REGISTER_BUILDER("picture", &InterfaceObjectConfigurable::buildPicture);
|
|
|
|
REGISTER_BUILDER("image", &InterfaceObjectConfigurable::buildImage);
|
|
|
|
REGISTER_BUILDER("texture", &InterfaceObjectConfigurable::buildTexture);
|
|
|
|
REGISTER_BUILDER("animation", &InterfaceObjectConfigurable::buildAnimation);
|
|
|
|
REGISTER_BUILDER("label", &InterfaceObjectConfigurable::buildLabel);
|
2023-08-23 17:29:50 +02:00
|
|
|
REGISTER_BUILDER("multiLineLabel", &InterfaceObjectConfigurable::buildMultiLineLabel);
|
2022-12-22 00:05:29 +02:00
|
|
|
REGISTER_BUILDER("toggleGroup", &InterfaceObjectConfigurable::buildToggleGroup);
|
|
|
|
REGISTER_BUILDER("toggleButton", &InterfaceObjectConfigurable::buildToggleButton);
|
|
|
|
REGISTER_BUILDER("button", &InterfaceObjectConfigurable::buildButton);
|
|
|
|
REGISTER_BUILDER("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
|
|
|
|
REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
|
2023-05-15 11:48:58 +02:00
|
|
|
REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
|
2023-08-25 12:07:38 +02:00
|
|
|
REGISTER_BUILDER("comboBox", &InterfaceObjectConfigurable::buildComboBox);
|
2023-08-25 18:20:26 +02:00
|
|
|
REGISTER_BUILDER("textInput", &InterfaceObjectConfigurable::buildTextInput);
|
2024-01-18 16:23:12 +02:00
|
|
|
REGISTER_BUILDER("graphicalPrimitive", &InterfaceObjectConfigurable::buildGraphicalPrimitive);
|
2023-09-30 22:49:22 +02:00
|
|
|
REGISTER_BUILDER("transparentFilledRectangle", &InterfaceObjectConfigurable::buildTransparentFilledRectangle);
|
|
|
|
REGISTER_BUILDER("textBox", &InterfaceObjectConfigurable::buildTextBox);
|
2022-12-22 00:05:29 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
|
|
|
|
{
|
|
|
|
builders[type] = f;
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceObjectConfigurable::addCallback(const std::string & callbackName, std::function<void(int)> callback)
|
|
|
|
{
|
2023-08-25 18:20:26 +02:00
|
|
|
callbacks_int[callbackName] = callback;
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
|
|
|
|
2023-08-25 18:20:26 +02:00
|
|
|
void InterfaceObjectConfigurable::addCallback(const std::string & callbackName, std::function<void(std::string)> callback)
|
|
|
|
{
|
|
|
|
callbacks_string[callbackName] = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-25 12:33:10 +02:00
|
|
|
void InterfaceObjectConfigurable::deleteWidget(const std::string & name)
|
|
|
|
{
|
|
|
|
auto iter = widgets.find(name);
|
|
|
|
if(iter != widgets.end())
|
|
|
|
widgets.erase(iter);
|
|
|
|
}
|
|
|
|
|
2023-05-14 23:53:26 +02:00
|
|
|
void InterfaceObjectConfigurable::loadCustomBuilders(const JsonNode & config)
|
|
|
|
{
|
|
|
|
for(auto & item : config.Struct())
|
|
|
|
{
|
|
|
|
std::string typeName = item.first;
|
|
|
|
JsonNode baseConfig = item.second;
|
|
|
|
|
|
|
|
auto const & functor = [this, baseConfig](const JsonNode & widgetConfig) -> std::shared_ptr<CIntObject>
|
|
|
|
{
|
|
|
|
JsonNode actualConfig = widgetConfig;
|
|
|
|
JsonUtils::mergeCopy(actualConfig, baseConfig);
|
|
|
|
|
|
|
|
return this->buildWidget(actualConfig);
|
|
|
|
};
|
|
|
|
registerBuilder(typeName, functor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-25 12:22:07 +02:00
|
|
|
void InterfaceObjectConfigurable::build(const JsonNode &config)
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION;
|
2023-05-14 23:53:26 +02:00
|
|
|
|
2022-12-22 00:08:26 +02:00
|
|
|
logGlobal->debug("Building configurable interface object");
|
2022-12-25 12:22:07 +02:00
|
|
|
auto * items = &config;
|
|
|
|
|
|
|
|
if(config.getType() == JsonNode::JsonType::DATA_STRUCT)
|
2022-12-17 18:38:16 +02:00
|
|
|
{
|
2023-05-15 13:00:52 +02:00
|
|
|
if (!config["library"].isNull())
|
|
|
|
{
|
2024-02-18 22:15:31 +02:00
|
|
|
if (config["library"].isString())
|
|
|
|
{
|
|
|
|
const JsonNode library(JsonPath::fromJson(config["library"]));
|
|
|
|
loadCustomBuilders(library);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config["library"].isVector())
|
|
|
|
{
|
|
|
|
for (auto const & entry : config["library"].Vector())
|
|
|
|
{
|
|
|
|
const JsonNode library(JsonPath::fromJson(entry));
|
|
|
|
loadCustomBuilders(library);
|
|
|
|
}
|
|
|
|
}
|
2023-05-15 13:00:52 +02:00
|
|
|
}
|
|
|
|
|
2023-05-14 23:53:26 +02:00
|
|
|
loadCustomBuilders(config["customTypes"]);
|
|
|
|
|
2022-12-25 12:22:07 +02:00
|
|
|
for(auto & item : config["variables"].Struct())
|
|
|
|
{
|
|
|
|
logGlobal->debug("Read variable named %s", item.first);
|
|
|
|
variables[item.first] = item.second;
|
|
|
|
}
|
2023-05-15 13:00:52 +02:00
|
|
|
|
2022-12-25 12:22:07 +02:00
|
|
|
items = &config["items"];
|
2022-12-17 18:38:16 +02:00
|
|
|
}
|
|
|
|
|
2022-12-25 12:22:07 +02:00
|
|
|
for(const auto & item : items->Vector())
|
2023-05-04 18:04:36 +02:00
|
|
|
addWidget(item["name"].String(), buildWidget(item));
|
2023-11-11 16:43:58 +02:00
|
|
|
|
2024-01-12 01:10:41 +02:00
|
|
|
// load only if set
|
|
|
|
if (!config["width"].isNull())
|
|
|
|
pos.w = config["width"].Integer();
|
|
|
|
if (!config["height"].isNull())
|
|
|
|
pos.h = config["height"].Integer();
|
2023-05-04 18:04:36 +02:00
|
|
|
}
|
|
|
|
|
2023-05-19 22:19:43 +02:00
|
|
|
void InterfaceObjectConfigurable::addConditional(const std::string & name, bool active)
|
|
|
|
{
|
|
|
|
conditionals[name] = active;
|
|
|
|
}
|
|
|
|
|
2023-05-04 18:04:36 +02:00
|
|
|
void InterfaceObjectConfigurable::addWidget(const std::string & namePreferred, std::shared_ptr<CIntObject> widget)
|
|
|
|
{
|
|
|
|
static const std::string unnamedObjectPrefix = "__widget_";
|
|
|
|
|
|
|
|
std::string nameActual;
|
|
|
|
|
|
|
|
if (widgets.count(namePreferred) == 0)
|
|
|
|
nameActual = namePreferred;
|
|
|
|
else
|
|
|
|
logGlobal->error("Duplicated widget name: '%s'", namePreferred);
|
|
|
|
|
|
|
|
if (nameActual.empty())
|
|
|
|
nameActual = unnamedObjectPrefix + std::to_string(unnamedObjectId++);
|
|
|
|
|
|
|
|
logGlobal->debug("Building widget with name %s", nameActual);
|
|
|
|
widgets[nameActual] = widget;
|
2022-12-16 00:15:53 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
std::string InterfaceObjectConfigurable::readText(const JsonNode & config) const
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
|
|
|
if(config.isNull())
|
|
|
|
return "";
|
|
|
|
|
2022-12-16 00:48:07 +02:00
|
|
|
std::string s = config.String();
|
2023-08-29 12:53:15 +02:00
|
|
|
if(s.empty())
|
|
|
|
return s;
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading text from translations by key: %s", s);
|
2022-12-27 22:19:05 +02:00
|
|
|
return CGI->generaltexth->translate(s);
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
Point InterfaceObjectConfigurable::readPosition(const JsonNode & config) const
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
Point p;
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading point");
|
2022-12-15 22:46:36 +02:00
|
|
|
p.x = config["x"].Integer();
|
|
|
|
p.y = config["y"].Integer();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-12-17 06:19:16 +02:00
|
|
|
Rect InterfaceObjectConfigurable::readRect(const JsonNode & config) const
|
|
|
|
{
|
|
|
|
Rect p;
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading rect");
|
2022-12-17 06:19:16 +02:00
|
|
|
p.x = config["x"].Integer();
|
|
|
|
p.y = config["y"].Integer();
|
|
|
|
p.w = config["w"].Integer();
|
|
|
|
p.h = config["h"].Integer();
|
|
|
|
return p;
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
ETextAlignment InterfaceObjectConfigurable::readTextAlignment(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading text alignment");
|
2022-12-15 22:46:36 +02:00
|
|
|
if(!config.isNull())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
if(config.String() == "center")
|
|
|
|
return ETextAlignment::CENTER;
|
|
|
|
if(config.String() == "left")
|
|
|
|
return ETextAlignment::TOPLEFT;
|
|
|
|
if(config.String() == "right")
|
|
|
|
return ETextAlignment::BOTTOMRIGHT;
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
2023-10-17 22:06:08 +02:00
|
|
|
logGlobal->debug("Unknown text alignment attribute");
|
2022-12-15 22:46:36 +02:00
|
|
|
return ETextAlignment::CENTER;
|
|
|
|
}
|
|
|
|
|
2023-07-31 18:50:55 +02:00
|
|
|
ColorRGBA InterfaceObjectConfigurable::readColor(const JsonNode & config) const
|
2022-12-15 22:46:36 +02:00
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading color");
|
2022-12-15 22:46:36 +02:00
|
|
|
if(!config.isNull())
|
|
|
|
{
|
2023-08-13 23:13:37 +02:00
|
|
|
if(config.isString())
|
|
|
|
{
|
|
|
|
if(config.String() == "yellow")
|
|
|
|
return Colors::YELLOW;
|
|
|
|
if(config.String() == "white")
|
|
|
|
return Colors::WHITE;
|
|
|
|
if(config.String() == "gold")
|
|
|
|
return Colors::METALLIC_GOLD;
|
|
|
|
if(config.String() == "green")
|
|
|
|
return Colors::GREEN;
|
|
|
|
if(config.String() == "orange")
|
|
|
|
return Colors::ORANGE;
|
|
|
|
if(config.String() == "bright-yellow")
|
|
|
|
return Colors::BRIGHT_YELLOW;
|
|
|
|
}
|
|
|
|
if(config.isVector())
|
|
|
|
{
|
|
|
|
const auto & asVector = config.Vector();
|
|
|
|
if(asVector.size() == 4)
|
|
|
|
return ColorRGBA(asVector[0].Integer(), asVector[1].Integer(), asVector[2].Integer(), asVector[3].Integer());
|
|
|
|
if(asVector.size() == 3)
|
|
|
|
return ColorRGBA(asVector[0].Integer(), asVector[1].Integer(), asVector[2].Integer());
|
|
|
|
}
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
2023-10-17 22:06:08 +02:00
|
|
|
logGlobal->debug("Unknown color attribute");
|
2022-12-15 22:46:36 +02:00
|
|
|
return Colors::DEFAULT_KEY_COLOR;
|
2023-08-27 20:34:02 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
PlayerColor InterfaceObjectConfigurable::readPlayerColor(const JsonNode & config) const
|
|
|
|
{
|
|
|
|
logGlobal->debug("Reading PlayerColor");
|
|
|
|
if(!config.isNull() && config.isString())
|
2023-09-28 18:43:04 +02:00
|
|
|
return PlayerColor(PlayerColor::decode(config.String()));
|
2022-12-12 09:48:39 +02:00
|
|
|
|
2023-08-27 20:34:02 +02:00
|
|
|
logGlobal->debug("Unknown PlayerColor attribute");
|
|
|
|
return PlayerColor::CANNOT_DETERMINE;
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
2023-08-27 20:34:02 +02:00
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
EFonts InterfaceObjectConfigurable::readFont(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading font");
|
2022-12-15 22:46:36 +02:00
|
|
|
if(!config.isNull())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
if(config.String() == "big")
|
|
|
|
return EFonts::FONT_BIG;
|
|
|
|
if(config.String() == "medium")
|
|
|
|
return EFonts::FONT_MEDIUM;
|
|
|
|
if(config.String() == "small")
|
|
|
|
return EFonts::FONT_SMALL;
|
|
|
|
if(config.String() == "tiny")
|
|
|
|
return EFonts::FONT_TINY;
|
2023-04-26 14:44:10 +02:00
|
|
|
if(config.String() == "calisto")
|
|
|
|
return EFonts::FONT_CALLI;
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
2023-10-17 22:06:08 +02:00
|
|
|
logGlobal->debug("Unknown font attribute");
|
2024-09-23 20:15:30 +02:00
|
|
|
return EFonts::FONT_MEDIUM;
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::pair<std::string, std::string> InterfaceObjectConfigurable::readHintText(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Reading hint text");
|
2022-12-15 22:46:36 +02:00
|
|
|
std::pair<std::string, std::string> result;
|
|
|
|
if(!config.isNull())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
if(config.getType() == JsonNode::JsonType::DATA_STRUCT)
|
|
|
|
{
|
2022-12-16 00:49:52 +02:00
|
|
|
result.first = readText(config["hover"]);
|
|
|
|
result.second = readText(config["help"]);
|
2022-12-15 22:46:36 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
if(config.getType() == JsonNode::JsonType::DATA_STRING)
|
|
|
|
{
|
2022-12-28 23:23:11 +02:00
|
|
|
logGlobal->debug("Reading hint text (help) from generaltext handler:%sd", config.String());
|
2022-12-30 19:09:19 +02:00
|
|
|
result.first = CGI->generaltexth->translate( config.String(), "hover");
|
|
|
|
result.second = CGI->generaltexth->translate( config.String(), "help");
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
2022-12-15 22:46:36 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-04-29 12:48:21 +02:00
|
|
|
EShortcut InterfaceObjectConfigurable::readHotkey(const JsonNode & config) const
|
2022-12-25 12:22:07 +02:00
|
|
|
{
|
2023-04-29 12:48:21 +02:00
|
|
|
logGlobal->debug("Reading hotkey");
|
2023-04-08 18:47:38 +02:00
|
|
|
|
2023-04-27 19:21:06 +02:00
|
|
|
if(config.getType() != JsonNode::JsonType::DATA_STRING)
|
|
|
|
{
|
2023-04-29 12:48:21 +02:00
|
|
|
logGlobal->error("Invalid hotket format in interface configuration! Expected string!", config.String());
|
2023-04-27 19:21:06 +02:00
|
|
|
return EShortcut::NONE;
|
2022-12-25 12:22:07 +02:00
|
|
|
}
|
2023-04-08 18:47:38 +02:00
|
|
|
|
2023-05-18 19:32:29 +02:00
|
|
|
EShortcut result = GH.shortcuts().findShortcut(config.String());
|
2023-04-27 19:21:06 +02:00
|
|
|
if (result == EShortcut::NONE)
|
2023-04-29 12:48:21 +02:00
|
|
|
logGlobal->error("Invalid hotkey '%s' in interface configuration!", config.String());
|
2024-01-16 21:02:39 +02:00
|
|
|
return result;
|
2022-12-25 12:22:07 +02:00
|
|
|
}
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
std::shared_ptr<CPicture> InterfaceObjectConfigurable::buildPicture(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CPicture");
|
2023-08-23 14:07:50 +02:00
|
|
|
auto image = ImagePath::fromJson(config["image"]);
|
2022-12-15 22:46:36 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
2022-12-16 00:15:53 +02:00
|
|
|
auto pic = std::make_shared<CPicture>(image, position.x, position.y);
|
2023-01-04 16:40:15 +02:00
|
|
|
|
|
|
|
if ( config["playerColored"].Bool() && LOCPLINT)
|
2024-06-05 17:50:50 +02:00
|
|
|
pic->setPlayerColor(LOCPLINT->playerID);
|
2022-12-16 00:15:53 +02:00
|
|
|
return pic;
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CLabel> InterfaceObjectConfigurable::buildLabel(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CLabel");
|
2022-12-15 22:46:36 +02:00
|
|
|
auto font = readFont(config["font"]);
|
|
|
|
auto alignment = readTextAlignment(config["alignment"]);
|
|
|
|
auto color = readColor(config["color"]);
|
|
|
|
auto text = readText(config["text"]);
|
|
|
|
auto position = readPosition(config["position"]);
|
2024-07-31 21:40:49 +02:00
|
|
|
auto maxWidth = config["maxWidth"].Integer();
|
|
|
|
return std::make_shared<CLabel>(position.x, position.y, font, alignment, color, text, maxWidth);
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
|
|
|
|
2023-08-23 17:29:50 +02:00
|
|
|
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"]);
|
2024-09-23 17:43:11 +02:00
|
|
|
const auto & fontPtr = GH.renderHandler().loadFont(font);
|
2023-08-23 17:29:50 +02:00
|
|
|
if(!config["adoptHeight"].isNull() && config["adoptHeight"].Bool())
|
2024-09-23 17:43:11 +02:00
|
|
|
rect.h = fontPtr->getLineHeight() * 2;
|
2023-08-23 17:29:50 +02:00
|
|
|
return std::make_shared<CMultiLineLabel>(rect, font, alignment, color, text);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
std::shared_ptr<CToggleGroup> InterfaceObjectConfigurable::buildToggleGroup(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CToggleGroup");
|
2022-12-15 22:46:36 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
|
|
|
auto group = std::make_shared<CToggleGroup>(0);
|
|
|
|
group->pos += position;
|
|
|
|
if(!config["items"].isNull())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2024-08-09 17:30:04 +02:00
|
|
|
OBJECT_CONSTRUCTION_TARGETED(group.get());
|
2022-12-15 22:46:36 +02:00
|
|
|
int itemIdx = -1;
|
|
|
|
for(const auto & item : config["items"].Vector())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
itemIdx = item["index"].isNull() ? itemIdx + 1 : item["index"].Integer();
|
2023-05-15 18:44:02 +02:00
|
|
|
auto newToggle = std::dynamic_pointer_cast<CToggleButton>(buildWidget(item));
|
|
|
|
group->addToggle(itemIdx, newToggle);
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-15 22:46:36 +02:00
|
|
|
if(!config["selected"].isNull())
|
|
|
|
group->setSelected(config["selected"].Integer());
|
|
|
|
if(!config["callback"].isNull())
|
2023-08-25 18:20:26 +02:00
|
|
|
group->addCallback(callbacks_int.at(config["callback"].String()));
|
2022-12-15 22:46:36 +02:00
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CToggleButton> InterfaceObjectConfigurable::buildToggleButton(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CToggleButton");
|
2022-12-15 22:46:36 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
2023-08-23 14:07:50 +02:00
|
|
|
auto image = AnimationPath::fromJson(config["image"]);
|
2022-12-28 23:23:11 +02:00
|
|
|
auto help = readHintText(config["help"]);
|
|
|
|
auto button = std::make_shared<CToggleButton>(position, image, help);
|
2023-02-14 23:22:11 +02:00
|
|
|
if(!config["items"].isNull())
|
|
|
|
{
|
|
|
|
for(const auto & item : config["items"].Vector())
|
|
|
|
{
|
2024-02-27 22:19:09 +02:00
|
|
|
button->setOverlay(buildWidget(item));
|
2023-02-14 23:22:11 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-15 22:46:36 +02:00
|
|
|
if(!config["selected"].isNull())
|
|
|
|
button->setSelected(config["selected"].Bool());
|
|
|
|
if(!config["imageOrder"].isNull())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
auto imgOrder = config["imageOrder"].Vector();
|
|
|
|
assert(imgOrder.size() >= 4);
|
|
|
|
button->setImageOrder(imgOrder[0].Integer(), imgOrder[1].Integer(), imgOrder[2].Integer(), imgOrder[3].Integer());
|
|
|
|
}
|
2023-05-12 21:58:21 +02:00
|
|
|
loadToggleButtonCallback(button, config["callback"]);
|
2022-12-15 22:46:36 +02:00
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CButton> InterfaceObjectConfigurable::buildButton(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CButton");
|
2022-12-15 22:46:36 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
2023-08-23 14:07:50 +02:00
|
|
|
auto image = AnimationPath::fromJson(config["image"]);
|
2022-12-28 23:23:11 +02:00
|
|
|
auto help = readHintText(config["help"]);
|
|
|
|
auto button = std::make_shared<CButton>(position, image, help);
|
2022-12-15 22:46:36 +02:00
|
|
|
if(!config["items"].isNull())
|
|
|
|
{
|
|
|
|
for(const auto & item : config["items"].Vector())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2024-02-27 22:19:09 +02:00
|
|
|
button->setOverlay(buildWidget(item));
|
2022-12-12 09:48:39 +02:00
|
|
|
}
|
|
|
|
}
|
2022-12-25 12:22:07 +02:00
|
|
|
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());
|
|
|
|
}
|
2023-04-29 12:48:21 +02:00
|
|
|
|
2023-05-05 20:50:20 +02:00
|
|
|
loadButtonBorderColor(button, config["borderColor"]);
|
2023-05-02 15:09:36 +02:00
|
|
|
loadButtonCallback(button, config["callback"]);
|
|
|
|
loadButtonHotkey(button, config["hotkey"]);
|
|
|
|
return button;
|
|
|
|
}
|
|
|
|
|
2023-05-05 20:50:20 +02:00
|
|
|
void InterfaceObjectConfigurable::loadButtonBorderColor(std::shared_ptr<CButton> button, const JsonNode & config) const
|
|
|
|
{
|
|
|
|
if (config.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
auto color = readColor(config);
|
|
|
|
button->setBorderColor(color);
|
|
|
|
}
|
|
|
|
|
2023-05-12 21:58:21 +02:00
|
|
|
void InterfaceObjectConfigurable::loadToggleButtonCallback(std::shared_ptr<CToggleButton> button, const JsonNode & config) const
|
|
|
|
{
|
|
|
|
if(config.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string callbackName = config.String();
|
|
|
|
|
2023-08-25 18:20:26 +02:00
|
|
|
if (callbacks_int.count(callbackName) > 0)
|
|
|
|
button->addCallback(callbacks_int.at(callbackName));
|
2023-05-12 21:58:21 +02:00
|
|
|
else
|
|
|
|
logGlobal->error("Invalid callback '%s' in widget", callbackName );
|
|
|
|
}
|
|
|
|
|
2023-05-02 15:09:36 +02:00
|
|
|
void InterfaceObjectConfigurable::loadButtonCallback(std::shared_ptr<CButton> button, const JsonNode & config) const
|
|
|
|
{
|
|
|
|
if(config.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
std::string callbackName = config.String();
|
|
|
|
|
2023-08-25 18:20:26 +02:00
|
|
|
if (callbacks_int.count(callbackName) > 0)
|
|
|
|
button->addCallback(std::bind(callbacks_int.at(callbackName), 0));
|
2023-05-02 15:09:36 +02:00
|
|
|
else
|
|
|
|
logGlobal->error("Invalid callback '%s' in widget", callbackName );
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceObjectConfigurable::loadButtonHotkey(std::shared_ptr<CButton> button, const JsonNode & config) const
|
|
|
|
{
|
|
|
|
if(config.isNull())
|
|
|
|
return;
|
|
|
|
|
|
|
|
if(config.getType() != JsonNode::JsonType::DATA_STRING)
|
2022-12-25 12:22:07 +02:00
|
|
|
{
|
2023-05-02 15:09:36 +02:00
|
|
|
logGlobal->error("Invalid shortcut format - string expected!");
|
|
|
|
return;
|
2022-12-25 12:22:07 +02:00
|
|
|
}
|
2023-05-02 15:09:36 +02:00
|
|
|
|
|
|
|
button->assignedKey = readHotkey(config);
|
|
|
|
|
|
|
|
auto target = shortcuts.find(button->assignedKey);
|
|
|
|
if (target == shortcuts.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
button->addCallback(target->second.callback);
|
2024-05-19 10:23:28 +02:00
|
|
|
target->second.assignedButtons.push_back(button);
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CLabelGroup> InterfaceObjectConfigurable::buildLabelGroup(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CLabelGroup");
|
2022-12-15 22:46:36 +02:00
|
|
|
auto font = readFont(config["font"]);
|
|
|
|
auto alignment = readTextAlignment(config["alignment"]);
|
|
|
|
auto color = readColor(config["color"]);
|
|
|
|
auto group = std::make_shared<CLabelGroup>(font, alignment, color);
|
|
|
|
if(!config["items"].isNull())
|
2022-12-12 09:48:39 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
for(const auto & item : config["items"].Vector())
|
2022-12-13 01:47:29 +02:00
|
|
|
{
|
2022-12-15 22:46:36 +02:00
|
|
|
auto position = readPosition(item["position"]);
|
|
|
|
auto text = readText(item["text"]);
|
|
|
|
group->add(position.x, position.y, text);
|
2022-12-13 01:47:29 +02:00
|
|
|
}
|
2022-12-15 22:46:36 +02:00
|
|
|
}
|
|
|
|
return group;
|
|
|
|
}
|
|
|
|
|
2022-12-16 00:15:53 +02:00
|
|
|
std::shared_ptr<CSlider> InterfaceObjectConfigurable::buildSlider(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CSlider");
|
2022-12-16 00:15:53 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
|
|
|
int length = config["size"].Integer();
|
|
|
|
auto style = config["style"].String() == "brown" ? CSlider::BROWN : CSlider::BLUE;
|
|
|
|
auto value = config["selected"].Integer();
|
|
|
|
bool horizontal = config["orientation"].String() == "horizontal";
|
2023-11-10 17:18:49 +02:00
|
|
|
auto orientation = horizontal ? Orientation::HORIZONTAL : Orientation::VERTICAL;
|
|
|
|
|
|
|
|
std::shared_ptr<CSlider> result;
|
|
|
|
|
|
|
|
if (config["items"].isNull())
|
|
|
|
{
|
|
|
|
auto itemsVisible = config["itemsVisible"].Integer();
|
|
|
|
auto itemsTotal = config["itemsTotal"].Integer();
|
|
|
|
|
|
|
|
result = std::make_shared<CSlider>(position, length, callbacks_int.at(config["callback"].String()), itemsVisible, itemsTotal, value, orientation, style);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
auto items = config["items"].convertTo<std::vector<int>>();
|
|
|
|
result = std::make_shared<SliderNonlinear>(position, length, callbacks_int.at(config["callback"].String()), items, value, orientation, style);
|
|
|
|
}
|
|
|
|
|
2023-04-02 21:24:07 +02:00
|
|
|
|
2023-08-23 17:29:50 +02:00
|
|
|
if(!config["scrollBounds"].isNull())
|
2023-04-02 21:24:07 +02:00
|
|
|
{
|
|
|
|
Rect bounds = readRect(config["scrollBounds"]);
|
|
|
|
result->setScrollBounds(bounds);
|
|
|
|
}
|
2023-08-23 17:29:50 +02:00
|
|
|
|
|
|
|
if(!config["panningStep"].isNull())
|
|
|
|
result->setPanningStep(config["panningStep"].Integer());
|
2023-04-02 21:24:07 +02:00
|
|
|
|
|
|
|
return result;
|
2022-12-16 00:15:53 +02:00
|
|
|
}
|
|
|
|
|
2022-12-17 06:19:16 +02:00
|
|
|
std::shared_ptr<CAnimImage> InterfaceObjectConfigurable::buildImage(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CAnimImage");
|
2022-12-17 06:19:16 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
2023-08-23 14:07:50 +02:00
|
|
|
auto image = AnimationPath::fromJson(config["image"]);
|
2022-12-17 06:19:16 +02:00
|
|
|
int group = config["group"].isNull() ? 0 : config["group"].Integer();
|
|
|
|
int frame = config["frame"].isNull() ? 0 : config["frame"].Integer();
|
|
|
|
return std::make_shared<CAnimImage>(image, frame, group, position.x, position.y);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CFilledTexture");
|
2022-12-17 18:38:16 +02:00
|
|
|
auto rect = readRect(config["rect"]);
|
2023-08-27 20:34:02 +02:00
|
|
|
auto playerColor = readPlayerColor(config["color"]);
|
|
|
|
if(playerColor.isValidPlayer())
|
|
|
|
{
|
2024-09-12 18:11:03 +02:00
|
|
|
auto result = std::make_shared<FilledTexturePlayerColored>(rect);
|
2024-06-05 17:50:50 +02:00
|
|
|
result->setPlayerColor(playerColor);
|
2023-10-24 18:51:58 +02:00
|
|
|
return result;
|
2023-08-27 20:34:02 +02:00
|
|
|
}
|
2024-09-12 18:11:03 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
auto image = ImagePath::fromJson(config["image"]);
|
|
|
|
return std::make_shared<CFilledTexture>(image, rect);
|
|
|
|
}
|
2022-12-17 06:19:16 +02:00
|
|
|
}
|
|
|
|
|
2023-08-25 12:07:38 +02:00
|
|
|
std::shared_ptr<ComboBox> InterfaceObjectConfigurable::buildComboBox(const JsonNode & config)
|
|
|
|
{
|
|
|
|
logGlobal->debug("Building widget ComboBox");
|
|
|
|
auto position = readPosition(config["position"]);
|
2023-11-23 17:19:49 +02:00
|
|
|
auto dropDownPosition = readPosition(config["dropDownPosition"]);
|
2023-08-23 14:07:50 +02:00
|
|
|
auto image = AnimationPath::fromJson(config["image"]);
|
2023-08-25 12:07:38 +02:00
|
|
|
auto help = readHintText(config["help"]);
|
2023-11-23 17:19:49 +02:00
|
|
|
auto result = std::make_shared<ComboBox>(position, image, help, config["dropDown"], dropDownPosition);
|
|
|
|
|
2023-08-25 12:07:38 +02:00
|
|
|
if(!config["items"].isNull())
|
|
|
|
{
|
|
|
|
for(const auto & item : config["items"].Vector())
|
|
|
|
{
|
2024-02-27 22:19:09 +02:00
|
|
|
result->setOverlay(buildWidget(item));
|
2023-08-25 12:07:38 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if(!config["imageOrder"].isNull())
|
|
|
|
{
|
|
|
|
auto imgOrder = config["imageOrder"].Vector();
|
|
|
|
assert(imgOrder.size() >= 4);
|
|
|
|
result->setImageOrder(imgOrder[0].Integer(), imgOrder[1].Integer(), imgOrder[2].Integer(), imgOrder[3].Integer());
|
|
|
|
}
|
|
|
|
|
|
|
|
loadButtonBorderColor(result, config["borderColor"]);
|
|
|
|
loadButtonHotkey(result, config["hotkey"]);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-08-25 18:20:26 +02:00
|
|
|
std::shared_ptr<CTextInput> InterfaceObjectConfigurable::buildTextInput(const JsonNode & config) const
|
|
|
|
{
|
|
|
|
logGlobal->debug("Building widget CTextInput");
|
|
|
|
auto rect = readRect(config["rect"]);
|
|
|
|
auto offset = readPosition(config["backgroundOffset"]);
|
2023-08-23 14:07:50 +02:00
|
|
|
auto bgName = ImagePath::fromJson(config["background"]);
|
2024-05-12 16:17:49 +02:00
|
|
|
auto result = std::make_shared<CTextInput>(rect, offset, bgName);
|
2023-08-25 18:20:26 +02:00
|
|
|
if(!config["alignment"].isNull())
|
2024-05-12 16:17:49 +02:00
|
|
|
result->setAlignment(readTextAlignment(config["alignment"]));
|
2023-08-25 18:20:26 +02:00
|
|
|
if(!config["font"].isNull())
|
2024-05-12 16:17:49 +02:00
|
|
|
result->setFont(readFont(config["font"]));
|
2023-08-25 18:20:26 +02:00
|
|
|
if(!config["color"].isNull())
|
|
|
|
result->setColor(readColor(config["color"]));
|
2023-08-29 12:53:15 +02:00
|
|
|
if(!config["text"].isNull() && config["text"].isString())
|
|
|
|
result->setText(config["text"].String()); //for input field raw string is taken
|
2023-08-25 18:20:26 +02:00
|
|
|
if(!config["callback"].isNull())
|
2024-05-12 16:17:49 +02:00
|
|
|
result->setCallback(callbacks_string.at(config["callback"].String()));
|
2023-08-25 18:20:26 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-05-15 11:48:58 +02:00
|
|
|
/// Small helper class that provides ownership for shared_ptr's of child elements
|
|
|
|
class InterfaceLayoutWidget : public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
std::vector<std::shared_ptr<CIntObject>> ownedChildren;
|
2023-06-26 01:27:00 +02:00
|
|
|
InterfaceLayoutWidget();
|
2023-05-15 11:48:58 +02:00
|
|
|
};
|
|
|
|
|
2023-06-26 01:27:00 +02:00
|
|
|
InterfaceLayoutWidget::InterfaceLayoutWidget()
|
|
|
|
:CIntObject()
|
|
|
|
{
|
2023-07-03 18:24:12 +02:00
|
|
|
setRedrawParent(true);
|
2023-06-26 01:27:00 +02:00
|
|
|
}
|
|
|
|
|
2023-05-15 11:48:58 +02:00
|
|
|
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildLayout(const JsonNode & config)
|
|
|
|
{
|
|
|
|
logGlobal->debug("Building widget Layout");
|
|
|
|
bool vertical = config["vertical"].Bool();
|
|
|
|
bool horizontal = config["horizontal"].Bool();
|
|
|
|
bool dynamic = config["dynamic"].Bool();
|
|
|
|
int distance = config["distance"].Integer();
|
|
|
|
std::string customType = config["customType"].String();
|
|
|
|
auto position = readPosition(config["position"]);
|
|
|
|
|
|
|
|
auto result = std::make_shared<InterfaceLayoutWidget>();
|
|
|
|
result->moveBy(position);
|
|
|
|
Point layoutPosition;
|
|
|
|
|
|
|
|
for(auto item : config["items"].Vector())
|
|
|
|
{
|
|
|
|
if (item["type"].String().empty())
|
|
|
|
item["type"].String() = customType;
|
|
|
|
|
2023-05-19 22:19:43 +02:00
|
|
|
if (!item["created"].isNull())
|
|
|
|
{
|
|
|
|
std::string name = item["created"].String();
|
|
|
|
|
|
|
|
if (conditionals.count(name) != 0)
|
|
|
|
{
|
|
|
|
if (!conditionals.at(name))
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
logMod->warn("Unknown condition %s in widget!", name);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-15 11:48:58 +02:00
|
|
|
auto widget = buildWidget(item);
|
|
|
|
|
|
|
|
addWidget(item["name"].String(), widget);
|
|
|
|
result->ownedChildren.push_back(widget);
|
|
|
|
result->addChild(widget.get(), false);
|
|
|
|
|
|
|
|
widget->moveBy(position + layoutPosition);
|
|
|
|
|
|
|
|
if (dynamic && vertical)
|
|
|
|
layoutPosition.y += widget->pos.h;
|
|
|
|
if (dynamic && horizontal)
|
|
|
|
layoutPosition.x += widget->pos.w;
|
|
|
|
|
|
|
|
if (vertical)
|
|
|
|
layoutPosition.y += distance;
|
|
|
|
if (horizontal)
|
|
|
|
layoutPosition.x += distance;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2022-12-17 06:19:16 +02:00
|
|
|
std::shared_ptr<CShowableAnim> InterfaceObjectConfigurable::buildAnimation(const JsonNode & config) const
|
|
|
|
{
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget CShowableAnim");
|
2022-12-17 06:19:16 +02:00
|
|
|
auto position = readPosition(config["position"]);
|
2023-08-23 14:07:50 +02:00
|
|
|
auto image = AnimationPath::fromJson(config["image"]);
|
2022-12-17 06:19:16 +02:00
|
|
|
ui8 flags = 0;
|
|
|
|
if(!config["repeat"].Bool())
|
|
|
|
flags |= CShowableAnim::EFlags::PLAY_ONCE;
|
|
|
|
|
|
|
|
int group = config["group"].isNull() ? 0 : config["group"].Integer();
|
|
|
|
auto anim = std::make_shared<CShowableAnim>(position.x, position.y, image, flags, 4, group);
|
|
|
|
if(!config["alpha"].isNull())
|
|
|
|
anim->setAlpha(config["alpha"].Integer());
|
|
|
|
if(!config["callback"].isNull())
|
2023-08-25 18:20:26 +02:00
|
|
|
anim->callback = std::bind(callbacks_int.at(config["callback"].String()), 0);
|
2022-12-17 06:19:16 +02:00
|
|
|
if(!config["frames"].isNull())
|
|
|
|
{
|
|
|
|
auto b = config["frames"]["start"].Integer();
|
|
|
|
auto e = config["frames"]["end"].Integer();
|
|
|
|
anim->set(group, b, e);
|
|
|
|
}
|
|
|
|
return anim;
|
|
|
|
}
|
|
|
|
|
2024-01-18 16:23:12 +02:00
|
|
|
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildGraphicalPrimitive(const JsonNode & config) const
|
|
|
|
{
|
|
|
|
logGlobal->debug("Building widget GraphicalPrimitiveCanvas");
|
|
|
|
|
|
|
|
auto rect = readRect(config["rect"]);
|
|
|
|
auto widget = std::make_shared<GraphicalPrimitiveCanvas>(rect);
|
|
|
|
|
|
|
|
for (auto const & entry : config["primitives"].Vector())
|
|
|
|
{
|
|
|
|
auto color = readColor(entry["color"]);
|
2024-02-18 22:15:31 +02:00
|
|
|
auto typeString = entry["type"].String();
|
2024-01-18 16:23:12 +02:00
|
|
|
auto pointA = readPosition(entry["a"]);
|
|
|
|
auto pointB = readPosition(entry["b"]);
|
|
|
|
|
2024-02-18 22:15:31 +02:00
|
|
|
if (typeString == "line")
|
|
|
|
widget->addLine(pointA, pointB, color);
|
|
|
|
if (typeString == "filledBox")
|
|
|
|
widget->addBox(pointA, pointB, color);
|
|
|
|
if (typeString == "rectangle")
|
|
|
|
widget->addRectangle(pointA, pointB, color);
|
2024-01-18 16:23:12 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return widget;
|
|
|
|
}
|
|
|
|
|
2023-09-30 22:49:22 +02:00
|
|
|
std::shared_ptr<TransparentFilledRectangle> InterfaceObjectConfigurable::buildTransparentFilledRectangle(const JsonNode & config) const
|
|
|
|
{
|
|
|
|
logGlobal->debug("Building widget TransparentFilledRectangle");
|
|
|
|
|
|
|
|
auto rect = readRect(config["rect"]);
|
|
|
|
auto color = readColor(config["color"]);
|
|
|
|
if(!config["colorLine"].isNull())
|
|
|
|
{
|
|
|
|
auto colorLine = readColor(config["colorLine"]);
|
|
|
|
return std::make_shared<TransparentFilledRectangle>(rect, color, colorLine);
|
|
|
|
}
|
|
|
|
return std::make_shared<TransparentFilledRectangle>(rect, color);
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<CTextBox> InterfaceObjectConfigurable::buildTextBox(const JsonNode & config) const
|
|
|
|
{
|
|
|
|
logGlobal->debug("Building widget CTextBox");
|
|
|
|
|
|
|
|
auto rect = readRect(config["rect"]);
|
|
|
|
auto font = readFont(config["font"]);
|
|
|
|
auto alignment = readTextAlignment(config["alignment"]);
|
|
|
|
auto color = readColor(config["color"]);
|
|
|
|
auto text = readText(config["text"]);
|
2024-03-11 17:49:42 +02:00
|
|
|
auto blueTheme = config["blueTheme"].Bool();
|
2023-09-30 22:49:22 +02:00
|
|
|
|
2024-03-11 17:49:42 +02:00
|
|
|
return std::make_shared<CTextBox>(text, rect, blueTheme ? 1 : 0, font, alignment, color);
|
2023-09-30 22:49:22 +02:00
|
|
|
}
|
|
|
|
|
2022-12-17 18:38:16 +02:00
|
|
|
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildWidget(JsonNode config) const
|
2022-12-15 22:46:36 +02:00
|
|
|
{
|
|
|
|
assert(!config.isNull());
|
2022-12-21 23:13:32 +02:00
|
|
|
logGlobal->debug("Building widget from config");
|
2022-12-17 18:38:16 +02:00
|
|
|
//overrides from variables
|
|
|
|
for(auto & item : config["overrides"].Struct())
|
|
|
|
{
|
2023-10-18 01:41:02 +02:00
|
|
|
logGlobal->debug("Config attribute %s was overridden by variable %s", item.first, item.second.String());
|
2022-12-17 18:38:16 +02:00
|
|
|
config[item.first] = variables[item.second.String()];
|
|
|
|
}
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
auto type = config["type"].String();
|
2022-12-22 00:05:29 +02:00
|
|
|
auto buildIterator = builders.find(type);
|
|
|
|
if(buildIterator != builders.end())
|
|
|
|
return (buildIterator->second)(config);
|
2022-12-21 23:37:33 +02:00
|
|
|
|
2022-12-22 00:05:29 +02:00
|
|
|
logGlobal->error("Builder with type %s is not registered", type);
|
2022-12-15 22:57:10 +02:00
|
|
|
return nullptr;
|
|
|
|
}
|
2023-04-29 12:48:21 +02:00
|
|
|
|
|
|
|
void InterfaceObjectConfigurable::setShortcutBlocked(EShortcut shortcut, bool isBlocked)
|
|
|
|
{
|
2023-04-30 00:47:17 +02:00
|
|
|
auto target = shortcuts.find(shortcut);
|
2023-04-29 12:48:21 +02:00
|
|
|
if (target == shortcuts.end())
|
|
|
|
return;
|
|
|
|
|
|
|
|
target->second.blocked = isBlocked;
|
|
|
|
|
|
|
|
for (auto & entry : widgets)
|
|
|
|
{
|
|
|
|
auto button = std::dynamic_pointer_cast<CButton>(entry.second);
|
|
|
|
|
|
|
|
if (button && button->assignedKey == shortcut)
|
|
|
|
button->block(isBlocked);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceObjectConfigurable::addShortcut(EShortcut shortcut, std::function<void()> callback)
|
|
|
|
{
|
|
|
|
assert(shortcuts.count(shortcut) == 0);
|
|
|
|
shortcuts[shortcut].callback = callback;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InterfaceObjectConfigurable::keyPressed(EShortcut key)
|
|
|
|
{
|
|
|
|
auto target = shortcuts.find(key);
|
|
|
|
if (target == shortcuts.end())
|
|
|
|
return;
|
|
|
|
|
2024-05-19 10:23:28 +02:00
|
|
|
for (auto const & button :target->second.assignedButtons)
|
|
|
|
if (button->isActive())
|
|
|
|
return; // will be handled by button instance
|
2023-04-29 12:48:21 +02:00
|
|
|
|
|
|
|
if (target->second.blocked)
|
|
|
|
return;
|
|
|
|
|
|
|
|
target->second.callback();
|
|
|
|
}
|