summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/gui/gui.cpp84
-rw-r--r--src/gui/gui.h4
-rw-r--r--src/gui/login.cpp198
-rw-r--r--src/gui/login.h9
-rw-r--r--src/gui/setup.cpp4
-rw-r--r--src/map.cpp45
-rw-r--r--src/map.h4
7 files changed, 239 insertions, 109 deletions
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 1ef3dea4..b9dcf923 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -19,11 +19,12 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#include "gui.h"
-#include "../log.h"
-#include "allegro/internal/aintern.h"
+#include <allegro.h>
+#include <allegro/internal/aintern.h>
#include <math.h>
#include <alfont.h>
+#include "gui.h"
+#include "../log.h"
#include "../sound/sound.h"
#ifndef WIN32
@@ -55,24 +56,65 @@ extern TmwSound sound;
int (*gui__external_slider_callback)(void *, int);
int reroute_slider_proc(void *dp3, int d2);
+// Guichan Allegro stuff
+gcn::AllegroInput* input; // Input driver
+gcn::AllegroGraphics* graphics; // Graphics driver
+gcn::AllegroImageLoader* imageLoader; // For loading images
+
+// Guichan stuff
+gcn::Gui* gui; // A Gui object - binds it all together
+gcn::Container* guitop; // The top container
+gcn::ImageFont* guiFont; // A font
+
+
/** Initialize gui system */
void init_gui(BITMAP *bitmap, const char *skin) {
- gui_bitmap = bitmap;
- gui_load_skin(skin);
- //alfont_init();
- gui_font = alfont_load_font("./data/Skin/arial.ttf");
- alfont_set_font_size(gui_font, 14);
- drag = false;
- show_mouse(NULL);
+ imageLoader = new gcn::AllegroImageLoader();
+ gcn::Image::setImageLoader(imageLoader);
+
+ graphics = new gcn::AllegroGraphics();
+ graphics->setTarget(bitmap);
+
+ input = new gcn::AllegroInput();
+
+ guitop = new gcn::Container();
+ guitop->setDimension(gcn::Rectangle(0, 0, SCREEN_W, SCREEN_H));
+ guitop->setOpaque(false);
+
+ gui = new gcn::Gui();
+ gui->setGraphics(graphics);
+ gui->setInput(input);
+ gui->setTop(guitop);
+ guiFont = new gcn::ImageFont("./data/graphic/fixedfont.bmp",
+ " abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789");
+ gcn::Widget::setGlobalFont(guiFont);
+
+
+ gui_bitmap = bitmap;
+ gui_load_skin(skin);
+ //alfont_init();
+ gui_font = alfont_load_font("./data/Skin/arial.ttf");
+ alfont_set_font_size(gui_font, 14);
+ drag = false;
+ show_mouse(NULL);
}
int gui_update(DIALOG_PLAYER *player) {
- dialog_message(player->dialog, MSG_DRAW, 0, 0);
- int ret = update_dialog(player);
- draw_sprite(gui_bitmap, mouse_sprite, mouse_x, mouse_y);
- return ret;
+ int ret;
+ gui->logic();
+ gui->draw();
+
+ if (player) {
+ dialog_message(player->dialog, MSG_DRAW, 0, 0);
+ ret = update_dialog(player);
+ }
+
+ // Draw the mouse
+ draw_sprite(gui_bitmap, mouse_sprite, mouse_x, mouse_y);
+
+ return ret;
}
@@ -415,9 +457,17 @@ int gui_load_skin(const char* skinname) {
}
void gui_exit() {
- //alfont_destroy_font(gui_font);
- gui_shutdown();
- //alfont_exit();
+ delete guiFont;
+ delete guitop;
+ delete gui;
+
+ delete input;
+ delete graphics;
+ delete imageLoader;
+
+ //alfont_destroy_font(gui_font);
+ gui_shutdown();
+ //alfont_exit();
}
void gui_shutdown(void) {
diff --git a/src/gui/gui.h b/src/gui/gui.h
index e19db25f..a29d02b7 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -29,6 +29,8 @@
#include <allegro.h>
#include <alfont.h>
#include <string.h>
+#include <guichan.hpp>
+#include <guichan/allegro.hpp>
typedef struct {
BITMAP *grid[9];
@@ -101,6 +103,8 @@ extern LexSkin gui_skin;
extern BITMAP *gui_bitmap;
extern ALFONT_FONT *gui_font;
+extern gcn::Container* guitop; // The top container
+
/* Definition of the callback function prototypes */
typedef int (*gui_buttonCallback)(int id);
typedef char *(*getfuncptr)(int, int *);
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 342ea3dd..0fe39cef 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -22,87 +22,153 @@
*/
#include "login.h"
+#include "gui.h"
#include "../graphic/graphic.h"
-/** Display login GUI */
-void login() {
-DIALOG login_dialog[] = {
- /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
- { tmw_dialog_proc, 300, 252, 200, 96, 0, -1, 0, 0, 0, 0, (char*)"Login", NULL, NULL },
- { tmw_text_proc, 304, 284, 50, 10, 0, 0, 0, 0, 0, 0, (char*)"Name:", NULL, NULL },
- { tmw_text_proc, 304, 304, 50, 10, 0, 0, 0, 0, 0, 0,(char*)"Password:", NULL, NULL },
- { tmw_edit_proc, 360, 280, 130, 18, 0, -1, 0, 0, 24, 0, username, NULL, NULL },
- { tmw_password_proc, 360, 300, 130, 18, 0, -1, 0, 0, 24, 0, password, NULL, NULL },
- { tmw_button_proc, 398, 322, 44, 18, 0, -1, 'o', D_EXIT, -1, 0, (char*)"&Ok", NULL, NULL },
- { tmw_button_proc, 446, 322, 44, 18, 0, -1, 'c', D_EXIT, -1, 0, (char*)"&Cancel", NULL, NULL },
- { tmw_check_proc, 304, 322, 60, 18, 0, 0, '1', 0, 0, 0, (char*)"keep", NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
-};
-
- if(get_config_int("login", "remember", 0)!=0) {
- login_dialog[7].flags = D_SELECTED;
- if(get_config_string("login", "username", 0)) {
- strncpy(username, get_config_string("login", "username", 0), LEN_USERNAME);
- username[LEN_USERNAME] = '\0';
- }
- else strcpy(username, "player\0");
- }
- centre_dialog(login_dialog);
- DIALOG_PLAYER *player = init_dialog(login_dialog, -1);
- int gui_exit = 1;
- while ((!key[KEY_ESC])&&(gui_exit)&&(state!=EXIT)&&(!key[KEY_ENTER])) {
- clear_bitmap(buffer);
- blit((BITMAP *)graphic[LOGIN_BMP].dat, buffer, 0, 0, 0, 0, 800, 600);
- gui_exit = gui_update(player);
- blit(buffer, screen, 0, 0, 0, 0, 800, 600);
- }
- state = EXIT;
- set_config_int("login", "remember", (login_dialog[7].flags & D_SELECTED)>>1);
- if(login_dialog[7].flags & D_SELECTED) {
- if(!username)strcpy(username, "player\0");
- set_config_string("login", "username", username);
- } else set_config_string("login", "username", "player\0");
- log("Network", "Username is %s", username);
- gui_exit = shutdown_dialog(player);
- if((gui_exit==5)||(key[KEY_ENTER])) {
- if(username[0]=='\0') {
+// Dialog parts
+gcn::Container *dialog;
+gcn::Label *userLabel;
+gcn::Label *passLabel;
+gcn::TextField *userField;
+gcn::TextField *passField;
+gcn::CheckBox *keepCheck;
+gcn::Button *okButton;
+gcn::Button *cancelButton;
+
+void LoginActionListener::action(const std::string& eventId)
+{
+ if (eventId == "ok") {
+ const std::string user = userField->getText();
+ log("Network", "Username is %s", user.c_str());
+
+ // Store config settings
+ set_config_int("login", "remember", keepCheck->isMarked());
+ if (keepCheck->isMarked()) {
+ set_config_string("login", "username", user.c_str());
+ } else {
+ set_config_string("login", "username", "");
+ }
+
+ // Check login
+ if (user.length() == 0) {
ok("Error", "Enter your username first");
warning("Enter your username first");
state = LOGIN;
} else {
- server_login();
+ server_login(user, passField->getText());
close_session();
}
- }
+ } else if (eventId == "cancel") {
+ state = EXIT;
+ }
+}
+
+/*
+ * Display login GUI
+ */
+void login() {
+ // Create dialog
+ dialog = new gcn::Container();
+ userLabel = new gcn::Label("Name:");
+ passLabel = new gcn::Label("Password:");
+ userField = new gcn::TextField("player");
+ passField = new gcn::TextField();
+ keepCheck = new gcn::CheckBox("Keep", false);
+ okButton = new gcn::Button("OK");
+ cancelButton = new gcn::Button("Cancel");
+
+ dialog->setDimension(gcn::Rectangle(300, 250, 200, 80));
+ userLabel->setPosition(4, 14);
+ passLabel->setPosition(4, 34);
+ userField->setPosition(60, 10);
+ passField->setPosition(60, 30);
+ userField->setWidth(130);
+ passField->setWidth(130);
+ keepCheck->setPosition(4, 52);
+ keepCheck->setMarked(get_config_int("login", "remember", 0));
+ okButton->setPosition(120, 52);
+ cancelButton->setPosition(146, 52);
+
+ userField->setEventId("ok");
+ passField->setEventId("ok");
+ keepCheck->setEventId("ok");
+ okButton->setEventId("ok");
+ cancelButton->setEventId("cancel");
+
+ LoginActionListener *loginActionListener = new LoginActionListener();
+ userField->addActionListener(loginActionListener);
+ passField->addActionListener(loginActionListener);
+ keepCheck->addActionListener(loginActionListener);
+ okButton->addActionListener(loginActionListener);
+ cancelButton->addActionListener(loginActionListener);
+
+ dialog->add(userLabel);
+ dialog->add(passLabel);
+ dialog->add(userField);
+ dialog->add(passField);
+ dialog->add(keepCheck);
+ dialog->add(okButton);
+ dialog->add(cancelButton);
+
+ guitop->add(dialog);
+
+ if (get_config_int("login", "remember", 0)) {
+ if (get_config_string("login", "username", 0)) {
+ userField->setText(get_config_string("login", "username", ""));
+ }
+ }
+
+ userField->requestFocus();
+ userField->setCaretPosition(userField->getText().length());
+
+ while (state == LOGIN) {
+ clear_bitmap(buffer);
+ blit((BITMAP *)graphic[LOGIN_BMP].dat, buffer, 0, 0, 0, 0, 800, 600);
+ gui_update(NULL);
+ blit(buffer, screen, 0, 0, 0, 0, 800, 600);
+ if (key[KEY_ESC]) {
+ state = EXIT;
+ }
+ }
+
+ delete dialog;
+ delete userLabel;
+ delete passLabel;
+ delete userField;
+ delete passField;
+ delete keepCheck;
+ delete okButton;
+ delete cancelButton;
}
/** Attempt to login to login server */
-void server_login() {
- int ret;
+void server_login(const std::string& user, const std::string& pass) {
+ strncpy(username, user.c_str(), LEN_USERNAME);
+ strncpy(password, pass.c_str(), LEN_PASSWORD);
+ int ret;
// Connect to login server
- ret = open_session(get_config_string("server", "host", 0), get_config_int("server", "port", 0));
- if(ret==SOCKET_ERROR) {
- state = LOGIN;
- ok("Error", "Unable to connect to login server");
- warning("Unable to connect to login server");
- return;
- }
-
- // Send login infos
+ ret = open_session(get_config_string("server", "host", 0), get_config_int("server", "port", 0));
+ if (ret == SOCKET_ERROR) {
+ state = LOGIN;
+ ok("Error", "Unable to connect to login server");
+ warning("Unable to connect to login server");
+ return;
+ }
+ // Send login infos
- WFIFOW(0) = net_w_value(0x0064);
-
- WFIFOL(2) = 0;
- memcpy(WFIFOP(6), username, 24);
- memcpy(WFIFOP(30), password, 24);
- WFIFOB(54) = 0;
- WFIFOSET(55);
-
- while((in_size<23)||(out_size>0))flush();
- log("Network", "Packet ID: %x", RFIFOW(0));
- log("Network", "Packet length: %d", get_packet_length(RFIFOW(0)));
+ WFIFOW(0) = net_w_value(0x0064);
+
+ WFIFOL(2) = 0;
+ memcpy(WFIFOP(6), username, 24);
+ memcpy(WFIFOP(30), password, 24);
+ WFIFOB(54) = 0;
+ WFIFOSET(55);
+
+ while((in_size<23)||(out_size>0))flush();
+ log("Network", "Packet ID: %x", RFIFOW(0));
+ log("Network", "Packet length: %d", get_packet_length(RFIFOW(0)));
if(RFIFOW(0)==0x0069) {
while(in_size<RFIFOW(2))flush();
diff --git a/src/gui/login.h b/src/gui/login.h
index 6f7340fd..9f8f49b6 100644
--- a/src/gui/login.h
+++ b/src/gui/login.h
@@ -35,7 +35,14 @@
#include "../net/network.h"
#include "gui.h"
+// The action listener for the login dialog
+class LoginActionListener : public gcn::ActionListener
+{
+ public:
+ void action(const std::string& eventId);
+};
+
void login();
-void server_login();
+void server_login(const std::string& user, const std::string& pass);
#endif
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index a8059799..b88fc8cd 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -25,7 +25,7 @@ int apply_setup(int msg, DIALOG *d, int c); /* Need this here in order to acces
/*
* Hard coded list cuz get_gfx_mode_list fails with AUTODETECT
*/
-const LIST list[] = {
+const LIST mode_list[] = {
{ 1024,768, "1024x768" },
{ 800,600, "800x600" },
{ 640,480, "640x480"}
@@ -40,7 +40,7 @@ char *get_listbox_video_modes(int index, int *list_size)
*list_size = 3;
return NULL;
} else
- return list[index].desc;
+ return mode_list[index].desc;
}
/*
diff --git a/src/map.cpp b/src/map.cpp
index 125f2e0e..e10bb9fd 100644
--- a/src/map.cpp
+++ b/src/map.cpp
@@ -30,7 +30,7 @@
#include "./net/win2linux.h"
#endif
-MAP map;
+MAP tiled_map;
/** Loads a map file */
bool load_map(char *map_file) {
@@ -39,7 +39,7 @@ bool load_map(char *map_file) {
warning(map_file);
return false;
}
- pack_fread(&map, sizeof(MAP), file);
+ pack_fread(&tiled_map, sizeof(MAP), file);
pack_fclose(file);
return true;
}
@@ -47,13 +47,13 @@ bool load_map(char *map_file) {
/** Set walkability flag for a tile */
void set_walk(short x_c, short y_c, bool walkable) {
- if(walkable==true)map.tiles[x_c][y_c].data[3] |= 0x0002;
- else map.tiles[x_c][y_c].data[3] &= 0x00fd;
+ if(walkable==true)tiled_map.tiles[x_c][y_c].data[3] |= 0x0002;
+ else tiled_map.tiles[x_c][y_c].data[3] &= 0x00fd;
}
/** Tell if a tile is walkable or not */
bool get_walk(short x_c, short y_c) {
- bool ret = (map.tiles[x_c][y_c].data[3] & 0x0002)>0;
+ bool ret = (tiled_map.tiles[x_c][y_c].data[3] & 0x0002)>0;
if(ret==true) {
NODE *node = get_head();
while(node && ret==true) {
@@ -73,9 +73,9 @@ unsigned char get_path_walk(unsigned short x, unsigned short y) {
/** Tell if a tile is animated or not */
bool get_anim(short x_c, short y_c, char layer) {
- char temp = map.tiles[x_c][y_c].flags & 0x00C0;
+ char temp = tiled_map.tiles[x_c][y_c].flags & 0x00C0;
temp>>=6;
- if(abs(temp)==layer)return (map.tiles[x_c][y_c].data[3] & 0x0001)>0;
+ if(abs(temp)==layer)return (tiled_map.tiles[x_c][y_c].data[3] & 0x0001)>0;
else return false;
}
@@ -83,21 +83,21 @@ bool get_anim(short x_c, short y_c, char layer) {
void set_tile(short x_c, short y_c, char layer, unsigned short id) {
if(layer==0) {
id <<= 6;
- map.tiles[x_c][y_c].data[0] = HIBYTE(id);
- map.tiles[x_c][y_c].data[1] &= 0x003f;
- map.tiles[x_c][y_c].data[1] |= LOBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[0] = HIBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[1] &= 0x003f;
+ tiled_map.tiles[x_c][y_c].data[1] |= LOBYTE(id);
} else if(layer==1) {
id <<= 4;
- map.tiles[x_c][y_c].data[1] &= 0x00c0;
- map.tiles[x_c][y_c].data[1] |= HIBYTE(id);
- map.tiles[x_c][y_c].data[2] &= 0x000f;
- map.tiles[x_c][y_c].data[2] |= LOBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[1] &= 0x00c0;
+ tiled_map.tiles[x_c][y_c].data[1] |= HIBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[2] &= 0x000f;
+ tiled_map.tiles[x_c][y_c].data[2] |= LOBYTE(id);
} else if(layer==2) {
id <<= 2;
- map.tiles[x_c][y_c].data[2] &= 0x00f0;
- map.tiles[x_c][y_c].data[2] |= HIBYTE(id);
- map.tiles[x_c][y_c].data[3] &= 0x0003;
- map.tiles[x_c][y_c].data[3] |= LOBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[2] &= 0x00f0;
+ tiled_map.tiles[x_c][y_c].data[2] |= HIBYTE(id);
+ tiled_map.tiles[x_c][y_c].data[3] &= 0x0003;
+ tiled_map.tiles[x_c][y_c].data[3] |= LOBYTE(id);
}
}
@@ -105,13 +105,16 @@ void set_tile(short x_c, short y_c, char layer, unsigned short id) {
unsigned short get_tile(short x_c, short y_c, char layer) {
unsigned short id;
if(layer==0) {
- id = MAKEWORD(map.tiles[x_c][y_c].data[1] & 0x00c0, map.tiles[x_c][y_c].data[0]);
+ id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[1] & 0x00c0,
+ tiled_map.tiles[x_c][y_c].data[0]);
id >>= 6;
} else if(layer==1) {
- id = MAKEWORD(map.tiles[x_c][y_c].data[2] & 0x00f0, map.tiles[x_c][y_c].data[1] & 0x003f);
+ id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[2] & 0x00f0,
+ tiled_map.tiles[x_c][y_c].data[1] & 0x003f);
id >>= 4;
} else if(layer==2) {
- id = MAKEWORD(map.tiles[x_c][y_c].data[3] & 0x00fc, map.tiles[x_c][y_c].data[2] & 0x000f);
+ id = MAKEWORD(tiled_map.tiles[x_c][y_c].data[3] & 0x00fc,
+ tiled_map.tiles[x_c][y_c].data[2] & 0x000f);
id >>=2;
}
return id;
diff --git a/src/map.h b/src/map.h
index ff9b6309..02dba1c3 100644
--- a/src/map.h
+++ b/src/map.h
@@ -19,8 +19,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
-#ifndef _MAP_H
-#define _MAP_H
+#ifndef _TMW_MAP_H
+#define _TMW_MAP_H
#define MAP_WIDTH 200
#define MAP_HEIGHT 200