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 | |
parent | 1265eb758eedb57b8a66d6ebee8f03c22672586c (diff) | |
download | mana-client-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.tar.gz mana-client-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.tar.bz2 mana-client-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.tar.xz mana-client-9ddc6e0d5208820a374f3bc9b9c5678e013535b2.zip |
Ported NPC list dialog to Guichan.
-rw-r--r-- | src/game.cpp | 11 | ||||
-rw-r--r-- | src/graphic/graphic.cpp | 50 | ||||
-rw-r--r-- | src/graphic/graphic.h | 2 | ||||
-rw-r--r-- | src/gui/gui.cpp | 10 | ||||
-rw-r--r-- | src/gui/npc.cpp | 86 | ||||
-rw-r--r-- | src/gui/npc.h | 60 |
6 files changed, 131 insertions, 88 deletions
diff --git a/src/game.cpp b/src/game.cpp index 1c12a5d9..eb2a99a5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -871,22 +871,23 @@ void do_parse() { // List in NPC dialog case 0x00b7: current_npc = RFIFOL(4); - //alert(RFIFOP(8),"","","","",0,0); + // Hammerbear: Second argument here shouldn't be neccesary, instead + // make sure the string is \0 terminated. //parse_items(RFIFOP(8), RFIFOW(2)); - parse_items(RFIFOP(8)); + npcListDialog->parseItems(RFIFOP(8)); RFIFOW(2); - show_npc_dialog = 5; + npcListDialog->setVisible(true); break; // Look change case 0x00c3: // Change hair color - if(RFIFOB(6)==6) { + if (RFIFOB(6) == 6) { node = find_node(RFIFOL(2)); node->hair_color = RFIFOB(7); /*char prova[100]; sprintf(prova, "%i %i %i", RFIFOL(2), RFIFOB(6), RFIFOB(7)); alert(prova,"","","","",0,0);*/ - } else if(RFIFOB(6)==1) { + } else if (RFIFOB(6) == 1) { node = find_node(RFIFOL(2)); node->hair_style = RFIFOB(7); } diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp index cc450d33..bba04d52 100644 --- a/src/graphic/graphic.cpp +++ b/src/graphic/graphic.cpp @@ -46,6 +46,7 @@ BuyDialog *buyDialog; SellDialog *sellDialog; BuySellDialog *buySellDialog; InventoryWindow *inventoryWindow; +NpcListDialog *npcListDialog; void ChatListener::action(const std::string& eventId) { @@ -98,15 +99,6 @@ DIALOG skill_list_dialog[] = { { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } }; -DIALOG npc_list_dialog[] = { - /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */ - { tmw_dialog_proc, 300, 200, 260, 200, 0, 0, 0, 0, 0, 0, (char *)"NPC", NULL, NULL }, - { tmw_button_proc, 450, 376, 50, 20, 255, 0, 'o', D_EXIT, 0, 0, (char *)"&Ok", NULL, NULL }, - { tmw_button_proc, 508, 376, 50, 20, 255, 0, 'c', D_EXIT, 0, 0, (char *)"&Cancel", NULL, NULL }, - { tmw_list_proc, 304, 224, 252, 100, 0, 0, 0, 0, 0, 0, (char *)item_list, NULL, NULL }, - { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL } -}; - char hairtable[14][4][2] = { // S(x,y) W(x,y) N(x,y) E(x,y) { { 0, 0}, {-1, 2}, {-1, 2}, {0, 2} }, // STAND @@ -200,11 +192,13 @@ GraphicEngine::GraphicEngine() { inventoryWindow->setVisible(false); inventoryWindow->setPosition(100, 100); + npcListDialog = new NpcListDialog(guiTop); + npcListDialog->setVisible(false); + npc_player = init_dialog(npc_dialog, -1); position_dialog(npc_dialog, 300, 200); skill_player = init_dialog(skill_dialog, -1); skill_list_player = init_dialog(skill_list_dialog, -1); - npc_list_player = init_dialog(npc_list_dialog, -1); buffer = create_bitmap(SCREEN_W, SCREEN_H); if(!buffer) { @@ -291,28 +285,27 @@ void GraphicEngine::refresh() { else if (node->job < 10) { // Draw a player node->text_x = sx * 32 + get_x_offset(node) - offset_x; node->text_y = sy * 32 + get_y_offset(node) - offset_y; + int hf = node->hair_color - 1 + 10 * (dir + 4 * + (node->hair_style - 1)); if (node->action == SIT) node->frame = 0; if (node->action == ATTACK) { int pf = node->frame + node->action + 4 * node->weapon; - int wf = 16 * node->weapon + 4 * node->frame; playerset->spriteset[4 * pf + dir]->draw(buffer, - node->text_x-64, node->text_y-80); - /*draw_rle_sprite(buffer, (RLE_SPRITE*)weaponset[wf + dir].dat, - node->text_x, node->text_y);*/ - hairset->spriteset[node->hair_color-1+10*(dir+4*(node->hair_style-1))]->draw( - buffer, node->text_x -2 + 2*hairtable[pf][dir][0], - node->text_y -50 + 2*hairtable[pf][dir][1]); + node->text_x - 64, node->text_y - 80); + hairset->spriteset[hf]->draw( + buffer, node->text_x - 2 + 2 * hairtable[pf][dir][0], + node->text_y - 50 + 2 * hairtable[pf][dir][1]); } else { int pf = node->frame + node->action; playerset->spriteset[4 * pf + dir]->draw(buffer, - node->text_x-64, node->text_y-80); - hairset->spriteset[node->hair_color-1+10*(dir+4*(node->hair_style-1))]->draw( - buffer, node->text_x - 2 + 2*hairtable[pf][dir][0], - node->text_y - 50 + 2*hairtable[pf][dir][1]); + node->text_x - 64, node->text_y - 80); + hairset->spriteset[hf]->draw( + buffer, node->text_x - 2 + 2 * hairtable[pf][dir][0], + node->text_y - 50 + 2 * hairtable[pf][dir][1]); } if (node->emotion != 0) { emotionset->spriteset[node->emotion - 1]->draw(buffer, @@ -472,21 +465,6 @@ void GraphicEngine::refresh() { WFIFOSET(6); } break; - case 5: - dialog_message(npc_list_dialog, MSG_DRAW, 0, 0); - if (!gui_update(npc_list_player)) { - show_npc_dialog = shutdown_dialog(npc_list_player); - if (show_npc_dialog == 1) { - WFIFOW(0) = net_w_value(0x00b8); - WFIFOL(2) = net_l_value(current_npc); - WFIFOB(6) = net_b_value(npc_list_dialog[3].d1+1); - WFIFOSET(7); - } - show_npc_dialog = 0; - npc_list_player = init_dialog(npc_list_dialog, -1); - remove_all_items(); - } - break; } if (show_skill_dialog) { diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h index 40a6d107..564a380e 100644 --- a/src/graphic/graphic.h +++ b/src/graphic/graphic.h @@ -26,6 +26,7 @@ #include "../map.h" #include "../being.h" #include "../gui/buy.h" +#include "../gui/npc.h" #include "../gui/sell.h" #include "../gui/buysell.h" #include "../gui/chat.h" @@ -58,6 +59,7 @@ extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern BuySellDialog *buySellDialog; extern InventoryWindow *inventoryWindow; +extern NpcListDialog *npcListDialog; // The action listener for the chat field class ChatListener : public gcn::ActionListener { 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 |