summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorMateusz Kaduk <mateusz.kaduk@gmail.com>2004-12-12 17:51:50 +0000
committerMateusz Kaduk <mateusz.kaduk@gmail.com>2004-12-12 17:51:50 +0000
commit812e679c9befbfe98cc311723b8296df0384515e (patch)
treefe349e783efc0ee70ab60bcce866bdc4f9b67752 /src
parent197b684831c9701635fd140bbb06a6c2b3f0fcc7 (diff)
downloadmana-client-812e679c9befbfe98cc311723b8296df0384515e.tar.gz
mana-client-812e679c9befbfe98cc311723b8296df0384515e.tar.bz2
mana-client-812e679c9befbfe98cc311723b8296df0384515e.tar.xz
mana-client-812e679c9befbfe98cc311723b8296df0384515e.zip
Created setup class and changed to use guichan
Diffstat (limited to 'src')
-rw-r--r--src/game.cpp3
-rw-r--r--src/graphic/graphic.cpp7
-rw-r--r--src/gui/setup.cpp162
-rw-r--r--src/gui/setup.h30
4 files changed, 81 insertions, 121 deletions
diff --git a/src/game.cpp b/src/game.cpp
index 7b15b9ea..cdf4f7c2 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -48,6 +48,7 @@ volatile int tick_time;
volatile bool refresh = false, action_time = false;
int current_npc, server_tick;
extern unsigned char screen_mode;
+bool show_setup;
#define MAX_TIME 10000
@@ -238,7 +239,7 @@ void do_input() {
}
if(key[KEY_F11] && action_time==true)
- show_player_setup = true;
+ show_setup = true;
// Emotions, Skill dialog
if(key_shifts & KB_ALT_FLAG && action_time == true) {
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index 184ede63..efc0637f 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -54,6 +54,8 @@ bool show_skill_list_dialog = false;
char npc_button[10] = "Close";
gcn::TextField *chatInput;
+Setup *setup;
+extern bool show_setup;
void ChatListener::action(const std::string& eventId)
{
@@ -224,7 +226,7 @@ void init_graphic() {
clear_to_color(chat_background, makecol(0,0,0));
// Initialize gui
-
+
// Create chat input field
chatInput = new gcn::TextField();
chatInput->setPosition(0, SCREEN_H - chatInput->getHeight());
@@ -245,7 +247,6 @@ void init_graphic() {
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);
- init_setup();
//gui_bitmap = vpage[page_num];
alfont_text_mode(-1);
inventory.create(100, 100);
@@ -587,8 +588,6 @@ new_tileset->spriteset[0]->draw(vbuffer, 0, 0);
// character status display
update_stats_dialog();
gui_update(stats_player);
- update_setup();
-
draw_sprite(vpage[page_num], mouse_sprite, mouse_x, mouse_y);
#ifdef WIN32
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index b88fc8cd..c8b677db 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -5,133 +5,69 @@
* setup dialog.
*/
-#include <allegro.h>
-#include "gui.h"
+#include "setup.h"
-#define CONFIG_FILE "tmw.ini"
-
-extern unsigned int screen_mode;
-
-DIALOG_PLAYER *player_setup; /* Pointer to player's dialog */
-bool show_player_setup; /* Switch for setup dialog */
-
-typedef struct {
- int width, height;
- char* desc;
-} LIST; /* New type for holding video modes */
-
-int apply_setup(int msg, DIALOG *d, int c); /* Need this here in order to access dialog directly */
-
-/*
- * Hard coded list cuz get_gfx_mode_list fails with AUTODETECT
- */
-const LIST mode_list[] = {
- { 1024,768, "1024x768" },
- { 800,600, "800x600" },
- { 640,480, "640x480"}
-};
+extern bool show_setup;
/*
- * Get video modes list for setup
+ * Setup action listener
*/
-char *get_listbox_video_modes(int index, int *list_size)
-{
- if (index < 0 & index < 4) {
- *list_size = 3;
- return NULL;
- } else
- return mode_list[index].desc;
-}
-
-/*
- * Calls orginal tmw_button_proc and If D_O_K was cliked calls function in dp3
- */
-int tmw_ok_button_proc(int msg, DIALOG *d, int c)
-{
- int ret;
-
- ret = tmw_button_proc(msg, d, c); // returns D_CLOSE when D_O_K was clicked otherwise D_O_K
-
- if(ret == D_CLOSE && d->dp3 != NULL)
- return ((int(*)(void))d->dp3)();
-
- return ret;
+void SetupActionListener::action(const std::string& eventId) {
+ if(eventId == "apply") {
+ puts("apply");
+ show_setup = false;
+ } else if (eventId == "cancel") {
+ puts("calncel");
+ show_setup = false;
+ }
}
/*
- * Array for dialog objects and callbacks
- */
-DIALOG setup_dialog[] =
- {
- /* Dialog proc*/
- { tmw_dialog_proc, 300, 300, 300, 200, 0, 0, 0, 0, 0, 0, (char *)"Setup", NULL, NULL },
-
- /* Descriptions */
- { tmw_text_proc, 305, 320, 0, 0, 0, 0, 0, 0, 0, 0, (char *)"Display", NULL, NULL },
- { tmw_text_proc, 435, 320, 0, 0, 0, 0, 0, 0, 0, 0, (char *)"Strech modes", NULL, NULL },
-
- /* List */
- { tmw_list_proc, 305, 345, 100, 100, 0, 0, 0, 0, 0, 0, (char *)get_listbox_video_modes, NULL, NULL },
-
- /* Radio buttons */
- //{ tmw_radio_proc, 435, 339, 160, 19, 0, 0, 0, 0, 0, 0, (char *)"Normal", NULL, NULL },
- //{ tmw_radio_proc, 435, 358, 160, 19, 0, 0, 0, 0, 0, 0, (char *)"2xSaI", NULL, NULL },
- //{ tmw_radio_proc, 435, 377, 160, 19, 0, 0, 0, 0, 0, 0, (char *)"SuperEagle", NULL, NULL },
-
- /* Buttons */
- { tmw_ok_button_proc, 315, 470, 40, 20, 0, 0, 0, D_EXIT, 0, 0, (char *)"&Ok", NULL, (int*)apply_setup },
- { tmw_ok_button_proc, 535, 470, 40, 20, 0, 0, 0, D_EXIT, 0, 0, (char *)"&Cancel", NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
- };
-
-/*
- * Apply setup settings
+ * Display setup dialog
*/
-int apply_setup(int msg, DIALOG *d, int c) {
+Setup::Setup() {
+ visible = false;
+ setupDialog = new gcn::Container();
+ displayLabel = new gcn::Label("Display");
+ applyButton = new gcn::Button("Apply");
+ cancelButton = new gcn::Button("Cancel");
- int index = 0;
- int index_loaded = 0, value;
+ /* Set dialog elements */
+ setupDialog->setDimension(gcn::Rectangle(300,300,200,200));
+ displayLabel->setPosition(4,14);
+ applyButton->setPosition(30,162);
+ cancelButton->setPosition(146,162);
- /* Load settings from file */
- if(get_config_int("[settings]","selected_vmode",value) == 1)
- index_loaded = value;
+ /* Set events */
+ applyButton->setEventId("apply");
+ cancelButton->setEventId("cancel");
- /* Check if settings changed if so use and save them */
- if((index = setup_dialog[3].d1) != index_loaded) {
- set_config_int("[settings]","selected_vmode",index);
- flush_config_file();
- }
+ /* Listen for actions */
+ SetupActionListener *setupActionListener = new SetupActionListener();
+ applyButton->addActionListener(setupActionListener);
+ cancelButton->addActionListener(setupActionListener);
- /*
- if(set_gfx_mode(screen_mode, list[index].width, list[index].height, 0, 0))
- error(allegro_error);
- */
- return D_CLOSE; // closes the dialog
+ /* Assemble dialog */
+ setupDialog->add(displayLabel);
+ setupDialog->add(applyButton);
+ setupDialog->add(cancelButton);
+
+ setupDialog->setVisible(visible);
+ guiTop->add(setupDialog);
}
-/*
- * Initialize setup dialog
- */
-void init_setup(void) {
- int value = 0;
-
- show_player_setup = false; // setup starts as hidden
-
- /* Initialize */
- player_setup = init_dialog(setup_dialog, -1);
- position_dialog(setup_dialog, 300, 200);
- set_config_file(CONFIG_FILE);
-
- /* Set previous selections */
- value = get_config_int("[settings]","selected_vmode",0);
- setup_dialog[3].d1 = value;
+Setup::~Setup() {
+ delete setupDialog;
+ delete displayLabel;
+ delete applyButton;
+ delete cancelButton;
}
-/*
- * Update setup dialog
- */
-void update_setup(void) {
- if(show_player_setup) {
- if(gui_update(player_setup) == 0) show_player_setup = false;
- }
+void Setup::toggleVisible(bool toggle) {
+ if(visible == false && toggle == true)
+ visible == true;
+ else
+ if(visible == true && toggle == false) visible == false;
+
+ setupDialog->setVisible(visible);
}
diff --git a/src/gui/setup.h b/src/gui/setup.h
index 35700afb..1d8b859f 100644
--- a/src/gui/setup.h
+++ b/src/gui/setup.h
@@ -6,9 +6,33 @@
#ifndef tmw_included_setup_h
#define tmw_included_setup_h
-void init_setup();
-void update_setup();
+#include <allegro.h>
+#ifdef WIN32
+#include <winallegro.h>
+#endif
+#include "gui.h"
+#include "../graphic/graphic.h"
+
+class Setup {
+ public:
+ Setup();
+ ~Setup();
+ void toggleVisible(bool toggle);
+
+ private:
+ bool visible;
+ /* Dialog parts */
+ gcn::Container *setupDialog;
+ gcn::Label *displayLabel;
+ gcn::Button *applyButton;
+ gcn::Button *cancelButton;
+};
-extern bool show_player_setup;
+/* The action listener for setup dialog */
+class SetupActionListener : public gcn::ActionListener
+{
+ public:
+ void action(const std::string& eventId);
+};
#endif