summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-12 14:15:33 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-12 14:15:33 +0000
commit37061920bc263e9d5350aa2d83a7e7785fedc1df (patch)
treedfdf40c4eeb5d6cd4076fdeb804602b558ab2fd8 /src/gui
parent6808576588e94a3143120a1d1ac308092969f87e (diff)
downloadmana-client-37061920bc263e9d5350aa2d83a7e7785fedc1df.tar.gz
mana-client-37061920bc263e9d5350aa2d83a7e7785fedc1df.tar.bz2
mana-client-37061920bc263e9d5350aa2d83a7e7785fedc1df.tar.xz
mana-client-37061920bc263e9d5350aa2d83a7e7785fedc1df.zip
Added Guichan and converted login dialog. Also resolved some naming conflicts.
Diffstat (limited to 'src/gui')
-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
5 files changed, 213 insertions, 86 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;
}
/*