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. --- src/gui/inventorywindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/gui/inventorywindow.cpp') 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")), -- 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/inventorywindow.cpp') 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/inventorywindow.cpp') 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 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/inventorywindow.cpp') 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 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/inventorywindow.cpp') 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 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/inventorywindow.cpp') 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 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/inventorywindow.cpp') 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 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/inventorywindow.cpp') 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