summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am1
-rw-r--r--src/gui/char_select.cpp70
-rw-r--r--src/gui/char_select.h13
-rw-r--r--src/gui/confirm_dialog.cpp93
-rw-r--r--src/gui/confirm_dialog.h74
-rw-r--r--src/gui/gui.cpp164
-rw-r--r--src/gui/gui.h12
-rw-r--r--src/gui/windowcontainer.cpp3
8 files changed, 225 insertions, 205 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 8657d35e..5589a5ff 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -10,6 +10,7 @@ tmw_SOURCES = sound/sound.cpp \
gui/char_select.cpp \
gui/chat.cpp \
gui/checkbox.cpp \
+ gui/confirm_dialog.cpp \
gui/gui.cpp \
gui/inventory.cpp \
gui/listbox.cpp \
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index 30c2d2f3..259a01b9 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -31,6 +31,21 @@
#define NR_HAIR_STYLES 4
#define NR_HAIR_COLORS 10
+CharSelectDialog::CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m):
+ ConfirmDialog(m,
+ "Confirm", "Are you sure you want to delete this character?"),
+ master(m)
+{
+}
+
+void CharSelectDialog::CharDeleteConfirm::action(const std::string &eventId)
+{
+ ConfirmDialog::action(eventId);
+ if (eventId == "yes") {
+ master->serverCharDelete();
+ }
+}
+
CharSelectDialog::CharSelectDialog():
Window("Select Character")
{
@@ -118,7 +133,7 @@ void CharSelectDialog::action(const std::string& eventId)
} else if (eventId == "delete") {
// Delete character
if (n_character > 0) {
- serverCharDelete();
+ new CharDeleteConfirm(this);
}
}
}
@@ -155,35 +170,32 @@ void CharSelectDialog::setPlayerInfo(PLAYER_INFO *pi)
}
void CharSelectDialog::serverCharDelete() {
- // Delete a character
- if (yes_no("Confirm", "Are you sure?") == 0) {
- // Request character deletion
- WFIFOW(0) = net_w_value(0x0068);
- WFIFOL(2) = net_l_value(char_info->id);
- WFIFOSET(46);
-
- while ((in_size < 2) || (out_size > 0)) flush();
- if (RFIFOW(0) == 0x006f) {
- RFIFOSKIP(2);
- free(char_info);
- n_character = 0;
- setPlayerInfo(NULL);
- new OkDialog(this, "Info", "Player deleted");
- }
- else if (RFIFOW(0) == 0x006c) {
- switch (RFIFOB(2)) {
- case 0:
- new OkDialog(this, "Error", "Access denied");
- break;
- case 1:
- new OkDialog(this, "Error", "Cannot use this ID");
- break;
- }
- RFIFOSKIP(3);
- }
- else {
- new OkDialog(this, "Error", "Unknown error");
+ // Request character deletion
+ WFIFOW(0) = net_w_value(0x0068);
+ WFIFOL(2) = net_l_value(char_info->id);
+ WFIFOSET(46);
+
+ while ((in_size < 2) || (out_size > 0)) flush();
+ if (RFIFOW(0) == 0x006f) {
+ RFIFOSKIP(2);
+ free(char_info);
+ n_character = 0;
+ setPlayerInfo(NULL);
+ new OkDialog(this, "Info", "Player deleted");
+ }
+ else if (RFIFOW(0) == 0x006c) {
+ switch (RFIFOB(2)) {
+ case 0:
+ new OkDialog(this, "Error", "Access denied");
+ break;
+ case 1:
+ new OkDialog(this, "Error", "Cannot use this ID");
+ break;
}
+ RFIFOSKIP(3);
+ }
+ else {
+ new OkDialog(this, "Error", "Unknown error");
}
}
diff --git a/src/gui/char_select.h b/src/gui/char_select.h
index f1675cb1..ac3909bb 100644
--- a/src/gui/char_select.h
+++ b/src/gui/char_select.h
@@ -29,6 +29,7 @@
#include "../main.h"
#include "../net/network.h"
#include "gui.h"
+#include "confirm_dialog.h"
#include "playerbox.h"
#include <guichan/allegro.hpp>
@@ -61,6 +62,18 @@ class CharSelectDialog : public Window, public gcn::ActionListener {
*/
void serverCharSelect();
+ /**
+ * Listener for confirming character deletion.
+ */
+ class CharDeleteConfirm : public ConfirmDialog
+ {
+ public:
+ CharDeleteConfirm(CharSelectDialog *master);
+ void action(const std::string &eventId);
+ private:
+ CharSelectDialog *master;
+ };
+
public:
/**
* Constructor.
diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp
new file mode 100644
index 00000000..3a92e3f8
--- /dev/null
+++ b/src/gui/confirm_dialog.cpp
@@ -0,0 +1,93 @@
+/*
+ * 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
+ *
+ * $Id$
+ */
+
+#include "confirm_dialog.h"
+#include "button.h"
+
+ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg,
+ gcn::ActionListener *listener):
+ Window(title, true)
+{
+ init(msg, listener);
+}
+
+ConfirmDialog::ConfirmDialog(Window *parent, const std::string &title,
+ const std::string &msg, gcn::ActionListener *listener):
+ Window(title, true, parent)
+{
+ init(msg, listener);
+}
+
+void ConfirmDialog::init(const std::string &msg, gcn::ActionListener *listener)
+{
+ userLabel = new gcn::Label(msg);
+ yesButton = new Button("Yes");
+ noButton = new Button("No");
+
+ int w = userLabel->getWidth() + 20;
+ int inWidth = yesButton->getWidth() + noButton->getWidth() + 5;
+ int h = userLabel->getHeight() + 25 + yesButton->getHeight();
+
+ if (w < inWidth + 10) {
+ w = inWidth + 10;
+ }
+
+ setSize(w, h);
+ userLabel->setPosition(10, 10);
+ yesButton->setPosition(
+ (w - inWidth) / 2,
+ h - 5 - noButton->getHeight());
+ noButton->setPosition(
+ yesButton->getX() + yesButton->getWidth() + 5,
+ h - 5 - noButton->getHeight());
+
+ yesButton->setEventId("yes");
+ noButton->setEventId("no");
+ yesButton->addActionListener(this);
+ noButton->addActionListener(this);
+ if (listener) {
+ yesButton->addActionListener(listener);
+ noButton->addActionListener(listener);
+ }
+
+ add(userLabel);
+ add(yesButton);
+ add(noButton);
+
+ setLocationRelativeTo(getParent());
+ yesButton->requestFocus();
+}
+
+ConfirmDialog::~ConfirmDialog()
+{
+ delete userLabel;
+ delete yesButton;
+ delete noButton;
+}
+
+void ConfirmDialog::action(const std::string &eventId)
+{
+ if (eventId == "yes" || eventId == "no") {
+ windowContainer->scheduleDelete(this);
+ }
+}
diff --git a/src/gui/confirm_dialog.h b/src/gui/confirm_dialog.h
new file mode 100644
index 00000000..fcbd9b0f
--- /dev/null
+++ b/src/gui/confirm_dialog.h
@@ -0,0 +1,74 @@
+/*
+ * 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
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_OPTION_DIALOG_H
+#define _TMW_OPTION_DIALOG_H
+
+#include "gui.h"
+#include "window.h"
+
+/**
+ * An option dialog.
+ *
+ * \ingroup GUI
+ */
+class ConfirmDialog : public Window, public gcn::ActionListener {
+ public:
+ /**
+ * Constructor.
+ *
+ * @see Window::Window
+ */
+ ConfirmDialog(const std::string &title, const std::string &msg,
+ gcn::ActionListener *listener = NULL);
+
+ /**
+ * Constructor with parent reference.
+ *
+ * @see Window::Window
+ */
+ ConfirmDialog(Window *window, const std::string &title,
+ const std::string &msg,
+ gcn::ActionListener *listener = NULL);
+
+ /**
+ * Destructor.
+ */
+ ~ConfirmDialog();
+
+ /**
+ * Called when receiving actions from the widgets.
+ */
+ void action(const std::string& eventId);
+
+ private:
+ /**
+ * Initializes the dialog.
+ */
+ void init(const std::string &msg, gcn::ActionListener *listener);
+
+ gcn::Label *userLabel;
+ gcn::Button *yesButton, *noButton;
+};
+
+#endif
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 2a59370f..1ca5dc8f 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -594,167 +594,3 @@ void gui_shutdown(void) {
destroy_bitmap(gui__repository[a]);
}
}
-
-int gui_text(BITMAP *bmp, AL_CONST char *s, int x, int y, int color, int centre) {
- char tmp[1024];
- int hline_pos = -1;
- int len = 0;
- int in_pos = 0;
- int out_pos = 0;
- int pix_len, c;
-
- while (((c = ugetc(s+in_pos)) != 0) && (out_pos<(int)(sizeof(tmp)-ucwidth(0)))) {
- if (c == '&') {
- in_pos += uwidth(s+in_pos);
- c = ugetc(s+in_pos);
- if (c == '&') {
- out_pos += usetc(tmp+out_pos, '&');
- in_pos += uwidth(s+in_pos);
- len++;
- } else hline_pos = len;
- } else {
- out_pos += usetc(tmp+out_pos, c);
- in_pos += uwidth(s+in_pos);
- len++;
- }
- }
- usetc(tmp+out_pos, 0);
- pix_len = text_length(font, tmp);
-
- if (centre)x -= pix_len / 2;
- if (bmp) {
- textprintf_ex(bmp, font, x, y, color, -1, tmp);
- if (hline_pos >= 0) {
- c = ugetat(tmp, hline_pos);
- usetat(tmp, hline_pos, 0);
- hline_pos = text_length(font, tmp);
- c = usetc(tmp, c);
- usetc(tmp+c, 0);
- c = text_length(font, tmp);
- hline(bmp, x+hline_pos, y+text_height(font)-gui_font_baseline, x+hline_pos+c-1, color);
- }
- }
- return pix_len;
-}
-
-int tmw_text_proc(int msg, DIALOG *d, int c) {
- if (msg == MSG_DRAW) {
- gui_text(gui_bitmap, (char *)d->dp, d->x, d->y, d->fg, FALSE);
- }
- return D_O_K;
-}
-
-int tmw_button_proc(int msg, DIALOG *d, int c)
-{
- int col = 0;
- int ofs = 0;
- int ret = D_O_K;
-
- if (msg == MSG_DRAW) {
- rectfill(gui_bitmap, d->x, d->y, d->x + d->w, d->y+d->h, makecol(255,255,255));
-
- if (d->flags & D_DISABLED) {
- draw_skinned_rect(gui_bitmap, &gui_skin.button.background[3], d->x, d->y, d->w, d->h);
- col = gui_skin.button.textcolor[3];
- } else if (d->flags & D_SELECTED) {
- draw_skinned_rect(gui_bitmap, &gui_skin.button.background[2], d->x, d->y, d->w, d->h);
- col = gui_skin.button.textcolor[2];
- ofs = 1;
- } else if (d->flags & D_GOTMOUSE) {
- draw_skinned_rect(gui_bitmap, &gui_skin.button.background[1], d->x, d->y, d->w, d->h);
- col = gui_skin.button.textcolor[1];
- } else {
- draw_skinned_rect(gui_bitmap, &gui_skin.button.background[0], d->x, d->y, d->w, d->h);
- col = gui_skin.button.textcolor[0];
- }
- gui_text(gui_bitmap, (const char *)d->dp, d->x+d->w/2+ofs, d->y+d->h/2-text_height(font)/2+ofs, col, TRUE);
- ret = D_O_K;
- } else {
- /*
- if (msg == MSG_CLICK) {
- if (d->d1 == 1) ((int)d->dp2) + 1;
- else if (d->d1 == 2) ((int)d->dp2) - 1;
- }
- */
-
- ret = d_button_proc(msg,d,c);
- }
- return ret;
-}
-
-
-int tmw_dialog_proc(int msg, DIALOG *d, int c) {
- int x, y;
-
- switch (msg) {
- case MSG_CLICK:
- if (mouse_y<d->y + gui_skin.dialog.bg.grid[1]->h) {
- d->d1 = mouse_x - d->x;
- d->d2 = mouse_y - d->y;
- }
- break;
- case MSG_DRAW:
- if((mouse_b & 1) && (d->d1 >= 0) && (d->d2 >= 0)) {
- x = mouse_x - d->d1;
- y = mouse_y - d->d2;
- if (x < 15) {
- x = 0;
- position_mouse(d->d1, mouse_y);
- }
- if (y < 15) {
- y = 0;
- position_mouse(mouse_x, d->d2);
- }
- if (x + d->w >= SCREEN_W - 15) {
- x = SCREEN_W - d->w;
- position_mouse(x+d->d1, mouse_y);
- }
- if (y + d->h >= SCREEN_H - 15) {
- y = SCREEN_H - d->h;
- position_mouse(mouse_x, y + d->d2);
- }
- position_dialog(d, x, y);
- } else {
- d->d1 = -1;
- d->d2 = -1;
- }
- draw_skinned_rect(gui_bitmap, &gui_skin.dialog.bg,
- d->x, d->y, d->w, d->h);
-
- 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", (char*)d->dp);
-
- break;
- }
- return D_O_K;
-}
-
-unsigned int yes_no(const char *title, const char *message) {
- unsigned int ret;
- DIALOG alert_dialog[] = {
- /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
- { tmw_dialog_proc, 0, 0, 0, 60, 0, -1, 0, 0, 0, 0, (void *)title, NULL, NULL },
- { tmw_text_proc, 2, 22, 0, 0, 0, 0, 0, 0, 0, 0, (void *)message, NULL, NULL },
- { tmw_button_proc, 0, 40, 44, 18, 0, -1, 'o', D_EXIT, -1, 0, (char *)"&Yes", NULL, NULL },
- { tmw_button_proc, 0, 40, 44, 18, 0, -1, 'o', D_EXIT, -1, 0, (char *)"&No", NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
- };
-
- BITMAP *temp = gui_bitmap;
- gui_bitmap = screen;
- show_mouse(screen);
- int width = text_length(font, message) + 4;
- if (width < 100) width = 100;
- alert_dialog[0].w = width;
- alert_dialog[1].w = text_length(font, message);
- alert_dialog[1].h = text_height(font);
- alert_dialog[2].x = width / 2 - 46;
- alert_dialog[2].x = width / 2 + 2;
- position_dialog(alert_dialog, 400 - width / 2, 270);
- ret = do_dialog(alert_dialog, 3);
- show_mouse(NULL);
- gui_bitmap = temp;
- return ret - 2;
-}
diff --git a/src/gui/gui.h b/src/gui/gui.h
index 504c9ceb..f734e6a1 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -178,16 +178,4 @@ void gui_shutdown(void);
void draw_skinned_rect(BITMAP*dst, LexSkinnedRect *skin,
int x, int y, int w, int h);
-/** Draw text for gui widgets */
-int gui_text(BITMAP *bmp, AL_CONST char *s,
- int x, int y, int color, int centre);
-
-// Old Allegro GUI procs
-int tmw_button_proc(int msg, DIALOG *d, int c);
-int tmw_text_proc(int msg, DIALOG *d, int c);
-int tmw_dialog_proc(int msg, DIALOG *d, int c);
-
-// Last remaining Allegro GUI dialog
-unsigned int yes_no(const char *title, const char *message);
-
#endif
diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp
index 3367b5f4..c7e466fe 100644
--- a/src/gui/windowcontainer.cpp
+++ b/src/gui/windowcontainer.cpp
@@ -161,5 +161,8 @@ gcn::Widget *WindowContainer::getModalWindow()
void WindowContainer::scheduleDelete(gcn::Widget *widget)
{
+ if (widget == (gcn::Widget*)modalWindow) {
+ setModalWindow(NULL);
+ }
deathList.push_back(widget);
}