diff options
author | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-29 16:26:25 +0000 |
---|---|---|
committer | Bjørn Lindeijer <bjorn@lindeijer.nl> | 2004-12-29 16:26:25 +0000 |
commit | 9ddc6e0d5208820a374f3bc9b9c5678e013535b2 (patch) | |
tree | 8f536daa9dd1eabd890e1bb97235fec2cad94296 /src/gui | |
parent | 1265eb758eedb57b8a66d6ebee8f03c22672586c (diff) | |
download | mana-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.tar.gz mana-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.tar.bz2 mana-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.tar.xz mana-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.zip |
Ported NPC list dialog to Guichan.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/gui.cpp | 10 | ||||
-rw-r--r-- | src/gui/npc.cpp | 86 | ||||
-rw-r--r-- | src/gui/npc.h | 60 |
3 files changed, 109 insertions, 47 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6c515b51..e301f422 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -567,7 +567,6 @@ int tmw_text_proc(int msg, DIALOG *d, int c) { int tmw_button_proc(int msg, DIALOG *d, int c) { - int rtm = 0; int col = 0; int ofs = 0; int ret = D_O_K; @@ -684,7 +683,6 @@ int tmw_radio_proc(int msg, DIALOG *d, int c) { BITMAP *box = NULL; int x, y; int tx, ty, l; - int rtm = 0; int col = 0; @@ -746,7 +744,6 @@ int tmw_list_proc(int msg, DIALOG *d, int c) { int x,y,delta; int a, col; int w, h = 0; - int rtm = 0; int cl, cr, cb, ct; int th = text_height(font); @@ -914,7 +911,6 @@ return D_O_K; /* Dialog box with left centered head */ int tmw_dialog_proc(int msg, DIALOG *d, int c) { - int rtm; int x, y; switch(msg) { @@ -954,7 +950,7 @@ int tmw_dialog_proc(int msg, DIALOG *d, int c) { textprintf_centre_ex(gui_bitmap, font, d->x + d->w/2, - d->y + (gui_skin.dialog.bg.grid[1]->h - text_height(font))/2, d->fg, -1, "%s", d->dp); + d->y + (gui_skin.dialog.bg.grid[1]->h - text_height(font))/2, d->fg, -1, "%s", (char*)d->dp); break; } @@ -966,7 +962,6 @@ int tmw_dialog_proc(int msg, DIALOG *d, int c) { dialog box w/ left aligned head */ int tmw_ldialog_proc(int msg, DIALOG *d, int c) { - int rtm; int x, y; if (msg == MSG_CLICK) { @@ -1003,7 +998,7 @@ int tmw_ldialog_proc(int msg, DIALOG *d, int c) { } draw_skinned_rect(gui_bitmap, &gui_skin.dialog.bg, d->x, d->y, d->w, d->h); - textprintf_ex(gui_bitmap, font, d->x + 4, d->y + (gui_skin.dialog.bg.grid[1]->h - text_height(font))/2, d->fg, -1, "%s", d->dp); + textprintf_ex(gui_bitmap, font, d->x + 4, d->y + (gui_skin.dialog.bg.grid[1]->h - text_height(font))/2, d->fg, -1, "%s", (char*)d->dp); } return D_O_K; } @@ -1061,7 +1056,6 @@ void _gui_draw_textbox(char *thetext, int *listsize, int draw, int offset, int line = 0; int i = 0; int noignore; - int rtm; usetc(s+usetc(s, '.'), 0); usetc(text+usetc(text, ' '), 0); diff --git a/src/gui/npc.cpp b/src/gui/npc.cpp index eb864c39..d206010e 100644 --- a/src/gui/npc.cpp +++ b/src/gui/npc.cpp @@ -21,38 +21,50 @@ * $Id$ */ -#include <stdio.h> -#include <stdlib.h> -#include <string.h> - #include "npc.h" -#include <vector> +#include "button.h" +#include "scrollarea.h" +#include "../game.h" -std::vector<ITEM*> items; +NpcListDialog::NpcListDialog(gcn::Container *parent): + Window(parent, "NPC") +{ + itemList = new gcn::ListBox(this); + scrollArea = new ScrollArea(itemList); + okButton = new Button("OK"); + cancelButton = new Button("Cancel"); + setSize(260, 175); + scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 130)); + okButton->setPosition(180, 145); + cancelButton->setPosition(208, 145); -char *item_list(int index, int *list_size) { - if (index < 0) { - *list_size = items.size(); - return NULL; - } else { - return items[index]->name; - } + itemList->setEventId("item"); + okButton->setEventId("ok"); + cancelButton->setEventId("cancel"); + + itemList->addActionListener(this); + okButton->addActionListener(this); + cancelButton->addActionListener(this); + + add(scrollArea); + add(okButton); + add(cancelButton); + + setLocationRelativeTo(getParent()); } -void add_item(char *name) { - ITEM *item = (ITEM*)malloc(sizeof(ITEM)); - item->name = name; - items.push_back(item); +int NpcListDialog::getNumberOfElements() +{ + return items.size(); } -void remove_tail() { - free(items.back()->name); - free(items.back()); - items.pop_back(); -} +std::string NpcListDialog::getElementAt(int i) +{ + return items[i]; +} -void parse_items(const char *string) { +void NpcListDialog::parseItems(const char *string) { char *copy = new char[strlen(string) + 1]; strcpy(copy, string); @@ -60,18 +72,32 @@ void parse_items(const char *string) { while (token != NULL) { char *temp = (char*)malloc(strlen(token) + 1); strcpy(temp, token); - add_item(temp); + items.push_back(std::string(temp)); token = strtok(NULL, ":"); } delete[] copy; } -void remove_all_items() { - int i; - for (i = 0; i < items.size(); i++) { - free(items[i]->name); - free(items[i]); - } +void NpcListDialog::reset() { items.clear(); } + +void NpcListDialog::action(const std::string& eventId) +{ + if (eventId == "ok") { + // Send the selected index back to the server + int selectedIndex = itemList->getSelected(); + if (selectedIndex > -1) { + WFIFOW(0) = net_w_value(0x00b8); + WFIFOL(2) = net_l_value(current_npc); + WFIFOB(6) = net_b_value(selectedIndex + 1); + WFIFOSET(7); + setVisible(false); + reset(); + } + } else if (eventId == "cancel") { + setVisible(false); + reset(); + } +} diff --git a/src/gui/npc.h b/src/gui/npc.h index a8077dcf..acc91173 100644 --- a/src/gui/npc.h +++ b/src/gui/npc.h @@ -24,19 +24,61 @@ #ifndef _NPC_H #define _NPC_H -struct ITEM { - char *name; -}; - -char *item_list(int index, int *list_size); +#include <guichan.hpp> +#include <vector> +#include <string> +#include "window.h" /** - * Fills the options list for an NPC dialog. + * The npc list dialog. * - * @param string A string with the options separated with colons. + * \ingroup GUI */ -void parse_items(const char *string); +class NpcListDialog : public Window, public gcn::ActionListener, + public gcn::ListModel +{ + public: + /** + * Constructor. + * + * @see Window::Window + */ + NpcListDialog(gcn::Container *parent); + + /** + * Called when receiving actions from the widgets. + */ + void action(const std::string& eventId); + + /** + * Returns the number of items in the choices list. + */ + int getNumberOfElements(); + + /** + * Returns the name of item number i of the choices list. + */ + std::string getElementAt(int i); -void remove_all_items(); + /** + * Fills the options list for an NPC dialog. + * + * @param string A string with the options separated with colons. + */ + void parseItems(const char *string); + + /** + * Resets the list by removing all items. + */ + void reset(); + + private: + gcn::Button *okButton; + gcn::Button *cancelButton; + gcn::ListBox *itemList; + gcn::ScrollArea *scrollArea; + + std::vector<std::string> items; +}; #endif |