summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CMakeLists.txt6
-rw-r--r--src/Makefile.am2
-rw-r--r--src/gui/widgets/desktop.cpp95
-rw-r--r--src/gui/widgets/desktop.h62
-rw-r--r--src/gui/widgets/label.cpp3
-rw-r--r--src/main.cpp101
-rw-r--r--src/main.h9
-rw-r--r--src/net/ea/network.cpp4
-rw-r--r--src/net/ea/network.h3
-rw-r--r--src/resources/resourcemanager.h1
-rw-r--r--src/resources/wallpaper.cpp14
-rw-r--r--src/resources/wallpaper.h2
12 files changed, 201 insertions, 101 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0ffb7c5a..efb548ea 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -64,6 +64,8 @@ SET(SRCS
gui/widgets/chattab.h
gui/widgets/checkbox.cpp
gui/widgets/checkbox.h
+ gui/widgets/desktop.cpp
+ gui/widgets/desktop.h
gui/widgets/dropdown.cpp
gui/widgets/dropdown.h
gui/widgets/gccontainer.cpp
@@ -114,6 +116,8 @@ SET(SRCS
gui/buy.h
gui/buysell.cpp
gui/buysell.h
+ gui/char_select.cpp
+ gui/char_select.h
gui/charcreatedialog.cpp
gui/charcreatedialog.h
gui/chat.cpp
@@ -410,8 +414,6 @@ SET(SRCS
)
SET(SRCS_EA
- gui/char_select.cpp
- gui/char_select.h
gui/skill.cpp
gui/skill.h
gui/status.cpp
diff --git a/src/Makefile.am b/src/Makefile.am
index d48dbe60..e13299f0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,8 @@ tmw_SOURCES = gui/widgets/avatar.cpp \
gui/widgets/chattab.h \
gui/widgets/checkbox.cpp \
gui/widgets/checkbox.h \
+ gui/widgets/desktop.cpp \
+ gui/widgets/desktop.h \
gui/widgets/dropdown.cpp \
gui/widgets/dropdown.h \
gui/widgets/gccontainer.cpp \
diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp
new file mode 100644
index 00000000..fc66ed93
--- /dev/null
+++ b/src/gui/widgets/desktop.cpp
@@ -0,0 +1,95 @@
+/*
+ * Desktop widget
+ * Copyright (c) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "gui/widgets/desktop.h"
+
+#include "gui/palette.h"
+
+#include "resources/image.h"
+#include "resources/resourcemanager.h"
+#include "resources/wallpaper.h"
+
+#include "graphics.h"
+#include "log.h"
+
+Desktop::Desktop()
+ : mWallpaper(0)
+{
+ addWidgetListener(this);
+
+ Wallpaper::loadWallpapers();
+}
+
+Desktop::~Desktop()
+{
+ if (mWallpaper)
+ mWallpaper->decRef();
+}
+
+void Desktop::reloadWallpaper()
+{
+ Wallpaper::loadWallpapers();
+ setBestFittingWallpaper();
+}
+
+void Desktop::widgetResized(const gcn::Event &event)
+{
+ setBestFittingWallpaper();
+}
+
+void Desktop::draw(gcn::Graphics *graphics)
+{
+ Graphics *g = static_cast<Graphics *>(graphics);
+
+ if (!mWallpaper || (getWidth() > mWallpaper->getWidth() ||
+ getHeight() > mWallpaper->getHeight()))
+ {
+ // TODO: Color from palette
+ g->setColor(gcn::Color(64, 64, 64));
+ g->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight()));
+ }
+
+ if (mWallpaper)
+ {
+ g->drawImage(mWallpaper,
+ (getWidth() - mWallpaper->getWidth()) / 2,
+ (getHeight() - mWallpaper->getHeight()) / 2);
+ }
+}
+
+void Desktop::setBestFittingWallpaper()
+{
+ const std::string wallpaperName =
+ Wallpaper::getWallpaper(getWidth(), getHeight());
+
+ Image *temp = ResourceManager::getInstance()->getImage(wallpaperName);
+
+ if (temp)
+ {
+ if (mWallpaper)
+ mWallpaper->decRef();
+ mWallpaper = temp;
+ }
+ else
+ {
+ logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
+ }
+}
diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h
new file mode 100644
index 00000000..ed68145a
--- /dev/null
+++ b/src/gui/widgets/desktop.h
@@ -0,0 +1,62 @@
+/*
+ * Desktop widget
+ * Copyright (c) 2009 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * This program 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.
+ *
+ * This program 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 this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef DESKTOP_H
+#define DESKTOP_H
+
+#include <guichan/widget.hpp>
+#include <guichan/widgetlistener.hpp>
+
+class Image;
+
+/**
+ * Desktop widget, for drawing a background image and color.
+ *
+ * It picks the best fitting background image. If the image doesn't fit, a
+ * background color is drawn and the image is centered.
+ *
+ * When the desktop widget is resized, the background image is automatically
+ * updated.
+ *
+ * \ingroup GUI
+ */
+class Desktop : public gcn::Widget, gcn::WidgetListener
+{
+ public:
+ Desktop();
+ ~Desktop();
+
+ /**
+ * Has to be called after updates have been loaded.
+ */
+ void reloadWallpaper();
+
+ void widgetResized(const gcn::Event &event);
+
+ void draw(gcn::Graphics *graphics);
+
+ private:
+ void setBestFittingWallpaper();
+
+ Image *mWallpaper;
+};
+
+#endif // DESKTOP_H
diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp
index 39fbf220..2c559872 100644
--- a/src/gui/widgets/label.cpp
+++ b/src/gui/widgets/label.cpp
@@ -23,8 +23,7 @@
#include "gui/palette.h"
-Label::Label() :
- gcn::Label()
+Label::Label()
{
}
diff --git a/src/main.cpp b/src/main.cpp
index d113f3e4..1f3d4664 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -41,6 +41,7 @@
#include "units.h"
#include "gui/widgets/button.h"
+#include "gui/widgets/desktop.h"
#include "gui/widgets/label.h"
#include "gui/widgets/progressbar.h"
@@ -93,7 +94,6 @@
#include "resources/monsterdb.h"
#include "resources/npcdb.h"
#include "resources/resourcemanager.h"
-#include "resources/wallpaper.h"
#include "utils/gettext.h"
#include "utils/stringutils.h"
@@ -138,6 +138,12 @@ namespace
} listener;
}
+static const int defaultScreenWidth = 800;
+static const int defaultScreenHeight = 600;
+
+static const int defaultSfxVolume = 100;
+static const int defaultMusicVolume = 60;
+
std::string token; //used to store magic_token
// Account infos
@@ -922,10 +928,11 @@ int main(int argc, char *argv[])
#ifdef TMWSERV_SUPPORT
QuitDialog* quitDialog = NULL;
#endif
- Image *login_wallpaper = NULL;
setupWindow = new Setup;
gcn::Container *top = static_cast<gcn::Container*>(gui->getTop());
+ Desktop *desktop = new Desktop;
+ top->add(desktop);
#ifdef PACKAGE_VERSION
#ifdef TMWSERV_SUPPORT
gcn::Label *versionLabel = new Label(strprintf("%s (tmwserv)", PACKAGE_VERSION));
@@ -940,9 +947,9 @@ int main(int argc, char *argv[])
top->add(progressLabel, 15 + progressBar->getWidth(),
progressBar->getY() + 4);
progressBar->setVisible(false);
- gcn::Button *setup = new Button(_("Setup"), "Setup", &listener);
- setup->setPosition(top->getWidth() - setup->getWidth() - 3, 3);
- top->add(setup);
+ gcn::Button *setupButton = new Button(_("Setup"), "Setup", &listener);
+ setupButton->setPosition(top->getWidth() - setupButton->getWidth() - 3, 3);
+ top->add(setupButton);
sound.playMusic(branding.getValue("loginMusic", ""));
@@ -969,7 +976,6 @@ int main(int argc, char *argv[])
Net::initialize();
new TmwServ::GeneralHandler; // Currently registers itself
#else
- SDLNet_Init();
Network *network = new Network;
EAthena::GeneralHandler *generalHandler = new EAthena::GeneralHandler;
network->registerHandler(generalHandler);
@@ -977,20 +983,11 @@ int main(int argc, char *argv[])
Net::getGeneralHandler()->load();
- // Set the most appropriate wallpaper, based on screen width
- Wallpaper::loadWallpapers();
-
int screenWidth = (int) config.getValue("screenwidth", defaultScreenWidth);
int screenHeight = static_cast<int>(config.getValue("screenheight",
defaultScreenHeight));
- std::string wallpaperName = Wallpaper::getWallpaper(screenWidth,
- screenHeight);
-
- login_wallpaper = ResourceManager::getInstance()->getImage(wallpaperName);
-
- if (!login_wallpaper)
- logger->log("Couldn't load %s as wallpaper", wallpaperName.c_str());
+ desktop->setSize(screenWidth, screenHeight);
unsigned int oldstate = !state; // We start with a status change.
@@ -1059,16 +1056,6 @@ int main(int argc, char *argv[])
progressBar->setProgress(0.0f);
}
- if (graphics->getWidth() > login_wallpaper->getWidth() ||
- graphics->getHeight() > login_wallpaper->getHeight())
- {
- graphics->setColor(gcn::Color(64, 64, 64));
- graphics->fillRectangle(gcn::Rectangle(
- 0, 0, graphics->getWidth(), graphics->getHeight()));
- }
- graphics->drawImage(login_wallpaper,
- (graphics->getWidth() - login_wallpaper->getWidth()) / 2,
- (graphics->getHeight() - login_wallpaper->getHeight()) / 2);
gui->draw();
graphics->updateScreen();
@@ -1105,11 +1092,6 @@ int main(int argc, char *argv[])
if (oldstate == STATE_UPDATE)
{
loadUpdates();
- // Reload the wallpaper in case that it was updated
- login_wallpaper->decRef();
- login_wallpaper = ResourceManager::getInstance()->getImage(
- branding.getValue("loginWallpaper",
- "graphics/images/login_wallpaper.png"));
}
oldstate = state;
@@ -1196,24 +1178,7 @@ int main(int argc, char *argv[])
EmoteDB::load();
Units::loadUnits();
- Wallpaper::loadWallpapers();
-
- {
- int screenWidth = (int) config.getValue("screenwidth",
- defaultScreenWidth);
- int screenHeight = (int) config.getValue("screenheight",
- defaultScreenHeight);
-
- Image *temp = ResourceManager::getInstance()
- ->getImage(Wallpaper::getWallpaper(screenWidth,
- screenHeight));
-
- if (temp)
- {
- login_wallpaper->decRef();
- login_wallpaper = temp;
- }
- }
+ desktop->reloadWallpaper();
state = STATE_LOGIN;
break;
@@ -1409,25 +1374,6 @@ int main(int argc, char *argv[])
{
case STATE_UPDATE:
loadUpdates();
- // Reload the wallpaper in case that it was updated
- Wallpaper::loadWallpapers();
-
- {
- int screenWidth = (int) config.getValue("screenwidth",
- defaultScreenWidth);
- int screenHeight = (int) config.getValue("screenheight",
- defaultScreenHeight);
-
- Image *temp = ResourceManager::getInstance()
- ->getImage(Wallpaper::getWallpaper(screenWidth,
- screenHeight));
-
- if (temp)
- {
- login_wallpaper->decRef();
- login_wallpaper = temp;
- }
- }
break;
// Those states don't cause a network disconnect
@@ -1478,6 +1424,8 @@ int main(int argc, char *argv[])
// Load units
Units::loadUnits();
+ desktop->reloadWallpaper();
+
state = STATE_CHAR_CONNECT;
break;
@@ -1558,16 +1506,16 @@ int main(int argc, char *argv[])
#endif
delete progressBar;
delete progressLabel;
- delete setup;
+ delete setupButton;
+ delete desktop;
progressBar = NULL;
progressLabel = NULL;
currentDialog = NULL;
- setup = NULL;
- login_wallpaper->decRef();
- login_wallpaper = NULL;
+ setupButton = NULL;
+ desktop = NULL;
logger->log("State: GAME");
- game = new Game();
+ game = new Game;
game->logic();
delete game;
state = STATE_EXIT;
@@ -1651,13 +1599,12 @@ int main(int argc, char *argv[])
#endif
delete progressBar;
delete progressLabel;
- delete setup;
+ delete setupButton;
delete setupWindow;
+ delete desktop;
-#ifdef TMWSERV_SUPPORT
-#else
+#ifdef EATHENA_SUPPORT
delete network;
- SDLNet_Quit();
#endif
logger->log("Quitting");
diff --git a/src/main.h b/src/main.h
index ca5969d0..4f29425f 100644
--- a/src/main.h
+++ b/src/main.h
@@ -119,15 +119,6 @@ enum {
LEN_MIN_PASSWORD = 4
};
-// Default game values
-// -------------------
-// Screen
-const short defaultScreenWidth = 800;
-const short defaultScreenHeight = 600;
-// Sound
-const short defaultSfxVolume = 100;
-const short defaultMusicVolume = 60;
-
// Defines the number of usable player slots
const short maxSlot = 2;
diff --git a/src/net/ea/network.cpp b/src/net/ea/network.cpp
index 690ca946..7b731de3 100644
--- a/src/net/ea/network.cpp
+++ b/src/net/ea/network.cpp
@@ -103,6 +103,8 @@ Network::Network():
mState(IDLE),
mWorkerThread(0)
{
+ SDLNet_Init();
+
mMutex = SDL_CreateMutex();
mInstance = this;
}
@@ -119,6 +121,8 @@ Network::~Network()
delete[] mInBuffer;
delete[] mOutBuffer;
+
+ SDLNet_Quit();
}
bool Network::connect(const std::string &address, short port)
diff --git a/src/net/ea/network.h b/src/net/ea/network.h
index c246ab8e..741a8297 100644
--- a/src/net/ea/network.h
+++ b/src/net/ea/network.h
@@ -22,9 +22,10 @@
#ifndef EA_NETWORK_H
#define EA_NETWORK_H
-#include <map>
#include <SDL_net.h>
#include <SDL_thread.h>
+
+#include <map>
#include <string>
/**
diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h
index 17ce7cae..ec60fa9a 100644
--- a/src/resources/resourcemanager.h
+++ b/src/resources/resourcemanager.h
@@ -40,7 +40,6 @@ struct SDL_Surface;
*/
class ResourceManager
{
-
friend class Resource;
public:
diff --git a/src/resources/wallpaper.cpp b/src/resources/wallpaper.cpp
index 07f6ecb6..5e9aa008 100644
--- a/src/resources/wallpaper.cpp
+++ b/src/resources/wallpaper.cpp
@@ -53,20 +53,20 @@ bool wallpaperCompare(WallpaperSize a, WallpaperSize b)
void Wallpaper::loadWallpapers()
{
- char **imgs = PHYSFS_enumerateFiles(WALLPAPER_FOLDER);
- char **i;
- size_t baseLen = strlen(WALLPAPER_BASE);
- int width;
- int height;
-
wallpaperSizes.clear();
+ size_t baseLen = strlen(WALLPAPER_BASE);
haveBackup = false;
- for (i = imgs; *i != NULL; i++)
+ char **imgs = PHYSFS_enumerateFiles(WALLPAPER_FOLDER);
+
+ for (char **i = imgs; *i != NULL; i++)
{
if (strncmp(*i, WALLPAPER_BASE, baseLen) == 0)
{
+ int width;
+ int height;
+
if (strlen(*i) == baseLen + 4)
{
if (haveBackup)
diff --git a/src/resources/wallpaper.h b/src/resources/wallpaper.h
index 96a655e8..fd501a83 100644
--- a/src/resources/wallpaper.h
+++ b/src/resources/wallpaper.h
@@ -24,8 +24,6 @@
#include <string>
-#include <SDL_types.h>
-
/**
* Handles organizing and choosing of wallpapers.
*/