summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/browserbox.cpp56
-rw-r--r--src/gui/browserbox.h5
-rw-r--r--src/gui/gui.cpp20
-rw-r--r--src/gui/truetypefont.cpp170
-rw-r--r--src/gui/truetypefont.h134
-rw-r--r--src/gui/window.cpp1
-rw-r--r--src/main.cpp679
-rw-r--r--src/openglgraphics.cpp1
9 files changed, 676 insertions, 392 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index 1fe12518..7006f66e 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -66,6 +66,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \
gui/npc_text.h \
gui/ok_dialog.cpp \
gui/ok_dialog.h \
+ gui/truetypefont.cpp \
+ gui/truetypefont.h \
gui/passwordfield.cpp \
gui/passwordfield.h \
gui/playerbox.cpp \
diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp
index 4a3f2f64..c618fa69 100644
--- a/src/gui/browserbox.cpp
+++ b/src/gui/browserbox.cpp
@@ -30,14 +30,7 @@
#include <guichan/mouseinput.hpp>
#include "linkhandler.h"
-
-#ifdef USE_OPENGL
-#include "../configuration.h"
-#include "../resources/resourcemanager.h"
-
-int BrowserBox::instances = 0;
-gcn::ImageFont* BrowserBox::browserFont = NULL;
-#endif
+#include "truetypefont.h"
BrowserBox::BrowserBox(unsigned int mode):
gcn::Widget(),
@@ -47,35 +40,10 @@ BrowserBox::BrowserBox(unsigned int mode):
{
setFocusable(true);
addMouseListener(this);
-
-#ifdef USE_OPENGL
- if (config.getValue("opengl", 0)) {
- if (instances == 0) {
- browserFont = new gcn::ImageFont(
- "graphics/gui/browserfont.png",
- " abcdefghijklmnopqrstuvwxyz"
- "ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567"
- "89:@!\"$%&/=?^+*#[]{}()<>_;'.,\\|-~`"
- "øåáÁéÉíÍóÓúÚç륣¢¡¿àãõêñÑöüäÖÜÄßèÈÅ");
- }
- setFont(browserFont);
- instances++;
- }
-#endif
}
BrowserBox::~BrowserBox()
{
-#ifdef USE_OPENGL
- instances--;
-
- if (instances == 0)
- {
- // Clean up static resource font
- delete browserFont;
- browserFont = NULL;
- }
-#endif
}
void BrowserBox::setLinkHandler(LinkHandler* linkHandler)
@@ -104,7 +72,7 @@ void BrowserBox::addRow(const std::string &row)
std::string newRow;
BROWSER_LINK bLink;
int idx1, idx2, idx3;
- gcn::ImageFont *font = static_cast<gcn::ImageFont*>(getFont());
+ TrueTypeFont *font = static_cast<TrueTypeFont*>(getFont());
// Use links and user defined colors
if (mUseLinksAndUserColors)
@@ -172,7 +140,7 @@ void BrowserBox::addRow(const std::string &row)
{
unsigned int i, j, y = 0;
unsigned int nextChar;
- char hyphen = '~';
+ char *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
int x = 0;
for (i = 0; i < mTextRows.size(); i++)
@@ -180,7 +148,8 @@ void BrowserBox::addRow(const std::string &row)
std::string row = mTextRows[i];
for (j = 0; j < row.size(); j++)
{
- x += font->getWidth(row.at(j));
+ std::string character = row.substr(j, 1);
+ x += font->getWidth(character);
nextChar = j + 1;
// Wraping between words (at blank spaces)
@@ -294,7 +263,7 @@ BrowserBox::draw(gcn::Graphics *graphics)
unsigned int i, j;
int x = 0, y = 0;
int wrappedLines = 0;
- gcn::ImageFont *font = static_cast<gcn::ImageFont*>(getFont());
+ TrueTypeFont *font = static_cast<TrueTypeFont*>(getFont());
graphics->setColor(BLACK);
for (i = 0; i < mTextRows.size(); i++)
@@ -377,22 +346,23 @@ BrowserBox::draw(gcn::Graphics *graphics)
{
for (x = 0; x < getWidth(); x++)
{
- font->drawGlyph(graphics, '-', x, y);
- x += font->getWidth('-') - 2;
+ font->drawString(graphics, "-", x, y);
+ x += font->getWidth("-") - 2;
}
break;
}
// Draw each char
else
{
- font->drawGlyph(graphics, row.at(j), x, y);
- x += font->getWidth(row.at(j));
+ std::string character = row.substr(j, 1);
+ font->drawString(graphics, character, x, y);
+ x += font->getWidth(character.c_str());
// Auto wrap mode
if (mMode == AUTO_WRAP)
{
unsigned int nextChar = j + 1;
- char hyphen = '~';
+ char *hyphen = "~";
int hyphenWidth = font->getWidth(hyphen);
// Wraping between words (at blank spaces)
@@ -419,7 +389,7 @@ BrowserBox::draw(gcn::Graphics *graphics)
// Wrapping looong lines (brutal force)
else if ((x + 2 * hyphenWidth) > getWidth())
{
- font->drawGlyph(graphics, hyphen,
+ font->drawString(graphics, hyphen,
getWidth() - hyphenWidth, y);
x = 15; // Ident in new line
y += font->getHeight();
diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h
index 666a7754..1c33e6f9 100644
--- a/src/gui/browserbox.h
+++ b/src/gui/browserbox.h
@@ -158,11 +158,6 @@ class BrowserBox : public gcn::Widget, public gcn::MouseListener
bool mOpaque;
bool mUseLinksAndUserColors;
int mSelectedLink;
-
-#ifdef USE_OPENGL
- static int instances; /**< Number of Window instances */
- static gcn::ImageFont* browserFont;
-#endif
};
#endif
diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp
index 620dfb0b..dc51054c 100644
--- a/src/gui/gui.cpp
+++ b/src/gui/gui.cpp
@@ -26,14 +26,16 @@
#include <guichan/exception.hpp>
#include <guichan/image.hpp>
#include <guichan/imagefont.hpp>
+#include <SDL/SDL_ttf.h>
// Should stay here because of Guichan being sensitive to headers order
#include <guichan/sdl/sdlinput.hpp>
#include "focushandler.h"
+#include "truetypefont.h"
+#include "viewport.h"
#include "window.h"
#include "windowcontainer.h"
-#include "viewport.h"
#include "../configlistener.h"
#include "../configuration.h"
@@ -104,14 +106,13 @@ Gui::Gui(Graphics *graphics):
// Set global font
try {
- mGuiFont = new gcn::ImageFont("graphics/gui/sansserif8.png",
- " !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ["
- "\\]^_`abcdefghijklmnopqrstuvwxyz{|}~|"
- );
+ mGuiFont = new TrueTypeFont("data/fonts/dejavusans.ttf", 12);
}
catch (gcn::Exception e)
{
- logger->error("Unable to load sansserif8.png!");
+ logger->log("Unable to load dejavusans.ttf: %s",
+ e.getMessage().c_str());
+ throw;
}
// Set speech font
@@ -124,7 +125,9 @@ Gui::Gui(Graphics *graphics):
}
catch (gcn::Exception e)
{
- logger->error("Unable to load rpgfont_wider.png!");
+ logger->log("Unable to load rpgfont_wider.png: %s",
+ e.getMessage().c_str());
+ throw;
}
gcn::Widget::setGlobalFont(mGuiFont);
@@ -140,7 +143,8 @@ Gui::Gui(Graphics *graphics):
}
catch (gcn::Exception e)
{
- logger->error("Unable to load colored hits' fonts!");
+ logger->log("Unable to load colored hits' fonts: %s", e.getMessage().c_str());
+ throw;
}
// Initialize mouse cursor and listen for changes to the option
diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp
new file mode 100644
index 00000000..7ef29539
--- /dev/null
+++ b/src/gui/truetypefont.cpp
@@ -0,0 +1,170 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "truetypefont.h"
+
+#include <list>
+
+#include <guichan/exception.hpp>
+
+#include "../graphics.h"
+#include "../resources/image.h"
+
+#define CACHE_SIZE 30
+
+class TextChunk
+{
+ public:
+ TextChunk(const std::string &text, gcn::Color color) :
+ img(NULL), text(text), color(color)
+ {
+ }
+
+ ~TextChunk()
+ {
+ delete img;
+ }
+
+ bool operator==(const TextChunk &chunk) const
+ {
+ return (
+ chunk.text == text && chunk.color == color);
+ }
+
+ void generate(TTF_Font *font)
+ {
+ SDL_Color sdlCol;
+ sdlCol.b = color.b;
+ sdlCol.r = color.r;
+ sdlCol.g = color.g;
+
+ SDL_Surface *surface = TTF_RenderUTF8_Blended(
+ font, text.c_str(), sdlCol);
+
+ if (!surface)
+ {
+ throw "Rendering font to surface failed: " +
+ std::string(TTF_GetError());
+ }
+
+ img = Image::load(surface, std::string());
+
+ SDL_FreeSurface(surface);
+ }
+
+ Image *img;
+ std::string text;
+ gcn::Color color;
+};
+
+
+// Word surfaces cache
+static std::list<TextChunk> cache;
+typedef std::list<TextChunk>::iterator CacheIterator;
+
+
+TrueTypeFont::TrueTypeFont(const std::string& filename, int size)
+{
+ if (!TTF_WasInit() && TTF_Init() == -1)
+ {
+ throw GCN_EXCEPTION("Unable to initialize SDL_ttf: " +
+ std::string(TTF_GetError()));
+ }
+
+ mFont = TTF_OpenFont(filename.c_str(), size);
+
+ if (mFont == NULL)
+ {
+ throw GCN_EXCEPTION("SDLTrueTypeFont::SDLTrueTypeFont: " +
+ std::string(TTF_GetError()));
+ }
+}
+
+TrueTypeFont::~TrueTypeFont()
+{
+ TTF_CloseFont(mFont);
+
+ if (TTF_WasInit())
+ {
+ TTF_Quit();
+ }
+}
+
+void TrueTypeFont::drawString(gcn::Graphics *graphics,
+ const std::string &text,
+ int x, int y)
+{
+ if (text.empty())
+ {
+ return;
+ }
+
+ Graphics *g = dynamic_cast<Graphics *>(graphics);
+
+ if (!g)
+ {
+ throw "Not a valid graphics object!";
+ }
+
+ gcn::Color col = g->getColor();
+
+ TextChunk chunk(text, col);
+
+ bool found = false;
+
+ for (CacheIterator i = cache.begin(); i != cache.end(); i++)
+ {
+ if (chunk == (*i))
+ {
+ // Raise priority: move it to front
+ cache.splice(cache.begin(), cache, i);
+ found = true;
+ break;
+ }
+ }
+
+ // Surface not found
+ if (!found)
+ {
+ if (cache.size() >= CACHE_SIZE)
+ {
+ cache.pop_back();
+ }
+ cache.push_front(chunk);
+ cache.front().generate(mFont);
+ }
+
+ g->drawImage(cache.front().img, x, y);
+}
+
+int TrueTypeFont::getWidth(const std::string& text) const
+{
+ int w, h;
+ TTF_SizeUTF8(mFont, text.c_str(), &w, &h);
+ return w;
+}
+
+int TrueTypeFont::getHeight() const
+{
+ return TTF_FontHeight(mFont);
+}
diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h
new file mode 100644
index 00000000..e0e57cd7
--- /dev/null
+++ b/src/gui/truetypefont.h
@@ -0,0 +1,134 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_TRUETYPEFONT_H
+#define _TMW_TRUETYPEFONT_H
+
+#include <string>
+
+#include <guichan/font.hpp>
+#include <guichan/graphics.hpp>
+#include <SDL/SDL_ttf.h>
+
+/**
+ * A wrapper around SDL_ttf for allowing the use of TrueType fonts.
+ *
+ * <b>NOTE:</b> This class needs SDL_ttf to be initialized.
+ */
+class TrueTypeFont : public gcn::Font
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * @param filename Font filename.
+ * @param size Font size.
+ */
+ TrueTypeFont(const std::string& filename, int size);
+
+ /**
+ * Destructor.
+ */
+ ~TrueTypeFont();
+
+ virtual int getWidth(const std::string& text) const;
+
+ virtual int getHeight() const;
+
+ /**
+ * @see Font::drawString
+ */
+ void drawString(gcn::Graphics* graphics, const std::string& text, int x, int y);
+
+ private:
+ TTF_Font *mFont;
+};
+
+#endif
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#ifndef _TMW_TRUETYPEFONT_H
+#define _TMW_TRUETYPEFONT_H
+
+#include <string>
+
+#include <guichan/font.hpp>
+#include <guichan/graphics.hpp>
+#include <SDL/SDL_ttf.h>
+
+/**
+ * A wrapper around SDL_ttf for allowing the use of TrueType fonts.
+ *
+ * <b>NOTE:</b> This class needs SDL_ttf to be initialized.
+ */
+class TrueTypeFont : public gcn::Font
+{
+ public:
+ /**
+ * Constructor.
+ *
+ * @param filename Font filename.
+ * @param size Font size.
+ */
+ TrueTypeFont(const std::string& filename, int size);
+
+ /**
+ * Destructor.
+ */
+ ~TrueTypeFont();
+
+ virtual int getWidth(const std::string& text) const;
+
+ virtual int getHeight() const;
+
+ /**
+ * @see Font::drawString
+ */
+ void drawString(gcn::Graphics* graphics, const std::string& text, int x, int y);
+
+ private:
+ TTF_Font *mFont;
+};
+
+#endif
diff --git a/src/gui/window.cpp b/src/gui/window.cpp
index 3e6e1bac..84f4466c 100644
--- a/src/gui/window.cpp
+++ b/src/gui/window.cpp
@@ -173,6 +173,7 @@ void Window::draw(gcn::Graphics *graphics)
// Draw title
if (getTitleBarHeight())
{
+ graphics->setColor(gcn::Color(0, 0, 0));
graphics->setFont(getFont());
graphics->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT);
}
diff --git a/src/main.cpp b/src/main.cpp
index 67086f9f..1f4eafde 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -655,387 +655,395 @@ extern "C" char const *_nl_locale_name_default(void);
/** Main */
int main(int argc, char *argv[])
{
- // Parse command line options
- Options options;
- parseOptions(argc, argv, options);
- if (options.printHelp)
+ try
{
- printHelp();
- return 0;
- }
- else if (options.printVersion)
- {
- printVersion();
- return 0;
- }
+ // Parse command line options
+ Options options;
+ parseOptions(argc, argv, options);
+ if (options.printHelp)
+ {
+ printHelp();
+ return 0;
+ }
+ else if (options.printVersion)
+ {
+ printVersion();
+ return 0;
+ }
#if ENABLE_NLS
#ifdef WIN32
- putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str());
+ putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str());
#endif
- setlocale(LC_MESSAGES, "");
- bindtextdomain("tmw", LOCALEDIR);
- bind_textdomain_codeset("tmw", "UTF-8");
- textdomain("tmw");
+ setlocale(LC_MESSAGES, "");
+ bindtextdomain("tmw", LOCALEDIR);
+ bind_textdomain_codeset("tmw", "UTF-8");
+ textdomain("tmw");
#endif
- // Initialize PhysicsFS
- PHYSFS_init(argv[0]);
+ // Initialize PhysicsFS
+ PHYSFS_init(argv[0]);
- initHomeDir();
- // Configure logger
- logger = new Logger();
- logger->setLogFile(homeDir + std::string("/tmw.log"));
- logger->setLogToStandardOut(config.getValue("logToStandardOut", 0));
+ initHomeDir();
+ // Configure logger
+ logger = new Logger();
+ logger->setLogFile(homeDir + std::string("/tmw.log"));
+ logger->setLogToStandardOut(config.getValue("logToStandardOut", 0));
- // Log the tmw version
+ // Log the tmw version
#ifdef PACKAGE_VERSION
- logger->log("The Mana World v%s", PACKAGE_VERSION);
+ logger->log("The Mana World v%s", PACKAGE_VERSION);
#else
- logger->log("The Mana World - version not defined");
+ logger->log("The Mana World - version not defined");
#endif
- initXML();
- initConfiguration(options);
- initEngine();
+ initXML();
+ initConfiguration(options);
+ initEngine();
- Game *game = NULL;
- Window *currentDialog = NULL;
- QuitDialog* quitDialog = NULL;
- Image *login_wallpaper = NULL;
+ Game *game = NULL;
+ Window *currentDialog = NULL;
+ QuitDialog* quitDialog = NULL;
+ Image *login_wallpaper = NULL;
- gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
+ gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
#ifdef PACKAGE_VERSION
- gcn::Label *versionLabel = new gcn::Label(PACKAGE_VERSION);
- top->add(versionLabel, 2, 2);
+ gcn::Label *versionLabel = new gcn::Label(PACKAGE_VERSION);
+ top->add(versionLabel, 2, 2);
#endif
- sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg");
+ sound.playMusic(TMW_DATADIR "data/music/Magick - Real.ogg");
- // Server choice
- if (options.serverName.empty()) {
- loginData.hostname = config.getValue("MostUsedServerName0",
- defaultAccountServerName.c_str());
- }
- else {
- loginData.hostname = options.serverName;
- }
- if (options.serverPort == 0) {
- loginData.port = (short)config.getValue("MostUsedServerPort0",
- defaultAccountServerPort);
- } else {
- loginData.port = options.serverPort;
- }
+ // Server choice
+ if (options.serverName.empty()) {
+ loginData.hostname = config.getValue("MostUsedServerName0",
+ defaultAccountServerName.c_str());
+ }
+ else {
+ loginData.hostname = options.serverName;
+ }
+ if (options.serverPort == 0) {
+ loginData.port = (short)config.getValue("MostUsedServerPort0",
+ defaultAccountServerPort);
+ } else {
+ loginData.port = options.serverPort;
+ }
- loginData.username = options.playername;
- if (loginData.username.empty()) {
- if (config.getValue("remember", 0)) {
- loginData.username = config.getValue("username", "");
+ loginData.username = options.playername;
+ if (loginData.username.empty()) {
+ if (config.getValue("remember", 0)) {
+ loginData.username = config.getValue("username", "");
+ }
+ }
+ if (!options.password.empty()) {
+ loginData.password = options.password;
}
- }
- if (!options.password.empty()) {
- loginData.password = options.password;
- }
- loginData.remember = config.getValue("remember", 0);
- loginData.registerLogin = false;
+ loginData.remember = config.getValue("remember", 0);
+ loginData.registerLogin = false;
- Net::initialize();
- accountServerConnection = Net::getConnection();
- gameServerConnection = Net::getConnection();
- chatServerConnection = Net::getConnection();
+ Net::initialize();
+ accountServerConnection = Net::getConnection();
+ gameServerConnection = Net::getConnection();
+ chatServerConnection = Net::getConnection();
- unsigned int oldstate = !state; // We start with a status change.
+ unsigned int oldstate = !state; // We start with a status change.
- SDL_Event event;
- while (state != STATE_FORCE_QUIT)
- {
- // Handle SDL events
- while (SDL_PollEvent(&event)) {
- switch (event.type) {
- case SDL_QUIT:
- state = STATE_FORCE_QUIT;
- break;
-
- case SDL_KEYDOWN:
- if (event.key.keysym.sym == SDLK_ESCAPE)
- if (!quitDialog)
- {
- quitDialog = new QuitDialog(NULL, &quitDialog);
- }
- else
- {
- quitDialog->requestMoveToTop();
- }
- break;
+ SDL_Event event;
+ while (state != STATE_FORCE_QUIT)
+ {
+ // Handle SDL events
+ while (SDL_PollEvent(&event)) {
+ switch (event.type) {
+ case SDL_QUIT:
+ state = STATE_FORCE_QUIT;
+ break;
+
+ case SDL_KEYDOWN:
+ if (event.key.keysym.sym == SDLK_ESCAPE)
+ if (!quitDialog)
+ {
+ quitDialog = new QuitDialog(NULL, &quitDialog);
+ }
+ else
+ {
+ quitDialog->requestMoveToTop();
+ }
+ break;
+ }
+
+ guiInput->pushInput(event);
}
- guiInput->pushInput(event);
- }
-
- Net::flush();
- gui->logic();
+ Net::flush();
+ gui->logic();
- if (!login_wallpaper)
- {
- login_wallpaper = ResourceManager::getInstance()->
- getImage("graphics/images/login_wallpaper.png");
if (!login_wallpaper)
{
- logger->error("Couldn't load login_wallpaper.png");
+ login_wallpaper = ResourceManager::getInstance()->
+ getImage("graphics/images/login_wallpaper.png");
+ if (!login_wallpaper)
+ {
+ logger->error("Couldn't load login_wallpaper.png");
+ }
}
- }
- graphics->drawImage(login_wallpaper, 0, 0);
- gui->draw();
- graphics->updateScreen();
+ graphics->drawImage(login_wallpaper, 0, 0);
+ gui->draw();
+ graphics->updateScreen();
- // TODO: Add connect timeouts
- if (state == STATE_CONNECT_ACCOUNT &&
- accountServerConnection->isConnected())
- {
- if (options.skipUpdate) {
- state = STATE_LOADDATA;
- } else {
- state = STATE_UPDATE;
+ // TODO: Add connect timeouts
+ if (state == STATE_CONNECT_ACCOUNT &&
+ accountServerConnection->isConnected())
+ {
+ if (options.skipUpdate) {
+ state = STATE_LOADDATA;
+ } else {
+ state = STATE_UPDATE;
+ }
}
- }
- else if (state == STATE_CONNECT_GAME &&
- gameServerConnection->isConnected() &&
- chatServerConnection->isConnected())
- {
- accountServerConnection->disconnect();
- Net::clearHandlers();
-
- state = STATE_GAME;
- }
- else if (state == STATE_RECONNECT_ACCOUNT &&
- accountServerConnection->isConnected())
- {
- reconnectAccount(token);
- state = STATE_WAIT;
- }
+ else if (state == STATE_CONNECT_GAME &&
+ gameServerConnection->isConnected() &&
+ chatServerConnection->isConnected())
+ {
+ accountServerConnection->disconnect();
+ Net::clearHandlers();
- if (state != oldstate) {
- // Load updates after exiting the update state
- if (oldstate == STATE_UPDATE)
+ state = STATE_GAME;
+ }
+ else if (state == STATE_RECONNECT_ACCOUNT &&
+ accountServerConnection->isConnected())
{
- loadUpdates();
- // Reload the wallpaper in case that it was updated
- login_wallpaper->decRef();
- login_wallpaper = ResourceManager::getInstance()->
- getImage("graphics/images/login_wallpaper.png");
+ reconnectAccount(token);
+ state = STATE_WAIT;
}
- oldstate = state;
+ if (state != oldstate) {
+ // Load updates after exiting the update state
+ if (oldstate == STATE_UPDATE)
+ {
+ loadUpdates();
+ // Reload the wallpaper in case that it was updated
+ login_wallpaper->decRef();
+ login_wallpaper = ResourceManager::getInstance()->
+ getImage("graphics/images/login_wallpaper.png");
+ }
+
+ oldstate = state;
+
+ // Get rid of the dialog of the previous state
+ if (currentDialog) {
+ delete currentDialog;
+ currentDialog = NULL;
+ }
+ // State has changed, while the quitDialog was active, it might
+ // not be correct anymore
+ if (quitDialog) {
+ quitDialog->scheduleDelete();
+ }
+
+ switch (state) {
+ case STATE_CHOOSE_SERVER:
+ logger->log("State: CHOOSE_SERVER");
+
+ // Allow changing this using a server choice dialog
+ // We show the dialog box only if the command-line options
+ // weren't set.
+ if (options.serverName.empty() && options.serverPort == 0) {
+ currentDialog = new ServerDialog(&loginData);
+ } else {
+ state = STATE_CONNECT_ACCOUNT;
+
+ // Reset options so that cancelling or connect timeout
+ // will show the server dialog
+ options.serverName = "";
+ options.serverPort = 0;
+ }
+ break;
+
+ case STATE_CONNECT_ACCOUNT:
+ logger->log("State: CONNECT_ACCOUNT");
+ logger->log("Trying to connect to account server...");
+ accountServerConnection->connect(loginData.hostname,
+ loginData.port);
+ currentDialog = new ConnectionDialog(STATE_CHOOSE_SERVER);
+ break;
+
+ case STATE_UPDATE:
+ logger->log("State: UPDATE");
+ // TODO: Revive later
+ //currentDialog = new UpdaterWindow();
+ state = STATE_LOADDATA;
+ break;
+
+ case STATE_LOGIN:
+ logger->log("State: LOGIN");
+ currentDialog = new LoginDialog(&loginData);
+ // TODO: Restore autologin
+ //if (!loginData.password.empty()) {
+ // accountLogin(&loginData);
+ //}
+ break;
+
+ case STATE_LOADDATA:
+ logger->log("State: LOADDATA");
+
+ // Add customdata directory
+ ResourceManager::getInstance()->searchAndAddArchives(
+ "customdata/",
+ "zip",
+ false);
+
+ // Load XML databases
+ EquipmentDB::load();
+ ItemDB::load();
+ MonsterDB::load();
+ state = STATE_LOGIN;
+ break;
+
+ case STATE_LOGIN_ATTEMPT:
+ accountLogin(&loginData);
+ break;
+
+ case STATE_SWITCH_ACCOUNTSERVER:
+ logger->log("State: SWITCH_ACCOUNTSERVER");
+
+ gameServerConnection->disconnect();
+ chatServerConnection->disconnect();
+ accountServerConnection->disconnect();
+
+ state = STATE_CHOOSE_SERVER;
+ break;
+
+ case STATE_SWITCH_ACCOUNTSERVER_ATTEMPT:
+ logger->log("State: SWITCH_ACCOUNTSERVER_ATTEMPT");
+ switchAccountServer();
+ break;
+
+ case STATE_REGISTER:
+ logger->log("State: REGISTER");
+ currentDialog = new RegisterDialog(&loginData);
+ break;
+
+ case STATE_REGISTER_ATTEMPT:
+ accountRegister(&loginData);
+ break;
+
+ case STATE_CHAR_SELECT:
+ logger->log("State: CHAR_SELECT");
+ currentDialog =
+ new CharSelectDialog(&charInfo, &loginData);
+
+ if (((CharSelectDialog*) currentDialog)->
+ selectByName(options.playername))
+ options.chooseDefault = true;
+ else
+ ((CharSelectDialog*) currentDialog)->selectByName(
+ config.getValue("lastCharacter", ""));
- // Get rid of the dialog of the previous state
- if (currentDialog) {
- delete currentDialog;
- currentDialog = NULL;
- }
- // State has changed, while the quitDialog was active, it might
- // not be correct anymore
- if (quitDialog) {
- quitDialog->scheduleDelete();
- }
+ if (options.chooseDefault)
+ {
+ ((CharSelectDialog*) currentDialog)->action(
+ gcn::ActionEvent(NULL, "ok"));
+ options.chooseDefault = false;
+ }
- switch (state) {
- case STATE_CHOOSE_SERVER:
- logger->log("State: CHOOSE_SERVER");
-
- // Allow changing this using a server choice dialog
- // We show the dialog box only if the command-line options
- // weren't set.
- if (options.serverName.empty() && options.serverPort == 0) {
- currentDialog = new ServerDialog(&loginData);
- } else {
- state = STATE_CONNECT_ACCOUNT;
-
- // Reset options so that cancelling or connect timeout
- // will show the server dialog
- options.serverName = "";
- options.serverPort = 0;
- }
- break;
-
- case STATE_CONNECT_ACCOUNT:
- logger->log("State: CONNECT_ACCOUNT");
- logger->log("Trying to connect to account server...");
- accountServerConnection->connect(loginData.hostname,
- loginData.port);
- currentDialog = new ConnectionDialog(STATE_CHOOSE_SERVER);
- break;
-
- case STATE_UPDATE:
- logger->log("State: UPDATE");
- // TODO: Revive later
- //currentDialog = new UpdaterWindow();
- state = STATE_LOADDATA;
- break;
-
- case STATE_LOGIN:
- logger->log("State: LOGIN");
- currentDialog = new LoginDialog(&loginData);
- // TODO: Restore autologin
- //if (!loginData.password.empty()) {
- // accountLogin(&loginData);
- //}
- break;
-
- case STATE_LOADDATA:
- logger->log("State: LOADDATA");
-
- // Add customdata directory
- ResourceManager::getInstance()->searchAndAddArchives(
- "customdata/",
- "zip",
- false);
-
- // Load XML databases
- EquipmentDB::load();
- ItemDB::load();
- MonsterDB::load();
- state = STATE_LOGIN;
- break;
-
- case STATE_LOGIN_ATTEMPT:
- accountLogin(&loginData);
- break;
-
- case STATE_SWITCH_ACCOUNTSERVER:
- logger->log("State: SWITCH_ACCOUNTSERVER");
-
- gameServerConnection->disconnect();
- chatServerConnection->disconnect();
- accountServerConnection->disconnect();
-
- state = STATE_CHOOSE_SERVER;
- break;
-
- case STATE_SWITCH_ACCOUNTSERVER_ATTEMPT:
- logger->log("State: SWITCH_ACCOUNTSERVER_ATTEMPT");
- switchAccountServer();
- break;
-
- case STATE_REGISTER:
- logger->log("State: REGISTER");
- currentDialog = new RegisterDialog(&loginData);
- break;
-
- case STATE_REGISTER_ATTEMPT:
- accountRegister(&loginData);
- break;
-
- case STATE_CHAR_SELECT:
- logger->log("State: CHAR_SELECT");
- currentDialog =
- new CharSelectDialog(&charInfo, &loginData);
-
- if (((CharSelectDialog*) currentDialog)->
- selectByName(options.playername))
- options.chooseDefault = true;
- else
- ((CharSelectDialog*) currentDialog)->selectByName(
- config.getValue("lastCharacter", ""));
-
- if (options.chooseDefault)
- {
- ((CharSelectDialog*) currentDialog)->action(
- gcn::ActionEvent(NULL, "ok"));
- options.chooseDefault = false;
- }
-
- break;
-
- case STATE_UNREGISTER_ATTEMPT:
- logger->log("State: UNREGISTER ATTEMPT");
- accountUnRegister(&loginData);
- loginData.clear();
- break;
-
- case STATE_UNREGISTER:
- logger->log("State: UNREGISTER");
- accountServerConnection->disconnect();
- currentDialog = new OkDialog("Unregister succesfull",
- "Farewell, come back any time ....");
-
- //The errorlistener sets the state to STATE_CHOOSE_SERVER
- currentDialog->addActionListener(&errorListener);
- currentDialog = NULL; // OkDialog deletes itself
- break;
-
- case STATE_ERROR:
- logger->log("State: ERROR");
- currentDialog = new OkDialog("Error", errorMessage);
- currentDialog->addActionListener(&errorListener);
- currentDialog = NULL; // OkDialog deletes itself
- gameServerConnection->disconnect();
- chatServerConnection->disconnect();
- Net::clearHandlers();
- break;
-
- case STATE_CONNECT_GAME:
- logger->log("State: CONNECT_GAME");
- currentDialog = new ConnectionDialog(STATE_CHAR_SELECT);
- break;
-
- case STATE_GAME:
- logger->log("Memorizing selected character %s",
- player_node->getName().c_str());
- config.setValue("lastCharacter", player_node->getName());
-
- Net::GameServer::connect(gameServerConnection, token);
- Net::ChatServer::connect(chatServerConnection, token);
- sound.fadeOutMusic(1000);
+ break;
+
+ case STATE_UNREGISTER_ATTEMPT:
+ logger->log("State: UNREGISTER ATTEMPT");
+ accountUnRegister(&loginData);
+ loginData.clear();
+ break;
+
+ case STATE_UNREGISTER:
+ logger->log("State: UNREGISTER");
+ accountServerConnection->disconnect();
+ currentDialog = new OkDialog("Unregister succesfull",
+ "Farewell, come back any time ....");
+
+ //The errorlistener sets the state to STATE_CHOOSE_SERVER
+ currentDialog->addActionListener(&errorListener);
+ currentDialog = NULL; // OkDialog deletes itself
+ break;
+
+ case STATE_ERROR:
+ logger->log("State: ERROR");
+ currentDialog = new OkDialog("Error", errorMessage);
+ currentDialog->addActionListener(&errorListener);
+ currentDialog = NULL; // OkDialog deletes itself
+ gameServerConnection->disconnect();
+ chatServerConnection->disconnect();
+ Net::clearHandlers();
+ break;
+
+ case STATE_CONNECT_GAME:
+ logger->log("State: CONNECT_GAME");
+ currentDialog = new ConnectionDialog(STATE_CHAR_SELECT);
+ break;
+
+ case STATE_GAME:
+ logger->log("Memorizing selected character %s",
+ player_node->getName().c_str());
+ config.setValue("lastCharacter", player_node->getName());
+
+ Net::GameServer::connect(gameServerConnection, token);
+ Net::ChatServer::connect(chatServerConnection, token);
+ sound.fadeOutMusic(1000);
#ifdef PACKAGE_VERSION
- delete versionLabel;
- versionLabel = NULL;
+ delete versionLabel;
+ versionLabel = NULL;
#endif
- currentDialog = NULL;
+ currentDialog = NULL;
+
+ logger->log("State: GAME");
+ game = new Game;
+ game->logic();
+ delete game;
+
+ //If the quitdialog didn't set the next state
+ if (state == STATE_GAME)
+ {
+ state = STATE_EXIT;
+ }
+ break;
+
+ case STATE_SWITCH_CHARACTER:
+ logger->log("State: SWITCH_CHARACTER");
+ switchCharacter(&token);
+ break;
+
+ case STATE_RECONNECT_ACCOUNT:
+ logger->log("State: RECONNECT_ACCOUNT");
- logger->log("State: GAME");
- game = new Game;
- game->logic();
- delete game;
-
- //If the quitdialog didn't set the next state
- if (state == STATE_GAME)
- {
- state = STATE_EXIT;
- }
- break;
-
- case STATE_SWITCH_CHARACTER:
- logger->log("State: SWITCH_CHARACTER");
- switchCharacter(&token);
- break;
-
- case STATE_RECONNECT_ACCOUNT:
- logger->log("State: RECONNECT_ACCOUNT");
-
- //done with game&chat
- gameServerConnection->disconnect();
- chatServerConnection->disconnect();
-
- accountServerConnection->connect(loginData.hostname,
- loginData.port);
- break;
-
- case STATE_WAIT:
- break;
-
- case STATE_EXIT:
- logger->log("State: EXIT");
- logoutThenExit();
- break;
-
- default:
- state = STATE_FORCE_QUIT;
- break;
+ //done with game&chat
+ gameServerConnection->disconnect();
+ chatServerConnection->disconnect();
+
+ accountServerConnection->connect(loginData.hostname,
+ loginData.port);
+ break;
+
+ case STATE_WAIT:
+ break;
+
+ case STATE_EXIT:
+ logger->log("State: EXIT");
+ logoutThenExit();
+ break;
+
+ default:
+ state = STATE_FORCE_QUIT;
+ break;
+ }
}
}
+
+ }
+ catch (...)
+ {
+ logger->log("Exception");
}
accountServerConnection->disconnect();
@@ -1051,5 +1059,6 @@ int main(int argc, char *argv[])
exit_engine();
PHYSFS_deinit();
delete logger;
+
return 0;
}
diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp
index 375c43a0..51e99fa0 100644
--- a/src/openglgraphics.cpp
+++ b/src/openglgraphics.cpp
@@ -41,7 +41,6 @@
#include <guichan/exception.hpp>
#include <guichan/image.hpp>
-#include <guichan/opengl/openglimage.hpp>
#include "log.h"