|
@@ -20,6 +20,7 @@
|
|
#include "../render/Graphics.h"
|
|
#include "../render/Graphics.h"
|
|
#include "../render/IFont.h"
|
|
#include "../render/IFont.h"
|
|
#include "../widgets/CComponent.h"
|
|
#include "../widgets/CComponent.h"
|
|
|
|
+#include "../widgets/ComboBox.h"
|
|
#include "../widgets/Buttons.h"
|
|
#include "../widgets/Buttons.h"
|
|
#include "../widgets/MiscWidgets.h"
|
|
#include "../widgets/MiscWidgets.h"
|
|
#include "../widgets/ObjectLists.h"
|
|
#include "../widgets/ObjectLists.h"
|
|
@@ -52,6 +53,8 @@ InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset)
|
|
REGISTER_BUILDER("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
|
|
REGISTER_BUILDER("labelGroup", &InterfaceObjectConfigurable::buildLabelGroup);
|
|
REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
|
|
REGISTER_BUILDER("slider", &InterfaceObjectConfigurable::buildSlider);
|
|
REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
|
|
REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
|
|
|
|
+ REGISTER_BUILDER("comboBox", &InterfaceObjectConfigurable::buildComboBox);
|
|
|
|
+ REGISTER_BUILDER("textInput", &InterfaceObjectConfigurable::buildTextInput);
|
|
}
|
|
}
|
|
|
|
|
|
void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
|
|
void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
|
|
@@ -61,9 +64,15 @@ void InterfaceObjectConfigurable::registerBuilder(const std::string & type, Buil
|
|
|
|
|
|
void InterfaceObjectConfigurable::addCallback(const std::string & callbackName, std::function<void(int)> callback)
|
|
void InterfaceObjectConfigurable::addCallback(const std::string & callbackName, std::function<void(int)> callback)
|
|
{
|
|
{
|
|
- callbacks[callbackName] = callback;
|
|
|
|
|
|
+ callbacks_int[callbackName] = callback;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void InterfaceObjectConfigurable::addCallback(const std::string & callbackName, std::function<void(std::string)> callback)
|
|
|
|
+{
|
|
|
|
+ callbacks_string[callbackName] = callback;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+
|
|
void InterfaceObjectConfigurable::deleteWidget(const std::string & name)
|
|
void InterfaceObjectConfigurable::deleteWidget(const std::string & name)
|
|
{
|
|
{
|
|
auto iter = widgets.find(name);
|
|
auto iter = widgets.find(name);
|
|
@@ -338,7 +347,7 @@ std::shared_ptr<CToggleGroup> InterfaceObjectConfigurable::buildToggleGroup(cons
|
|
if(!config["selected"].isNull())
|
|
if(!config["selected"].isNull())
|
|
group->setSelected(config["selected"].Integer());
|
|
group->setSelected(config["selected"].Integer());
|
|
if(!config["callback"].isNull())
|
|
if(!config["callback"].isNull())
|
|
- group->addCallback(callbacks.at(config["callback"].String()));
|
|
|
|
|
|
+ group->addCallback(callbacks_int.at(config["callback"].String()));
|
|
return group;
|
|
return group;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -411,8 +420,8 @@ void InterfaceObjectConfigurable::loadToggleButtonCallback(std::shared_ptr<CTogg
|
|
|
|
|
|
std::string callbackName = config.String();
|
|
std::string callbackName = config.String();
|
|
|
|
|
|
- if (callbacks.count(callbackName) > 0)
|
|
|
|
- button->addCallback(callbacks.at(callbackName));
|
|
|
|
|
|
+ if (callbacks_int.count(callbackName) > 0)
|
|
|
|
+ button->addCallback(callbacks_int.at(callbackName));
|
|
else
|
|
else
|
|
logGlobal->error("Invalid callback '%s' in widget", callbackName );
|
|
logGlobal->error("Invalid callback '%s' in widget", callbackName );
|
|
}
|
|
}
|
|
@@ -424,8 +433,8 @@ void InterfaceObjectConfigurable::loadButtonCallback(std::shared_ptr<CButton> bu
|
|
|
|
|
|
std::string callbackName = config.String();
|
|
std::string callbackName = config.String();
|
|
|
|
|
|
- if (callbacks.count(callbackName) > 0)
|
|
|
|
- button->addCallback(std::bind(callbacks.at(callbackName), 0));
|
|
|
|
|
|
+ if (callbacks_int.count(callbackName) > 0)
|
|
|
|
+ button->addCallback(std::bind(callbacks_int.at(callbackName), 0));
|
|
else
|
|
else
|
|
logGlobal->error("Invalid callback '%s' in widget", callbackName );
|
|
logGlobal->error("Invalid callback '%s' in widget", callbackName );
|
|
}
|
|
}
|
|
@@ -481,7 +490,7 @@ std::shared_ptr<CSlider> InterfaceObjectConfigurable::buildSlider(const JsonNode
|
|
auto value = config["selected"].Integer();
|
|
auto value = config["selected"].Integer();
|
|
bool horizontal = config["orientation"].String() == "horizontal";
|
|
bool horizontal = config["orientation"].String() == "horizontal";
|
|
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_int.at(config["callback"].String()), itemsVisible, itemsTotal, value, horizontal ? Orientation::HORIZONTAL : Orientation::VERTICAL, style);
|
|
|
|
|
|
if(!config["scrollBounds"].isNull())
|
|
if(!config["scrollBounds"].isNull())
|
|
{
|
|
{
|
|
@@ -513,6 +522,54 @@ std::shared_ptr<CFilledTexture> InterfaceObjectConfigurable::buildTexture(const
|
|
return std::make_shared<CFilledTexture>(image, rect);
|
|
return std::make_shared<CFilledTexture>(image, rect);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+std::shared_ptr<ComboBox> InterfaceObjectConfigurable::buildComboBox(const JsonNode & config)
|
|
|
|
+{
|
|
|
|
+ logGlobal->debug("Building widget ComboBox");
|
|
|
|
+ auto position = readPosition(config["position"]);
|
|
|
|
+ auto image = config["image"].String();
|
|
|
|
+ auto help = readHintText(config["help"]);
|
|
|
|
+ auto result = std::make_shared<ComboBox>(position, image, help, config["dropDown"]);
|
|
|
|
+ if(!config["items"].isNull())
|
|
|
|
+ {
|
|
|
|
+ for(const auto & item : config["items"].Vector())
|
|
|
|
+ {
|
|
|
|
+ result->addOverlay(buildWidget(item));
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ 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;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+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"]);
|
|
|
|
+ auto bgName = config["background"].String();
|
|
|
|
+ auto result = std::make_shared<CTextInput>(rect, offset, bgName, 0);
|
|
|
|
+ if(!config["alignment"].isNull())
|
|
|
|
+ result->alignment = readTextAlignment(config["alignment"]);
|
|
|
|
+ if(!config["font"].isNull())
|
|
|
|
+ result->font = readFont(config["font"]);
|
|
|
|
+ if(!config["color"].isNull())
|
|
|
|
+ result->setColor(readColor(config["color"]));
|
|
|
|
+ if(!config["text"].isNull())
|
|
|
|
+ result->setText(readText(config["text"]));
|
|
|
|
+ if(!config["callback"].isNull())
|
|
|
|
+ result->cb += callbacks_string.at(config["callback"].String());
|
|
|
|
+ if(!config["help"].isNull())
|
|
|
|
+ result->setHelpText(readText(config["help"]));
|
|
|
|
+ return result;
|
|
|
|
+}
|
|
|
|
+
|
|
/// Small helper class that provides ownership for shared_ptr's of child elements
|
|
/// Small helper class that provides ownership for shared_ptr's of child elements
|
|
class InterfaceLayoutWidget : public CIntObject
|
|
class InterfaceLayoutWidget : public CIntObject
|
|
{
|
|
{
|
|
@@ -597,7 +654,7 @@ std::shared_ptr<CShowableAnim> InterfaceObjectConfigurable::buildAnimation(const
|
|
if(!config["alpha"].isNull())
|
|
if(!config["alpha"].isNull())
|
|
anim->setAlpha(config["alpha"].Integer());
|
|
anim->setAlpha(config["alpha"].Integer());
|
|
if(!config["callback"].isNull())
|
|
if(!config["callback"].isNull())
|
|
- anim->callback = std::bind(callbacks.at(config["callback"].String()), 0);
|
|
|
|
|
|
+ anim->callback = std::bind(callbacks_int.at(config["callback"].String()), 0);
|
|
if(!config["frames"].isNull())
|
|
if(!config["frames"].isNull())
|
|
{
|
|
{
|
|
auto b = config["frames"]["start"].Integer();
|
|
auto b = config["frames"]["start"].Integer();
|