summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-20 14:20:10 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-20 14:20:10 +0000
commitfec8d201c51d82c370cb6052209397d88d004490 (patch)
tree57c12776fce97ee9824cd2df2d7ab475014418ef
parent41b0b5c0ed80d812d13c8c92d286a8663084ec58 (diff)
downloadmana-client-fec8d201c51d82c370cb6052209397d88d004490.tar.gz
mana-client-fec8d201c51d82c370cb6052209397d88d004490.tar.bz2
mana-client-fec8d201c51d82c370cb6052209397d88d004490.tar.xz
mana-client-fec8d201c51d82c370cb6052209397d88d004490.zip
Converted the progress bar and stats dialog to Guichan widgets.
-rw-r--r--The Mana World.dev22
-rw-r--r--file.list17
-rw-r--r--src/Makefile.am17
-rw-r--r--src/game.cpp2
-rw-r--r--src/graphic/graphic.cpp33
-rw-r--r--src/graphic/graphic.h3
-rw-r--r--src/gui/gui.cpp21
-rw-r--r--src/gui/gui.h1
-rw-r--r--src/gui/progressbar.cpp78
-rw-r--r--src/gui/progressbar.h47
-rw-r--r--src/gui/stats.cpp81
-rw-r--r--src/gui/stats.h24
-rw-r--r--src/gui/window.cpp7
-rw-r--r--src/gui/window.h7
14 files changed, 275 insertions, 85 deletions
diff --git a/The Mana World.dev b/The Mana World.dev
index 5c13e067..6d41552b 100644
--- a/The Mana World.dev
+++ b/The Mana World.dev
@@ -1,7 +1,7 @@
[Project]
FileName=The Mana World.dev
Name=tmw
-UnitCount=52
+UnitCount=54
Type=0
Ver=1
ObjFiles=
@@ -573,3 +573,23 @@ Priority=1000
OverrideBuildCmd=0
BuildCmd=
+[Unit53]
+FileName=src\gui\progressbar.cpp
+CompileCpp=1
+Folder=gui
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=0
+BuildCmd=
+
+[Unit54]
+FileName=src\gui\progressbar.h
+CompileCpp=1
+Folder=gui
+Compile=1
+Link=1
+Priority=1000
+OverrideBuildCmd=0
+BuildCmd=
+
diff --git a/file.list b/file.list
index 25695034..0920814e 100644
--- a/file.list
+++ b/file.list
@@ -2,18 +2,19 @@ MODULES = src/sound/sound.cpp \
src/graphic/2xsai.cpp \
src/graphic/graphic.cpp \
src/gui/button.cpp \
+ src/gui/char_server.cpp \
+ src/gui/char_select.cpp \
src/gui/chat.cpp \
src/gui/checkbox.cpp \
- src/gui/skill.cpp \
- src/gui/shop.cpp \
- src/gui/stats.cpp \
- src/gui/npc.cpp \
- src/gui/setup.cpp \
src/gui/gui.cpp \
- src/gui/login.cpp \
- src/gui/char_server.cpp \
- src/gui/char_select.cpp \
src/gui/inventory.cpp \
+ src/gui/login.cpp \
+ src/gui/npc.cpp \
+ src/gui/progressbar.cpp \
+ src/gui/setup.cpp \
+ src/gui/shop.cpp \
+ src/gui/skill.cpp \
+ src/gui/stats.cpp \
src/gui/window.cpp \
src/net/network.cpp \
src/net/protocol.cpp \
diff --git a/src/Makefile.am b/src/Makefile.am
index 14744376..13b290ce 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -3,18 +3,19 @@ tmw_SOURCES = sound/sound.cpp \
graphic/2xsai.cpp \
graphic/graphic.cpp \
gui/button.cpp \
+ gui/char_server.cpp \
+ gui/char_select.cpp \
gui/chat.cpp \
gui/checkbox.cpp \
- gui/skill.cpp \
- gui/shop.cpp \
- gui/stats.cpp \
- gui/npc.cpp \
- gui/setup.cpp \
gui/gui.cpp \
- gui/login.cpp \
- gui/char_server.cpp \
- gui/char_select.cpp \
gui/inventory.cpp \
+ gui/login.cpp \
+ gui/npc.cpp \
+ gui/progressbar.cpp \
+ gui/setup.cpp \
+ gui/shop.cpp \
+ gui/skill.cpp \
+ gui/stats.cpp \
gui/window.cpp \
net/network.cpp \
net/protocol.cpp \
diff --git a/src/game.cpp b/src/game.cpp
index 1f54bb95..f6da9a5b 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -599,7 +599,7 @@ void do_parse() {
char_info->job_lv = RFIFOW(4);
break;
}
- update_stats_dialog();
+ statsDialog->update();
if(char_info->hp==0) {
ok("Message", "You're now dead, press ok to restart");
WFIFOW(0) = net_w_value(0x00b2);
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 375f2256..d3d944a6 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -25,6 +25,7 @@
#include "2xsai.h"
#include "../gui/gui.h"
#include "../gui/setup.h"
+#include "../gui/stats.h"
#define TILESET_W 480
#define TILESET_H 320
@@ -42,7 +43,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, *stats_player, *skill_list_player, *npc_list_player;
+DIALOG_PLAYER *npc_player, *skill_player, *buy_sell_player, *buy_player, *sell_player, *skill_list_player, *npc_list_player;
char npc_text[1000] = "";
char statsString2[255] = "n/a";
char skill_points[10] = "";
@@ -54,6 +55,7 @@ bool show_skill_list_dialog = false;
char npc_button[10] = "Close";
gcn::TextField *chatInput;
+StatsDialog *statsDialog;
Setup *setup;
extern bool show_setup;
@@ -233,18 +235,20 @@ void init_graphic() {
chatInput->requestFocus();
+ // Create stats dialog
+ statsDialog = new StatsDialog(guiTop);
+ statsDialog->setPosition(SCREEN_W - statsDialog->getWidth() - 10, 10);
+
npc_player = init_dialog(npc_dialog, -1);
position_dialog(npc_dialog, 300, 200);
skill_player = init_dialog(skill_dialog, -1);
- stats_player = init_dialog(stats_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);
//gui_bitmap = vpage[page_num];
- text_mode(-1);
inventory.create(100, 100);
#ifdef WIN32
@@ -590,20 +594,19 @@ new_tileset->spriteset[0]->draw(vbuffer, 0, 0);
}
}
- // character status display
- update_stats_dialog();
- gui_update(stats_player);
+ // character status display
+ statsDialog->update();
- draw_sprite(vpage[page_num], mouse_sprite, mouse_x, mouse_y);
+ draw_sprite(vpage[page_num], mouse_sprite, mouse_x, mouse_y);
#ifdef WIN32
- if(stretch_mode==0) {
- release_bitmap(vpage[page_num]);
- show_video_bitmap(vpage[page_num]);
- } else
+ if (stretch_mode == 0) {
+ release_bitmap(vpage[page_num]);
+ show_video_bitmap(vpage[page_num]);
+ } else
#endif
- blit(vpage[page_num], screen, 0, 0, 0, 0, 800, 600);
- page_num = 1-page_num;
- gui_bitmap = vpage[page_num];
+ blit(vpage[page_num], screen, 0, 0, 0, 0, 800, 600);
+ page_num = 1-page_num;
+ gui_bitmap = vpage[page_num];
}
void exit_graphic() {
@@ -643,4 +646,4 @@ GraphicEngine::GraphicEngine() {
GraphicEngine::~GraphicEngine() {
delete tileset;
-} \ No newline at end of file
+}
diff --git a/src/graphic/graphic.h b/src/graphic/graphic.h
index 08ed79d2..4cd00d5b 100644
--- a/src/graphic/graphic.h
+++ b/src/graphic/graphic.h
@@ -33,6 +33,7 @@
#include "../gui/chat.h"
#include "../gui/inventory.h"
#include "../gui/npc.h"
+#include "../gui/stats.h"
#include "../../data/graphic/gfx_data.h"
#include "image.h"
#include <allegro.h>
@@ -49,6 +50,8 @@ extern int map_x, map_y, camera_x, camera_y;
extern BITMAP *hairset;
extern char npc_button[10];
+extern StatsDialog *statsDialog;
+
// The action listener for the chat field
class ChatListener : public gcn::ActionListener {
public:
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2d26b3af..273aa885 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -1045,27 +1045,6 @@ if(mouse_b & 1)
return D_O_K;
}
-int tmw_bar_proc(int msg, DIALOG *d, int c)
-{
-float share2 = ((float)d->d1 / (float)d->d2);
-if(share2!=0)
- masked_blit(gui_skin.bar.bg.grid[3], gui_bitmap, 0, 0, d->x, d->y, gui_bitmap->w, gui_bitmap->h);
-else
- masked_blit(gui_skin.bar.bg.grid[0], gui_bitmap, 0, 0, d->x, d->y, gui_bitmap->w, gui_bitmap->h);
-
-for(int i = 3; i < (d->w-3); i++)
- if(i<share2*d->w-3)
- masked_blit(gui_skin.bar.bg.grid[4], gui_bitmap, 0, 0, d->x+1*i, d->y, gui_bitmap->w, gui_bitmap->h);
- else
- masked_blit(gui_skin.bar.bg.grid[1], gui_bitmap, 0, 0, d->x+1*i, d->y, gui_bitmap->w, gui_bitmap->h);
-
-if(share2==1)
- masked_blit(gui_skin.bar.bg.grid[5], gui_bitmap, 0, 0, d->x+d->w-3, d->y, gui_bitmap->w, gui_bitmap->h);
-else
- masked_blit(gui_skin.bar.bg.grid[2], gui_bitmap, 0, 0, d->x+d->w-3, d->y, gui_bitmap->w, gui_bitmap->h);
-return D_O_K;
-}
-
/* Dialog box with left centered head */
int tmw_dialog_proc(int msg, DIALOG *d, int c) {
int rtm;
diff --git a/src/gui/gui.h b/src/gui/gui.h
index bf411f77..46bfc22a 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -138,7 +138,6 @@ int tmw_dialog_proc(int msg, DIALOG *d, int c);
int tmw_ldialog_proc(int msg, DIALOG *d, int c);
int tmw_textbox_proc(int msg, DIALOG *d, int c);
int tmw_bitmap_proc(int msg, DIALOG *d, int c);
-int tmw_bar_proc(int msg, DIALOG *d, int c);
int tmw_plus_proc(int msg, DIALOG *d, int c);
void ok(const char *title, const char *message);
diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp
new file mode 100644
index 00000000..28151de3
--- /dev/null
+++ b/src/gui/progressbar.cpp
@@ -0,0 +1,78 @@
+/*
+ * 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
+ *
+ * By ElvenProgrammer aka Eugenio Favalli (umperio@users.sourceforge.net)
+ */
+
+#include "progressbar.h"
+#include "gui.h"
+
+
+ProgressBar::ProgressBar(float progress)
+{
+ setProgress(progress);
+}
+
+void ProgressBar::draw(gcn::Graphics *graphics)
+{
+ int x, y, w, h;
+ getAbsolutePosition(x, y);
+ w = getWidth();
+ h = getHeight();
+
+ if (progress != 0) {
+ masked_blit(gui_skin.bar.bg.grid[3], gui_bitmap,
+ 0, 0, x, y, gui_bitmap->w, gui_bitmap->h);
+ }
+ else {
+ masked_blit(gui_skin.bar.bg.grid[0], gui_bitmap,
+ 0, 0, x, y, gui_bitmap->w, gui_bitmap->h);
+ }
+
+ for (int i = 3; i < (w - 3); i++) {
+ if (i < progress * w - 3) {
+ masked_blit(gui_skin.bar.bg.grid[4], gui_bitmap,
+ 0, 0, x + 1 * i, y, gui_bitmap->w, gui_bitmap->h);
+ }
+ else {
+ masked_blit(gui_skin.bar.bg.grid[1], gui_bitmap,
+ 0, 0, x + 1 * i, y, gui_bitmap->w, gui_bitmap->h);
+ }
+ }
+
+ if (progress == 1) {
+ masked_blit(gui_skin.bar.bg.grid[5], gui_bitmap,
+ 0, 0, x + w - 3, y, gui_bitmap->w, gui_bitmap->h);
+ }
+ else {
+ masked_blit(gui_skin.bar.bg.grid[2], gui_bitmap,
+ 0, 0, x + w - 3, y, gui_bitmap->w, gui_bitmap->h);
+ }
+}
+
+void ProgressBar::setProgress(float progress)
+{
+ this->progress = progress;
+}
+
+float ProgressBar::getProgress()
+{
+ return progress;
+}
diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h
new file mode 100644
index 00000000..beab9b7f
--- /dev/null
+++ b/src/gui/progressbar.h
@@ -0,0 +1,47 @@
+/*
+ * 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 __PROGRESSBAR_H__
+#define __PROGRESSBAR_H__
+
+#include <iostream>
+#include <allegro.h>
+#include <guichan.hpp>
+
+/**
+ * A progress bar.
+ *
+ * \ingroup GUI
+ */
+class ProgressBar : public gcn::Widget {
+ public:
+ ProgressBar(float progress = 0.0f);
+
+ void draw(gcn::Graphics *graphics);
+
+ void setProgress(float progress);
+ float getProgress();
+
+ private:
+ float progress;
+};
+
+#endif
diff --git a/src/gui/stats.cpp b/src/gui/stats.cpp
index 401ca369..521f2dbd 100644
--- a/src/gui/stats.cpp
+++ b/src/gui/stats.cpp
@@ -21,30 +21,59 @@
#include "stats.h"
-char stats_name[42];
-char stats_hp[24];
-char stats_sp[24];
-char stats_gp[24];
-
-DIALOG stats_dialog[] = {
- /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
- { tmw_dialog_proc, 493-10, 0+10, 300, 55, 0, 0, 0, 0, 0, 0, stats_name, NULL, NULL },
- { tmw_text_proc, 497-10, 34+10, 296, 100, 0, 0, 0, 0, 0, 0, stats_hp, NULL, NULL },
- { tmw_bar_proc, 507-10, 22+10, 60, 18, 0, 0, '1', 0, 1, 1, NULL, NULL, NULL },
- { tmw_text_proc, 707-10, 34+10, 296, 100, 0, 0, 0, 0, 0, 0, stats_gp, NULL, NULL },
- { tmw_text_proc, 607-10, 34+10, 296, 100, 0, 0, 0, 0, 0, 0, stats_sp, NULL, NULL },
- { tmw_bar_proc, 617-10, 22+10, 60, 18, 0, 0, '1', 0, 1, 1, NULL, NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
-};
-
-/**
- updates stats_dialog w/ values from PLAYER_INFO *char_info
-*/
-void update_stats_dialog() {
- sprintf(stats_name, "%s Lvl: % 2i Job: % 2i", char_info->name, char_info->lv, char_info->job_lv);
- sprintf(stats_hp, "HP % 4d / % 4d", char_info->hp, char_info->max_hp);
- sprintf(stats_gp, "GP % 5i", char_info->gp);
- sprintf(stats_sp, "SP % 4d / % 4d", char_info->sp, char_info->max_sp);
- stats_dialog[2].d1 = char_info->hp;
- stats_dialog[2].d2 = char_info->max_hp;
+StatsDialog::StatsDialog(gcn::Container *parent):
+ Window(parent, "%s Lvl: % 2i Job: % 2i")
+{
+ hp = new gcn::Label("HP");
+ sp = new gcn::Label("SP");
+ gp = new gcn::Label("GP");
+ healthBar = new ProgressBar(1.0f);
+ manaBar = new ProgressBar(1.0f);
+
+ setSize(270, 40);
+ hp->setPosition(6, 20);
+ sp->setPosition(106, 20);
+ gp->setPosition(206, 20);
+ healthBar->setDimension(gcn::Rectangle(16, 6, 60, 18));
+ manaBar->setDimension(gcn::Rectangle(116, 6, 60, 18));
+
+ add(hp);
+ add(sp);
+ add(gp);
+ add(healthBar);
+ add(manaBar);
+}
+
+StatsDialog::~StatsDialog()
+{
+ delete hp;
+ delete sp;
+ delete gp;
+ delete healthBar;
+ delete manaBar;
+}
+
+void StatsDialog::update()
+{
+ char *tempstr = new char[64];
+
+ sprintf(tempstr, "%s Lvl: % 2i Job: % 2i",
+ char_info->name, char_info->lv, char_info->job_lv);
+ setTitle(tempstr);
+
+ sprintf(tempstr, "HP % 4d / % 4d", char_info->hp, char_info->max_hp);
+ hp->setCaption(tempstr);
+ hp->adjustSize();
+
+ sprintf(tempstr, "GP % 6i", char_info->gp);
+ gp->setCaption(tempstr);
+ gp->adjustSize();
+
+ sprintf(tempstr, "SP % 4d / % 4d", char_info->sp, char_info->max_sp);
+ sp->setCaption(tempstr);
+ sp->adjustSize();
+
+ healthBar->setProgress((float)char_info->hp / (float)char_info->max_hp);
+
+ delete tempstr;
}
diff --git a/src/gui/stats.h b/src/gui/stats.h
index d95dbb9c..a10a9c70 100644
--- a/src/gui/stats.h
+++ b/src/gui/stats.h
@@ -26,10 +26,30 @@
#ifndef _STATS_H
#define _STATS_H
-#include <allegro.h>
#include "../main.h"
#include "gui.h"
+#include "window.h"
+#include "progressbar.h"
+#include <allegro.h>
+
+/**
+ * The player statistics dialog.
+ *
+ * \ingroup GUI
+ */
+class StatsDialog : public Window {
+ public:
+ StatsDialog(gcn::Container *parent);
+ ~StatsDialog();
+
+ /**
+ * Updates this dialog with values from PLAYER_INFO *char_info
+ */
+ void update();
-void update_stats_dialog();
+ private:
+ gcn::Label *hp, *sp, *gp;
+ ProgressBar *healthBar, *manaBar;
+};
#endif
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index eb886538..75208350 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -23,7 +23,7 @@
#include "gui.h"
#include <guichan/allegro.hpp>
-Window::Window(gcn::Container *parent, std::string text) :
+Window::Window(gcn::Container *parent, const std::string& text) :
caption(text),
mousePX(0),
mousePY(0),
@@ -112,6 +112,11 @@ void Window::draw(gcn::Graphics* graphics)
drawChildren(graphics);
}
+void Window::setTitle(const std::string& text)
+{
+ caption = std::string(text);
+}
+
void Window::setDimension(const gcn::Rectangle &dimension)
{
gcn::Container::setDimension(gcn::Rectangle(
diff --git a/src/gui/window.h b/src/gui/window.h
index 3fa3f58f..92fe0313 100644
--- a/src/gui/window.h
+++ b/src/gui/window.h
@@ -49,7 +49,7 @@ class Window : public gcn::Container, public gcn::MouseListener
BITMAP *dRight; /**< Right side of title bar */
public:
- Window(gcn::Container *parent, std::string text = "Window");
+ Window(gcn::Container *parent, const std::string& text = "Window");
~Window();
/**
@@ -68,6 +68,11 @@ class Window : public gcn::Container, public gcn::MouseListener
void add(gcn::Widget *w, int x, int y);
/**
+ * Sets the title of the window.
+ */
+ void setTitle(const std::string& text);
+
+ /**
* Sets the dimension of the window contents.
*/
void setDimension(const gcn::Rectangle& dimension);