diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-28 21:02:57 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-28 22:52:27 +0300 |
commit | ed17aa400a745a81940020e024a3944671a47281 (patch) | |
tree | eac1fe8c0a1e4f1cac2fce2614c002dd449141dd | |
parent | 519c7cfaccac61beaa84751b7dfeed1c50600bed (diff) | |
download | mv-ed17aa400a745a81940020e024a3944671a47281.tar.gz mv-ed17aa400a745a81940020e024a3944671a47281.tar.bz2 mv-ed17aa400a745a81940020e024a3944671a47281.tar.xz mv-ed17aa400a745a81940020e024a3944671a47281.zip |
Add text object to skined npc menus.
-rw-r--r-- | src/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/Makefile.am | 1 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 26 | ||||
-rw-r--r-- | src/resources/db/npcdialogdb.cpp | 22 | ||||
-rw-r--r-- | src/resources/npcdialoginfo.h | 2 | ||||
-rw-r--r-- | src/resources/npctextinfo.h | 46 |
6 files changed, 97 insertions, 1 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 474354b95..04c906dd8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -675,6 +675,7 @@ SET(SRCS resources/npcbuttoninfo.h resources/npcdialoginfo.h resources/npcimageinfo.h + resources/npctextinfo.h enums/resources/notifyflags.h enums/resources/notifytypes.h resources/db/monsterdb.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 7a29b24cb..65ae3ace3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -340,6 +340,7 @@ SRC += events/actionevent.h \ resources/npcbuttoninfo.h \ resources/npcdialoginfo.h \ resources/npcimageinfo.h \ + resources/npctextinfo.h \ enums/resources/notifyflags.h \ enums/resources/notifytypes.h \ resources/imagerect.h \ diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 9d96336b1..f5639acd8 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -1173,7 +1173,31 @@ void NpcDialog::createSkinControls() mSkinContainer->add(icon); } } - + FOR_EACH (std::vector<NpcTextInfo*>::const_iterator, it, dialog->texts) + { + const NpcTextInfo *const info = *it; + BrowserBox *box = new BrowserBox(this, + BrowserBox::AUTO_WRAP, + true, + "browserbox.xml"); + box->setOpaque(false); + box->setMaxRow(config.getIntValue("ChatLogLength")); + box->setLinkHandler(mItemLinkHandler); + box->setProcessVars(true); + box->setFont(gui->getNpcFont()); + box->setEnableKeys(true); + box->setEnableTabs(true); + box->setPosition(info->x, info->y); + mSkinContainer->add(box); + box->setWidth(info->width); + box->setHeight(info->height); + StringVect parts; + splitToStringVector(parts, info->text, '\n'); + FOR_EACH (StringVectCIter, it2, parts) + { + box->addRow(*it2); + } + } FOR_EACH (std::vector<NpcButtonInfo*>::const_iterator, it, dialog->buttons) { const NpcButtonInfo *const info = *it; diff --git a/src/resources/db/npcdialogdb.cpp b/src/resources/db/npcdialogdb.cpp index 86bc712f2..22dbb9b79 100644 --- a/src/resources/db/npcdialogdb.cpp +++ b/src/resources/db/npcdialogdb.cpp @@ -96,6 +96,26 @@ static void loadNpcDialog(NpcDialogInfo *const dialog, childNode, "y", 0, 0, 10000); dialog->images.push_back(imageInfo); } + else if (xmlNameEqual(childNode, "text")) + { + const std::string text = XML::getProperty(childNode, "text", ""); + if (text.empty()) + { + logger->log("Error: no text attribute found in text tag."); + continue; + } + NpcTextInfo *const textInfo = new NpcTextInfo; + textInfo->text = text; + textInfo->x = XML::getIntProperty( + childNode, "x", 0, 0, 10000); + textInfo->y = XML::getIntProperty( + childNode, "y", 0, 0, 10000); + textInfo->width = XML::getIntProperty( + childNode, "width", 20, 10, 10000); + textInfo->height = XML::getIntProperty( + childNode, "height", 20, 10, 10000); + dialog->texts.push_back(textInfo); + } } } @@ -149,6 +169,7 @@ void NpcDialogDB::deleteDialog(const std::string &name) NpcDialogInfo *dialog = (*it).second; delete_all(dialog->buttons); delete_all(dialog->images); + delete_all(dialog->texts); mDialogs.erase(it); delete dialog; } @@ -162,6 +183,7 @@ void NpcDialogDB::unload() NpcDialogInfo *dialog = (*it).second; delete_all(dialog->buttons); delete_all(dialog->images); + delete_all(dialog->texts); delete dialog; } mDialogs.clear(); diff --git a/src/resources/npcdialoginfo.h b/src/resources/npcdialoginfo.h index aa73d2c01..e6fe6e331 100644 --- a/src/resources/npcdialoginfo.h +++ b/src/resources/npcdialoginfo.h @@ -23,6 +23,7 @@ #include "resources/npcbuttoninfo.h" #include "resources/npcimageinfo.h" +#include "resources/npctextinfo.h" #include "utils/stringvector.h" @@ -40,6 +41,7 @@ struct NpcDialogInfo final std::vector<NpcButtonInfo*> buttons; std::vector<NpcImageInfo*> images; + std::vector<NpcTextInfo*> texts; std::string name; bool hideText; }; diff --git a/src/resources/npctextinfo.h b/src/resources/npctextinfo.h new file mode 100644 index 000000000..78b9fbf1d --- /dev/null +++ b/src/resources/npctextinfo.h @@ -0,0 +1,46 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011-2015 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see <http://www.gnu.org/licenses/>. + */ + +#ifndef RESOURCES_NPCTEXTINFO_H +#define RESOURCES_NPCTEXTINFO_H + +#include <string> + +#include "localconsts.h" + +struct NpcTextInfo final +{ + NpcTextInfo() : + text(), + x(0), + y(0), + width(32), + height(32) + { + } + + std::string text; + int x; + int y; + int width; + int height; +}; + +#endif // RESOURCES_NPCTEXTINFO_H |