summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-12 19:58:11 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2004-12-12 19:58:11 +0000
commit75b19e771c527e8444aae70543b2b617dae2e892 (patch)
tree7414fdd8d4a9bb9da3a79cd29a833c22f4380284 /src
parent812e679c9befbfe98cc311723b8296df0384515e (diff)
downloadmana-75b19e771c527e8444aae70543b2b617dae2e892.tar.gz
mana-75b19e771c527e8444aae70543b2b617dae2e892.tar.bz2
mana-75b19e771c527e8444aae70543b2b617dae2e892.tar.xz
mana-75b19e771c527e8444aae70543b2b617dae2e892.zip
Ported server list dialog over to Guichan.
Diffstat (limited to 'src')
-rw-r--r--src/graphic/graphic.cpp7
-rw-r--r--src/gui/char_server.cpp255
-rw-r--r--src/gui/char_server.h15
-rw-r--r--src/gui/chat.cpp2
-rw-r--r--src/gui/login.cpp1
5 files changed, 168 insertions, 112 deletions
diff --git a/src/graphic/graphic.cpp b/src/graphic/graphic.cpp
index efc0637f..4cb1c815 100644
--- a/src/graphic/graphic.cpp
+++ b/src/graphic/graphic.cpp
@@ -123,13 +123,6 @@ DIALOG skill_list_dialog[] = {
{ NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
};
-/*
-DIALOG chat_dialog[] = {
- { tmw_edit_proc, 0, 574, 592, 25, 0, 0, 'c', 0, 90, 0, speech, NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
-};
-*/
-
DIALOG npc_list_dialog[] = {
/* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
{ tmw_dialog_proc, 300, 200, 260, 200, 0, 0, 0, 0, 0, 0, (char *)"NPC", NULL, NULL },
diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp
index 7217abd8..c84fc167 100644
--- a/src/gui/char_server.cpp
+++ b/src/gui/char_server.cpp
@@ -25,118 +25,169 @@
#include "../graphic/graphic.h"
char server[30];
+int showServerList = 1;
-DIALOG char_server_dialog[] = {
- /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
- { tmw_dialog_proc, 300, 240, 200, 104, 0, -1, 0, 0, 0, 0, (char*)"Server select", NULL, NULL },
- { tmw_list_proc, 304, 262, 192, 55, 0, 0, 0, 0, 0, 0, (char*)server_list, 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 },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
-};
-
-/** Helper function to create server list */
-char *server_list(int index, int *size) {
- static char buffer[30];
- if (index < 0) {
- *size = n_server;
- return NULL;
- }
- sprintf(buffer, "%s (%i)", server_info[index].name, server_info[index].online_users);
- return buffer;
+ServerListModel *serverListModel;
+gcn::ListBox *serverList;
+
+
+void ServerSelectListener::action(const std::string& eventId) {
+ printf("%s\n", eventId.c_str());
+ if (eventId == "ok") {
+ server_char_server(serverList->getSelected());
+ }
+ else if (eventId == "cancel") {
+ }
+ showServerList = 0;
+}
+
+
+int ServerListModel::getNumberOfElements() {
+ return n_server;
+}
+
+std::string ServerListModel::getElementAt(int i) {
+ static char buffer[30];
+ sprintf(buffer, "%s (%i)", server_info[i].name,
+ server_info[i].online_users);
+ return buffer;
}
+
void char_server() {
- state = LOGIN;
- centre_dialog(char_server_dialog);
- DIALOG_PLAYER *player = init_dialog(char_server_dialog, -1);
- if(!player)ok("Error", "Unable to initialize login dialog");
- int gui_exit = 1;
- if(n_server==0)char_server_dialog[2].flags |= D_DISABLED;
- while ((!key[KEY_ESC])&&(gui_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);
- }
- gui_exit = shutdown_dialog(player);
- if((gui_exit==2)||(key[KEY_ENTER])) {
- server_char_server();
- }
+ // Create dialog
+ gcn::Container *dialog;
+ gcn::Button *okButton;
+ gcn::Button *cancelButton;
+ gcn::ScrollArea *scrollArea;
+
+ serverListModel = new ServerListModel();
+ dialog = new gcn::Container();
+ serverList = new gcn::ListBox(serverListModel);
+ scrollArea = new gcn::ScrollArea(serverList);
+ okButton = new gcn::Button("OK");
+ cancelButton = new gcn::Button("Cancel");
+
+ dialog->setDimension(gcn::Rectangle(300, 200, 200, 100));
+ scrollArea->setDimension(gcn::Rectangle(4, 4, 192, 55));
+ okButton->setPosition(120, 70);
+ cancelButton->setPosition(146, 70);
+
+ serverList->setEventId("ok");
+ okButton->setEventId("ok");
+ cancelButton->setEventId("cancel");
+
+ ServerSelectListener *actionListener = new ServerSelectListener();
+ serverList->addActionListener(actionListener);
+ okButton->addActionListener(actionListener);
+ cancelButton->addActionListener(actionListener);
+
+ dialog->add(scrollArea);
+ dialog->add(okButton);
+ dialog->add(cancelButton);
+
+ guiTop->add(dialog);
+
+ state = LOGIN;
+
+ if (n_server == 0) {
+ // Disable Ok button
+ //okButton->char_server_dialog[2].flags |= D_DISABLED;
+ } else {
+ // Select first server
+ serverList->setSelected(1);
+ }
+
+ showServerList = 1;
+ while (showServerList) {
+ 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);
+ }
+
+ delete dialog;
+ delete serverList;
+ delete serverListModel;
+ delete scrollArea;
+ delete okButton;
+ delete cancelButton;
+ delete actionListener;
}
-void server_char_server() {
- int ret;
- state = LOGIN;
+void server_char_server(int serverIndex) {
+ int ret;
+ state = LOGIN;
// Connect to char server
- ret = open_session(iptostring(server_info[char_server_dialog[1].d1].address), server_info[char_server_dialog[1].d1].port);
- if(ret==SOCKET_ERROR) {
- ok("Error", "Unable to connect to char server");
- return;
- }
-
- // Send login infos
- WFIFOW(0) = net_w_value(0x0065);
- WFIFOL(2) = net_l_value(account_ID);
- WFIFOL(6) = net_l_value(session_ID1);
- WFIFOL(10) = net_l_value(session_ID2);
- WFIFOW(14) = 0;
- WFIFOB(16) = net_b_value(sex);
- WFIFOSET(17);
-
- while((in_size<4)||(out_size>0))flush();
- RFIFOSKIP(4);
+ ret = open_session(iptostring(server_info[serverIndex].address),
+ server_info[serverIndex].port);
+ if (ret == SOCKET_ERROR) {
+ ok("Error", "Unable to connect to char server");
+ return;
+ }
+
+ // Send login infos
+ WFIFOW(0) = net_w_value(0x0065);
+ WFIFOL(2) = net_l_value(account_ID);
+ WFIFOL(6) = net_l_value(session_ID1);
+ WFIFOL(10) = net_l_value(session_ID2);
+ WFIFOW(14) = 0;
+ WFIFOB(16) = net_b_value(sex);
+ WFIFOSET(17);
+
+ while((in_size<4)||(out_size>0))flush();
+ RFIFOSKIP(4);
while(in_size<3)flush();
- if(RFIFOW(0)==0x006b) {
- while(in_size<RFIFOW(2))flush();
- n_character = (RFIFOW(2)-24)/106;
- char_info = (PLAYER_INFO *)malloc(sizeof(PLAYER_INFO)*n_character);
- for(int i=0;i<n_character;i++) {
- char_info[i].id = RFIFOL(24+106*i);
- strcpy(char_info[i].name, RFIFOP(24+106*i+74));
- char_info[i].hp = RFIFOW(24+106*i+42);
- char_info[i].max_hp = RFIFOW(24+106*i+44);
- char_info[i].xp = RFIFOL(24+106*i+4);
- char_info[i].gp = RFIFOL(24+106*i+8);
- char_info[i].job_xp = RFIFOL(24+106*i+12);
- char_info[i].job_lv = RFIFOL(24+106*i+16);
- char_info[i].sp = RFIFOW(24+106*i+46);
- char_info[i].max_sp = RFIFOW(24+106*i+48);
- char_info[i].lv = RFIFOW(24+106*i+58);
- char_info[i].STR = RFIFOB(24+106*i+98);
- char_info[i].AGI = RFIFOB(24+106*i+99);
- char_info[i].VIT = RFIFOB(24+106*i+100);
- char_info[i].INT = RFIFOB(24+106*i+101);
- char_info[i].DEX = RFIFOB(24+106*i+102);
- char_info[i].LUK = RFIFOB(24+106*i+103);
- char_info[i].hair_style = RFIFOW(24+106*i+54);
- char_info[i].hair_color = RFIFOW(24+106*i+70);
- char_info[i].weapon = RFIFOW(24+106*i+56);
- }
- state = CHAR_SELECT;
-
- log("CharServer", "Player: %s (Packet ID: %x, Length: %d",
- char_info->name, RFIFOW(0), RFIFOW(2));
-
-
- RFIFOSKIP(RFIFOW(2));
- } else if(RFIFOW(0)==0x006c) {
- switch(RFIFOB(2)) {
- case 0:
- ok("Error", "Access denied");
- break;
- case 1:
- ok("Error", "Cannot use this ID");
+ if(RFIFOW(0)==0x006b) {
+ while(in_size<RFIFOW(2))flush();
+ n_character = (RFIFOW(2)-24)/106;
+ char_info = (PLAYER_INFO *)malloc(sizeof(PLAYER_INFO)*n_character);
+ for(int i=0;i<n_character;i++) {
+ char_info[i].id = RFIFOL(24+106*i);
+ strcpy(char_info[i].name, RFIFOP(24+106*i+74));
+ char_info[i].hp = RFIFOW(24+106*i+42);
+ char_info[i].max_hp = RFIFOW(24+106*i+44);
+ char_info[i].xp = RFIFOL(24+106*i+4);
+ char_info[i].gp = RFIFOL(24+106*i+8);
+ char_info[i].job_xp = RFIFOL(24+106*i+12);
+ char_info[i].job_lv = RFIFOL(24+106*i+16);
+ char_info[i].sp = RFIFOW(24+106*i+46);
+ char_info[i].max_sp = RFIFOW(24+106*i+48);
+ char_info[i].lv = RFIFOW(24+106*i+58);
+ char_info[i].STR = RFIFOB(24+106*i+98);
+ char_info[i].AGI = RFIFOB(24+106*i+99);
+ char_info[i].VIT = RFIFOB(24+106*i+100);
+ char_info[i].INT = RFIFOB(24+106*i+101);
+ char_info[i].DEX = RFIFOB(24+106*i+102);
+ char_info[i].LUK = RFIFOB(24+106*i+103);
+ char_info[i].hair_style = RFIFOW(24+106*i+54);
+ char_info[i].hair_color = RFIFOW(24+106*i+70);
+ char_info[i].weapon = RFIFOW(24+106*i+56);
+ }
+ state = CHAR_SELECT;
+
+ log("CharServer", "Player: %s (Packet ID: %x, Length: %d",
+ char_info->name, RFIFOW(0), RFIFOW(2));
+
+
+ RFIFOSKIP(RFIFOW(2));
+ } else if(RFIFOW(0)==0x006c) {
+ switch(RFIFOB(2)) {
+ case 0:
+ ok("Error", "Access denied");
+ break;
+ case 1:
+ ok("Error", "Cannot use this ID");
+ break;
+ default:
+ ok("Error", "Rejected from server");
break;
- default:
- ok("Error", "Rejected from server");
- break;
- }
- RFIFOSKIP(3);
- close_session();
- } else ok("Error", "Unknown error");
- // Todo: add other packets
+ }
+ RFIFOSKIP(3);
+ close_session();
+ } else ok("Error", "Unknown error");
+ // Todo: add other packets
}
diff --git a/src/gui/char_server.h b/src/gui/char_server.h
index 575518ce..521aa4c9 100644
--- a/src/gui/char_server.h
+++ b/src/gui/char_server.h
@@ -32,8 +32,21 @@
#include "../net/network.h"
#include "gui.h"
+// The action listener for the server select dialog
+class ServerSelectListener : public gcn::ActionListener {
+ public:
+ void action(const std::string& eventId);
+};
+
+// The list model for the server list
+class ServerListModel : public gcn::ListModel {
+ public:
+ int getNumberOfElements();
+ std::string getElementAt(int i);
+};
+
void char_server();
-void server_char_server();
+void server_char_server(int serverIndex);
char *server_list(int index, int *size);
#endif
diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp
index b1cec890..9b1d6e4c 100644
--- a/src/gui/chat.cpp
+++ b/src/gui/chat.cpp
@@ -24,8 +24,6 @@
/*
* Simple ChatLog Object v0.5 (i'd say...)
*
- * Bestviewd w/ Bitstream Vera Sans Mono @ 9pt and a tab-width of 2 spaces
- *
* Author: kth5 aka Alexander Baldeck
* pipe your questions, suggestions and flames to: kth5@gawab.com
*/
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index c61b0e01..94c9729e 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -139,6 +139,7 @@ void login() {
delete keepCheck;
delete okButton;
delete cancelButton;
+ delete loginActionListener;
}
/** Attempt to login to login server */