diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-28 18:18:13 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-28 18:18:13 +0300 |
commit | 8cd16a9a9ca605137276379361b0328af736c2cc (patch) | |
tree | 5a0c52367d604c42e0bcd7bdf26665900b179166 /src | |
parent | 0cdc936ea83fe265fb6bd1d128b10ff6b53e6254 (diff) | |
download | manaverse-8cd16a9a9ca605137276379361b0328af736c2cc.tar.gz manaverse-8cd16a9a9ca605137276379361b0328af736c2cc.tar.bz2 manaverse-8cd16a9a9ca605137276379361b0328af736c2cc.tar.xz manaverse-8cd16a9a9ca605137276379361b0328af736c2cc.zip |
Add support for add images into buttons in skinned npc dialogs.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/widgets/button.h | 6 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 20 | ||||
-rw-r--r-- | src/resources/db/npcdialogdb.cpp | 14 | ||||
-rw-r--r-- | src/resources/npcbuttoninfo.h | 8 |
4 files changed, 39 insertions, 9 deletions
diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index cb96fa7e3..67ba32da8 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -253,6 +253,12 @@ class Button final : public Widget, void setWindow(Widget *const widget) override final; + void setImageWidth(const int width) + { mImageWidth = width; } + + void setImageHeight(const int height) + { mImageHeight = height; } + enum { BUTTON_STANDARD = 0, // 0 diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 8e9ef526a..bb6a84eb7 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -1146,12 +1146,22 @@ void NpcDialog::createSkinControls() FOR_EACH (std::vector<NpcButtonInfo*>::const_iterator, it, dialog->buttons) { const NpcButtonInfo *const info = *it; - Button *const button = new Button(this, - info->name, - "skin_" + info->value, - this); - + Button *const button = new Button(this); + button->setCaption(info->name); + button->setActionEventId("skin_" + info->value); + button->addActionListener(this); button->setPosition(info->x, info->y); + if (!info->image.empty()) + { + button->setImageWidth(info->imageWidth); + button->setImageHeight(info->imageHeight); + button->loadImageSet(info->image); + } mSkinContainer->add(button); + logger->log("test 1"); + button->adjustSize(); + logger->log("test 2"); + button->setWidth(20); + button->setHeight(20); } } diff --git a/src/resources/db/npcdialogdb.cpp b/src/resources/db/npcdialogdb.cpp index 628ee233e..cf334a601 100644 --- a/src/resources/db/npcdialogdb.cpp +++ b/src/resources/db/npcdialogdb.cpp @@ -56,9 +56,6 @@ static void loadNpcDialog(NpcDialogInfo *const dialog, if (xmlNameEqual(childNode, "button")) { const std::string name = XML::getProperty(childNode, "name", ""); - if (name.empty()) - continue; - const std::string value = XML::getProperty(childNode, "value", ""); if (value.empty()) continue; @@ -70,6 +67,17 @@ static void loadNpcDialog(NpcDialogInfo *const dialog, childNode, "y", 0, 0, 10000); button->name = name; button->value = value; + button->image = XML::getProperty(childNode, "image", ""); + if (button->name.empty() && button->image.empty()) + { + logger->log("Error: npc button without name or image"); + delete button; + continue; + } + button->imageWidth = XML::getIntProperty( + childNode, "imageWidth", 16, 1, 1000); + button->imageHeight = XML::getIntProperty( + childNode, "imageHeight", 16, 1, 1000); dialog->buttons.push_back(button); } } diff --git a/src/resources/npcbuttoninfo.h b/src/resources/npcbuttoninfo.h index 19de87891..d54b7d94c 100644 --- a/src/resources/npcbuttoninfo.h +++ b/src/resources/npcbuttoninfo.h @@ -30,15 +30,21 @@ struct NpcButtonInfo final NpcButtonInfo() : name(), value(), + image(), x(0), - y(0) + y(0), + imageWidth(16), + imageHeight(16) { } std::string name; std::string value; + std::string image; int x; int y; + int imageWidth; + int imageHeight; }; #endif // RESOURCES_NPCBUTTONINFO_H |