2022-12-12 09:48:39 +02:00
|
|
|
/*
|
|
|
|
* 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"
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
class CPicture;
|
|
|
|
class CLabel;
|
|
|
|
class CToggleGroup;
|
|
|
|
class CToggleButton;
|
|
|
|
class CButton;
|
|
|
|
class CLabelGroup;
|
2022-12-16 00:15:53 +02:00
|
|
|
class CSlider;
|
2022-12-17 06:19:16 +02:00
|
|
|
class CAnimImage;
|
|
|
|
class CShowableAnim;
|
|
|
|
class CFilledTexture;
|
2022-12-15 22:46:36 +02:00
|
|
|
|
2022-12-12 09:48:39 +02:00
|
|
|
class InterfaceObjectConfigurable: public CIntObject
|
|
|
|
{
|
|
|
|
public:
|
2022-12-16 00:15:53 +02:00
|
|
|
InterfaceObjectConfigurable(int used=0, Point offset=Point());
|
|
|
|
InterfaceObjectConfigurable(const JsonNode & config, int used=0, Point offset=Point());
|
2022-12-12 09:48:39 +02:00
|
|
|
|
|
|
|
protected:
|
|
|
|
//must be called after adding callbacks
|
|
|
|
void init(const JsonNode & config);
|
|
|
|
|
|
|
|
void addCallback(const std::string & callbackName, std::function<void(int)> callback);
|
|
|
|
|
|
|
|
template<class T>
|
|
|
|
const std::shared_ptr<T> widget(const std::string & name) const
|
|
|
|
{
|
|
|
|
auto iter = widgets.find(name);
|
|
|
|
if(iter == widgets.end())
|
|
|
|
return nullptr;
|
|
|
|
return std::dynamic_pointer_cast<T>(iter->second);
|
|
|
|
}
|
|
|
|
|
2022-12-16 00:15:53 +02:00
|
|
|
const JsonNode & variable(const std::string & name) const;
|
2022-12-15 22:57:10 +02:00
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
//basic serializers
|
|
|
|
Point readPosition(const JsonNode &) const;
|
2022-12-17 06:19:16 +02:00
|
|
|
Rect readRect(const JsonNode &) const;
|
2022-12-15 22:46:36 +02:00
|
|
|
ETextAlignment readTextAlignment(const JsonNode &) const;
|
|
|
|
SDL_Color readColor(const JsonNode &) const;
|
|
|
|
EFonts readFont(const JsonNode &) const;
|
|
|
|
std::string readText(const JsonNode &) const;
|
|
|
|
std::pair<std::string, std::string> readHintText(const JsonNode &) const;
|
|
|
|
|
|
|
|
//basic widgets
|
|
|
|
std::shared_ptr<CPicture> buildPicture(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CLabel> buildLabel(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CToggleGroup> buildToggleGroup(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CToggleButton> buildToggleButton(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CButton> buildButton(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CLabelGroup> buildLabelGroup(const JsonNode &) const;
|
2022-12-16 00:15:53 +02:00
|
|
|
std::shared_ptr<CSlider> buildSlider(const JsonNode &) const;
|
2022-12-17 06:19:16 +02:00
|
|
|
std::shared_ptr<CAnimImage> buildImage(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CShowableAnim> buildAnimation(const JsonNode &) const;
|
|
|
|
std::shared_ptr<CFilledTexture> buildTexture(const JsonNode &) const;
|
|
|
|
|
2022-12-15 22:46:36 +02:00
|
|
|
|
2022-12-16 00:15:53 +02:00
|
|
|
//composite widgets
|
|
|
|
virtual std::shared_ptr<CIntObject> buildCustomWidget(const JsonNode & config);
|
2022-12-15 22:46:36 +02:00
|
|
|
std::shared_ptr<CIntObject> buildWidget(const JsonNode & config) const;
|
|
|
|
|
2022-12-12 09:48:39 +02:00
|
|
|
private:
|
|
|
|
|
|
|
|
std::map<std::string, std::shared_ptr<CIntObject>> widgets;
|
|
|
|
std::map<std::string, std::function<void(int)>> callbacks;
|
2022-12-16 00:15:53 +02:00
|
|
|
JsonNode variables;
|
2022-12-12 09:48:39 +02:00
|
|
|
};
|