summaryrefslogtreecommitdiff
path: root/src/gui
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 /src/gui
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.
Diffstat (limited to 'src/gui')
-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
8 files changed, 214 insertions, 52 deletions
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);