From 00e16d73c34a894ff70bae27eb22be14a245543d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 31 Dec 2008 16:29:33 +0100 Subject: Synchronized font size with mainline --- src/gui/gui.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index a65cb0fb..4052951f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -108,7 +108,7 @@ Gui::Gui(Graphics *graphics): // Set global font (based on ISO-8859-15) try { - mGuiFont = new TrueTypeFont("data/fonts/dejavusans.ttf", 12); + mGuiFont = new TrueTypeFont("data/fonts/dejavusans.ttf", 11); } catch (gcn::Exception e) { -- cgit v1.2.3-70-g09d2 From 0c8980d0d68faaff62b96555d0bb050ee767c4dd Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 31 Dec 2008 17:13:53 +0100 Subject: Made an option around the syncing, but no way to change it for now. (cherry picked from mainline commit f6f8b2f885145d4cacf7a6c42d88b6a39f71b366) Conflicts: src/openglgraphics.cpp --- src/openglgraphics.cpp | 16 ++++++++++++---- src/openglgraphics.h | 8 ++++++++ 2 files changed, 20 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index d8d7a807..48b10a1f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -45,7 +45,8 @@ #include "resources/image.h" OpenGLGraphics::OpenGLGraphics(): - mAlpha(false), mTexture(false), mColorAlpha(false) + mAlpha(false), mTexture(false), mColorAlpha(false), + mSync(false) { } @@ -53,6 +54,11 @@ OpenGLGraphics::~OpenGLGraphics() { } +void OpenGLGraphics::setSync(bool sync) +{ + mSync = sync; +} + bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) { logger->log("Setting video mode %dx%d %s", @@ -74,8 +80,10 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) } #ifdef __APPLE__ -// long VBL = 1; -// CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); + if (mSync) { + const GLint VBL = 1; + CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); + } #endif // Setup OpenGL @@ -352,7 +360,7 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) void OpenGLGraphics::drawRectangle(const gcn::Rectangle& rect, bool filled) { - float offset = filled ? 0 : 0.5f; + const float offset = filled ? 0 : 0.5f; setTexturingAndBlending(false); diff --git a/src/openglgraphics.h b/src/openglgraphics.h index 7d39e306..ea30e019 100644 --- a/src/openglgraphics.h +++ b/src/openglgraphics.h @@ -31,6 +31,13 @@ class OpenGLGraphics : public Graphics ~OpenGLGraphics(); + /** + * Sets whether vertical refresh syncing is enabled. Takes effect after + * the next call to setVideoMode(). Only implemented on MacOS for now. + */ + void setSync(bool sync); + bool getSync() const { return mSync; } + bool setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel); bool drawImage(Image *image, @@ -72,6 +79,7 @@ class OpenGLGraphics : public Graphics private: bool mAlpha, mTexture; bool mColorAlpha; + bool mSync; }; #endif -- cgit v1.2.3-70-g09d2 From 3ef079d0062aa08515369b186696617ec384cb5d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 2 Jan 2009 18:32:40 +0100 Subject: Removed executable bits from SDLMain.{h,m} --- src/SDLMain.h | 0 src/SDLMain.m | 0 2 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/SDLMain.h mode change 100755 => 100644 src/SDLMain.m (limited to 'src') diff --git a/src/SDLMain.h b/src/SDLMain.h old mode 100755 new mode 100644 diff --git a/src/SDLMain.m b/src/SDLMain.m old mode 100755 new mode 100644 -- cgit v1.2.3-70-g09d2 From 33130dd288f5842f0edde0fff8618cdfe3afc856 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 2 Jan 2009 20:42:58 +0100 Subject: Removed duplicate TrueTypeFont class declaration Noticed by QOAL --- src/gui/truetypefont.cpp | 9 ++---- src/gui/truetypefont.h | 75 +++--------------------------------------------- 2 files changed, 7 insertions(+), 77 deletions(-) (limited to 'src') diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 7f9abd3a..0eed6f08 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -17,8 +17,6 @@ * 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" @@ -47,8 +45,7 @@ class TextChunk bool operator==(const TextChunk &chunk) const { - return ( - chunk.text == text && chunk.color == color); + return (chunk.text == text && chunk.color == color); } void generate(TTF_Font *font) @@ -84,7 +81,7 @@ typedef std::list::iterator CacheIterator; static int fontCounter; -TrueTypeFont::TrueTypeFont(const std::string& filename, int size) +TrueTypeFont::TrueTypeFont(const std::string &filename, int size) { if (fontCounter == 0 && TTF_Init() == -1) { @@ -167,7 +164,7 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, g->drawImage(cache.front().img, x, y); } -int TrueTypeFont::getWidth(const std::string& text) const +int TrueTypeFont::getWidth(const std::string &text) const { int w, h; TTF_SizeUTF8(mFont, text.c_str(), &w, &h); diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 48502f1f..e8617c7d 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -17,8 +17,6 @@ * 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 @@ -44,74 +42,7 @@ class TrueTypeFont : public gcn::Font * @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 - -#include -#include -#include - -/** - * A wrapper around SDL_ttf for allowing the use of TrueType fonts. - * - * NOTE: 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); + TrueTypeFont(const std::string &filename, int size); /** * Destructor. @@ -125,7 +56,9 @@ class TrueTypeFont : public gcn::Font /** * @see Font::drawString */ - void drawString(gcn::Graphics* graphics, const std::string& text, int x, int y); + void drawString(gcn::Graphics *graphics, + const std::string &text, + int x, int y); private: TTF_Font *mFont; -- cgit v1.2.3-70-g09d2 From ad276ae0d4679aee9d7e6082fa602b49c6fd940a Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 17 Dec 2008 20:23:33 +0100 Subject: Code reformatting Mainly making sure 'const std::string &' is used everywhere instead of 'std::string const &'. The former has always been the preferred order in this project. (cherry picked from mainline) --- src/animatedsprite.h | 27 ++++++++++----------------- src/gui/chat.cpp | 37 +++++++++++++------------------------ src/gui/chat.h | 21 +++++++-------------- src/gui/window.h | 9 +++------ src/localplayer.cpp | 5 +---- src/properties.h | 15 ++++++--------- src/resources/dye.cpp | 6 +++--- src/resources/dye.h | 6 +++--- src/resources/imageloader.cpp | 2 +- src/resources/imageloader.h | 3 ++- src/resources/resourcemanager.cpp | 12 ++++++------ src/resources/resourcemanager.h | 9 +++++---- src/resources/spritedef.cpp | 28 +++++++++++----------------- src/resources/spritedef.h | 23 +++++++++-------------- 14 files changed, 80 insertions(+), 123 deletions(-) (limited to 'src') diff --git a/src/animatedsprite.h b/src/animatedsprite.h index 405bf42e..41857d8f 100644 --- a/src/animatedsprite.h +++ b/src/animatedsprite.h @@ -50,7 +50,8 @@ class AnimatedSprite * @param filename the file of the sprite to animate * @param variant the sprite variant */ - static AnimatedSprite *load(std::string const &filename, int variant = 0); + static AnimatedSprite *load(const std::string &filename, + int variant = 0); /** * Destructor. @@ -60,50 +61,42 @@ class AnimatedSprite /** * Resets the animated sprite. */ - void - reset(); + void reset(); /** * Plays an action using the current direction */ - void - play(SpriteAction action); + void play(SpriteAction action); /** * Inform the animation of the passed time so that it can output the * correct animation frame. */ - void - update(int time); + void update(int time); /** * Draw the current animation frame at the coordinates given in screen * pixels. */ - bool - draw(Graphics* graphics, int posX, int posY) const; + bool draw(Graphics* graphics, int posX, int posY) const; /** * gets the width in pixels of the image of the current frame */ - int - getWidth() const; + int getWidth() const; /** * gets the height in pixels of the image of the current frame */ - int - getHeight() const; + int getHeight() const; /** * Sets the direction. */ - void - setDirection(SpriteDirection direction); + void setDirection(SpriteDirection direction); private: - bool - updateCurrentAnimation(unsigned int dt); + bool updateCurrentAnimation(unsigned int dt); SpriteDirection mDirection; /**< The sprite direction. */ int mLastTime; /**< The last time update was called. */ diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index edde42d0..aa24ba7f 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -91,8 +91,7 @@ void ChatWindow::widgetResized(const gcn::Event &event) mChatInput->getHeight() - 5); } -void -ChatWindow::chatLog(std::string line, int own) +void ChatWindow::chatLog(std::string line, int own) { // Trim whitespace trim(line); @@ -182,14 +181,12 @@ ChatWindow::chatLog(std::string line, int own) } } -void -ChatWindow::chatLog(CHATSKILL act) +void ChatWindow::chatLog(CHATSKILL act) { chatLog(const_msg(act), BY_SERVER); } -void -ChatWindow::action(const gcn::ActionEvent &event) +void ChatWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "chatinput") { @@ -222,8 +219,7 @@ ChatWindow::action(const gcn::ActionEvent &event) } } -void -ChatWindow::requestChatFocus() +void ChatWindow::requestChatFocus() { // Make sure chatWindow is visible if (!isVisible()) @@ -243,14 +239,13 @@ ChatWindow::requestChatFocus() mChatInput->requestFocus(); } -bool -ChatWindow::isInputFocused() +bool ChatWindow::isInputFocused() { return mChatInput->isFocused(); } -void -ChatWindow::whisper(const std::string &nick, std::string msg, int prefixlen) +void ChatWindow::whisper(const std::string &nick, std::string msg, + int prefixlen) { std::string recvnick = ""; msg.erase(0, prefixlen + 1); @@ -281,8 +276,7 @@ ChatWindow::whisper(const std::string &nick, std::string msg, int prefixlen) chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER); } -void -ChatWindow::chatSend(const std::string &nick, std::string msg) +void ChatWindow::chatSend(const std::string &nick, std::string msg) { /* Some messages are managed client side, while others * require server handling by proper packet. Probably @@ -354,8 +348,7 @@ ChatWindow::chatSend(const std::string &nick, std::string msg) } } -std::string -ChatWindow::const_msg(CHATSKILL act) +std::string ChatWindow::const_msg(CHATSKILL act) { std::string msg; if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) { @@ -432,8 +425,7 @@ ChatWindow::const_msg(CHATSKILL act) return msg; } -void -ChatWindow::scroll(int amount) +void ChatWindow::scroll(int amount) { if (!isVisible()) return; @@ -445,8 +437,7 @@ ChatWindow::scroll(int amount) mTextOutput->showPart(scr); } -void -ChatWindow::keyPressed(gcn::KeyEvent &event) +void ChatWindow::keyPressed(gcn::KeyEvent &event) { if (event.getKey().getValue() == gcn::Key::DOWN && mCurHist != mHistory.end()) @@ -471,15 +462,13 @@ ChatWindow::keyPressed(gcn::KeyEvent &event) } } -void -ChatWindow::setInputText(std::string input_str) +void ChatWindow::setInputText(std::string input_str) { mChatInput->setText(input_str + " "); requestChatFocus(); } -void -ChatWindow::setVisible(bool isVisible) +void ChatWindow::setVisible(bool isVisible) { Window::setVisible(isVisible); diff --git a/src/gui/chat.h b/src/gui/chat.h index 09c3712b..dc0d002d 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -183,20 +183,16 @@ class ChatWindow : public Window, public gcn::ActionListener, * // for simple message by a user /- message * chatlog.chat_send("Zaeiru", "Hello to all users on the screen!"); */ - void - chatSend(const std::string &nick, std::string msg); + void chatSend(const std::string &nick, std::string msg); /** Called when key is pressed */ - void - keyPressed(gcn::KeyEvent &event); + void keyPressed(gcn::KeyEvent &event); /** Called to set current text */ - void - setInputText(std::string input_str); + void setInputText(std::string input_str); /** Override to reset mTmpVisible */ - void - setVisible(bool visible); + void setVisible(bool visible); /** * Scrolls the chat window @@ -205,8 +201,7 @@ class ChatWindow : public Window, public gcn::ActionListener, * up, positive numbers scroll down. The absolute amount indicates the * amount of 1/8ths of chat window real estate that should be scrolled. */ - void - scroll(int amount); + void scroll(int amount); /** * help implements the /help command @@ -214,15 +209,13 @@ class ChatWindow : public Window, public gcn::ActionListener, * @param msg1 is the command that the player needs help on * @param msg2 is the sub-command relating to the command */ - void - help(const std::string &msg1, const std::string &msg2); + void help(const std::string &msg1, const std::string &msg2); private: Network *mNetwork; bool mTmpVisible; - void - whisper(const std::string &nick, std::string msg, int prefixlen); + void whisper(const std::string &nick, std::string msg, int prefixlen); /** One item in the chat log */ struct CHATLOG diff --git a/src/gui/window.h b/src/gui/window.h index 984c6f06..d40e8c91 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -163,8 +163,7 @@ class Window : public gcn::Window, gcn::WidgetListener * * @return The parent window or NULL if there is none. */ - Window* - getParentWindow() { return mParent; } + Window *getParentWindow() { return mParent; } /** * Schedule this window for deletion. It will be deleted at the start @@ -204,14 +203,12 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets the name of the window. This is not the window title. */ - void - setWindowName(const std::string &name) { mWindowName = name; } + void setWindowName(const std::string &name) { mWindowName = name; } /** * Returns the name of the window. This is not the window title. */ - const std::string& - getWindowName() { return mWindowName; } + const std::string &getWindowName() { return mWindowName; } /** * Reads the position (and the size for resizable windows) in the diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 044f62bf..aa27607c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -276,10 +276,7 @@ void LocalPlayer::setDestination(Uint16 x, Uint16 y) void LocalPlayer::setWalkingDir(int dir) { - if (mWalkingDir != dir) - { - mWalkingDir = dir; - } + mWalkingDir = dir; // If we're not already walking, start walking. if (mAction != WALK && dir) diff --git a/src/properties.h b/src/properties.h index 2eafeeca..a593e8c2 100644 --- a/src/properties.h +++ b/src/properties.h @@ -35,8 +35,7 @@ class Properties /** * Destructor. */ - virtual - ~Properties() {} + virtual ~Properties() {} /** * Get a map property. @@ -46,8 +45,8 @@ class Properties * @return the value of the given property or the given default when it * doesn't exist. */ - const std::string& - getProperty(const std::string &name, const std::string &def = "") const + const std::string &getProperty(const std::string &name, + const std::string &def = "") const { PropertyMap::const_iterator i = mProperties.find(name); return (i != mProperties.end()) ? i->second : def; @@ -61,7 +60,7 @@ class Properties * @return the value of the given property, or 0.0f when it doesn't * exist. */ - float getFloatProperty(std::string const &name, float def = 0.0f) const + float getFloatProperty(const std::string &name, float def = 0.0f) const { PropertyMap::const_iterator i = mProperties.find(name); float ret = def; @@ -81,8 +80,7 @@ class Properties * @return true when a property is defined, * false otherwise. */ - bool - hasProperty(const std::string &name) const + bool hasProperty(const std::string &name) const { return (mProperties.find(name) != mProperties.end()); } @@ -93,8 +91,7 @@ class Properties * @param name The name of the property. * @param value The value of the property. */ - void - setProperty(const std::string &name, const std::string &value) + void setProperty(const std::string &name, const std::string &value) { mProperties[name] = value; } diff --git a/src/resources/dye.cpp b/src/resources/dye.cpp index 3be105d8..d180d725 100644 --- a/src/resources/dye.cpp +++ b/src/resources/dye.cpp @@ -26,7 +26,7 @@ #include "../log.h" -Palette::Palette(std::string const &description) +Palette::Palette(const std::string &description) { int size = description.length(); if (size == 0) return; @@ -109,7 +109,7 @@ void Palette::getColor(int intensity, int color[3]) const color[2] = ((255 - t) * b1 + t * b2) / 255; } -Dye::Dye(std::string const &description) +Dye::Dye(const std::string &description) { for (int i = 0; i < 7; ++i) mPalettes[i] = 0; @@ -175,7 +175,7 @@ void Dye::update(int color[3]) const mPalettes[i - 1]->getColor(cmax, color); } -void Dye::instantiate(std::string &target, std::string const &palettes) +void Dye::instantiate(std::string &target, const std::string &palettes) { std::string::size_type next_pos = target.find('|'); if (next_pos == std::string::npos || palettes.empty()) return; diff --git a/src/resources/dye.h b/src/resources/dye.h index 528a1d91..f0bd7aab 100644 --- a/src/resources/dye.h +++ b/src/resources/dye.h @@ -36,7 +36,7 @@ class Palette * The string is either a file name or a sequence of hexadecimal RGB * values separated by ',' and starting with '#'. */ - Palette(std::string const &); + Palette(const std::string &); /** * Gets a pixel color depending on its intensity. @@ -63,7 +63,7 @@ class Dye * The parts of string are separated by semi-colons. Each part starts * by an uppercase letter, followed by a colon and then a palette name. */ - Dye(std::string const &); + Dye(const std::string &); /** * Destroys the associated palettes. @@ -79,7 +79,7 @@ class Dye * Fills the blank in a dye placeholder with some palette names. */ static void instantiate(std::string &target, - std::string const &palettes); + const std::string &palettes); private: diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index 29458ba3..835ba100 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -88,7 +88,7 @@ void ProxyImage::convertToDisplayFormat() mSDLImage = NULL; } -gcn::Image *ImageLoader::load(std::string const &filename, bool convert) +gcn::Image *ImageLoader::load(const std::string &filename, bool convert) { ResourceManager *resman = ResourceManager::getInstance(); ProxyImage *i = new ProxyImage(resman->loadSDLSurface(filename)); diff --git a/src/resources/imageloader.h b/src/resources/imageloader.h index 7979fd2f..821a0254 100644 --- a/src/resources/imageloader.h +++ b/src/resources/imageloader.h @@ -61,7 +61,8 @@ class ProxyImage : public gcn::Image class ImageLoader : public gcn::ImageLoader { public: - gcn::Image *load(std::string const &filename, bool convertToDisplayFormat); + gcn::Image *load(const std::string &filename, + bool convertToDisplayFormat); }; #endif diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index a1965d57..3d42d92e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -215,7 +215,7 @@ std::string ResourceManager::getPath(const std::string &file) return path; } -Resource *ResourceManager::get(std::string const &idPath, generator fun, +Resource *ResourceManager::get(const std::string &idPath, generator fun, void *data) { // Check if the id exists, and return the value if it does. @@ -267,7 +267,7 @@ struct ResourceLoader } }; -Resource *ResourceManager::load(std::string const &path, loader fun) +Resource *ResourceManager::load(const std::string &path, loader fun) { ResourceLoader l = { this, path, fun }; return get(path, ResourceLoader::load, &l); @@ -309,7 +309,7 @@ struct DyedImageLoader } }; -Image *ResourceManager::getImage(std::string const &idPath) +Image *ResourceManager::getImage(const std::string &idPath) { DyedImageLoader l = { this, idPath }; return static_cast(get(idPath, DyedImageLoader::load, &l)); @@ -351,8 +351,7 @@ struct SpriteDefLoader } }; -SpriteDef *ResourceManager::getSprite - (std::string const &path, int variant) +SpriteDef *ResourceManager::getSprite(const std::string &path, int variant) { SpriteDefLoader l = { path, variant }; std::stringstream ss; @@ -381,7 +380,8 @@ void ResourceManager::release(Resource *res) ResourceManager *ResourceManager::getInstance() { // Create a new instance if necessary. - if (instance == NULL) instance = new ResourceManager(); + if (!instance) + instance = new ResourceManager(); return instance; } diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index c1007f4a..e70dfb9d 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -98,7 +98,8 @@ class ResourceManager bool isDirectory(const std::string &path); /** - * Returns the real path to a file + * Returns the real path to a file. Note that this method will always + * return a path, it does not check whether the file exists. * * @param file The file to get the real path to. * @return The real path. @@ -114,7 +115,7 @@ class ResourceManager * @return A valid resource or NULL if the resource could * not be generated. */ - Resource *get(std::string const &idPath, generator fun, void *data); + Resource *get(const std::string &idPath, generator fun, void *data); /** * Loads a resource from a file and adds it to the resource map. @@ -124,7 +125,7 @@ class ResourceManager * @return A valid resource or NULL if the resource could * not be loaded. */ - Resource *load(std::string const &path, loader fun); + Resource *load(const std::string &path, loader fun); /** * Convenience wrapper around ResourceManager::get for loading @@ -154,7 +155,7 @@ class ResourceManager * Creates a sprite definition based on a given path and the supplied * variant. */ - SpriteDef *getSprite(std::string const &path, int variant = 0); + SpriteDef *getSprite(const std::string &path, int variant = 0); /** * Releases a resource, placing it in the set of orphaned resources. diff --git a/src/resources/spritedef.cpp b/src/resources/spritedef.cpp index 3eb1d92b..28db0452 100644 --- a/src/resources/spritedef.cpp +++ b/src/resources/spritedef.cpp @@ -46,7 +46,7 @@ Action *SpriteDef::getAction(SpriteAction action) const return i->second; } -SpriteDef *SpriteDef::load(std::string const &animationFile, int variant) +SpriteDef *SpriteDef::load(const std::string &animationFile, int variant) { std::string::size_type pos = animationFile.find('|'); std::string palettes; @@ -121,7 +121,7 @@ void SpriteDef::loadSprite(xmlNodePtr spriteNode, int variant, } } -void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes) +void SpriteDef::loadImageSet(xmlNodePtr node, const std::string &palettes) { const std::string name = XML::getProperty(node, "name", ""); @@ -146,8 +146,7 @@ void SpriteDef::loadImageSet(xmlNodePtr node, std::string const &palettes) mImageSets[name] = imageSet; } -void -SpriteDef::loadAction(xmlNodePtr node, int variant_offset) +void SpriteDef::loadAction(xmlNodePtr node, int variant_offset) { const std::string actionName = XML::getProperty(node, "name", ""); const std::string imageSetName = XML::getProperty(node, "imageset", ""); @@ -187,10 +186,9 @@ SpriteDef::loadAction(xmlNodePtr node, int variant_offset) } } -void -SpriteDef::loadAnimation(xmlNodePtr animationNode, - Action *action, ImageSet *imageSet, - int variant_offset) +void SpriteDef::loadAnimation(xmlNodePtr animationNode, + Action *action, ImageSet *imageSet, + int variant_offset) { const std::string directionName = XML::getProperty(animationNode, "direction", ""); @@ -267,8 +265,7 @@ SpriteDef::loadAnimation(xmlNodePtr animationNode, } // for frameNode } -void -SpriteDef::includeSprite(xmlNodePtr includeNode) +void SpriteDef::includeSprite(xmlNodePtr includeNode) { // TODO: Perform circular dependency check, since it's easy to crash the // client this way. @@ -289,8 +286,7 @@ SpriteDef::includeSprite(xmlNodePtr includeNode) loadSprite(rootNode, 0); } -void -SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) +void SpriteDef::substituteAction(SpriteAction complete, SpriteAction with) { if (mActions.find(complete) == mActions.end()) { @@ -324,8 +320,7 @@ SpriteDef::~SpriteDef() } } -SpriteAction -SpriteDef::makeSpriteAction(const std::string& action) +SpriteAction SpriteDef::makeSpriteAction(const std::string &action) { if (action == "" || action == "default") { return ACTION_DEFAULT; @@ -377,8 +372,7 @@ SpriteDef::makeSpriteAction(const std::string& action) } } -SpriteDirection -SpriteDef::makeSpriteDirection(const std::string& direction) +SpriteDirection SpriteDef::makeSpriteDirection(const std::string& direction) { if (direction == "" || direction == "default") { return DIRECTION_DEFAULT; @@ -397,5 +391,5 @@ SpriteDef::makeSpriteDirection(const std::string& direction) } else { return DIRECTION_INVALID; - }; + } } diff --git a/src/resources/spritedef.h b/src/resources/spritedef.h index 88f9b7b7..49a4ca51 100644 --- a/src/resources/spritedef.h +++ b/src/resources/spritedef.h @@ -71,7 +71,7 @@ class SpriteDef : public Resource /** * Loads a sprite definition file. */ - static SpriteDef *load(std::string const &file, int variant); + static SpriteDef *load(const std::string &file, int variant); /** * Returns the specified action. @@ -81,8 +81,7 @@ class SpriteDef : public Resource /** * Converts a string into a SpriteAction enum. */ - static SpriteAction - makeSpriteAction(const std::string &action); + static SpriteAction makeSpriteAction(const std::string &action); /** * Converts a string into a SpriteDirection enum. @@ -111,27 +110,24 @@ class SpriteDef : public Resource /** * Loads an imageset element. */ - void loadImageSet(xmlNodePtr node, std::string const &palettes); + void loadImageSet(xmlNodePtr node, const std::string &palettes); /** * Loads an action element. */ - void - loadAction(xmlNodePtr node, int variant_offset); + void loadAction(xmlNodePtr node, int variant_offset); /** * Loads an animation element. */ - void - loadAnimation(xmlNodePtr animationNode, - Action *action, ImageSet *imageSet, - int variant_offset); + void loadAnimation(xmlNodePtr animationNode, + Action *action, ImageSet *imageSet, + int variant_offset); /** * Include another sprite into this one. */ - void - includeSprite(xmlNodePtr includeNode); + void includeSprite(xmlNodePtr includeNode); /** * Complete missing actions by copying existing ones. @@ -142,8 +138,7 @@ class SpriteDef : public Resource * When there are no animations defined for the action "complete", its * animations become a copy of those of the action "with". */ - void - substituteAction(SpriteAction complete, SpriteAction with); + void substituteAction(SpriteAction complete, SpriteAction with); typedef std::map ImageSets; -- cgit v1.2.3-70-g09d2 From 5cffb54e48034b0bc7bce2ae9a61ce4a24464e63 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 4 Jan 2009 13:17:38 +0100 Subject: Fixed installing of dejavusans.ttf font. (cherry picked from mainline commit 8d1299338e033e1de539dae36856e365855fabc1) Conflicts: src/gui/gui.cpp --- configure.ac | 1 + data/Makefile.am | 2 +- data/fonts/Makefile.am | 5 +++++ src/gui/gui.cpp | 6 ++++-- 4 files changed, 11 insertions(+), 3 deletions(-) create mode 100644 data/fonts/Makefile.am (limited to 'src') diff --git a/configure.ac b/configure.ac index 556f6beb..791a84c5 100755 --- a/configure.ac +++ b/configure.ac @@ -106,6 +106,7 @@ AC_CONFIG_FILES([ Makefile src/Makefile data/Makefile +data/fonts/Makefile data/graphics/Makefile data/graphics/gui/Makefile data/graphics/images/Makefile diff --git a/data/Makefile.am b/data/Makefile.am index 5a28f7c1..62672207 100644 --- a/data/Makefile.am +++ b/data/Makefile.am @@ -1,4 +1,4 @@ -SUBDIRS = graphics help icons +SUBDIRS = fonts graphics help icons tmwdatadir = $(pkgdatadir)/data diff --git a/data/fonts/Makefile.am b/data/fonts/Makefile.am new file mode 100644 index 00000000..331f6c8b --- /dev/null +++ b/data/fonts/Makefile.am @@ -0,0 +1,5 @@ +fontsdir = $(pkgdatadir)/data/fonts + +fonts_DATA = dejavusans.ttf + +EXTRA_DIST = $(fonts_DATA) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 4052951f..61da1a0c 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -106,9 +106,11 @@ Gui::Gui(Graphics *graphics): Window::setWindowContainer(guiTop); setTop(guiTop); - // Set global font (based on ISO-8859-15) + // Set global font + ResourceManager *resman = ResourceManager::getInstance(); + std::string path = resman->getPath("fonts/dejavusans.ttf"); try { - mGuiFont = new TrueTypeFont("data/fonts/dejavusans.ttf", 11); + mGuiFont = new TrueTypeFont(path, 11); } catch (gcn::Exception e) { -- cgit v1.2.3-70-g09d2 From 0de4d5397f431d1fb1501230b9b69095642ce9ce Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 4 Jan 2009 13:31:19 +0100 Subject: Fixed rendering of special characters The font was interpreting the strings as UTF8, as they are in the mainline client. But in the eAthena client they are regular text. --- src/gui/truetypefont.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 0eed6f08..9343c224 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -55,7 +55,7 @@ class TextChunk sdlCol.r = color.r; sdlCol.g = color.g; - SDL_Surface *surface = TTF_RenderUTF8_Blended( + SDL_Surface *surface = TTF_RenderText_Blended( font, text.c_str(), sdlCol); if (!surface) @@ -167,7 +167,7 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, int TrueTypeFont::getWidth(const std::string &text) const { int w, h; - TTF_SizeUTF8(mFont, text.c_str(), &w, &h); + TTF_SizeText(mFont, text.c_str(), &w, &h); return w; } -- cgit v1.2.3-70-g09d2 From 81ca2120284ac7fd84e22ee61545b2b789f982e7 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 4 Jan 2009 23:51:48 +0100 Subject: Merged Vector class improvements from mainline --- src/CMakeLists.txt | 1 + src/Makefile.am | 1 + src/vector.cpp | 28 ++++++++++++++++++++++ src/vector.h | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++---- 4 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 src/vector.cpp (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 130452c6..94d25cc5 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -340,6 +340,7 @@ SET(SRCS textparticle.cpp textparticle.h tileset.h + vector.cpp vector.h ) diff --git a/src/Makefile.am b/src/Makefile.am index 1f23e328..d8aa5443 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -301,6 +301,7 @@ tmw_SOURCES = gui/widgets/resizegrip.cpp \ textparticle.cpp \ textparticle.h \ tileset.h \ + vector.cpp \ vector.h # set the include path found by configure diff --git a/src/vector.cpp b/src/vector.cpp new file mode 100644 index 00000000..7d5f055a --- /dev/null +++ b/src/vector.cpp @@ -0,0 +1,28 @@ +/* + * The Mana World + * Copyright 2007 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 + */ + +#include "vector.h" + +std::ostream& operator <<(std::ostream &os, const Vector &v) +{ + os << "Vector(" << v.x << ", " << v.y << ", " << v.z << ")"; + return os; +} diff --git a/src/vector.h b/src/vector.h index b19f6c64..f32b201a 100644 --- a/src/vector.h +++ b/src/vector.h @@ -22,6 +22,10 @@ #ifndef _TMW_VECTOR_H_ #define _TMW_VECTOR_H_ +#include + +#include + /** * Vector class. Represents either a 3D point in space, a velocity or a force. * Provides several convenient operator overloads. @@ -41,7 +45,7 @@ class Vector /** * Constructor. */ - Vector(float x, float y, float z): + Vector(float x, float y, float z = 0.0f): x(x), y(y), z(z) @@ -69,11 +73,12 @@ class Vector /** * In-place scale vector operator. */ - void operator*=(float c) + Vector &operator*=(float c) { x *= c; y *= c; z *= c; + return *this; } /** @@ -86,6 +91,17 @@ class Vector z / c); } + /** + * In-place scale vector operator. + */ + Vector &operator/=(float c) + { + x /= c; + y /= c; + z /= c; + return *this; + } + /** * Add vector operator. */ @@ -99,11 +115,12 @@ class Vector /** * In-place add vector operator. */ - void operator+=(const Vector &v) + Vector &operator+=(const Vector &v) { x += v.x; y += v.y; z += v.z; + return *this; } /** @@ -119,14 +136,55 @@ class Vector /** * In-place substract vector operator. */ - void operator-=(const Vector &v) + Vector &operator-=(const Vector &v) { x -= v.x; y -= v.y; z -= v.z; + return *this; + } + + /** + * Returns the length of this vector. This method does a relatively + * slow square root. + */ + float length() const + { + return sqrtf(x * x + y * y + z * z); + } + + /** + * Returns the squared length of this vector. Avoids the square root. + */ + float squaredLength() const + { + return x * x + y * y + z * z; + } + + /** + * Returns the manhattan length of this vector. + */ + float manhattanLength() const + { + return fabsf(x) + fabsf(y) + fabsf(z); + } + + /** + * Returns a normalized version of this vector. This is a unit vector + * running parallel to it. + */ + Vector normalized() const + { + const float l = length(); + return Vector(x / l, y / l, z / l); } float x, y, z; }; -#endif +/** + * Appends a string representation of a vector to the output stream. + */ +std::ostream& operator <<(std::ostream &os, const Vector &v); + +#endif // _TMW_VECTOR_H_ -- cgit v1.2.3-70-g09d2 From 12d4837d4d8bb6cbb5d4cd4199bb77b76108fa51 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Mon, 5 Jan 2009 00:15:27 +0100 Subject: Renamed PATH_NODE to Position as on mainline --- src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/being.cpp | 16 +++++++-------- src/being.h | 24 ++-------------------- src/map.cpp | 2 +- src/map.h | 20 +++++++++---------- src/position.cpp | 45 ++++++++++++++++++++++++++++++++++++++++++ src/position.h | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 127 insertions(+), 42 deletions(-) create mode 100644 src/position.cpp create mode 100644 src/position.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 94d25cc5..61fc77e8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -328,6 +328,8 @@ SET(SRCS player.h player_relations.cpp player_relations.h + position.cpp + position.h properties.h serverinfo.h shopitem.cpp diff --git a/src/Makefile.am b/src/Makefile.am index d8aa5443..4ef07773 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -283,6 +283,8 @@ tmw_SOURCES = gui/widgets/resizegrip.cpp \ player.h \ player_relations.cpp \ player_relations.h \ + position.cpp \ + position.h \ properties.h \ serverinfo.h \ shopitem.cpp \ diff --git a/src/being.cpp b/src/being.cpp index 88063ac1..f9c6296c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -322,29 +322,29 @@ void Being::nextStep() return; } - PATH_NODE node = mPath.front(); + Position pos = mPath.front(); mPath.pop_front(); int dir = 0; - if (node.x > mX) + if (pos.x > mX) dir |= RIGHT; - else if (node.x < mX) + else if (pos.x < mX) dir |= LEFT; - if (node.y > mY) + if (pos.y > mY) dir |= DOWN; - else if (node.y < mY) + else if (pos.y < mY) dir |= UP; setDirection(dir); - if (mMap->tileCollides(node.x, node.y)) + if (mMap->tileCollides(pos.x, pos.y)) { setAction(STAND); return; } - mX = node.x; - mY = node.y; + mX = pos.x; + mY = pos.y; setAction(WALK); mWalkTime += mWalkSpeed / 10; } diff --git a/src/being.h b/src/being.h index f48ebae2..6319bd47 100644 --- a/src/being.h +++ b/src/being.h @@ -28,6 +28,7 @@ #include #include +#include "position.h" #include "sprite.h" #include "map.h" #include "animatedsprite.h" @@ -49,24 +50,6 @@ class Text; class StatusEffect; -/** - * A position along a being's path. - */ -struct PATH_NODE -{ - /** - * Constructor. - */ - PATH_NODE(unsigned short x, unsigned short y): - x(x), y(y) - { } - - unsigned short x; - unsigned short y; -}; -typedef std::list Path; -typedef Path::iterator PathIterator; - class Being : public Sprite { public: @@ -115,10 +98,7 @@ class Being : public Sprite /** * Directions, to be used as bitmask values */ - static const char DOWN = 1; - static const char LEFT = 2; - static const char UP = 4; - static const char RIGHT = 8; + enum { DOWN = 1, LEFT = 2, UP = 4, RIGHT = 8 }; Uint16 mJob; /**< Job (player job, npc, monster, ) */ Uint16 mX, mY; /**< Tile coordinates */ diff --git a/src/map.cpp b/src/map.cpp index 6e33d255..6170adef 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -485,7 +485,7 @@ Path Map::findPath(int startX, int startY, int destX, int destY) while (pathX != startX || pathY != startY) { // Add the new path node to the start of the path list - path.push_front(PATH_NODE(pathX, pathY)); + path.push_front(Position(pathX, pathY)); // Find out the next parent MetaTile *tile = getMetaTile(pathX, pathY); diff --git a/src/map.h b/src/map.h index 6eaf9e43..56183abf 100644 --- a/src/map.h +++ b/src/map.h @@ -25,6 +25,7 @@ #include #include +#include "position.h" #include "properties.h" class AmbientOverlay; @@ -35,8 +36,6 @@ class Particle; class Sprite; class Tileset; -struct PATH_NODE; - typedef std::vector Tilesets; typedef std::list Sprites; typedef Sprites::iterator SpriteIterator; @@ -55,13 +54,13 @@ struct MetaTile MetaTile():whichList(0) {}; // Pathfinding members - int Fcost; /**< Estimation of total path cost */ - int Gcost; /**< Cost from start to this location */ - int Hcost; /**< Estimated cost to goal */ - int whichList; /**< No list, open list or closed list */ - int parentX; /**< X coordinate of parent tile */ - int parentY; /**< Y coordinate of parent tile */ - bool walkable; /**< Can beings walk on this tile */ + int Fcost; /**< Estimation of total path cost */ + int Gcost; /**< Cost from start to this location */ + int Hcost; /**< Estimated cost to goal */ + int whichList; /**< No list, open list or closed list */ + int parentX; /**< X coordinate of parent tile */ + int parentY; /**< Y coordinate of parent tile */ + bool walkable; /**< Can beings walk on this tile */ }; /** @@ -204,8 +203,7 @@ class Map : public Properties /** * Find a path from one location to the next. */ - std::list - findPath(int startX, int startY, int destX, int destY); + Path findPath(int startX, int startY, int destX, int destY); /** * Adds a sprite to the map. diff --git a/src/position.cpp b/src/position.cpp new file mode 100644 index 00000000..cc39a1af --- /dev/null +++ b/src/position.cpp @@ -0,0 +1,45 @@ +/* + * The Mana World + * Copyright 2007 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 + */ + +#include "position.h" + +std::ostream& operator <<(std::ostream &os, const Position &p) +{ + os << "(" << p.x << ", " << p.y << ")"; + return os; +} + +std::ostream& operator <<(std::ostream &os, const Path &path) +{ + Path::const_iterator i = path.begin(); + + os << "("; + while (i != path.end()) + { + os << *i; + ++i; + if (i != path.end()) + os << ", "; + } + os << ")"; + + return os; +} diff --git a/src/position.h b/src/position.h new file mode 100644 index 00000000..7beb3ef7 --- /dev/null +++ b/src/position.h @@ -0,0 +1,58 @@ +/* + * The Mana World + * Copyright 2008 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 + */ + +#ifndef TMW_POSITION_H +#define TMW_POSITION_H + +#include +#include + +/** + * A position along a being's path. + */ +struct Position +{ + /** + * Constructor. + */ + Position(int x, int y): + x(x), y(y) + { } + + int x; + int y; +}; + +typedef std::list Path; +typedef Path::iterator PathIterator; + +/** + * Appends a string representation of a position to the output stream. + */ +std::ostream& operator <<(std::ostream &os, const Position &p); + +/** + * Appends a string representation of a path (sequence of positions) to the + * output stream. + */ +std::ostream& operator <<(std::ostream &os, const Path &path); + +#endif // TMW_POSITION_H -- cgit v1.2.3-70-g09d2 From 615b1bc6080a3418b18fd4ab93b4212470709731 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Fri, 22 Feb 2008 19:58:29 +0000 Subject: Handling gender with an enum everywhere. (cherry picked from mainline commit d3adc61aa4b4924f82d8cbc23bea26da7257da97) Conflicts: src/net/beinghandler.cpp src/net/charserverhandler.cpp src/player.cpp src/player.h --- src/being.cpp | 7 ++++--- src/being.h | 13 +++++++++---- src/gui/char_select.cpp | 4 ++-- src/gui/char_select.h | 7 ++++--- src/main.cpp | 10 +++++----- src/net/beinghandler.cpp | 6 ++++-- src/net/charserverhandler.cpp | 5 +++-- src/player.cpp | 20 ++++++-------------- src/player.h | 2 +- src/resources/itemdb.cpp | 8 ++++---- src/resources/iteminfo.cpp | 2 +- src/resources/iteminfo.h | 6 ++++-- 12 files changed, 47 insertions(+), 43 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index f9c6296c..c04aeaa9 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -70,7 +70,7 @@ Being::Being(int id, int job, Map *map): mMap(NULL), mEquippedWeapon(NULL), mHairStyle(1), mHairColor(0), - mGender(2), + mGender(GENDER_UNSPECIFIED), mSpeechTime(0), mPx(0), mPy(0), mStunMode(0), @@ -669,9 +669,10 @@ static void initializeHair() if (hairInitialized) return; - // Hairstyles are encoded as negative numbers. Count how far negative we can go. + // Hairstyles are encoded as negative numbers. Count how far negative we + // can go. int hairstylesCtr = -1; - while (ItemDB::get(hairstylesCtr).getSprite(0) != "error.xml") + while (ItemDB::get(hairstylesCtr).getSprite(GENDER_MALE) != "error.xml") --hairstylesCtr; hairStylesNr = -hairstylesCtr; // done. diff --git a/src/being.h b/src/being.h index 6319bd47..e70cdd09 100644 --- a/src/being.h +++ b/src/being.h @@ -47,9 +47,14 @@ class ImageSet; class Particle; class Text; - class StatusEffect; +enum Gender { + GENDER_MALE = 0, + GENDER_FEMALE = 1, + GENDER_UNSPECIFIED = 2 +}; + class Being : public Sprite { public: @@ -193,12 +198,12 @@ class Being : public Sprite /** * Sets the gender of this being. */ - virtual void setGender(int gender) { mGender = gender; } + virtual void setGender(Gender gender) { mGender = gender; } /** * Gets the gender of this being. */ - int getGender() const { return mGender; } + Gender getGender() const { return mGender; } /** * Makes this being take the next step of his path. @@ -418,7 +423,7 @@ class Being : public Sprite Path mPath; Text *mSpeech; Uint16 mHairStyle, mHairColor; - Uint8 mGender; + Gender mGender; Uint32 mSpeechTime; Sint32 mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index d951f12e..7c067eef 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -74,7 +74,7 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event) CharSelectDialog::CharSelectDialog(Network *network, LockedArray *charInfo, - unsigned char gender): + Gender gender): Window("Select Character"), mNetwork(network), mCharInfo(charInfo), mGender(gender), mCharSelected(false) { @@ -249,7 +249,7 @@ bool CharSelectDialog::selectByName(const std::string &name) } CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char gender): + Gender gender): Window("Create Character", true, parent), mNetwork(network), mSlot(slot) { mPlayer = new Player(0, 0, NULL); diff --git a/src/gui/char_select.h b/src/gui/char_select.h index 0890bea9..22c247b6 100644 --- a/src/gui/char_select.h +++ b/src/gui/char_select.h @@ -26,6 +26,7 @@ #include "../guichanfwd.h" #include "../lockedarray.h" +#include "../being.h" #include @@ -48,7 +49,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener */ CharSelectDialog(Network *network, LockedArray *charInfo, - unsigned char gender); + Gender gender); void action(const gcn::ActionEvent &event); @@ -76,7 +77,7 @@ class CharSelectDialog : public Window, public gcn::ActionListener PlayerBox *mPlayerBox; - unsigned char mGender; + Gender mGender; bool mCharSelected; /** @@ -102,7 +103,7 @@ class CharCreateDialog : public Window, public gcn::ActionListener * Constructor. */ CharCreateDialog(Window *parent, int slot, Network *network, - unsigned char gender); + Gender gender); /** * Destructor. diff --git a/src/main.cpp b/src/main.cpp index d99c1985..83686749 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -34,6 +34,9 @@ #include +#ifdef WIN32 +#include +#endif #ifndef WIN32 #include #include @@ -83,10 +86,6 @@ #include "utils/dtor.h" #include "utils/tostring.h" -#ifdef WIN32 -#include -#endif - namespace { Window *setupWindow = 0; @@ -874,7 +873,8 @@ int main(int argc, char *argv[]) case CHAR_SELECT_STATE: logger->log("State: CHAR_SELECT"); currentDialog = new CharSelectDialog(network, &charInfo, - 1 - loginData.sex); + (loginData.sex == 0) ? + GENDER_FEMALE : GENDER_MALE); if (((CharSelectDialog*) currentDialog)-> selectByName(options.playername)) diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 9d91d988..c8d12499 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -141,7 +141,8 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt16(); // manner dstBeing->setStatusEffectBlock(32, msg->readInt16()); // opt3 msg->readInt8(); // karma - dstBeing->setGender(1 - msg->readInt8()); // gender + dstBeing->setGender( + (msg->readInt8() == 0) ? GENDER_FEMALE : GENDER_MALE); // Set these after the gender, as the sprites may be gender-specific dstBeing->setSprite(Being::BOTTOMCLOTHES_SPRITE, headBottom); @@ -420,7 +421,8 @@ void BeingHandler::handleMessage(MessageIn *msg) msg->readInt16(); // manner dstBeing->setStatusEffectBlock(32, msg->readInt16()); // opt3 msg->readInt8(); // karma - dstBeing->setGender(1 - msg->readInt8()); // gender + dstBeing->setGender( + (msg->readInt8() == 0) ? GENDER_FEMALE : GENDER_MALE); // Set these after the gender, as the sprites may be gender-specific dstBeing->setSprite(Being::WEAPON_SPRITE, weapon); diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 249995ee..df3f5ecf 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -176,10 +176,11 @@ void CharServerHandler::handleMessage(MessageIn *msg) } } -LocalPlayer* CharServerHandler::readPlayerData(MessageIn &msg, int &slot) +LocalPlayer *CharServerHandler::readPlayerData(MessageIn &msg, int &slot) { LocalPlayer *tempPlayer = new LocalPlayer(mLoginData->account_ID, 0, NULL); - tempPlayer->setGender(1 - mLoginData->sex); + tempPlayer->setGender( + (mLoginData->sex == 0) ? GENDER_FEMALE : GENDER_MALE); tempPlayer->mCharId = msg.readInt32(); tempPlayer->setXp(msg.readInt32()); diff --git a/src/player.cpp b/src/player.cpp index f43e54d5..f81c039c 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -105,25 +105,17 @@ Player::flash(int time) } } -void Player::setGender(int gender) +void Player::setGender(Gender gender) { - // Players can only be male or female - if (gender > 1) - { - logger->log("Warning: unsupported gender %i, assuming male.", gender); - gender = 0; - } - - if (gender != mGender) { Being::setGender(gender); - setSprite(Being::BASE_SPRITE, -100); /* Human base sprite. When implementing - * different races remove this line - * and set the base sprite when setting - * the race of the player character. - */ + /* Human base sprite. When implementing different races remove this + * line and set the base sprite when setting the race of the player + * character. + */ + setSprite(Being::BASE_SPRITE, -100); // Reload all subsprites for (int i = 1; i < VECTOREND_SPRITE; i++) diff --git a/src/player.h b/src/player.h index 4676124c..268c77bb 100644 --- a/src/player.h +++ b/src/player.h @@ -53,7 +53,7 @@ class Player : public Being getType() const; virtual void - setGender(int gender); + setGender(Gender gender); /** * Sets the hair style and color for this player. diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index c05d4604..8fd60110 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -53,8 +53,8 @@ void ItemDB::load() mUnknown = new ItemInfo(); mUnknown->setName("Unknown item"); mUnknown->setImageName(""); - mUnknown->setSprite("error.xml", 0); - mUnknown->setSprite("error.xml", 1); + mUnknown->setSprite("error.xml", GENDER_MALE); + mUnknown->setSprite("error.xml", GENDER_FEMALE); XML::Document doc("items.xml"); xmlNodePtr rootNode = doc.rootNode(); @@ -172,12 +172,12 @@ void loadSpriteRef(ItemInfo *itemInfo, xmlNodePtr node) if (gender == "male" || gender == "unisex") { - itemInfo->setSprite(filename, 0); + itemInfo->setSprite(filename, GENDER_MALE); } if (gender == "female" || gender == "unisex") { - itemInfo->setSprite(filename, 1); + itemInfo->setSprite(filename, GENDER_FEMALE); } } diff --git a/src/resources/iteminfo.cpp b/src/resources/iteminfo.cpp index fb2c8ffe..201b8ca9 100644 --- a/src/resources/iteminfo.cpp +++ b/src/resources/iteminfo.cpp @@ -24,7 +24,7 @@ #include "itemdb.h" const std::string& -ItemInfo::getSprite(int gender) const +ItemInfo::getSprite(Gender gender) const { if (mView) { diff --git a/src/resources/iteminfo.h b/src/resources/iteminfo.h index 4678bc08..b7729d2c 100644 --- a/src/resources/iteminfo.h +++ b/src/resources/iteminfo.h @@ -28,6 +28,8 @@ #include "spritedef.h" +#include "../being.h" + enum EquipmentSoundEvent { EQUIP_EVENT_STRIKE, @@ -91,10 +93,10 @@ class ItemInfo void setView(int view) { mView = view; } - void setSprite(const std::string &animationFile, int gender) + void setSprite(const std::string &animationFile, Gender gender) { mAnimationFiles[gender] = animationFile; } - const std::string& getSprite(int gender) const; + const std::string& getSprite(Gender gender) const; void setWeaponType(int); -- cgit v1.2.3-70-g09d2 From 4e439b3115c487dc67dbe2cd5aaab1e15f3d09e8 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Fri, 21 Sep 2007 03:58:07 +0000 Subject: Refactor the way in which browser box text is drawn and wrapped. (cherry picked from mainline commit ecabe82d8720689905a6d035b0597d97037287c7) Conflicts: src/gui/browserbox.cpp --- src/gui/browserbox.cpp | 139 ++++++++++++++++++++++++++----------------------- 1 file changed, 74 insertions(+), 65 deletions(-) (limited to 'src') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 3e446928..80e41fc2 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -21,11 +21,8 @@ #include -#include -#include -#include - #include "browserbox.h" + #include "linkhandler.h" #include "truetypefont.h" @@ -143,7 +140,7 @@ void BrowserBox::addRow(const std::string &row) if (mMode == AUTO_WRAP) { - unsigned int j, y = 0; + unsigned int y = 0; unsigned int nextChar; const char *hyphen = "~"; int hyphenWidth = font->getWidth(hyphen); @@ -152,7 +149,7 @@ void BrowserBox::addRow(const std::string &row) for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++) { std::string row = *i; - for (j = 0; j < row.size(); j++) + for (unsigned int j = 0; j < row.size(); j++) { std::string character = row.substr(j, 1); x += font->getWidth(character); @@ -266,7 +263,6 @@ BrowserBox::draw(gcn::Graphics *graphics) } } - unsigned int j; int x = 0, y = 0; int wrappedLines = 0; TrueTypeFont *font = static_cast(getFont()); @@ -277,17 +273,45 @@ BrowserBox::draw(gcn::Graphics *graphics) int selColor = BLACK; int prevColor = selColor; std::string row = *(i); + bool wrapped = false; x = 0; - for (j = 0; j < row.size(); j++) + // Check for separator lines + if (row.find("---", 0) == 0) + { + for (x = 0; x < getWidth(); x++) + { + font->drawString(graphics, "-", x, y); + x += font->getWidth("-") - 2; + } + y += font->getHeight(); + continue; + } + + // TODO: Check if we must take texture size limits into account here + // TODO: Check if some of the O(n) calls can be removed + for (std::string::size_type start = 0, end = std::string::npos; + start != std::string::npos; + start = end, end = std::string::npos) { - if ( (mUseLinksAndUserColors && (j + 3) <= row.size()) || - (!mUseLinksAndUserColors && (j == 0)) ) + // Wrapped line continuation shall be indented + if (wrapped) + { + y += font->getHeight(); + x = 15; + } + + // "Tokenize" the string at control sequences + if (mUseLinksAndUserColors) + end = row.find("##", start + 1); + + if (mUseLinksAndUserColors || + (!mUseLinksAndUserColors && (start == 0))) { // Check for color change in format "##x", x = [L,P,0..9] - if ((row.at(j) == '#') && (row.at(j + 1) == '#')) + if (row.find("##", start) == start && row.size() > start + 2) { - switch (row.at(j + 2)) + switch (row.at(start + 2)) { case 'L': // Link color prevColor = selColor; @@ -337,72 +361,57 @@ BrowserBox::draw(gcn::Graphics *graphics) prevColor = selColor; selColor = BLACK; } - j += 3; - - if (j == row.size()) - { - break; - } + start += 3; } graphics->setColor(gcn::Color(selColor)); } - // Check for line separators in format "---" - if (row == "---") - { - for (x = 0; x < getWidth(); x++) - { - font->drawString(graphics, "-", x, y); - x += font->getWidth("-") - 2; - } - break; - } - // Draw each char - else + std::string::size_type len = + end == std::string::npos ? end : end - start; + std::string part = row.substr(start, len); + + // Auto wrap mode + if (mMode == AUTO_WRAP && + (x + font->getWidth(part.c_str()) + 10) > getWidth()) { - std::string character = row.substr(j, 1); - font->drawString(graphics, character, x, y); - x += font->getWidth(character.c_str()); + bool forced = false; + char const *hyphen = "~"; + int hyphenWidth = font->getWidth(hyphen); - // Auto wrap mode - if (mMode == AUTO_WRAP) + do { - unsigned int nextChar = j + 1; - const char *hyphen = "~"; - int hyphenWidth = font->getWidth(hyphen); + if (!forced) + end = row.rfind(" ", end); - // Wraping between words (at blank spaces) - if ((nextChar < row.size()) && (row.at(nextChar) == ' ')) + // Check if we have to (stupidly) force-wrap + if (end == std::string::npos || end <= start) { - int nextSpacePos = row.find(" ", (nextChar + 1)); - if (nextSpacePos <= 0) - { - nextSpacePos = row.size() - 1; - } - int nextWordWidth = font->getWidth( - row.substr(nextChar, - (nextSpacePos - nextChar))); - - if ((x + nextWordWidth + 10) > getWidth()) - { - x = 15; // Ident in new line - y += font->getHeight(); - wrappedLines++; - j++; - } + forced = true; + end = row.size(); + x += hyphenWidth * 2; // Account for the wrap-notifier + continue; } - // Wrapping looong lines (brutal force) - else if ((x + 2 * hyphenWidth) > getWidth()) - { - font->drawString(graphics, hyphen, - getWidth() - hyphenWidth, y); - x = 15; // Ident in new line - y += font->getHeight(); - wrappedLines++; - } + end--; + + part = row.substr(start, end - start + 1); + } while ((x + font->getWidth(part.c_str()) + 10) > getWidth()); + + if (forced) + { + x -= hyphenWidth; // Remove the wrap-notifier accounting + font->drawString(graphics, hyphen, + getWidth() - hyphenWidth, y); + end++; // Skip to the next character } + else + end += 2; // Skip to after the space + + wrapped = true; + wrappedLines++; } + font->drawString(graphics, part, x, y); + x += font->getWidth(part.c_str()); } y += font->getHeight(); setHeight((mTextRows.size() + wrappedLines) * font->getHeight()); -- cgit v1.2.3-70-g09d2 From ce0d7b62824d620ec8c3daceac5710fbbd6b12f1 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Wed, 2 Aug 2006 12:41:35 +0000 Subject: Cleaned autotools files Put object files in subdirectories. Moved compilation flags to configure script. Added library header checks. (cherry picked from mainline commit 0bebbc320d50178a7ece573319cd6687a950dafa) --- configure.ac | 68 ++++++++++++++++++++++++++++++--------------------------- src/Makefile.am | 8 ++----- 2 files changed, 38 insertions(+), 38 deletions(-) (limited to 'src') diff --git a/configure.ac b/configure.ac index 791a84c5..c95d3006 100755 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,6 @@ AC_PREREQ(2.59) AC_INIT([The Mana World], [0.0.27], [themanaworld-devel@lists.sourceforge.net], [tmw]) +AM_INIT_AUTOMAKE AC_CONFIG_HEADERS([config.h:config.h.in]) AC_LANG_CPLUSPLUS @@ -22,31 +23,54 @@ AC_FUNC_SELECT_ARGTYPES AC_FUNC_VPRINTF AC_CHECK_FUNCS([atexit floor getcwd gethostbyname memset mkdir select socket]) +# Search for *-config +AC_PATH_PROG(SDL_CONFIG, sdl-config) +AC_PATH_PROG(PKG_CONFIG, pkg-config) +AC_PATH_PROG(CURL_CONFIG, curl-config) + # Checks for libraries AC_CHECK_LIB([pthread], [pthread_create], , AC_MSG_ERROR([ *** Unable to find pthread library])) AC_CHECK_LIB([guichan], [gcnGuichanVersion], , -AC_MSG_ERROR([ *** Unable to find Guichan library (guichan.sf.net)])) +AC_MSG_ERROR([ *** Unable to find Guichan library (http://guichan.sf.net/)])) +AC_CHECK_HEADERS([guichan.hpp], , +AC_MSG_ERROR([ *** Guichan library found but cannot find headers (http://guichan.sf.net/)])) -#AC_CHECK_LIB([guichan_sdl], [gcnSDL], , -#AC_MSG_ERROR([ *** Unable to find Guichan SDL library (guichan.sf.net)])) +if test -n "$SDL_CONFIG"; then + LIBS="$LIBS `$SDL_CONFIG --libs`" + CPPFLAGS="$CPPFLAGS `$SDL_CONFIG --cflags`" +fi +AC_CHECK_LIB([SDL], [SDL_Init], , +AC_MSG_ERROR([ *** Unable to find SDL library (http://www.libsdl.org/)])) +AC_CHECK_HEADERS([SDL.h], , +AC_MSG_ERROR([ *** SDL library found but cannot find headers (http://www.libsdl.org/)])) AC_CHECK_LIB([z], [inflate], , AC_MSG_ERROR([ *** Unable to find zlib (http://www.gzip.org/zlib/)])) AC_CHECK_LIB([physfs], [PHYSFS_init], , -AC_MSG_ERROR([ *** Unable to find PhysFS library (icculus.org/physfs/)])) +AC_MSG_ERROR([ *** Unable to find PhysFS library (http://icculus.org/physfs/)])) +AC_CHECK_HEADERS([physfs.h], , +AC_MSG_ERROR([ *** PhysFS library found but cannot find headers (http://icculus.org/physfs/)])) +if test -n "$CURL_CONFIG"; then + LIBS="$LIBS `$CURL_CONFIG --libs`" + CPPFLAGS="$CPPFLAGS `$CURL_CONFIG --cflags`" +fi AC_CHECK_LIB([curl], [curl_global_init], , AC_MSG_ERROR([ *** Unable to find CURL library (http://curl.haxx.se/)])) -CURL_LIBS=" `curl-config --libs`" -CURL_CFLAGS=" `curl-config --cflags` " -AC_SUBST(CURL_LIBS) -AC_SUBST(CURL_CFLAGS) +AC_CHECK_HEADERS([curl/curl.h], , +AC_MSG_ERROR([ *** CURL library found but cannot find headers (http://curl.haxx.se/)])) +if test -n "$PKG_CONFIG"; then + LIBS="$LIBS `$PKG_CONFIG --libs libxml-2.0`" + CPPFLAGS="$CPPFLAGS `$PKG_CONFIG --cflags libxml-2.0`" +fi AC_CHECK_LIB([xml2], [xmlInitParser], , -AC_MSG_ERROR([ *** Unable to find libxml2 library (xmlsoft.org)])) +AC_MSG_ERROR([ *** Unable to find libxml2 library (http://xmlsoft.org/)])) +AC_CHECK_HEADERS([libxml/xmlreader.h], , +AC_MSG_ERROR([ *** libxml2 library found but cannot find headers (http://xmlsoft.org/)])) AC_CHECK_LIB(png, png_write_info, , AC_MSG_ERROR([ *** Unable to find png library])) @@ -61,6 +85,9 @@ AC_MSG_ERROR([ *** Unable to find SDL_ttf library (http://www.libsdl.org/project AC_CHECK_LIB([SDL_mixer], [Mix_OpenAudio], , AC_MSG_ERROR([ *** Unable to find SDL_mixer library (http://www.libsdl.org/projects/SDL_mixer/)])) +AC_CHECK_LIB([guichan_sdl], [gcnSDL], , +AC_MSG_ERROR([ *** Unable to find Guichan SDL library (http://guichan.sf.net/)])) + AC_CHECK_LIB(SDL_net, SDLNet_Init, , AC_MSG_ERROR([ *** Unable to find SDL_net library])) @@ -68,12 +95,6 @@ AC_MSG_ERROR([ *** Unable to find SDL_net library])) AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h malloc.h netdb.h netinet/in.h stdlib.h string.h sys/socket.h unistd.h]) -# Check for guichan headers -AC_CHECK_HEADERS([guichan.hpp], , -AC_MSG_ERROR([*** Library found but cannot find headers (guichan.sf.net) *** ])) - -AM_INIT_AUTOMAKE - # Option to enable OpenGL AC_ARG_WITH(opengl,[ --without-opengl don't use OpenGL ] ) if test "x$with_opengl" == "xno"; then @@ -85,23 +106,6 @@ else AC_DEFINE(USE_OPENGL, 1, [Defines if tmw should use an OpenGL display]) fi -# Search for sdl-config -AC_PATH_PROG(LIBSDL_CONFIG, sdl-config) - -if test -n "$LIBSDL_CONFIG"; then - LIBSDL_LIBS="`$LIBSDL_CONFIG --libs` -lSDL_image -lSDL_mixer" - LIBSDL_CFLAGS="`$LIBSDL_CONFIG --cflags`" - AC_SUBST(LIBSDL_LIBS) - AC_SUBST(LIBSDL_CFLAGS) - - AC_DEFINE_UNQUOTED(HAVE_LIBSDL, 1, - [Defines if your system has the LIBSDL library]) -else - AC_DEFINE_UNQUOTED(HAVE_LIBSDL, 0, - [Defines if your system has the LIBSDL library]) - AC_MSG_ERROR([Could not find sdl-config, check http://www.libsdl.org]) -fi - AC_CONFIG_FILES([ Makefile src/Makefile diff --git a/src/Makefile.am b/src/Makefile.am index 4ef07773..7c547a11 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,3 +1,5 @@ +AUTOMAKE_OPTIONS = subdir-objects + bin_PROGRAMS = tmw tmw_SOURCES = gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ @@ -310,9 +312,3 @@ tmw_SOURCES = gui/widgets/resizegrip.cpp \ INCLUDES = \ $(all_includes) \ -DTMW_DATADIR=\""$(pkgdatadir)/"\" - -# the library search path. -tmw_LDFLAGS = $(all_libraries) $(LIBSDL_RPATH) `pkg-config --libs libxml-2.0` -tmw_CXXFLAGS = -Wall $(LIBSDL_CFLAGS) `pkg-config --cflags libxml-2.0` $(CURL_CFLAGS) -tmw_LDADD = $(LIBSDL_LIBS) -lguichan_sdl $(CURL_LIBS) -tmw_TARGET = tmw -- cgit v1.2.3-70-g09d2 From bfd1d1bcc2a6ecd7efe301bfbf22a1e9b9188706 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 6 Jan 2009 13:52:30 +0100 Subject: Added support for internationalization Merged from the mainline client. Originally implemented by Guillaume Melquiond, starting with commit 1828eee6a6d91fd385ad1e69d93044516493aa91. --- INSTALL | 5 +- Makefile.am | 5 +- configure.ac | 9 +- po/LINGUAS | 1 + po/Makevars | 41 ++++ po/POTFILES.in | 25 +++ po/tmw.pot | 486 ++++++++++++++++++++++++++++++++++++++++++++ src/CMakeLists.txt | 1 + src/Makefile.am | 4 +- src/graphics.cpp | 2 +- src/gui/buy.cpp | 34 ++-- src/gui/char_select.cpp | 63 +++--- src/gui/char_server.cpp | 8 +- src/gui/confirm_dialog.cpp | 5 +- src/gui/connection.cpp | 6 +- src/gui/equipmentwindow.cpp | 4 +- src/gui/inventorywindow.cpp | 51 ++--- src/gui/item_amount.cpp | 34 ++-- src/gui/login.cpp | 20 +- src/gui/menuwindow.cpp | 18 +- src/gui/minimap.cpp | 4 +- src/gui/npc_text.cpp | 6 +- src/gui/npclistdialog.cpp | 8 +- src/gui/ok_dialog.cpp | 4 +- src/gui/popupmenu.cpp | 29 +-- src/gui/register.cpp | 51 ++--- src/gui/sell.cpp | 41 ++-- src/gui/setup.cpp | 18 +- src/gui/setup_audio.cpp | 8 +- src/gui/setup_joystick.cpp | 18 +- src/gui/setup_video.cpp | 55 ++--- src/gui/trade.cpp | 43 ++-- src/main.cpp | 14 +- src/resources/itemdb.cpp | 5 +- src/utils/gettext.h | 44 ++++ 35 files changed, 913 insertions(+), 257 deletions(-) create mode 100644 po/LINGUAS create mode 100644 po/Makevars create mode 100644 po/POTFILES.in create mode 100644 po/tmw.pot create mode 100644 src/utils/gettext.h (limited to 'src') diff --git a/INSTALL b/INSTALL index cd530cae..d604895c 100644 --- a/INSTALL +++ b/INSTALL @@ -12,7 +12,7 @@ IRC: irc.freenode.net / #themanaworld 1. Requirements =============== -You are expected to have either checked out TMW from CVS or you have downloaded +You are expected to have either checked out TMW from Git or you have downloaded a source release. To get The Mana World to compile, you need a compiler (GCC) and some libraries. The required libraries are: @@ -20,6 +20,7 @@ and some libraries. The required libraries are: * SDL_mixer http://www.libsdl.org/projects/SDL_mixer/ * SDL_image http://www.libsdl.org/projects/SDL_image/ * SDL_net http://www.libsdl.org/projects/SDL_net/ +* SDL_ttf http://www.libsdl.org/projects/SDL_ttf/ * Guichan 0.8.x http://guichan.sourceforge.net/ * libxml2 http://www.xmlsoft.org/ * physfs 1.0.x http://icculus.org/physfs/ @@ -30,6 +31,8 @@ If you've cloned the Git repository, you will also need these tools to compile: * GNU automake 1.9 http://www.gnu.org/software/automake/ * GNU autoconf http://www.gnu.org/software/autoconf/ +* GNU gettext http://www.gnu.org/software/gettext/ +* CVS http://www.nongnu.org/cvs/ (needed to run autopoint) Installing these dependencies is distributions-specific, and we'll leave it to you to figure this out. diff --git a/Makefile.am b/Makefile.am index 7306c71f..2d7250cc 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,5 +1,5 @@ # Subdirectories to build -SUBDIRS = data docs src +SUBDIRS = data docs po src desktopdir = $(datadir)/applications @@ -7,3 +7,6 @@ desktop_DATA = tmw.desktop # Extra files to include EXTRA_DIST = $(desktop_DATA) + +# Autopoint m4 stuff +ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index c95d3006..8c1ce8a4 100755 --- a/configure.ac +++ b/configure.ac @@ -7,13 +7,9 @@ AC_LANG_CPLUSPLUS # Checks for programs. AC_PROG_CXX AC_PROG_INSTALL -AC_PROG_MAKE_SET # Checks for typedefs, structures, and compiler characteristics. -AC_HEADER_STDBOOL -AC_C_CONST AC_HEADER_TIME -AC_C_VOLATILE # Checks for library functions. AC_FUNC_ERROR_AT_LINE @@ -23,6 +19,10 @@ AC_FUNC_SELECT_ARGTYPES AC_FUNC_VPRINTF AC_CHECK_FUNCS([atexit floor getcwd gethostbyname memset mkdir select socket]) +# Checks for internationalization support +AM_GNU_GETTEXT([external]) +AM_GNU_GETTEXT_VERSION([0.16.1]) + # Search for *-config AC_PATH_PROG(SDL_CONFIG, sdl-config) AC_PATH_PROG(PKG_CONFIG, pkg-config) @@ -117,6 +117,7 @@ data/graphics/images/Makefile data/help/Makefile data/icons/Makefile docs/Makefile +po/Makefile.in ]) AC_OUTPUT diff --git a/po/LINGUAS b/po/LINGUAS new file mode 100644 index 00000000..8bba9bc2 --- /dev/null +++ b/po/LINGUAS @@ -0,0 +1 @@ +# Set of available languages. diff --git a/po/Makevars b/po/Makevars new file mode 100644 index 00000000..76e72f50 --- /dev/null +++ b/po/Makevars @@ -0,0 +1,41 @@ +# Makefile variables for PO directory in any package using GNU gettext. + +# Usually the message domain is the same as the package name. +DOMAIN = tmw + +# These two variables depend on the location of this directory. +subdir = po +top_builddir = .. + +# These options get passed to xgettext. +XGETTEXT_OPTIONS = --keyword=_ --keyword=N_ + +# This is the copyright holder that gets inserted into the header of the +# $(DOMAIN).pot file. Set this to the copyright holder of the surrounding +# package. (Note that the msgstr strings, extracted from the package's +# sources, belong to the copyright holder of the package.) Translators are +# expected to transfer the copyright for their translations to this person +# or entity, or to disclaim their copyright. The empty string stands for +# the public domain; in this case the translators are expected to disclaim +# their copyright. +COPYRIGHT_HOLDER = The Mana World Development Team + +# This is the email address or URL to which the translators shall report +# bugs in the untranslated strings: +# - Strings which are not entire sentences, see the maintainer guidelines +# in the GNU gettext documentation, section 'Preparing Strings'. +# - Strings which use unclear terms or require additional context to be +# understood. +# - Strings which make invalid assumptions about notation of date, time or +# money. +# - Pluralisation problems. +# - Incorrect English spelling. +# - Incorrect formatting. +# It can be your email address, or a mailing list address where translators +# can write to without being subscribed, or the URL of a web page through +# which the translators can contact you. +MSGID_BUGS_ADDRESS = + +# This is the list of locale categories, beyond LC_MESSAGES, for which the +# message catalogs shall be used. It is usually empty. +EXTRA_LOCALE_CATEGORIES = diff --git a/po/POTFILES.in b/po/POTFILES.in new file mode 100644 index 00000000..f750976e --- /dev/null +++ b/po/POTFILES.in @@ -0,0 +1,25 @@ +# List of source files which contain translatable strings. + +src/gui/buy.cpp +src/gui/char_select.cpp +src/gui/char_server.cpp +src/gui/confirm_dialog.cpp +src/gui/connection.cpp +src/gui/equipmentwindow.cpp +src/gui/inventorywindow.cpp +src/gui/item_amount.cpp +src/gui/login.cpp +src/gui/menuwindow.cpp +src/gui/minimap.cpp +src/gui/npclistdialog.cpp +src/gui/npc_text.cpp +src/gui/ok_dialog.cpp +src/gui/popupmenu.cpp +src/gui/register.cpp +src/gui/sell.cpp +src/gui/setup_audio.cpp +src/gui/setup.cpp +src/gui/setup_joystick.cpp +src/gui/setup_video.cpp +src/gui/trade.cpp +src/resources/itemdb.cpp diff --git a/po/tmw.pot b/po/tmw.pot new file mode 100644 index 00000000..ae49bb32 --- /dev/null +++ b/po/tmw.pot @@ -0,0 +1,486 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR The Mana World Development Team +# This file is distributed under the same license as the PACKAGE package. +# FIRST AUTHOR , YEAR. +# +#, fuzzy +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"Report-Msgid-Bugs-To: themanaworld-devel@lists.sourceforge.net\n" +"POT-Creation-Date: 2009-01-06 14:37+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=CHARSET\n" +"Content-Transfer-Encoding: 8bit\n" + +#: src/gui/buy.cpp:41 src/gui/buy.cpp:59 +msgid "Buy" +msgstr "" + +#: src/gui/buy.cpp:56 src/gui/buy.cpp:284 src/gui/sell.cpp:63 +#: src/gui/sell.cpp:304 +#, c-format +msgid "Price: %d GP / Total: %d GP" +msgstr "" + +#: src/gui/buy.cpp:60 src/gui/sell.cpp:67 +msgid "Quit" +msgstr "" + +#: src/gui/buy.cpp:61 src/gui/buy.cpp:251 src/gui/buy.cpp:269 +#: src/gui/inventorywindow.cpp:150 src/gui/inventorywindow.cpp:160 +#: src/gui/sell.cpp:68 src/gui/sell.cpp:275 src/gui/sell.cpp:289 +#: src/gui/trade.cpp:94 src/gui/trade.cpp:266 +#, c-format +msgid "Description: %s" +msgstr "" + +#: src/gui/buy.cpp:62 src/gui/buy.cpp:253 src/gui/buy.cpp:270 +#: src/gui/inventorywindow.cpp:149 src/gui/inventorywindow.cpp:158 +#: src/gui/sell.cpp:69 src/gui/sell.cpp:277 src/gui/sell.cpp:290 +#, c-format +msgid "Effect: %s" +msgstr "" + +#: src/gui/char_select.cpp:61 +msgid "Confirm Character Delete" +msgstr "" + +#: src/gui/char_select.cpp:62 +msgid "Are you sure you want to delete this character?" +msgstr "" + +#: src/gui/char_select.cpp:79 +msgid "Select Character" +msgstr "" + +#: src/gui/char_select.cpp:82 src/gui/item_amount.cpp:50 src/gui/login.cpp:49 +#: src/gui/ok_dialog.cpp:37 src/gui/trade.cpp:62 +msgid "Ok" +msgstr "" + +#: src/gui/char_select.cpp:83 src/gui/char_select.cpp:271 +#: src/gui/char_server.cpp:60 src/gui/connection.cpp:47 +#: src/gui/item_amount.cpp:51 src/gui/login.cpp:50 +#: src/gui/npclistdialog.cpp:45 src/gui/register.cpp:76 src/gui/setup.cpp:58 +#: src/gui/trade.cpp:63 +msgid "Cancel" +msgstr "" + +#: src/gui/char_select.cpp:84 +msgid "New" +msgstr "" + +#: src/gui/char_select.cpp:85 +msgid "Delete" +msgstr "" + +#: src/gui/char_select.cpp:86 +msgid "Previous" +msgstr "" + +#: src/gui/char_select.cpp:87 +msgid "Next" +msgstr "" + +#: src/gui/char_select.cpp:89 src/gui/char_select.cpp:184 +#: src/gui/char_select.cpp:196 src/gui/inventorywindow.cpp:148 +#: src/gui/inventorywindow.cpp:156 src/gui/trade.cpp:92 src/gui/trade.cpp:264 +#, c-format +msgid "Name: %s" +msgstr "" + +#: src/gui/char_select.cpp:90 src/gui/char_select.cpp:185 +#: src/gui/char_select.cpp:197 +#, c-format +msgid "Level: %d" +msgstr "" + +#: src/gui/char_select.cpp:91 src/gui/char_select.cpp:186 +#: src/gui/char_select.cpp:198 +#, c-format +msgid "Job Level: %d" +msgstr "" + +#: src/gui/char_select.cpp:92 src/gui/char_select.cpp:199 +#, c-format +msgid "Money: %d" +msgstr "" + +#: src/gui/char_select.cpp:187 +#, c-format +msgid "Gold: %d" +msgstr "" + +#: src/gui/char_select.cpp:256 +msgid "Create Character" +msgstr "" + +#: src/gui/char_select.cpp:263 src/gui/login.cpp:42 src/gui/register.cpp:65 +msgid "Name:" +msgstr "" + +#: src/gui/char_select.cpp:266 +msgid "Hair Color:" +msgstr "" + +#: src/gui/char_select.cpp:269 +msgid "Hair Style:" +msgstr "" + +#: src/gui/char_select.cpp:270 +msgid "Create" +msgstr "" + +#: src/gui/char_server.cpp:52 +msgid "Select Server" +msgstr "" + +#: src/gui/char_server.cpp:59 src/gui/npclistdialog.cpp:44 +#: src/gui/npc_text.cpp:46 +msgid "OK" +msgstr "" + +#: src/gui/confirm_dialog.cpp:35 +msgid "Yes" +msgstr "" + +#: src/gui/confirm_dialog.cpp:36 +msgid "No" +msgstr "" + +#: src/gui/connection.cpp:49 +msgid "Connecting..." +msgstr "" + +#: src/gui/equipmentwindow.cpp:38 src/gui/menuwindow.cpp:62 +msgid "Equipment" +msgstr "" + +#: src/gui/inventorywindow.cpp:46 src/gui/menuwindow.cpp:63 +msgid "Inventory" +msgstr "" + +#: src/gui/inventorywindow.cpp:56 src/gui/inventorywindow.cpp:232 +msgid "Use" +msgstr "" + +#: src/gui/inventorywindow.cpp:57 +msgid "Drop" +msgstr "" + +#: src/gui/inventorywindow.cpp:99 +#, c-format +msgid "Weight: %d / %d" +msgstr "" + +#: src/gui/inventorywindow.cpp:104 +#, c-format +msgid "Slots used: %d / %d" +msgstr "" + +#: src/gui/inventorywindow.cpp:225 +msgid "Unequip" +msgstr "" + +#: src/gui/inventorywindow.cpp:228 +msgid "Equip" +msgstr "" + +#: src/gui/item_amount.cpp:75 +msgid "Select amount of items to trade." +msgstr "" + +#: src/gui/item_amount.cpp:79 +msgid "Select amount of items to drop." +msgstr "" + +#: src/gui/login.cpp:40 +msgid "Login" +msgstr "" + +#: src/gui/login.cpp:43 src/gui/register.cpp:66 +msgid "Password:" +msgstr "" + +#: src/gui/login.cpp:44 src/gui/register.cpp:68 +msgid "Server:" +msgstr "" + +#: src/gui/login.cpp:48 +msgid "Remember Username" +msgstr "" + +#: src/gui/login.cpp:51 src/gui/register.cpp:75 +msgid "Register" +msgstr "" + +#: src/gui/menuwindow.cpp:61 +msgid "Status" +msgstr "" + +#: src/gui/menuwindow.cpp:64 +msgid "Skills" +msgstr "" + +#: src/gui/menuwindow.cpp:65 +msgid "Shortcut" +msgstr "" + +#: src/gui/menuwindow.cpp:66 +msgid "Setup" +msgstr "" + +#: src/gui/minimap.cpp:34 +msgid "MiniMap" +msgstr "" + +#: src/gui/npclistdialog.cpp:35 src/gui/npc_text.cpp:35 +msgid "NPC" +msgstr "" + +#: src/gui/popupmenu.cpp:81 +#, c-format +msgid "@@trade|Trade With %s@@" +msgstr "" + +#: src/gui/popupmenu.cpp:83 +#, c-format +msgid "@@attack|Attack %s@@" +msgstr "" + +#: src/gui/popupmenu.cpp:114 +msgid "@@talk|Talk To NPC@@" +msgstr "" + +#: src/gui/popupmenu.cpp:124 src/gui/popupmenu.cpp:140 +#: src/gui/popupmenu.cpp:293 +msgid "@@cancel|Cancel@@" +msgstr "" + +#: src/gui/popupmenu.cpp:136 +#, c-format +msgid "@@pickup|Pick Up %s@@" +msgstr "" + +#: src/gui/popupmenu.cpp:283 +msgid "@@use|Unequip@@" +msgstr "" + +#: src/gui/popupmenu.cpp:285 +msgid "@@use|Equip@@" +msgstr "" + +#: src/gui/popupmenu.cpp:288 +msgid "@@use|Use@@" +msgstr "" + +#: src/gui/popupmenu.cpp:290 +msgid "@@drop|Drop@@" +msgstr "" + +#: src/gui/popupmenu.cpp:291 +msgid "@@description|Description@@" +msgstr "" + +#: src/gui/register.cpp:67 +msgid "Confirm:" +msgstr "" + +#: src/gui/register.cpp:73 +msgid "Male" +msgstr "" + +#: src/gui/register.cpp:74 +msgid "Female" +msgstr "" + +#: src/gui/register.cpp:176 +#, c-format +msgid "The username needs to be at least %d characters long." +msgstr "" + +#: src/gui/register.cpp:184 +#, c-format +msgid "The username needs to be less than %d characters long." +msgstr "" + +#: src/gui/register.cpp:192 +#, c-format +msgid "The password needs to be at least %d characters long." +msgstr "" + +#: src/gui/register.cpp:200 +#, c-format +msgid "The password needs to be less than %d characters long." +msgstr "" + +#: src/gui/register.cpp:207 +msgid "Passwords do not match." +msgstr "" + +#: src/gui/register.cpp:227 +msgid "Error" +msgstr "" + +#: src/gui/sell.cpp:46 src/gui/sell.cpp:66 +msgid "Sell" +msgstr "" + +#: src/gui/setup_audio.cpp:40 +msgid "Sound" +msgstr "" + +#: src/gui/setup_audio.cpp:46 +msgid "Sfx volume" +msgstr "" + +#: src/gui/setup_audio.cpp:47 +msgid "Music volume" +msgstr "" + +#: src/gui/setup.cpp:58 +msgid "Apply" +msgstr "" + +#: src/gui/setup.cpp:58 +msgid "Reset Windows" +msgstr "" + +#: src/gui/setup.cpp:79 +msgid "Video" +msgstr "" + +#: src/gui/setup.cpp:83 +msgid "Audio" +msgstr "" + +#: src/gui/setup.cpp:87 +msgid "Joystick" +msgstr "" + +#: src/gui/setup.cpp:91 +msgid "Keyboard" +msgstr "" + +#: src/gui/setup.cpp:95 +msgid "Players" +msgstr "" + +#: src/gui/setup_joystick.cpp:36 src/gui/setup_joystick.cpp:70 +msgid "Press the button to start calibration" +msgstr "" + +#: src/gui/setup_joystick.cpp:37 src/gui/setup_joystick.cpp:68 +msgid "Calibrate" +msgstr "" + +#: src/gui/setup_joystick.cpp:38 +msgid "Enable joystick" +msgstr "" + +#: src/gui/setup_joystick.cpp:73 +msgid "Stop" +msgstr "" + +#: src/gui/setup_joystick.cpp:74 +msgid "Rotate the stick" +msgstr "" + +#: src/gui/setup_video.cpp:112 +msgid "Full screen" +msgstr "" + +#: src/gui/setup_video.cpp:113 +msgid "OpenGL" +msgstr "" + +#: src/gui/setup_video.cpp:114 +msgid "Custom cursor" +msgstr "" + +#: src/gui/setup_video.cpp:116 +msgid "FPS Limit:" +msgstr "" + +#: src/gui/setup_video.cpp:135 +msgid "Gui opacity" +msgstr "" + +#: src/gui/setup_video.cpp:192 +msgid "Scroll radius" +msgstr "" + +#: src/gui/setup_video.cpp:200 +msgid "Scroll laziness" +msgstr "" + +#: src/gui/setup_video.cpp:208 +msgid "Ambient FX" +msgstr "" + +#: src/gui/setup_video.cpp:215 src/gui/setup_video.cpp:412 +msgid "off" +msgstr "" + +#: src/gui/setup_video.cpp:218 src/gui/setup_video.cpp:234 +#: src/gui/setup_video.cpp:415 src/gui/setup_video.cpp:429 +msgid "low" +msgstr "" + +#: src/gui/setup_video.cpp:221 src/gui/setup_video.cpp:240 +#: src/gui/setup_video.cpp:418 src/gui/setup_video.cpp:435 +msgid "high" +msgstr "" + +#: src/gui/setup_video.cpp:227 +msgid "Particle Detail" +msgstr "" + +#: src/gui/setup_video.cpp:237 src/gui/setup_video.cpp:432 +msgid "medium" +msgstr "" + +#: src/gui/setup_video.cpp:243 src/gui/setup_video.cpp:438 +msgid "max" +msgstr "" + +#: src/gui/setup_video.cpp:309 +msgid "Switching to full screen" +msgstr "" + +#: src/gui/setup_video.cpp:310 +msgid "Restart needed for changes to take effect." +msgstr "" + +#: src/gui/setup_video.cpp:322 +msgid "Changing OpenGL" +msgstr "" + +#: src/gui/setup_video.cpp:323 +msgid "Applying change to OpenGL requires restart." +msgstr "" + +#: src/gui/trade.cpp:61 +msgid "Add" +msgstr "" + +#: src/gui/trade.cpp:64 +msgid "Trade" +msgstr "" + +#: src/gui/trade.cpp:80 src/gui/trade.cpp:156 src/gui/trade.cpp:204 +#, c-format +msgid "You get %d GP." +msgstr "" + +#: src/gui/trade.cpp:81 +msgid "You give:" +msgstr "" + +#: src/resources/itemdb.cpp:99 +msgid "Unnamed" +msgstr "" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 61fc77e8..666a675d 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -261,6 +261,7 @@ SET(SRCS utils/base64.h utils/dtor.h utils/fastsqrt.h + utils/gettext.h utils/strprintf.cpp utils/strprintf.h utils/tostring.h diff --git a/src/Makefile.am b/src/Makefile.am index 7c547a11..c924760f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -215,6 +215,7 @@ tmw_SOURCES = gui/widgets/resizegrip.cpp \ utils/base64.h \ utils/dtor.h \ utils/fastsqrt.h \ + utils/gettext.h \ utils/strprintf.cpp \ utils/strprintf.h \ utils/tostring.h \ @@ -311,4 +312,5 @@ tmw_SOURCES = gui/widgets/resizegrip.cpp \ # set the include path found by configure INCLUDES = \ $(all_includes) \ - -DTMW_DATADIR=\""$(pkgdatadir)/"\" + -DTMW_DATADIR=\""$(pkgdatadir)/"\" \ + -DLOCALEDIR=\""$(localedir)"\" diff --git a/src/graphics.cpp b/src/graphics.cpp index c8cb0091..6920bcb0 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -123,7 +123,7 @@ bool Graphics::drawImage(Image *image, int x, int y) { return drawImage(image, 0, 0, x, y, image->mBounds.w, image->mBounds.h); } -#include + bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, int width, int height, bool) { diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 714f52db..c1e5a272 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -34,10 +34,11 @@ #include "../net/messageout.h" #include "../net/protocol.h" -#include "../utils/tostring.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" BuyDialog::BuyDialog(Network *network): - Window("Buy"), mNetwork(network), + Window(_("Buy")), mNetwork(network), mMoney(0), mAmountItems(0), mMaxItems(0) { setWindowName("Buy"); @@ -52,13 +53,13 @@ BuyDialog::BuyDialog(Network *network): mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label("Price : 0 GP / 0 GP"); + mMoneyLabel = new gcn::Label(strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); - mBuyButton = new Button("Buy", "buy", this); - mQuitButton = new Button("Quit", "quit", this); - mItemDescLabel = new gcn::Label("Description:"); - mItemEffectLabel = new gcn::Label("Effect:"); + mBuyButton = new Button(_("Buy"), "buy", this); + mQuitButton = new Button(_("Quit"), "quit", this); + mItemDescLabel = new gcn::Label(strprintf(_("Description: %s"), "")); + mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), "")); mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); @@ -159,7 +160,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) } // TODO: Actually we'd have a bug elsewhere if this check for the number // of items to be bought ever fails, Bertram removed the assertions, is - // there a better way to ensure this fails in an _obivous_ way in C++? + // there a better way to ensure this fails in an _obvious_ way in C++? else if (event.getId() == "buy" && mAmountItems > 0 && mAmountItems <= mMaxItems) { @@ -246,8 +247,10 @@ BuyDialog::updateButtonsAndLabels() { const ItemInfo &info = mShopItems->at(selectedItem)->getInfo(); - mItemDescLabel->setCaption("Description: " + info.getDescription()); - mItemEffectLabel->setCaption("Effect: " + info.getEffect()); + mItemDescLabel->setCaption + (strprintf(_("Description: %s"), info.getDescription().c_str())); + mItemEffectLabel->setCaption + (strprintf(_("Effect: %s"), info.getEffect().c_str())); int itemPrice = mShopItems->at(selectedItem)->getPrice(); @@ -263,8 +266,8 @@ BuyDialog::updateButtonsAndLabels() } else { - mItemDescLabel->setCaption("Description:"); - mItemEffectLabel->setCaption("Effect:"); + mItemDescLabel->setCaption(strprintf(_("Description: %s"), "")); + mItemEffectLabel->setCaption(strprintf(_("Effect: %s"), "")); mMaxItems = 0; mAmountItems = 0; } @@ -276,8 +279,7 @@ BuyDialog::updateButtonsAndLabels() mSlider->setEnabled(mMaxItems > 1); // Update quantity and money labels - mQuantityLabel->setCaption( - toString(mAmountItems) + " / " + toString(mMaxItems)); - mMoneyLabel->setCaption("Price: " + toString(price) + " GP / " - + toString(mMoney - price) + " GP" ); + mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); + mMoneyLabel->setCaption + (strprintf(_("Price: %d GP / Total: %d GP"), price, mMoney - price)); } diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 7c067eef..65dafeea 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -38,7 +38,8 @@ #include "../net/charserverhandler.h" #include "../net/messageout.h" -#include "../utils/tostring.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/trim.h" // Defined in main.cpp, used here for setting the char create dialog @@ -57,8 +58,8 @@ class CharDeleteConfirm : public ConfirmDialog }; CharDeleteConfirm::CharDeleteConfirm(CharSelectDialog *m): - ConfirmDialog("Confirm", "Are you sure you want to delete this character?", - m), + ConfirmDialog(_("Confirm Character Delete"), + _("Are you sure you want to delete this character?"), m), master(m) { } @@ -75,21 +76,23 @@ void CharDeleteConfirm::action(const gcn::ActionEvent &event) CharSelectDialog::CharSelectDialog(Network *network, LockedArray *charInfo, Gender gender): - Window("Select Character"), mNetwork(network), + Window(_("Select Character")), mNetwork(network), mCharInfo(charInfo), mGender(gender), mCharSelected(false) { - mSelectButton = new Button("Ok", "ok", this); - mCancelButton = new Button("Cancel", "cancel", this); - mNewCharButton = new Button("New", "new", this); - mDelCharButton = new Button("Delete", "delete", this); - mPreviousButton = new Button("Previous", "previous", this); - mNextButton = new Button("Next", "next", this); - - mNameLabel = new gcn::Label("Name"); - mLevelLabel = new gcn::Label("Level"); - mJobLevelLabel = new gcn::Label("Job Level"); - mMoneyLabel = new gcn::Label("Money"); - mPlayerBox = new PlayerBox(); + mSelectButton = new Button(_("Ok"), "ok", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); + mNewCharButton = new Button(_("New"), "new", this); + mDelCharButton = new Button(_("Delete"), "delete", this); + mPreviousButton = new Button(_("Previous"), "previous", this); + mNextButton = new Button(_("Next"), "next", this); + + mNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); + mLevelLabel = new gcn::Label(strprintf(_("Level: %d"), 0)); + mJobLevelLabel = new gcn::Label(strprintf(_("Job Level: %d"), 0)); + mMoneyLabel = new gcn::Label(strprintf(_("Money: %d"), 0)); + + // Control that shows the Player + mPlayerBox = new PlayerBox; int w = 195; int h = 220; @@ -178,10 +181,10 @@ void CharSelectDialog::updatePlayerInfo() if (pi) { - mNameLabel->setCaption(pi->getName()); - mLevelLabel->setCaption("Lvl: " + toString(pi->mLevel)); - mJobLevelLabel->setCaption("Job Lvl: " + toString(pi->mJobLevel)); - mMoneyLabel->setCaption("Gold: " + toString(pi->mGp)); + mNameLabel->setCaption(strprintf(_("Name: %s"), pi->getName().c_str())); + mLevelLabel->setCaption(strprintf(_("Level: %d"), pi->mLevel)); + mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), pi->mJobLevel)); + mMoneyLabel->setCaption(strprintf(_("Gold: %d"), pi->mGp)); if (!mCharSelected) { mNewCharButton->setEnabled(false); @@ -190,10 +193,10 @@ void CharSelectDialog::updatePlayerInfo() } } else { - mNameLabel->setCaption("Name"); - mLevelLabel->setCaption("Level"); - mJobLevelLabel->setCaption("Job Level"); - mMoneyLabel->setCaption("Money"); + mNameLabel->setCaption(strprintf(_("Name: %s"), "")); + mLevelLabel->setCaption(strprintf(_("Level: %d"), 0)); + mJobLevelLabel->setCaption(strprintf(_("Job Level: %d"), 0)); + mMoneyLabel->setCaption(strprintf(_("Money: %d"), 0)); mNewCharButton->setEnabled(true); mDelCharButton->setEnabled(false); mSelectButton->setEnabled(false); @@ -250,22 +253,22 @@ bool CharSelectDialog::selectByName(const std::string &name) CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, Gender gender): - Window("Create Character", true, parent), mNetwork(network), mSlot(slot) + Window(_("Create Character"), true, parent), mNetwork(network), mSlot(slot) { mPlayer = new Player(0, 0, NULL); mPlayer->setGender(gender); mPlayer->setHairStyle(rand() % Being::getHairStylesNr(), rand() % Being::getHairColorsNr()); mNameField = new TextField(""); - mNameLabel = new gcn::Label("Name:"); + mNameLabel = new gcn::Label(_("Name:")); mNextHairColorButton = new Button(">", "nextcolor", this); mPrevHairColorButton = new Button("<", "prevcolor", this); - mHairColorLabel = new gcn::Label("Hair Color:"); + mHairColorLabel = new gcn::Label(_("Hair Color:")); mNextHairStyleButton = new Button(">", "nextstyle", this); mPrevHairStyleButton = new Button("<", "prevstyle", this); - mHairStyleLabel = new gcn::Label("Hair Style:"); - mCreateButton = new Button("Create", "create", this); - mCancelButton = new Button("Cancel", "cancel", this); + mHairStyleLabel = new gcn::Label(_("Hair Style:")); + mCreateButton = new Button(_("Create"), "create", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); mPlayerBox = new PlayerBox(mPlayer); mNameField->setActionEventId("create"); diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index ce068ad1..3d3309fb 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -31,6 +31,8 @@ #include "../net/network.h" // TODO this is just for iptostring, move that? +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/tostring.h" extern SERVER_INFO **server_info; @@ -47,15 +49,15 @@ class ServerListModel : public gcn::ListModel { }; ServerSelectDialog::ServerSelectDialog(LoginData *loginData, int nextState): - Window("Select Server"), + Window(_("Select Server")), mLoginData(loginData), mNextState(nextState) { mServerListModel = new ServerListModel(); mServerList = new ListBox(mServerListModel); ScrollArea *mScrollArea = new ScrollArea(mServerList); - mOkButton = new Button("OK", "ok", this); - Button *mCancelButton = new Button("Cancel", "cancel", this); + mOkButton = new Button(_("OK"), "ok", this); + Button *mCancelButton = new Button(_("Cancel"), "cancel", this); setContentSize(200, 100); diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 9ef94f62..5f2b9cb2 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -25,14 +25,15 @@ #include "button.h" +#include "../utils/gettext.h" ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, Window *parent): Window(title, true, parent) { gcn::Label *textLabel = new gcn::Label(msg); - gcn::Button *yesButton = new Button("Yes", "yes", this); - gcn::Button *noButton = new Button("No", "no", this); + gcn::Button *yesButton = new Button(_("Yes"), "yes", this); + gcn::Button *noButton = new Button(_("No"), "no", this); int w = textLabel->getWidth() + 20; int inWidth = yesButton->getWidth() + noButton->getWidth() + 5; diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index 8ad3b436..0f43ff14 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -30,6 +30,8 @@ #include "../main.h" +#include "../utils/gettext.h" + namespace { struct ConnectionActionListener : public gcn::ActionListener { @@ -42,9 +44,9 @@ ConnectionDialog::ConnectionDialog(): { setContentSize(200, 100); - Button *cancelButton = new Button("Cancel", "cancelButton", &listener); + Button *cancelButton = new Button(_("Cancel"), "cancelButton", &listener); mProgressBar = new ProgressBar(0.0, 200 - 10, 20, 128, 128, 128); - gcn::Label *label = new gcn::Label("Connecting..."); + gcn::Label *label = new gcn::Label(_("Connecting...")); cancelButton->setPosition(5, 100 - 5 - cancelButton->getHeight()); mProgressBar->setPosition(5, cancelButton->getY() - 25); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 762ca8e8..f3a143be 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -31,10 +31,12 @@ #include "../resources/iteminfo.h" #include "../resources/resourcemanager.h" +#include "../utils/gettext.h" #include "../utils/tostring.h" EquipmentWindow::EquipmentWindow(Equipment *equipment): - Window("Equipment"), mEquipment(equipment) + Window(_("Equipment")), + mEquipment(equipment) { setWindowName("Equipment"); setCloseButton(true); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 0e1c5291..ac368aa7 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -39,10 +39,11 @@ #include "../resources/iteminfo.h" -#include "../utils/tostring.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" InventoryWindow::InventoryWindow(): - Window("Inventory") + Window(_("Inventory")) { setWindowName("Inventory"); setResizable(true); @@ -52,8 +53,8 @@ InventoryWindow::InventoryWindow(): // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(115, 25, 322, 200); - mUseButton = new Button("Use", "use", this); - mDropButton = new Button("Drop", "drop", this); + mUseButton = new Button(_("Use"), "use", this); + mDropButton = new Button(_("Drop"), "drop", this); mItems = new ItemContainer(player_node->getInventory()); mItems->addSelectionListener(this); @@ -95,15 +96,14 @@ void InventoryWindow::logic() updateButtons(); // Update weight information - mWeightLabel->setCaption( - "Weight: " + toString(player_node->mTotalWeight) + - "/" + toString(player_node->mMaxWeight)); + mWeightLabel->setCaption(strprintf(_("Weight: %d / %d"), + player_node->mTotalWeight, + player_node->mMaxWeight)); // Update number of items in inventory - mInvenSlotLabel->setCaption( - "Slots used: " - + toString(player_node->getInventory()->getNumberOfSlotsUsed()) - + "/" + toString(player_node->getInventory()->getInventorySize())); + mInvenSlotLabel->setCaption(strprintf(_("Slots used: %d / %d"), + player_node->getInventory()->getNumberOfSlotsUsed(), + player_node->getInventory()->getInventorySize())); } void InventoryWindow::action(const gcn::ActionEvent &event) @@ -145,20 +145,20 @@ void InventoryWindow::valueChanged(const gcn::SelectionEvent &event) // Update name, effect and description if (!item) { - mItemNameLabel->setCaption("Name:"); - mItemEffectLabel->setCaption("Effect:"); - mItemDescriptionLabel->setCaption("Description:"); + mItemNameLabel->setCaption(strprintf(_("Name: %s"), "")); + mItemEffectLabel->setCaption(strprintf(_("Effect: %s"), "")); + mItemDescriptionLabel->setCaption(strprintf(_("Description: %s"), "")); } else { const ItemInfo& itemInfo = item->getInfo(); - std::string SomeText; - SomeText = "Name: " + itemInfo.getName(); - mItemNameLabel->setCaption(SomeText); - SomeText = "Effect: " + itemInfo.getEffect(); - mItemEffectLabel->setCaption(SomeText); - SomeText = "Description: " + itemInfo.getDescription(); - mItemDescriptionLabel->setCaption(SomeText); + mItemNameLabel->setCaption( + strprintf(_("Name: %s"), itemInfo.getName().c_str())); + mItemEffectLabel->setCaption( + strprintf(_("Effect: %s"), itemInfo.getEffect().c_str())); + mItemDescriptionLabel->setCaption( + strprintf(_("Description: %s"), + itemInfo.getDescription().c_str())); } } @@ -170,7 +170,8 @@ void InventoryWindow::mouseClicked(gcn::MouseEvent &event) { Item *item = mItems->getSelectedItem(); - if (!item) return; + if (!item) + return; /* Convert relative to the window coordinates to absolute screen * coordinates. @@ -221,14 +222,14 @@ void InventoryWindow::updateButtons() if (selectedItem && selectedItem->isEquipment()) { if (selectedItem->isEquipped()) { - mUseButton->setCaption("Unequip"); + mUseButton->setCaption(_("Unequip")); } else { - mUseButton->setCaption("Equip"); + mUseButton->setCaption(_("Equip")); } } else { - mUseButton->setCaption("Use"); + mUseButton->setCaption(_("Use")); } mUseButton->setEnabled(selectedItem != 0); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 2e8941e8..064c8f93 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -29,31 +29,33 @@ #include "../item.h" #include "../localplayer.h" +#include "../utils/gettext.h" + ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): - Window("Select amount of items to drop.", true, parent), + Window("", true, parent), mItem(item) { - // New labels + // Integer field mItemAmountTextBox = new IntTextBox(1); - - // New buttons - Button *minusButton = new Button("-", "Minus", this); - Button *plusButton = new Button("+", "Plus", this); - Button *okButton = new Button("Okay", "Drop", this); - Button *cancelButton = new Button("Cancel", "Cancel", this); - mItemAmountSlide = new Slider(1.0, mItem->getQuantity()); - mItemAmountTextBox->setRange(1, mItem->getQuantity()); - mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10)); - // Set button events Id + // Slider + mItemAmountSlide = new Slider(1.0, mItem->getQuantity()); mItemAmountSlide->setActionEventId("Slide"); + mItemAmountSlide->addActionListener(this); + + // Buttons + Button *minusButton = new Button("-", "Minus", this); + Button *plusButton = new Button("+", "Plus", this); + Button *okButton = new Button(_("Ok"), "Drop", this); + Button *cancelButton = new Button(_("Cancel"), "Cancel", this); - // Set position + // Set positions mItemAmountTextBox->setPosition(35, 10); mItemAmountTextBox->setSize(24, 16); plusButton->setPosition(60, 5); minusButton->setPosition(10, 5); + mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10)); mItemAmountSlide->setPosition(10, 35); okButton->setPosition(10, 50); cancelButton->setPosition(60, 50); @@ -66,17 +68,15 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): add(okButton); add(cancelButton); - mItemAmountSlide->addActionListener(this); - resetAmount(); switch (usage) { case AMOUNT_TRADE_ADD: - setCaption("Select amount of items to trade."); + setCaption(_("Select amount of items to trade.")); okButton->setActionEventId("AddTrade"); break; case AMOUNT_ITEM_DROP: - setCaption("Select amount of items to drop."); + setCaption(_("Select amount of items to drop.")); okButton->setActionEventId("Drop"); break; default: diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 06a5f9f0..5a748b52 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -34,21 +34,23 @@ #include "passwordfield.h" #include "textfield.h" +#include "../utils/gettext.h" + LoginDialog::LoginDialog(LoginData *loginData): - Window("Login"), mLoginData(loginData) + Window(_("Login")), mLoginData(loginData) { - gcn::Label *userLabel = new gcn::Label("Name:"); - gcn::Label *passLabel = new gcn::Label("Password:"); - gcn::Label *serverLabel = new gcn::Label("Server:"); + gcn::Label *userLabel = new gcn::Label(_("Name:")); + gcn::Label *passLabel = new gcn::Label(_("Password:")); + gcn::Label *serverLabel = new gcn::Label(_("Server:")); mUserField = new TextField(mLoginData->username); mPassField = new PasswordField(mLoginData->password); mServerField = new TextField(mLoginData->hostname); - mKeepCheck = new CheckBox("Keep", mLoginData->remember); - mOkButton = new Button("OK", "ok", this); - mCancelButton = new Button("Cancel", "cancel", this); - mRegisterButton = new Button("Register", "register", this); + mKeepCheck = new CheckBox(_("Remember Username"), mLoginData->remember); + mOkButton = new Button(_("Ok"), "ok", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); + mRegisterButton = new Button(_("Register"), "register", this); - const int width = 220; + const int width = 250; const int height = 100; setContentSize(width, height); diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 3c3e4ab8..0893cb1c 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -28,6 +28,8 @@ #include "button.h" #include "windowcontainer.h" +#include "../utils/gettext.h" + extern Window *setupWindow; extern Window *inventoryWindow; extern Window *equipmentWindow; @@ -54,21 +56,21 @@ MenuWindow::MenuWindow(): setTitleBarHeight(0); // Buttons - const char *buttonNames[] = + static const char *buttonNames[] = { - "Status", - "Equipment", - "Inventory", - "Skills", - "Shortcut", - "Setup", + N_("Status"), + N_("Equipment"), + N_("Inventory"), + N_("Skills"), + N_("Shortcut"), + N_("Setup"), 0 }; int x = 0, h = 0; for (const char **curBtn = buttonNames; *curBtn; curBtn++) { - gcn::Button *btn = new Button(*curBtn, *curBtn, &listener); + gcn::Button *btn = new Button(gettext(*curBtn), *curBtn, &listener); btn->setPosition(x, 0); add(btn); x += btn->getWidth() + 3; diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 231c749f..55132d6d 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -28,8 +28,10 @@ #include "../resources/image.h" +#include "../utils/gettext.h" + Minimap::Minimap(): - Window("Map"), + Window(_("MiniMap")), mMapImage(NULL) { setWindowName("MiniMap"); diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 34c9cce1..c9ace303 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -29,8 +29,10 @@ #include "../npc.h" +#include "../utils/gettext.h" + NpcTextDialog::NpcTextDialog(): - Window("NPC") + Window(_("NPC")) { setResizable(true); @@ -41,7 +43,7 @@ NpcTextDialog::NpcTextDialog(): mTextBox->setEditable(false); scrollArea = new ScrollArea(mTextBox); - okButton = new Button("OK", "ok", this); + okButton = new Button(_("OK"), "ok", this); setContentSize(260, 175); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index cdd38312..bff6994d 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -29,8 +29,10 @@ #include "../npc.h" +#include "../utils/gettext.h" + NpcListDialog::NpcListDialog(): - Window("NPC") + Window(_("NPC")) { setResizable(true); @@ -39,8 +41,8 @@ NpcListDialog::NpcListDialog(): mItemList = new ListBox(this); scrollArea = new ScrollArea(mItemList); - okButton = new Button("OK", "ok", this); - cancelButton = new Button("Cancel", "cancel", this); + okButton = new Button(_("OK"), "ok", this); + cancelButton = new Button(_("Cancel"), "cancel", this); setContentSize(260, 175); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index d43c8e69..9db3cd7b 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -24,6 +24,8 @@ #include "button.h" #include "scrollarea.h" +#include "../utils/gettext.h" + OkDialog::OkDialog(const std::string &title, const std::string &msg, Window *parent): Window(title, true, parent) @@ -32,7 +34,7 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, textBox->setEditable(false); gcn::ScrollArea *scrollArea = new ScrollArea(textBox); - gcn::Button *okButton = new Button("Ok", "ok", this); + gcn::Button *okButton = new Button(_("Ok"), "ok", this); setContentSize(260, 175); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 07719d2c..bfa75ef9 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -42,6 +42,9 @@ #include "../resources/iteminfo.h" #include "../resources/itemdb.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" + extern std::string tradePartnerName; PopupMenu::PopupMenu(): @@ -74,8 +77,10 @@ void PopupMenu::showPopup(int x, int y, Being *being) // Players can be traded with. Later also attack, follow and // add as buddy will be options in this menu. const std::string &name = being->getName(); - mBrowserBox->addRow("@@trade|Trade With " + name + "@@"); - mBrowserBox->addRow("@@attack|Attack " + name + "@@"); + mBrowserBox->addRow( + strprintf(_("@@trade|Trade With %s@@"), name.c_str())); + mBrowserBox->addRow( + strprintf(_("@@attack|Attack %s@@"), name.c_str())); mBrowserBox->addRow("##3---"); @@ -106,7 +111,7 @@ void PopupMenu::showPopup(int x, int y, Being *being) case Being::NPC: // NPCs can be talked to (single option, candidate for removal // unless more options would be added) - mBrowserBox->addRow("@@talk|Talk To NPC@@"); + mBrowserBox->addRow(_("@@talk|Talk To NPC@@")); break; default: @@ -116,7 +121,7 @@ void PopupMenu::showPopup(int x, int y, Being *being) //browserBox->addRow("@@look|Look To@@"); mBrowserBox->addRow("##3---"); - mBrowserBox->addRow("@@cancel|Cancel@@"); + mBrowserBox->addRow(_("@@cancel|Cancel@@")); showPopup(x, y); } @@ -128,11 +133,11 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) // Floor item can be picked up (single option, candidate for removal) std::string name = ItemDB::get(mFloorItem->getItemId()).getName(); - mBrowserBox->addRow("@@pickup|Pick Up " + name + "@@"); + mBrowserBox->addRow(strprintf(_("@@pickup|Pick Up %s@@"), name.c_str())); //browserBox->addRow("@@look|Look To@@"); mBrowserBox->addRow("##3---"); - mBrowserBox->addRow("@@cancel|Cancel@@"); + mBrowserBox->addRow(_("@@cancel|Cancel@@")); showPopup(x, y); } @@ -275,17 +280,17 @@ void PopupMenu::showPopup(int x, int y, Item *item) if (item->isEquipment()) { if (item->isEquipped()) - mBrowserBox->addRow("@@use|Unequip@@"); + mBrowserBox->addRow(_("@@use|Unequip@@")); else - mBrowserBox->addRow("@@use|Equip@@"); + mBrowserBox->addRow(_("@@use|Equip@@")); } else - mBrowserBox->addRow("@@use|Use@@"); + mBrowserBox->addRow(_("@@use|Use@@")); - mBrowserBox->addRow("@@drop|Drop@@"); - mBrowserBox->addRow("@@description|Description@@"); + mBrowserBox->addRow(_("@@drop|Drop@@")); + mBrowserBox->addRow(_("@@description|Description@@")); mBrowserBox->addRow("##3---"); - mBrowserBox->addRow("@@cancel|Cancel@@"); + mBrowserBox->addRow(_("@@cancel|Cancel@@")); showPopup(x, y); } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 2a97a3e5..ce36efa2 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -39,6 +39,9 @@ #include "textfield.h" #include "ok_dialog.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" + void WrongDataNoticeListener::setTarget(gcn::TextField *textField) { @@ -59,18 +62,18 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mWrongDataNoticeListener(new WrongDataNoticeListener()), mLoginData(loginData) { - gcn::Label *userLabel = new gcn::Label("Name:"); - gcn::Label *passwordLabel = new gcn::Label("Password:"); - gcn::Label *confirmLabel = new gcn::Label("Confirm:"); - gcn::Label *serverLabel = new gcn::Label("Server:"); + gcn::Label *userLabel = new gcn::Label(_("Name:")); + gcn::Label *passwordLabel = new gcn::Label(_("Password:")); + gcn::Label *confirmLabel = new gcn::Label(_("Confirm:")); + gcn::Label *serverLabel = new gcn::Label(_("Server:")); mUserField = new TextField(loginData->username); mPasswordField = new PasswordField(loginData->password); mConfirmField = new PasswordField(); mServerField = new TextField(loginData->hostname); - mMaleButton = new RadioButton("Male", "sex", true); - mFemaleButton = new RadioButton("Female", "sex", false); - mRegisterButton = new Button("Register", "register", this); - mCancelButton = new Button("Cancel", "cancel", this); + mMaleButton = new RadioButton(_("Male"), "sex", true); + mFemaleButton = new RadioButton(_("Female"), "sex", false); + mRegisterButton = new Button(_("Register"), "register", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); const int width = 220; const int height = 150; @@ -163,45 +166,45 @@ RegisterDialog::action(const gcn::ActionEvent &event) const std::string user = mUserField->getText(); logger->log("RegisterDialog::register Username is %s", user.c_str()); - std::stringstream errorMsg; + std::string errorMsg; int error = 0; if (user.length() < LEN_MIN_USERNAME) { // Name too short - errorMsg << "The username needs to be at least " - << LEN_MIN_USERNAME - << " characters long."; + errorMsg = strprintf + (_("The username needs to be at least %d characters long."), + LEN_MIN_USERNAME); error = 1; } else if (user.length() > LEN_MAX_USERNAME - 1 ) { // Name too long - errorMsg << "The username needs to be less than " - << LEN_MAX_USERNAME - << " characters long."; + errorMsg = strprintf + (_("The username needs to be less than %d characters long."), + LEN_MAX_USERNAME); error = 1; } else if (mPasswordField->getText().length() < LEN_MIN_PASSWORD) { // Pass too short - errorMsg << "The password needs to be at least " - << LEN_MIN_PASSWORD - << " characters long."; + errorMsg = strprintf + (_("The password needs to be at least %d characters long."), + LEN_MIN_PASSWORD); error = 2; } else if (mPasswordField->getText().length() > LEN_MAX_PASSWORD - 1 ) { // Pass too long - errorMsg << "The password needs to be less than " - << LEN_MAX_PASSWORD - << " characters long."; + errorMsg = strprintf + (_("The password needs to be less than %d characters long."), + LEN_MAX_PASSWORD); error = 2; } else if (mPasswordField->getText() != mConfirmField->getText()) { // Password does not match with the confirmation one - errorMsg << "Passwords do not match."; + errorMsg = _("Passwords do not match."); error = 2; } @@ -220,8 +223,8 @@ RegisterDialog::action(const gcn::ActionEvent &event) mWrongDataNoticeListener->setTarget(this->mPasswordField); } - OkDialog *mWrongRegisterNotice = new OkDialog("Error", - errorMsg.str()); + OkDialog *mWrongRegisterNotice = + new OkDialog(_("Error"), errorMsg); mWrongRegisterNotice->addActionListener(mWrongDataNoticeListener); } else diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 6df1cbf6..7a2e94c6 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -39,10 +39,11 @@ #include "../net/messageout.h" #include "../net/protocol.h" -#include "../utils/tostring.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" SellDialog::SellDialog(Network *network): - Window("Sell"), + Window(_("Sell")), mNetwork(network), mMaxItems(0), mAmountItems(0) { @@ -58,13 +59,14 @@ SellDialog::SellDialog(Network *network): mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label("Money: 0 GP / Total: 0 GP"); + mMoneyLabel = new gcn::Label( + strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); mIncreaseButton = new Button("+", "+", this); mDecreaseButton = new Button("-", "-", this); - mSellButton = new Button("Sell", "sell", this); - mQuitButton = new Button("Quit", "quit", this); - mItemDescLabel = new gcn::Label("Description:"); - mItemEffectLabel = new gcn::Label("Effect:"); + mSellButton = new Button(_("Sell"), "sell", this); + mQuitButton = new Button(_("Quit"), "quit", this); + mItemDescLabel = new gcn::Label(strprintf(_("Description: %s"), "")); + mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), "")); mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); @@ -261,14 +263,19 @@ void SellDialog::setMoney(int amount) mShopItemList->setPlayersMoney(amount); } -void -SellDialog::updateButtonsAndLabels() +void SellDialog::updateButtonsAndLabels() { int selectedItem = mShopItemList->getSelected(); int income = 0; if (selectedItem > -1) { + const ItemInfo &info = mShopItems->at(selectedItem)->getInfo(); + mItemDescLabel->setCaption + (strprintf(_("Description: %s"), info.getDescription().c_str())); + mItemEffectLabel->setCaption + (strprintf(_("Effect: %s"), info.getEffect().c_str())); + mMaxItems = mShopItems->at(selectedItem)->getQuantity(); if (mAmountItems > mMaxItems) { @@ -276,17 +283,13 @@ SellDialog::updateButtonsAndLabels() } income = mAmountItems * mShopItems->at(selectedItem)->getPrice(); - - const ItemInfo &info = mShopItems->at(selectedItem)->getInfo(); - mItemDescLabel->setCaption("Description: " + info.getDescription()); - mItemEffectLabel->setCaption("Effect: " + info.getEffect()); } else { + mItemDescLabel->setCaption(strprintf(_("Description: %s"), "")); + mItemEffectLabel->setCaption(strprintf(_("Effect: %s"), "")); mMaxItems = 0; mAmountItems = 0; - mItemDescLabel->setCaption("Description:"); - mItemEffectLabel->setCaption("Effect:"); } // Update Buttons and slider @@ -296,8 +299,8 @@ SellDialog::updateButtonsAndLabels() mSlider->setEnabled(mMaxItems > 1); // Update the quantity and money labels - mQuantityLabel->setCaption( - toString(mAmountItems) + " / " + toString(mMaxItems)); - mMoneyLabel->setCaption("Money: " + toString(income) + " GP / Total: " - + toString(mPlayerMoney + income) + " GP"); + mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); + mMoneyLabel->setCaption + (strprintf(_("Price: %d GP / Total: %d GP"), + income, mPlayerMoney + income)); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 2da9d1b5..067d8d64 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -32,6 +32,8 @@ #include "tabbedcontainer.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" + #include extern Window *statusWindow; @@ -52,12 +54,12 @@ Setup::Setup(): int height = 265; setContentSize(width, height); - const char *buttonNames[] = { - "Apply", "Cancel", "Reset Windows", 0 + static const char *buttonNames[] = { + N_("Apply"), N_("Cancel"), N_("Reset Windows"), 0 }; int x = width; for (const char **curBtn = buttonNames; *curBtn; ++curBtn) { - Button *btn = new Button(*curBtn, *curBtn, this); + Button *btn = new Button(gettext(*curBtn), *curBtn, this); x -= btn->getWidth() + 5; btn->setPosition(x, height - btn->getHeight() - 5); add(btn); @@ -74,23 +76,23 @@ Setup::Setup(): SetupTab *tab; tab = new Setup_Video(); - panel->addTab(tab, "Video"); + panel->addTab(tab, _("Video")); mTabs.push_back(tab); tab = new Setup_Audio(); - panel->addTab(tab, "Audio"); + panel->addTab(tab, _("Audio")); mTabs.push_back(tab); tab = new Setup_Joystick(); - panel->addTab(tab, "Joystick"); + panel->addTab(tab, _("Joystick")); mTabs.push_back(tab); tab = new Setup_Keyboard(); - panel->addTab(tab, "Keyboard"); + panel->addTab(tab, _("Keyboard")); mTabs.push_back(tab); tab = new Setup_Players(); - panel->addTab(tab, "Players"); + panel->addTab(tab, _("Players")); mTabs.push_back(tab); add(panel); diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index a027e133..c595edc9 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -31,18 +31,20 @@ #include "../log.h" #include "../sound.h" +#include "../utils/gettext.h" + Setup_Audio::Setup_Audio(): mMusicVolume((int)config.getValue("musicVolume", 60)), mSfxVolume((int)config.getValue("sfxVolume", 100)), mSoundEnabled(config.getValue("sound", 0)), - mSoundCheckBox(new CheckBox("Sound", mSoundEnabled)), + mSoundCheckBox(new CheckBox(_("Sound"), mSoundEnabled)), mSfxSlider(new Slider(0, 128)), mMusicSlider(new Slider(0, 128)) { setOpaque(false); - gcn::Label *sfxLabel = new gcn::Label("Sfx volume"); - gcn::Label *musicLabel = new gcn::Label("Music volume"); + gcn::Label *sfxLabel = new gcn::Label(_("Sfx volume")); + gcn::Label *musicLabel = new gcn::Label(_("Music volume")); mSfxSlider->setActionEventId("sfx"); mMusicSlider->setActionEventId("music"); diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index c59068f7..a718f87e 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -28,12 +28,14 @@ #include "../configuration.h" #include "../joystick.h" +#include "../utils/gettext.h" + extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): - mCalibrateLabel(new gcn::Label("Press the button to start calibration")), - mCalibrateButton(new Button("Calibrate", "calibrate", this)), - mJoystickEnabled(new CheckBox("Enable joystick")) + mCalibrateLabel(new gcn::Label(_("Press the button to start calibration"))), + mCalibrateButton(new Button(_("Calibrate"), "calibrate", this)), + mJoystickEnabled(new CheckBox(_("Enable joystick"))) { setOpaque(false); mJoystickEnabled->setPosition(10, 10); @@ -63,13 +65,13 @@ void Setup_Joystick::action(const gcn::ActionEvent &event) else { if (joystick->isCalibrating()) { - mCalibrateButton->setCaption("Calibrate"); - mCalibrateLabel->setCaption( - "Press the button to start calibration"); + mCalibrateButton->setCaption(_("Calibrate")); + mCalibrateLabel->setCaption + (_("Press the button to start calibration")); joystick->finishCalibration(); } else { - mCalibrateButton->setCaption("Stop"); - mCalibrateLabel->setCaption("Rotate the stick"); + mCalibrateButton->setCaption(_("Stop")); + mCalibrateLabel->setCaption(_("Rotate the stick")); joystick->startCalibration(); } } diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 54169b63..0debe163 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -43,6 +43,7 @@ #include "../main.h" #include "../particle.h" +#include "../utils/gettext.h" #include "../utils/tostring.h" extern Graphics *graphics; @@ -108,11 +109,11 @@ Setup_Video::Setup_Video(): mFps((int) config.getValue("fpslimit", 0)), mModeListModel(new ModeListModel), mModeList(new ListBox(mModeListModel)), - mFsCheckBox(new CheckBox("Full screen", mFullScreenEnabled)), - mOpenGLCheckBox(new CheckBox("OpenGL", mOpenGLEnabled)), - mCustomCursorCheckBox(new CheckBox("Custom cursor", mCustomCursorEnabled)), + mFsCheckBox(new CheckBox(_("Full screen"), mFullScreenEnabled)), + mOpenGLCheckBox(new CheckBox(_("OpenGL"), mOpenGLEnabled)), + mCustomCursorCheckBox(new CheckBox(_("Custom cursor"), mCustomCursorEnabled)), mAlphaSlider(new Slider(0.2, 1.0)), - mFpsCheckBox(new CheckBox("FPS Limit: ")), + mFpsCheckBox(new CheckBox(_("FPS Limit:"))), mFpsSlider(new Slider(10, 200)), mFpsField(new TextField), mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 16)), @@ -131,7 +132,7 @@ Setup_Video::Setup_Video(): setOpaque(false); ScrollArea *scrollArea = new ScrollArea(mModeList); - gcn::Label *alphaLabel = new gcn::Label("Gui opacity"); + gcn::Label *alphaLabel = new gcn::Label(_("Gui opacity")); mModeList->setEnabled(false); #ifndef USE_OPENGL @@ -188,7 +189,7 @@ Setup_Video::Setup_Video(): mParticleDetailField->addKeyListener(this); mScrollRadiusSlider->setDimension(gcn::Rectangle(10, 120, 75, 10)); - gcn::Label *scrollRadiusLabel = new gcn::Label("Scroll radius"); + gcn::Label *scrollRadiusLabel = new gcn::Label(_("Scroll radius")); scrollRadiusLabel->setPosition(90, 120); mScrollRadiusField->setPosition(mFpsField->getX(), 120); mScrollRadiusField->setWidth(30); @@ -196,7 +197,7 @@ Setup_Video::Setup_Video(): mScrollRadiusSlider->setValue(mOriginalScrollRadius); mScrollLazinessSlider->setDimension(gcn::Rectangle(10, 140, 75, 10)); - gcn::Label *scrollLazinessLabel = new gcn::Label("Scroll laziness"); + gcn::Label *scrollLazinessLabel = new gcn::Label(_("Scroll laziness")); scrollLazinessLabel->setPosition(90, 140); mScrollLazinessField->setPosition(mFpsField->getX(), 140); mScrollLazinessField->setWidth(30); @@ -204,42 +205,42 @@ Setup_Video::Setup_Video(): mScrollLazinessSlider->setValue(mOriginalScrollLaziness); mOverlayDetailSlider->setDimension(gcn::Rectangle(10, 160, 75, 10)); - gcn::Label *overlayDetailLabel = new gcn::Label("Ambient FX"); + gcn::Label *overlayDetailLabel = new gcn::Label(_("Ambient FX")); overlayDetailLabel->setPosition(90, 160); mOverlayDetailField->setPosition(180, 160); mOverlayDetailField->setWidth(30); switch (mOverlayDetail) { case 0: - mOverlayDetailField->setCaption("off"); + mOverlayDetailField->setCaption(_("off")); break; case 1: - mOverlayDetailField->setCaption("low"); + mOverlayDetailField->setCaption(_("low")); break; case 2: - mOverlayDetailField->setCaption("high"); + mOverlayDetailField->setCaption(_("high")); break; } mOverlayDetailSlider->setValue(mOverlayDetail); mParticleDetailSlider->setDimension(gcn::Rectangle(10, 180, 75, 10)); - gcn::Label *particleDetailLabel = new gcn::Label("Particle Detail"); + gcn::Label *particleDetailLabel = new gcn::Label(_("Particle Detail")); particleDetailLabel->setPosition(90, 180); mParticleDetailField->setPosition(180, 180); mParticleDetailField->setWidth(60); switch (mParticleDetail) { case 0: - mParticleDetailField->setCaption("low"); + mParticleDetailField->setCaption(_("low")); break; case 1: - mParticleDetailField->setCaption("medium"); + mParticleDetailField->setCaption(_("medium")); break; case 2: - mParticleDetailField->setCaption("high"); + mParticleDetailField->setCaption(_("high")); break; case 3: - mParticleDetailField->setCaption("max"); + mParticleDetailField->setCaption(_("max")); break; } mParticleDetailSlider->setValue(mParticleDetail); @@ -305,8 +306,8 @@ void Setup_Video::apply() } #ifdef WIN32 } else { - new OkDialog("Switching to full screen", - "Restart needed for changes to take effect."); + new OkDialog(_("Switching to full screen"), + _("Restart needed for changes to take effect.")); } #endif config.setValue("screen", fullscreen ? 1 : 0); @@ -318,8 +319,8 @@ void Setup_Video::apply() config.setValue("opengl", mOpenGLCheckBox->isSelected() ? 1 : 0); // OpenGL can currently only be changed by restarting, notify user. - new OkDialog("Changing OpenGL", - "Applying change to OpenGL requires restart."); + new OkDialog(_("Changing OpenGL"), + _("Applying change to OpenGL requires restart.")); } // FPS change @@ -408,13 +409,13 @@ void Setup_Video::action(const gcn::ActionEvent &event) switch (val) { case 0: - mOverlayDetailField->setCaption("off"); + mOverlayDetailField->setCaption(_("off")); break; case 1: - mOverlayDetailField->setCaption("low"); + mOverlayDetailField->setCaption(_("low")); break; case 2: - mOverlayDetailField->setCaption("high"); + mOverlayDetailField->setCaption(_("high")); break; } config.setValue("OverlayDetail", val); @@ -425,16 +426,16 @@ void Setup_Video::action(const gcn::ActionEvent &event) switch (val) { case 0: - mParticleDetailField->setCaption("low"); + mParticleDetailField->setCaption(_("low")); break; case 1: - mParticleDetailField->setCaption("medium"); + mParticleDetailField->setCaption(_("medium")); break; case 2: - mParticleDetailField->setCaption("high"); + mParticleDetailField->setCaption(_("high")); break; case 3: - mParticleDetailField->setCaption("max"); + mParticleDetailField->setCaption(_("max")); break; } config.setValue("particleEmitterSkip", 3 - val); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 9347cc02..9b88b6fb 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -41,6 +41,8 @@ #include "../resources/iteminfo.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/tostring.h" TradeWindow::TradeWindow(Network *network): @@ -56,10 +58,10 @@ TradeWindow::TradeWindow(Network *network): setMinWidth(342); setMinHeight(209); - mAddButton = new Button("Add", "add", this); - mOkButton = new Button("Ok", "ok", this); - mCancelButton = new Button("Cancel", "cancel", this); - mTradeButton = new Button("Trade", "trade", this); + mAddButton = new Button(_("Add"), "add", this); + mOkButton = new Button(_("Ok"), "ok", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); + mTradeButton = new Button(_("Trade"), "trade", this); mMyItemContainer = new ItemContainer(mMyInventory.get()); mMyItemContainer->addSelectionListener(this); @@ -75,8 +77,8 @@ TradeWindow::TradeWindow(Network *network): mPartnerScroll = new ScrollArea(mPartnerItemContainer); mPartnerScroll->setPosition(8, 64); - mMoneyLabel = new gcn::Label("You get: 0 GP"); - mMoneyLabel2 = new gcn::Label("You give:"); + mMoneyLabel = new gcn::Label(strprintf(_("You get %d GP."), 0)); + mMoneyLabel2 = new gcn::Label(_("You give:")); mMoneyField = new TextField; mMoneyField->setWidth(50); @@ -87,8 +89,9 @@ TradeWindow::TradeWindow(Network *network): mTradeButton->setEnabled(false); - mItemNameLabel = new gcn::Label("Name:"); - mItemDescriptionLabel = new gcn::Label("Description:"); + mItemNameLabel = new gcn::Label(strprintf(_("Name: %s"), "")); + mItemDescriptionLabel = new gcn::Label( + strprintf(_("Description: %s"), "")); add(mMyScroll); add(mPartnerScroll); @@ -150,7 +153,7 @@ void TradeWindow::widgetResized(const gcn::Event &event) void TradeWindow::addMoney(int amount) { - mMoneyLabel->setCaption("You get: " + toString(amount) + " GP"); + mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); mMoneyLabel->adjustSize(); } @@ -198,7 +201,7 @@ void TradeWindow::reset() mOkButton->setEnabled(true); mOkOther = false; mOkMe = false; - mMoneyLabel->setCaption("You get: 0 GP"); + mMoneyLabel->setCaption(strprintf(_("You get %d GP."), 0)); mMoneyField->setEnabled(true); mMoneyField->setText(""); } @@ -257,21 +260,11 @@ void TradeWindow::valueChanged(const gcn::SelectionEvent &event) } // Update name and description - if (!item) - { - mItemNameLabel->setCaption("Name:"); - mItemDescriptionLabel->setCaption("Description:"); - } - else - { - std::string SomeText; - SomeText = "Name: " + item->getInfo().getName(); - mItemNameLabel->setCaption(SomeText); - mItemNameLabel->adjustSize(); - SomeText = "Description: " + item->getInfo().getDescription(); - mItemDescriptionLabel->setCaption(SomeText); - mItemDescriptionLabel->adjustSize(); - } + ItemInfo const *info = item ? &item->getInfo() : NULL; + mItemNameLabel->setCaption(strprintf(_("Name: %s"), + info ? info->getName().c_str() : "")); + mItemDescriptionLabel->setCaption(strprintf(_("Description: %s"), + info ? info->getDescription().c_str() : "")); } void TradeWindow::action(const gcn::ActionEvent &event) diff --git a/src/main.cpp b/src/main.cpp index 83686749..09a1a41d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -84,6 +84,7 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" +#include "utils/gettext.h" #include "utils/tostring.h" namespace { @@ -267,7 +268,7 @@ void init_engine(const Options &options) // Add the user's homedir to PhysicsFS search path resman->addToSearchPath(homeDir, false); - // Add the main data directory to our PhysicsFS search path + // Add the main data directories to our PhysicsFS search path if (!options.dataPath.empty()) { resman->addToSearchPath(options.dataPath, true); } @@ -646,6 +647,7 @@ void mapLogin(Network *network, LoginData *loginData) } // namespace +extern "C" char const *_nl_locale_name_default(void); /** Main */ int main(int argc, char *argv[]) @@ -666,6 +668,16 @@ int main(int argc, char *argv[]) printVersion(); return 0; } + +#if ENABLE_NLS +#ifdef WIN32 + putenv(("LANG=" + std::string(_nl_locale_name_default())).c_str()); +#endif + setlocale(LC_MESSAGES, ""); + bindtextdomain("tmw", LOCALEDIR); + textdomain("tmw"); +#endif + // Initialize libxml2 and check for potential ABI mismatches between // compiled version and the shared library actually used. xmlInitParser(); diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 8fd60110..4b3024a7 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -30,6 +30,7 @@ #include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" #include "../utils/xml.h" namespace @@ -93,9 +94,9 @@ void ItemDB::load() if (id) { - ItemInfo *itemInfo = new ItemInfo(); + ItemInfo *itemInfo = new ItemInfo; itemInfo->setImageName(image); - itemInfo->setName((name == "") ? "Unnamed" : name); + itemInfo->setName(name.empty() ? _("Unnamed") : name); itemInfo->setDescription(description); itemInfo->setEffect(effect); itemInfo->setType(type); diff --git a/src/utils/gettext.h b/src/utils/gettext.h new file mode 100644 index 00000000..0cd9114b --- /dev/null +++ b/src/utils/gettext.h @@ -0,0 +1,44 @@ +/* + * The Mana World + * Copyright 2007 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 + */ + +#ifndef _TMW_UTILS_GETTEXT_H +#define _TMW_UTILS_GETTEXT_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if ENABLE_NLS + +#include + +#define _(s) ((char const *)gettext(s)) +#define N_(s) ((char const *)s) + +#else + +#define gettext(s) ((char const *)s) +#define _(s) ((char const *)s) +#define N_(s) ((char const *)s) + +#endif + +#endif -- cgit v1.2.3-70-g09d2 From 6b60673b0805fbab747924d1a0b6d9c66fc96f64 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Tue, 6 Jan 2009 14:33:20 +0100 Subject: Added support for animated tiles. --- src/map.cpp | 51 ++++++++++++++++++++++++- src/map.h | 40 +++++++++++++++++++- src/resources/mapreader.cpp | 90 +++++++++++++++++++++++++++++++++------------ src/utils/gettext.h | 44 ++++++++++++++++++++++ 4 files changed, 199 insertions(+), 26 deletions(-) create mode 100644 src/utils/gettext.h (limited to 'src') diff --git a/src/map.cpp b/src/map.cpp index 6170adef..abe87dfd 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -62,6 +62,34 @@ struct Location MetaTile *tile; }; +TileAnimation::TileAnimation(Animation *ani): + mAnimation(ani), + mLastUpdate(tick_time), + mLastImage(NULL) +{ +} + +void TileAnimation::update() +{ + //update animation + mAnimation.update(tick_time - mLastUpdate); + mLastUpdate = tick_time; + + // exchange images + Image *img = mAnimation.getCurrentImage(); + if (img != mLastImage) + { + for (std::list >::iterator i = mAffected.begin(); + i != mAffected.end(); + i++) + { + i->first->setTile(i->second, img); + } + mLastImage = img; + } + +} + MapLayer::MapLayer(int x, int y, int width, int height, bool isFringeLayer): mX(x), mY(y), mWidth(width), mHeight(height), @@ -79,7 +107,7 @@ MapLayer::~MapLayer() void MapLayer::setTile(int x, int y, Image *img) { - mTiles[x + y * mWidth] = img; + setTile(x + y * mWidth, img); } Image* MapLayer::getTile(int x, int y) const @@ -155,6 +183,7 @@ Map::~Map() delete_all(mLayers); delete_all(mTilesets); delete_all(mOverlays); + delete_all(mTileAnimations); } void Map::initializeOverlays() @@ -216,6 +245,15 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) // Make sure sprites are sorted mSprites.sort(spriteCompare); + //update animated tiles + for (std::map::iterator iAni = mTileAnimations.begin(); + iAni != mTileAnimations.end(); + iAni++) + { + iAni->second->update(); + } + + // draw the game world Layers::const_iterator layeri = mLayers.begin(); for (; layeri != mLayers.end(); ++layeri) { (*layeri)->draw(graphics, @@ -516,3 +554,14 @@ void Map::initializeParticleEffects(Particle* particleEngine) particleEngine->addEffect(i->file, i->x, i->y); } } + +TileAnimation* Map::getAnimationForGid(int gid) +{ + std::map::iterator i = mTileAnimations.find(gid); + if (i == mTileAnimations.end()) + { + return NULL; + } else { + return i->second; + } +} diff --git a/src/map.h b/src/map.h index 56183abf..81d0b629 100644 --- a/src/map.h +++ b/src/map.h @@ -28,6 +28,8 @@ #include "position.h" #include "properties.h" +#include "simpleanimation.h" + class AmbientOverlay; class Graphics; class Image; @@ -63,6 +65,23 @@ struct MetaTile bool walkable; /**< Can beings walk on this tile */ }; +/** + * Animation cycle of a tile image which changes the map accordingly. + */ +class TileAnimation +{ + public: + TileAnimation(Animation *ani); + void update(); + void addAffectedTile(MapLayer *layer, int index) + { mAffected.push_back(std::make_pair(layer, index)); } + private: + std::list > mAffected; + SimpleAnimation mAnimation; + int mLastUpdate; + Image* mLastImage; +}; + /** * A map layer. Stores a grid of tiles and their offset, and implements layer * rendering. @@ -87,6 +106,11 @@ class MapLayer */ void setTile(int x, int y, Image *img); + /** + * Set tile image with x + y * width already known. + */ + void setTile(int index, Image *img) { mTiles[index] = img; } + /** * Get tile image, with x and y in layer coordinates. */ @@ -225,8 +249,18 @@ class Map : public Properties /** * Initializes all added particle effects */ - void - initializeParticleEffects(Particle* particleEngine); + void initializeParticleEffects(Particle* particleEngine); + + /** + * Adds a tile animation to the map + */ + void addAnimation(int gid, TileAnimation *animation) + { mTileAnimations[gid] = animation; } + + /** + * Gets the tile animation for a specific gid + */ + TileAnimation *getAnimationForGid(int gid); private: /** @@ -270,6 +304,8 @@ class Map : public Properties int y; }; std::list particleEffects; + + std::map mTileAnimations; }; #endif diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 835e52b3..4e116889 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -304,7 +304,8 @@ void MapReader::readProperties(xmlNodePtr node, Properties *props) static void setTile(Map *map, MapLayer *layer, int x, int y, int gid) { const Tileset * const set = map->getTilesetWithGid(gid); - if (layer) { + if (layer) + { // Set regular tile on a layer Image * const img = set ? set->get(gid - set->getFirstGid()) : 0; layer->setTile(x, y, img); @@ -407,6 +408,12 @@ void MapReader::readLayer(xmlNodePtr node, Map *map) setTile(map, layer, x, y, gid); + TileAnimation* ani = map->getAnimationForGid(gid); + if (ani) + { + ani->addAffectedTile(layer, x + y * w); + } + x++; if (x == w) { x = 0; y++; @@ -452,10 +459,12 @@ Tileset *MapReader::readTileset(xmlNodePtr node, const std::string &path, Map *map) { + Tileset *set = NULL; + if (xmlHasProp(node, BAD_CAST "source")) { logger->log("Warning: External tilesets not supported yet."); - return NULL; + return set; } const int firstGid = XML::getProperty(node, "firstgid", 0); @@ -464,34 +473,69 @@ Tileset *MapReader::readTileset(xmlNodePtr node, for_each_xml_child_node(childNode, node) { - if (!xmlStrEqual(childNode->name, BAD_CAST "image")) - continue; + if (xmlStrEqual(childNode->name, BAD_CAST "image")) + { + const std::string source = XML::getProperty(childNode, "source", ""); - const std::string source = XML::getProperty(childNode, "source", ""); + if (!source.empty()) + { + std::string sourceStr = source; + sourceStr.erase(0, 3); // Remove "../" + + ResourceManager *resman = ResourceManager::getInstance(); + Image* tilebmp = resman->getImage(sourceStr); - if (!source.empty()) + if (tilebmp) + { + set = new Tileset(tilebmp, tw, th, firstGid); + tilebmp->decRef(); + } + else { + logger->log("Warning: Failed to load tileset (%s)", + source.c_str()); + } + } + } + else if (xmlStrEqual(childNode->name, BAD_CAST "tile")) { - std::string sourceStr = source; - sourceStr.erase(0, 3); // Remove "../" + for_each_xml_child_node(tileNode, childNode) + { + if (!xmlStrEqual(tileNode->name, BAD_CAST "properties")) continue; - ResourceManager *resman = ResourceManager::getInstance(); - Image* tilebmp = resman->getImage(sourceStr); + int tileGID = firstGid + XML::getProperty(childNode, "id", 0); - if (tilebmp) - { - Tileset *set = new Tileset(tilebmp, tw, th, firstGid); - tilebmp->decRef(); - return set; - } - else { - logger->log("Warning: Failed to load tileset (%s)", - source.c_str()); + // read tile properties to a map for simpler handling + std::map tileProperties; + for_each_xml_child_node(propertyNode, tileNode) + { + if (!xmlStrEqual(propertyNode->name, BAD_CAST "property")) continue; + std::string name = XML::getProperty(propertyNode, "name", ""); + int value = XML::getProperty(propertyNode, "value", 0); + tileProperties[name] = value; + logger->log("Tile Prop of %d \"%s\" = \"%d\"", tileGID, name.c_str(), value); + } + + // create animation + if (!set) continue; + + Animation *ani = new Animation(); + for (int i = 0; ;i++) + { + std::map::iterator iFrame, iDelay; + iFrame = tileProperties.find("animation-frame" + toString(i)); + iDelay = tileProperties.find("animation-delay" + toString(i)); + if (iFrame != tileProperties.end() && iDelay != tileProperties.end()) + { + ani->addFrame(set->get(iFrame->second), iDelay->second, 0, 0); + } else { + break; + } + } + map->addAnimation(tileGID, new TileAnimation(ani)); + logger->log("Animation length: %d", ani->getLength()); } } - - // Only one image element expected - break; } - return NULL; + return set; } diff --git a/src/utils/gettext.h b/src/utils/gettext.h new file mode 100644 index 00000000..0cd9114b --- /dev/null +++ b/src/utils/gettext.h @@ -0,0 +1,44 @@ +/* + * The Mana World + * Copyright 2007 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 + */ + +#ifndef _TMW_UTILS_GETTEXT_H +#define _TMW_UTILS_GETTEXT_H + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#if ENABLE_NLS + +#include + +#define _(s) ((char const *)gettext(s)) +#define N_(s) ((char const *)s) + +#else + +#define gettext(s) ((char const *)s) +#define _(s) ((char const *)s) +#define N_(s) ((char const *)s) + +#endif + +#endif -- cgit v1.2.3-70-g09d2 From 9219f1ffd4b05886b66c9074c918850fc97c430c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 6 Jan 2009 17:50:52 +0100 Subject: Merged layout handler from mainline Also fixed login dialog layout. This is the layout handler by Guillaume Melquiond, which he started in commit 59472ef68fdef3f7e8858a81a46e28c127119c58. --- src/CMakeLists.txt | 2 + src/Makefile.am | 4 +- src/gui/login.cpp | 59 +++----- src/gui/popupmenu.cpp | 2 +- src/gui/widgets/layout.cpp | 327 +++++++++++++++++++++++++++++++++++++++++++++ src/gui/widgets/layout.h | 320 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.cpp | 85 +++++++----- src/gui/window.h | 64 +++++---- 8 files changed, 759 insertions(+), 104 deletions(-) create mode 100644 src/gui/widgets/layout.cpp create mode 100644 src/gui/widgets/layout.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 666a675d..0a01f925 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -51,6 +51,8 @@ MARK_AS_ADVANCED(SDL_LIBRARY) SET(SRCS gui/widgets/resizegrip.cpp gui/widgets/resizegrip.h + gui/widgets/layout.cpp + gui/widgets/layout.h gui/box.cpp gui/box.h gui/browserbox.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c924760f..a366e9b3 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -1,7 +1,9 @@ AUTOMAKE_OPTIONS = subdir-objects bin_PROGRAMS = tmw -tmw_SOURCES = gui/widgets/resizegrip.cpp \ +tmw_SOURCES = gui/widgets/layout.cpp \ + gui/widgets/layout.h \ + gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ gui/box.h \ gui/box.cpp \ diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 5a748b52..db81c683 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -34,6 +34,8 @@ #include "passwordfield.h" #include "textfield.h" +#include "widgets/layout.h" + #include "../utils/gettext.h" LoginDialog::LoginDialog(LoginData *loginData): @@ -50,33 +52,6 @@ LoginDialog::LoginDialog(LoginData *loginData): mCancelButton = new Button(_("Cancel"), "cancel", this); mRegisterButton = new Button(_("Register"), "register", this); - const int width = 250; - const int height = 100; - - setContentSize(width, height); - - userLabel->setPosition(5, 5); - passLabel->setPosition(5, 14 + userLabel->getHeight()); - serverLabel->setPosition( - 5, 23 + userLabel->getHeight() + passLabel->getHeight()); - mUserField->setPosition(65, 5); - mPassField->setPosition(65, 14 + userLabel->getHeight()); - mServerField->setPosition( - 65, 23 + userLabel->getHeight() + passLabel->getHeight()); - mUserField->setWidth(width - 70); - mPassField->setWidth(width - 70); - mServerField->setWidth(width - 70); - mKeepCheck->setPosition(4, 77); - mCancelButton->setPosition( - width - mCancelButton->getWidth() - 5, - height - mCancelButton->getHeight() - 5); - mOkButton->setPosition( - mCancelButton->getX() - mOkButton->getWidth() - 5, - height - mOkButton->getHeight() - 5); - mRegisterButton->setPosition( - mKeepCheck->getX() + mKeepCheck->getWidth() + 10, - height - mRegisterButton->getHeight() - 5); - mUserField->setActionEventId("ok"); mPassField->setActionEventId("ok"); mServerField->setActionEventId("ok"); @@ -89,16 +64,17 @@ LoginDialog::LoginDialog(LoginData *loginData): mServerField->addActionListener(this); mKeepCheck->addActionListener(this); - add(userLabel); - add(passLabel); - add(serverLabel); - add(mUserField); - add(mPassField); - add(mServerField); - add(mKeepCheck); - add(mOkButton); - add(mCancelButton); - add(mRegisterButton); + place(0, 0, userLabel); + place(0, 1, passLabel); + place(0, 2, serverLabel); + place(1, 0, mUserField, 3).setPadding(2); + place(1, 1, mPassField, 3).setPadding(2); + place(1, 2, mServerField, 3).setPadding(2); + place(0, 3, mKeepCheck, 4); + place(0, 4, mRegisterButton).setHAlign(LayoutCell::LEFT); + place(2, 4, mOkButton); + place(3, 4, mCancelButton); + reflowLayout(250, 0); setLocationRelativeTo(getParent()); setVisible(true); @@ -116,8 +92,7 @@ LoginDialog::~LoginDialog() { } -void -LoginDialog::action(const gcn::ActionEvent &event) +void LoginDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok" && canSubmit()) { @@ -147,14 +122,12 @@ LoginDialog::action(const gcn::ActionEvent &event) } } -void -LoginDialog::keyPressed(gcn::KeyEvent &keyEvent) +void LoginDialog::keyPressed(gcn::KeyEvent &keyEvent) { mOkButton->setEnabled(canSubmit()); } -bool -LoginDialog::canSubmit() +bool LoginDialog::canSubmit() { return !mUserField->getText().empty() && !mPassField->getText().empty() && diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index bfa75ef9..1f5b3556 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -55,7 +55,7 @@ PopupMenu::PopupMenu(): { setResizable(false); setTitleBarHeight(0); - mShowTitle = false; + setShowTitle(false); mBrowserBox = new BrowserBox(); mBrowserBox->setPosition(4, 4); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp new file mode 100644 index 00000000..bcc54cf7 --- /dev/null +++ b/src/gui/widgets/layout.cpp @@ -0,0 +1,327 @@ +/* + * The Mana World + * Copyright 2007 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 + */ + +#include + +#include "layout.h" + +ContainerPlacer ContainerPlacer::at(int x, int y) +{ + return ContainerPlacer(mContainer, &mCell->at(x, y)); +} + +LayoutCell &ContainerPlacer::operator() + (int x, int y, gcn::Widget *wg, int w, int h) +{ + mContainer->add(wg); + return mCell->place(wg, x, y, w, h); +} + +LayoutCell::~LayoutCell() +{ + if (mType == ARRAY) delete mArray; +} + +LayoutArray &LayoutCell::getArray() +{ + assert(mType != WIDGET); + if (mType == ARRAY) return *mArray; + mArray = new LayoutArray; + mType = ARRAY; + mExtent[0] = 1; + mExtent[1] = 1; + mPadding = 0; + mAlign[0] = FILL; + mAlign[1] = FILL; + return *mArray; +} + +void LayoutCell::reflow(int nx, int ny, int nw, int nh) +{ + assert(mType != NONE); + nx += mPadding; + ny += mPadding; + nw -= 2 * mPadding; + nh -= 2 * mPadding; + if (mType == ARRAY) + mArray->reflow(nx, ny, nw, nh); + else + mWidget->setDimension(gcn::Rectangle(nx, ny, nw, nh)); +} + +void LayoutCell::computeSizes() +{ + assert(mType == ARRAY); + + for (std::vector< std::vector< LayoutCell * > >::iterator + i = mArray->mCells.begin(), i_end = mArray->mCells.end(); + i != i_end; ++i) + { + for (std::vector< LayoutCell * >::iterator + j = i->begin(), j_end = i->end(); j != j_end; ++j) + { + LayoutCell *cell = *j; + if (cell && cell->mType == ARRAY) cell->computeSizes(); + } + } + + mSize[0] = mArray->getSize(0); + mSize[1] = mArray->getSize(1); +} + +LayoutArray::LayoutArray(): mSpacing(4) +{ +} + +LayoutArray::~LayoutArray() +{ + for (std::vector< std::vector< LayoutCell * > >::iterator + i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) + { + for (std::vector< LayoutCell * >::iterator + j = i->begin(), j_end = i->end(); j != j_end; ++j) + { + delete *j; + } + } +} + +LayoutCell &LayoutArray::at(int x, int y, int w, int h) +{ + resizeGrid(x + w, y + h); + LayoutCell *&cell = mCells[y][x]; + if (!cell) + { + cell = new LayoutCell; + } + return *cell; +} + +void LayoutArray::resizeGrid(int w, int h) +{ + bool extW = w && w > (int)mSizes[0].size(), + extH = h && h > (int)mSizes[1].size(); + if (!extW && !extH) return; + + if (extH) + { + mSizes[1].resize(h, Layout::AUTO_DEF); + mCells.resize(h); + if (!extW) w = mSizes[0].size(); + } + + if (extW) + { + mSizes[0].resize(w, Layout::AUTO_DEF); + } + + for (std::vector< std::vector< LayoutCell * > >::iterator + i = mCells.begin(), i_end = mCells.end(); i != i_end; ++i) + { + i->resize(w, NULL); + } +} + +void LayoutArray::setColWidth(int n, int w) +{ + resizeGrid(n + 1, 0); + mSizes[0][n] = w; +} + +void LayoutArray::setRowHeight(int n, int h) +{ + resizeGrid(0, n + 1); + mSizes[1][n] = h; +} + +void LayoutArray::matchColWidth(int n1, int n2) +{ + resizeGrid(std::max(n1, n2) + 1, 0); + std::vector< short > widths = getSizes(0, Layout::AUTO_DEF); + int s = std::max(widths[n1], widths[n2]); + mSizes[0][n1] = s; + mSizes[0][n2] = s; +} + +void LayoutArray::extend(int x, int y, int w, int h) +{ + LayoutCell &cell = at(x, y, w, h); + cell.mExtent[0] = w; + cell.mExtent[1] = h; +} + +LayoutCell &LayoutArray::place(gcn::Widget *widget, int x, int y, int w, int h) +{ + LayoutCell &cell = at(x, y, w, h); + assert(cell.mType == LayoutCell::NONE); + cell.mType = LayoutCell::WIDGET; + cell.mWidget = widget; + cell.mSize[0] = w == 1 ? widget->getWidth() : 0; + cell.mSize[1] = h == 1 ? widget->getHeight() : 0; + cell.mExtent[0] = w; + cell.mExtent[1] = h; + cell.mPadding = 0; + cell.mAlign[0] = LayoutCell::FILL; + cell.mAlign[1] = LayoutCell::FILL; + short &cs = mSizes[0][x], &rs = mSizes[1][y]; + if (cs == Layout::AUTO_DEF && w == 1) cs = 0; + if (rs == Layout::AUTO_DEF && h == 1) rs = 0; + return cell; +} + +void LayoutArray::align(int &pos, int &size, int dim, + LayoutCell const &cell, short *sizes) const +{ + int size_max = sizes[0]; + for (int i = 1; i < cell.mExtent[dim]; ++i) + size_max += sizes[i] + mSpacing; + size = std::min(cell.mSize[dim], size_max); + + switch (cell.mAlign[dim]) + { + case LayoutCell::LEFT: + return; + case LayoutCell::RIGHT: + pos += size_max - size; + return; + case LayoutCell::CENTER: + pos += (size_max - size) / 2; + return; + case LayoutCell::FILL: + size = size_max; + return; + } +} + +std::vector< short > LayoutArray::getSizes(int dim, int upp) const +{ + int gridW = mSizes[0].size(), gridH = mSizes[1].size(); + std::vector< short > sizes = mSizes[dim]; + + // Compute minimum sizes. + for (int gridY = 0; gridY < gridH; ++gridY) + { + for (int gridX = 0; gridX < gridW; ++gridX) + { + LayoutCell const *cell = mCells[gridY][gridX]; + if (!cell || cell->mType == LayoutCell::NONE) continue; + + if (cell->mExtent[dim] == 1) + { + int n = dim == 0 ? gridX : gridY; + int s = cell->mSize[dim] + cell->mPadding * 2; + if (s > sizes[n]) sizes[n] = s; + } + } + } + + if (upp == Layout::AUTO_DEF) return sizes; + + // Compute the FILL sizes. + int nb = sizes.size(); + int nbFill = 0; + for (int i = 0; i < nb; ++i) + { + if (mSizes[dim][i] <= Layout::AUTO_DEF) + { + ++nbFill; + if (mSizes[dim][i] == Layout::AUTO_SET || + sizes[i] <= Layout::AUTO_DEF) + { + sizes[i] = 0; + } + } + upp -= sizes[i] + mSpacing; + } + upp = upp + mSpacing; + + if (nbFill == 0) return sizes; + + for (int i = 0; i < nb; ++i) + { + if (mSizes[dim][i] > Layout::AUTO_DEF) continue; + int s = upp / nbFill; + sizes[i] += s; + upp -= s; + --nbFill; + } + + return sizes; +} + +int LayoutArray::getSize(int dim) const +{ + std::vector< short > sizes = getSizes(dim, Layout::AUTO_DEF); + int size = 0; + int nb = sizes.size(); + for (int i = 0; i < nb; ++i) + { + if (sizes[i] > Layout::AUTO_DEF) size += sizes[i]; + size += mSpacing; + } + return size - mSpacing; +} + +void LayoutArray::reflow(int nx, int ny, int nw, int nh) +{ + int gridW = mSizes[0].size(), gridH = mSizes[1].size(); + + std::vector< short > widths = getSizes(0, nw); + std::vector< short > heights = getSizes(1, nh); + + int y = ny; + for (int gridY = 0; gridY < gridH; ++gridY) + { + int x = nx; + for (int gridX = 0; gridX < gridW; ++gridX) + { + LayoutCell *cell = mCells[gridY][gridX]; + if (cell && cell->mType != LayoutCell::NONE) + { + int dx = x, dy = y, dw, dh; + align(dx, dw, 0, *cell, &widths[gridX]); + align(dy, dh, 1, *cell, &heights[gridY]); + cell->reflow(dx, dy, dw, dh); + } + x += widths[gridX] + mSpacing; + } + y += heights[gridY] + mSpacing; + } +} + +Layout::Layout(): mComputed(false) +{ + getArray(); + setPadding(6); +} + +void Layout::reflow(int &nw, int &nh) +{ + if (!mComputed) + { + computeSizes(); + mComputed = true; + } + + nw = nw == 0 ? mSize[0] + 2 * mPadding : nw; + nh = nh == 0 ? mSize[1] + 2 * mPadding : nh; + LayoutCell::reflow(0, 0, nw, nh); +} diff --git a/src/gui/widgets/layout.h b/src/gui/widgets/layout.h new file mode 100644 index 00000000..d631c154 --- /dev/null +++ b/src/gui/widgets/layout.h @@ -0,0 +1,320 @@ +/* + * The Mana World + * Copyright 2007 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 + */ + +#ifndef _TMW_WIDGET_LAYOUT_H__ +#define _TMW_WIDGET_LAYOUT_H__ + +#include + +#include + +class LayoutCell; + +/** + * This class is a helper for adding widgets to nested tables in a window. + */ +class ContainerPlacer +{ + public: + + ContainerPlacer(gcn::Container *c = NULL, LayoutCell *l = NULL): + mContainer(c), mCell(l) + {} + + /** + * Gets the pointed cell. + */ + LayoutCell &getCell() + { return *mCell; } + + /** + * Returns a placer for the same container but to an inner cell. + */ + ContainerPlacer at(int x, int y); + + /** + * Adds the given widget to the container and places it in the layout. + * @see LayoutArray::place + */ + LayoutCell &operator() + (int x, int y, gcn::Widget *, int w = 1, int h = 1); + + private: + + gcn::Container *mContainer; + LayoutCell *mCell; +}; + +/** + * This class contains a rectangular array of cells. + */ +class LayoutArray +{ + friend class LayoutCell; + + public: + + LayoutArray(); + + ~LayoutArray(); + + /** + * Returns a reference on the cell at given position. + */ + LayoutCell &at(int x, int y, int w = 1, int h = 1); + + /** + * Places a widget in a given cell. + * @param w number of columns the widget spawns. + * @param h number of rows the widget spawns. + * @note When @a w is 1, the width of column @a x is reset to zero if + * it was AUTO_DEF. Similarly for @a h. + */ + LayoutCell &place(gcn::Widget *, int x, int y, int w = 1, int h = 1); + + /** + * Sets the minimum width of a column. + */ + void setColWidth(int n, int w); + + /** + * Sets the minimum height of a row. + */ + void setRowHeight(int n, int h); + + /** + * Sets the widths of two columns to the maximum of their widths. + */ + void matchColWidth(int n1, int n2); + + /** + * Spawns a cell over several columns/rows. + */ + void extend(int x, int y, int w, int h); + + /** + * Computes and sets the positions of all the widgets. + * @param nW width of the array, used to resize the AUTO_ columns. + * @param nH height of the array, used to resize the AUTO_ rows. + */ + void reflow(int nX, int nY, int nW, int nH); + + private: + + // Copy not allowed, as the array owns all its cells. + LayoutArray(LayoutArray const &); + LayoutArray &operator=(LayoutArray const &); + + /** + * Gets the position and size of a widget along a given axis + */ + void align(int &pos, int &size, int dim, + LayoutCell const &cell, short *sizes) const; + + /** + * Ensures the private vectors are large enough. + */ + void resizeGrid(int w, int h); + + /** + * Gets the column/row sizes along a given axis. + * @param upp target size for the array. Ignored if AUTO_DEF. + */ + std::vector< short > getSizes(int dim, int upp) const; + + /** + * Gets the total size along a given axis. + */ + int getSize(int dim) const; + + std::vector< short > mSizes[2]; + std::vector< std::vector < LayoutCell * > > mCells; + + char mSpacing; +}; + +/** + * This class describes the formatting of a widget in the cell of a layout + * table. Horizontally, a widget can either fill the width of the cell (minus + * the cell padding), or it can retain its size and be flushed left, or flush + * right, or centered in the cell. The process is similar for the vertical + * alignment, except that top is represented by LEFT and bottom by RIGHT. + */ +class LayoutCell +{ + friend class Layout; + friend class LayoutArray; + + public: + + enum Alignment + { + LEFT, RIGHT, CENTER, FILL + }; + + LayoutCell(): mType(NONE) {} + + ~LayoutCell(); + + /** + * Sets the padding around the cell content. + */ + LayoutCell &setPadding(int p) + { mPadding = p; return *this; } + + /** + * Sets the horizontal alignment of the cell content. + */ + LayoutCell &setHAlign(Alignment a) + { mAlign[0] = a; return *this; } + + /** + * Sets the vertical alignment of the cell content. + */ + LayoutCell &setVAlign(Alignment a) + { mAlign[1] = a; return *this; } + + /** + * @see LayoutArray::at + */ + LayoutCell &at(int x, int y) + { return getArray().at(x, y); } + + /** + * @see LayoutArray::place + */ + LayoutCell &place(gcn::Widget *wg, int x, int y, int w = 1, int h = 1) + { return getArray().place(wg, x, y, w, h); } + + /** + * @see LayoutArray::matchColWidth + */ + void matchColWidth(int n1, int n2) + { getArray().matchColWidth(n1, n2); } + + /** + * @see LayoutArray::setColWidth + */ + void setColWidth(int n, int w) + { getArray().setColWidth(n, w); } + + /** + * @see LayoutArray::setRowHeight + */ + void setRowHeight(int n, int h) + { getArray().setRowHeight(n, h); } + + /** + * @see LayoutArray::extend. + */ + void extend(int x, int y, int w, int h) + { getArray().extend(x, y, w, h); } + + /** + * Sets the minimum widths and heights of this cell and of all the + * inner cells. + */ + void computeSizes(); + + private: + + // Copy not allowed, as the cell may own an array. + LayoutCell(LayoutCell const &); + LayoutCell &operator=(LayoutCell const &); + + union + { + gcn::Widget *mWidget; + LayoutArray *mArray; + }; + + enum + { + NONE, WIDGET, ARRAY + }; + + /** + * Returns the embedded array. Creates it if the cell does not contain + * anything yet. Aborts if it contains a widget. + */ + LayoutArray &getArray(); + + /** + * @see LayoutArray::reflow + */ + void reflow(int nx, int ny, int nw, int nh); + + short mSize[2]; + char mPadding; + char mExtent[2]; + char mAlign[2]; + char mNbFill[2]; + char mType; +}; + +/** + * This class is an helper for setting the position of widgets. They are + * positioned along the cells of some rectangular tables. The layout may either + * be a single table or a tree of nested tables. + * + * The size of a given table column can either be set manually or be chosen + * from the widest widget of the column. An empty column has a AUTO_DEF width, + * which means it will be extended so that the layout fits its minimum width. + * + * The process is similar for table rows. By default, there is a spacing of 4 + * pixels between rows and between columns, and a margin of 6 pixels around the + * whole layout. + */ +class Layout: public LayoutCell +{ + public: + + Layout(); + + /** + * Sets the margin around the layout. + */ + void setMargin(int m) + { setPadding(m); } + + /** + * Sets the positions of all the widgets. + * @see LayoutArray::reflow + */ + void reflow(int &nW, int &nH); + + /** + * When the minimum size of the layout is less than the available size, + * the remaining pixels are equally split amongst the FILL items. + */ + enum + { + AUTO_DEF = -42, /**< Default value, behaves like AUTO_ADD. */ + AUTO_SET = -43, /**< Uses the share as the new size. */ + AUTO_ADD = -44 /**< Adds the share to the current size. */ + }; + + private: + + bool mComputed; +}; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 630b4ddd..dfe7ac64 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -20,8 +20,8 @@ */ #include -#include #include +#include #include #include @@ -29,9 +29,9 @@ #include "window.h" #include "gui.h" -#include "gccontainer.h" #include "windowcontainer.h" +#include "widgets/layout.h" #include "widgets/resizegrip.h" #include "../configlistener.h" @@ -63,6 +63,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): gcn::Window(caption), mGrip(0), mParent(parent), + mLayout(NULL), mWindowName("window"), mShowTitle(true), mModal(modal), @@ -76,7 +77,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent): logger->log("Window::Window(\"%s\")", caption.c_str()); if (!windowContainer) { - throw GCN_EXCEPTION("Window::Window. no windowContainer set"); + throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); } if (instances == 0) @@ -108,11 +109,6 @@ Window::Window(const std::string& caption, bool modal, Window *parent): setPadding(3); setTitleBarHeight(20); - // Add chrome - mChrome = new GCContainer(); - mChrome->setOpaque(false); - gcn::Window::add(mChrome); - // Add this window to the window container windowContainer->add(this); @@ -145,6 +141,15 @@ Window::~Window() } } + delete mLayout; + + while (!mWidgets.empty()) + { + gcn::Widget *w = mWidgets.front(); + remove(w); + delete(w); + } + instances--; if (instances == 0) @@ -165,9 +170,6 @@ Window::~Window() delete border.grid[8]; closeImage->decRef(); } - - delete mChrome; - delete mGrip; } void Window::setWindowContainer(WindowContainer *wc) @@ -202,7 +204,6 @@ void Window::draw(gcn::Graphics *graphics) void Window::setContentSize(int width, int height) { - mChrome->setSize(width, height); setSize(width + 2 * getPadding(), height + getPadding() + getTitleBarHeight()); } @@ -248,10 +249,11 @@ void Window::setResizable(bool r) mGrip = new ResizeGrip(); mGrip->setX(getWidth() - mGrip->getWidth() - getChildrenArea().x); mGrip->setY(getHeight() - mGrip->getHeight() - getChildrenArea().y); - gcn::Window::add(mGrip); + add(mGrip); } else { + remove(mGrip); delete mGrip; mGrip = 0; } @@ -259,15 +261,19 @@ void Window::setResizable(bool r) void Window::widgetResized(const gcn::Event &event) { - const gcn::Rectangle area = getChildrenArea(); - - mChrome->setSize(area.width, area.height); - if (mGrip) { + const gcn::Rectangle area = getChildrenArea(); mGrip->setPosition(getWidth() - mGrip->getWidth() - area.x, getHeight() - mGrip->getHeight() - area.y); } + + if (mLayout) + { + int w = getWidth() - 2 * getPadding(); + int h = getHeight() - getPadding() - getTitleBarHeight(); + mLayout->reflow(w, h); + } } void Window::setCloseButton(bool flag) @@ -292,14 +298,7 @@ bool Window::isSticky() void Window::setVisible(bool visible) { - if (isSticky()) - { - gcn::Window::setVisible(true); - } - else - { - gcn::Window::setVisible(visible); - } + gcn::Window::setVisible(isSticky() || visible); } void Window::scheduleDelete() @@ -307,16 +306,6 @@ void Window::scheduleDelete() windowContainer->scheduleDelete(this); } -void Window::add(gcn::Widget *w) -{ - mChrome->add(w); -} - -void Window::add(gcn::Widget *w, int x, int y) -{ - mChrome->add(w, x, y); -} - void Window::mousePressed(gcn::MouseEvent &event) { // Let Guichan move window to top and figure out title bar drag @@ -535,3 +524,29 @@ int Window::getResizeHandles(gcn::MouseEvent &event) return resizeHandles; } + +Layout &Window::getLayout() +{ + if (!mLayout) mLayout = new Layout; + return *mLayout; +} + +LayoutCell &Window::place(int x, int y, gcn::Widget *wg, int w, int h) +{ + add(wg); + return getLayout().place(wg, x, y, w, h); +} + +ContainerPlacer Window::getPlacer(int x, int y) +{ + return ContainerPlacer(this, &getLayout().at(x, y)); +} + +void Window::reflowLayout(int w, int h) +{ + assert(mLayout); + mLayout->reflow(w, h); + delete mLayout; + mLayout = NULL; + setContentSize(w, h); +} diff --git a/src/gui/window.h b/src/gui/window.h index d40e8c91..a49788a5 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -28,11 +28,13 @@ #include "../guichanfwd.h" class ConfigListener; -class GCContainer; +class ContainerPlacer; +class Image; class ImageRect; +class Layout; +class LayoutCell; class ResizeGrip; class WindowContainer; -class Image; /** * A window. This window can be dragged around and has a title bar. Windows are @@ -59,7 +61,7 @@ class Window : public gcn::Window, gcn::WidgetListener Window *parent = NULL); /** - * Destructor. + * Destructor. Deletes all the added widgets. */ ~Window(); @@ -73,18 +75,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ void draw(gcn::Graphics *graphics); - /** - * Adds a widget to the window. The widget will be deleted by the - * window. - */ - void add(gcn::Widget *w); - - /** - * Adds a widget to the window and also specifices its position. The - * widget will be deleted by the window. - */ - void add(gcn::Widget *w, int x, int y); - /** * Sets the size of this window. */ @@ -217,21 +207,51 @@ class Window : public gcn::Window, gcn::WidgetListener * Don't forget to set these default values and resizable before * calling this function. */ - virtual void loadWindowState(); + void loadWindowState(); /** * Set the default win pos and size. * (which can be different of the actual ones.) */ - virtual void setDefaultSize(int defaultX, int defaultY, - int defaultWidth, int defaultHeight); + void setDefaultSize(int defaultX, int defaultY, + int defaultWidth, int defaultHeight); /** * Reset the win pos and size to default. Don't forget to set defaults * first. */ - virtual void resetToDefaultSize(); + void resetToDefaultSize(); + + /** + * Gets the layout handler for this window. + */ + Layout &getLayout(); + + /** + * Computes the position of the widgets according to the current + * layout. Resizes the window so that the layout fits. Deletes the + * layout. + * @param w if non-zero, force the window to this width. + * @param h if non-zero, force the window to this height. + * @note This function is meant to be called with fixed-size windows. + */ + void reflowLayout(int w = 0, int h = 0); + /** + * Adds a widget to the window and sets it at given cell. + */ + LayoutCell &place(int x, int y, gcn::Widget *, int w = 1, int h = 1); + + /** + * Returns a proxy for adding widgets in an inner table of the layout. + */ + ContainerPlacer getPlacer(int x, int y); + + protected: + /** The window container windows add themselves to. */ + static WindowContainer *windowContainer; + + private: enum ResizeHandles { TOP = 0x01, @@ -240,7 +260,6 @@ class Window : public gcn::Window, gcn::WidgetListener LEFT = 0x08 }; - protected: /** * Determines if the mouse is in a resize area and returns appropriate * resize handles. Also initializes drag offset in case the resize @@ -250,9 +269,9 @@ class Window : public gcn::Window, gcn::WidgetListener */ int getResizeHandles(gcn::MouseEvent &event); - GCContainer *mChrome; /**< Contained container */ ResizeGrip *mGrip; /**< Resize grip */ Window *mParent; /**< The parent window */ + Layout *mLayout; /**< Layout handler */ std::string mWindowName; /**< Name of the window */ bool mShowTitle; /**< Window has a title bar */ bool mModal; /**< Window is modal */ @@ -267,9 +286,6 @@ class Window : public gcn::Window, gcn::WidgetListener int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ - /** The window container windows add themselves to. */ - static WindowContainer *windowContainer; - /** * The config listener that listens to changes relevant to all windows. */ -- cgit v1.2.3-70-g09d2 From 705d753cd7e762095ae53a428ed277449d064fed Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 6 Jan 2009 21:35:19 +0100 Subject: Used layout for buy, sell and item amount dialogs (changes by Guillaume Melquiond, merged from the mainline client) --- src/gui/buy.cpp | 77 ++++++++++--------------------------------------- src/gui/buy.h | 8 +---- src/gui/item_amount.cpp | 59 +++++++++++++++++++------------------ src/gui/sell.cpp | 75 ++++++++++------------------------------------- src/gui/sell.h | 5 ---- 5 files changed, 61 insertions(+), 163 deletions(-) (limited to 'src') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c1e5a272..4d028ab3 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -29,6 +29,8 @@ #include "shoplistbox.h" #include "slider.h" +#include "widgets/layout.h" + #include "../npc.h" #include "../net/messageout.h" @@ -63,7 +65,6 @@ BuyDialog::BuyDialog(Network *network): mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); - mQuantityLabel->setWidth(60); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); @@ -71,22 +72,22 @@ BuyDialog::BuyDialog(Network *network): mBuyButton->setEnabled(false); mSlider->setEnabled(false); - mShopItemList->setActionEventId("item"); mSlider->setActionEventId("slider"); - - mShopItemList->addSelectionListener(this); mSlider->addActionListener(this); + mShopItemList->addSelectionListener(this); - add(mScrollArea); - add(mSlider); - add(mQuantityLabel); - add(mBuyButton); - add(mQuitButton); - add(mIncreaseButton); - add(mDecreaseButton); - add(mMoneyLabel); - add(mItemDescLabel); - add(mItemEffectLabel); + place(0, 0, mScrollArea, 5).setPadding(3); + place(0, 1, mQuantityLabel, 2); + place(2, 1, mSlider, 3); + place(0, 2, mMoneyLabel, 5); + place(0, 3, mItemEffectLabel, 5); + place(0, 4, mItemDescLabel, 5); + place(0, 5, mDecreaseButton); + place(1, 5, mIncreaseButton); + place(3, 5, mBuyButton); + place(4, 5, mQuitButton); + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); setLocationRelativeTo(getParent()); @@ -192,53 +193,7 @@ void BuyDialog::valueChanged(const gcn::SelectionEvent &event) mSlider->gcn::Slider::setScale(1, mMaxItems); } -void BuyDialog::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - const gcn::Rectangle &area = getChildrenArea(); - const int width = area.width; - const int height = area.height; - - mDecreaseButton->setPosition(8, height - 8 - mDecreaseButton->getHeight()); - mIncreaseButton->setPosition( - mDecreaseButton->getX() + mDecreaseButton->getWidth() + 5, - mDecreaseButton->getY()); - - mQuitButton->setPosition( - width - 8 - mQuitButton->getWidth(), - height - 8 - mQuitButton->getHeight()); - mBuyButton->setPosition( - mQuitButton->getX() - 5 - mBuyButton->getWidth(), - mQuitButton->getY()); - - mItemDescLabel->setDimension(gcn::Rectangle(8, - mBuyButton->getY() - 5 - mItemDescLabel->getHeight(), - width - 16, - mItemDescLabel->getHeight())); - mItemEffectLabel->setDimension(gcn::Rectangle(8, - mItemDescLabel->getY() - 5 - mItemEffectLabel->getHeight(), - width - 16, - mItemEffectLabel->getHeight())); - mMoneyLabel->setDimension(gcn::Rectangle(8, - mItemEffectLabel->getY() - 5 - mMoneyLabel->getHeight(), - width - 16, - mMoneyLabel->getHeight())); - - mQuantityLabel->setPosition( - width - mQuantityLabel->getWidth() - 8, - mMoneyLabel->getY() - 5 - mQuantityLabel->getHeight()); - mSlider->setDimension(gcn::Rectangle(8, - mQuantityLabel->getY(), - mQuantityLabel->getX() - 8 - 8, - 10)); - - mScrollArea->setDimension(gcn::Rectangle(8, 8, width - 16, - mSlider->getY() - 5 - 8)); -} - -void -BuyDialog::updateButtonsAndLabels() +void BuyDialog::updateButtonsAndLabels() { const int selectedItem = mShopItemList->getSelected(); int price = 0; diff --git a/src/gui/buy.h b/src/gui/buy.h index 0915385a..329d35ec 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -93,13 +93,7 @@ class BuyDialog : public Window, public gcn::ActionListener, /** * Updates the state of buttons and labels. */ - void - updateButtonsAndLabels(); - - /** - * Called whenever the widget changes size. - */ - void widgetResized(const gcn::Event &event); + void updateButtonsAndLabels(); private: Network *mNetwork; diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 064c8f93..17c3243a 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -26,6 +26,8 @@ #include "slider.h" #include "trade.h" +#include "widgets/layout.h" + #include "../item.h" #include "../localplayer.h" @@ -35,38 +37,37 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), mItem(item) { + const int maxRange = mItem->getQuantity(); + // Integer field mItemAmountTextBox = new IntTextBox(1); - mItemAmountTextBox->setRange(1, mItem->getQuantity()); + mItemAmountTextBox->setRange(1, maxRange); + mItemAmountTextBox->setWidth(30); + mItemAmountTextBox->setActionEventId("Dummy"); + mItemAmountTextBox->addActionListener(this); // Slider - mItemAmountSlide = new Slider(1.0, mItem->getQuantity()); + mItemAmountSlide = new Slider(1.0, maxRange); + mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("Slide"); mItemAmountSlide->addActionListener(this); // Buttons Button *minusButton = new Button("-", "Minus", this); + minusButton->setSize(20, 20); Button *plusButton = new Button("+", "Plus", this); + plusButton->setSize(20, 20); Button *okButton = new Button(_("Ok"), "Drop", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); // Set positions - mItemAmountTextBox->setPosition(35, 10); - mItemAmountTextBox->setSize(24, 16); - plusButton->setPosition(60, 5); - minusButton->setPosition(10, 5); - mItemAmountSlide->setDimension(gcn::Rectangle(5, 120, 180, 10)); - mItemAmountSlide->setPosition(10, 35); - okButton->setPosition(10, 50); - cancelButton->setPosition(60, 50); - - // Assemble - add(mItemAmountTextBox); - add(plusButton); - add(minusButton); - add(mItemAmountSlide); - add(okButton); - add(cancelButton); + place(0, 0, minusButton); + place(1, 0, mItemAmountTextBox).setPadding(2); + place(2, 0, plusButton); + place(0, 1, mItemAmountSlide, 6); + place(4, 2, okButton); + place(5, 2, cancelButton); + reflowLayout(250, 0); resetAmount(); @@ -83,7 +84,6 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): break; } - setContentSize(200, 80); setLocationRelativeTo(getParentWindow()); setVisible(true); } @@ -101,16 +101,6 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { scheduleDelete(); } - else if (event.getId() == "Drop") - { - player_node->dropItem(mItem, mItemAmountTextBox->getInt()); - scheduleDelete(); - } - else if (event.getId() == "AddTrade") - { - tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt()); - scheduleDelete(); - } else if (event.getId() == "Plus") { amount++; @@ -123,7 +113,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { amount = static_cast(mItemAmountSlide->getValue()); } + else if (event.getId() == "Drop") + { + player_node->dropItem(mItem, mItemAmountTextBox->getInt()); + scheduleDelete(); + } + else if (event.getId() == "AddTrade") + { + tradeWindow->tradeItem(mItem, mItemAmountTextBox->getInt()); + scheduleDelete(); + } mItemAmountTextBox->setInt(amount); mItemAmountSlide->setValue(amount); } - diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 7a2e94c6..f7f66345 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -31,6 +31,8 @@ #include "shop.h" #include "slider.h" +#include "widgets/layout.h" + #include "../item.h" #include "../npc.h" @@ -70,7 +72,6 @@ SellDialog::SellDialog(Network *network): mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); - mQuantityLabel->setWidth(60); mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); @@ -79,23 +80,22 @@ SellDialog::SellDialog(Network *network): mSlider->setEnabled(false); mShopItemList->setPriceCheck(false); - mShopItemList->setActionEventId("item"); - mSlider->setActionEventId("slider"); - - mShopItemList->addActionListener(this); mShopItemList->addSelectionListener(this); + mSlider->setActionEventId("slider"); mSlider->addActionListener(this); - add(mScrollArea); - add(mSlider); - add(mQuantityLabel); - add(mMoneyLabel); - add(mItemEffectLabel); - add(mItemDescLabel); - add(mIncreaseButton); - add(mDecreaseButton); - add(mSellButton); - add(mQuitButton); + place(0, 0, mScrollArea, 5).setPadding(3); + place(0, 1, mQuantityLabel, 2); + place(2, 1, mSlider, 3); + place(0, 2, mMoneyLabel, 5); + place(0, 3, mItemEffectLabel, 5); + place(0, 4, mItemDescLabel, 5); + place(0, 5, mDecreaseButton); + place(1, 5, mIncreaseButton); + place(3, 5, mSellButton); + place(4, 5, mQuitButton); + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); setLocationRelativeTo(getParent()); @@ -212,51 +212,6 @@ void SellDialog::valueChanged(const gcn::SelectionEvent &event) mSlider->gcn::Slider::setScale(1, mMaxItems); } -void SellDialog::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - gcn::Rectangle area = getChildrenArea(); - int width = area.width; - int height = area.height; - - mDecreaseButton->setPosition(8, height - 8 - mDecreaseButton->getHeight()); - mIncreaseButton->setPosition( - mDecreaseButton->getX() + mDecreaseButton->getWidth() + 5, - mDecreaseButton->getY()); - - mQuitButton->setPosition( - width - 8 - mQuitButton->getWidth(), - height - 8 - mQuitButton->getHeight()); - mSellButton->setPosition( - mQuitButton->getX() - 5 - mSellButton->getWidth(), - mQuitButton->getY()); - - mItemDescLabel->setDimension(gcn::Rectangle(8, - mSellButton->getY() - 5 - mItemDescLabel->getHeight(), - width - 16, - mItemDescLabel->getHeight())); - mItemEffectLabel->setDimension(gcn::Rectangle(8, - mItemDescLabel->getY() - 5 - mItemEffectLabel->getHeight(), - width - 16, - mItemEffectLabel->getHeight())); - mMoneyLabel->setDimension(gcn::Rectangle(8, - mItemEffectLabel->getY() - 5 - mMoneyLabel->getHeight(), - width - 16, - mMoneyLabel->getHeight())); - - mQuantityLabel->setPosition( - width - mQuantityLabel->getWidth() - 8, - mMoneyLabel->getY() - 5 - mQuantityLabel->getHeight()); - mSlider->setDimension(gcn::Rectangle(8, - mQuantityLabel->getY(), - mQuantityLabel->getX() - 8 - 8, - 10)); - - mScrollArea->setDimension(gcn::Rectangle(8, 8, width - 16, - mSlider->getY() - 5 - 8)); -} - void SellDialog::setMoney(int amount) { mPlayerMoney = amount; diff --git a/src/gui/sell.h b/src/gui/sell.h index 48961efc..0bf8b5a6 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -76,11 +76,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void valueChanged(const gcn::SelectionEvent &event); - /** - * Called whenever the widget changes size. - */ - void widgetResized(const gcn::Event &event); - /** * Gives Player's Money amount */ -- cgit v1.2.3-70-g09d2 From 6f08807edfa6719b73795a0630ba0affd4f9a7dc Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 6 Jan 2009 21:59:12 +0100 Subject: Fixed font colors in inventory and shortcut window They were not explicitly set to black. Because the bitmap font used to be black, these bugs didn't show up earlier. With the introduction of true type fonts, the text can be any color anywhere. --- src/gui/itemcontainer.cpp | 1 + src/gui/itemshortcutcontainer.cpp | 1 + 2 files changed, 2 insertions(+) (limited to 'src') diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 9115b1fb..65f8132a 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -115,6 +115,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) } // Draw item caption + graphics->setColor(gcn::Color(0, 0, 0)); graphics->drawText( (item->isEquipped() ? "Eq." : toString(item->getQuantity())), itemX + gridWidth / 2, diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 2ea5d584..ac62dbd6 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -75,6 +75,7 @@ ItemShortcutContainer::draw(gcn::Graphics *graphics) { Graphics *g = static_cast(graphics); + graphics->setColor(gcn::Color(0, 0, 0)); graphics->setFont(getFont()); for (int i = 0; i < mMaxItems; i++) -- cgit v1.2.3-70-g09d2 From cf0b8753dadbcc6484b859a21544e437ef7d33eb Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Thu, 20 Sep 2007 22:17:21 +0000 Subject: Added support for unicode charset in textfields and chat. Conflicts: src/Makefile.am src/game.cpp src/gui/browserbox.cpp src/gui/gui.cpp src/gui/textfield.cpp src/main.cpp (cherry picked from mainline commit 7b67e852086ad3ccd98a622f890b245ab6a0a321) --- src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 3 +- src/gui/browserbox.h | 2 +- src/gui/gui.cpp | 8 +- src/gui/gui.h | 3 +- src/gui/sdlinput.cpp | 429 +++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/sdlinput.h | 188 ++++++++++++++++++++++ src/gui/textfield.cpp | 102 +++++++++++- src/gui/textfield.h | 5 + src/gui/viewport.cpp | 2 - src/keyboardconfig.cpp | 2 - src/keyboardconfig.h | 3 +- src/main.cpp | 4 +- 14 files changed, 737 insertions(+), 18 deletions(-) create mode 100644 src/gui/sdlinput.cpp create mode 100644 src/gui/sdlinput.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a01f925..b9152100 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -136,6 +136,8 @@ SET(SRCS gui/register.h gui/scrollarea.cpp gui/scrollarea.h + gui/sdlinput.cpp + gui/sdlinput.h gui/sell.cpp gui/sell.h gui/setup_audio.cpp diff --git a/src/Makefile.am b/src/Makefile.am index a366e9b3..08ce3041 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -90,6 +90,8 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/register.h \ gui/scrollarea.cpp \ gui/scrollarea.h \ + gui/sdlinput.cpp \ + gui/sdlinput.h \ gui/sell.cpp \ gui/sell.h \ gui/setup_audio.cpp \ diff --git a/src/game.cpp b/src/game.cpp index a4d15548..efa0e859 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -26,7 +26,6 @@ #include #include -#include #include #include "beingmanager.h" @@ -59,6 +58,7 @@ #include "gui/npclistdialog.h" #include "gui/npc_text.h" #include "gui/ok_dialog.h" +#include "gui/sdlinput.h" #include "gui/sell.h" #include "gui/setup.h" #include "gui/skill.h" @@ -83,7 +83,6 @@ #include "resources/imagewriter.h" extern Graphics *graphics; -extern gcn::SDLInput *guiInput; class Map; diff --git a/src/gui/browserbox.h b/src/gui/browserbox.h index 465ff497..cb4c23ed 100644 --- a/src/gui/browserbox.h +++ b/src/gui/browserbox.h @@ -25,8 +25,8 @@ #include #include -#include #include +#include #include "../guichanfwd.h" #include "../main.h" diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 61da1a0c..f7f582fb 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -26,10 +26,8 @@ #include #include -// Should stay here because of Guichan being sensitive to headers order -#include - #include "focushandler.h" +#include "sdlinput.h" #include "truetypefont.h" #include "viewport.h" #include "window.h" @@ -48,7 +46,7 @@ // Guichan stuff Gui *gui; Viewport *viewport; /**< Viewport on the map. */ -gcn::SDLInput *guiInput; /**< GUI input. */ +SDLInput *guiInput; /**< GUI input. */ // Fonts used in showing hits gcn::Font *hitRedFont; @@ -91,7 +89,7 @@ Gui::Gui(Graphics *graphics): gcn::Image::setImageLoader(&imageLoader); // Set input - guiInput = new gcn::SDLInput(); + guiInput = new SDLInput; setInput(guiInput); // Set focus handler diff --git a/src/gui/gui.h b/src/gui/gui.h index 15d5d99c..7d390df9 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -29,6 +29,7 @@ class GuiConfigListener; class Graphics; class ImageSet; +class SDLInput; class Viewport; /** @@ -115,7 +116,7 @@ class Gui : public gcn::Gui extern Gui *gui; /**< The GUI system */ extern Viewport *viewport; /**< The viewport */ -extern gcn::SDLInput *guiInput; /**< GUI input */ +extern SDLInput *guiInput; /**< GUI input */ /** * Fonts used in showing hits diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp new file mode 100644 index 00000000..ee94b2c6 --- /dev/null +++ b/src/gui/sdlinput.cpp @@ -0,0 +1,429 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright 2007 The Mana World Development Team + * + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u + +SDLInput::SDLInput() +{ + mMouseInWindow = true; + mMouseDown = false; +} + +bool SDLInput::isKeyQueueEmpty() +{ + return mKeyInputQueue.empty(); +} + +gcn::KeyInput SDLInput::dequeueKeyInput() +{ + gcn::KeyInput keyInput; + + if (mKeyInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } + + keyInput = mKeyInputQueue.front(); + mKeyInputQueue.pop(); + + return keyInput; +} + +bool SDLInput::isMouseQueueEmpty() +{ + return mMouseInputQueue.empty(); +} + +gcn::MouseInput SDLInput::dequeueMouseInput() +{ + gcn::MouseInput mouseInput; + + if (mMouseInputQueue.empty()) + { + throw GCN_EXCEPTION("The queue is empty."); + } + + mouseInput = mMouseInputQueue.front(); + mMouseInputQueue.pop(); + + return mouseInput; +} + +void SDLInput::pushInput(SDL_Event event) +{ + gcn::KeyInput keyInput; + gcn::MouseInput mouseInput; + + switch (event.type) + { + case SDL_KEYDOWN: + keyInput.setKey(gcn::Key(convertKeyCharacter(event))); + keyInput.setType(gcn::KeyInput::PRESSED); + keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); + keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); + keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); + keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 + && event.key.keysym.sym <= SDLK_KP_EQUALS); + + mKeyInputQueue.push(keyInput); + break; + + case SDL_KEYUP: + keyInput.setKey(gcn::Key(convertKeyCharacter(event))); + keyInput.setType(gcn::KeyInput::RELEASED); + keyInput.setShiftPressed(event.key.keysym.mod & KMOD_SHIFT); + keyInput.setControlPressed(event.key.keysym.mod & KMOD_CTRL); + keyInput.setAltPressed(event.key.keysym.mod & KMOD_ALT); + keyInput.setMetaPressed(event.key.keysym.mod & KMOD_META); + keyInput.setNumericPad(event.key.keysym.sym >= SDLK_KP0 + && event.key.keysym.sym <= SDLK_KP_EQUALS); + + mKeyInputQueue.push(keyInput); + break; + + case SDL_MOUSEBUTTONDOWN: + mMouseDown = true; + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(convertMouseButton(event.button.button)); + + if (event.button.button == SDL_BUTTON_WHEELDOWN) + { + mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_DOWN); + } + else if (event.button.button == SDL_BUTTON_WHEELUP) + { + mouseInput.setType(gcn::MouseInput::WHEEL_MOVED_UP); + } + else + { + mouseInput.setType(gcn::MouseInput::PRESSED); + } + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; + + case SDL_MOUSEBUTTONUP: + mMouseDown = false; + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(convertMouseButton(event.button.button)); + mouseInput.setType(gcn::MouseInput::RELEASED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; + + case SDL_MOUSEMOTION: + mouseInput.setX(event.button.x); + mouseInput.setY(event.button.y); + mouseInput.setButton(gcn::MouseInput::EMPTY); + mouseInput.setType(gcn::MouseInput::MOVED); + mouseInput.setTimeStamp(SDL_GetTicks()); + mMouseInputQueue.push(mouseInput); + break; + + case SDL_ACTIVEEVENT: + /* + * This occurs when the mouse leaves the window and the Gui-chan + * application loses its mousefocus. + */ + if ((event.active.state & SDL_APPMOUSEFOCUS) + && !event.active.gain) + { + mMouseInWindow = false; + + if (!mMouseDown) + { + mouseInput.setX(-1); + mouseInput.setY(-1); + mouseInput.setButton(gcn::MouseInput::EMPTY); + mouseInput.setType(gcn::MouseInput::MOVED); + mMouseInputQueue.push(mouseInput); + } + } + + if ((event.active.state & SDL_APPMOUSEFOCUS) + && event.active.gain) + { + mMouseInWindow = true; + } + break; + + } // end switch +} + +int SDLInput::convertMouseButton(int button) +{ + switch (button) + { + case SDL_BUTTON_LEFT: + return gcn::MouseInput::LEFT; + case SDL_BUTTON_RIGHT: + return gcn::MouseInput::RIGHT; + case SDL_BUTTON_MIDDLE: + return gcn::MouseInput::MIDDLE; + default: + // We have an unknown mouse type which is ignored. + return button; + } +} + +int SDLInput::convertKeyCharacter(SDL_Event event) +{ + SDL_keysym keysym = event.key.keysym; + + int value = keysym.unicode; + + switch (keysym.sym) + { + case SDLK_TAB: + value = Key::TAB; + break; + case SDLK_LALT: + value = Key::LEFT_ALT; + break; + case SDLK_RALT: + value = Key::RIGHT_ALT; + break; + case SDLK_LSHIFT: + value = Key::LEFT_SHIFT; + break; + case SDLK_RSHIFT: + value = Key::RIGHT_SHIFT; + break; + case SDLK_LCTRL: + value = Key::LEFT_CONTROL; + break; + case SDLK_RCTRL: + value = Key::RIGHT_CONTROL; + break; + case SDLK_BACKSPACE: + value = Key::BACKSPACE; + break; + case SDLK_PAUSE: + value = Key::PAUSE; + break; + case SDLK_SPACE: + // Special characters like ~ (tilde) ends up + // with the keysym.sym SDLK_SPACE which + // without this check would be lost. The check + // is only valid on key down events in SDL. + if (event.type == SDL_KEYUP || keysym.unicode == ' ') + { + value = Key::SPACE; + } + break; + case SDLK_ESCAPE: + value = Key::ESCAPE; + break; + case SDLK_DELETE: + value = Key::DELETE; + break; + case SDLK_INSERT: + value = Key::INSERT; + break; + case SDLK_HOME: + value = Key::HOME; + break; + case SDLK_END: + value = Key::END; + break; + case SDLK_PAGEUP: + value = Key::PAGE_UP; + break; + case SDLK_PRINT: + value = Key::PRINT_SCREEN; + break; + case SDLK_PAGEDOWN: + value = Key::PAGE_DOWN; + break; + case SDLK_F1: + value = Key::F1; + break; + case SDLK_F2: + value = Key::F2; + break; + case SDLK_F3: + value = Key::F3; + break; + case SDLK_F4: + value = Key::F4; + break; + case SDLK_F5: + value = Key::F5; + break; + case SDLK_F6: + value = Key::F6; + break; + case SDLK_F7: + value = Key::F7; + break; + case SDLK_F8: + value = Key::F8; + break; + case SDLK_F9: + value = Key::F9; + break; + case SDLK_F10: + value = Key::F10; + break; + case SDLK_F11: + value = Key::F11; + break; + case SDLK_F12: + value = Key::F12; + break; + case SDLK_F13: + value = Key::F13; + break; + case SDLK_F14: + value = Key::F14; + break; + case SDLK_F15: + value = Key::F15; + break; + case SDLK_NUMLOCK: + value = Key::NUM_LOCK; + break; + case SDLK_CAPSLOCK: + value = Key::CAPS_LOCK; + break; + case SDLK_SCROLLOCK: + value = Key::SCROLL_LOCK; + break; + case SDLK_RMETA: + value = Key::RIGHT_META; + break; + case SDLK_LMETA: + value = Key::LEFT_META; + break; + case SDLK_LSUPER: + value = Key::LEFT_SUPER; + break; + case SDLK_RSUPER: + value = Key::RIGHT_SUPER; + break; + case SDLK_MODE: + value = Key::ALT_GR; + break; + case SDLK_UP: + value = Key::UP; + break; + case SDLK_DOWN: + value = Key::DOWN; + break; + case SDLK_LEFT: + value = Key::LEFT; + break; + case SDLK_RIGHT: + value = Key::RIGHT; + break; + case SDLK_RETURN: + value = Key::ENTER; + break; + case SDLK_KP_ENTER: + value = Key::ENTER; + break; + + default: + break; + } + + if (!(keysym.mod & KMOD_NUM)) + { + switch (keysym.sym) + { + case SDLK_KP0: + value = Key::INSERT; + break; + case SDLK_KP1: + value = Key::END; + break; + case SDLK_KP2: + value = Key::DOWN; + break; + case SDLK_KP3: + value = Key::PAGE_DOWN; + break; + case SDLK_KP4: + value = Key::LEFT; + break; + case SDLK_KP5: + value = 0; + break; + case SDLK_KP6: + value = Key::RIGHT; + break; + case SDLK_KP7: + value = Key::HOME; + break; + case SDLK_KP8: + value = Key::UP; + break; + case SDLK_KP9: + value = Key::PAGE_UP; + break; + default: + break; + } + } + + return value; +} diff --git a/src/gui/sdlinput.h b/src/gui/sdlinput.h new file mode 100644 index 00000000..72d949e1 --- /dev/null +++ b/src/gui/sdlinput.h @@ -0,0 +1,188 @@ +/* _______ __ __ __ ______ __ __ _______ __ __ + * / _____/\ / /\ / /\ / /\ / ____/\ / /\ / /\ / ___ /\ / |\/ /\ + * / /\____\// / // / // / // /\___\// /_// / // /\_/ / // , |/ / / + * / / /__ / / // / // / // / / / ___ / // ___ / // /| ' / / + * / /_// /\ / /_// / // / // /_/_ / / // / // /\_/ / // / | / / + * /______/ //______/ //_/ //_____/\ /_/ //_/ //_/ //_/ //_/ /|_/ / + * \______\/ \______\/ \_\/ \_____\/ \_\/ \_\/ \_\/ \_\/ \_\/ \_\/ + * + * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson + * Copyright 2007 The Mana World Development Team + * + * Js_./ + * Per Larsson a.k.a finalman _RqZ{a<^_aa + * Olof Naessén a.k.a jansem/yakslem _asww7!uY`> )\a// + * _Qhm`] _f "'c 1!5m + * Visit: http://guichan.darkbits.org )Qk

ws?a-?' ._/L #' + * binary forms, with or without )4d[#7r, . ' )d`)[ + * modification, are permitted provided _Q-5'5W..j/?' -?!\)cam' + * that the following conditions are met: j<. a J@\ + * this list of conditions and the j(]1u + +#include + +#include +#include +#include +#include + +namespace Key +{ + enum + { + SPACE = ' ', + TAB = '\t', + ENTER = '\n', + // Negative values, to avoid conflicts with higher character codes. + LEFT_ALT = -1000, + RIGHT_ALT, + LEFT_SHIFT, + RIGHT_SHIFT, + LEFT_CONTROL, + RIGHT_CONTROL, + LEFT_META, + RIGHT_META, + LEFT_SUPER, + RIGHT_SUPER, + INSERT, + HOME, + PAGE_UP, + DELETE, + END, + PAGE_DOWN, + ESCAPE, + CAPS_LOCK, + BACKSPACE, + F1, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + PRINT_SCREEN, + SCROLL_LOCK, + PAUSE, + NUM_LOCK, + ALT_GR, + LEFT, + RIGHT, + UP, + DOWN + }; +} + +/** + * SDL implementation of Input. + */ +class SDLInput : public gcn::Input +{ +public: + + /** + * Constructor. + */ + SDLInput(); + + /** + * Pushes an SDL event. It should be called at least once per frame to + * update input with user input. + * + * @param event an event from SDL. + */ + virtual void pushInput(SDL_Event event); + + /** + * Polls all input. It exists for input driver compatibility. If you + * only use SDL and plan sticking with SDL you can safely ignore this + * function as it in the SDL case does nothing. + */ + virtual void _pollInput() { } + + + // Inherited from Input + + virtual bool isKeyQueueEmpty(); + + virtual gcn::KeyInput dequeueKeyInput(); + + virtual bool isMouseQueueEmpty(); + + virtual gcn::MouseInput dequeueMouseInput(); + +protected: + /** + * Converts a mouse button from SDL to a Guichan mouse button + * representation. + * + * @param button an SDL mouse button. + * @return a Guichan mouse button. + */ + int convertMouseButton(int button); + + /** + * Converts an SDL event key to a key value. + * + * @param event an SDL event with a key to convert. + * @return a key value. + * @see Key + */ + int convertKeyCharacter(SDL_Event event); + + std::queue mKeyInputQueue; + std::queue mMouseInputQueue; + + bool mMouseDown; + bool mMouseInWindow; +}; + +#endif diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index ea82ba77..bbedb29d 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -19,11 +19,13 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "textfield.h" + #include #include -#include "textfield.h" +#include "sdlinput.h" #include "../graphics.h" @@ -32,6 +34,8 @@ #include "../utils/dtor.h" +#undef DELETE //Win32 compatibility hack + int TextField::instances = 0; ImageRect TextField::skin; @@ -100,3 +104,99 @@ void TextField::drawFrame(gcn::Graphics *graphics) static_cast(graphics)->drawImageRect(0, 0, w, h, skin); } + +void TextField::keyPressed(gcn::KeyEvent &keyEvent) +{ + int val = keyEvent.getKey().getValue(); + + if (val >= 32) + { + int l; + if (val < 128) l = 1; // 0xxxxxxx + else if (val < 0x800) l = 2; // 110xxxxx 10xxxxxx + else if (val < 0x10000) l = 3; // 1110xxxx 10xxxxxx 10xxxxxx + else l = 4; // 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + + char buf[4]; + for (int i = 0; i < l; ++i) + { + buf[i] = val >> (6 * (l - i - 1)); + if (i > 0) buf[i] = (buf[i] & 63) | 128; + } + + if (l > 1) buf[0] |= 255 << (8 - l); + + mText.insert(mCaretPosition, std::string(buf, buf + l)); + mCaretPosition += l; + } + + /* In UTF-8, 10xxxxxx is only used for inner parts of characters. So skip + them when processing key presses. */ + + switch (val) + { + case Key::LEFT: + { + while (mCaretPosition > 0) + { + --mCaretPosition; + if ((mText[mCaretPosition] & 192) != 128) + break; + } + } break; + + case Key::RIGHT: + { + unsigned sz = mText.size(); + while (mCaretPosition < sz) + { + ++mCaretPosition; + if (mCaretPosition == sz || + (mText[mCaretPosition] & 192) != 128) + break; + } + } break; + + case Key::DELETE: + { + unsigned sz = mText.size(); + while (mCaretPosition < sz) + { + --sz; + mText.erase(mCaretPosition, 1); + if (mCaretPosition == sz || + (mText[mCaretPosition] & 192) != 128) + break; + } + } break; + + case Key::BACKSPACE: + { + while (mCaretPosition > 0) + { + --mCaretPosition; + int v = mText[mCaretPosition]; + mText.erase(mCaretPosition, 1); + if ((v & 192) != 128) break; + } + } break; + + case Key::ENTER: + distributeActionEvent(); + break; + + case Key::HOME: + mCaretPosition = 0; + break; + + case Key::END: + mCaretPosition = mText.size(); + break; + + case Key::TAB: + return; + } + + keyEvent.consume(); + fixScroll(); +} diff --git a/src/gui/textfield.h b/src/gui/textfield.h index 60a50c69..b808fad2 100644 --- a/src/gui/textfield.h +++ b/src/gui/textfield.h @@ -53,6 +53,11 @@ class TextField : public gcn::TextField { */ void drawFrame(gcn::Graphics *graphics); + /** + * Processes one keypress. + */ + void keyPressed(gcn::KeyEvent &keyEvent); + private: static int instances; static ImageRect skin; diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 37aa40ce..9eab7c95 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -21,8 +21,6 @@ #include "viewport.h" -#include - #include "gui.h" #include "popupmenu.h" #include "ministatus.h" diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 60b0c02a..a471f70f 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -23,8 +23,6 @@ #include "configuration.h" #include "log.h" -#include - #include "gui/setup_keyboard.h" struct KeyData diff --git a/src/keyboardconfig.h b/src/keyboardconfig.h index c6769821..414682bc 100644 --- a/src/keyboardconfig.h +++ b/src/keyboardconfig.h @@ -24,10 +24,9 @@ #include +#include "gui/sdlinput.h" #include "gui/setup_keyboard.h" -#include - /** * Each key represents a key function. Such as 'Move up', 'Attack' etc. */ diff --git a/src/main.cpp b/src/main.cpp index 09a1a41d..3833b8fa 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,7 +29,6 @@ #include #include -#include #include #include @@ -67,9 +66,10 @@ #include "gui/ok_dialog.h" #include "gui/progressbar.h" #include "gui/register.h" +#include "gui/sdlinput.h" #include "gui/setup.h" -#include "gui/updatewindow.h" #include "gui/textfield.h" +#include "gui/updatewindow.h" #include "net/charserverhandler.h" #include "net/loginhandler.h" -- cgit v1.2.3-70-g09d2 From d3eced6c5078ff7330383ee9317ac4f37389ac69 Mon Sep 17 00:00:00 2001 From: Björn Steinbrink Date: Tue, 6 Jan 2009 22:43:06 +0100 Subject: Fix wrapping of UTF-8 multi-byte characters. (cherry picked from commit 82182aeb9eacb3a6e10e34b34b46ef63222ecd7d) --- src/gui/browserbox.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 80e41fc2..2706a4c4 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -392,7 +392,10 @@ BrowserBox::draw(gcn::Graphics *graphics) continue; } - end--; + // Skip to the start of the current character + while ((row[end] & 192) == 128) + end--; + end--; // And then to the last byte of the previous one part = row.substr(start, end - start + 1); } while ((x + font->getWidth(part.c_str()) + 10) > getWidth()); -- cgit v1.2.3-70-g09d2 From 467065bab257b23d7783088563ff82459e9179c9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 6 Jan 2009 22:56:43 +0100 Subject: Fixed the true type font to render unicode now --- src/gui/gui.cpp | 6 +++--- src/gui/truetypefont.cpp | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index f7f582fb..87bab0ea 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -24,7 +24,6 @@ #include #include #include -#include #include "focushandler.h" #include "sdlinput.h" @@ -46,7 +45,7 @@ // Guichan stuff Gui *gui; Viewport *viewport; /**< Viewport on the map. */ -SDLInput *guiInput; /**< GUI input. */ +SDLInput *guiInput; // Fonts used in showing hits gcn::Font *hitRedFont; @@ -104,8 +103,9 @@ Gui::Gui(Graphics *graphics): Window::setWindowContainer(guiTop); setTop(guiTop); - // Set global font ResourceManager *resman = ResourceManager::getInstance(); + + // Set global font std::string path = resman->getPath("fonts/dejavusans.ttf"); try { mGuiFont = new TrueTypeFont(path, 11); diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 9343c224..0eed6f08 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -55,7 +55,7 @@ class TextChunk sdlCol.r = color.r; sdlCol.g = color.g; - SDL_Surface *surface = TTF_RenderText_Blended( + SDL_Surface *surface = TTF_RenderUTF8_Blended( font, text.c_str(), sdlCol); if (!surface) @@ -167,7 +167,7 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, int TrueTypeFont::getWidth(const std::string &text) const { int w, h; - TTF_SizeText(mFont, text.c_str(), &w, &h); + TTF_SizeUTF8(mFont, text.c_str(), &w, &h); return w; } -- cgit v1.2.3-70-g09d2 From 20d247cb9849bb7fb0e4df993a2fc0f0e0d5bf74 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 6 Jan 2009 23:15:48 +0100 Subject: Correct the codeset for translations to be UTF-8 As on the mainline client --- src/main.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index 3833b8fa..3c106633 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -675,6 +675,7 @@ int main(int argc, char *argv[]) #endif setlocale(LC_MESSAGES, ""); bindtextdomain("tmw", LOCALEDIR); + bind_textdomain_codeset("tmw", "UTF-8"); textdomain("tmw"); #endif -- cgit v1.2.3-70-g09d2 From dfd31a12ae8a8d44b622b6aa2cd922fca18edf37 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Wed, 14 Nov 2007 09:26:03 +0000 Subject: Fixed up and down arrows in chat box. (cherry picked from commit cb04d148c9aed572fe6e66313100e2cd9b66f5d5) Conflicts: src/gui/chat.cpp --- src/gui/chat.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index aa24ba7f..3c02e656 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -23,13 +23,13 @@ #include #include -#include #include "chat.h" #include "browserbox.h" #include "chatinput.h" #include "scrollarea.h" +#include "sdlinput.h" #include "windowcontainer.h" #include "../configuration.h" @@ -439,7 +439,7 @@ void ChatWindow::scroll(int amount) void ChatWindow::keyPressed(gcn::KeyEvent &event) { - if (event.getKey().getValue() == gcn::Key::DOWN && + if (event.getKey().getValue() == Key::DOWN && mCurHist != mHistory.end()) { // Move forward through the history @@ -452,7 +452,7 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event) mCurHist = prevHist; } } - else if (event.getKey().getValue() == gcn::Key::UP && + else if (event.getKey().getValue() == Key::UP && mCurHist != mHistory.begin() && mHistory.size() > 0) { // Move backward through the history -- cgit v1.2.3-70-g09d2 From d9a77ca6c6c74e0333079208da0d04117f70e48c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 7 Jan 2009 23:06:24 +0100 Subject: Used layout manager for character selection dialog Based on the layout from the mainline client done by Guillaume Melquiond in commits aab0b1724897e186d2d4056da7f0cd34ccc12fcb and 97bbe57e21a28544646da087e2a522390bf2ce5c. Fixes hidden Ok button on many translations. --- src/gui/char_select.cpp | 53 +++++++++++++++++++------------------------------ 1 file changed, 20 insertions(+), 33 deletions(-) (limited to 'src') diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 65dafeea..643a598f 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -31,6 +31,8 @@ #include "playerbox.h" #include "textfield.h" +#include "widgets/layout.h" + #include "../game.h" #include "../localplayer.h" #include "../main.h" @@ -93,39 +95,24 @@ CharSelectDialog::CharSelectDialog(Network *network, // Control that shows the Player mPlayerBox = new PlayerBox; - - int w = 195; - int h = 220; - setContentSize(w, h); - mPlayerBox->setDimension(gcn::Rectangle(5, 5, w - 10, 90)); - mNameLabel->setDimension(gcn::Rectangle(10, 100, 128, 16)); - mLevelLabel->setDimension(gcn::Rectangle(10, 116, 128, 16)); - mJobLevelLabel->setDimension(gcn::Rectangle(10, 132, 128, 16)); - mMoneyLabel->setDimension(gcn::Rectangle(10, 148, 128, 16)); - mPreviousButton->setPosition(5, 170); - mNextButton->setPosition(mPreviousButton->getWidth() + 10, 170); - mNewCharButton->setPosition(5, h - 5 - mNewCharButton->getHeight()); - mDelCharButton->setPosition( - 5 + mNewCharButton->getWidth() + 5, - mNewCharButton->getY()); - mCancelButton->setPosition( - w - 5 - mCancelButton->getWidth(), - mNewCharButton->getY()); - mSelectButton->setPosition( - mCancelButton->getX() - 5 - mSelectButton->getWidth(), - mNewCharButton->getY()); - - add(mPlayerBox); - add(mSelectButton); - add(mCancelButton); - add(mNewCharButton); - add(mDelCharButton); - add(mPreviousButton); - add(mNextButton); - add(mNameLabel); - add(mLevelLabel); - add(mJobLevelLabel); - add(mMoneyLabel); + mPlayerBox->setWidth(74); + + ContainerPlacer place; + place = getPlacer(0, 0); + place(0, 0, mPlayerBox, 1, 6).setPadding(3); + place(1, 0, mNameLabel, 3); + place(1, 1, mLevelLabel, 3); + place(1, 2, mJobLevelLabel, 3); + place(1, 3, mMoneyLabel, 3); + place(1, 4, mPreviousButton); + place(2, 4, mNextButton); + place(1, 5, mNewCharButton); + place(2, 5, mDelCharButton); + place.getCell().matchColWidth(1, 2); + place = getPlacer(0, 2); + place(0, 0, mSelectButton); + place(1, 0, mCancelButton); + reflowLayout(265, 0); setLocationRelativeTo(getParent()); setVisible(true); -- cgit v1.2.3-70-g09d2 From 2f28a665e61359dab6aec92546161d22766d838c Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Thu, 8 Jan 2009 11:31:49 +0100 Subject: Fixed segvault when exiting with logToChat enabled --- src/game.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index efa0e859..a788c51a 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -228,6 +228,7 @@ void createGuiWindows(Network *network) */ void destroyGuiWindows() { + logger->setChatWindow(NULL); delete chatWindow; delete statusWindow; delete miniStatusWindow; -- cgit v1.2.3-70-g09d2 From bbb89909e72ee1d1d5d8d469d505aff3bd5aa23c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 8 Jan 2009 20:38:41 +0100 Subject: Removed the unused Box, VBox and HBox classes They were once meant for doing layout, but never used and the way they're implemented they would be relayouting with every draw, which isn't really nice. --- src/CMakeLists.txt | 6 ------ src/Makefile.am | 6 ------ src/gui/box.cpp | 42 --------------------------------------- src/gui/box.h | 58 ------------------------------------------------------ src/gui/hbox.cpp | 39 ------------------------------------ src/gui/hbox.h | 33 ------------------------------- src/gui/vbox.cpp | 43 ---------------------------------------- src/gui/vbox.h | 33 ------------------------------- tmw.cbp | 6 ------ 9 files changed, 266 deletions(-) delete mode 100644 src/gui/box.cpp delete mode 100644 src/gui/box.h delete mode 100644 src/gui/hbox.cpp delete mode 100644 src/gui/hbox.h delete mode 100644 src/gui/vbox.cpp delete mode 100644 src/gui/vbox.h (limited to 'src') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b9152100..27d1e1d8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -53,8 +53,6 @@ SET(SRCS gui/widgets/resizegrip.h gui/widgets/layout.cpp gui/widgets/layout.h - gui/box.cpp - gui/box.h gui/browserbox.cpp gui/browserbox.h gui/buddywindow.cpp @@ -89,8 +87,6 @@ SET(SRCS gui/gccontainer.h gui/gui.cpp gui/gui.h - gui/hbox.cpp - gui/hbox.h gui/help.cpp gui/help.h gui/inttextbox.cpp @@ -177,8 +173,6 @@ SET(SRCS gui/trade.h gui/updatewindow.h gui/updatewindow.cpp - gui/vbox.h - gui/vbox.cpp gui/viewport.cpp gui/viewport.h gui/window.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 08ce3041..d882f426 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -5,8 +5,6 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/widgets/layout.h \ gui/widgets/resizegrip.cpp \ gui/widgets/resizegrip.h \ - gui/box.h \ - gui/box.cpp \ gui/browserbox.cpp \ gui/browserbox.h \ gui/buddywindow.cpp \ @@ -41,8 +39,6 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/gccontainer.h \ gui/gui.cpp \ gui/gui.h \ - gui/hbox.h \ - gui/hbox.cpp \ gui/help.cpp \ gui/help.h \ gui/inttextbox.h \ @@ -131,8 +127,6 @@ tmw_SOURCES = gui/widgets/layout.cpp \ gui/trade.h \ gui/updatewindow.h \ gui/updatewindow.cpp \ - gui/vbox.h \ - gui/vbox.cpp \ gui/viewport.cpp \ gui/viewport.h \ gui/window.cpp \ diff --git a/src/gui/box.cpp b/src/gui/box.cpp deleted file mode 100644 index 59d8c135..00000000 --- a/src/gui/box.cpp +++ /dev/null @@ -1,42 +0,0 @@ -/* - * 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 - */ - -#include "box.h" - -Box::Box(): - padding(0) -{ - setOpaque(false); -} - -Box::~Box() -{ -} - -unsigned int Box::getPadding() -{ - return padding; -} - -void Box::setPadding(unsigned int p) -{ - padding = p; -} diff --git a/src/gui/box.h b/src/gui/box.h deleted file mode 100644 index 46654b48..00000000 --- a/src/gui/box.h +++ /dev/null @@ -1,58 +0,0 @@ -/* - * 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 - */ - - -#ifndef BOX_H -#define BOX_H - -#include - -#include "../guichanfwd.h" - -class Box : public gcn::Container -{ - public: - /** - * Returns padding. - */ - unsigned int getPadding(); - - /** - * Sets padding between widgets. - */ - void setPadding(unsigned int); - - protected: - Box(); - virtual ~Box(); - - /** - * Spacing between client widgets. - */ - unsigned int padding; - - virtual void draw(gcn::Graphics *) = 0; - - typedef std::list Widgets; - typedef Widgets::iterator WidgetIterator; -}; - -#endif diff --git a/src/gui/hbox.cpp b/src/gui/hbox.cpp deleted file mode 100644 index 020e85c6..00000000 --- a/src/gui/hbox.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* - * 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 - */ - -#include "hbox.h" - -void HBox::draw(gcn::Graphics *graphics) -{ - int widgetCount = mWidgets.size(); - int childHeight = getHeight(); - if (widgetCount == 0) - return; - int childWidth = getWidth() / widgetCount; - - int i = 0; - for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) { - (*w)->setPosition(childWidth * i - padding, 0); - (*w)->setSize(childWidth, childHeight); - i++; - } - gcn::Container::draw(graphics); -} diff --git a/src/gui/hbox.h b/src/gui/hbox.h deleted file mode 100644 index 4b241383..00000000 --- a/src/gui/hbox.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 - */ - -#ifndef HBOX_H -#define HBOX_H - -#include "box.h" - -class HBox : public Box -{ - public: - void draw(gcn::Graphics *); -}; - -#endif diff --git a/src/gui/vbox.cpp b/src/gui/vbox.cpp deleted file mode 100644 index 2ec1112d..00000000 --- a/src/gui/vbox.cpp +++ /dev/null @@ -1,43 +0,0 @@ -/* - * 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 - */ - -#include "vbox.h" - -void VBox::draw(gcn::Graphics *graphics) -{ - if (mWidgets.empty()) - { - return; - } - - int childWidth = getWidth(); - int childHeight = getHeight() / mWidgets.size(); - int i = 0; - - for (WidgetIterator w = mWidgets.begin(); w != mWidgets.end(); w++) - { - (*w)->setPosition(0, childHeight * i - padding); - (*w)->setSize(childWidth, childHeight); - i++; - } - - gcn::Container::draw(graphics); -} diff --git a/src/gui/vbox.h b/src/gui/vbox.h deleted file mode 100644 index 2072ab24..00000000 --- a/src/gui/vbox.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * 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 - */ - -#ifndef VBOX_H -#define VBOX_H - -#include "box.h" - -class VBox : public Box -{ - public: - void draw(gcn::Graphics *); -}; - -#endif diff --git a/tmw.cbp b/tmw.cbp index f3dc7258..3b9a0993 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -99,8 +99,6 @@ - - @@ -135,8 +133,6 @@ - - @@ -224,8 +220,6 @@ - - -- cgit v1.2.3-70-g09d2 From 08a2e6eac1166f6fb22fd2058326ab1f72e5bdc9 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 8 Jan 2009 22:03:33 +0100 Subject: Made remaining dialogs translatable MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Most strings are now translatable. Please do report any missing ones. Strings excluded from translation are anything that gets written to the log file or is otherwise not shown in the GUI. Signed-off-by: Bjørn Lindeijer --- po/POTFILES.in | 9 +++ src/gui/buysell.cpp | 10 +-- src/gui/chat.cpp | 172 ++++++++++++++++++++++++--------------------- src/gui/help.cpp | 6 +- src/gui/setup_keyboard.cpp | 12 ++-- src/gui/setup_players.cpp | 60 ++++++++++------ src/gui/skill.cpp | 35 ++++----- src/gui/status.cpp | 88 +++++++++++------------ src/gui/trade.cpp | 4 +- src/gui/updatewindow.cpp | 11 +-- src/main.cpp | 13 ++-- 11 files changed, 235 insertions(+), 185 deletions(-) (limited to 'src') diff --git a/po/POTFILES.in b/po/POTFILES.in index f750976e..4207012b 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,11 +1,14 @@ # List of source files which contain translatable strings. src/gui/buy.cpp +src/gui/buysell.cpp src/gui/char_select.cpp src/gui/char_server.cpp +src/gui/chat.cpp src/gui/confirm_dialog.cpp src/gui/connection.cpp src/gui/equipmentwindow.cpp +src/gui/help.cpp src/gui/inventorywindow.cpp src/gui/item_amount.cpp src/gui/login.cpp @@ -20,6 +23,12 @@ src/gui/sell.cpp src/gui/setup_audio.cpp src/gui/setup.cpp src/gui/setup_joystick.cpp +src/gui/setup_keyboard.cpp +src/gui/setup_players.cpp src/gui/setup_video.cpp +src/gui/skill.cpp +src/gui/status.cpp src/gui/trade.cpp +src/gui/updatewindow.cpp src/resources/itemdb.cpp +src/main.cpp diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 42380882..a8223ca4 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -25,18 +25,20 @@ #include "../npc.h" +#include "../utils/gettext.h" + BuySellDialog::BuySellDialog(): - Window("Shop") + Window(_("Shop")) { Button *buyButton = 0; - const char *buttonNames[] = { - "Buy", "Sell", "Cancel", 0 + static const char *buttonNames[] = { + N_("Buy"), N_("Sell"), N_("Cancel"), 0 }; int x = 10, y = 10; for (const char **curBtn = buttonNames; *curBtn; curBtn++) { - Button *btn = new Button(*curBtn, *curBtn, this); + Button *btn = new Button(gettext(*curBtn), *curBtn, this); if (!buyButton) buyButton = btn; // For focus request btn->setPosition(x, y); add(btn); diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 3c02e656..d61ec021 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -39,6 +39,8 @@ #include "../net/messageout.h" #include "../net/protocol.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/trim.h" ChatWindow::ChatWindow(Network *network): @@ -116,11 +118,14 @@ void ChatWindow::chatLog(std::string line, int own) std::string lineColor = "##0"; // Equiv. to BrowserBox::BLACK switch (own) { case BY_GM: - if (tmp.nick.empty()) - tmp.nick = std::string("Global announcement: "); - else - tmp.nick = std::string("Global announcement from " + tmp.nick - + std::string(": ")); + if (tmp.nick.empty()) { + tmp.nick = _("Global announcement:"); + tmp.nick += " "; + } else { + tmp.nick = strprintf(_("Global announcement from %s:"), + tmp.nick.c_str()); + tmp.nick += " "; + } lineColor = "##1"; // Equiv. to BrowserBox::RED break; case BY_PLAYER: @@ -132,12 +137,14 @@ void ChatWindow::chatLog(std::string line, int own) lineColor = "##0"; // Equiv. to BrowserBox::BLACK break; case BY_SERVER: - tmp.nick = "Server: "; + tmp.nick = _("Server:"); + tmp.nick += " "; tmp.text = line; lineColor = "##7"; // Equiv. to BrowserBox::PINK break; case ACT_WHISPER: - tmp.nick += CAT_WHISPER; + tmp.nick = strprintf(_("%s whispers:"), tmp.nick.c_str()); + tmp.nick += " "; lineColor = "##3"; // Equiv. to BrowserBox::BLUE break; case ACT_IS: @@ -250,7 +257,7 @@ void ChatWindow::whisper(const std::string &nick, std::string msg, std::string recvnick = ""; msg.erase(0, prefixlen + 1); - if (msg.substr(0,1) == "\"") + if (msg.substr(0, 1) == "\"") { const std::string::size_type pos = msg.find('"', 1); if (pos != std::string::npos) { @@ -273,7 +280,9 @@ void ChatWindow::whisper(const std::string &nick, std::string msg, outMsg.writeString(recvnick, 24); outMsg.writeString(msg, msg.length()); - chatLog("Whispering to " + recvnick + " : " + msg, BY_PLAYER); + chatLog(strprintf(_("Whispering to %s: %s"), + recvnick.c_str(), msg.c_str()), + BY_PLAYER); } void ChatWindow::chatSend(const std::string &nick, std::string msg) @@ -344,7 +353,7 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) whisper(nick, msg, IS_SHORT_WHISPER_LENGTH); else { - chatLog("Unknown command", BY_SERVER); + chatLog(_("Unknown command"), BY_SERVER); } } @@ -353,71 +362,73 @@ std::string ChatWindow::const_msg(CHATSKILL act) std::string msg; if (act.success == SKILL_FAILED && act.skill == SKILL_BASIC) { switch (act.bskill) { - case BSKILL_TRADE : - msg = "Trade failed!"; + case BSKILL_TRADE: + msg = _("Trade failed!"); break; - case BSKILL_EMOTE : - msg = "Emote failed!"; + case BSKILL_EMOTE: + msg = _("Emote failed!"); break; - case BSKILL_SIT : - msg = "Sit failed!"; + case BSKILL_SIT: + msg = _("Sit failed!"); break; - case BSKILL_CREATECHAT : - msg = "Chat creating failed!"; + case BSKILL_CREATECHAT: + msg = _("Chat creating failed!"); break; - case BSKILL_JOINPARTY : - msg = "Could not join party!"; + case BSKILL_JOINPARTY: + msg = _("Could not join party!"); break; - case BSKILL_SHOUT : - msg = "Cannot shout!"; + case BSKILL_SHOUT: + msg = _("Cannot shout!"); break; } + msg += " "; + switch (act.reason) { - case RFAIL_SKILLDEP : - msg += " You have not yet reached a high enough lvl!"; + case RFAIL_SKILLDEP: + msg += _("You have not yet reached a high enough lvl!"); break; - case RFAIL_INSUFHP : - msg += " Insufficient HP!"; + case RFAIL_INSUFHP: + msg += _("Insufficient HP!"); break; - case RFAIL_INSUFSP : - msg += " Insufficient SP!"; + case RFAIL_INSUFSP: + msg += _("Insufficient SP!"); break; - case RFAIL_NOMEMO : - msg += " You have no memos!"; + case RFAIL_NOMEMO: + msg += _("You have no memos!"); break; - case RFAIL_SKILLDELAY : - msg += " You cannot do that right now!"; + case RFAIL_SKILLDELAY: + msg += _("You cannot do that right now!"); break; - case RFAIL_ZENY : - msg += " Seems you need more Zeny... ;-)"; + case RFAIL_ZENY: + msg += _("Seems you need more Zeny... ;-)"); break; - case RFAIL_WEAPON : - msg += " You cannot use this skill with that kind of weapon!"; + case RFAIL_WEAPON: + msg += _("You cannot use this skill with that kind of weapon!"); break; - case RFAIL_REDGEM : - msg += " You need another red gem!"; + case RFAIL_REDGEM: + msg += _("You need another red gem!"); break; - case RFAIL_BLUEGEM : - msg += " You need another blue gem!"; + case RFAIL_BLUEGEM: + msg += _("You need another blue gem!"); break; - case RFAIL_OVERWEIGHT : - msg += " You're carrying to much to do this!"; + case RFAIL_OVERWEIGHT: + msg += _("You're carrying to much to do this!"); break; - default : - msg += " Huh? What's that?"; + default: + msg += _("Huh? What's that?"); break; } } else { - switch(act.skill) { + switch (act.skill) { case SKILL_WARP : - msg = "Warp failed..."; + msg = _("Warp failed..."); break; case SKILL_STEAL : - msg = "Could not steal anything..."; + msg = _("Could not steal anything..."); break; case SKILL_ENVENOM : - msg = "Poison had no effect..."; + msg = _("Poison had no effect..."); break; } } @@ -482,67 +493,68 @@ void ChatWindow::setVisible(bool isVisible) void ChatWindow::help(const std::string &msg1, const std::string &msg2) { - chatLog("-- Help --", BY_SERVER); + chatLog(_("-- Help --"), BY_SERVER); if (msg1 == "") { - chatLog("/announce: Global announcement (GM only)", BY_SERVER); - chatLog("/clear: Clears this window", BY_SERVER); - chatLog("/help: Display this help.", BY_SERVER); - chatLog("/where: Display map name", BY_SERVER); - chatLog("/whisper : Sends a private " - " to ", BY_SERVER); - chatLog("/w : Short form for /whisper", BY_SERVER); - chatLog("/who: Display number of online users", BY_SERVER); - chatLog("For more information, type /help ", BY_SERVER); + chatLog(_("/announce: Global announcement (GM only)"), BY_SERVER); + chatLog(_("/clear: Clears this window"), BY_SERVER); + chatLog(_("/help: Display this help"), BY_SERVER); + chatLog(_("/where: Display map name"), BY_SERVER); + chatLog(_("/whisper : Sends a private " + " to "), BY_SERVER); + chatLog(_("/w : Short form for /whisper"), BY_SERVER); + chatLog(_("/who: Display number of online users"), BY_SERVER); + chatLog(_("For more information, type /help "), BY_SERVER); return; } if (msg1 == "announce") { - chatLog("Command: /announce ", BY_SERVER); - chatLog("*** only available to a GM ***", BY_SERVER); - chatLog("This command sends the message to " - "all players currently online.", BY_SERVER); + chatLog(_("Command: /announce "), BY_SERVER); + chatLog(_("*** only available to a GM ***"), BY_SERVER); + chatLog(_("This command sends the message to " + "all players currently online."), BY_SERVER); return; } if (msg1 == "clear") { - chatLog("Command: /clear", BY_SERVER); - chatLog("This command clears the chat log of previous chat.", + chatLog(_("Command: /clear"), BY_SERVER); + chatLog(_("This command clears the chat log of previous chat."), BY_SERVER); return; } if (msg1 == "help") { - chatLog("Command: /help", BY_SERVER); - chatLog("This command displays a list of all commands available.", + chatLog(_("Command: /help"), BY_SERVER); + chatLog(_("This command displays a list of all commands available."), BY_SERVER); - chatLog("Command: /help ", BY_SERVER); - chatLog("This command displays help on .", BY_SERVER); + chatLog(_("Command: /help "), BY_SERVER); + chatLog(_("This command displays help on ."), BY_SERVER); return; } if (msg1 == "where") { - chatLog("Command: /where", BY_SERVER); - chatLog("This command displays the name of the current map.", + chatLog(_("Command: /where"), BY_SERVER); + chatLog(_("This command displays the name of the current map."), BY_SERVER); return; } if (msg1 == "whisper" || msg1 == "w") { - chatLog("Command: /whisper ", BY_SERVER); - chatLog("Command: /w ", BY_SERVER); - chatLog("This command sends the message to .", BY_SERVER); - chatLog("If the has spaces in it, enclose it in " - "double quotes (\").", BY_SERVER); + chatLog(_("Command: /whisper "), BY_SERVER); + chatLog(_("Command: /w "), BY_SERVER); + chatLog(_("This command sends the message to ."), + BY_SERVER); + chatLog(_("If the has spaces in it, enclose it in " + "double quotes (\")."), BY_SERVER); return; } if (msg1 == "who") { - chatLog("Command: /who", BY_SERVER); - chatLog("This command displays the number of players currently " - "online.", BY_SERVER); + chatLog(_("Command: /who"), BY_SERVER); + chatLog(_("This command displays the number of players currently " + "online."), BY_SERVER); return; } - chatLog("Unknown command.", BY_SERVER); - chatLog("Type /help for a list of commands.", BY_SERVER); + chatLog(_("Unknown command."), BY_SERVER); + chatLog(_("Type /help for a list of commands."), BY_SERVER); } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index 290679b9..a52119b8 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -27,8 +27,10 @@ #include "../resources/resourcemanager.h" +#include "../utils/gettext.h" + HelpWindow::HelpWindow(): - Window("Help") + Window(_("Help")) { setContentSize(455, 350); setWindowName("Help"); @@ -36,7 +38,7 @@ HelpWindow::HelpWindow(): mBrowserBox = new BrowserBox(); mBrowserBox->setOpaque(false); mScrollArea = new ScrollArea(mBrowserBox); - Button *okButton = new Button("Close", "close", this); + Button *okButton = new Button(_("Close"), "close", this); mScrollArea->setDimension(gcn::Rectangle( 5, 5, 445, 335 - okButton->getHeight())); diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index c6247487..de3c0ce1 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -32,6 +32,7 @@ #include "../configuration.h" #include "../keyboardconfig.h" +#include "../utils/gettext.h" #include "../utils/tostring.h" #include @@ -84,13 +85,13 @@ Setup_Keyboard::Setup_Keyboard(): scrollArea->setDimension(gcn::Rectangle(10, 10, 200, 140)); add(scrollArea); - mAssignKeyButton = new Button("Assign", "assign", this); + mAssignKeyButton = new Button(_("Assign"), "assign", this); mAssignKeyButton->setPosition(165, 155); mAssignKeyButton->addActionListener(this); mAssignKeyButton->setEnabled(false); add(mAssignKeyButton); - mMakeDefaultButton = new Button("Default", "makeDefault", this); + mMakeDefaultButton = new Button(_("Default"), "makeDefault", this); mMakeDefaultButton->setPosition(10, 155); mMakeDefaultButton->addActionListener(this); add(mMakeDefaultButton); @@ -111,8 +112,9 @@ void Setup_Keyboard::apply() if (keyboard.hasConflicts()) { - new OkDialog("Key Conflict(s) Detected.", - "Resolve them, or gameplay may result in strange behaviour."); + new OkDialog(_("Key Conflict(s) Detected."), + _("Resolve them, or gameplay may result in strange " + "behaviour.")); } keyboard.setEnabled(true); keyboard.store(); @@ -170,7 +172,7 @@ void Setup_Keyboard::newKeyCallback(int index) void Setup_Keyboard::refreshKeys() { - for(int i = 0; i < keyboard.KEY_TOTAL; i++) + for (int i = 0; i < keyboard.KEY_TOTAL; i++) { refreshAssignedKey(i); } diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index c556a82d..122f54e1 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -30,6 +30,8 @@ #include "../log.h" #include "../sound.h" +#include "../utils/gettext.h" + #include #include @@ -47,10 +49,16 @@ #define WIDGET_AT(row, column) (((row) * COLUMNS_NR) + column) -static std::string table_titles[COLUMNS_NR] = {"name", "relation"}; +static const char *table_titles[COLUMNS_NR] = { + N_("Name"), + N_("Relation") +}; -static const std::string RELATION_NAMES[PlayerRelation::RELATIONS_NR] = { - "neutral", "friend", "disregarded", "ignored" +static const char *RELATION_NAMES[PlayerRelation::RELATIONS_NR] = { + N_("Neutral"), + N_("Friend"), + N_("Disregarded"), + N_("Ignored") }; class PlayerRelationListModel : public gcn::ListModel @@ -67,7 +75,7 @@ public: { if (i >= getNumberOfElements() || i < 0) return ""; - return RELATION_NAMES[i]; + return gettext(RELATION_NAMES[i]); } }; @@ -136,7 +144,8 @@ public: virtual void updateModelInRow(int row) { - gcn::DropDown *choicebox = dynamic_cast(getElementAt(row, RELATION_CHOICE_COLUMN)); + gcn::DropDown *choicebox = dynamic_cast( + getElementAt(row, RELATION_CHOICE_COLUMN)); player_relations.setRelation(getPlayerAt(row), static_cast(choicebox->getSelected())); } @@ -202,21 +211,27 @@ Setup_Players::Setup_Players(): mPlayerTable(new GuiTable(mPlayerTableModel)), mPlayerTitleTable(new GuiTable(mPlayerTableTitleModel)), mPlayerScrollArea(new ScrollArea(mPlayerTable)), - mPersistIgnores(new CheckBox("save player list", player_relations.getPersistIgnores())), - mDefaultTrading(new CheckBox("allow trading", player_relations.getDefault() & PlayerRelation::TRADE)), - mDefaultWhisper(new CheckBox("allow whispers", player_relations.getDefault() & PlayerRelation::WHISPER)), - mDeleteButton(new Button("Delete", ACTION_DELETE, this)), + mPersistIgnores(new CheckBox(_("Save player list"), + player_relations.getPersistIgnores())), + mDefaultTrading(new CheckBox(_("Allow trading"), + player_relations.getDefault() & PlayerRelation::TRADE)), + mDefaultWhisper(new CheckBox(_("Allow whispers"), + player_relations.getDefault() & PlayerRelation::WHISPER)), + mDeleteButton(new Button(_("Delete"), ACTION_DELETE, this)), mIgnoreActionChoicesBox(new gcn::DropDown(new IgnoreChoicesListModel())) { setOpaque(false); int table_width = NAME_COLUMN_WIDTH + RELATION_CHOICE_COLUMN_WIDTH; mPlayerTableTitleModel->fixColumnWidth(NAME_COLUMN, NAME_COLUMN_WIDTH); - mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN, RELATION_CHOICE_COLUMN_WIDTH); + mPlayerTableTitleModel->fixColumnWidth(RELATION_CHOICE_COLUMN, + RELATION_CHOICE_COLUMN_WIDTH); mPlayerTitleTable->setDimension(gcn::Rectangle(10, 10, table_width, 10)); mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf)); - for (int i = 0; i < COLUMNS_NR; i++) - mPlayerTableTitleModel->set(0, i, new gcn::Label(table_titles[i])); + for (int i = 0; i < COLUMNS_NR; i++) { + mPlayerTableTitleModel->set(0, i, + new gcn::Label(gettext(table_titles[i]))); + } mPlayerTitleTable->setLinewiseSelection(true); mPlayerScrollArea->setDimension(gcn::Rectangle(10, 25, table_width + COLUMNS_NR, 90)); @@ -227,7 +242,7 @@ Setup_Players::Setup_Players(): mDeleteButton->setPosition(10, 118); - gcn::Label *ignore_action_label = new gcn::Label("When ignoring:"); + gcn::Label *ignore_action_label = new gcn::Label(_("When ignoring:")); ignore_action_label->setPosition(80, 118); mIgnoreActionChoicesBox->setDimension(gcn::Rectangle(80, 132, 120, 12)); @@ -269,9 +284,9 @@ Setup_Players::~Setup_Players() void Setup_Players::reset() { - // We now have to search through the list of ignore choices to find the current - // selection. We could use an index into the table of config options in - // player_relations instead of strategies to sidestep this. + // We now have to search through the list of ignore choices to find the + // current selection. We could use an index into the table of config + // options in player_relations instead of strategies to sidestep this. int selection = 0; for (unsigned int i = 0; i < player_relations.getPlayerIgnoreStrategies()->size(); ++i) if ((*player_relations.getPlayerIgnoreStrategies())[i] == @@ -303,9 +318,10 @@ void Setup_Players::cancel() void Setup_Players::action(const gcn::ActionEvent &event) { if (event.getId() == ACTION_TABLE) { - // temporarily eliminate ourselves: we are fully aware of this change, so there is no - // need for asynchronous updates. (In fact, thouse might destroy the widet that - // triggered them, which would be rather embarrassing.) + // temporarily eliminate ourselves: we are fully aware of this change, + // so there is no need for asynchronous updates. (In fact, thouse + // might destroy the widet that triggered them, which would be rather + // embarrassing.) player_relations.removeListener(this); int row = mPlayerTable->getSelectedRow(); @@ -336,6 +352,8 @@ void Setup_Players::action(const gcn::ActionEvent &event) void Setup_Players::updatedPlayer(const std::string &name) { mPlayerTableModel->playerRelationsUpdated(); - mDefaultTrading->setSelected(player_relations.getDefault() & PlayerRelation::TRADE); - mDefaultWhisper->setSelected(player_relations.getDefault() & PlayerRelation::WHISPER); + mDefaultTrading->setSelected( + player_relations.getDefault() & PlayerRelation::TRADE); + mDefaultWhisper->setSelected( + player_relations.getDefault() & PlayerRelation::WHISPER); } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 82108f84..8b8c58cd 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -29,12 +29,14 @@ #include "windowcontainer.h" #include "../localplayer.h" +#include "../log.h" #include "../utils/dtor.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/xml.h" -#include "../log.h" -#define SKILLS_FILE "skills.xml" +static const char *SKILLS_FILE = "skills.xml"; struct SkillInfo { std::string name; @@ -73,7 +75,10 @@ public: virtual void update() { - static const SkillInfo fakeSkillInfo = { "Mystery Skill", false }; + static const SkillInfo fakeSkillInfo = { + _("Mystery Skill"), + false + }; mEntriesNr = mDialog->getSkills().size(); resize(); @@ -90,13 +95,13 @@ public: info = &fakeSkillInfo; sprintf(tmp, "%c%s", info->modifiable? ' ' : '*', info->name.c_str()); - gcn::Label *name_label = new gcn::Label(std::string(tmp)); + gcn::Label *name_label = new gcn::Label(tmp); sprintf(tmp, "Lv:%i", skill->lv); - gcn::Label *lv_label = new gcn::Label(std::string(tmp)); + gcn::Label *lv_label = new gcn::Label(tmp); sprintf(tmp, "Sp:%i", skill->sp); - gcn::Label *sp_label = new gcn::Label(std::string(tmp)); + gcn::Label *sp_label = new gcn::Label(tmp); set(i, 0, name_label); set(i, 1, lv_label); @@ -111,7 +116,7 @@ private: SkillDialog::SkillDialog(): - Window("Skills") + Window(_("Skills")) { initSkillinfo(); mTableModel = new SkillGuiTableModel(this); @@ -124,9 +129,9 @@ SkillDialog::SkillDialog(): // mSkillListBox = new ListBox(this); ScrollArea *skillScrollArea = new ScrollArea(&mTable); - mPointsLabel = new gcn::Label("Skill Points:"); - mIncButton = new Button("Up", "inc", this); - mUseButton = new Button("Use", "use", this); + mPointsLabel = new gcn::Label(strprintf(_("Skill points: %d"), 0)); + mIncButton = new Button(_("Up"), "inc", this); + mUseButton = new Button(_("Use"), "use", this); mUseButton->setEnabled(false); // mSkillListBox->setActionEventId("skill"); @@ -180,11 +185,8 @@ void SkillDialog::action(const gcn::ActionEvent &event) void SkillDialog::update() { - if (mPointsLabel != NULL) { - char tmp[128]; - sprintf(tmp, "Skill points: %i", player_node->mSkillPoint); - mPointsLabel->setCaption(tmp); - } + mPointsLabel->setCaption(strprintf(_("Skill points: %d"), + player_node->mSkillPoint)); int selectedSkill = mTable.getSelectedRow(); @@ -254,8 +256,7 @@ static void initSkillinfo() if (!root || !xmlStrEqual(root->name, BAD_CAST "skills")) { - logger->log("Error loading skills file: " - SKILLS_FILE); + logger->log("Error loading skills file: %s", SKILLS_FILE); skill_db.resize(2, emptySkillInfo); skill_db[1].name = "Basic"; skill_db[1].modifiable = true; diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 1a257ae8..a5bb77c3 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -29,6 +29,8 @@ #include "../localplayer.h" +#include "../utils/gettext.h" +#include "../utils/strprintf.h" #include "../utils/tostring.h" StatusWindow::StatusWindow(LocalPlayer *player): @@ -46,25 +48,25 @@ StatusWindow::StatusWindow(LocalPlayer *player): // Status Part // ---------------------- - mLvlLabel = new gcn::Label("Level:"); - mGpLabel = new gcn::Label("Money:"); - mJobLvlLabel = new gcn::Label("Job:"); + mLvlLabel = new gcn::Label(strprintf(_("Level: %d"), 0)); + mGpLabel = new gcn::Label(strprintf(_("Job: %d"), 0)); + mJobLvlLabel = new gcn::Label(strprintf(_("Money: %d GP"), 0)); mHpLabel = new gcn::Label("HP:"); mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34); - mHpValueLabel = new gcn::Label(""); + mHpValueLabel = new gcn::Label; mXpLabel = new gcn::Label("Exp:"); mXpBar = new ProgressBar(1.0f, 80, 15, 143, 192, 211); - mXpValueLabel = new gcn::Label(""); + mXpValueLabel = new gcn::Label; mMpLabel = new gcn::Label("MP:"); mMpBar = new ProgressBar(1.0f, 80, 15, 26, 102, 230); - mMpValueLabel = new gcn::Label(""); + mMpValueLabel = new gcn::Label; mJobXpLabel = new gcn::Label("Job:"); mJobXpBar = new ProgressBar(1.0f, 80, 15, 220, 135, 203); - mJobValueLabel = new gcn::Label(""); + mJobValueLabel = new gcn::Label; int y = 3; int x = 5; @@ -122,34 +124,34 @@ StatusWindow::StatusWindow(LocalPlayer *player): // ---------------------- // Static Labels - gcn::Label *mStatsTitleLabel = new gcn::Label("Stats"); - gcn::Label *mStatsTotalLabel = new gcn::Label("Total"); - gcn::Label *mStatsCostLabel = new gcn::Label("Cost"); + gcn::Label *mStatsTitleLabel = new gcn::Label(_("Stats")); + gcn::Label *mStatsTotalLabel = new gcn::Label(_("Total")); + gcn::Label *mStatsCostLabel = new gcn::Label(_("Cost")); // Derived Stats - mStatsAttackLabel = new gcn::Label("Attack:"); - mStatsDefenseLabel= new gcn::Label("Defense:"); - mStatsMagicAttackLabel = new gcn::Label("M.Attack:"); - mStatsMagicDefenseLabel = new gcn::Label("M.Defense:"); - mStatsAccuracyLabel = new gcn::Label("% Accuracy:"); - mStatsEvadeLabel = new gcn::Label("% Evade:"); - mStatsReflexLabel = new gcn::Label("% Reflex:"); - - mStatsAttackPoints = new gcn::Label(""); - mStatsDefensePoints = new gcn::Label(""); - mStatsMagicAttackPoints = new gcn::Label(""); - mStatsMagicDefensePoints = new gcn::Label(""); - mStatsAccuracyPoints = new gcn::Label("% Accuracy:"); - mStatsEvadePoints = new gcn::Label("% Evade:"); - mStatsReflexPoints = new gcn::Label("% Reflex:"); + mStatsAttackLabel = new gcn::Label(_("Attack:")); + mStatsDefenseLabel= new gcn::Label(_("Defense:")); + mStatsMagicAttackLabel = new gcn::Label(_("M.Attack:")); + mStatsMagicDefenseLabel = new gcn::Label(_("M.Defense:")); + mStatsAccuracyLabel = new gcn::Label(_("% Accuracy:")); + mStatsEvadeLabel = new gcn::Label(_("% Evade:")); + mStatsReflexLabel = new gcn::Label(_("% Reflex:")); + + mStatsAttackPoints = new gcn::Label; + mStatsDefensePoints = new gcn::Label; + mStatsMagicAttackPoints = new gcn::Label; + mStatsMagicDefensePoints = new gcn::Label; + mStatsAccuracyPoints = new gcn::Label; + mStatsEvadePoints = new gcn::Label; + mStatsReflexPoints = new gcn::Label; // New labels for (int i = 0; i < 6; i++) { - mStatsLabel[i] = new gcn::Label(); - mStatsDisplayLabel[i] = new gcn::Label(); + mStatsLabel[i] = new gcn::Label; + mStatsDisplayLabel[i] = new gcn::Label; mPointsLabel[i] = new gcn::Label("0"); } - mRemainingStatsPointsLabel = new gcn::Label(); + mRemainingStatsPointsLabel = new gcn::Label; // Set button events Id mStatsButton[0] = new Button("+", "STR", this); @@ -227,13 +229,13 @@ void StatusWindow::update() { // Status Part // ----------- - mLvlLabel->setCaption("Level: " + toString(mPlayer->mLevel)); + mLvlLabel->setCaption(strprintf(_("Level: %d"), mPlayer->mLevel)); mLvlLabel->adjustSize(); - mJobLvlLabel->setCaption("Job: " + toString(mPlayer->mJobLevel)); + mJobLvlLabel->setCaption(strprintf(_("Job: %d"), mPlayer->mJobLevel)); mJobLvlLabel->adjustSize(); - mGpLabel->setCaption("Money: " + toString(mPlayer->mGp) + " GP"); + mGpLabel->setCaption(strprintf(_("Money: %d GP"), mPlayer->mGp)); mGpLabel->adjustSize(); mHpValueLabel->setCaption(toString(mPlayer->mHp) + @@ -276,20 +278,20 @@ void StatusWindow::update() // Stats Part // ---------- - static const std::string attrNames[6] = { - "Strength", - "Agility", - "Vitality", - "Intelligence", - "Dexterity", - "Luck" + static const char *attrNames[6] = { + N_("Strength"), + N_("Agility"), + N_("Vitality"), + N_("Intelligence"), + N_("Dexterity"), + N_("Luck") }; int statusPoints = mPlayer->mStatsPointsToAttribute; // Update labels for (int i = 0; i < 6; i++) { - mStatsLabel[i]->setCaption(attrNames[i]); + mStatsLabel[i]->setCaption(gettext(attrNames[i])); mStatsDisplayLabel[i]->setCaption(toString((int) mPlayer->mAttr[i])); mPointsLabel[i]->setCaption(toString((int) mPlayer->mAttrUp[i])); @@ -299,8 +301,8 @@ void StatusWindow::update() mStatsButton[i]->setEnabled(mPlayer->mAttrUp[i] <= statusPoints); } - mRemainingStatsPointsLabel->setCaption("Remaining Status Points: " + - toString(statusPoints)); + mRemainingStatsPointsLabel->setCaption( + strprintf(_("Remaining Status Points: %d"), statusPoints)); mRemainingStatsPointsLabel->adjustSize(); // Derived Stats Points @@ -353,12 +355,12 @@ void StatusWindow::update() mXpBar->getX() + mXpBar->getWidth() + 5, mXpLabel->getY()); - mJobXpLabel->setPosition(mXpBar->getX() - mJobXpLabel->getWidth() - 5, + mJobXpLabel->setPosition(mXpBar->getX() - mJobXpLabel->getWidth() - 5, mMpLabel->getY()); mJobXpBar->setPosition( mJobXpLabel->getX() + mJobXpLabel->getWidth() + 5, mJobXpLabel->getY()); - mJobValueLabel->setPosition(mJobXpBar->getX() + mJobXpBar->getWidth() + 5, + mJobValueLabel->setPosition(mJobXpBar->getX() + mJobXpBar->getWidth() + 5, mJobXpLabel->getY()); } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 9b88b6fb..405d871f 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -280,8 +280,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) return; if (mMyInventory->contains(item)) { - chatWindow->chatLog("Failed adding item. You can not " - "overlap one kind of item on the window.", BY_SERVER); + chatWindow->chatLog(_("Failed adding item. You can not " + "overlap one kind of item on the window."), BY_SERVER); return; } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 7f7d45fc..891fa769 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -40,6 +40,7 @@ #include "../log.h" #include "../main.h" +#include "../utils/gettext.h" #include "../utils/tostring.h" #include "../resources/resourcemanager.h" @@ -89,7 +90,7 @@ loadTextFile(const std::string &fileName) UpdaterWindow::UpdaterWindow(const std::string &updateHost, const std::string &updatesDir): - Window("Updating..."), + Window(_("Updating...")), mThread(NULL), mDownloadStatus(UPDATE_NEWS), mUpdateHost(updateHost), @@ -112,10 +113,10 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mBrowserBox = new BrowserBox(); mScrollArea = new ScrollArea(mBrowserBox); - mLabel = new gcn::Label("Connecting..."); + mLabel = new gcn::Label(_("Connecting...")); mProgressBar = new ProgressBar(0.0, w - 10, 20, 37, 70, 200); - mCancelButton = new Button("Cancel", "cancel", this); - mPlayButton = new Button("Play", "play", this); + mCancelButton = new Button(_("Cancel"), "cancel", this); + mPlayButton = new Button(_("Play"), "play", this); mBrowserBox->setOpaque(false); mPlayButton->setEnabled(false); @@ -521,7 +522,7 @@ void UpdaterWindow::logic() break; case UPDATE_COMPLETE: enable(); - setLabel("Completed"); + setLabel(_("Completed")); break; case UPDATE_IDLE: break; diff --git a/src/main.cpp b/src/main.cpp index 3c106633..584ca5d5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -713,7 +713,7 @@ 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); + gcn::Button *setup = new Button(_("Setup"), "Setup", &listener); setup->setPosition(top->getWidth() - setup->getWidth() - 3, 3); top->add(setup); @@ -766,7 +766,7 @@ int main(int argc, char *argv[]) if (!network->getError().empty()) { errorMessage = network->getError(); } else { - errorMessage = "Got disconnected from server!"; + errorMessage = _("Got disconnected from server!"); } } @@ -942,7 +942,7 @@ int main(int argc, char *argv[]) case ERROR_STATE: logger->log("State: ERROR"); - currentDialog = new OkDialog("Error", errorMessage); + currentDialog = new OkDialog(_("Error"), errorMessage); currentDialog->addActionListener(&errorListener); currentDialog = NULL; // OkDialog deletes itself network->disconnect(); @@ -952,7 +952,8 @@ int main(int argc, char *argv[]) case CONNECTING_STATE: logger->log("State: CONNECTING"); progressBar->setVisible(true); - progressLabel->setCaption("Connecting to map server..."); + progressLabel->setCaption( + _("Connecting to map server...")); progressLabel->adjustSize(); mapLogin(network, &loginData); break; @@ -960,7 +961,7 @@ int main(int argc, char *argv[]) case CHAR_CONNECT_STATE: progressBar->setVisible(true); progressLabel->setCaption( - "Connecting to character server..."); + _("Connecting to character server...")); progressLabel->adjustSize(); charLogin(network, &loginData); break; @@ -968,7 +969,7 @@ int main(int argc, char *argv[]) case ACCOUNT_STATE: progressBar->setVisible(true); progressLabel->setCaption( - "Connecting to account server..."); + _("Connecting to account server...")); progressLabel->adjustSize(); accountLogin(network, &loginData); break; -- cgit v1.2.3-70-g09d2 From 48c1d819bdf112754f3d7ad33f499837018f0759 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Fri, 9 Jan 2009 10:08:38 +0100 Subject: Fixed nonsensical percent values in update dialog. --- src/gui/updatewindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 891fa769..c07e0643 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -229,8 +229,9 @@ int UpdaterWindow::updateProgress(void *ptr, float progress = dn / dt; UpdaterWindow *uw = reinterpret_cast(ptr); - if (progress < 0) progress = 0.0f; - if (progress > 1) progress = 1.0f; + if(progress != progress) progress = 0.0f; // check for NaN + if (progress < 0.0f) progress = 0.0f; // no idea how this could ever happen, but why not check for it anyway. + if (progress > 1.0f) progress = 1.0f; uw->setLabel( uw->mCurrentFile + " (" + toString((int) (progress * 100)) + "%)"); -- cgit v1.2.3-70-g09d2 From c5e565e5d4b09e42e0327afd99b8f37d67b9577c Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Fri, 9 Jan 2009 11:20:06 +0100 Subject: Style fix for last commit --- src/gui/updatewindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index c07e0643..a6857d21 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -229,7 +229,7 @@ int UpdaterWindow::updateProgress(void *ptr, float progress = dn / dt; UpdaterWindow *uw = reinterpret_cast(ptr); - if(progress != progress) progress = 0.0f; // check for NaN + if (progress != progress) progress = 0.0f; // check for NaN if (progress < 0.0f) progress = 0.0f; // no idea how this could ever happen, but why not check for it anyway. if (progress > 1.0f) progress = 1.0f; -- cgit v1.2.3-70-g09d2 From 04471a1d4a9575a81016de0375c2000d793a044d Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 11 Apr 2008 23:57:58 +0000 Subject: Removed the rhombs around the radio buttons. (cherry picked from commit 2fd5b9e2fea5f95f54e543011e2e8fb70f0b037f) --- src/gui/radiobutton.cpp | 19 +++++++++++++++++++ src/gui/radiobutton.h | 6 ++++++ 2 files changed, 25 insertions(+) (limited to 'src') diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index 5f929e62..619ec84f 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -81,3 +81,22 @@ void RadioButton::drawBox(gcn::Graphics* graphics) static_cast(graphics)->drawImage(box, 2, 2); } } + +void RadioButton::draw(gcn::Graphics* graphics) +{ + + graphics->pushClipArea(gcn::Rectangle(1, + 1, + getWidth() - 1, + getHeight() - 1)); + + drawBox(graphics); + + graphics->popClipArea(); + + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + + int h = getHeight() + getHeight() / 2; + graphics->drawText(getCaption(), h - 2, 0); +} diff --git a/src/gui/radiobutton.h b/src/gui/radiobutton.h index 6506444f..09f703dc 100644 --- a/src/gui/radiobutton.h +++ b/src/gui/radiobutton.h @@ -48,6 +48,12 @@ class RadioButton : public gcn::RadioButton { */ void drawBox(gcn::Graphics* graphics); + /** + * Implementation of the draw methods. + * Thus, avoiding the rhomb around the radio button. + */ + void draw(gcn::Graphics* graphics); + private: static int instances; static Image *radioNormal; -- cgit v1.2.3-70-g09d2 From 469b6dfc1badbac467b9145d2eaaaa87238087d9 Mon Sep 17 00:00:00 2001 From: Guillaume Melquiond Date: Wed, 14 Nov 2007 10:07:55 +0000 Subject: Improved item amount dialog box. (cherry picked from commit 69c147510bce9aa24be5ddcb3d050a5d52e3abe7) Conflicts: src/gui/item_amount.cpp --- src/gui/inttextbox.cpp | 21 +++++++++++---------- src/gui/inttextbox.h | 4 ++-- 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/gui/inttextbox.cpp b/src/gui/inttextbox.cpp index 4825fbf5..a995f084 100644 --- a/src/gui/inttextbox.cpp +++ b/src/gui/inttextbox.cpp @@ -21,7 +21,7 @@ #include "inttextbox.h" -#include +#include "sdlinput.h" #include "../utils/tostring.h" @@ -35,17 +35,20 @@ IntTextBox::keyPressed(gcn::KeyEvent &event) { const gcn::Key &key = event.getKey(); - if (key.isNumber() || key.getValue() == gcn::Key::BACKSPACE - || key.getValue() == gcn::Key::DELETE) + if (key.getValue() == Key::BACKSPACE || + key.getValue() == Key::DELETE) { - gcn::TextBox::keyPressed(event); + setText(std::string()); + event.consume(); } - std::stringstream s(gcn::TextBox::getText()); + if (!key.isNumber()) return; + TextField::keyPressed(event); + + std::istringstream s(getText()); int i; s >> i; - if (gcn::TextBox::getText() != "") - setInt(i); + setInt(i); } void IntTextBox::setRange(int min, int max) @@ -56,9 +59,7 @@ void IntTextBox::setRange(int min, int max) int IntTextBox::getInt() { - if (gcn::TextBox::getText() == "") - return 0; - return mValue; + return getText().empty() ? mMin : mValue; } void IntTextBox::setInt(int i) diff --git a/src/gui/inttextbox.h b/src/gui/inttextbox.h index 8fc8e404..8dad0c39 100644 --- a/src/gui/inttextbox.h +++ b/src/gui/inttextbox.h @@ -22,12 +22,12 @@ #ifndef INTTEXTBOX_H #define INTTEXTBOX_H -#include "textbox.h" +#include "textfield.h" /** * TextBox which only accepts numbers as input. */ -class IntTextBox : public TextBox +class IntTextBox : public TextField { public: /** -- cgit v1.2.3-70-g09d2 From ed60c53eb2fe5ef377fc726df796d0aaf2005c6c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sat, 10 Jan 2009 00:57:09 +0100 Subject: Merged comment by silene from mainline We should probably look into fixing the thing he's talking about. --- src/gui/browserbox.cpp | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'src') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 2706a4c4..03540d31 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -378,6 +378,10 @@ BrowserBox::draw(gcn::Graphics *graphics) char const *hyphen = "~"; int hyphenWidth = font->getWidth(hyphen); + /* FIXME: This code layout makes it easy to crash remote + clients by talking garbage. Forged long utf-8 characters + will cause either a buffer underflow in substr or an + infinite loop in the main loop. */ do { if (!forced) -- cgit v1.2.3-70-g09d2