summaryrefslogtreecommitdiff
path: root/src/gui/npcdialog.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-07-27 02:32:32 +0300
committerAndrei Karas <akaras@inbox.ru>2012-07-28 00:47:21 +0300
commitc9bb66d595927bd14871c10b216ed05ffb5e3b12 (patch)
treeaef6dc1911678dd813c64b3397ac13bbad7de622 /src/gui/npcdialog.cpp
parent54f3d4ce98b81a744ef6c0068100f4eb36a6528b (diff)
downloadmanaverse-c9bb66d595927bd14871c10b216ed05ffb5e3b12.tar.gz
manaverse-c9bb66d595927bd14871c10b216ed05ffb5e3b12.tar.bz2
manaverse-c9bb66d595927bd14871c10b216ed05ffb5e3b12.tar.xz
manaverse-c9bb66d595927bd14871c10b216ed05ffb5e3b12.zip
Add support for images in npc menu.
Diffstat (limited to 'src/gui/npcdialog.cpp')
-rw-r--r--src/gui/npcdialog.cpp50
1 files changed, 46 insertions, 4 deletions
diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp
index aa86ffeec..04e0aa9fb 100644
--- a/src/gui/npcdialog.cpp
+++ b/src/gui/npcdialog.cpp
@@ -37,12 +37,14 @@
#include "gui/widgets/inttextfield.h"
#include "gui/widgets/itemlinkhandler.h"
#include "gui/widgets/layout.h"
-#include "gui/widgets/listbox.h"
+#include "gui/widgets/extendedlistbox.h"
#include "gui/widgets/playerbox.h"
#include "gui/widgets/scrollarea.h"
#include "gui/widgets/textbox.h"
#include "gui/widgets/textfield.h"
+#include "resources/resourcemanager.h"
+
#include "net/net.h"
#include "net/npchandler.h"
@@ -103,12 +105,16 @@ NpcDialog::NpcDialog(int npcId) :
mScrollArea->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS);
// Setup listbox
- mItemList = new ListBox(this);
+ mItemList = new ExtendedListBox(this);
mItemList->setWrappingEnabled(true);
mItemList->setActionEventId("ok");
mItemList->addActionListener(this);
mItemList->setDistributeMousePressed(false);
mItemList->setFont(gui->getNpcFont());
+ if (gui->getNpcFont()->getHeight() < 20)
+ mItemList->setRowHeight(20);
+ else
+ mItemList->setRowHeight(gui->getNpcFont()->getHeight());
setContentSize(260, 175);
@@ -200,6 +206,15 @@ NpcDialog::~NpcDialog()
delete mListScrollArea;
mListScrollArea = nullptr;
+ for (std::vector<Image *>::iterator it = mImages.begin(),
+ it_end = mImages.end(); it != it_end; ++ it)
+ {
+ if (*it)
+ (*it)->decRef();
+ }
+
+ mImages.clear();
+
instances.remove(this);
}
@@ -242,7 +257,6 @@ void NpcDialog::showCloseButton()
void NpcDialog::action(const gcn::ActionEvent &event)
{
- logger->log(event.getId());
if (event.getId() == "ok")
{
if (mActionState == NPC_ACTION_NEXT)
@@ -355,9 +369,21 @@ std::string NpcDialog::getElementAt(int i)
return mItems[i];
}
+const Image *NpcDialog::getImageAt(int i)
+{
+ return mImages[i];
+}
+
void NpcDialog::choiceRequest()
{
mItems.clear();
+ for (std::vector<Image *>::iterator it = mImages.begin(),
+ it_end = mImages.end(); it != it_end; ++ it)
+ {
+ if (*it)
+ (*it)->decRef();
+ }
+ mImages.clear();
mActionState = NPC_ACTION_INPUT;
mInputState = NPC_INPUT_LIST;
buildLayout();
@@ -366,15 +392,31 @@ void NpcDialog::choiceRequest()
void NpcDialog::addChoice(const std::string &choice)
{
mItems.push_back(choice);
+ mImages.push_back(nullptr);
}
void NpcDialog::parseListItems(const std::string &itemString)
{
std::istringstream iss(itemString);
+ ResourceManager *resman = ResourceManager::getInstance();
std::string tmp;
while (getline(iss, tmp, ':'))
- mItems.push_back(tmp);
+ {
+ const size_t pos = tmp.find("|");
+ if (pos == std::string::npos)
+ {
+ mItems.push_back(tmp);
+ mImages.push_back(nullptr);
+ }
+ else
+ {
+ mItems.push_back(tmp.substr(pos + 1));
+ Image *img = resman->getImage(paths.getStringValue("guiIcons")
+ + tmp.substr(0, pos) + ".png");
+ mImages.push_back(img);
+ }
+ }
if (!mItems.empty())
{