summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-26 16:12:09 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-26 16:12:09 +0000
commit251031b790ebc5cd677315174d4e46bc4e287718 (patch)
tree0f810a515bd5390f771d0dc41cd2e59e9914732d /src
parent87bee54dede4d9d80731a01bd8c4e9384e047e58 (diff)
downloadmana-client-251031b790ebc5cd677315174d4e46bc4e287718.tar.gz
mana-client-251031b790ebc5cd677315174d4e46bc4e287718.tar.bz2
mana-client-251031b790ebc5cd677315174d4e46bc4e287718.tar.xz
mana-client-251031b790ebc5cd677315174d4e46bc4e287718.zip
Ported buy dialog, which could still use visual improvement, and added
\|-`~ to the fixed font.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/game.cpp18
-rw-r--r--src/graphic/graphic.cpp33
-rw-r--r--src/graphic/graphic.h2
-rw-r--r--src/gui/buy.cpp152
-rw-r--r--src/gui/buy.h96
-rw-r--r--src/gui/char_server.h6
-rw-r--r--src/gui/gui.cpp2
-rw-r--r--src/gui/shop.h2
-rw-r--r--src/gui/skill.cpp2
10 files changed, 279 insertions, 35 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index c5c4bb9d..be31df8f 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -4,6 +4,7 @@ tmw_SOURCES = sound/sound.cpp \
graphic/graphic.cpp \
graphic/image.cpp \
gui/button.cpp \
+ gui/buy.cpp \
gui/char_server.cpp \
gui/char_select.cpp \
gui/chat.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 37162409..64336157 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -734,17 +734,19 @@ void do_parse() {
break;
// Buy/Sell dialog
case 0x00c4:
- //if(show_npc_dialog==0) {
- show_npc_dialog = 2;
- current_npc = RFIFOL(2);
- //}
+ buyDialog->setVisible(false);
+ show_npc_dialog = 2;
+ current_npc = RFIFOL(2);
break;
// Buy dialog
case 0x00c6:
- n_items = (len-4)/11;
- show_npc_dialog = 3;
- for(int k=0;k<n_items;k++)
- add_buy_item(RFIFOW(4+11*k+9), RFIFOL(4+11*k));
+ n_items = (len - 4) / 11;
+ buyDialog->reset();
+ buyDialog->setMoney(char_info->gp);
+ buyDialog->setVisible(true);
+ for (int k = 0; k < n_items; k++) {
+ buyDialog->addItem(RFIFOW(4 + 11 * k + 9), RFIFOL(4 + 11 * k));
+ }
break;
// Sell dialog
case 0x00c7:
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 46413d2b..b3173881 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -44,7 +44,7 @@ DATAFILE *tileset;
char itemCurrenyQ[10] = "0";
//char page_num;
int map_x, map_y, camera_x, camera_y;
-DIALOG_PLAYER *npc_player, *skill_player, *buy_sell_player, *buy_player, *sell_player, *skill_list_player, *npc_list_player;
+DIALOG_PLAYER *npc_player, *skill_player, *buy_sell_player, *sell_player, *skill_list_player, *npc_list_player;
char npc_text[1000] = "";
char statsString2[255] = "n/a";
char skill_points[10] = "";
@@ -57,6 +57,7 @@ char npc_button[10] = "Close";
gcn::TextField *chatInput;
StatsDialog *statsDialog;
+BuyDialog *buyDialog;
void ChatListener::action(const std::string& eventId)
{
@@ -92,18 +93,6 @@ DIALOG buy_sell_dialog[] = {
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
-DIALOG buy_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 *)"Buy", 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 *)shop_list, NULL, NULL },
- { tmw_text_proc, 304, 326+25, 50, 20, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
- { tmw_slider_proc, 304, 326, 200, 20, 255, 0, 0, 0, 10, 0, NULL, (void *)changeQ, NULL },
- { tmw_text_proc, 514, 326, 40, 20, 0, 0, 0, 0, 0, 0, (char *)itemCurrenyQ, NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
-};
-
DIALOG sell_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 *)"Sell", NULL, NULL },
@@ -117,7 +106,7 @@ DIALOG sell_dialog[] = {
DIALOG skill_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 *)"Skills", NULL, NULL },
+ { tmw_dialog_proc, 300, 200, 260, 200, 0, 0, 0, 0, 0, 0, (char *)"Stats", NULL, NULL },
{ tmw_button_proc, 450, 376, 50, 20, 255, 0, 'u', D_EXIT, 0, 0, (char *)"&Up", NULL, NULL },
{ tmw_button_proc, 508, 376, 50, 20, 255, 0, 'c', D_EXIT, 0, 0, (char *)"&Close", NULL, NULL },
{ tmw_list_proc, 304, 224, 252, 100, 0, 0, 0, 0, 0, 0, (char *)skill_list, NULL, NULL },
@@ -215,12 +204,15 @@ void init_graphic() {
statsDialog = new StatsDialog(guiTop);
statsDialog->setPosition(SCREEN_W - statsDialog->getWidth() - 10, 10);
+ // Create buy dialog
+ buyDialog = new BuyDialog(guiTop);
+ buyDialog->setVisible(false);
+
npc_player = init_dialog(npc_dialog, -1);
position_dialog(npc_dialog, 300, 200);
skill_player = init_dialog(skill_dialog, -1);
buy_sell_player = init_dialog(buy_sell_dialog, -1);
- buy_player = init_dialog(buy_dialog, -1);
sell_player = init_dialog(sell_dialog, -1);
skill_list_player = init_dialog(skill_list_dialog, -1);
npc_list_player = init_dialog(npc_list_dialog, -1);
@@ -379,12 +371,6 @@ void do_graphic(void) {
}
}
}
-
- textprintf_centre_ex(vbuffer, font,
- node->text_x + 45,
- node->text_y + 55,
- node->speech_color, -1,
- "(%d,%d), %d", x, y, dir);
}
else if (node->job == 45) { // Draw a warp
} else { // Draw a monster
@@ -561,6 +547,7 @@ void do_graphic(void) {
}
break;
case 3:
+ /*
char money[20];
sprintf(money, "%i gp", char_info->gp);
buy_dialog[4].dp = &money;
@@ -583,6 +570,7 @@ void do_graphic(void) {
buy_player = init_dialog(buy_dialog, -1);
close_shop();
}
+ */
break;
case 4:
//alert("","","","","",0,0);
@@ -664,6 +652,9 @@ void do_graphic(void) {
}
void exit_graphic() {
+ delete statsDialog;
+ delete buyDialog;
+
shutdown_dialog(npc_player);
shutdown_dialog(skill_player);
}
diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h
index 019cb67f..ad1d02fa 100644
--- a/src/graphic/graphic.h
+++ b/src/graphic/graphic.h
@@ -27,6 +27,7 @@
#include "../game.h"
#include "../map.h"
#include "../being.h"
+#include "../gui/buy.h"
#include "../gui/chat.h"
#include "../gui/inventory.h"
#include "../gui/shop.h"
@@ -52,6 +53,7 @@ extern BITMAP *hairset;
extern char npc_button[10];
extern StatsDialog *statsDialog;
+extern BuyDialog *buyDialog;
// The action listener for the chat field
class ChatListener : public gcn::ActionListener {
diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp
new file mode 100644
index 00000000..c3b8751d
--- /dev/null
+++ b/src/gui/buy.cpp
@@ -0,0 +1,152 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "buy.h"
+#include "button.h"
+
+#include <sstream>
+
+BuyDialog::BuyDialog(gcn::Container *parent):
+ Window(parent, "Buy"),
+ money(0)
+{
+ itemList = new gcn::ListBox(this);
+ scrollArea = new gcn::ScrollArea(itemList);
+ slider = new gcn::Slider(1.0);
+ quantityLabel = new gcn::Label("0");
+ moneyLabel = new gcn::Label("350 G");
+ okButton = new Button("OK");
+ cancelButton = new Button("Cancel");
+
+ setSize(260, 175);
+ scrollArea->setDimension(gcn::Rectangle(5, 5, 250, 110));
+ slider->setDimension(gcn::Rectangle(5, 120, 200, 10));
+ quantityLabel->setPosition(215, 120);
+ moneyLabel->setPosition(5, 135);
+ okButton->setPosition(180, 145);
+ cancelButton->setPosition(208, 145);
+
+ itemList->setEventId("item");
+ slider->setEventId("slider");
+ okButton->setEventId("ok");
+ cancelButton->setEventId("cancel");
+
+ itemList->addActionListener(this);
+ slider->addActionListener(this);
+ okButton->addActionListener(this);
+ cancelButton->addActionListener(this);
+
+ add(scrollArea);
+ add(slider);
+ add(quantityLabel);
+ add(moneyLabel);
+ add(okButton);
+ add(cancelButton);
+
+ setLocationRelativeTo(getParent());
+}
+
+BuyDialog::~BuyDialog()
+{
+ delete cancelButton;
+ delete okButton;
+ delete moneyLabel;
+ delete slider;
+ delete itemList;
+ delete scrollArea;
+}
+
+void BuyDialog::setMoney(int amount)
+{
+ money = amount;
+ std::stringstream ss;
+ ss << money << " G";
+ moneyLabel->setCaption(ss.str());
+ moneyLabel->adjustSize();
+}
+
+void BuyDialog::reset()
+{
+ shopInventory.clear();
+ money = 0;
+}
+
+void BuyDialog::addItem(short id, int price)
+{
+ ITEM_SHOP item_shop;
+
+ if (id - 501 >= 0 && id - 501 <= 11) {
+ sprintf(item_shop.name, "%s %i gp", item_db[id - 501], price);
+ }
+ else {
+ sprintf(item_shop.name, "Unknown item %i gp", price);
+ }
+ item_shop.price = price;
+ item_shop.id = id;
+
+ shopInventory.push_back(item_shop);
+ itemList->adjustSize();
+}
+
+void BuyDialog::action(const std::string& eventId)
+{
+ int selectedItem = itemList->getSelected();
+
+ if (eventId == "slider" || eventId == "item") {
+ if (selectedItem > -1) {
+ int maxItems = money / shopInventory[selectedItem].price;
+ std::stringstream ss;
+
+ ss << (int)(slider->getValue() * maxItems);
+ quantityLabel->setCaption(ss.str());
+ quantityLabel->adjustSize();
+ }
+ }
+ else if (eventId == "ok") {
+ if (selectedItem > -1) {
+ // Attempt purchase
+ int maxItems = money / shopInventory[selectedItem].price;
+ int amount = (int)(slider->getValue() * maxItems);
+
+ if (amount > 0) {
+ WFIFOW(0) = net_w_value(0x00c8);
+ WFIFOW(2) = net_w_value(8);
+ WFIFOW(4) = net_w_value(amount);
+ WFIFOW(6) = net_w_value(shopInventory[selectedItem].id);
+ WFIFOSET(8);
+ }
+ }
+ setVisible(false);
+ }
+ else if (eventId == "cancel") {
+ setVisible(false);
+ }
+}
+
+int BuyDialog::getNumberOfElements()
+{
+ return shopInventory.size();
+}
+
+std::string BuyDialog::getElementAt(int i)
+{
+ return shopInventory[i].name;
+}
diff --git a/src/gui/buy.h b/src/gui/buy.h
new file mode 100644
index 00000000..67978409
--- /dev/null
+++ b/src/gui/buy.h
@@ -0,0 +1,96 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _TMW_BUY_H
+#define _TMW_BUY_H
+
+#include "gui.h"
+#include "window.h"
+#include "shop.h"
+
+#include <vector>
+
+/**
+ * The buy dialog.
+ *
+ * \ingroup GUI
+ */
+class BuyDialog : public Window, public gcn::ActionListener,
+ public gcn::ListModel
+{
+ public:
+ /**
+ * Constructor
+ *
+ * @see Window::Window
+ */
+ BuyDialog(gcn::Container *parent);
+
+ /**
+ * Destructor
+ */
+ ~BuyDialog();
+
+ /**
+ * Resets the dialog, clearing shop inventory.
+ */
+ void reset();
+
+ /**
+ * Sets the amount of available money.
+ */
+ void setMoney(int amount);
+
+ /**
+ * Adds an item to the shop inventory.
+ */
+ void addItem(short id, int price);
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const std::string& eventId);
+
+ /**
+ * Returns the number of items in the shop inventory.
+ */
+ int getNumberOfElements();
+
+ /**
+ * Returns the name of item number i in the shop inventory.
+ */
+ std::string getElementAt(int i);
+
+ private:
+ gcn::Button *okButton;
+ gcn::Button *cancelButton;
+ gcn::ListBox *itemList;
+ gcn::ScrollArea *scrollArea;
+ gcn::Label *moneyLabel;
+ gcn::Label *quantityLabel;
+ gcn::Slider *slider;
+
+ std::vector<ITEM_SHOP> shopInventory;
+
+ int money;
+};
+
+#endif
diff --git a/src/gui/char_server.h b/src/gui/char_server.h
index 2f2a6f46..c1cb704b 100644
--- a/src/gui/char_server.h
+++ b/src/gui/char_server.h
@@ -19,13 +19,13 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
+#ifndef _CHAR_SEL_SERVER_H
+#define _CHAR_SEL_SERVER_H
+
#ifdef WIN32
#pragma warning (disable:4312)
#endif
-#ifndef _CHAR_SEL_SERVER_H
-#define _CHAR_SEL_SERVER_H
-
#include "../main.h"
#include "../net/network.h"
#include "gui.h"
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index b6bfd72f..ee6d2a0a 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -87,7 +87,7 @@ void init_gui(BITMAP *bitmap, const char *skin) {
gui->setTop(guiTop);
guiFont = new gcn::ImageFont("./data/graphic/fixedfont.bmp",
" abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789:@"
- "!\"$%&/=?^+*#[]{}()<>_;'.,"
+ "!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`"
);
gcn::Widget::setGlobalFont(guiFont);
diff --git a/src/gui/shop.h b/src/gui/shop.h
index 0d8e31ad..73b14e97 100644
--- a/src/gui/shop.h
+++ b/src/gui/shop.h
@@ -27,7 +27,6 @@
#include <stdlib.h>
#include <stdio.h>
-#include "../graphic/graphic.h"
#include "inventory.h"
@@ -43,6 +42,7 @@ struct ITEM_SHOP {
extern int n_items;
extern char* selectedItem;
extern char itemCurrenyQ[10];
+extern char *item_db[];
char *shop_list(int index, int *list_size);
void add_buy_item(short id, int price);
diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp
index 65014cb9..5deb270a 100644
--- a/src/gui/skill.cpp
+++ b/src/gui/skill.cpp
@@ -62,7 +62,7 @@ char *skill_db[] = {
DIALOG skill_dialog[] = {
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
- { tmw_dialog_proc, 300, 200, 150, 60, 0, 0, 0, 0, 0, 0, (char *)"Skill", NULL, NULL },
+ { tmw_dialog_proc, 300, 200, 150, 60, 0, 0, 0, 0, 0, 0, (char *)"Skills", NULL, NULL },
{ tmw_text_proc, 304, 224, 252, 100, 0, 0, 0, 0, 0, 0, str_string, NULL, NULL },
{ tmw_plus_proc, 354, 224, 16, 16, 0, 0, '0', 0, 0, 1, (void*)increaseStatus,NULL, NULL },
{ tmw_text_proc, 304, 234, 252, 100, 0, 0, 0, 0, 0, 0, agi_string, NULL, NULL },