diff options
author | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-09-13 01:08:06 +0000 |
---|---|---|
committer | Björn Steinbrink <B.Steinbrink@gmx.de> | 2005-09-13 01:08:06 +0000 |
commit | 6a8f1f5914721d1e8b8f9688b1d6ab71c0ed9bce (patch) | |
tree | 1a846219c3fdf6b3a0b2f17f15c4da4fec406845 /src/gui | |
parent | 07b3632e605488221f34bff48f298b394af7083a (diff) | |
download | mana-6a8f1f5914721d1e8b8f9688b1d6ab71c0ed9bce.tar.gz mana-6a8f1f5914721d1e8b8f9688b1d6ab71c0ed9bce.tar.bz2 mana-6a8f1f5914721d1e8b8f9688b1d6ab71c0ed9bce.tar.xz mana-6a8f1f5914721d1e8b8f9688b1d6ab71c0ed9bce.zip |
Unified the loops for the various dialogs that are shown before the actual game starts.
Diffstat (limited to 'src/gui')
-rw-r--r-- | src/gui/char_select.cpp | 55 | ||||
-rw-r--r-- | src/gui/char_select.h | 5 | ||||
-rw-r--r-- | src/gui/char_server.cpp | 48 | ||||
-rw-r--r-- | src/gui/char_server.h | 3 | ||||
-rw-r--r-- | src/gui/login.cpp | 67 | ||||
-rw-r--r-- | src/gui/login.h | 12 | ||||
-rw-r--r-- | src/gui/updatewindow.cpp | 249 | ||||
-rw-r--r-- | src/gui/updatewindow.h | 23 |
8 files changed, 180 insertions, 282 deletions
diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index de01a571..cb85d39c 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -24,13 +24,11 @@ #include "char_select.h" #include <sstream> - -#include <guichan/sdl/sdlinput.hpp> +#include <SDL.h> #include <guichan/widgets/label.hpp> #include "button.h" -#include "gui.h" #include "ok_dialog.h" #include "playerbox.h" #include "textfield.h" @@ -38,7 +36,6 @@ #include "../being.h" #include "../game.h" -#include "../graphics.h" #include "../log.h" #include "../main.h" #include "../playerinfo.h" @@ -46,8 +43,6 @@ #include "../net/network.h" #include "../net/protocol.h" -extern Graphics *graphics; - CharSelectDialog::CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): ConfirmDialog(m, "Confirm", "Are you sure you want to delete this character?"), @@ -272,6 +267,13 @@ void CharSelectDialog::serverCharSelect() // Todo: add other packets } +void CharSelectDialog::logic() +{ + if (n_character > 0) { + setPlayerInfo(char_info); + } +} + CharCreateDialog::CharCreateDialog(Window *parent): Window("Create Character", true, parent) { @@ -447,45 +449,10 @@ void CharCreateDialog::serverCharCreate() } } -void charSelect() +void charSelectInputHandler(SDL_KeyboardEvent *keyEvent) { - CharSelectDialog *sel; - sel = new CharSelectDialog(); - - state = CHAR_SELECT; - - while (/*!key[KEY_ESC] && !key[KEY_ENTER] &&*/ state == CHAR_SELECT) + if (keyEvent->keysym.sym == SDLK_ESCAPE) { - // Handle SDL events - SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - state = EXIT; - break; - - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_ESCAPE) - { - state = EXIT; - } - break; - } - - guiInput->pushInput(event); - } - - if (n_character > 0) { - sel->setPlayerInfo(char_info); - } - - gui->logic(); - - graphics->drawImage(login_wallpaper, 0, 0); - gui->draw(); - graphics->updateScreen(); + state = EXIT; } - - delete sel; } - diff --git a/src/gui/char_select.h b/src/gui/char_select.h index b229a04c..c4aac4b9 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -31,6 +31,7 @@ class PlayerBox; struct PLAYER_INFO; +struct SDL_KeyboardEvent; /** * Character selection dialog. @@ -87,6 +88,8 @@ class CharSelectDialog : public Window, public gcn::ActionListener { void action(const std::string& eventId); void setPlayerInfo(PLAYER_INFO* pi); + + void logic(); }; /** @@ -131,6 +134,6 @@ class CharCreateDialog : public Window, public gcn::ActionListener { std::string getName(); }; -void charSelect(); +void charSelectInputHandler(SDL_KeyboardEvent *keyEvent); #endif diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 24e58c5c..b4b01350 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -23,15 +23,13 @@ #include "char_server.h" -#include <guichan/sdl/sdlinput.hpp> +#include <SDL.h> #include "button.h" -#include "gui.h" #include "listbox.h" #include "ok_dialog.h" #include "scrollarea.h" -#include "../graphics.h" #include "../log.h" #include "../main.h" #include "../playerinfo.h" @@ -39,10 +37,7 @@ #include "../net/network.h" -extern Graphics *graphics; - char server[30]; -int showServerList = 1; ServerSelectDialog::ServerSelectDialog(): @@ -107,8 +102,8 @@ void ServerSelectDialog::action(const std::string& eventId) server_char_server(serverList->getSelected()); } else if (eventId == "cancel") { + state = LOGIN; } - showServerList = 0; } @@ -123,43 +118,12 @@ std::string ServerListModel::getElementAt(int i) { return buffer; } - -void char_server() { - ServerSelectDialog *dialog = new ServerSelectDialog(); - - state = LOGIN; - - showServerList = 1; - while (showServerList) +void charServerInputHandler(SDL_KeyboardEvent *keyEvent) +{ + if (keyEvent->keysym.sym == SDLK_ESCAPE) { - // Handle SDL events - SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - state = EXIT; - showServerList = false; - break; - - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_ESCAPE) - { - showServerList = false; - } - break; - } - - guiInput->pushInput(event); - } - - gui->logic(); - - graphics->drawImage(login_wallpaper, 0, 0); - gui->draw(); - graphics->updateScreen(); + state = LOGIN; } - - delete dialog; } void server_char_server(int serverIndex) diff --git a/src/gui/char_server.h b/src/gui/char_server.h index ec2e90d1..d19e84af 100644 --- a/src/gui/char_server.h +++ b/src/gui/char_server.h @@ -31,6 +31,7 @@ #include "../guichanfwd.h" +struct SDL_KeyboardEvent; /** * The list model for the server list. @@ -75,7 +76,7 @@ class ServerSelectDialog : public Window, public gcn::ActionListener { gcn::ScrollArea *scrollArea; }; -void char_server(); +void charServerInputHandler(SDL_KeyboardEvent *keyEvent); void server_char_server(int serverIndex); char *server_list(int index, int *size); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 8f26cf7d..a8ecf6a2 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -25,8 +25,7 @@ #include <string> #include <sstream> - -#include <guichan/sdl/sdlinput.hpp> +#include <SDL.h> #include <guichan/widgets/label.hpp> @@ -34,40 +33,47 @@ #include "button.h" #include "checkbox.h" -#include "gui.h" #include "passwordfield.h" #include "textfield.h" #include "ok_dialog.h" #include "../configuration.h" -#include "../graphics.h" #include "../log.h" #include "../serverinfo.h" #include "../net/network.h" -extern Graphics *graphics; - OkDialog *wrongLoginNotice = NULL; -LoginDialog *loginDialog = NULL; WrongUsernameNoticeListener wrongUsernameNoticeListener; WrongPasswordNoticeListener wrongPasswordNoticeListener; +void WrongPasswordNoticeListener::setLoginDialog( + LoginDialog *loginDialog) +{ + mLoginDialog = loginDialog; +} + void WrongPasswordNoticeListener::action(const std::string &eventId) { // Reset the password and put the caret ready to retype it. - loginDialog->passField->setText(""); - loginDialog->passField->setCaretPosition(0); - loginDialog->passField->requestFocus(); + mLoginDialog->passField->setText(""); + mLoginDialog->passField->setCaretPosition(0); + mLoginDialog->passField->requestFocus(); wrongLoginNotice = NULL; } +void WrongUsernameNoticeListener::setLoginDialog( + LoginDialog *loginDialog) +{ + mLoginDialog = loginDialog; +} + void WrongUsernameNoticeListener::action(const std::string &eventId) { // Set the focus on the username Field - loginDialog->userField->setCaretPosition(LEN_MAX_USERNAME - 1); - loginDialog->userField->requestFocus(); + mLoginDialog->userField->setCaretPosition(LEN_MAX_USERNAME - 1); + mLoginDialog->userField->requestFocus(); wrongLoginNotice = NULL; } @@ -148,6 +154,8 @@ LoginDialog::LoginDialog(): serverField->setText(config.getValue("host", "")); + wrongUsernameNoticeListener.setLoginDialog(this); + wrongPasswordNoticeListener.setLoginDialog(this); } LoginDialog::~LoginDialog() @@ -277,43 +285,14 @@ void LoginDialog::action(const std::string& eventId) } } - -void login() +void loginInputHandler(SDL_KeyboardEvent *keyEvent) { - loginDialog = new LoginDialog(); - - while (state == LOGIN) + if (keyEvent->keysym.sym == SDLK_ESCAPE) { - // Handle SDL events - SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - state = EXIT; - break; - - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_ESCAPE) - { - state = EXIT; - } - break; - } - - guiInput->pushInput(event); - } - - gui->logic(); - - graphics->drawImage(login_wallpaper, 0, 0); - gui->draw(); - graphics->updateScreen(); + state = EXIT; } - - delete loginDialog; } - int attemptLogin(const std::string& user, const std::string& pass) { username = user; password = pass; diff --git a/src/gui/login.h b/src/gui/login.h index 1322a1c3..ce983b8a 100644 --- a/src/gui/login.h +++ b/src/gui/login.h @@ -30,6 +30,8 @@ #include "window.h" #include "../guichanfwd.h" +struct SDL_KeyboardEvent; + /** * The login dialog. * @@ -75,7 +77,10 @@ class LoginDialog : public Window, public gcn::ActionListener { */ class WrongPasswordNoticeListener : public gcn::ActionListener { public: + void setLoginDialog(LoginDialog *loginDialog); void action(const std::string &eventId); + private: + LoginDialog *mLoginDialog; }; /** @@ -83,14 +88,17 @@ class WrongPasswordNoticeListener : public gcn::ActionListener { */ class WrongUsernameNoticeListener : public gcn::ActionListener { public: + void setLoginDialog(LoginDialog *loginDialog); void action(const std::string &eventId); + private: + LoginDialog *mLoginDialog; }; /** - * Display login dialog + * Handle input */ -void login(); +void loginInputHandler(SDL_KeyboardEvent *keyEvent); /** * Attempt to login to login server diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 4f53495c..0c7bd7a7 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -23,44 +23,32 @@ #include "updatewindow.h" -#include <cstdio> #include <iostream> #include <sstream> +#include <SDL.h> #include <SDL_thread.h> #include <curl/curl.h> -#include <guichan/sdl/sdlinput.hpp> - #include <guichan/widgets/label.hpp> #include "browserbox.h" #include "button.h" -#include "gui.h" #include "progressbar.h" #include "scrollarea.h" #include "../configuration.h" -#include "../graphics.h" #include "../log.h" #include "../main.h" -extern Graphics *graphics; - UpdaterWindow::UpdaterWindow(): - Window("Updating...") + Window("Updating..."), + mThread(NULL), mMutex(NULL), mDownloadStatus(UPDATE_NEWS), + mUpdateHost(""), mCurrentFile("news.txt"), mBasePath(""), + mStoreInMemory(true), mDownloadComplete(true), mDownloadedBytes(0), + mMemoryBuffer(NULL), mCurlError(new char[CURL_ERROR_SIZE]), + mFileIndex(0) { - mThread = NULL; - mMutex = NULL; - mDownloadStatus = UPDATE_NEWS; - mUpdateHost = ""; - mCurrentFile = "news.txt"; - mDownloadComplete = true; - mBasePath = ""; - mStoreInMemory = true; - mDownloadedBytes = 0; - mMemoryBuffer = NULL; - mCurlError = new char[CURL_ERROR_SIZE]; mCurlError[0] = 0; int h = 240; @@ -96,10 +84,28 @@ UpdaterWindow::UpdaterWindow(): mCancelButton->requestFocus(); setLocationRelativeTo(getParent()); + + mUpdateHost = config.getValue("updatehost", "themanaworld.org/files"); + mBasePath = config.getValue("homeDir", "."); + + // Try to download the updates list + download(); } UpdaterWindow::~UpdaterWindow() { + if (mThread) + { + SDL_WaitThread(mThread, NULL); + mThread = NULL; + } + + free(mMemoryBuffer); + // Remove downloaded files + remove((mBasePath + "/updates/news.txt").c_str()); + remove((mBasePath + "/updates/resources.txt").c_str()); + remove((mBasePath + "/updates/download.temp").c_str()); + delete mCurlError; delete mLabel; delete mProgressBar; @@ -301,145 +307,100 @@ void UpdaterWindow::download() } } -void UpdaterWindow::updateData() +void updateInputHandler(SDL_KeyboardEvent *keyEvent) { - std::ifstream in; - std::vector<std::string> files; - - state = UPDATE; - unsigned int fileIndex = 0; - - mUpdateHost = config.getValue("updatehost", "themanaworld.org/files"); - mBasePath = config.getValue("homeDir", "."); - - // Try to download the updates list - download(); - - while (state == UPDATE) + if (keyEvent->keysym.sym == SDLK_ESCAPE) { - // Handle SDL events - SDL_Event event; - while (SDL_PollEvent(&event)) { - switch (event.type) { - case SDL_QUIT: - state = EXIT; - break; - - case SDL_KEYDOWN: - if (event.key.keysym.sym == SDLK_ESCAPE) - { - state = EXIT; - } - break; - } - - guiInput->pushInput(event); - } + state = EXIT; + } +} - switch (mDownloadStatus) { - case UPDATE_ERROR: - if (mThread) +void UpdaterWindow::logic() +{ + switch (mDownloadStatus) { + case UPDATE_ERROR: + if (mThread) + { + SDL_WaitThread(mThread, NULL); + mThread = NULL; + } + addRow(""); + addRow("##1 The update process is incomplete."); + addRow("##1 It is strongly recommended that"); + addRow("##1 you try again later"); + addRow(mCurlError); + mDownloadStatus = UPDATE_COMPLETE; + break; + case UPDATE_NEWS: + if (mDownloadComplete) { + // Try to open news.txt + loadNews(); + // Doesn't matter if it couldn't find news.txt, + // go to the next step + mCurrentFile = "resources.txt"; + if (mMemoryBuffer != NULL) { - SDL_WaitThread(mThread, NULL); - mThread = NULL; + free(mMemoryBuffer); + mMemoryBuffer = NULL; } - addRow(""); - addRow("##1 The update process is incomplete."); - addRow("##1 It is strongly recommended that"); - addRow("##1 you try again later"); - addRow(mCurlError); - mDownloadStatus = UPDATE_COMPLETE; - break; - case UPDATE_NEWS: - if (mDownloadComplete) { - // Try to open news.txt - loadNews(); - // Doesn't matter if it couldn't find news.txt, - // go to the next step - mCurrentFile = "resources.txt"; - if (mMemoryBuffer != NULL) + download(); + mDownloadStatus = UPDATE_LIST; + } + break; + case UPDATE_LIST: + if (mDownloadComplete) { + if (mMemoryBuffer != NULL) + { + // Tokenize and add each line separately + char *line = strtok(mMemoryBuffer, "\n"); + while (line != NULL) { - free(mMemoryBuffer); - mMemoryBuffer = NULL; + mFiles.push_back(line); + line = strtok(NULL, "\n"); } - download(); - mDownloadStatus = UPDATE_LIST; + mStoreInMemory = false; + mDownloadStatus = UPDATE_RESOURCES; } - break; - case UPDATE_LIST: - if (mDownloadComplete) { - if (mMemoryBuffer != NULL) - { - // Tokenize and add each line separately - char *line = strtok(mMemoryBuffer, "\n"); - while (line != NULL) - { - files.push_back(line); - line = strtok(NULL, "\n"); - } - mStoreInMemory = false; - mDownloadStatus = UPDATE_RESOURCES; - } - else { - logger->log("Unable to download resources.txt"); - mDownloadStatus = UPDATE_ERROR; - } + else { + logger->log("Unable to download resources.txt"); + mDownloadStatus = UPDATE_ERROR; } - break; - case UPDATE_RESOURCES: - if (mDownloadComplete) + } + break; + case UPDATE_RESOURCES: + if (mDownloadComplete) + { + if (mThread) { - if (mThread) - { - SDL_WaitThread(mThread, NULL); - mThread = NULL; - } + SDL_WaitThread(mThread, NULL); + mThread = NULL; + } - if (fileIndex < files.size()) - { - mCurrentFile = files[fileIndex]; - std::ifstream temp( - (mBasePath + "/updates/" + mCurrentFile).c_str()); - if (!temp.is_open()) { - temp.close(); - download(); - } - else { - logger->log("%s already here", mCurrentFile.c_str()); - } - fileIndex++; + if (mFileIndex < mFiles.size()) + { + mCurrentFile = mFiles[mFileIndex]; + std::ifstream temp( + (mBasePath + "/updates/" + mCurrentFile).c_str()); + if (!temp.is_open()) { + temp.close(); + download(); } else { - // Download of updates completed - mDownloadStatus = UPDATE_COMPLETE; + logger->log("%s already here", mCurrentFile.c_str()); } + mFileIndex++; } - break; - case UPDATE_COMPLETE: - enable(); - setLabel("Completed"); - break; - case UPDATE_IDLE: - break; - } - - gui->logic(); - - graphics->drawImage(login_wallpaper, 0, 0); - gui->draw(); - graphics->updateScreen(); - } - - if (mThread) - { - SDL_WaitThread(mThread, NULL); - mThread = NULL; + else { + // Download of updates completed + mDownloadStatus = UPDATE_COMPLETE; + } + } + break; + case UPDATE_COMPLETE: + enable(); + setLabel("Completed"); + break; + case UPDATE_IDLE: + break; } - - free(mMemoryBuffer); - in.close(); - // Remove downloaded files - remove((mBasePath + "/updates/news.txt").c_str()); - remove((mBasePath + "/updates/resources.txt").c_str()); - remove((mBasePath + "/updates/download.temp").c_str()); } diff --git a/src/gui/updatewindow.h b/src/gui/updatewindow.h index fa69bd4b..56ff4065 100644 --- a/src/gui/updatewindow.h +++ b/src/gui/updatewindow.h @@ -26,6 +26,9 @@ #include <guichan/actionlistener.hpp> +#include <string> +#include <vector> + #include "window.h" #include "../guichanfwd.h" @@ -34,8 +37,10 @@ class BrowserBox; class Button; class ProgressBar; class ScrollArea; -class SDL_Thread; -class SDL_mutex; + +struct SDL_mutex; +struct SDL_KeyboardEvent; +struct SDL_Thread; /** * Update progress window GUI @@ -82,7 +87,7 @@ class UpdaterWindow : public Window, public gcn::ActionListener */ void addRow(const std::string &row); - void updateData(); + void logic(); int updateState; @@ -172,6 +177,16 @@ class UpdaterWindow : public Window, public gcn::ActionListener */ char *mCurlError; + /** + * List of files to download + */ + std::vector<std::string> mFiles; + + /** + * Index of the file to be downloaded + */ + unsigned int mFileIndex; + gcn::Label *mLabel; /**< Progress bar caption. */ Button *mCancelButton; /**< Button to stop the update process. */ Button *mPlayButton; /**< Button to start playing. */ @@ -180,6 +195,6 @@ class UpdaterWindow : public Window, public gcn::ActionListener ScrollArea *mScrollArea; /**< Used to scroll news box. */ }; -void updateData(); +void updateInputHandler(SDL_KeyboardEvent *keyEvent); #endif |