summaryrefslogtreecommitdiff
path: root/src/gui/login.cpp
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/login.cpp
parent6808576588e94a3143120a1d1ac308092969f87e (diff)
downloadmana-37061920bc263e9d5350aa2d83a7e7785fedc1df.tar.gz
mana-37061920bc263e9d5350aa2d83a7e7785fedc1df.tar.bz2
mana-37061920bc263e9d5350aa2d83a7e7785fedc1df.tar.xz
mana-37061920bc263e9d5350aa2d83a7e7785fedc1df.zip
Added Guichan and converted login dialog. Also resolved some naming conflicts.
Diffstat (limited to 'src/gui/login.cpp')
-rw-r--r--src/gui/login.cpp198
1 files changed, 132 insertions, 66 deletions
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();