From 35ea5c4f99dde984f9b22dd92699c24ac46dc718 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Feb 2009 19:37:43 +0000 Subject: Move check to a more appropriate place It shouldn't have been moved to where it was in the first place, as it doesn't have any effecxt on that code, but was originally on the other code (where it is now). --- src/gui/char_select.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 34218477..6d5e082a 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -152,11 +152,11 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "newdel") { // Check for a character - if (mCharInfo->getEntry() && n_character <= MAX_SLOT + 1) + if (mCharInfo->getEntry()) { new CharDeleteConfirm(this); } - else + else if (n_character <= MAX_SLOT) { // Start new character dialog CharCreateDialog *charCreateDialog = -- cgit v1.2.3-70-g09d2 From b8f0e1755ae8c6acf9bc681a83f18ef6ff0a1172 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Feb 2009 19:37:43 +0000 Subject: Move check to a more appropriate place It shouldn't have been moved to where it was in the first place, as it doesn't have any effecxt on that code, but was originally on the other code (where it is now). --- src/gui/char_select.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index ae78b384..bad6d8de 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -148,11 +148,11 @@ void CharSelectDialog::action(const gcn::ActionEvent &event) else if (event.getId() == "newdel") { // Check for a character - if (mCharInfo->getEntry() && n_character <= MAX_SLOT + 1) + if (mCharInfo->getEntry()) { new CharDeleteConfirm(this); } - else + else if (n_character <= MAX_SLOT) { // Start new character dialog CharCreateDialog *charCreateDialog = -- cgit v1.2.3-70-g09d2 From c3f7f72f37adad5103587069ff549798fc9d652d Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 18 Feb 2009 20:14:23 +0100 Subject: Introduced a toLower method and grouped string utils The string utility methods are now grouped together in the stringutils.h header. Also, a toLower method was added for convenience. --- aethyra.cbp | 4 +-- src/CMakeLists.txt | 4 +-- src/Makefile.am | 4 +-- src/being.cpp | 5 ++- src/configuration.cpp | 2 +- src/emoteshortcut.cpp | 2 +- src/engine.cpp | 4 +-- src/gui/char_select.cpp | 2 +- src/gui/char_server.cpp | 4 +-- src/gui/chat.cpp | 23 +++---------- src/gui/color.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/emotecontainer.cpp | 2 +- src/gui/emoteshortcutcontainer.cpp | 2 +- src/gui/emotewindow.cpp | 2 +- src/gui/equipmentwindow.cpp | 2 +- src/gui/inttextfield.cpp | 2 +- src/gui/inventorywindow.cpp | 2 +- src/gui/itemcontainer.cpp | 2 +- src/gui/itempopup.cpp | 2 +- src/gui/itemshortcutcontainer.cpp | 2 +- src/gui/login.cpp | 2 +- src/gui/ministatus.cpp | 2 +- src/gui/recorder.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/setup_colors.cpp | 2 +- src/gui/setup_keyboard.cpp | 2 +- src/gui/setup_video.cpp | 2 +- src/gui/shortcutcontainer.cpp | 2 +- src/gui/status.cpp | 2 +- src/gui/trade.cpp | 2 +- src/gui/updatewindow.cpp | 2 +- src/gui/viewport.cpp | 2 +- src/itemshortcut.cpp | 2 +- src/localplayer.cpp | 2 +- src/main.cpp | 4 +-- src/map.cpp | 2 +- src/net/charserverhandler.cpp | 4 +-- src/net/chathandler.cpp | 3 +- src/net/inventoryhandler.cpp | 2 +- src/net/loginhandler.cpp | 4 +-- src/net/network.cpp | 4 +-- src/net/playerhandler.cpp | 2 +- src/resources/itemdb.cpp | 9 ++--- src/resources/mapreader.cpp | 2 +- src/utils/stringutils.cpp | 64 +++++++++++++++++++++++++++++++++++ src/utils/stringutils.h | 69 ++++++++++++++++++++++++++++++++++++++ src/utils/trim.h | 52 ---------------------------- 48 files changed, 192 insertions(+), 133 deletions(-) create mode 100644 src/utils/stringutils.cpp create mode 100644 src/utils/stringutils.h delete mode 100644 src/utils/trim.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index 08ec74fd..29bc7227 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -420,10 +420,10 @@ + + - - diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 25bcbfb0..51d6b937 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -296,10 +296,10 @@ SET(SRCS utils/dtor.h utils/fastsqrt.h utils/gettext.h + utils/stringutils.cpp + utils/stringutils.h utils/strprintf.cpp utils/strprintf.h - utils/tostring.h - utils/trim.h utils/xml.cpp utils/xml.h animatedsprite.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 71862994..6b5dda8b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -246,10 +246,10 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ utils/dtor.h \ utils/fastsqrt.h \ utils/gettext.h \ + utils/stringutils.cpp \ + utils/stringutils.h \ utils/strprintf.cpp \ utils/strprintf.h \ - utils/tostring.h \ - utils/trim.h \ utils/mutex.h \ utils/xml.cpp \ utils/xml.h \ diff --git a/src/being.cpp b/src/being.cpp index 34b042e8..3f34948e 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -50,9 +50,8 @@ #include "gui/speechbubble.h" #include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/tostring.h" -#include "utils/trim.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" #include "utils/xml.h" int Being::instances = 0; diff --git a/src/configuration.cpp b/src/configuration.cpp index 2224a6c7..0df666ab 100644 --- a/src/configuration.cpp +++ b/src/configuration.cpp @@ -24,7 +24,7 @@ #include "configuration.h" #include "log.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" #include "utils/xml.h" void ConfigurationObject::setValue(const std::string &key, std::string value) diff --git a/src/emoteshortcut.cpp b/src/emoteshortcut.cpp index c1ca3c2c..b229ec70 100644 --- a/src/emoteshortcut.cpp +++ b/src/emoteshortcut.cpp @@ -25,7 +25,7 @@ #include "configuration.h" #include "localplayer.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" EmoteShortcut::EmoteShortcut *emoteShortcut; diff --git a/src/engine.cpp b/src/engine.cpp index d491b3ff..cc19bd72 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -40,9 +40,7 @@ #include "resources/mapreader.h" #include "resources/resourcemanager.h" -#include "utils/tostring.h" - -char itemCurrenyQ[10] = "0"; +#include "utils/stringutils.h" Engine::Engine(Network *network): mCurrentMap(NULL), diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index bad6d8de..fa0594d6 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -46,7 +46,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" // Defined in main.cpp, used here for setting the char create dialog extern CharServerHandler charServerHandler; diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 60f8f5dd..6977a104 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -30,7 +30,7 @@ #include "../serverinfo.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern SERVER_INFO **server_info; @@ -102,7 +102,7 @@ void ServerSelectDialog::action(const gcn::ActionEvent &event) { mOkButton->setEnabled(false); const SERVER_INFO *si = server_info[mServerList->getSelected()]; - mLoginData->hostname = iptostring(si->address); + mLoginData->hostname = ipToString(si->address); mLoginData->port = si->port; mLoginData->updateHost = si->updateHost; state = mNextState; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 0e8810ac..91e410ce 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -47,8 +47,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" ChatWindow::ChatWindow(Network * network): Window(""), mNetwork(network), mTmpVisible(false) @@ -336,15 +335,8 @@ void ChatWindow::whisper(const std::string &nick, std::string msg) std::string playerName = player_node->getName(); std::string tempNick = recvnick; - for (unsigned int i = 0; i < playerName.size(); i++) - { - playerName[i] = (char) tolower(playerName[i]); - } - - for (unsigned int i = 0; i < tempNick.size(); i++) - { - tempNick[i] = (char) tolower(tempNick[i]); - } + toLower(playerName); + toLower(tempNick); if (tempNick.compare(playerName) == 0 || msg.empty()) return; @@ -405,14 +397,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) start = msg.find('[', start + 1); } - std::string temp = msg.substr(start+1, end - start - 1); - - trim(temp); + std::string temp = msg.substr(start + 1, end - start - 1); - for (unsigned int i = 0; i < temp.size(); i++) - { - temp[i] = (char) tolower(temp[i]); - } + toLower(trim(temp)); const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) diff --git a/src/gui/color.cpp b/src/gui/color.cpp index aa249077..b68bf68b 100644 --- a/src/gui/color.cpp +++ b/src/gui/color.cpp @@ -24,7 +24,7 @@ #include "../configuration.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" Color::Color() { diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 2d8bb826..c41e0a5e 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -34,7 +34,7 @@ #include "../particle.h" #include "../map.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" DebugWindow::DebugWindow(): Window("Debug") diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index 721a0ebd..c4cace55 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -39,7 +39,7 @@ #include "../utils/dtor.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" const int EmoteContainer::gridWidth = 34; // emote icon width + 4 const int EmoteContainer::gridHeight = 36; // emote icon height + 4 diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index af83a743..e828df8b 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -39,7 +39,7 @@ #include "../utils/dtor.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" static const int MAX_ITEMS = 12; diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp index 8cf1d730..30129941 100644 --- a/src/gui/emotewindow.cpp +++ b/src/gui/emotewindow.cpp @@ -30,7 +30,7 @@ #include "../localplayer.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" EmoteWindow::EmoteWindow(): Window(_("Emote")) diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index fae517a9..6be55e1c 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -41,7 +41,7 @@ #include "../resources/resourcemanager.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" // Positions of the boxes, 2nd dimension is X and Y respectively. static const int boxPosition[][2] = { diff --git a/src/gui/inttextfield.cpp b/src/gui/inttextfield.cpp index adade3b9..40bbd887 100644 --- a/src/gui/inttextfield.cpp +++ b/src/gui/inttextfield.cpp @@ -22,7 +22,7 @@ #include "inttextfield.h" #include "sdlinput.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" IntTextField::IntTextField(int def): TextField(toString(def)), diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index ec825ae3..e8457337 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -44,7 +44,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" InventoryWindow::InventoryWindow(int invSize): Window(_("Inventory")), diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index e84c79ca..79aeb227 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -38,7 +38,7 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" const int ItemContainer::gridWidth = 36; // item icon width + 4 const int ItemContainer::gridHeight = 42; // item icon height + 10 diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index d13cd1c2..88afcd5b 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -36,7 +36,7 @@ #include "../resources/iteminfo.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" ItemPopup::ItemPopup(): Window() diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 324e1b6c..10ced157 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -36,7 +36,7 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" ItemShortcutContainer::ItemShortcutContainer(): ShortcutContainer(), diff --git a/src/gui/login.cpp b/src/gui/login.cpp index 159b7f6f..cd331322 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -39,7 +39,7 @@ #include "../configuration.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" static const int MAX_SERVER_LIST_SIZE = 5; static const int LOGIN_DIALOG_WIDTH = 220; diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 629cf45c..6537b48e 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -28,7 +28,7 @@ #include "../graphics.h" #include "../localplayer.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" MiniStatusWindow::MiniStatusWindow(): Window("") diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index 982d808d..ff8825ef 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -28,7 +28,7 @@ #include "widgets/layout.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" Recorder::Recorder(ChatWindow *chat, const std::string &title, const std::string &buttonTxt) : diff --git a/src/gui/register.cpp b/src/gui/register.cpp index fd7df18d..13928e41 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -40,7 +40,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** * Listener used while dealing with wrong data. It is used to direct the focus diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index f3fa3c65..31b56b51 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -40,7 +40,7 @@ #include "../configuration.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" Setup_Colors::Setup_Colors() : mSelected(-1) diff --git a/src/gui/setup_keyboard.cpp b/src/gui/setup_keyboard.cpp index 1fb0b443..0f79e3c6 100644 --- a/src/gui/setup_keyboard.cpp +++ b/src/gui/setup_keyboard.cpp @@ -36,7 +36,7 @@ #include "../keyboardconfig.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** * The list model for key function list. diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 34dfde0f..8b21582e 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -47,7 +47,7 @@ #include "../particle.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern Graphics *graphics; diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index cc559def..13ff042d 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -26,7 +26,7 @@ #include "../resources/image.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" float ShortcutContainer::mAlpha = config.getValue("guialpha", 0.8); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 42a48b2f..49af3ae2 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -33,7 +33,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" StatusWindow::StatusWindow(LocalPlayer *player): Window(player->getName()), diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index c57cac59..ba2e2462 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -44,7 +44,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" TradeWindow::TradeWindow(Network *network): Window(_("Trade: You")), diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index a25d57d4..81dcb047 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -45,7 +45,7 @@ #include "../resources/resourcemanager.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** * Calculates the Alder-32 checksum for the given file. diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 79a37227..9a7f6173 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -37,7 +37,7 @@ #include "../resources/monsterinfo.h" #include "../resources/resourcemanager.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern volatile int tick_time; diff --git a/src/itemshortcut.cpp b/src/itemshortcut.cpp index fd32c4f5..0627ccda 100644 --- a/src/itemshortcut.cpp +++ b/src/itemshortcut.cpp @@ -26,7 +26,7 @@ #include "itemshortcut.h" #include "localplayer.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" ItemShortcut::ItemShortcut *itemShortcut; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 0470fefc..608c25b8 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -45,7 +45,7 @@ #include "resources/imageset.h" #include "resources/resourcemanager.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" LocalPlayer *player_node = NULL; diff --git a/src/main.cpp b/src/main.cpp index a6ddd597..06ec2f75 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -81,7 +81,7 @@ #include "resources/resourcemanager.h" #include "utils/gettext.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" #ifdef __APPLE__ #include @@ -964,7 +964,7 @@ int main(int argc, char *argv[]) if (n_server == 1) { SERVER_INFO *si = *server_info; - loginData.hostname = iptostring(si->address); + loginData.hostname = ipToString(si->address); loginData.port = si->port; loginData.updateHost = si->updateHost; state = UPDATE_STATE; diff --git a/src/map.cpp b/src/map.cpp index 5e38aee2..b780b5cc 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -37,7 +37,7 @@ #include "resources/resourcemanager.h" #include "utils/dtor.h" -#include "utils/tostring.h" +#include "utils/stringutils.h" extern volatile int tick_time; diff --git a/src/net/charserverhandler.cpp b/src/net/charserverhandler.cpp index 5bf45bb4..95555300 100644 --- a/src/net/charserverhandler.cpp +++ b/src/net/charserverhandler.cpp @@ -34,7 +34,7 @@ #include "../gui/ok_dialog.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" CharServerHandler::CharServerHandler(): mCharCreateDialog(0) @@ -166,7 +166,7 @@ void CharServerHandler::handleMessage(MessageIn *msg) slot = mCharInfo->getPos(); msg->skip(4); // CharID, must be the same as player_node->charID map_path = msg->readString(16); - mLoginData->hostname = iptostring(msg->readInt32()); + mLoginData->hostname = ipToString(msg->readInt32()); mLoginData->port = msg->readInt16(); mCharInfo->unlock(); mCharInfo->select(0); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 14566b39..6717f515 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -35,8 +35,7 @@ #include "../gui/chat.h" #include "../utils/gettext.h" -#include "../utils/tostring.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" extern Being *player_node; diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index ac5f94d3..8ea0071d 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -38,7 +38,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" InventoryHandler::InventoryHandler() { diff --git a/src/net/loginhandler.cpp b/src/net/loginhandler.cpp index e173252f..cf45dbd4 100644 --- a/src/net/loginhandler.cpp +++ b/src/net/loginhandler.cpp @@ -31,7 +31,7 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" extern SERVER_INFO **server_info; @@ -111,7 +111,7 @@ void LoginHandler::handleMessage(MessageIn *msg) logger->log("Network: Server: %s (%s:%d)", server_info[i]->name.c_str(), - iptostring(server_info[i]->address), + ipToString(server_info[i]->address), server_info[i]->port); } state = CHAR_SERVER_STATE; diff --git a/src/net/network.cpp b/src/net/network.cpp index 02d8bf4f..0126ad6d 100644 --- a/src/net/network.cpp +++ b/src/net/network.cpp @@ -27,7 +27,7 @@ #include "network.h" #include "../log.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" /** Warning: buffers and other variables are shared, so there can be only one connection active at a time */ @@ -327,7 +327,7 @@ bool Network::realConnect() } logger->log("Network::Started session with %s:%i", - iptostring(ipAddress.host), ipAddress.port); + ipToString(ipAddress.host), ipAddress.port); mState = CONNECTED; diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 9c34cec6..bce53ae9 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -39,7 +39,7 @@ #include "../gui/skill.h" #include "../gui/viewport.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" #include "../utils/gettext.h" // TODO Move somewhere else diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index ceaf0395..0031bbd0 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -30,7 +30,7 @@ #include "../utils/dtor.h" #include "../utils/gettext.h" -#include "../utils/trim.h" +#include "../utils/stringutils.h" #include "../utils/xml.h" namespace @@ -125,12 +125,7 @@ void ItemDB::load() if (itr == mNamedItemInfos.end()) { std::string temp = name; - trim(temp); - - for (unsigned int i = 0; i < temp.size(); i++) - { - temp[i] = (char) tolower(temp[i]); - } + toLower(trim(temp)); mNamedItemInfos[temp] = itemInfo; } diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 840f0677..901a2561 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -34,7 +34,7 @@ #include "../tileset.h" #include "../utils/base64.h" -#include "../utils/tostring.h" +#include "../utils/stringutils.h" #include "../utils/xml.h" const unsigned int DEFAULT_TILE_WIDTH = 32; diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp new file mode 100644 index 00000000..d414d665 --- /dev/null +++ b/src/utils/stringutils.cpp @@ -0,0 +1,64 @@ +/* + * Aethyra + * Copyright (C) 2007 The Mana World Development Team + * + * This file is part of Aethyra based on original code + * from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "stringutils.h" + +#include + +std::string &trim(std::string &str) +{ + std::string::size_type pos = str.find_last_not_of(' '); + if (pos != std::string::npos) + { + str.erase(pos + 1); + pos = str.find_first_not_of(' '); + if (pos != std::string::npos) + { + str.erase(0, pos); + } + } + else + { + // There is nothing else but whitespace in the string + str.clear(); + } + return str; +} + +std::string &toLower(std::string &str) +{ + std::transform(str.begin(), str.end(), str.begin(), tolower); + return str; +} + +const char *ipToString(int address) +{ + static char asciiIP[16]; + + sprintf(asciiIP, "%i.%i.%i.%i", + (unsigned char)(address), + (unsigned char)(address >> 8), + (unsigned char)(address >> 16), + (unsigned char)(address >> 24)); + + return asciiIP; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h new file mode 100644 index 00000000..7d8df748 --- /dev/null +++ b/src/utils/stringutils.h @@ -0,0 +1,69 @@ +/* + * Aethyra + * Copyright (C) 2007 The Mana World Development Team + * + * This file is part of Aethyra based on original code + * from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef UTILS_STRINGUTILS_H +#define UTILS_STRINGUTILS_H + +#include +#include + +/** + * Trims spaces off the end and the beginning of the given string. + * + * @param str the string to trim spaces off + * @return a reference to the trimmed string + */ +std::string &trim(std::string &str); + +/** + * Converts the given string to lower case. + * + * @param str the string to convert to lower case + * @return a reference to the given string converted to lower case + */ +std::string &toLower(std::string &str); + +/** + * Converts the given value to a string using std::stringstream. + * + * @param arg the value to convert to a string + * @return the string representation of arg + */ +template std::string toString(const T &arg) +{ + std::stringstream ss; + ss << arg; + return ss.str(); +} + +/** + * Converts the given IP address to a string. + * + * The returned string is statically allocated, and shouldn't be freed. It is + * changed upon the next use of this method. + * + * @param address the address to convert to a string + * @return the string representation of the address + */ +const char *ipToString(int address); + +#endif // UTILS_STRINGUTILS_H diff --git a/src/utils/trim.h b/src/utils/trim.h deleted file mode 100644 index 0602842f..00000000 --- a/src/utils/trim.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * Aethyra - * Copyright (C) 2007 The Mana World Development Team - * - * This file is part of Aethyra based on original code - * from The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef UTILS_TRIM_H -#define UTILS_TRIM_H - -#include - -/** - * Trims spaces off the end and the beginning of the given string. - * - * @param str the string to trim spaces off - */ -inline void trim(std::string &str) -{ - std::string::size_type pos = str.find_last_not_of(' '); - if (pos != std::string::npos) - { - str.erase(pos + 1); - pos = str.find_first_not_of(' '); - if (pos != std::string::npos) - { - str.erase(0, pos); - } - } - else - { - // There is nothing else but whitespace in the string - str.clear(); - } -} - -#endif -- cgit v1.2.3-70-g09d2 From 1713f33dbd71b6378c8a4e58452fb16147f320d7 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Fri, 20 Feb 2009 00:19:52 +0100 Subject: Added a pickup notification as particle effect. Also make a ui option to enable/disable this effect (default is off) and another option to disable the pickup notification in the chat log (default is on). --- src/gui/gui.cpp | 1 + src/gui/gui.h | 8 ++++++++ src/gui/setup_video.cpp | 41 +++++++++++++++++++++++++++++++++++------ src/gui/setup_video.h | 6 ++++++ src/gui/truetypefont.cpp | 3 ++- src/gui/truetypefont.h | 2 +- src/localplayer.cpp | 12 ++++++++++++ src/localplayer.h | 5 +++++ src/net/inventoryhandler.cpp | 15 ++++++++++++--- src/particle.cpp | 11 +++++++---- src/particle.h | 8 +++++--- src/textparticle.cpp | 23 +++++++++++++++++++++-- src/textparticle.h | 4 +++- 13 files changed, 118 insertions(+), 21 deletions(-) (limited to 'src/gui') diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 9b9e74f4..431e4d2d 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -112,6 +112,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); + mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 5c0c24f7..d5680412 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -76,6 +76,13 @@ class Gui : public gcn::Gui gcn::Font* getFont() const { return mGuiFont; } + /** + * Return the Font used for "Info Particles", i.e. ones showing, what + * you picked up, etc. + */ + gcn::Font* getInfoParticleFont() const + { return mInfoParicleFont; } + /** * Sets whether a custom cursor should be rendered. */ @@ -107,6 +114,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ + gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index aa39dd36..37197cd2 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -109,6 +109,8 @@ Setup_Video::Setup_Video(): mCustomCursorEnabled(config.getValue("customcursor", true)), mParticleEffectsEnabled(config.getValue("particleeffects", true)), mNameEnabled(config.getValue("showownname", false)), + mPickupChatEnabled(config.getValue("showpickupchat", true)), + mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 0)), mSpeechMode((int) config.getValue("speech", 3)), @@ -136,7 +138,11 @@ Setup_Video::Setup_Video(): mOverlayDetailField(new gcn::Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")) + mParticleDetailField(new gcn::Label("")), + mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), + mPickupParticleCheckBox(new CheckBox(_("as particle"), + mPickupParticleEnabled)) { setOpaque(false); @@ -169,6 +175,8 @@ Setup_Video::Setup_Video(): mModeList->setActionEventId("videomode"); mCustomCursorCheckBox->setActionEventId("customcursor"); mParticleEffectsCheckBox->setActionEventId("particleeffects"); + mPickupChatCheckBox->setActionEventId("pickupchat"); + mPickupParticleCheckBox->setActionEventId("pickupparticle"); mNameCheckBox->setActionEventId("showownname"); mAlphaSlider->setActionEventId("guialpha"); mFpsCheckBox->setActionEventId("fpslimitcheckbox"); @@ -186,6 +194,8 @@ Setup_Video::Setup_Video(): mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); + mPickupChatCheckBox->addActionListener(this); + mPickupParticleCheckBox->addActionListener(this); mNameCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); @@ -260,11 +270,14 @@ Setup_Video::Setup_Video(): ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, scrollArea, 1, 6).setPadding(2); - place(1, 0, mFsCheckBox, 3); - place(1, 1, mOpenGLCheckBox, 3); - place(1, 2, mCustomCursorCheckBox, 3); - place(1, 3, mNameCheckBox, 3); - place(1, 4, mParticleEffectsCheckBox, 3); + place(1, 0, mFsCheckBox, 2); + place(3, 0, mOpenGLCheckBox, 1); + place(1, 1, mCustomCursorCheckBox, 3); + place(1, 2, mNameCheckBox, 3); + place(1, 3, mParticleEffectsCheckBox, 3); + place(1, 4, mPickupNotifyLabel, 3); + place(1, 5, mPickupChatCheckBox, 1); + place(2, 5, mPickupParticleCheckBox, 2); place(0, 6, mAlphaSlider); place(0, 7, mFpsSlider); @@ -354,6 +367,8 @@ void Setup_Video::apply() mOpacity = config.getValue("guialpha", 0.8); mOverlayDetail = (int) config.getValue("OverlayDetail", 2); mOpenGLEnabled = config.getValue("opengl", false); + mPickupChatEnabled = config.getValue("showpickupchat", true); + mPickupParticleEnabled = config.getValue("showpickupparticle", false); } int Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, @@ -400,6 +415,9 @@ void Setup_Video::cancel() config.setValue("showownname", mNameEnabled ? true : false); config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); + config.setValue("showpickupchat", mPickupChatEnabled ? true : false); + config.setValue("showpickupparticle", mPickupParticleEnabled ? + true : false); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -433,6 +451,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) new OkDialog(_("Particle effect settings changed"), _("Restart your client or change maps for the change to take effect.")); } + else if (event.getId() == "pickupchat") + { + config.setValue("showpickupchat", mPickupChatCheckBox->isSelected() + ? true : false); + } + else if (event.getId() == "pickupparticle") + { + config.setValue("showpickupparticle", + mPickupParticleCheckBox->isSelected() + ? true : false); + } else if (event.getId() == "speech") { int val = (int) mSpeechSlider->getValue(); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index e57e33cc..7d9732a1 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -52,6 +52,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mCustomCursorEnabled; bool mParticleEffectsEnabled; bool mNameEnabled; + bool mPickupChatEnabled; + bool mPickupParticleEnabled; double mOpacity; int mFps; int mSpeechMode; @@ -72,6 +74,10 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, gcn::CheckBox *mParticleEffectsCheckBox; gcn::CheckBox *mNameCheckBox; + gcn::Label *mPickupNotifyLabel; + gcn::CheckBox *mPickupChatCheckBox; + gcn::CheckBox *mPickupParticleCheckBox; + gcn::Slider *mSpeechSlider; gcn::Label *mSpeechLabel; gcn::Slider *mAlphaSlider; diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 7c72e2f5..b4b839e9 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -76,7 +76,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, int style) { if (fontCounter == 0 && TTF_Init() == -1) { @@ -86,6 +86,7 @@ TrueTypeFont::TrueTypeFont(const std::string &filename, int size) ++fontCounter; mFont = TTF_OpenFont(filename.c_str(), size); + TTF_SetFontStyle (mFont, style); if (!mFont) { diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 71b45fd1..de146087 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -48,7 +48,7 @@ class TrueTypeFont : public gcn::Font * @param filename Font filename. * @param size Font size. */ - TrueTypeFont(const std::string &filename, int size); + TrueTypeFont(const std::string &filename, int size, int style = 0); /** * Destructor. diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b9654e63..ea05bd7e 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -587,6 +587,18 @@ void LocalPlayer::setXp(int xp) mXp = xp; } +void LocalPlayer::pickedUp(std::string item) +{ + if (mMap) + { + // Show pickup notification + particleEngine->addTextRiseFadeOutEffect(item, + gui->getInfoParticleFont (), + mPx + 16, mPy - 16, + 40, 220, 40, true); + } +} + bool LocalPlayer::withinAttackRange(Being *target) { int dist_x = abs(target->mX - mX); diff --git a/src/localplayer.h b/src/localplayer.h index 5f02de4f..2226671b 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -202,6 +202,11 @@ class LocalPlayer : public Player */ void setXp(int xp); + /** + * Shows item pickup effect if the player is on a map. + */ + void pickedUp(std::string item); + /** * Returns the amount of experience points. */ diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index d5ac0c29..a227701e 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -25,6 +25,7 @@ #include "messagein.h" #include "protocol.h" +#include "../configuration.h" #include "../inventory.h" #include "../item.h" #include "../itemshortcut.h" @@ -141,13 +142,21 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemType = msg->readInt8(); if (msg->readInt8() > 0) { - chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + } } else { const ItemInfo &itemInfo = ItemDB::get(itemId); const std::string amountStr = (amount > 1) ? toString(amount) : "a"; - chatWindow->chatLog(strprintf(_("You picked up %s %s"), - amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(strprintf(_("You picked up %s %s"), + amountStr.c_str(), itemInfo.getName().c_str()), + BY_SERVER); + } + if (config.getValue("showpickupparticle", false)) { + player_node->pickedUp(itemInfo.getName()); + } if (Item *item = inventory->getItem(index)) { item->setId(itemId); diff --git a/src/particle.cpp b/src/particle.cpp index 45cbb4c9..6dc45a08 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -326,10 +326,10 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, Particle *Particle::addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y) + gcn::Font *font, int x, int y, bool outline) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font); + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -346,9 +346,12 @@ Particle *Particle::addTextSplashEffect(const std::string &text, Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y) + int x, int y, + int colorR, int colorG, + int colorB, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); + Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index 1baf11f8..b4c80194 100644 --- a/src/particle.h +++ b/src/particle.h @@ -107,15 +107,17 @@ class Particle : public Sprite */ Particle *addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y); + gcn::Font *font, int x, int y, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y); - + int x, int y, int colorR = 255, + int colorG = 255, int colorB = 255, + bool outline = false); /** * Adds an emitter to the particle. */ diff --git a/src/textparticle.cpp b/src/textparticle.cpp index f38c32ce..3494b97f 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -23,16 +23,18 @@ #include "graphics.h" #include "textparticle.h" +#include TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font): + gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), mColorR(colorR), mColorG(colorG), - mColorB(colorB) + mColorB(colorB), + mOutline(outline) { } @@ -59,6 +61,23 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const } graphics->setFont(mTextFont); + if (mOutline) + { + graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); + // Text outline + graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); + graphics->drawText(mText, screenX + 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX - 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY + 1, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY - 1, + gcn::Graphics::CENTER); + } graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } diff --git a/src/textparticle.h b/src/textparticle.h index 76c247bf..d72df138 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,7 +33,7 @@ class TextParticle : public Particle */ TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font); + gcn::Font *font, bool outline = false); /** * Draws the particle image. @@ -48,6 +48,8 @@ class TextParticle : public Particle std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text readable - draw it the way + a Text is usually drawn: with outline */ }; #endif -- cgit v1.2.3-70-g09d2 From c16086df4022e5c6c9818dbcaf02ffeb6d6684d7 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 20 Feb 2009 07:32:46 -0700 Subject: Restore old middle click behavior --- src/gui/viewport.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a1a02e1e..1ac82281 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -336,7 +336,8 @@ void Viewport::mousePressed(gcn::MouseEvent &event) else if (event.getButton() == gcn::MouseEvent::MIDDLE) { // Find the being nearest to the clicked position - Being *target = beingManager->findBeingByPixel(x, y); + Being *target = beingManager->findNearestLivingBeing(tilex, tiley, 20, + Being::MONSTER); if (target) { -- cgit v1.2.3-70-g09d2 From b2eb8daa8c39bcfd5fbd3a76dbbc432b43c561a9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Fri, 20 Feb 2009 00:19:52 +0100 Subject: Added a pickup notification as particle effect. Also make a ui option to enable/disable this effect (default is off) and another option to disable the pickup notification in the chat log (default is on). --- src/gui/gui.cpp | 1 + src/gui/gui.h | 8 ++++++++ src/gui/setup_video.cpp | 41 +++++++++++++++++++++++++++++++++++------ src/gui/setup_video.h | 6 ++++++ src/gui/truetypefont.cpp | 3 ++- src/gui/truetypefont.h | 2 +- src/localplayer.cpp | 12 ++++++++++++ src/localplayer.h | 5 +++++ src/net/inventoryhandler.cpp | 15 ++++++++++++--- src/particle.cpp | 11 +++++++---- src/particle.h | 8 +++++--- src/textparticle.cpp | 23 +++++++++++++++++++++-- src/textparticle.h | 4 +++- 13 files changed, 118 insertions(+), 21 deletions(-) (limited to 'src/gui') diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 4b5c375d..ed85fa8f 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -113,6 +113,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); + mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { diff --git a/src/gui/gui.h b/src/gui/gui.h index 0c6529bd..e19a0a87 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -77,6 +77,13 @@ class Gui : public gcn::Gui gcn::Font* getFont() const { return mGuiFont; } + /** + * Return the Font used for "Info Particles", i.e. ones showing, what + * you picked up, etc. + */ + gcn::Font* getInfoParticleFont() const + { return mInfoParicleFont; } + /** * Sets whether a custom cursor should be rendered. */ @@ -108,6 +115,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ + gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 8b21582e..35c58ecd 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -110,6 +110,8 @@ Setup_Video::Setup_Video(): mCustomCursorEnabled(config.getValue("customcursor", true)), mParticleEffectsEnabled(config.getValue("particleeffects", true)), mNameEnabled(config.getValue("showownname", false)), + mPickupChatEnabled(config.getValue("showpickupchat", true)), + mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 0)), mSpeechMode((int) config.getValue("speech", 3)), @@ -137,7 +139,11 @@ Setup_Video::Setup_Video(): mOverlayDetailField(new gcn::Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")) + mParticleDetailField(new gcn::Label("")), + mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), + mPickupParticleCheckBox(new CheckBox(_("as particle"), + mPickupParticleEnabled)) { setOpaque(false); @@ -170,6 +176,8 @@ Setup_Video::Setup_Video(): mModeList->setActionEventId("videomode"); mCustomCursorCheckBox->setActionEventId("customcursor"); mParticleEffectsCheckBox->setActionEventId("particleeffects"); + mPickupChatCheckBox->setActionEventId("pickupchat"); + mPickupParticleCheckBox->setActionEventId("pickupparticle"); mNameCheckBox->setActionEventId("showownname"); mAlphaSlider->setActionEventId("guialpha"); mFpsCheckBox->setActionEventId("fpslimitcheckbox"); @@ -187,6 +195,8 @@ Setup_Video::Setup_Video(): mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); + mPickupChatCheckBox->addActionListener(this); + mPickupParticleCheckBox->addActionListener(this); mNameCheckBox->addActionListener(this); mAlphaSlider->addActionListener(this); mFpsCheckBox->addActionListener(this); @@ -261,11 +271,14 @@ Setup_Video::Setup_Video(): ContainerPlacer place = h.getPlacer(0, 0); place(0, 0, scrollArea, 1, 6).setPadding(2); - place(1, 0, mFsCheckBox, 3); - place(1, 1, mOpenGLCheckBox, 3); - place(1, 2, mCustomCursorCheckBox, 3); - place(1, 3, mNameCheckBox, 3); - place(1, 4, mParticleEffectsCheckBox, 3); + place(1, 0, mFsCheckBox, 2); + place(3, 0, mOpenGLCheckBox, 1); + place(1, 1, mCustomCursorCheckBox, 3); + place(1, 2, mNameCheckBox, 3); + place(1, 3, mParticleEffectsCheckBox, 3); + place(1, 4, mPickupNotifyLabel, 3); + place(1, 5, mPickupChatCheckBox, 1); + place(2, 5, mPickupParticleCheckBox, 2); place(0, 6, mAlphaSlider); place(0, 7, mFpsSlider); @@ -355,6 +368,8 @@ void Setup_Video::apply() mOpacity = config.getValue("guialpha", 0.8); mOverlayDetail = (int) config.getValue("OverlayDetail", 2); mOpenGLEnabled = config.getValue("opengl", false); + mPickupChatEnabled = config.getValue("showpickupchat", true); + mPickupParticleEnabled = config.getValue("showpickupparticle", false); } int Setup_Video::updateSlider(gcn::Slider *slider, gcn::TextField *field, @@ -401,6 +416,9 @@ void Setup_Video::cancel() config.setValue("showownname", mNameEnabled ? true : false); config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); + config.setValue("showpickupchat", mPickupChatEnabled ? true : false); + config.setValue("showpickupparticle", mPickupParticleEnabled ? + true : false); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -434,6 +452,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) new OkDialog(_("Particle effect settings changed"), _("Restart your client or change maps for the change to take effect.")); } + else if (event.getId() == "pickupchat") + { + config.setValue("showpickupchat", mPickupChatCheckBox->isSelected() + ? true : false); + } + else if (event.getId() == "pickupparticle") + { + config.setValue("showpickupparticle", + mPickupParticleCheckBox->isSelected() + ? true : false); + } else if (event.getId() == "speech") { int val = (int) mSpeechSlider->getValue(); diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 525e8941..b491cf23 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -53,6 +53,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mCustomCursorEnabled; bool mParticleEffectsEnabled; bool mNameEnabled; + bool mPickupChatEnabled; + bool mPickupParticleEnabled; double mOpacity; int mFps; int mSpeechMode; @@ -95,6 +97,10 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, int mParticleDetail; gcn::Slider *mParticleDetailSlider; gcn::Label *mParticleDetailField; + + gcn::Label *mPickupNotifyLabel; + gcn::CheckBox *mPickupChatCheckBox; + gcn::CheckBox *mPickupParticleCheckBox; }; #endif diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index 24c60caf..e50fb457 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -78,7 +78,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, int style) { if (fontCounter == 0 && TTF_Init() == -1) { @@ -88,6 +88,7 @@ TrueTypeFont::TrueTypeFont(const std::string& filename, int size) ++fontCounter; mFont = TTF_OpenFont(filename.c_str(), size); + TTF_SetFontStyle (mFont, style); if (!mFont) { diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 35e8270f..085aa226 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -49,7 +49,7 @@ class TrueTypeFont : public gcn::Font * @param filename Font filename. * @param size Font size. */ - TrueTypeFont(const std::string& filename, int size); + TrueTypeFont(const std::string &filename, int size, int style = 0); /** * Destructor. diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 608c25b8..cbc2ec7a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -589,6 +589,18 @@ void LocalPlayer::setXp(int xp) mXp = xp; } +void LocalPlayer::pickedUp(std::string item) +{ + if (mMap) + { + // Show pickup notification + particleEngine->addTextRiseFadeOutEffect(item, + gui->getInfoParticleFont (), + mPx + 16, mPy - 16, + 40, 220, 40, true); + } +} + bool LocalPlayer::withinAttackRange(Being *target) { int dist_x = abs(target->mX - mX); diff --git a/src/localplayer.h b/src/localplayer.h index b368d7c1..0ae99bb0 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -202,6 +202,11 @@ class LocalPlayer : public Player */ void setXp(int xp); + /** + * Shows item pickup effect if the player is on a map. + */ + void pickedUp(std::string item); + /** * Returns the amount of experience points. */ diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 8ea0071d..be128609 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -26,6 +26,7 @@ #include "messagein.h" #include "protocol.h" +#include "../configuration.h" #include "../inventory.h" #include "../item.h" #include "../itemshortcut.h" @@ -142,13 +143,21 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemType = msg->readInt8(); if (msg->readInt8() > 0) { - chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(_("Unable to pick up item"), BY_SERVER); + } } else { const ItemInfo &itemInfo = ItemDB::get(itemId); const std::string amountStr = (amount > 1) ? toString(amount) : "a"; - chatWindow->chatLog(strprintf(_("You picked up %s %s"), - amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); + if (config.getValue("showpickupchat", true)) { + chatWindow->chatLog(strprintf(_("You picked up %s %s"), + amountStr.c_str(), itemInfo.getName().c_str()), + BY_SERVER); + } + if (config.getValue("showpickupparticle", false)) { + player_node->pickedUp(itemInfo.getName()); + } if (Item *item = inventory->getItem(index)) { item->setId(itemId); diff --git a/src/particle.cpp b/src/particle.cpp index 9510573f..8bc764ba 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -327,10 +327,10 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, Particle *Particle::addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y) + gcn::Font *font, int x, int y, bool outline) { Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font); + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -347,9 +347,12 @@ Particle *Particle::addTextSplashEffect(const std::string &text, Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y) + int x, int y, + int colorR, int colorG, + int colorB, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, 255, 255, 255, font); + Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, + font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index 9c01bcdf..f03f081d 100644 --- a/src/particle.h +++ b/src/particle.h @@ -108,15 +108,17 @@ class Particle : public Sprite */ Particle *addTextSplashEffect(const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y); + gcn::Font *font, int x, int y, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, gcn::Font *font, - int x, int y); - + int x, int y, int colorR = 255, + int colorG = 255, int colorB = 255, + bool outline = false); /** * Adds an emitter to the particle. */ diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 3283f9fd..8a8948f4 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -24,16 +24,18 @@ #include "graphics.h" #include "textparticle.h" +#include TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font): + gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), mColorR(colorR), mColorG(colorG), - mColorB(colorB) + mColorB(colorB), + mOutline(outline) { } @@ -60,6 +62,23 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const } graphics->setFont(mTextFont); + if (mOutline) + { + graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); + // Text outline + graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); + graphics->drawText(mText, screenX + 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX - 1, screenY, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY + 1, + gcn::Graphics::CENTER); + + graphics->drawText(mText, screenX, screenY - 1, + gcn::Graphics::CENTER); + } graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); } diff --git a/src/textparticle.h b/src/textparticle.h index d847eb00..26b92a50 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -34,7 +34,7 @@ class TextParticle : public Particle */ TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, - gcn::Font *font); + gcn::Font *font, bool outline = false); /** * Draws the particle image. @@ -49,6 +49,8 @@ class TextParticle : public Particle std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text readable - draw it the way + a Text is usually drawn: with outline */ }; #endif -- cgit v1.2.3-70-g09d2 From 6635294efc3d94dd468c7a4a723e7169402c018c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 20 Feb 2009 08:57:42 -0700 Subject: Removed the last of the image particle guichan fonts. Signed-off-by: Ira Rice --- data/graphics/gui/CMakeLists.txt | 3 --- data/graphics/gui/Makefile.am | 3 --- data/graphics/gui/hits_blue.png | Bin 884 -> 0 bytes data/graphics/gui/hits_red.png | Bin 813 -> 0 bytes data/graphics/gui/hits_yellow.png | Bin 907 -> 0 bytes src/being.cpp | 46 ++++++++++++++++++++++++++++++-------- src/gui/gui.cpp | 24 ++------------------ src/gui/gui.h | 11 ++------- src/localplayer.cpp | 6 +++-- 9 files changed, 45 insertions(+), 48 deletions(-) delete mode 100644 data/graphics/gui/hits_blue.png delete mode 100644 data/graphics/gui/hits_red.png delete mode 100644 data/graphics/gui/hits_yellow.png (limited to 'src/gui') diff --git a/data/graphics/gui/CMakeLists.txt b/data/graphics/gui/CMakeLists.txt index c5961f7a..a562b8f1 100644 --- a/data/graphics/gui/CMakeLists.txt +++ b/data/graphics/gui/CMakeLists.txt @@ -9,9 +9,6 @@ SET (FILES deepbox.png default.png gui.xml - hits_blue.png - hits_red.png - hits_yellow.png hscroll_left_default.png hscroll_left_highlight.png hscroll_left_pressed.png diff --git a/data/graphics/gui/Makefile.am b/data/graphics/gui/Makefile.am index 921469a1..f2b62698 100644 --- a/data/graphics/gui/Makefile.am +++ b/data/graphics/gui/Makefile.am @@ -12,9 +12,6 @@ gui_DATA = \ deepbox.png \ default.png \ gui.xml \ - hits_blue.png \ - hits_red.png \ - hits_yellow.png \ hscroll_left_default.png \ hscroll_left_highlight.png \ hscroll_left_pressed.png \ diff --git a/data/graphics/gui/hits_blue.png b/data/graphics/gui/hits_blue.png deleted file mode 100644 index cfb04ab8..00000000 Binary files a/data/graphics/gui/hits_blue.png and /dev/null differ diff --git a/data/graphics/gui/hits_red.png b/data/graphics/gui/hits_red.png deleted file mode 100644 index 150f1c1e..00000000 Binary files a/data/graphics/gui/hits_red.png and /dev/null differ diff --git a/data/graphics/gui/hits_yellow.png b/data/graphics/gui/hits_yellow.png deleted file mode 100644 index 6975dfd5..00000000 Binary files a/data/graphics/gui/hits_yellow.png and /dev/null differ diff --git a/src/being.cpp b/src/being.cpp index 3f34948e..cebf6d1c 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -226,20 +226,36 @@ void Being::takeDamage(int amount) gcn::Font *font; std::string damage = amount ? toString(amount) : "miss"; + int red, green, blue; + + font = gui->getInfoParticleFont(); + // Selecting the right color if (damage == "miss") - font = hitYellowFont; + { + red = 255; + green = 255; + blue = 0; + } else { if (getType() == MONSTER) - font = hitBlueFont; + { + red = 0; + green = 100; + blue = 255; + } else - font = hitRedFont; + { + red = 255; + green = 50; + blue = 50; + } } // Show damage number - particleEngine->addTextSplashEffect(damage, 255, 255, 255, font, - mPx + 16, mPy + 16); + particleEngine->addTextSplashEffect(damage, red, green, blue, font, + mPx + 16, mPy + 16, true); } void Being::showCrit() @@ -247,15 +263,27 @@ void Being::showCrit() gcn::Font *font; std::string text = "crit!"; + int red, green, blue; + + font = gui->getInfoParticleFont(); + // Selecting the right color if (getType() == MONSTER) - font = hitBlueFont; + { + red = 0; + green = 100; + blue = 255; + } else - font = hitRedFont; + { + red = 255; + green = 50; + blue = 50; + } // Show crit notice - particleEngine->addTextSplashEffect(text, 255, 255, 255, font, - mPx + 16, mPy + 16); + particleEngine->addTextSplashEffect(text, red, green, blue, font, + mPx + 16, mPy + 16, true); } void Being::handleAttack(Being *victim, int damage) diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index ed85fa8f..85a33218 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -113,7 +113,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); - mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); + mInfoParticleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { @@ -136,22 +136,6 @@ Gui::Gui(Graphics *graphics): gcn::Widget::setGlobalFont(mGuiFont); - // Load hits' colorful fonts - try - { - hitRedFont = new gcn::ImageFont("graphics/gui/hits_red.png", - "0123456789crit! "); - hitBlueFont = new gcn::ImageFont("graphics/gui/hits_blue.png", - "0123456789crit! "); - hitYellowFont = new gcn::ImageFont("graphics/gui/hits_yellow.png", - "0123456789misxp "); - } - catch (gcn::Exception e) - { - logger->error(std::string("Unable to load colored hits' fonts: ") - + e.getMessage()); - } - // Initialize mouse cursor and listen for changes to the option setUseCustomCursor(config.getValue("customcursor", 1) == 1); mConfigListener = new GuiConfigListener(this); @@ -169,16 +153,12 @@ Gui::~Gui() config.removeListener("customcursor", mConfigListener); delete mConfigListener; - // Fonts used in showing hits - delete hitRedFont; - delete hitBlueFont; - delete hitYellowFont; - if (mMouseCursors) mMouseCursors->decRef(); delete mGuiFont; delete boldFont; + delete mInfoParticleFont; delete viewport; delete getTop(); diff --git a/src/gui/gui.h b/src/gui/gui.h index e19a0a87..295bc595 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -82,7 +82,7 @@ class Gui : public gcn::Gui * you picked up, etc. */ gcn::Font* getInfoParticleFont() const - { return mInfoParicleFont; } + { return mInfoParticleFont; } /** * Sets whether a custom cursor should be rendered. @@ -115,7 +115,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ + gcn::Font *mInfoParticleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; @@ -126,13 +126,6 @@ class Gui : public gcn::Gui extern Gui *gui; /**< The GUI system */ extern SDLInput *guiInput; /**< GUI input */ -/** - * Fonts used in showing hits - */ -extern gcn::Font *hitRedFont; -extern gcn::Font *hitBlueFont; -extern gcn::Font *hitYellowFont; - /** * Bolded text font */ diff --git a/src/localplayer.cpp b/src/localplayer.cpp index cbc2ec7a..9bf5d990 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -583,8 +583,10 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, hitYellowFont, - mPx + 16, mPy - 16); + particleEngine->addTextRiseFadeOutEffect(text, + gui->getInfoParticleFont(), + mPx + 16, mPy - 16, + 255, 255, 0, true); } mXp = xp; } -- cgit v1.2.3-70-g09d2 From 8c1e0d01cdd4ec664aa7a6d11a129263a353a61b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 20 Feb 2009 19:56:56 -0700 Subject: Fixed some lines from cutting off in English (which would carry over to other languages as well). Signed-off-by: Ira Rice --- src/gui/setup_video.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 35c58ecd..7e3d483c 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -288,7 +288,7 @@ Setup_Video::Setup_Video(): place(0, 11, mOverlayDetailSlider); place(0, 12, mParticleDetailSlider); - place(1, 6, alphaLabel, 2); + place(1, 6, alphaLabel, 3); place(1, 7, mFpsCheckBox).setPadding(3); place(1, 8, scrollRadiusLabel); place(1, 9, scrollLazinessLabel); @@ -299,9 +299,9 @@ Setup_Video::Setup_Video(): place(2, 7, mFpsField).setPadding(1); place(2, 8, mScrollRadiusField).setPadding(1); place(2, 9, mScrollLazinessField).setPadding(1); - place(2, 10, mSpeechLabel, 2).setPadding(2); - place(2, 11, mOverlayDetailField, 2).setPadding(2); - place(2, 12, mParticleDetailField, 2).setPadding(2); + place(2, 10, mSpeechLabel, 3).setPadding(2); + place(2, 11, mOverlayDetailField, 3).setPadding(2); + place(2, 12, mParticleDetailField, 3).setPadding(2); setDimension(gcn::Rectangle(0, 0, 325, 280)); } -- cgit v1.2.3-70-g09d2 From df37ad4697e674d16859e69c0ce358283f410e20 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 20 Feb 2009 22:49:45 -0700 Subject: Fix debug window to show correct mouse coordinates --- src/gui/debugwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 2ed891db..42f2f110 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -67,8 +67,8 @@ void DebugWindow::logic() // Get the current mouse position int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = mouseX / 32 + viewport->getCameraX(); - int mouseTileY = mouseY / 32 + viewport->getCameraY(); + int mouseTileX = (mouseX + viewport->getCameraX()) / 32; + int mouseTileY = (mouseY + viewport->getCameraY()) / 32; mFPSLabel->setCaption(toString(fps) + " FPS"); mFPSLabel->adjustSize(); -- cgit v1.2.3-70-g09d2 From 1bb480c85d255dc53654dd7b86495583f7875217 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 20 Feb 2009 22:49:45 -0700 Subject: Fix debug window to show correct mouse coordinates --- src/gui/debugwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index c41e0a5e..68b70817 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -68,8 +68,8 @@ void DebugWindow::logic() // Get the current mouse position int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = mouseX / 32 + viewport->getCameraX(); - int mouseTileY = mouseY / 32 + viewport->getCameraY(); + int mouseTileX = (mouseX + viewport->getCameraX()) / 32; + int mouseTileY = (mouseY + viewport->getCameraY()) / 32; mFPSLabel->setCaption(toString(fps) + " FPS"); mFPSLabel->adjustSize(); -- cgit v1.2.3-70-g09d2 From 68340bb2222890407b03e2dd7868c0e13a13a156 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 21 Feb 2009 11:00:36 -0700 Subject: Fix bug when maximum level is reached Also centralize code for updating the various progress bars for player status. --- src/gui/ministatus.cpp | 36 +++---------------- src/gui/status.cpp | 98 ++++++++++++++++++++++++++++++++++---------------- src/gui/status.h | 5 +++ 3 files changed, 77 insertions(+), 62 deletions(-) (limited to 'src/gui') diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 25f17bd3..9a3d27cc 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -22,6 +22,7 @@ #include "gui.h" #include "ministatus.h" #include "progressbar.h" +#include "status.h" #include "../animatedsprite.h" #include "../configuration.h" @@ -76,36 +77,9 @@ extern volatile int tick_time; void MiniStatusWindow::update() { - // HP Bar coloration - if (player_node->mHp < int(player_node->mMaxHp / 3)) - { - mHpBar->setColor(223, 32, 32); // Red - } - else if (player_node->mHp < int((player_node->mMaxHp / 3) * 2)) - { - mHpBar->setColor(230, 171, 34); // Orange - } - else - { - mHpBar->setColor(0, 171, 34); // Green - } - - float xp = (float) player_node->getXp() / player_node->mXpForNextLevel; - - if (xp != xp) xp = 0.0f; // check for NaN - if (xp < 0.0f) xp = 0.0f; // make sure the experience isn't negative (uninitialized pointer most likely) - if (xp > 1.0f) xp = 1.0f; - - mHpBar->setProgress((float) player_node->mHp / player_node->mMaxHp); - mMpBar->setProgress((float) player_node->mMp / player_node->mMaxMp); - mXpBar->setProgress(xp); - - // Update labels - mHpBar->setText(toString(player_node->mHp)); - mMpBar->setText(toString(player_node->mMp)); - - std::stringstream updatedText; - updatedText << (float) ((int) (xp * 10000.0f)) / 100.0f << "%"; + StatusWindow::updateHPBar(mHpBar); + StatusWindow::updateMPBar(mMpBar); + StatusWindow::updateXPBar(mXpBar); // Displays the number of monsters to next lvl // (disabled for now but interesting idea) @@ -120,8 +94,6 @@ void MiniStatusWindow::update() } */ - mXpBar->setText(updatedText.str()); - for (unsigned int i = 0; i < mIcons.size(); i++) if (mIcons[i]) mIcons[i]->update(tick_time * 10); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index b1a973fe..0f695b68 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -181,39 +181,13 @@ void StatusWindow::update() mGpLabel->adjustSize(); } - mHpBar->setText(toString(mPlayer->mHp) + - "/" + toString(mPlayer->mMaxHp)); + updateHPBar(mHpBar, true); - mMpBar->setText(toString(mPlayer->mMp) + - "/" + toString(mPlayer->mMaxMp)); + updateMPBar(mMpBar, true); - mXpBar->setText(toString(mPlayer->getXp()) + - "/" + toString(mPlayer->mXpForNextLevel)); + updateXPBar(mXpBar); - mJobBar->setText(toString(mPlayer->mJobXp) + - "/" + toString(mPlayer->mJobXpForNextLevel)); - - // HP Bar coloration - if (mPlayer->mHp < int(mPlayer->mMaxHp / 3)) - { - mHpBar->setColor(223, 32, 32); // Red - } - else if (mPlayer->mHp < int((mPlayer->mMaxHp / 3) * 2)) - { - mHpBar->setColor(230, 171, 34); // Orange - } - else - { - mHpBar->setColor(0, 171, 34); // Green - } - - mHpBar->setProgress((float) mPlayer->mHp / (float) mPlayer->mMaxHp); - mMpBar->setProgress((float) mPlayer->mMp / (float) mPlayer->mMaxMp); - - mXpBar->setProgress( - (float) mPlayer->getXp() / (float) mPlayer->mXpForNextLevel); - mJobBar->setProgress( - (float) mPlayer->mJobXp / (float) mPlayer->mJobXpForNextLevel); + updateJobBar(mJobBar); // Stats Part // ---------- @@ -318,3 +292,67 @@ void StatusWindow::action(const gcn::ActionEvent &event) } } +void StatusWindow::updateHPBar(ProgressBar *bar, bool showMax) +{ + if (showMax) + bar->setText(toString(player_node->mHp) + + "/" + toString(player_node->mMaxHp)); + else + bar->setText(toString(player_node->mHp)); + + // HP Bar coloration + if (player_node->mHp < player_node->mMaxHp / 3) + { + bar->setColor(223, 32, 32); // Red + } + else if (player_node->mHp < (player_node->mMaxHp / 3) * 2) + { + bar->setColor(230, 171, 34); // Orange + } + else + { + bar->setColor(0, 171, 34); // Green + } + + bar->setProgress((float) player_node->mHp / (float) player_node->mMaxHp); +} + +void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) +{ + if (showMax) + bar->setText(toString(player_node->mMp) + + "/" + toString(player_node->mMaxMp)); + else + bar->setText(toString(player_node->mMp)); + + + bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp); +} + +void StatusWindow::updateXPBar(ProgressBar *bar) +{ + if (player_node->mXpForNextLevel == 0) { + bar->setText(_("Max level")); + bar->setProgress(1.0); + } else { + bar->setText(toString(player_node->getXp()) + + "/" + toString(player_node->mXpForNextLevel)); + + bar->setProgress((float) player_node->getXp() / + (float) player_node->mXpForNextLevel); + } +} + +void StatusWindow::updateJobBar(ProgressBar *bar) +{ + if (player_node->mXpForNextLevel == 0) { + bar->setText(_("Max level")); + bar->setProgress(1.0); + } else { + bar->setText(toString(player_node->mJobXp) + + "/" + toString(player_node->mJobXpForNextLevel)); + + bar->setProgress((float) player_node->mJobXp / + (float) player_node->mJobXpForNextLevel); + } +} diff --git a/src/gui/status.h b/src/gui/status.h index 136c6c3f..99facb28 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -57,6 +57,11 @@ class StatusWindow : public Window, public gcn::ActionListener */ void update(); + static void updateHPBar(ProgressBar *bar, bool showMax = false); + static void updateMPBar(ProgressBar *bar, bool showMax = false); + static void updateXPBar(ProgressBar *bar); + static void updateJobBar(ProgressBar *bar); + private: LocalPlayer *mPlayer; -- cgit v1.2.3-70-g09d2 From 6250168c410843cce560197b1ae440d1c2a0ba32 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 22 Feb 2009 17:56:32 +0100 Subject: Renamed InfoParicleFont to InfoParticleFont (typo?) --- src/gui/gui.cpp | 2 +- src/gui/gui.h | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 431e4d2d..26192e26 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -112,7 +112,7 @@ Gui::Gui(Graphics *graphics): { const int fontSize = (int)config.getValue("fontSize", 11); mGuiFont = new TrueTypeFont(path, fontSize); - mInfoParicleFont = new TrueTypeFont(path, fontSize, 1); + mInfoParticleFont = new TrueTypeFont(path, fontSize, 1); } catch (gcn::Exception e) { diff --git a/src/gui/gui.h b/src/gui/gui.h index d5680412..7483cb82 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -81,7 +81,7 @@ class Gui : public gcn::Gui * you picked up, etc. */ gcn::Font* getInfoParticleFont() const - { return mInfoParicleFont; } + { return mInfoParticleFont; } /** * Sets whether a custom cursor should be rendered. @@ -114,7 +114,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - gcn::Font *mInfoParicleFont; /**< Font for Info Paricles*/ + gcn::Font *mInfoParticleFont; /**< Font for Info Paricles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; -- cgit v1.2.3-70-g09d2 From ffaee35f99686709300b8d1977ade714d5a4e8af Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 22 Feb 2009 18:00:14 +0100 Subject: Fixed another Particle/Paricle mismatch in a comment --- src/gui/gui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/gui.h b/src/gui/gui.h index 7483cb82..41df3dda 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -114,7 +114,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - gcn::Font *mInfoParticleFont; /**< Font for Info Paricles*/ + gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; -- cgit v1.2.3-70-g09d2 From 57007e5ecadef9439998b229cb4b1427239f68eb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 22 Feb 2009 10:00:20 -0700 Subject: Allow percentage for exp displays --- src/gui/status.cpp | 30 +++++++++++++++++++++++------- src/gui/status.h | 4 ++-- 2 files changed, 25 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 0f695b68..f5ec5c13 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -185,9 +185,9 @@ void StatusWindow::update() updateMPBar(mMpBar, true); - updateXPBar(mXpBar); + updateXPBar(mXpBar, false); - updateJobBar(mJobBar); + updateJobBar(mJobBar, false); // Stats Part // ---------- @@ -329,13 +329,21 @@ void StatusWindow::updateMPBar(ProgressBar *bar, bool showMax) bar->setProgress((float) player_node->mMp / (float) player_node->mMaxMp); } -void StatusWindow::updateXPBar(ProgressBar *bar) +void StatusWindow::updateXPBar(ProgressBar *bar, bool percent) { if (player_node->mXpForNextLevel == 0) { bar->setText(_("Max level")); bar->setProgress(1.0); } else { - bar->setText(toString(player_node->getXp()) + + if (percent) + { + float xp = (float) player_node->getXp() / + player_node->mXpForNextLevel; + bar->setText(toString((float) ((int) (xp * 10000.0f)) / 100.0f) + + "%"); + } + else + bar->setText(toString(player_node->getXp()) + "/" + toString(player_node->mXpForNextLevel)); bar->setProgress((float) player_node->getXp() / @@ -343,14 +351,22 @@ void StatusWindow::updateXPBar(ProgressBar *bar) } } -void StatusWindow::updateJobBar(ProgressBar *bar) +void StatusWindow::updateJobBar(ProgressBar *bar, bool percent) { if (player_node->mXpForNextLevel == 0) { bar->setText(_("Max level")); bar->setProgress(1.0); } else { - bar->setText(toString(player_node->mJobXp) + - "/" + toString(player_node->mJobXpForNextLevel)); + if (percent) + { + float xp = (float) player_node->mJobXp / + player_node->mJobXpForNextLevel; + bar->setText(toString((float) ((int) (xp * 10000.0f)) / 100.0f) + + "%"); + } + else + bar->setText(toString(player_node->mJobXp) + + "/" + toString(player_node->mJobXpForNextLevel)); bar->setProgress((float) player_node->mJobXp / (float) player_node->mJobXpForNextLevel); diff --git a/src/gui/status.h b/src/gui/status.h index 99facb28..f3f54f4e 100644 --- a/src/gui/status.h +++ b/src/gui/status.h @@ -59,8 +59,8 @@ class StatusWindow : public Window, public gcn::ActionListener static void updateHPBar(ProgressBar *bar, bool showMax = false); static void updateMPBar(ProgressBar *bar, bool showMax = false); - static void updateXPBar(ProgressBar *bar); - static void updateJobBar(ProgressBar *bar); + static void updateXPBar(ProgressBar *bar, bool percent = true); + static void updateJobBar(ProgressBar *bar, bool percent = true); private: LocalPlayer *mPlayer; -- cgit v1.2.3-70-g09d2 From 0a2fb7484cf06f5645e176e543b423601bff7f3f Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 22 Feb 2009 10:00:40 -0700 Subject: Make progressbars more readable --- src/gui/progressbar.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 0f59371a..019bf371 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -134,13 +134,13 @@ void ProgressBar::draw(gcn::Graphics *graphics) graphics->setFont(f); - graphics->setColor(gcn::Color(0, 0, 0, alpha)); + graphics->setColor(gcn::Color(0, 0, 0)); graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(255, 255, 255, alpha)); + graphics->setColor(gcn::Color(255, 255, 255)); graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); graphics->setColor(gcn::Color(0, 0, 0)); -- cgit v1.2.3-70-g09d2 From d27772e75e53731a39df96e5256b089a9aa3075d Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 22 Feb 2009 18:00:14 +0100 Subject: Fixed another Particle/Paricle mismatch in a comment --- src/gui/gui.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/gui.h b/src/gui/gui.h index 295bc595..afa358be 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -115,7 +115,7 @@ class Gui : public gcn::Gui private: GuiConfigListener *mConfigListener; gcn::Font *mGuiFont; /**< The global GUI font */ - gcn::Font *mInfoParticleFont; /**< Font for Info Paricles*/ + gcn::Font *mInfoParticleFont; /**< Font for Info Particles*/ bool mCustomCursor; /**< Show custom cursor */ ImageSet *mMouseCursors; /**< Mouse cursor images */ float mMouseCursorAlpha; -- cgit v1.2.3-70-g09d2 From ebe59b84ab4c378bc0c203d7f22e1196058a15d2 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 22 Feb 2009 19:00:56 -0700 Subject: Highlight unbuyable items in red --- src/gui/shoplistbox.cpp | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 8aed3c77..b258c2d8 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -80,15 +80,14 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { gcn::Color backgroundColor = gcn::Color(255, 255, 255, alpha); - if (i == mSelected) - { - backgroundColor = gcn::Color(red, green, blue, alpha); - } - else if (mShopItems && + if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) - { - backgroundColor = gcn::Color(145, 145, 145, alpha); - } + if (i == mSelected) + backgroundColor = gcn::Color(145, 0, 0, alpha); + else + backgroundColor = gcn::Color(145, 145, 145, alpha); + else if (i == mSelected) + backgroundColor = gcn::Color(red, green, blue, alpha); graphics->setColor(backgroundColor); graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); -- cgit v1.2.3-70-g09d2 From 208e4cfad44dd5bf1d0409d1c2227a1a5eae3a2e Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 23 Feb 2009 06:47:44 -0700 Subject: Clear text from NpcTextDialog when character dies Also hid the integer and string dialogs --- src/gui/npc_text.cpp | 5 +++++ src/net/playerhandler.cpp | 9 ++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index e6f039a0..be67fb6e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -73,6 +73,11 @@ void NpcTextDialog::addText(const std::string &text) mScrollArea->setVerticalScrollAmount(mScrollArea->getVerticalMaxScroll()); } +void NpcTextDialog::clearText() +{ + setText(""); +} + void NpcTextDialog::showNextButton() { mButton->setCaption(_("Next")); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index fc3506fb..ee1b2fd9 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -32,8 +32,10 @@ #include "../gui/buy.h" #include "../gui/chat.h" #include "../gui/gui.h" -#include "../gui/npclistdialog.h" #include "../gui/npc_text.h" +#include "../gui/npcintegerdialog.h" +#include "../gui/npclistdialog.h" +#include "../gui/npcstringdialog.h" #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" @@ -46,7 +48,9 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; +extern NpcIntegerDialog *npcIntegerDialog; extern NpcListDialog *npcListDialog; +extern NpcStringDialog *npcStringDialog; extern NpcTextDialog *npcTextDialog; extern BuyDialog *buyDialog; extern SellDialog *sellDialog; @@ -81,7 +85,10 @@ namespace { { player_node->revive(); deathNotice = NULL; + npcIntegerDialog->setVisible(false); npcListDialog->setVisible(false); + npcStringDialog->setVisible(false); + npcTextDialog->clearText(); npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); -- cgit v1.2.3-70-g09d2 From b9a643f1e7a1ec5e3ec8eaee8bc285f7d10a0e74 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 23 Feb 2009 11:16:08 -0700 Subject: Fix Job EXP bar code --- src/gui/status.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/status.cpp b/src/gui/status.cpp index f5ec5c13..0528a439 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -353,7 +353,7 @@ void StatusWindow::updateXPBar(ProgressBar *bar, bool percent) void StatusWindow::updateJobBar(ProgressBar *bar, bool percent) { - if (player_node->mXpForNextLevel == 0) { + if (player_node->mJobXpForNextLevel == 0) { bar->setText(_("Max level")); bar->setProgress(1.0); } else { -- cgit v1.2.3-70-g09d2 From e01a1776f20a499003ae976e4b145a9c85f6a014 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 23 Feb 2009 12:48:14 -0700 Subject: End NPC interraction when canceling list inpu --- src/gui/npclistdialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 78d43fd2..c476999a 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -108,6 +108,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { choice = 0xff; // 0xff means cancel npcTextDialog->addText(_("\n> Cancel\n")); + npcTextDialog->showCloseButton(); } if (choice) -- cgit v1.2.3-70-g09d2 From c54b987a4e4d28d35e8bafb03e1dba33b5fda4ab Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 23 Feb 2009 13:19:31 -0700 Subject: Hide the buy/sell dialogs when there is no NPC --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 5 +++++ src/gui/buysell.cpp | 7 +++++++ src/gui/buysell.h | 5 +++++ src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 5 +++++ 6 files changed, 36 insertions(+) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index b31d48e1..c084c7c2 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -241,3 +241,10 @@ void BuyDialog::updateButtonsAndLabels() Units::formatCurrency(price).c_str(), Units::formatCurrency(mMoney - price).c_str())); } + +void BuyDialog::logic() +{ + Window::logic(); + + if (!current_npc) setVisible(false); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 0f1cfede..55a1898c 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -95,6 +95,11 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + /** + * Check for current NPC + */ + void logic(); + private: Network *mNetwork; gcn::Button *mBuyButton; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 2d39eac7..8bf5f1f4 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -51,6 +51,13 @@ BuySellDialog::BuySellDialog(): requestFocus(); } +void BuySellDialog::logic() +{ + Window::logic(); + + if (!current_npc) setVisible(false); +} + void BuySellDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "Buy") { diff --git a/src/gui/buysell.h b/src/gui/buysell.h index e3cdc52a..754bb551 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -42,6 +42,11 @@ class BuySellDialog : public Window, public gcn::ActionListener */ BuySellDialog(); + /** + * Check for current NPC + */ + void logic(); + /** * Called when receiving actions from the widgets. */ diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index dad6af21..20a2a786 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -254,3 +254,10 @@ void SellDialog::updateButtonsAndLabels() Units::formatCurrency(income).c_str(), Units::formatCurrency(mPlayerMoney - income).c_str())); } + +void SellDialog::logic() +{ + Window::logic(); + + if (!current_npc) setVisible(false); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index c11a7b7c..3777b91e 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -81,6 +81,11 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + /** + * Check for current NPC + */ + void logic(); + private: /** * Updates the state of buttons and labels. -- cgit v1.2.3-70-g09d2 From e15b8c360ac5171fe73b8b73fbe00eedba8970ff Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:19:55 +0100 Subject: Allow to sell non-stackable items like stackables Make it possible to sell non-stackable items all at once by introducing "Duplicate Items" and a Shop that can handle them. Also fix a trivial bug to correctly preview you money while selling. --- src/gui/sell.cpp | 35 +++++++++++++++------- src/gui/shop.cpp | 51 +++++++++++++++++++++++++++----- src/gui/shop.h | 59 ++++++++++++++++++++++++++++++++----- src/shopitem.cpp | 58 ++++++++++++++++++++++++++++++++++-- src/shopitem.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 260 insertions(+), 33 deletions(-) (limited to 'src/gui') diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 20a2a786..14620aa6 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -50,7 +50,8 @@ SellDialog::SellDialog(Network *network): setMinHeight(230); setDefaultSize(0, 0, 260, 230); - mShopItems = new ShopItems; + // Create a ShopItems instance, that is aware of duplicate entries. + mShopItems = new ShopItems(true); mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); @@ -115,10 +116,11 @@ void SellDialog::reset() void SellDialog::addItem(const Item *item, int price) { if (!item) + { return; + } - mShopItems->addItem( - item->getInvIndex(), item->getId(), + mShopItems->addItem(item->getInvIndex(), item->getId(), item->getQuantity(), price); mShopItemList->adjustSize(); @@ -164,23 +166,34 @@ void SellDialog::action(const gcn::ActionEvent &event) { // Attempt sell MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); - outMsg.writeInt16(8); - outMsg.writeInt16(mShopItems->at(selectedItem)->getInvIndex()); - outMsg.writeInt16(mAmountItems); + ShopItem* item = mShopItems->at(selectedItem); + int sellCount; + mPlayerMoney += + mAmountItems * mShopItems->at(selectedItem)->getPrice(); mMaxItems -= mAmountItems; - mShopItems->getShop()->at(selectedItem)->setQuantity(mMaxItems); + while (mAmountItems > 0) { + outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); + outMsg.writeInt16(8); + outMsg.writeInt16(item->getCurrentInvIndex()); + // This order is important, item->getCurrentInvIndex() would return + // the inventory index of the next Duplicate otherwise. + sellCount = item->sellCurrentDuplicate(mAmountItems); + mAmountItems -= sellCount; + outMsg.writeInt16(sellCount); + } + mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); mAmountItems = 1; + mSlider->setValue(0); if (!mMaxItems) { // All were sold mShopItemList->setSelected(-1); - mShopItems->getShop()->erase( - mShopItems->getShop()->begin() + selectedItem); + delete mShopItems->at(selectedItem); + mShopItems->erase(selectedItem); gcn::Rectangle scroll; scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1); @@ -252,7 +265,7 @@ void SellDialog::updateButtonsAndLabels() mQuantityLabel->setCaption(strprintf("%d / %d", mAmountItems, mMaxItems)); mMoneyLabel->setCaption(strprintf(_("Price: %s / Total: %s"), Units::formatCurrency(income).c_str(), - Units::formatCurrency(mPlayerMoney - income).c_str())); + Units::formatCurrency(mPlayerMoney + income).c_str())); } void SellDialog::logic() diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index a5f59bac..e13e218c 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -23,6 +23,11 @@ #include "../utils/dtor.h" +ShopItems::ShopItems(bool mergeDuplicates) : + mMergeDuplicates(mergeDuplicates) +{ +} + ShopItems::~ShopItems() { clear(); @@ -38,16 +43,29 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(int inventoryIndex, short id, int amount, int price) +void ShopItems::addItem(int inventoryIndex, int id, int quantity, + int price) { - ShopItem *item = new ShopItem(id, amount, price); - item->setInvIndex(inventoryIndex); - mShopItems.push_back(item); + ShopItem* item = 0; + if (mMergeDuplicates) + { + item = findItem(id); + } + + if (item) + { + item->addDuplicate (inventoryIndex, quantity); + } + else + { + item = new ShopItem(inventoryIndex, id, quantity, price); + mShopItems.push_back(item); + } } -void ShopItems::addItem(short id, int price) +void ShopItems::addItem(int id, int price) { - mShopItems.push_back(new ShopItem(id, 0, price)); + addItem(-1, id, 0, price); } ShopItem* ShopItems::at(int i) const @@ -55,13 +73,30 @@ ShopItem* ShopItems::at(int i) const return mShopItems.at(i); } +void ShopItems::erase(int i) +{ + mShopItems.erase(mShopItems.begin() + i); +} + void ShopItems::clear() { delete_all(mShopItems); mShopItems.clear(); } -std::vector* ShopItems::getShop() +ShopItem* ShopItems::findItem(int id) { - return &mShopItems; + ShopItem *item; + + std::vector::iterator it; + for(it = mShopItems.begin(); it != mShopItems.end(); it++) + { + item = *(it); + if (item->getId() == id) + { + return item; + } + } + + return 0; } diff --git a/src/gui/shop.h b/src/gui/shop.h index e0db4c59..faffe7e3 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -31,31 +31,62 @@ class ShopItem; +/** + * This class handles the list of items available in a shop. + * + * The addItem routine can automatically check, if an item already exists and + * only adds duplicates to the old item, if one is found. The original + * distribution of the duplicates can be retrieved from the item. + * + * This functionality can be enabled in the constructor. + */ class ShopItems : public gcn::ListModel { public: + /** + * Constructor. Creates a new ShopItems instance. + * + * @param mergeDuplicates lets the Shop look for duplicate entries and + * merges them to one item. + */ + ShopItems(bool mergeDuplicates = false); + /** * Destructor. */ ~ShopItems(); /** - * Adds an item to the list (used by sell dialog). + * Adds an item to the list (used by sell dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item */ - void addItem(int inventoryIndex, short id, int amount, int price); + void addItem(int inventoryIndex, int id, int amount, int price); /** - * Adds an item to the list (used by buy dialog). + * Adds an item to the list (used by buy dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param id the id of the item + * @param price price of the item */ - void addItem(short id, int price); + void addItem(int id, int price); /** * Returns the number of items in the shop. + * + * @return the number of items in the shop */ int getNumberOfElements(); /** * Returns the name of item number i in the shop. + * + * @param i the index to retrieve */ std::string getElementAt(int i); @@ -64,18 +95,32 @@ class ShopItems : public gcn::ListModel */ ShopItem* at(int i) const; + /** + * Removes an element from the shop. + * + * @param i index to remove + */ + void erase(int i); + /** * Clear the vector. */ void clear(); + private: /** - * Direct access to the vector. + * Searches the current items in the shop for the specified + * id and returns the item if found, or 0 else. + * + * @return the item found or 0 */ - std::vector* getShop(); + ShopItem* findItem(int id); - private: + /** the shop storage */ std::vector mShopItems; + + /** Look for duplicate entries on addition */ + bool mMergeDuplicates; }; #endif diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 6547aaf1..d6bb1d49 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -23,10 +23,62 @@ #include "units.h" -ShopItem::ShopItem(int id, int quantity, int price): - Item(id, quantity), - mPrice(price) +ShopItem::ShopItem (int inventoryIndex, int id, + int quantity, int price) : + Item (id, 0), mPrice(price) { mDisplayName = getInfo().getName() + " (" + Units::formatCurrency(mPrice).c_str() + ")"; + setInvIndex(inventoryIndex); + addDuplicate(inventoryIndex, quantity); +} + +ShopItem::ShopItem (int id, int price) : Item (id, 0), mPrice(price) +{ + mDisplayName = getInfo().getName() + + " (" + Units::formatCurrency(mPrice).c_str() + ")"; + setInvIndex(-1); + addDuplicate(-1, 0); +} + +ShopItem::~ShopItem() +{ + /** Clear all remaining duplicates on Object destruction. */ + while (!mDuplicates.empty()) + { + delete mDuplicates.top(); + mDuplicates.pop(); + } +} + +void ShopItem::addDuplicate(int inventoryIndex, + int quantity) +{ + DuplicateItem* di = new DuplicateItem; + di->inventoryIndex = inventoryIndex; + di->quantity = quantity; + mDuplicates.push(di); + mQuantity += quantity; +} + + +void ShopItem::addDuplicate() +{ + DuplicateItem* di = new DuplicateItem; + di->inventoryIndex = -1; + di->quantity = 0; + mDuplicates.push(di); +} + +int ShopItem::sellCurrentDuplicate(int quantity) +{ + DuplicateItem* dupl = mDuplicates.top(); + int sellCount = quantity <= dupl->quantity ? quantity : dupl->quantity; + dupl->quantity -= sellCount; + mQuantity -= sellCount; + if (dupl->quantity == 0) { + delete dupl; + mDuplicates.pop(); + } + return sellCount; } diff --git a/src/shopitem.h b/src/shopitem.h index 3353ebe7..69bed334 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -22,27 +22,100 @@ #ifndef _SHOPITEM_H #define _SHOPITEM_H +#include + #include "item.h" /** - * Represents an item in a shop inventory. + * Represents an item in a shop inventory. It can store quantity and inventory + * indices of duplicate entries in the shop as well. */ class ShopItem : public Item { public: /** - * Constructor. + * Constructor. Creates a new ShopItem. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item + */ + ShopItem(int inventoryIndex, int id, int quantity, int price); + + /** + * Constructor. Creates a new ShopItem. Inventory index will be set to + * -1 and quantity to 0. + * + * @param id the id of the item + * @param price price of the item + */ + ShopItem(int id, int price); + + /** + * Destructor. + */ + ~ShopItem(); + + /** + * Add a duplicate. Id and price will be taken from this item. + * + * @param inventoryIndex the inventory index of the item + * @param quantity number of available copies of the item + */ + void addDuplicate (int inventoryIndex, int quantity); + + /** + * Add a duplicate. Id and price will be taken from this item. + * Needed for compatibility with ShopDuplicateItems (see) class + * documentation). */ - ShopItem(int id, int quantity, int price); + void addDuplicate (); + + /** + * Gets the quantity of the currently topmost duplicate. + * + * @return the quantity of the currently topmost duplicate + */ + int getCurrentQuantity() { + return mDuplicates.empty() ? 0 : mDuplicates.top()->quantity; + } + + /** + * Gets the inventory index of the currently topmost duplicate. + * + * @return the inventory index of the currently topmost duplicate + */ + int getCurrentInvIndex() { + return mDuplicates.empty() ? mInvIndex : + mDuplicates.top()->inventoryIndex; + } + + /** + * Reduces the quantity of the topmost duplicate by the specified + * amount. Also reduces the total quantity of this DuplicateItem. + * Empty duplicates are automatically removed. + * + * If the amount is bigger than the quantity of the current topmost, + * only sell as much as possible. Returns the amount actually sold (do + * not ignore the return value!) + * + * @return the amount, that actually was sold. + */ + int sellCurrentDuplicate(int quantity); /** * Gets the price of the item. + * + * @return the price of the item */ int getPrice() const { return mPrice; } /** - * Gets the display name for in the shop list. + * Gets the display name for the item in the shop list. + * + * @return the display name for the item in the shop list */ const std::string& getDisplayName() const { return mDisplayName; } @@ -51,6 +124,15 @@ class ShopItem : public Item int mPrice; int mIndex; std::string mDisplayName; + + /** + * Struct to keep track of duplicates. + */ + typedef struct { + int inventoryIndex; + int quantity; + } DuplicateItem; + std::stack mDuplicates; /** <-- Stores duplicates */ }; #endif -- cgit v1.2.3-70-g09d2 From f65c1e48107fa2cc615c86d8f6829b50c05baa3f Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:19:55 +0100 Subject: Allow to sell non-stackable items like stackables Make it possible to sell non-stackable items all at once by introducing "Duplicate Items" and a Shop that can handle them. Also fix a trivial bug to correctly preview you money while selling. --- src/gui/sell.cpp | 33 ++++++++++++++------- src/gui/shop.cpp | 51 +++++++++++++++++++++++++++----- src/gui/shop.h | 59 ++++++++++++++++++++++++++++++++----- src/shopitem.cpp | 58 ++++++++++++++++++++++++++++++++++-- src/shopitem.h | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 5 files changed, 259 insertions(+), 32 deletions(-) (limited to 'src/gui') diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index fd271c63..f974f247 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -50,7 +50,8 @@ SellDialog::SellDialog(Network *network): setMinHeight(230); setDefaultSize(0, 0, 260, 230); - mShopItems = new ShopItems(); + // Create a ShopItems instance, that is aware of duplicate entries. + mShopItems = new ShopItems(true); mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); @@ -115,10 +116,11 @@ void SellDialog::reset() void SellDialog::addItem(const Item *item, int price) { if (!item) + { return; + } - mShopItems->addItem( - item->getInvIndex(), item->getId(), + mShopItems->addItem(item->getInvIndex(), item->getId(), item->getQuantity(), price); mShopItemList->adjustSize(); @@ -164,23 +166,34 @@ void SellDialog::action(const gcn::ActionEvent &event) { // Attempt sell MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); - outMsg.writeInt16(8); - outMsg.writeInt16(mShopItems->at(selectedItem)->getInvIndex()); - outMsg.writeInt16(mAmountItems); + ShopItem* item = mShopItems->at(selectedItem); + int sellCount; + mPlayerMoney += + mAmountItems * mShopItems->at(selectedItem)->getPrice(); mMaxItems -= mAmountItems; - mShopItems->getShop()->at(selectedItem)->setQuantity(mMaxItems); + while (mAmountItems > 0) { + outMsg.writeInt16(CMSG_NPC_SELL_REQUEST); + outMsg.writeInt16(8); + outMsg.writeInt16(item->getCurrentInvIndex()); + // This order is important, item->getCurrentInvIndex() would return + // the inventory index of the next Duplicate otherwise. + sellCount = item->sellCurrentDuplicate(mAmountItems); + mAmountItems -= sellCount; + outMsg.writeInt16(sellCount); + } + mPlayerMoney += mAmountItems * mShopItems->at(selectedItem)->getPrice(); mAmountItems = 1; + mSlider->setValue(0); if (!mMaxItems) { // All were sold mShopItemList->setSelected(-1); - mShopItems->getShop()->erase( - mShopItems->getShop()->begin() + selectedItem); + delete mShopItems->at(selectedItem); + mShopItems->erase(selectedItem); gcn::Rectangle scroll; scroll.y = mShopItemList->getRowHeight() * (selectedItem + 1); diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index a56116d3..da68cf28 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -24,6 +24,11 @@ #include "../utils/dtor.h" +ShopItems::ShopItems(bool mergeDuplicates) : + mMergeDuplicates(mergeDuplicates) +{ +} + ShopItems::~ShopItems() { clear(); @@ -39,16 +44,29 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(int inventoryIndex, short id, int amount, int price) +void ShopItems::addItem(int inventoryIndex, int id, int quantity, + int price) { - ShopItem *item = new ShopItem(id, amount, price); - item->setInvIndex(inventoryIndex); - mShopItems.push_back(item); + ShopItem* item = 0; + if (mMergeDuplicates) + { + item = findItem(id); + } + + if (item) + { + item->addDuplicate (inventoryIndex, quantity); + } + else + { + item = new ShopItem(inventoryIndex, id, quantity, price); + mShopItems.push_back(item); + } } -void ShopItems::addItem(short id, int price) +void ShopItems::addItem(int id, int price) { - mShopItems.push_back(new ShopItem(id, 0, price)); + addItem(-1, id, 0, price); } ShopItem* ShopItems::at(int i) const @@ -56,13 +74,30 @@ ShopItem* ShopItems::at(int i) const return mShopItems.at(i); } +void ShopItems::erase(int i) +{ + mShopItems.erase(mShopItems.begin() + i); +} + void ShopItems::clear() { delete_all(mShopItems); mShopItems.clear(); } -std::vector* ShopItems::getShop() +ShopItem* ShopItems::findItem(int id) { - return &mShopItems; + ShopItem *item; + + std::vector::iterator it; + for(it = mShopItems.begin(); it != mShopItems.end(); it++) + { + item = *(it); + if (item->getId() == id) + { + return item; + } + } + + return 0; } diff --git a/src/gui/shop.h b/src/gui/shop.h index 166eb00b..26a9429d 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -32,31 +32,62 @@ class ShopItem; +/** + * This class handles the list of items available in a shop. + * + * The addItem routine can automatically check, if an item already exists and + * only adds duplicates to the old item, if one is found. The original + * distribution of the duplicates can be retrieved from the item. + * + * This functionality can be enabled in the constructor. + */ class ShopItems : public gcn::ListModel { public: + /** + * Constructor. Creates a new ShopItems instance. + * + * @param mergeDuplicates lets the Shop look for duplicate entries and + * merges them to one item. + */ + ShopItems(bool mergeDuplicates = false); + /** * Destructor. */ ~ShopItems(); /** - * Adds an item to the list (used by sell dialog). + * Adds an item to the list (used by sell dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item */ - void addItem(int inventoryIndex, short id, int amount, int price); + void addItem(int inventoryIndex, int id, int amount, int price); /** - * Adds an item to the list (used by buy dialog). + * Adds an item to the list (used by buy dialog). Looks for + * duplicate entries, if mergeDuplicates was turned on. + * + * @param id the id of the item + * @param price price of the item */ - void addItem(short id, int price); + void addItem(int id, int price); /** * Returns the number of items in the shop. + * + * @return the number of items in the shop */ int getNumberOfElements(); /** * Returns the name of item number i in the shop. + * + * @param i the index to retrieve */ std::string getElementAt(int i); @@ -65,18 +96,32 @@ class ShopItems : public gcn::ListModel */ ShopItem* at(int i) const; + /** + * Removes an element from the shop. + * + * @param i index to remove + */ + void erase(int i); + /** * Clear the vector. */ void clear(); + private: /** - * Direct access to the vector. + * Searches the current items in the shop for the specified + * id and returns the item if found, or 0 else. + * + * @return the item found or 0 */ - std::vector* getShop(); + ShopItem* findItem(int id); - private: + /** the shop storage */ std::vector mShopItems; + + /** Look for duplicate entries on addition */ + bool mMergeDuplicates; }; #endif diff --git a/src/shopitem.cpp b/src/shopitem.cpp index c8015e45..5573eb37 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -24,10 +24,62 @@ #include "utils/stringutils.h" -ShopItem::ShopItem(int id, int quantity, int price): - Item(id, quantity), - mPrice(price) +ShopItem::ShopItem (int inventoryIndex, int id, + int quantity, int price) : + Item (id, 0), mPrice(price) { mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; + setInvIndex(inventoryIndex); + addDuplicate(inventoryIndex, quantity); +} + +ShopItem::ShopItem (int id, int price) : Item (id, 0), mPrice(price) +{ + mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; + setInvIndex(-1); + addDuplicate(-1, 0); +} + +ShopItem::~ShopItem() +{ + /** Clear all remaining duplicates on Object destruction. */ + while (!mDuplicates.empty()) + { + delete mDuplicates.top(); + mDuplicates.pop(); + } +} + +void ShopItem::addDuplicate(int inventoryIndex, + int quantity) +{ + DuplicateItem* di = new DuplicateItem; + di->inventoryIndex = inventoryIndex; + di->quantity = quantity; + mDuplicates.push(di); + mQuantity += quantity; +} + + +void ShopItem::addDuplicate() +{ + DuplicateItem* di = new DuplicateItem; + di->inventoryIndex = -1; + di->quantity = 0; + mDuplicates.push(di); +} + +int ShopItem::sellCurrentDuplicate(int quantity) +{ + DuplicateItem* dupl = mDuplicates.top(); + int sellCount = quantity <= dupl->quantity ? quantity : dupl->quantity; + dupl->quantity -= sellCount; + mQuantity -= sellCount; + if (dupl->quantity == 0) + { + delete dupl; + mDuplicates.pop(); + } + return sellCount; } diff --git a/src/shopitem.h b/src/shopitem.h index 8b1ba4b2..d6226732 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -23,27 +23,100 @@ #ifndef _SHOPITEM_H #define _SHOPITEM_H +#include + #include "item.h" /** - * Represents an item in a shop inventory. + * Represents an item in a shop inventory. It can store quantity and inventory + * indices of duplicate entries in the shop as well. */ class ShopItem : public Item { public: /** - * Constructor. + * Constructor. Creates a new ShopItem. + * + * @param inventoryIndex the inventory index of the item + * @param id the id of the item + * @param quantity number of available copies of the item + * @param price price of the item + */ + ShopItem(int inventoryIndex, int id, int quantity, int price); + + /** + * Constructor. Creates a new ShopItem. Inventory index will be set to + * -1 and quantity to 0. + * + * @param id the id of the item + * @param price price of the item + */ + ShopItem(int id, int price); + + /** + * Destructor. + */ + ~ShopItem(); + + /** + * Add a duplicate. Id and price will be taken from this item. + * + * @param inventoryIndex the inventory index of the item + * @param quantity number of available copies of the item + */ + void addDuplicate (int inventoryIndex, int quantity); + + /** + * Add a duplicate. Id and price will be taken from this item. + * Needed for compatibility with ShopDuplicateItems (see) class + * documentation). */ - ShopItem(int id, int quantity, int price); + void addDuplicate (); + + /** + * Gets the quantity of the currently topmost duplicate. + * + * @return the quantity of the currently topmost duplicate + */ + int getCurrentQuantity() { + return mDuplicates.empty() ? 0 : mDuplicates.top()->quantity; + } + + /** + * Gets the inventory index of the currently topmost duplicate. + * + * @return the inventory index of the currently topmost duplicate + */ + int getCurrentInvIndex() { + return mDuplicates.empty() ? mInvIndex : + mDuplicates.top()->inventoryIndex; + } + + /** + * Reduces the quantity of the topmost duplicate by the specified + * amount. Also reduces the total quantity of this DuplicateItem. + * Empty duplicates are automatically removed. + * + * If the amount is bigger than the quantity of the current topmost, + * only sell as much as possible. Returns the amount actually sold (do + * not ignore the return value!) + * + * @return the amount, that actually was sold. + */ + int sellCurrentDuplicate(int quantity); /** * Gets the price of the item. + * + * @return the price of the item */ int getPrice() const { return mPrice; } /** - * Gets the display name for in the shop list. + * Gets the display name for the item in the shop list. + * + * @return the display name for the item in the shop list */ const std::string& getDisplayName() const { return mDisplayName; } @@ -52,6 +125,15 @@ class ShopItem : public Item int mPrice; int mIndex; std::string mDisplayName; + + /** + * Struct to keep track of duplicates. + */ + typedef struct { + int inventoryIndex; + int quantity; + } DuplicateItem; + std::stack mDuplicates; /** <-- Stores duplicates */ }; #endif -- cgit v1.2.3-70-g09d2 From f4704ccd2a71ca222d8584aac42c80d346a0b688 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Tue, 24 Feb 2009 22:42:33 +0100 Subject: Fixed compile warnings Order of initialization and suggested parenthesis. --- src/gui/npc_text.cpp | 2 +- src/gui/npc_text.h | 2 +- src/gui/setup_video.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index be67fb6e..f4754ef7 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -100,7 +100,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) current_npc->nextDialog(); addText("\n> Next\n"); } else if (mState == NPC_TEXT_STATE_CLOSE || - mState == NPC_TEXT_STATE_NEXT && !current_npc) { + (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { setText(""); setVisible(false); if (current_npc) current_npc->handleDeath(); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index a1373830..00b11b3c 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -93,7 +93,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener NPC_TEXT_STATE_NEXT, NPC_TEXT_STATE_CLOSE }; - int mState; + NPCTextState mState; }; #endif // NPC_TEXT_H diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 37197cd2..b019edb9 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -121,6 +121,10 @@ Setup_Video::Setup_Video(): mCustomCursorCheckBox(new CheckBox(_("Custom cursor"), mCustomCursorEnabled)), mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), mParticleEffectsEnabled)), mNameCheckBox(new CheckBox(_("Show name"), mNameEnabled)), + mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), + mPickupParticleCheckBox(new CheckBox(_("as particle"), + mPickupParticleEnabled)), mSpeechSlider(new Slider(0, 3)), mSpeechLabel(new gcn::Label("")), mAlphaSlider(new Slider(0.2, 1.0)), @@ -138,11 +142,7 @@ Setup_Video::Setup_Video(): mOverlayDetailField(new gcn::Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")), - mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), - mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), - mPickupParticleCheckBox(new CheckBox(_("as particle"), - mPickupParticleEnabled)) + mParticleDetailField(new gcn::Label("")) { setOpaque(false); -- cgit v1.2.3-70-g09d2 From 9759b0bd0a4777c5645c695c119b4716e251add1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 24 Feb 2009 20:01:31 -0700 Subject: Send a next dialog packet when ending interaction Server seems to want it in some cases --- src/gui/npc_text.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index f4754ef7..1750cbd4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -102,6 +102,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) } else if (mState == NPC_TEXT_STATE_CLOSE || (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { setText(""); + if (current_npc) current_npc->nextDialog(); setVisible(false); if (current_npc) current_npc->handleDeath(); } else return; -- cgit v1.2.3-70-g09d2 From b32ee882097905faea84ed73aa86620248fdefae Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 24 Feb 2009 20:19:34 -0700 Subject: Small dialog visibility fix Basically ensures that the NPC text dialog is visible before making NPC input dialogs visible --- src/gui/npcintegerdialog.cpp | 7 +++++++ src/gui/npcintegerdialog.h | 2 ++ src/gui/npclistdialog.cpp | 7 +++++++ src/gui/npclistdialog.h | 2 ++ src/gui/npcstringdialog.cpp | 7 +++++++ src/gui/npcstringdialog.h | 2 ++ 6 files changed, 27 insertions(+) (limited to 'src/gui') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 463f46ae..f91b42da 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -123,3 +123,10 @@ void NpcIntegerDialog::requestFocus() { mValueField->requestFocus(); } + +void NpcIntegerDialog::setVisible(bool visible) +{ + if (visible) npcTextDialog->setVisible(true); + + Window::setVisible(visible); +} diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 941bb55a..6083338c 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -78,6 +78,8 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener */ void requestFocus(); + void setVisible(bool visible); + private: gcn::Button *mDecButton; gcn::Button *mIncButton; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index c476999a..8349cb4a 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -118,3 +118,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) current_npc->dialogChoice(choice); } } + +void NpcListDialog::setVisible(bool visible) +{ + if (visible) npcTextDialog->setVisible(true); + + Window::setVisible(visible); +} diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 57d6247a..e7e2f9a9 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -72,6 +72,8 @@ class NpcListDialog : public Window, public gcn::ActionListener, */ void reset(); + void setVisible(bool visible); + private: gcn::ListBox *mItemList; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index d9bf5682..679c93e5 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -87,3 +87,10 @@ void NpcStringDialog::requestFocus() { mValueField->requestFocus(); } + +void NpcStringDialog::setVisible(bool visible) +{ + if (visible) npcTextDialog->setVisible(true); + + Window::setVisible(visible); +} diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 0faaf203..31f9c9a0 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -68,6 +68,8 @@ class NpcStringDialog : public Window, public gcn::ActionListener */ void requestFocus(); + void setVisible(bool visible); + private: gcn::TextField *mValueField; std::string mDefault; -- cgit v1.2.3-70-g09d2 From a1e483913672e55704e8fbafeff5ea0ccc0c9b07 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 24 Feb 2009 23:03:31 -0700 Subject: Cleaned up some code, as well as removed redundant talk client requesting (which would happen from using the keyboard instead of the mouse). Signed-off-by: Ira Rice --- src/game.cpp | 44 ++++++++++++++++++++++++-------------------- src/gui/npc_text.cpp | 7 ++++++- src/gui/npc_text.h | 2 ++ src/gui/npcintegerdialog.h | 2 ++ src/gui/npclistdialog.h | 2 ++ src/gui/npcstringdialog.h | 2 ++ src/gui/textbox.cpp | 32 +++++++++++++------------------- src/gui/viewport.cpp | 29 +++++++++++++++++++---------- src/net/npchandler.cpp | 7 ++----- src/net/playerhandler.cpp | 9 ++++++--- src/npc.cpp | 12 +++++++++--- src/npc.h | 2 ++ 12 files changed, 89 insertions(+), 61 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index e4b6e54d..e5f7b22b 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -145,9 +145,9 @@ namespace { { void action(const gcn::ActionEvent &event) { - if (event.getId() == "yes" || event.getId() == "ok") { + if (event.getId() == "yes" || event.getId() == "ok") done = true; - } + exitConfirm = NULL; disconnectedDialog = NULL; } @@ -178,13 +178,9 @@ Uint32 nextSecond(Uint32 interval, void *param) int get_elapsed_time(int start_time) { if (start_time <= tick_time) - { return (tick_time - start_time) * 10; - } else - { return (tick_time + (MAX_TIME - start_time)) * 10; - } } /** @@ -213,8 +209,10 @@ void createGuiWindows(Network *network) tradeWindow = new TradeWindow(network); helpWindow = new HelpWindow(); debugWindow = new DebugWindow(); - itemShortcutWindow = new ShortcutWindow("ItemShortcut",new ItemShortcutContainer); - emoteShortcutWindow = new ShortcutWindow("emoteShortcut",new EmoteShortcutContainer); + itemShortcutWindow = new ShortcutWindow("ItemShortcut", + new ItemShortcutContainer); + emoteShortcutWindow = new ShortcutWindow("emoteShortcut", + new EmoteShortcutContainer); // Set initial window visibility chatWindow->setVisible((bool) config.getValue( @@ -465,7 +463,9 @@ void Game::logic() if (!disconnectedDialog) { disconnectedDialog = new OkDialog(_("Network Error"), - _("The connection to the server was lost, the program will now quit")); + _("The connection to the " + "server was lost, the " + "program will now quit")); disconnectedDialog->addActionListener(&exitListener); disconnectedDialog->requestMoveToTop(); } @@ -853,9 +853,11 @@ void Game::handleInput() } // Attack priorioty is: Monster, Player, auto target - target = beingManager->findBeing(targetX, targetY, Being::MONSTER); + target = beingManager->findBeing(targetX, targetY, + Being::MONSTER); if (!target) - target = beingManager->findBeing(targetX, targetY, Being::PLAYER); + target = beingManager->findBeing(targetX, targetY, + Being::PLAYER); } player_node->attack(target, newTarget); @@ -863,30 +865,31 @@ void Game::handleInput() // Target the nearest player if 'q' is pressed if ( keyboard.isKeyActive(keyboard.KEY_TARGET_PLAYER) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) + !keyboard.isKeyActive(keyboard.KEY_TARGET) ) { - Being *target = beingManager->findNearestLivingBeing(player_node, 20, Being::PLAYER); + Being *target = beingManager->findNearestLivingBeing(player_node, + 20, Being::PLAYER); player_node->setTarget(target); } // Target the nearest monster if 'a' pressed if ((keyboard.isKeyActive(keyboard.KEY_TARGET_CLOSEST) || - (joystick && joystick->buttonPressed(3))) && - !keyboard.isKeyActive(keyboard.KEY_TARGET)) + (joystick && joystick->buttonPressed(3))) && + !keyboard.isKeyActive(keyboard.KEY_TARGET)) { Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::MONSTER); + x, y, 20, Being::MONSTER); player_node->setTarget(target); } // Target the nearest npc if 'n' pressed if ( keyboard.isKeyActive(keyboard.KEY_TARGET_NPC) && - !keyboard.isKeyActive(keyboard.KEY_TARGET) ) + !keyboard.isKeyActive(keyboard.KEY_TARGET) ) { Being *target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); + x, y, 20, Being::NPC); player_node->setTarget(target); } @@ -894,14 +897,15 @@ void Game::handleInput() // Talk to the nearest NPC if 't' pressed if ( keyboard.isKeyActive(keyboard.KEY_TALK) ) { - if (!npcTextDialog->isVisible() && !npcListDialog->isVisible()) + if (!npcTextDialog->isVisible() && !npcListDialog->isVisible() && + !npcStringDialog->isVisible() && !npcIntegerDialog->isVisible()) { Being *target = player_node->getTarget(); if (!target) { target = beingManager->findNearestLivingBeing( - x, y, 20, Being::NPC); + x, y, 20, Being::NPC); } if (target) diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index ed75b76e..0b7592c7 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -73,11 +73,16 @@ void NpcTextDialog::addText(const std::string &text) setText(mText + text + "\n"); } +void NpcTextDialog::clearText() +{ + setText(""); +} + void NpcTextDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") { - setText(""); + clearText(); setVisible(false); if (current_npc) diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 5e2ff118..63d41cd6 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -87,4 +87,6 @@ class NpcTextDialog : public Window, public gcn::ActionListener std::string mText; }; +extern NpcTextDialog *npcTextDialog; + #endif // NPC_TEXT_H diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 858bce5b..a4ca33cf 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -81,4 +81,6 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener gcn::Button *resetButton; }; +extern NpcIntegerDialog *npcIntegerDialog; + #endif // GUI_NPCINTEGERDIALOG_H diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 8d8b6545..a30bec28 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -82,4 +82,6 @@ class NpcListDialog : public Window, public gcn::ActionListener, std::vector mItems; }; +extern NpcListDialog *npcListDialog; + #endif // GUI_NPCLISTDIALOG_H diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 71d1f15c..c8871184 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -75,4 +75,6 @@ class NpcStringDialog : public Window, public gcn::ActionListener gcn::Button *cancelButton; }; +extern NpcStringDialog *npcStringDialog; + #endif // GUI_NPCSTRINGDIALOG_H diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index dc94ead2..589986cd 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -38,52 +38,46 @@ void TextBox::setTextWrapped(const std::string &text, int minDimension) { // Make sure parent scroll area sets width of this widget if (getParent()) - { getParent()->logic(); - } // Take the supplied minimum dimension as a starting point and try to beat it mMinWidth = minDimension; std::stringstream wrappedStream; - std::string::size_type newlinePos, lastNewlinePos = 0; + std::string::size_type spacePos, newlinePos, lastNewlinePos = 0; int minWidth = 0; int xpos; + spacePos = text.rfind(" ", text.size()); + + if (spacePos != std::string::npos) + { + const std::string word = text.substr(spacePos + 1); + const int length = getFont()->getWidth(word); + + if (length > mMinWidth) + mMinWidth = length; + } + do { // Determine next piece of string to wrap newlinePos = text.find("\n", lastNewlinePos); if (newlinePos == std::string::npos) - { newlinePos = text.size(); - } std::string line = text.substr(lastNewlinePos, newlinePos - lastNewlinePos); - std::string::size_type spacePos, lastSpacePos = 0; + std::string::size_type lastSpacePos = 0; xpos = 0; - spacePos = text.rfind(" ", text.size()); - - if (spacePos != std::string::npos) - { - const std::string word = text.substr(spacePos + 1); - const int length = getFont()->getWidth(word); - - if (length > mMinWidth) - mMinWidth = length; - } - do { spacePos = line.find(" ", lastSpacePos); if (spacePos == std::string::npos) - { spacePos = line.size(); - } std::string word = line.substr(lastSpacePos, spacePos - lastSpacePos); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 9a7f6173..f655888c 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -111,19 +111,23 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) { if (player_x > mPixelViewX + mScrollRadius) { - mPixelViewX += (player_x - mPixelViewX - mScrollRadius) / mScrollLaziness; + mPixelViewX += (player_x - mPixelViewX - mScrollRadius) / + mScrollLaziness; } if (player_x < mPixelViewX - mScrollRadius) { - mPixelViewX += (player_x - mPixelViewX + mScrollRadius) / mScrollLaziness; + mPixelViewX += (player_x - mPixelViewX + mScrollRadius) / + mScrollLaziness; } if (player_y > mPixelViewY + mScrollRadius) { - mPixelViewY += (player_y - mPixelViewY - mScrollRadius) / mScrollLaziness; + mPixelViewY += (player_y - mPixelViewY - mScrollRadius) / + mScrollLaziness; } if (player_y < mPixelViewY - mScrollRadius) { - mPixelViewY += (player_y - mPixelViewY + mScrollRadius) / mScrollLaziness; + mPixelViewY += (player_y - mPixelViewY + mScrollRadius) / + mScrollLaziness; } lastTick++; } @@ -166,8 +170,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) { mMap->draw(graphics, (int) mPixelViewX, (int) mPixelViewY); - // Find a path from the player to the mouse, and draw it. This is for debug - // purposes. + // Find a path from the player to the mouse, and draw it. This is for + // debug purposes. if (mShowDebugPath) { // Get the current mouse position @@ -177,7 +181,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int mouseTileX = mouseX / 32 + mTileViewX; int mouseTileY = mouseY / 32 + mTileViewY; - Path debugPath = mMap->findPath(player_node->mX, player_node->mY, mouseTileX, mouseTileY); + Path debugPath = mMap->findPath(player_node->mX, player_node->mY, + mouseTileX, mouseTileY); graphics->setColor(gcn::Color(255, 0, 0)); for (PathIterator i = debugPath.begin(); i != debugPath.end(); i++) @@ -186,7 +191,9 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int squareY = i->y * 32 - (int) mPixelViewY + 12; graphics->fillRectangle(gcn::Rectangle(squareX, squareY, 8, 8)); - graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost), squareX + 4, squareY + 12, gcn::Graphics::CENTER); + graphics->drawText(toString(mMap->getMetaTile(i->x, i->y)->Gcost), + squareX + 4, squareY + 12, + gcn::Graphics::CENTER); } } } @@ -300,10 +307,12 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (being->mAction == Being::DEAD) break; - if (player_node->withinAttackRange(being) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) + if (player_node->withinAttackRange(being) || + keyboard.isKeyActive(keyboard.KEY_ATTACK)) { player_node->setGotoTarget(being); - player_node->attack(being, !keyboard.isKeyActive(keyboard.KEY_TARGET)); + player_node->attack(being, + !keyboard.isKeyActive(keyboard.KEY_TARGET)); } else { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 8425a215..94e145b4 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -33,11 +33,6 @@ #include "../gui/npclistdialog.h" #include "../gui/npcstringdialog.h" -extern NpcIntegerDialog *npcIntegerDialog; -extern NpcListDialog *npcListDialog; -extern NpcTextDialog *npcTextDialog; -extern NpcStringDialog *npcStringDialog; - NPCHandler::NPCHandler() { static const Uint16 _messages[] = { @@ -81,10 +76,12 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); if (current_npc == dynamic_cast(beingManager->findBeing(id))) current_npc = NULL; + NPC::mTalking = false; break; case SMSG_NPC_NEXT: // Next button in NPC dialog, currently unused + NPC::mTalking = false; break; case SMSG_NPC_INT_INPUT: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index bce53ae9..c1e0d033 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -32,8 +32,10 @@ #include "../gui/buy.h" #include "../gui/chat.h" #include "../gui/gui.h" -#include "../gui/npclistdialog.h" #include "../gui/npc_text.h" +#include "../gui/npcintegerdialog.h" +#include "../gui/npclistdialog.h" +#include "../gui/npcstringdialog.h" #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" @@ -46,8 +48,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern NpcListDialog *npcListDialog; -extern NpcTextDialog *npcTextDialog; extern BuyDialog *buyDialog; extern SellDialog *sellDialog; extern Window *buySellDialog; @@ -81,7 +81,10 @@ namespace { { player_node->revive(); deathNotice = NULL; + npcIntegerDialog->setVisible(false); npcListDialog->setVisible(false); + npcStringDialog->setVisible(false); + npcTextDialog->clearText(); npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); diff --git a/src/npc.cpp b/src/npc.cpp index dbd7a990..eaf6b78b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -25,12 +25,15 @@ #include "particle.h" #include "text.h" +#include "gui/npc_text.h" + #include "net/messageout.h" #include "net/protocol.h" #include "resources/npcdb.h" NPC *current_npc = 0; +bool NPC::mTalking = false; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -46,7 +49,8 @@ NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): i != info.sprites.end(); i++) { - if (c == VECTOREND_SPRITE) break; + if (c == VECTOREND_SPRITE) + break; std::string file = "graphics/sprites/" + (*i)->sprite; int variant = (*i)->variant; @@ -103,6 +107,10 @@ Being::Type NPC::getType() const void NPC::talk() { + if (mTalking) + return; + + mTalking = true; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); @@ -165,7 +173,5 @@ void NPC::sell() void NPC::updateCoords() { if (mName) - { mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); - } } diff --git a/src/npc.h b/src/npc.h index f8aaad7f..0dc9c742 100644 --- a/src/npc.h +++ b/src/npc.h @@ -51,6 +51,8 @@ class NPC : public Player void buy(); void sell(); + static bool mTalking; + protected: Network *mNetwork; void updateCoords(); -- cgit v1.2.3-70-g09d2 From d8bc3a6418c5027d7f6c42ce8f8dceca8dee8971 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 00:50:33 -0700 Subject: Fixed up NPC list dialogs to be navigatable by keyboard (scrolling through the list requires the use of the mouse wheel at the moment), fixed wrapping behavior for wrapping around lists to actually wrap around lists properly, and placed a few checks for current_npc where they were assumed before which could cause the client to hang or crash in case the NPC is no longer around. Signed-off-by: Ira Rice --- src/game.cpp | 2 +- src/gui/listbox.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/listbox.h | 19 ++++++++++ src/gui/npcintegerdialog.cpp | 11 +++--- src/gui/npclistdialog.cpp | 16 +++++++-- src/gui/npclistdialog.h | 5 +++ src/gui/npcstringdialog.cpp | 5 ++- src/gui/table.cpp | 6 +--- src/net/npchandler.cpp | 2 +- 9 files changed, 136 insertions(+), 15 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index e5f7b22b..16790cac 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -490,7 +490,7 @@ void Game::handleInput() gcn::Window *requestedWindow = NULL; if (setupWindow->isVisible() && - keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) + keyboard.getNewKeyIndex() > keyboard.KEY_NO_VALUE) { keyboard.setNewKey((int) event.key.keysym.sym); keyboard.callbackNewKey(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index f16857ce..8ae68e09 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -22,6 +22,7 @@ #include #include +#include #include #include "color.h" @@ -69,6 +70,90 @@ void ListBox::draw(gcn::Graphics *graphics) } } +void ListBox::setSelected(int selected) +{ + if (!mListModel) + { + mSelected = -1; + } + else + { + if (selected < 0 && !mWrappingEnabled) + { + mSelected = -1; + } + else if (selected >= mListModel->getNumberOfElements() && + mWrappingEnabled) + { + mSelected = 0; + } + else if ((selected >= mListModel->getNumberOfElements() && + !mWrappingEnabled) || (selected < 0 && mWrappingEnabled)) + { + mSelected = mListModel->getNumberOfElements() - 1; + } + else + { + mSelected = selected; + } + } +} + +// -- KeyListener notifications +void ListBox::keyPressed(gcn::KeyEvent& keyEvent) +{ + gcn::Key key = keyEvent.getKey(); + + if (key.getValue() == gcn::Key::ENTER || key.getValue() == gcn::Key::SPACE) + { + distributeActionEvent(); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::UP) + { + setSelected(mSelected - 1); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::DOWN) + { + setSelected(mSelected + 1); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::HOME) + { + setSelected(0); + keyEvent.consume(); + } + else if (key.getValue() == gcn::Key::END) + { + setSelected(getListModel()->getNumberOfElements() - 1); + keyEvent.consume(); + } +} + +void ListBox::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + if (getSelected() > 0 || (getSelected() == 0 && mWrappingEnabled)) + { + setSelected(getSelected() - 1); + } + + mouseEvent.consume(); + } +} + +void ListBox::mouseWheelMovedDown(gcn::MouseEvent& mouseEvent) +{ + if (isFocused()) + { + setSelected(getSelected() + 1); + + mouseEvent.consume(); + } +} + void ListBox::mouseDragged(gcn::MouseEvent &event) { // Pretend mouse is pressed continuously while dragged. Causes list diff --git a/src/gui/listbox.h b/src/gui/listbox.h index e783083f..a6392a94 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -49,6 +49,25 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); + // Inherited from KeyListener + + virtual void keyPressed(gcn::KeyEvent& keyEvent); + + // Inherited from MouseListener + + virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + + virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + + /** + * Sets the selected item. The selected item is represented by + * an index from the list model. + * + * @param selected the selected item as an index from the list model. + * @see getSelected + */ + void setSelected(int selected); + private: static float mAlpha; }; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index ea3398c9..d0a7c7be 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -72,15 +72,15 @@ int NpcIntegerDialog::getValue() void NpcIntegerDialog::action(const gcn::ActionEvent &event) { - int finish = 0; + bool finish = false; if (event.getId() == "ok") { - finish = 1; + finish = true; } else if (event.getId() == "cancel") { - finish = 1; + finish = true; mValueField->reset(); } else if (event.getId() == "decvalue") @@ -99,7 +99,10 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + if (current_npc) + current_npc->integerInput(mValueField->getValue()); + current_npc = NULL; mValueField->reset(); } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 81c33049..f3bb949a 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,9 @@ NpcListDialog::NpcListDialog(): mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); + scrollArea = new ScrollArea(mItemList); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); @@ -95,10 +97,9 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { // Send the selected index back to the server int selectedIndex = mItemList->getSelected(); + if (selectedIndex > -1) - { choice = selectedIndex + 1; - } } else if (event.getId() == "cancel") { @@ -109,7 +110,16 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + + if (current_npc) + current_npc->dialogChoice(choice); + current_npc = NULL; } } + +void NpcListDialog::requestFocus() +{ + mItemList->requestFocus(); + mItemList->setSelected(0); +} diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index a30bec28..de3a7a77 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -73,6 +73,11 @@ class NpcListDialog : public Window, public gcn::ActionListener, */ void reset(); + /** + * Requests the listbox to take focus for input. + */ + void requestFocus(); + private: gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index ef2de73a..140ca40f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,7 +64,10 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + + if (current_npc) + current_npc->stringInput(mValueField->getText()); + current_npc = NULL; mValueField->setText(""); } diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 8acbc4f4..29a33b7a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -402,25 +402,21 @@ void GuiTable::keyPressed(gcn::KeyEvent& keyEvent) else if (key.getValue() == gcn::Key::UP) { setSelectedRow(mSelectedRow - 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) { setSelectedRow(mSelectedRow + 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::LEFT) { setSelectedColumn(mSelectedColumn - 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::RIGHT) { setSelectedColumn(mSelectedColumn + 1); - keyEvent.consume(); } else if (key.getValue() == gcn::Key::HOME) @@ -460,7 +456,7 @@ void GuiTable::mouseWheelMovedUp(gcn::MouseEvent& mouseEvent) { if (isFocused()) { - if (getSelectedRow() >= 0 ) + if (getSelectedRow() > 0 || (getSelectedRow() == 0 && mWrappingEnabled)) { setSelectedRow(getSelectedRow() - 1); } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 94e145b4..26250d9e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -60,6 +60,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); + npcListDialog->requestFocus(); break; case SMSG_NPC_MESSAGE: @@ -68,7 +69,6 @@ void NPCHandler::handleMessage(MessageIn *msg) player_node->setAction(LocalPlayer::STAND); current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); - npcListDialog->setVisible(false); npcTextDialog->setVisible(true); break; -- cgit v1.2.3-70-g09d2 From 543166b9d50ebf06bfc83a32fb2bab3b366eb871 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 10:29:34 -0700 Subject: Make sure that all dialogs are cleared on player death, not just the NPC text dialog. Signed-off-by: Ira Rice --- src/gui/npc_text.cpp | 1 + src/gui/npcintegerdialog.cpp | 5 +++++ src/gui/npcintegerdialog.h | 5 +++++ src/gui/npclistdialog.cpp | 1 + src/net/npchandler.cpp | 2 -- src/net/playerhandler.cpp | 4 +++- 6 files changed, 15 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 0b7592c7..c28f1403 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -75,6 +75,7 @@ void NpcTextDialog::addText(const std::string &text) void NpcTextDialog::clearText() { + NPC::mTalking = false; setText(""); } diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index d0a7c7be..9c49a630 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -70,6 +70,11 @@ int NpcIntegerDialog::getValue() return mValueField->getValue(); } +void NpcIntegerDialog::reset() +{ + mValueField->reset(); +} + void NpcIntegerDialog::action(const gcn::ActionEvent &event) { bool finish = false; diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index a4ca33cf..cca8cb32 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -54,6 +54,11 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener */ int getValue(); + /** + * Resets the integer input field. + */ + void reset(); + /** * Prepares the NPC dialog. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f3bb949a..2c4dfc04 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -86,6 +86,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { + mItemList->setSelected(-1); mItems.clear(); } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 26250d9e..a59ee814 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -76,12 +76,10 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); if (current_npc == dynamic_cast(beingManager->findBeing(id))) current_npc = NULL; - NPC::mTalking = false; break; case SMSG_NPC_NEXT: // Next button in NPC dialog, currently unused - NPC::mTalking = false; break; case SMSG_NPC_INT_INPUT: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index c1e0d033..0637d784 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -82,14 +82,16 @@ namespace { player_node->revive(); deathNotice = NULL; npcIntegerDialog->setVisible(false); + npcListDialog->reset(); npcListDialog->setVisible(false); + npcStringDialog->setValue(""); npcStringDialog->setVisible(false); npcTextDialog->clearText(); npcTextDialog->setVisible(false); buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = 0; + current_npc = NULL; } } deathListener; } -- cgit v1.2.3-70-g09d2 From f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 13:38:55 -0700 Subject: Fix NPC handling to not need a handle on the NPC The Being ID is used instead, as that is all that was ever really needed. --- src/beingmanager.cpp | 21 +++++++------- src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buy.cpp | 2 +- src/gui/buysell.cpp | 22 +++++++++++---- src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 21 ++++++++++---- src/gui/npc_text.h | 8 +++++- src/gui/npcintegerdialog.cpp | 14 +++++++-- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 12 ++++++-- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 16 +++++++++-- src/gui/npcstringdialog.h | 5 +++- src/gui/sell.cpp | 2 +- src/net/beinghandler.cpp | 14 ++++++--- src/net/buysellhandler.cpp | 4 +-- src/net/npchandler.cpp | 27 ++++++++---------- src/net/playerhandler.cpp | 4 +-- src/npc.cpp | 67 ++------------------------------------------ src/npc.h | 15 +--------- 21 files changed, 142 insertions(+), 148 deletions(-) (limited to 'src/gui') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 3b73d29f..273436bf 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -96,10 +96,7 @@ Being* BeingManager::createBeing(Uint32 id, Uint16 job) void BeingManager::destroyBeing(Being *being) { mBeings.remove(being); - if (being == current_npc) - current_npc->handleDeath(); - else - delete being; + delete being; } Being* BeingManager::findBeing(Uint32 id) @@ -196,12 +193,6 @@ void BeingManager::clear() mBeings.remove(player_node); } - if (current_npc) - { - mBeings.remove(current_npc); - current_npc->handleDeath(); - } - delete_all(mBeings); mBeings.clear(); @@ -264,3 +255,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 11721709..02c83725 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -98,13 +98,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index cb85fc5c..6f9dbb88 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -198,13 +198,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow; buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog; + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow; emoteWindow = new EmoteWindow; - npcTextDialog = new NpcTextDialog; - npcIntegerDialog = new NpcIntegerDialog; - npcListDialog = new NpcListDialog; - npcStringDialog = new NpcStringDialog; + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog; setupWindow = new Setup; minimap = new Minimap; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c084c7c2..cad21ab5 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -132,7 +132,7 @@ void BuyDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 8bf5f1f4..c1c934d1 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -24,10 +24,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -60,12 +63,19 @@ void BuySellDialog::logic() void BuySellDialog::action(const gcn::ActionEvent &event) { + setVisible(false); + int action; if (event.getId() == "Buy") { - current_npc->buy(); + action = 0; } else if (event.getId() == "Sell") { - current_npc->sell(); + action = 1; } else if (event.getId() == "Cancel") { - if (current_npc) current_npc->handleDeath(); + current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 754bb551..197c1a2b 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -26,6 +26,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -40,7 +42,7 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Check for current NPC @@ -51,6 +53,9 @@ class BuySellDialog : public Window, public gcn::ActionListener * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 1750cbd4..db0015e9 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")), +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network), mState(NPC_TEXT_STATE_WAITING) { setResizable(true); @@ -97,14 +100,14 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) if (event.getId() == "ok") { if (mState == NPC_TEXT_STATE_NEXT && current_npc) { - current_npc->nextDialog(); + nextDialog(); addText("\n> Next\n"); } else if (mState == NPC_TEXT_STATE_CLOSE || (mState == NPC_TEXT_STATE_NEXT && !current_npc)) { setText(""); - if (current_npc) current_npc->nextDialog(); + if (current_npc) nextDialog(); setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } else return; } else return; @@ -114,10 +117,16 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) mState = NPC_TEXT_STATE_WAITING; } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); setText(mText); } - diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 00b11b3c..62486fff 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -28,6 +28,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -43,7 +46,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -74,6 +77,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void showCloseButton(); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -82,6 +87,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index f91b42da..f6d788df 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField; @@ -104,7 +107,12 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); - current_npc->integerInput(mValueField->getValue()); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); + mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index 6083338c..80a21848 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -26,6 +26,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -41,7 +42,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -81,6 +82,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 8349cb4a..fc7d2979 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,13 +31,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -115,7 +118,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) { setVisible(false); reset(); - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index e7e2f9a9..a7b49506 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -29,6 +29,8 @@ #include +class Network; + /** * The npc list dialog. * @@ -43,7 +45,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -75,6 +77,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void setVisible(bool visible); private: + Network *mNetwork; gcn::ListBox *mItemList; std::vector mItems; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 679c93e5..7ed05288 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,13 +28,16 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" #include "../utils/strprintf.h" extern NpcTextDialog *npcTextDialog; -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -74,8 +77,15 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); - current_npc->stringInput(mValueField->getText()); + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index 31f9c9a0..43283219 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -26,6 +26,8 @@ #include +class Network; + /** * The npc integer input dialog. * @@ -39,7 +41,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +73,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void setVisible(bool visible); private: + Network *mNetwork; gcn::TextField *mValueField; std::string mDefault; }; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 14620aa6..51fc8f9f 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -133,7 +133,7 @@ void SellDialog::action(const gcn::ActionEvent &event) if (event.getId() == "quit") { setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; return; } diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 3e746eb5..982667d1 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -35,6 +35,10 @@ #include "../npc.h" #include "../player_relations.h" +#include "../gui/npc_text.h" + +extern NpcTextDialog *npcTextDialog; + const int EMOTION_TIME = 150; /**< Duration of emotion icon */ BeingHandler::BeingHandler(bool enableSync): @@ -204,7 +208,12 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + + if (id == current_npc) + npcTextDialog->showCloseButton(); + + dstBeing = beingManager->findBeing(id); if (!dstBeing) break; @@ -213,9 +222,6 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc->handleDeath(); - if (msg->readInt8() == 1) dstBeing->setAction(Being::DEAD); else diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index a2442d70..714bc0ea 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -65,7 +65,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -107,7 +107,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) } else { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } break; diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index ae521bd5..405217bb 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -54,24 +54,21 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { int id; - NPC *temporaryNPC; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); break; case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(false); npcTextDialog->setVisible(true); @@ -79,30 +76,28 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_CLOSE: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the close button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - temporaryNPC->nextDialog(); + npcTextDialog->nextDialog(id); break; case SMSG_NPC_NEXT: id = msg->readInt32(); - temporaryNPC = dynamic_cast(beingManager->findBeing(id)); // If we're talking to that NPC, show the next button - if (temporaryNPC == current_npc) + if (id == current_npc) npcTextDialog->showNextButton(); - else if (temporaryNPC) // Otherwise, move on as an empty dialog doesn't help - temporaryNPC->nextDialog(); + else + npcTextDialog->nextDialog(id); break; case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setDefaultValue(0); npcIntegerDialog->setVisible(true); @@ -111,8 +106,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ee1b2fd9..550753b7 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -93,7 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - if (current_npc) current_npc->handleDeath(); + current_npc = 0; } } deathListener; } @@ -147,8 +147,6 @@ void PlayerHandler::handleMessage(MessageIn *msg) // Switch the actual map, deleting the previous one if necessary engine->changeMap(mapPath); - if (current_npc) current_npc->handleDeath(); - float scrollOffsetX = 0.0f; float scrollOffsetY = 0.0f; diff --git a/src/npc.cpp b/src/npc.cpp index ecac2509..8fd8a86b 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -20,6 +20,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -33,7 +34,7 @@ extern NpcTextDialog *npcTextDialog; -NPC *current_npc = NULL; +int current_npc = NULL; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -113,60 +114,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!this || !mNetwork) return; - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) @@ -174,13 +121,3 @@ void NPC::updateCoords() mName->adviseXY(mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET); } } - -void NPC::handleDeath() -{ - if (this != current_npc) return; - - if (npcTextDialog->isVisible()) - npcTextDialog->showCloseButton(); - else - current_npc = NULL; -} diff --git a/src/npc.h b/src/npc.h index 81b6d51e..ef9fdc7d 100644 --- a/src/npc.h +++ b/src/npc.h @@ -42,19 +42,6 @@ class NPC : public Player virtual Type getType() const; void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); - - /** - * Call this to ease clean up of the current NPC, without causing - * interface problems - */ - void handleDeath(); protected: Network *mNetwork; void updateCoords(); @@ -62,6 +49,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern int current_npc; #endif -- cgit v1.2.3-70-g09d2 From 3ad6ac47d4967870a54fddd66aa9996724115b94 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 25 Feb 2009 13:50:47 -0700 Subject: Prevent duplicate NPC talking when using keyboard Based on commit a1e483913672e55704e8fbafeff5ea0ccc0c9b07 from Aethyra. --- src/gui/npc_text.cpp | 1 + src/npc.cpp | 7 +++++-- src/npc.h | 2 ++ 3 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index db0015e9..520efad4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -108,6 +108,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) if (current_npc) nextDialog(); setVisible(false); current_npc = 0; + NPC::isTalking = false; } else return; } else return; diff --git a/src/npc.cpp b/src/npc.cpp index 8fd8a86b..5132e0dc 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -34,7 +34,8 @@ extern NpcTextDialog *npcTextDialog; -int current_npc = NULL; +int current_npc = 0; +bool NPC::isTalking = false; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -107,7 +108,9 @@ Being::Type NPC::getType() const void NPC::talk() { - if (!this || !mNetwork) return; + if (isTalking || !this || !mNetwork) return; + + isTalking = true; MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_NPC_TALK); outMsg.writeInt32(mId); diff --git a/src/npc.h b/src/npc.h index ef9fdc7d..182da3e5 100644 --- a/src/npc.h +++ b/src/npc.h @@ -42,6 +42,8 @@ class NPC : public Player virtual Type getType() const; void talk(); + + static bool isTalking; protected: Network *mNetwork; void updateCoords(); -- cgit v1.2.3-70-g09d2 From 0dde31c3db09113639fa443142995b6efcff6646 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 25 Feb 2009 19:04:39 -0700 Subject: Fix NPC handling to not need a handle on the NPC Loosely based on TMW commit f04a8713ffc83db8b3dc4a472b28aad25a2b2bd1 Signed-off-by: Ira Rice --- src/beingmanager.cpp | 10 +++++++ src/beingmanager.h | 10 ++++++- src/game.cpp | 10 +++---- src/gui/buysell.cpp | 34 +++++++++++++++++------ src/gui/buysell.h | 7 ++++- src/gui/npc_text.cpp | 18 +++++++++--- src/gui/npc_text.h | 9 ++++-- src/gui/npcintegerdialog.cpp | 16 +++++++---- src/gui/npcintegerdialog.h | 4 ++- src/gui/npclistdialog.cpp | 16 +++++++---- src/gui/npclistdialog.h | 5 +++- src/gui/npcstringdialog.cpp | 22 +++++++++++---- src/gui/npcstringdialog.h | 5 +++- src/net/beinghandler.cpp | 13 ++++----- src/net/buysellhandler.cpp | 25 ++++++++++------- src/net/npchandler.cpp | 22 +++++++-------- src/net/playerhandler.cpp | 2 +- src/npc.cpp | 65 ++------------------------------------------ src/npc.h | 13 +++------ 19 files changed, 165 insertions(+), 141 deletions(-) (limited to 'src/gui') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index b4ffa76c..d63e0dc5 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -253,3 +253,13 @@ Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } + +bool BeingManager::hasBeing(Being *being) +{ + for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) + { + if (being == *i) return true; + } + + return false; +} diff --git a/src/beingmanager.h b/src/beingmanager.h index 59a7c76a..32ba6242 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -99,13 +99,21 @@ class BeingManager */ Beings& getAll(); + /** + * Returns true if the given being is in the manager's list, false + * otherwise. + * + * \param being the being to search for + */ + bool hasBeing(Being *being); + /** * Logic. */ void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 16790cac..110b75cc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -195,13 +195,13 @@ void createGuiWindows(Network *network) miniStatusWindow = new MiniStatusWindow(); buyDialog = new BuyDialog(network); sellDialog = new SellDialog(network); - buySellDialog = new BuySellDialog(); + buySellDialog = new BuySellDialog(network); inventoryWindow = new InventoryWindow(); emoteWindow = new EmoteWindow(); - npcTextDialog = new NpcTextDialog(); - npcIntegerDialog = new NpcIntegerDialog(); - npcListDialog = new NpcListDialog(); - npcStringDialog = new NpcStringDialog(); + npcTextDialog = new NpcTextDialog(network); + npcIntegerDialog = new NpcIntegerDialog(network); + npcListDialog = new NpcListDialog(network); + npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); setupWindow = new Setup(); minimap = new Minimap(); diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 7d63f184..dc7deef6 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -25,10 +25,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -BuySellDialog::BuySellDialog(): - Window(_("Shop")) +BuySellDialog::BuySellDialog(Network *network): + Window(_("Shop")), mNetwork(network) { Button *buyButton = 0; static const char *buttonNames[] = { @@ -54,12 +57,27 @@ BuySellDialog::BuySellDialog(): void BuySellDialog::action(const gcn::ActionEvent &event) { - if (event.getId() == "Buy") { - current_npc->buy(); - } else if (event.getId() == "Sell") { - current_npc->sell(); - } else if (event.getId() == "Cancel") { + setVisible(false); + int action = 0; + + NPC::mTalking = false; + + if (event.getId() == "Buy") + { + action = 0; + } + else if (event.getId() == "Sell") + { + action = 1; + } + else if (event.getId() == "Cancel") + { current_npc = 0; + return; } - setVisible(false); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(action); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index c12e3c9b..747066a7 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * A dialog to choose between buying or selling at a shop. * @@ -41,12 +43,15 @@ class BuySellDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - BuySellDialog(); + BuySellDialog(Network *network); /** * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); + + private: + Network *mNetwork; }; #endif diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index c28f1403..b94e8aa4 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -29,10 +29,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcTextDialog::NpcTextDialog(): - Window(_("NPC")) +NpcTextDialog::NpcTextDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -87,12 +90,19 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) setVisible(false); if (current_npc) - current_npc->nextDialog(); + nextDialog(); - current_npc = NULL; + current_npc = 0; } } +void NpcTextDialog::nextDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 63d41cd6..a72de5d0 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -29,6 +29,9 @@ #include "window.h" +#include "../npc.h" + +class Network; class TextBox; /** @@ -44,7 +47,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcTextDialog(); + NpcTextDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -71,6 +74,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + void nextDialog(int npcID = current_npc); + /** * Called when resizing the window. * @@ -79,7 +84,7 @@ class NpcTextDialog : public Window, public gcn::ActionListener void widgetResized(const gcn::Event &event); private: - gcn::Button *okButton; + Network *mNetwork; gcn::ScrollArea *mScrollArea; TextBox *mTextBox; gcn::Button *mButton; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9c49a630..132a7608 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcIntegerDialog::NpcIntegerDialog(): - Window(_("NPC Number Request")) +NpcIntegerDialog::NpcIntegerDialog(Network *network): + Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); @@ -104,11 +107,14 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) if (finish) { setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->integerInput(mValueField->getValue()); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); + outMsg.writeInt32(current_npc); + outMsg.writeInt32(mValueField->getValue()); - current_npc = NULL; + current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npcintegerdialog.h b/src/gui/npcintegerdialog.h index cca8cb32..15bdee48 100644 --- a/src/gui/npcintegerdialog.h +++ b/src/gui/npcintegerdialog.h @@ -27,6 +27,7 @@ #include "window.h" +class Network; class IntTextField; /** @@ -42,7 +43,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcIntegerDialog(); + NpcIntegerDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -78,6 +79,7 @@ class NpcIntegerDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::Button *mDecButton; gcn::Button *mIncButton; IntTextField *mValueField; diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 2c4dfc04..73b00239 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -31,10 +31,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcListDialog::NpcListDialog(): - Window(_("NPC")) +NpcListDialog::NpcListDialog(Network *network): + Window(_("NPC")), mNetwork(network) { setResizable(true); @@ -86,6 +89,7 @@ void NpcListDialog::parseItems(const std::string &itemString) void NpcListDialog::reset() { + NPC::mTalking = false; mItemList->setSelected(-1); mItems.clear(); } @@ -112,10 +116,12 @@ void NpcListDialog::action(const gcn::ActionEvent &event) setVisible(false); reset(); - if (current_npc) - current_npc->dialogChoice(choice); + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); + outMsg.writeInt32(current_npc); + outMsg.writeInt8(choice); - current_npc = NULL; + current_npc = 0; } } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index de3a7a77..0a0e9813 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -30,6 +30,8 @@ #include "window.h" +class Network; + /** * The npc list dialog. * @@ -44,7 +46,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, * * @see Window::Window */ - NpcListDialog(); + NpcListDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -79,6 +81,7 @@ class NpcListDialog : public Window, public gcn::ActionListener, void requestFocus(); private: + Network *mNetwork; gcn::ListBox *mItemList; gcn::ScrollArea *scrollArea; gcn::Button *okButton; diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 140ca40f..f2c7434c 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -28,10 +28,13 @@ #include "../npc.h" +#include "../net/messageout.h" +#include "../net/protocol.h" + #include "../utils/gettext.h" -NpcStringDialog::NpcStringDialog(): - Window(_("NPC Text Request")) +NpcStringDialog::NpcStringDialog(Network *network): + Window(_("NPC Text Request")), mNetwork(network) { mValueField = new TextField(""); @@ -64,12 +67,19 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) } setVisible(false); + NPC::mTalking = false; - if (current_npc) - current_npc->stringInput(mValueField->getText()); - - current_npc = NULL; + std::string text = mValueField->getText(); mValueField->setText(""); + + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); + outMsg.writeInt16(text.length() + 9); + outMsg.writeInt32(current_npc); + outMsg.writeString(text, text.length()); + outMsg.writeInt8(0); + + current_npc = 0; } bool NpcStringDialog::isInputFocused() diff --git a/src/gui/npcstringdialog.h b/src/gui/npcstringdialog.h index c8871184..ee620daf 100644 --- a/src/gui/npcstringdialog.h +++ b/src/gui/npcstringdialog.h @@ -27,6 +27,8 @@ #include "window.h" +class Network; + /** * The npc integer input dialog. * @@ -40,7 +42,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener * * @see Window::Window */ - NpcStringDialog(); + NpcStringDialog(Network *network); /** * Called when receiving actions from the widgets. @@ -70,6 +72,7 @@ class NpcStringDialog : public Window, public gcn::ActionListener void requestFocus(); private: + Network *mNetwork; gcn::TextField *mValueField; gcn::Button *okButton; gcn::Button *cancelButton; diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index c11d22e7..bae14a05 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -196,7 +196,11 @@ void BeingHandler::handleMessage(MessageIn *msg) case SMSG_BEING_REMOVE: // A being should be removed or has died - dstBeing = beingManager->findBeing(msg->readInt32()); + id = msg->readInt32(); + dstBeing = beingManager->findBeing(id); + + if (id == current_npc) + current_npc = 0; if (!dstBeing) break; @@ -205,12 +209,7 @@ void BeingHandler::handleMessage(MessageIn *msg) if (dstBeing == player_node->getTarget()) player_node->stopAttack(); - if (dstBeing == current_npc) - current_npc = NULL; - - if (msg->readInt8() == 1) - dstBeing->setAction(Being::DEAD); - else + if (!(msg->readInt8() == 1)) beingManager->destroyBeing(dstBeing); break; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 245b8a50..e9255540 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -66,7 +66,7 @@ void BuySellHandler::handleMessage(MessageIn *msg) sellDialog->setVisible(false); sellDialog->reset(); buySellDialog->setVisible(true); - current_npc = dynamic_cast(beingManager->findBeing(msg->readInt32())); + current_npc = msg->readInt32(); break; case SMSG_NPC_BUY: @@ -89,7 +89,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) case SMSG_NPC_SELL: msg->readInt16(); // length n_items = (msg->getLength() - 4) / 10; - if (n_items > 0) { + if (n_items > 0) + { sellDialog->setMoney(player_node->mGp); sellDialog->reset(); sellDialog->setVisible(true); @@ -101,21 +102,25 @@ void BuySellHandler::handleMessage(MessageIn *msg) msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); - if (item && !(item->isEquipped())) { + + if (item && !(item->isEquipped())) sellDialog->addItem(item, value); - } } } - else { + else + { chatWindow->chatLog(_("Nothing to sell"), BY_SERVER); current_npc = 0; } break; case SMSG_NPC_BUY_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) + { chatWindow->chatLog(_("Thanks for buying"), BY_SERVER); - } else { + } + else + { // Reset player money since buy dialog already assumed purchase // would go fine buyDialog->setMoney(player_node->mGp); @@ -124,11 +129,11 @@ void BuySellHandler::handleMessage(MessageIn *msg) break; case SMSG_NPC_SELL_RESPONSE: - if (msg->readInt8() == 0) { + if (msg->readInt8() == 0) chatWindow->chatLog(_("Thanks for selling"), BY_SERVER); - } else { + else chatWindow->chatLog(_("Unable to sell"), BY_SERVER); - } + break; } } diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index a59ee814..1067a57e 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -20,6 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "messagein.h" #include "npchandler.h" #include "protocol.h" @@ -49,15 +51,14 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - int id; + Uint32 id; switch (msg->getId()) { case SMSG_NPC_CHOICE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); npcListDialog->setVisible(true); npcListDialog->requestFocus(); @@ -65,17 +66,16 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_MESSAGE: msg->readInt16(); // length - id = msg->readInt32(); + current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); - current_npc = dynamic_cast(beingManager->findBeing(id)); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); npcTextDialog->setVisible(true); break; case SMSG_NPC_CLOSE: id = msg->readInt32(); - if (current_npc == dynamic_cast(beingManager->findBeing(id))) - current_npc = NULL; + if (current_npc == id) + current_npc = 0; break; case SMSG_NPC_NEXT: @@ -84,8 +84,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_INT_INPUT: // Request for an integer - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcIntegerDialog->setRange(0, 2147483647); npcIntegerDialog->setVisible(true); npcIntegerDialog->requestFocus(); @@ -93,8 +93,8 @@ void NPCHandler::handleMessage(MessageIn *msg) case SMSG_NPC_STR_INPUT: // Request for a string - id = msg->readInt32(); - current_npc = dynamic_cast(beingManager->findBeing(id)); + current_npc = msg->readInt32(); + player_node->setAction(LocalPlayer::STAND); npcStringDialog->setValue(""); npcStringDialog->setVisible(true); npcStringDialog->requestFocus(); diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index f18c5d82..ffeb3fab 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -92,7 +92,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = NULL; + current_npc = 0; } } deathListener; } diff --git a/src/npc.cpp b/src/npc.cpp index 832e6926..92ef4d82 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -21,6 +21,7 @@ */ #include "animatedsprite.h" +#include "beingmanager.h" #include "npc.h" #include "particle.h" #include "text.h" @@ -32,8 +33,8 @@ #include "resources/npcdb.h" -NPC *current_npc = 0; bool NPC::mTalking = false; +Uint32 current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; @@ -117,68 +118,6 @@ void NPC::talk() outMsg.writeInt8(0); } -void NPC::nextDialog() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_NEXT_REQUEST); - outMsg.writeInt32(mId); -} - -void NPC::dialogChoice(char choice) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); - outMsg.writeInt32(mId); - outMsg.writeInt8(choice); -} - -void NPC::integerInput(int value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_INT_RESPONSE); - outMsg.writeInt32(mId); - outMsg.writeInt32(value); -} - -void NPC::stringInput(const std::string &value) -{ - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_STR_RESPONSE); - outMsg.writeInt16(value.length() + 9); - outMsg.writeInt32(mId); - outMsg.writeString(value, value.length()); - outMsg.writeInt8(0); -} - -/* - * TODO Unify the buy() and sell() methods, without sacrificing readability of - * the code calling the method. buy(bool buySell) would be bad... - */ -void NPC::buy() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(0); -} - -void NPC::sell() -{ - if (!mNetwork) - return; - - MessageOut outMsg(mNetwork); - outMsg.writeInt16(CMSG_NPC_BUY_SELL_REQUEST); - outMsg.writeInt32(mId); - outMsg.writeInt8(1); -} - void NPC::updateCoords() { if (mName) diff --git a/src/npc.h b/src/npc.h index 0dc9c742..e1bf9737 100644 --- a/src/npc.h +++ b/src/npc.h @@ -23,6 +23,8 @@ #ifndef NPC_H #define NPC_H +#include + #include "player.h" class Network; @@ -42,14 +44,7 @@ class NPC : public Player virtual Type getType() const; - void talk(); - void nextDialog(); - void dialogChoice(char choice); - void integerInput(int value); - void stringInput(const std::string &value); - - void buy(); - void sell(); + void talk();; static bool mTalking; @@ -60,6 +55,6 @@ class NPC : public Player Text *mName; }; -extern NPC *current_npc; +extern Uint32 current_npc; #endif -- cgit v1.2.3-70-g09d2 From 0ffbbaa33f633bccf3b2a49713eb1cb117ff8a5a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 26 Feb 2009 08:24:01 -0700 Subject: Fixed an error in shoplistboxes as identified by Octalot. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 2 +- src/gui/buy.h | 2 +- src/gui/listbox.cpp | 3 ++- src/gui/listbox.h | 10 +++++----- src/gui/sell.cpp | 2 +- src/gui/shop.cpp | 3 +-- src/gui/shoplistbox.cpp | 9 --------- src/gui/shoplistbox.h | 2 -- src/shopitem.cpp | 6 ++---- src/shopitem.h | 2 +- 10 files changed, 14 insertions(+), 27 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index a2485ca1..5a57dcc6 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -118,7 +118,7 @@ void BuyDialog::reset() setMoney(0); } -void BuyDialog::addItem(short id, int price) +void BuyDialog::addItem(int id, int price) { mShopItems->addItem(id, price); mShopItemList->adjustSize(); diff --git a/src/gui/buy.h b/src/gui/buy.h index b05608c0..9029fe9d 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -69,7 +69,7 @@ class BuyDialog : public Window, public gcn::ActionListener, /** * Adds an item to the shop inventory. */ - void addItem(short id, int price); + void addItem(int id, int price); /** * Called when receiving actions from the widgets. diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 8ae68e09..45d14884 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -56,7 +56,7 @@ void ListBox::draw(gcn::Graphics *graphics) const int fontHeight = getFont()->getHeight(); - // Draw rectangle below the selected list element + // Draw filled rectangle around the selected list element if (mSelected >= 0) graphics->fillRectangle(gcn::Rectangle(0, fontHeight * mSelected, getWidth(), fontHeight)); @@ -97,6 +97,7 @@ void ListBox::setSelected(int selected) mSelected = selected; } } + gcn::ListBox::setSelected(mSelected); } // -- KeyListener notifications diff --git a/src/gui/listbox.h b/src/gui/listbox.h index a6392a94..09f00cdf 100644 --- a/src/gui/listbox.h +++ b/src/gui/listbox.h @@ -47,17 +47,17 @@ class ListBox : public gcn::ListBox */ void draw(gcn::Graphics *graphics); - void mouseDragged(gcn::MouseEvent &event); - // Inherited from KeyListener - virtual void keyPressed(gcn::KeyEvent& keyEvent); + void keyPressed(gcn::KeyEvent& keyEvent); // Inherited from MouseListener - virtual void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); + void mouseWheelMovedUp(gcn::MouseEvent& mouseEvent); - virtual void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + void mouseWheelMovedDown(gcn::MouseEvent& mouseEvent); + + void mouseDragged(gcn::MouseEvent &event); /** * Sets the selected item. The selected item is represented by diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index f974f247..154d1a57 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -121,7 +121,7 @@ void SellDialog::addItem(const Item *item, int price) } mShopItems->addItem(item->getInvIndex(), item->getId(), - item->getQuantity(), price); + item->getQuantity(), price); mShopItemList->adjustSize(); } diff --git a/src/gui/shop.cpp b/src/gui/shop.cpp index da68cf28..bd676bc0 100644 --- a/src/gui/shop.cpp +++ b/src/gui/shop.cpp @@ -44,8 +44,7 @@ std::string ShopItems::getElementAt(int i) return mShopItems.at(i)->getDisplayName(); } -void ShopItems::addItem(int inventoryIndex, int id, int quantity, - int price) +void ShopItems::addItem(int inventoryIndex, int id, int quantity, int price) { ShopItem* item = 0; if (mMergeDuplicates) diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 6d3d9464..6e70e022 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -108,15 +108,6 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) } } -void ShopListBox::mousePressed(gcn::MouseEvent &event) -{ - if (event.getButton() == gcn::MouseEvent::LEFT) - { - setSelected(event.getY() / mRowHeight); - distributeActionEvent(); - } -} - void ShopListBox::adjustSize() { if (mListModel) diff --git a/src/gui/shoplistbox.h b/src/gui/shoplistbox.h index 8542a7b8..bed9902b 100644 --- a/src/gui/shoplistbox.h +++ b/src/gui/shoplistbox.h @@ -57,8 +57,6 @@ class ShopListBox : public ListBox */ unsigned int getRowHeight() const { return mRowHeight; } - void mousePressed(gcn::MouseEvent &event); - /** * gives information about the current player's money */ diff --git a/src/shopitem.cpp b/src/shopitem.cpp index 5573eb37..00875a2d 100644 --- a/src/shopitem.cpp +++ b/src/shopitem.cpp @@ -24,8 +24,7 @@ #include "utils/stringutils.h" -ShopItem::ShopItem (int inventoryIndex, int id, - int quantity, int price) : +ShopItem::ShopItem (int inventoryIndex, int id, int quantity, int price) : Item (id, 0), mPrice(price) { mDisplayName = getInfo().getName() + " (" + toString(mPrice) + " GP)"; @@ -50,8 +49,7 @@ ShopItem::~ShopItem() } } -void ShopItem::addDuplicate(int inventoryIndex, - int quantity) +void ShopItem::addDuplicate(int inventoryIndex, int quantity) { DuplicateItem* di = new DuplicateItem; di->inventoryIndex = inventoryIndex; diff --git a/src/shopitem.h b/src/shopitem.h index d6226732..18608a94 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -89,7 +89,7 @@ class ShopItem : public Item */ int getCurrentInvIndex() { return mDuplicates.empty() ? mInvIndex : - mDuplicates.top()->inventoryIndex; + mDuplicates.top()->inventoryIndex; } /** -- cgit v1.2.3-70-g09d2 From 071b1c3126362967b0b6a837349b7c5e327574e9 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 26 Feb 2009 13:47:55 -0700 Subject: Don't clear current NPC early --- src/gui/npcintegerdialog.cpp | 1 - src/gui/npclistdialog.cpp | 2 -- src/gui/npcstringdialog.cpp | 2 -- 3 files changed, 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9dc3660b..9778d790 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -119,7 +119,6 @@ void NpcIntegerDialog::action(const gcn::ActionEvent &event) outMsg.writeInt32(current_npc); outMsg.writeInt32(mValueField->getValue()); - current_npc = 0; mValueField->reset(); } } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 53d4f21f..f5479efc 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -128,8 +128,6 @@ void NpcListDialog::action(const gcn::ActionEvent &event) outMsg.writeInt16(CMSG_NPC_LIST_CHOICE); outMsg.writeInt32(current_npc); outMsg.writeInt8(choice); - - current_npc = 0; } } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index fb3b43db..aec30826 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -88,8 +88,6 @@ void NpcStringDialog::action(const gcn::ActionEvent &event) outMsg.writeInt32(current_npc); outMsg.writeString(text, text.length()); outMsg.writeInt8(0); - - current_npc = 0; } bool NpcStringDialog::isInputFocused() -- cgit v1.2.3-70-g09d2 From a65570a60c1d2f58d2f3fe01a4a54cd08a90d932 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 28 Feb 2009 10:49:55 -0700 Subject: Allow chatting while talking to NPCs --- src/game.cpp | 40 ++++++++++++---------------------------- src/gui/chat.cpp | 7 ++++++- src/gui/chat.h | 5 ++++- 3 files changed, 22 insertions(+), 30 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index 6bff0025..d6445ecc 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -513,58 +513,42 @@ void Game::handleInput() } } - if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT) || - keyboard.isKeyActive(keyboard.KEY_OK)) - { - // Input chat window - if (!(chatWindow->isInputFocused() || - deathNotice || - weightNotice)) + if (!(chatWindow->isInputFocused() || deathNotice || weightNotice)) + if (keyboard.isKeyActive(keyboard.KEY_OK)) { - // Quit by pressing Enter if the exit confirm is there if (exitConfirm && keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) done = true; // Close the Browser if opened else if (helpWindow->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) helpWindow->setVisible(false); // Close the config window, cancelling changes if opened else if (setupWindow->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) setupWindow->action(gcn::ActionEvent(NULL, "cancel")); // Submits the text and proceeds to the next dialog else if (npcStringDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcStringDialog->action(gcn::ActionEvent(NULL, "ok")); // Proceed to the next dialog option, or close the window else if (npcTextDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcTextDialog->action(gcn::ActionEvent(NULL, "ok")); // Choose the currently highlighted dialogue option else if (npcListDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcListDialog->action(gcn::ActionEvent(NULL, "ok")); // Submits the text and proceeds to the next dialog else if (npcIntegerDialog->isVisible() && - keyboard.isKeyActive(keyboard.KEY_OK)) + keyboard.isKeyActive(keyboard.KEY_OK)) npcIntegerDialog->action(gcn::ActionEvent(NULL, "ok")); - else if (!(keyboard.getKeyValue( - KeyboardConfig::KEY_TOGGLE_CHAT) == - keyboard.getKeyValue( - KeyboardConfig::KEY_OK) && - (helpWindow->isVisible() || - setupWindow->isVisible() || - npcStringDialog->isVisible() || - npcTextDialog->isVisible() || - npcListDialog->isVisible() || - npcIntegerDialog->isVisible()))) - { - chatWindow->requestChatFocus(); + } + if (keyboard.isKeyActive(keyboard.KEY_TOGGLE_CHAT)) + { + if (chatWindow->requestChatFocus()) used = true; - } } - } const int tKey = keyboard.getKeyIndex(event.key.keysym.sym); switch (tKey) diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index ac13355c..20d0213b 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -284,7 +284,7 @@ void ChatWindow::action(const gcn::ActionEvent &event) } } -void ChatWindow::requestChatFocus() +bool ChatWindow::requestChatFocus() { // Make sure chatWindow is visible if (!isVisible()) @@ -299,9 +299,14 @@ void ChatWindow::requestChatFocus() mTmpVisible = true; } + // Don't do anything else if the input is already visible and has focus + if (mChatInput->isVisible() && mChatInput->isFocused()) + return false; + // Give focus to the chat input mChatInput->setVisible(true); mChatInput->requestFocus(); + return true; } bool ChatWindow::isInputFocused() diff --git a/src/gui/chat.h b/src/gui/chat.h index 2fadb014..6002fed3 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -138,8 +138,11 @@ class ChatWindow : public Window, public gcn::ActionListener, /** * Request focus for typing chat message. + * + * \returns true if the input was shown + * false otherwise */ - void requestChatFocus(); + bool requestChatFocus(); /** * Checks whether ChatWindow is Focused or not. -- cgit v1.2.3-70-g09d2 From c75511fffc77d517fbf854ec8bef791f055de44c Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 26 Feb 2009 22:22:22 +0100 Subject: Got rid of Sint{8,16,32} and Uint32 for being ID Using unsigned rarely makes sense, especially when the server doesn't use it either. Other uses of unsigned should be reviewed. In all other cases, int is the fastest integer type on any architecture. Using 8 or 16 bits can basically only be a memory optimization. --- src/being.cpp | 2 +- src/being.h | 12 ++++++------ src/beingmanager.cpp | 16 ++++++++-------- src/beingmanager.h | 14 +++++++------- src/floor_item.cpp | 10 +++++----- src/floor_item.h | 20 ++++++++++---------- src/flooritemmanager.cpp | 9 ++++----- src/flooritemmanager.h | 7 +++---- src/gui/popupmenu.h | 4 +--- src/localplayer.cpp | 2 +- src/localplayer.h | 4 ++-- src/monster.cpp | 2 +- src/monster.h | 2 +- src/net/beinghandler.cpp | 6 +++--- src/net/buysellhandler.cpp | 8 ++++---- src/net/chathandler.cpp | 2 +- src/net/equipmenthandler.cpp | 6 +++--- src/net/inventoryhandler.cpp | 6 +++--- src/net/itemhandler.cpp | 2 +- src/net/npchandler.cpp | 2 +- src/net/playerhandler.cpp | 22 +++++++++++----------- src/net/skillhandler.cpp | 8 ++++---- src/net/tradehandler.cpp | 6 +++--- src/npc.cpp | 2 +- src/npc.h | 2 +- 25 files changed, 86 insertions(+), 90 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index 902bd4e1..45019bf2 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -185,7 +185,7 @@ void Being::setSprite(int slot, int id, std::string color) mSpriteColors[slot] = color; } -void Being::setSpeech(const std::string &text, Uint32 time) +void Being::setSpeech(const std::string &text, int time) { mSpeech = text; diff --git a/src/being.h b/src/being.h index ef830e3a..8b2a1e7e 100644 --- a/src/being.h +++ b/src/being.h @@ -166,7 +166,7 @@ class Being : public Sprite * @param text The text that should appear. * @param time The amount of time the text should stay in milliseconds. */ - void setSpeech(const std::string &text, Uint32 time = 500); + void setSpeech(const std::string &text, int time = 500); /** * Puts a damage bubble above this being. @@ -285,12 +285,12 @@ class Being : public Sprite /** * Gets the sprite id. */ - Uint32 getId() const { return mId; } + int getId() const { return mId; } /** * Sets the sprite id. */ - void setId(Uint32 id) { mId = id; } + void setId(int id) { mId = id; } /** * Sets the map the being is on @@ -477,7 +477,7 @@ class Being : public Sprite */ virtual void handleStatusEffect(StatusEffect *effect, int effectId); - Uint32 mId; /**< Unique sprite id */ + int mId; /**< Unique sprite id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint8 mDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ @@ -496,8 +496,8 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - Uint32 mSpeechTime; - Sint32 mPx, mPy; /**< Pixel coordinates */ + int mSpeechTime; + int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set mStatusEffects; /**< set of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 15f683af..83e16f4c 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -67,7 +67,7 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint32 id, Uint16 job) +Being *BeingManager::createBeing(int id, Uint16 job) { Being *being; @@ -99,7 +99,7 @@ void BeingManager::destroyBeing(Being *being) delete being; } -Being* BeingManager::findBeing(Uint32 id) +Being *BeingManager::findBeing(int id) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -111,7 +111,7 @@ Being* BeingManager::findBeing(Uint32 id) return NULL; } -Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) +Being *BeingManager::findBeing(int x, int y, Being::Type type) { beingFinder.x = x; beingFinder.y = y; @@ -122,7 +122,7 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } -Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) +Being *BeingManager::findBeingByPixel(int x, int y) { BeingIterator itr = mBeings.begin(); BeingIterator itr_end = mBeings.end(); @@ -148,7 +148,7 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) return NULL; } -Being* BeingManager::findBeingByName(std::string name, Being::Type type) +Being *BeingManager::findBeingByName(std::string name, Being::Type type) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -161,7 +161,7 @@ Being* BeingManager::findBeingByName(std::string name, Being::Type type) return NULL; } -Beings& BeingManager::getAll() +Beings &BeingManager::getAll() { return mBeings; } @@ -202,7 +202,7 @@ void BeingManager::clear() } } -Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, +Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, Being::Type type) { Being *closestBeing = NULL; @@ -229,7 +229,7 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } -Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, +Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type) { Being *closestBeing = NULL; diff --git a/src/beingmanager.h b/src/beingmanager.h index 02c83725..6c0e0fda 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -49,7 +49,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being *createBeing(Uint32 id, Uint16 job); + Being *createBeing(int id, Uint16 job); /** * Remove a Being. @@ -59,13 +59,13 @@ class BeingManager /** * Return a specific id Being. */ - Being* findBeing(Uint32 id); - Being* findBeingByPixel(Uint16 x, Uint16 y); + Being *findBeing(int id); + Being *findBeingByPixel(int x, int y); /** * Returns a being at specific coordinates. */ - Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to specific coordinates. @@ -76,13 +76,13 @@ class BeingManager * no being is returned. * @param type The type of being to look for. */ - Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being *findNearestLivingBeing(int x, int y, int maxdist, Being::Type type = Being::UNKNOWN); /** * Finds a being by name and (optionally) by type. */ - Being* findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); + Being *findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to another being. @@ -90,7 +90,7 @@ class BeingManager * \param maxdist maximal distance. If minimal distance is larger, * no being is returned */ - Being* findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being *findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type = Being::UNKNOWN); /** diff --git a/src/floor_item.cpp b/src/floor_item.cpp index fbe606b4..000835ad 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -26,10 +26,10 @@ #include "resources/image.h" -FloorItem::FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, +FloorItem::FloorItem(int id, + int itemId, + int x, + int y, Map *map): mId(id), mX(x), @@ -51,7 +51,7 @@ FloorItem::~FloorItem() delete mItem; } -unsigned int FloorItem::getItemId() const +int FloorItem::getItemId() const { return mItem->getId(); } diff --git a/src/floor_item.h b/src/floor_item.h index 444c756a..7ca0f5a3 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -42,10 +42,10 @@ class FloorItem : public Sprite /** * Constructor. */ - FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, + FloorItem(int id, + int itemId, + int x, + int y, Map *map); /** @@ -56,22 +56,22 @@ class FloorItem : public Sprite /** * Returns instance id of this item. */ - unsigned int getId() const { return mId; } + int getId() const { return mId; } /** * Returns the item id. */ - unsigned int getItemId() const; + int getItemId() const; /** * Returns the x coordinate. */ - unsigned short getX() const { return mX; } + int getX() const { return mX; } /** * Returns the y coordinate. */ - unsigned short getY() const { return mY; } + int getY() const { return mY; } /** * Returns the pixel y coordinate. @@ -88,8 +88,8 @@ class FloorItem : public Sprite void draw(Graphics *graphics, int offsetX, int offsetY) const; private: - unsigned int mId; - unsigned short mX, mY; + int mId; + int mX, mY; Item *mItem; Sprites::iterator mSpriteIterator; Map *mMap; diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index 65556abb..65fb2146 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -29,8 +29,8 @@ FloorItemManager::~FloorItemManager() clear(); } -FloorItem* FloorItemManager::create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map) +FloorItem* FloorItemManager::create(int id, int itemId, + int x, int y, Map *map) { FloorItem *floorItem = new FloorItem(id, itemId, x, y, map); mFloorItems.push_back(floorItem); @@ -49,7 +49,7 @@ void FloorItemManager::clear() mFloorItems.clear(); } -FloorItem* FloorItemManager::findById(unsigned int id) +FloorItem *FloorItemManager::findById(int id) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) @@ -63,8 +63,7 @@ FloorItem* FloorItemManager::findById(unsigned int id) return NULL; } -FloorItem* FloorItemManager::findByCoordinates(unsigned short x, - unsigned short y) +FloorItem *FloorItemManager::findByCoordinates(int x, int y) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) diff --git a/src/flooritemmanager.h b/src/flooritemmanager.h index 3f96b587..704b39fd 100644 --- a/src/flooritemmanager.h +++ b/src/flooritemmanager.h @@ -32,15 +32,14 @@ class FloorItemManager public: ~FloorItemManager(); - FloorItem* create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map); + FloorItem* create(int id, int itemId, int x, int y, Map *map); void destroy(FloorItem *item); void clear(); - FloorItem* findById(unsigned int id); - FloorItem* findByCoordinates(unsigned short x, unsigned short y); + FloorItem* findById(int id); + FloorItem* findByCoordinates(int x, int y); private: typedef std::list FloorItems; diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index 2694abd8..0a6877d9 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -22,8 +22,6 @@ #ifndef POPUP_MENU_H #define POPUP_MENU_H -#include // for Uint32 - #include "linkhandler.h" #include "window.h" @@ -68,7 +66,7 @@ class PopupMenu : public Window, public LinkHandler private: BrowserBox* mBrowserBox; - Uint32 mBeingId; + int mBeingId; FloorItem* mFloorItem; Item *mItem; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5b1500ff..18f25257 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -295,7 +295,7 @@ void LocalPlayer::walk(unsigned char dir) return; } - Sint16 dx = 0, dy = 0; + int dx = 0, dy = 0; if (dir & UP) dy--; if (dir & DOWN) diff --git a/src/localplayer.h b/src/localplayer.h index 2226671b..ba6e7670 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -228,8 +228,8 @@ class LocalPlayer : public Player Uint8 mAttr[6]; Uint8 mAttrUp[6]; - Sint16 ATK, MATK, DEF, MDEF, HIT, FLEE; - Sint16 ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; + int ATK, MATK, DEF, MDEF, HIT, FLEE; + int ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; Uint16 mStatPoint, mSkillPoint; Uint16 mStatsPointsToAttribute; diff --git a/src/monster.cpp b/src/monster.cpp index 610da492..2979e9fd 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -33,7 +33,7 @@ static const int NAME_X_OFFSET = 16; static const int NAME_Y_OFFSET = 16; -Monster::Monster(Uint32 id, Uint16 job, Map *map): +Monster::Monster(int id, Uint16 job, Map *map): Being(id, job, map), mText(0) { diff --git a/src/monster.h b/src/monster.h index 8d7f8ae7..ab6f85df 100644 --- a/src/monster.h +++ b/src/monster.h @@ -30,7 +30,7 @@ class Text; class Monster : public Being { public: - Monster(Uint32 id, Uint16 job, Map *map); + Monster(int id, Uint16 job, Map *map); ~Monster(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index b706b088..356d9509 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -69,16 +69,16 @@ BeingHandler::BeingHandler(bool enableSync): void BeingHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; Uint16 job, speed; Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves; Uint16 weapon, shield; Uint16 gmstatus; - Sint16 param1; + int param1; int stunMode; Uint32 statusEffects; - Sint8 type; + int type; Uint16 status; Being *srcBeing, *dstBeing; int hairStyle, hairColor, flag; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 65f8498a..520a1fe6 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -77,10 +77,10 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint32 value = msg->readInt32(); + int value = msg->readInt32(); msg->readInt32(); // DCvalue msg->readInt8(); // type - Sint16 itemId = msg->readInt16(); + int itemId = msg->readInt16(); buyDialog->addItem(itemId, value); } break; @@ -96,8 +96,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint16 index = msg->readInt16(); - Sint32 value = msg->readInt32(); + int index = msg->readInt16(); + int value = msg->readInt32(); msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index a3ccc4fb..8e108142 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -60,7 +60,7 @@ void ChatHandler::handleMessage(MessageIn *msg) Being *being; std::string chatMsg; std::string nick; - Sint16 chatMsgLength; + int chatMsgLength; switch (msg->getId()) { diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index 9a3c396a..a31da38e 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -48,9 +48,9 @@ EquipmentHandler::EquipmentHandler() void EquipmentHandler::handleMessage(MessageIn *msg) { - Sint32 itemCount; - Sint16 index, equipPoint, itemId; - Sint8 type; + int itemCount; + int index, equipPoint, itemId; + int type; int mask, position; Item *item; Inventory *inventory = player_node->getInventory(); diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index a227701e..d78a7a45 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -61,9 +61,9 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(MessageIn *msg) { - Sint32 number; - Sint16 index, amount, itemId, equipType, arrow; - Sint16 identified, cards[4], itemType; + int number; + int index, amount, itemId, equipType, arrow; + int identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); Inventory *storage = player_node->getStorage(); diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index 8c4af4e4..b7ac23a8 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -41,7 +41,7 @@ void ItemHandler::handleMessage(MessageIn *msg) { Uint32 id; Uint16 x, y; - Sint16 itemId; + int itemId; switch (msg->getId()) { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 2ecd4726..487b358f 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -50,7 +50,7 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; switch (msg->getId()) { diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 7790cdd0..d99a97a5 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -164,8 +164,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mY = y; logger->log("Adjust scrolling by %d:%d", - (int)scrollOffsetX, - (int)scrollOffsetY); + (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -173,7 +173,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_1: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); Uint32 value = msg->readInt32(); switch (type) @@ -301,10 +301,10 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_3: { - Sint32 type = msg->readInt32(); - Sint32 base = msg->readInt32(); - Sint32 bonus = msg->readInt32(); - Sint32 total = base + bonus; + int type = msg->readInt32(); + int base = msg->readInt32(); + int bonus = msg->readInt32(); + int total = base + bonus; switch (type) { case 0x000d: player_node->mAttr[LocalPlayer::STR] = total; @@ -325,9 +325,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_4: { - Sint16 type = msg->readInt16(); - Sint8 fail = msg->readInt8(); - Sint8 value = msg->readInt8(); + int type = msg->readInt16(); + int fail = msg->readInt8(); + int value = msg->readInt8(); if (fail != 1) break; @@ -404,7 +404,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_ARROW_MESSAGE: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); switch (type) { case 0: diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index e2185524..526698f4 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -51,14 +51,14 @@ void SkillHandler::handleMessage(MessageIn *msg) for (int k = 0; k < skillCount; k++) { - Sint16 skillId = msg->readInt16(); + int skillId = msg->readInt16(); msg->readInt16(); // target type msg->readInt16(); // unknown - Sint16 level = msg->readInt16(); - Sint16 sp = msg->readInt16(); + int level = msg->readInt16(); + int sp = msg->readInt16(); msg->readInt16(); // range std::string skillName = msg->readString(24); - Sint8 up = msg->readInt8(); + int up = msg->readInt8(); if (level != 0 || up != 0) { diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index c5465835..ab2eba31 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -140,8 +140,8 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD: { - Sint32 amount = msg->readInt32(); - Sint16 type = msg->readInt16(); + int amount = msg->readInt32(); + int type = msg->readInt16(); msg->readInt8(); // identified flag msg->readInt8(); // attribute msg->readInt8(); // refine @@ -166,7 +166,7 @@ void TradeHandler::handleMessage(MessageIn *msg) tradeWindow->receivedOk(true); return; } - Sint16 quantity = msg->readInt16(); + int quantity = msg->readInt16(); switch (msg->readInt8()) { diff --git a/src/npc.cpp b/src/npc.cpp index 7ba25c08..5a4f9507 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -38,7 +38,7 @@ int current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): +NPC::NPC(int id, Uint16 job, Map *map, Network *network): Player(id, job, map), mNetwork(network) { NPCInfo info = NPCDB::get(job); diff --git a/src/npc.h b/src/npc.h index 216fb2fe..63a0b953 100644 --- a/src/npc.h +++ b/src/npc.h @@ -33,7 +33,7 @@ class Text; class NPC : public Player { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(int id, Uint16 job, Map *map, Network *network); ~NPC(); -- cgit v1.2.3-70-g09d2 From 616afb27c23def5661b3466d6fc86fd1c65c0082 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Fri, 6 Mar 2009 00:09:38 +0100 Subject: Microoptimization in compile speed No need to include localplayer.h from inventorywindow.h --- src/gui/inventorywindow.cpp | 1 + src/gui/inventorywindow.h | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index fea86b81..e4896063 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -38,6 +38,7 @@ #include "../inventory.h" #include "../item.h" +#include "../localplayer.h" #include "../units.h" #include "../resources/iteminfo.h" diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index 45796e74..e1196f78 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -22,12 +22,12 @@ #ifndef INVENTORYWINDOW_H #define INVENTORYWINDOW_H -#include -#include - #include "window.h" -#include "../localplayer.h" +#include "../inventory.h" + +#include +#include class Item; class ItemContainer; -- cgit v1.2.3-70-g09d2 From 448d9076137fc5dde666a90820992a34a945cbf7 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 26 Feb 2009 22:22:22 +0100 Subject: Got rid of Sint{8,16,32} and Uint32 for being ID Using unsigned rarely makes sense, especially when the server doesn't use it either. Other uses of unsigned should be reviewed. In all other cases, int is the fastest integer type on any architecture. Using 8 or 16 bits can basically only be a memory optimization. --- src/being.cpp | 2 +- src/being.h | 12 ++++---- src/beingmanager.cpp | 16 +++++------ src/beingmanager.h | 14 +++++----- src/floor_item.cpp | 8 ++---- src/floor_item.h | 18 +++++------- src/flooritemmanager.cpp | 8 ++---- src/flooritemmanager.h | 7 ++--- src/gui/inventorywindow.cpp | 1 + src/gui/inventorywindow.h | 2 +- src/gui/popupmenu.cpp | 66 ++++++++++++++++++++++++++------------------ src/gui/popupmenu.h | 2 +- src/localplayer.cpp | 2 +- src/localplayer.h | 4 +-- src/monster.cpp | 2 +- src/monster.h | 2 +- src/net/beinghandler.cpp | 6 ++-- src/net/buysellhandler.cpp | 8 +++--- src/net/chathandler.cpp | 2 +- src/net/equipmenthandler.cpp | 6 ++-- src/net/inventoryhandler.cpp | 6 ++-- src/net/itemhandler.cpp | 2 +- src/net/npchandler.cpp | 2 +- src/net/playerhandler.cpp | 22 +++++++-------- src/net/skillhandler.cpp | 8 +++--- src/net/tradehandler.cpp | 6 ++-- src/npc.cpp | 4 +-- src/npc.h | 6 ++-- 28 files changed, 122 insertions(+), 122 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index cebf6d1c..312904ad 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -179,7 +179,7 @@ void Being::setSprite(int slot, int id, std::string color) mSpriteColors[slot] = color; } -void Being::setSpeech(const std::string &text, Uint32 time) +void Being::setSpeech(const std::string &text, int time) { mSpeech = text; diff --git a/src/being.h b/src/being.h index 7fd0c7ef..49f95662 100644 --- a/src/being.h +++ b/src/being.h @@ -165,7 +165,7 @@ class Being : public Sprite * @param text The text that should appear. * @param time The amount of time the text should stay in milliseconds. */ - void setSpeech(const std::string &text, Uint32 time = 500); + void setSpeech(const std::string &text, int time = 500); /** * Puts a damage bubble above this being. @@ -282,12 +282,12 @@ class Being : public Sprite /** * Gets the sprite id. */ - Uint32 getId() const { return mId; } + int getId() const { return mId; } /** * Sets the sprite id. */ - void setId(Uint32 id) { mId = id; } + void setId(int id) { mId = id; } /** * Sets the map the being is on @@ -416,7 +416,7 @@ class Being : public Sprite */ void internalTriggerEffect(int effectId, bool sfx, bool gfx); - Uint32 mId; /**< Unique sprite id */ + int mId; /**< Unique sprite id */ Uint16 mWalkSpeed; /**< Walking speed */ Uint8 mDirection; /**< Facing direction */ Map *mMap; /**< Map on which this being resides */ @@ -437,8 +437,8 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - Uint32 mSpeechTime; - Sint32 mPx, mPy; /**< Pixel coordinates */ + int mSpeechTime; + int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ StatusEffects mStatusEffects; /**< Bitset of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index d6d71a91..0cf783d8 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -65,7 +65,7 @@ void BeingManager::setPlayer(LocalPlayer *player) mBeings.push_back(player); } -Being* BeingManager::createBeing(Uint32 id, Uint16 job) +Being *BeingManager::createBeing(int id, Uint16 job) { Being *being; @@ -97,7 +97,7 @@ void BeingManager::destroyBeing(Being *being) delete being; } -Being* BeingManager::findBeing(Uint32 id) +Being *BeingManager::findBeing(int id) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -109,7 +109,7 @@ Being* BeingManager::findBeing(Uint32 id) return NULL; } -Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) +Being *BeingManager::findBeing(int x, int y, Being::Type type) { beingFinder.x = x; beingFinder.y = y; @@ -120,7 +120,7 @@ Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type) return (i == mBeings.end()) ? NULL : *i; } -Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) +Being *BeingManager::findBeingByPixel(int x, int y) { BeingIterator itr = mBeings.begin(); BeingIterator itr_end = mBeings.end(); @@ -146,7 +146,7 @@ Being* BeingManager::findBeingByPixel(Uint16 x, Uint16 y) return NULL; } -Being* BeingManager::findBeingByName(std::string name, Being::Type type) +Being *BeingManager::findBeingByName(std::string name, Being::Type type) { for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { @@ -159,7 +159,7 @@ Being* BeingManager::findBeingByName(std::string name, Being::Type type) return NULL; } -Beings& BeingManager::getAll() +Beings &BeingManager::getAll() { return mBeings; } @@ -200,7 +200,7 @@ void BeingManager::clear() } } -Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, +Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, Being::Type type) { Being *closestBeing = NULL; @@ -227,7 +227,7 @@ Being* BeingManager::findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, return (maxdist >= dist) ? closestBeing : NULL; } -Being* BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, +Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type) { Being *closestBeing = NULL; diff --git a/src/beingmanager.h b/src/beingmanager.h index 32ba6242..472e2c83 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -50,7 +50,7 @@ class BeingManager /** * Create a being and add it to the list of beings. */ - Being *createBeing(Uint32 id, Uint16 job); + Being *createBeing(int id, Uint16 job); /** * Remove a Being. @@ -60,13 +60,13 @@ class BeingManager /** * Return a specific id Being. */ - Being* findBeing(Uint32 id); - Being* findBeingByPixel(Uint16 x, Uint16 y); + Being *findBeing(int id); + Being *findBeingByPixel(int x, int y); /** * Returns a being at specific coordinates. */ - Being* findBeing(Uint16 x, Uint16 y, Being::Type type = Being::UNKNOWN); + Being *findBeing(int x, int y, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to specific coordinates. @@ -77,13 +77,13 @@ class BeingManager * no being is returned. * @param type The type of being to look for. */ - Being* findNearestLivingBeing(Uint16 x, Uint16 y, int maxdist, + Being *findNearestLivingBeing(int x, int y, int maxdist, Being::Type type = Being::UNKNOWN); /** * Finds a being by name and (optionally) by type. */ - Being* findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); + Being *findBeingByName(std::string name, Being::Type type = Being::UNKNOWN); /** * Returns a being nearest to another being. @@ -91,7 +91,7 @@ class BeingManager * \param maxdist maximal distance. If minimal distance is larger, * no being is returned */ - Being* findNearestLivingBeing(Being *aroundBeing, int maxdist, + Being *findNearestLivingBeing(Being *aroundBeing, int maxdist, Being::Type type = Being::UNKNOWN); /** diff --git a/src/floor_item.cpp b/src/floor_item.cpp index 232c1aee..82506f8f 100644 --- a/src/floor_item.cpp +++ b/src/floor_item.cpp @@ -27,11 +27,7 @@ #include "resources/image.h" -FloorItem::FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, - Map *map): +FloorItem::FloorItem(int id, int itemId, int x, int y, Map *map): mId(id), mX(x), mY(y), @@ -52,7 +48,7 @@ FloorItem::~FloorItem() delete mItem; } -unsigned int FloorItem::getItemId() const +int FloorItem::getItemId() const { return mItem->getId(); } diff --git a/src/floor_item.h b/src/floor_item.h index 8485172c..0972a983 100644 --- a/src/floor_item.h +++ b/src/floor_item.h @@ -43,11 +43,7 @@ class FloorItem : public Sprite /** * Constructor. */ - FloorItem(unsigned int id, - unsigned int itemId, - unsigned short x, - unsigned short y, - Map *map); + FloorItem(int id, int itemId, int x, int y, Map *map); /** * Destructor. @@ -57,22 +53,22 @@ class FloorItem : public Sprite /** * Returns instance id of this item. */ - unsigned int getId() const { return mId; } + int getId() const { return mId; } /** * Returns the item id. */ - unsigned int getItemId() const; + int getItemId() const; /** * Returns the x coordinate. */ - unsigned short getX() const { return mX; } + int getX() const { return mX; } /** * Returns the y coordinate. */ - unsigned short getY() const { return mY; } + int getY() const { return mY; } /** * Returns the pixel y coordinate. @@ -89,8 +85,8 @@ class FloorItem : public Sprite void draw(Graphics *graphics, int offsetX, int offsetY) const; private: - unsigned int mId; - unsigned short mX, mY; + int mId; + int mX, mY; Item *mItem; Sprites::iterator mSpriteIterator; Map *mMap; diff --git a/src/flooritemmanager.cpp b/src/flooritemmanager.cpp index dbb93526..97b3ca5b 100644 --- a/src/flooritemmanager.cpp +++ b/src/flooritemmanager.cpp @@ -30,8 +30,7 @@ FloorItemManager::~FloorItemManager() clear(); } -FloorItem* FloorItemManager::create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map) +FloorItem* FloorItemManager::create(int id, int itemId, int x, int y, Map *map) { FloorItem *floorItem = new FloorItem(id, itemId, x, y, map); mFloorItems.push_back(floorItem); @@ -50,7 +49,7 @@ void FloorItemManager::clear() mFloorItems.clear(); } -FloorItem* FloorItemManager::findById(unsigned int id) +FloorItem *FloorItemManager::findById(int id) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) @@ -64,8 +63,7 @@ FloorItem* FloorItemManager::findById(unsigned int id) return NULL; } -FloorItem* FloorItemManager::findByCoordinates(unsigned short x, - unsigned short y) +FloorItem *FloorItemManager::findByCoordinates(int x, int y) { FloorItemIterator i; for (i = mFloorItems.begin(); i != mFloorItems.end(); i++) diff --git a/src/flooritemmanager.h b/src/flooritemmanager.h index 5ff8fe5c..1a6e8e0a 100644 --- a/src/flooritemmanager.h +++ b/src/flooritemmanager.h @@ -33,15 +33,14 @@ class FloorItemManager public: ~FloorItemManager(); - FloorItem* create(unsigned int id, unsigned int itemId, - unsigned short x, unsigned short y, Map *map); + FloorItem* create(int id, int itemId, int x, int y, Map *map); void destroy(FloorItem *item); void clear(); - FloorItem* findById(unsigned int id); - FloorItem* findByCoordinates(unsigned short x, unsigned short y); + FloorItem* findById(int id); + FloorItem* findByCoordinates(int x, int y); private: typedef std::list FloorItems; diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index e8457337..347c36ac 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -39,6 +39,7 @@ #include "../inventory.h" #include "../item.h" +#include "../localplayer.h" #include "../resources/iteminfo.h" diff --git a/src/gui/inventorywindow.h b/src/gui/inventorywindow.h index a46a3fbb..83e98687 100644 --- a/src/gui/inventorywindow.h +++ b/src/gui/inventorywindow.h @@ -28,7 +28,7 @@ #include "window.h" -#include "../localplayer.h" +#include "../inventory.h" class Item; class ItemContainer; diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 7f82d1b5..ebaba977 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -30,6 +30,7 @@ #include "windowcontainer.h" #include "../being.h" +#include "../beingmanager.h" #include "../floor_item.h" #include "../item.h" #include "../localplayer.h" @@ -48,7 +49,7 @@ extern std::string tradePartnerName; PopupMenu::PopupMenu(): Window(), - mBeing(NULL), + mBeingId(0), mFloorItem(NULL), mItem(NULL) { @@ -66,16 +67,16 @@ PopupMenu::PopupMenu(): void PopupMenu::showPopup(int x, int y, Being *being) { - mBeing = being; + mBeingId = being->getId(); mBrowserBox->clearRows(); - switch (mBeing->getType()) + switch (being->getType()) { case Being::PLAYER: { - // Players can be traded with. Later also attack, follow and + // Players can be traded with. Later also follow and // add as buddy will be options in this menu. - const std::string &name = mBeing->getName(); + const std::string &name = being->getName(); mBrowserBox->addRow(strprintf(_("@@trade|Trade With %s@@"), name.c_str())); mBrowserBox->addRow(strprintf(_("@@attack|Attack %s@@"), name.c_str())); @@ -144,45 +145,56 @@ void PopupMenu::showPopup(int x, int y, FloorItem *floorItem) void PopupMenu::handleLink(const std::string& link) { + Being *being = beingManager->findBeing(mBeingId); + + if (!being) + { + mBeingId = 0; + mFloorItem = NULL; + mItem = NULL; + setVisible(false); + return; + } + // Talk To action - if (link == "talk" && mBeing && mBeing->getType() == Being::NPC && + if (link == "talk" && being && being->getType() == Being::NPC && current_npc == 0) { - dynamic_cast(mBeing)->talk(); + dynamic_cast(being)->talk(); } // Trade action - else if (link == "trade" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "trade" && being && being->getType() == Being::PLAYER) { - player_node->trade(mBeing); - tradePartnerName = mBeing->getName(); + player_node->trade(being); + tradePartnerName = being->getName(); } // Attack action - else if (link == "attack" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "attack" && being && being->getType() == Being::PLAYER) { - player_node->attack(mBeing, true); + player_node->attack(being, true); } - else if (link == "unignore" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "unignore" && being && being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::NEUTRAL); + player_relations.setRelation(being->getName(), PlayerRelation::NEUTRAL); } - else if (link == "ignore" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "ignore" && being && being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::IGNORED); + player_relations.setRelation(being->getName(), PlayerRelation::IGNORED); } - else if (link == "disregard" && mBeing && - mBeing->getType() == Being::PLAYER) + else if (link == "disregard" && being && + being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::DISREGARDED); + player_relations.setRelation(being->getName(), PlayerRelation::DISREGARDED); } - else if (link == "friend" && mBeing && mBeing->getType() == Being::PLAYER) + else if (link == "friend" && being && being->getType() == Being::PLAYER) { - player_relations.setRelation(mBeing->getName(), PlayerRelation::FRIEND); + player_relations.setRelation(being->getName(), PlayerRelation::FRIEND); } /* @@ -193,12 +205,12 @@ void PopupMenu::handleLink(const std::string& link) /* // Add Buddy action - else if ((link == "buddy") && mBeing && mBeing->isPlayer()) + else if ((link == "buddy") && being && being->isPlayer()) { if (!buddyWindow->isVisible()) buddyWindow->setVisible(true); - buddyWindow->addBuddy(mBeing->getName()); + buddyWindow->addBuddy(being->getName()); }*/ // Pick Up Floor Item action @@ -241,12 +253,12 @@ void PopupMenu::handleLink(const std::string& link) { new ItemAmountWindow(AMOUNT_ITEM_DROP, inventoryWindow, mItem); } - else if (link == "party-invite" && mBeing && - mBeing->getType() == Being::PLAYER) + else if (link == "party-invite" && being && + being->getType() == Being::PLAYER) { MessageOut outMsg(player_node->getNetwork()); outMsg.writeInt16(CMSG_PARTY_INVITE); - outMsg.writeInt32(mBeing->getId()); + outMsg.writeInt32(being->getId()); } // Unknown actions @@ -257,7 +269,7 @@ void PopupMenu::handleLink(const std::string& link) setVisible(false); - mBeing = NULL; + mBeingId = 0; mFloorItem = NULL; mItem = NULL; } diff --git a/src/gui/popupmenu.h b/src/gui/popupmenu.h index c62014f9..89152751 100644 --- a/src/gui/popupmenu.h +++ b/src/gui/popupmenu.h @@ -67,7 +67,7 @@ class PopupMenu : public Window, public LinkHandler private: BrowserBox* mBrowserBox; - Being* mBeing; + int mBeingId; FloorItem* mFloorItem; Item *mItem; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 2607b460..76d13a4b 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -318,7 +318,7 @@ void LocalPlayer::walk(unsigned char dir) return; } - Sint16 dx = 0, dy = 0; + int dx = 0, dy = 0; if (dir & UP) dy--; if (dir & DOWN) diff --git a/src/localplayer.h b/src/localplayer.h index 0ae99bb0..2fb8c615 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -228,8 +228,8 @@ class LocalPlayer : public Player Uint8 mAttr[6]; Uint8 mAttrUp[6]; - Sint16 ATK, MATK, DEF, MDEF, HIT, FLEE; - Sint16 ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; + int ATK, MATK, DEF, MDEF, HIT, FLEE; + int ATK_BONUS, MATK_BONUS, DEF_BONUS, MDEF_BONUS, FLEE_BONUS; Uint16 mStatPoint, mSkillPoint; Uint16 mStatsPointsToAttribute; diff --git a/src/monster.cpp b/src/monster.cpp index f5687ef6..61c867e9 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -34,7 +34,7 @@ static const int NAME_X_OFFSET = 16; static const int NAME_Y_OFFSET = 16; -Monster::Monster(Uint32 id, Uint16 job, Map *map): +Monster::Monster(int id, Uint16 job, Map *map): Being(id, job, map), mText(0) { diff --git a/src/monster.h b/src/monster.h index 776a215b..12297373 100644 --- a/src/monster.h +++ b/src/monster.h @@ -31,7 +31,7 @@ class Text; class Monster : public Being { public: - Monster(Uint32 id, Uint16 job, Map *map); + Monster(int id, Uint16 job, Map *map); ~Monster(); diff --git a/src/net/beinghandler.cpp b/src/net/beinghandler.cpp index 71369031..4ff303ab 100644 --- a/src/net/beinghandler.cpp +++ b/src/net/beinghandler.cpp @@ -65,14 +65,14 @@ BeingHandler::BeingHandler(bool enableSync): void BeingHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; Uint16 job, speed; Uint16 headTop, headMid, headBottom; Uint16 shoes, gloves, cape, misc1, misc2; Uint16 weapon, shield; Uint16 gmstatus; - Sint16 param1; - Sint8 type; + int param1; + int type; Being *srcBeing, *dstBeing; int hairStyle, hairColor; diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index e9255540..5b8f0b68 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -78,10 +78,10 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint32 value = msg->readInt32(); + int value = msg->readInt32(); msg->readInt32(); // DCvalue msg->readInt8(); // type - Sint16 itemId = msg->readInt16(); + int itemId = msg->readInt16(); buyDialog->addItem(itemId, value); } break; @@ -97,8 +97,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) for (int k = 0; k < n_items; k++) { - Sint16 index = msg->readInt16(); - Sint32 value = msg->readInt32(); + int index = msg->readInt16(); + int value = msg->readInt32(); msg->readInt32(); // OCvalue Item *item = player_node->getInventory()->getItem(index); diff --git a/src/net/chathandler.cpp b/src/net/chathandler.cpp index 6717f515..185ce7d8 100644 --- a/src/net/chathandler.cpp +++ b/src/net/chathandler.cpp @@ -61,7 +61,7 @@ void ChatHandler::handleMessage(MessageIn *msg) Being *being; std::string chatMsg; std::string nick; - Sint16 chatMsgLength; + int chatMsgLength; switch (msg->getId()) { diff --git a/src/net/equipmenthandler.cpp b/src/net/equipmenthandler.cpp index fe158198..9a6f424e 100644 --- a/src/net/equipmenthandler.cpp +++ b/src/net/equipmenthandler.cpp @@ -49,9 +49,9 @@ EquipmentHandler::EquipmentHandler() void EquipmentHandler::handleMessage(MessageIn *msg) { - Sint32 itemCount; - Sint16 index, equipPoint, itemId; - Sint8 type; + int itemCount; + int index, equipPoint, itemId; + int type; int mask, position; Item *item; Inventory *inventory = player_node->getInventory(); diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index be128609..b0511080 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -62,9 +62,9 @@ InventoryHandler::InventoryHandler() void InventoryHandler::handleMessage(MessageIn *msg) { - Sint32 number; - Sint16 index, amount, itemId, equipType, arrow; - Sint16 identified, cards[4], itemType; + int number; + int index, amount, itemId, equipType, arrow; + int identified, cards[4], itemType; Inventory *inventory = player_node->getInventory(); Inventory *storage = player_node->getStorage(); diff --git a/src/net/itemhandler.cpp b/src/net/itemhandler.cpp index e38be454..d9d84248 100644 --- a/src/net/itemhandler.cpp +++ b/src/net/itemhandler.cpp @@ -42,7 +42,7 @@ void ItemHandler::handleMessage(MessageIn *msg) { Uint32 id; Uint16 x, y; - Sint16 itemId; + int itemId; switch (msg->getId()) { diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 1067a57e..1161bc36 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -51,7 +51,7 @@ NPCHandler::NPCHandler() void NPCHandler::handleMessage(MessageIn *msg) { - Uint32 id; + int id; switch (msg->getId()) { diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index ffeb3fab..232cf075 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -166,8 +166,8 @@ void PlayerHandler::handleMessage(MessageIn *msg) player_node->mY = y; logger->log("Adjust scrolling by %d:%d", - (int)scrollOffsetX, - (int)scrollOffsetY); + (int) scrollOffsetX, + (int) scrollOffsetY); viewport->scrollBy(scrollOffsetX, scrollOffsetY); } @@ -175,7 +175,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_1: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); Uint32 value = msg->readInt32(); switch (type) @@ -303,10 +303,10 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_3: { - Sint32 type = msg->readInt32(); - Sint32 base = msg->readInt32(); - Sint32 bonus = msg->readInt32(); - Sint32 total = base + bonus; + int type = msg->readInt32(); + int base = msg->readInt32(); + int bonus = msg->readInt32(); + int total = base + bonus; switch (type) { case 0x000d: player_node->mAttr[LocalPlayer::STR] = total; @@ -327,9 +327,9 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STAT_UPDATE_4: { - Sint16 type = msg->readInt16(); - Sint8 fail = msg->readInt8(); - Sint8 value = msg->readInt8(); + int type = msg->readInt16(); + int fail = msg->readInt8(); + int value = msg->readInt8(); if (fail != 1) break; @@ -406,7 +406,7 @@ void PlayerHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_ARROW_MESSAGE: { - Sint16 type = msg->readInt16(); + int type = msg->readInt16(); switch (type) { case 0: diff --git a/src/net/skillhandler.cpp b/src/net/skillhandler.cpp index 8ef37101..be757d7c 100644 --- a/src/net/skillhandler.cpp +++ b/src/net/skillhandler.cpp @@ -52,14 +52,14 @@ void SkillHandler::handleMessage(MessageIn *msg) for (int k = 0; k < skillCount; k++) { - Sint16 skillId = msg->readInt16(); + int skillId = msg->readInt16(); msg->readInt16(); // target type msg->readInt16(); // unknown - Sint16 level = msg->readInt16(); - Sint16 sp = msg->readInt16(); + int level = msg->readInt16(); + int sp = msg->readInt16(); msg->readInt16(); // range std::string skillName = msg->readString(24); - Sint8 up = msg->readInt8(); + int up = msg->readInt8(); if (level != 0 || up != 0) { diff --git a/src/net/tradehandler.cpp b/src/net/tradehandler.cpp index 98f26cbd..fd772d01 100644 --- a/src/net/tradehandler.cpp +++ b/src/net/tradehandler.cpp @@ -141,8 +141,8 @@ void TradeHandler::handleMessage(MessageIn *msg) case SMSG_TRADE_ITEM_ADD: { - Sint32 amount = msg->readInt32(); - Sint16 type = msg->readInt16(); + int amount = msg->readInt32(); + int type = msg->readInt16(); msg->readInt8(); // identified flag msg->readInt8(); // attribute msg->readInt8(); // refine @@ -167,7 +167,7 @@ void TradeHandler::handleMessage(MessageIn *msg) tradeWindow->receivedOk(true); return; } - Sint16 quantity = msg->readInt16(); + int quantity = msg->readInt16(); switch (msg->readInt8()) { diff --git a/src/npc.cpp b/src/npc.cpp index 92ef4d82..c9250415 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -34,12 +34,12 @@ #include "resources/npcdb.h" bool NPC::mTalking = false; -Uint32 current_npc = 0; +int current_npc = 0; static const int NAME_X_OFFSET = 15; static const int NAME_Y_OFFSET = 30; -NPC::NPC(Uint32 id, Uint16 job, Map *map, Network *network): +NPC::NPC(int id, Uint16 job, Map *map, Network *network): Player(id, job, map), mNetwork(network) { NPCInfo info = NPCDB::get(job); diff --git a/src/npc.h b/src/npc.h index e1bf9737..137cd5f5 100644 --- a/src/npc.h +++ b/src/npc.h @@ -23,8 +23,6 @@ #ifndef NPC_H #define NPC_H -#include - #include "player.h" class Network; @@ -34,7 +32,7 @@ class Text; class NPC : public Player { public: - NPC(Uint32 id, Uint16 job, Map *map, Network *network); + NPC(int id, Uint16 job, Map *map, Network *network); ~NPC(); @@ -55,6 +53,6 @@ class NPC : public Player Text *mName; }; -extern Uint32 current_npc; +extern int current_npc; #endif -- cgit v1.2.3-70-g09d2 From 93e45964f3b7a0735984616f622ec32b40a21781 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 5 Mar 2009 18:35:35 -0700 Subject: Removed a check I added in the previous commit which isn't necessary. Signed-off-by: Ira Rice --- src/gui/popupmenu.cpp | 9 --------- 1 file changed, 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index ebaba977..cead20ed 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -147,15 +147,6 @@ void PopupMenu::handleLink(const std::string& link) { Being *being = beingManager->findBeing(mBeingId); - if (!being) - { - mBeingId = 0; - mFloorItem = NULL; - mItem = NULL; - setVisible(false); - return; - } - // Talk To action if (link == "talk" && being && being->getType() == Being::NPC && current_npc == 0) -- cgit v1.2.3-70-g09d2 From aa4229cbb9f2b264ca96c3beedc66b1c79ccc1f5 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 5 Mar 2009 23:13:55 -0700 Subject: Made some optimizations based on some profiling done by Octalot, as well as some other optimizations that I could see that cut down on some unneeded redraws, which in turn improved frame rates slightly. Signed-off-by: Ira Rice --- src/being.cpp | 61 +++++++++++-------------------- src/being.h | 18 +++++----- src/beingmanager.cpp | 15 +++----- src/gui/browserbox.cpp | 3 ++ src/gui/confirm_dialog.cpp | 18 +++++----- src/gui/debugwindow.cpp | 27 ++++++-------- src/gui/emotecontainer.cpp | 5 +-- src/gui/emoteshortcutcontainer.cpp | 34 ++++++++---------- src/gui/equipmentwindow.cpp | 3 ++ src/gui/inventorywindow.cpp | 3 ++ src/gui/itemcontainer.cpp | 40 +++++++++------------ src/gui/itemlinkhandler.cpp | 8 ++--- src/gui/itempopup.cpp | 3 ++ src/gui/itemshortcutcontainer.cpp | 73 ++++++++++++++++++-------------------- src/gui/listbox.cpp | 2 +- src/gui/menuwindow.cpp | 1 - src/gui/minimap.cpp | 3 ++ src/gui/ok_dialog.cpp | 15 ++++---- src/gui/playerbox.cpp | 3 ++ src/gui/progressbar.h | 1 + src/gui/radiobutton.cpp | 3 ++ src/gui/scrollarea.cpp | 6 ++++ src/gui/shoplistbox.cpp | 2 +- src/gui/shortcutcontainer.cpp | 32 +++++++---------- src/gui/speechbubble.cpp | 10 ++++-- src/gui/speechbubble.h | 3 +- src/gui/status.cpp | 3 ++ src/gui/table.cpp | 2 +- src/gui/textfield.cpp | 6 +++- src/gui/trade.cpp | 1 - src/gui/viewport.cpp | 35 ++++++++---------- src/gui/viewport.h | 24 +++++++++---- src/gui/widgets/dropdown.cpp | 22 ++++++------ src/gui/widgets/tab.cpp | 8 +++-- src/gui/widgets/tabbedarea.cpp | 17 ++------- src/gui/window.cpp | 3 ++ 36 files changed, 248 insertions(+), 265 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index 312904ad..c31dae6d 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -70,6 +70,7 @@ Being::Being(int id, int job, Map *map): mAction(STAND), mWalkTime(0), mEmotion(0), mEmotionTime(0), + mSpeechTime(0), mAttackSpeed(350), mId(id), mWalkSpeed(150), @@ -81,7 +82,6 @@ Being::Being(int id, int job, Map *map): mEquippedWeapon(NULL), mHairStyle(1), mHairColor(0), mGender(GENDER_UNSPECIFIED), - mSpeechTime(0), mPx(0), mPy(0), mSprites(VECTOREND_SPRITE, NULL), mSpriteIDs(VECTOREND_SPRITE, 0), @@ -136,9 +136,7 @@ Being::~Being() instances--; if (instances == 0) - { delete_all(emotionSet); - } delete mSpeechBubble; delete mText; @@ -328,13 +326,10 @@ void Being::setAction(Action action) break; case ATTACK: if (mEquippedWeapon) - { currentAction = mEquippedWeapon->getAttackType(); - } else - { currentAction = ACTION_ATTACK; - } + for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i]) @@ -385,21 +380,13 @@ SpriteDirection Being::getSpriteDirection() const SpriteDirection dir; if (mDirection & UP) - { dir = DIRECTION_UP; - } else if (mDirection & DOWN) - { dir = DIRECTION_DOWN; - } else if (mDirection & RIGHT) - { dir = DIRECTION_RIGHT; - } else - { - dir = DIRECTION_LEFT; - } + dir = DIRECTION_LEFT; return dir; } @@ -445,7 +432,7 @@ void Being::logic() if (mSpeechTime > 0) mSpeechTime--; - // Remove text if speech boxes aren't being used + // Remove text and speechbubbles if speech boxes aren't being used if (mSpeechTime == 0 && mText) { delete mText; @@ -482,9 +469,7 @@ void Being::logic() } // Update particle effects - mChildParticleEffects.moveTo((float) mPx + 16.0f, - (float) mPy + 32.0f); - + mChildParticleEffects.moveTo((float) mPx + 16.0f, (float) mPy + 32.0f); } void Being::draw(Graphics *graphics, int offsetX, int offsetY) const @@ -493,16 +478,12 @@ void Being::draw(Graphics *graphics, int offsetX, int offsetY) const int py = mPy + offsetY; if (mUsedTargetCursor != NULL) - { mUsedTargetCursor->draw(graphics, px, py); - } for (int i = 0; i < VECTOREND_SPRITE; i++) { if (mSprites[i]) - { mSprites[i]->draw(graphics, px, py); - } } } @@ -511,8 +492,8 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) if (!mEmotion) return; - const int px = mPx + offsetX + 3; - const int py = mPy + offsetY - 60; + const int px = mPx - offsetX; + const int py = mPy - offsetY - 64; const int emotionIndex = mEmotion - 1; if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast()) @@ -521,20 +502,25 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) void Being::drawSpeech(int offsetX, int offsetY) { - const int px = mPx + offsetX; - const int py = mPy + offsetY; + const int px = mPx - offsetX; + const int py = mPy - offsetY; const int speech = (int) config.getValue("speech", NAME_IN_BUBBLE); // Draw speech above this being - if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE || - speech == NO_NAME_IN_BUBBLE)) + if (mSpeechTime == 0) + { + if (mSpeechBubble->isVisible()) + mSpeechBubble->setVisible(false); + } + else if (mSpeechTime > 0 && (speech == NAME_IN_BUBBLE || + speech == NO_NAME_IN_BUBBLE)) { const bool showName = (speech == NAME_IN_BUBBLE); if (mText) { delete mText; - mText = 0; + mText = NULL; } mSpeechBubble->setCaption(showName ? mName : "", mNameColor); @@ -550,6 +536,7 @@ void Being::drawSpeech(int offsetX, int offsetY) else if (mSpeechTime > 0 && speech == TEXT_OVERHEAD) { mSpeechBubble->setVisible(false); + // don't introduce a memory leak if (mText) delete mText; @@ -560,14 +547,12 @@ void Being::drawSpeech(int offsetX, int offsetY) else if (speech == NO_SPEECH) { mSpeechBubble->setVisible(false); + if (mText) delete mText; + mText = NULL; } - else if (mSpeechTime == 0) - { - mSpeechBubble->setVisible(false); - } } Being::Type Being::getType() const @@ -579,24 +564,18 @@ int Being::getOffset(char pos, char neg) const { // Check whether we're walking in the requested direction if (mAction != WALK || !(mDirection & (pos | neg))) - { return 0; - } int offset = (get_elapsed_time(mWalkTime) * 32) / mWalkSpeed; // We calculate the offset _from_ the _target_ location offset -= 32; if (offset > 0) - { offset = 0; - } // Going into negative direction? Invert the offset. if (mDirection & pos) - { offset = -offset; - } return offset; } diff --git a/src/being.h b/src/being.h index 49f95662..9b3bbde4 100644 --- a/src/being.h +++ b/src/being.h @@ -128,15 +128,16 @@ class Being : public Sprite */ enum { DOWN = 1, LEFT = 2, UP = 4, RIGHT = 8 }; - Uint16 mJob; /**< Job (player job, npc, monster, ) */ - Uint16 mX, mY; /**< Tile coordinates */ - Action mAction; /**< Action the being is performing */ - Uint16 mFrame; - Uint16 mWalkTime; - Uint8 mEmotion; /**< Currently showing emotion */ - Uint8 mEmotionTime; /**< Time until emotion disappears */ + Uint16 mJob; /**< Job (player job, npc, monster, ) */ + Uint16 mX, mY; /**< Tile coordinates */ + Action mAction; /**< Action the being is performing */ + int mFrame; + int mWalkTime; + int mEmotion; /**< Currently showing emotion */ + int mEmotionTime; /**< Time until emotion disappears */ + int mSpeechTime; - Uint16 mAttackSpeed; /**< Attack speed */ + int mAttackSpeed; /**< Attack speed */ /** * Constructor. @@ -437,7 +438,6 @@ class Being : public Sprite Text *mText; Uint16 mHairStyle, mHairColor; Gender mGender; - int mSpeechTime; int mPx, mPy; /**< Pixel coordinates */ Uint16 mStunMode; /**< Stun mode; zero if not stunned */ StatusEffects mStatusEffects; /**< Bitset of active status effects */ diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0cf783d8..0c7a310a 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -151,9 +151,8 @@ Being *BeingManager::findBeingByName(std::string name, Being::Type type) for (BeingIterator i = mBeings.begin(); i != mBeings.end(); i++) { Being *being = (*i); - if (being->getName() == name - && (type == Being::UNKNOWN - || type == being->getType())) + if (being->getName() == name && + (type == Being::UNKNOWN || type == being->getType())) return being; } return NULL; @@ -187,17 +186,13 @@ void BeingManager::logic() void BeingManager::clear() { if (player_node) - { mBeings.remove(player_node); - } delete_all(mBeings); mBeings.clear(); if (player_node) - { mBeings.push_back(player_node); - } } Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, @@ -216,8 +211,7 @@ Being *BeingManager::findNearestLivingBeing(int x, int y, int maxdist, if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer - && being->mAction != Being::DEAD // no dead beings - ) + && being->mAction != Being::DEAD) // no dead beings { dist = d; closestBeing = being; @@ -243,8 +237,7 @@ Being *BeingManager::findNearestLivingBeing(Being *aroundBeing, int maxdist, if ((being->getType() == type || type == Being::UNKNOWN) && (d < dist || closestBeing == NULL) // it is closer && being->mAction != Being::DEAD // no dead beings - && being != aroundBeing - ) + && being != aroundBeing) { dist = d; closestBeing = being; diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 18fa2ad4..b8f58dbb 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -244,6 +244,9 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event) void BrowserBox::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + if (mOpaque) { graphics->setColor(gcn::Color(BGCOLOR)); diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2287a195..2bc330c0 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -24,6 +24,7 @@ #include "button.h" #include "confirm_dialog.h" +#include "gui.h" #include "scrollarea.h" #include "textbox.h" @@ -50,14 +51,16 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, int numRows = mTextBox->getNumberOfRows(); int width = getFont()->getWidth(title); int inWidth = yesButton->getWidth() + noButton->getWidth() + 5; + const int fontHeight = getFont()->getHeight(); if (numRows > 1) { - // 15 == height of each line of text (based on font heights) + // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15) + noButton->getHeight()); + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * 14))); + 3 + (numRows * fontHeight))); } else { @@ -65,16 +68,17 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + 15, 30 + noButton->getHeight()); + setContentSize(width + fontHeight, (2 * fontHeight) + + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } yesButton->setPosition( (mTextBox->getMinWidth() - inWidth) / 2, - (numRows * 14) + noButton->getHeight() - 8); + ((numRows - 1) * fontHeight) + noButton->getHeight() + 2); noButton->setPosition( yesButton->getX() + yesButton->getWidth() + 5, - (numRows * 14) + noButton->getHeight() - 8); + ((numRows - 1) * fontHeight) + noButton->getHeight() + 2); add(mTextArea); add(yesButton); @@ -105,7 +109,5 @@ void ConfirmDialog::action(const gcn::ActionEvent &event) // Can we receive anything else anyway? if (event.getId() == "yes" || event.getId() == "no") - { scheduleDelete(); - } } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 68b70817..1e199314 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include #include "debugwindow.h" @@ -55,28 +53,27 @@ DebugWindow::DebugWindow(): place(0, 0, mFPSLabel); place(3, 0, mTileMouseLabel); - place(0, 1, mMusicFileLabel, 2); + place(0, 1, mMusicFileLabel, 3); place(3, 1, mParticleCountLabel); - place(0, 2, mMapLabel, 2); - place(0, 3, mMiniMapLabel, 2); + place(0, 2, mMapLabel, 4); + place(0, 3, mMiniMapLabel, 4); reflowLayout(375, 0); } void DebugWindow::logic() { + if (!isVisible()) + return; + // Get the current mouse position - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - int mouseTileX = (mouseX + viewport->getCameraX()) / 32; - int mouseTileY = (mouseY + viewport->getCameraY()) / 32; + int mouseTileX = (viewport->getMouseX() + viewport->getCameraX()) / 32; + int mouseTileY = (viewport->getMouseY() + viewport->getCameraY()) / 32; mFPSLabel->setCaption(toString(fps) + " FPS"); - mFPSLabel->adjustSize(); - mTileMouseLabel->setCaption("Mouse: " + - toString(mouseTileX) + ", " + toString(mouseTileY)); - mTileMouseLabel->adjustSize(); + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); if (currentMap) @@ -84,20 +81,16 @@ void DebugWindow::logic() const std::string music = "Music: " + currentMap->getProperty("music"); mMusicFileLabel->setCaption(music); - mMusicFileLabel->adjustSize(); const std::string minimap = "MiniMap: " + currentMap->getProperty("minimap"); mMiniMapLabel->setCaption(minimap); - mMiniMapLabel->adjustSize(); const std::string map = "Map: " + currentMap->getProperty("_filename"); mMapLabel->setCaption(map); - mMapLabel->adjustSize(); } mParticleCountLabel->setCaption("Particle count: " + toString(Particle::particleCount)); - mParticleCountLabel->adjustSize(); } diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index c4cace55..9764ab9c 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -79,13 +79,14 @@ EmoteContainer::~EmoteContainer() void EmoteContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + int columns = getWidth() / gridWidth; // Have at least 1 column if (columns < 1) - { columns = 1; - } for (int i = 0; i < mMaxEmote ; i++) { diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index e828df8b..f4cef106 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -76,6 +76,15 @@ EmoteShortcutContainer::~EmoteShortcutContainer() void EmoteShortcutContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + + if (config.getValue("guialpha", 0.8) != mAlpha) + { + mAlpha = config.getValue("guialpha", 0.8); + mBackgroundImg->setAlpha(mAlpha); + } + Graphics *g = static_cast(graphics); graphics->setFont(getFont()); @@ -95,7 +104,8 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (emoteShortcut->getEmote(i)) { - mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, emoteY + 10); + mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, + emoteY + 10); } } @@ -112,12 +122,6 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) sprite->draw(g, tPosX, tPosY); } } - - if (config.getValue("guialpha", 0.8) != mAlpha) - { - mAlpha = config.getValue("guialpha", 0.8); - mBackgroundImg->setAlpha(mAlpha); - } } void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event) @@ -130,9 +134,7 @@ void EmoteShortcutContainer::mouseDragged(gcn::MouseEvent &event) const int emoteId = emoteShortcut->getEmote(index); if (index == -1) - { return; - } if (emoteId) { @@ -153,19 +155,17 @@ void EmoteShortcutContainer::mousePressed(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); if (index == -1) - { - return; - } + return; // Stores the selected emote if there is one. if (emoteShortcut->isEmoteSelected()) { - emoteShortcut->setEmote(index); - emoteShortcut->setEmoteSelected(0); + emoteShortcut->setEmote(index); + emoteShortcut->setEmoteSelected(0); } else if (emoteShortcut->getEmote(index)) { - mEmoteClicked = true; + mEmoteClicked = true; } } @@ -176,9 +176,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); if (emoteShortcut->isEmoteSelected()) - { emoteShortcut->setEmoteSelected(0); - } if (index == -1) { @@ -197,9 +195,7 @@ void EmoteShortcutContainer::mouseReleased(gcn::MouseEvent &event) } if (mEmoteClicked) - { mEmoteClicked = false; - } } } diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 6be55e1c..27ea38ff 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -99,6 +99,9 @@ EquipmentWindow::~EquipmentWindow() void EquipmentWindow::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + // Draw window graphics Window::draw(graphics); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 347c36ac..226b3178 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -113,6 +113,9 @@ InventoryWindow::~InventoryWindow() void InventoryWindow::logic() { + if (!isVisible()) + return; + Window::logic(); // It would be nicer if this update could be event based, needs some diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 79aeb227..02d6e66d 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -20,13 +20,12 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include #include #include "itemcontainer.h" #include "itempopup.h" +#include "viewport.h" #include "../graphics.h" #include "../inventory.h" @@ -72,6 +71,9 @@ ItemContainer::~ItemContainer() void ItemContainer::logic() { + if (!isVisible()) + return; + gcn::Widget::logic(); int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 @@ -85,18 +87,19 @@ void ItemContainer::logic() void ItemContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + int columns = getWidth() / gridWidth; // Have at least 1 column if (columns < 1) - { columns = 1; - } /* - * mOffset is used to compensate for some weirdness that eAthena inherited from - * Ragnarok Online. Inventory slots and cart slots are +2 from their actual index, - * while storage slots are +1. + * mOffset is used to compensate for some weirdness that eAthena inherited + * from Ragnarok Online. Inventory slots and cart slots are +2 from their + * actual index, while storage slots are +1. */ for (int i = mOffset; i < mInventory->getSize(); i++) { @@ -105,31 +108,25 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (!item || item->getQuantity() <= 0) continue; - int itemX = ((i - 2) % columns) * gridWidth; - int itemY = ((i - 2) / columns) * gridHeight; + int itemX = ((i - mOffset) % columns) * gridWidth; + int itemY = ((i - mOffset) / columns) * gridHeight; // Draw selection image below selected item if (mSelectedItemIndex == i) - { - static_cast(graphics)->drawImage( - mSelImg, itemX, itemY); - } + static_cast(graphics)->drawImage(mSelImg, itemX, itemY); // Draw item icon Image* image = item->getImage(); + if (image) - { - static_cast(graphics)->drawImage( - image, itemX, itemY); - } + static_cast(graphics)->drawImage(image, itemX, itemY); // Draw item caption graphics->setFont(getFont()); graphics->setColor(0x000000); graphics->drawText( (item->isEquipped() ? "Eq." : toString(item->getQuantity())), - itemX + gridWidth / 2, - itemY + gridHeight - 11, + itemX + gridWidth / 2, itemY + gridHeight - 11, gcn::Graphics::CENTER); } } @@ -258,12 +255,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) if (item) { - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); - mItemPopup->view(mouseX, mouseY); + mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp index 4a64d53f..06263ce2 100644 --- a/src/gui/itemlinkhandler.cpp +++ b/src/gui/itemlinkhandler.cpp @@ -23,10 +23,9 @@ #include #include -#include - #include "itemlinkhandler.h" #include "itempopup.h" +#include "viewport.h" #include "../resources/iteminfo.h" #include "../resources/itemdb.h" @@ -50,15 +49,12 @@ void ItemLinkHandler::handleLink(const std::string &link) if (id > 0) { const ItemInfo &iteminfo = ItemDB::get(id); - int mouseX, mouseY; - - SDL_GetMouseState(&mouseX, &mouseY); mItemPopup->setItem(iteminfo); if (mItemPopup->isVisible()) mItemPopup->setVisible(false); else - mItemPopup->view(mouseX, mouseY); + mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 88afcd5b..0f7e2d11 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -104,6 +104,9 @@ ItemPopup::~ItemPopup() void ItemPopup::setItem(const ItemInfo &item) { + if (item.getName() == mItemName->getCaption()) + return; + mItemName->setCaption(item.getName()); mItemName->setForegroundColor(getColor(item.getType())); mItemName->setWidth(boldFont->getWidth(item.getName())); diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 10ced157..e7a9afbe 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -19,7 +19,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include #include "itemshortcutcontainer.h" #include "itempopup.h" @@ -67,6 +66,9 @@ ItemShortcutContainer::~ItemShortcutContainer() void ItemShortcutContainer::logic() { + if (!isVisible()) + return; + gcn::Widget::logic(); int i = itemShortcut->getItemCount(); @@ -80,6 +82,15 @@ void ItemShortcutContainer::logic() void ItemShortcutContainer::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + + if (config.getValue("guialpha", 0.8) != mAlpha) + { + mAlpha = config.getValue("guialpha", 0.8); + mBackgroundImg->setAlpha(mAlpha); + } + Graphics *g = static_cast(graphics); graphics->setFont(getFont()); @@ -102,23 +113,23 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) Item *item = player_node->getInventory()->findItem(itemShortcut->getItem(i)); - if (item) { + + if (item) + { // Draw item icon. - const std::string label = - item->isEquipped() ? "Eq." : toString(item->getQuantity()); Image* image = item->getImage(); - if (image) { + + if (image) + { const std::string label = item->isEquipped() ? "Eq." : toString(item->getQuantity()); g->drawImage(image, itemX, itemY); - g->drawText( - label, - itemX + mBoxWidth / 2, - itemY + mBoxHeight - 14, - gcn::Graphics::CENTER); + g->drawText(label, itemX + mBoxWidth / 2, + itemY + mBoxHeight - 14, gcn::Graphics::CENTER); } } } + if (mItemMoved) { // Draw the item image being dragged by the cursor. @@ -129,18 +140,11 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) const int tPosY = mCursorPosY - (image->getHeight() / 2); g->drawImage(image, tPosX, tPosY); - g->drawText( - toString(mItemMoved->getQuantity()), - tPosX + mBoxWidth / 2, - tPosY + mBoxHeight - 14, - gcn::Graphics::CENTER); + g->drawText(toString(mItemMoved->getQuantity()), + tPosX + mBoxWidth / 2, tPosY + mBoxHeight - 14, + gcn::Graphics::CENTER); } } - - if (config.getValue("guialpha", 0.8) != mAlpha) - { - mBackgroundImg->setAlpha(config.getValue("guialpha", 0.8)); - } } void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) @@ -152,10 +156,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); const int itemId = itemShortcut->getItem(index); - if (index == -1) - return; - - if (itemId < 0) + if (index == -1 || itemId < 0) return; Item *item = player_node->getInventory()->findItem(itemId); @@ -166,7 +167,8 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) itemShortcut->removeItem(index); } } - if (mItemMoved) { + if (mItemMoved) + { mCursorPosX = event.getX(); mCursorPosY = event.getY(); } @@ -176,6 +178,7 @@ void ItemShortcutContainer::mouseDragged(gcn::MouseEvent &event) void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) { const int index = getIndexFromGrid(event.getX(), event.getY()); + if (index == -1) return; @@ -199,12 +202,9 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) if (!item) return; - /* Convert relative to the window coordinates to absolute screen - * coordinates. - */ - int mx, my; - SDL_GetMouseState(&mx, &my); - viewport->showPopup(mx, my, item); + // Convert relative to the window coordinates to absolute screen + // coordinates. + viewport->showPopup(viewport->getMouseX(), viewport->getMouseY(), item); } } @@ -230,6 +230,7 @@ void ItemShortcutContainer::mouseReleased(gcn::MouseEvent &event) { itemShortcut->useItem(index); } + if (mItemClicked) mItemClicked = false; } @@ -241,22 +242,16 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) const int index = getIndexFromGrid(event.getX(), event.getY()); const int itemId = itemShortcut->getItem(index); - if (index == -1) - return; - - if (itemId < 0) + if (index == -1 || itemId < 0) return; Item *item = player_node->getInventory()->findItem(itemId); if (item) { - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); - mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); - mItemPopup->view(mouseX, mouseY); + mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else { diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 45d14884..6d5c0ca8 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -39,7 +39,7 @@ ListBox::ListBox(gcn::ListModel *listModel): void ListBox::draw(gcn::Graphics *graphics) { - if (!mListModel) + if (!mListModel || !isVisible()) return; if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 65bd7082..8a695865 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -90,7 +90,6 @@ void MenuWindow::draw(gcn::Graphics *graphics) drawChildren(graphics); } - void MenuWindowListener::action(const gcn::ActionEvent &event) { Window *window = NULL; diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 80c95dd7..2a97b949 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -113,6 +113,9 @@ void Minimap::draw(gcn::Graphics *graphics) { setVisible(mShow); + if (!isVisible()) + return; + Window::draw(graphics); if (!mShow) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 23c4d465..9621b389 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -23,6 +23,7 @@ #include #include "button.h" +#include "gui.h" #include "ok_dialog.h" #include "scrollarea.h" #include "textbox.h" @@ -47,14 +48,15 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, mTextBox->setTextWrapped(msg, 260); int numRows = mTextBox->getNumberOfRows(); + const int fontHeight = getFont()->getHeight(); if (numRows > 1) { - // 15 == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + 15, 15 + (numRows * 15) + okButton->getHeight()); + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + fontHeight) + okButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * 14))); + 3 + (numRows * fontHeight))); } else { @@ -63,12 +65,12 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < okButton->getWidth()) width = okButton->getWidth(); - setContentSize(width + 15, 30 + okButton->getHeight()); + setContentSize(width + fontHeight, 30 + okButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } okButton->setPosition((mTextBox->getMinWidth() - okButton->getWidth()) / 2, - (numRows * 14) + okButton->getHeight() - 8); + ((numRows - 1) * fontHeight) + okButton->getHeight() + 2); add(mTextArea); add(okButton); @@ -93,7 +95,6 @@ void OkDialog::action(const gcn::ActionEvent &event) } // Can we receive anything else anyway? - if (event.getId() == "ok") { + if (event.getId() == "ok") scheduleDelete(); - } } diff --git a/src/gui/playerbox.cpp b/src/gui/playerbox.cpp index e7ee3afe..2a6cdb20 100644 --- a/src/gui/playerbox.cpp +++ b/src/gui/playerbox.cpp @@ -79,6 +79,9 @@ PlayerBox::~PlayerBox() void PlayerBox::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + if (mPlayer) { // Draw character diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h index ff146745..3c88f3a3 100644 --- a/src/gui/progressbar.h +++ b/src/gui/progressbar.h @@ -108,6 +108,7 @@ class ProgressBar : public gcn::Widget Uint8 mRed, mGreen, mBlue; Uint8 mRedToGo, mGreenToGo, mBlueToGo; std::string mText; + bool mUpdated; static ImageRect mBorder; static int mInstances; diff --git a/src/gui/radiobutton.cpp b/src/gui/radiobutton.cpp index a8ab61c4..c839238b 100644 --- a/src/gui/radiobutton.cpp +++ b/src/gui/radiobutton.cpp @@ -70,6 +70,9 @@ RadioButton::~RadioButton() void RadioButton::drawBox(gcn::Graphics* graphics) { + if (!isVisible()) + return; + if (config.getValue("guialpha", 0.8) != mAlpha) { mAlpha = config.getValue("guialpha", 0.8); diff --git a/src/gui/scrollarea.cpp b/src/gui/scrollarea.cpp index d655ad52..43b27f23 100644 --- a/src/gui/scrollarea.cpp +++ b/src/gui/scrollarea.cpp @@ -149,6 +149,9 @@ void ScrollArea::init() void ScrollArea::logic() { + if (!isVisible()) + return; + gcn::ScrollArea::logic(); gcn::Widget *content = getContent(); @@ -171,6 +174,9 @@ void ScrollArea::logic() void ScrollArea::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + if (mVBarVisible) { drawUpButton(graphics); diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 6e70e022..776f26bc 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -58,7 +58,7 @@ void ShopListBox::setPlayersMoney(int money) void ShopListBox::draw(gcn::Graphics *gcnGraphics) { - if (!mListModel) + if (!mListModel || !isVisible()) return; if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index 13ff042d..50ec9d06 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -39,34 +39,28 @@ ShortcutContainer::ShortcutContainer(): void ShortcutContainer::widgetResized(const gcn::Event &event) { mGridWidth = getWidth() / mBoxWidth; + if (mGridWidth < 1) - { mGridWidth = 1; - } - - setHeight((mMaxItems / mGridWidth + - (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); mGridHeight = getHeight() / mBoxHeight; + if (mGridHeight < 1) - { mGridHeight = 1; - } + + setHeight((mMaxItems / mGridWidth + + (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); } int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const { - const gcn::Rectangle tRect = gcn::Rectangle( - 0, 0, mGridWidth * mBoxWidth, mGridHeight * mBoxHeight); - if (!tRect.isPointInRect(pointX, pointY)) - { - return -1; - } - const int index = ((pointY / mBoxHeight) * mGridWidth) + - pointX / mBoxWidth; - if (index >= mMaxItems) - { - return -1; - } + const gcn::Rectangle tRect = gcn::Rectangle(0, 0, mGridWidth * mBoxWidth, + mGridHeight * mBoxHeight); + + int index = ((pointY / mBoxHeight) * mGridWidth) + pointX / mBoxWidth; + + if (!tRect.isPointInRect(pointX, pointY) || index >= mMaxItems) + index = -1; + return index; } diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 209f964b..d54bf9ad 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -32,7 +32,8 @@ #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): - Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml") + Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml"), + mText("") { setContentSize(140, 46); setShowTitle(false); @@ -67,10 +68,13 @@ void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color) mCaption->setForegroundColor(color); } -void SpeechBubble::setText(std::string mText, bool showName) +void SpeechBubble::setText(std::string text, bool showName) { + if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth())) + return; + int width = mCaption->getWidth(); - mSpeechBox->setTextWrapped(mText, 130 > width ? 130 : width); + mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width); const int fontHeight = getFont()->getHeight(); const int numRows = showName ? mSpeechBox->getNumberOfRows() + 1 : diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index dce421ec..6b03cc85 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -35,11 +35,12 @@ class SpeechBubble : public Window void setCaption(const std::string &name, const gcn::Color &color = 0x000000); - void setText(std::string mText, bool showName = true); + void setText(std::string text, bool showName = true); void setLocation(int x, int y); unsigned int getNumRows(); private: + std::string mText; gcn::Label *mCaption; TextBox *mSpeechBox; ScrollArea *mSpeechArea; diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 49af3ae2..6419eabb 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -272,6 +272,9 @@ void StatusWindow::update() void StatusWindow::draw(gcn::Graphics *g) { + if (!isVisible()) + return; + update(); Window::draw(g); diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 29a33b7a..b2571495 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -265,7 +265,7 @@ void GuiTable::installActionListeners(void) // -- widget ops void GuiTable::draw(gcn::Graphics* graphics) { - if (!mModel) + if (!mModel || !isVisible()) return; if (config.getValue("guialpha", 0.8) != mAlpha) diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index ed83622d..054bc405 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -84,7 +84,11 @@ TextField::~TextField() void TextField::draw(gcn::Graphics *graphics) { - if (isFocused()) { + if (!isVisible()) + return; + + if (isFocused()) + { drawCaret(graphics, getFont()->getWidth(mText.substr(0, mCaretPosition)) - mXScroll); diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index ba2e2462..a12b94ed 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -117,7 +117,6 @@ void TradeWindow::widgetResized(const gcn::Event &event) Window::widgetResized(event); } - void TradeWindow::addMoney(int amount) { mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index f655888c..56274573 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -43,6 +43,8 @@ extern volatile int tick_time; Viewport::Viewport(): mMap(0), + mMouseX(0), + mMouseY(0), mPixelViewX(0.0f), mPixelViewY(0.0f), mTileViewX(0), @@ -148,18 +150,14 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) int viewYmax = (mMap->getHeight() * 32) - graphics->getHeight(); if (mMap) { - if (mPixelViewX < 0) { + if (mPixelViewX < 0) mPixelViewX = 0; - } - if (mPixelViewY < 0) { + if (mPixelViewY < 0) mPixelViewY = 0; - } - if (mPixelViewX > viewXmax) { + if (mPixelViewX > viewXmax) mPixelViewX = viewXmax; - } - if (mPixelViewY > viewYmax) { + if (mPixelViewY > viewYmax) mPixelViewY = viewYmax; - } } mTileViewX = (int) (mPixelViewX + 16) / 32; @@ -175,11 +173,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) if (mShowDebugPath) { // Get the current mouse position - int mouseX, mouseY; - SDL_GetMouseState(&mouseX, &mouseY); + SDL_GetMouseState(&mMouseX, &mMouseY); - int mouseTileX = mouseX / 32 + mTileViewX; - int mouseTileY = mouseY / 32 + mTileViewY; + int mouseTileX = mMouseX / 32 + mTileViewX; + int mouseTileY = mMouseY / 32 + mTileViewY; Path debugPath = mMap->findPath(player_node->mX, player_node->mY, mouseTileX, mouseTileY); @@ -204,7 +201,6 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) player_node->setName(player_node->getName()); } - // Draw text if (textManager) { @@ -215,8 +211,8 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) Beings &beings = beingManager->getAll(); for (BeingIterator i = beings.begin(); i != beings.end(); i++) { - (*i)->drawSpeech(-(int) mPixelViewX, -(int) mPixelViewY); - (*i)->drawEmotion(graphics, -(int) mPixelViewX, -(int) mPixelViewY); + (*i)->drawSpeech((int) mPixelViewX, (int) mPixelViewY); + (*i)->drawEmotion(graphics, (int) mPixelViewX, (int) mPixelViewY); } // Draw contained widgets @@ -230,14 +226,13 @@ void Viewport::logic() if (!mMap || !player_node) return; - int mouseX, mouseY; - Uint8 button = SDL_GetMouseState(&mouseX, &mouseY); + Uint8 button = SDL_GetMouseState(&mMouseX, &mMouseY); if (mPlayerFollowMouse && button & SDL_BUTTON(1) && mWalkTime != player_node->mWalkTime) { - player_node->setDestination(mouseX / 32 + mTileViewX, - mouseY / 32 + mTileViewY); + player_node->setDestination(mMouseX / 32 + mTileViewX, + mMouseY / 32 + mTileViewY); mWalkTime = player_node->mWalkTime; } } @@ -343,9 +338,7 @@ void Viewport::mousePressed(gcn::MouseEvent &event) Being *target = beingManager->findBeingByPixel(x, y); if (target) - { player_node->setTarget(target); - } } } diff --git a/src/gui/viewport.h b/src/gui/viewport.h index a131d162..12fdb187 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -115,30 +115,42 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ int getCameraY() const { return (int) mPixelViewY; } + /** + * Returns mouse x in pixels. + */ + int getMouseX() const { return mMouseX; } + + /** + * Returns mouse y in pixels. + */ + int getMouseY() const { return mMouseY; } + /** * Changes viewpoint by relative pixel coordinates. */ void scrollBy(float x, float y) { mPixelViewX += x; mPixelViewY += y; } private: - Map *mMap; /**< The current map. */ + Map *mMap; /**< The current map. */ int mScrollRadius; int mScrollLaziness; int mScrollCenterOffsetX; int mScrollCenterOffsetY; - float mPixelViewX; /**< Current viewpoint in pixels. */ - float mPixelViewY; /**< Current viewpoint in pixels. */ + int mMouseX; /**< Current mouse position in pixels. */ + int mMouseY; /**< Current mouse position in pixels. */ + float mPixelViewX; /**< Current viewpoint in pixels. */ + float mPixelViewY; /**< Current viewpoint in pixels. */ int mTileViewX; /**< Current viewpoint in tiles. */ int mTileViewY; /**< Current viewpoint in tiles. */ - bool mShowDebugPath; /**< Show a path from player to pointer. */ + bool mShowDebugPath; /**< Show a path from player to pointer. */ bool mPlayerFollowMouse; int mWalkTime; - PopupMenu *mPopupMenu; /**< Popup menu. */ + PopupMenu *mPopupMenu; /**< Popup menu. */ }; -extern Viewport *viewport; /**< The viewport */ +extern Viewport *viewport; /**< The viewport */ #endif diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index ed4d260b..9fcf173c 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -75,12 +75,15 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage( - gridx[x], gridy[y], - gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - gridy[y] + 1); + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - + gridx[x] + 1, + gridy[y + 1] - + gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; } @@ -109,16 +112,15 @@ DropDown::~DropDown() void DropDown::draw(gcn::Graphics* graphics) { + if (!isVisible()) + return; + int h; if (mDroppedDown) - { h = mFoldedUpHeight; - } else - { h = getHeight(); - } if (config.getValue("guialpha", 0.8) != mAlpha) { diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 263e5bbd..97f6010c 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -36,7 +36,7 @@ int Tab::mInstances = 0; float Tab::mAlpha = config.getValue("guialpha", 0.8); -enum{ +enum { TAB_STANDARD, // 0 TAB_HIGHLIGHTED, // 1 TAB_SELECTED, // 2 @@ -95,8 +95,10 @@ void Tab::init() { tab[mode] = resman->getImage(data[mode].file); a = 0; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { tabImg[mode].grid[a] = tab[mode]->getSubImage( data[x].gridX, data[y].gridY, data[x + 1].gridX - data[x].gridX + 1, diff --git a/src/gui/widgets/tabbedarea.cpp b/src/gui/widgets/tabbedarea.cpp index aaa3463f..2c454b69 100644 --- a/src/gui/widgets/tabbedarea.cpp +++ b/src/gui/widgets/tabbedarea.cpp @@ -41,9 +41,8 @@ Tab* TabbedArea::getTab(const std::string &name) while (itr != itr_end) { if ((*itr).first->getCaption() == name) - { return static_cast((*itr).first); - } + ++itr; } return NULL; @@ -52,9 +51,7 @@ Tab* TabbedArea::getTab(const std::string &name) void TabbedArea::draw(gcn::Graphics *graphics) { if (mTabs.empty()) - { return; - } drawChildren(graphics); } @@ -65,9 +62,8 @@ gcn::Widget* TabbedArea::getWidget(const std::string &name) while (itr != itr_end) { if ((*itr).first->getCaption() == name) - { return (*itr).second; - } + ++itr; } @@ -92,9 +88,7 @@ void TabbedArea::addTab(Tab *tab, gcn::Widget *widget) mTabs.push_back(std::pair(tab, widget)); if (!mSelectedTab) - { setSelectedTab(tab); - } adjustTabPositions(); adjustSize(); @@ -108,15 +102,10 @@ void TabbedArea::removeTab(Tab *tab) { int index = getSelectedTabIndex(); - if (index == (int)mTabs.size() - 1 - && mTabs.size() == 1) - { + if (index == (int)mTabs.size() - 1 && mTabs.size() == 1) tabIndexToBeSelected = -1; - } else - { tabIndexToBeSelected = index - 1; - } } TabContainer::iterator iter; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 516b4138..e285c3c4 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -169,6 +169,9 @@ void Window::setWindowContainer(WindowContainer *wc) void Window::draw(gcn::Graphics *graphics) { + if (!isVisible()) + return; + Graphics *g = static_cast(graphics); g->drawImageRect(0, 0, getWidth(), getHeight(), border); -- cgit v1.2.3-70-g09d2 From 2c35b0be762e2f309514b454ab89f2f0c6db715a Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 6 Mar 2009 06:26:15 -0700 Subject: Fix layout of debug window --- src/gui/debugwindow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 99b36fe4..33304944 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -41,7 +41,6 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); setDefaultSize(0, 0, 400, 60); - loadWindowState(); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); @@ -50,14 +49,14 @@ DebugWindow::DebugWindow(): mTileMouseLabel = new gcn::Label("Mouse: 0, 0"); mParticleCountLabel = new gcn::Label("Particle count: 0"); - place(0, 0, mFPSLabel); + place(0, 0, mFPSLabel, 3); place(3, 0, mTileMouseLabel); place(0, 1, mMusicFileLabel, 3); place(3, 1, mParticleCountLabel); place(0, 2, mMapLabel, 4); place(0, 3, mMiniMapLabel, 4); - reflowLayout(375, 0); + loadWindowState(); } void DebugWindow::logic() -- cgit v1.2.3-70-g09d2 From 249b699ee7d6b80700cd648c4a7634c267b0ee68 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Fri, 6 Mar 2009 06:26:15 -0700 Subject: Fix layout of debug window --- src/gui/debugwindow.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 1e199314..1a805dd4 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -42,7 +42,6 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); setDefaultSize(0, 0, 400, 60); - loadWindowState(); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); @@ -51,14 +50,14 @@ DebugWindow::DebugWindow(): mTileMouseLabel = new gcn::Label("Mouse: 0, 0"); mParticleCountLabel = new gcn::Label("Particle count: 0"); - place(0, 0, mFPSLabel); + place(0, 0, mFPSLabel, 3); place(3, 0, mTileMouseLabel); place(0, 1, mMusicFileLabel, 3); place(3, 1, mParticleCountLabel); place(0, 2, mMapLabel, 4); place(0, 3, mMiniMapLabel, 4); - reflowLayout(375, 0); + loadWindowState(); } void DebugWindow::logic() -- cgit v1.2.3-70-g09d2 From 6ea994477c58912785729e7922eb90862a1ab13c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 6 Mar 2009 08:50:11 -0700 Subject: Cut down on redundant constant int declarations in the windows skinning code. While this shouldn't do too much, if anything, for performance, it makes maintenence easier in the future if only one set of ints needs to be modified rather than 9 when they do the same thing. Signed-off-by: Ira Rice --- src/gui/window.cpp | 74 +++++------------------------------------------------- 1 file changed, 6 insertions(+), 68 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e285c3c4..0869368d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -569,7 +569,7 @@ void Window::loadSkin(const std::string &filename) if (!skinSetImage.empty()) { logger->log("Window::loadSkin(): defines '%s' as a skin image.", skinSetImage.c_str()); - dBorders = resman->getImage("graphics/gui/" + skinSetImage);//"graphics/gui/speech_bubble.png"); + dBorders = resman->getImage("graphics/gui/" + skinSetImage); } else { @@ -593,104 +593,42 @@ void Window::loadSkin(const std::string &filename) for_each_xml_child_node(partNode, widgetNode) { if (!xmlStrEqual(partNode->name, BAD_CAST "part")) - { continue; - } std::string partType; partType = XML::getProperty(partNode, "type", "unknown"); // TOP ROW - if (partType == "top-left-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); + const int xPos = XML::getProperty(partNode, "xpos", 0); + const int yPos = XML::getProperty(partNode, "ypos", 0); + const int width = XML::getProperty(partNode, "width", 1); + const int height = XML::getProperty(partNode, "height", 1); + if (partType == "top-left-corner") border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "top-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "top-right-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); - } // MIDDLE ROW else if (partType == "left-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "bg-quad") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "right-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); - } // BOTTOM ROW else if (partType == "bottom-left-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "bottom-edge") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); - } else if (partType == "bottom-right-corner") - { - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); - } // Part is of an uknown type. else - { logger->log("Window::loadSkin(): Unknown Part Type '%s'", partType.c_str()); - } } } // Widget is of an uknown type. -- cgit v1.2.3-70-g09d2 From 6099a24784843ac2c6eb4036f5c08bba2f9299c3 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 8 Mar 2009 18:40:48 -0600 Subject: Add an interface for eAthena's storage system --- src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/game.cpp | 5 +++ src/gui/item_amount.cpp | 19 ++++++++++++ src/gui/item_amount.h | 2 ++ src/inventory.h | 1 + src/localplayer.cpp | 7 +++++ src/localplayer.h | 5 +-- src/net/inventoryhandler.cpp | 73 ++++++++++++++++++++++++++++++++------------ tmw.cbp | 2 ++ 10 files changed, 94 insertions(+), 24 deletions(-) (limited to 'src/gui') diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index e7abb5fd..fc6d1f35 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,6 +191,8 @@ SET(SRCS gui/speechbubble.h gui/status.cpp gui/status.h + gui/storagewindow.cpp + gui/storagewindow.h gui/table.cpp gui/table.h gui/table_model.cpp diff --git a/src/Makefile.am b/src/Makefile.am index e8e9a695..4982c215 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -141,6 +141,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/speechbubble.h \ gui/status.cpp \ gui/status.h \ + gui/storagewindow.cpp \ + gui/storagewindow.h \ gui/table.cpp \ gui/table.h \ gui/table_model.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 40bfd5e4..9f8a2613 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -69,6 +69,7 @@ #include "gui/setup.h" #include "gui/skill.h" #include "gui/status.h" +#include "gui/storagewindow.h" #include "gui/trade.h" #include "gui/viewport.h" @@ -128,6 +129,7 @@ HelpWindow *helpWindow; DebugWindow *debugWindow; ShortcutWindow *itemShortcutWindow; ShortcutWindow *emoteShortcutWindow; +StorageWindow *storageWindow; BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; @@ -212,6 +214,7 @@ void createGuiWindows(Network *network) new ItemShortcutContainer); emoteShortcutWindow = new ShortcutWindow("emoteShortcut", new EmoteShortcutContainer); + storageWindow = new StorageWindow(network); // Set initial window visibility chatWindow->setVisible((bool) config.getValue( @@ -231,6 +234,7 @@ void createGuiWindows(Network *network) emoteShortcutWindow->getWindowName() + "Visible", true)); minimap->setVisible((bool) config.getValue( minimap->getWindowName() + "Visible", true)); + storageWindow->setVisible(false); } /** @@ -261,6 +265,7 @@ void destroyGuiWindows() delete debugWindow; delete itemShortcutWindow; delete emoteShortcutWindow; + delete storageWindow; } Game::Game(Network *network): diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 92be3d6e..280f063e 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -23,6 +23,7 @@ #include "inttextfield.h" #include "item_amount.h" #include "slider.h" +#include "storagewindow.h" #include "trade.h" #include "widgets/layout.h" @@ -80,6 +81,14 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): setCaption(_("Select amount of items to drop.")); okButton->setActionEventId("Drop"); break; + case AMOUNT_STORE_ADD: + setCaption(_("Select amount of items to store.")); + okButton->setActionEventId("AddStore"); + break; + case AMOUNT_STORE_REMOVE: + setCaption(_("Select amount of items to remove from storage.")); + okButton->setActionEventId("RemoveStore"); + break; default: break; } @@ -123,6 +132,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue()); scheduleDelete(); } + else if (event.getId() == "AddStore") + { + storageWindow->addStore(mItem, mItemAmountTextField->getValue()); + scheduleDelete(); + } + else if (event.getId() == "RemoveStore") + { + storageWindow->removeStore(mItem, mItemAmountTextField->getValue()); + scheduleDelete(); + } mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 618d7d51..26cca32c 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -31,6 +31,8 @@ class Item; #define AMOUNT_TRADE_ADD 1 #define AMOUNT_ITEM_DROP 2 +#define AMOUNT_STORE_ADD 3 +#define AMOUNT_STORE_REMOVE 4 /** * Window used for selecting the amount of items to drop or trade. diff --git a/src/inventory.h b/src/inventory.h index 2c5d99e3..df2aac38 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -25,6 +25,7 @@ class Item; #define INVENTORY_SIZE 102 +#define STORAGE_SIZE 301 class Inventory { diff --git a/src/localplayer.cpp b/src/localplayer.cpp index abeb134c..296bc28c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -38,6 +38,7 @@ #include "gui/gui.h" #include "gui/ministatus.h" +#include "gui/storagewindow.h" #include "net/messageout.h" #include "net/protocol.h" @@ -742,3 +743,9 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height, mTargetCursor[index][size] = currentCursor; } +void LocalPlayer::setInStorage(bool inStorage) +{ + mInStorage = inStorage; + + storageWindow->setVisible(inStorage); +} diff --git a/src/localplayer.h b/src/localplayer.h index ba6e7670..ce181c74 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -30,9 +30,6 @@ // TODO move into some sane place... #define MAX_SLOT 2 -#define INVENTORY_SIZE 102 -#define STORAGE_SIZE 301 - class Equipment; class FloorItem; class ImageSet; @@ -194,7 +191,7 @@ class LocalPlayer : public Player * Accessors for mInStorage */ bool getInStorage() { return mInStorage; } - void setInStorage(bool inStorage) { mInStorage = inStorage; } + void setInStorage(bool inStorage); /** * Sets the amount of XP. Shows XP gaining effect if the player is on diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index d78a7a45..ebcca885 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -33,6 +33,7 @@ #include "../log.h" #include "../gui/chat.h" +#include "../gui/storagewindow.h" #include "../resources/iteminfo.h" @@ -71,7 +72,6 @@ void InventoryHandler::handleMessage(MessageIn *msg) { case SMSG_PLAYER_INVENTORY: case SMSG_PLAYER_STORAGE_ITEMS: - case SMSG_PLAYER_STORAGE_EQUIP: switch (msg->getId()) { case SMSG_PLAYER_INVENTORY: // Clear inventory - this will be a complete refresh @@ -85,11 +85,10 @@ void InventoryHandler::handleMessage(MessageIn *msg) * clear storage here */ storage->clear(); - logger->log("Received SMSG_PLAYER_STORAGE_ITEMS"); break; default: - logger->log("Received SMSG_PLAYER_STORAGE_EQUIP"); - break; + logger->log("HOW DID WE GET HERE?"); + return; } msg->readInt16(); // length number = (msg->getLength() - 4) / 18; @@ -99,17 +98,8 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemId = msg->readInt16(); itemType = msg->readInt8(); identified = msg->readInt8(); - if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { - amount = 1; - msg->readInt16(); // Equip Point? - } else { - amount = msg->readInt16(); - } + amount = msg->readInt16(); arrow = msg->readInt16(); - if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { - msg->readInt8(); // Attribute (broken) - msg->readInt8(); // Refine level - } for (int i = 0; i < 4; i++) cards[i] = msg->readInt16(); @@ -129,6 +119,29 @@ void InventoryHandler::handleMessage(MessageIn *msg) } break; + case SMSG_PLAYER_STORAGE_EQUIP: + msg->readInt16(); // length + number = (msg->getLength() - 4) / 20; + + for (int loop = 0; loop < number; loop++) { + index = msg->readInt16(); + itemId = msg->readInt16(); + itemType = msg->readInt8(); + identified = msg->readInt8(); + amount = 1; + msg->readInt16(); // Equip Point? + msg->readInt16(); // Another Equip Point? + msg->readInt8(); // Attribute (broken) + msg->readInt8(); // Refine level + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d", + index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]); + storage->setItem(index, itemId, amount, false); + } + break; + case SMSG_PLAYER_INVENTORY_ADD: index = msg->readInt16(); amount = msg->readInt16(); @@ -209,7 +222,6 @@ void InventoryHandler::handleMessage(MessageIn *msg) * SMSG_PLAYER_STORAGE_... packets that update * storage contents. */ - logger->log("Received SMSG_PLAYER_STORAGE_STATUS"); player_node->setInStorage(true); break; @@ -217,20 +229,41 @@ void InventoryHandler::handleMessage(MessageIn *msg) /* * Move an item into storage */ + index = msg->readInt16(); + amount = msg->readInt32(); + itemId = msg->readInt16(); + identified = msg->readInt8(); + msg->readInt8(); // attribute + msg->readInt8(); // refine + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + if (Item *item = storage->getItem(index)) { + item->setId(itemId); + item->increaseQuantity(amount); + } else { + storage->setItem(index, itemId, amount, false); + } break; case SMSG_PLAYER_STORAGE_REMOVE: /* - * Move an item out of storage - */ + * Move an item out of storage + */ + index = msg->readInt16(); + amount = msg->readInt16(); + if (Item *item = storage->getItem(index)) { + item->increaseQuantity(-amount); + if (item->getQuantity() == 0) + storage->removeItemAt(index); + } break; case SMSG_PLAYER_STORAGE_CLOSE: /* - * Storage access has been closed - */ + * Storage access has been closed + */ player_node->setInStorage(false); - logger->log("Received SMSG_PLAYER_STORAGE_CLOSE"); break; } } diff --git a/tmw.cbp b/tmw.cbp index 7d24164a..62799884 100644 --- a/tmw.cbp +++ b/tmw.cbp @@ -236,6 +236,8 @@ + + -- cgit v1.2.3-70-g09d2 From 0644076cbb731d1f7a55b66bf6d16a309cccea01 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 8 Mar 2009 22:58:42 -0600 Subject: Forgot the actual storage window --- src/gui/storagewindow.cpp | 213 +++++++++++++++++++++++++++++++++++++++++++ src/gui/storagewindow.h | 107 ++++++++++++++++++++++ src/net/inventoryhandler.cpp | 11 +-- src/net/playerhandler.cpp | 4 +- 4 files changed, 328 insertions(+), 7 deletions(-) create mode 100644 src/gui/storagewindow.cpp create mode 100644 src/gui/storagewindow.h (limited to 'src/gui') diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp new file mode 100644 index 00000000..9cdc2da7 --- /dev/null +++ b/src/gui/storagewindow.cpp @@ -0,0 +1,213 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#include + +#include "button.h" +#include "inventorywindow.h" +#include "item_amount.h" +#include "itemcontainer.h" +#include "progressbar.h" +#include "scrollarea.h" +#include "storagewindow.h" +#include "viewport.h" + +#include "widgets/layout.h" + +#include "../inventory.h" +#include "../item.h" +#include "../localplayer.h" +#include "../units.h" + +#include "../net/messageout.h" +#include "../net/protocol.h" + +#include "../resources/iteminfo.h" + +#include "../utils/gettext.h" +#include "../utils/strprintf.h" +#include "../utils/stringutils.h" + +StorageWindow::StorageWindow(Network *network, int invSize): + Window(_("Storage")), + mNetwork(network), + mMaxSlots(invSize), + mItemDesc(false) +{ + setWindowName("Storage"); + setResizable(true); + + // If you adjust these defaults, don't forget to adjust the trade window's. + setDefaultSize(115, 25, 375, 300); + + mCancelButton = new Button(_("Close"), "close", this); + mStoreButton = new Button(_("Store"), "store", this); + mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); + + mItems = new ItemContainer(player_node->getStorage(), 1); + mItems->addSelectionListener(this); + + mInvenScroll = new ScrollArea(mItems); + mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsLabel = new gcn::Label(_("Slots: ")); + + mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); + + setMinHeight(130); + setMinWidth(mSlotsLabel->getWidth()); + + place(0, 0, mSlotsLabel).setPadding(3); + place(1, 0, mSlotsBar, 3); + place(0, 1, mInvenScroll, 4, 4); + place(0, 5, mCancelButton); + place(2, 5, mStoreButton); + place(3, 5, mRetrieveButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, mStoreButton->getHeight()); + + loadWindowState(); + setLocationRelativeTo(getParent()); +} + +StorageWindow::~StorageWindow() +{ + delete mItems; +} + +void StorageWindow::logic() +{ + if (!isVisible()) + return; + + Window::logic(); + + if (mUsedSlots != toString(player_node->getStorage()->getNumberOfSlotsUsed())) + { + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsBar->setProgress((float) + player_node->getStorage()->getNumberOfSlotsUsed() / mMaxSlots); + + mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots)); + } +} + +void StorageWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "close") + { + close(); + } + else if (event.getId() == "store") + { + Item *item = inventoryWindow->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + addStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_ADD, this, item); + } + } + else if (event.getId() == "retrieve") + { + Item *item = mItems->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + removeStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item); + } + } +} + +void StorageWindow::mouseClicked(gcn::MouseEvent &event) +{ + Window::mouseClicked(event); + + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + Item *item = mItems->getSelectedItem(); + + if (!item) { + mRetrieveButton->setEnabled(false); + return; + } + + mRetrieveButton->setEnabled(true); + + /* Convert relative to the window coordinates to absolute screen + * coordinates. + */ + const int mx = event.getX() + getX(); + const int my = event.getY() + getY(); + viewport->showPopup(mx, my, item); + } +} + +Item* StorageWindow::getSelectedItem() const +{ + return mItems->getSelectedItem(); +} + +void StorageWindow::addStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_MOVE_TO_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::removeStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CSMG_MOVE_FROM_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CLOSE_STORAGE); +} \ No newline at end of file diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h new file mode 100644 index 00000000..35d76ffb --- /dev/null +++ b/src/gui/storagewindow.h @@ -0,0 +1,107 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef STORAGEWINDOW_H +#define STORAGEWINDOW_H + +#include "window.h" + +#include "../inventory.h" + +#include "../net/network.h" + +#include +#include + +class Item; +class ItemContainer; +class ProgressBar; +class TextBox; + +/** + * Storage dialog. + * + * \ingroup Interface + */ +class StorageWindow : public Window, gcn::ActionListener, + gcn::SelectionListener +{ + public: + /** + * Constructor. + */ + StorageWindow(Network *network, int invSize = (STORAGE_SIZE - 1)); + + /** + * Destructor. + */ + ~StorageWindow(); + + /** + * Logic (updates buttons and weight information). + */ + void logic(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Returns the selected item. + */ + Item* getSelectedItem() const; + + void mouseClicked(gcn::MouseEvent &event); + + /** + * Add the specified ammount of the specified item to storage + */ + void addStore(Item* item, int ammount); + + /** + * Remove the specified ammount of the specified item from storage + */ + void removeStore(Item* item, int ammount); + + void close(); + + private: + Network *mNetwork; + ItemContainer *mItems; + + std::string mSlots; + std::string mUsedSlots; + gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton; + gcn::ScrollArea *mInvenScroll; + + gcn::Label *mSlotsLabel; + + ProgressBar *mSlotsBar; + + int mMaxSlots; + + bool mItemDesc; +}; + +extern StorageWindow *storageWindow; + +#endif // STORAGEWINDOW_H diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index ebcca885..243d1e79 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -215,14 +215,13 @@ void InventoryHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STORAGE_STATUS: /* - * Basic slots used vs total slots info - * We don't really need this information, but this is - * the closest we get to an "Open Storage" packet - * from the server. It always comes after the two - * SMSG_PLAYER_STORAGE_... packets that update - * storage contents. + * This is the closest we get to an "Open Storage" packet from the + * server. It always comes after the two SMSG_PLAYER_STORAGE_... + * packets that update storage contents. */ player_node->setInStorage(true); + msg->readInt16(); // Storage capacity + msg->readInt16(); // Used count break; case SMSG_PLAYER_STORAGE_ADD: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index d99a97a5..4cc29568 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -39,6 +39,7 @@ #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" +#include "../gui/storagewindow.h" #include "../gui/viewport.h" #include "../utils/stringutils.h" @@ -92,7 +93,8 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); - current_npc = 0; + + if (storageWindow->isVisible()) storageWindow->close(); } } deathListener; } -- cgit v1.2.3-70-g09d2 From 5fa3f62d0d6d9cbffeef0f6a2497aae023dbadcf Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sun, 8 Mar 2009 18:40:48 -0600 Subject: Add an interface for eAthena's storage system --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 5 + src/gui/item_amount.cpp | 19 ++++ src/gui/item_amount.h | 2 + src/gui/itemcontainer.cpp | 4 +- src/gui/itemshortcutcontainer.cpp | 16 --- src/gui/itemshortcutcontainer.h | 5 - src/gui/shortcutcontainer.cpp | 5 +- src/gui/storagewindow.cpp | 213 ++++++++++++++++++++++++++++++++++++++ src/gui/storagewindow.h | 105 +++++++++++++++++++ src/gui/trade.cpp | 4 +- src/gui/window.h | 5 +- src/inventory.cpp | 11 +- src/inventory.h | 4 +- src/localplayer.cpp | 11 +- src/localplayer.h | 5 +- src/net/inventoryhandler.cpp | 84 ++++++++++----- src/net/playerhandler.cpp | 2 + 20 files changed, 437 insertions(+), 69 deletions(-) create mode 100644 src/gui/storagewindow.cpp create mode 100644 src/gui/storagewindow.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index 29bc7227..46034040 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -242,6 +242,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 51d6b937..c7003946 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -191,6 +191,8 @@ SET(SRCS gui/speechbubble.h gui/status.cpp gui/status.h + gui/storagewindow.cpp + gui/storagewindow.h gui/table.cpp gui/table.h gui/table_model.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 6b5dda8b..963e41fb 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -141,6 +141,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/speechbubble.h \ gui/status.cpp \ gui/status.h \ + gui/storagewindow.cpp \ + gui/storagewindow.h \ gui/table.cpp \ gui/table.h \ gui/table_model.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 110b75cc..ba035ecd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -70,6 +70,7 @@ #include "gui/setup.h" #include "gui/skill.h" #include "gui/status.h" +#include "gui/storagewindow.h" #include "gui/trade.h" #include "gui/viewport.h" @@ -129,6 +130,7 @@ HelpWindow *helpWindow; DebugWindow *debugWindow; ShortcutWindow *itemShortcutWindow; ShortcutWindow *emoteShortcutWindow; +StorageWindow *storageWindow; BeingManager *beingManager = NULL; FloorItemManager *floorItemManager = NULL; @@ -213,6 +215,7 @@ void createGuiWindows(Network *network) new ItemShortcutContainer); emoteShortcutWindow = new ShortcutWindow("emoteShortcut", new EmoteShortcutContainer); + storageWindow = new StorageWindow(network); // Set initial window visibility chatWindow->setVisible((bool) config.getValue( @@ -230,6 +233,7 @@ void createGuiWindows(Network *network) emoteShortcutWindow->getWindowName() + "Visible", true)); minimap->setVisible((bool) config.getValue( minimap->getWindowName() + "Visible", true)); + storageWindow->setVisible(false); } /** @@ -260,6 +264,7 @@ void destroyGuiWindows() delete debugWindow; delete itemShortcutWindow; delete emoteShortcutWindow; + delete storageWindow; } Game::Game(Network *network): diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8ab36df0..05dca472 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -24,6 +24,7 @@ #include "inttextfield.h" #include "item_amount.h" #include "slider.h" +#include "storagewindow.h" #include "trade.h" #include "widgets/layout.h" @@ -81,6 +82,14 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): setCaption(_("Select amount of items to drop.")); okButton->setActionEventId("Drop"); break; + case AMOUNT_STORE_ADD: + setCaption(_("Select amount of items to store.")); + okButton->setActionEventId("AddStore"); + break; + case AMOUNT_STORE_REMOVE: + setCaption(_("Select amount of items to remove from storage.")); + okButton->setActionEventId("RemoveStore"); + break; default: break; } @@ -124,6 +133,16 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue()); scheduleDelete(); } + else if (event.getId() == "AddStore") + { + storageWindow->addStore(mItem, mItemAmountTextField->getValue()); + scheduleDelete(); + } + else if (event.getId() == "RemoveStore") + { + storageWindow->removeStore(mItem, mItemAmountTextField->getValue()); + scheduleDelete(); + } mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 6bec86b3..279c239e 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -32,6 +32,8 @@ class Item; #define AMOUNT_TRADE_ADD 1 #define AMOUNT_ITEM_DROP 2 +#define AMOUNT_STORE_ADD 3 +#define AMOUNT_STORE_REMOVE 4 /** * Window used for selecting the amount of items to drop or trade. diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 02d6e66d..54f1f647 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -57,7 +57,7 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset): mSelImg = resman->getImage("graphics/gui/selection.png"); if (!mSelImg) logger->error("Unable to load selection.png"); - mMaxItems = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 + mMaxItems = mInventory->getLastUsedSlot() - (mOffset - 1); // Count from 0, usage from 2 addMouseListener(this); addWidgetListener(this); @@ -76,7 +76,7 @@ void ItemContainer::logic() gcn::Widget::logic(); - int i = mInventory->getLastUsedSlot() - 1; // Count from 0, usage from 2 + int i = mInventory->getLastUsedSlot() - (mOffset - 1); // Count from 0, usage from 2 if (i != mMaxItems) { diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index e7a9afbe..abe81537 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -64,22 +64,6 @@ ItemShortcutContainer::~ItemShortcutContainer() delete mItemPopup; } -void ItemShortcutContainer::logic() -{ - if (!isVisible()) - return; - - gcn::Widget::logic(); - - int i = itemShortcut->getItemCount(); - - if (i != mMaxItems) - { - mMaxItems = i; - setWidth(getWidth()); - } -} - void ItemShortcutContainer::draw(gcn::Graphics *graphics) { if (!isVisible()) diff --git a/src/gui/itemshortcutcontainer.h b/src/gui/itemshortcutcontainer.h index f6137af0..0149754e 100644 --- a/src/gui/itemshortcutcontainer.h +++ b/src/gui/itemshortcutcontainer.h @@ -49,11 +49,6 @@ class ItemShortcutContainer : public ShortcutContainer */ virtual ~ItemShortcutContainer(); - /** - * Handles the logic of the ItemContainer - */ - void logic(); - /** * Draws the items. */ diff --git a/src/gui/shortcutcontainer.cpp b/src/gui/shortcutcontainer.cpp index 50ec9d06..fcb33279 100644 --- a/src/gui/shortcutcontainer.cpp +++ b/src/gui/shortcutcontainer.cpp @@ -43,13 +43,12 @@ void ShortcutContainer::widgetResized(const gcn::Event &event) if (mGridWidth < 1) mGridWidth = 1; + setHeight((mMaxItems / mGridWidth) * mBoxHeight); + mGridHeight = getHeight() / mBoxHeight; if (mGridHeight < 1) mGridHeight = 1; - - setHeight((mMaxItems / mGridWidth + - (mMaxItems % mGridWidth > 0 ? 1 : 0)) * mBoxHeight); } int ShortcutContainer::getIndexFromGrid(int pointX, int pointY) const diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp new file mode 100644 index 00000000..856f9166 --- /dev/null +++ b/src/gui/storagewindow.cpp @@ -0,0 +1,213 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include +#include + +#include + +#include "button.h" +#include "inventorywindow.h" +#include "item_amount.h" +#include "itemcontainer.h" +#include "progressbar.h" +#include "scrollarea.h" +#include "storagewindow.h" +#include "viewport.h" + +#include "widgets/layout.h" + +#include "../inventory.h" +#include "../item.h" +#include "../localplayer.h" + +#include "../net/messageout.h" +#include "../net/network.h" +#include "../net/protocol.h" + +#include "../resources/iteminfo.h" + +#include "../utils/gettext.h" +#include "../utils/strprintf.h" +#include "../utils/stringutils.h" + +StorageWindow::StorageWindow(Network *network, int invSize): + Window(_("Storage")), + mNetwork(network), + mMaxSlots(invSize), + mItemDesc(false) +{ + setWindowName("Storage"); + setResizable(true); + + // If you adjust these defaults, don't forget to adjust the trade window's. + setDefaultSize(115, 25, 375, 300); + + mCancelButton = new Button(_("Close"), "close", this); + mStoreButton = new Button(_("Store"), "store", this); + mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); + + mItems = new ItemContainer(player_node->getStorage(), 1); + mItems->addSelectionListener(this); + + mInvenScroll = new ScrollArea(mItems); + mInvenScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsLabel = new gcn::Label(_("Slots: ")); + + mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); + + setMinHeight(130); + setMinWidth(mSlotsLabel->getWidth()); + + place(0, 0, mSlotsLabel).setPadding(3); + place(1, 0, mSlotsBar, 3); + place(0, 1, mInvenScroll, 4, 4); + place(0, 5, mCancelButton); + place(2, 5, mStoreButton); + place(3, 5, mRetrieveButton); + + Layout &layout = getLayout(); + layout.setRowHeight(0, mStoreButton->getHeight()); + + loadWindowState(); + setLocationRelativeTo(getParent()); +} + +StorageWindow::~StorageWindow() +{ + delete mItems; +} + +void StorageWindow::logic() +{ + if (!isVisible()) + return; + + Window::logic(); + + if (mUsedSlots != toString(player_node->getStorage()->getNumberOfSlotsUsed())) + { + mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); + + mSlotsBar->setProgress((float) + player_node->getStorage()->getNumberOfSlotsUsed() / mMaxSlots); + + mSlotsBar->setText(strprintf("%s/%d", mUsedSlots.c_str(), mMaxSlots)); + } +} + +void StorageWindow::action(const gcn::ActionEvent &event) +{ + if (event.getId() == "close") + { + close(); + } + else if (event.getId() == "store") + { + Item *item = inventoryWindow->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + addStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_ADD, this, item); + } + } + else if (event.getId() == "retrieve") + { + Item *item = mItems->getSelectedItem(); + + if (!item) + return; + + if (item->getQuantity() == 1) + { + removeStore(item, 1); + } + else + { + // Choose amount of items to trade + new ItemAmountWindow(AMOUNT_STORE_REMOVE, this, item); + } + } +} + +void StorageWindow::mouseClicked(gcn::MouseEvent &event) +{ + Window::mouseClicked(event); + + if (event.getButton() == gcn::MouseEvent::RIGHT) + { + Item *item = mItems->getSelectedItem(); + + if (!item) { + mRetrieveButton->setEnabled(false); + return; + } + + mRetrieveButton->setEnabled(true); + + /* Convert relative to the window coordinates to absolute screen + * coordinates. + */ + const int mx = event.getX() + getX(); + const int my = event.getY() + getY(); + viewport->showPopup(mx, my, item); + } +} + +Item* StorageWindow::getSelectedItem() const +{ + return mItems->getSelectedItem(); +} + +void StorageWindow::addStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_MOVE_TO_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::removeStore(Item* item, int ammount) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CSMG_MOVE_FROM_STORAGE); + outMsg.writeInt16(item->getInvIndex()); + outMsg.writeInt32(ammount); +} + +void StorageWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_CLOSE_STORAGE); +} diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h new file mode 100644 index 00000000..23142ac1 --- /dev/null +++ b/src/gui/storagewindow.h @@ -0,0 +1,105 @@ +/* + * The Mana World + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef STORAGEWINDOW_H +#define STORAGEWINDOW_H + +#include "window.h" + +#include "../inventory.h" + +#include +#include + +class Item; +class ItemContainer; +class Network; +class ProgressBar; +class TextBox; + +/** + * Storage dialog. + * + * \ingroup Interface + */ +class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener +{ + public: + /** + * Constructor. + */ + StorageWindow(Network *network, int invSize = (STORAGE_SIZE - 1)); + + /** + * Destructor. + */ + ~StorageWindow(); + + /** + * Logic (updates buttons and weight information). + */ + void logic(); + + /** + * Called when receiving actions from the widgets. + */ + void action(const gcn::ActionEvent &event); + + /** + * Returns the selected item. + */ + Item* getSelectedItem() const; + + void mouseClicked(gcn::MouseEvent &event); + + /** + * Add the specified ammount of the specified item to storage + */ + void addStore(Item* item, int ammount); + + /** + * Remove the specified ammount of the specified item from storage + */ + void removeStore(Item* item, int ammount); + + void close(); + + private: + Network *mNetwork; + ItemContainer *mItems; + + std::string mSlots; + std::string mUsedSlots; + gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton; + gcn::ScrollArea *mInvenScroll; + + gcn::Label *mSlotsLabel; + + ProgressBar *mSlotsBar; + + int mMaxSlots; + + bool mItemDesc; +}; + +extern StorageWindow *storageWindow; + +#endif // STORAGEWINDOW_H diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index a12b94ed..76795688 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -49,8 +49,8 @@ TradeWindow::TradeWindow(Network *network): Window(_("Trade: You")), mNetwork(network), - mMyInventory(new Inventory(INVENTORY_SIZE)), - mPartnerInventory(new Inventory(INVENTORY_SIZE)) + mMyInventory(new Inventory(INVENTORY_SIZE, 2)), + mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) { setWindowName(_("Trade")); setDefaultSize(115, 227, 342, 209); diff --git a/src/gui/window.h b/src/gui/window.h index 0a0f4be9..a4f56e05 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -63,7 +63,7 @@ class Window : public gcn::Window, gcn::WidgetListener * @param skin The location where the window's skin XML can be found. */ Window(const std::string &caption = "Window", bool modal = false, - Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); + Window *parent = NULL, const std::string &skin = "graphics/gui/gui.xml"); /** * Destructor. Deletes all the added widgets. @@ -153,8 +153,7 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets flag to show a title or not. */ - void setShowTitle(bool flag) - { mShowTitle = flag; } + void setShowTitle(bool flag) { mShowTitle = flag; } /** * Sets whether the window is sticky. A sticky window will not have diff --git a/src/inventory.cpp b/src/inventory.cpp index 4053bc96..d72e0e4a 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -34,8 +34,9 @@ struct SlotUsed : public std::unary_function } }; -Inventory::Inventory(int size): - mSize(size) +Inventory::Inventory(int size, int offset): + mSize(size), + mOffset(offset) { mItems = new Item*[mSize]; std::fill_n(mItems, mSize, (Item*) 0); @@ -51,7 +52,7 @@ Inventory::~Inventory() Item* Inventory::getItem(int index) const { - if (index < 0 || index >= INVENTORY_SIZE || !mItems[index] || mItems[index]->getQuantity() <= 0) + if (index < 0 || index >= mSize || !mItems[index] || mItems[index]->getQuantity() <= 0) return 0; return mItems[index]; @@ -127,7 +128,7 @@ bool Inventory::contains(Item *item) const int Inventory::getFreeSlot() const { - Item **i = std::find_if(mItems + 2, mItems + mSize, + Item **i = std::find_if(mItems, mItems + mSize, std::not1(SlotUsed())); return (i == mItems + mSize) ? -1 : (i - mItems); } @@ -148,5 +149,5 @@ int Inventory::getLastUsedSlot() const int Inventory::getInventorySize() const { - return INVENTORY_SIZE - 2; + return mSize - mOffset; } diff --git a/src/inventory.h b/src/inventory.h index 3b3ec507..e23f7657 100644 --- a/src/inventory.h +++ b/src/inventory.h @@ -26,6 +26,7 @@ class Item; #define INVENTORY_SIZE 102 +#define STORAGE_SIZE 301 class Inventory { @@ -33,7 +34,7 @@ class Inventory /** * Constructor. */ - Inventory(int size); + Inventory(int size, int offset); /** * Destructor. @@ -111,6 +112,7 @@ class Inventory protected: Item **mItems; /**< The holder of items */ int mSize; /**< The max number of inventory items */ + int mOffset; /**< Offset used by the inventory */ }; #endif diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 76d13a4b..d6acc48f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -37,6 +37,7 @@ #include "text.h" #include "gui/gui.h" +#include "gui/storagewindow.h" #include "net/messageout.h" #include "net/protocol.h" @@ -74,8 +75,8 @@ LocalPlayer::LocalPlayer(Uint32 id, Uint16 job, Map *map): mTargetTime(-1), mLastAction(-1), mLastTarget(-1), mWalkingDir(0), mDestX(0), mDestY(0), - mInventory(new Inventory(INVENTORY_SIZE)), - mStorage(new Inventory(STORAGE_SIZE)) + mInventory(new Inventory(INVENTORY_SIZE, 2)), + mStorage(new Inventory(STORAGE_SIZE, 1)) { // Variable to keep the local player from doing certain actions before a map // is initialized. e.g. drawing a player's name using the TextManager, since @@ -694,3 +695,9 @@ void LocalPlayer::loadTargetCursor(std::string filename, int width, int height, mTargetCursor[index][size] = currentCursor; } +void LocalPlayer::setInStorage(bool inStorage) +{ + mInStorage = inStorage; + + storageWindow->setVisible(inStorage); +} diff --git a/src/localplayer.h b/src/localplayer.h index 2fb8c615..85868750 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -30,9 +30,6 @@ // TODO move into some sane place... #define MAX_SLOT 2 -#define INVENTORY_SIZE 102 -#define STORAGE_SIZE 301 - class Equipment; class FloorItem; class ImageSet; @@ -194,7 +191,7 @@ class LocalPlayer : public Player * Accessors for mInStorage */ bool getInStorage() { return mInStorage; } - void setInStorage(bool inStorage) { mInStorage = inStorage; } + void setInStorage(bool inStorage); /** * Sets the amount of XP. Shows XP gaining effect if the player is on diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index b0511080..553ec8fd 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -34,6 +34,7 @@ #include "../log.h" #include "../gui/chat.h" +#include "../gui/storagewindow.h" #include "../resources/iteminfo.h" @@ -72,7 +73,6 @@ void InventoryHandler::handleMessage(MessageIn *msg) { case SMSG_PLAYER_INVENTORY: case SMSG_PLAYER_STORAGE_ITEMS: - case SMSG_PLAYER_STORAGE_EQUIP: switch (msg->getId()) { case SMSG_PLAYER_INVENTORY: // Clear inventory - this will be a complete refresh @@ -86,11 +86,10 @@ void InventoryHandler::handleMessage(MessageIn *msg) * clear storage here */ storage->clear(); - logger->log("Received SMSG_PLAYER_STORAGE_ITEMS"); break; default: - logger->log("Received SMSG_PLAYER_STORAGE_EQUIP"); - break; + logger->log("HOW DID WE GET HERE?"); + return; } msg->readInt16(); // length number = (msg->getLength() - 4) / 18; @@ -100,17 +99,8 @@ void InventoryHandler::handleMessage(MessageIn *msg) itemId = msg->readInt16(); itemType = msg->readInt8(); identified = msg->readInt8(); - if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { - amount = 1; - msg->readInt16(); // Equip Point? - } else { - amount = msg->readInt16(); - } + amount = msg->readInt16(); arrow = msg->readInt16(); - if (msg->getId() == SMSG_PLAYER_STORAGE_EQUIP) { - msg->readInt8(); // Attribute (broken) - msg->readInt8(); // Refine level - } for (int i = 0; i < 4; i++) cards[i] = msg->readInt16(); @@ -130,6 +120,29 @@ void InventoryHandler::handleMessage(MessageIn *msg) } break; + case SMSG_PLAYER_STORAGE_EQUIP: + msg->readInt16(); // length + number = (msg->getLength() - 4) / 20; + + for (int loop = 0; loop < number; loop++) { + index = msg->readInt16(); + itemId = msg->readInt16(); + itemType = msg->readInt8(); + identified = msg->readInt8(); + amount = 1; + msg->readInt16(); // Equip Point? + msg->readInt16(); // Another Equip Point? + msg->readInt8(); // Attribute (broken) + msg->readInt8(); // Refine level + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + logger->log("Index:%d, ID:%d, Type:%d, Identified:%d, Qty:%d, Cards:%d, %d, %d, %d", + index, itemId, itemType, identified, amount, cards[0], cards[1], cards[2], cards[3]); + storage->setItem(index, itemId, amount, false); + } + break; + case SMSG_PLAYER_INVENTORY_ADD: index = msg->readInt16(); amount = msg->readInt16(); @@ -203,35 +216,54 @@ void InventoryHandler::handleMessage(MessageIn *msg) case SMSG_PLAYER_STORAGE_STATUS: /* - * Basic slots used vs total slots info - * We don't really need this information, but this is - * the closest we get to an "Open Storage" packet - * from the server. It always comes after the two - * SMSG_PLAYER_STORAGE_... packets that update - * storage contents. + * This is the closest we get to an "Open Storage" packet from the + * server. It always comes after the two SMSG_PLAYER_STORAGE_... + * packets that update storage contents.. */ - logger->log("Received SMSG_PLAYER_STORAGE_STATUS"); player_node->setInStorage(true); + msg->readInt16(); // Storage capacity + msg->readInt16(); // Used count break; case SMSG_PLAYER_STORAGE_ADD: /* * Move an item into storage */ + index = msg->readInt16(); + amount = msg->readInt32(); + itemId = msg->readInt16(); + identified = msg->readInt8(); + msg->readInt8(); // attribute + msg->readInt8(); // refine + for (int i = 0; i < 4; i++) + cards[i] = msg->readInt16(); + + if (Item *item = storage->getItem(index)) { + item->setId(itemId); + item->increaseQuantity(amount); + } else { + storage->setItem(index, itemId, amount, false); + } break; case SMSG_PLAYER_STORAGE_REMOVE: /* - * Move an item out of storage - */ + * Move an item out of storage + */ + index = msg->readInt16(); + amount = msg->readInt16(); + if (Item *item = storage->getItem(index)) { + item->increaseQuantity(-amount); + if (item->getQuantity() == 0) + storage->removeItemAt(index); + } break; case SMSG_PLAYER_STORAGE_CLOSE: /* - * Storage access has been closed - */ + * Storage access has been closed + */ player_node->setInStorage(false); - logger->log("Received SMSG_PLAYER_STORAGE_CLOSE"); break; } } diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 232cf075..6533ac1e 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -39,6 +39,7 @@ #include "../gui/ok_dialog.h" #include "../gui/sell.h" #include "../gui/skill.h" +#include "../gui/storagewindow.h" #include "../gui/viewport.h" #include "../utils/stringutils.h" @@ -92,6 +93,7 @@ namespace { buyDialog->setVisible(false); sellDialog->setVisible(false); buySellDialog->setVisible(false); + if (storageWindow->isVisible()) storageWindow->close(); current_npc = 0; } } deathListener; -- cgit v1.2.3-70-g09d2 From 40883938ceb60b0999f9b693dadbe2239e83f139 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Mon, 9 Mar 2009 01:23:14 -0600 Subject: Got rid of an ugly and unified interface breaking cancel button in favor of adding overridable close functionality to the Window class. Now, if you need a close button, but need to do something different, or in addition to the Window close functionality, you can override it and do that action. Signed-off-by: Ira Rice --- src/gui/storagewindow.cpp | 9 ++------- src/gui/storagewindow.h | 2 +- src/gui/window.cpp | 7 ++++++- src/gui/window.h | 2 ++ src/inventory.cpp | 2 +- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 856f9166..d3bc7ef8 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -59,11 +59,11 @@ StorageWindow::StorageWindow(Network *network, int invSize): { setWindowName("Storage"); setResizable(true); + setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. setDefaultSize(115, 25, 375, 300); - mCancelButton = new Button(_("Close"), "close", this); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -85,7 +85,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): place(0, 0, mSlotsLabel).setPadding(3); place(1, 0, mSlotsBar, 3); place(0, 1, mInvenScroll, 4, 4); - place(0, 5, mCancelButton); place(2, 5, mStoreButton); place(3, 5, mRetrieveButton); @@ -121,11 +120,7 @@ void StorageWindow::logic() void StorageWindow::action(const gcn::ActionEvent &event) { - if (event.getId() == "close") - { - close(); - } - else if (event.getId() == "store") + if (event.getId() == "store") { Item *item = inventoryWindow->getSelectedItem(); diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 23142ac1..86451bfe 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -88,7 +88,7 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener std::string mSlots; std::string mUsedSlots; - gcn::Button *mCancelButton, *mStoreButton, *mRetrieveButton; + gcn::Button *mStoreButton, *mRetrieveButton; gcn::ScrollArea *mInvenScroll; gcn::Label *mSlotsLabel; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0869368d..2b422f86 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -328,7 +328,7 @@ void Window::mousePressed(gcn::MouseEvent &event) if (closeButtonRect.isPointInRect(x, y)) { - setVisible(false); + close(); } } @@ -337,6 +337,11 @@ void Window::mousePressed(gcn::MouseEvent &event) } } +void Window::close() +{ + setVisible(false); +} + void Window::mouseReleased(gcn::MouseEvent &event) { if (mGrip && mouseResize) diff --git a/src/gui/window.h b/src/gui/window.h index a4f56e05..3a92ac17 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -276,6 +276,8 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + virtual void close(); + protected: /** The window container windows add themselves to. */ static WindowContainer *windowContainer; diff --git a/src/inventory.cpp b/src/inventory.cpp index d72e0e4a..3d1a4786 100644 --- a/src/inventory.cpp +++ b/src/inventory.cpp @@ -128,7 +128,7 @@ bool Inventory::contains(Item *item) const int Inventory::getFreeSlot() const { - Item **i = std::find_if(mItems, mItems + mSize, + Item **i = std::find_if(mItems + mOffset, mItems + mSize, std::not1(SlotUsed())); return (i == mItems + mSize) ? -1 : (i - mItems); } -- cgit v1.2.3-70-g09d2 From d605691a3fe219cde175eb68239bea91ae2d91fd Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 9 Mar 2009 13:26:59 -0600 Subject: Send the correct packet for the NPC close button Both packets do the same, but we should be explicit anyways. Also, seperate out NPC client packets. --- src/gui/npc_text.cpp | 7 +++++++ src/gui/npc_text.h | 2 ++ src/net/npchandler.cpp | 2 +- src/net/protocol.h | 18 ++++++++++-------- 4 files changed, 20 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 954f22d8..61f3e510 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -126,6 +126,13 @@ void NpcTextDialog::nextDialog(int npcID) outMsg.writeInt32(npcID); } +void NpcTextDialog::closeDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_CLOSE); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 019c22a5..f030115b 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -79,6 +79,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void nextDialog(int npcID = current_npc); + void closeDialog(int npcID = current_npc); + /** * Called when resizing the window. * diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 487b358f..08ea8506 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -78,7 +78,7 @@ void NPCHandler::handleMessage(MessageIn *msg) npcTextDialog->showCloseButton(); // Otherwise, move on as an empty dialog doesn't help else - npcTextDialog->nextDialog(id); + npcTextDialog->closeDialog(id); break; case SMSG_NPC_NEXT: diff --git a/src/net/protocol.h b/src/net/protocol.h index e9053451..4b470d12 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -121,30 +121,32 @@ #define CMSG_TRADE_RESPONSE 0x00e6 #define CMSG_ITEM_PICKUP 0x009f #define CMSG_MAP_LOADED 0x007d -#define CMSG_NPC_BUY_REQUEST 0x00c8 -#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 #define CMSG_CHAT_MESSAGE 0x008c #define CMSG_CHAT_WHISPER 0x0096 #define CMSG_CHAT_ANNOUNCE 0x0099 #define CMSG_CHAT_WHO 0x00c1 -#define CMSG_NPC_LIST_CHOICE 0x00b8 -#define CMSG_NPC_NEXT_REQUEST 0x00b9 -#define CMSG_NPC_SELL_REQUEST 0x00c9 -#define CMSG_NPC_INT_RESPONSE 0x0143 -#define CMSG_NPC_STR_RESPONSE 0x01d5 #define CMSG_SKILL_LEVELUP_REQUEST 0x0112 #define CMSG_STAT_UPDATE_REQUEST 0x00bb #define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8 #define CMSG_TRADE_CANCEL_REQUEST 0x00ed #define CMSG_TRADE_ADD_COMPLETE 0x00eb #define CMSG_TRADE_OK 0x00ef -#define CMSG_NPC_TALK 0x0090 #define CMSG_TRADE_REQUEST 0x00e4 #define CMSG_PLAYER_INVENTORY_USE 0x00a7 #define CMSG_PLAYER_INVENTORY_DROP 0x00a2 #define CMSG_PLAYER_EQUIP 0x00a9 #define CMSG_PLAYER_UNEQUIP 0x00ab +#define CMSG_NPC_TALK 0x0090 +#define CMSG_NPC_NEXT_REQUEST 0x00b9 +#define CMSG_NPC_CLOSE 0x0146 +#define CMSG_NPC_LIST_CHOICE 0x00b8 +#define CMSG_NPC_INT_RESPONSE 0x0143 +#define CMSG_NPC_STR_RESPONSE 0x01d5 +#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 +#define CMSG_NPC_BUY_REQUEST 0x00c8 +#define CMSG_NPC_SELL_REQUEST 0x00c9 + #define CMSG_PARTY_CREATE 0x00f9 #define CMSG_PARTY_INVITE 0x00fc #define CMSG_PARTY_INVITED 0x00ff -- cgit v1.2.3-70-g09d2 From 4463387e133b0cd238ebb1ff89b8362fc2adbe75 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Mon, 9 Mar 2009 13:26:59 -0600 Subject: Send the correct packet for the NPC close button Both packets do the same, but we should be explicit anyways. Also, seperate out NPC client packets. --- src/gui/npc_text.cpp | 8 ++++++++ src/gui/npc_text.h | 2 ++ src/gui/npclistdialog.cpp | 4 ++-- src/net/npchandler.cpp | 1 + src/net/protocol.h | 18 ++++++++++-------- 5 files changed, 23 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index b94e8aa4..ec8a4b6e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -38,6 +38,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Window(_("NPC")), mNetwork(network) { setResizable(true); + setCloseButton(true); setMinWidth(200); setMinHeight(150); @@ -103,6 +104,13 @@ void NpcTextDialog::nextDialog(int npcID) outMsg.writeInt32(npcID); } +void NpcTextDialog::closeDialog(int npcID) +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_NPC_CLOSE); + outMsg.writeInt32(npcID); +} + void NpcTextDialog::widgetResized(const gcn::Event &event) { Window::widgetResized(event); diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index a72de5d0..615902db 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -76,6 +76,8 @@ class NpcTextDialog : public Window, public gcn::ActionListener void nextDialog(int npcID = current_npc); + void closeDialog(int npcID = current_npc); + /** * Called when resizing the window. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 73b00239..c639411d 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -58,8 +58,8 @@ NpcListDialog::NpcListDialog(Network *network): scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); place(0, 0, scrollArea, 5).setPadding(3); - place(3, 1, okButton); - place(4, 1, cancelButton); + place(3, 1, cancelButton); + place(4, 1, okButton); Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 1161bc36..41af4467 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -76,6 +76,7 @@ void NPCHandler::handleMessage(MessageIn *msg) id = msg->readInt32(); if (current_npc == id) current_npc = 0; + npcTextDialog->closeDialog(id); break; case SMSG_NPC_NEXT: diff --git a/src/net/protocol.h b/src/net/protocol.h index 081f8873..645d667f 100644 --- a/src/net/protocol.h +++ b/src/net/protocol.h @@ -122,30 +122,32 @@ #define CMSG_TRADE_RESPONSE 0x00e6 #define CMSG_ITEM_PICKUP 0x009f #define CMSG_MAP_LOADED 0x007d -#define CMSG_NPC_BUY_REQUEST 0x00c8 -#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 #define CMSG_CHAT_MESSAGE 0x008c #define CMSG_CHAT_WHISPER 0x0096 #define CMSG_CHAT_ANNOUNCE 0x0099 #define CMSG_CHAT_WHO 0x00c1 -#define CMSG_NPC_LIST_CHOICE 0x00b8 -#define CMSG_NPC_NEXT_REQUEST 0x00b9 -#define CMSG_NPC_SELL_REQUEST 0x00c9 -#define CMSG_NPC_INT_RESPONSE 0x0143 -#define CMSG_NPC_STR_RESPONSE 0x01d5 #define CMSG_SKILL_LEVELUP_REQUEST 0x0112 #define CMSG_STAT_UPDATE_REQUEST 0x00bb #define CMSG_TRADE_ITEM_ADD_REQUEST 0x00e8 #define CMSG_TRADE_CANCEL_REQUEST 0x00ed #define CMSG_TRADE_ADD_COMPLETE 0x00eb #define CMSG_TRADE_OK 0x00ef -#define CMSG_NPC_TALK 0x0090 #define CMSG_TRADE_REQUEST 0x00e4 #define CMSG_PLAYER_INVENTORY_USE 0x00a7 #define CMSG_PLAYER_INVENTORY_DROP 0x00a2 #define CMSG_PLAYER_EQUIP 0x00a9 #define CMSG_PLAYER_UNEQUIP 0x00ab +#define CMSG_NPC_TALK 0x0090 +#define CMSG_NPC_NEXT_REQUEST 0x00b9 +#define CMSG_NPC_CLOSE 0x0146 +#define CMSG_NPC_LIST_CHOICE 0x00b8 +#define CMSG_NPC_INT_RESPONSE 0x0143 +#define CMSG_NPC_STR_RESPONSE 0x01d5 +#define CMSG_NPC_BUY_SELL_REQUEST 0x00c5 +#define CMSG_NPC_BUY_REQUEST 0x00c8 +#define CMSG_NPC_SELL_REQUEST 0x00c9 + #define CMSG_PARTY_CREATE 0x00f9 #define CMSG_PARTY_INVITE 0x00fc #define CMSG_PARTY_INVITED 0x00ff -- cgit v1.2.3-70-g09d2 From 881f3c693e2ac4d17f2e7109a809d1bd4c2f62c6 Mon Sep 17 00:00:00 2001 From: Kess Vargavind Date: Mon, 16 Feb 2009 17:22:38 +0100 Subject: Expand the scope where item links work This patch makes item links work in any chatLog() message, not only chatSend() as before. I enabled it for the "You picked " message by explicitly adding [] around the item name in the string. --- src/gui/chat.cpp | 62 ++++++++++++++++++++++---------------------- src/net/inventoryhandler.cpp | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 20d0213b..26eaf488 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -223,6 +223,37 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << (int) ((t / 60) % 60) << "] "; + // Check for item link + std::string::size_type start = msg.find('['); + while (start != std::string::npos && msg[start+1] != '@') + { + std::string::size_type end = msg.find(']', start); + if (start+1 != end && end != std::string::npos) + { + // Catch multiple embeds and ignore them + // so it doesn't crash the client. + while ((msg.find('[', start + 1) != std::string::npos) && + (msg.find('[', start + 1) < end)) + { + start = msg.find('[', start + 1); + } + + std::string temp = msg.substr(start + 1, end - start - 1); + + toLower(trim(temp)); + + const ItemInfo itemInfo = ItemDB::get(temp); + if (itemInfo.getName() != _("Unknown item")) + { + msg.insert(end, "@@"); + msg.insert(start+1, "|"); + msg.insert(start+1, toString(itemInfo.getId())); + msg.insert(start+1, "@@"); + } + } + start = msg.find('[', start + 1); + } + line = lineColor + timeStr.str() + tmp.nick + tmp.text; // We look if the Vertical Scroll Bar is set at the max before @@ -389,37 +420,6 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) return; } - // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') - { - std::string::size_type end = msg.find(']', start); - if (start+1 != end && end != std::string::npos) - { - // Catch multiple embeds and ignore them - // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) - { - start = msg.find('[', start + 1); - } - - std::string temp = msg.substr(start + 1, end - start - 1); - - toLower(trim(temp)); - - const ItemInfo itemInfo = ItemDB::get(temp); - if (itemInfo.getName() != _("Unknown item")) - { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); - } - } - start = msg.find('[', start + 1); - } - // Prepare ordinary message if (msg.substr(0, 1) != "/") { diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 243d1e79..7d33b419 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -163,7 +163,7 @@ void InventoryHandler::handleMessage(MessageIn *msg) const std::string amountStr = (amount > 1) ? toString(amount) : "a"; if (config.getValue("showpickupchat", true)) { - chatWindow->chatLog(strprintf(_("You picked up %s %s"), + chatWindow->chatLog(strprintf(_("You picked up %s [%s]"), amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); } -- cgit v1.2.3-70-g09d2 From 9e7dfd7397ed2c282015f4cc13c42598b6bb1f39 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:15:20 -0600 Subject: Remove some tabs and trailing whitespace --- src/gui/chat.cpp | 16 ++++++++-------- src/gui/confirm_dialog.cpp | 4 ++-- src/gui/debugwindow.cpp | 2 +- src/gui/listbox.cpp | 2 +- src/gui/ok_dialog.cpp | 6 +++--- src/gui/setup_players.cpp | 4 ++-- src/gui/shop.h | 2 +- src/gui/widgets/dropdown.cpp | 6 +++--- src/map.cpp | 2 +- src/shopitem.h | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 26eaf488..702327a5 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -140,12 +140,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -622,9 +622,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index fbbc6101..0d41525a 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -56,7 +56,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, { // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); @@ -67,7 +67,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + fontHeight, (2 * fontHeight) + + setContentSize(width + fontHeight, (2 * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 33304944..cf2f9613 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -70,7 +70,7 @@ void DebugWindow::logic() mFPSLabel->setCaption(toString(fps) + " FPS"); - mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 2f7d2f7f..cd5aa736 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -111,7 +111,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } else if (key.getValue() == gcn::Key::UP) { - setSelected(mSelected - 1); + setSelected(mSelected - 1); keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index d73c7d7c..4f4f1117 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -52,10 +52,10 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, if (numRows > 1) { // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + okButton->getHeight()); - mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * fontHeight))); + mTextArea->setDimension(gcn::Rectangle(4, 5, + mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); } else { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 96792436..84dbed55 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -329,7 +329,7 @@ void Setup_Players::apply() ~(PlayerRelation::TRADE | PlayerRelation::WHISPER); player_relations.setDefault(old_default_relations - | (mDefaultTrading->isSelected() ? + | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); @@ -341,7 +341,7 @@ void Setup_Players::cancel() void Setup_Players::action(const gcn::ActionEvent &event) { - if (event.getId() == ACTION_TABLE) + 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 diff --git a/src/gui/shop.h b/src/gui/shop.h index faffe7e3..0c900d9d 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -37,7 +37,7 @@ class ShopItem; * The addItem routine can automatically check, if an item already exists and * only adds duplicates to the old item, if one is found. The original * distribution of the duplicates can be retrieved from the item. - * + * * This functionality can be enabled in the constructor. */ class ShopItems : public gcn::ListModel diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index eef9ae33..e1a24cb7 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -78,10 +78,10 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, { for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], - gridx[x + 1] - + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - + gridy[y + 1] - gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; diff --git a/src/map.cpp b/src/map.cpp index 814b4225..39e6d0a5 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -85,7 +85,7 @@ void TileAnimation::update() Image *img = mAnimation->getCurrentImage(); if (img != mLastImage) { - for (std::list >::iterator i = + for (std::list >::iterator i = mAffected.begin(); i != mAffected.end(); i++) { i->first->setTile(i->second, img); diff --git a/src/shopitem.h b/src/shopitem.h index 3b00a3c8..cbe0a06f 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -95,7 +95,7 @@ class ShopItem : public Item * Reduces the quantity of the topmost duplicate by the specified * amount. Also reduces the total quantity of this DuplicateItem. * Empty duplicates are automatically removed. - * + * * If the amount is bigger than the quantity of the current topmost, * only sell as much as possible. Returns the amount actually sold (do * not ignore the return value!) -- cgit v1.2.3-70-g09d2 From a872eb3364eec4a9778692a1e529aa506c9e09ca Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:25:49 -0600 Subject: Fix typo in item link parsing --- src/gui/chat.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 702327a5..8ecb5f63 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -224,34 +224,39 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << "] "; // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') + std::string::size_type start = tmp.text.find('['); + while (start != std::string::npos && tmp.text[start+1] != '@') { - std::string::size_type end = msg.find(']', start); + std::string::size_type end = tmp.text.find(']', start); if (start+1 != end && end != std::string::npos) { // Catch multiple embeds and ignore them // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) + while ((tmp.text.find('[', start + 1) != std::string::npos) && + (tmp.text.find('[', start + 1) < end)) { - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } - std::string temp = msg.substr(start + 1, end - start - 1); + std::string temp = tmp.text.substr(start+1, end - start - 1); - toLower(trim(temp)); + trim(temp); + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); + tmp.text.insert(end, "@@"); + tmp.text.insert(start+1, "|"); + tmp.text.insert(start+1, toString(itemInfo.getId())); + tmp.text.insert(start+1, "@@"); } } - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } line = lineColor + timeStr.str() + tmp.nick + tmp.text; -- cgit v1.2.3-70-g09d2 From 2ef75627a69a02609e6753d7c3f1189ca3071b07 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:29:18 -0600 Subject: Fix layout issue of NPC list dialog --- src/gui/npclistdialog.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f5479efc..66c2d9a0 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -68,6 +68,7 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); + resetToDefaultSize(); setLocationRelativeTo(getParent()); } -- cgit v1.2.3-70-g09d2 From 7aeec98b0d2ff6c034c78e9ae6572179a808cfc5 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:37:44 +0100 Subject: Fix video config cancel button for "show name". The cancel button in Video configuration window doesn't switch back the "show name" setting to the original state. This patch fixes that. --- src/gui/setup_video.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gui') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index e89afd94..ad133e7e 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -413,6 +413,8 @@ void Setup_Video::cancel() config.setValue("particleeffects", mParticleEffectsEnabled ? true : false); config.setValue("speech", mSpeechMode); config.setValue("showownname", mNameEnabled ? true : false); + if (player_node) + player_node->mUpdateName = true; config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); config.setValue("showpickupchat", mPickupChatEnabled ? true : false); -- cgit v1.2.3-70-g09d2 From 2d6e867ba8306bc662b9cf42dd403f2ebcb140a6 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:15:20 -0600 Subject: Remove some tabs and trailing whitespace --- src/gui/chat.cpp | 16 ++++++++-------- src/gui/confirm_dialog.cpp | 4 ++-- src/gui/debugwindow.cpp | 2 +- src/gui/listbox.cpp | 2 +- src/gui/ok_dialog.cpp | 6 +++--- src/gui/setup_players.cpp | 4 ++-- src/gui/shop.h | 2 +- src/gui/widgets/dropdown.cpp | 6 +++--- src/map.cpp | 2 +- src/shopitem.h | 2 +- 10 files changed, 23 insertions(+), 23 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 91e410ce..47fadc8d 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -141,12 +141,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -615,9 +615,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 2bc330c0..f4b49251 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -57,7 +57,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, { // fontHeight == height of each line of text (based on font heights) // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); @@ -68,7 +68,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, width = getFont()->getWidth(msg); if (width < inWidth) width = inWidth; - setContentSize(width + fontHeight, (2 * fontHeight) + + setContentSize(width + fontHeight, (2 * fontHeight) + noButton->getHeight()); mTextArea->setDimension(gcn::Rectangle(4, 5, width + 5, 17)); } diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 1a805dd4..dafd604a 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -71,7 +71,7 @@ void DebugWindow::logic() mFPSLabel->setCaption(toString(fps) + " FPS"); - mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + + mTileMouseLabel->setCaption("Tile: (" + toString(mouseTileX) + ", " + toString(mouseTileY) + ")"); Map *currentMap = engine->getCurrentMap(); diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 6d5c0ca8..82011239 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -112,7 +112,7 @@ void ListBox::keyPressed(gcn::KeyEvent& keyEvent) } else if (key.getValue() == gcn::Key::UP) { - setSelected(mSelected - 1); + setSelected(mSelected - 1); keyEvent.consume(); } else if (key.getValue() == gcn::Key::DOWN) diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 9621b389..d3e7bec6 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -53,10 +53,10 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, if (numRows > 1) { // 14 == row top + bottom graphic pixel heights - setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * + setContentSize(mTextBox->getMinWidth() + fontHeight, ((numRows + 1) * fontHeight) + okButton->getHeight()); - mTextArea->setDimension(gcn::Rectangle(4, 5, mTextBox->getMinWidth() + 5, - 3 + (numRows * fontHeight))); + mTextArea->setDimension(gcn::Rectangle(4, 5, + mTextBox->getMinWidth() + 5, 3 + (numRows * fontHeight))); } else { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 9105d44a..faf80640 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -330,7 +330,7 @@ void Setup_Players::apply() ~(PlayerRelation::TRADE | PlayerRelation::WHISPER); player_relations.setDefault(old_default_relations - | (mDefaultTrading->isSelected() ? + | (mDefaultTrading->isSelected() ? PlayerRelation::TRADE : 0) | (mDefaultWhisper->isSelected() ? PlayerRelation::WHISPER : 0)); @@ -342,7 +342,7 @@ void Setup_Players::cancel() void Setup_Players::action(const gcn::ActionEvent &event) { - if (event.getId() == ACTION_TABLE) + 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 diff --git a/src/gui/shop.h b/src/gui/shop.h index 26a9429d..118847f9 100644 --- a/src/gui/shop.h +++ b/src/gui/shop.h @@ -38,7 +38,7 @@ class ShopItem; * The addItem routine can automatically check, if an item already exists and * only adds duplicates to the old item, if one is found. The original * distribution of the duplicates can be retrieved from the item. - * + * * This functionality can be enabled in the constructor. */ class ShopItems : public gcn::ListModel diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 9fcf173c..035ce5d7 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -79,10 +79,10 @@ DropDown::DropDown(gcn::ListModel *listModel, gcn::ScrollArea *scrollArea, { for (x = 0; x < 3; x++) { - skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], - gridx[x + 1] - + skin.grid[a] = boxBorder->getSubImage(gridx[x], gridy[y], + gridx[x + 1] - gridx[x] + 1, - gridy[y + 1] - + gridy[y + 1] - gridy[y] + 1); skin.grid[a]->setAlpha(mAlpha); a++; diff --git a/src/map.cpp b/src/map.cpp index b780b5cc..bda618e2 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -86,7 +86,7 @@ void TileAnimation::update() Image *img = mAnimation->getCurrentImage(); if (img != mLastImage) { - for (std::list >::iterator i = + for (std::list >::iterator i = mAffected.begin(); i != mAffected.end(); i++) { i->first->setTile(i->second, img); diff --git a/src/shopitem.h b/src/shopitem.h index 18608a94..afc48bf5 100644 --- a/src/shopitem.h +++ b/src/shopitem.h @@ -96,7 +96,7 @@ class ShopItem : public Item * Reduces the quantity of the topmost duplicate by the specified * amount. Also reduces the total quantity of this DuplicateItem. * Empty duplicates are automatically removed. - * + * * If the amount is bigger than the quantity of the current topmost, * only sell as much as possible. Returns the amount actually sold (do * not ignore the return value!) -- cgit v1.2.3-70-g09d2 From ec838fe4abf3d1003c654d3b6902a4f145d0fb5a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 07:29:56 -0600 Subject: Fixed an indentation error in the last commit. Signed-off-by: Ira Rice --- src/gui/chat.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 47fadc8d..9ae1be2c 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -141,12 +141,12 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) // *implements actions in a backwards compatible way* if (own == BY_PLAYER && - tmp.text.at(0) == '*' && - tmp.text.at(tmp.text.length()-1) == '*') + tmp.text.at(0) == '*' && + tmp.text.at(tmp.text.length()-1) == '*') { - tmp.text[0] = ' '; - tmp.text.erase(tmp.text.length() - 1); - own = ACT_IS; + tmp.text[0] = ' '; + tmp.text.erase(tmp.text.length() - 1); + own = ACT_IS; } std::string lineColor = "##C"; @@ -615,9 +615,9 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) } else if (command == "me") { - std::stringstream actionStr; - actionStr << "*" << msg << "*"; - chatSend(player_node->getName(), actionStr.str()); + std::stringstream actionStr; + actionStr << "*" << msg << "*"; + chatSend(player_node->getName(), actionStr.str()); } else { -- cgit v1.2.3-70-g09d2 From 3f322e9eec45751686c59ec89bee46d1da34c885 Mon Sep 17 00:00:00 2001 From: Kess Vargavind Date: Mon, 16 Feb 2009 17:22:38 +0100 Subject: Expand the scope where item links work This patch makes item links work in any chatLog() message, not only chatSend() as before. I enabled it for the "You picked " message by explicitly adding [] around the item name in the string. --- src/gui/chat.cpp | 62 ++++++++++++++++++++++---------------------- src/net/inventoryhandler.cpp | 2 +- 2 files changed, 32 insertions(+), 32 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 9ae1be2c..fd2b05e4 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -221,6 +221,37 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << (int) ((t / 60) % 60) << "] "; + // Check for item link + std::string::size_type start = msg.find('['); + while (start != std::string::npos && msg[start+1] != '@') + { + std::string::size_type end = msg.find(']', start); + if (start+1 != end && end != std::string::npos) + { + // Catch multiple embeds and ignore them + // so it doesn't crash the client. + while ((msg.find('[', start + 1) != std::string::npos) && + (msg.find('[', start + 1) < end)) + { + start = msg.find('[', start + 1); + } + + std::string temp = msg.substr(start + 1, end - start - 1); + + toLower(trim(temp)); + + const ItemInfo itemInfo = ItemDB::get(temp); + if (itemInfo.getName() != _("Unknown item")) + { + msg.insert(end, "@@"); + msg.insert(start+1, "|"); + msg.insert(start+1, toString(itemInfo.getId())); + msg.insert(start+1, "@@"); + } + } + start = msg.find('[', start + 1); + } + line = lineColor + timeStr.str() + tmp.nick + tmp.text; // We look if the Vertical Scroll Bar is set at the max before @@ -382,37 +413,6 @@ void ChatWindow::chatSend(const std::string &nick, std::string msg) return; } - // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') - { - std::string::size_type end = msg.find(']', start); - if (start+1 != end && end != std::string::npos) - { - // Catch multiple embeds and ignore them - // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) - { - start = msg.find('[', start + 1); - } - - std::string temp = msg.substr(start + 1, end - start - 1); - - toLower(trim(temp)); - - const ItemInfo itemInfo = ItemDB::get(temp); - if (itemInfo.getName() != _("Unknown item")) - { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); - } - } - start = msg.find('[', start + 1); - } - // Prepare ordinary message if (msg.substr(0, 1) != "/") { diff --git a/src/net/inventoryhandler.cpp b/src/net/inventoryhandler.cpp index 553ec8fd..9fcfedf1 100644 --- a/src/net/inventoryhandler.cpp +++ b/src/net/inventoryhandler.cpp @@ -164,7 +164,7 @@ void InventoryHandler::handleMessage(MessageIn *msg) const std::string amountStr = (amount > 1) ? toString(amount) : "a"; if (config.getValue("showpickupchat", true)) { - chatWindow->chatLog(strprintf(_("You picked up %s %s"), + chatWindow->chatLog(strprintf(_("You picked up %s [%s]"), amountStr.c_str(), itemInfo.getName().c_str()), BY_SERVER); } -- cgit v1.2.3-70-g09d2 From 0fb4dc37c61341a237bab30896bd2c457222ed03 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 05:25:49 -0600 Subject: Fix typo in item link parsing --- src/gui/chat.cpp | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index fd2b05e4..5cf8b739 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -222,34 +222,39 @@ void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) << "] "; // Check for item link - std::string::size_type start = msg.find('['); - while (start != std::string::npos && msg[start+1] != '@') + std::string::size_type start = tmp.text.find('['); + while (start != std::string::npos && tmp.text[start+1] != '@') { - std::string::size_type end = msg.find(']', start); + std::string::size_type end = tmp.text.find(']', start); if (start+1 != end && end != std::string::npos) { // Catch multiple embeds and ignore them // so it doesn't crash the client. - while ((msg.find('[', start + 1) != std::string::npos) && - (msg.find('[', start + 1) < end)) + while ((tmp.text.find('[', start + 1) != std::string::npos) && + (tmp.text.find('[', start + 1) < end)) { - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } - std::string temp = msg.substr(start + 1, end - start - 1); + std::string temp = tmp.text.substr(start+1, end - start - 1); - toLower(trim(temp)); + trim(temp); + + for (unsigned int i = 0; i < temp.size(); i++) + { + temp[i] = (char) tolower(temp[i]); + } const ItemInfo itemInfo = ItemDB::get(temp); if (itemInfo.getName() != _("Unknown item")) { - msg.insert(end, "@@"); - msg.insert(start+1, "|"); - msg.insert(start+1, toString(itemInfo.getId())); - msg.insert(start+1, "@@"); + tmp.text.insert(end, "@@"); + tmp.text.insert(start+1, "|"); + tmp.text.insert(start+1, toString(itemInfo.getId())); + tmp.text.insert(start+1, "@@"); } } - start = msg.find('[', start + 1); + start = tmp.text.find('[', start + 1); } line = lineColor + timeStr.str() + tmp.nick + tmp.text; -- cgit v1.2.3-70-g09d2 From 03507766fa4ee07491b7ee702093669de6222c9c Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Mon, 23 Feb 2009 19:37:44 +0100 Subject: Fix video config cancel button for "show name". The cancel button in Video configuration window doesn't switch back the "show name" setting to the original state. This patch fixes that. --- src/gui/setup_video.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gui') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 7e3d483c..59eb4096 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -414,6 +414,8 @@ void Setup_Video::cancel() config.setValue("particleeffects", mParticleEffectsEnabled ? true : false); config.setValue("speech", mSpeechMode); config.setValue("showownname", mNameEnabled ? true : false); + if (player_node) + player_node->mUpdateName = true; config.setValue("guialpha", mOpacity); config.setValue("opengl", mOpenGLEnabled ? true : false); config.setValue("showpickupchat", mPickupChatEnabled ? true : false); -- cgit v1.2.3-70-g09d2 From 443a10db52e909c4c2a33543795ec8837547e973 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:11:48 -0600 Subject: Made it so that when windows load previous states, they are never smaller than the minimum width and height (a check that should have been enforced in the first place), as well as modified the NPC list and text dialogs to remember where they were when they were moved or resized last. Signed-off-by: Ira Rice --- src/gui/npc_text.cpp | 11 +++++++++-- src/gui/npc_text.h | 13 +++++++++++++ src/gui/npclistdialog.cpp | 6 +++++- src/gui/npclistdialog.h | 3 ++- src/gui/window.cpp | 41 +++++++++++++++++++++++++---------------- src/gui/window.h | 6 ++++++ src/net/npchandler.cpp | 3 +-- 7 files changed, 61 insertions(+), 22 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index ec8a4b6e..58aa0c5e 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -35,10 +35,10 @@ #include "../utils/gettext.h" NpcTextDialog::NpcTextDialog(Network *network): - Window(_("NPC")), mNetwork(network) + Window("NPC"), mNetwork(network) { + setWindowName(_("NPC")); setResizable(true); - setCloseButton(true); setMinWidth(200); setMinHeight(150); @@ -89,6 +89,7 @@ void NpcTextDialog::action(const gcn::ActionEvent &event) { clearText(); setVisible(false); + saveWindowState(); if (current_npc) nextDialog(); @@ -118,3 +119,9 @@ void NpcTextDialog::widgetResized(const gcn::Event &event) setText(mText); } +void NpcTextDialog::requestFocus() +{ + loadWindowState(); + setVisible(true); +} + diff --git a/src/gui/npc_text.h b/src/gui/npc_text.h index 615902db..f01e3602 100644 --- a/src/gui/npc_text.h +++ b/src/gui/npc_text.h @@ -74,10 +74,23 @@ class NpcTextDialog : public Window, public gcn::ActionListener */ void addText(const std::string &string); + /** + * Notifies the server that the client has performed a next action. + */ void nextDialog(int npcID = current_npc); + /** + * Notifies the server that the client has performed a close action. + */ void closeDialog(int npcID = current_npc); + /** + * Initializes window width to the last known setting. Since the dialog + * doesn't need any extra focus outside of what it's given in the Game + * class, this is all it does for now. + */ + void requestFocus(); + /** * Called when resizing the window. * diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index c639411d..f049cba7 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -37,8 +37,9 @@ #include "../utils/gettext.h" NpcListDialog::NpcListDialog(Network *network): - Window(_("NPC")), mNetwork(network) + Window("NPC"), mNetwork(network) { + setWindowName(_("NPC")); setResizable(true); setMinWidth(200); @@ -114,6 +115,7 @@ void NpcListDialog::action(const gcn::ActionEvent &event) if (choice) { setVisible(false); + saveWindowState(); reset(); MessageOut outMsg(mNetwork); @@ -129,4 +131,6 @@ void NpcListDialog::requestFocus() { mItemList->requestFocus(); mItemList->setSelected(0); + loadWindowState(); + setVisible(true); } diff --git a/src/gui/npclistdialog.h b/src/gui/npclistdialog.h index 0a0e9813..e3cf375b 100644 --- a/src/gui/npclistdialog.h +++ b/src/gui/npclistdialog.h @@ -76,7 +76,8 @@ class NpcListDialog : public Window, public gcn::ActionListener, void reset(); /** - * Requests the listbox to take focus for input. + * Requests the listbox to take focus for input and sets window width + * to the last known setting. */ void requestFocus(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 2b422f86..8faf63a0 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -118,21 +118,8 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std Window::~Window() { logger->log("Window::~Window(\"%s\")", getCaption().c_str()); - const std::string &name = mWindowName; - // Saving X, Y and Width and Height for resizables in the config - if (!name.empty()) - { - config.setValue(name + "WinX", getX()); - config.setValue(name + "WinY", getY()); - config.setValue(name + "Visible", isVisible()); - - if (mGrip) - { - config.setValue(name + "WinWidth", getWidth()); - config.setValue(name + "WinHeight", getHeight()); - } - } + saveWindowState(); delete mLayout; @@ -478,8 +465,13 @@ void Window::loadWindowState() if (mGrip) { - setSize((int) config.getValue(name + "WinWidth", mDefaultWidth), - (int) config.getValue(name + "WinHeight", mDefaultHeight)); + const int width = (int) config.getValue(name + "WinWidth", + mDefaultWidth); + const int height = (int) config.getValue(name + "WinHeight", + mDefaultHeight); + + setSize(width < getMinWidth() ? getMinWidth() : width, + height < getMinHeight() ? getMinHeight() : height); } else { @@ -487,6 +479,23 @@ void Window::loadWindowState() } } +void Window::saveWindowState() +{ + // Saving X, Y and Width and Height for resizables in the config + if (!mWindowName.empty()) + { + config.setValue(mWindowName + "WinX", getX()); + config.setValue(mWindowName + "WinY", getY()); + config.setValue(mWindowName + "Visible", isVisible()); + + if (mGrip) + { + config.setValue(mWindowName + "WinWidth", getWidth()); + config.setValue(mWindowName + "WinHeight", getHeight()); + } + } +} + void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) { diff --git a/src/gui/window.h b/src/gui/window.h index 3a92ac17..bf15dedb 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -233,6 +233,12 @@ class Window : public gcn::Window, gcn::WidgetListener */ void loadWindowState(); + /** + * Saves the window state so that when the window is reloaded, it'll + * maintain its previous state and location. + */ + void saveWindowState(); + /** * Set the default win pos and size. * (which can be different of the actual ones.) diff --git a/src/net/npchandler.cpp b/src/net/npchandler.cpp index 41af4467..60a77af1 100644 --- a/src/net/npchandler.cpp +++ b/src/net/npchandler.cpp @@ -60,7 +60,6 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); npcListDialog->parseItems(msg->readString(msg->getLength() - 8)); - npcListDialog->setVisible(true); npcListDialog->requestFocus(); break; @@ -69,7 +68,7 @@ void NPCHandler::handleMessage(MessageIn *msg) current_npc = msg->readInt32(); player_node->setAction(LocalPlayer::STAND); npcTextDialog->addText(msg->readString(msg->getLength() - 8)); - npcTextDialog->setVisible(true); + npcTextDialog->requestFocus(); break; case SMSG_NPC_CLOSE: -- cgit v1.2.3-70-g09d2 From 67ea3716f8b01484527ead747c0cc6af3ac0cd76 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:29:49 -0600 Subject: Moved enforcement of minimum widths and heights to the Window class. This was needed in the Minimap class, but not migrated out to the Window class until now. Signed-off-by: Ira Rice --- src/gui/login.cpp | 28 +++++++++------------------- src/gui/minimap.cpp | 12 ------------ src/gui/window.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- 3 files changed, 53 insertions(+), 40 deletions(-) (limited to 'src/gui') diff --git a/src/gui/login.cpp b/src/gui/login.cpp index cd331322..ce13aaf0 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -117,11 +117,10 @@ LoginDialog::LoginDialog(LoginData *loginData): setLocationRelativeTo(getParent()); setVisible(true); - if (mUserField->getText().empty()) { + if (mUserField->getText().empty()) mUserField->requestFocus(); - } else { + else mPassField->requestFocus(); - } mOkButton->setEnabled(canSubmit()); } @@ -156,14 +155,12 @@ void LoginDialog::action(const gcn::ActionEvent &event) { // Transfer these fields on to the register dialog mLoginData->hostname = mServerField->getText(); + if (isUShort(mPortField->getText())) - { mLoginData->port = getUShort(mPortField->getText()); - } else - { mLoginData->port = 6901; - } + mLoginData->username = mUserField->getText(); mLoginData->password = mPassField->getText(); @@ -196,14 +193,12 @@ bool LoginDialog::isUShort(const std::string &str) strPtr != strEnd; ++strPtr) { if (*strPtr < '0' || *strPtr > '9') - { return false; - } + l = l * 10 + (*strPtr - '0'); // *strPtr - '0' will never be negative + if (l > 65535) - { return false; - } } return true; } @@ -279,9 +274,7 @@ void LoginDialog::DropDownList::save(const std::string &server, ++sPtr, ++pPtr) { if (*sPtr != server || *pPtr != port) - { saveEntry(*sPtr, *pPtr, position); - } } } @@ -293,26 +286,23 @@ int LoginDialog::DropDownList::getNumberOfElements() std::string LoginDialog::DropDownList::getElementAt(int i) { if (i < 0 || i >= getNumberOfElements()) - { return ""; - } + return getServerAt(i) + ":" + getPortAt(i); } std::string LoginDialog::DropDownList::getServerAt(int i) { if (i < 0 || i >= getNumberOfElements()) - { return ""; - } + return mServers.at(i); } std::string LoginDialog::DropDownList::getPortAt(int i) { if (i < 0 || i >= getNumberOfElements()) - { return ""; - } + return mPorts.at(i); } diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index 2a97b949..ecda29ce 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -80,18 +80,6 @@ void Minimap::setMapImage(Image *img) mMapImage->getWidth() + offsetX : titleWidth); setMaxHeight(mMapImage->getHeight() + offsetY); - // Make sure the window is within the minimum and maximum boundaries - // TODO: Shouldn't this be happening automatically within the Window - // class? - if (getMinWidth() > getWidth()) - setWidth(getMinWidth()); - else if (getMaxWidth() < getWidth()) - setWidth(getMaxWidth()); - if (getMinHeight() > getHeight()) - setHeight(getMinHeight()); - else if (getMaxHeight() < getHeight()) - setHeight(getMaxHeight()); - setContentSize(getWidth() - offsetX, getHeight() - offsetY); setDefaultSize(getX(), getY(), getWidth(), getHeight()); resetToDefaultSize(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 8faf63a0..5253dd2e 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -193,8 +193,19 @@ void Window::draw(gcn::Graphics *graphics) void Window::setContentSize(int width, int height) { - setSize(width + 2 * getPadding(), - height + getPadding() + getTitleBarHeight()); + width = width + 2 * getPadding(); + height = height + getPadding() + getTitleBarHeight(); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); } void Window::setLocationRelativeTo(gcn::Widget *widget) @@ -465,13 +476,19 @@ void Window::loadWindowState() if (mGrip) { - const int width = (int) config.getValue(name + "WinWidth", - mDefaultWidth); - const int height = (int) config.getValue(name + "WinHeight", - mDefaultHeight); - - setSize(width < getMinWidth() ? getMinWidth() : width, - height < getMinHeight() ? getMinHeight() : height); + int width = (int) config.getValue(name + "WinWidth", mDefaultWidth); + int height = (int) config.getValue(name + "WinHeight", mDefaultHeight); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); } else { @@ -490,6 +507,15 @@ void Window::saveWindowState() if (mGrip) { + if (getMinWidth() > getWidth()) + setWidth(getMinWidth()); + else if (getMaxWidth() < getWidth()) + setWidth(getMaxWidth()); + if (getMinHeight() > getHeight()) + setHeight(getMinHeight()); + else if (getMaxHeight() < getHeight()) + setHeight(getMaxHeight()); + config.setValue(mWindowName + "WinWidth", getWidth()); config.setValue(mWindowName + "WinHeight", getHeight()); } @@ -499,6 +525,15 @@ void Window::saveWindowState() void Window::setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight) { + if (getMinWidth() > defaultWidth) + defaultWidth = getMinWidth(); + else if (getMaxWidth() < defaultWidth) + defaultWidth = getMaxWidth(); + if (getMinHeight() > defaultHeight) + defaultHeight = getMinHeight(); + else if (getMaxHeight() < defaultHeight) + defaultHeight = getMaxHeight(); + mDefaultX = defaultX; mDefaultY = defaultY; mDefaultWidth = defaultWidth; -- cgit v1.2.3-70-g09d2 From 6b0659b6cc921aa6589681820b431af44f458440 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:37:10 -0600 Subject: Fixed setContentSize in the window class to only care about exceeding the maximum width and height. Exceeding the minumum width and height is a desireable case in some situations. Signed-off-by: Ira Rice --- src/gui/window.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5253dd2e..3c73a586 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -196,13 +196,9 @@ void Window::setContentSize(int width, int height) width = width + 2 * getPadding(); height = height + getPadding() + getTitleBarHeight(); - if (getMinWidth() > width) - width = getMinWidth(); - else if (getMaxWidth() < width) + if (getMaxWidth() < width) width = getMaxWidth(); - if (getMinHeight() > height) - height = getMinHeight(); - else if (getMaxHeight() < height) + if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); -- cgit v1.2.3-70-g09d2 From 1570fb33d5909786ef2997246ada7c46dd6de9e4 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 08:43:26 -0600 Subject: Reverted last commit (since I confused it with something else) as well as removed a redundant call for sizing in the minimap class. Signed-off-by: Ira Rice --- src/gui/minimap.cpp | 1 - src/gui/window.cpp | 8 ++++++-- 2 files changed, 6 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index ecda29ce..f3da52c6 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -80,7 +80,6 @@ void Minimap::setMapImage(Image *img) mMapImage->getWidth() + offsetX : titleWidth); setMaxHeight(mMapImage->getHeight() + offsetY); - setContentSize(getWidth() - offsetX, getHeight() - offsetY); setDefaultSize(getX(), getY(), getWidth(), getHeight()); resetToDefaultSize(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 3c73a586..5253dd2e 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -196,9 +196,13 @@ void Window::setContentSize(int width, int height) width = width + 2 * getPadding(); height = height + getPadding() + getTitleBarHeight(); - if (getMaxWidth() < width) + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) width = getMaxWidth(); - if (getMaxHeight() < height) + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) height = getMaxHeight(); setSize(width, height); -- cgit v1.2.3-70-g09d2 From 343d290f639646b9a3a90c9402dfc8e76989bdcb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 09:29:15 -0600 Subject: Don't center the NPC interraction dialogs Use the last location the user gave instead. Also, do the same for the inventory dialog. --- src/gui/buy.cpp | 1 - src/gui/buysell.cpp | 1 - src/gui/inventorywindow.cpp | 1 - src/gui/npc_text.cpp | 2 +- src/gui/npcintegerdialog.cpp | 3 +-- src/gui/npclistdialog.cpp | 2 +- src/gui/npcstringdialog.cpp | 3 +-- src/gui/sell.cpp | 1 - src/gui/storagewindow.cpp | 1 - 9 files changed, 4 insertions(+), 11 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 768dab4d..d267e5ad 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -91,7 +91,6 @@ BuyDialog::BuyDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } BuyDialog::~BuyDialog() diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 818413c2..0550a822 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,7 +49,6 @@ BuySellDialog::BuySellDialog(Network *network): buyButton->requestFocus(); setContentSize(x, 2 * y + buyButton->getHeight()); - setLocationRelativeTo(getParent()); requestFocus(); } diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index e5450748..80017d28 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -103,7 +103,6 @@ InventoryWindow::InventoryWindow(int invSize): layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } InventoryWindow::~InventoryWindow() diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 61f3e510..53c64a54 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -37,6 +37,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Window(_("NPC")), mNetwork(network), mState(NPC_TEXT_STATE_WAITING) { + setWindowName("NPCText"); setResizable(true); setMinWidth(200); @@ -61,7 +62,6 @@ NpcTextDialog::NpcTextDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } void NpcTextDialog::clearText() diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 9778d790..ea06ca8d 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -39,6 +39,7 @@ extern NpcTextDialog *npcTextDialog; NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { + setWindowName("NPCInteger"); mValueField = new IntTextField; mDecButton = new Button("-", "decvalue", this); @@ -62,8 +63,6 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(2, 0, cancelButton); place(3, 0, okButton); reflowLayout(175, 0); - - setLocationRelativeTo(getParent()); } void NpcIntegerDialog::setRange(int min, int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 66c2d9a0..c1493afd 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -42,6 +42,7 @@ extern NpcTextDialog *npcTextDialog; NpcListDialog::NpcListDialog(Network *network): Window(_("NPC")), mNetwork(network) { + setWindowName("NPCList"); setResizable(true); setMinWidth(200); @@ -69,7 +70,6 @@ NpcListDialog::NpcListDialog(Network *network): loadWindowState(); resetToDefaultSize(); - setLocationRelativeTo(getParent()); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index aec30826..525a73a0 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -39,6 +39,7 @@ extern NpcTextDialog *npcTextDialog; NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { + setWindowName("NPCList"); mValueField = new TextField(""); gcn::Button *okButton = new Button(_("OK"), "ok", this); @@ -48,8 +49,6 @@ NpcStringDialog::NpcStringDialog(Network *network): place(1, 1, cancelButton); place(2, 1, okButton); reflowLayout(175, 0); - - setLocationRelativeTo(getParent()); } std::string NpcStringDialog::getValue() diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 1aa0e2d3..b53a23c1 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -94,7 +94,6 @@ SellDialog::SellDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } SellDialog::~SellDialog() diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 9cdc2da7..2b8ab8f3 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -93,7 +93,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): layout.setRowHeight(0, mStoreButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } StorageWindow::~StorageWindow() -- cgit v1.2.3-70-g09d2 From 171198999b4290f3e2adadd019c8d914212ecf47 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 09:34:07 -0600 Subject: Make sure NPC input dialogs get focus --- src/gui/npcintegerdialog.cpp | 5 ++++- src/gui/npclistdialog.cpp | 5 ++++- src/gui/npcstringdialog.cpp | 5 ++++- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index ea06ca8d..fad37700 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -139,7 +139,10 @@ void NpcIntegerDialog::requestFocus() void NpcIntegerDialog::setVisible(bool visible) { - if (visible) npcTextDialog->setVisible(true); + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); + } Window::setVisible(visible); } diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index c1493afd..94dfabeb 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -134,7 +134,10 @@ void NpcListDialog::action(const gcn::ActionEvent &event) void NpcListDialog::setVisible(bool visible) { - if (visible) npcTextDialog->setVisible(true); + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); + } Window::setVisible(visible); } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 525a73a0..7c9f78af 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -101,7 +101,10 @@ void NpcStringDialog::requestFocus() void NpcStringDialog::setVisible(bool visible) { - if (visible) npcTextDialog->setVisible(true); + if (visible) { + npcTextDialog->setVisible(true); + requestFocus(); + } Window::setVisible(visible); } -- cgit v1.2.3-70-g09d2 From 3aa9e681e466b1596a99b0361277975476790c3f Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 09:35:26 -0600 Subject: Allow NPCList dialog to use it's old location --- src/gui/npclistdialog.cpp | 2 +- src/gui/window.cpp | 4 ++-- src/gui/window.h | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 94dfabeb..95fe5983 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -69,7 +69,7 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - resetToDefaultSize(); + resetToDefaultSize(false); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 48229ec8..8eaaf31d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -490,9 +490,9 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } -void Window::resetToDefaultSize() +void Window::resetToDefaultSize(bool changePosition) { - setPosition(mDefaultX, mDefaultY); + if (changePosition) setPosition(mDefaultX, mDefaultY); setSize(mDefaultWidth, mDefaultHeight); } diff --git a/src/gui/window.h b/src/gui/window.h index 518de6e9..9977aff4 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -243,7 +243,7 @@ class Window : public gcn::Window, gcn::WidgetListener * Reset the win pos and size to default. Don't forget to set defaults * first. */ - void resetToDefaultSize(); + void resetToDefaultSize(bool changePosition = true); /** * Gets the layout handler for this window. -- cgit v1.2.3-70-g09d2 From 4a08d3b4bec3fa0fc1878140b0f14c8b38d6420b Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 11:03:38 -0600 Subject: Allow null link handlers for browser box --- src/gui/browserbox.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 6614feb9..7bdbcbef 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -225,6 +225,7 @@ struct MouseOverLink void BrowserBox::mousePressed(gcn::MouseEvent &event) { + if (!mLinkHandler) return; LinkIterator i = find_if(mLinks.begin(), mLinks.end(), MouseOverLink(event.getX(), event.getY())); -- cgit v1.2.3-70-g09d2 From 58ee835c3763e7bf088fa6c7e31dda1d687589cc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 11:50:27 -0600 Subject: Extended window layout to take relative positions, as well as offsets to that position. This makes it so that when resolutions are changed, the default locations stay relative to the window's position, and not the 800x600 screen resolution. Signed-off-by: Ira Rice --- src/graphics.cpp | 30 ++++++-------- src/graphics.h | 13 ++++++ src/gui/buy.cpp | 3 +- src/gui/buysell.cpp | 1 - src/gui/chat.cpp | 2 +- src/gui/debugwindow.cpp | 2 +- src/gui/emotewindow.cpp | 2 +- src/gui/equipmentwindow.cpp | 2 +- src/gui/inventorywindow.cpp | 3 +- src/gui/npc_text.cpp | 3 +- src/gui/npcintegerdialog.cpp | 7 +++- src/gui/npclistdialog.cpp | 3 +- src/gui/npcstringdialog.cpp | 7 +++- src/gui/recorder.cpp | 8 ++-- src/gui/sell.cpp | 3 +- src/gui/shortcutwindow.cpp | 13 ++---- src/gui/skill.cpp | 2 +- src/gui/status.cpp | 3 +- src/gui/storagewindow.cpp | 3 +- src/gui/trade.cpp | 2 +- src/gui/window.cpp | 99 ++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.h | 16 ++++++- src/openglgraphics.cpp | 42 ++++++++++--------- 23 files changed, 194 insertions(+), 75 deletions(-) (limited to 'src/gui') diff --git a/src/graphics.cpp b/src/graphics.cpp index 3c507f4b..48fd1340 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -50,30 +50,25 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } - if (hwaccel) { + if (hwaccel) displayFlags |= SDL_HWSURFACE | SDL_DOUBLEBUF; - } else { + else displayFlags |= SDL_SWSURFACE; - } mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags); - if (!mScreen) { + if (!mScreen) return false; - } char videoDriverName[64]; - if (SDL_VideoDriverName(videoDriverName, 64)) { + if (SDL_VideoDriverName(videoDriverName, 64)) logger->log("Using video driver: %s", videoDriverName); - } - else { + else logger->log("Using video driver: unknown"); - } const SDL_VideoInfo *vi = SDL_GetVideoInfo(); @@ -104,9 +99,8 @@ bool Graphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) bool Graphics::setFullscreen(bool fs) { - if (mFullscreen == fs) { + if (mFullscreen == fs) return true; - } return setVideoMode(mScreen->w, mScreen->h, mScreen->format->BitsPerPixel, fs, mHWAccel); @@ -128,7 +122,7 @@ bool Graphics::drawImage(Image *image, int x, int y) } bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, - int width, int height, bool) + int width, int height, bool) { // Check that preconditions for blitting are met. if (!mScreen || !image || !image->mImage) return false; @@ -150,7 +144,7 @@ bool Graphics::drawImage(Image *image, int srcX, int srcY, int dstX, int dstY, } void Graphics::drawImage(gcn::Image const *image, int srcX, int srcY, - int dstX, int dstY, int width, int height) + int dstX, int dstY, int width, int height) { ProxyImage const *srcImage = dynamic_cast< ProxyImage const * >(image); @@ -167,8 +161,10 @@ void Graphics::drawImagePattern(Image *image, int x, int y, int w, int h) int px = 0; // X position on pattern plane int py = 0; // Y position on pattern plane - while (py < h) { - while (px < w) { + while (py < h) + { + while (px < w) + { int dw = (px + iw >= w) ? w - px : iw; int dh = (py + ih >= h) ? h - py : ih; drawImage(image, 0, 0, x + px, y + py, dw, dh); diff --git a/src/graphics.h b/src/graphics.h index 3ad3b85c..ec0b5e9c 100644 --- a/src/graphics.h +++ b/src/graphics.h @@ -49,6 +49,19 @@ struct SDL_Surface; */ struct ImageRect { + enum ImagePosition + { + UPPER_LEFT = 0, + UPPER_CENTER = 1, + UPPER_RIGHT = 2, + LEFT = 3, + CENTER = 4, + RIGHT = 5, + LOWER_LEFT = 6, + LOWER_CENTER = 7, + LOWER_RIGHT = 8, + }; + Image *grid[9]; }; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 5a57dcc6..2b5aeeb7 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -47,7 +47,7 @@ BuyDialog::BuyDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); mShopItems = new ShopItems; @@ -90,7 +90,6 @@ BuyDialog::BuyDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } BuyDialog::~BuyDialog() diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index dc7deef6..f7684670 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -50,7 +50,6 @@ BuySellDialog::BuySellDialog(Network *network): buyButton->requestFocus(); setContentSize(x, 2 * y + buyButton->getHeight()); - setLocationRelativeTo(getParent()); requestFocus(); } diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 5cf8b739..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -55,7 +55,7 @@ Window(""), mNetwork(network), mTmpVisible(false) setWindowName(_("Chat")); setResizable(true); - setDefaultSize(0, windowContainer->getHeight() - 123, 600, 123); + setDefaultSize(600, 123, ImageRect::LOWER_LEFT); setMinWidth(150); setMinHeight(90); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index dafd604a..71855977 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -41,7 +41,7 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); - setDefaultSize(0, 0, 400, 60); + setDefaultSize(400, 60, ImageRect::CENTER); mFPSLabel = new gcn::Label("0 FPS"); mMusicFileLabel = new gcn::Label("Music: "); diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp index 30129941..77168993 100644 --- a/src/gui/emotewindow.cpp +++ b/src/gui/emotewindow.cpp @@ -40,7 +40,7 @@ EmoteWindow::EmoteWindow(): setCloseButton(true); setMinWidth(80); setMinHeight(130); - setDefaultSize(115, 25, 322, 200); + setDefaultSize(322, 200, ImageRect::CENTER); mUseButton = new Button(_("Use"), "use", this); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 27ea38ff..0d2097f8 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -71,7 +71,7 @@ EquipmentWindow::EquipmentWindow(): setWindowName("Equipment"); setCloseButton(true); - setDefaultSize(5, 195, 180, 300); + setDefaultSize(180, 300, ImageRect::CENTER); loadWindowState(); mUnequip = new Button(_("Unequip"), "unequip", this); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 226b3178..7e75411e 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -57,7 +57,7 @@ InventoryWindow::InventoryWindow(int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); std::string longestUseString = getFont()->getWidth(_("Equip")) > getFont()->getWidth(_("Use")) ? @@ -103,7 +103,6 @@ InventoryWindow::InventoryWindow(int invSize): layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } InventoryWindow::~InventoryWindow() diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 58aa0c5e..f524f8ea 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -43,7 +43,7 @@ NpcTextDialog::NpcTextDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mTextBox = new TextBox; mTextBox->setEditable(false); @@ -63,7 +63,6 @@ NpcTextDialog::NpcTextDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } void NpcTextDialog::setText(const std::string &text) diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 132a7608..5b3e05aa 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -37,6 +37,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { mValueField = new IntTextField(); + setWindowName("NPCInput"); + + setDefaultSize(175, 75, ImageRect::CENTER); mDecButton = new Button("-", "decvalue", this); mIncButton = new Button("+", "incvalue", this); @@ -58,9 +61,9 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(0, 0, resetButton); place(2, 0, cancelButton); place(3, 0, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } void NpcIntegerDialog::setRange(const int min, const int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index f049cba7..505912ac 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -45,7 +45,7 @@ NpcListDialog::NpcListDialog(Network *network): setMinWidth(200); setMinHeight(150); - setDefaultSize(0, 0, 260, 200); + setDefaultSize(260, 200, ImageRect::CENTER); mItemList = new ListBox(this); mItemList->setWrappingEnabled(true); @@ -66,7 +66,6 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f2c7434c..58a5c0c8 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -36,17 +36,20 @@ NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { + setWindowName("NPCInput"); mValueField = new TextField(""); + setDefaultSize(175, 75, ImageRect::CENTER); + okButton = new Button(_("OK"), "ok", this); cancelButton = new Button(_("Cancel"), "cancel", this); place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - reflowLayout(175, 0); + //reflowLayout(175, 0); - setLocationRelativeTo(getParent()); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/recorder.cpp b/src/gui/recorder.cpp index ff8825ef..9320e020 100644 --- a/src/gui/recorder.cpp +++ b/src/gui/recorder.cpp @@ -40,9 +40,11 @@ Recorder::Recorder(ChatWindow *chat, const std::string &title, mChat = chat; Button *button = new Button(buttonTxt, "activate", this); - setDefaultSize(0, windowContainer->getHeight() - 123 - button->getHeight() - - offsetY, button->getWidth() + offsetX, button->getHeight() + - offsetY); + + // 123 is the default chat window height. If you change this in Chat, please + // change it here as well + setDefaultSize(button->getWidth() + offsetX, button->getHeight() + + offsetY, ImageRect::LOWER_LEFT, 0, 123); place(0, 0, button); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 154d1a57..397e29a6 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -48,7 +48,7 @@ SellDialog::SellDialog(Network *network): setResizable(true); setMinWidth(260); setMinHeight(230); - setDefaultSize(0, 0, 260, 230); + setDefaultSize(260, 230, ImageRect::CENTER); // Create a ShopItems instance, that is aware of duplicate entries. mShopItems = new ShopItems(true); @@ -94,7 +94,6 @@ SellDialog::SellDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - setLocationRelativeTo(getParent()); } SellDialog::~SellDialog() diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index ee32ca70..c2df1f9c 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -40,22 +40,17 @@ ShortcutWindow::ShortcutWindow(const char *title, ShortcutContainer *content) mItems = content; - mInstances++; - const int border = SCROLL_PADDING * 2 + getPadding() * 2; setMinWidth(mItems->getBoxWidth() + border); setMinHeight(mItems->getBoxHeight() + border); setMaxWidth(mItems->getBoxWidth() * mItems->getMaxItems() + border); setMaxHeight(mItems->getBoxHeight() * mItems->getMaxItems() + border); - const int width = (int) config.getValue("screenwidth", 800); - const int height = (int) config.getValue("screenheight", 600); + setDefaultSize(mItems->getBoxWidth() + border, (mItems->getBoxHeight() * + mItems->getMaxItems()) + border, ImageRect::LOWER_RIGHT, + mInstances * mItems->getBoxWidth(), 0); - setDefaultSize(width - (mInstances * mItems->getBoxWidth()) - - (mInstances * border), height - (mItems->getBoxHeight() * - mItems->getMaxItems()) - border, mItems->getBoxWidth() + - border, (mItems->getBoxHeight() * mItems->getMaxItems()) + - border); + mInstances++; mScrollArea = new ScrollArea(mItems); mScrollArea->setPosition(SCROLL_PADDING, SCROLL_PADDING); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 42ac4d86..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -135,7 +135,7 @@ SkillDialog::SkillDialog(): setWindowName(_("Skills")); setCloseButton(true); - setDefaultSize(windowContainer->getWidth() - 260, 25, 255, 260); + setDefaultSize(255, 260, ImageRect::CENTER); setMinHeight(50 + mTableModel->getHeight()); setMinWidth(200); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 6419eabb..e534edb8 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -41,8 +41,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): { setWindowName(_("Status")); setCloseButton(true); - setDefaultSize((windowContainer->getWidth() - 365) / 2, - (windowContainer->getHeight() - 255) / 2, 400, 345); + setDefaultSize(400, 345, ImageRect::CENTER); // ---------------------- // Status Part diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index d3bc7ef8..ca7a547f 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -62,7 +62,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): setCloseButton(true); // If you adjust these defaults, don't forget to adjust the trade window's. - setDefaultSize(115, 25, 375, 300); + setDefaultSize(375, 300, ImageRect::CENTER); mStoreButton = new Button(_("Store"), "store", this); mRetrieveButton = new Button(_("Retrieve"), "retrieve", this); @@ -92,7 +92,6 @@ StorageWindow::StorageWindow(Network *network, int invSize): layout.setRowHeight(0, mStoreButton->getHeight()); loadWindowState(); - setLocationRelativeTo(getParent()); } StorageWindow::~StorageWindow() diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 76795688..a28ff0f9 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -53,7 +53,7 @@ TradeWindow::TradeWindow(Network *network): mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) { setWindowName(_("Trade")); - setDefaultSize(115, 227, 342, 209); + setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); setMinWidth(342); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5253dd2e..f1316b4c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,6 +220,53 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } +void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = (windowContainer->getHeight() - getHeight()) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - getWidth()) / 2; + y = windowContainer->getHeight() - getHeight(); + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - getWidth(); + y = windowContainer->getHeight() - getHeight(); + } + + setPosition(x, y); +} + void Window::setMinWidth(unsigned int width) { mMinWinWidth = width; @@ -540,6 +587,58 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetX, int offsetY) +{ + int x = 0, y = 0; + + if (position == ImageRect::UPPER_LEFT) + { + } + else if (position == ImageRect::UPPER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + } + else if (position == ImageRect::UPPER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + } + else if (position == ImageRect::LEFT) + { + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = (windowContainer->getHeight() - defaultHeight) / 2; + } + else if (position == ImageRect::LOWER_LEFT) + { + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_CENTER) + { + x = (windowContainer->getWidth() - defaultWidth) / 2; + y = windowContainer->getHeight() - defaultHeight; + } + else if (position == ImageRect::LOWER_RIGHT) + { + x = windowContainer->getWidth() - defaultWidth; + y = windowContainer->getHeight() - defaultHeight; + } + + mDefaultX = x - offsetX; + mDefaultY = y - offsetY; + mDefaultWidth = defaultWidth; + mDefaultHeight = defaultHeight; +} + void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); diff --git a/src/gui/window.h b/src/gui/window.h index bf15dedb..c24bde76 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -34,7 +34,6 @@ class ConfigListener; class GCContainer; class ContainerPlacer; class Image; -class ImageRect; class Layout; class LayoutCell; class ResizeGrip; @@ -90,6 +89,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ void setLocationRelativeTo(gcn::Widget *widget); + /** + * Sets the location relative to the given enumerated position. + */ + void setLocationRelativeTo(ImageRect::ImagePosition position); + /** * Sets whether or not the window can be resized. */ @@ -246,6 +250,16 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size. + * (which can be different of the actual ones.) + * This version of setDefaultSize sets the window's position based + * on a relative enumerated position, rather than a coordinate position. + */ + void setDefaultSize(int defaultWidth, int defaultHeight, + ImageRect::ImagePosition position, + int offsetx = 0, int offsetY = 0); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index 71ab2fe3..9bd3ab2f 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -63,18 +63,17 @@ bool OpenGLGraphics::setVideoMode(int w, int h, int bpp, bool fs, bool hwaccel) mFullscreen = fs; mHWAccel = hwaccel; - if (fs) { + if (fs) displayFlags |= SDL_FULLSCREEN; - } SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) { + if (!(mScreen = SDL_SetVideoMode(w, h, bpp, displayFlags))) return false; - } #ifdef __APPLE__ - if (mSync) { + if (mSync) + { const GLint VBL = 1; CGLSetParameter(CGLGetCurrentContext(), kCGLCPSwapInterval, &VBL); } @@ -158,9 +157,7 @@ bool OpenGLGraphics::drawImage(Image *image, int srcX, int srcY, glEnd(); if (!useColor) - { glColor4ub(mColor.r, mColor.g, mColor.b, mColor.a); - } return true; } @@ -206,9 +203,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() w, h, 24, 0xff0000, 0x00ff00, 0x0000ff, 0x000000); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_LockSurface(screenshot); - } // Grap the pixel buffer and write it to the SDL surface glPixelStorei(GL_PACK_ALIGNMENT, 1); @@ -230,9 +226,8 @@ SDL_Surface* OpenGLGraphics::getScreenshot() free(buf); - if (SDL_MUSTLOCK(screenshot)) { + if (SDL_MUSTLOCK(screenshot)) SDL_UnlockSurface(screenshot); - } return screenshot; } @@ -242,7 +237,8 @@ bool OpenGLGraphics::pushClipArea(gcn::Rectangle area) int transX = 0; int transY = 0; - if (!mClipStack.empty()) { + if (!mClipStack.empty()) + { transX = -mClipStack.top().xOffset; transY = -mClipStack.top().yOffset; } @@ -267,9 +263,7 @@ void OpenGLGraphics::popClipArea() gcn::Graphics::popClipArea(); if (mClipStack.empty()) - { return; - } glPopMatrix(); glScissor(mClipStack.top().x, @@ -325,8 +319,10 @@ void OpenGLGraphics::setTargetPlane(int width, int height) void OpenGLGraphics::setTexturingAndBlending(bool enable) { - if (enable) { - if (!mTexture) { + if (enable) + { + if (!mTexture) + { glEnable(Image::mTextureType); mTexture = true; } @@ -336,16 +332,22 @@ void OpenGLGraphics::setTexturingAndBlending(bool enable) glEnable(GL_BLEND); mAlpha = true; } - } else { - if (mAlpha && !mColorAlpha) { + } + else + { + if (mAlpha && !mColorAlpha) + { glDisable(GL_BLEND); mAlpha = false; - } else if (!mAlpha && mColorAlpha) { + } + else if (!mAlpha && mColorAlpha) + { glEnable(GL_BLEND); mAlpha = true; } - if (mTexture) { + if (mTexture) + { glDisable(Image::mTextureType); mTexture = false; } -- cgit v1.2.3-70-g09d2 From 9b259c3d502795b2bbbfbe6a275cb503b1fc78b1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 11:03:38 -0600 Subject: Allow null link handlers for browser box --- src/gui/browserbox.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index b8f58dbb..2b690b21 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -226,6 +226,7 @@ struct MouseOverLink void BrowserBox::mousePressed(gcn::MouseEvent &event) { + if (!mLinkHandler) return; LinkIterator i = find_if(mLinks.begin(), mLinks.end(), MouseOverLink(event.getX(), event.getY())); -- cgit v1.2.3-70-g09d2 From 0540c611b48fd8dee14066b13755138192b7084b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 12:09:53 -0600 Subject: Allow for offsets for the enumerated position version of setLocationRelativeTo as well. Signed-off-by: Ira Rice --- src/gui/window.cpp | 31 +++++++++++++++---------------- src/gui/window.h | 3 ++- 2 files changed, 17 insertions(+), 17 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f1316b4c..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -220,51 +220,50 @@ void Window::setLocationRelativeTo(gcn::Widget *widget) getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); } -void Window::setLocationRelativeTo(ImageRect::ImagePosition position) +void Window::setLocationRelativeTo(ImageRect::ImagePosition position, + int offsetX, int offsetY) { - int x = 0, y = 0; - if (position == ImageRect::UPPER_LEFT) { } else if (position == ImageRect::UPPER_CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; + offsetX += (windowContainer->getWidth() - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = windowContainer->getWidth() - getWidth(); + offsetX += windowContainer->getWidth() - getWidth(); } else if (position == ImageRect::LEFT) { - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - x = windowContainer->getWidth() - getWidth(); - y = (windowContainer->getHeight() - getHeight()) / 2; + offsetX += windowContainer->getWidth() - getWidth(); + offsetY += (windowContainer->getHeight() - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = windowContainer->getHeight() - getHeight(); + offsetY += windowContainer->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - x = (windowContainer->getWidth() - getWidth()) / 2; - y = windowContainer->getHeight() - getHeight(); + offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetY += windowContainer->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - x = windowContainer->getWidth() - getWidth(); - y = windowContainer->getHeight() - getHeight(); + offsetX += windowContainer->getWidth() - getWidth(); + offsetY += windowContainer->getHeight() - getHeight(); } - setPosition(x, y); + setPosition(offsetX, offsetY); } void Window::setMinWidth(unsigned int width) diff --git a/src/gui/window.h b/src/gui/window.h index c24bde76..4fc6c862 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -92,7 +92,8 @@ class Window : public gcn::Window, gcn::WidgetListener /** * Sets the location relative to the given enumerated position. */ - void setLocationRelativeTo(ImageRect::ImagePosition position); + void setLocationRelativeTo(ImageRect::ImagePosition position, + int offsetX = 0, int offsetY = 0); /** * Sets whether or not the window can be resized. -- cgit v1.2.3-70-g09d2 From 17f9d5abcb05da185486ccfba293f3a8c9eab437 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 5 +++-- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 11 +++++++++-- src/gui/setup.h | 4 ++++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 24 ++++++++++++++---------- src/player_relations.h | 2 ++ 13 files changed, 48 insertions(+), 20 deletions(-) (limited to 'src/gui') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 73fa683a..23d91526 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -54,6 +54,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 6c0e0fda..d0690798 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -36,6 +36,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -112,7 +114,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 74a52ddf..ae708adf 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -204,7 +204,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog; - setupWindow = new Setup; minimap = new Minimap; equipmentWindow = new EquipmentWindow; tradeWindow = new TradeWindow(network); @@ -341,11 +340,12 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; @@ -353,6 +353,7 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; + delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 8ecb5f63..55bc2696 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -108,6 +108,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 148e8b75..62d79d4d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -64,9 +64,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } TabbedArea *panel = new TabbedArea; @@ -101,6 +101,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() @@ -140,3 +142,8 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index e4eb0902..075c88bf 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -31,6 +31,7 @@ #include "../guichanfwd.h" class SetupTab; +class Button; /** * The setup dialog. @@ -50,6 +51,8 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); + void setInGame(bool inGame); + /** * Event handling method. */ @@ -57,6 +60,7 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; + gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 49c99996..2610be03 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,9 +57,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 61bb9ce9..6112f0e3 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -163,7 +163,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 1371a78e..274f9a48 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -98,6 +98,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable() { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 8eaaf31d..be63ff21 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -142,6 +142,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index 2c2ff0b6..06093946 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1027,7 +1027,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index c82876e1..14df3f01 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -28,6 +28,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -37,7 +39,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -92,6 +93,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -345,24 +351,22 @@ private: -static std::vector player_ignore_strategies; - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 1eb4ede6..dd363d41 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -94,6 +94,7 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); + ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -232,6 +233,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From 75fc8e62d25ff1d39408588f76d95df4a9a7e663 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 5 +++-- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 11 +++++++++-- src/gui/setup.h | 4 ++++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 24 ++++++++++++++---------- src/player_relations.h | 2 ++ 13 files changed, 48 insertions(+), 20 deletions(-) (limited to 'src/gui') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 144b059f..3e626d87 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,7 +205,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -339,11 +338,12 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() { - delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,6 +351,7 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; + delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 4798f598..b24aeb5d 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } TabbedArea *panel = new TabbedArea(); @@ -102,6 +102,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() @@ -141,3 +143,8 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index 9f1bafc7..d798162c 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,6 +32,7 @@ #include "../guichanfwd.h" class SetupTab; +class Button; /** * The setup dialog. @@ -51,6 +52,8 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); + void setInGame(bool inGame); + /** * Event handling method. */ @@ -58,6 +61,7 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; + gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 31b56b51..ecb5bcf7 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,9 +57,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index a8250fce..c29b70ab 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index b2571495..7d0fd48a 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf1ec01c..b0bf1c59 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,6 +130,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index f7468d84..a43544bc 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,7 +1015,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..65219626 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -346,24 +352,22 @@ private: -static std::vector player_ignore_strategies; - std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..edfa9b28 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,6 +95,7 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); + ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -233,6 +234,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From e2e30710a646965a506444cc0dc8a91e1a718002 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:43:56 -0600 Subject: Remove some SetupWindow weirdness --- src/game.cpp | 2 -- src/gui/setup.cpp | 10 ++++++++-- src/gui/setup.h | 2 ++ src/main.cpp | 3 --- 4 files changed, 10 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index ae708adf..6e513eec 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -121,7 +121,6 @@ NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; -Setup* setupWindow; Minimap *minimap; EquipmentWindow *equipmentWindow; TradeWindow *tradeWindow; @@ -261,7 +260,6 @@ void destroyGuiWindows() delete npcTextDialog; delete npcStringDialog; delete skillDialog; - delete setupWindow; delete minimap; delete equipmentWindow; delete tradeWindow; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 62d79d4d..8062ac06 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,10 +65,14 @@ Setup::Setup(): add(btn); // Store this button, as it needs to be enabled/disabled - if (!strcmp(*curBtn, "Reset Windows")) + if (!strcmp(*curBtn, "Reset Windows")) { mResetWindows = btn; + printf("!\n"); + } } + if (mResetWindows) printf("!\n"); + TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); @@ -146,4 +150,6 @@ void Setup::action(const gcn::ActionEvent &event) void Setup::setInGame(bool inGame) { mResetWindows->setEnabled(inGame); -} \ No newline at end of file +} + +Setup* setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index 075c88bf..919445b7 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -63,4 +63,6 @@ class Setup : public Window, public gcn::ActionListener gcn::Button *mResetWindows; }; +extern Setup* setupWindow; + #endif diff --git a/src/main.cpp b/src/main.cpp index 06093946..32ff3ac3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,8 +101,6 @@ namespace { - Window *setupWindow = 0; - struct SetupListener : public gcn::ActionListener { /** @@ -1031,7 +1029,6 @@ int main(int argc, char *argv[]) progressLabel = NULL; currentDialog = NULL; setup = NULL; - setupWindow = NULL; login_wallpaper->decRef(); login_wallpaper = NULL; -- cgit v1.2.3-70-g09d2 From cabb9735f2e31b9f1f64b2496e1775d54861da36 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 ----- src/beingmanager.h | 4 +--- src/game.cpp | 5 ++--- src/gui/chat.cpp | 2 -- src/gui/setup.cpp | 11 ++--------- src/gui/setup.h | 4 ---- src/gui/setup_colors.cpp | 5 +++-- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 - src/gui/window.cpp | 2 -- src/main.cpp | 1 + src/player_relations.cpp | 24 ++++++++++-------------- src/player_relations.h | 2 -- 13 files changed, 20 insertions(+), 48 deletions(-) (limited to 'src/gui') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index e5836aa7..0c7a310a 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,11 +52,6 @@ BeingManager::BeingManager(Network *network): { } -BeingManager::~BeingManager() -{ - clear(); -} - void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 3284ce16..472e2c83 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,8 +37,6 @@ class BeingManager public: BeingManager(Network *network); - ~BeingManager(); - /** * Sets the map on which beings are created */ @@ -115,7 +113,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player + * Destroys all beings except the local player and current NPC (if any) */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 3e626d87..144b059f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -205,6 +205,7 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); + setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -338,12 +339,11 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); - - setupWindow->setInGame(true); } Game::~Game() { + delete player_node; destroyGuiWindows(); delete beingManager; @@ -351,7 +351,6 @@ Game::~Game() delete joystick; delete particleEngine; delete engine; - delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..098d4e46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,8 +109,6 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; - delete mItemLinkHandler; - delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index b24aeb5d..4798f598 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,9 +65,9 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Store this button, as it needs to be enabled/disabled + // Disable this button when the windows aren't created yet if (!strcmp(*curBtn, "Reset Windows")) - mResetWindows = btn; + btn->setEnabled(statusWindow != NULL); } TabbedArea *panel = new TabbedArea(); @@ -102,8 +102,6 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); - - setInGame(false); } Setup::~Setup() @@ -143,8 +141,3 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } - -void Setup::setInGame(bool inGame) -{ - mResetWindows->setEnabled(inGame); -} \ No newline at end of file diff --git a/src/gui/setup.h b/src/gui/setup.h index d798162c..9f1bafc7 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -32,7 +32,6 @@ #include "../guichanfwd.h" class SetupTab; -class Button; /** * The setup dialog. @@ -52,8 +51,6 @@ class Setup : public Window, public gcn::ActionListener */ ~Setup(); - void setInGame(bool inGame); - /** * Event handling method. */ @@ -61,7 +58,6 @@ class Setup : public Window, public gcn::ActionListener private: std::list mTabs; - gcn::Button *mResetWindows; }; #endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index ecb5bcf7..31b56b51 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -57,8 +57,9 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // don't do anything with links - mPreview->setLinkHandler(NULL); + // Replace this later with a more appropriate link handler. For now, this'll + // do, as it'll do nothing when clicked on. + mPreview->setLinkHandler(new ItemLinkHandler()); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index c29b70ab..a8250fce 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -162,7 +162,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete_all(mSkillList); + delete mTable; } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 7d0fd48a..b2571495 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,7 +99,6 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { - uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index b0bf1c59..bf1ec01c 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -130,8 +130,6 @@ Window::~Window() delete(w); } - removeWidgetListener(this); - instances--; // Clean up static resources diff --git a/src/main.cpp b/src/main.cpp index a43544bc..f7468d84 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1015,6 +1015,7 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; + delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 65219626..1c1ba669 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,8 +29,6 @@ #include "player.h" #include "player_relations.h" -#include "utils/dtor.h" - #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -40,6 +38,7 @@ #define IGNORE_EMOTE_TIME 100 + // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -94,11 +93,6 @@ PlayerRelationsManager::PlayerRelationsManager() : { } -PlayerRelationsManager::~PlayerRelationsManager() -{ - delete_all(mIgnoreStrategies); -} - void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -352,22 +346,24 @@ private: +static std::vector player_ignore_strategies; + std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (mIgnoreStrategies.size() == 0) { + if (player_ignore_strategies.size() == 0) { // not initialised yet? - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, "floating '...' bubble", PLAYER_IGNORE_STRATEGY_EMOTE0)); - mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, "floating bubble", "emote1")); - mIgnoreStrategies.push_back(new PIS_nothing()); - mIgnoreStrategies.push_back(new PIS_dotdotdot()); - mIgnoreStrategies.push_back(new PIS_blinkname()); + player_ignore_strategies.push_back(new PIS_nothing()); + player_ignore_strategies.push_back(new PIS_dotdotdot()); + player_ignore_strategies.push_back(new PIS_blinkname()); } - return &mIgnoreStrategies; + return &player_ignore_strategies; } diff --git a/src/player_relations.h b/src/player_relations.h index edfa9b28..0440cace 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -95,7 +95,6 @@ class PlayerRelationsManager { public: PlayerRelationsManager(); - ~PlayerRelationsManager(); /** * Initialise player relations manager (load config file etc.) @@ -234,7 +233,6 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; - std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From 4676d0fe6ee938031ce13a65927718f9b53810cf Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:43:56 -0600 Subject: Remove some SetupWindow weirdness --- src/game.cpp | 2 -- src/gui/setup.cpp | 13 ++++++++++--- src/gui/setup.h | 8 ++++++++ src/main.cpp | 3 --- 4 files changed, 18 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index 144b059f..3b621acd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -122,7 +122,6 @@ NpcListDialog *npcListDialog; NpcTextDialog *npcTextDialog; NpcStringDialog *npcStringDialog; SkillDialog *skillDialog; -Setup* setupWindow; Minimap *minimap; EquipmentWindow *equipmentWindow; TradeWindow *tradeWindow; @@ -261,7 +260,6 @@ void destroyGuiWindows() delete npcTextDialog; delete npcStringDialog; delete skillDialog; - delete setupWindow; delete minimap; delete equipmentWindow; delete tradeWindow; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 4798f598..f1e7a6d9 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -65,12 +65,12 @@ Setup::Setup(): btn->setPosition(x, height - btn->getHeight() - 5); add(btn); - // Disable this button when the windows aren't created yet + // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) - btn->setEnabled(statusWindow != NULL); + mResetWindows = btn; } - TabbedArea *panel = new TabbedArea(); + TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); SetupTab *tab; @@ -141,3 +141,10 @@ void Setup::action(const gcn::ActionEvent &event) tradeWindow->resetToDefaultSize(); } } + +void Setup::setInGame(bool inGame) +{ + mResetWindows->setEnabled(inGame); +} + +Setup* setupWindow; diff --git a/src/gui/setup.h b/src/gui/setup.h index 9f1bafc7..663bdfcb 100644 --- a/src/gui/setup.h +++ b/src/gui/setup.h @@ -56,8 +56,16 @@ class Setup : public Window, public gcn::ActionListener */ void action(const gcn::ActionEvent &event); + /** + * Enables the reset button when in game. + */ + void setInGame(bool inGame); + private: std::list mTabs; + gcn::Button* mResetWindows; }; +extern Setup* setupWindow; + #endif diff --git a/src/main.cpp b/src/main.cpp index f7468d84..9e7c91c0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -101,8 +101,6 @@ namespace { - Window *setupWindow = 0; - struct SetupListener : public gcn::ActionListener { /** @@ -1020,7 +1018,6 @@ int main(int argc, char *argv[]) progressLabel = NULL; currentDialog = NULL; setup = NULL; - setupWindow = NULL; login_wallpaper->decRef(); login_wallpaper = NULL; -- cgit v1.2.3-70-g09d2 From 43eca19b045f30c6456dd936b2baddff945cc047 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 16:31:14 -0600 Subject: Set minimum bounds for speech bubbles, based on the skin's minimum dimensions. Signed-off-by: Ira Rice --- src/gui/speechbubble.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gui') diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index d54bf9ad..dcb03dca 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -39,6 +39,9 @@ SpeechBubble::SpeechBubble(): setShowTitle(false); setTitleBarHeight(0); + setMinWidth(29); + setMinHeight(29); + mCaption = new gcn::Label(""); mCaption->setFont(boldFont); mCaption->setPosition(5, 3); -- cgit v1.2.3-70-g09d2 From 7af746a8ce0c64932923419c5a35a25a5b8c4005 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 16:36:34 -0600 Subject: Delete local player earlier and fix a rare crash Rare crash is in KeyboardConfig, where the active keys array is accessed before it's initialized. Also remove some debug prints that made it into a previous commit. --- src/game.cpp | 2 +- src/gui/setup.cpp | 3 --- src/keyboardconfig.cpp | 1 + 3 files changed, 2 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index 6e513eec..e04a5ee8 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -347,11 +347,11 @@ Game::~Game() destroyGuiWindows(); delete beingManager; + delete player_node; delete floorItemManager; delete joystick; delete particleEngine; delete engine; - delete player_node; beingManager = NULL; floorItemManager = NULL; diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 8062ac06..68bc3a4b 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -67,12 +67,9 @@ Setup::Setup(): // Store this button, as it needs to be enabled/disabled if (!strcmp(*curBtn, "Reset Windows")) { mResetWindows = btn; - printf("!\n"); } } - if (mResetWindows) printf("!\n"); - TabbedArea *panel = new TabbedArea; panel->setDimension(gcn::Rectangle(5, 5, width - 10, height - 40)); diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index 73c0fe0a..06ce4ac7 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -197,6 +197,7 @@ int KeyboardConfig::getKeyEmoteOffset(int keyValue) const bool KeyboardConfig::isKeyActive(int index) { + if (!mActiveKeys) return false; return mActiveKeys[mKey[index].value]; } -- cgit v1.2.3-70-g09d2 From 265172dc1e7b97611c485752dc10345545c4e296 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Tue, 10 Mar 2009 17:33:32 -0600 Subject: Introduced in a Skin holder class, to reduce the amount of needed XML skin loads. Signed-off-by: Ira Rice --- src/gui/window.cpp | 97 +++++++++++++++++++++++++++++++++--------------------- src/gui/window.h | 35 ++++++++++++++++++-- 2 files changed, 91 insertions(+), 41 deletions(-) (limited to 'src/gui') diff --git a/src/gui/window.cpp b/src/gui/window.cpp index bf1ec01c..0e91b68d 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -40,15 +40,15 @@ #include "../resources/image.h" #include "../resources/resourcemanager.h" +#include "../utils/dtor.h" #include "../utils/xml.h" ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; -//ImageRect Window::border; -Image *Window::closeImage = NULL; bool Window::mAlphaChanged = false; +Window::Skins mSkins; class WindowConfigListener : public ConfigListener { @@ -58,6 +58,24 @@ class WindowConfigListener : public ConfigListener } }; +Skin::Skin(): + closeImage(NULL), + instances(0) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + { + delete border.grid[i]; + border.grid[i] = NULL; + } + + closeImage->decRef(); +} + Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), @@ -71,8 +89,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mMinWinWidth(100), mMinWinHeight(40), mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX), - mSkin(skin) + mMaxWinHeight(INT_MAX) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -82,7 +99,7 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std } // Loads the skin - loadSkin(mSkin); + loadSkin(skin); setGuiAlpha(); @@ -132,20 +149,14 @@ Window::~Window() instances--; - // Clean up static resources - for (int i = 0; i < 9; i++) - { - delete border.grid[i]; - border.grid[i] = NULL; - } + mSkin->instances--; if (instances == 0) { config.removeListener("guialpha", windowConfigListener); delete windowConfigListener; windowConfigListener = NULL; - - closeImage->decRef(); + delete_all(mSkins); } } @@ -161,7 +172,7 @@ void Window::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); // Draw title if (mShowTitle) @@ -174,8 +185,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - g->drawImage(closeImage, - getWidth() - closeImage->getWidth() - getPadding(), + g->drawImage(mSkin->closeImage, + getWidth() - mSkin->closeImage->getWidth() - getPadding(), getPadding() ); } @@ -183,10 +194,10 @@ void Window::draw(gcn::Graphics *graphics) // Update window alpha values if (mAlphaChanged) { - for_each(border.grid, border.grid + 9, + for_each(mSkin->border.grid, mSkin->border.grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); - closeImage->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->closeImage->setAlpha(config.getValue("guialpha", 0.8)); } drawChildren(graphics); } @@ -365,10 +376,10 @@ void Window::mousePressed(gcn::MouseEvent &event) if (mCloseButton) { gcn::Rectangle closeButtonRect( - getWidth() - closeImage->getWidth() - getPadding(), + getWidth() - mSkin->closeImage->getWidth() - getPadding(), getPadding(), - closeImage->getWidth(), - closeImage->getHeight()); + mSkin->closeImage->getWidth(), + mSkin->closeImage->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { @@ -679,7 +690,7 @@ void Window::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; @@ -687,14 +698,24 @@ void Window::setGuiAlpha() void Window::loadSkin(const std::string &filename) { + SkinIterator skinIterator = mSkins.find(filename); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + mSkin = skinIterator->second; + return; + } + const std::string windowId = Window::getId(); + mSkin = new Skin(); + ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Window Skin '%s'.", filename.c_str()); logger->log("Loading Window ID '%s'.", windowId.c_str()); - if (filename.empty()) logger->error("Window::loadSkin(): Invalid File Name."); @@ -706,16 +727,15 @@ void Window::loadSkin(const std::string &filename) xmlNodePtr rootNode = doc.rootNode(); if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - { logger->error("Widget Skinning error"); - } std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); Image *dBorders = NULL; if (!skinSetImage.empty()) { - logger->log("Window::loadSkin(): defines '%s' as a skin image.", skinSetImage.c_str()); + logger->log("Window::loadSkin(): defines " + "'%s' as a skin image.", skinSetImage.c_str()); dBorders = resman->getImage("graphics/gui/" + skinSetImage); } else @@ -735,8 +755,8 @@ void Window::loadSkin(const std::string &filename) { // Iterate through 's // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For now it - // can just be hard-coded. + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. for_each_xml_child_node(partNode, widgetNode) { if (!xmlStrEqual(partNode->name, BAD_CAST "part")) @@ -751,27 +771,27 @@ void Window::loadSkin(const std::string &filename) const int height = XML::getProperty(partNode, "height", 1); if (partType == "top-left-corner") - border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-edge") - border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-right-corner") - border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); // MIDDLE ROW else if (partType == "left-edge") - border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bg-quad") - border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "right-edge") - border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); // BOTTOM ROW else if (partType == "bottom-left-corner") - border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-edge") - border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-right-corner") - border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + mSkin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); // Part is of an uknown type. else @@ -789,7 +809,8 @@ void Window::loadSkin(const std::string &filename) logger->log("Finished loading Window Skin."); // Hard-coded for now until we update the above code to look for window buttons. - closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkin->closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkins[filename] = mSkin; } Layout &Window::getLayout() diff --git a/src/gui/window.h b/src/gui/window.h index 4fc6c862..c5660c58 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -23,6 +23,8 @@ #ifndef WINDOW_H #define WINDOW_H +#include + #include #include @@ -39,6 +41,18 @@ class LayoutCell; class ResizeGrip; class WindowContainer; +class Skin +{ + public: + Skin(); + ~Skin(); + + std::string mName; /**< Name of the skin to use */ + ImageRect border; /**< The window border and background */ + Image *closeImage; /**< Close Button Image */ + int instances; +}; + /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -297,7 +311,23 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + /** + * Overrideable functionality for when the window is to close. This + * allows for class implementations to clean up or do certain actions + * on window close they couldn't do otherwise. + */ virtual void close(); + + /** + * Map containing all window skins + */ + typedef std::map Skins; + + /** + * Iterator for window skins + */ + typedef Skins::iterator SkinIterator; + protected: /** The window container windows add themselves to. */ @@ -341,7 +371,6 @@ class Window : public gcn::Window, gcn::WidgetListener int mDefaultY; /**< Default window Y position */ int mDefaultWidth; /**< Default window width */ int mDefaultHeight; /**< Default window height */ - std::string mSkin; /**< Name of the skin to use */ /** * The config listener that listens to changes relevant to all windows. @@ -350,8 +379,8 @@ class Window : public gcn::Window, gcn::WidgetListener static int mouseResize; /**< Active resize handles */ static int instances; /**< Number of Window instances */ - ImageRect border; /**< The window border and background */ - static Image *closeImage; /**< Close Button Image */ + + Skin* mSkin; /**< Skin in use by this window */ /** * The width of the resize border. Is independent of the actual window -- cgit v1.2.3-70-g09d2 From a3d675e1dde4c80e687c7264bc86c6189c13dddb Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 11:34:43 -0600 Subject: Don't move stuff from inventory when not visible --- src/gui/itemshortcutcontainer.cpp | 6 +++--- src/gui/storagewindow.cpp | 2 ++ src/gui/trade.cpp | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index 603e7e50..67525140 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -19,6 +19,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "inventorywindow.h" #include "itemshortcutcontainer.h" #include "itempopup.h" #include "viewport.h" @@ -184,9 +185,8 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) + if (itemShortcut->isItemSelected() && inventoryWindow->isVisible()) { itemShortcut->setItem(index); itemShortcut->setItemSelected(-1); @@ -247,7 +247,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item) + if (item && inventoryWindow->isVisible()) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 2b8ab8f3..5981f121 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -126,6 +126,8 @@ void StorageWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "store") { + if (!inventoryWindow->isVisible()) return; + Item *item = inventoryWindow->getSelectedItem(); if (!item) diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 2deabbf2..30604d6b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -240,6 +240,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (event.getId() == "add") { + if (!inventoryWindow->isVisible()) return; + if (!item) return; -- cgit v1.2.3-70-g09d2 From c2e4a7a70971355f1446bb01053af8a1da8c98e1 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 13:37:38 -0600 Subject: Fix a memory leak in dropdown --- src/gui/widgets/dropdown.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gui') diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index e1a24cb7..c91a8524 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -107,6 +107,9 @@ DropDown::~DropDown() for_each(skin.grid, skin.grid + 9, dtor()); } + + gcn::ListModel *listModel = getListModel(); + if (listModel) delete listModel; } void DropDown::draw(gcn::Graphics* graphics) -- cgit v1.2.3-70-g09d2 From 2a6b52f6467bfb4babb2a33205752f58554b651b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 14:38:26 -0600 Subject: Moved the Skin class outside of the Window class, in order to allow other widget containers to use skins as well, and to make it easier to extend later. Signed-off-by: Ira Rice --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 1 - src/gui/gui.cpp | 1 + src/gui/skin.cpp | 174 +++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/skin.h | 67 +++++++++++++++++++++ src/gui/window.cpp | 156 +++-------------------------------------------- src/gui/window.h | 33 +--------- src/main.cpp | 54 +++++++++-------- 10 files changed, 288 insertions(+), 204 deletions(-) create mode 100644 src/gui/skin.cpp create mode 100644 src/gui/skin.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index 46034040..6bae4561 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -236,6 +236,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c7003946..171ec7ff 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -185,6 +185,8 @@ SET(SRCS gui/shortcutcontainer.h gui/skill.cpp gui/skill.h + gui/skin.cpp + gui/skin.h gui/slider.cpp gui/slider.h gui/speechbubble.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 963e41fb..440c020e 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -135,6 +135,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/shortcutcontainer.h \ gui/skill.cpp \ gui/skill.h \ + gui/skin.cpp \ + gui/skin.h \ gui/slider.cpp \ gui/slider.h \ gui/speechbubble.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 13be3663..3b621acd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -345,7 +345,6 @@ Game::~Game() destroyGuiWindows(); delete beingManager; - delete player_node; delete floorItemManager; delete joystick; delete particleEngine; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 85a33218..2c0ddee9 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -27,6 +27,7 @@ #include "focushandler.h" #include "gui.h" #include "sdlinput.h" +#include "skin.h" #include "truetypefont.h" #include "viewport.h" #include "window.h" diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp new file mode 100644 index 00000000..e9d081e9 --- /dev/null +++ b/src/gui/skin.cpp @@ -0,0 +1,174 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "skin.h" + +#include "../log.h" + +#include "../resources/image.h" +#include "../resources/resourcemanager.h" + +#include "../utils/dtor.h" +#include "../utils/xml.h" + +SkinLoader* skinLoader = NULL; + +Skin::Skin(): + closeImage(NULL), + instances(0) +{ +} + +Skin::~Skin() +{ + // Clean up static resources + for (int i = 0; i < 9; i++) + { + delete border.grid[i]; + border.grid[i] = NULL; + } + + closeImage->decRef(); +} + +Skin* SkinLoader::load(const std::string &filename) +{ + SkinIterator skinIterator = mSkins.find(filename); + + if (mSkins.end() != skinIterator) + { + skinIterator->second->instances++; + return skinIterator->second; + } + + Skin* skin = new Skin(); + + ResourceManager *resman = ResourceManager::getInstance(); + + logger->log("Loading Skin '%s'.", filename.c_str()); + + if (filename.empty()) + logger->error("SkinLoader::load(): Invalid File Name."); + + // TODO: + // If there is an error loading the specified file, we should try to revert + // to a 'default' skin file. Only if the 'default' skin file can't be loaded + // should we have a terminating error. + XML::Document doc(filename); + xmlNodePtr rootNode = doc.rootNode(); + + if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) + logger->error("Widget Skinning error"); + + std::string skinSetImage; + skinSetImage = XML::getProperty(rootNode, "image", ""); + Image *dBorders = NULL; + if (!skinSetImage.empty()) + { + logger->log("SkinLoader::load(): defines " + "'%s' as a skin image.", skinSetImage.c_str()); + dBorders = resman->getImage("graphics/gui/" + skinSetImage); + } + else + { + logger->error("SkinLoader::load(): Skinset does not define an image!"); + } + + //iterate 's + for_each_xml_child_node(widgetNode, rootNode) + { + if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) + continue; + + std::string widgetType; + widgetType = XML::getProperty(widgetNode, "type", "unknown"); + if (widgetType == "Window") + { + // Iterate through 's + // LEEOR / TODO: + // We need to make provisions to load in a CloseButton image. For + // now it can just be hard-coded. + for_each_xml_child_node(partNode, widgetNode) + { + if (!xmlStrEqual(partNode->name, BAD_CAST "part")) + continue; + + std::string partType; + partType = XML::getProperty(partNode, "type", "unknown"); + // TOP ROW + const int xPos = XML::getProperty(partNode, "xpos", 0); + const int yPos = XML::getProperty(partNode, "ypos", 0); + const int width = XML::getProperty(partNode, "width", 1); + const int height = XML::getProperty(partNode, "height", 1); + + if (partType == "top-left-corner") + skin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-edge") + skin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "top-right-corner") + skin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + + // MIDDLE ROW + else if (partType == "left-edge") + skin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bg-quad") + skin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "right-edge") + skin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + + // BOTTOM ROW + else if (partType == "bottom-left-corner") + skin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-edge") + skin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + else if (partType == "bottom-right-corner") + skin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + + // Part is of an uknown type. + else + logger->log("SkinLoader::load(): Unknown Part Type '%s'", partType.c_str()); + } + } + // Widget is of an uknown type. + else + { + logger->log("SkinLoader::load(): Unknown Widget Type '%s'", widgetType.c_str()); + } + } + dBorders->decRef(); + + logger->log("Finished loading Skin."); + + // Hard-coded for now until we update the above code to look for window buttons. + skin->closeImage = resman->getImage("graphics/gui/close_button.png"); + mSkins[filename] = skin; + return skin; +} + +SkinLoader::SkinLoader() +{ +} + +SkinLoader::~SkinLoader() +{ + delete_all(mSkins); +} + diff --git a/src/gui/skin.h b/src/gui/skin.h new file mode 100644 index 00000000..6dddb4a8 --- /dev/null +++ b/src/gui/skin.h @@ -0,0 +1,67 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef SKIN_H +#define SKIN_H + +#include +#include + +#include "../graphics.h" + +class Image; + +class Skin +{ + public: + Skin(); + ~Skin(); + + std::string mName; /**< Name of the skin to use */ + ImageRect border; /**< The window border and background */ + Image *closeImage; /**< Close Button Image */ + int instances; +}; + +// Map containing all window skins +typedef std::map Skins; + +// Iterator for window skins +typedef Skins::iterator SkinIterator; + +class SkinLoader +{ + public: + SkinLoader(); + ~SkinLoader(); + + /** + * Loads a skin + */ + Skin* load(const std::string &filename); + + private: + Skins mSkins; +}; + +extern SkinLoader* skinLoader; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 0e91b68d..def81c53 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -27,6 +27,7 @@ #include #include "gui.h" +#include "skin.h" #include "window.h" #include "windowcontainer.h" @@ -38,17 +39,12 @@ #include "../log.h" #include "../resources/image.h" -#include "../resources/resourcemanager.h" - -#include "../utils/dtor.h" -#include "../utils/xml.h" ConfigListener *Window::windowConfigListener = 0; WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; bool Window::mAlphaChanged = false; -Window::Skins mSkins; class WindowConfigListener : public ConfigListener { @@ -58,24 +54,6 @@ class WindowConfigListener : public ConfigListener } }; -Skin::Skin(): - closeImage(NULL), - instances(0) -{ -} - -Skin::~Skin() -{ - // Clean up static resources - for (int i = 0; i < 9; i++) - { - delete border.grid[i]; - border.grid[i] = NULL; - } - - closeImage->decRef(); -} - Window::Window(const std::string& caption, bool modal, Window *parent, const std::string& skin): gcn::Window(caption), mGrip(0), @@ -94,17 +72,11 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std logger->log("Window::Window(\"%s\")", caption.c_str()); if (!windowContainer) - { throw GCN_EXCEPTION("Window::Window(): no windowContainer set"); - } - - // Loads the skin - loadSkin(skin); - - setGuiAlpha(); if (instances == 0) { + skinLoader = new SkinLoader(); windowConfigListener = new WindowConfigListener(); // Send GUI alpha changed for initialization windowConfigListener->optionChanged("guialpha"); @@ -117,6 +89,11 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std setPadding(3); setTitleBarHeight(20); + // Loads the skin + mSkin = skinLoader->load(skin); + + setGuiAlpha(); + // Add this window to the window container windowContainer->add(this); @@ -153,10 +130,10 @@ Window::~Window() if (instances == 0) { + delete skinLoader; config.removeListener("guialpha", windowConfigListener); delete windowConfigListener; windowConfigListener = NULL; - delete_all(mSkins); } } @@ -696,123 +673,6 @@ void Window::setGuiAlpha() mAlphaChanged = false; } -void Window::loadSkin(const std::string &filename) -{ - SkinIterator skinIterator = mSkins.find(filename); - - if (mSkins.end() != skinIterator) - { - skinIterator->second->instances++; - mSkin = skinIterator->second; - return; - } - - const std::string windowId = Window::getId(); - - mSkin = new Skin(); - - ResourceManager *resman = ResourceManager::getInstance(); - - logger->log("Loading Window Skin '%s'.", filename.c_str()); - logger->log("Loading Window ID '%s'.", windowId.c_str()); - - if (filename.empty()) - logger->error("Window::loadSkin(): Invalid File Name."); - - // TODO: - // If there is an error loading the specified file, we should try to revert - // to a 'default' skin file. Only if the 'default' skin file can't be loaded - // should we have a terminating error. - XML::Document doc(filename); - xmlNodePtr rootNode = doc.rootNode(); - - if (!rootNode || !xmlStrEqual(rootNode->name, BAD_CAST "skinset")) - logger->error("Widget Skinning error"); - - std::string skinSetImage; - skinSetImage = XML::getProperty(rootNode, "image", ""); - Image *dBorders = NULL; - if (!skinSetImage.empty()) - { - logger->log("Window::loadSkin(): defines " - "'%s' as a skin image.", skinSetImage.c_str()); - dBorders = resman->getImage("graphics/gui/" + skinSetImage); - } - else - { - logger->error("Window::loadSkin(): Skinset does not define an image!"); - } - - //iterate 's - for_each_xml_child_node(widgetNode, rootNode) - { - if (!xmlStrEqual(widgetNode->name, BAD_CAST "widget")) - continue; - - std::string widgetType; - widgetType = XML::getProperty(widgetNode, "type", "unknown"); - if (widgetType == "Window") - { - // Iterate through 's - // LEEOR / TODO: - // We need to make provisions to load in a CloseButton image. For - // now it can just be hard-coded. - for_each_xml_child_node(partNode, widgetNode) - { - if (!xmlStrEqual(partNode->name, BAD_CAST "part")) - continue; - - std::string partType; - partType = XML::getProperty(partNode, "type", "unknown"); - // TOP ROW - const int xPos = XML::getProperty(partNode, "xpos", 0); - const int yPos = XML::getProperty(partNode, "ypos", 0); - const int width = XML::getProperty(partNode, "width", 1); - const int height = XML::getProperty(partNode, "height", 1); - - if (partType == "top-left-corner") - mSkin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-edge") - mSkin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "top-right-corner") - mSkin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); - - // MIDDLE ROW - else if (partType == "left-edge") - mSkin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bg-quad") - mSkin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "right-edge") - mSkin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); - - // BOTTOM ROW - else if (partType == "bottom-left-corner") - mSkin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-edge") - mSkin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); - else if (partType == "bottom-right-corner") - mSkin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); - - // Part is of an uknown type. - else - logger->log("Window::loadSkin(): Unknown Part Type '%s'", partType.c_str()); - } - } - // Widget is of an uknown type. - else - { - logger->log("Window::loadSkin(): Unknown Widget Type '%s'", widgetType.c_str()); - } - } - dBorders->decRef(); - - logger->log("Finished loading Window Skin."); - - // Hard-coded for now until we update the above code to look for window buttons. - mSkin->closeImage = resman->getImage("graphics/gui/close_button.png"); - mSkins[filename] = mSkin; -} - Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index c5660c58..7ae7ebba 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -23,8 +23,6 @@ #ifndef WINDOW_H #define WINDOW_H -#include - #include #include @@ -35,24 +33,13 @@ class ConfigListener; class GCContainer; class ContainerPlacer; -class Image; class Layout; class LayoutCell; class ResizeGrip; +class Skin; +class SkinLoader; class WindowContainer; -class Skin -{ - public: - Skin(); - ~Skin(); - - std::string mName; /**< Name of the skin to use */ - ImageRect border; /**< The window border and background */ - Image *closeImage; /**< Close Button Image */ - int instances; -}; - /** * A window. This window can be dragged around and has a title bar. Windows are * invisible by default. @@ -296,11 +283,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ void reflowLayout(int w = 0, int h = 0); - /** - * Loads a window skin - */ - void loadSkin(const std::string &filename); - /** * Adds a widget to the window and sets it at given cell. */ @@ -317,17 +299,6 @@ class Window : public gcn::Window, gcn::WidgetListener * on window close they couldn't do otherwise. */ virtual void close(); - - /** - * Map containing all window skins - */ - typedef std::map Skins; - - /** - * Iterator for window skins - */ - typedef Skins::iterator SkinIterator; - protected: /** The window container windows add themselves to. */ diff --git a/src/main.cpp b/src/main.cpp index 9e7c91c0..a7032fb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -437,16 +437,18 @@ void init_engine(const Options &options) state = LOGIN_STATE; /**< Initial game state */ // Initialize sound engine - try { - if (config.getValue("sound", 0) == 1) { + try + { + if (config.getValue("sound", 0) == 1) sound.init(); - } + sound.setSfxVolume((int) config.getValue("sfxVolume", defaultSfxVolume)); sound.setMusicVolume((int) config.getValue("musicVolume", defaultMusicVolume)); } - catch (const char *err) { + catch (const char *err) + { state = ERROR_STATE; errorMessage = err; logger->log("Warning: %s", err); @@ -830,17 +832,18 @@ int main(int argc, char *argv[]) while (state != EXIT_STATE) { // Handle SDL events - while (SDL_PollEvent(&event)) { - switch (event.type) { + while (SDL_PollEvent(&event)) + { + switch (event.type) + { case SDL_QUIT: state = EXIT_STATE; break; case SDL_KEYDOWN: if (event.key.keysym.sym == SDLK_ESCAPE) - { state = EXIT_STATE; - } + break; } @@ -855,11 +858,10 @@ int main(int argc, char *argv[]) { state = ERROR_STATE; - if (!network->getError().empty()) { + if (!network->getError().empty()) errorMessage = network->getError(); - } else { + else errorMessage = _("Got disconnected from server!"); - } } if (progressBar->isVisible()) @@ -882,7 +884,8 @@ int main(int argc, char *argv[]) gui->draw(); graphics->updateScreen(); - if (state != oldstate) { + if (state != oldstate) + { switch (oldstate) { case UPDATE_STATE: @@ -913,12 +916,14 @@ int main(int argc, char *argv[]) oldstate = state; if (currentDialog && state != ACCOUNT_STATE && - state != CHAR_CONNECT_STATE) { + state != CHAR_CONNECT_STATE) + { delete currentDialog; currentDialog = NULL; } - switch (state) { + switch (state) + { case LOADDATA_STATE: logger->log("State: LOADDATA"); @@ -941,10 +946,13 @@ int main(int argc, char *argv[]) case LOGIN_STATE: logger->log("State: LOGIN"); - if (!loginData.password.empty()) { + if (!loginData.password.empty()) + { loginData.registerLogin = false; state = ACCOUNT_STATE; - } else { + } + else + { currentDialog = new LoginDialog(&loginData); positionDialog(currentDialog, screenWidth, screenHeight); @@ -1029,9 +1037,12 @@ int main(int argc, char *argv[]) break; case UPDATE_STATE: - if (options.skipUpdate) { + if (options.skipUpdate) + { state = LOADDATA_STATE; - } else { + } + else + { // Determine which source to use for the update host if (!options.updateHost.empty()) updateHost = options.updateHost; @@ -1109,9 +1120,8 @@ int main(int argc, char *argv[]) SDLNet_Quit(); if (nullFile) - { fclose(nullFile); - } + logger->log("State: EXIT"); exit_engine(); PHYSFS_deinit(); @@ -1123,16 +1133,12 @@ void SetupListener::action(const gcn::ActionEvent &event) Window *window = NULL; if (event.getId() == "Setup") - { window = setupWindow; - } if (window) { window->setVisible(!window->isVisible()); if (window->isVisible()) - { window->requestMoveToTop(); - } } } -- cgit v1.2.3-70-g09d2 From a34d8a88df817371823e8e036b3a9208f8d5ba85 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 11:34:43 -0600 Subject: Don't move stuff from inventory when not visible --- src/gui/itemshortcutcontainer.cpp | 6 +++--- src/gui/storagewindow.cpp | 2 ++ src/gui/trade.cpp | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index abe81537..cb709227 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -20,6 +20,7 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include "inventorywindow.h" #include "itemshortcutcontainer.h" #include "itempopup.h" #include "viewport.h" @@ -168,9 +169,8 @@ void ItemShortcutContainer::mousePressed(gcn::MouseEvent &event) if (event.getButton() == gcn::MouseEvent::LEFT) { - // Stores the selected item if theirs one. - if (itemShortcut->isItemSelected()) + if (itemShortcut->isItemSelected() && inventoryWindow->isVisible()) { itemShortcut->setItem(index); itemShortcut->setItemSelected(-1); @@ -231,7 +231,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item) + if (item && inventoryWindow->isVisible()) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index ca7a547f..6a813bc4 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -121,6 +121,8 @@ void StorageWindow::action(const gcn::ActionEvent &event) { if (event.getId() == "store") { + if (!inventoryWindow->isVisible()) return; + Item *item = inventoryWindow->getSelectedItem(); if (!item) diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index a28ff0f9..caae33c0 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -239,6 +239,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (event.getId() == "add") { + if (!inventoryWindow->isVisible()) return; + if (!item) return; -- cgit v1.2.3-70-g09d2 From 6b538196a799525d8ad4bf5cb5affe87745d4242 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 11 Mar 2009 13:37:38 -0600 Subject: Fix a memory leak in dropdown --- src/gui/widgets/dropdown.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/gui') diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 035ce5d7..7036c2ee 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -108,6 +108,9 @@ DropDown::~DropDown() for_each(skin.grid, skin.grid + 9, dtor()); } + + gcn::ListModel *listModel = getListModel(); + if (listModel) delete listModel; } void DropDown::draw(gcn::Graphics* graphics) -- cgit v1.2.3-70-g09d2 From c2ae6d9cea9fc3d861e73d4cf7eca5284519758e Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:06:30 -0600 Subject: Added a new Popup class, which overall is functionally similar to the Window class, but stripped down to the bare essential functionality to just draw and position them. This means no resizing, no close buttons, no ability to move them, etc. This should help reduce the overhead in drawing speech bubbles, as well as other popup type dialogs, but is also not a drop in replacement for the Window class as well. Signed-off-by: Ira Rice --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 2 + src/game.cpp | 4 +- src/gui/itempopup.cpp | 13 +-- src/gui/itempopup.h | 4 +- src/gui/itemshortcutcontainer.cpp | 2 +- src/gui/menuwindow.cpp | 13 +-- src/gui/menuwindow.h | 4 +- src/gui/ministatus.cpp | 15 +-- src/gui/ministatus.h | 4 +- src/gui/popup.cpp | 211 ++++++++++++++++++++++++++++++++++++++ src/gui/popup.h | 196 +++++++++++++++++++++++++++++++++++ src/gui/popupmenu.cpp | 10 +- src/gui/speechbubble.cpp | 5 +- src/gui/speechbubble.h | 4 +- src/gui/window.cpp | 61 ++++++----- src/gui/window.h | 4 - src/gui/windowcontainer.cpp | 2 + src/gui/windowcontainer.h | 7 ++ 20 files changed, 479 insertions(+), 86 deletions(-) create mode 100644 src/gui/popup.cpp create mode 100644 src/gui/popup.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index 6bae4561..aa1737b7 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -195,6 +195,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 171ec7ff..9fdca23a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -144,6 +144,8 @@ SET(SRCS gui/passwordfield.h gui/playerbox.cpp gui/playerbox.h + gui/popup.cpp + gui/popup.h gui/popupmenu.cpp gui/popupmenu.h gui/progressbar.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 440c020e..c4265dec 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -94,6 +94,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ gui/playerbox.h \ + gui/popup.cpp \ + gui/popup.h \ gui/popupmenu.cpp \ gui/popupmenu.h \ gui/progressbar.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 3b621acd..47f4ffd2 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -220,12 +220,12 @@ void createGuiWindows(Network *network) chatWindow->setVisible((bool) config.getValue( chatWindow->getWindowName() + "Visible", true)); miniStatusWindow->setVisible((bool) config.getValue( - miniStatusWindow->getWindowName() + "Visible", true)); + miniStatusWindow->getPopupName() + "Visible", true)); buyDialog->setVisible(false); sellDialog->setVisible(false); tradeWindow->setVisible(false); menuWindow->setVisible((bool) config.getValue( - menuWindow->getWindowName() + "Visible", true)); + menuWindow->getPopupName() + "Visible", true)); itemShortcutWindow->setVisible((bool) config.getValue( itemShortcutWindow->getWindowName() + "Visible", true)); emoteShortcutWindow->setVisible((bool) config.getValue( diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 0f7e2d11..ebbc6af3 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -29,9 +29,8 @@ #include "itempopup.h" #include "scrollarea.h" #include "textbox.h" -#include "windowcontainer.h" -#include "widgets/layout.h" +#include "../graphics.h" #include "../resources/iteminfo.h" @@ -39,12 +38,8 @@ #include "../utils/stringutils.h" ItemPopup::ItemPopup(): - Window() + Popup() { - setResizable(false); - setShowTitle(false); - setTitleBarHeight(0); - // Item Name mItemName = new gcn::Label("Label"); mItemName->setFont(boldFont); @@ -208,8 +203,8 @@ unsigned int ItemPopup::getNumRows() void ItemPopup::view(int x, int y) { - if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); + if (graphics->getWidth() < (x + getWidth() + 5)) + x = graphics->getWidth() - getWidth(); if ((y - getHeight() - 10) < 0) y = 0; else diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index a91d8c6f..97da4cbb 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -24,13 +24,13 @@ #ifndef ITEMPOPUP_H #define ITEMPOPUP_H -#include "window.h" +#include "popup.h" class ItemInfo; class ScrollArea; class TextBox; -class ItemPopup : public Window +class ItemPopup : public Popup { public: ItemPopup(); diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index cb709227..c1baca76 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -231,7 +231,7 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) Item *item = player_node->getInventory()->findItem(itemId); - if (item && inventoryWindow->isVisible()) + if (item) { mItemPopup->setItem(item->getInfo()); mItemPopup->setOpaque(false); diff --git a/src/gui/menuwindow.cpp b/src/gui/menuwindow.cpp index 8a695865..e1be908b 100644 --- a/src/gui/menuwindow.cpp +++ b/src/gui/menuwindow.cpp @@ -26,7 +26,9 @@ #include "button.h" #include "menuwindow.h" -#include "windowcontainer.h" +#include "window.h" + +#include "../graphics.h" #include "../utils/gettext.h" @@ -50,13 +52,8 @@ namespace { } MenuWindow::MenuWindow(): - Window("") + Popup("Menu") { - setResizable(false); - setWindowName("Menu"); - setMovable(false); - setTitleBarHeight(0); - // Buttons static const char *buttonNames[] = { @@ -81,7 +78,7 @@ MenuWindow::MenuWindow(): h = btn->getHeight(); } - setPosition(windowContainer->getWidth() - x - 3, 3); + setPosition(graphics->getWidth() - x - 3, 3); setContentSize(x - 3, h); } diff --git a/src/gui/menuwindow.h b/src/gui/menuwindow.h index f70a332e..e8dc0b2e 100644 --- a/src/gui/menuwindow.h +++ b/src/gui/menuwindow.h @@ -23,14 +23,14 @@ #ifndef MENU_H #define MENU_H -#include "window.h" +#include "popup.h" /** * The Button Menu. * * \ingroup Interface */ -class MenuWindow : public Window +class MenuWindow : public Popup { public: /** diff --git a/src/gui/ministatus.cpp b/src/gui/ministatus.cpp index 6537b48e..18b9d714 100644 --- a/src/gui/ministatus.cpp +++ b/src/gui/ministatus.cpp @@ -31,13 +31,8 @@ #include "../utils/stringutils.h" MiniStatusWindow::MiniStatusWindow(): - Window("") + Popup("MiniStatus") { - setWindowName("MiniStatus"); - setResizable(false); - setMovable(false); - setTitleBarHeight(0); - mHpBar = new ProgressBar(1.0f, 100, 20, 0, 171, 34); mMpBar = new ProgressBar(1.0f, 100, 20, 26, 102, 230); mXpBar = new ProgressBar(1.0f, 100, 20, 143, 192, 211); @@ -52,25 +47,17 @@ MiniStatusWindow::MiniStatusWindow(): setContentSize(mXpBar->getX() + mXpBar->getWidth(), mXpBar->getY() + mXpBar->getHeight()); - setDefaultSize(0, 0, getWidth(), getHeight()); - loadWindowState(); } void MiniStatusWindow::update() { // HP Bar coloration if (player_node->mHp < int(player_node->mMaxHp / 3)) - { mHpBar->setColor(223, 32, 32); // Red - } else if (player_node->mHp < int((player_node->mMaxHp / 3) * 2)) - { mHpBar->setColor(230, 171, 34); // Orange - } else - { mHpBar->setColor(0, 171, 34); // Green - } float xp = (float) player_node->getXp() / player_node->mXpForNextLevel; diff --git a/src/gui/ministatus.h b/src/gui/ministatus.h index 33ee548d..b3fc58fc 100644 --- a/src/gui/ministatus.h +++ b/src/gui/ministatus.h @@ -23,7 +23,7 @@ #ifndef MINISTATUS_H #define MINISTATUS_H -#include "window.h" +#include "popup.h" class ProgressBar; @@ -32,7 +32,7 @@ class ProgressBar; * * \ingroup Interface */ -class MiniStatusWindow : public Window +class MiniStatusWindow : public Popup { public: /** diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp new file mode 100644 index 00000000..906f7a2e --- /dev/null +++ b/src/gui/popup.cpp @@ -0,0 +1,211 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include +#include + +#include + +#include "gui.h" +#include "skin.h" +#include "popup.h" +#include "window.h" +#include "windowcontainer.h" + +#include "../configlistener.h" +#include "../configuration.h" +#include "../log.h" + +#include "../resources/image.h" + +ConfigListener *Popup::popupConfigListener = 0; +int Popup::instances = 0; +bool Popup::mAlphaChanged = false; + +class PopupConfigListener : public ConfigListener +{ + void optionChanged(const std::string &) + { + Popup::mAlphaChanged = true; + } +}; + +Popup::Popup(const std::string& name, Window *parent, + const std::string& skin): + mParent(parent), + mPopupName(name), + mMinWidth(100), + mMinHeight(40), + mMaxWidth(INT_MAX), + mMaxHeight(INT_MAX) +{ + logger->log("Popup::Popup(\"%s\")", name.c_str()); + + if (!windowContainer) + throw GCN_EXCEPTION("Popup::Popup(): no windowContainer set"); + + if (instances == 0) + { + popupConfigListener = new PopupConfigListener(); + // Send GUI alpha changed for initialization + popupConfigListener->optionChanged("guialpha"); + config.addListener("guialpha", popupConfigListener); + } + + setPadding(3); + + instances++; + + // Loads the skin + mSkin = skinLoader->load(skin); + + setGuiAlpha(); + + // Add this window to the window container + windowContainer->add(this); + + // Popups are invisible by default + setVisible(false); + + addWidgetListener(this); +} + +Popup::~Popup() +{ + logger->log("Popup::~Popup(\"%s\")", mPopupName.c_str()); + + while (!mWidgets.empty()) + { + gcn::Widget *w = mWidgets.front(); + remove(w); + delete(w); + } + + instances--; + + mSkin->instances--; + + if (instances == 0) + { + config.removeListener("guialpha", popupConfigListener); + delete popupConfigListener; + popupConfigListener = NULL; + } +} + +void Popup::setWindowContainer(WindowContainer *wc) +{ + windowContainer = wc; +} + +void Popup::draw(gcn::Graphics *graphics) +{ + if (!isVisible()) + return; + + Graphics *g = static_cast(graphics); + + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + + // Update Popup alpha values + if (mAlphaChanged) + { + for_each(mSkin->border.grid, mSkin->border.grid + 9, + std::bind2nd(std::mem_fun(&Image::setAlpha), + config.getValue("guialpha", 0.8))); + } + drawChildren(graphics); +} + +gcn::Rectangle Popup::getChildrenArea() +{ + return gcn::Rectangle(getPadding(), 0, getWidth() - getPadding() * 2, + getHeight() - getPadding() * 2); +} + +void Popup::setContentSize(int width, int height) +{ + width += 2 * getPadding(); + height += 2 * getPadding(); + + if (getMinWidth() > width) + width = getMinWidth(); + else if (getMaxWidth() < width) + width = getMaxWidth(); + if (getMinHeight() > height) + height = getMinHeight(); + else if (getMaxHeight() < height) + height = getMaxHeight(); + + setSize(width, height); +} + +void Popup::setLocationRelativeTo(gcn::Widget *widget) +{ + int wx, wy; + int x, y; + + widget->getAbsolutePosition(wx, wy); + getAbsolutePosition(x, y); + + setPosition(getX() + (wx + (widget->getWidth() - getWidth()) / 2 - x), + getY() + (wy + (widget->getHeight() - getHeight()) / 2 - y)); +} + +void Popup::setMinWidth(unsigned int width) +{ + mMinWidth = width; +} + +void Popup::setMinHeight(unsigned int height) +{ + mMinHeight = height; +} + +void Popup::setMaxWidth(unsigned int width) +{ + mMaxWidth = width; +} + +void Popup::setMaxHeight(unsigned int height) +{ + mMaxHeight = height; +} + +void Popup::scheduleDelete() +{ + windowContainer->scheduleDelete(this); +} + +void Popup::setGuiAlpha() +{ + //logger->log("Popup::setGuiAlpha: Alpha Value %f", config.getValue("guialpha", 0.8)); + for (int i = 0; i < 9; i++) + { + //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); + mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + } + + mAlphaChanged = false; +} + diff --git a/src/gui/popup.h b/src/gui/popup.h new file mode 100644 index 00000000..0f7eebbf --- /dev/null +++ b/src/gui/popup.h @@ -0,0 +1,196 @@ +/* + * Aethyra + * Copyright (C) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef POPUP_H +#define POPUP_H + +#include + +#include + +#include "../graphics.h" +#include "../guichanfwd.h" + +class ConfigListener; +class Skin; +class SkinLoader; +class Window; +class WindowContainer; + +/** + * A rather reduced down version of the Window class that is particularly suited + * for + * + * \ingroup GUI + */ +class Popup : public gcn::Container, gcn::WidgetListener +{ + public: + friend class PopupConfigListener; + + /** + * Constructor. Initializes the title to the given text and hooks + * itself into the popup container. + * + * @param name A human readable name for the popup. Only useful for + * debugging purposes. + * @param parent The parent Window. This is the Window standing above + * this one in the Window hiearchy. When reordering, + * a Popup will never go below its parent Window. + * @param skin The location where the Popup's skin XML can be found. + */ + Popup(const std::string& name = "", Window *parent = NULL, + const std::string &skin = "graphics/gui/gui.xml"); + + /** + * Destructor. Deletes all the added widgets. + */ + ~Popup(); + + /** + * Sets the window container to be used by new popups. + */ + static void setWindowContainer(WindowContainer *windowContainer); + + /** + * Draws the popup. + */ + void draw(gcn::Graphics *graphics); + + /** + * Sets the size of this popup. + */ + void setContentSize(int width, int height); + + /** + * Sets the location relative to the given widget. + */ + void setLocationRelativeTo(gcn::Widget *widget); + + /** + * Sets the minimum width of the popup. + */ + void setMinWidth(unsigned int width); + + /** + * Sets the minimum height of the popup. + */ + void setMinHeight(unsigned int height); + + /** + * Sets the maximum width of the popup. + */ + void setMaxWidth(unsigned int width); + + /** + * Sets the minimum height of the popup. + */ + void setMaxHeight(unsigned int height); + + /** + * Gets the minimum width of the popup. + */ + int getMinWidth() { return mMinWidth; } + + /** + * Gets the minimum height of the popup. + */ + int getMinHeight() { return mMinHeight; } + + /** + * Gets the maximum width of the popup. + */ + int getMaxWidth() { return mMaxWidth; } + + /** + * Gets the minimum height of the popup. + */ + int getMaxHeight() { return mMaxHeight; } + + /** + * Gets the padding of the popup. The padding is the distance between + * the popup border and the content. + * + * @return The padding of the popup. + * @see setPadding + */ + unsigned int getPadding() const { return mPadding; } + + /** + * Sets the padding of the popup. The padding is the distance between the + * popup border and the content. + * + * @param padding The padding of the popup. + * @see getPadding + */ + void setPadding(unsigned int padding) { mPadding = padding; } + + /** + * Returns the parent Window. + * + * @return The parent Window or NULL if there is none. + */ + Window* getParentWindow() { return mParent; } + + /** + * Sets the name of the popup. This is only useful for debug purposes. + */ + void setPopupName(const std::string &name) { mPopupName = name; } + + /** + * Returns the name of the popup. This is only useful for debug purposes. + */ + const std::string& getPopupName() { return mPopupName; } + + /** + * Schedule this popup for deletion. It will be deleted at the start + * of the next logic update. + */ + void scheduleDelete(); + + // Inherited from BasicContainer + + virtual gcn::Rectangle getChildrenArea(); + + private: + void setGuiAlpha(); + + Window *mParent; /**< The parent Window (if there is one) */ + std::string mPopupName; /**< Name of the Popup */ + static bool mAlphaChanged; /**< Whether the alpha percent was changed */ + int mMinWidth; /**< Minimum Popup width */ + int mMinHeight; /**< Minimum Popup height */ + int mMaxWidth; /**< Maximum Popup width */ + int mMaxHeight; /**< Maximum Popup height */ + unsigned int mPadding; /**< Holds the padding of the window. */ + + /** + * The config listener that listens to changes relevant to all Popups. + */ + static ConfigListener *popupConfigListener; + + static int instances; /**< Number of Popup instances */ + + Skin* mSkin; /**< Skin in use by this Popup */ +}; + +#endif diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index cead20ed..02be3055 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,11 +27,11 @@ #include "inventorywindow.h" #include "item_amount.h" #include "popupmenu.h" -#include "windowcontainer.h" #include "../being.h" #include "../beingmanager.h" #include "../floor_item.h" +#include "../graphics.h" #include "../item.h" #include "../localplayer.h" #include "../npc.h" @@ -292,10 +292,10 @@ void PopupMenu::showPopup(int x, int y, Item *item) void PopupMenu::showPopup(int x, int y) { setContentSize(mBrowserBox->getWidth() + 8, mBrowserBox->getHeight() + 8); - if (windowContainer->getWidth() < (x + getWidth() + 5)) - x = windowContainer->getWidth() - getWidth(); - if (windowContainer->getHeight() < (y + getHeight() + 5)) - y = windowContainer->getHeight() - getHeight(); + if (graphics->getWidth() < (x + getWidth() + 5)) + x = graphics->getWidth() - getWidth(); + if (graphics->getHeight() < (y + getHeight() + 5)) + y = graphics->getHeight() - getHeight(); setPosition(x, y); setVisible(true); requestMoveToTop(); diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index dcb03dca..0b18209e 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -32,13 +32,10 @@ #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): - Window(_("Speech"), false, NULL, "graphics/gui/speechbubble.xml"), + Popup("Speech", NULL, "graphics/gui/speechbubble.xml"), mText("") { setContentSize(140, 46); - setShowTitle(false); - setTitleBarHeight(0); - setMinWidth(29); setMinHeight(29); diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index 6b03cc85..a1a597c1 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -23,12 +23,12 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H -#include "window.h" +#include "popup.h" class ScrollArea; class TextBox; -class SpeechBubble : public Window +class SpeechBubble : public Popup { public: SpeechBubble(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index def81c53..76c19751 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -41,7 +41,6 @@ #include "../resources/image.h" ConfigListener *Window::windowConfigListener = 0; -WindowContainer *Window::windowContainer = 0; int Window::instances = 0; int Window::mouseResize = 0; bool Window::mAlphaChanged = false; @@ -216,39 +215,39 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, } else if (position == ImageRect::UPPER_CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; + offsetX += (graphics->getWidth() - getWidth()) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); + offsetX += graphics->getWidth() - getWidth(); } else if (position == ImageRect::LEFT) { - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetX += (graphics->getWidth() - getWidth()) / 2; + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); - offsetY += (windowContainer->getHeight() - getHeight()) / 2; + offsetX += graphics->getWidth() - getWidth(); + offsetY += (graphics->getHeight() - getHeight()) / 2; } else if (position == ImageRect::LOWER_LEFT) { - offsetY += windowContainer->getHeight() - getHeight(); + offsetY += graphics->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_CENTER) { - offsetX += (windowContainer->getWidth() - getWidth()) / 2; - offsetY += windowContainer->getHeight() - getHeight(); + offsetX += (graphics->getWidth() - getWidth()) / 2; + offsetY += graphics->getHeight() - getHeight(); } else if (position == ImageRect::LOWER_RIGHT) { - offsetX += windowContainer->getWidth() - getWidth(); - offsetY += windowContainer->getHeight() - getHeight(); + offsetX += graphics->getWidth() - getWidth(); + offsetY += graphics->getHeight() - getHeight(); } setPosition(offsetX, offsetY); @@ -429,8 +428,8 @@ void Window::mouseDragged(gcn::MouseEvent &event) { int newX = std::max(0, getX()); int newY = std::max(0, getY()); - newX = std::min(windowContainer->getWidth() - getWidth(), newX); - newY = std::min(windowContainer->getHeight() - getHeight(), newY); + newX = std::min(graphics->getWidth() - getWidth(), newX); + newY = std::min(graphics->getHeight() - getHeight(), newY); setPosition(newX, newY); } @@ -475,13 +474,13 @@ void Window::mouseDragged(gcn::MouseEvent &event) newDim.height += newDim.y; newDim.y = 0; } - if (newDim.x + newDim.width > windowContainer->getWidth()) + if (newDim.x + newDim.width > graphics->getWidth()) { - newDim.width = windowContainer->getWidth() - newDim.x; + newDim.width = graphics->getWidth() - newDim.x; } - if (newDim.y + newDim.height > windowContainer->getHeight()) + if (newDim.y + newDim.height > graphics->getHeight()) { - newDim.height = windowContainer->getHeight() - newDim.y; + newDim.height = graphics->getHeight() - newDim.y; } // Update mouse offset when dragging bottom or right border @@ -585,39 +584,39 @@ void Window::setDefaultSize(int defaultWidth, int defaultHeight, } else if (position == ImageRect::UPPER_CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; + x = (graphics->getWidth() - defaultWidth) / 2; } else if (position == ImageRect::UPPER_RIGHT) { - x = windowContainer->getWidth() - defaultWidth; + x = graphics->getWidth() - defaultWidth; } else if (position == ImageRect::LEFT) { - y = (windowContainer->getHeight() - defaultHeight) / 2; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; - y = (windowContainer->getHeight() - defaultHeight) / 2; + x = (graphics->getWidth() - defaultWidth) / 2; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::RIGHT) { - x = windowContainer->getWidth() - defaultWidth; - y = (windowContainer->getHeight() - defaultHeight) / 2; + x = graphics->getWidth() - defaultWidth; + y = (graphics->getHeight() - defaultHeight) / 2; } else if (position == ImageRect::LOWER_LEFT) { - y = windowContainer->getHeight() - defaultHeight; + y = graphics->getHeight() - defaultHeight; } else if (position == ImageRect::LOWER_CENTER) { - x = (windowContainer->getWidth() - defaultWidth) / 2; - y = windowContainer->getHeight() - defaultHeight; + x = (graphics->getWidth() - defaultWidth) / 2; + y = graphics->getHeight() - defaultHeight; } else if (position == ImageRect::LOWER_RIGHT) { - x = windowContainer->getWidth() - defaultWidth; - y = windowContainer->getHeight() - defaultHeight; + x = graphics->getWidth() - defaultWidth; + y = graphics->getHeight() - defaultHeight; } mDefaultX = x - offsetX; diff --git a/src/gui/window.h b/src/gui/window.h index 7ae7ebba..d573d85f 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,10 +300,6 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); - protected: - /** The window container windows add themselves to. */ - static WindowContainer *windowContainer; - private: enum ResizeHandles { diff --git a/src/gui/windowcontainer.cpp b/src/gui/windowcontainer.cpp index 0aa61965..ad86a253 100644 --- a/src/gui/windowcontainer.cpp +++ b/src/gui/windowcontainer.cpp @@ -24,6 +24,8 @@ #include "../utils/dtor.h" +WindowContainer *windowContainer = NULL; + void WindowContainer::logic() { delete_all(mDeathList); diff --git a/src/gui/windowcontainer.h b/src/gui/windowcontainer.h index 09f34cf5..23b221cf 100644 --- a/src/gui/windowcontainer.h +++ b/src/gui/windowcontainer.h @@ -46,6 +46,11 @@ class WindowContainer : public gcn::Container */ void scheduleDelete(gcn::Widget *widget); + /** + * Get the number of widget instances + */ + int getNumberOfInstances() { return mDeathList.size(); } + private: /** * List of widgets that are scheduled to be deleted. @@ -55,4 +60,6 @@ class WindowContainer : public gcn::Container Widgets mDeathList; }; +extern WindowContainer* windowContainer; + #endif -- cgit v1.2.3-70-g09d2 From 951fc647b291b38a3e4652b326ed4c4867c7ec0b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:28:40 -0600 Subject: Fixed up speech bubbles slightly so that it respects different padding values. Signed-off-by: Ira Rice --- src/gui/speechbubble.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 0b18209e..d342328e 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -79,7 +79,7 @@ void SpeechBubble::setText(std::string text, bool showName) const int fontHeight = getFont()->getHeight(); const int numRows = showName ? mSpeechBox->getNumberOfRows() + 1 : mSpeechBox->getNumberOfRows(); - int yPos = showName ? fontHeight + 3 : 3; + int yPos = showName ? fontHeight + getPadding() : getPadding(); int height = (numRows * fontHeight); if (width < mSpeechBox->getMinWidth()) @@ -87,11 +87,11 @@ void SpeechBubble::setText(std::string text, bool showName) if (numRows == 1) { - yPos = (fontHeight / 4) + 3; + yPos = (fontHeight / 4) + getPadding(); height = ((3 * fontHeight) / 2) + 1; } - setContentSize(width + fontHeight, height + 6); + setContentSize(width + fontHeight, height + getPadding()); mSpeechArea->setDimension(gcn::Rectangle(4, yPos, width + 5, height)); } -- cgit v1.2.3-70-g09d2 From daf0d9e183456b30ffebfddfbcb2da2946c32e1d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 18:34:09 -0600 Subject: Removed widget listeners from the popup class. Tests have shown that at least for popup type functionality, this isn't needed. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 2 -- src/gui/popup.h | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 906f7a2e..4cf6bbf0 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -86,8 +86,6 @@ Popup::Popup(const std::string& name, Window *parent, // Popups are invisible by default setVisible(false); - - addWidgetListener(this); } Popup::~Popup() diff --git a/src/gui/popup.h b/src/gui/popup.h index 0f7eebbf..bfe8d7e9 100644 --- a/src/gui/popup.h +++ b/src/gui/popup.h @@ -23,8 +23,6 @@ #ifndef POPUP_H #define POPUP_H -#include - #include #include "../graphics.h" @@ -42,7 +40,7 @@ class WindowContainer; * * \ingroup GUI */ -class Popup : public gcn::Container, gcn::WidgetListener +class Popup : public gcn::Container { public: friend class PopupConfigListener; -- cgit v1.2.3-70-g09d2 From 1e2fbea2e6d4ab319763c6ffb35e4e4acdd4d5f5 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 20:47:09 -0600 Subject: Centered buy/sell dialog. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gui') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index f7684670..2022b040 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -51,6 +51,8 @@ BuySellDialog::BuySellDialog(Network *network): setContentSize(x, 2 * y + buyButton->getHeight()); + setLocationRelativeTo(ImageRect::CENTER); + requestFocus(); } -- cgit v1.2.3-70-g09d2 From c410a861fddc7829408d687e61c67c6101555067 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 21:38:17 -0600 Subject: Modified Skin class to use proper encapsulation, instead of leaving its skin variables public. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 6 +++--- src/gui/skin.cpp | 47 ++++++++++++++++++++++++++++++++--------------- src/gui/skin.h | 40 +++++++++++++++++++++++++++++++++++++--- src/gui/window.cpp | 18 +++++++++--------- 4 files changed, 81 insertions(+), 30 deletions(-) (limited to 'src/gui') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 4cf6bbf0..8e0c8fb9 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -123,12 +123,12 @@ void Popup::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); // Update Popup alpha values if (mAlphaChanged) { - for_each(mSkin->border.grid, mSkin->border.grid + 9, + for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); } @@ -201,7 +201,7 @@ void Popup::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Popup::setGuiAlpha: Border Image (%i)", i); - mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index e9d081e9..8787770c 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -31,9 +31,11 @@ SkinLoader* skinLoader = NULL; -Skin::Skin(): - closeImage(NULL), - instances(0) +Skin::Skin(ImageRect skin, Image* close, std::string name): + instances(0), + mName(name), + border(skin), + closeImage(close) { } @@ -49,6 +51,18 @@ Skin::~Skin() closeImage->decRef(); } +int Skin::getMinWidth() +{ + return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + + border.grid[2]->getWidth(); +} + +int Skin::getMinHeight() +{ + return (border.grid[0]->getHeight() + border.grid[3]->getHeight()) + + border.grid[6]->getHeight(); +} + Skin* SkinLoader::load(const std::string &filename) { SkinIterator skinIterator = mSkins.find(filename); @@ -59,8 +73,6 @@ Skin* SkinLoader::load(const std::string &filename) return skinIterator->second; } - Skin* skin = new Skin(); - ResourceManager *resman = ResourceManager::getInstance(); logger->log("Loading Skin '%s'.", filename.c_str()); @@ -81,6 +93,8 @@ Skin* SkinLoader::load(const std::string &filename) std::string skinSetImage; skinSetImage = XML::getProperty(rootNode, "image", ""); Image *dBorders = NULL; + ImageRect border; + if (!skinSetImage.empty()) { logger->log("SkinLoader::load(): defines " @@ -120,27 +134,27 @@ Skin* SkinLoader::load(const std::string &filename) const int height = XML::getProperty(partNode, "height", 1); if (partType == "top-left-corner") - skin->border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[0] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-edge") - skin->border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[1] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "top-right-corner") - skin->border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[2] = dBorders->getSubImage(xPos, yPos, width, height); // MIDDLE ROW else if (partType == "left-edge") - skin->border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[3] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bg-quad") - skin->border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[4] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "right-edge") - skin->border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[5] = dBorders->getSubImage(xPos, yPos, width, height); // BOTTOM ROW else if (partType == "bottom-left-corner") - skin->border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[6] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-edge") - skin->border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[7] = dBorders->getSubImage(xPos, yPos, width, height); else if (partType == "bottom-right-corner") - skin->border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); + border.grid[8] = dBorders->getSubImage(xPos, yPos, width, height); // Part is of an uknown type. else @@ -158,7 +172,10 @@ Skin* SkinLoader::load(const std::string &filename) logger->log("Finished loading Skin."); // Hard-coded for now until we update the above code to look for window buttons. - skin->closeImage = resman->getImage("graphics/gui/close_button.png"); + Image* closeImage = resman->getImage("graphics/gui/close_button.png"); + + Skin* skin = new Skin(border, closeImage); + mSkins[filename] = skin; return skin; } diff --git a/src/gui/skin.h b/src/gui/skin.h index 6dddb4a8..b7e70330 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -32,13 +32,47 @@ class Image; class Skin { public: - Skin(); + Skin(ImageRect skin, Image* close, std::string name = ""); ~Skin(); + /** + * Returns the skin's name. Useful for giving a human friendly skin + * name if a dialog for skin selection for a specific window type is + * done. + */ + std::string getName() { return mName; } + + /** + * Returns the background skin. + */ + ImageRect getBorder() { return border; } + + /** + * Returns the image used by a close button for this skin. + */ + Image* getCloseImage() { return closeImage; } + + /** + * Returns the number of instances which use this skin. + */ + int getNumberOfInstances() { return instances; } + + /** + * Returns the minimum width which can be used with this skin. + */ + int getMinWidth(); + + /** + * Returns the minimum height which can be used with this skin. + */ + int getMinHeight(); + + int instances; + + private: std::string mName; /**< Name of the skin to use */ ImageRect border; /**< The window border and background */ Image *closeImage; /**< Close Button Image */ - int instances; }; // Map containing all window skins @@ -47,7 +81,7 @@ typedef std::map Skins; // Iterator for window skins typedef Skins::iterator SkinIterator; -class SkinLoader +class SkinLoader { public: SkinLoader(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 76c19751..5c01daf3 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -148,7 +148,7 @@ void Window::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->border); + g->drawImageRect(0, 0, getWidth(), getHeight(), mSkin->getBorder()); // Draw title if (mShowTitle) @@ -161,8 +161,8 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton) { - g->drawImage(mSkin->closeImage, - getWidth() - mSkin->closeImage->getWidth() - getPadding(), + g->drawImage(mSkin->getCloseImage(), + getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), getPadding() ); } @@ -170,10 +170,10 @@ void Window::draw(gcn::Graphics *graphics) // Update window alpha values if (mAlphaChanged) { - for_each(mSkin->border.grid, mSkin->border.grid + 9, + for_each(mSkin->getBorder().grid, mSkin->getBorder().grid + 9, std::bind2nd(std::mem_fun(&Image::setAlpha), config.getValue("guialpha", 0.8))); - mSkin->closeImage->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getCloseImage()->setAlpha(config.getValue("guialpha", 0.8)); } drawChildren(graphics); } @@ -352,10 +352,10 @@ void Window::mousePressed(gcn::MouseEvent &event) if (mCloseButton) { gcn::Rectangle closeButtonRect( - getWidth() - mSkin->closeImage->getWidth() - getPadding(), + getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), getPadding(), - mSkin->closeImage->getWidth(), - mSkin->closeImage->getHeight()); + mSkin->getCloseImage()->getWidth(), + mSkin->getCloseImage()->getHeight()); if (closeButtonRect.isPointInRect(x, y)) { @@ -666,7 +666,7 @@ void Window::setGuiAlpha() for (int i = 0; i < 9; i++) { //logger->log("Window::setGuiAlpha: Border Image (%i)", i); - mSkin->border.grid[i]->setAlpha(config.getValue("guialpha", 0.8)); + mSkin->getBorder().grid[i]->setAlpha(config.getValue("guialpha", 0.8)); } mAlphaChanged = false; -- cgit v1.2.3-70-g09d2 From 5b1e2aae6391edc99425ed7671d59eddd774212e Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Wed, 11 Mar 2009 21:46:22 -0600 Subject: Enforce minimum widths and heights to be at least as big as the minumum width and height for the skin used. Signed-off-by: Ira Rice --- src/gui/popup.cpp | 4 ++-- src/gui/skin.cpp | 4 ++-- src/gui/skin.h | 4 ++-- src/gui/window.cpp | 5 +++-- 4 files changed, 9 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/popup.cpp b/src/gui/popup.cpp index 8e0c8fb9..17d299a5 100644 --- a/src/gui/popup.cpp +++ b/src/gui/popup.cpp @@ -172,12 +172,12 @@ void Popup::setLocationRelativeTo(gcn::Widget *widget) void Popup::setMinWidth(unsigned int width) { - mMinWidth = width; + mMinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth(); } void Popup::setMinHeight(unsigned int height) { - mMinHeight = height; + mMinHeight = height > mSkin->getMinHeight() ? height : mSkin->getMinHeight(); } void Popup::setMaxWidth(unsigned int width) diff --git a/src/gui/skin.cpp b/src/gui/skin.cpp index 8787770c..d44c54a8 100644 --- a/src/gui/skin.cpp +++ b/src/gui/skin.cpp @@ -51,13 +51,13 @@ Skin::~Skin() closeImage->decRef(); } -int Skin::getMinWidth() +unsigned int Skin::getMinWidth() { return (border.grid[0]->getWidth() + border.grid[1]->getWidth()) + border.grid[2]->getWidth(); } -int Skin::getMinHeight() +unsigned int Skin::getMinHeight() { return (border.grid[0]->getHeight() + border.grid[3]->getHeight()) + border.grid[6]->getHeight(); diff --git a/src/gui/skin.h b/src/gui/skin.h index b7e70330..b8a1242e 100644 --- a/src/gui/skin.h +++ b/src/gui/skin.h @@ -60,12 +60,12 @@ class Skin /** * Returns the minimum width which can be used with this skin. */ - int getMinWidth(); + unsigned int getMinWidth(); /** * Returns the minimum height which can be used with this skin. */ - int getMinHeight(); + unsigned int getMinHeight(); int instances; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 5c01daf3..d40ebca6 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -255,12 +255,13 @@ void Window::setLocationRelativeTo(ImageRect::ImagePosition position, void Window::setMinWidth(unsigned int width) { - mMinWinWidth = width; + mMinWinWidth = width > mSkin->getMinWidth() ? width : mSkin->getMinWidth(); } void Window::setMinHeight(unsigned int height) { - mMinWinHeight = height; + mMinWinHeight = height > mSkin->getMinHeight() ? + height : mSkin->getMinHeight(); } void Window::setMaxWidth(unsigned int width) -- cgit v1.2.3-70-g09d2 From e2d60401eaf55abe9e2251854f3174ffe0f4ad9e Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 12 Mar 2009 06:44:16 -0600 Subject: Move emote sprite loading into EmoteDB --- src/being.cpp | 25 ++----------------------- src/being.h | 10 +--------- src/gui/emotecontainer.cpp | 2 +- src/gui/emotecontainer.h | 2 +- src/gui/emoteshortcutcontainer.cpp | 4 ++-- src/gui/emoteshortcutcontainer.h | 2 +- src/main.cpp | 2 -- src/resources/emotedb.cpp | 24 +++++++++++++++++------- src/resources/emotedb.h | 9 ++++++--- 9 files changed, 31 insertions(+), 49 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index bf49e852..60fb8d13 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -61,7 +61,6 @@ int Being::mNumberOfHairColors = 1; int Being::mNumberOfHairstyles = 1; std::vector Being::hairColors; -std::vector Being::emotionSet; static const int X_SPEECH_OFFSET = 18; static const int Y_SPEECH_OFFSET = 60; @@ -487,7 +486,7 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) const int emotionIndex = mEmotion - 1; if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast()) - emotionSet[emotionIndex]->draw(graphics, px, py); + EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py); } void Being::drawSpeech(int offsetX, int offsetY) @@ -770,7 +769,7 @@ std::string Being::getHairColor(int index) return hairColors[index]; } -void Being::initializeHair() +void Being::load() { // Hairstyles are encoded as negative numbers. Count how far negative // we can go. @@ -809,23 +808,3 @@ void Being::initializeHair() } } } - -void Being::load() -{ - // Setup emote sprites - for (int i = 0; i <= EmoteDB::getLast(); i++) - { - EmoteInfo info = EmoteDB::get(i); - - std::string file = "graphics/sprites/" + info.sprites.front()->sprite; - int variant = info.sprites.front()->variant; - emotionSet.push_back(AnimatedSprite::load(file, variant)); - } - - initializeHair(); -} - -void Being::cleanup() -{ - delete_all(emotionSet); -} \ No newline at end of file diff --git a/src/being.h b/src/being.h index 754c163a..b9b57a0d 100644 --- a/src/being.h +++ b/src/being.h @@ -392,8 +392,6 @@ class Being : public Sprite */ void untarget() { mUsedTargetCursor = NULL; } - AnimatedSprite* getEmote(int index) { return emotionSet[index]; } - void setEmote(Uint8 emotion, Uint8 emote_time) { mEmotion = emotion; @@ -447,8 +445,6 @@ class Being : public Sprite static void load(); - static void cleanup(); - protected: /** * Sets the new path for this being. @@ -511,7 +507,7 @@ class Being : public Sprite Uint16 mHairStyle, mHairColor; Gender mGender; int mPx, mPy; /**< Pixel coordinates */ - Uint16 mStunMode; /**< Stun mode; zero if not stunned */ + Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set mStatusEffects; /**< set of active status effects */ gcn::Color mNameColor; @@ -524,8 +520,6 @@ class Being : public Sprite ParticleList mChildParticleEffects; private: - static void initializeHair(); - /** * Calculates the offset in the given directions. * If walking in direction 'neg' the value is negated. @@ -540,8 +534,6 @@ class Being : public Sprite // Target cursor being used SimpleAnimation* mUsedTargetCursor; - - static std::vector emotionSet; /**< Emoticons used by beings */ }; #endif diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index ad3f5c83..ececd9aa 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -53,7 +53,7 @@ EmoteContainer::EmoteContainer(): // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(player_node->getEmote(i)); + mEmoteImg.push_back(EmoteDB::getAnimation(i)); } mSelImg = resman->getImage("graphics/gui/selection.png"); diff --git a/src/gui/emotecontainer.h b/src/gui/emotecontainer.h index fefce793..88df29fc 100644 --- a/src/gui/emotecontainer.h +++ b/src/gui/emotecontainer.h @@ -121,7 +121,7 @@ class EmoteContainer : public gcn::Widget, */ void distributeValueChangedEvent(void); - std::vector mEmoteImg; + std::vector mEmoteImg; Image *mSelImg; int mSelectedEmoteIndex; diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index df1bf74c..c96ea855 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -59,7 +59,7 @@ EmoteShortcutContainer::EmoteShortcutContainer(): // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(player_node->getEmote(i)); + mEmoteImg.push_back(EmoteDB::getAnimation(i)); } mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS; @@ -112,7 +112,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (mEmoteMoved) { // Draw the emote image being dragged by the cursor. - AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; + const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; if (sprite) { const int tPosX = mCursorPosX - (sprite->getWidth() / 2); diff --git a/src/gui/emoteshortcutcontainer.h b/src/gui/emoteshortcutcontainer.h index d32a9f79..2997cb09 100644 --- a/src/gui/emoteshortcutcontainer.h +++ b/src/gui/emoteshortcutcontainer.h @@ -68,7 +68,7 @@ class EmoteShortcutContainer : public ShortcutContainer void mouseReleased(gcn::MouseEvent &event); private: - std::vector mEmoteImg; + std::vector mEmoteImg; bool mEmoteClicked; int mEmoteMoved; diff --git a/src/main.cpp b/src/main.cpp index 306514e4..0034fc60 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -482,8 +482,6 @@ void exit_engine() // Shutdown sound sound.close(); - Being::cleanup(); - // Unload XML databases ColorDB::unload(); EmoteDB::unload(); diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 5e9a146c..5bc8407a 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -21,6 +21,7 @@ #include "emotedb.h" +#include "../animatedsprite.h" #include "../log.h" #include "../utils/xml.h" @@ -41,9 +42,8 @@ void EmoteDB::load() mLastEmote = 0; EmoteSprite *unknownSprite = new EmoteSprite; - unknownSprite->sprite = "error.xml"; + unknownSprite->sprite = AnimatedSprite::load("error.xml"); unknownSprite->name = "unknown"; - unknownSprite->variant = 0; mUnknown.sprites.push_back(unknownSprite); logger->log("Initializing emote database..."); @@ -77,8 +77,10 @@ void EmoteDB::load() if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { EmoteSprite *currentSprite = new EmoteSprite; - currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content; - currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + std::string file = "graphics/sprites/" + (std::string) + (const char*) spriteNode->xmlChildrenNode->content; + currentSprite->sprite = AnimatedSprite::load(file, + XML::getProperty(spriteNode, "variant", 0)); currentInfo->sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) @@ -102,6 +104,7 @@ void EmoteDB::unload() { while (!i->second->sprites.empty()) { + delete i->second->sprites.front()->sprite; delete i->second->sprites.front(); i->second->sprites.pop_front(); } @@ -112,6 +115,7 @@ void EmoteDB::unload() while (!mUnknown.sprites.empty()) { + delete mUnknown.sprites.front()->sprite; delete mUnknown.sprites.front(); mUnknown.sprites.pop_front(); } @@ -119,21 +123,27 @@ void EmoteDB::unload() mLoaded = false; } -const EmoteInfo& EmoteDB::get(int id) +const EmoteInfo *EmoteDB::get(int id) { EmoteInfosIterator i = mEmoteInfos.find(id); if (i == mEmoteInfos.end()) { logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); - return mUnknown; + return &mUnknown; } else { - return *(i->second); + return i->second; } } +const AnimatedSprite* EmoteDB::getAnimation(int id) +{ + const EmoteInfo *info = get(id); + return info->sprites.front()->sprite; +} + const int& EmoteDB::getLast() { return mLastEmote; diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h index ad21722a..691881c8 100644 --- a/src/resources/emotedb.h +++ b/src/resources/emotedb.h @@ -26,11 +26,12 @@ #include #include +class AnimatedSprite; + struct EmoteSprite { - std::string sprite; + const AnimatedSprite *sprite; std::string name; - int variant; }; struct EmoteInfo @@ -50,7 +51,9 @@ namespace EmoteDB void unload(); - const EmoteInfo& get(int id); + const EmoteInfo *get(int id); + + const AnimatedSprite *getAnimation(int id); const int& getLast(); -- cgit v1.2.3-70-g09d2 From 37b812f2892a9b11a88abcbcde0b47aca76f4a71 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 12 Mar 2009 06:44:16 -0600 Subject: Move emote sprite loading into EmoteDB --- src/being.cpp | 30 +----------------------------- src/being.h | 10 ---------- src/gui/emotecontainer.cpp | 2 +- src/gui/emotecontainer.h | 2 +- src/gui/emoteshortcutcontainer.cpp | 4 ++-- src/gui/emoteshortcutcontainer.h | 2 +- src/main.cpp | 3 --- src/resources/emotedb.cpp | 24 +++++++++++++++++------- src/resources/emotedb.h | 9 ++++++--- 9 files changed, 29 insertions(+), 57 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index d94d50d9..54908b07 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -52,10 +52,8 @@ #include "utils/dtor.h" #include "utils/gettext.h" #include "utils/stringutils.h" -#include "utils/xml.h" int Being::mNumberOfHairstyles = 1; -std::vector Being::emotionSet; static const int X_SPEECH_OFFSET = 18; static const int Y_SPEECH_OFFSET = 60; @@ -461,7 +459,7 @@ void Being::drawEmotion(Graphics *graphics, int offsetX, int offsetY) const int emotionIndex = mEmotion - 1; if (emotionIndex >= 0 && emotionIndex <= EmoteDB::getLast()) - emotionSet[emotionIndex]->draw(graphics, px, py); + EmoteDB::getAnimation(emotionIndex)->draw(graphics, px, py); } void Being::drawSpeech(int offsetX, int offsetY) @@ -580,29 +578,3 @@ void Being::setTargetAnimation(SimpleAnimation* animation) mUsedTargetCursor->reset(); } -void Being::load() -{ - // Setup emote sprites - for (int i = 0; i <= EmoteDB::getLast(); i++) - { - EmoteInfo info = EmoteDB::get(i); - - std::string file = "graphics/sprites/" + info.sprites.front()->sprite; - int variant = info.sprites.front()->variant; - emotionSet.push_back(AnimatedSprite::load(file, variant)); - } - - // Hairstyles are encoded as negative numbers. Count how far negative - // we can go. - int hairstyles = 1; - while (ItemDB::get(-hairstyles).getSprite(GENDER_MALE) != "error.xml") - { - hairstyles++; - } - mNumberOfHairstyles = hairstyles; -} - -void Being::cleanup() -{ - delete_all(emotionSet); -} diff --git a/src/being.h b/src/being.h index 85e0c080..6f3125c8 100644 --- a/src/being.h +++ b/src/being.h @@ -387,8 +387,6 @@ class Being : public Sprite */ void untarget() { mUsedTargetCursor = NULL; } - AnimatedSprite* getEmote(int index) { return emotionSet[index]; } - void setEmote(Uint8 emotion, Uint8 emote_time) { mEmotion = emotion; @@ -404,10 +402,6 @@ class Being : public Sprite virtual AnimatedSprite* getSprite(int index) const { return mSprites[index]; } - static void load(); - - static void cleanup(); - protected: /** * Sets the new path for this being. @@ -450,8 +444,6 @@ class Being : public Sprite Uint16 mHairStyle, mHairColor; Gender mGender; int mPx, mPy; /**< Pixel coordinates */ - Uint16 mStunMode; /**< Stun mode; zero if not stunned */ - StatusEffects mStatusEffects; /**< Bitset of active status effects */ gcn::Color mNameColor; @@ -474,8 +466,6 @@ class Being : public Sprite // Target cursor being used SimpleAnimation* mUsedTargetCursor; - - static std::vector emotionSet; /**< Emoticons used by beings */ }; #endif diff --git a/src/gui/emotecontainer.cpp b/src/gui/emotecontainer.cpp index 9764ab9c..22b4cf50 100644 --- a/src/gui/emotecontainer.cpp +++ b/src/gui/emotecontainer.cpp @@ -54,7 +54,7 @@ EmoteContainer::EmoteContainer(): // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(player_node->getEmote(i)); + mEmoteImg.push_back(EmoteDB::getAnimation(i)); } mSelImg = resman->getImage("graphics/gui/selection.png"); diff --git a/src/gui/emotecontainer.h b/src/gui/emotecontainer.h index 260f1754..7e88cb71 100644 --- a/src/gui/emotecontainer.h +++ b/src/gui/emotecontainer.h @@ -122,7 +122,7 @@ class EmoteContainer : public gcn::Widget, */ void distributeValueChangedEvent(void); - std::vector mEmoteImg; + std::vector mEmoteImg; Image *mSelImg; int mSelectedEmoteIndex; diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index f4cef106..8c9df14e 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -60,7 +60,7 @@ EmoteShortcutContainer::EmoteShortcutContainer(): // Setup emote sprites for (int i = 0; i <= EmoteDB::getLast(); i++) { - mEmoteImg.push_back(player_node->getEmote(i)); + mEmoteImg.push_back(EmoteDB::getAnimation(i)); } mMaxItems = EmoteDB::getLast() < MAX_ITEMS ? EmoteDB::getLast() : MAX_ITEMS; @@ -113,7 +113,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) if (mEmoteMoved) { // Draw the emote image being dragged by the cursor. - AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; + const AnimatedSprite* sprite = mEmoteImg[mEmoteMoved - 1]; if (sprite) { const int tPosX = mCursorPosX - (sprite->getWidth() / 2); diff --git a/src/gui/emoteshortcutcontainer.h b/src/gui/emoteshortcutcontainer.h index 4c4b3614..ff9f929c 100644 --- a/src/gui/emoteshortcutcontainer.h +++ b/src/gui/emoteshortcutcontainer.h @@ -69,7 +69,7 @@ class EmoteShortcutContainer : public ShortcutContainer void mouseReleased(gcn::MouseEvent &event); private: - std::vector mEmoteImg; + std::vector mEmoteImg; bool mEmoteClicked; int mEmoteMoved; diff --git a/src/main.cpp b/src/main.cpp index ec075a4c..a7032fb1 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -479,8 +479,6 @@ void exit_engine() // Shutdown sound sound.close(); - Being::cleanup(); - // Unload XML databases ColorDB::unload(); EmoteDB::unload(); @@ -941,7 +939,6 @@ int main(int argc, char *argv[]) MonsterDB::load(); NPCDB::load(); EmoteDB::load(); - Being::load(); // Hairstyles and emotions state = CHAR_CONNECT_STATE; break; diff --git a/src/resources/emotedb.cpp b/src/resources/emotedb.cpp index 23a7833c..ec87c5cd 100644 --- a/src/resources/emotedb.cpp +++ b/src/resources/emotedb.cpp @@ -21,6 +21,7 @@ #include "emotedb.h" +#include "../animatedsprite.h" #include "../log.h" #include "../utils/xml.h" @@ -41,9 +42,8 @@ void EmoteDB::load() mLastEmote = 0; EmoteSprite *unknownSprite = new EmoteSprite; - unknownSprite->sprite = "error.xml"; + unknownSprite->sprite = AnimatedSprite::load("error.xml"); unknownSprite->name = "unknown"; - unknownSprite->variant = 0; mUnknown.sprites.push_back(unknownSprite); logger->log("Initializing emote database..."); @@ -77,8 +77,10 @@ void EmoteDB::load() if (xmlStrEqual(spriteNode->name, BAD_CAST "sprite")) { EmoteSprite *currentSprite = new EmoteSprite; - currentSprite->sprite = (const char*) spriteNode->xmlChildrenNode->content; - currentSprite->variant = XML::getProperty(spriteNode, "variant", 0); + std::string file = "graphics/sprites/" + (std::string) + (const char*) spriteNode->xmlChildrenNode->content; + currentSprite->sprite = AnimatedSprite::load(file, + XML::getProperty(spriteNode, "variant", 0)); currentInfo->sprites.push_back(currentSprite); } else if (xmlStrEqual(spriteNode->name, BAD_CAST "particlefx")) @@ -102,6 +104,7 @@ void EmoteDB::unload() { while (!i->second->sprites.empty()) { + delete i->second->sprites.front()->sprite; delete i->second->sprites.front(); i->second->sprites.pop_front(); } @@ -112,6 +115,7 @@ void EmoteDB::unload() while (!mUnknown.sprites.empty()) { + delete mUnknown.sprites.front()->sprite; delete mUnknown.sprites.front(); mUnknown.sprites.pop_front(); } @@ -119,21 +123,27 @@ void EmoteDB::unload() mLoaded = false; } -const EmoteInfo& EmoteDB::get(int id) +const EmoteInfo *EmoteDB::get(int id) { EmoteInfosIterator i = mEmoteInfos.find(id); if (i == mEmoteInfos.end()) { logger->log("EmoteDB: Warning, unknown emote ID %d requested", id); - return mUnknown; + return &mUnknown; } else { - return *(i->second); + return i->second; } } +const AnimatedSprite* EmoteDB::getAnimation(int id) +{ + const EmoteInfo *info = get(id); + return info->sprites.front()->sprite; +} + const int& EmoteDB::getLast() { return mLastEmote; diff --git a/src/resources/emotedb.h b/src/resources/emotedb.h index d0cd4d71..48e1d53c 100644 --- a/src/resources/emotedb.h +++ b/src/resources/emotedb.h @@ -26,11 +26,12 @@ #include #include +class AnimatedSprite; + struct EmoteSprite { - std::string sprite; + const AnimatedSprite *sprite; std::string name; - int variant; }; struct EmoteInfo @@ -50,7 +51,9 @@ namespace EmoteDB void unload(); - const EmoteInfo& get(int id); + const EmoteInfo *get(int id); + + const AnimatedSprite *getAnimation(int id); const int& getLast(); -- cgit v1.2.3-70-g09d2 From 4260cb92571842c6336537bf0d0c47c4f011ac0f Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 15:35:54 +0100 Subject: Extending the internal handling of colors The internal storage for colors was in the file color.h/color.cpp. It mainly managed the colors in the chat. The Color class was extended to be more generic now and it stores gcn::Color objects instead of integers now. A lot of new colortypes are now available, though not many of them are used for now, that will come in the next patches. The Color class was renamed to Palette and color.{h,cpp} to palette.{h,cpp} to better describe its purpose. The color config gui now lists the new colors, even changes them, but the result is not displayed properly for now. --- src/Makefile.am | 4 +- src/gui/browserbox.cpp | 21 ++- src/gui/color.cpp | 146 -------------------- src/gui/color.h | 136 ------------------- src/gui/listbox.cpp | 11 +- src/gui/palette.cpp | 315 +++++++++++++++++++++++++++++++++++++++++++ src/gui/palette.h | 296 ++++++++++++++++++++++++++++++++++++++++ src/gui/setup_colors.cpp | 55 ++++---- src/gui/setup_colors.h | 2 + src/gui/shoplistbox.cpp | 33 +++-- src/gui/table.cpp | 33 +---- src/gui/widgets/dropdown.cpp | 21 ++- src/main.cpp | 8 +- 13 files changed, 700 insertions(+), 381 deletions(-) delete mode 100644 src/gui/color.cpp delete mode 100644 src/gui/color.h create mode 100644 src/gui/palette.cpp create mode 100644 src/gui/palette.h (limited to 'src/gui') diff --git a/src/Makefile.am b/src/Makefile.am index 4982c215..06c392db 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,8 +31,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/chatinput.h \ gui/checkbox.cpp \ gui/checkbox.h \ - gui/color.cpp \ - gui/color.h \ + gui/palette.cpp \ + gui/palette.h \ gui/confirm_dialog.cpp \ gui/confirm_dialog.h \ gui/connection.cpp \ diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 7bdbcbef..596174cc 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -24,8 +24,8 @@ #include #include "browserbox.h" -#include "color.h" #include "linkhandler.h" +#include "palette.h" #include "truetypefont.h" BrowserBox::BrowserBox(unsigned int mode, bool opaque): @@ -249,16 +249,15 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mOpaque) { - graphics->setColor(gcn::Color(BGCOLOR)); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } if (mSelectedLink >= 0) { - bool valid; if ((mHighMode & BACKGROUND)) { - graphics->setColor(gcn::Color(textColor->getColor('H', valid))); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT)); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -269,7 +268,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - graphics->setColor(gcn::Color(textColor->getColor('<', valid))); + graphics->setColor(guiPalette->getColor(Palette::HYPERLINK)); graphics->drawLine( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y2, @@ -283,11 +282,11 @@ void BrowserBox::draw(gcn::Graphics *graphics) int link = 0; TrueTypeFont *font = static_cast(getFont()); - graphics->setColor(BLACK); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++) { - int selColor = BLACK; - int prevColor = selColor; + const gcn::Color *selColor = &guiPalette->getColor(Palette::TEXT); + const gcn::Color *prevColor = selColor; std::string row = *(i); bool wrapped = false; x = 0; @@ -335,7 +334,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) else { bool valid; - int rgb = textColor->getColor(c, valid); + const gcn::Color *col = &guiPalette->getColor(c, valid); if (c == '<') { const int size = mLinks[link].x2 - mLinks[link].x1; @@ -348,7 +347,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) } if (valid) { - selColor = rgb; + selColor = col; } } start += 3; @@ -358,7 +357,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) break; } } - graphics->setColor(gcn::Color(selColor)); + graphics->setColor(*selColor); } std::string::size_type len = diff --git a/src/gui/color.cpp b/src/gui/color.cpp deleted file mode 100644 index f9b89857..00000000 --- a/src/gui/color.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "color.h" - -#include "../configuration.h" - -#include "../utils/gettext.h" -#include "../utils/stringutils.h" - -Color::Color() -{ - addColor('C', 0x000000, _("Chat")); - addColor('G', 0xff0000, _("GM")); - addColor('H', 0xebc873, _("Highlight")); - addColor('Y', 0x1fa052, _("Player")); - addColor('W', 0x0000ff, _("Whisper")); - addColor('I', 0xa08527, _("Is")); - addColor('P', 0xff00d8, _("Party")); - addColor('S', 0x8415e2, _("Server")); - addColor('L', 0x919191, _("Logger")); - addColor('<', 0xe50d0d, _("Hyperlink")); - commit(); -} - -Color::~Color() -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - config.setValue("Color" + col->text, toString(col->rgb)); - } -} - -void Color::setColor(char c, int rgb) -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - col->rgb = rgb; - return; - } - } -} - -int Color::getColor(char c, bool &valid) const -{ - for (ColVector::const_iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - valid = true; - return col->rgb; - } - } - valid = false; - return 0x000000; -} - -std::string Color::getElementAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return ""; - } - return mColVector[i].text; -} - -char Color::getColorCharAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 'C'; - } - return mColVector[i].ch; -} - -void Color::addColor(char c, int rgb, const std::string &text) -{ - int trueRgb = (int) config.getValue("Color" + text, rgb); - mColVector.push_back(ColorElem(c, trueRgb, text)); -} - -int Color::getColorAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 0; - } - return mColVector[i].rgb; -} - -void Color::setColorAt(int i, int rgb) -{ - if (i >= 0 && i < getNumberOfElements()) - { - mColVector[i].rgb = rgb; - } -} - -void Color::commit() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->committedRgb = i->rgb; - } -} - -void Color::rollback() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->rgb = i->committedRgb; - } -} diff --git a/src/gui/color.h b/src/gui/color.h deleted file mode 100644 index 2816cedc..00000000 --- a/src/gui/color.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of The Mana World. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef COLOR_H -#define COLOR_H - -#include -#include - -#include - -class Color : public gcn::ListModel -{ - public: - /** - * Constructor - */ - Color(); - - /** - * Destructor - */ - ~Color(); - - /** - * Define the color replacement for a character - * - * @param c charater to be replaced - * @param rgb color to replace character - */ - void setColor(char c, int rgb); - - /** - * Define the color replacement for a character - * - * @param c character to be replaced - * @param r red component - * @param g green component - * @param b blue component - */ - void setColor(char c, int r, int g, int b) - { - setColor(c, (r << 16) | (g << 8) | b); - } - - /** - * Return the color associated with a character, if exists - * - * @param c character requested - * @param valid indicate whether character is known - */ - int getColor(char c, bool &valid) const; - - /** - * Return the number of colors known - */ - int getNumberOfElements() { return mColVector.size(); } - - /** - * Return the name of the ith color - * - * @param i index of color interested in - */ - std::string getElementAt(int i); - - /** - * Get the color for the element at index i in the current color - * model - */ - int getColorAt(int i); - - /** - * Get the character used by the color for the element at index i in - * the current color model - */ - char getColorCharAt(int i); - - /** - * Set the color for the element at index i - */ - void setColorAt(int i, int rgb); - - /** - * Commit the colors - */ - void commit(); - - /** - * Rollback the colors - */ - void rollback(); - - private: - struct ColorElem - { - ColorElem(char c, int rgb, const std::string &text) : - ch(c), rgb(rgb), text(text) {} - char ch; - int rgb; - int committedRgb; - std::string text; - }; - typedef std::vector ColVector; - ColVector mColVector; - - /** - * Initialise color - * - * @param c character that needs initialising - * @param rgb default color if not found in config - * @param text identifier of color - */ - void addColor(char c, int rgb, const std::string &text); -}; - -extern Color *textColor; - -#endif diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index cd5aa736..23d43066 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -24,8 +24,8 @@ #include #include -#include "color.h" #include "listbox.h" +#include "palette.h" #include "../configuration.h" @@ -44,13 +44,8 @@ void ListBox::draw(gcn::Graphics *graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); - bool valid; - const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 255.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 255.0f))); graphics->setFont(getFont()); const int fontHeight = getFont()->getHeight(); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp new file mode 100644 index 00000000..0298953c --- /dev/null +++ b/src/gui/palette.cpp @@ -0,0 +1,315 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "palette.h" +#include "gui.h" + +#include "../configuration.h" +#include "../game.h" + +#include "../utils/gettext.h" +#include "../utils/stringutils.h" + +const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); + +const gcn::Color Palette::RAINBOW_COLORS[8] = { + gcn::Color(255, 0, 0), + gcn::Color(255, 153, 0), + gcn::Color(255, 255, 0), + gcn::Color(0, 153, 0), + gcn::Color(0, 204, 204), + gcn::Color(51, 0, 153), + gcn::Color(153, 0, 153) +}; +/** Number of Elemets of RAINBOW_COLORS */ +const int Palette::RAINBOW_COLOR_COUNT = 7; + +std::string Palette::getConfigName(const std::string& typeName) +{ + std::string res = "Color" + typeName; + + int pos = 5; + for (int i = 0; i < typeName.length(); i++) + { + if (i==0 || typeName[i] == '_') + { + if (i > 0) + { + i++; + } + res[pos] = typeName[i]; + } + else + { + res[pos] = tolower(typeName[i]); + } + pos++; + } + res.erase(pos, res.length() - pos); + + return res; +} + +DEFENUMNAMES(ColorType, COLOR_TYPE); + +const int Palette::GRADIENT_DELAY = 20; + +Palette::Palette() : mColVector(ColVector(TYPE_COUNT)), mGradVector(), + mRainbowTime(tick_time) +{ + std::string indent = " "; + addColor(TEXT, 0x000000, STATIC, _("Text")); + addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0); + addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0); + + addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); + + addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); + addColor(SHOP_WARNING, 0x910000, STATIC, indent + + _("Item too expensive")); + + addColor(CHAT, 0x000000, STATIC, _("Chat"), 'C'); + addColor(GM, 0xff0000, STATIC, indent + _("GM"), 'G'); + addColor(PLAYER, 0x1fa052, STATIC, indent + _("Player"), 'Y'); + addColor(WHISPER, 0x0000ff, STATIC, indent + _("Whisper"), 'W'); + addColor(IS, 0xa08527, STATIC, indent + _("Is"), 'I'); + addColor(PARTY, 0xff00d8, STATIC, indent + _("Party"), 'P'); + addColor(SERVER, 0x8415e2, STATIC, indent + _("Server"), 'S'); + addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L'); + addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<'); + + addColor(BEING, 0xffffff, STATIC, _("Being"), 0); + addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0); + addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0); + addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0); + addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0); + addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0); + + addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); + addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), + 0); + addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0); + addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, + indent + _("Player hits Monster"), 0); + addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, + indent + _("Monster hits Player"), 0); + addColor(HIT_CRITICAL, 0xff0000, RAINBOW, + indent + _("Critical Hit"), 0); + addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0); + commit(true); +} + +Palette::~Palette() +{ + const std::string *configName; + for (ColVector::iterator col = mColVector.begin(), + colEnd = mColVector.end(); + col != colEnd; ++col) + { + configName = &ColorTypeNames[col->type]; + config.setValue(*configName + "Gradient", col->grad); + if (col->grad == STATIC) + { + config.setValue(*configName, toString(col->getRGB())); + } + } +} + +const gcn::Color& Palette::getColor(char c, bool &valid) + { + for (ColVector::const_iterator col = mColVector.begin(), + colEnd = mColVector.end(); col != colEnd; ++col) + { + if (col->ch == c) + { + valid = true; + return col->color; + } + } + valid = false; + return BLACK; +} + +void Palette::setColor(ColorType type, int r, int g, int b) +{ + mColVector[type].color.r = r; + mColVector[type].color.g = g; + mColVector[type].color.b = b; +} + +void Palette::setGradient(ColorType type, GradientType grad) +{ + ColorElem *elem = &mColVector[type]; + if (elem->grad != STATIC && grad == STATIC) + { + for (int i = 0; i < mGradVector.size(); i++) + { + if (mGradVector[i] == elem) + { + mGradVector.erase(mGradVector.begin() + i); + break; + } + } + } + else if (elem->grad == STATIC && grad != STATIC) + { + mGradVector.push_back(elem); + } + + if (elem->grad != grad) + { + elem->grad = grad; + } +} + +std::string Palette::getElementAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return mColVector[i].text; +} + +Palette::ColorType Palette::getColorTypeAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return CHAT; + } + return mColVector[i].type; +} + +void Palette::commit(bool commitNonStatic) +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; ++i) + { + i->committedGrad = i->grad; + if (commitNonStatic || i->grad == STATIC) + { + i->committedColor = i->color; + } + } +} + +void Palette::rollback() +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; + ++i) + { + i->grad = i->committedGrad; + if (i->grad == STATIC) + { + i->color = i->committedColor; + } + } +} + +void Palette::addColor(Palette::ColorType type, int rgb, + Palette::GradientType grad, + const std::string &text, char c) +{ + const std::string *configName = &ColorTypeNames[type]; + gcn::Color trueCol = (int)config.getValue(*configName, rgb); + grad = (GradientType)config.getValue(*configName + "Gradient", grad); + mColVector[type].set(type, trueCol, grad, text, c); + if (grad != STATIC) + { + mGradVector.push_back(&mColVector[type]); + } +} + +void Palette::advanceGradient () +{ + if (get_elapsed_time(mRainbowTime) > 5) + { + int pos, colIndex, colVal; + // For slower systems, advance can be greater than one (adcanve > 1 + // skips advance-1 steps). Should make gradient look the same + // independent of the framerate. + int advance = get_elapsed_time(mRainbowTime) / 5; + double startColVal, destColVal; + + for (int i = 0; i < mGradVector.size(); i++) + { + mGradVector[i]->gradientIndex = + (mGradVector[i]->gradientIndex + advance) % + (GRADIENT_DELAY * + ((mGradVector[i]->grad == SPECTRUM) ? 6 : + RAINBOW_COLOR_COUNT)); + + pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY; + colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY; + + if (mGradVector[i]->grad == SPECTRUM) + { + if (colIndex % 2) + { // falling curve + colVal = (int)(255.0 * + (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + } + else + { // ascending curve + colVal = (int)(255.0 * + (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + + 1) / 2); + } + + mGradVector[i]->color.r = + (colIndex == 0 || colIndex == 5) ? 255 : + (colIndex == 1 || colIndex == 4) ? colVal : 0; + mGradVector[i]->color.g = + (colIndex == 1 || colIndex == 2) ? 255 : + (colIndex == 0 || colIndex == 3) ? colVal : 0; + mGradVector[i]->color.b = + (colIndex == 3 || colIndex == 4) ? 255 : + (colIndex == 2 || colIndex == 5) ? colVal : 0; + } + else + { + const gcn::Color* startCol = &RAINBOW_COLORS[colIndex]; + const gcn::Color* destCol = + &RAINBOW_COLORS[(colIndex + 1) % RAINBOW_COLOR_COUNT]; + + startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2; + destColVal = 1 - startColVal; + + mGradVector[i]->color.r =(int)( + startColVal * startCol->r + + destColVal * destCol->r); + + mGradVector[i]->color.g =(int)( + startColVal * startCol->g + + destColVal * destCol->g); + + mGradVector[i]->color.b =(int)( + startColVal * startCol->b + + destColVal * destCol->b); + } + } + + mRainbowTime = tick_time; + } +} diff --git a/src/gui/palette.h b/src/gui/palette.h new file mode 100644 index 00000000..c32fbc8a --- /dev/null +++ b/src/gui/palette.h @@ -0,0 +1,296 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALETTE_H +#define PALETTE_H + +#include +#include +#include + +#include +#include + +// Generate strings from an enum ... some preprocessor fun. +#define EDEF(a) a, +#define ECONFIGSTR(a) Palette::getConfigName(#a), + +#define TEXTENUM(name,def)\ + enum name { def(EDEF) };\ + static const std::string name ## Names[]; +#define DEFENUMNAMES(name,def)\ + const std::string Palette::name ## Names[] = { def(ECONFIGSTR) "" }; + +/** + * Class controlling the game's color palette. + */ +class Palette : public gcn::ListModel +{ + public: + /** List of all colors that are configurable. */ + #define COLOR_TYPE(ENTRY)\ + ENTRY(TEXT)\ + ENTRY(SHADOW)\ + ENTRY(OUTLINE)\ + ENTRY(BACKGROUND)\ + ENTRY(HIGHLIGHT)\ + ENTRY(SHOP_WARNING)\ + ENTRY(CHAT)\ + ENTRY(GM)\ + ENTRY(PLAYER)\ + ENTRY(WHISPER)\ + ENTRY(IS)\ + ENTRY(PARTY)\ + ENTRY(SERVER)\ + ENTRY(LOGGER)\ + ENTRY(HYPERLINK)\ + ENTRY(BEING)\ + ENTRY(PC)\ + ENTRY(SELF)\ + ENTRY(GM_NAME)\ + ENTRY(NPC)\ + ENTRY(MONSTER)\ + ENTRY(PARTICLE)\ + ENTRY(EXP_INFO)\ + ENTRY(PICKUP_INFO)\ + ENTRY(HIT_PLAYER_MONSTER)\ + ENTRY(HIT_MONSTER_PLAYER)\ + ENTRY(HIT_CRITICAL)\ + ENTRY(MISS)\ + ENTRY(TYPE_COUNT)\ + + TEXTENUM(ColorType, COLOR_TYPE); + + /** Colors can be static or can alter over time. */ + enum GradientType { + STATIC, + SPECTRUM, + RAINBOW + }; + + /** + * Constructor + */ + Palette(); + + /** + * Destructor + */ + ~Palette(); + + /** + * Returns the color associated with a character, if it exists. Returns + * Palette::BLACK if the character is not found. + * + * @param c character requested + * @param valid indicate whether character is known + * + * @return the requested color or Palette::BLACK + */ + const gcn::Color& getColor(char c, bool &valid); + + /** + * Gets the color with the associated type. Sets the alpha channel + * before returning. + * + * @param type the color type requested + * @param alpha alpha channel to use + * + * @return the requested color + */ + inline const gcn::Color& getColor(ColorType type, int alpha = 255) + { + gcn::Color* col = &mColVector[type].color; + col->a = alpha; + return *col; + } + + /** + * Gets the GradientType used by the specified color. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ + inline GradientType getGradientType(ColorType type) + { + return mColVector[type].grad; + } + + /** + * Get the character used by the specified color. + * + * @param type the color type of the color + * + * @return the color char of the color with the given index + */ + inline char getColorChar(ColorType type) + { + return mColVector[type].ch; + } + + /** + * Sets the color for the specified type. + * + * @param type color to be set + * @param r red component + * @param g green component + * @param b blue component + */ + void setColor(ColorType type, int r, int g, int b); + + /** + * Sets the gradient type for the specified color. + * + * @param grad gradient type to set + */ + void setGradient(ColorType type, GradientType grad); + + /** + * Returns the number of colors known. + * + * @return the number of colors known + */ + inline int getNumberOfElements() { return mColVector.size(); } + + /** + * Returns the name of the ith color. + * + * @param i index of color interested in + * + * @return the name of the color + */ + std::string getElementAt(int i); + + /** + * Gets the ColorType used by the color for the element at index i in + * the current color model. + * + * @param i the index of the color + * + * @return the color type of the color with the given index + */ + ColorType getColorTypeAt(int i); + + /** + * Commit the colors + */ + inline void commit() + { + commit(false); + } + + /** + * Rollback the colors + */ + void rollback(); + + /** + * Updates all colors, that are non-static. + */ + void advanceGradient(); + + private: + /** Black Color Constant */ + static const gcn::Color BLACK; + + /** Colors used for the rainbow gradient */ + static const gcn::Color RAINBOW_COLORS[]; + static const int RAINBOW_COLOR_COUNT; + /** Parameter to control the speed of the gradient */ + static const int GRADIENT_DELAY; + /** Time tick, that gradient-type colors were updated the last time. */ + int mRainbowTime; + + /** + * Define a color replacement. + * + * @param i the index of the color to replace + * @param r red component + * @param g green component + * @param b blue component + */ + void setColorAt(int i, int r, int g, int b); + + /** + * Commit the colors. Commit the non-static color values, if + * commitNonStatic is true. Only needed in the constructor. + */ + void commit(bool commitNonStatic); + + struct ColorElem + { + ColorType type; + gcn::Color color; + gcn::Color committedColor; + std::string text; + char ch; + GradientType grad; + GradientType committedGrad; + int gradientIndex; + + void set(ColorType type, gcn::Color& color, GradientType grad, + const std::string &text, char c) + { + ColorElem::type = type; + ColorElem::color = color; + ColorElem::text = text; + ColorElem::ch = c; + ColorElem::grad = grad; + ColorElem::gradientIndex = rand(); + } + + inline int getRGB() { + return (committedColor.r << 16) | (committedColor.g << 8) | + committedColor.b; + } + }; + typedef std::vector ColVector; + /** Vector containing the colors. */ + ColVector mColVector; + std::vector mGradVector; + + /** + * Initialise color + * + * @param c character that needs initialising + * @param rgb default color if not found in config + * @param text identifier of color + */ + void addColor(ColorType type, int rgb, GradientType grad, + const std::string &text, char c = 0); + + /** + * Prefixes the given string with "Color", lowercases all letters but + * the first and all following a '_'. All '_'s will be removed. + * + * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster + * + * @param typeName string to transform + * + * @return the transformed string + */ + static std::string getConfigName(const std::string& typeName); +}; + +extern Palette *guiPalette; + +#endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 2610be03..6f1da525 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,9 +27,9 @@ #include #include "browserbox.h" -#include "color.h" #include "itemlinkhandler.h" #include "listbox.h" +#include "palette.h" #include "scrollarea.h" #include "setup_colors.h" #include "slider.h" @@ -42,12 +42,14 @@ #include "../utils/gettext.h" #include "../utils/stringutils.h" +const std::string Setup_Colors::rawmsg = _("This is what the color looks like"); + Setup_Colors::Setup_Colors() : mSelected(-1) { setOpaque(false); - mColorBox = new ListBox(textColor); + mColorBox = new ListBox(guiPalette); mColorBox->setActionEventId("color_box"); mColorBox->addActionListener(this); @@ -130,6 +132,9 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { + delete mPreview; + delete mPreviewBox; + delete mRedLabel; delete mRedSlider; delete mRedText; @@ -142,6 +147,7 @@ Setup_Colors::~Setup_Colors() delete mBlueSlider; delete mBlueText; + delete mColorBox; delete mScroll; } @@ -150,22 +156,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event) if (event.getId() == "color_box") { mSelected = mColorBox->getSelected(); - int col = textColor->getColorAt(mSelected); - char ch = textColor->getColorCharAt(mSelected); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + std::string msg; + mPreview->clearRows(); + char ch = guiPalette->getColorChar(type); if (ch == '<') - msg = toString("@@|") + - _("This is what the color looks like") + "@@"; + msg = toString("@@|") + rawmsg + "@@"; else - msg = "##" + toString(ch) + - _("This is what the color looks like"); - - mPreview->clearRows(); + msg = "##" + toString(ch) + rawmsg; mPreview->addRow(msg); - setEntry(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); + + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); return; } @@ -201,16 +207,17 @@ void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value) void Setup_Colors::apply() { - textColor->commit(); + guiPalette->commit(); } void Setup_Colors::cancel() { - textColor->rollback(); - int col = textColor->getColorAt(mSelected); - setEntry(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); + guiPalette->rollback(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); } void Setup_Colors::listen(const TextField *tf) @@ -241,8 +248,10 @@ void Setup_Colors::updateColor() { return; } - int rgb = static_cast(mRedSlider->getValue()) << 16 | - static_cast(mGreenSlider->getValue()) << 8 | - static_cast(mBlueSlider->getValue()); - textColor->setColorAt(mSelected, rgb); + + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 2831297f..050ea638 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -48,6 +48,8 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void listen(const TextField *tf); private: + static const std::string rawmsg; + gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 64c97246..19c8a7b4 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -22,7 +22,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "shop.h" #include "shoplistbox.h" @@ -63,11 +63,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); - bool valid; - const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 255.0f); + int alpha = (int)(mAlpha * 255.0f); + const gcn::Color* highlightColor = + &guiPalette->getColor(Palette::HIGHLIGHT, alpha); Graphics *graphics = static_cast(gcnGraphics); @@ -78,18 +76,27 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) i < mListModel->getNumberOfElements(); ++i, y += mRowHeight) { - gcn::Color backgroundColor = gcn::Color(255, 255, 255, alpha); + gcn::Color temp; + const gcn::Color* backgroundColor = + &guiPalette->getColor(Palette::BACKGROUND, alpha); if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) - if (i == mSelected) - backgroundColor = gcn::Color(145, 0, 0, alpha); + if (i != mSelected) + backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING, + alpha); else - backgroundColor = gcn::Color(145, 145, 145, alpha); + { + temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha); + temp.r = (temp.r + highlightColor->r) / 2; + temp.g = (temp.g + highlightColor->g) / 2; + temp.b = (temp.g + highlightColor->b) / 2; + backgroundColor = &temp; + } else if (i == mSelected) - backgroundColor = gcn::Color(red, green, blue, alpha); + backgroundColor = highlightColor; - graphics->setColor(backgroundColor); + graphics->setColor(*backgroundColor); graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); if (mShopItems) @@ -100,7 +107,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) graphics->drawImage(icon, 1, y); } } - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); } diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 274f9a48..ece470b1 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -23,7 +23,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "table.h" #include "../configuration.h" @@ -273,11 +273,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mOpaque) { - const int red = getBackgroundColor().r; - const int green = getBackgroundColor().g; - const int blue = getBackgroundColor().b; - const int alpha = (int)(mAlpha * 255.0f); - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -324,15 +321,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow) { - bool valid; - const int red = - (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = - (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 127.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 127.0f))); graphics->fillRectangle(bounds); } @@ -346,17 +336,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mLinewiseMode && r == mSelectedRow) { - bool valid; - const int red = - (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = - (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 127.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); - graphics->fillRectangle(gcn::Rectangle(0, y_offset, - x_offset, height)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 127.0f))); } y_offset += height; diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index c91a8524..022da0f0 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -23,8 +23,8 @@ #include "dropdown.h" -#include "../color.h" #include "../listbox.h" +#include "../palette.h" #include "../scrollarea.h" #include "../../configuration.h" @@ -139,27 +139,24 @@ void DropDown::draw(gcn::Graphics* graphics) } } - bool valid; +// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = textColor->getColor('H', valid); - highlightColor.a = alpha; + gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - int red = getBackgroundColor().r; - int green = getBackgroundColor().g; - int blue = getBackgroundColor().b; - graphics->setColor(gcn::Color(red, green, blue, alpha)); + gcn::Color col = getBackgroundColor(); + col.a = alpha; + graphics->setColor(col); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - red = getForegroundColor().r; - green = getForegroundColor().g; - blue = getForegroundColor().b; - graphics->setColor(gcn::Color(red, green, blue, alpha)); + col = getForegroundColor(); + col.a = alpha; + graphics->setColor(col); } graphics->setFont(getFont()); diff --git a/src/main.cpp b/src/main.cpp index f1424096..dddf53d0 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -57,10 +57,10 @@ #include "gui/button.h" #include "gui/char_server.h" #include "gui/char_select.h" -#include "gui/color.h" #include "gui/gui.h" #include "gui/login.h" #include "gui/ok_dialog.h" +#include "gui/palette.h" #include "gui/progressbar.h" #include "gui/register.h" #include "gui/sdlinput.h" @@ -135,7 +135,7 @@ CharServerHandler charServerHandler; LoginData loginData; LockedArray charInfo(MAX_SLOT + 1); -Color *textColor; +Palette *guiPalette; // This anonymous namespace hides whatever is inside from other modules. namespace { @@ -774,7 +774,7 @@ int main(int argc, char *argv[]) unsigned int oldstate = !state; // We start with a status change. // Needs to be created in main, as the updater uses it - textColor = new Color; + guiPalette = new Palette; Game *game = NULL; Window *currentDialog = NULL; @@ -1111,7 +1111,7 @@ int main(int argc, char *argv[]) usleep(50000); } - delete textColor; + delete guiPalette; #ifdef PACKAGE_VERSION delete versionLabel; #endif -- cgit v1.2.3-70-g09d2 From c7fa79ff1704d86e12e12b83e1e4745ca27a543a Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 17:19:31 +0100 Subject: Added a class for rendering of floating text This is a header only-class that merges the textrendering of the TextParticle and Text classes. It is done to reduce code duplication and to prepare some color configuration gui. --- src/gui/textrenderer.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/text.cpp | 36 ++++------------------ src/textparticle.cpp | 30 +++++-------------- 3 files changed, 94 insertions(+), 53 deletions(-) create mode 100644 src/gui/textrenderer.h (limited to 'src/gui') diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h new file mode 100644 index 00000000..0381f766 --- /dev/null +++ b/src/gui/textrenderer.h @@ -0,0 +1,81 @@ +/* + * Text Renderer + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TEXT_RENDERER_H +#define TEXT_RENDERER_H + +#include "graphics.h" +#include "palette.h" + +/** + * Class for text rendering. Used by the TextParticle, the Text and FlashText + * objects and the Preview in the color dialog. + */ +class TextRenderer +{ + public: + /** + * Renders a specified text. + */ + static inline void renderText(gcn::Graphics *graphics, const std::string& + text, int x, int y, gcn::Graphics::Alignment align, + const gcn::Color* color, gcn::Font *font, bool outline = false, + bool shadow = false, int alpha = 255) + { + graphics->setFont(font); + + // Text shadow + if (shadow) + { + graphics->setColor(guiPalette->getColor(Palette::SHADOW, + alpha / 2)); + if (outline) + { + graphics->drawText(text, x + 2, y + 2, align); + } + else + { + graphics->drawText(text, x + 1, y + 1, align); + } + } + + if (outline) { +/* graphics->setColor(guiPalette->getColor(Palette::OUTLINE, + alpha/4)); + // TODO: Reanable when we can draw it nicely in software mode + graphics->drawText(text, x + 2, y + 2, align); + graphics->drawText(text, x + 1, y + 2, align); + graphics->drawText(text, x + 2, y + 1, align);*/ + + // Text outline + graphics->setColor(guiPalette->getColor(Palette::OUTLINE, alpha)); + graphics->drawText(text, x + 1, y, align); + graphics->drawText(text, x - 1, y, align); + graphics->drawText(text, x, y + 1, align); + graphics->drawText(text, x, y - 1, align); + } + + graphics->setColor(*color); + graphics->drawText(text, x, y, align); + } +}; + +#endif diff --git a/src/text.cpp b/src/text.cpp index cb4587d3..5a912d17 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -30,6 +30,8 @@ #include "resources/image.h" #include "gui/gui.h" +#include "gui/palette.h" +#include "gui/textrenderer.h" int Text::mInstances = 0; ImageRect Text::mBubble; @@ -129,37 +131,9 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) */ } - // Text shadow - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mText, mX - xOff + 1, mY - yOff + 1, - gcn::Graphics::LEFT); - - if (!mIsSpeech) { - graphics->setColor(gcn::Color(0, 0, 0, 64)); - /* - // TODO: Reanable when we can draw it nicely in software mode - graphics->drawText(mText, mX - xOff + 2, mY - yOff + 2, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff + 1, mY - yOff + 2, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff + 2, mY - yOff + 1, - gcn::Graphics::LEFT); - */ - - // Text outline - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mText, mX - xOff + 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff - 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff + 1, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff - 1, - gcn::Graphics::LEFT); - } - - graphics->setColor(mColor); - graphics->drawText(mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT); + TextRenderer::renderText(graphics, mText, + mX - xOff, mY - yOff, gcn::Graphics::LEFT, + &mColor, boldFont, !mIsSpeech, true); } FlashText::FlashText(const std::string &text, int x, int y, diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 3494b97f..ed8609e9 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -21,10 +21,12 @@ #include -#include "graphics.h" -#include "textparticle.h" #include +#include "textparticle.h" + +#include "gui/textrenderer.h" + TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, gcn::Font *font, bool outline): @@ -60,24 +62,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const alpha /= mFadeIn; } - graphics->setFont(mTextFont); - if (mOutline) - { - graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); - // Text outline - graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); - graphics->drawText(mText, screenX + 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX - 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY + 1, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY - 1, - gcn::Graphics::CENTER); - } - graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); - graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); + TextRenderer::renderText(graphics, mText, + screenX, screenY, gcn::Graphics::CENTER, + &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, + (int)alpha); } -- cgit v1.2.3-70-g09d2 From b9191530c81595b0ad3d2faa6c4d21d75a720c29 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 16:48:03 +0100 Subject: Extend color config gui to support the new colors The new color palette supports many more colors that the browserbox can display. So a change to the color config gui was needed. --- src/Makefile.am | 3 + src/gui/gui.cpp | 7 +- src/gui/palette.h | 26 ++++-- src/gui/setup_colors.cpp | 182 ++++++++++++++++++++++++++++++++++++---- src/gui/setup_colors.h | 9 ++ src/gui/widgets/textpreview.cpp | 53 ++++++++++++ src/gui/widgets/textpreview.h | 114 +++++++++++++++++++++++++ 7 files changed, 369 insertions(+), 25 deletions(-) create mode 100644 src/gui/widgets/textpreview.cpp create mode 100644 src/gui/widgets/textpreview.h (limited to 'src/gui') diff --git a/src/Makefile.am b/src/Makefile.am index 06c392db..39fbc856 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/tab.h \ gui/widgets/tabbedarea.cpp \ gui/widgets/tabbedarea.h \ + gui/widgets/textpreview.cpp \ + gui/widgets/textpreview.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/button.cpp \ @@ -151,6 +153,7 @@ tmw_SOURCES = gui/widgets/dropdown.cpp \ gui/textbox.h \ gui/textfield.cpp \ gui/textfield.h \ + gui/textrenderer.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 6d6ccbdf..e14642dd 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -25,6 +25,7 @@ #include "focushandler.h" #include "gui.h" +#include "palette.h" #include "sdlinput.h" #include "truetypefont.h" #include "viewport.h" @@ -45,11 +46,11 @@ Gui *gui = 0; Viewport *viewport = 0; /**< Viewport on the map. */ SDLInput *guiInput = 0; - +/* // Fonts used in showing hits gcn::Font *hitRedFont = 0; gcn::Font *hitBlueFont = 0; -gcn::Font *hitYellowFont = 0; +gcn::Font *hitYellowFont = 0;*/ // Bolded font gcn::Font *boldFont = 0; @@ -175,6 +176,8 @@ void Gui::logic() else mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f); + guiPalette->advanceGradient(); + gcn::Gui::logic(); } diff --git a/src/gui/palette.h b/src/gui/palette.h index c32fbc8a..77ead4f6 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -108,7 +108,7 @@ class Palette : public gcn::ListModel const gcn::Color& getColor(char c, bool &valid); /** - * Gets the color with the associated type. Sets the alpha channel + * Gets the color associated with the type. Sets the alpha channel * before returning. * * @param type the color type requested @@ -124,12 +124,24 @@ class Palette : public gcn::ListModel } /** - * Gets the GradientType used by the specified color. - * - * @param type the color type of the color - * - * @return the gradient type of the color with the given index - */ + * Gets the committed color associated with the specified type. + * + * @param type the color type requested + * + * @return the requested committed color + */ + inline const gcn::Color& getCommittedColor(ColorType type) + { + return mColVector[type].committedColor; + } + + /** + * Gets the GradientType associated with the specified type. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ inline GradientType getGradientType(ColorType type) { return mColVector[type].grad; diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 6f1da525..7990e217 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,6 +27,7 @@ #include #include "browserbox.h" +#include "gui.h" #include "itemlinkhandler.h" #include "listbox.h" #include "palette.h" @@ -56,8 +57,10 @@ Setup_Colors::Setup_Colors() : mScroll = new ScrollArea(mColorBox); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mTextPreview = new TextPreview(&rawmsg); + mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); - mPreview->setOpaque(false); + mPreview->setOpaque(true); // don't do anything with links mPreview->setLinkHandler(NULL); @@ -67,6 +70,17 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); + mGradTypeLabel = new gcn::Label(_("Type: ")); + + mGradTypeSlider = new Slider(0, 2); + mGradTypeSlider->setWidth(160); + mGradTypeSlider->setActionEventId("slider_grad"); + mGradTypeSlider->setValue(0); + mGradTypeSlider->addActionListener(this); + mGradTypeSlider->setEnabled(false); + + mGradTypeText = new gcn::Label(); + mRedLabel = new gcn::Label(_("Red: ")); mRedText = new TextField; @@ -74,12 +88,14 @@ Setup_Colors::Setup_Colors() : mRedText->setRange(0, 255); mRedText->setNumeric(true); mRedText->addListener(this); + mRedText->setEnabled(false); mRedSlider = new Slider(0, 255); mRedSlider->setWidth(160); mRedSlider->setValue(mRedText->getValue()); mRedSlider->setActionEventId("slider_red"); mRedSlider->addActionListener(this); + mRedSlider->setEnabled(false); mGreenLabel = new gcn::Label(_("Green: ")); @@ -88,12 +104,14 @@ Setup_Colors::Setup_Colors() : mGreenText->setRange(0, 255); mGreenText->setNumeric(true); mGreenText->addListener(this); + mGreenText->setEnabled(false); mGreenSlider = new Slider(0, 255); mGreenSlider->setWidth(160); mGreenSlider->setValue(mGreenText->getValue()); mGreenSlider->setActionEventId("slider_green"); mGreenSlider->addActionListener(this); + mGreenSlider->setEnabled(false); mBlueLabel = new gcn::Label(_("Blue: ")); @@ -102,12 +120,14 @@ Setup_Colors::Setup_Colors() : mBlueText->setRange(0, 255); mBlueText->setNumeric(true); mBlueText->addListener(this); + mBlueText->setEnabled(false); mBlueSlider = new Slider(0, 255); mBlueSlider->setWidth(160); mBlueSlider->setValue(mBlueText->getValue()); mBlueSlider->setActionEventId("slider_blue"); mBlueSlider->addActionListener(this); + mBlueSlider->setEnabled(false); setOpaque(false); @@ -115,8 +135,11 @@ Setup_Colors::Setup_Colors() : LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mScroll, 4, 7).setPadding(2); - place(0, 7, mPreviewBox, 4).setPadding(2); + place(0, 0, mScroll, 4, 6).setPadding(2); + place(0, 6, mPreviewBox, 4).setPadding(2); + place(0, 7, mGradTypeLabel, 2); + place(2, 7, mGradTypeSlider); + place(3, 7, mGradTypeText); place(0, 8, mRedLabel, 2); place(2, 8, mRedSlider); place(3, 8, mRedText).setPadding(1); @@ -132,8 +155,21 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { - delete mPreview; - delete mPreviewBox; + //delete mPreview; + if (mPreviewBox->getContent() == mPreview) + { + delete mTextPreview; + } + else + { + delete mPreview; + } + // delete mTextPreview; +// delete mPreviewBox; + +/* delete mGradTypeLabel; + delete mGradTypeSlider; + delete mGradTypeText; delete mRedLabel; delete mRedSlider; @@ -148,7 +184,7 @@ Setup_Colors::~Setup_Colors() delete mBlueText; delete mColorBox; - delete mScroll; + delete mScroll;*/ } void Setup_Colors::action(const gcn::ActionEvent &event) @@ -158,20 +194,103 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mSelected = mColorBox->getSelected(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + Palette::GradientType grad = guiPalette->getGradientType(type); std::string msg; + char ch = guiPalette->getColorChar(type); mPreview->clearRows(); - char ch = guiPalette->getColorChar(type); - if (ch == '<') - msg = toString("@@|") + rawmsg + "@@"; - else - msg = "##" + toString(ch) + rawmsg; - mPreview->addRow(msg); + mPreviewBox->setContent(mTextPreview); + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor( + &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextBGColor(NULL); + mTextPreview->setShadow(true); + mTextPreview->setOutline(true); + + switch (type) + { + case Palette::TEXT: + case Palette::SHADOW: + case Palette::OUTLINE: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setOutline(true); + mTextPreview->setShadow(type == Palette::SHADOW); + mTextPreview->setOutline(type == Palette::OUTLINE); + break; + case Palette::BACKGROUND: + case Palette::HIGHLIGHT: + case Palette::SHOP_WARNING: + mTextPreview->setTextBGColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + mPreview->addRow(rawmsg); + break; + case Palette::CHAT: + case Palette::GM: + case Palette::PLAYER: + case Palette::WHISPER: + case Palette::IS: + case Palette::PARTY: + case Palette::SERVER: + case Palette::LOGGER: + case Palette::HYPERLINK: + mPreviewBox->setContent(mPreview); + mPreview->clearRows(); + //char ch = guiPalette->getColorCharAt(mSelected); + //std::string msg; + + if (ch == '<') + { + msg = toString("@@|") + rawmsg + "@@"; + } + else + { + msg = "##" + toString(ch) + rawmsg; + } + //std::cout << msg << std::endl; + mPreview->addRow(msg); + break; + case Palette::PARTICLE: + case Palette::EXP_INFO: + case Palette::PICKUP_INFO: + case Palette::HIT_PLAYER_MONSTER: + case Palette::HIT_MONSTER_PLAYER: + case Palette::HIT_CRITICAL: + case Palette::MISS: + mTextPreview->setShadow(false); + case Palette::BEING: + case Palette::PC: + case Palette::SELF: + case Palette::GM_NAME: + case Palette::NPC: + case Palette::MONSTER: + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + break; + } + + if (grad != Palette::STATIC) + { // If nonstatic color, don't display the current, but the committed + // color at the sliders + col = &guiPalette->getCommittedColor(type); + } setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); + + mGradTypeSlider->setValue(grad); + updateGradType(); + mGradTypeSlider->setEnabled(true); + + return; + } + + if (event.getId() == "slider_grad") + { + updateGradType(); + updateColor(); return; } @@ -215,6 +334,7 @@ void Setup_Colors::cancel() guiPalette->rollback(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + mGradTypeSlider->setValue(guiPalette->getGradientType(type)); setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); @@ -242,6 +362,29 @@ void Setup_Colors::listen(const TextField *tf) } } +void Setup_Colors::updateGradType() { + if (mSelected == -1) + { + return; + } + + mSelected = mColorBox->getSelected(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + Palette::GradientType grad = guiPalette->getGradientType(type); + + mGradTypeText->setCaption( + (grad == Palette::STATIC) ? _("Static") : + (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); + + bool enable = (grad == Palette::STATIC); + mRedText->setEnabled(enable); + mRedSlider->setEnabled(enable); + mGreenText->setEnabled(enable); + mGreenSlider->setEnabled(enable); + mBlueText->setEnabled(enable); + mBlueSlider->setEnabled(enable); +} + void Setup_Colors::updateColor() { if (mSelected == -1) @@ -250,8 +393,15 @@ void Setup_Colors::updateColor() } Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); - guiPalette->setColor(type, - static_cast(mRedSlider->getValue()), - static_cast(mGreenSlider->getValue()), - static_cast(mBlueSlider->getValue())); + Palette::GradientType grad = + static_cast(mGradTypeSlider->getValue()); + guiPalette->setGradient(type, grad); + + if (grad == Palette::STATIC) + { + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); + } } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 050ea638..842fd6cc 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -34,6 +34,8 @@ #include "../guichanfwd.h" +#include "widgets/textpreview.h" + class BrowserBox; class Setup_Colors : public SetupTab, public gcn::ActionListener, @@ -53,9 +55,15 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; + TextPreview *mTextPreview; gcn::ScrollArea *mPreviewBox; int mSelected; + gcn::Label *mGradTypeLabel; + gcn::Slider *mGradTypeSlider; + gcn::Label *mGradTypeText; +// Palette::GradientType mGradType; + gcn::Label *mRedLabel; gcn::Slider *mRedSlider; TextField *mRedText; @@ -73,5 +81,6 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void setEntry(gcn::Slider *s, TextField *t, int value); void updateColor(); + void updateGradType(); }; #endif diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp new file mode 100644 index 00000000..28d7fd35 --- /dev/null +++ b/src/gui/widgets/textpreview.cpp @@ -0,0 +1,53 @@ +/* + * The Mana World + * Copyright (C) 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include "textpreview.h" + +#include "../gui.h" +#include "../palette.h" +#include "../textrenderer.h" +#include "../truetypefont.h" + +TextPreview::TextPreview(const std::string* text) +{ + mText = text; + mFont = gui->getFont(); + mTextColor = &guiPalette->getColor(Palette::TEXT); + mTextBGColor = NULL; + mBGColor = &guiPalette->getColor(Palette::BACKGROUND); +} + +void TextPreview::draw(gcn::Graphics* graphics) +{ + graphics->setColor(*mBGColor); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + + if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) { + TrueTypeFont *font = static_cast(mFont); + graphics->setColor(*mTextBGColor); + int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); + int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + } + + TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, + mTextColor, mFont, mOutline, mShadow); +} diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h new file mode 100644 index 00000000..1c1fa1e4 --- /dev/null +++ b/src/gui/widgets/textpreview.h @@ -0,0 +1,114 @@ +/* + * The Mana World + * Copyright (C) 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TEXTPREVIEW_H +#define TEXTPREVIEW_H + +#include +#include +#include + +/** + * Preview widget for particle colors, etc. + */ +class TextPreview : public gcn::Widget { + public: + TextPreview(const std::string* text); + + /** + * Sets the color the text is printed in. + * + * @param color the color to set + */ + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + + /** + * Sets the color the text background is drawn in. This is only the + * rectangle directly behind the text, not to full widget. + * + * @param color the color to set + */ + inline void setTextBGColor(const gcn::Color* color) + { + mTextBGColor = color; + } + + /** + * Sets the background color of the widget. + * + * @param color the color to set + */ + inline void setBGColor(const gcn::Color* color) + { + mBGColor = color; + } + + /** + * Sets the font to render the text in. + * + * @param font the font to use. + */ + inline void setFont(gcn::Font *font) + { + mFont = font; + } + + /** + * Sets whether to use a shadow while rendering. + * + * @param shadow true, if a shadow is wanted, false else + */ + inline void setShadow(bool shadow) + { + mShadow = shadow; + } + + /** + * Sets whether to use an outline while rendering. + * + * @param outline true, if an outline is wanted, false else + */ + inline void setOutline(bool outline) + { + mOutline = outline; + } + + /** + * Widget's draw method. Does the actual job. + * + * @param graphics graphics to draw into + */ + void draw(gcn::Graphics *graphics); + + private: + gcn::Font *mFont; + const std::string* mText; + const gcn::Color* mTextColor; + const gcn::Color* mBGColor; + const gcn::Color* mTextBGColor; + bool mShadow; + bool mOutline; +}; + +#endif -- cgit v1.2.3-70-g09d2 From 3b1fbbe072e4da86be4c8f8f22655d04565379d2 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 22:42:42 +0100 Subject: Make use of the new available colors This patch lets all being derivatives use the palette to set their name's colors. Text Particle Effects all respect the new settings. Some widgets were updated to use the colors. --- src/being.cpp | 37 ++++++++++++++----------------------- src/being.h | 2 +- src/gui/gui.cpp | 5 ----- src/gui/listbox.cpp | 2 +- src/gui/shoplistbox.cpp | 2 +- src/gui/speechbubble.cpp | 5 +++-- src/gui/speechbubble.h | 4 +++- src/gui/table.cpp | 2 ++ src/gui/textbox.cpp | 5 +++-- src/gui/textbox.h | 15 +++++++++++++++ src/gui/widgets/dropdown.cpp | 16 ++++++---------- src/gui/widgets/textpreview.cpp | 2 ++ src/localplayer.cpp | 19 ++++++++++--------- src/monster.cpp | 7 +++++-- src/npc.cpp | 6 ++++-- src/particle.cpp | 17 +++++------------ src/particle.h | 14 ++++++-------- src/player.cpp | 13 +++++++++---- src/text.cpp | 6 +++--- src/text.h | 6 +++--- src/textparticle.cpp | 11 +++-------- src/textparticle.h | 7 +++---- 22 files changed, 102 insertions(+), 101 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index 60fb8d13..66273710 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -45,6 +45,7 @@ #include "resources/resourcemanager.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/speechbubble.h" #include "utils/dtor.h" @@ -101,7 +102,7 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble; mSpeech = ""; - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::CHAT); mText = 0; } @@ -202,17 +203,14 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font; std::string damage = amount ? toString(amount) : type == FLEE ? "dodge" : "miss"; - - int red, green, blue; + const gcn::Color* color; font = gui->getInfoParticleFont(); // Selecting the right color if (type == CRITICAL || type == FLEE) { - red = 255; - green = 128; - blue = 0; + color = &guiPalette->getColor(Palette::HIT_CRITICAL); } else if (!amount) { @@ -220,33 +218,25 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) { // This is intended to be the wrong direction to visually // differentiate between hits and misses - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } else { - red = 255; - green = 255; - blue = 0; - } - } + color = &guiPalette->getColor(Palette::MISS); + } + } else if (getType() == MONSTER) { - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_PLAYER_MONSTER); } else { - red = 255; - green = 50; - blue = 50; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect(damage, mPx + 16, mPy + 16, + color, font, true); if (amount > 0) { @@ -531,7 +521,8 @@ void Being::drawSpeech(int offsetX, int offsetY) delete mText; mText = new Text(mSpeech, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET, - gcn::Graphics::CENTER, gcn::Color(255, 255, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::PARTICLE)); } else if (speech == NO_SPEECH) { diff --git a/src/being.h b/src/being.h index b9b57a0d..ec6f1c44 100644 --- a/src/being.h +++ b/src/being.h @@ -510,7 +510,7 @@ class Being : public Sprite Uint16 mStunMode; /**< Stun mode; zero if not stunned */ std::set mStatusEffects; /**< set of active status effects */ - gcn::Color mNameColor; + const gcn::Color* mNameColor; std::vector mSprites; std::vector mSpriteIDs; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index e14642dd..4081eeac 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -46,11 +46,6 @@ Gui *gui = 0; Viewport *viewport = 0; /**< Viewport on the map. */ SDLInput *guiInput = 0; -/* -// Fonts used in showing hits -gcn::Font *hitRedFont = 0; -gcn::Font *hitBlueFont = 0; -gcn::Font *hitYellowFont = 0;*/ // Bolded font gcn::Font *boldFont = 0; diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 23d43066..7ba84ee7 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -56,7 +56,7 @@ void ListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); // Draw the list elements - graphics->setColor(gcn::Color(0, 0, 0, 255)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 19c8a7b4..aa42c294 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -78,7 +78,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { gcn::Color temp; const gcn::Color* backgroundColor = - &guiPalette->getColor(Palette::BACKGROUND, alpha); + &guiPalette->getColor(Palette::BACKGROUND, alpha); if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 9ee91166..5f05971d 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -45,6 +45,7 @@ SpeechBubble::SpeechBubble(): mSpeechBox = new TextBox; mSpeechBox->setEditable(false); mSpeechBox->setOpaque(false); + mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT)); mSpeechArea = new ScrollArea(mSpeechBox); @@ -60,11 +61,11 @@ SpeechBubble::SpeechBubble(): setLocationRelativeTo(getParent()); } -void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color) +void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) { mCaption->setCaption(name); mCaption->adjustSize(); - mCaption->setForegroundColor(color); + mCaption->setForegroundColor(*color); } void SpeechBubble::setText(std::string text, bool showName) diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index 573e61f0..34e00722 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -22,6 +22,7 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H +#include "palette.h" #include "window.h" class ScrollArea; @@ -33,7 +34,8 @@ class SpeechBubble : public Window SpeechBubble(); void setCaption(const std::string &name, - const gcn::Color &color = 0x000000); + const gcn::Color *color = + &guiPalette->getColor(Palette::TEXT)); void setText(std::string text, bool showName = true); void setLocation(int x, int y); unsigned int getNumRows(); diff --git a/src/gui/table.cpp b/src/gui/table.cpp index ece470b1..5fc96dbd 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -338,6 +338,8 @@ void GuiTable::draw(gcn::Graphics* graphics) { graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, (int)(mAlpha * 127.0f))); + graphics->fillRectangle(gcn::Rectangle(0, y_offset, + x_offset, height)); } y_offset += height; diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index a4024de3..10f727e3 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -23,10 +23,11 @@ #include +#include "palette.h" #include "textbox.h" -TextBox::TextBox(): - gcn::TextBox() +TextBox::TextBox() : + gcn::TextBox(), mTextColor(&guiPalette->getColor(Palette::TEXT)) { setOpaque(false); setFrameSize(0); diff --git a/src/gui/textbox.h b/src/gui/textbox.h index 10a81fc0..5884e11c 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -39,6 +39,11 @@ class TextBox : public gcn::TextBox */ TextBox(); + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + /** * Sets the text after wrapping it to the current width of the widget. */ @@ -49,8 +54,18 @@ class TextBox : public gcn::TextBox */ int getMinWidth() { return mMinWidth; } + /** + * Draws the text. + */ + inline void draw(gcn::Graphics *graphics) + { + setForegroundColor(*mTextColor); + gcn::TextBox::draw(graphics); + } + private: int mMinWidth; + const gcn::Color* mTextColor; }; #endif diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 022da0f0..b736591c 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -139,24 +139,20 @@ void DropDown::draw(gcn::Graphics* graphics) } } -// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); + const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT, + alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - gcn::Color col = getBackgroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - col = getForegroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); } graphics->setFont(getFont()); @@ -168,7 +164,7 @@ void DropDown::draw(gcn::Graphics* graphics) if (isFocused()) { - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -180,7 +176,7 @@ void DropDown::draw(gcn::Graphics* graphics) // Draw two lines separating the ListBox with selected // element view. - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawLine(0, h, getWidth(), h); graphics->setColor(shadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index 28d7fd35..4fcaa4a7 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -19,6 +19,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ +#include + #include "textpreview.h" #include "../gui.h" diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 296bc28c..30ff9c35 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -38,6 +38,7 @@ #include "gui/gui.h" #include "gui/ministatus.h" +#include "gui/palette.h" #include "gui/storagewindow.h" #include "net/messageout.h" @@ -212,7 +213,9 @@ void LocalPlayer::logic() void LocalPlayer::setGM() { mIsGM = !mIsGM; - mNameColor = mIsGM ? 0x009000: 0x202020; + mNameColor = mIsGM ? + &guiPalette->getColor(Palette::GM) : + &guiPalette->getColor(Palette::PLAYER); setName(getName()); config.setValue(getName() + "GMassert", mIsGM); } @@ -614,10 +617,9 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, - gui->getInfoParticleFont(), - mPx + 16, mPy - 16, - 255, 255, 0, true); + particleEngine->addTextRiseFadeOutEffect(text, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::EXP_INFO), + gui->getInfoParticleFont(), true); } mXp = xp; } @@ -627,10 +629,9 @@ void LocalPlayer::pickedUp(std::string item) if (mMap) { // Show pickup notification - particleEngine->addTextRiseFadeOutEffect(item, - gui->getInfoParticleFont (), - mPx + 16, mPy - 16, - 40, 220, 40, true); + particleEngine->addTextRiseFadeOutEffect(item, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::PICKUP_INFO), + gui->getInfoParticleFont (), true); } } diff --git a/src/monster.cpp b/src/monster.cpp index 89d0953d..7dc08238 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -27,6 +27,8 @@ #include "sound.h" #include "text.h" +#include "gui/palette.h" + #include "resources/monsterdb.h" #include "resources/monsterinfo.h" @@ -71,7 +73,7 @@ Monster::Monster(int id, Uint16 job, Map *map): } } - mNameColor = 0xff2020; + mNameColor = &guiPalette->getColor(Palette::MONSTER); } Monster::~Monster() @@ -195,7 +197,8 @@ void Monster::showName(bool show) { mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET - getHeight(), - gcn::Graphics::CENTER, gcn::Color(255, 64, 64)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::MONSTER)); } else { diff --git a/src/npc.cpp b/src/npc.cpp index 5a4f9507..630316e0 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -26,6 +26,7 @@ #include "text.h" #include "gui/npc_text.h" +#include "gui/palette.h" #include "net/messageout.h" #include "net/protocol.h" @@ -71,7 +72,7 @@ NPC::NPC(int id, Uint16 job, Map *map, Network *network): } mName = 0; - mNameColor = 0x21bbbb; + mNameColor = &guiPalette->getColor(Palette::NPC); } NPC::~NPC() @@ -85,7 +86,8 @@ void NPC::setName(const std::string &name) delete mName; mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, - gcn::Graphics::CENTER, gcn::Color(200, 200, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::NPC)); Being::setName(displayName + " (NPC)"); } diff --git a/src/particle.cpp b/src/particle.cpp index 6dc45a08..82c163c6 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -324,12 +324,10 @@ Particle *Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, bool outline) +Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -345,13 +343,8 @@ Particle *Particle::addTextSplashEffect(const std::string &text, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, - int colorR, int colorG, - int colorB, bool outline) -{ - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + int x, int y, const gcn::Color *color, gcn::Font *font, bool outline){ + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index b4c80194..3584c4fc 100644 --- a/src/particle.h +++ b/src/particle.h @@ -105,19 +105,17 @@ class Particle : public Sprite /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, - bool outline = false); + Particle *addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, int colorR = 255, - int colorG = 255, int colorB = 255, - bool outline = false); + int x, int y, const gcn::Color *color, gcn::Font *font, + bool outline = false); + /** * Adds an emitter to the particle. */ diff --git a/src/player.cpp b/src/player.cpp index e1928280..8668ac58 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -21,10 +21,13 @@ #include "animatedsprite.h" #include "game.h" +#include "localplayer.h" #include "particle.h" #include "player.h" #include "text.h" +#include "gui/palette.h" + #include "resources/colordb.h" #include "resources/itemdb.h" @@ -50,17 +53,19 @@ void Player::setName(const std::string &name) { if (mIsGM) { - mNameColor = 0x009000; + mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(0, 255, 0)); + &guiPalette->getColor(Palette::GM)); } else { - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::PLAYER); mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(255, 255, 255)); + (this == player_node) ? + &guiPalette->getColor(Palette::SELF) : + &guiPalette->getColor(Palette::PC)); } Being::setName(name); } diff --git a/src/text.cpp b/src/text.cpp index 5a912d17..b0be25bf 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -39,7 +39,7 @@ Image *Text::mBubbleArrow; Text::Text(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color, bool isSpeech) : + const gcn::Color* color, bool isSpeech) : mText(text), mColor(color), mIsSpeech(isSpeech) @@ -133,12 +133,12 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, !mIsSpeech, true); + mColor, boldFont, !mIsSpeech, true); } FlashText::FlashText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color) : + const gcn::Color *color) : Text(text, x, y, alignment, color), mTime(0) { diff --git a/src/text.h b/src/text.h index 6e121da7..a96096cc 100644 --- a/src/text.h +++ b/src/text.h @@ -40,7 +40,7 @@ class Text */ Text(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color, bool isSpeech = false); + const gcn::Color *color, bool isSpeech = false); /** * Destructor. The text is removed from the screen. @@ -65,7 +65,7 @@ class Text int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - gcn::Color mColor; /**< The color of the text. */ + const gcn::Color *mColor; /**< The color of the text. */ bool mIsSpeech; /**< Is this text a speech bubble? */ protected: @@ -78,7 +78,7 @@ class FlashText : public Text public: FlashText(const std::string &text, int x, int y, gcn::Graphics::Alignment alignment, - gcn::Color color); + const gcn::Color* color); /** * Remove the text from the screen diff --git a/src/textparticle.cpp b/src/textparticle.cpp index ed8609e9..792b6bea 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -21,21 +21,17 @@ #include -#include - #include "textparticle.h" #include "gui/textrenderer.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), - mColorR(colorR), - mColorG(colorG), - mColorB(colorB), + mColor(color), mOutline(outline) { } @@ -64,6 +60,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, - (int)alpha); + mColor, mTextFont, mOutline, false, (int)alpha); } diff --git a/src/textparticle.h b/src/textparticle.h index d72df138..8b7d3e01 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -32,7 +32,7 @@ class TextParticle : public Particle * Constructor. */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline = false); /** @@ -47,9 +47,8 @@ class TextParticle : public Particle private: std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ - int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ - bool mOutline; /**< Make the text readable - draw it the way - a Text is usually drawn: with outline */ + const gcn::Color* mColor; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text better readable */ }; #endif -- cgit v1.2.3-70-g09d2 From 393c1085ed1cb24092778594d2945a39428e41ad Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 17:19:31 +0100 Subject: Added a class for rendering of floating text This is a header only-class that merges the textrendering of the TextParticle and Text classes. It is done to reduce code duplication and to prepare some color configuration gui. --- src/gui/textrenderer.h | 81 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/window.cpp | 1 + src/text.cpp | 24 ++++----------- src/textparticle.cpp | 30 +++++-------------- 4 files changed, 95 insertions(+), 41 deletions(-) create mode 100644 src/gui/textrenderer.h (limited to 'src/gui') diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h new file mode 100644 index 00000000..599e85a3 --- /dev/null +++ b/src/gui/textrenderer.h @@ -0,0 +1,81 @@ +/* + * Text Renderer + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra based on code from The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TEXT_RENDERER_H +#define TEXT_RENDERER_H + +#include "graphics.h" +#include "palette.h" + +/** + * Class for text rendering. Used by the TextParticle, the Text and FlashText + * objects and the Preview in the color dialog. + */ +class TextRenderer +{ + public: + /** + * Renders a specified text. + */ + static inline void renderText(gcn::Graphics *graphics, const std::string& + text, int x, int y, gcn::Graphics::Alignment align, + const gcn::Color* color, gcn::Font *font, bool outline = false, + bool shadow = false, int alpha = 255) + { + graphics->setFont(font); + + // Text shadow + if (shadow) + { + graphics->setColor(guiPalette->getColor(Palette::SHADOW, + alpha / 2)); + if (outline) + { + graphics->drawText(text, x + 2, y + 2, align); + } + else + { + graphics->drawText(text, x + 1, y + 1, align); + } + } + + if (outline) { +/* graphics->setColor(guiPalette->getColor(Palette::OUTLINE, + alpha/4)); + // TODO: Reanable when we can draw it nicely in software mode + graphics->drawText(text, x + 2, y + 2, align); + graphics->drawText(text, x + 1, y + 2, align); + graphics->drawText(text, x + 2, y + 1, align);*/ + + // Text outline + graphics->setColor(guiPalette->getColor(Palette::OUTLINE, alpha)); + graphics->drawText(text, x + 1, y, align); + graphics->drawText(text, x - 1, y, align); + graphics->drawText(text, x, y + 1, align); + graphics->drawText(text, x, y - 1, align); + } + + graphics->setColor(*color); + graphics->drawText(text, x, y, align); + } +}; + +#endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index d40ebca6..f6d23950 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -630,6 +630,7 @@ void Window::resetToDefaultSize() { setPosition(mDefaultX, mDefaultY); setSize(mDefaultWidth, mDefaultHeight); + saveWindowState(); } int Window::getResizeHandles(gcn::MouseEvent &event) diff --git a/src/text.cpp b/src/text.cpp index e5e40235..c167701a 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -26,6 +26,8 @@ #include "textmanager.h" #include "gui/gui.h" +#include "gui/palette.h" +#include "gui/textrenderer.h" int Text::mInstances = 0; @@ -76,23 +78,9 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) { graphics->setFont(boldFont); - // Text shadow - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mText, mX - xOff + 1, mY - yOff + 1, - gcn::Graphics::LEFT); - - // Text outline - graphics->drawText(mText, mX - xOff + 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff - 1, mY - yOff, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff + 1, - gcn::Graphics::LEFT); - graphics->drawText(mText, mX - xOff, mY - yOff - 1, - gcn::Graphics::LEFT); - - graphics->setColor(mColor); - graphics->drawText(mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT); + TextRenderer::renderText(graphics, mText, + mX - xOff, mY - yOff, gcn::Graphics::LEFT, + &mColor, boldFont, !mIsSpeech, true); } FlashText::FlashText(const std::string &text, int x, int y, @@ -107,9 +95,7 @@ void FlashText::draw(gcn::Graphics *graphics, int xOff, int yOff) if (mTime) { if ((--mTime & 4) == 0) - { return; - } } Text::draw(graphics, xOff, yOff); } diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 8a8948f4..a065eadd 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -22,10 +22,12 @@ #include -#include "graphics.h" -#include "textparticle.h" #include +#include "textparticle.h" + +#include "gui/textrenderer.h" + TextParticle::TextParticle(Map *map, const std::string &text, int colorR, int colorG, int colorB, gcn::Font *font, bool outline): @@ -61,24 +63,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const alpha /= mFadeIn; } - graphics->setFont(mTextFont); - if (mOutline) - { - graphics->setColor(gcn::Color(0, 0, 0, (int)(alpha/4))); - // Text outline - graphics->setColor(gcn::Color(0, 0, 0, (int)alpha)); - graphics->drawText(mText, screenX + 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX - 1, screenY, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY + 1, - gcn::Graphics::CENTER); - - graphics->drawText(mText, screenX, screenY - 1, - gcn::Graphics::CENTER); - } - graphics->setColor(gcn::Color(mColorR, mColorG, mColorB, (int)alpha)); - graphics->drawText(mText, screenX, screenY, gcn::Graphics::CENTER); + TextRenderer::renderText(graphics, mText, + screenX, screenY, gcn::Graphics::CENTER, + &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, + (int) alpha); } -- cgit v1.2.3-70-g09d2 From 7d20381b7b9abdf0934ee0fbbb196c788ea93a0d Mon Sep 17 00:00:00 2001 From: sniper Date: Wed, 11 Mar 2009 15:35:54 +0100 Subject: Extending the internal handling of colors The internal storage for colors was in the file color.h/color.cpp. It mainly managed the colors in the chat. The Color class was extended to be more generic now and it stores gcn::Color objects instead of integers now. A lot of new colortypes are now available, though not many of them are used for now, that will come in the next patches. The Color class was renamed to Palette and color.{h,cpp} to palette.{h,cpp} to better describe its purpose. The color config gui now lists the new colors, even changes them, but the result is not displayed properly for now. --- aethyra.cbp | 5 +- src/CMakeLists.txt | 5 +- src/Makefile.am | 5 +- src/gui/browserbox.cpp | 21 ++- src/gui/listbox.cpp | 11 +- src/gui/palette.cpp | 317 +++++++++++++++++++++++++++++++++++++++++++ src/gui/palette.h | 297 ++++++++++++++++++++++++++++++++++++++++ src/gui/setup_colors.cpp | 55 ++++---- src/gui/setup_colors.h | 2 + src/gui/shoplistbox.cpp | 40 +++--- src/gui/table.cpp | 31 +---- src/gui/widgets/dropdown.cpp | 21 ++- src/main.cpp | 8 +- src/text.cpp | 2 +- 14 files changed, 714 insertions(+), 106 deletions(-) create mode 100644 src/gui/palette.cpp create mode 100644 src/gui/palette.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index aa1737b7..b9e80430 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -132,8 +132,6 @@ - - @@ -191,6 +189,8 @@ + + @@ -256,6 +256,7 @@ + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9fdca23a..6565a1b0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -81,8 +81,6 @@ SET(SRCS gui/chatinput.h gui/checkbox.cpp gui/checkbox.h - gui/color.cpp - gui/color.h gui/confirm_dialog.cpp gui/confirm_dialog.h gui/connection.cpp @@ -140,6 +138,8 @@ SET(SRCS gui/npc_text.h gui/ok_dialog.cpp gui/ok_dialog.h + gui/palette.cpp + gui/palette.h gui/passwordfield.cpp gui/passwordfield.h gui/playerbox.cpp @@ -205,6 +205,7 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h + gui/textrenderer.h gui/trade.cpp gui/trade.h gui/truetypefont.cpp diff --git a/src/Makefile.am b/src/Makefile.am index c4265dec..b3bdde9d 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -31,8 +31,6 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/chatinput.h \ gui/checkbox.cpp \ gui/checkbox.h \ - gui/color.cpp \ - gui/color.h \ gui/confirm_dialog.cpp \ gui/confirm_dialog.h \ gui/connection.cpp \ @@ -90,6 +88,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/npc_text.h \ gui/ok_dialog.cpp \ gui/ok_dialog.h \ + gui/palette.cpp \ + gui/palette.h \ gui/passwordfield.cpp \ gui/passwordfield.h \ gui/playerbox.cpp \ @@ -155,6 +155,7 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/textbox.h \ gui/textfield.cpp \ gui/textfield.h \ + gui/textrenderer.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/gui/browserbox.cpp b/src/gui/browserbox.cpp index 2b690b21..46c8bdf1 100644 --- a/src/gui/browserbox.cpp +++ b/src/gui/browserbox.cpp @@ -25,8 +25,8 @@ #include #include "browserbox.h" -#include "color.h" #include "linkhandler.h" +#include "palette.h" #include "truetypefont.h" BrowserBox::BrowserBox(unsigned int mode, bool opaque): @@ -250,16 +250,15 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mOpaque) { - graphics->setColor(gcn::Color(BGCOLOR)); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } if (mSelectedLink >= 0) { - bool valid; if ((mHighMode & BACKGROUND)) { - graphics->setColor(gcn::Color(textColor->getColor('H', valid))); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT)); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -270,7 +269,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - graphics->setColor(gcn::Color(textColor->getColor('<', valid))); + graphics->setColor(guiPalette->getColor(Palette::HYPERLINK)); graphics->drawLine( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y2, @@ -284,11 +283,11 @@ void BrowserBox::draw(gcn::Graphics *graphics) int link = 0; TrueTypeFont *font = static_cast(getFont()); - graphics->setColor(BLACK); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++) { - int selColor = BLACK; - int prevColor = selColor; + const gcn::Color *selColor = &guiPalette->getColor(Palette::TEXT); + const gcn::Color *prevColor = selColor; std::string row = *(i); bool wrapped = false; x = 0; @@ -336,7 +335,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) else { bool valid; - int rgb = textColor->getColor(c, valid); + const gcn::Color *col = &guiPalette->getColor(c, valid); if (c == '<') { const int size = mLinks[link].x2 - mLinks[link].x1; @@ -349,7 +348,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) } if (valid) { - selColor = rgb; + selColor = col; } } start += 3; @@ -359,7 +358,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) break; } } - graphics->setColor(gcn::Color(selColor)); + graphics->setColor(*selColor); } std::string::size_type len = diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index 82011239..e53a1652 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -25,8 +25,8 @@ #include #include -#include "color.h" #include "listbox.h" +#include "palette.h" #include "../configuration.h" @@ -45,13 +45,8 @@ void ListBox::draw(gcn::Graphics *graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); - bool valid; - const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 255.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 255.0f))); graphics->setFont(getFont()); const int fontHeight = getFont()->getHeight(); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp new file mode 100644 index 00000000..a79f2050 --- /dev/null +++ b/src/gui/palette.cpp @@ -0,0 +1,317 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "palette.h" +#include "gui.h" + +#include "../configuration.h" +#include "../game.h" + +#include "../utils/gettext.h" +#include "../utils/stringutils.h" + +const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); + +const gcn::Color Palette::RAINBOW_COLORS[8] = { + gcn::Color(255, 0, 0), + gcn::Color(255, 153, 0), + gcn::Color(255, 255, 0), + gcn::Color(0, 153, 0), + gcn::Color(0, 204, 204), + gcn::Color(51, 0, 153), + gcn::Color(153, 0, 153) +}; +/** Number of Elemets of RAINBOW_COLORS */ +const int Palette::RAINBOW_COLOR_COUNT = 7; + +std::string Palette::getConfigName(const std::string& typeName) +{ + std::string res = "Color" + typeName; + + int pos = 5; + for (unsigned int i = 0; i < typeName.length(); i++) + { + if (i==0 || typeName[i] == '_') + { + if (i > 0) + { + i++; + } + res[pos] = typeName[i]; + } + else + { + res[pos] = tolower(typeName[i]); + } + pos++; + } + res.erase(pos, res.length() - pos); + + return res; +} + +DEFENUMNAMES(ColorType, COLOR_TYPE); + +const int Palette::GRADIENT_DELAY = 20; + +Palette::Palette() : + mRainbowTime(tick_time), + mColVector(ColVector(TYPE_COUNT)), + mGradVector() +{ + std::string indent = " "; + addColor(TEXT, 0x000000, STATIC, _("Text")); + addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0); + addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0); + + addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); + + addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); + addColor(SHOP_WARNING, 0x910000, STATIC, indent + + _("Item too expensive")); + + addColor(CHAT, 0x000000, STATIC, _("Chat"), 'C'); + addColor(GM, 0xff0000, STATIC, indent + _("GM"), 'G'); + addColor(PLAYER, 0x1fa052, STATIC, indent + _("Player"), 'Y'); + addColor(WHISPER, 0x0000ff, STATIC, indent + _("Whisper"), 'W'); + addColor(IS, 0xa08527, STATIC, indent + _("Is"), 'I'); + addColor(PARTY, 0xff00d8, STATIC, indent + _("Party"), 'P'); + addColor(SERVER, 0x8415e2, STATIC, indent + _("Server"), 'S'); + addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L'); + addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<'); + + addColor(BEING, 0xffffff, STATIC, _("Being"), 0); + addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0); + addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0); + addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0); + addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0); + addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0); + + addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); + addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), + 0); + addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0); + addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, + indent + _("Player hits Monster"), 0); + addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, + indent + _("Monster hits Player"), 0); + addColor(HIT_CRITICAL, 0xff0000, RAINBOW, + indent + _("Critical Hit"), 0); + addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0); + commit(true); +} + +Palette::~Palette() +{ + const std::string *configName; + for (ColVector::iterator col = mColVector.begin(), + colEnd = mColVector.end(); col != colEnd; ++col) + { + configName = &ColorTypeNames[col->type]; + config.setValue(*configName + "Gradient", col->grad); + if (col->grad == STATIC) + { + config.setValue(*configName, toString(col->getRGB())); + } + } +} + +const gcn::Color& Palette::getColor(char c, bool &valid) + { + for (ColVector::const_iterator col = mColVector.begin(), + colEnd = mColVector.end(); col != colEnd; ++col) + { + if (col->ch == c) + { + valid = true; + return col->color; + } + } + valid = false; + return BLACK; +} + +void Palette::setColor(ColorType type, int r, int g, int b) +{ + mColVector[type].color.r = r; + mColVector[type].color.g = g; + mColVector[type].color.b = b; +} + +void Palette::setGradient(ColorType type, GradientType grad) +{ + ColorElem *elem = &mColVector[type]; + if (elem->grad != STATIC && grad == STATIC) + { + for (unsigned int i = 0; i < mGradVector.size(); i++) + { + if (mGradVector[i] == elem) + { + mGradVector.erase(mGradVector.begin() + i); + break; + } + } + } + else if (elem->grad == STATIC && grad != STATIC) + { + mGradVector.push_back(elem); + } + + if (elem->grad != grad) + { + elem->grad = grad; + } +} + +std::string Palette::getElementAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return ""; + } + return mColVector[i].text; +} + +Palette::ColorType Palette::getColorTypeAt(int i) +{ + if (i < 0 || i >= getNumberOfElements()) + { + return CHAT; + } + return mColVector[i].type; +} + +void Palette::commit(bool commitNonStatic) +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; ++i) + { + i->committedGrad = i->grad; + if (commitNonStatic || i->grad == STATIC) + { + i->committedColor = i->color; + } + } +} + +void Palette::rollback() +{ + for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); + i != iEnd; + ++i) + { + i->grad = i->committedGrad; + if (i->grad == STATIC) + { + i->color = i->committedColor; + } + } +} + +void Palette::addColor(Palette::ColorType type, int rgb, + Palette::GradientType grad, + const std::string &text, char c) +{ + const std::string *configName = &ColorTypeNames[type]; + gcn::Color trueCol = (int)config.getValue(*configName, rgb); + grad = (GradientType)config.getValue(*configName + "Gradient", grad); + mColVector[type].set(type, trueCol, grad, text, c); + if (grad != STATIC) + { + mGradVector.push_back(&mColVector[type]); + } +} + +void Palette::advanceGradient () +{ + if (get_elapsed_time(mRainbowTime) > 5) + { + int pos, colIndex, colVal; + // For slower systems, advance can be greater than one (adcanve > 1 + // skips advance-1 steps). Should make gradient look the same + // independent of the framerate. + int advance = get_elapsed_time(mRainbowTime) / 5; + double startColVal, destColVal; + + for (unsigned int i = 0; i < mGradVector.size(); i++) + { + mGradVector[i]->gradientIndex = + (mGradVector[i]->gradientIndex + advance) % + (GRADIENT_DELAY * + ((mGradVector[i]->grad == SPECTRUM) ? 6 : + RAINBOW_COLOR_COUNT)); + + pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY; + colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY; + + if (mGradVector[i]->grad == SPECTRUM) + { + if (colIndex % 2) + { // falling curve + colVal = (int)(255.0 * + (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + } + else + { // ascending curve + colVal = (int)(255.0 * + (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + + 1) / 2); + } + + mGradVector[i]->color.r = + (colIndex == 0 || colIndex == 5) ? 255 : + (colIndex == 1 || colIndex == 4) ? colVal : 0; + mGradVector[i]->color.g = + (colIndex == 1 || colIndex == 2) ? 255 : + (colIndex == 0 || colIndex == 3) ? colVal : 0; + mGradVector[i]->color.b = + (colIndex == 3 || colIndex == 4) ? 255 : + (colIndex == 2 || colIndex == 5) ? colVal : 0; + } + else + { + const gcn::Color* startCol = &RAINBOW_COLORS[colIndex]; + const gcn::Color* destCol = + &RAINBOW_COLORS[(colIndex + 1) % RAINBOW_COLOR_COUNT]; + + startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2; + destColVal = 1 - startColVal; + + mGradVector[i]->color.r =(int)( + startColVal * startCol->r + + destColVal * destCol->r); + + mGradVector[i]->color.g =(int)( + startColVal * startCol->g + + destColVal * destCol->g); + + mGradVector[i]->color.b =(int)( + startColVal * startCol->b + + destColVal * destCol->b); + } + } + + mRainbowTime = tick_time; + } +} diff --git a/src/gui/palette.h b/src/gui/palette.h new file mode 100644 index 00000000..a372d6cd --- /dev/null +++ b/src/gui/palette.h @@ -0,0 +1,297 @@ +/* + * Configurable text colors + * Copyright (C) 2008 Douglas Boffey + * Copyright (C) 2009 The Mana World Development Team + * + * This file is part of Aethyra. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef PALETTE_H +#define PALETTE_H + +#include +#include +#include + +#include +#include + +// Generate strings from an enum ... some preprocessor fun. +#define EDEF(a) a, +#define ECONFIGSTR(a) Palette::getConfigName(#a), + +#define TEXTENUM(name,def)\ + enum name { def(EDEF) };\ + static const std::string name ## Names[]; +#define DEFENUMNAMES(name,def)\ + const std::string Palette::name ## Names[] = { def(ECONFIGSTR) "" }; + +/** + * Class controlling the game's color palette. + */ +class Palette : public gcn::ListModel +{ + public: + /** List of all colors that are configurable. */ + #define COLOR_TYPE(ENTRY)\ + ENTRY(TEXT)\ + ENTRY(SHADOW)\ + ENTRY(OUTLINE)\ + ENTRY(BACKGROUND)\ + ENTRY(HIGHLIGHT)\ + ENTRY(SHOP_WARNING)\ + ENTRY(CHAT)\ + ENTRY(GM)\ + ENTRY(PLAYER)\ + ENTRY(WHISPER)\ + ENTRY(IS)\ + ENTRY(PARTY)\ + ENTRY(SERVER)\ + ENTRY(LOGGER)\ + ENTRY(HYPERLINK)\ + ENTRY(BEING)\ + ENTRY(PC)\ + ENTRY(SELF)\ + ENTRY(GM_NAME)\ + ENTRY(NPC)\ + ENTRY(MONSTER)\ + ENTRY(PARTICLE)\ + ENTRY(EXP_INFO)\ + ENTRY(PICKUP_INFO)\ + ENTRY(HIT_PLAYER_MONSTER)\ + ENTRY(HIT_MONSTER_PLAYER)\ + ENTRY(HIT_CRITICAL)\ + ENTRY(MISS)\ + ENTRY(TYPE_COUNT)\ + + TEXTENUM(ColorType, COLOR_TYPE); + + /** Colors can be static or can alter over time. */ + enum GradientType { + STATIC, + SPECTRUM, + RAINBOW + }; + + /** + * Constructor + */ + Palette(); + + /** + * Destructor + */ + ~Palette(); + + /** + * Returns the color associated with a character, if it exists. Returns + * Palette::BLACK if the character is not found. + * + * @param c character requested + * @param valid indicate whether character is known + * + * @return the requested color or Palette::BLACK + */ + const gcn::Color& getColor(char c, bool &valid); + + /** + * Gets the color with the associated type. Sets the alpha channel + * before returning. + * + * @param type the color type requested + * @param alpha alpha channel to use + * + * @return the requested color + */ + inline const gcn::Color& getColor(ColorType type, int alpha = 255) + { + gcn::Color* col = &mColVector[type].color; + col->a = alpha; + return *col; + } + + /** + * Gets the GradientType used by the specified color. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ + inline GradientType getGradientType(ColorType type) + { + return mColVector[type].grad; + } + + /** + * Get the character used by the specified color. + * + * @param type the color type of the color + * + * @return the color char of the color with the given index + */ + inline char getColorChar(ColorType type) + { + return mColVector[type].ch; + } + + /** + * Sets the color for the specified type. + * + * @param type color to be set + * @param r red component + * @param g green component + * @param b blue component + */ + void setColor(ColorType type, int r, int g, int b); + + /** + * Sets the gradient type for the specified color. + * + * @param grad gradient type to set + */ + void setGradient(ColorType type, GradientType grad); + + /** + * Returns the number of colors known. + * + * @return the number of colors known + */ + inline int getNumberOfElements() { return mColVector.size(); } + + /** + * Returns the name of the ith color. + * + * @param i index of color interested in + * + * @return the name of the color + */ + std::string getElementAt(int i); + + /** + * Gets the ColorType used by the color for the element at index i in + * the current color model. + * + * @param i the index of the color + * + * @return the color type of the color with the given index + */ + ColorType getColorTypeAt(int i); + + /** + * Commit the colors + */ + inline void commit() + { + commit(false); + } + + /** + * Rollback the colors + */ + void rollback(); + + /** + * Updates all colors, that are non-static. + */ + void advanceGradient(); + + private: + /** Black Color Constant */ + static const gcn::Color BLACK; + + /** Colors used for the rainbow gradient */ + static const gcn::Color RAINBOW_COLORS[]; + static const int RAINBOW_COLOR_COUNT; + /** Parameter to control the speed of the gradient */ + static const int GRADIENT_DELAY; + /** Time tick, that gradient-type colors were updated the last time. */ + int mRainbowTime; + + /** + * Define a color replacement. + * + * @param i the index of the color to replace + * @param r red component + * @param g green component + * @param b blue component + */ + void setColorAt(int i, int r, int g, int b); + + /** + * Commit the colors. Commit the non-static color values, if + * commitNonStatic is true. Only needed in the constructor. + */ + void commit(bool commitNonStatic); + + struct ColorElem + { + ColorType type; + gcn::Color color; + gcn::Color committedColor; + std::string text; + char ch; + GradientType grad; + GradientType committedGrad; + int gradientIndex; + + void set(ColorType type, gcn::Color& color, GradientType grad, + const std::string &text, char c) + { + ColorElem::type = type; + ColorElem::color = color; + ColorElem::text = text; + ColorElem::ch = c; + ColorElem::grad = grad; + ColorElem::gradientIndex = rand(); + } + + inline int getRGB() { + return (committedColor.r << 16) | (committedColor.g << 8) | + committedColor.b; + } + }; + typedef std::vector ColVector; + /** Vector containing the colors. */ + ColVector mColVector; + std::vector mGradVector; + + /** + * Initialise color + * + * @param c character that needs initialising + * @param rgb default color if not found in config + * @param text identifier of color + */ + void addColor(ColorType type, int rgb, GradientType grad, + const std::string &text, char c = 0); + + /** + * Prefixes the given string with "Color", lowercases all letters but + * the first and all following a '_'. All '_'s will be removed. + * + * E.g.: HIT_PLAYER_MONSTER -> HitPlayerMonster + * + * @param typeName string to transform + * + * @return the transformed string + */ + static std::string getConfigName(const std::string& typeName); +}; + +extern Palette *guiPalette; + +#endif diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 31b56b51..4f017e15 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,9 +27,9 @@ #include #include "browserbox.h" -#include "color.h" #include "itemlinkhandler.h" #include "listbox.h" +#include "palette.h" #include "scrollarea.h" #include "setup_colors.h" #include "slider.h" @@ -42,12 +42,14 @@ #include "../utils/gettext.h" #include "../utils/stringutils.h" +const std::string Setup_Colors::rawmsg = _("This is what the color looks like"); + Setup_Colors::Setup_Colors() : mSelected(-1) { setOpaque(false); - mColorBox = new ListBox(textColor); + mColorBox = new ListBox(guiPalette); mColorBox->setActionEventId("color_box"); mColorBox->addActionListener(this); @@ -131,6 +133,9 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { + delete mPreview; + delete mPreviewBox; + delete mRedLabel; delete mRedSlider; delete mRedText; @@ -143,6 +148,7 @@ Setup_Colors::~Setup_Colors() delete mBlueSlider; delete mBlueText; + delete mColorBox; delete mScroll; } @@ -151,22 +157,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event) if (event.getId() == "color_box") { mSelected = mColorBox->getSelected(); - int col = textColor->getColorAt(mSelected); - char ch = textColor->getColorCharAt(mSelected); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + std::string msg; + mPreview->clearRows(); + char ch = guiPalette->getColorChar(type); if (ch == '<') - msg = toString("@@|") + - _("This is what the color looks like") + "@@"; + msg = toString("@@|") + rawmsg + "@@"; else - msg = "##" + toString(ch) + - _("This is what the color looks like"); - - mPreview->clearRows(); + msg = "##" + toString(ch) + rawmsg; mPreview->addRow(msg); - setEntry(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); + + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); return; } @@ -202,16 +208,17 @@ void Setup_Colors::setEntry(gcn::Slider *s, TextField *t, int value) void Setup_Colors::apply() { - textColor->commit(); + guiPalette->commit(); } void Setup_Colors::cancel() { - textColor->rollback(); - int col = textColor->getColorAt(mSelected); - setEntry(mRedSlider, mRedText, col >> 16); - setEntry(mGreenSlider, mGreenText, (col >> 8) & 0xff); - setEntry(mBlueSlider, mBlueText, col & 0xff); + guiPalette->rollback(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + const gcn::Color *col = &guiPalette->getColor(type); + setEntry(mRedSlider, mRedText, col->r); + setEntry(mGreenSlider, mGreenText, col->g); + setEntry(mBlueSlider, mBlueText, col->b); } void Setup_Colors::listen(const TextField *tf) @@ -242,8 +249,10 @@ void Setup_Colors::updateColor() { return; } - int rgb = static_cast(mRedSlider->getValue()) << 16 | - static_cast(mGreenSlider->getValue()) << 8 | - static_cast(mBlueSlider->getValue()); - textColor->setColorAt(mSelected, rgb); + + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 98a2d18b..6cf59b6d 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -48,6 +48,8 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void listen(const TextField *tf); private: + static const std::string rawmsg; + gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 776f26bc..74209122 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -23,7 +23,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "shop.h" #include "shoplistbox.h" @@ -64,11 +64,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); - bool valid; - const int red = (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 255.0f); + int alpha = (int)(mAlpha * 255.0f); + const gcn::Color* highlightColor = + &guiPalette->getColor(Palette::HIGHLIGHT, alpha); Graphics *graphics = static_cast(gcnGraphics); @@ -79,19 +77,27 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) i < mListModel->getNumberOfElements(); ++i, y += mRowHeight) { - gcn::Color backgroundColor = gcn::Color(255, 255, 255, alpha); + gcn::Color temp; + const gcn::Color* backgroundColor = + &guiPalette->getColor(Palette::BACKGROUND, alpha); - if (i == mSelected) - { - backgroundColor = gcn::Color(red, green, blue, alpha); - } - else if (mShopItems && + if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) - { - backgroundColor = gcn::Color(145, 145, 145, alpha); - } + if (i != mSelected) + backgroundColor = &guiPalette->getColor(Palette::SHOP_WARNING, + alpha); + else + { + temp = guiPalette->getColor(Palette::SHOP_WARNING, alpha); + temp.r = (temp.r + highlightColor->r) / 2; + temp.g = (temp.g + highlightColor->g) / 2; + temp.b = (temp.g + highlightColor->b) / 2; + backgroundColor = &temp; + } + else if (i == mSelected) + backgroundColor = highlightColor; - graphics->setColor(backgroundColor); + graphics->setColor(*backgroundColor); graphics->fillRectangle(gcn::Rectangle(0, y, getWidth(), mRowHeight)); if (mShopItems) @@ -102,7 +108,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) graphics->drawImage(icon, 1, y); } } - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); } diff --git a/src/gui/table.cpp b/src/gui/table.cpp index b2571495..144e7e21 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -24,7 +24,7 @@ #include #include -#include "color.h" +#include "palette.h" #include "table.h" #include "../configuration.h" @@ -273,11 +273,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mOpaque) { - const int red = getBackgroundColor().r; - const int green = getBackgroundColor().g; - const int blue = getBackgroundColor().b; - const int alpha = (int)(mAlpha * 255.0f); - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -324,15 +321,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow) { - bool valid; - const int red = - (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = - (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 127.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 127.0f))); graphics->fillRectangle(bounds); } @@ -346,15 +336,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mLinewiseMode && r == mSelectedRow) { - bool valid; - const int red = - (textColor->getColor('H', valid) >> 16) & 0xFF; - const int green = - (textColor->getColor('H', valid) >> 8) & 0xFF; - const int blue = textColor->getColor('H', valid) & 0xFF; - const int alpha = (int)(mAlpha * 127.0f); - - graphics->setColor(gcn::Color(red, green, blue, alpha)); + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 127.0f))); graphics->fillRectangle(gcn::Rectangle(0, y_offset, x_offset, height)); } diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 7036c2ee..076a167f 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -24,8 +24,8 @@ #include "dropdown.h" -#include "../color.h" #include "../listbox.h" +#include "../palette.h" #include "../scrollarea.h" #include "../../configuration.h" @@ -140,27 +140,24 @@ void DropDown::draw(gcn::Graphics* graphics) } } - bool valid; +// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = textColor->getColor('H', valid); - highlightColor.a = alpha; + gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - int red = getBackgroundColor().r; - int green = getBackgroundColor().g; - int blue = getBackgroundColor().b; - graphics->setColor(gcn::Color(red, green, blue, alpha)); + gcn::Color col = getBackgroundColor(); + col.a = alpha; + graphics->setColor(col); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - red = getForegroundColor().r; - green = getForegroundColor().g; - blue = getForegroundColor().b; - graphics->setColor(gcn::Color(red, green, blue, alpha)); + col = getForegroundColor(); + col.a = alpha; + graphics->setColor(col); } graphics->setFont(getFont()); diff --git a/src/main.cpp b/src/main.cpp index fab7ed95..bed297de 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -56,10 +56,10 @@ #include "gui/button.h" #include "gui/char_server.h" #include "gui/char_select.h" -#include "gui/color.h" #include "gui/gui.h" #include "gui/login.h" #include "gui/ok_dialog.h" +#include "gui/palette.h" #include "gui/progressbar.h" #include "gui/register.h" #include "gui/sdlinput.h" @@ -134,7 +134,7 @@ CharServerHandler charServerHandler; LoginData loginData; LockedArray charInfo(MAX_SLOT + 1); -Color *textColor; +Palette *guiPalette; // This anonymous namespace hides whatever is inside from other modules. namespace { @@ -767,7 +767,7 @@ int main(int argc, char *argv[]) unsigned int oldstate = !state; // We start with a status change. // Needs to be created in main, as the updater uses it - textColor = new Color(); + guiPalette = new Palette; Game *game = NULL; Window *currentDialog = NULL; @@ -1108,7 +1108,7 @@ int main(int argc, char *argv[]) usleep(50000); } - delete textColor; + delete guiPalette; #ifdef PACKAGE_VERSION delete versionLabel; #endif diff --git a/src/text.cpp b/src/text.cpp index c167701a..2d96152b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -80,7 +80,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, !mIsSpeech, true); + &mColor, boldFont, true, true); } FlashText::FlashText(const std::string &text, int x, int y, -- cgit v1.2.3-70-g09d2 From 5207b4cbb462cfa962a6f566897a6affd92eef94 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 16:48:03 +0100 Subject: Extend color config gui to support the new colors The new color palette supports many more colors that the browserbox can display. So a change to the color config gui was needed. --- aethyra.cbp | 2 + src/CMakeLists.txt | 2 + src/Makefile.am | 4 +- src/gui/gui.cpp | 8 +- src/gui/palette.h | 26 ++++-- src/gui/setup_colors.cpp | 185 +++++++++++++++++++++++++++++++++------- src/gui/setup_colors.h | 8 ++ src/gui/widgets/textpreview.cpp | 58 +++++++++++++ src/gui/widgets/textpreview.h | 115 +++++++++++++++++++++++++ 9 files changed, 363 insertions(+), 45 deletions(-) create mode 100644 src/gui/widgets/textpreview.cpp create mode 100644 src/gui/widgets/textpreview.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index b9e80430..e88f491d 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -256,6 +256,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 6565a1b0..7025c2c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -205,6 +205,8 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h + gui/textpreview.cpp + gui/textpreview.h gui/textrenderer.h gui/trade.cpp gui/trade.h diff --git a/src/Makefile.am b/src/Makefile.am index b3bdde9d..069b12f2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -13,6 +13,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/widgets/tab.h \ gui/widgets/tabbedarea.cpp \ gui/widgets/tabbedarea.h \ + gui/widgets/textpreview.cpp \ + gui/widgets/textpreview.h \ gui/browserbox.cpp \ gui/browserbox.h \ gui/button.cpp \ @@ -155,7 +157,7 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/textbox.h \ gui/textfield.cpp \ gui/textfield.h \ - gui/textrenderer.h \ + gui/textrenderer.h \ gui/trade.cpp \ gui/trade.h \ gui/truetypefont.cpp \ diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 2c0ddee9..434fc1e1 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -26,6 +26,7 @@ #include "focushandler.h" #include "gui.h" +#include "palette.h" #include "sdlinput.h" #include "skin.h" #include "truetypefont.h" @@ -48,11 +49,6 @@ Gui *gui = 0; Viewport *viewport = 0; /**< Viewport on the map. */ SDLInput *guiInput = 0; -// Fonts used in showing hits -gcn::Font *hitRedFont = 0; -gcn::Font *hitBlueFont = 0; -gcn::Font *hitYellowFont = 0; - // Bolded font gcn::Font *boldFont = 0; @@ -177,6 +173,8 @@ void Gui::logic() else mMouseCursorAlpha = std::max(0.0f, mMouseCursorAlpha - 0.005f); + guiPalette->advanceGradient(); + gcn::Gui::logic(); } diff --git a/src/gui/palette.h b/src/gui/palette.h index a372d6cd..02489686 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -109,7 +109,7 @@ class Palette : public gcn::ListModel const gcn::Color& getColor(char c, bool &valid); /** - * Gets the color with the associated type. Sets the alpha channel + * Gets the color associated with the type. Sets the alpha channel * before returning. * * @param type the color type requested @@ -125,12 +125,24 @@ class Palette : public gcn::ListModel } /** - * Gets the GradientType used by the specified color. - * - * @param type the color type of the color - * - * @return the gradient type of the color with the given index - */ + * Gets the committed color associated with the specified type. + * + * @param type the color type requested + * + * @return the requested committed color + */ + inline const gcn::Color& getCommittedColor(ColorType type) + { + return mColVector[type].committedColor; + } + + /** + * Gets the GradientType associated with the specified type. + * + * @param type the color type of the color + * + * @return the gradient type of the color with the given index + */ inline GradientType getGradientType(ColorType type) { return mColVector[type].grad; diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 4f017e15..5019a61a 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -27,6 +27,7 @@ #include #include "browserbox.h" +#include "gui.h" #include "itemlinkhandler.h" #include "listbox.h" #include "palette.h" @@ -56,8 +57,10 @@ Setup_Colors::Setup_Colors() : mScroll = new ScrollArea(mColorBox); mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mTextPreview = new TextPreview(&rawmsg); + mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); - mPreview->setOpaque(false); + mPreview->setOpaque(true); // Replace this later with a more appropriate link handler. For now, this'll // do, as it'll do nothing when clicked on. @@ -68,6 +71,17 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); + mGradTypeLabel = new gcn::Label(_("Type: ")); + + mGradTypeSlider = new Slider(0, 2); + mGradTypeSlider->setWidth(160); + mGradTypeSlider->setActionEventId("slider_grad"); + mGradTypeSlider->setValue(0); + mGradTypeSlider->addActionListener(this); + mGradTypeSlider->setEnabled(false); + + mGradTypeText = new gcn::Label(); + mRedLabel = new gcn::Label(_("Red: ")); mRedText = new TextField(); @@ -75,12 +89,14 @@ Setup_Colors::Setup_Colors() : mRedText->setRange(0, 255); mRedText->setNumeric(true); mRedText->addListener(this); + mRedText->setEnabled(false); mRedSlider = new Slider(0, 255); mRedSlider->setWidth(160); mRedSlider->setValue(mRedText->getValue()); mRedSlider->setActionEventId("slider_red"); mRedSlider->addActionListener(this); + mRedSlider->setEnabled(false); mGreenLabel = new gcn::Label(_("Green: ")); @@ -89,12 +105,14 @@ Setup_Colors::Setup_Colors() : mGreenText->setRange(0, 255); mGreenText->setNumeric(true); mGreenText->addListener(this); + mGreenText->setEnabled(false); mGreenSlider = new Slider(0, 255); mGreenSlider->setWidth(160); mGreenSlider->setValue(mGreenText->getValue()); mGreenSlider->setActionEventId("slider_green"); mGreenSlider->addActionListener(this); + mGreenSlider->setEnabled(false); mBlueLabel = new gcn::Label(_("Blue: ")); @@ -103,12 +121,14 @@ Setup_Colors::Setup_Colors() : mBlueText->setRange(0, 255); mBlueText->setNumeric(true); mBlueText->addListener(this); + mBlueText->setEnabled(false); mBlueSlider = new Slider(0, 255); mBlueSlider->setWidth(160); mBlueSlider->setValue(mBlueText->getValue()); mBlueSlider->setActionEventId("slider_blue"); mBlueSlider->addActionListener(this); + mBlueSlider->setEnabled(false); setOpaque(false); @@ -116,8 +136,11 @@ Setup_Colors::Setup_Colors() : LayoutHelper h(this); ContainerPlacer place = h.getPlacer(0, 0); - place(0, 0, mScroll, 4, 7).setPadding(2); - place(0, 7, mPreviewBox, 4).setPadding(2); + place(0, 0, mScroll, 4, 6).setPadding(2); + place(0, 6, mPreviewBox, 4).setPadding(2); + place(0, 7, mGradTypeLabel, 2); + place(2, 7, mGradTypeSlider); + place(3, 7, mGradTypeText); place(0, 8, mRedLabel, 2); place(2, 8, mRedSlider); place(3, 8, mRedText).setPadding(1); @@ -133,23 +156,10 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { - delete mPreview; - delete mPreviewBox; - - delete mRedLabel; - delete mRedSlider; - delete mRedText; - - delete mGreenLabel; - delete mGreenSlider; - delete mGreenText; - - delete mBlueLabel; - delete mBlueSlider; - delete mBlueText; - - delete mColorBox; - delete mScroll; + if (mPreviewBox->getContent() == mPreview) + delete mTextPreview; + else + delete mPreview; } void Setup_Colors::action(const gcn::ActionEvent &event) @@ -159,20 +169,103 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mSelected = mColorBox->getSelected(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + Palette::GradientType grad = guiPalette->getGradientType(type); std::string msg; + char ch = guiPalette->getColorChar(type); mPreview->clearRows(); - char ch = guiPalette->getColorChar(type); - if (ch == '<') - msg = toString("@@|") + rawmsg + "@@"; - else - msg = "##" + toString(ch) + rawmsg; - mPreview->addRow(msg); + mPreviewBox->setContent(mTextPreview); + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor( + &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextBGColor(NULL); + mTextPreview->setShadow(true); + mTextPreview->setOutline(true); + + switch (type) + { + case Palette::TEXT: + case Palette::SHADOW: + case Palette::OUTLINE: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setOutline(true); + mTextPreview->setShadow(type == Palette::SHADOW); + mTextPreview->setOutline(type == Palette::OUTLINE); + break; + case Palette::BACKGROUND: + case Palette::HIGHLIGHT: + case Palette::SHOP_WARNING: + mTextPreview->setTextBGColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + mPreview->addRow(rawmsg); + break; + case Palette::CHAT: + case Palette::GM: + case Palette::PLAYER: + case Palette::WHISPER: + case Palette::IS: + case Palette::PARTY: + case Palette::SERVER: + case Palette::LOGGER: + case Palette::HYPERLINK: + mPreviewBox->setContent(mPreview); + mPreview->clearRows(); + //char ch = guiPalette->getColorCharAt(mSelected); + //std::string msg; + + if (ch == '<') + { + msg = toString("@@|") + rawmsg + "@@"; + } + else + { + msg = "##" + toString(ch) + rawmsg; + } + //std::cout << msg << std::endl; + mPreview->addRow(msg); + break; + case Palette::PARTICLE: + case Palette::EXP_INFO: + case Palette::PICKUP_INFO: + case Palette::HIT_PLAYER_MONSTER: + case Palette::HIT_MONSTER_PLAYER: + case Palette::HIT_CRITICAL: + case Palette::MISS: + mTextPreview->setShadow(false); + case Palette::BEING: + case Palette::PC: + case Palette::SELF: + case Palette::GM_NAME: + case Palette::NPC: + case Palette::MONSTER: + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + break; + } + + if (grad != Palette::STATIC) + { // If nonstatic color, don't display the current, but the committed + // color at the sliders + col = &guiPalette->getCommittedColor(type); + } setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); + + mGradTypeSlider->setValue(grad); + updateGradType(); + mGradTypeSlider->setEnabled(true); + + return; + } + + if (event.getId() == "slider_grad") + { + updateGradType(); + updateColor(); return; } @@ -216,6 +309,7 @@ void Setup_Colors::cancel() guiPalette->rollback(); Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); const gcn::Color *col = &guiPalette->getColor(type); + mGradTypeSlider->setValue(guiPalette->getGradientType(type)); setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); setEntry(mBlueSlider, mBlueText, col->b); @@ -243,16 +337,43 @@ void Setup_Colors::listen(const TextField *tf) } } +void Setup_Colors::updateGradType() +{ + if (mSelected == -1) + return; + + mSelected = mColorBox->getSelected(); + Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); + Palette::GradientType grad = guiPalette->getGradientType(type); + + mGradTypeText->setCaption( + (grad == Palette::STATIC) ? _("Static") : + (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); + + bool enable = (grad == Palette::STATIC); + mRedText->setEnabled(enable); + mRedSlider->setEnabled(enable); + mGreenText->setEnabled(enable); + mGreenSlider->setEnabled(enable); + mBlueText->setEnabled(enable); + mBlueSlider->setEnabled(enable); +} + void Setup_Colors::updateColor() { if (mSelected == -1) - { return; - } Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); - guiPalette->setColor(type, - static_cast(mRedSlider->getValue()), - static_cast(mGreenSlider->getValue()), - static_cast(mBlueSlider->getValue())); + Palette::GradientType grad = + static_cast(mGradTypeSlider->getValue()); + guiPalette->setGradient(type, grad); + + if (grad == Palette::STATIC) + { + guiPalette->setColor(type, + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue())); + } } diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 6cf59b6d..00f77d57 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -34,6 +34,8 @@ #include "../guichanfwd.h" +#include "widgets/textpreview.h" + class BrowserBox; class Setup_Colors : public SetupTab, public gcn::ActionListener, @@ -53,9 +55,14 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, gcn::ListBox *mColorBox; gcn::ScrollArea *mScroll; BrowserBox *mPreview; + TextPreview *mTextPreview; gcn::ScrollArea *mPreviewBox; int mSelected; + gcn::Label *mGradTypeLabel; + gcn::Slider *mGradTypeSlider; + gcn::Label *mGradTypeText; + gcn::Label *mRedLabel; gcn::Slider *mRedSlider; TextField *mRedText; @@ -73,5 +80,6 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, void setEntry(gcn::Slider *s, TextField *t, int value); void updateColor(); + void updateGradType(); }; #endif diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp new file mode 100644 index 00000000..f77657c2 --- /dev/null +++ b/src/gui/widgets/textpreview.cpp @@ -0,0 +1,58 @@ +/* + * The Mana World + * Copyright (C) 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include + +#include "textpreview.h" + +#include "../gui.h" +#include "../palette.h" +#include "../textrenderer.h" +#include "../truetypefont.h" + +TextPreview::TextPreview(const std::string* text) +{ + mText = text; + mFont = gui->getFont(); + mTextColor = &guiPalette->getColor(Palette::TEXT); + mTextBGColor = NULL; + mBGColor = &guiPalette->getColor(Palette::BACKGROUND); +} + +void TextPreview::draw(gcn::Graphics* graphics) +{ + graphics->setColor(*mBGColor); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + + const std::string ttf = "TrueTypeFont"; + + if (mTextBGColor && typeid(*mFont).name() == ttf) + { + TrueTypeFont *font = static_cast(mFont); + graphics->setColor(*mTextBGColor); + int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); + int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + } + + TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, + mTextColor, mFont, mOutline, mShadow); +} diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h new file mode 100644 index 00000000..12db9f3f --- /dev/null +++ b/src/gui/widgets/textpreview.h @@ -0,0 +1,115 @@ +/* + * The Mana World + * Copyright (C) 2006 The Mana World Development Team + * + * This file is part of The Mana World. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef TEXTPREVIEW_H +#define TEXTPREVIEW_H + +#include +#include +#include + +/** + * Preview widget for particle colors, etc. + */ +class TextPreview : public gcn::Widget +{ + public: + TextPreview(const std::string* text); + + /** + * Sets the color the text is printed in. + * + * @param color the color to set + */ + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + + /** + * Sets the color the text background is drawn in. This is only the + * rectangle directly behind the text, not to full widget. + * + * @param color the color to set + */ + inline void setTextBGColor(const gcn::Color* color) + { + mTextBGColor = color; + } + + /** + * Sets the background color of the widget. + * + * @param color the color to set + */ + inline void setBGColor(const gcn::Color* color) + { + mBGColor = color; + } + + /** + * Sets the font to render the text in. + * + * @param font the font to use. + */ + inline void setFont(gcn::Font *font) + { + mFont = font; + } + + /** + * Sets whether to use a shadow while rendering. + * + * @param shadow true, if a shadow is wanted, false else + */ + inline void setShadow(bool shadow) + { + mShadow = shadow; + } + + /** + * Sets whether to use an outline while rendering. + * + * @param outline true, if an outline is wanted, false else + */ + inline void setOutline(bool outline) + { + mOutline = outline; + } + + /** + * Widget's draw method. Does the actual job. + * + * @param graphics graphics to draw into + */ + void draw(gcn::Graphics *graphics); + + private: + gcn::Font *mFont; + const std::string* mText; + const gcn::Color* mTextColor; + const gcn::Color* mBGColor; + const gcn::Color* mTextBGColor; + bool mShadow; + bool mOutline; +}; + +#endif -- cgit v1.2.3-70-g09d2 From f0d5e3da15a308fcc962590330e7d8e39e8874b9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 12 Mar 2009 22:42:42 +0100 Subject: Make use of the new available colors This patch lets all being derivatives use the palette to set their name's colors. Text Particle Effects all respect the new settings. Some widgets were updated to use the colors. --- src/being.cpp | 41 ++++++++++++++++------------------------- src/being.h | 2 +- src/gui/listbox.cpp | 2 +- src/gui/shoplistbox.cpp | 2 +- src/gui/speechbubble.cpp | 5 +++-- src/gui/speechbubble.h | 4 +++- src/gui/textbox.cpp | 5 +++-- src/gui/textbox.h | 15 +++++++++++++++ src/gui/widgets/dropdown.cpp | 16 ++++++---------- src/localplayer.cpp | 19 ++++++++++--------- src/monster.cpp | 7 +++++-- src/npc.cpp | 6 ++++-- src/particle.cpp | 17 +++++------------ src/particle.h | 14 ++++++-------- src/player.cpp | 13 +++++++++---- src/text.cpp | 10 ++++++---- src/text.h | 8 +++++--- src/textparticle.cpp | 11 +++-------- src/textparticle.h | 7 +++---- 19 files changed, 105 insertions(+), 99 deletions(-) (limited to 'src/gui') diff --git a/src/being.cpp b/src/being.cpp index 64972912..3a772fbd 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -47,6 +47,7 @@ #include "resources/resourcemanager.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/speechbubble.h" #include "utils/dtor.h" @@ -91,7 +92,7 @@ Being::Being(int id, int job, Map *map): mSpeechBubble = new SpeechBubble(); mSpeech = ""; - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::CHAT); mText = 0; } @@ -192,17 +193,14 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) gcn::Font *font; std::string damage = amount ? toString(amount) : type == FLEE ? "dodge" : "miss"; - - int red, green, blue; + const gcn::Color* color; font = gui->getInfoParticleFont(); // Selecting the right color if (type == CRITICAL || type == FLEE) { - red = 255; - green = 128; - blue = 0; + color = &guiPalette->getColor(Palette::HIT_CRITICAL); } else if (!amount) { @@ -210,39 +208,31 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) { // This is intended to be the wrong direction to visually // differentiate between hits and misses - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } else { - red = 255; - green = 255; - blue = 0; - } - } + color = &guiPalette->getColor(Palette::MISS); + } + } else if (getType() == MONSTER) { - red = 0; - green = 100; - blue = 255; + color = &guiPalette->getColor(Palette::HIT_PLAYER_MONSTER); } else { - red = 255; - green = 50; - blue = 50; + color = &guiPalette->getColor(Palette::HIT_MONSTER_PLAYER); } if (amount > 0 && type == CRITICAL) { - particleEngine->addTextSplashEffect("crit!", red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect("crit!", mPx + 16, mPy + 16, + color, font, true); } // Show damage number - particleEngine->addTextSplashEffect(damage, red, green, blue, font, - mPx + 16, mPy + 16, true); + particleEngine->addTextSplashEffect(damage, mPx + 16, mPy + 16, + color, font, true); } void Being::handleAttack(Being *victim, int damage, AttackType type) @@ -503,7 +493,8 @@ void Being::drawSpeech(int offsetX, int offsetY) delete mText; mText = new Text(mSpeech, mPx + X_SPEECH_OFFSET, mPy - Y_SPEECH_OFFSET, - gcn::Graphics::CENTER, gcn::Color(255, 255, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::PARTICLE)); } else if (speech == NO_SPEECH) { diff --git a/src/being.h b/src/being.h index 4b30b6c5..689eda02 100644 --- a/src/being.h +++ b/src/being.h @@ -428,7 +428,7 @@ class Being : public Sprite Gender mGender; int mPx, mPy; /**< Pixel coordinates */ - gcn::Color mNameColor; + const gcn::Color* mNameColor; std::vector mSprites; std::vector mSpriteIDs; diff --git a/src/gui/listbox.cpp b/src/gui/listbox.cpp index e53a1652..71e92eaf 100644 --- a/src/gui/listbox.cpp +++ b/src/gui/listbox.cpp @@ -57,7 +57,7 @@ void ListBox::draw(gcn::Graphics *graphics) getWidth(), fontHeight)); // Draw the list elements - graphics->setColor(gcn::Color(0, 0, 0, 255)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += fontHeight) { diff --git a/src/gui/shoplistbox.cpp b/src/gui/shoplistbox.cpp index 74209122..5c55069f 100644 --- a/src/gui/shoplistbox.cpp +++ b/src/gui/shoplistbox.cpp @@ -79,7 +79,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) { gcn::Color temp; const gcn::Color* backgroundColor = - &guiPalette->getColor(Palette::BACKGROUND, alpha); + &guiPalette->getColor(Palette::BACKGROUND, alpha); if (mShopItems && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index d342328e..cb1724c8 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -46,6 +46,7 @@ SpeechBubble::SpeechBubble(): mSpeechBox = new TextBox(); mSpeechBox->setEditable(false); mSpeechBox->setOpaque(false); + mSpeechBox->setTextColor(&guiPalette->getColor(Palette::CHAT)); mSpeechArea = new ScrollArea(mSpeechBox); @@ -61,11 +62,11 @@ SpeechBubble::SpeechBubble(): setLocationRelativeTo(getParent()); } -void SpeechBubble::setCaption(const std::string &name, const gcn::Color &color) +void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) { mCaption->setCaption(name); mCaption->adjustSize(); - mCaption->setForegroundColor(color); + mCaption->setForegroundColor(*color); } void SpeechBubble::setText(std::string text, bool showName) diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index a1a597c1..d356dac1 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -23,6 +23,7 @@ #ifndef SPEECHBUBBLE_H #define SPEECHBUBBLE_H +#include "palette.h" #include "popup.h" class ScrollArea; @@ -34,7 +35,8 @@ class SpeechBubble : public Popup SpeechBubble(); void setCaption(const std::string &name, - const gcn::Color &color = 0x000000); + const gcn::Color *color = + &guiPalette->getColor(Palette::TEXT)); void setText(std::string text, bool showName = true); void setLocation(int x, int y); unsigned int getNumRows(); diff --git a/src/gui/textbox.cpp b/src/gui/textbox.cpp index 589986cd..51a8efc6 100644 --- a/src/gui/textbox.cpp +++ b/src/gui/textbox.cpp @@ -24,10 +24,11 @@ #include +#include "palette.h" #include "textbox.h" -TextBox::TextBox(): - gcn::TextBox() +TextBox::TextBox() : + gcn::TextBox(), mTextColor(&guiPalette->getColor(Palette::TEXT)) { setOpaque(false); setFrameSize(0); diff --git a/src/gui/textbox.h b/src/gui/textbox.h index 33ea42f9..20f4ebe2 100644 --- a/src/gui/textbox.h +++ b/src/gui/textbox.h @@ -40,6 +40,11 @@ class TextBox : public gcn::TextBox */ TextBox(); + inline void setTextColor(const gcn::Color* color) + { + mTextColor = color; + } + /** * Sets the text after wrapping it to the current width of the widget. */ @@ -50,8 +55,18 @@ class TextBox : public gcn::TextBox */ int getMinWidth() { return mMinWidth; } + /** + * Draws the text. + */ + inline void draw(gcn::Graphics *graphics) + { + setForegroundColor(*mTextColor); + gcn::TextBox::draw(graphics); + } + private: int mMinWidth; + const gcn::Color* mTextColor; }; #endif diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 076a167f..0015beed 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -140,24 +140,20 @@ void DropDown::draw(gcn::Graphics* graphics) } } -// bool valid; const int alpha = (int)(mAlpha * 255.0f); gcn::Color faceColor = getBaseColor(); faceColor.a = alpha; - gcn::Color highlightColor = guiPalette->getColor(Palette::HIGHLIGHT, alpha); + const gcn::Color* highlightColor = &guiPalette->getColor(Palette::HIGHLIGHT, + alpha); gcn::Color shadowColor = faceColor - 0x303030; shadowColor.a = alpha; if (mOpaque) { - gcn::Color col = getBackgroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::BACKGROUND, alpha)); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), h)); - col = getForegroundColor(); - col.a = alpha; - graphics->setColor(col); + graphics->setColor(guiPalette->getColor(Palette::TEXT, alpha)); } graphics->setFont(getFont()); @@ -169,7 +165,7 @@ void DropDown::draw(gcn::Graphics* graphics) if (isFocused()) { - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -181,7 +177,7 @@ void DropDown::draw(gcn::Graphics* graphics) // Draw two lines separating the ListBox with selected // element view. - graphics->setColor(highlightColor); + graphics->setColor(*highlightColor); graphics->drawLine(0, h, getWidth(), h); graphics->setColor(shadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index d6acc48f..f72aa59a 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -37,6 +37,7 @@ #include "text.h" #include "gui/gui.h" +#include "gui/palette.h" #include "gui/storagewindow.h" #include "net/messageout.h" @@ -201,7 +202,9 @@ void LocalPlayer::logic() void LocalPlayer::setGM() { mIsGM = !mIsGM; - mNameColor = mIsGM ? 0x009000: 0x202020; + mNameColor = mIsGM ? + &guiPalette->getColor(Palette::GM) : + &guiPalette->getColor(Palette::PLAYER); setName(getName()); config.setValue(getName() + "GMassert", mIsGM); } @@ -608,10 +611,9 @@ void LocalPlayer::setXp(int xp) const std::string text = toString(xp - mXp) + " xp"; // Show XP number - particleEngine->addTextRiseFadeOutEffect(text, - gui->getInfoParticleFont(), - mPx + 16, mPy - 16, - 255, 255, 0, true); + particleEngine->addTextRiseFadeOutEffect(text, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::EXP_INFO), + gui->getInfoParticleFont(), true); } mXp = xp; } @@ -621,10 +623,9 @@ void LocalPlayer::pickedUp(std::string item) if (mMap) { // Show pickup notification - particleEngine->addTextRiseFadeOutEffect(item, - gui->getInfoParticleFont (), - mPx + 16, mPy - 16, - 40, 220, 40, true); + particleEngine->addTextRiseFadeOutEffect(item, mPx + 16, mPy - 16, + &guiPalette->getColor(Palette::PICKUP_INFO), + gui->getInfoParticleFont (), true); } } diff --git a/src/monster.cpp b/src/monster.cpp index 45d2fbeb..f71457df 100644 --- a/src/monster.cpp +++ b/src/monster.cpp @@ -28,6 +28,8 @@ #include "sound.h" #include "text.h" +#include "gui/palette.h" + #include "resources/monsterdb.h" #include "resources/monsterinfo.h" @@ -72,7 +74,7 @@ Monster::Monster(int id, Uint16 job, Map *map): } } - mNameColor = 0xff2020; + mNameColor = &guiPalette->getColor(Palette::MONSTER); } Monster::~Monster() @@ -196,7 +198,8 @@ void Monster::showName(bool show) { mText = new Text(getInfo().getName(), mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET - getHeight(), - gcn::Graphics::CENTER, gcn::Color(255, 32, 32)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::MONSTER)); } else { diff --git a/src/npc.cpp b/src/npc.cpp index c9250415..a6d60dbb 100644 --- a/src/npc.cpp +++ b/src/npc.cpp @@ -27,6 +27,7 @@ #include "text.h" #include "gui/npc_text.h" +#include "gui/palette.h" #include "net/messageout.h" #include "net/protocol.h" @@ -72,7 +73,7 @@ NPC::NPC(int id, Uint16 job, Map *map, Network *network): } mName = 0; - mNameColor = 0x21bbbb; + mNameColor = &guiPalette->getColor(Palette::NPC); } NPC::~NPC() @@ -86,7 +87,8 @@ void NPC::setName(const std::string &name) delete mName; mName = new Text(displayName, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, - gcn::Graphics::CENTER, gcn::Color(200, 200, 255)); + gcn::Graphics::CENTER, + &guiPalette->getColor(Palette::NPC)); Being::setName(displayName + " (NPC)"); } diff --git a/src/particle.cpp b/src/particle.cpp index 8bc764ba..e56435ed 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -325,12 +325,10 @@ Particle* Particle::addEffect(const std::string &particleEffectFile, return newParticle; } -Particle *Particle::addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, bool outline) +Particle *Particle::addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, bool outline) { - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(((rand() % 100) - 50) / 200.0f, // X ((rand() % 100) - 50) / 200.0f, // Y @@ -346,13 +344,8 @@ Particle *Particle::addTextSplashEffect(const std::string &text, } Particle *Particle::addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, - int colorR, int colorG, - int colorB, bool outline) -{ - Particle *newParticle = new TextParticle(mMap, text, colorR, colorG, colorB, - font, outline); + int x, int y, const gcn::Color *color, gcn::Font *font, bool outline){ + Particle *newParticle = new TextParticle(mMap, text, color, font, outline); newParticle->moveTo(x, y); newParticle->setVelocity(0.0f, 0.0f, 0.5f); newParticle->setGravity(0.0015f); diff --git a/src/particle.h b/src/particle.h index f03f081d..76beb8d1 100644 --- a/src/particle.h +++ b/src/particle.h @@ -106,19 +106,17 @@ class Particle : public Sprite /** * Creates a standalone text particle. */ - Particle *addTextSplashEffect(const std::string &text, - int colorR, int colorG, int colorB, - gcn::Font *font, int x, int y, - bool outline = false); + Particle *addTextSplashEffect(const std::string &text, int x, int y, + const gcn::Color *color, gcn::Font *font, + bool outline = false); /** * Creates a standalone text particle. */ Particle *addTextRiseFadeOutEffect(const std::string &text, - gcn::Font *font, - int x, int y, int colorR = 255, - int colorG = 255, int colorB = 255, - bool outline = false); + int x, int y, const gcn::Color *color, gcn::Font *font, + bool outline = false); + /** * Adds an emitter to the particle. */ diff --git a/src/player.cpp b/src/player.cpp index 61e91613..b289c3e5 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -22,10 +22,13 @@ #include "animatedsprite.h" #include "game.h" +#include "localplayer.h" #include "particle.h" #include "player.h" #include "text.h" +#include "gui/palette.h" + #include "resources/colordb.h" #include "resources/itemdb.h" @@ -51,17 +54,19 @@ void Player::setName(const std::string &name) { if (mIsGM) { - mNameColor = 0x009000; + mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(0, 255, 0)); + &guiPalette->getColor(Palette::GM)); } else { - mNameColor = 0x202020; + mNameColor = &guiPalette->getColor(Palette::PLAYER); mName = new FlashText(name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - gcn::Color(255, 255, 255)); + (this == player_node) ? + &guiPalette->getColor(Palette::SELF) : + &guiPalette->getColor(Palette::PC)); } Being::setName(name); } diff --git a/src/text.cpp b/src/text.cpp index 2d96152b..420eeb8b 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -32,8 +32,9 @@ int Text::mInstances = 0; Text::Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color) : - mText(text), mColor(color) + gcn::Graphics::Alignment alignment, const gcn::Color* color) : + mText(text), + mColor(color) { if (textManager == 0) { @@ -80,11 +81,12 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - &mColor, boldFont, true, true); + mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color) : + gcn::Graphics::Alignment alignment, + const gcn::Color *color) : Text(text, x, y, alignment, color), mTime(0) { diff --git a/src/text.h b/src/text.h index 0b53dd48..cf0aac48 100644 --- a/src/text.h +++ b/src/text.h @@ -39,7 +39,8 @@ class Text * Constructor creates a text object to display on the screen. */ Text(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color); + gcn::Graphics::Alignment alignment, + const gcn::Color *color); /** * Destructor. The text is removed from the screen. @@ -64,14 +65,15 @@ class Text int mXOffset; /**< The offset of mX from the desired x. */ static int mInstances; /**< Instances of text. */ std::string mText; /**< The text to display. */ - gcn::Color mColor; /**< The color of the text. */ + const gcn::Color *mColor; /**< The color of the text. */ }; class FlashText : public Text { public: FlashText(const std::string &text, int x, int y, - gcn::Graphics::Alignment alignment, gcn::Color color); + gcn::Graphics::Alignment alignment, + const gcn::Color* color); /** * Remove the text from the screen diff --git a/src/textparticle.cpp b/src/textparticle.cpp index a065eadd..865c6764 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -22,21 +22,17 @@ #include -#include - #include "textparticle.h" #include "gui/textrenderer.h" TextParticle::TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline): Particle(map), mText(text), mTextFont(font), - mColorR(colorR), - mColorG(colorG), - mColorB(colorB), + mColor(color), mOutline(outline) { } @@ -65,6 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - &gcn::Color(mColorR, mColorG, mColorB), mTextFont, mOutline, false, - (int) alpha); + mColor, mTextFont, mOutline, false, (int) alpha); } diff --git a/src/textparticle.h b/src/textparticle.h index 26b92a50..1a49b5ef 100644 --- a/src/textparticle.h +++ b/src/textparticle.h @@ -33,7 +33,7 @@ class TextParticle : public Particle * Constructor. */ TextParticle(Map *map, const std::string &text, - int colorR, int colorG, int colorB, + const gcn::Color* color, gcn::Font *font, bool outline = false); /** @@ -48,9 +48,8 @@ class TextParticle : public Particle private: std::string mText; /**< Text of the particle. */ gcn::Font *mTextFont; /**< Font used for drawing the text. */ - int mColorR, mColorG, mColorB; /**< Color used for drawing the text. */ - bool mOutline; /**< Make the text readable - draw it the way - a Text is usually drawn: with outline */ + const gcn::Color* mColor; /**< Color used for drawing the text. */ + bool mOutline; /**< Make the text better readable */ }; #endif -- cgit v1.2.3-70-g09d2 From 14fbd95172a6c41abc8e985680c684c40e9e50a8 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 12 Mar 2009 22:07:29 -0600 Subject: Added in option for opacity for the text preview widget, which all of the other widgets have as well. Also set the preview widget to have opacity off, like all of the other widgets (if it is on, then opacity can't be applied to it. Also looks rather tacky with it) Signed-off-by: Ira Rice --- src/gui/setup_colors.cpp | 4 +--- src/gui/widgets/textpreview.cpp | 13 +++++++++---- src/gui/widgets/textpreview.h | 17 ++++++++++++++++- 3 files changed, 26 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 5019a61a..f0f7a529 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -60,7 +60,7 @@ Setup_Colors::Setup_Colors() : mTextPreview = new TextPreview(&rawmsg); mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); - mPreview->setOpaque(true); + mPreview->setOpaque(false); // Replace this later with a more appropriate link handler. For now, this'll // do, as it'll do nothing when clicked on. @@ -212,8 +212,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HYPERLINK: mPreviewBox->setContent(mPreview); mPreview->clearRows(); - //char ch = guiPalette->getColorCharAt(mSelected); - //std::string msg; if (ch == '<') { diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index f77657c2..b13d12e4 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -2,7 +2,7 @@ * The Mana World * Copyright (C) 2006 The Mana World Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra based on code from The Mana World. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -35,12 +35,16 @@ TextPreview::TextPreview(const std::string* text) mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; mBGColor = &guiPalette->getColor(Palette::BACKGROUND); + mOpaque = false; } void TextPreview::draw(gcn::Graphics* graphics) { - graphics->setColor(*mBGColor); - graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + if (mOpaque) + { + graphics->setColor(*mBGColor); + graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); + } const std::string ttf = "TrueTypeFont"; @@ -50,7 +54,8 @@ void TextPreview::draw(gcn::Graphics* graphics) graphics->setColor(*mTextBGColor); int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); - graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + if (mOpaque) + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index 12db9f3f..7e7e461c 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -2,7 +2,7 @@ * The Mana World * Copyright (C) 2006 The Mana World Development Team * - * This file is part of The Mana World. + * This file is part of Aethyra based on code from The Mana World. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -102,12 +102,27 @@ class TextPreview : public gcn::Widget */ void draw(gcn::Graphics *graphics); + /** + * Set opacity for this widget (whether or not to show the background + * color) + * + * @param opaque Whether the widget should be opaque or not + */ + void setOpaque(bool opaque) { mOpaque = opaque; } + + /** + * Gets opacity for this widget (whether or not the background color + * is shown below the widget) + */ + bool isOpaque() { return mOpaque; } + private: gcn::Font *mFont; const std::string* mText; const gcn::Color* mTextColor; const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; + bool mOpaque; bool mShadow; bool mOutline; }; -- cgit v1.2.3-70-g09d2 From 9df0ea3ab0faeb3e9fce71dccb76624d7737798f Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 12 Mar 2009 23:59:28 -0600 Subject: Fixed an incorrect palette reference, as well as a break that was introduced from the palette code. TODO: Cancel is effectively broken, and broken badly in the Colors setup pane. Fix this. Signed-off-by: Ira Rice --- src/gui/speechbubble.cpp | 5 +++++ src/player.cpp | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index cb1724c8..944bae42 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -25,10 +25,13 @@ #include #include "gui.h" +#include "palette.h" #include "scrollarea.h" #include "speechbubble.h" #include "textbox.h" +#include "../graphics.h" + #include "../utils/gettext.h" SpeechBubble::SpeechBubble(): @@ -74,6 +77,8 @@ void SpeechBubble::setText(std::string text, bool showName) if ((text == mText) && (mCaption->getWidth() <= mSpeechBox->getMinWidth())) return; + graphics->setColor(guiPalette->getColor(Palette::TEXT)); + int width = mCaption->getWidth(); mSpeechBox->setTextWrapped(text, 130 > width ? 130 : width); diff --git a/src/player.cpp b/src/player.cpp index b289c3e5..ba4ed1ff 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -57,7 +57,7 @@ void Player::setName(const std::string &name) mNameColor = &guiPalette->getColor(Palette::GM); mName = new FlashText("(GM) " + name, mPx + NAME_X_OFFSET, mPy + NAME_Y_OFFSET, gcn::Graphics::CENTER, - &guiPalette->getColor(Palette::GM)); + &guiPalette->getColor(Palette::GM_NAME)); } else { -- cgit v1.2.3-70-g09d2 From 011133ef09dd4340c7649100cea170e2595b6b2f Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 13 Mar 2009 00:47:50 -0600 Subject: Made the TextPreview widget respect alpha values. Signed-off-by: Ira Rice --- src/gui/setup_colors.cpp | 3 ++- src/gui/widgets/textpreview.cpp | 24 +++++++++++++++++------- src/gui/widgets/textpreview.h | 1 + 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index f0f7a529..038b21c6 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -180,6 +180,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setTextColor( &guiPalette->getColor(Palette::TEXT)); mTextPreview->setTextBGColor(NULL); + mTextPreview->setOpaque(false); mTextPreview->setShadow(true); mTextPreview->setOutline(true); @@ -197,6 +198,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: mTextPreview->setTextBGColor(col); + //mTextPreview->setOpaque(true); mTextPreview->setOutline(false); mTextPreview->setShadow(false); mPreview->addRow(rawmsg); @@ -221,7 +223,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) { msg = "##" + toString(ch) + rawmsg; } - //std::cout << msg << std::endl; mPreview->addRow(msg); break; case Palette::PARTICLE: diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index b13d12e4..e34bb5cb 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -28,6 +28,10 @@ #include "../textrenderer.h" #include "../truetypefont.h" +#include "../../configuration.h" + +float TextPreview::mAlpha = config.getValue("guialpha", 0.8); + TextPreview::TextPreview(const std::string* text) { mText = text; @@ -40,22 +44,28 @@ TextPreview::TextPreview(const std::string* text) void TextPreview::draw(gcn::Graphics* graphics) { + if (config.getValue("guialpha", 0.8) != mAlpha) + mAlpha = config.getValue("guialpha", 0.8); + if (mOpaque) { - graphics->setColor(*mBGColor); + graphics->setColor(gcn::Color((int) mBGColor->r, + (int) mBGColor->g, + (int) mBGColor->b, + (int)(mAlpha * 255.0f))); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } - const std::string ttf = "TrueTypeFont"; - - if (mTextBGColor && typeid(*mFont).name() == ttf) + if (mTextBGColor && typeid(*mFont) == typeid(TrueTypeFont)) { TrueTypeFont *font = static_cast(mFont); - graphics->setColor(*mTextBGColor); int x = font->getWidth(*mText) + 1 + 2 * ((mOutline || mShadow) ? 1 :0); int y = font->getHeight() + 1 + 2 * ((mOutline || mShadow) ? 1 : 0); - if (mOpaque) - graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); + graphics->setColor(gcn::Color((int) mTextBGColor->r, + (int) mTextBGColor->g, + (int) mTextBGColor->b, + (int)(mAlpha * 255.0f))); + graphics->fillRectangle(gcn::Rectangle(1, 1, x, y)); } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index 7e7e461c..a73eb638 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -122,6 +122,7 @@ class TextPreview : public gcn::Widget const gcn::Color* mTextColor; const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; + static float mAlpha; bool mOpaque; bool mShadow; bool mOutline; -- cgit v1.2.3-70-g09d2 From 90e29d12a044030c140382c038c4b01e722113e7 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Fri, 13 Mar 2009 01:16:21 -0600 Subject: Added item types to the palette class. Signed-off-by: Ira Rice --- src/gui/itempopup.cpp | 27 ++++++++++++++------------- src/gui/palette.cpp | 26 ++++++++++++++++++++------ src/gui/palette.h | 13 +++++++++++++ src/gui/setup_colors.cpp | 17 +++++++++++++++++ 4 files changed, 64 insertions(+), 19 deletions(-) (limited to 'src/gui') diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index ebbc6af3..b3002290 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -27,6 +27,7 @@ #include "gui.h" #include "itempopup.h" +#include "palette.h" #include "scrollarea.h" #include "textbox.h" @@ -166,31 +167,31 @@ gcn::Color ItemPopup::getColor(const std::string& type) gcn::Color color; if (type.compare("generic") == 0) - color = 0x21a5b1; + color = guiPalette->getColor(Palette::GENERIC); else if (type.compare("equip-head") == 0) - color = 0x527fa4; + color = guiPalette->getColor(Palette::HEAD); else if (type.compare("usable") == 0) - color = 0x268d24; + color = guiPalette->getColor(Palette::USABLE); else if (type.compare("equip-torso") == 0) - color = 0xd12aa4; + color = guiPalette->getColor(Palette::TORSO); else if (type.compare("equip-1hand") == 0) - color = 0xf42a2a; + color = guiPalette->getColor(Palette::ONEHAND); else if (type.compare("equip-legs") == 0) - color = 0x699900; + color = guiPalette->getColor(Palette::LEGS); else if (type.compare("equip-feet") == 0) - color = 0xaa1d48; + color = guiPalette->getColor(Palette::FEET); else if (type.compare("equip-2hand") == 0) - color = 0xf46d0e; + color = guiPalette->getColor(Palette::TWOHAND); else if (type.compare("equip-shield") == 0) - color = 0x9c2424; + color = guiPalette->getColor(Palette::SHIELD); else if (type.compare("equip-ring") == 0) - color = 0x0000ff; + color = guiPalette->getColor(Palette::RING); else if (type.compare("equip-arms") == 0) - color = 0x9c24e8; + color = guiPalette->getColor(Palette::ARMS); else if (type.compare("equip-ammo") == 0) - color = 0x8b6311; + color = guiPalette->getColor(Palette::AMMO); else - color = 0x000000; + color = guiPalette->getColor(Palette::UNKNOWN_ITEM); return color; } diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index a79f2050..80b5f1f1 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -101,12 +101,26 @@ Palette::Palette() : addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L'); addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<'); - addColor(BEING, 0xffffff, STATIC, _("Being"), 0); - addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0); - addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0); - addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0); - addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0); - addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0); + addColor(BEING, 0xffffff, STATIC, _("Being")); + addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names")); + addColor(SELF, 0xff8040, STATIC, indent + _("Own Name")); + addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names")); + addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs")); + addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters")); + + addColor(UNKNOWN_ITEM, 0x000000, STATIC, _("Unknown Item Type")); + addColor(GENERIC, 0x21a5b1, STATIC, indent + _("Generic")); + addColor(HEAD, 0x527fa4, STATIC, indent + _("Hat")); + addColor(USABLE, 0x268d24, STATIC, indent + _("Usable")); + addColor(TORSO, 0xd12aa4, STATIC, indent + _("Shirt")); + addColor(ONEHAND, 0xf42a2a, STATIC, indent + _("1 Handed Weapons")); + addColor(LEGS, 0x699900, STATIC, indent + _("Pants")); + addColor(FEET, 0xaa1d48, STATIC, indent + _("Shoes")); + addColor(TWOHAND, 0xf46d0e, STATIC, indent + _("2 Handed Weapons")); + addColor(SHIELD, 0x9c2424, STATIC, indent + _("Shield")); + addColor(RING, 0x0000ff, STATIC, indent + _("Ring")); + addColor(ARMS, 0x9c24e8, STATIC, indent + _("Arms")); + addColor(AMMO, 0x8b6311, STATIC, indent + _("Ammo")); addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), diff --git a/src/gui/palette.h b/src/gui/palette.h index 02489686..a91d3605 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -69,6 +69,19 @@ class Palette : public gcn::ListModel ENTRY(GM_NAME)\ ENTRY(NPC)\ ENTRY(MONSTER)\ + ENTRY(UNKNOWN_ITEM)\ + ENTRY(GENERIC)\ + ENTRY(HEAD)\ + ENTRY(USABLE)\ + ENTRY(TORSO)\ + ENTRY(ONEHAND)\ + ENTRY(LEGS)\ + ENTRY(FEET)\ + ENTRY(TWOHAND)\ + ENTRY(SHIELD)\ + ENTRY(RING)\ + ENTRY(ARMS)\ + ENTRY(AMMO)\ ENTRY(PARTICLE)\ ENTRY(EXP_INFO)\ ENTRY(PICKUP_INFO)\ diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 038b21c6..0dfaf7a6 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -225,6 +225,22 @@ void Setup_Colors::action(const gcn::ActionEvent &event) } mPreview->addRow(msg); break; + case Palette::UNKNOWN_ITEM: + case Palette::GENERIC: + case Palette::HEAD: + case Palette::USABLE: + case Palette::TORSO: + case Palette::ONEHAND: + case Palette::LEGS: + case Palette::FEET: + case Palette::TWOHAND: + case Palette::SHIELD: + case Palette::RING: + case Palette::ARMS: + case Palette::AMMO: + mTextPreview->setFont(boldFont); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); case Palette::PARTICLE: case Palette::EXP_INFO: case Palette::PICKUP_INFO: @@ -241,6 +257,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::MONSTER: mTextPreview->setFont(boldFont); mTextPreview->setTextColor(col); + case Palette::TYPE_COUNT: break; } -- cgit v1.2.3-70-g09d2 From ef30aa36a6559d3d39033b81fe23e225e258e312 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Sat, 14 Mar 2009 14:50:10 +0100 Subject: Fix cancel button in color config dialog Also save the committed gradient, not the one currently used. --- src/gui/palette.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 0298953c..e93c7744 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -127,7 +127,7 @@ Palette::~Palette() col != colEnd; ++col) { configName = &ColorTypeNames[col->type]; - config.setValue(*configName + "Gradient", col->grad); + config.setValue(*configName + "Gradient", col->comittedGrad); if (col->grad == STATIC) { config.setValue(*configName, toString(col->getRGB())); @@ -219,11 +219,12 @@ void Palette::rollback() i != iEnd; ++i) { - i->grad = i->committedGrad; - if (i->grad == STATIC) + if (i->grad != i->committedGrad) { - i->color = i->committedColor; + setGradient(i->type, i->committedGrad); } + setColor(i->type, i->committedColor.r, i->committedColor.g, + i->committedColor.b); } } -- cgit v1.2.3-70-g09d2 From 28b709ebcc804c3d4a45604abcf2b200453185b9 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 14 Mar 2009 08:16:49 -0600 Subject: Fix a spelling error in palette --- src/gui/palette.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index e93c7744..967212fe 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -127,7 +127,7 @@ Palette::~Palette() col != colEnd; ++col) { configName = &ColorTypeNames[col->type]; - config.setValue(*configName + "Gradient", col->comittedGrad); + config.setValue(*configName + "Gradient", col->committedGrad); if (col->grad == STATIC) { config.setValue(*configName, toString(col->getRGB())); -- cgit v1.2.3-70-g09d2 From 90c43c8d53c4e50f09cf3bf6bc8518e0d27b8e57 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Sat, 14 Mar 2009 14:50:10 +0100 Subject: Fix cancel button in color config dialog Also save the committed gradient, not the one currently used. --- src/gui/palette.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 80b5f1f1..162081e1 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -143,7 +143,7 @@ Palette::~Palette() colEnd = mColVector.end(); col != colEnd; ++col) { configName = &ColorTypeNames[col->type]; - config.setValue(*configName + "Gradient", col->grad); + config.setValue(*configName + "Gradient", col->comittedGrad); if (col->grad == STATIC) { config.setValue(*configName, toString(col->getRGB())); @@ -235,11 +235,12 @@ void Palette::rollback() i != iEnd; ++i) { - i->grad = i->committedGrad; - if (i->grad == STATIC) + if (i->grad != i->committedGrad) { - i->color = i->committedColor; + setGradient(i->type, i->committedGrad); } + setColor(i->type, i->committedColor.r, i->committedColor.g, + i->committedColor.b); } } -- cgit v1.2.3-70-g09d2 From a1b399ad3956b03ce26416abd906f22e3c3d2d82 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Sat, 14 Mar 2009 08:16:49 -0600 Subject: Fix a spelling error in palette --- src/gui/palette.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 162081e1..8cc9c57b 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -143,7 +143,7 @@ Palette::~Palette() colEnd = mColVector.end(); col != colEnd; ++col) { configName = &ColorTypeNames[col->type]; - config.setValue(*configName + "Gradient", col->comittedGrad); + config.setValue(*configName + "Gradient", col->committedGrad); if (col->grad == STATIC) { config.setValue(*configName, toString(col->getRGB())); -- cgit v1.2.3-70-g09d2 From 102fce1d3948277c882a0a3043b2d7423a4b4af9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Sat, 14 Mar 2009 15:47:31 +0100 Subject: Code cleanup in the color/palette code --- src/gui/palette.cpp | 34 ++++++++++++++++------------------ src/gui/setup_colors.cpp | 25 ------------------------- src/gui/setup_colors.h | 1 - 3 files changed, 16 insertions(+), 44 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 967212fe..bb2245ce 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -79,8 +79,8 @@ Palette::Palette() : mColVector(ColVector(TYPE_COUNT)), mGradVector(), { std::string indent = " "; addColor(TEXT, 0x000000, STATIC, _("Text")); - addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0); - addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0); + addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); + addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); @@ -98,24 +98,22 @@ Palette::Palette() : mColVector(ColVector(TYPE_COUNT)), mGradVector(), addColor(LOGGER, 0x919191, STATIC, indent + _("Logger"), 'L'); addColor(HYPERLINK, 0xe50d0d, STATIC, indent + _("Hyperlink"), '<'); - addColor(BEING, 0xffffff, STATIC, _("Being"), 0); - addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names"), 0); - addColor(SELF, 0xff8040, STATIC, indent + _("Own Name"), 0); - addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names"), 0); - addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs"), 0); - addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters"), 0); - - addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); - addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), - 0); - addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0); + addColor(BEING, 0xffffff, STATIC, _("Being")); + addColor(PC, 0xffffff, STATIC, indent + _("Other Player's Names")); + addColor(SELF, 0xff8040, STATIC, indent + _("Own Name")); + addColor(GM_NAME, 0x00ff00, STATIC, indent + _("GM Names")); + addColor(NPC, 0xc8c8ff, STATIC, indent + _("NPCs")); + addColor(MONSTER, 0xff4040, STATIC, indent + _("Monsters")); + + addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects")); + addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification")); + addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification")); addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, - indent + _("Player hits Monster"), 0); + indent + _("Player hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, - indent + _("Monster hits Player"), 0); - addColor(HIT_CRITICAL, 0xff0000, RAINBOW, - indent + _("Critical Hit"), 0); - addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0); + indent + _("Monster hits Player")); + addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit")); + addColor(MISS, 0xffff00, STATIC, indent + _("Misses")); commit(true); } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 7990e217..b786a7fa 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -155,7 +155,6 @@ Setup_Colors::Setup_Colors() : Setup_Colors::~Setup_Colors() { - //delete mPreview; if (mPreviewBox->getContent() == mPreview) { delete mTextPreview; @@ -164,27 +163,6 @@ Setup_Colors::~Setup_Colors() { delete mPreview; } - // delete mTextPreview; -// delete mPreviewBox; - -/* delete mGradTypeLabel; - delete mGradTypeSlider; - delete mGradTypeText; - - delete mRedLabel; - delete mRedSlider; - delete mRedText; - - delete mGreenLabel; - delete mGreenSlider; - delete mGreenText; - - delete mBlueLabel; - delete mBlueSlider; - delete mBlueText; - - delete mColorBox; - delete mScroll;*/ } void Setup_Colors::action(const gcn::ActionEvent &event) @@ -237,8 +215,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HYPERLINK: mPreviewBox->setContent(mPreview); mPreview->clearRows(); - //char ch = guiPalette->getColorCharAt(mSelected); - //std::string msg; if (ch == '<') { @@ -248,7 +224,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) { msg = "##" + toString(ch) + rawmsg; } - //std::cout << msg << std::endl; mPreview->addRow(msg); break; case Palette::PARTICLE: diff --git a/src/gui/setup_colors.h b/src/gui/setup_colors.h index 842fd6cc..52d3f727 100644 --- a/src/gui/setup_colors.h +++ b/src/gui/setup_colors.h @@ -62,7 +62,6 @@ class Setup_Colors : public SetupTab, public gcn::ActionListener, gcn::Label *mGradTypeLabel; gcn::Slider *mGradTypeSlider; gcn::Label *mGradTypeText; -// Palette::GradientType mGradType; gcn::Label *mRedLabel; gcn::Slider *mRedSlider; -- cgit v1.2.3-70-g09d2 From 698e166377fa4e7e4e4a971af33458c68bd70809 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 09:33:48 -0600 Subject: Commented up item popups, speech bubbles, as well as only update item info on item change. Also fixed color updating for item shortcuts and item links, as the displayed colors wouldn't update on change on color change in the setup color dialog. Signed-off-by: Ira Rice --- src/gui/itemcontainer.cpp | 9 ++++++--- src/gui/itemlinkhandler.cpp | 9 ++++++++- src/gui/itempopup.cpp | 17 +++++++++++++++-- src/gui/itempopup.h | 29 +++++++++++++++++++++++++++++ src/gui/itemshortcutcontainer.cpp | 6 ++++-- src/gui/speechbubble.cpp | 1 - src/gui/speechbubble.h | 18 ++++++++++++++++++ 7 files changed, 80 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/itemcontainer.cpp b/src/gui/itemcontainer.cpp index 54f1f647..8139e85e 100644 --- a/src/gui/itemcontainer.cpp +++ b/src/gui/itemcontainer.cpp @@ -25,6 +25,7 @@ #include "itemcontainer.h" #include "itempopup.h" +#include "palette.h" #include "viewport.h" #include "../graphics.h" @@ -51,6 +52,7 @@ ItemContainer::ItemContainer(Inventory *inventory, int offset): mOffset(offset) { mItemPopup = new ItemPopup(); + mItemPopup->setOpaque(false); ResourceManager *resman = ResourceManager::getInstance(); @@ -123,7 +125,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) // Draw item caption graphics->setFont(getFont()); - graphics->setColor(0x000000); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText( (item->isEquipped() ? "Eq." : toString(item->getQuantity())), itemX + gridWidth / 2, itemY + gridHeight - 11, @@ -255,8 +257,9 @@ void ItemContainer::mouseMoved(gcn::MouseEvent &event) if (item) { - mItemPopup->setItem(item->getInfo()); - mItemPopup->setOpaque(false); + if (item->getInfo().getName() != mItemPopup->getItemName()) + mItemPopup->setItem(item->getInfo()); + mItemPopup->updateColors(); mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else diff --git a/src/gui/itemlinkhandler.cpp b/src/gui/itemlinkhandler.cpp index 06263ce2..e9993c2d 100644 --- a/src/gui/itemlinkhandler.cpp +++ b/src/gui/itemlinkhandler.cpp @@ -33,6 +33,7 @@ ItemLinkHandler::ItemLinkHandler() { mItemPopup = new ItemPopup; + mItemPopup->setOpaque(false); } ItemLinkHandler::~ItemLinkHandler() @@ -50,11 +51,17 @@ void ItemLinkHandler::handleLink(const std::string &link) { const ItemInfo &iteminfo = ItemDB::get(id); - mItemPopup->setItem(iteminfo); + if (iteminfo.getName() != mItemPopup->getItemName()) + mItemPopup->setItem(iteminfo); if (mItemPopup->isVisible()) + { mItemPopup->setVisible(false); + } else + { + mItemPopup->updateColors(); mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); + } } } diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index b3002290..c76c3750 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -41,8 +41,10 @@ ItemPopup::ItemPopup(): Popup() { + mItemType = ""; + // Item Name - mItemName = new gcn::Label("Label"); + mItemName = new gcn::Label(""); mItemName->setFont(boldFont); mItemName->setPosition(2, 2); @@ -104,12 +106,12 @@ void ItemPopup::setItem(const ItemInfo &item) return; mItemName->setCaption(item.getName()); - mItemName->setForegroundColor(getColor(item.getType())); mItemName->setWidth(boldFont->getWidth(item.getName())); mItemDesc->setTextWrapped(item.getDescription(), 196); mItemEffect->setTextWrapped(item.getEffect(), 196); mItemWeight->setTextWrapped(_("Weight: ") + toString(item.getWeight()) + _(" grams"), 196); + mItemType = item.getType(); int minWidth = mItemName->getWidth(); @@ -162,6 +164,12 @@ void ItemPopup::setItem(const ItemInfo &item) (2 * getFont()->getHeight())); } +void ItemPopup::updateColors() +{ + mItemName->setForegroundColor(getColor(mItemType)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); +} + gcn::Color ItemPopup::getColor(const std::string& type) { gcn::Color color; @@ -196,6 +204,11 @@ gcn::Color ItemPopup::getColor(const std::string& type) return color; } +std::string ItemPopup::getItemName() +{ + return mItemName->getCaption(); +} + unsigned int ItemPopup::getNumRows() { return mItemDesc->getNumberOfRows() + mItemEffect->getNumberOfRows() + diff --git a/src/gui/itempopup.h b/src/gui/itempopup.h index 97da4cbb..29fd127a 100644 --- a/src/gui/itempopup.h +++ b/src/gui/itempopup.h @@ -33,11 +33,39 @@ class TextBox; class ItemPopup : public Popup { public: + /** + * Constructor. Initializes the item popup. + */ ItemPopup(); + + /** + * Destructor. Cleans up the item popup on deletion. + */ ~ItemPopup(); + /** + * Sets the info to be displayed given a particular item. + */ void setItem(const ItemInfo &item); + + /** + * Gets the number of rows that the item popup currently has. + */ unsigned int getNumRows(); + + /** + * Gets the name of the currently stored item in this popup. + */ + std::string getItemName(); + + /** + * Updates the colors used within the item popup. + */ + void updateColors(); + + /** + * Sets the location to display the item popup. + */ void view(int x, int y); private: @@ -45,6 +73,7 @@ class ItemPopup : public Popup TextBox *mItemDesc; TextBox *mItemEffect; TextBox *mItemWeight; + std::string mItemType; ScrollArea *mItemDescScroll; ScrollArea *mItemEffectScroll; ScrollArea *mItemWeightScroll; diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index c1baca76..cbbbaf60 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -47,6 +47,7 @@ ItemShortcutContainer::ItemShortcutContainer(): addWidgetListener(this); mItemPopup = new ItemPopup(); + mItemPopup->setOpaque(false); ResourceManager *resman = ResourceManager::getInstance(); @@ -233,8 +234,9 @@ void ItemShortcutContainer::mouseMoved(gcn::MouseEvent &event) if (item) { - mItemPopup->setItem(item->getInfo()); - mItemPopup->setOpaque(false); + if (item->getInfo().getName() != mItemPopup->getItemName()) + mItemPopup->setItem(item->getInfo()); + mItemPopup->updateColors(); mItemPopup->view(viewport->getMouseX(), viewport->getMouseY()); } else diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 944bae42..811fddfa 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -25,7 +25,6 @@ #include #include "gui.h" -#include "palette.h" #include "scrollarea.h" #include "speechbubble.h" #include "textbox.h" diff --git a/src/gui/speechbubble.h b/src/gui/speechbubble.h index d356dac1..9eb400fb 100644 --- a/src/gui/speechbubble.h +++ b/src/gui/speechbubble.h @@ -32,13 +32,31 @@ class TextBox; class SpeechBubble : public Popup { public: + /** + * Constructor. Initializes the speech bubble. + */ SpeechBubble(); + /** + * Sets the name displayed for the speech bubble, and in what color. + */ void setCaption(const std::string &name, const gcn::Color *color = &guiPalette->getColor(Palette::TEXT)); + + /** + * Sets the text to be displayed. + */ void setText(std::string text, bool showName = true); + + /** + * Sets the location in which the speech bubble will be displayed. + */ void setLocation(int x, int y); + + /** + * Gets the number of rows the speech bubble has. + */ unsigned int getNumRows(); private: -- cgit v1.2.3-70-g09d2 From 998a63d41fcb9cc7b9ac04ed20ca02f4f83775c9 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Sat, 14 Mar 2009 15:47:31 +0100 Subject: Code cleanup in the color/palette code --- src/gui/palette.cpp | 20 +++++++++----------- src/gui/setup_colors.cpp | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 8cc9c57b..e007dd5c 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -82,8 +82,8 @@ Palette::Palette() : { std::string indent = " "; addColor(TEXT, 0x000000, STATIC, _("Text")); - addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow"), 0); - addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline"), 0); + addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); + addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); @@ -122,17 +122,15 @@ Palette::Palette() : addColor(ARMS, 0x9c24e8, STATIC, indent + _("Arms")); addColor(AMMO, 0x8b6311, STATIC, indent + _("Ammo")); - addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects"), 0); - addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification"), - 0); - addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification"),0); + addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects")); + addColor(PICKUP_INFO, 0x28dc28, STATIC, indent + _("Pickup Notification")); + addColor(EXP_INFO, 0xffff00, STATIC, indent + _("Exp Notification")); addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, - indent + _("Player hits Monster"), 0); + indent + _("Player hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, - indent + _("Monster hits Player"), 0); - addColor(HIT_CRITICAL, 0xff0000, RAINBOW, - indent + _("Critical Hit"), 0); - addColor(MISS, 0xffff00, STATIC, indent + _("Misses"), 0); + indent + _("Monster hits Player")); + addColor(HIT_CRITICAL, 0xff0000, RAINBOW, indent + _("Critical Hit")); + addColor(MISS, 0xffff00, STATIC, indent + _("Misses")); commit(true); } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 0dfaf7a6..91b20f5f 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -198,7 +198,6 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: mTextPreview->setTextBGColor(col); - //mTextPreview->setOpaque(true); mTextPreview->setOutline(false); mTextPreview->setShadow(false); mPreview->addRow(rawmsg); -- cgit v1.2.3-70-g09d2 From f754da1e3a3a4d2c377cb8d1b61899783dff5736 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 09:47:20 -0600 Subject: Got rid of two direct references to the color black. These now always pull from the stored text color. This should help in situations in which the user has their own custom skin in the future, and needs to adjust text colors to be more friendly to a darker skin. Signed-off-by: Ira Rice --- src/gui/emoteshortcutcontainer.cpp | 3 ++- src/gui/itemshortcutcontainer.cpp | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/emoteshortcutcontainer.cpp b/src/gui/emoteshortcutcontainer.cpp index 8c9df14e..47fb9b06 100644 --- a/src/gui/emoteshortcutcontainer.cpp +++ b/src/gui/emoteshortcutcontainer.cpp @@ -21,6 +21,7 @@ */ #include "emoteshortcutcontainer.h" +#include "palette.h" #include "../animatedsprite.h" #include "../configuration.h" @@ -99,7 +100,7 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) // Draw emote keyboard shortcut. const char *key = SDL_GetKeyName( (SDLKey) keyboard.getKeyValue(keyboard.KEY_EMOTE_1 + i)); - graphics->setColor(0x000000); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); if (emoteShortcut->getEmote(i)) diff --git a/src/gui/itemshortcutcontainer.cpp b/src/gui/itemshortcutcontainer.cpp index cbbbaf60..a0697c5d 100644 --- a/src/gui/itemshortcutcontainer.cpp +++ b/src/gui/itemshortcutcontainer.cpp @@ -23,6 +23,7 @@ #include "inventorywindow.h" #include "itemshortcutcontainer.h" #include "itempopup.h" +#include "palette.h" #include "viewport.h" #include "../configuration.h" @@ -91,7 +92,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. const char *key = SDL_GetKeyName( (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i)); - graphics->setColor(0x000000); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); if (itemShortcut->getItem(i) < 0) -- cgit v1.2.3-70-g09d2 From f0c6bed3d879e1c7b9a6d5b7e676a4f1c6a29a54 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 09:52:31 -0600 Subject: Fixed sliders to initialize their alpha values on loading, instead of only using alpha values after the first change. Signed-off-by: Ira Rice --- src/gui/slider.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/gui') diff --git a/src/gui/slider.cpp b/src/gui/slider.cpp index db34cc6a..a2df59a4 100644 --- a/src/gui/slider.cpp +++ b/src/gui/slider.cpp @@ -96,6 +96,16 @@ void Slider::init() vGrip = slider->getSubImage(x, y, w, h); slider->decRef(); + + hStart->setAlpha(mAlpha); + hMid->setAlpha(mAlpha); + hEnd->setAlpha(mAlpha); + hGrip->setAlpha(mAlpha); + + vStart->setAlpha(mAlpha); + vMid->setAlpha(mAlpha); + vEnd->setAlpha(mAlpha); + vGrip->setAlpha(mAlpha); } mInstances++; -- cgit v1.2.3-70-g09d2 From 3575c7a606c2d24c0d444e9999892c0390fa5ae8 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 13:21:35 -0600 Subject: Made a label class derived from the guichan label class which utilizes the palette colors. While technically, this can be accomplished through other means, it's rather clumsy overall, and is prone to introducing in programmer errors. This commit finally catches every case where text is used, and applies the text color from the color dialog to each of them appropriately. Signed-off-by: Ira Rice --- aethyra.cbp | 2 ++ src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/gui/button.cpp | 3 +- src/gui/buy.cpp | 11 +++---- src/gui/char_select.cpp | 17 +++++----- src/gui/checkbox.cpp | 13 ++++++++ src/gui/checkbox.h | 5 +++ src/gui/connection.cpp | 5 ++- src/gui/debugwindow.cpp | 15 +++++---- src/gui/inventorywindow.cpp | 7 ++--- src/gui/login.cpp | 13 ++++---- src/gui/palette.cpp | 1 + src/gui/palette.h | 1 + src/gui/register.cpp | 19 +++++------ src/gui/sell.cpp | 11 +++---- src/gui/setup_audio.cpp | 10 +++--- src/gui/setup_colors.cpp | 18 +++++++---- src/gui/setup_joystick.cpp | 5 ++- src/gui/setup_players.cpp | 9 +++--- src/gui/setup_video.cpp | 23 +++++++------- src/gui/skill.cpp | 11 +++---- src/gui/status.cpp | 77 +++++++++++++++++---------------------------- src/gui/storagewindow.cpp | 5 ++- src/gui/textfield.cpp | 29 +++++++---------- src/gui/trade.cpp | 9 +++--- src/gui/updatewindow.cpp | 6 ++-- src/gui/widgets/tab.cpp | 10 ++++-- src/gui/window.cpp | 3 +- src/main.cpp | 7 ++--- 30 files changed, 173 insertions(+), 176 deletions(-) (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index e88f491d..6e71375c 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -168,6 +168,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7025c2c4..93bac9ae 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,6 +117,8 @@ SET(SRCS gui/itemshortcutcontainer.h\ gui/item_amount.cpp gui/item_amount.h + gui/label.cpp + gui/label.h gui/linkhandler.h gui/listbox.cpp gui/listbox.h diff --git a/src/Makefile.am b/src/Makefile.am index 069b12f2..5029697a 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,6 +69,8 @@ aethyra_SOURCES = gui/widgets/dropdown.cpp \ gui/itemshortcutcontainer.h \ gui/item_amount.cpp \ gui/item_amount.h \ + gui/label.cpp \ + gui/label.h \ gui/linkhandler.h \ gui/listbox.cpp \ gui/listbox.h \ diff --git a/src/gui/button.cpp b/src/gui/button.cpp index dbb5f568..592edce5 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -24,6 +24,7 @@ #include #include "button.h" +#include "palette.h" #include "../configuration.h" #include "../graphics.h" @@ -151,7 +152,7 @@ void Button::draw(gcn::Graphics *graphics) static_cast(graphics)-> drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); - graphics->setColor(getForegroundColor()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); int textX; int textY = getHeight() / 2 - getFont()->getHeight() / 2; diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 2b5aeeb7..367a041e 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" #include "buy.h" +#include "label.h" #include "scrollarea.h" #include "shop.h" #include "shoplistbox.h" @@ -54,14 +53,14 @@ BuyDialog::BuyDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); - mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label(strprintf(_("Price: %d GP / Total: %d GP"), 0, 0)); + mQuantityLabel = new Label("0"); + mMoneyLabel = new 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(strprintf(_("Description: %s"), "")); - mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), "")); + mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); + mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index fa0594d6..f88736c1 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -24,11 +24,10 @@ #include -#include - #include "button.h" #include "char_select.h" #include "confirm_dialog.h" +#include "label.h" #include "ok_dialog.h" #include "playerbox.h" #include "textfield.h" @@ -90,10 +89,10 @@ CharSelectDialog::CharSelectDialog(Network *network, mPlayerBox = new PlayerBox; mPlayerBox->setWidth(74); - 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)); + mNameLabel = new Label(strprintf(_("Name: %s"), "")); + mLevelLabel = new Label(strprintf(_("Level: %d"), 0)); + mJobLevelLabel = new Label(strprintf(_("Job Level: %d"), 0)); + mMoneyLabel = new Label(strprintf(_("Money: %d"), 0)); const std::string tempString = getFont()->getWidth(_("New")) < getFont()->getWidth(_("Delete")) ? @@ -259,13 +258,13 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, mPlayer->setHairStyle(rand() % mPlayer->getNumOfHairstyles(), rand() % numberOfHairColors); mNameField = new TextField(""); - mNameLabel = new gcn::Label(_("Name:")); + mNameLabel = new Label(_("Name:")); mNextHairColorButton = new Button(">", "nextcolor", this); mPrevHairColorButton = new Button("<", "prevcolor", this); - mHairColorLabel = new gcn::Label(_("Hair Color:")); + mHairColorLabel = new Label(_("Hair Color:")); mNextHairStyleButton = new Button(">", "nextstyle", this); mPrevHairStyleButton = new Button("<", "prevstyle", this); - mHairStyleLabel = new gcn::Label(_("Hair Style:")); + mHairStyleLabel = new Label(_("Hair Style:")); mCreateButton = new Button(_("Create"), "create", this); mCancelButton = new Button(_("Cancel"), "cancel", this); mPlayerBox = new PlayerBox(mPlayer); diff --git a/src/gui/checkbox.cpp b/src/gui/checkbox.cpp index 413c28d0..f6cce581 100644 --- a/src/gui/checkbox.cpp +++ b/src/gui/checkbox.cpp @@ -21,6 +21,7 @@ */ #include "checkbox.h" +#include "palette.h" #include "../configuration.h" #include "../graphics.h" @@ -69,6 +70,18 @@ CheckBox::~CheckBox() } } +void CheckBox::draw(gcn::Graphics* graphics) +{ + drawBox(graphics); + + graphics->setFont(getFont()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); + + const int h = getHeight() + getHeight() / 2; + + graphics->drawText(getCaption(), h - 2, 0); +} + void CheckBox::drawBox(gcn::Graphics* graphics) { Image *box; diff --git a/src/gui/checkbox.h b/src/gui/checkbox.h index 260ed3a1..93b62b9d 100644 --- a/src/gui/checkbox.h +++ b/src/gui/checkbox.h @@ -45,6 +45,11 @@ class CheckBox : public gcn::CheckBox */ ~CheckBox(); + /** + * Draws the caption, then calls drawBox to draw the check box. + */ + void draw(gcn::Graphics* graphics); + /** * Draws the check box, not the caption. */ diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index f6033cd7..d4a2b18a 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -22,10 +22,9 @@ #include -#include - #include "button.h" #include "connection.h" +#include "label.h" #include "progressbar.h" #include "../main.h" @@ -47,7 +46,7 @@ ConnectionDialog::ConnectionDialog(): 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 Label(_("Connecting...")); cancelButton->setPosition(5, 100 - 5 - cancelButton->getHeight()); mProgressBar->setPosition(5, cancelButton->getY() - 25); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 71855977..999e00a2 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "debugwindow.h" +#include "label.h" #include "viewport.h" #include "widgets/layout.h" @@ -43,12 +42,12 @@ DebugWindow::DebugWindow(): setCloseButton(true); setDefaultSize(400, 60, ImageRect::CENTER); - mFPSLabel = new gcn::Label("0 FPS"); - mMusicFileLabel = new gcn::Label("Music: "); - mMapLabel = new gcn::Label("Map: "); - mMiniMapLabel = new gcn::Label("Mini-Map: "); - mTileMouseLabel = new gcn::Label("Mouse: 0, 0"); - mParticleCountLabel = new gcn::Label("Particle count: 0"); + mFPSLabel = new Label("0 FPS"); + mMusicFileLabel = new Label("Music: "); + mMapLabel = new Label("Map: "); + mMiniMapLabel = new Label("Mini-Map: "); + mTileMouseLabel = new Label("Mouse: 0, 0"); + mParticleCountLabel = new Label("Particle count: 0"); place(0, 0, mFPSLabel, 3); place(3, 0, mTileMouseLabel); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 7e75411e..98916c07 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -25,12 +25,11 @@ #include #include -#include - #include "button.h" #include "inventorywindow.h" #include "item_amount.h" #include "itemcontainer.h" +#include "label.h" #include "progressbar.h" #include "scrollarea.h" #include "viewport.h" @@ -82,8 +81,8 @@ InventoryWindow::InventoryWindow(int invSize): mMaxWeight = toString(player_node->mMaxWeight); mUsedSlots = toString(player_node->getInventory()->getNumberOfSlotsUsed()); - mSlotsLabel = new gcn::Label(_("Slots: ")); - mWeightLabel = new gcn::Label(_("Weight: ")); + mSlotsLabel = new Label(_("Slots: ")); + mWeightLabel = new Label(_("Weight: ")); mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); mWeightBar = new ProgressBar(1.0f, 100, 20, 0, 0, 255); diff --git a/src/gui/login.cpp b/src/gui/login.cpp index ce13aaf0..7b9829fb 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" #include "checkbox.h" +#include "label.h" #include "listbox.h" #include "login.h" #include "ok_dialog.h" @@ -49,11 +48,11 @@ static const int FIELD_WIDTH = LOGIN_DIALOG_WIDTH - 70; LoginDialog::LoginDialog(LoginData *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 *portLabel = new gcn::Label(_("Port:")); - gcn::Label *dropdownLabel = new gcn::Label(_("Recent:")); + gcn::Label *userLabel = new Label(_("Name:")); + gcn::Label *passLabel = new Label(_("Password:")); + gcn::Label *serverLabel = new Label(_("Server:")); + gcn::Label *portLabel = new Label(_("Port:")); + gcn::Label *dropdownLabel = new Label(_("Recent:")); std::vector dfltServer; dfltServer.push_back("www.aethyra.org"); dfltServer.push_back("www.aethyra.org"); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index e007dd5c..c155cfe2 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -88,6 +88,7 @@ Palette::Palette() : addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); + addColor(TAB_HIGHLIGHT, 0xff0000, STATIC, indent + _("Tab Highlight")); addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item too expensive")); diff --git a/src/gui/palette.h b/src/gui/palette.h index a91d3605..4d8f7f11 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -53,6 +53,7 @@ class Palette : public gcn::ListModel ENTRY(OUTLINE)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ + ENTRY(TAB_HIGHLIGHT)\ ENTRY(SHOP_WARNING)\ ENTRY(CHAT)\ ENTRY(GM)\ diff --git a/src/gui/register.cpp b/src/gui/register.cpp index 13928e41..63a0d29c 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -20,8 +20,6 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "../configuration.h" #include "../log.h" #include "../logindata.h" @@ -29,6 +27,7 @@ #include "button.h" #include "checkbox.h" +#include "label.h" #include "login.h" #include "ok_dialog.h" #include "passwordfield.h" @@ -47,7 +46,8 @@ * to the field which contained wrong data when the Ok button was pressed on * the error notice. */ -class WrongDataNoticeListener : public gcn::ActionListener { +class WrongDataNoticeListener : public gcn::ActionListener +{ public: void setTarget(gcn::TextField *textField); void action(const gcn::ActionEvent &event); @@ -63,22 +63,19 @@ void WrongDataNoticeListener::setTarget(gcn::TextField *textField) void WrongDataNoticeListener::action(const gcn::ActionEvent &event) { if (event.getId() == "ok") - { mTarget->requestFocus(); - } } - RegisterDialog::RegisterDialog(LoginData *loginData): Window(_("Register")), 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 *portLabel = new gcn::Label(_("Port:")); + gcn::Label *userLabel = new Label(_("Name:")); + gcn::Label *passwordLabel = new Label(_("Password:")); + gcn::Label *confirmLabel = new Label(_("Confirm:")); + gcn::Label *serverLabel = new Label(_("Server:")); + gcn::Label *portLabel = new Label(_("Port:")); mUserField = new TextField(loginData->username); mPasswordField = new PasswordField(loginData->password); mConfirmField = new PasswordField; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 397e29a6..b780b02b 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" +#include "label.h" #include "scrollarea.h" #include "sell.h" #include "shop.h" @@ -56,15 +55,15 @@ SellDialog::SellDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); mSlider = new Slider(1.0); - mQuantityLabel = new gcn::Label("0"); - mMoneyLabel = new gcn::Label( + mQuantityLabel = new Label("0"); + mMoneyLabel = new 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(strprintf(_("Description: %s"), "")); - mItemEffectLabel = new gcn::Label(strprintf(_("Effect: %s"), "")); + mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); + mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); mIncreaseButton->setSize(20, 20); mDecreaseButton->setSize(20, 20); diff --git a/src/gui/setup_audio.cpp b/src/gui/setup_audio.cpp index 3c26f14b..08eda848 100644 --- a/src/gui/setup_audio.cpp +++ b/src/gui/setup_audio.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "checkbox.h" +#include "label.h" #include "ok_dialog.h" #include "setup_audio.h" #include "slider.h" @@ -45,8 +44,8 @@ Setup_Audio::Setup_Audio(): { setOpaque(false); - gcn::Label *sfxLabel = new gcn::Label(_("Sfx volume")); - gcn::Label *musicLabel = new gcn::Label(_("Music volume")); + gcn::Label *sfxLabel = new Label(_("Sfx volume")); + gcn::Label *musicLabel = new Label(_("Music volume")); mSfxSlider->setActionEventId("sfx"); mMusicSlider->setActionEventId("music"); @@ -80,7 +79,8 @@ void Setup_Audio::apply() if (mSoundCheckBox->isSelected()) { config.setValue("sound", 1); - try { + try + { sound.init(); } catch (const char *err) diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 91b20f5f..09c6a3a9 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -23,12 +23,12 @@ #include #include -#include #include #include "browserbox.h" #include "gui.h" #include "itemlinkhandler.h" +#include "label.h" #include "listbox.h" #include "palette.h" #include "scrollarea.h" @@ -71,7 +71,7 @@ Setup_Colors::Setup_Colors() : mPreviewBox->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, gcn::ScrollArea::SHOW_NEVER); - mGradTypeLabel = new gcn::Label(_("Type: ")); + mGradTypeLabel = new Label(_("Type: ")); mGradTypeSlider = new Slider(0, 2); mGradTypeSlider->setWidth(160); @@ -80,9 +80,9 @@ Setup_Colors::Setup_Colors() : mGradTypeSlider->addActionListener(this); mGradTypeSlider->setEnabled(false); - mGradTypeText = new gcn::Label(); + mGradTypeText = new Label(); - mRedLabel = new gcn::Label(_("Red: ")); + mRedLabel = new Label(_("Red: ")); mRedText = new TextField(); mRedText->setWidth(40); @@ -98,7 +98,7 @@ Setup_Colors::Setup_Colors() : mRedSlider->addActionListener(this); mRedSlider->setEnabled(false); - mGreenLabel = new gcn::Label(_("Green: ")); + mGreenLabel = new Label(_("Green: ")); mGreenText = new TextField(); mGreenText->setWidth(40); @@ -114,7 +114,7 @@ Setup_Colors::Setup_Colors() : mGreenSlider->addActionListener(this); mGreenSlider->setEnabled(false); - mBlueLabel = new gcn::Label(_("Blue: ")); + mBlueLabel = new Label(_("Blue: ")); mBlueText = new TextField(); mBlueText->setWidth(40); @@ -194,6 +194,12 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setShadow(type == Palette::SHADOW); mTextPreview->setOutline(type == Palette::OUTLINE); break; + case Palette::TAB_HIGHLIGHT: + mTextPreview->setFont(gui->getFont()); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; case Palette::BACKGROUND: case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: diff --git a/src/gui/setup_joystick.cpp b/src/gui/setup_joystick.cpp index 5bbaa368..4d80e0dd 100644 --- a/src/gui/setup_joystick.cpp +++ b/src/gui/setup_joystick.cpp @@ -20,10 +20,9 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" #include "checkbox.h" +#include "label.h" #include "setup_joystick.h" #include "widgets/layouthelper.h" @@ -36,7 +35,7 @@ extern Joystick *joystick; Setup_Joystick::Setup_Joystick(): - mCalibrateLabel(new gcn::Label(_("Press the button to start calibration"))), + mCalibrateLabel(new Label(_("Press the button to start calibration"))), mCalibrateButton(new Button(_("Calibrate"), "calibrate", this)), mJoystickEnabled(new CheckBox(_("Enable joystick"))) { diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index faf80640..05748000 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -23,10 +23,9 @@ #include #include -#include - #include "button.h" #include "checkbox.h" +#include "label.h" #include "listbox.h" #include "ok_dialog.h" #include "scrollarea.h" @@ -138,7 +137,7 @@ public: for (unsigned int r = 0; r < player_names->size(); ++r) { std::string name = (*player_names)[r]; - gcn::Widget *widget = new gcn::Label(name); + gcn::Widget *widget = new Label(name); mWidgets.push_back(widget); gcn::ListModel *playerRelation = new PlayerRelationListModel(); @@ -248,7 +247,7 @@ Setup_Players::Setup_Players(): for (int i = 0; i < COLUMNS_NR; i++) { mPlayerTableTitleModel->set(0, i, - new gcn::Label(gettext(table_titles[i]))); + new Label(gettext(table_titles[i]))); } mPlayerTitleTable->setLinewiseSelection(true); @@ -258,7 +257,7 @@ Setup_Players::Setup_Players(): mPlayerTable->setLinewiseSelection(true); mPlayerTable->addActionListener(this); - gcn::Label *ignore_action_label = new gcn::Label(_("When ignoring:")); + gcn::Label *ignore_action_label = new Label(_("When ignoring:")); mIgnoreActionChoicesBox->setActionEventId(ACTION_STRATEGY); mIgnoreActionChoicesBox->addActionListener(this); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 59eb4096..d1d7e4f8 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -27,9 +27,8 @@ #include #include -#include - #include "checkbox.h" +#include "label.h" #include "listbox.h" #include "ok_dialog.h" #include "scrollarea.h" @@ -123,7 +122,7 @@ Setup_Video::Setup_Video(): mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), mParticleEffectsEnabled)), mNameCheckBox(new CheckBox(_("Show name"), mNameEnabled)), mSpeechSlider(new Slider(0, 3)), - mSpeechLabel(new gcn::Label("")), + mSpeechLabel(new Label("")), mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox(_("FPS Limit:"))), mFpsSlider(new Slider(10, 200)), @@ -136,11 +135,11 @@ Setup_Video::Setup_Video(): mScrollRadiusField(new TextField), mOverlayDetail((int) config.getValue("OverlayDetail", 2)), mOverlayDetailSlider(new Slider(0, 2)), - mOverlayDetailField(new gcn::Label("")), + mOverlayDetailField(new Label("")), mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), - mParticleDetailField(new gcn::Label("")), - mPickupNotifyLabel(new gcn::Label(_("Show pickup notification"))), + mParticleDetailField(new Label("")), + mPickupNotifyLabel(new Label(_("Show pickup notification"))), mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), mPickupParticleCheckBox(new CheckBox(_("as particle"), mPickupParticleEnabled)) @@ -150,12 +149,12 @@ Setup_Video::Setup_Video(): ScrollArea *scrollArea = new ScrollArea(mModeList); scrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); - speechLabel = new gcn::Label(_("Overhead text")); - alphaLabel = new gcn::Label(_("Gui opacity")); - scrollRadiusLabel = new gcn::Label(_("Scroll radius")); - scrollLazinessLabel = new gcn::Label(_("Scroll laziness")); - overlayDetailLabel = new gcn::Label(_("Ambient FX")); - particleDetailLabel = new gcn::Label(_("Particle Detail")); + speechLabel = new Label(_("Overhead text")); + alphaLabel = new Label(_("Gui opacity")); + scrollRadiusLabel = new Label(_("Scroll radius")); + scrollLazinessLabel = new Label(_("Scroll laziness")); + overlayDetailLabel = new Label(_("Ambient FX")); + particleDetailLabel = new Label(_("Particle Detail")); mModeList->setEnabled(true); #ifndef USE_OPENGL diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index a8250fce..64214ff5 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" +#include "label.h" #include "listbox.h" #include "scrollarea.h" #include "skill.h" @@ -100,13 +99,13 @@ public: info = &fakeSkillInfo; sprintf(tmp, "%c%s", info->modifiable? ' ' : '*', info->name.c_str()); - gcn::Label *name_label = new gcn::Label(tmp); + gcn::Label *name_label = new Label(tmp); sprintf(tmp, "Lv:%i", skill->lv); - gcn::Label *lv_label = new gcn::Label(tmp); + gcn::Label *lv_label = new Label(tmp); sprintf(tmp, "Sp:%i", skill->sp); - gcn::Label *sp_label = new gcn::Label(tmp); + gcn::Label *sp_label = new Label(tmp); set(i, 0, name_label); set(i, 1, lv_label); @@ -141,7 +140,7 @@ SkillDialog::SkillDialog(): setMinWidth(200); ScrollArea *skillScrollArea = new ScrollArea(mTable); - mPointsLabel = new gcn::Label(strprintf(_("Skill points: %d"), 0)); + mPointsLabel = new Label(strprintf(_("Skill points: %d"), 0)); mIncButton = new Button(_("Up"), _("inc"), this); mUseButton = new Button(_("Use"), _("use"), this); mUseButton->setEnabled(false); diff --git a/src/gui/status.cpp b/src/gui/status.cpp index e534edb8..3fd62b83 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -20,9 +20,8 @@ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ -#include - #include "button.h" +#include "label.h" #include "progressbar.h" #include "status.h" #include "windowcontainer.h" @@ -47,20 +46,20 @@ StatusWindow::StatusWindow(LocalPlayer *player): // Status Part // ---------------------- - mLvlLabel = new gcn::Label(strprintf(_("Level: %d"), 0)); - mJobLvlLabel = new gcn::Label(strprintf(_("Job: %d"), 0)); - mGpLabel = new gcn::Label(strprintf(_("Money: %d GP"), 0)); + mLvlLabel = new Label(strprintf(_("Level: %d"), 0)); + mJobLvlLabel = new Label(strprintf(_("Job: %d"), 0)); + mGpLabel = new Label(strprintf(_("Money: %d GP"), 0)); - mHpLabel = new gcn::Label(_("HP:")); + mHpLabel = new Label(_("HP:")); mHpBar = new ProgressBar(1.0f, 80, 15, 0, 171, 34); - mXpLabel = new gcn::Label(_("Exp:")); + mXpLabel = new Label(_("Exp:")); mXpBar = new ProgressBar(1.0f, 80, 15, 143, 192, 211); - mMpLabel = new gcn::Label(_("MP:")); + mMpLabel = new Label(_("MP:")); mMpBar = new ProgressBar(1.0f, 80, 15, 26, 102, 230); - mJobLabel = new gcn::Label(_("Job:")); + mJobLabel = new Label(_("Job:")); mJobBar = new ProgressBar(1.0f, 80, 15, 220, 135, 203); // ---------------------- @@ -68,35 +67,35 @@ 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 Label(_("Stats")); + gcn::Label *mStatsTotalLabel = new Label(_("Total")); + gcn::Label *mStatsCostLabel = new Label(_("Cost")); mStatsTotalLabel->setAlignment(gcn::Graphics::CENTER); // 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; - mStatsEvadePoints = new gcn::Label; - mStatsReflexPoints = new gcn::Label; + mStatsAttackLabel = new Label(_("Attack:")); + mStatsDefenseLabel= new Label(_("Defense:")); + mStatsMagicAttackLabel = new Label(_("M.Attack:")); + mStatsMagicDefenseLabel = new Label(_("M.Defense:")); + mStatsAccuracyLabel = new Label(_("% Accuracy:")); + mStatsEvadeLabel = new Label(_("% Evade:")); + mStatsReflexLabel = new Label(_("% Reflex:")); + + mStatsAttackPoints = new Label; + mStatsDefensePoints = new Label; + mStatsMagicAttackPoints = new Label; + mStatsMagicDefensePoints = new Label; + mStatsAccuracyPoints = new Label; + mStatsEvadePoints = new Label; + mStatsReflexPoints = new Label; // New labels for (int i = 0; i < 6; i++) { - mStatsLabel[i] = new gcn::Label("0"); + mStatsLabel[i] = new Label("0"); mStatsLabel[i]->setAlignment(gcn::Graphics::CENTER); - mStatsDisplayLabel[i] = new gcn::Label; - mPointsLabel[i] = new gcn::Label("0"); + mStatsDisplayLabel[i] = new Label; + mPointsLabel[i] = new Label("0"); mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER); } mRemainingStatsPointsLabel = new gcn::Label; @@ -185,17 +184,11 @@ void StatusWindow::update() // HP Bar coloration if (mPlayer->mHp < int(mPlayer->mMaxHp / 3)) - { mHpBar->setColor(223, 32, 32); // Red - } else if (mPlayer->mHp < int((mPlayer->mMaxHp / 3) * 2)) - { mHpBar->setColor(230, 171, 34); // Orange - } else - { mHpBar->setColor(0, 171, 34); // Green - } mHpBar->setProgress((float) mPlayer->mHp / (float) mPlayer->mMaxHp); mMpBar->setProgress((float) mPlayer->mMp / (float) mPlayer->mMaxMp); @@ -285,28 +278,16 @@ void StatusWindow::action(const gcn::ActionEvent &event) if (event.getId().length() == 3) { if (event.getId() == "STR") - { player_node->raiseAttribute(LocalPlayer::STR); - } if (event.getId() == "AGI") - { player_node->raiseAttribute(LocalPlayer::AGI); - } if (event.getId() == "VIT") - { player_node->raiseAttribute(LocalPlayer::VIT); - } if (event.getId() == "INT") - { player_node->raiseAttribute(LocalPlayer::INT); - } if (event.getId() == "DEX") - { player_node->raiseAttribute(LocalPlayer::DEX); - } if (event.getId() == "LUK") - { player_node->raiseAttribute(LocalPlayer::LUK); - } } } diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 6a813bc4..5036fc15 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -24,12 +24,11 @@ #include #include -#include - #include "button.h" #include "inventorywindow.h" #include "item_amount.h" #include "itemcontainer.h" +#include "label.h" #include "progressbar.h" #include "scrollarea.h" #include "storagewindow.h" @@ -75,7 +74,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): mUsedSlots = toString(player_node->getStorage()->getNumberOfSlotsUsed()); - mSlotsLabel = new gcn::Label(_("Slots: ")); + mSlotsLabel = new Label(_("Slots: ")); mSlotsBar = new ProgressBar(1.0f, 100, 20, 225, 200, 25); diff --git a/src/gui/textfield.cpp b/src/gui/textfield.cpp index 054bc405..257ddaa1 100644 --- a/src/gui/textfield.cpp +++ b/src/gui/textfield.cpp @@ -22,6 +22,7 @@ #include +#include "palette.h" #include "sdlinput.h" #include "textfield.h" @@ -55,8 +56,10 @@ TextField::TextField(const std::string& text): int gridy[4] = {0, 3, 28, 31}; int a = 0, x, y; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { skin.grid[a] = textbox->getSubImage( gridx[x], gridy[y], gridx[x + 1] - gridx[x] + 1, @@ -77,9 +80,7 @@ TextField::~TextField() instances--; if (instances == 0) - { for_each(skin.grid, skin.grid + 9, dtor()); - } } void TextField::draw(gcn::Graphics *graphics) @@ -90,11 +91,11 @@ void TextField::draw(gcn::Graphics *graphics) if (isFocused()) { drawCaret(graphics, - getFont()->getWidth(mText.substr(0, mCaretPosition)) - - mXScroll); + getFont()->getWidth(mText.substr(0, mCaretPosition)) - + mXScroll); } - graphics->setColor(getForegroundColor()); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); graphics->setFont(getFont()); graphics->drawText(mText, 1 - mXScroll, 1); @@ -102,9 +103,7 @@ void TextField::draw(gcn::Graphics *graphics) { mAlpha = config.getValue("guialpha", 0.8); for (int a = 0; a < 9; a++) - { skin.grid[a]->setAlpha(mAlpha); - } } } @@ -122,9 +121,8 @@ void TextField::setNumeric(bool numeric) { mNumeric = numeric; if (!numeric) - { return; - } + const char *text = mText.c_str(); for (const char *textPtr = text; *textPtr; ++textPtr) { @@ -139,18 +137,15 @@ void TextField::setNumeric(bool numeric) int TextField::getValue() const { if (!mNumeric) - { return 0; - } + int value = atoi(mText.c_str()); if (value < mMinimum) - { return mMinimum; - } + if (value > mMaximum) - { return mMaximum; - } + return value; } diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index caae33c0..bae0b651 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -22,13 +22,12 @@ #include -#include - #include "button.h" #include "chat.h" #include "inventorywindow.h" #include "item_amount.h" #include "itemcontainer.h" +#include "label.h" #include "scrollarea.h" #include "textfield.h" #include "trade.h" @@ -47,7 +46,7 @@ #include "../utils/stringutils.h" TradeWindow::TradeWindow(Network *network): - Window(_("Trade: You")), + Window("Trade"), mNetwork(network), mMyInventory(new Inventory(INVENTORY_SIZE, 2)), mPartnerInventory(new Inventory(INVENTORY_SIZE, 2)) @@ -78,8 +77,8 @@ TradeWindow::TradeWindow(Network *network): mPartnerScroll = new ScrollArea(mPartnerItemContainer); - mMoneyLabel = new gcn::Label(strprintf(_("You get %d GP."), 0)); - mMoneyLabel2 = new gcn::Label(_("You give:")); + mMoneyLabel = new Label(strprintf(_("You get %d GP."), 0)); + mMoneyLabel2 = new Label(_("You give:")); mMoneyField = new TextField; mMoneyField->setWidth(50); diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 81dcb047..927d6eaf 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -25,13 +25,11 @@ #include #include -#include - -// Curl should be included after Guichan to avoid Windows redefinitions #include #include "browserbox.h" #include "button.h" +#include "label.h" #include "progressbar.h" #include "scrollarea.h" #include "updatewindow.h" @@ -110,7 +108,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mBrowserBox = new BrowserBox(); mScrollArea = new ScrollArea(mBrowserBox); - mLabel = new gcn::Label(_("Connecting...")); + mLabel = new Label(_("Connecting...")); mProgressBar = new ProgressBar(0.0, 310, 20, 168, 116, 31); mCancelButton = new Button(_("Cancel"), "cancel", this); mPlayButton = new Button(_("Play"), "play", this); diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index 97f6010c..942ad3ef 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -25,6 +25,8 @@ #include "tab.h" #include "tabbedarea.h" +#include "../palette.h" + #include "../../configuration.h" #include "../../graphics.h" @@ -124,13 +126,17 @@ void Tab::draw(gcn::Graphics *graphics) { mode = TAB_SELECTED; // if tab is selected, it doesnt need to highlight activity - mLabel->setForegroundColor(gcn::Color(0, 0, 0)); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TEXT)); mHighlighted = false; } else if (mHighlighted) { mode = TAB_HIGHLIGHTED; - mLabel->setForegroundColor(gcn::Color(255, 0, 0)); + mLabel->setForegroundColor(guiPalette->getColor(Palette::TAB_HIGHLIGHT)); + } + else + { + mLabel->setForegroundColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index f6d23950..144357ca 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -27,6 +27,7 @@ #include #include "gui.h" +#include "palette.h" #include "skin.h" #include "window.h" #include "windowcontainer.h" @@ -153,7 +154,7 @@ void Window::draw(gcn::Graphics *graphics) // Draw title if (mShowTitle) { - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(guiPalette->getColor(Palette::TEXT)); g->setFont(getFont()); g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } diff --git a/src/main.cpp b/src/main.cpp index bed297de..60a4d500 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -29,8 +29,6 @@ #include -#include - #include #include @@ -57,6 +55,7 @@ #include "gui/char_server.h" #include "gui/char_select.h" #include "gui/gui.h" +#include "gui/label.h" #include "gui/login.h" #include "gui/ok_dialog.h" #include "gui/palette.h" @@ -776,11 +775,11 @@ int main(int argc, char *argv[]) gcn::Container *top = static_cast(gui->getTop()); #ifdef PACKAGE_VERSION - gcn::Label *versionLabel = new gcn::Label(PACKAGE_VERSION); + gcn::Label *versionLabel = new Label(PACKAGE_VERSION); top->add(versionLabel, 2, 2); #endif ProgressBar *progressBar = new ProgressBar(0.0f, 100, 20, 168, 116, 31); - gcn::Label *progressLabel = new gcn::Label(); + gcn::Label *progressLabel = new Label(); top->add(progressBar, 5, top->getHeight() - 5 - progressBar->getHeight()); top->add(progressLabel, 15 + progressBar->getWidth(), progressBar->getY() + 4); -- cgit v1.2.3-70-g09d2 From 20ad38045482254b9875ee80de44a9b6f9367d2d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:28:26 -0600 Subject: Exposed the progress bar colors to the color management tab. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 1 + src/gui/palette.h | 1 + src/gui/progressbar.cpp | 13 ++++++++++--- src/gui/setup_colors.cpp | 27 ++++++++++++++++++--------- src/gui/textrenderer.h | 7 +++---- src/gui/widgets/textpreview.cpp | 10 +++++++++- src/gui/widgets/textpreview.h | 11 +++++++++++ src/gui/window.cpp | 6 ++++++ src/gui/window.h | 5 +++++ src/text.cpp | 2 +- src/textparticle.cpp | 2 +- 11 files changed, 66 insertions(+), 19 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index c155cfe2..a3d654be 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -84,6 +84,7 @@ Palette::Palette() : addColor(TEXT, 0x000000, STATIC, _("Text")); addColor(SHADOW, 0x000000, STATIC, indent + _("Text Shadow")); addColor(OUTLINE, 0x000000, STATIC, indent + _("Text Outline")); + addColor(PROGRESS_BAR, 0xffffff, STATIC, indent + _("Progress Bar Labels")); addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); diff --git a/src/gui/palette.h b/src/gui/palette.h index 4d8f7f11..f0a3d541 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -51,6 +51,7 @@ class Palette : public gcn::ListModel ENTRY(TEXT)\ ENTRY(SHADOW)\ ENTRY(OUTLINE)\ + ENTRY(PROGRESS_BAR)\ ENTRY(BACKGROUND)\ ENTRY(HIGHLIGHT)\ ENTRY(TAB_HIGHLIGHT)\ diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index bec86bb1..025e0ec5 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -23,6 +23,7 @@ #include #include "gui.h" +#include "palette.h" #include "progressbar.h" #include "../configuration.h" @@ -133,18 +134,24 @@ void ProgressBar::draw(gcn::Graphics *graphics) const int textX = getWidth() / 2; const int textY = (getHeight() - f->getHeight()) / 2; + gcn::Color tempColor = guiPalette->getColor(Palette::OUTLINE); + graphics->setFont(f); - graphics->setColor(gcn::Color(0, 0, 0, alpha)); + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(255, 255, 255, alpha)); + tempColor = guiPalette->getColor(Palette::PROGRESS_BAR); + + graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, + (int) tempColor.b, alpha)); graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); - graphics->setColor(gcn::Color(0, 0, 0)); + graphics->setColor(guiPalette->getColor(Palette::TEXT)); } } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 09c6a3a9..b7c408d1 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -177,12 +177,12 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); mPreviewBox->setContent(mTextPreview); mTextPreview->setFont(gui->getFont()); - mTextPreview->setTextColor( - &guiPalette->getColor(Palette::TEXT)); + mTextPreview->setTextColor(&guiPalette->getColor(Palette::TEXT)); mTextPreview->setTextBGColor(NULL); - mTextPreview->setOpaque(false); + mTextPreview->setOpaque(false); mTextPreview->setShadow(true); mTextPreview->setOutline(true); + mTextPreview->useTextAlpha(false); switch (type) { @@ -190,10 +190,16 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::SHADOW: case Palette::OUTLINE: mTextPreview->setFont(gui->getFont()); - mTextPreview->setOutline(true); mTextPreview->setShadow(type == Palette::SHADOW); mTextPreview->setOutline(type == Palette::OUTLINE); break; + case Palette::PROGRESS_BAR: + mTextPreview->useTextAlpha(true); + mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); + mTextPreview->setOutline(true); + mTextPreview->setShadow(false); + break; case Palette::TAB_HIGHLIGHT: mTextPreview->setFont(gui->getFont()); mTextPreview->setTextColor(col); @@ -201,8 +207,13 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setShadow(false); break; case Palette::BACKGROUND: - case Palette::HIGHLIGHT: case Palette::SHOP_WARNING: + mTextPreview->setBGColor(col); + mTextPreview->setOpaque(true); + mTextPreview->setOutline(false); + mTextPreview->setShadow(false); + break; + case Palette::HIGHLIGHT: mTextPreview->setTextBGColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); @@ -221,13 +232,10 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mPreview->clearRows(); if (ch == '<') - { msg = toString("@@|") + rawmsg + "@@"; - } else - { msg = "##" + toString(ch) + rawmsg; - } + mPreview->addRow(msg); break; case Palette::UNKNOWN_ITEM: @@ -246,6 +254,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) mTextPreview->setFont(boldFont); mTextPreview->setOutline(false); mTextPreview->setShadow(false); + break; case Palette::PARTICLE: case Palette::EXP_INFO: case Palette::PICKUP_INFO: diff --git a/src/gui/textrenderer.h b/src/gui/textrenderer.h index 599e85a3..c0f5a0e9 100644 --- a/src/gui/textrenderer.h +++ b/src/gui/textrenderer.h @@ -37,7 +37,7 @@ class TextRenderer */ static inline void renderText(gcn::Graphics *graphics, const std::string& text, int x, int y, gcn::Graphics::Alignment align, - const gcn::Color* color, gcn::Font *font, bool outline = false, + const gcn::Color color, gcn::Font *font, bool outline = false, bool shadow = false, int alpha = 255) { graphics->setFont(font); @@ -45,8 +45,7 @@ class TextRenderer // Text shadow if (shadow) { - graphics->setColor(guiPalette->getColor(Palette::SHADOW, - alpha / 2)); + graphics->setColor(guiPalette->getColor(Palette::SHADOW, alpha / 2)); if (outline) { graphics->drawText(text, x + 2, y + 2, align); @@ -73,7 +72,7 @@ class TextRenderer graphics->drawText(text, x, y - 1, align); } - graphics->setColor(*color); + graphics->setColor(color); graphics->drawText(text, x, y, align); } }; diff --git a/src/gui/widgets/textpreview.cpp b/src/gui/widgets/textpreview.cpp index e34bb5cb..5408eebe 100644 --- a/src/gui/widgets/textpreview.cpp +++ b/src/gui/widgets/textpreview.cpp @@ -35,6 +35,7 @@ float TextPreview::mAlpha = config.getValue("guialpha", 0.8); TextPreview::TextPreview(const std::string* text) { mText = text; + mTextAlpha = false; mFont = gui->getFont(); mTextColor = &guiPalette->getColor(Palette::TEXT); mTextBGColor = NULL; @@ -47,6 +48,11 @@ void TextPreview::draw(gcn::Graphics* graphics) if (config.getValue("guialpha", 0.8) != mAlpha) mAlpha = config.getValue("guialpha", 0.8); + int alpha = (int) (mAlpha * 255.0f); + + if (!mTextAlpha) + alpha = 255; + if (mOpaque) { graphics->setColor(gcn::Color((int) mBGColor->r, @@ -69,5 +75,7 @@ void TextPreview::draw(gcn::Graphics* graphics) } TextRenderer::renderText(graphics, *mText, 2, 2, gcn::Graphics::LEFT, - mTextColor, mFont, mOutline, mShadow); + gcn::Color(mTextColor->r, mTextColor->g, + mTextColor->b, alpha), + mFont, mOutline, mShadow, alpha); } diff --git a/src/gui/widgets/textpreview.h b/src/gui/widgets/textpreview.h index a73eb638..8e116262 100644 --- a/src/gui/widgets/textpreview.h +++ b/src/gui/widgets/textpreview.h @@ -44,6 +44,16 @@ class TextPreview : public gcn::Widget mTextColor = color; } + /** + * Sets the text to use the set alpha value. + * + * @param alpha whether to use alpha values for the text or not + */ + inline void useTextAlpha(bool alpha) + { + mTextAlpha = alpha; + } + /** * Sets the color the text background is drawn in. This is only the * rectangle directly behind the text, not to full widget. @@ -123,6 +133,7 @@ class TextPreview : public gcn::Widget const gcn::Color* mBGColor; const gcn::Color* mTextBGColor; static float mAlpha; + bool mTextAlpha; bool mOpaque; bool mShadow; bool mOutline; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 144357ca..e6e79b45 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -675,6 +675,12 @@ void Window::setGuiAlpha() mAlphaChanged = false; } +int Window::getGuiAlpha() +{ + float alpha = config.getValue("guialpha", 0.8); + return (int) (alpha * 255.0f); +} + Layout &Window::getLayout() { if (!mLayout) mLayout = new Layout; diff --git a/src/gui/window.h b/src/gui/window.h index d573d85f..e04fcfc3 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -300,6 +300,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ virtual void close(); + /** + * Gets the alpha value used by the window, in a GUIChan usable format. + */ + int getGuiAlpha(); + private: enum ResizeHandles { diff --git a/src/text.cpp b/src/text.cpp index 420eeb8b..4e697f15 100644 --- a/src/text.cpp +++ b/src/text.cpp @@ -81,7 +81,7 @@ void Text::draw(gcn::Graphics *graphics, int xOff, int yOff) TextRenderer::renderText(graphics, mText, mX - xOff, mY - yOff, gcn::Graphics::LEFT, - mColor, boldFont, true); + *mColor, boldFont, true); } FlashText::FlashText(const std::string &text, int x, int y, diff --git a/src/textparticle.cpp b/src/textparticle.cpp index 865c6764..957d67c0 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -61,5 +61,5 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, - mColor, mTextFont, mOutline, false, (int) alpha); + *mColor, mTextFont, mOutline, false, (int) alpha); } -- cgit v1.2.3-70-g09d2 From 1a0703fe7e90638efac2e7be1cf115c5e243fa9b Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:29:15 -0600 Subject: Added the label classes that were accidently left out in commit 3575c7a606c2d24c0d444e9999892c0390fa5ae8 Signed-off-by: Ira Rice --- src/gui/label.cpp | 68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/label.h | 55 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 123 insertions(+) create mode 100644 src/gui/label.cpp create mode 100644 src/gui/label.h (limited to 'src/gui') diff --git a/src/gui/label.cpp b/src/gui/label.cpp new file mode 100644 index 00000000..bab8c465 --- /dev/null +++ b/src/gui/label.cpp @@ -0,0 +1,68 @@ +/* + * Aethyra + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * Copyright (c) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from GUIChan. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#include +#include + +#include "gui.h" +#include "label.h" +#include "palette.h" + +#include "../graphics.h" + +Label::Label() : + gcn::Label() +{ +} + +Label::Label(const std::string& caption) : + gcn::Label(caption) +{ +} + +void Label::draw(gcn::Graphics* graphics) +{ + int textX; + int textY = getHeight() / 2 - getFont()->getHeight() / 2; + + switch (getAlignment()) + { + case gcn::Graphics::LEFT: + textX = 0; + break; + case gcn::Graphics::CENTER: + textX = getWidth() / 2; + break; + case gcn::Graphics::RIGHT: + textX = getWidth(); + break; + default: + throw GCN_EXCEPTION("Unknown alignment."); + } + + setForegroundColor(guiPalette->getColor(Palette::TEXT)); + + graphics->setFont(getFont()); + graphics->setColor(getForegroundColor()); + graphics->drawText(getCaption(), textX, textY, getAlignment()); +} diff --git a/src/gui/label.h b/src/gui/label.h new file mode 100644 index 00000000..961286e0 --- /dev/null +++ b/src/gui/label.h @@ -0,0 +1,55 @@ +/* + * Aethyra + * Copyright (c) 2004 - 2008 Olof Naessén and Per Larsson + * Copyright (c) 2009 Aethyra Development Team + * + * This file is part of Aethyra based on original code + * from GUIChan. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +#ifndef LABEL_H +#define LABEL_H + +#include + +/** + * Label widget. Same as the Guichan label but modified to use the palette + * system. + * + * \ingroup GUI + */ +class Label : public gcn::Label +{ + public: + /** + * Constructor. + */ + Label(); + + /** + * Constructor. This version of the constructor sets the label with an + * inintialization string. + */ + Label(const std::string& caption); + + /** + * Draws the label. + */ + void draw(gcn::Graphics* graphics); +}; + +#endif -- cgit v1.2.3-70-g09d2 From 01c1c1874a4ebeef1f4c9ad7844e0eb5afd34217 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 14:57:14 -0600 Subject: Fixed a label in the status window to use the label widget inside the gui folder. Signed-off-by: Ira Rice --- src/gui/status.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/status.cpp b/src/gui/status.cpp index 3fd62b83..8dd32039 100644 --- a/src/gui/status.cpp +++ b/src/gui/status.cpp @@ -98,7 +98,7 @@ StatusWindow::StatusWindow(LocalPlayer *player): mPointsLabel[i] = new Label("0"); mPointsLabel[i]->setAlignment(gcn::Graphics::CENTER); } - mRemainingStatsPointsLabel = new gcn::Label; + mRemainingStatsPointsLabel = new Label; // Set button events Id mStatsButton[0] = new Button("+", "STR", this); -- cgit v1.2.3-70-g09d2 From 78c607671bc62daf0901417ffc557f50bbf63f76 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 15:06:53 -0600 Subject: Fixed item popups in the equipment window to display the proper item type colors. Signed-off-by: Ira Rice --- src/gui/equipmentwindow.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 0d2097f8..1d9b4721 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -63,6 +63,7 @@ EquipmentWindow::EquipmentWindow(): mSelected(-1) { mItemPopup = new ItemPopup(); + mItemPopup->setOpaque(false); // Control that shows the Player mPlayerBox = new PlayerBox; @@ -235,8 +236,9 @@ void EquipmentWindow::mouseMoved(gcn::MouseEvent &event) int mouseX, mouseY; SDL_GetMouseState(&mouseX, &mouseY); - mItemPopup->setItem(item->getInfo()); - mItemPopup->setOpaque(false); + if (item->getInfo().getName() != mItemPopup->getItemName()) + mItemPopup->setItem(item->getInfo()); + mItemPopup->updateColors(); mItemPopup->view(x + getX(), y + getY()); } else -- cgit v1.2.3-70-g09d2 From 79fa5a629426888f51241914d90ca8599373f2d0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 15:17:38 -0600 Subject: Modified the equipment window to use the highlight color for selections. Signed-off-by: Ira Rice --- src/gui/equipmentwindow.cpp | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'src/gui') diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 1d9b4721..31fe3b8b 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -28,6 +28,7 @@ #include "button.h" #include "equipmentwindow.h" #include "itempopup.h" +#include "palette.h" #include "playerbox.h" #include "viewport.h" @@ -114,6 +115,22 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) for (int i = EQUIP_LEGS_SLOT; i < EQUIP_VECTOREND; i++) { + if (i == mSelected) + { + const gcn::Color color = guiPalette->getColor(Palette::HIGHLIGHT); + + // Set color to the highligh color + g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); + g->fillRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT)); + } + + // Set color black. + g->setColor(gcn::Color(0, 0, 0)); + // Draw box border. + g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, + BOX_WIDTH, BOX_HEIGHT)); + item = (i != EQUIP_AMMO_SLOT) ? mInventory->getItem(mEquipment->getEquipment(i)) : mInventory->getItem(mEquipment->getArrows()); @@ -124,28 +141,13 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) g->drawImage(image, mEquipBox[i].posX, mEquipBox[i].posY); if (i == EQUIP_AMMO_SLOT) { - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(guiPalette->getColor(Palette::TEXT)); graphics->drawText(toString(item->getQuantity()), mEquipBox[i].posX + (BOX_WIDTH / 2), mEquipBox[i].posY - getFont()->getHeight(), gcn::Graphics::CENTER); } } - - if (i == mSelected) - { - // Set color red. - g->setColor(gcn::Color(255, 0, 0)); - } - else - { - // Set color black. - g->setColor(gcn::Color(0, 0, 0)); - } - - // Draw box border. - g->drawRectangle(gcn::Rectangle(mEquipBox[i].posX, mEquipBox[i].posY, - BOX_WIDTH, BOX_HEIGHT)); } } -- cgit v1.2.3-70-g09d2 From 8fb5276dcc5c527a3daf99c18826d6d9bf9802be Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 20:20:04 -0600 Subject: Added a pulse effect into the palette class, which uses the set color and pulsates back and forth between it and black. Added directly after the spectrum effect. Also modified the gradient delay to be a lot farther out, so that we don't end up with a Pokemon seizure causing disaster (the speed was the same, as well as the colors. The new speed should be a lot more considerate of people who are prone to having issues from that speed of color changing). TODO: Modify the palette class to allow for updating the color for the pulse gradient without needing to have it applied first. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 55 ++++++++++++++++++++++++++---------------------- src/gui/palette.h | 22 ++++++------------- src/gui/setup_colors.cpp | 3 ++- 3 files changed, 39 insertions(+), 41 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index a3d654be..412550c7 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -33,7 +33,7 @@ const gcn::Color Palette::BLACK = gcn::Color(0, 0, 0); -const gcn::Color Palette::RAINBOW_COLORS[8] = { +const gcn::Color Palette::RAINBOW_COLORS[7] = { gcn::Color(255, 0, 0), gcn::Color(255, 153, 0), gcn::Color(255, 255, 0), @@ -73,7 +73,7 @@ std::string Palette::getConfigName(const std::string& typeName) DEFENUMNAMES(ColorType, COLOR_TYPE); -const int Palette::GRADIENT_DELAY = 20; +const int Palette::GRADIENT_DELAY = 40; Palette::Palette() : mRainbowTime(tick_time), @@ -89,7 +89,7 @@ Palette::Palette() : addColor(BACKGROUND, 0xffffff, STATIC, _("Background")); addColor(HIGHLIGHT, 0xebc873, STATIC, _("Highlight"), 'H'); - addColor(TAB_HIGHLIGHT, 0xff0000, STATIC, indent + _("Tab Highlight")); + addColor(TAB_HIGHLIGHT, 0xff0000, PULSE, indent + _("Tab Highlight")); addColor(SHOP_WARNING, 0x910000, STATIC, indent + _("Item too expensive")); @@ -222,7 +222,7 @@ void Palette::commit(bool commitNonStatic) i != iEnd; ++i) { i->committedGrad = i->grad; - if (commitNonStatic || i->grad == STATIC) + if (commitNonStatic || i->grad == STATIC || i->grad == PULSE) { i->committedColor = i->color; } @@ -245,8 +245,8 @@ void Palette::rollback() } void Palette::addColor(Palette::ColorType type, int rgb, - Palette::GradientType grad, - const std::string &text, char c) + Palette::GradientType grad, + const std::string &text, char c) { const std::string *configName = &ColorTypeNames[type]; gcn::Color trueCol = (int)config.getValue(*configName, rgb); @@ -263,7 +263,7 @@ void Palette::advanceGradient () if (get_elapsed_time(mRainbowTime) > 5) { int pos, colIndex, colVal; - // For slower systems, advance can be greater than one (adcanve > 1 + // For slower systems, advance can be greater than one (advance > 1 // skips advance-1 steps). Should make gradient look the same // independent of the framerate. int advance = get_elapsed_time(mRainbowTime) / 5; @@ -273,25 +273,32 @@ void Palette::advanceGradient () { mGradVector[i]->gradientIndex = (mGradVector[i]->gradientIndex + advance) % - (GRADIENT_DELAY * - ((mGradVector[i]->grad == SPECTRUM) ? 6 : - RAINBOW_COLOR_COUNT)); + (GRADIENT_DELAY * ((mGradVector[i]->grad == SPECTRUM) ? + (mGradVector[i]->grad == PULSE) ? 255 : 6 : + RAINBOW_COLOR_COUNT)); pos = mGradVector[i]->gradientIndex % GRADIENT_DELAY; colIndex = mGradVector[i]->gradientIndex / GRADIENT_DELAY; + if (mGradVector[i]->grad == PULSE) + { + colVal = (int) (255.0 * (sin(M_PI * (mGradVector[i]->gradientIndex) / 255) + 1) / 2); + + const gcn::Color* col = &mGradVector[i]->committedColor; + + mGradVector[i]->color.r = (colVal) % (col->r + 1); + mGradVector[i]->color.g = (colVal) % (col->g + 1); + mGradVector[i]->color.b = (colVal) % (col->b + 1); + } if (mGradVector[i]->grad == SPECTRUM) { if (colIndex % 2) { // falling curve - colVal = (int)(255.0 * - (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); } else { // ascending curve - colVal = (int)(255.0 * - (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + - 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + 1) / 2); } mGradVector[i]->color.r = @@ -304,7 +311,7 @@ void Palette::advanceGradient () (colIndex == 3 || colIndex == 4) ? 255 : (colIndex == 2 || colIndex == 5) ? colVal : 0; } - else + else if (mGradVector[i]->grad == RAINBOW) { const gcn::Color* startCol = &RAINBOW_COLORS[colIndex]; const gcn::Color* destCol = @@ -313,20 +320,18 @@ void Palette::advanceGradient () startColVal = (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2; destColVal = 1 - startColVal; - mGradVector[i]->color.r =(int)( - startColVal * startCol->r + - destColVal * destCol->r); + mGradVector[i]->color.r =(int)(startColVal * startCol->r + + destColVal * destCol->r); - mGradVector[i]->color.g =(int)( - startColVal * startCol->g + - destColVal * destCol->g); + mGradVector[i]->color.g =(int)(startColVal * startCol->g + + destColVal * destCol->g); - mGradVector[i]->color.b =(int)( - startColVal * startCol->b + - destColVal * destCol->b); + mGradVector[i]->color.b =(int)(startColVal * startCol->b + + destColVal * destCol->b); } } mRainbowTime = tick_time; } } + diff --git a/src/gui/palette.h b/src/gui/palette.h index f0a3d541..0947aa58 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -98,6 +98,7 @@ class Palette : public gcn::ListModel /** Colors can be static or can alter over time. */ enum GradientType { STATIC, + PULSE, SPECTRUM, RAINBOW }; @@ -147,9 +148,7 @@ class Palette : public gcn::ListModel * @return the requested committed color */ inline const gcn::Color& getCommittedColor(ColorType type) - { - return mColVector[type].committedColor; - } + { return mColVector[type].committedColor; } /** * Gets the GradientType associated with the specified type. @@ -159,9 +158,7 @@ class Palette : public gcn::ListModel * @return the gradient type of the color with the given index */ inline GradientType getGradientType(ColorType type) - { - return mColVector[type].grad; - } + { return mColVector[type].grad; } /** * Get the character used by the specified color. @@ -170,10 +167,7 @@ class Palette : public gcn::ListModel * * @return the color char of the color with the given index */ - inline char getColorChar(ColorType type) - { - return mColVector[type].ch; - } + inline char getColorChar(ColorType type) { return mColVector[type].ch; } /** * Sets the color for the specified type. @@ -221,10 +215,7 @@ class Palette : public gcn::ListModel /** * Commit the colors */ - inline void commit() - { - commit(false); - } + inline void commit() { commit(false); } /** * Rollback the colors @@ -286,7 +277,8 @@ class Palette : public gcn::ListModel ColorElem::gradientIndex = rand(); } - inline int getRGB() { + inline int getRGB() + { return (committedColor.r << 16) | (committedColor.g << 8) | committedColor.b; } diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index b7c408d1..79c4fcb5 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -73,7 +73,7 @@ Setup_Colors::Setup_Colors() : mGradTypeLabel = new Label(_("Type: ")); - mGradTypeSlider = new Slider(0, 2); + mGradTypeSlider = new Slider(0, 3); mGradTypeSlider->setWidth(160); mGradTypeSlider->setActionEventId("slider_grad"); mGradTypeSlider->setValue(0); @@ -378,6 +378,7 @@ void Setup_Colors::updateGradType() mGradTypeText->setCaption( (grad == Palette::STATIC) ? _("Static") : + (grad == Palette::PULSE) ? _("Pulse") : (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); bool enable = (grad == Palette::STATIC); -- cgit v1.2.3-70-g09d2 From 6d6fd0cec10601a51cab67e623a579a14af775fc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 20:54:35 -0600 Subject: Made the slider editable when pulse gradient is selected. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 34 +++++++++++++++++++++++----------- src/gui/palette.h | 20 ++++++++++++++++++++ src/gui/setup_colors.cpp | 15 +++++++++++++-- 3 files changed, 56 insertions(+), 13 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 412550c7..5b98f403 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -52,12 +52,11 @@ std::string Palette::getConfigName(const std::string& typeName) int pos = 5; for (unsigned int i = 0; i < typeName.length(); i++) { - if (i==0 || typeName[i] == '_') + if (i == 0 || typeName[i] == '_') { if (i > 0) - { i++; - } + res[pos] = typeName[i]; } else @@ -144,7 +143,7 @@ Palette::~Palette() { configName = &ColorTypeNames[col->type]; config.setValue(*configName + "Gradient", col->committedGrad); - if (col->grad == STATIC) + if (col->grad == STATIC || col->grad == PULSE) { config.setValue(*configName, toString(col->getRGB())); } @@ -154,7 +153,7 @@ Palette::~Palette() const gcn::Color& Palette::getColor(char c, bool &valid) { for (ColVector::const_iterator col = mColVector.begin(), - colEnd = mColVector.end(); col != colEnd; ++col) + colEnd = mColVector.end(); col != colEnd; ++col) { if (col->ch == c) { @@ -222,10 +221,14 @@ void Palette::commit(bool commitNonStatic) i != iEnd; ++i) { i->committedGrad = i->grad; - if (commitNonStatic || i->grad == STATIC || i->grad == PULSE) + if (commitNonStatic || i->grad == STATIC) { i->committedColor = i->color; } + else if (i->grad == PULSE) + { + i->committedColor = i->testColor; + } } } @@ -240,7 +243,13 @@ void Palette::rollback() setGradient(i->type, i->committedGrad); } setColor(i->type, i->committedColor.r, i->committedColor.g, - i->committedColor.b); + i->committedColor.b); + if (i->grad == PULSE) + { + i->testColor.r = i->committedColor.r; + i->testColor.g = i->committedColor.g; + i->testColor.b = i->committedColor.b; + } } } @@ -282,9 +291,10 @@ void Palette::advanceGradient () if (mGradVector[i]->grad == PULSE) { - colVal = (int) (255.0 * (sin(M_PI * (mGradVector[i]->gradientIndex) / 255) + 1) / 2); + colVal = (int) (255.0 * (sin(M_PI * + (mGradVector[i]->gradientIndex) / 255) + 1) / 2); - const gcn::Color* col = &mGradVector[i]->committedColor; + const gcn::Color* col = &mGradVector[i]->testColor; mGradVector[i]->color.r = (colVal) % (col->r + 1); mGradVector[i]->color.g = (colVal) % (col->g + 1); @@ -294,11 +304,13 @@ void Palette::advanceGradient () { if (colIndex % 2) { // falling curve - colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) + 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * pos / GRADIENT_DELAY) + + 1) / 2); } else { // ascending curve - colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) / GRADIENT_DELAY) + 1) / 2); + colVal = (int)(255.0 * (cos(M_PI * (GRADIENT_DELAY-pos) / + GRADIENT_DELAY) + 1) / 2); } mGradVector[i]->color.r = diff --git a/src/gui/palette.h b/src/gui/palette.h index 0947aa58..ccef231e 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -150,6 +150,25 @@ class Palette : public gcn::ListModel inline const gcn::Color& getCommittedColor(ColorType type) { return mColVector[type].committedColor; } + /** + * Gets the test color associated with the specified type. + * + * @param type the color type requested + * + * @return the requested test color + */ + inline const gcn::Color& getTestColor(ColorType type) + { return mColVector[type].testColor; } + + /** + * Sets the test color associated with the specified type. + * + * @param type the color type requested + * @param color the color that should be tested + */ + inline void setTestColor(ColorType type, gcn::Color color) + { mColVector[type].testColor = color; } + /** * Gets the GradientType associated with the specified type. * @@ -259,6 +278,7 @@ class Palette : public gcn::ListModel { ColorType type; gcn::Color color; + gcn::Color testColor; gcn::Color committedColor; std::string text; char ch; diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 79c4fcb5..760fdc1f 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -275,11 +275,15 @@ void Setup_Colors::action(const gcn::ActionEvent &event) break; } - if (grad != Palette::STATIC) + if (grad != Palette::STATIC && grad != Palette::PULSE) { // If nonstatic color, don't display the current, but the committed // color at the sliders col = &guiPalette->getCommittedColor(type); } + else if (grad == Palette::PULSE) + { + col = &guiPalette->getTestColor(type); + } setEntry(mRedSlider, mRedText, col->r); setEntry(mGreenSlider, mGreenText, col->g); @@ -381,7 +385,7 @@ void Setup_Colors::updateGradType() (grad == Palette::PULSE) ? _("Pulse") : (grad == Palette::RAINBOW) ? _("Rainbow") : _("Spectrum")); - bool enable = (grad == Palette::STATIC); + bool enable = (grad == Palette::STATIC || grad == Palette::PULSE); mRedText->setEnabled(enable); mRedSlider->setEnabled(enable); mGreenText->setEnabled(enable); @@ -407,4 +411,11 @@ void Setup_Colors::updateColor() static_cast(mGreenSlider->getValue()), static_cast(mBlueSlider->getValue())); } + else if (grad == Palette::PULSE) + { + guiPalette->setTestColor(type, gcn::Color( + static_cast(mRedSlider->getValue()), + static_cast(mGreenSlider->getValue()), + static_cast(mBlueSlider->getValue()))); + } } -- cgit v1.2.3-70-g09d2 From 73fa81961d141b7592862a50993cd998fbd4de31 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 21:50:58 -0600 Subject: Exposed a few more windows to the reset window button under the setup dialog. Signed-off-by: Ira Rice --- src/gui/npcstringdialog.cpp | 1 - src/gui/setup.cpp | 6 ++++++ 2 files changed, 6 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 58a5c0c8..f50136ba 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,7 +47,6 @@ NpcStringDialog::NpcStringDialog(Network *network): place(0, 0, mValueField, 3); place(1, 1, cancelButton); place(2, 1, okButton); - //reflowLayout(175, 0); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index f1e7a6d9..5fe35a6c 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -45,6 +45,9 @@ extern Window *itemShortcutWindow; extern Window *emoteShortcutWindow; extern Window *emoteWindow; extern Window *tradeWindow; +extern Window *npcTextDialog; +extern Window *npcStringDialog; +extern Window *storageWindow; Setup::Setup(): Window(_("Setup")) @@ -139,6 +142,9 @@ void Setup::action(const gcn::ActionEvent &event) emoteShortcutWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); tradeWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From a9a1ed080289185cc5e71a127d7fdf35c920de8a Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:03:30 -0600 Subject: Exposed a few more windows to the reset button on the setup window. These windows required an external declaration to reset. Signed-off-by: Ira Rice --- src/gui/buy.h | 2 ++ src/gui/chat.h | 12 ++++++------ src/gui/debugwindow.h | 2 ++ src/gui/sell.h | 2 ++ src/gui/setup.cpp | 36 +++++++++++++++++++++--------------- 5 files changed, 33 insertions(+), 21 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.h b/src/gui/buy.h index 9029fe9d..17ab6e19 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -117,4 +117,6 @@ class BuyDialog : public Window, public gcn::ActionListener, Uint32 mMaxItems; }; +extern BuyDialog *buyDialog; + #endif diff --git a/src/gui/chat.h b/src/gui/chat.h index 45d0c92f..28408b93 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -236,12 +236,12 @@ class ChatWindow : public Window, public gcn::ActionListener, typedef std::list History; typedef History::iterator HistoryIterator; History mHistory; /**< Command history */ - HistoryIterator mCurHist; /**< History iterator */ - Recorder *mRecorder; /**< Recording class */ - char mPartyPrefix; /**< Messages beginning with the prefix are sent to - the party */ - bool mReturnToggles; /**< Marks whether toggles the chat log - or not */ + HistoryIterator mCurHist; /**< History iterator */ + Recorder *mRecorder; /**< Recording class */ + char mPartyPrefix; /**< Messages beginning with the prefix are + sent to the party */ + bool mReturnToggles; /**< Marks whether toggles the chat + log or not */ Party *mParty; }; extern ChatWindow *chatWindow; diff --git a/src/gui/debugwindow.h b/src/gui/debugwindow.h index 95e8b5e4..c82521f9 100644 --- a/src/gui/debugwindow.h +++ b/src/gui/debugwindow.h @@ -51,4 +51,6 @@ class DebugWindow : public Window gcn::Label *mParticleCountLabel; }; +extern DebugWindow *debugWindow; + #endif diff --git a/src/gui/sell.h b/src/gui/sell.h index 3776477f..5fb94c4e 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -108,4 +108,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener int mAmountItems; }; +extern SellDialog *sellDialog; + #endif diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 5fe35a6c..ab0b2245 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -35,18 +35,21 @@ #include "../utils/gettext.h" extern Window *chatWindow; -extern Window *equipmentWindow; -extern Window *helpWindow; -extern Window *inventoryWindow; -extern Window *minimap; -extern Window *skillDialog; extern Window *statusWindow; -extern Window *itemShortcutWindow; -extern Window *emoteShortcutWindow; +extern Window *buyDialog; +extern Window *sellDialog; +extern Window *inventoryWindow; extern Window *emoteWindow; -extern Window *tradeWindow; extern Window *npcTextDialog; extern Window *npcStringDialog; +extern Window *skillDialog; +extern Window *minimap; +extern Window *equipmentWindow; +extern Window *tradeWindow; +extern Window *helpWindow; +extern Window *debugWindow; +extern Window *itemShortcutWindow; +extern Window *emoteShortcutWindow; extern Window *storageWindow; Setup::Setup(): @@ -131,19 +134,22 @@ void Setup::action(const gcn::ActionEvent &event) if (!statusWindow) return; - statusWindow->resetToDefaultSize(); - minimap->resetToDefaultSize(); chatWindow->resetToDefaultSize(); + statusWindow->resetToDefaultSize(); + buyDialog->resetToDefaultSize(); + sellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); + emoteWindow->resetToDefaultSize(); + npcTextDialog->resetToDefaultSize(); + npcStringDialog->resetToDefaultSize(); + skillDialog->resetToDefaultSize(); + minimap->resetToDefaultSize(); equipmentWindow->resetToDefaultSize(); + tradeWindow->resetToDefaultSize(); helpWindow->resetToDefaultSize(); - skillDialog->resetToDefaultSize(); + debugWindow->resetToDefaultSize(); itemShortcutWindow->resetToDefaultSize(); emoteShortcutWindow->resetToDefaultSize(); - emoteWindow->resetToDefaultSize(); - tradeWindow->resetToDefaultSize(); - npcTextDialog->resetToDefaultSize(); - npcStringDialog->resetToDefaultSize(); storageWindow->resetToDefaultSize(); } } -- cgit v1.2.3-70-g09d2 From ebd128d47a3bcdf0b0bc03f179c4365c7c23a084 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:20:12 -0600 Subject: Removed a redundant widget resize function in the shortcut window. Signed-off-by: Ira Rice --- src/gui/shortcutwindow.cpp | 18 +++++++----------- src/gui/shortcutwindow.h | 5 ----- 2 files changed, 7 insertions(+), 16 deletions(-) (limited to 'src/gui') diff --git a/src/gui/shortcutwindow.cpp b/src/gui/shortcutwindow.cpp index c2df1f9c..8342465a 100644 --- a/src/gui/shortcutwindow.cpp +++ b/src/gui/shortcutwindow.cpp @@ -24,6 +24,8 @@ #include "shortcutcontainer.h" #include "shortcutwindow.h" +#include "widgets/layout.h" + #include "../configuration.h" static const int SCROLL_PADDING = 0; @@ -57,7 +59,11 @@ ShortcutWindow::ShortcutWindow(const char *title, ShortcutContainer *content) mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mScrollArea->setOpaque(false); - add(mScrollArea); + place(0, 0, mScrollArea, 5, 5).setPadding(0); + + Layout &layout = getLayout(); + layout.setRowHeight(0, Layout::AUTO_SET); + layout.setMargin(0); loadWindowState(); } @@ -67,13 +73,3 @@ ShortcutWindow::~ShortcutWindow() delete mItems; } -void ShortcutWindow::widgetResized(const gcn::Event &event) -{ - Window::widgetResized(event); - - const gcn::Rectangle &area = getChildrenArea(); - - mScrollArea->setSize( - area.width - SCROLL_PADDING, - area.height - SCROLL_PADDING); -} diff --git a/src/gui/shortcutwindow.h b/src/gui/shortcutwindow.h index 42077d9c..d79fffd2 100644 --- a/src/gui/shortcutwindow.h +++ b/src/gui/shortcutwindow.h @@ -46,11 +46,6 @@ class ShortcutWindow : public Window */ ~ShortcutWindow(); - /** - * Called whenever the widget changes size. - */ - void widgetResized(const gcn::Event &event); - private: ShortcutWindow(); ShortcutContainer *mItems; -- cgit v1.2.3-70-g09d2 From 4a5c8c418703a65c8f6576a6dcdbb2529c26764d Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 22:27:45 -0600 Subject: Fixed default size for the debug window. Signed-off-by: Ira Rice --- src/gui/debugwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 999e00a2..9b8ea6bd 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -40,7 +40,7 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); - setDefaultSize(400, 60, ImageRect::CENTER); + setDefaultSize(400, 100, ImageRect::CENTER); mFPSLabel = new Label("0 FPS"); mMusicFileLabel = new Label("Music: "); -- cgit v1.2.3-70-g09d2 From 4b459b50521f5d7a0518e229a20f14ed2f1d22f9 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sat, 14 Mar 2009 23:34:18 -0600 Subject: Improved pulsating algorithm to look better for impure colors. Signed-off-by: Ira Rice --- src/gui/palette.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index 5b98f403..d3e06902 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -296,9 +296,9 @@ void Palette::advanceGradient () const gcn::Color* col = &mGradVector[i]->testColor; - mGradVector[i]->color.r = (colVal) % (col->r + 1); - mGradVector[i]->color.g = (colVal) % (col->g + 1); - mGradVector[i]->color.b = (colVal) % (col->b + 1); + mGradVector[i]->color.r = ((colVal * col->r) / 255) % (col->r + 1); + mGradVector[i]->color.g = ((colVal * col->g) / 255) % (col->g + 1); + mGradVector[i]->color.b = ((colVal * col->b) / 255) % (col->b + 1); } if (mGradVector[i]->grad == SPECTRUM) { -- cgit v1.2.3-70-g09d2 From d6f89802e5aa32f266e881e43d6005e821040c57 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Tue, 10 Mar 2009 12:23:50 -0600 Subject: Fix some mem leaks --- src/beingmanager.cpp | 5 +++++ src/beingmanager.h | 4 +++- src/game.cpp | 3 ++- src/gui/chat.cpp | 2 ++ src/gui/setup.cpp | 2 ++ src/gui/setup_colors.cpp | 5 ++--- src/gui/skill.cpp | 2 +- src/gui/table.cpp | 1 + src/gui/window.cpp | 2 ++ src/main.cpp | 1 - src/player_relations.cpp | 31 +++++++++++++++++++------------ src/player_relations.h | 6 +++--- 12 files changed, 42 insertions(+), 22 deletions(-) (limited to 'src/gui') diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp index 0c7a310a..e5836aa7 100644 --- a/src/beingmanager.cpp +++ b/src/beingmanager.cpp @@ -52,6 +52,11 @@ BeingManager::BeingManager(Network *network): { } +BeingManager::~BeingManager() +{ + clear(); +} + void BeingManager::setMap(Map *map) { mMap = map; diff --git a/src/beingmanager.h b/src/beingmanager.h index 472e2c83..3284ce16 100644 --- a/src/beingmanager.h +++ b/src/beingmanager.h @@ -37,6 +37,8 @@ class BeingManager public: BeingManager(Network *network); + ~BeingManager(); + /** * Sets the map on which beings are created */ @@ -113,7 +115,7 @@ class BeingManager void logic(); /** - * Destroys all beings except the local player and current NPC (if any) + * Destroys all beings except the local player */ void clear(); diff --git a/src/game.cpp b/src/game.cpp index 47f4ffd2..a346616f 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -204,7 +204,6 @@ void createGuiWindows(Network *network) npcListDialog = new NpcListDialog(network); npcStringDialog = new NpcStringDialog(network); skillDialog = new SkillDialog(); - setupWindow = new Setup(); minimap = new Minimap(); equipmentWindow = new EquipmentWindow(); tradeWindow = new TradeWindow(network); @@ -337,6 +336,8 @@ Game::Game(Network *network): msg.writeInt32(tick_time); engine->changeMap(map_path); + + setupWindow->setInGame(true); } Game::~Game() diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 098d4e46..44e08052 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -109,6 +109,8 @@ ChatWindow::~ChatWindow() config.setValue("PartyPrefix", partyPrefix); config.setValue("ReturnToggles", mReturnToggles ? "1" : "0"); delete mRecorder; + delete mItemLinkHandler; + delete mParty; } void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index ab0b2245..dc232296 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -108,6 +108,8 @@ Setup::Setup(): add(panel); setLocationRelativeTo(getParent()); + + setInGame(false); } Setup::~Setup() diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 760fdc1f..148fd679 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -62,9 +62,8 @@ Setup_Colors::Setup_Colors() : mPreview = new BrowserBox(BrowserBox::AUTO_WRAP); mPreview->setOpaque(false); - // Replace this later with a more appropriate link handler. For now, this'll - // do, as it'll do nothing when clicked on. - mPreview->setLinkHandler(new ItemLinkHandler()); + // don't do anything with links + mPreview->setLinkHandler(NULL); mPreviewBox = new ScrollArea(mPreview); mPreviewBox->setHeight(20); diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 64214ff5..9fbae7a6 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -161,7 +161,7 @@ SkillDialog::SkillDialog(): SkillDialog::~SkillDialog() { - delete mTable; + delete_all(mSkillList); } void SkillDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index 144e7e21..fa801865 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -99,6 +99,7 @@ GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, GuiTable::~GuiTable(void) { + uninstallActionListeners(); delete mModel; } diff --git a/src/gui/window.cpp b/src/gui/window.cpp index e6e79b45..404f5746 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -124,6 +124,8 @@ Window::~Window() delete(w); } + removeWidgetListener(this); + instances--; mSkin->instances--; diff --git a/src/main.cpp b/src/main.cpp index 60a4d500..7ee2f6b4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1021,7 +1021,6 @@ int main(int argc, char *argv[]) delete progressBar; delete progressLabel; delete setup; - delete setupWindow; progressBar = NULL; progressLabel = NULL; currentDialog = NULL; diff --git a/src/player_relations.cpp b/src/player_relations.cpp index 1c1ba669..eec4153c 100644 --- a/src/player_relations.cpp +++ b/src/player_relations.cpp @@ -29,6 +29,8 @@ #include "player.h" #include "player_relations.h" +#include "utils/dtor.h" + #define PLAYER_IGNORE_STRATEGY_NOP "nop" #define PLAYER_IGNORE_STRATEGY_EMOTE0 "emote0" #define DEFAULT_IGNORE_STRATEGY PLAYER_IGNORE_STRATEGY_EMOTE0 @@ -38,7 +40,6 @@ #define IGNORE_EMOTE_TIME 100 - // (De)serialisation class class PlayerConfSerialiser : public ConfigurationListManager, std::map *> @@ -93,6 +94,11 @@ PlayerRelationsManager::PlayerRelationsManager() : { } +PlayerRelationsManager::~PlayerRelationsManager() +{ + delete_all(mIgnoreStrategies); +} + void PlayerRelationsManager::clear() { std::vector *names = getPlayers(); @@ -351,19 +357,20 @@ static std::vector player_ignore_strategies; std::vector * PlayerRelationsManager::getPlayerIgnoreStrategies() { - if (player_ignore_strategies.size() == 0) { + if (mIgnoreStrategies.size() == 0) + { // not initialised yet? - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, - "floating '...' bubble", - PLAYER_IGNORE_STRATEGY_EMOTE0)); - player_ignore_strategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, - "floating bubble", - "emote1")); - player_ignore_strategies.push_back(new PIS_nothing()); - player_ignore_strategies.push_back(new PIS_dotdotdot()); - player_ignore_strategies.push_back(new PIS_blinkname()); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE, + "floating '...' bubble", + PLAYER_IGNORE_STRATEGY_EMOTE0)); + mIgnoreStrategies.push_back(new PIS_emote(FIRST_IGNORE_EMOTE + 1, + "floating bubble", + "emote1")); + mIgnoreStrategies.push_back(new PIS_nothing()); + mIgnoreStrategies.push_back(new PIS_dotdotdot()); + mIgnoreStrategies.push_back(new PIS_blinkname()); } - return &player_ignore_strategies; + return &mIgnoreStrategies; } diff --git a/src/player_relations.h b/src/player_relations.h index 0440cace..f4860e08 100644 --- a/src/player_relations.h +++ b/src/player_relations.h @@ -96,6 +96,8 @@ class PlayerRelationsManager public: PlayerRelationsManager(); + ~PlayerRelationsManager(); + /** * Initialise player relations manager (load config file etc.) */ @@ -143,7 +145,6 @@ public: */ void removePlayer(const std::string &name); - /** * Retrieves the default permissions. */ @@ -154,8 +155,6 @@ public: */ void setDefault(unsigned int permissions); - - /** * Retrieves all known player ignore strategies. * @@ -233,6 +232,7 @@ private: PlayerIgnoreStrategy *mIgnoreStrategy; std::map mRelations; std::list mListeners; + std::vector mIgnoreStrategies; }; -- cgit v1.2.3-70-g09d2 From 3123c8ce5f882f0bfb99a2d2efa45d760237ebcc Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 13:35:02 -0600 Subject: Fixed color previews for item types. Signed-off-by: Ira Rice --- src/gui/setup_colors.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index 148fd679..108067f5 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -251,6 +251,7 @@ void Setup_Colors::action(const gcn::ActionEvent &event) case Palette::ARMS: case Palette::AMMO: mTextPreview->setFont(boldFont); + mTextPreview->setTextColor(col); mTextPreview->setOutline(false); mTextPreview->setShadow(false); break; -- cgit v1.2.3-70-g09d2 From a9b1eccdd2c719f86475c6ce01d4b8eea7dede6c Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 13:56:40 -0600 Subject: Overrode the reset window function in the chat window to also reset the position of the recorder, as well as fixed resetting the help window, and exposing the buy/sell window to being resettable, as well as remembering its previous position. All windows should now be covered by the reset button on the setup pane. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 5 +++-- src/gui/buysell.h | 2 ++ src/gui/chat.cpp | 6 ++++++ src/gui/chat.h | 6 ++++++ src/gui/help.cpp | 13 +++++++------ src/gui/setup.cpp | 2 ++ src/gui/window.h | 2 +- 7 files changed, 27 insertions(+), 9 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 2022b040..4ac06220 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,10 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - setContentSize(x, 2 * y + buyButton->getHeight()); + setDefaultSize(x + getPadding(), (2 * y + buyButton->getHeight() + + getTitleBarHeight()), ImageRect::CENTER); - setLocationRelativeTo(ImageRect::CENTER); + loadWindowState(); requestFocus(); } diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 747066a7..0842c0e1 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -54,4 +54,6 @@ class BuySellDialog : public Window, public gcn::ActionListener Network *mNetwork; }; +extern BuySellDialog *buySellDialog; + #endif diff --git a/src/gui/chat.cpp b/src/gui/chat.cpp index 44e08052..5ff9ed46 100644 --- a/src/gui/chat.cpp +++ b/src/gui/chat.cpp @@ -113,6 +113,12 @@ ChatWindow::~ChatWindow() delete mParty; } +void ChatWindow::resetToDefaultSize() +{ + mRecorder->resetToDefaultSize(); + Window::resetToDefaultSize(); +} + void ChatWindow::chatLog(std::string line, int own, bool ignoreRecord) { // Trim whitespace diff --git a/src/gui/chat.h b/src/gui/chat.h index 28408b93..8b710dc8 100644 --- a/src/gui/chat.h +++ b/src/gui/chat.h @@ -119,6 +119,12 @@ class ChatWindow : public Window, public gcn::ActionListener, */ ~ChatWindow(); + /** + * Reset the chat window and recorder window attached to it to their + * default positions. + */ + void resetToDefaultSize(); + /** * Adds a line of text to our message list. Parameters: * diff --git a/src/gui/help.cpp b/src/gui/help.cpp index fec39199..0974abf7 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -40,16 +40,17 @@ HelpWindow::HelpWindow(): setWindowName(_("Help")); setResizable(true); + setDefaultSize(500, 400, ImageRect::CENTER); + mBrowserBox = new BrowserBox(); mBrowserBox->setOpaque(false); mScrollArea = new ScrollArea(mBrowserBox); Button *okButton = new Button(_("Close"), "close", this); - mScrollArea->setDimension(gcn::Rectangle( - 5, 5, 445, 335 - okButton->getHeight())); - okButton->setPosition( - 450 - okButton->getWidth(), - 345 - okButton->getHeight()); + mScrollArea->setDimension(gcn::Rectangle(5, 5, 445, + 335 - okButton->getHeight())); + okButton->setPosition(450 - okButton->getWidth(), + 345 - okButton->getHeight()); mBrowserBox->setLinkHandler(this); @@ -59,7 +60,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + loadWindowState(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index dc232296..ca6b4010 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -38,6 +38,7 @@ extern Window *chatWindow; extern Window *statusWindow; extern Window *buyDialog; extern Window *sellDialog; +extern Window *buySellDialog; extern Window *inventoryWindow; extern Window *emoteWindow; extern Window *npcTextDialog; @@ -140,6 +141,7 @@ void Setup::action(const gcn::ActionEvent &event) statusWindow->resetToDefaultSize(); buyDialog->resetToDefaultSize(); sellDialog->resetToDefaultSize(); + buySellDialog->resetToDefaultSize(); inventoryWindow->resetToDefaultSize(); emoteWindow->resetToDefaultSize(); npcTextDialog->resetToDefaultSize(); diff --git a/src/gui/window.h b/src/gui/window.h index e04fcfc3..518e1ec2 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -266,7 +266,7 @@ class Window : public gcn::Window, gcn::WidgetListener * Reset the win pos and size to default. Don't forget to set defaults * first. */ - void resetToDefaultSize(); + virtual void resetToDefaultSize(); /** * Gets the layout handler for this window. -- cgit v1.2.3-70-g09d2 From 94495012ea5919cddaf47e7a7818fd8ba4e76708 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Sun, 15 Mar 2009 14:08:14 -0600 Subject: Fixed BuySell dialog to remember its position. For proper configuration saving, this needed a window name set. Signed-off-by: Ira Rice --- src/gui/buysell.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 4ac06220..64ffdc3f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -33,6 +33,7 @@ BuySellDialog::BuySellDialog(Network *network): Window(_("Shop")), mNetwork(network) { + setWindowName("BuySell"); Button *buyButton = 0; static const char *buttonNames[] = { N_("Buy"), N_("Sell"), N_("Cancel"), 0 -- cgit v1.2.3-70-g09d2 From d495617bfba570ebabf2ee8edb6f465145dbe9c0 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Wed, 18 Mar 2009 11:20:42 +0100 Subject: Fixed a broken Mac include for SDL_ttf Reviewed-by: trapdoor --- src/gui/truetypefont.h | 4 ++-- src/openglgraphics.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index de146087..1cf6c2c8 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -26,8 +26,8 @@ #include #include -#ifndef __APPLE__ -#include +#ifdef __APPLE__ +#include #else #include #endif diff --git a/src/openglgraphics.cpp b/src/openglgraphics.cpp index e7e7b204..0ee2bc50 100644 --- a/src/openglgraphics.cpp +++ b/src/openglgraphics.cpp @@ -26,12 +26,12 @@ #include "resources/image.h" +#ifdef USE_OPENGL + #ifdef __APPLE__ #include #endif -#ifdef USE_OPENGL - #ifndef GL_TEXTURE_RECTANGLE_ARB #define GL_TEXTURE_RECTANGLE_ARB 0x84F5 #define GL_MAX_RECTANGLE_TEXTURE_SIZE_ARB 0x84F8 -- cgit v1.2.3-70-g09d2 From 203e995140e710475e1d8a3b512c8fe16a1acd96 Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Wed, 18 Mar 2009 18:54:10 +0100 Subject: Windows compilation fixes --- src/gui/setup_colors.cpp | 2 +- src/gui/truetypefont.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/setup_colors.cpp b/src/gui/setup_colors.cpp index b786a7fa..dcad8670 100644 --- a/src/gui/setup_colors.cpp +++ b/src/gui/setup_colors.cpp @@ -369,7 +369,7 @@ void Setup_Colors::updateColor() Palette::ColorType type = guiPalette->getColorTypeAt(mSelected); Palette::GradientType grad = - static_cast(mGradTypeSlider->getValue()); + static_cast((int)mGradTypeSlider->getValue()); guiPalette->setGradient(type, grad); if (grad == Palette::STATIC) diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 1cf6c2c8..9d6c4ef5 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -29,7 +29,7 @@ #ifdef __APPLE__ #include #else -#include +#include #endif class TextChunk; -- cgit v1.2.3-70-g09d2 From f64903f3f139ba83e94c6260c39f88b8d31b793b Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 14:20:14 -0600 Subject: Fix up the NPC interraction widnows a bit --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 4 ++++ src/gui/buysell.cpp | 16 +++++++++++++--- src/gui/buysell.h | 4 ++++ src/gui/npcintegerdialog.cpp | 2 -- src/gui/npclistdialog.cpp | 3 --- src/gui/npcstringdialog.cpp | 4 +--- src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 4 ++++ src/gui/window.cpp | 2 +- src/net/buysellhandler.cpp | 7 ++----- src/net/playerhandler.cpp | 5 +---- 12 files changed, 44 insertions(+), 21 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index d267e5ad..3107c529 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -247,3 +247,10 @@ void BuyDialog::logic() if (!current_npc) setVisible(false); } + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 2555e139..5e2f0b8f 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -100,6 +100,8 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void logic(); + void setVisible(bool visible); + private: Network *mNetwork; gcn::Button *mBuyButton; @@ -121,4 +123,6 @@ class BuyDialog : public Window, public gcn::ActionListener, Uint32 mMaxItems; }; +extern BuyDialog *buyDialog; + #endif diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 0550a822..75c49b1f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -32,6 +32,7 @@ BuySellDialog::BuySellDialog(Network *network): Window(_("Shop")), mNetwork(network) { + setWindowName("BuySell"); Button *buyButton = 0; static const char *buttonNames[] = { N_("Buy"), N_("Sell"), N_("Cancel"), 0 @@ -48,16 +49,25 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - setContentSize(x, 2 * y + buyButton->getHeight()); + loadWindowState(); - requestFocus(); + setContentSize(x, 2 * y + buyButton->getHeight()); } void BuySellDialog::logic() { Window::logic(); - if (!current_npc) setVisible(false); + if (isVisible() && !current_npc) { + setVisible(false); + } +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); } void BuySellDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 197c1a2b..4b137554 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -49,6 +49,8 @@ class BuySellDialog : public Window, public gcn::ActionListener */ void logic(); + void setVisible(bool visible); + /** * Called when receiving actions from the widgets. */ @@ -58,4 +60,6 @@ class BuySellDialog : public Window, public gcn::ActionListener Network *mNetwork; }; +extern BuySellDialog *buySellDialog; + #endif diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index fad37700..c1460f8d 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -34,8 +34,6 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -extern NpcTextDialog *npcTextDialog; - NpcIntegerDialog::NpcIntegerDialog(Network *network): Window(_("NPC Number Request")), mNetwork(network) { diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 95fe5983..3960cb21 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -37,8 +37,6 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -extern NpcTextDialog *npcTextDialog; - NpcListDialog::NpcListDialog(Network *network): Window(_("NPC")), mNetwork(network) { @@ -69,7 +67,6 @@ NpcListDialog::NpcListDialog(Network *network): layout.setRowHeight(0, Layout::AUTO_SET); loadWindowState(); - resetToDefaultSize(false); } int NpcListDialog::getNumberOfElements() diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 7c9f78af..4d170208 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -34,12 +34,10 @@ #include "../utils/gettext.h" #include "../utils/strprintf.h" -extern NpcTextDialog *npcTextDialog; - NpcStringDialog::NpcStringDialog(Network *network): Window(_("NPC Text Request")), mNetwork(network) { - setWindowName("NPCList"); + setWindowName("NPCString"); mValueField = new TextField(""); gcn::Button *okButton = new Button(_("OK"), "ok", this); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b53a23c1..4cdabe68 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -273,3 +273,10 @@ void SellDialog::logic() if (!current_npc) setVisible(false); } + +void SellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index 3777b91e..3ae5e320 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -86,6 +86,8 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void logic(); + void setVisible(bool visible); + private: /** * Updates the state of buttons and labels. @@ -112,4 +114,6 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener int mAmountItems; }; +extern SellDialog *sellDialog; + #endif diff --git a/src/gui/window.cpp b/src/gui/window.cpp index be63ff21..4bc0e4d0 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -120,7 +120,7 @@ Window::~Window() const std::string &name = mWindowName; // Saving X, Y and Width and Height for resizables in the config - if (!name.empty()) + if (!name.empty() && name != "window") { config.setValue(name + "WinX", getX()); config.setValue(name + "WinY", getY()); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 520a1fe6..dcefe905 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -32,15 +32,12 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/sell.h" #include "../utils/gettext.h" -extern BuyDialog *buyDialog; -extern Window *buySellDialog; -extern SellDialog *sellDialog; - BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { @@ -64,8 +61,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) buyDialog->reset(); sellDialog->setVisible(false); sellDialog->reset(); - buySellDialog->setVisible(true); current_npc = msg->readInt32(); + buySellDialog->setVisible(true); break; case SMSG_NPC_BUY: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 4cc29568..aa0ef16c 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -30,6 +30,7 @@ #include "../units.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/gui.h" #include "../gui/npc_text.h" @@ -49,10 +50,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; -extern Window *buySellDialog; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -- cgit v1.2.3-70-g09d2 From 87a5e7ff9aab0073a0658b543376622febabc630 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 18:06:21 -0600 Subject: Clean up TtemAmount dialog and add an All button --- src/gui/item_amount.cpp | 58 ++++++++++++++++++++++++++----------------------- src/gui/item_amount.h | 2 ++ 2 files changed, 33 insertions(+), 27 deletions(-) (limited to 'src/gui') diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 280f063e..aca7ff52 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -35,19 +35,17 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item) + mItem(item), mUsage(usage), mMax(mItem->getQuantity()) { - const int maxRange = mItem->getQuantity(); - // Integer field mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, maxRange); + mItemAmountTextField->setRange(1, mMax); mItemAmountTextField->setWidth(30); mItemAmountTextField->setActionEventId("Dummy"); mItemAmountTextField->addActionListener(this); // Slider - mItemAmountSlide = new Slider(1.0, maxRange); + mItemAmountSlide = new Slider(1.0, mMax); mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("Slide"); mItemAmountSlide->addActionListener(this); @@ -59,11 +57,13 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): plusButton->setSize(20, 20); Button *okButton = new Button(_("Ok"), "Drop", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); + Button *addAllButton = new Button(_("All"), "All", this); // Set positions place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); + place(4, 0, addAllButton, 2); place(0, 1, mItemAmountSlide, 6); place(4, 2, okButton); place(5, 2, cancelButton); @@ -75,19 +75,15 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): { case AMOUNT_TRADE_ADD: setCaption(_("Select amount of items to trade.")); - okButton->setActionEventId("AddTrade"); break; case AMOUNT_ITEM_DROP: setCaption(_("Select amount of items to drop.")); - okButton->setActionEventId("Drop"); break; case AMOUNT_STORE_ADD: setCaption(_("Select amount of items to store.")); - okButton->setActionEventId("AddStore"); break; case AMOUNT_STORE_REMOVE: - setCaption(_("Select amount of items to remove from storage.")); - okButton->setActionEventId("RemoveStore"); + setCaption(_("Select amount of items to retrieve.")); break; default: break; @@ -122,26 +118,34 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { amount = static_cast(mItemAmountSlide->getValue()); } - else if (event.getId() == "Drop") - { - player_node->dropItem(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "AddTrade") - { - tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "AddStore") + else if (event.getId() == "Ok" || event.getId() == "All") { - storageWindow->addStore(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "RemoveStore") - { - storageWindow->removeStore(mItem, mItemAmountTextField->getValue()); + if (event.getId() == "All") { + amount = mMax; + } + + switch (mUsage) + { + case AMOUNT_TRADE_ADD: + tradeWindow->tradeItem(mItem, amount); + break; + case AMOUNT_ITEM_DROP: + player_node->dropItem(mItem, amount); + break; + case AMOUNT_STORE_ADD: + storageWindow->addStore(mItem, amount); + break; + case AMOUNT_STORE_REMOVE: + storageWindow->removeStore(mItem, amount); + break; + default: + return; + break; + } + scheduleDelete(); } + mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 26cca32c..f0534ec8 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -61,6 +61,8 @@ class ItemAmountWindow : public Window, public gcn::ActionListener IntTextField *mItemAmountTextField; /**< Item amount caption. */ Item *mItem; + int mMax, mUsage; + /** * Item Amount buttons. */ -- cgit v1.2.3-70-g09d2 From 74fa304602e0e7ad845e606db8868b32f1d10864 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 18:06:21 -0600 Subject: Clean up TtemAmount dialog and add an All button --- src/gui/item_amount.cpp | 58 ++++++++++++++++++++++++++----------------------- src/gui/item_amount.h | 2 ++ 2 files changed, 33 insertions(+), 27 deletions(-) (limited to 'src/gui') diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 05dca472..8208d323 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,19 +36,17 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item) + mItem(item), mUsage(usage), mMax(mItem->getQuantity()) { - const int maxRange = mItem->getQuantity(); - // Integer field mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, maxRange); + mItemAmountTextField->setRange(1, mMax); mItemAmountTextField->setWidth(30); mItemAmountTextField->setActionEventId("Dummy"); mItemAmountTextField->addActionListener(this); // Slider - mItemAmountSlide = new Slider(1.0, maxRange); + mItemAmountSlide = new Slider(1.0, mMax); mItemAmountSlide->setHeight(10); mItemAmountSlide->setActionEventId("Slide"); mItemAmountSlide->addActionListener(this); @@ -60,11 +58,13 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): plusButton->setSize(20, 20); Button *okButton = new Button(_("Ok"), "Drop", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); + Button *addAllButton = new Button(_("All"), "All", this); // Set positions place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); + place(4, 0, addAllButton, 2); place(0, 1, mItemAmountSlide, 6); place(4, 2, okButton); place(5, 2, cancelButton); @@ -76,19 +76,15 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): { case AMOUNT_TRADE_ADD: setCaption(_("Select amount of items to trade.")); - okButton->setActionEventId("AddTrade"); break; case AMOUNT_ITEM_DROP: setCaption(_("Select amount of items to drop.")); - okButton->setActionEventId("Drop"); break; case AMOUNT_STORE_ADD: setCaption(_("Select amount of items to store.")); - okButton->setActionEventId("AddStore"); break; case AMOUNT_STORE_REMOVE: - setCaption(_("Select amount of items to remove from storage.")); - okButton->setActionEventId("RemoveStore"); + setCaption(_("Select amount of items to retrieve.")); break; default: break; @@ -123,26 +119,34 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) { amount = static_cast(mItemAmountSlide->getValue()); } - else if (event.getId() == "Drop") - { - player_node->dropItem(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "AddTrade") - { - tradeWindow->tradeItem(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "AddStore") + else if (event.getId() == "Ok" || event.getId() == "All") { - storageWindow->addStore(mItem, mItemAmountTextField->getValue()); - scheduleDelete(); - } - else if (event.getId() == "RemoveStore") - { - storageWindow->removeStore(mItem, mItemAmountTextField->getValue()); + if (event.getId() == "All") { + amount = mMax; + } + + switch (mUsage) + { + case AMOUNT_TRADE_ADD: + tradeWindow->tradeItem(mItem, amount); + break; + case AMOUNT_ITEM_DROP: + player_node->dropItem(mItem, amount); + break; + case AMOUNT_STORE_ADD: + storageWindow->addStore(mItem, amount); + break; + case AMOUNT_STORE_REMOVE: + storageWindow->removeStore(mItem, amount); + break; + default: + return; + break; + } + scheduleDelete(); } + mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index 279c239e..b802f71c 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -62,6 +62,8 @@ class ItemAmountWindow : public Window, public gcn::ActionListener IntTextField *mItemAmountTextField; /**< Item amount caption. */ Item *mItem; + int mMax, mUsage; + /** * Item Amount buttons. */ -- cgit v1.2.3-70-g09d2 From ff3e3d5c6da770391daa4314410e2e716569f7f4 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 18:41:55 -0600 Subject: A few more fixes in the ItemAmount dialog --- src/gui/item_amount.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index aca7ff52..b440dfc0 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -55,7 +55,7 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): minusButton->setSize(20, 20); Button *plusButton = new Button("+", "Plus", this); plusButton->setSize(20, 20); - Button *okButton = new Button(_("Ok"), "Drop", this); + Button *okButton = new Button(_("Ok"), "Ok", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); @@ -144,8 +144,12 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } scheduleDelete(); + return; } + if (amount < 0) amount = 0; + else if (amount > mMax) amount = mMax; + mItemAmountTextField->setValue(amount); mItemAmountSlide->setValue(amount); } -- cgit v1.2.3-70-g09d2 From 6f0d88e781c8b1a75858c769b3641aa8cd477314 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Wed, 18 Mar 2009 14:20:14 -0600 Subject: Fix up the NPC interraction widnows a bit --- src/gui/buy.cpp | 7 +++++++ src/gui/buy.h | 1 + src/gui/buysell.cpp | 16 +++++++++++++++- src/gui/buysell.h | 10 ++++++++++ src/gui/item_amount.cpp | 24 ++++++++++++------------ src/gui/npcstringdialog.cpp | 2 -- src/gui/sell.cpp | 7 +++++++ src/gui/sell.h | 1 + src/gui/storagewindow.h | 4 ++++ src/gui/trade.cpp | 27 ++++++++++++++------------- src/gui/trade.h | 13 ++++++------- src/gui/window.cpp | 2 +- src/net/buysellhandler.cpp | 7 ++----- src/net/playerhandler.cpp | 5 +---- 14 files changed, 81 insertions(+), 45 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 367a041e..ea1df204 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -236,3 +236,10 @@ void BuyDialog::updateButtonsAndLabels() mMoneyLabel->setCaption (strprintf(_("Price: %d GP / Total: %d GP"), price, mMoney - price)); } + +void BuyDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/buy.h b/src/gui/buy.h index 17ab6e19..08697889 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,6 +96,7 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + void setVisible(bool visible); private: Network *mNetwork; gcn::Button *mBuyButton; diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 64ffdc3f..df222797 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -54,8 +54,22 @@ BuySellDialog::BuySellDialog(Network *network): getTitleBarHeight()), ImageRect::CENTER); loadWindowState(); +} + +void BuySellDialog::logic() +{ + Window::logic(); + + if (isVisible() && !current_npc) + setVisible(false); +} + +void BuySellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); - requestFocus(); + if (visible) + requestFocus(); } void BuySellDialog::action(const gcn::ActionEvent &event) diff --git a/src/gui/buysell.h b/src/gui/buysell.h index 0842c0e1..c6989709 100644 --- a/src/gui/buysell.h +++ b/src/gui/buysell.h @@ -46,6 +46,16 @@ class BuySellDialog : public Window, public gcn::ActionListener BuySellDialog(Network *network); /** +<<<<<<< HEAD:src/gui/buysell.h +======= + * Check for current NPC + */ + void logic(); + + void setVisible(bool visible); + + /** +>>>>>>> f64903f... Fix up the NPC interraction widnows a bit:src/gui/buysell.h * Called when receiving actions from the widgets. */ void action(const gcn::ActionEvent &event); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 8208d323..c5b27524 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -36,7 +36,9 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item), mUsage(usage), mMax(mItem->getQuantity()) + mItem(item), + mMax(item->getQuantity()), + mUsage(usage) { // Integer field mItemAmountTextField = new IntTextField(1); @@ -53,10 +55,8 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): // 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 *okButton = new Button(_("Ok"), "Ok", this); Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); @@ -64,10 +64,10 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): place(0, 0, minusButton); place(1, 0, mItemAmountTextField).setPadding(2); place(2, 0, plusButton); - place(4, 0, addAllButton, 2); + place(5, 0, addAllButton); place(0, 1, mItemAmountSlide, 6); - place(4, 2, okButton); - place(5, 2, cancelButton); + place(4, 2, cancelButton); + place(5, 2, okButton); reflowLayout(250, 0); resetAmount(); @@ -101,17 +101,17 @@ void ItemAmountWindow::resetAmount() void ItemAmountWindow::action(const gcn::ActionEvent &event) { - int amount = mItemAmountTextField->getValue(); + int amount = mItemAmountSlide->getValue(); if (event.getId() == "Cancel") { scheduleDelete(); } - else if (event.getId() == "Plus") + else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus") + else if (event.getId() == "Minus" && amount > 0) { amount--; } @@ -121,9 +121,8 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } else if (event.getId() == "Ok" || event.getId() == "All") { - if (event.getId() == "All") { + if (event.getId() == "All") amount = mMax; - } switch (mUsage) { @@ -145,6 +144,7 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) } scheduleDelete(); + return; } mItemAmountTextField->setValue(amount); diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index f50136ba..43d0722f 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -64,9 +64,7 @@ void NpcStringDialog::setValue(const std::string &value) void NpcStringDialog::action(const gcn::ActionEvent &event) { if (event.getId() == "cancel") - { mValueField->setText(""); - } setVisible(false); NPC::mTalking = false; diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index b780b02b..ed023227 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -265,3 +265,10 @@ void SellDialog::updateButtonsAndLabels() (strprintf(_("Price: %d GP / Total: %d GP"), income, mPlayerMoney + income)); } + +void SellDialog::setVisible(bool visible) +{ + Window::setVisible(visible); + + if (visible) requestFocus(); +} diff --git a/src/gui/sell.h b/src/gui/sell.h index 5fb94c4e..c67a25b9 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,6 +82,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + void setVisible(bool visible); private: /** * Updates the state of buttons and labels. diff --git a/src/gui/storagewindow.h b/src/gui/storagewindow.h index 86451bfe..8f02a618 100644 --- a/src/gui/storagewindow.h +++ b/src/gui/storagewindow.h @@ -80,6 +80,10 @@ class StorageWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void removeStore(Item* item, int ammount); + /** + * Closes the Storage Window, as well as telling the server that the + * window has been closed. + */ void close(); private: diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index bae0b651..18b86d4b 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -54,6 +54,7 @@ TradeWindow::TradeWindow(Network *network): setWindowName(_("Trade")); setDefaultSize(342, 209, ImageRect::CENTER); setResizable(true); + setCloseButton(true); setMinWidth(342); setMinHeight(209); @@ -90,10 +91,10 @@ TradeWindow::TradeWindow(Network *network): place(0, 0, mMoneyLabel2); place(1, 0, mMoneyField); place = getPlacer(0, 2); - place(0, 0, mAddButton); - place(1, 0, mOkButton); - place(2, 0, mTradeButton); - place(3, 0, mCancelButton); + place(4, 0, mCancelButton); + place(5, 0, mTradeButton); + place(6, 0, mAddButton); + place(7, 0, mOkButton); Layout &layout = getLayout(); layout.extend(0, 2, 2, 1); layout.setRowHeight(1, Layout::AUTO_SET); @@ -108,14 +109,6 @@ TradeWindow::~TradeWindow() { } -void TradeWindow::widgetResized(const gcn::Event &event) -{ - mMyItemContainer->setWidth(mMyScroll->getWidth()); - mPartnerItemContainer->setWidth(mPartnerScroll->getWidth()); - - Window::widgetResized(event); -} - void TradeWindow::addMoney(int amount) { mMoneyLabel->setCaption(strprintf(_("You get %d GP."), amount)); @@ -212,6 +205,7 @@ void TradeWindow::receivedOk(bool own) void TradeWindow::tradeItem(Item *item, int quantity) { + addItem(item->getId(), true, quantity, item->isEquipment()); MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); @@ -249,7 +243,8 @@ void TradeWindow::action(const gcn::ActionEvent &event) if (mMyInventory->contains(item)) { chatWindow->chatLog(_("Failed adding item. You can not " - "overlap one kind of item on the window."), BY_SERVER); + "overlap one kind of item on the window."), + BY_SERVER); return; } @@ -295,3 +290,9 @@ void TradeWindow::action(const gcn::ActionEvent &event) outMsg.writeInt16(CMSG_TRADE_OK); } } + +void TradeWindow::close() +{ + MessageOut outMsg(mNetwork); + outMsg.writeInt16(CMSG_TRADE_CANCEL_REQUEST); +} diff --git a/src/gui/trade.h b/src/gui/trade.h index f4a6b5cd..c4d3076a 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -56,13 +56,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ ~TradeWindow(); - /** - * Called when resizing the window. - * - * @param event The calling event - */ - void widgetResized(const gcn::Event &event); - /** * Add money to the trade window. */ @@ -119,6 +112,12 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void action(const gcn::ActionEvent &event); + /** + * Closes the Trade Window, as well as telling the server that the + * window has been closed. + */ + void close(); + private: Network *mNetwork; diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 404f5746..13c8f4ce 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -536,7 +536,7 @@ void Window::loadWindowState() void Window::saveWindowState() { // Saving X, Y and Width and Height for resizables in the config - if (!mWindowName.empty()) + if (!mWindowName.empty() && mWindowName != "window") { config.setValue(mWindowName + "WinX", getX()); config.setValue(mWindowName + "WinY", getY()); diff --git a/src/net/buysellhandler.cpp b/src/net/buysellhandler.cpp index 5b8f0b68..287e5400 100644 --- a/src/net/buysellhandler.cpp +++ b/src/net/buysellhandler.cpp @@ -33,15 +33,12 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/sell.h" #include "../utils/gettext.h" -extern BuyDialog *buyDialog; -extern Window *buySellDialog; -extern SellDialog *sellDialog; - BuySellHandler::BuySellHandler() { static const Uint16 _messages[] = { @@ -65,8 +62,8 @@ void BuySellHandler::handleMessage(MessageIn *msg) buyDialog->reset(); sellDialog->setVisible(false); sellDialog->reset(); - buySellDialog->setVisible(true); current_npc = msg->readInt32(); + buySellDialog->setVisible(true); break; case SMSG_NPC_BUY: diff --git a/src/net/playerhandler.cpp b/src/net/playerhandler.cpp index 6533ac1e..60d58a37 100644 --- a/src/net/playerhandler.cpp +++ b/src/net/playerhandler.cpp @@ -30,6 +30,7 @@ #include "../npc.h" #include "../gui/buy.h" +#include "../gui/buysell.h" #include "../gui/chat.h" #include "../gui/gui.h" #include "../gui/npc_text.h" @@ -49,10 +50,6 @@ OkDialog *weightNotice = NULL; OkDialog *deathNotice = NULL; -extern BuyDialog *buyDialog; -extern SellDialog *sellDialog; -extern Window *buySellDialog; - // Max. distance we are willing to scroll after a teleport; // everything beyond will reset the port hard. static const int MAP_TELEPORT_SCROLL_DISTANCE = 8; -- cgit v1.2.3-70-g09d2 From 9d75e8647bd8ac0dc1fd0a6b96b8d68929eeed0e Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Thu, 19 Mar 2009 09:21:59 +0100 Subject: Fixed SDL_ttf include again Please set up your include path if this include doesn't work for you. --- src/gui/truetypefont.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/truetypefont.h b/src/gui/truetypefont.h index 9d6c4ef5..1cf6c2c8 100644 --- a/src/gui/truetypefont.h +++ b/src/gui/truetypefont.h @@ -29,7 +29,7 @@ #ifdef __APPLE__ #include #else -#include +#include #endif class TextChunk; -- cgit v1.2.3-70-g09d2 From dbf402a235d142b44c1936c305f6b3f4c02890bc Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 19 Mar 2009 18:58:11 +0100 Subject: Port Progressbar to TextRenderer --- src/gui/progressbar.cpp | 22 ++++++++-------------- src/gui/progressbar.h | 2 ++ 2 files changed, 10 insertions(+), 14 deletions(-) (limited to 'src/gui') diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 019bf371..f0acfecf 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -23,6 +23,7 @@ #include "gui.h" #include "progressbar.h" +#include "textrenderer.h" #include "../configuration.h" #include "../graphics.h" @@ -34,6 +35,8 @@ ImageRect ProgressBar::mBorder; int ProgressBar::mInstances = 0; float ProgressBar::mAlpha = config.getValue("guialpha", 0.8); +const gcn::Color ProgressBar::TEXT_COLOR = gcn::Color(255, 255, 255); + ProgressBar::ProgressBar(float progress, unsigned int width, unsigned int height, Uint8 red, Uint8 green, Uint8 blue): @@ -129,21 +132,12 @@ void ProgressBar::draw(gcn::Graphics *graphics) if (!mText.empty()) { gcn::Font *f = boldFont; - const int textX = getWidth() / 2; - const int textY = (getHeight() - f->getHeight()) / 2; - - graphics->setFont(f); - - graphics->setColor(gcn::Color(0, 0, 0)); - graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); - graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); - graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); - graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - - graphics->setColor(gcn::Color(255, 255, 255)); - graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); + int textX = getWidth() / 2; + int textY = (getHeight() - f->getHeight()) / 2; - graphics->setColor(gcn::Color(0, 0, 0)); + TextRenderer::renderText(graphics, mText, textX, textY, + gcn::Graphics::CENTER, &TEXT_COLOR, f, true, + false); } } diff --git a/src/gui/progressbar.h b/src/gui/progressbar.h index 5526589c..aa36e02b 100644 --- a/src/gui/progressbar.h +++ b/src/gui/progressbar.h @@ -112,6 +112,8 @@ class ProgressBar : public gcn::Widget static ImageRect mBorder; static int mInstances; static float mAlpha; + + static const gcn::Color TEXT_COLOR; }; #endif -- cgit v1.2.3-70-g09d2 From 0221ab5dc5236e9e35fe6c832a52020551dafa85 Mon Sep 17 00:00:00 2001 From: Majin Sniper Date: Thu, 19 Mar 2009 18:58:11 +0100 Subject: Port Progressbar to TextRenderer --- src/gui/progressbar.cpp | 31 ++++++++----------------------- 1 file changed, 8 insertions(+), 23 deletions(-) (limited to 'src/gui') diff --git a/src/gui/progressbar.cpp b/src/gui/progressbar.cpp index 025e0ec5..1f21df79 100644 --- a/src/gui/progressbar.cpp +++ b/src/gui/progressbar.cpp @@ -25,6 +25,7 @@ #include "gui.h" #include "palette.h" #include "progressbar.h" +#include "textrenderer.h" #include "../configuration.h" #include "../graphics.h" @@ -120,38 +121,22 @@ void ProgressBar::draw(gcn::Graphics *graphics) // The bar if (mProgress > 0) { - graphics->setColor(gcn::Color(mRed, mGreen, mBlue, alpha)); graphics->fillRectangle(gcn::Rectangle(4, 4, - (int) (mProgress * (getWidth() - 8)), - getHeight() - 8)); + (int) (mProgress * (getWidth() - 8)), + getHeight() - 8)); } // The label if (!mText.empty()) { - gcn::Font *f = boldFont; const int textX = getWidth() / 2; - const int textY = (getHeight() - f->getHeight()) / 2; - - gcn::Color tempColor = guiPalette->getColor(Palette::OUTLINE); - - graphics->setFont(f); - - graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, - (int) tempColor.b, alpha)); - graphics->drawText(mText, textX + 1, textY, gcn::Graphics::CENTER); - graphics->drawText(mText, textX, textY - 1, gcn::Graphics::CENTER); - graphics->drawText(mText, textX, textY + 1, gcn::Graphics::CENTER); - graphics->drawText(mText, textX - 1, textY, gcn::Graphics::CENTER); - - tempColor = guiPalette->getColor(Palette::PROGRESS_BAR); - - graphics->setColor(gcn::Color((int) tempColor.r, (int) tempColor.g, - (int) tempColor.b, alpha)); - graphics->drawText(mText, textX, textY, gcn::Graphics::CENTER); + const int textY = (getHeight() - boldFont->getHeight()) / 2; - graphics->setColor(guiPalette->getColor(Palette::TEXT)); + TextRenderer::renderText(graphics, mText, textX, textY, + gcn::Graphics::CENTER, + guiPalette->getColor(Palette::PROGRESS_BAR, + alpha), boldFont, true, false); } } -- cgit v1.2.3-70-g09d2 From 61f4e3b9838ac7a0e06cd066ea07224670f1b851 Mon Sep 17 00:00:00 2001 From: Jared Adams Date: Thu, 19 Mar 2009 16:27:51 -0600 Subject: Make sure positionable dialogs start out centered --- src/gui/buy.cpp | 1 + src/gui/buysell.cpp | 6 ++++-- src/gui/char_select.cpp | 4 ++-- src/gui/char_server.cpp | 2 +- src/gui/confirm_dialog.cpp | 2 +- src/gui/connection.cpp | 2 +- src/gui/help.cpp | 2 +- src/gui/itempopup.cpp | 2 +- src/gui/login.cpp | 2 +- src/gui/npc_text.cpp | 1 + src/gui/npcintegerdialog.cpp | 4 ++++ src/gui/npclistdialog.cpp | 1 + src/gui/npcstringdialog.cpp | 4 ++++ src/gui/ok_dialog.cpp | 2 +- src/gui/register.cpp | 2 +- src/gui/sell.cpp | 1 + src/gui/setup.cpp | 2 +- src/gui/skill.cpp | 2 +- src/gui/speechbubble.cpp | 2 +- src/gui/storagewindow.cpp | 1 + src/gui/updatewindow.cpp | 2 +- src/gui/window.cpp | 20 ++++++++++++++++---- src/gui/window.h | 10 ++++++++++ 23 files changed, 57 insertions(+), 20 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index 3107c529..7e03c591 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -90,6 +90,7 @@ BuyDialog::BuyDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/buysell.cpp b/src/gui/buysell.cpp index 75c49b1f..e6dc7c1f 100644 --- a/src/gui/buysell.cpp +++ b/src/gui/buysell.cpp @@ -49,9 +49,11 @@ BuySellDialog::BuySellDialog(Network *network): } buyButton->requestFocus(); - loadWindowState(); - setContentSize(x, 2 * y + buyButton->getHeight()); + + center(); + setDefaultSize(); + loadWindowState(); } void BuySellDialog::logic() diff --git a/src/gui/char_select.cpp b/src/gui/char_select.cpp index 6d5e082a..709988a3 100644 --- a/src/gui/char_select.cpp +++ b/src/gui/char_select.cpp @@ -127,7 +127,7 @@ CharSelectDialog::CharSelectDialog(Network *network, reflowLayout(250, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mSelectButton->requestFocus(); updatePlayerInfo(); @@ -306,7 +306,7 @@ CharCreateDialog::CharCreateDialog(Window *parent, int slot, Network *network, reflowLayout(225, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mNameField->requestFocus(); } diff --git a/src/gui/char_server.cpp b/src/gui/char_server.cpp index 89bfa93a..22b0e7aa 100644 --- a/src/gui/char_server.cpp +++ b/src/gui/char_server.cpp @@ -85,7 +85,7 @@ ServerSelectDialog::ServerSelectDialog(LoginData *loginData, int nextState): // Select first server mServerList->setSelected(1); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mOkButton->requestFocus(); } diff --git a/src/gui/confirm_dialog.cpp b/src/gui/confirm_dialog.cpp index 0d41525a..a40593e3 100644 --- a/src/gui/confirm_dialog.cpp +++ b/src/gui/confirm_dialog.cpp @@ -85,7 +85,7 @@ ConfirmDialog::ConfirmDialog(const std::string &title, const std::string &msg, if (getParent()) { - setLocationRelativeTo(getParent()); + center(); getParent()->moveToTop(this); } setVisible(true); diff --git a/src/gui/connection.cpp b/src/gui/connection.cpp index a69698e9..981100f9 100644 --- a/src/gui/connection.cpp +++ b/src/gui/connection.cpp @@ -56,7 +56,7 @@ ConnectionDialog::ConnectionDialog(): add(cancelButton); add(mProgressBar); - setLocationRelativeTo(getParent()); + center(); setVisible(true); } diff --git a/src/gui/help.cpp b/src/gui/help.cpp index 30c6a9c4..78b3c93a 100644 --- a/src/gui/help.cpp +++ b/src/gui/help.cpp @@ -58,7 +58,7 @@ HelpWindow::HelpWindow(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); } void HelpWindow::action(const gcn::ActionEvent &event) diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index 0e0dd9e6..efbee6b0 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -89,7 +89,7 @@ ItemPopup::ItemPopup(): add(mItemEffectScroll); add(mItemWeightScroll); - setLocationRelativeTo(getParent()); + center(); } ItemPopup::~ItemPopup() diff --git a/src/gui/login.cpp b/src/gui/login.cpp index e91f7616..414de40e 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -110,7 +110,7 @@ LoginDialog::LoginDialog(LoginData *loginData): place(3, 6, mOkButton); reflowLayout(250, 0); - setLocationRelativeTo(getParent()); + center(); setVisible(true); if (mUserField->getText().empty()) { diff --git a/src/gui/npc_text.cpp b/src/gui/npc_text.cpp index 53c64a54..5bc654b8 100644 --- a/src/gui/npc_text.cpp +++ b/src/gui/npc_text.cpp @@ -61,6 +61,7 @@ NpcTextDialog::NpcTextDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index c1460f8d..643a7ef8 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -61,6 +61,10 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): place(2, 0, cancelButton); place(3, 0, okButton); reflowLayout(175, 0); + + center(); + setDefaultSize(); + loadWindowState(); } void NpcIntegerDialog::setRange(int min, int max) diff --git a/src/gui/npclistdialog.cpp b/src/gui/npclistdialog.cpp index 3960cb21..d280a982 100644 --- a/src/gui/npclistdialog.cpp +++ b/src/gui/npclistdialog.cpp @@ -66,6 +66,7 @@ NpcListDialog::NpcListDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/npcstringdialog.cpp b/src/gui/npcstringdialog.cpp index 4d170208..7ae2d5ed 100644 --- a/src/gui/npcstringdialog.cpp +++ b/src/gui/npcstringdialog.cpp @@ -47,6 +47,10 @@ NpcStringDialog::NpcStringDialog(Network *network): place(1, 1, cancelButton); place(2, 1, okButton); reflowLayout(175, 0); + + center(); + setDefaultSize(); + loadWindowState(); } std::string NpcStringDialog::getValue() diff --git a/src/gui/ok_dialog.cpp b/src/gui/ok_dialog.cpp index 4f4f1117..f1a97b49 100644 --- a/src/gui/ok_dialog.cpp +++ b/src/gui/ok_dialog.cpp @@ -74,7 +74,7 @@ OkDialog::OkDialog(const std::string &title, const std::string &msg, add(mTextArea); add(okButton); - setLocationRelativeTo(getParent()); + center(); setVisible(true); okButton->requestFocus(); } diff --git a/src/gui/register.cpp b/src/gui/register.cpp index c2190501..25c97713 100644 --- a/src/gui/register.cpp +++ b/src/gui/register.cpp @@ -130,7 +130,7 @@ RegisterDialog::RegisterDialog(LoginData *loginData): mServerField->addActionListener(this); mPortField->addActionListener(this); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mUserField->requestFocus(); mUserField->setCaretPosition(mUserField->getText().length()); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 4cdabe68..e1b15bac 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -93,6 +93,7 @@ SellDialog::SellDialog(Network *network): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); + center(); loadWindowState(); } diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 68bc3a4b..872596b0 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -101,7 +101,7 @@ Setup::Setup(): add(panel); - setLocationRelativeTo(getParent()); + center(); setInGame(false); } diff --git a/src/gui/skill.cpp b/src/gui/skill.cpp index 6112f0e3..ed374a31 100644 --- a/src/gui/skill.cpp +++ b/src/gui/skill.cpp @@ -157,7 +157,7 @@ SkillDialog::SkillDialog(): Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); loadWindowState(); } diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 5f05971d..fb0d7684 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -58,7 +58,7 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); - setLocationRelativeTo(getParent()); + center(); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/storagewindow.cpp b/src/gui/storagewindow.cpp index 5981f121..663ad784 100644 --- a/src/gui/storagewindow.cpp +++ b/src/gui/storagewindow.cpp @@ -92,6 +92,7 @@ StorageWindow::StorageWindow(Network *network, int invSize): Layout &layout = getLayout(); layout.setRowHeight(0, mStoreButton->getHeight()); + center(); loadWindowState(); } diff --git a/src/gui/updatewindow.cpp b/src/gui/updatewindow.cpp index 6ec62337..df0a1f80 100644 --- a/src/gui/updatewindow.cpp +++ b/src/gui/updatewindow.cpp @@ -131,7 +131,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); - setLocationRelativeTo(getParent()); + center(); setVisible(true); mCancelButton->requestFocus(); diff --git a/src/gui/window.cpp b/src/gui/window.cpp index 4bc0e4d0..d4665427 100644 --- a/src/gui/window.cpp +++ b/src/gui/window.cpp @@ -67,10 +67,9 @@ Window::Window(const std::string& caption, bool modal, Window *parent, const std mModal(modal), mCloseButton(false), mSticky(false), - mMinWinWidth(100), - mMinWinHeight(40), - mMaxWinWidth(INT_MAX), - mMaxWinHeight(INT_MAX), + mMinWinWidth(100), mDefaultWidth(100), mMaxWinWidth(INT_MAX), + mMinWinHeight(40), mDefaultHeight(40), mMaxWinHeight(INT_MAX), + mDefaultX(100), mDefaultY(100), mSkin(skin) { logger->log("Window::Window(\"%s\")", caption.c_str()); @@ -492,6 +491,14 @@ void Window::setDefaultSize(int defaultX, int defaultY, mDefaultHeight = defaultHeight; } +void Window::setDefaultSize() +{ + mDefaultX = getX(); + mDefaultY = getY(); + mDefaultWidth = getWidth(); + mDefaultHeight = getHeight(); +} + void Window::resetToDefaultSize(bool changePosition) { if (changePosition) setPosition(mDefaultX, mDefaultY); @@ -733,3 +740,8 @@ void Window::reflowLayout(int w, int h) mLayout = NULL; setContentSize(w, h); } + +void Window::center() +{ + setLocationRelativeTo(getParent()); +} diff --git a/src/gui/window.h b/src/gui/window.h index 9977aff4..95fe2174 100644 --- a/src/gui/window.h +++ b/src/gui/window.h @@ -239,6 +239,11 @@ class Window : public gcn::Window, gcn::WidgetListener void setDefaultSize(int defaultX, int defaultY, int defaultWidth, int defaultHeight); + /** + * Set the default win pos and size tot he current ones. + */ + void setDefaultSize(); + /** * Reset the win pos and size to default. Don't forget to set defaults * first. @@ -275,6 +280,11 @@ class Window : public gcn::Window, gcn::WidgetListener */ ContainerPlacer getPlacer(int x, int y); + /** + * Positions the window in the center of it's parent. + */ + void center(); + protected: /** The window container windows add themselves to. */ static WindowContainer *windowContainer; -- cgit v1.2.3-70-g09d2 From a7a8ec7961fd7b1c8f83b92905f85c5a6e0358c0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 17:31:47 -0600 Subject: Some minor cleanups in a few windows and build scripts, as well as fixing tables to correct the highlights to draw where they're supposed to, as well as at the opacity they're supposed to. Signed-off-by: Ira Rice --- aethyra.cbp | 4 +- src/CMakeLists.txt | 8 +-- src/gui/color.cpp | 146 ----------------------------------------------- src/gui/color.h | 136 ------------------------------------------- src/gui/itempopup.cpp | 2 - src/gui/speechbubble.cpp | 2 - src/gui/table.cpp | 25 ++++---- 7 files changed, 18 insertions(+), 305 deletions(-) delete mode 100644 src/gui/color.cpp delete mode 100644 src/gui/color.h (limited to 'src/gui') diff --git a/aethyra.cbp b/aethyra.cbp index 6e71375c..8ccdaa35 100644 --- a/aethyra.cbp +++ b/aethyra.cbp @@ -258,8 +258,6 @@ - - @@ -281,6 +279,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 93bac9ae..0176e617 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -61,10 +61,10 @@ SET(SRCS gui/widgets/tab.h gui/widgets/tabbedarea.cpp gui/widgets/tabbedarea.h + gui/widgets/textpreview.cpp + gui/widgets/textpreview.h gui/browserbox.cpp gui/browserbox.h - gui/buddywindow.cpp - gui/buddywindow.h gui/button.cpp gui/button.h gui/buy.cpp @@ -114,7 +114,7 @@ SET(SRCS gui/itempopup.cpp gui/itempopup.h gui/itemshortcutcontainer.cpp - gui/itemshortcutcontainer.h\ + gui/itemshortcutcontainer.h gui/item_amount.cpp gui/item_amount.h gui/label.cpp @@ -207,8 +207,6 @@ SET(SRCS gui/textbox.h gui/textfield.cpp gui/textfield.h - gui/textpreview.cpp - gui/textpreview.h gui/textrenderer.h gui/trade.cpp gui/trade.h diff --git a/src/gui/color.cpp b/src/gui/color.cpp deleted file mode 100644 index b68bf68b..00000000 --- a/src/gui/color.cpp +++ /dev/null @@ -1,146 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#include "color.h" - -#include "../configuration.h" - -#include "../utils/gettext.h" -#include "../utils/stringutils.h" - -Color::Color() -{ - addColor('C', 0x000000, _("Chat")); - addColor('G', 0xff0000, _("GM")); - addColor('H', 0xebc873, _("Highlight")); - addColor('Y', 0x1fa052, _("Player")); - addColor('W', 0x0000ff, _("Whisper")); - addColor('I', 0xa08527, _("Is")); - addColor('P', 0xff00d8, _("Party")); - addColor('S', 0x8415e2, _("Server")); - addColor('L', 0x919191, _("Logger")); - addColor('<', 0xe50d0d, _("Hyperlink")); - commit(); -} - -Color::~Color() -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - config.setValue("Color" + col->text, toString(col->rgb)); - } -} - -void Color::setColor(const char c, const int rgb) -{ - for (ColVector::iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - col->rgb = rgb; - return; - } - } -} - -int Color::getColor(const char c, bool &valid) const -{ - for (ColVector::const_iterator col = mColVector.begin(), - colEnd = mColVector.end(); - col != colEnd; - ++col) - { - if (col->ch == c) - { - valid = true; - return col->rgb; - } - } - valid = false; - return 0x000000; -} - -std::string Color::getElementAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return ""; - } - return mColVector[i].text; -} - -char Color::getColorCharAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 'C'; - } - return mColVector[i].ch; -} - -void Color::addColor(const char c, const int rgb, const std::string &text) -{ - int trueRgb = (int) config.getValue("Color" + text, rgb); - mColVector.push_back(ColorElem(c, trueRgb, text)); -} - -int Color::getColorAt(int i) -{ - if (i < 0 || i >= getNumberOfElements()) - { - return 0; - } - return mColVector[i].rgb; -} - -void Color::setColorAt(int i, int rgb) -{ - if (i >= 0 && i < getNumberOfElements()) - { - mColVector[i].rgb = rgb; - } -} - -void Color::commit() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->committedRgb = i->rgb; - } -} - -void Color::rollback() -{ - for (ColVector::iterator i = mColVector.begin(), iEnd = mColVector.end(); - i != iEnd; - ++i) - { - i->rgb = i->committedRgb; - } -} diff --git a/src/gui/color.h b/src/gui/color.h deleted file mode 100644 index aca3d045..00000000 --- a/src/gui/color.h +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Configurable text colors - * Copyright (C) 2008 Douglas Boffey - * - * This file is part of Aethyra. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA - */ - -#ifndef COLOR_H -#define COLOR_H - -#include -#include - -#include - -class Color : public gcn::ListModel -{ - public: - /** - * Constructor - */ - Color(); - - /** - * Destructor - */ - ~Color(); - - /** - * Define the color replacement for a character - * - * @param c charater to be replaced - * @param rgb color to replace character - */ - void setColor(const char c, const int rgb); - - /** - * Define the color replacement for a character - * - * @param c character to be replaced - * @param r red component - * @param g green component - * @param b blue component - */ - void setColor(const char c, const int r, const int g, const int b) - { - setColor(c, (r << 16) | (g << 8) | b); - } - - /** - * Return the color associated with a character, if exists - * - * @param c character requested - * @param valid indicate whether character is known - */ - int getColor(const char c, bool &valid) const; - - /** - * Return the number of colors known - */ - int getNumberOfElements() {return mColVector.size(); } - - /** - * Return the name of the ith color - * - * @param i index of color interested in - */ - std::string getElementAt(int i); - - /** - * Get the color for the element at index i in the current color - * model - */ - int getColorAt(int i); - - /** - * Get the character used by the color for the element at index i in - * the current color model - */ - char getColorCharAt(int i); - - /** - * Set the color for the element at index i - */ - void setColorAt(int i, int rgb); - - /** - * Commit the colors - */ - void commit(); - - /** - * Rollback the colors - */ - void rollback(); - - private: - struct ColorElem - { - ColorElem(const char c, const int rgb, const std::string &text) : - ch(c), rgb(rgb), text(text) {} - char ch; - int rgb; - int committedRgb; - std::string text; - }; - typedef std::vector ColVector; - ColVector mColVector; - - /** - * Initialise color - * - * @param c character that needs initialising - * @param rgb default color if not found in config - * @param text identifier of color - */ - void addColor(const char c, const int rgb, const std::string &text); -}; - -extern Color *textColor; - -#endif diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index c76c3750..a4042ae2 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -85,8 +85,6 @@ ItemPopup::ItemPopup(): add(mItemDescScroll); add(mItemEffectScroll); add(mItemWeightScroll); - - setLocationRelativeTo(getParent()); } ItemPopup::~ItemPopup() diff --git a/src/gui/speechbubble.cpp b/src/gui/speechbubble.cpp index 811fddfa..9e4c9234 100644 --- a/src/gui/speechbubble.cpp +++ b/src/gui/speechbubble.cpp @@ -60,8 +60,6 @@ SpeechBubble::SpeechBubble(): add(mCaption); add(mSpeechArea); - - setLocationRelativeTo(getParent()); } void SpeechBubble::setCaption(const std::string &name, const gcn::Color *color) diff --git a/src/gui/table.cpp b/src/gui/table.cpp index fa801865..17d8bfbf 100644 --- a/src/gui/table.cpp +++ b/src/gui/table.cpp @@ -320,29 +320,30 @@ void GuiTable::draw(gcn::Graphics* graphics) widget->setDimension(bounds); - if (!mLinewiseMode && c == mSelectedColumn && r == mSelectedRow) + graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, + (int)(mAlpha * 255.0f))); + + if (mLinewiseMode && r == mSelectedRow && c == 0) + { + graphics->fillRectangle(gcn::Rectangle(0, y_offset, + getWidth(), height)); + } + else if (!mLinewiseMode && + c == mSelectedColumn && r == mSelectedRow) { - graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, - (int)(mAlpha * 127.0f))); - graphics->fillRectangle(bounds); + graphics->fillRectangle(gcn::Rectangle(x_offset, y_offset, + width, height)); } graphics->pushClipArea(bounds); widget->draw(graphics); graphics->popClipArea(); + } x_offset += width; } - if (mLinewiseMode && r == mSelectedRow) - { - graphics->setColor(guiPalette->getColor(Palette::HIGHLIGHT, - (int)(mAlpha * 127.0f))); - graphics->fillRectangle(gcn::Rectangle(0, y_offset, - x_offset, height)); - } - y_offset += height; } -- cgit v1.2.3-70-g09d2 From abeaa1184ae1f30adeeb6684748b3cf8e3f16b11 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 18:13:12 -0600 Subject: Simplified trading dialog controls. Signed-off-by: Ira Rice --- src/gui/button.cpp | 4 ++-- src/gui/trade.cpp | 47 +++++++++++++++++++---------------------------- src/gui/trade.h | 7 +------ 3 files changed, 22 insertions(+), 36 deletions(-) (limited to 'src/gui') diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 592edce5..1b206161 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -74,9 +74,9 @@ Button::Button(const std::string& caption, const std::string &actionEventId, { init(); setActionEventId(actionEventId); - if (listener) { + + if (listener) addActionListener(listener); - } } void Button::init() diff --git a/src/gui/trade.cpp b/src/gui/trade.cpp index 18b86d4b..82ac4647 100644 --- a/src/gui/trade.cpp +++ b/src/gui/trade.cpp @@ -22,6 +22,8 @@ #include +#include + #include "button.h" #include "chat.h" #include "inventorywindow.h" @@ -59,12 +61,12 @@ 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); + std::string longestName = getFont()->getWidth(_("OK")) > + getFont()->getWidth(_("Trade")) ? + _("OK") : _("Trade"); - mTradeButton->setEnabled(false); + mAddButton = new Button(_("Add"), "add", this); + mOkButton = new Button(longestName, "ok", this); mMyItemContainer = new ItemContainer(mMyInventory.get(), 2); mMyItemContainer->setWidth(160); @@ -91,8 +93,6 @@ TradeWindow::TradeWindow(Network *network): place(0, 0, mMoneyLabel2); place(1, 0, mMoneyField); place = getPlacer(0, 2); - place(4, 0, mCancelButton); - place(5, 0, mTradeButton); place(6, 0, mAddButton); place(7, 0, mOkButton); Layout &layout = getLayout(); @@ -102,6 +102,8 @@ TradeWindow::TradeWindow(Network *network): layout.setColWidth(0, Layout::AUTO_SET); layout.setColWidth(1, Layout::AUTO_SET); + mOkButton->setCaption(_("OK")); + loadWindowState(); } @@ -157,7 +159,8 @@ void TradeWindow::reset() { mMyInventory->clear(); mPartnerInventory->clear(); - mTradeButton->setEnabled(false); + mOkButton->setCaption(_("OK")); + mOkButton->setActionEventId("ok"); mOkButton->setEnabled(true); mOkOther = false; mOkMe = false; @@ -166,11 +169,6 @@ void TradeWindow::reset() mMoneyField->setText(""); } -void TradeWindow::setTradeButton(bool enabled) -{ - mTradeButton->setEnabled(enabled); -} - void TradeWindow::receivedOk(bool own) { if (own) @@ -178,13 +176,8 @@ void TradeWindow::receivedOk(bool own) mOkMe = true; if (mOkOther) { - mTradeButton->setEnabled(true); - mOkButton->setEnabled(false); - } - else - { - mTradeButton->setEnabled(false); - mOkButton->setEnabled(false); + mOkButton->setCaption(_("Trade")); + mOkButton->setActionEventId("trade"); } } else @@ -192,20 +185,18 @@ void TradeWindow::receivedOk(bool own) mOkOther = true; if (mOkMe) { - mTradeButton->setEnabled(true); - mOkButton->setEnabled(false); - } - else - { - mTradeButton->setEnabled(false); - mOkButton->setEnabled(true); + mOkButton->setCaption(_("Trade")); + mOkButton->setActionEventId("trade"); } } } void TradeWindow::tradeItem(Item *item, int quantity) { - addItem(item->getId(), true, quantity, item->isEquipment()); + // TODO: Our newer version of eAthena doesn't register this following + // function. Detect the actual server version, and re-enable this + // for that version only. + //addItem(item->getId(), true, quantity, item->isEquipment()); MessageOut outMsg(mNetwork); outMsg.writeInt16(CMSG_TRADE_ITEM_ADD_REQUEST); outMsg.writeInt16(item->getInvIndex()); diff --git a/src/gui/trade.h b/src/gui/trade.h index c4d3076a..76ba5a4c 100644 --- a/src/gui/trade.h +++ b/src/gui/trade.h @@ -86,11 +86,6 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener */ void increaseQuantity(int index, bool own, int quantity); - /** - * Set trade Button disabled - */ - void setTradeButton(bool enabled); - /** * Player received ok message from server */ @@ -130,7 +125,7 @@ class TradeWindow : public Window, gcn::ActionListener, gcn::SelectionListener gcn::Label *mMoneyLabel; gcn::Label *mMoneyLabel2; - gcn::Button *mAddButton, *mOkButton, *mCancelButton, *mTradeButton; + gcn::Button *mAddButton, *mOkButton; ScrollArea *mMyScroll, *mPartnerScroll; gcn::TextField *mMoneyField; bool mOkOther, mOkMe; -- cgit v1.2.3-70-g09d2 From abffda81e5bab1fbf4870238e803bb5bae9d0df0 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:20:11 -0600 Subject: Reformatted the item amount window and the buy/sell windows so that their guis are similarly laid out. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 62 ++++++++++++++++++++++++++++------------- src/gui/buy.h | 9 ++++++ src/gui/gui.cpp | 5 ++++ src/gui/gui.h | 5 ++++ src/gui/inventorywindow.cpp | 2 +- src/gui/item_amount.cpp | 48 ++++++++++++++++++++------------ src/gui/item_amount.h | 7 ++++- src/gui/npcintegerdialog.cpp | 5 ++-- src/gui/sell.cpp | 66 +++++++++++++++++++++++++++++--------------- src/gui/sell.h | 9 ++++++ 10 files changed, 156 insertions(+), 62 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index ea1df204..c2c8cfed 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -22,6 +22,7 @@ #include "button.h" #include "buy.h" +#include "gui.h" #include "label.h" #include "scrollarea.h" #include "shop.h" @@ -39,11 +40,12 @@ #include "../utils/strprintf.h" BuyDialog::BuyDialog(Network *network): - Window(_("Buy")), mNetwork(network), + Window("Buy"), mNetwork(network), mMoney(0), mAmountItems(0), mMaxItems(0) { setWindowName(_("Buy")); setResizable(true); + setCloseButton(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); @@ -52,20 +54,25 @@ BuyDialog::BuyDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mSlider = new Slider(1.0); - mQuantityLabel = new Label("0"); + + mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); + mQuantityLabel->setAlignment(gcn::Graphics::CENTER); mMoneyLabel = new 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); + mAddMaxButton = new Button(_("Max"), "max", this); mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(20, 20); - mDecreaseButton->setSize(20, 20); + mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mBuyButton->setEnabled(false); @@ -75,16 +82,21 @@ BuyDialog::BuyDialog(Network *network): mSlider->addActionListener(this); mShopItemList->addSelectionListener(this); - 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); + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mScrollArea, 8, 5).setPadding(3); place(0, 5, mDecreaseButton); - place(1, 5, mIncreaseButton); - place(3, 5, mBuyButton); - place(4, 5, mQuitButton); + place(1, 5, mSlider, 3); + place(4, 5, mIncreaseButton); + place(5, 5, mQuantityLabel, 2); + place(7, 5, mAddMaxButton); + place(0, 6, mMoneyLabel, 8); + place(0, 7, mItemEffectLabel, 8); + place(0, 8, mItemDescLabel, 8); + place(6, 9, mBuyButton); + place(7, 9, mQuitButton); + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); @@ -124,15 +136,14 @@ void BuyDialog::addItem(int id, int price) void BuyDialog::action(const gcn::ActionEvent &event) { - int selectedItem = mShopItemList->getSelected(); - if (event.getId() == "quit") { - setVisible(false); - current_npc = 0; + close(); return; } + int selectedItem = mShopItemList->getSelected(); + // The following actions require a valid selection if (selectedItem < 0 || selectedItem >= (int) mShopItems->getNumberOfElements()) @@ -157,6 +168,12 @@ void BuyDialog::action(const gcn::ActionEvent &event) mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } + else if (event.getId() == "max") + { + mAmountItems = mMaxItems; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } // 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 _obvious_ way in C++? @@ -241,5 +258,12 @@ void BuyDialog::setVisible(bool visible) { Window::setVisible(visible); - if (visible) requestFocus(); + if (visible) + requestFocus(); +} + +void BuyDialog::close() +{ + setVisible(false); + current_npc = 0; } diff --git a/src/gui/buy.h b/src/gui/buy.h index 08697889..ffd3f5c9 100644 --- a/src/gui/buy.h +++ b/src/gui/buy.h @@ -96,11 +96,20 @@ class BuyDialog : public Window, public gcn::ActionListener, */ void updateButtonsAndLabels(); + /** + * Sets the visibility of this window. + */ void setVisible(bool visible); + + /** + * Closes the Buy Window, as well as resetting the current npc. + */ + void close(); private: Network *mNetwork; gcn::Button *mBuyButton; gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index 434fc1e1..5bdab453 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -241,3 +241,8 @@ void Gui::handleMouseMoved(const gcn::MouseInput &mouseInput) gcn::Gui::handleMouseMoved(mouseInput); mMouseInactivityTimer = 0; } + +const int Gui::getFontHeight() const +{ + return mGuiFont->getHeight(); +} diff --git a/src/gui/gui.h b/src/gui/gui.h index afa358be..609648fd 100644 --- a/src/gui/gui.h +++ b/src/gui/gui.h @@ -77,6 +77,11 @@ class Gui : public gcn::Gui gcn::Font* getFont() const { return mGuiFont; } + /** + * Return game font height. + */ + const int getFontHeight() const; + /** * Return the Font used for "Info Particles", i.e. ones showing, what * you picked up, etc. diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 98916c07..f6e81fc5 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -99,7 +99,7 @@ InventoryWindow::InventoryWindow(int invSize): place(6, 5, mUseButton); Layout &layout = getLayout(); - layout.setRowHeight(0, mDropButton->getHeight()); + layout.setRowHeight(0, mDropButton->getHeight()); loadWindowState(); } diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index c5b27524..5a7cf18f 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -21,8 +21,9 @@ */ #include "button.h" -#include "inttextfield.h" +#include "gui.h" #include "item_amount.h" +#include "label.h" #include "slider.h" #include "storagewindow.h" #include "trade.h" @@ -33,6 +34,7 @@ #include "../localplayer.h" #include "../utils/gettext.h" +#include "../utils/strprintf.h" ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), @@ -40,12 +42,12 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): mMax(item->getQuantity()), mUsage(usage) { + setCloseButton(true); + // Integer field - mItemAmountTextField = new IntTextField(1); - mItemAmountTextField->setRange(1, mMax); - mItemAmountTextField->setWidth(30); - mItemAmountTextField->setActionEventId("Dummy"); - mItemAmountTextField->addActionListener(this); + + mItemAmountLabel = new Label(strprintf("%d / %d", 1, mMax)); + mItemAmountLabel->setAlignment(gcn::Graphics::CENTER); // Slider mItemAmountSlide = new Slider(1.0, mMax); @@ -60,15 +62,22 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); + minusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + plusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + // Set positions + ContainerPlacer place; + place = getPlacer(0, 0); + place(0, 0, minusButton); - place(1, 0, mItemAmountTextField).setPadding(2); - place(2, 0, plusButton); - place(5, 0, addAllButton); - place(0, 1, mItemAmountSlide, 6); - place(4, 2, cancelButton); - place(5, 2, okButton); - reflowLayout(250, 0); + place(1, 0, mItemAmountSlide, 3); + place(4, 0, plusButton); + place(5, 0, mItemAmountLabel, 2); + place(7, 0, addAllButton); + place = getPlacer(0, 1); + place(4, 0, cancelButton); + place(5, 0, okButton); + reflowLayout(225, 0); resetAmount(); @@ -96,7 +105,7 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): void ItemAmountWindow::resetAmount() { - mItemAmountTextField->setValue(1); + mItemAmountLabel->setCaption(strprintf("%d / %d", 1, mMax)); } void ItemAmountWindow::action(const gcn::ActionEvent &event) @@ -105,13 +114,13 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) if (event.getId() == "Cancel") { - scheduleDelete(); + close(); } else if (event.getId() == "Plus" && amount < mMax) { amount++; } - else if (event.getId() == "Minus" && amount > 0) + else if (event.getId() == "Minus" && amount > 1) { amount--; } @@ -147,6 +156,11 @@ void ItemAmountWindow::action(const gcn::ActionEvent &event) return; } - mItemAmountTextField->setValue(amount); + mItemAmountLabel->setCaption(strprintf("%d / %d", amount, mMax)); mItemAmountSlide->setValue(amount); } + +void ItemAmountWindow::close() +{ + scheduleDelete(); +} diff --git a/src/gui/item_amount.h b/src/gui/item_amount.h index b802f71c..34b33b37 100644 --- a/src/gui/item_amount.h +++ b/src/gui/item_amount.h @@ -58,8 +58,13 @@ class ItemAmountWindow : public Window, public gcn::ActionListener */ void resetAmount(); + /** + * Schedules the Item Amount window for deletion. + */ + void close(); + private: - IntTextField *mItemAmountTextField; /**< Item amount caption. */ + gcn::Label *mItemAmountLabel; /**< Item amount caption. */ Item *mItem; int mMax, mUsage; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 5b3e05aa..5332d196 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,6 +21,7 @@ */ #include "button.h" +#include "gui.h" #include "inttextfield.h" #include "npcintegerdialog.h" @@ -47,8 +48,8 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): cancelButton = new Button(_("Cancel"), "cancel", this); resetButton = new Button(_("Reset"), "reset", this); - mDecButton->setSize(20, 20); - mIncButton->setSize(20, 20); + mIncButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecButton->setSize(gui->getFontHeight(), gui->getFontHeight()); ContainerPlacer place; place = getPlacer(0, 0); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index ed023227..47e44ffe 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,6 +21,7 @@ */ #include "button.h" +#include "gui.h" #include "label.h" #include "scrollarea.h" #include "sell.h" @@ -39,12 +40,13 @@ #include "../utils/strprintf.h" SellDialog::SellDialog(Network *network): - Window(_("Sell")), + Window("Sell"), mNetwork(network), mMaxItems(0), mAmountItems(0) { - setWindowName("Sell"); + setWindowName(_("Sell")); setResizable(true); + setCloseButton(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); @@ -54,21 +56,26 @@ SellDialog::SellDialog(Network *network): mShopItemList = new ShopListBox(mShopItems, mShopItems); mScrollArea = new ScrollArea(mShopItemList); + mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); + mSlider = new Slider(1.0); - mQuantityLabel = new Label("0"); + + mQuantityLabel = new Label(strprintf("%d / %d", mAmountItems, mMaxItems)); + mQuantityLabel->setAlignment(gcn::Graphics::CENTER); mMoneyLabel = new 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); + mAddMaxButton = new Button(_("Max"), "max", this); mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(20, 20); - mDecreaseButton->setSize(20, 20); + mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mScrollArea->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); mSellButton->setEnabled(false); @@ -79,16 +86,21 @@ SellDialog::SellDialog(Network *network): mSlider->setActionEventId("slider"); mSlider->addActionListener(this); - 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); + ContainerPlacer place; + place = getPlacer(0, 0); + + place(0, 0, mScrollArea, 8, 5).setPadding(3); place(0, 5, mDecreaseButton); - place(1, 5, mIncreaseButton); - place(3, 5, mSellButton); - place(4, 5, mQuitButton); + place(1, 5, mSlider, 3); + place(4, 5, mIncreaseButton); + place(5, 5, mQuantityLabel, 2); + place(7, 5, mAddMaxButton); + place(0, 6, mMoneyLabel, 8); + place(0, 7, mItemEffectLabel, 8); + place(0, 8, mItemDescLabel, 8); + place(6, 9, mSellButton); + place(7, 9, mQuitButton); + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); @@ -114,9 +126,7 @@ void SellDialog::reset() void SellDialog::addItem(const Item *item, int price) { if (!item) - { return; - } mShopItems->addItem(item->getInvIndex(), item->getId(), item->getQuantity(), price); @@ -126,15 +136,14 @@ void SellDialog::addItem(const Item *item, int price) void SellDialog::action(const gcn::ActionEvent &event) { - int selectedItem = mShopItemList->getSelected(); - if (event.getId() == "quit") { - setVisible(false); - current_npc = 0; + close(); return; } + int selectedItem = mShopItemList->getSelected(); + // The following actions require a valid item selection if (selectedItem == -1 || selectedItem >= (int) mShopItems->getNumberOfElements()) @@ -159,6 +168,12 @@ void SellDialog::action(const gcn::ActionEvent &event) mSlider->setValue(mAmountItems); updateButtonsAndLabels(); } + else if (event.getId() == "max") + { + mAmountItems = mMaxItems; + mSlider->setValue(mAmountItems); + updateButtonsAndLabels(); + } else if (event.getId() == "sell" && mAmountItems > 0 && mAmountItems <= mMaxItems) { @@ -270,5 +285,12 @@ void SellDialog::setVisible(bool visible) { Window::setVisible(visible); - if (visible) requestFocus(); + if (visible) + requestFocus(); +} + +void SellDialog::close() +{ + setVisible(false); + current_npc = 0; } diff --git a/src/gui/sell.h b/src/gui/sell.h index c67a25b9..930f8bc1 100644 --- a/src/gui/sell.h +++ b/src/gui/sell.h @@ -82,7 +82,15 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener */ void setMoney(int amount); + /** + * Sets the visibility of this window. + */ void setVisible(bool visible); + + /** + * Closes the Buy Window, as well as resetting the current npc. + */ + void close(); private: /** * Updates the state of buttons and labels. @@ -92,6 +100,7 @@ class SellDialog : public Window, gcn::ActionListener, gcn::SelectionListener Network *mNetwork; gcn::Button *mSellButton; gcn::Button *mQuitButton; + gcn::Button *mAddMaxButton; gcn::Button *mIncreaseButton; gcn::Button *mDecreaseButton; ShopListBox *mShopItemList; -- cgit v1.2.3-70-g09d2 From 0b076a2dd247cd128599bf24eeba31f372f89585 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:39:12 -0600 Subject: Made the plus and minus buttons in the last commit look more aesthetically pleasing. Signed-off-by: Ira Rice --- src/gui/button.cpp | 6 ++++-- src/gui/buy.cpp | 4 ++-- src/gui/item_amount.cpp | 4 ++-- src/gui/npcintegerdialog.cpp | 4 ++-- src/gui/sell.cpp | 4 ++-- 5 files changed, 12 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/button.cpp b/src/gui/button.cpp index 1b206161..16a2853c 100644 --- a/src/gui/button.cpp +++ b/src/gui/button.cpp @@ -95,8 +95,10 @@ void Button::init() { btn[mode] = resman->getImage(data[mode].file); a = 0; - for (y = 0; y < 3; y++) { - for (x = 0; x < 3; x++) { + for (y = 0; y < 3; y++) + { + for (x = 0; x < 3; x++) + { button[mode].grid[a] = btn[mode]->getSubImage( data[x].gridX, data[y].gridY, data[x + 1].gridX - data[x].gridX + 1, diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index c2c8cfed..a0944086 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -70,8 +70,8 @@ BuyDialog::BuyDialog(Network *network): mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->adjustSize(); + mDecreaseButton->setWidth(mIncreaseButton->getWidth()); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 5a7cf18f..41122229 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -62,8 +62,8 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Button *cancelButton = new Button(_("Cancel"), "Cancel", this); Button *addAllButton = new Button(_("All"), "All", this); - minusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - plusButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + minusButton->adjustSize(); + minusButton->setWidth(plusButton->getWidth()); // Set positions ContainerPlacer place; diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index 5332d196..b4498b31 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -48,8 +48,8 @@ NpcIntegerDialog::NpcIntegerDialog(Network *network): cancelButton = new Button(_("Cancel"), "cancel", this); resetButton = new Button(_("Reset"), "reset", this); - mIncButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mDecButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecButton->adjustSize(); + mDecButton->setWidth(mIncButton->getWidth()); ContainerPlacer place; place = getPlacer(0, 0); diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 47e44ffe..4b58d075 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -73,8 +73,8 @@ SellDialog::SellDialog(Network *network): mItemDescLabel = new Label(strprintf(_("Description: %s"), "")); mItemEffectLabel = new Label(strprintf(_("Effect: %s"), "")); - mIncreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); - mDecreaseButton->setSize(gui->getFontHeight(), gui->getFontHeight()); + mDecreaseButton->adjustSize(); + mDecreaseButton->setWidth(mIncreaseButton->getWidth()); mIncreaseButton->setEnabled(false); mDecreaseButton->setEnabled(false); -- cgit v1.2.3-70-g09d2 From 5022aad7e787777e6fd3e8e34956e53aabb41c21 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:40:58 -0600 Subject: Forgot to remove some now unneeded includes. Signed-off-by: Ira Rice --- src/gui/buy.cpp | 1 - src/gui/item_amount.cpp | 1 - src/gui/npcintegerdialog.cpp | 1 - src/gui/sell.cpp | 1 - 4 files changed, 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/buy.cpp b/src/gui/buy.cpp index a0944086..43c423f1 100644 --- a/src/gui/buy.cpp +++ b/src/gui/buy.cpp @@ -22,7 +22,6 @@ #include "button.h" #include "buy.h" -#include "gui.h" #include "label.h" #include "scrollarea.h" #include "shop.h" diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index 41122229..5b3380c2 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -21,7 +21,6 @@ */ #include "button.h" -#include "gui.h" #include "item_amount.h" #include "label.h" #include "slider.h" diff --git a/src/gui/npcintegerdialog.cpp b/src/gui/npcintegerdialog.cpp index b4498b31..27721f0c 100644 --- a/src/gui/npcintegerdialog.cpp +++ b/src/gui/npcintegerdialog.cpp @@ -21,7 +21,6 @@ */ #include "button.h" -#include "gui.h" #include "inttextfield.h" #include "npcintegerdialog.h" diff --git a/src/gui/sell.cpp b/src/gui/sell.cpp index 4b58d075..591cf97b 100644 --- a/src/gui/sell.cpp +++ b/src/gui/sell.cpp @@ -21,7 +21,6 @@ */ #include "button.h" -#include "gui.h" #include "label.h" #include "scrollarea.h" #include "sell.h" -- cgit v1.2.3-70-g09d2 From c2c0a9fa8476b9335a6198b41cc702da82fd40bd Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 20:55:42 -0600 Subject: Reduced down label code. Signed-off-by: Ira Rice --- src/gui/label.cpp | 30 +----------------------------- 1 file changed, 1 insertion(+), 29 deletions(-) (limited to 'src/gui') diff --git a/src/gui/label.cpp b/src/gui/label.cpp index bab8c465..e8d72ace 100644 --- a/src/gui/label.cpp +++ b/src/gui/label.cpp @@ -20,16 +20,9 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */ - -#include -#include - -#include "gui.h" #include "label.h" #include "palette.h" -#include "../graphics.h" - Label::Label() : gcn::Label() { @@ -42,27 +35,6 @@ Label::Label(const std::string& caption) : void Label::draw(gcn::Graphics* graphics) { - int textX; - int textY = getHeight() / 2 - getFont()->getHeight() / 2; - - switch (getAlignment()) - { - case gcn::Graphics::LEFT: - textX = 0; - break; - case gcn::Graphics::CENTER: - textX = getWidth() / 2; - break; - case gcn::Graphics::RIGHT: - textX = getWidth(); - break; - default: - throw GCN_EXCEPTION("Unknown alignment."); - } - setForegroundColor(guiPalette->getColor(Palette::TEXT)); - - graphics->setFont(getFont()); - graphics->setColor(getForegroundColor()); - graphics->drawText(getCaption(), textX, textY, getAlignment()); + gcn::Label::draw(static_cast(graphics)); } -- cgit v1.2.3-70-g09d2 From 4b7755fcae0de15951c508ec034158007c8b6cf3 Mon Sep 17 00:00:00 2001 From: Ira Rice Date: Thu, 19 Mar 2009 23:05:20 -0600 Subject: Throttle framerates down to save CPU cycles. Now that we're getting high framerates in OpenGL even on older hardware, this should be done to conserve on CPU usage, rather than stressing it with more frames than the monitor can render. Signed-off-by: Ira Rice --- src/game.cpp | 7 +++++-- src/gui/setup_video.cpp | 32 ++++++++++++++++++-------------- src/main.cpp | 4 ++-- 3 files changed, 25 insertions(+), 18 deletions(-) (limited to 'src/gui') diff --git a/src/game.cpp b/src/game.cpp index a346616f..7f0186d1 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -408,8 +408,11 @@ void Game::optionChanged(const std::string &name) { int fpsLimit = (int) config.getValue("fpslimit", 0); - // Calculate new minimum frame time - mMinFrameTime = fpsLimit ? 1000 / fpsLimit : 0; + // Calculate new minimum frame time. If one isn't set, use 60 FPS. + // (1000 / 60 is 16.66) Since the client can go well above the refresh + // rates for monitors now in OpenGL mode, this cutoff is done to help + // conserve on CPU time. + mMinFrameTime = fpsLimit ? 1000 / fpsLimit : 16; // Reset draw time to current time mDrawTime = tick_time * 10; diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index d1d7e4f8..e181f744 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -88,13 +88,15 @@ ModeListModel::ModeListModel() SDL_Rect **modes = SDL_ListModes(NULL, SDL_FULLSCREEN | SDL_HWSURFACE); /* Check which modes are available */ - if (modes == (SDL_Rect **)0) { + if (modes == (SDL_Rect **)0) logger->log("No modes available"); - } else if (modes == (SDL_Rect **)-1) { + else if (modes == (SDL_Rect **)-1) logger->log("All resolutions available"); - } else { + else + { //logger->log("Available Modes"); - for (int i = 0; modes[i]; ++i) { + for (int i = 0; modes[i]; ++i) + { const std::string modeString = toString((int)modes[i]->w) + "x" + toString((int)modes[i]->h); //logger->log(modeString.c_str()); @@ -125,7 +127,7 @@ Setup_Video::Setup_Video(): mSpeechLabel(new Label("")), mAlphaSlider(new Slider(0.2, 1.0)), mFpsCheckBox(new CheckBox(_("FPS Limit:"))), - mFpsSlider(new Slider(10, 200)), + mFpsSlider(new Slider(10, 120)), mFpsField(new TextField), mOriginalScrollLaziness((int) config.getValue("ScrollLaziness", 16)), mScrollLazinessSlider(new Slider(1, 64)), @@ -337,9 +339,11 @@ void Setup_Video::apply() } } #ifdef WIN32 - } else { + } + else + { new OkDialog(_("Switching to full screen"), - _("Restart needed for changes to take effect.")); + _("Restart needed for changes to take effect.")); } #endif config.setValue("screen", fullscreen ? true : false); @@ -352,7 +356,7 @@ void Setup_Video::apply() // OpenGL can currently only be changed by restarting, notify user. new OkDialog(_("Changing OpenGL"), - _("Applying change to OpenGL requires restart.")); + _("Applying change to OpenGL requires restart.")); } // FPS change @@ -450,8 +454,9 @@ void Setup_Video::action(const gcn::ActionEvent &event) { config.setValue("particleeffects", mParticleEffectsCheckBox->isSelected() ? true : false); - new OkDialog(_("Particle effect settings changed"), - _("Restart your client or change maps for the change to take effect.")); + new OkDialog(_("Particle effect settings changed."), + _("Restart your client or change maps " + "for the change to take effect.")); } else if (event.getId() == "pickupchat") { @@ -461,8 +466,7 @@ void Setup_Video::action(const gcn::ActionEvent &event) else if (event.getId() == "pickupparticle") { config.setValue("showpickupparticle", - mPickupParticleCheckBox->isSelected() - ? true : false); + mPickupParticleCheckBox->isSelected() ? true : false); } else if (event.getId() == "speech") { @@ -576,9 +580,9 @@ void Setup_Video::keyPressed(gcn::KeyEvent &event) { mFps = 10; } - else if (mFps > 200) + else if (mFps > 120) { - mFps = 200; + mFps = 120; } mFpsField->setText(toString(mFps)); mFpsSlider->setValue(mFps); diff --git a/src/main.cpp b/src/main.cpp index 7ee2f6b4..a04c8696 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1101,9 +1101,9 @@ int main(int argc, char *argv[]) /* * This loop can really stress the CPU, for no reason since it's * just constantly redrawing the wallpaper. Added the following - * usleep to limit it to 20 FPS during the login sequence + * usleep to limit it to 40 FPS during the login sequence */ - usleep(50000); + usleep(25000); } delete guiPalette; -- cgit v1.2.3-70-g09d2 From fa8a4bf49100c0a1d5b96e00803f43bbbb861100 Mon Sep 17 00:00:00 2001 From: Bjørn Lindeijer Date: Sun, 22 Mar 2009 20:27:48 +0100 Subject: Fixed some compiler warnings Superfluous semicolons, initialization order and signed/unsigned mismatches. --- src/gui/item_amount.cpp | 4 +++- src/gui/palette.cpp | 17 +++++++++-------- src/gui/palette.h | 2 +- 3 files changed, 13 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/item_amount.cpp b/src/gui/item_amount.cpp index b440dfc0..9398dc47 100644 --- a/src/gui/item_amount.cpp +++ b/src/gui/item_amount.cpp @@ -35,7 +35,9 @@ ItemAmountWindow::ItemAmountWindow(int usage, Window *parent, Item *item): Window("", true, parent), - mItem(item), mUsage(usage), mMax(mItem->getQuantity()) + mItem(item), + mMax(mItem->getQuantity()), + mUsage(usage) { // Integer field mItemAmountTextField = new IntTextField(1); diff --git a/src/gui/palette.cpp b/src/gui/palette.cpp index bb2245ce..fec04145 100644 --- a/src/gui/palette.cpp +++ b/src/gui/palette.cpp @@ -44,14 +44,14 @@ const gcn::Color Palette::RAINBOW_COLORS[8] = { /** Number of Elemets of RAINBOW_COLORS */ const int Palette::RAINBOW_COLOR_COUNT = 7; -std::string Palette::getConfigName(const std::string& typeName) +std::string Palette::getConfigName(const std::string &typeName) { std::string res = "Color" + typeName; int pos = 5; - for (int i = 0; i < typeName.length(); i++) + for (size_t i = 0; i < typeName.length(); i++) { - if (i==0 || typeName[i] == '_') + if (i == 0 || typeName[i] == '_') { if (i > 0) { @@ -70,12 +70,13 @@ std::string Palette::getConfigName(const std::string& typeName) return res; } -DEFENUMNAMES(ColorType, COLOR_TYPE); +DEFENUMNAMES(ColorType, COLOR_TYPE) const int Palette::GRADIENT_DELAY = 20; -Palette::Palette() : mColVector(ColVector(TYPE_COUNT)), mGradVector(), - mRainbowTime(tick_time) +Palette::Palette() : + mRainbowTime(tick_time), + mColVector(ColVector(TYPE_COUNT)) { std::string indent = " "; addColor(TEXT, 0x000000, STATIC, _("Text")); @@ -160,7 +161,7 @@ void Palette::setGradient(ColorType type, GradientType grad) ColorElem *elem = &mColVector[type]; if (elem->grad != STATIC && grad == STATIC) { - for (int i = 0; i < mGradVector.size(); i++) + for (size_t i = 0; i < mGradVector.size(); i++) { if (mGradVector[i] == elem) { @@ -251,7 +252,7 @@ void Palette::advanceGradient () int advance = get_elapsed_time(mRainbowTime) / 5; double startColVal, destColVal; - for (int i = 0; i < mGradVector.size(); i++) + for (size_t i = 0; i < mGradVector.size(); i++) { mGradVector[i]->gradientIndex = (mGradVector[i]->gradientIndex + advance) % diff --git a/src/gui/palette.h b/src/gui/palette.h index 77ead4f6..e56bf9c5 100644 --- a/src/gui/palette.h +++ b/src/gui/palette.h @@ -77,7 +77,7 @@ class Palette : public gcn::ListModel ENTRY(MISS)\ ENTRY(TYPE_COUNT)\ - TEXTENUM(ColorType, COLOR_TYPE); + TEXTENUM(ColorType, COLOR_TYPE) /** Colors can be static or can alter over time. */ enum GradientType { -- cgit v1.2.3-70-g09d2