mirror of
https://github.com/vcmi/vcmi.git
synced 2025-03-21 21:17:49 +02:00
code review
This commit is contained in:
parent
2eb4413978
commit
61aae7bccc
@ -56,6 +56,8 @@ InterfaceObjectConfigurable::InterfaceObjectConfigurable(int used, Point offset)
|
||||
REGISTER_BUILDER("layout", &InterfaceObjectConfigurable::buildLayout);
|
||||
REGISTER_BUILDER("comboBox", &InterfaceObjectConfigurable::buildComboBox);
|
||||
REGISTER_BUILDER("textInput", &InterfaceObjectConfigurable::buildTextInput);
|
||||
REGISTER_BUILDER("transparentFilledRectangle", &InterfaceObjectConfigurable::buildTransparentFilledRectangle);
|
||||
REGISTER_BUILDER("textBox", &InterfaceObjectConfigurable::buildTextBox);
|
||||
}
|
||||
|
||||
void InterfaceObjectConfigurable::registerBuilder(const std::string & type, BuilderFunction f)
|
||||
@ -684,6 +686,33 @@ std::shared_ptr<CShowableAnim> InterfaceObjectConfigurable::buildAnimation(const
|
||||
return anim;
|
||||
}
|
||||
|
||||
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"]);
|
||||
|
||||
return std::make_shared<CTextBox>(text, rect, 0, font, alignment, color);
|
||||
}
|
||||
|
||||
std::shared_ptr<CIntObject> InterfaceObjectConfigurable::buildWidget(JsonNode config) const
|
||||
{
|
||||
assert(!config.isNull());
|
||||
|
@ -29,6 +29,8 @@ class CShowableAnim;
|
||||
class CFilledTexture;
|
||||
class ComboBox;
|
||||
class CTextInput;
|
||||
class TransparentFilledRectangle;
|
||||
class CTextBox;
|
||||
|
||||
#define REGISTER_BUILDER(type, method) registerBuilder(type, std::bind(method, this, std::placeholders::_1))
|
||||
|
||||
@ -105,6 +107,8 @@ protected:
|
||||
std::shared_ptr<CIntObject> buildLayout(const JsonNode &);
|
||||
std::shared_ptr<ComboBox> buildComboBox(const JsonNode &);
|
||||
std::shared_ptr<CTextInput> buildTextInput(const JsonNode &) const;
|
||||
std::shared_ptr<TransparentFilledRectangle> buildTransparentFilledRectangle(const JsonNode & config) const;
|
||||
std::shared_ptr<CTextBox> buildTextBox(const JsonNode & config) const;
|
||||
|
||||
//composite widgets
|
||||
std::shared_ptr<CIntObject> buildWidget(JsonNode config) const;
|
||||
|
@ -134,20 +134,6 @@ std::vector<std::shared_ptr<IImage>> CMapOverview::CMapOverviewWidget::createMin
|
||||
return ret;
|
||||
}
|
||||
|
||||
std::shared_ptr<TransparentFilledRectangle> CMapOverview::CMapOverviewWidget::CMapOverviewWidget::buildDrawTransparentRect(const JsonNode & config) const
|
||||
{
|
||||
logGlobal->debug("Building widget drawTransparentRect");
|
||||
|
||||
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<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(const JsonNode & config) const
|
||||
{
|
||||
logGlobal->debug("Building widget drawMinimap");
|
||||
@ -158,11 +144,11 @@ std::shared_ptr<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(con
|
||||
if(!renderImage)
|
||||
return nullptr;
|
||||
|
||||
ResourcePath res = ResourcePath(parent.resource.getName(), EResType::MAP);
|
||||
ResourcePath res = ResourcePath(p.resource.getName(), EResType::MAP);
|
||||
std::unique_ptr<CMap> campaignMap = nullptr;
|
||||
if(parent.tabType != ESelectionScreen::newGame)
|
||||
if(p.tabType != ESelectionScreen::newGame)
|
||||
{
|
||||
CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION);
|
||||
CLoadFile lf(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::SAVEGAME)), MINIMAL_SERIALIZATION_VERSION);
|
||||
lf.checkMagicBytes(SAVEGAME_MAGIC);
|
||||
|
||||
std::unique_ptr<CMapHeader> mapHeader = std::make_unique<CMapHeader>();
|
||||
@ -187,54 +173,34 @@ std::shared_ptr<CPicture> CMapOverview::CMapOverviewWidget::buildDrawMinimap(con
|
||||
return std::make_shared<CPicture>(images[id], Point(rect.x, rect.y));
|
||||
}
|
||||
|
||||
std::shared_ptr<CTextBox> CMapOverview::CMapOverviewWidget::buildDrawPath(const JsonNode & config) const
|
||||
{
|
||||
logGlobal->debug("Building widget drawPath");
|
||||
|
||||
auto rect = readRect(config["rect"]);
|
||||
auto font = readFont(config["font"]);
|
||||
auto alignment = readTextAlignment(config["alignment"]);
|
||||
auto color = readColor(config["color"]);
|
||||
|
||||
return std::make_shared<CTextBox>(parent.fileName, rect, 0, font, alignment, color);
|
||||
}
|
||||
|
||||
std::shared_ptr<CLabel> CMapOverview::CMapOverviewWidget::buildDrawString(const JsonNode & config) const
|
||||
{
|
||||
logGlobal->debug("Building widget drawString");
|
||||
|
||||
auto font = readFont(config["font"]);
|
||||
auto alignment = readTextAlignment(config["alignment"]);
|
||||
auto color = readColor(config["color"]);
|
||||
std::string text = "";
|
||||
if("mapname" == config["text"].String())
|
||||
text = parent.mapName;
|
||||
if("date" == config["text"].String())
|
||||
{
|
||||
if(parent.date.empty())
|
||||
{
|
||||
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(parent.resource.getName(), EResType::MAP)));
|
||||
text = vstd::getFormattedDateTime(time);
|
||||
}
|
||||
else
|
||||
text = parent.date;
|
||||
}
|
||||
auto position = readPosition(config["position"]);
|
||||
return std::make_shared<CLabel>(position.x, position.y, font, alignment, color, text);
|
||||
}
|
||||
|
||||
CMapOverview::CMapOverviewWidget::CMapOverviewWidget(CMapOverview& parent):
|
||||
InterfaceObjectConfigurable(), parent(parent)
|
||||
InterfaceObjectConfigurable(), p(parent)
|
||||
{
|
||||
drawPlayerElements = parent.tabType == ESelectionScreen::newGame;
|
||||
drawPlayerElements = p.tabType == ESelectionScreen::newGame;
|
||||
renderImage = settings["lobby"]["mapPreview"].Bool();
|
||||
|
||||
const JsonNode config(JsonPath::builtin("config/widgets/mapOverview.json"));
|
||||
|
||||
REGISTER_BUILDER("drawTransparentRect", &CMapOverview::CMapOverviewWidget::buildDrawTransparentRect);
|
||||
REGISTER_BUILDER("drawMinimap", &CMapOverview::CMapOverviewWidget::buildDrawMinimap);
|
||||
REGISTER_BUILDER("drawPath", &CMapOverview::CMapOverviewWidget::buildDrawPath);
|
||||
REGISTER_BUILDER("drawString", &CMapOverview::CMapOverviewWidget::buildDrawString);
|
||||
|
||||
build(config);
|
||||
|
||||
if(auto w = widget<CTextBox>("fileName"))
|
||||
{
|
||||
w->setText(p.fileName);
|
||||
}
|
||||
if(auto w = widget<CLabel>("mapName"))
|
||||
{
|
||||
w->setText(p.mapName);
|
||||
}
|
||||
if(auto w = widget<CLabel>("date"))
|
||||
{
|
||||
if(p.date.empty())
|
||||
{
|
||||
std::time_t time = boost::filesystem::last_write_time(*CResourceHandler::get()->getResourceName(ResourcePath(p.resource.getName(), EResType::MAP)));
|
||||
w->setText(vstd::getFormattedDateTime(time));
|
||||
}
|
||||
else
|
||||
w->setText(p.date);
|
||||
}
|
||||
}
|
@ -30,7 +30,7 @@ class CMapOverview : public CWindowObject
|
||||
{
|
||||
class CMapOverviewWidget : public InterfaceObjectConfigurable
|
||||
{
|
||||
CMapOverview& parent;
|
||||
CMapOverview& p;
|
||||
|
||||
bool drawPlayerElements;
|
||||
bool renderImage;
|
||||
@ -38,12 +38,9 @@ class CMapOverview : public CWindowObject
|
||||
std::vector<std::shared_ptr<IImage>> createMinimaps(ResourcePath resource, Point size) const;
|
||||
std::vector<std::shared_ptr<IImage>> createMinimaps(std::unique_ptr<CMap> & map, Point size) const;
|
||||
|
||||
std::shared_ptr<TransparentFilledRectangle> buildDrawTransparentRect(const JsonNode & config) const;
|
||||
std::shared_ptr<CPicture> buildDrawMinimap(const JsonNode & config) const;
|
||||
std::shared_ptr<CTextBox> buildDrawPath(const JsonNode & config) const;
|
||||
std::shared_ptr<CLabel> buildDrawString(const JsonNode & config) const;
|
||||
public:
|
||||
CMapOverviewWidget(CMapOverview& parent);
|
||||
CMapOverviewWidget(CMapOverview& p);
|
||||
};
|
||||
|
||||
std::shared_ptr<CMapOverviewWidget> widget;
|
||||
|
@ -8,7 +8,7 @@
|
||||
"rect": {"w": 428, "h": 379}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 5, "w": 418, "h": 20},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
@ -22,21 +22,22 @@
|
||||
"position": {"x": 214, "y": 15}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 30, "w": 418, "h": 20},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
},
|
||||
{
|
||||
"type": "drawString",
|
||||
"type": "label",
|
||||
"name": "mapName",
|
||||
"font": "small",
|
||||
"alignment": "center",
|
||||
"color": "white",
|
||||
"text": "mapname",
|
||||
"text": "",
|
||||
"position": {"x": 214, "y": 40}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 55, "w": 418, "h": 20},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
@ -50,7 +51,7 @@
|
||||
"position": {"x": 214, "y": 65}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 29, "y": 79, "w": 171, "h": 171},
|
||||
"color": [0, 0, 0, 255],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
@ -61,7 +62,7 @@
|
||||
"rect": {"x": 30, "y": 80, "w": 169, "h": 169}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 228, "y": 79, "w": 171, "h": 171},
|
||||
"color": [0, 0, 0, 255],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
@ -72,7 +73,7 @@
|
||||
"rect": {"x": 229, "y": 80, "w": 169, "h": 169}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 254, "w": 418, "h": 20},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
@ -86,21 +87,22 @@
|
||||
"position": {"x": 214, "y": 264}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 279, "w": 418, "h": 20},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
},
|
||||
{
|
||||
"type": "drawString",
|
||||
"type": "label",
|
||||
"name": "date",
|
||||
"font": "small",
|
||||
"alignment": "center",
|
||||
"color": "white",
|
||||
"text": "date",
|
||||
"text": "",
|
||||
"position": {"x": 214, "y": 289}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 304, "w": 418, "h": 20},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
@ -114,16 +116,18 @@
|
||||
"position": {"x": 214, "y": 314}
|
||||
},
|
||||
{
|
||||
"type": "drawTransparentRect",
|
||||
"type": "transparentFilledRectangle",
|
||||
"rect": {"x": 5, "y": 329, "w": 418, "h": 45},
|
||||
"color": [0, 0, 0, 75],
|
||||
"colorLine": [128, 100, 75, 255]
|
||||
},
|
||||
{
|
||||
"type": "drawPath",
|
||||
"type": "textBox",
|
||||
"name": "fileName",
|
||||
"font": "small",
|
||||
"alignment": "center",
|
||||
"color": "white",
|
||||
"text": "",
|
||||
"rect": {"x": 10, "y": 334, "w": 408, "h": 35}
|
||||
}
|
||||
]
|
||||
|
Loading…
x
Reference in New Issue
Block a user