From 2433741a77ba0f08f4243a9482d3cf95cfe9edf3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 27 Oct 2015 17:31:26 +0300 Subject: Impliment npc menu skins based on previous commits. --- src/gui/windows/npcdialog.cpp | 92 ++++++++++++++++++++++++++++++++++++++++++- src/gui/windows/npcdialog.h | 11 ++++++ 2 files changed, 102 insertions(+), 1 deletion(-) (limited to 'src/gui/windows') 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::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 mImages; ItemLinkHandler *mItemLinkHandler A_NONNULLPOINTER; @@ -296,6 +305,8 @@ class NpcDialog final : public Window, NpcInputState mInputState; NpcActionState mActionState; + std::vector mSkinControls; + std::string mSkinName; PlayerBox *mPlayerBox A_NONNULLPOINTER; Being *mAvatarBeing; int mLastNextTime; -- cgit v1.2.3-70-g09d2