diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-10-27 17:31:26 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-10-27 18:37:33 +0300 |
commit | 2433741a77ba0f08f4243a9482d3cf95cfe9edf3 (patch) | |
tree | 193fcf05c35fcc5096302482598abfe299270996 /src | |
parent | d3010ba93e3f30b4af2314434c21f114459b8ef7 (diff) | |
download | mv-2433741a77ba0f08f4243a9482d3cf95cfe9edf3.tar.gz mv-2433741a77ba0f08f4243a9482d3cf95cfe9edf3.tar.bz2 mv-2433741a77ba0f08f4243a9482d3cf95cfe9edf3.tar.xz mv-2433741a77ba0f08f4243a9482d3cf95cfe9edf3.zip |
Impliment npc menu skins based on previous commits.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/windows/npcdialog.cpp | 92 | ||||
-rw-r--r-- | src/gui/windows/npcdialog.h | 11 | ||||
-rw-r--r-- | src/resources/db/npcdialogdb.cpp | 8 | ||||
-rw-r--r-- | src/resources/db/npcdialogdb.h | 4 |
4 files changed, 114 insertions, 1 deletions
diff --git a/src/gui/windows/npcdialog.cpp b/src/gui/windows/npcdialog.cpp index 32bf7bdab..8e9ef526a 100644 --- a/src/gui/windows/npcdialog.cpp +++ b/src/gui/windows/npcdialog.cpp @@ -56,6 +56,7 @@ #include "resources/db/avatardb.h" #include "resources/db/npcdb.h" +#include "resources/db/npcdialogdb.h" #include "net/npchandler.h" #include "net/packetlimiter.h" @@ -99,6 +100,9 @@ NpcDialog::NpcDialog(const BeingId npcId) : this, this, "extendedlistbox.xml")), mListScrollArea(new ScrollArea(this, mItemList, getOptionBool("showlistbackground"), "npc_listbackground.xml")), + mSkinContainer(new Container(this)), + mSkinScrollArea(new ScrollArea(this, mSkinContainer, + getOptionBool("showlistbackground"), "npc_listbackground.xml")), mItems(), mImages(), mItemLinkHandler(new ItemLinkHandler), @@ -123,6 +127,8 @@ NpcDialog::NpcDialog(const BeingId npcId) : getOptionBool("showitemsbackground"), "npc_listbackground.xml")), mInputState(NPC_INPUT_NONE), mActionState(NPC_ACTION_WAIT), + mSkinControls(), + mSkinName(), mPlayerBox(new PlayerBox(nullptr)), mAvatarBeing(nullptr), mLastNextTime(0), @@ -172,6 +178,8 @@ NpcDialog::NpcDialog(const BeingId npcId) : setContentSize(260, 175); mListScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); mItemScrollArea->setHorizontalScrollPolicy(ScrollArea::SHOW_NEVER); + mSkinScrollArea->setScrollPolicy(ScrollArea::SHOW_NEVER, + ScrollArea::SHOW_NEVER); mItemList->setVisible(Visible_true); mTextField->setVisible(Visible_true); mIntField->setVisible(Visible_true); @@ -226,6 +234,8 @@ NpcDialog::~NpcDialog() delete mPlayerBox; } + deleteSkinControls(); + delete2(mTextBox); delete2(mClearButton); delete2(mButton); @@ -243,6 +253,7 @@ NpcDialog::~NpcDialog() delete2(mInventory); delete2(mItemScrollArea); delete2(mListScrollArea); + delete2(mSkinScrollArea); FOR_EACH (ImageVectorIter, it, mImages) { @@ -546,6 +557,29 @@ void NpcDialog::action(const ActionEvent &event) } } } + else if (eventId.find("skin_") == 0) + { + const std::string cmd = eventId.substr(5); + std::string printText; + int cnt = 0; + FOR_EACH(StringVectCIter, it, mItems) + { + if (cmd == *it) + { + npcHandler->listInput(mNpcId, cnt + 1); + printText = mItems[cnt]; + break; + } + cnt ++; + } + if (mInputState != NPC_INPUT_ITEM && + mInputState != NPC_INPUT_ITEM_INDEX) + { + // addText will auto remove the input layout + addText(strprintf("> \"%s\"", printText.c_str()), false); + } + mNewText.clear(); + } } void NpcDialog::nextDialog() @@ -791,6 +825,28 @@ void NpcDialog::placeMenuControls() } } +void NpcDialog::placeSkinControls() +{ + createSkinControls(); + if (mShowAvatar) + { + place(0, 0, mPlayerBox); + place(1, 0, mScrollArea, 6, 3); + place(0, 3, mSkinScrollArea, 7, 3); + place(1, 6, mButton2, 2); + place(3, 6, mClearButton, 2); + place(5, 6, mButton, 2); + } + else + { + place(0, 0, mScrollArea, 6, 3); + place(0, 3, mSkinScrollArea, 6, 3); + place(0, 6, mButton2, 2); + place(2, 6, mClearButton, 2); + place(4, 6, mButton, 2); + } +} + void NpcDialog::placeTextInputControls() { if (mShowAvatar) @@ -878,7 +934,10 @@ void NpcDialog::buildLayout() switch (mInputState) { case NPC_INPUT_LIST: - placeMenuControls(); + if (mSkinName.empty()) + placeMenuControls(); + else + placeSkinControls(); mItemList->setSelected(-1); break; @@ -1064,4 +1123,35 @@ void NpcDialog::copyToClipboard(const BeingId npcId, void NpcDialog::setSkin(const std::string &skin) { + mSkinName = skin; +} + +void NpcDialog::deleteSkinControls() +{ + mSkinContainer->removeControls(); +} + +void NpcDialog::createSkinControls() +{ + deleteSkinControls(); + + const NpcDialogInfo *const dialog = NpcDialogDB::getDialog(mSkinName); + if (!dialog) + { + logger->log("Error: creating controls for not existing npc dialog %s", + mSkinName.c_str()); + return; + } + + 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->setPosition(info->x, info->y); + mSkinContainer->add(button); + } } diff --git a/src/gui/windows/npcdialog.h b/src/gui/windows/npcdialog.h index 4f6a0f3cf..6c6ea7fba 100644 --- a/src/gui/windows/npcdialog.h +++ b/src/gui/windows/npcdialog.h @@ -35,6 +35,7 @@ class Being; class Button; class BrowserBox; +class Container; class ExtendedListBox; class ItemLinkHandler; class Inventory; @@ -233,12 +234,18 @@ class NpcDialog final : public Window, void placeMenuControls(); + void placeSkinControls(); + void placeTextInputControls(); void placeIntInputControls(); void placeItemInputControls(); + void createSkinControls(); + + void deleteSkinControls(); + BeingId mNpcId; int mDefaultInt; @@ -253,6 +260,8 @@ class NpcDialog final : public Window, // Used for choice input ExtendedListBox *mItemList A_NONNULLPOINTER; ScrollArea *mListScrollArea A_NONNULLPOINTER; + Container *mSkinContainer A_NONNULLPOINTER; + ScrollArea *mSkinScrollArea A_NONNULLPOINTER; StringVect mItems; std::vector<Image *> mImages; ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER; @@ -296,6 +305,8 @@ class NpcDialog final : public Window, NpcInputState mInputState; NpcActionState mActionState; + std::vector<Widget*> mSkinControls; + std::string mSkinName; PlayerBox *mPlayerBox A_NONNULLPOINTER; Being *mAvatarBeing; int mLastNextTime; diff --git a/src/resources/db/npcdialogdb.cpp b/src/resources/db/npcdialogdb.cpp index 79918307a..628ee233e 100644 --- a/src/resources/db/npcdialogdb.cpp +++ b/src/resources/db/npcdialogdb.cpp @@ -140,3 +140,11 @@ void NpcDialogDB::unload() mLoaded = false; } + +NpcDialogInfo *NpcDialogDB::getDialog(const std::string &name) +{ + DialogsIter it = mDialogs.find(name); + if (it == mDialogs.end()) + return nullptr; + return (*it).second; +} diff --git a/src/resources/db/npcdialogdb.h b/src/resources/db/npcdialogdb.h index 8b2caac65..d77826ab3 100644 --- a/src/resources/db/npcdialogdb.h +++ b/src/resources/db/npcdialogdb.h @@ -27,6 +27,8 @@ #include "localconsts.h" +class Widget; + /** * Color information database. */ @@ -46,6 +48,8 @@ namespace NpcDialogDB void deleteDialog(const std::string &name); + NpcDialogInfo *getDialog(const std::string &name); + typedef std::map<std::string, NpcDialogInfo*> Dialogs; typedef Dialogs::iterator DialogsIter; |