summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-13 02:55:05 +0000
committerBjørn Lindeijer <bjorn@lindeijer.nl>2005-01-13 02:55:05 +0000
commit682d6a9e44e583c088ed5970d69ef6bd9db7fd23 (patch)
tree73079cdd7d9b57d104c8db400f09aabc3d833122 /src
parent3657bf87641144b605d49767cf466f04242c29c9 (diff)
downloadmana-client-682d6a9e44e583c088ed5970d69ef6bd9db7fd23.tar.gz
mana-client-682d6a9e44e583c088ed5970d69ef6bd9db7fd23.tar.bz2
mana-client-682d6a9e44e583c088ed5970d69ef6bd9db7fd23.tar.xz
mana-client-682d6a9e44e583c088ed5970d69ef6bd9db7fd23.zip
Got rid of Allegro ok dialog completely. Now just the yes_no dialog remaining.
Diffstat (limited to 'src')
-rw-r--r--src/astar.cpp4
-rw-r--r--src/configuration.cpp8
-rw-r--r--src/gui/char_select.cpp3
-rw-r--r--src/gui/gui.cpp22
-rw-r--r--src/gui/gui.h3
-rw-r--r--src/gui/login.cpp7
-rw-r--r--src/gui/ok_dialog.cpp14
-rw-r--r--src/gui/ok_dialog.h8
-rw-r--r--src/gui/setup.cpp3
-rw-r--r--src/main.cpp50
-rw-r--r--src/main.h1
-rw-r--r--src/net/protocol.cpp17
-rw-r--r--src/sound/sound.cpp26
13 files changed, 94 insertions, 72 deletions
diff --git a/src/astar.cpp b/src/astar.cpp
index 00d3be4b..a1683699 100644
--- a/src/astar.cpp
+++ b/src/astar.cpp
@@ -297,12 +297,12 @@ PATH_NODE *find_path(int pathfinderID, int s_x, int s_y, int e_x, int e_y) {
temp->next = new PATH_NODE(
path_bank[pathLocation * 2 - 2],
path_bank[pathLocation * 2 - 1]);
- if(temp->next==NULL)ok("Error", "Unable to create path node");
+ if(temp->next==NULL) throw "Unable to create path node";
temp = temp->next;
pathLocation++;
}
if(temp!=NULL)temp->next = new PATH_NODE(e_x, e_y);
- else ok("Error", "Null reference");
+ else throw "Null reference";
return ret;
}
diff --git a/src/configuration.cpp b/src/configuration.cpp
index bd8c3669..759a1fa9 100644
--- a/src/configuration.cpp
+++ b/src/configuration.cpp
@@ -42,7 +42,6 @@ void Configuration::init(std::string filename) {
std::ifstream inFile(filename.c_str(), std::ifstream::in);
std::string inBuffer;
unsigned int position;
- OptionValue optionTmp;
iniOptions.clear();
@@ -57,10 +56,13 @@ void Configuration::init(std::string filename) {
position = inBuffer.find(INI_DELIMITER, 0);
- if (position != std::string::npos) {
+ if (position != std::string::npos)
+ {
std::string key = inBuffer.substr(0, position);
+ OptionValue optionTmp;
- if (inBuffer.length() > position + 1) {
+ if (inBuffer.length() > position + 1)
+ {
optionTmp.stringValue = inBuffer.substr(
position + 1, inBuffer.length());
optionTmp.numericValue = atof(
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp
index ebf439b1..30c2d2f3 100644
--- a/src/gui/char_select.cpp
+++ b/src/gui/char_select.cpp
@@ -219,7 +219,8 @@ void CharSelectDialog::serverCharSelect()
log("CharSelect", "Server: %s:%d", iptostring(map_address), map_port);
RFIFOSKIP(28);
close_session();
- } else if (RFIFOW(0) == 0x006c) {
+ }
+ else if (RFIFOW(0) == 0x006c) {
switch (RFIFOB(2)) {
case 0:
new OkDialog(this, "Error", "Access denied");
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index dac21c00..2a59370f 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -731,28 +731,6 @@ int tmw_dialog_proc(int msg, DIALOG *d, int c) {
return D_O_K;
}
-void ok(const char *title, const char *message) {
- DIALOG alert_dialog[] = {
- /* (dialog proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
- { tmw_dialog_proc, 0, 0, 0, 60, 0, -1, 0, 0, 0, 0, (void *)title, NULL, NULL },
- { tmw_text_proc, 2, 22, 0, 0, 0, 0, 0, 0, 0, 0, (void *)message, NULL, NULL },
- { tmw_button_proc, 0, 40, 44, 18, 0, -1, 'o', D_EXIT, -1, 0, (char *)"&Ok", NULL, NULL },
- { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
- };
-
- BITMAP *temp = gui_bitmap;
- gui_bitmap = screen;
- show_mouse(screen);
- alert_dialog[0].w = text_length(font, message) + 4;
- alert_dialog[1].w = text_length(font, message);
- alert_dialog[1].h = text_height(font);
- alert_dialog[2].x = text_length(font, message) / 2 - 22;
- position_dialog(alert_dialog, 400 - alert_dialog[0].w / 2, 270);
- do_dialog(alert_dialog, 2);
- show_mouse(NULL);
- gui_bitmap = temp;
-}
-
unsigned int yes_no(const char *title, const char *message) {
unsigned int ret;
DIALOG alert_dialog[] = {
diff --git a/src/gui/gui.h b/src/gui/gui.h
index e3a77f31..504c9ceb 100644
--- a/src/gui/gui.h
+++ b/src/gui/gui.h
@@ -187,8 +187,7 @@ int tmw_button_proc(int msg, DIALOG *d, int c);
int tmw_text_proc(int msg, DIALOG *d, int c);
int tmw_dialog_proc(int msg, DIALOG *d, int c);
-// Last two remaining Allegro GUI dialogs
-void ok(const char *title, const char *message);
+// Last remaining Allegro GUI dialog
unsigned int yes_no(const char *title, const char *message);
#endif
diff --git a/src/gui/login.cpp b/src/gui/login.cpp
index 08276562..b1e8b43e 100644
--- a/src/gui/login.cpp
+++ b/src/gui/login.cpp
@@ -116,9 +116,7 @@ void LoginDialog::action(const std::string& eventId)
// Check login
if (user.length() == 0) {
- ok("Error", "Enter your username first");
- warning("Enter your username first");
- state = LOGIN;
+ new OkDialog("Error", "Enter your username first");
} else {
server_login(user, passField->getText());
close_session();
@@ -157,8 +155,7 @@ void server_login(const std::string& user, const std::string& pass) {
if (ret == SOCKET_ERROR) {
state = LOGIN;
- ok("Error", "Unable to connect to login server");
- warning("Unable to connect to login server");
+ new OkDialog("Error", "Unable to connect to login server");
return;
}
diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp
index 54ddf3e9..9164cfa3 100644
--- a/src/gui/ok_dialog.cpp
+++ b/src/gui/ok_dialog.cpp
@@ -24,20 +24,21 @@
#include "ok_dialog.h"
#include "button.h"
-OkDialog::OkDialog(const std::string &title, const std::string &msg):
+OkDialog::OkDialog(const std::string &title, const std::string &msg,
+ gcn::ActionListener *listener):
Window(title, true)
{
- init(msg);
+ init(msg, listener);
}
OkDialog::OkDialog(Window *parent, const std::string &title,
- const std::string &msg):
+ const std::string &msg, gcn::ActionListener *listener):
Window(title, true, parent)
{
- init(msg);
+ init(msg, listener);
}
-void OkDialog::init(const std::string &msg)
+void OkDialog::init(const std::string &msg, gcn::ActionListener *listener)
{
userLabel = new gcn::Label(msg);
okButton = new Button("OK");
@@ -57,6 +58,9 @@ void OkDialog::init(const std::string &msg)
okButton->setEventId("ok");
okButton->addActionListener(this);
+ if (listener) {
+ okButton->addActionListener(listener);
+ }
add(userLabel);
add(okButton);
diff --git a/src/gui/ok_dialog.h b/src/gui/ok_dialog.h
index 95ae52da..bb1a4e58 100644
--- a/src/gui/ok_dialog.h
+++ b/src/gui/ok_dialog.h
@@ -39,7 +39,8 @@ class OkDialog : public Window, public gcn::ActionListener {
*
* @see Window::Window
*/
- OkDialog(const std::string &title, const std::string &msg);
+ OkDialog(const std::string &title, const std::string &msg,
+ gcn::ActionListener *listener = NULL);
/**
* Constructor with parent reference.
@@ -47,7 +48,8 @@ class OkDialog : public Window, public gcn::ActionListener {
* @see Window::Window
*/
OkDialog(Window *window, const std::string &title,
- const std::string &msg);
+ const std::string &msg,
+ gcn::ActionListener *listener = NULL);
/**
* Destructor.
@@ -63,7 +65,7 @@ class OkDialog : public Window, public gcn::ActionListener {
/**
* Initializes the dialog.
*/
- void init(const std::string &msg);
+ void init(const std::string &msg, gcn::ActionListener *listener);
gcn::Label *userLabel;
gcn::Button *okButton;
diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp
index 89f7e0a4..589935be 100644
--- a/src/gui/setup.cpp
+++ b/src/gui/setup.cpp
@@ -32,6 +32,7 @@
#include "scrollarea.h"
#include "listbox.h"
#include "radiobutton.h"
+#include "ok_dialog.h"
#ifndef WIN32
extern Sound sound;
@@ -158,7 +159,7 @@ void Setup::action(const std::string& eventId)
sound.init(32, 20);
}
catch (const char *err) {
- ok("Sound Engine", err);
+ new OkDialog(this, "Sound Engine", err);
warning(err);
}
} else {
diff --git a/src/main.cpp b/src/main.cpp
index 57422e63..61de436f 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -25,6 +25,7 @@
#include "gui/char_server.h"
#include "gui/char_select.h"
#include "gui/inventory.h"
+#include "gui/ok_dialog.h"
#include "./sound/sound.h"
#include "./graphic/graphic.h"
@@ -97,8 +98,31 @@ Sound sound;
// ini file configuration reader
Configuration config;
+
+/**
+ * Listener used for responding to map start error dialog.
+ */
+class MapStartErrorListener : public gcn::ActionListener {
+ void action(const std::string &eventId) {
+ if (eventId == "ok") {
+ state = LOGIN;
+ }
+ }
+} mapStartErrorListener;
+
+/**
+ * Listener used for responding to init warning.
+ */
+class InitWarningListener : public gcn::ActionListener {
+ void action(const std::string &eventId) {
+ if (eventId == "ok") {
+ state = LOGIN;
+ }
+ }
+} initWarningListener;
+
void request_exit() {
- state = EXIT;
+ state = EXIT;
}
/**
@@ -314,9 +338,11 @@ void init_engine() {
SOUND_SID id = sound.loadItem("./data/sound/wavs/level.ogg");
sound.startItem(id, 70);
*/
- } catch (const char *err) {
- ok("Sound Engine", err);
- warning(err);
+ }
+ catch (const char *err) {
+ state = ERROR;
+ new OkDialog("Sound Engine", err, &initWarningListener);
+ warning(err);
}
#endif /* not WIN32 */
}
@@ -353,9 +379,21 @@ int main() {
sound.stopBgm();
#endif /* not WIN32 */
status("GAME");
- map_start();
- if (state == GAME)
+ try {
+ map_start();
game();
+ }
+ catch (const char* err) {
+ state = ERROR;
+ new OkDialog("Error", err, &mapStartErrorListener);
+ }
+ break;
+ case ERROR:
+ // Redraw GUI
+ blit(login_wallpaper, buffer, 0, 0, 0, 0, 800, 600);
+ guiGraphics->setTarget(buffer);
+ gui->update();
+ blit(buffer, screen, 0, 0, 0, 0, 800, 600);
break;
default:
state = EXIT;
diff --git a/src/main.h b/src/main.h
index 1af900bf..7ed65b5c 100644
--- a/src/main.h
+++ b/src/main.h
@@ -54,6 +54,7 @@
#define CHAR_NEW 4
#define CHAR_DEL 5
#define GAME 6
+#define ERROR 7
/* length definitions for several char[]s in order
* to be able to use strncpy instead of strcpy for
diff --git a/src/net/protocol.cpp b/src/net/protocol.cpp
index 7b4c9ced..b9a9c938 100644
--- a/src/net/protocol.cpp
+++ b/src/net/protocol.cpp
@@ -145,10 +145,9 @@ void set_coordinates(char *data, unsigned short x, unsigned short y,
void map_start() {
// Connect to map server
- if(open_session(iptostring(map_address), map_port)==SOCKET_ERROR) {
+ if (open_session(iptostring(map_address), map_port) == SOCKET_ERROR) {
warning("Unable to connect to map server");
- state = LOGIN;
- ok("Error", "Unable to connect to map server");
+ throw "Unable to connect to map server";
return;
}
@@ -161,13 +160,13 @@ void map_start() {
WFIFOB(18) = net_b_value(sex);
WFIFOSET(19);
- while((in_size<4)||(out_size>0))flush();
+ while ((in_size < 4)|| (out_size > 0)) flush();
RFIFOSKIP(4);
- while(in_size<2)flush();
+ while (in_size < 2) flush();
- if(RFIFOW(0)==0x0073) {
- while(in_size<11)flush();
+ if (RFIFOW(0) == 0x0073) {
+ while (in_size < 11) flush();
x = get_x(RFIFOP(6));
y = get_y(RFIFOP(6));
//direction = get_direction(RFIFOP(6));
@@ -180,7 +179,7 @@ void map_start() {
// Send "map loaded"
WFIFOW(0) = net_w_value(0x007d);
WFIFOSET(2);
- while(out_size>0)flush();
+ while (out_size > 0) flush();
}
void walk(unsigned short x, unsigned short y, unsigned char direction) {
@@ -194,7 +193,7 @@ void walk(unsigned short x, unsigned short y, unsigned char direction) {
void speak(char *speech) {
int len = (int)strlen(speech);
WFIFOW(0) = net_w_value(0x008c);
- WFIFOW(2) = net_w_value(len+4);
+ WFIFOW(2) = net_w_value(len + 4);
memcpy(WFIFOP(4), speech, len);
WFIFOSET(len + 4);
}
diff --git a/src/sound/sound.cpp b/src/sound/sound.cpp
index 7d2ba834..5e66c208 100644
--- a/src/sound/sound.cpp
+++ b/src/sound/sound.cpp
@@ -45,7 +45,7 @@
32/20 sounds realistic here.
*/
void Sound::init(int voices, int mod_voices) {
- if(isOk == 0) {
+ if (isOk == 0) {
throw("Sound engine cannot be initialized twice!\n");
}
@@ -55,7 +55,7 @@ void Sound::init(int voices, int mod_voices) {
int audio_channels = 2;
int audio_buffers = 4096;
- if(Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
+ if (Mix_OpenAudio(audio_rate, audio_format, audio_channels, audio_buffers)) {
#ifndef __DEBUG
throw("Unable to open audio device!\n");
#else
@@ -83,10 +83,10 @@ void Sound::init(int voices, int mod_voices) {
muted.
*/
void Sound::setVolume(int music) {
- if(isOk==-1)
+ if (isOk == -1)
return;
- if(isMaxVol(music) == false) {
+ if (isMaxVol(music) == false) {
vol_music = music;
Mix_VolumeMusic(vol_music);
}
@@ -97,10 +97,10 @@ void Sound::setVolume(int music) {
\param amusic volume difference
*/
void Sound::adjustVolume(int amusic) {
- if(isOk==-1)
+ if (isOk == -1)
return;
- if(isMaxVol(vol_music + amusic) == false) {
+ if (!isMaxVol(vol_music + amusic)) {
vol_music += amusic;
Mix_VolumeMusic(vol_music);
}
@@ -112,10 +112,10 @@ void Sound::adjustVolume(int amusic) {
\param loop how many times should the midi be looped? (-1 = infinite)
*/
void Sound::startBgm(char * in, int loop) {
- if(isOk==-1)
+ if (isOk == -1)
return;
- if(bgm != NULL) {
+ if (bgm != NULL) {
stopBgm();
}
@@ -137,7 +137,7 @@ void Sound::startBgm(char * in, int loop) {
playback stop.
*/
void Sound::stopBgm() {
- if(isOk==-1) {
+ if (isOk == -1) {
return;
}
@@ -145,7 +145,7 @@ void Sound::stopBgm() {
std::cout << "Sound::stopBgm()\n";
#endif
- if(bgm != NULL) {
+ if (bgm != NULL) {
Mix_HaltMusic();
Mix_FreeMusic(bgm);
bgm = NULL;
@@ -170,7 +170,7 @@ SOUND_SID Sound::loadItem(char *fpath) {
std::cout << "Sound::loadItem() precaching \"" << fpath << "\"\n";
#endif
Mix_Chunk *newItem;
- if(newItem = Mix_LoadWAV(fpath)) {
+ if (newItem = Mix_LoadWAV(fpath)) {
soundpool[++items] = newItem;
#ifdef __DEBUG
std::cout << "Sound::loadItem() success SOUND_SID = " << items << std::endl;
@@ -187,7 +187,7 @@ SOUND_SID Sound::loadItem(char *fpath) {
\param volume volume the sound should be played with (possible range: 0-128)
*/
void Sound::startItem(SOUND_SID id, int volume) {
- if(soundpool[id]) {
+ if (soundpool[id]) {
#ifdef __DEBUG
std::cout << "Sound::startItem() playing SOUND_SID = " << id << std::endl;
#endif
@@ -235,7 +235,7 @@ void Sound::close(void) {
true if that's the case.
*/
bool Sound::isMaxVol(int vol) {
- if( vol > 0 && vol < 128 ) return false;
+ if (vol > 0 && vol < 128) return false;
else return true;
}