From a19ff6d060d0be8a7cb25bde5c7ad9f0b8027231 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 21 Aug 2011 22:31:24 +0300 Subject: Fix compilation with external guichan library. --- src/gui/equipmentwindow.h | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/gui') diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index 082a9b409..c59600dd8 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -32,6 +32,8 @@ #include +#include + #ifdef __GNUC__ #define A_UNUSED __attribute__ ((unused)) #else -- cgit v1.2.3-70-g09d2 From 07c2eb8ffd62fe69f410cc045efc837441a6b6d4 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 00:42:03 +0300 Subject: Replace typo dont to don't. --- src/gui/popupmenu.cpp | 2 +- src/gui/statuswindow.cpp | 4 ++-- src/gui/widgets/button.cpp | 2 +- src/gui/widgets/scrollarea.cpp | 2 +- src/map.cpp | 2 +- src/net/tmwa/beinghandler.cpp | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index eefa83500..61769bc7e 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -574,7 +574,7 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) if (tab->getRemoveNames()) { mBrowserBox->addRow(strprintf("@@dont remove name|%s@@", - _("Dont remove name"))); + _("Don't remove name"))); } else { diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index fcc324730..a60707f4c 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -356,7 +356,7 @@ void StatusWindow::event(Mana::Channels channel A_UNUSED, if (!lvl) { - // possible server broken and dont send job level, + // possible server broken and don't send job level, // then we fixing it :) if (exp.second < 20000) { @@ -372,7 +372,7 @@ void StatusWindow::event(Mana::Channels channel A_UNUSED, } if (exp.first < oldExp && exp.second >= 20000) - { // possible job level up. but server broken and dont send + { // possible job level up. but server broken and don't send // new job exp limit, we fixing it lvl ++; blocked = true; diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 2d9678a53..41fbc1093 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -202,7 +202,7 @@ void Button::draw(gcn::Graphics *graphics) } else { - // because we dont know where parent windows was moved, + // because we don't know where parent windows was moved, // need recalc vertexes gcn::ClipRectangle &rect = static_cast( graphics)->getTopClip(); diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 08f0b5a70..03f5f8c4c 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -336,7 +336,7 @@ void ScrollArea::drawFrame(gcn::Graphics *graphics) } else { - // because we dont know where parent windows was moved, + // because we don't know where parent windows was moved, // need recalc vertexes gcn::ClipRectangle &rect = static_cast( graphics)->getTopClip(); diff --git a/src/map.cpp b/src/map.cpp index 700f6d0d2..721967b25 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -918,7 +918,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) } } - // Dont draw if gui opacity == 1 + // Don't draw if gui opacity == 1 if (mBeingOpacity && mOpacity != 1.0f) { // Draws beings with a lower opacity to make them visible diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 17503a406..5016b2f8c 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -552,7 +552,7 @@ void BeingHandler::processPlayerMoveUpdate(Net::MessageIn &msg, int msgType) dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); - // because server dont send direction in move packet, + // because server don't send direction in move packet, // we fixing it if (srcX != dstX || srcY != dstY) -- cgit v1.2.3-70-g09d2 From dddfb405de9d04f50d3a95cc3b0ebc3e49884a65 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 03:07:13 +0300 Subject: Add highlight list option. Before in highlight was only player nick. --- src/gui/chatwindow.cpp | 20 +++++++++++++++++++- src/gui/chatwindow.h | 5 +++++ src/gui/setup_chat.cpp | 8 ++++++++ src/gui/widgets/chattab.cpp | 4 +--- src/utils/stringutils.cpp | 17 +++++++++++++++-- src/utils/stringutils.h | 5 ++++- 6 files changed, 52 insertions(+), 7 deletions(-) (limited to 'src/gui') diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 1ef3139db..8896ca028 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -211,6 +211,7 @@ ChatWindow::ChatWindow(): fillCommands(); initTradeFilter(); loadCustomList(); + parseHighlights(); } ChatWindow::~ChatWindow() @@ -1503,7 +1504,7 @@ void ChatWindow::addToAwayLog(std::string line) if (mAwayLog.size() > 20) mAwayLog.pop_front(); - if (line.find(player_node->getName()) != std::string::npos) + if (findI(line, mHighlights) != std::string::npos) mAwayLog.push_back("##9away:" + line); } @@ -1520,3 +1521,20 @@ void ChatWindow::displayAwayLog() ++i; } } + +void ChatWindow::parseHighlights() +{ + mHighlights.clear(); + if (!player_node) + return; + + splitToStringVector(mHighlights, config.getStringValue( + "highlightWords"), ','); + + mHighlights.push_back(player_node->getName()); +} + +bool ChatWindow::findHighlight(std::string &str) +{ + return findI(str, mHighlights) != std::string::npos; +} \ No newline at end of file diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h index b6a37ef79..6e1d548a3 100644 --- a/src/gui/chatwindow.h +++ b/src/gui/chatwindow.h @@ -260,6 +260,10 @@ class ChatWindow : public Window, void clearAwayLog() { mAwayLog.clear(); } + void parseHighlights(); + + bool findHighlight(std::string &str); + protected: friend class ChatTab; friend class WhisperTab; @@ -329,6 +333,7 @@ class ChatWindow : public Window, int mChatColor; unsigned int mChatHistoryIndex; std::list mAwayLog; + std::vector mHighlights; }; extern ChatWindow *chatWindow; diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp index 722a3f8b2..9e75b9c0a 100644 --- a/src/gui/setup_chat.cpp +++ b/src/gui/setup_chat.cpp @@ -120,6 +120,11 @@ Setup_Chat::Setup_Chat() new SetupItemCheckBox(_("Use local time"), "", "useLocalTime", this, "useLocalTimeEvent"); + new SetupItemLabel(_("Other"), "", this); + + new SetupItemTextField(_("Highlight words (separated by comma)"), "", + "highlightWords", this, "highlightWordsEvent"); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } @@ -128,5 +133,8 @@ void Setup_Chat::apply() SetupTabScroll::apply(); if (chatWindow) + { chatWindow->adjustTabSize(); + chatWindow->parseHighlights(); + } } diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 785bdd6be..81c0d277f 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -283,9 +283,7 @@ void ChatTab::chatLog(std::string line, Own own, { if (player_node) { - std::string::size_type pos - = tmp.text.find(player_node->getName()); - if (pos != std::string::npos) + if (chatWindow && chatWindow->findHighlight(tmp.text)) setFlash(2); else setFlash(1); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 13170092e..0243c4315 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -181,9 +181,9 @@ unsigned long findI(std::string str, std::string subStr) return str.find(subStr); } -unsigned long findI(std::string str, std::vector &list) +unsigned long findI(std::string &text, std::vector &list) { - str = toLower(str); + std::string str = toLower(text); unsigned long idx; for (std::vector::iterator i = list.begin(); i != list.end(); ++i) @@ -414,6 +414,19 @@ std::list splitToStringList(const std::string &text, return tokens; } +void splitToStringVector(std::vector &tokens, + const std::string &text, char separator) +{ + std::stringstream ss(text); + std::string item; + while(std::getline(ss, item, separator)) + { + item = trim(item); + if (!item.empty()) + tokens.push_back(item); + } +} + std::string combineDye(std::string file, std::string dye) { if (dye.empty()) diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 94747d2fe..4fe6369e9 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -133,7 +133,7 @@ bool isWordSeparator(char chr); unsigned long findI(std::string str, std::string subStr); -unsigned long findI(std::string str, std::vector &list); +unsigned long findI(std::string &text, std::vector &list); const std::string encodeStr(unsigned int value, unsigned int size = 0); @@ -176,6 +176,9 @@ std::list splitToIntList(const std::string &text, char separator); std::list splitToStringList(const std::string &text, char separator); +void splitToStringVector(std::vector &tokens, + const std::string &text, char separator); + std::string combineDye(std::string file, std::string dye); std::string combineDye2(std::string file, std::string dye); -- cgit v1.2.3-70-g09d2 From 8257d7d35e0dd915512df06cafb810f4611be06a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 04:38:03 +0300 Subject: Fix some theme font colors in different gui elements. Add new color ITEM_NOT_EQUIPPED. --- data/graphics/gui/colors.xml | 1 + data/themes/blackwood/colors.xml | 1 + data/themes/enchilado/colors.xml | 3 ++- data/themes/mana/colors.xml | 1 + data/themes/pink/colors.xml | 1 + data/themes/redandblack/colors.xml | 1 + data/themes/wood/colors.xml | 1 + src/gui/equipmentwindow.cpp | 2 +- src/gui/itempopup.cpp | 3 ++- src/gui/spellpopup.cpp | 5 +++-- src/gui/statuspopup.cpp | 29 +++++++++++++++-------------- src/gui/textpopup.cpp | 10 ++++++---- src/gui/theme.cpp | 1 + src/gui/theme.h | 1 + src/gui/widgets/itemcontainer.cpp | 2 +- src/gui/widgets/label.cpp | 1 + src/gui/widgets/radiobutton.cpp | 1 + 17 files changed, 40 insertions(+), 24 deletions(-) (limited to 'src/gui') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index df42dcdfd..b17e4b80c 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index 51eba63fe..b30121a6b 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index e7ab17da2..839f06772 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -16,11 +16,12 @@ + - + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index 557ba34d5..9e7b73c69 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index b49be8015..2e56c6e3c 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index 50384ce3a..fc026b361 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -16,6 +16,7 @@ + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 13d942d62..67c2da3c7 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -16,6 +16,7 @@ + diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 67ec78e49..ddcd6b81c 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -147,7 +147,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } // Set color black - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(Theme::getThemeColor(Theme::OUTLINE)); // Draw box border g->drawRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); diff --git a/src/gui/itempopup.cpp b/src/gui/itempopup.cpp index f5117ed5a..4d401a627 100644 --- a/src/gui/itempopup.cpp +++ b/src/gui/itempopup.cpp @@ -32,6 +32,7 @@ #include "gui/theme.h" #include "gui/widgets/icon.h" +#include "gui/widgets/label.h" #include "gui/widgets/textbox.h" #include "utils/gettext.h" @@ -54,7 +55,7 @@ ItemPopup::ItemPopup(): mLastColor(1) { // Item Name - mItemName = new gcn::Label; + mItemName = new Label; mItemName->setFont(boldFont); mItemName->setPosition(getPadding(), getPadding()); diff --git a/src/gui/spellpopup.cpp b/src/gui/spellpopup.cpp index 86aeb2206..a918e037d 100644 --- a/src/gui/spellpopup.cpp +++ b/src/gui/spellpopup.cpp @@ -27,6 +27,8 @@ #include "gui/gui.h" #include "gui/palette.h" +#include "gui/widgets/label.h" + #include "textcommand.h" #include "graphics.h" @@ -36,7 +38,6 @@ #include "utils/stringutils.h" #include -#include #include "debug.h" @@ -44,7 +45,7 @@ SpellPopup::SpellPopup(): Popup("SpellPopup") { // Item Name - mItemName = new gcn::Label; + mItemName = new Label; mItemName->setFont(boldFont); mItemName->setPosition(getPadding(), getPadding()); diff --git a/src/gui/statuspopup.cpp b/src/gui/statuspopup.cpp index 08400a916..bb7a295ab 100644 --- a/src/gui/statuspopup.cpp +++ b/src/gui/statuspopup.cpp @@ -28,6 +28,7 @@ #include "gui/palette.h" #include "gui/viewport.h" +#include "gui/widgets/label.h" #include "gui/widgets/layout.h" #include "gui/widgets/textbox.h" @@ -50,51 +51,51 @@ StatusPopup::StatusPopup(): const int fontHeight = getFont()->getHeight(); - mMoveType = new gcn::Label; + mMoveType = new Label; mMoveType->setPosition(getPadding(), getPadding()); - mCrazyMoveType = new gcn::Label; + mCrazyMoveType = new Label; mCrazyMoveType->setPosition(getPadding(), fontHeight + getPadding()); - mMoveToTargetType = new gcn::Label; + mMoveToTargetType = new Label; mMoveToTargetType->setPosition(getPadding(), 2 * fontHeight + getPadding()); - mFollowMode = new gcn::Label; + mFollowMode = new Label; mFollowMode->setPosition(getPadding(), 3 * fontHeight + getPadding()); - mAttackWeaponType = new gcn::Label; + mAttackWeaponType = new Label; mAttackWeaponType->setPosition(getPadding(), 4 + 4 * fontHeight + getPadding()); - mAttackType = new gcn::Label; + mAttackType = new Label; mAttackType->setPosition(getPadding(), 4 + 5 * fontHeight + getPadding()); - mMagicAttackType = new gcn::Label; + mMagicAttackType = new Label; mMagicAttackType->setPosition(getPadding(), 4 + 6 * fontHeight + getPadding()); - mDropCounter = new gcn::Label; + mDropCounter = new Label; mDropCounter->setPosition(getPadding(), 8 + 7 * fontHeight + getPadding()); - mPickUpType = new gcn::Label; + mPickUpType = new Label; mPickUpType->setPosition(getPadding(), 8 + 8 * fontHeight + getPadding()); - mMapType = new gcn::Label; + mMapType = new Label; mMapType->setPosition(getPadding(), 12 + 9 * fontHeight + getPadding()); - mImitationMode = new gcn::Label; + mImitationMode = new Label; mImitationMode->setPosition(getPadding(), 16 + 10 * fontHeight + getPadding()); - mAwayMode = new gcn::Label; + mAwayMode = new Label; mAwayMode->setPosition(getPadding(), 16 + 11 * fontHeight + getPadding()); - mCameraMode = new gcn::Label; + mCameraMode = new Label; mCameraMode->setPosition(getPadding(), 16 + 12 * fontHeight + getPadding()); - mDisableGameModifiers = new gcn::Label; + mDisableGameModifiers = new Label; mDisableGameModifiers->setPosition(getPadding(), 20 + 13 * fontHeight + getPadding()); diff --git a/src/gui/textpopup.cpp b/src/gui/textpopup.cpp index 7f1e0e6b8..1ff601154 100644 --- a/src/gui/textpopup.cpp +++ b/src/gui/textpopup.cpp @@ -26,6 +26,9 @@ #include "gui/gui.h" #include "gui/palette.h" +#include "gui/theme.h" + +#include "gui/widgets/label.h" #include "graphics.h" #include "units.h" @@ -34,7 +37,6 @@ #include "utils/stringutils.h" #include -#include #include "debug.h" @@ -43,13 +45,13 @@ TextPopup::TextPopup(): { const int fontHeight = getFont()->getHeight(); - mText1 = new gcn::Label; + mText1 = new Label; mText1->setPosition(getPadding(), getPadding()); - mText2 = new gcn::Label; + mText2 = new Label; mText2->setPosition(getPadding(), fontHeight + 2 * getPadding()); - mText3 = new gcn::Label; + mText3 = new Label; mText3->setPosition(getPadding(), (2 * fontHeight) + 2 * getPadding()); add(mText1); diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 056eafc0f..e126c0505 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -613,6 +613,7 @@ static int readColorType(const std::string &type) "TAB_PLAYER_FLASH", "SHOP_WARNING", "ITEM_EQUIPPED", + "ITEM_NOT_EQUIPPED", "CHAT", "GM", "PLAYER", diff --git a/src/gui/theme.h b/src/gui/theme.h index 120214232..5fe938a20 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -157,6 +157,7 @@ class Theme : public Palette, public ConfigListener TAB_PLAYER_FLASH, SHOP_WARNING, ITEM_EQUIPPED, + ITEM_NOT_EQUIPPED, CHAT, GM, PLAYER, diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index b79f26226..c2a5ec1b7 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -206,7 +206,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) if (item->isEquipped()) g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); else - g->setColor(gcn::Color(0, 0, 0)); + g->setColor(Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED)); g->drawText(caption, itemX + BOX_WIDTH / 2, itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER); diff --git a/src/gui/widgets/label.cpp b/src/gui/widgets/label.cpp index 16b813dd5..67e8bd12b 100644 --- a/src/gui/widgets/label.cpp +++ b/src/gui/widgets/label.cpp @@ -26,6 +26,7 @@ Label::Label() { + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } Label::Label(const std::string &caption) : diff --git a/src/gui/widgets/radiobutton.cpp b/src/gui/widgets/radiobutton.cpp index a82ec3e8d..e641be323 100644 --- a/src/gui/widgets/radiobutton.cpp +++ b/src/gui/widgets/radiobutton.cpp @@ -46,6 +46,7 @@ RadioButton::RadioButton(const std::string &caption, const std::string &group, gcn::RadioButton(caption, group, marked), mHasMouse(false) { + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); if (instances == 0) { radioNormal = Theme::getImageFromTheme("radioout.png"); -- cgit v1.2.3-70-g09d2 From 7bedfccf5982534a9cbcb2c18ca0d37df117bfc8 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 16:28:01 +0300 Subject: Add new colors to themes: BORDER, BACKGROUND_GRAY, SCROLLBAR_GRAY. --- data/graphics/gui/colors.xml | 3 +++ data/themes/blackwood/colors.xml | 3 +++ data/themes/enchilado/colors.xml | 3 +++ data/themes/mana/colors.xml | 3 +++ data/themes/pink/colors.xml | 3 +++ data/themes/redandblack/colors.xml | 3 +++ data/themes/wood/colors.xml | 3 +++ src/gui/botcheckerwindow.cpp | 1 - src/gui/equipmentwindow.cpp | 2 +- src/gui/outfitwindow.cpp | 5 +++-- src/gui/statuswindow.cpp | 2 -- src/gui/theme.cpp | 3 +++ src/gui/theme.h | 3 +++ src/gui/widgets/desktop.cpp | 7 ++++--- src/gui/widgets/itemcontainer.cpp | 2 ++ src/gui/widgets/scrollarea.cpp | 8 ++++---- src/gui/widgets/spellshortcutcontainer.cpp | 1 - 17 files changed, 41 insertions(+), 14 deletions(-) (limited to 'src/gui') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index b17e4b80c..017b55400 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index b30121a6b..b85ccdfc7 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index 839f06772..38167192d 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index 9e7b73c69..96a929a5e 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index 2e56c6e3c..44aac3527 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index fc026b361..b705241fb 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 67c2da3c7..1080f2022 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -2,6 +2,7 @@ + @@ -11,6 +12,8 @@ + + diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 2851d3d1d..4a8f8cf0d 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -290,7 +290,6 @@ BotCheckerWindow::BotCheckerWindow(): } mPlayerTitleTable = new GuiTable(mPlayerTableTitleModel); - //mPlayerTitleTable->setBackgroundColor(gcn::Color(0xbf, 0xbf, 0xbf)); mPlayerTitleTable->setHeight(1); mPlayerTableTitleModel->set(0, 0, new Label(_("Name"))); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index ddcd6b81c..3284301ec 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -147,7 +147,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) } // Set color black - g->setColor(Theme::getThemeColor(Theme::OUTLINE)); + g->setColor(Theme::getThemeColor(Theme::BORDER)); // Draw box border g->drawRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 09e75856f..79ac88d94 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -32,6 +32,7 @@ #include "playerinfo.h" #include "gui/chatwindow.h" +#include "gui/theme.h" #include "gui/viewport.h" #include "gui/widgets/button.h" @@ -303,9 +304,9 @@ void OutfitWindow::draw(gcn::Graphics *graphics) const int itemX = 10 + ((i % mGridWidth) * mBoxWidth); const int itemY = 25 + ((i / mGridWidth) * mBoxHeight); - graphics->setColor(gcn::Color(0, 0, 0, 64)); + graphics->setColor(Theme::getThemeColor(Theme::BORDER, 64)); graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); - graphics->setColor(gcn::Color(255, 255, 255, 32)); + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, 32)); graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); if (mItems[mCurrentOutfit][i] < 0) diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index a60707f4c..7ab2afa2d 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -889,7 +889,6 @@ void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) col.r = 100; col.g = 100; col.b = 100; -// bar->setColor(new gcn::Color(100, 100, 100)); bar->setColor(col); } else @@ -898,7 +897,6 @@ void StatusWindow::updateStatusBar(ProgressBar *bar, bool percent A_UNUSED) col.r = 255; col.g = 255; col.b = 0; -// bar->setColor(new gcn::Color(255, 255, 0)); bar->setColor(col); } } diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index e126c0505..5fcfeade2 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -599,6 +599,7 @@ static int readColorType(const std::string &type) "TEXT", "SHADOW", "OUTLINE", + "BORDER", "PROGRESS_BAR", "BUTTON", "BUTTON_DISABLED", @@ -608,6 +609,8 @@ static int readColorType(const std::string &type) "GUILD_CHAT_TAB", "GUILD_SOCIAL_TAB", "BACKGROUND", + "BACKGROUND_GRAY", + "SCROLLBAR_GRAY", "HIGHLIGHT", "TAB_FLASH", "TAB_PLAYER_FLASH", diff --git a/src/gui/theme.h b/src/gui/theme.h index 5fe938a20..bdcdafc74 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -143,6 +143,7 @@ class Theme : public Palette, public ConfigListener TEXT = 0, SHADOW, OUTLINE, + BORDER, PROGRESS_BAR, BUTTON, BUTTON_DISABLED, @@ -152,6 +153,8 @@ class Theme : public Palette, public ConfigListener GUILD_CHAT_TAB, GUILD_SOCIAL_TAB, BACKGROUND, + BACKGROUND_GRAY, + SCROLLBAR_GRAY, HIGHLIGHT, TAB_FLASH, TAB_PLAYER_FLASH, diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index cfb757638..40d90ba11 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -53,7 +53,8 @@ Desktop::Desktop() : mVersionLabel = new Label(strprintf("%s (Mana %s)", appName.c_str(), FULL_VERSION)); - mVersionLabel->setBackgroundColor(gcn::Color(255, 255, 255, 128)); + mVersionLabel->setBackgroundColor( + Theme::getThemeColor(Theme::BACKGROUND, 128)); add(mVersionLabel, 25, 2); } @@ -85,7 +86,7 @@ void Desktop::draw(gcn::Graphics *graphics) getHeight() > mWallpaper->getHeight())) { // TODO: Color from palette - g->setColor(gcn::Color(64, 64, 64)); + g->setColor(Theme::getThemeColor(Theme::BACKGROUND_GRAY)); g->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -106,7 +107,7 @@ void Desktop::draw(gcn::Graphics *graphics) } // Draw a thin border under the application version... - g->setColor(gcn::Color(255, 255, 255, 128)); + g->setColor(Theme::getThemeColor(Theme::BACKGROUND, 128)); g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension())); Container::draw(graphics); diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index c2a5ec1b7..c28e4fb4c 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -213,6 +213,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) } } +/* // Draw an orange box around the selected item if (isFocused() && mHighlightedIndex != -1 && mGridColumns) { @@ -221,6 +222,7 @@ void ItemContainer::draw(gcn::Graphics *graphics) g->setColor(gcn::Color(255, 128, 0)); g->drawRectangle(gcn::Rectangle(itemX, itemY, BOX_WIDTH, BOX_HEIGHT)); } +*/ } void ItemContainer::selectNone() diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 03f5f8c4c..3e90bf4c7 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -439,17 +439,17 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics) void ScrollArea::drawVBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getVerticalBarDimension(); - graphics->setColor(gcn::Color(0, 0, 0, 32)); + graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); graphics->fillRectangle(dim); - graphics->setColor(gcn::Color(255, 255, 255)); + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); } void ScrollArea::drawHBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getHorizontalBarDimension(); - graphics->setColor(gcn::Color(0, 0, 0, 32)); + graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); graphics->fillRectangle(dim); - graphics->setColor(gcn::Color(255, 255, 255)); + graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); } void ScrollArea::drawVMarker(gcn::Graphics *graphics) diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 8d5b563bb..7e19b0348 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -106,7 +106,6 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) Graphics *g = static_cast(graphics); - graphics->setColor(gcn::Color(0, 0, 0, 255)); graphics->setFont(getFont()); int selectedId = spellShortcut->getSelectedItem(); -- cgit v1.2.3-70-g09d2 From 2d17967845119a77aec6388bb27c47339052704a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 22 Aug 2011 21:16:34 +0300 Subject: Improve draw perfomance. Add new theme color DROPDOWN_SHADOW. --- data/graphics/gui/colors.xml | 1 + data/themes/blackwood/colors.xml | 1 + data/themes/enchilado/colors.xml | 1 + data/themes/mana/colors.xml | 1 + data/themes/pink/colors.xml | 1 + data/themes/redandblack/colors.xml | 1 + data/themes/wood/colors.xml | 1 + src/gui/equipmentwindow.cpp | 12 +++++---- src/gui/equipmentwindow.h | 2 ++ src/gui/outfitwindow.cpp | 7 ++++-- src/gui/outfitwindow.h | 2 ++ src/gui/serverdialog.cpp | 24 +++++++++++------- src/gui/skilldialog.cpp | 12 ++++++--- src/gui/theme.cpp | 1 + src/gui/theme.h | 1 + src/gui/widgets/avatarlistbox.cpp | 13 ++++++---- src/gui/widgets/avatarlistbox.h | 1 + src/gui/widgets/browserbox.cpp | 10 +++++--- src/gui/widgets/browserbox.h | 4 +++ src/gui/widgets/button.cpp | 7 ++++-- src/gui/widgets/button.h | 2 ++ src/gui/widgets/checkbox.cpp | 4 ++- src/gui/widgets/desktop.cpp | 8 +++--- src/gui/widgets/desktop.h | 2 ++ src/gui/widgets/dropdown.cpp | 22 ++++++++-------- src/gui/widgets/dropdown.h | 3 +++ src/gui/widgets/dropshortcutcontainer.cpp | 14 ++++------- src/gui/widgets/dropshortcutcontainer.h | 2 ++ src/gui/widgets/emoteshortcutcontainer.cpp | 14 ++--------- src/gui/widgets/guitable.cpp | 16 ++++++------ src/gui/widgets/guitable.h | 3 ++- src/gui/widgets/itemcontainer.cpp | 7 ++++-- src/gui/widgets/itemcontainer.h | 2 ++ src/gui/widgets/itemshortcutcontainer.cpp | 14 +++++------ src/gui/widgets/itemshortcutcontainer.h | 3 ++- src/gui/widgets/listbox.cpp | 8 +++--- src/gui/widgets/listbox.h | 1 + src/gui/widgets/scrollarea.cpp | 12 +++++---- src/gui/widgets/scrollarea.h | 3 +++ src/gui/widgets/shoplistbox.cpp | 40 +++++++++++++++++------------- src/gui/widgets/shoplistbox.h | 6 +++++ src/gui/widgets/spellshortcutcontainer.cpp | 3 ++- src/gui/widgets/tab.cpp | 8 +++--- src/gui/widgets/tab.h | 2 ++ src/gui/widgets/textfield.cpp | 4 ++- src/gui/widgets/window.cpp | 8 ++---- 46 files changed, 190 insertions(+), 124 deletions(-) (limited to 'src/gui') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index 017b55400..2091494b3 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index b85ccdfc7..ef06fdc9f 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index 38167192d..f4ae878e4 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index 96a929a5e..c623b8396 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index 44aac3527..6be3ab630 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index b705241fb..8fe785114 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -14,6 +14,7 @@ + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 1080f2022..1f1ac1776 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -14,6 +14,7 @@ + diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 3284301ec..3abd97c73 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -99,6 +99,9 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, add(mPlayerBox); add(mUnequip); + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mBorderColor = Theme::getThemeColor(Theme::BORDER); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } EquipmentWindow::~EquipmentWindow() @@ -138,16 +141,15 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) continue; if (i == mSelected) { - const gcn::Color color = Theme::getThemeColor(Theme::HIGHLIGHT); - + mHighlightColor.a = getGuiAlpha(); // Set color to the highlight color - g->setColor(gcn::Color(color.r, color.g, color.b, getGuiAlpha())); + g->setColor(mHighlightColor); g->fillRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); } // Set color black - g->setColor(Theme::getThemeColor(Theme::BORDER)); + g->setColor(mBorderColor); // Draw box border g->drawRectangle(gcn::Rectangle(box->first, box->second, BOX_WIDTH, BOX_HEIGHT)); @@ -167,7 +169,7 @@ void EquipmentWindow::draw(gcn::Graphics *graphics) g->drawImage(image, box->first + 2, box->second + 2); if (i == EQUIP_PROJECTILE_SLOT) { - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(getForegroundColor()); graphics->drawText(toString(item->getQuantity()), box->first + (BOX_WIDTH / 2), box->second - fontHeight, diff --git a/src/gui/equipmentwindow.h b/src/gui/equipmentwindow.h index c59600dd8..cadf27620 100644 --- a/src/gui/equipmentwindow.h +++ b/src/gui/equipmentwindow.h @@ -116,6 +116,8 @@ class EquipmentWindow : public Window, public gcn::ActionListener bool mForing; Being *mBeing; std::vector*> mBoxes; + gcn::Color mHighlightColor; + gcn::Color mBorderColor; }; extern EquipmentWindow *equipmentWindow; diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 79ac88d94..d3bc6a302 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -78,6 +78,9 @@ OutfitWindow::OutfitWindow(): addMouseListener(this); + mBorderColor = Theme::getThemeColor(Theme::BORDER, 64); + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND, 32); + mPreviousButton = new Button(_("<"), "previous", this); mNextButton = new Button(_(">"), "next", this); mCurrentLabel = new Label(strprintf(_("Outfit: %d"), 1)); @@ -304,9 +307,9 @@ void OutfitWindow::draw(gcn::Graphics *graphics) const int itemX = 10 + ((i % mGridWidth) * mBoxWidth); const int itemY = 25 + ((i / mGridWidth) * mBoxHeight); - graphics->setColor(Theme::getThemeColor(Theme::BORDER, 64)); + graphics->setColor(mBorderColor); graphics->drawRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, 32)); + graphics->setColor(mBackgroundColor); graphics->fillRectangle(gcn::Rectangle(itemX, itemY, 32, 32)); if (mItems[mCurrentOutfit][i] < 0) diff --git a/src/gui/outfitwindow.h b/src/gui/outfitwindow.h index 60634dbdd..8dd5fd6a3 100644 --- a/src/gui/outfitwindow.h +++ b/src/gui/outfitwindow.h @@ -137,6 +137,8 @@ class OutfitWindow : public Window, gcn::ActionListener int mAwayOutfit; Image *mBackgroundImg; + gcn::Color mBorderColor; + gcn::Color mBackgroundColor; static float mAlpha; }; diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 143d3e5a3..763c190d6 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -158,6 +158,10 @@ public: ServersListBox(ServersListModel *model): ListBox(model) { + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mTextColor = Theme::getThemeColor(Theme::TEXT); + mNotSupportedColor = Theme::getThemeColor( + Theme::SERVER_VERSION_NOT_SUPPORTED); } void draw(gcn::Graphics *graphics) @@ -169,20 +173,18 @@ public: updateAlpha(); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); const int height = getRowHeight(); - const gcn::Color unsupported = - Theme::getThemeColor(Theme::SERVER_VERSION_NOT_SUPPORTED, - static_cast(mAlpha * 255.0f)); + mNotSupportedColor.a = static_cast(mAlpha * 255.0f); // Draw filled rectangle around the selected list element if (mSelected >= 0) { - graphics->fillRectangle(gcn::Rectangle(0, height * mSelected, - getWidth(), height)); + graphics->fillRectangle(gcn::Rectangle(0, + height * mSelected, getWidth(), height)); } // Draw the list elements @@ -191,7 +193,7 @@ public: { ServerInfo info = model->getServer(i); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(mTextColor); int top; @@ -212,7 +214,7 @@ public: if (info.version.first > 0) { - graphics->setColor(unsupported); + graphics->setColor(mNotSupportedColor); graphics->drawText(info.version.second, getWidth() - info.version.first - 2, top); @@ -224,6 +226,10 @@ public: { return 2 * getFont()->getHeight(); } +private: + gcn::Color mHighlightColor; + gcn::Color mTextColor; + gcn::Color mNotSupportedColor; }; diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index 896f06cab..ff57195a9 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -152,7 +152,9 @@ public: SkillListBox(SkillModel *model): ListBox(model), mModel(model), - mPopup(new TextPopup()) + mPopup(new TextPopup()), + mHighlightColor(Theme::getThemeColor(Theme::HIGHLIGHT)), + mTextColor(Theme::getThemeColor(Theme::TEXT)) { } @@ -187,8 +189,8 @@ public: Graphics *graphics = static_cast(gcnGraphics); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); // Draw filled rectangle around the selected list element @@ -199,7 +201,7 @@ public: } // Draw the list elements - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(mTextColor); for (int i = 0, y = 1; i < model->getNumberOfElements(); ++i, y += getRowHeight()) @@ -239,6 +241,8 @@ public: private: SkillModel *mModel; TextPopup *mPopup; + gcn::Color mHighlightColor; + gcn::Color mTextColor; }; class SkillTab : public Tab diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 5fcfeade2..15554044d 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -611,6 +611,7 @@ static int readColorType(const std::string &type) "BACKGROUND", "BACKGROUND_GRAY", "SCROLLBAR_GRAY", + "DROPDOWN_SHADOW", "HIGHLIGHT", "TAB_FLASH", "TAB_PLAYER_FLASH", diff --git a/src/gui/theme.h b/src/gui/theme.h index bdcdafc74..4e6a64a6f 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -155,6 +155,7 @@ class Theme : public Palette, public ConfigListener BACKGROUND, BACKGROUND_GRAY, SCROLLBAR_GRAY, + DROPDOWN_SHADOW, HIGHLIGHT, TAB_FLASH, TAB_PLAYER_FLASH, diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 0d35ad188..d4764cba5 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -66,6 +66,9 @@ AvatarListBox::AvatarListBox(AvatarListModel *model): config.addListener("showgender", this); config.addListener("showlevel", this); + + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } AvatarListBox::~AvatarListBox() @@ -102,8 +105,8 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) Graphics *graphics = static_cast(gcnGraphics); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); const int fontHeight = getFont()->getHeight(); @@ -113,7 +116,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) const std::string name = player_node->getName(); // Draw the list elements - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); for (int i = 0, y = 0; i < model->getNumberOfElements(); ++i, y += fontHeight) @@ -206,7 +209,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) if (a->getLevel() > 1) { - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); int minHp = 40 + ((a->getLevel() - 1) * 5); if (minHp < 0) minHp = 40; @@ -283,7 +286,7 @@ void AvatarListBox::draw(gcn::Graphics *gcnGraphics) } } - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); // Draw Name if (a->getType() == MapItem::SEPARATOR) diff --git a/src/gui/widgets/avatarlistbox.h b/src/gui/widgets/avatarlistbox.h index 2fe1dfe3d..afb4abdf5 100644 --- a/src/gui/widgets/avatarlistbox.h +++ b/src/gui/widgets/avatarlistbox.h @@ -62,6 +62,7 @@ public: private: bool mShowGender; bool mShowLevel; + gcn::Color mHighlightColor; static int instances; static Image *onlineIcon; diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 7df70bd04..bb83c1159 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -64,6 +64,10 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque): { setFocusable(true); addMouseListener(this); + + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mHyperLinkColor = Theme::getThemeColor(Theme::HYPERLINK); } BrowserBox::~BrowserBox() @@ -310,7 +314,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mOpaque) { - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); + graphics->setColor(mBackgroundColor); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -319,7 +323,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) { if ((mHighMode & BACKGROUND)) { - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT)); + graphics->setColor(mHighlightColor); graphics->fillRectangle(gcn::Rectangle( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y1, @@ -330,7 +334,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) if ((mHighMode & UNDERLINE)) { - graphics->setColor(Theme::getThemeColor(Theme::HYPERLINK)); + graphics->setColor(mHyperLinkColor); graphics->drawLine( mLinks[mSelectedLink].x1, mLinks[mSelectedLink].y2, diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 6fdb40042..9969bfd3b 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -225,6 +225,10 @@ class BrowserBox : public gcn::Widget, bool mAlwaysUpdate; bool mProcessVersion; bool mEnableImages; + + gcn::Color mBackgroundColor; + gcn::Color mHighlightColor; + gcn::Color mHyperLinkColor; }; #endif diff --git a/src/gui/widgets/button.cpp b/src/gui/widgets/button.cpp index 41fbc1093..7c46ae9df 100644 --- a/src/gui/widgets/button.cpp +++ b/src/gui/widgets/button.cpp @@ -135,6 +135,9 @@ void Button::init() } updateAlpha(); } + mEnabledColor = Theme::getThemeColor(Theme::BUTTON); + mDisabledColor = Theme::getThemeColor(Theme::BUTTON_DISABLED); + mInstances++; } @@ -238,9 +241,9 @@ void Button::draw(gcn::Graphics *graphics) // drawImageRect(0, 0, getWidth(), getHeight(), button[mode]); if (mode == BUTTON_DISABLED) - graphics->setColor(Theme::getThemeColor(Theme::BUTTON_DISABLED)); + graphics->setColor(mDisabledColor); else - graphics->setColor(Theme::getThemeColor(Theme::BUTTON)); + graphics->setColor(mEnabledColor); int textX; int textY = getHeight() / 2 - getFont()->getHeight() / 2; diff --git a/src/gui/widgets/button.h b/src/gui/widgets/button.h index 8c43b6ddd..1b62179b3 100644 --- a/src/gui/widgets/button.h +++ b/src/gui/widgets/button.h @@ -101,6 +101,8 @@ class Button : public gcn::Button, public gcn::WidgetListener int mMode; int mXOffset; int mYOffset; + gcn::Color mEnabledColor; + gcn::Color mDisabledColor; }; #endif diff --git a/src/gui/widgets/checkbox.cpp b/src/gui/widgets/checkbox.cpp index 61e5d9118..65d26e196 100644 --- a/src/gui/widgets/checkbox.cpp +++ b/src/gui/widgets/checkbox.cpp @@ -86,6 +86,8 @@ CheckBox::CheckBox(const std::string &caption, bool selected, if (listener) addActionListener(listener); + + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } CheckBox::~CheckBox() @@ -114,7 +116,7 @@ void CheckBox::draw(gcn::Graphics* graphics) drawBox(graphics); graphics->setFont(getFont()); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); const int h = getHeight() + getHeight() / 2; diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 40d90ba11..46240f76d 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -56,6 +56,9 @@ Desktop::Desktop() : mVersionLabel->setBackgroundColor( Theme::getThemeColor(Theme::BACKGROUND, 128)); add(mVersionLabel, 25, 2); + + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND, 128); + mBackgroundGrayColor = Theme::getThemeColor(Theme::BACKGROUND_GRAY); } Desktop::~Desktop() @@ -85,8 +88,7 @@ void Desktop::draw(gcn::Graphics *graphics) if (!mWallpaper || (getWidth() > mWallpaper->getWidth() || getHeight() > mWallpaper->getHeight())) { - // TODO: Color from palette - g->setColor(Theme::getThemeColor(Theme::BACKGROUND_GRAY)); + g->setColor(mBackgroundGrayColor); g->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -107,7 +109,7 @@ void Desktop::draw(gcn::Graphics *graphics) } // Draw a thin border under the application version... - g->setColor(Theme::getThemeColor(Theme::BACKGROUND, 128)); + g->setColor(mBackgroundColor); g->fillRectangle(gcn::Rectangle(mVersionLabel->getDimension())); Container::draw(graphics); diff --git a/src/gui/widgets/desktop.h b/src/gui/widgets/desktop.h index 962cc3c01..6364ecfe9 100644 --- a/src/gui/widgets/desktop.h +++ b/src/gui/widgets/desktop.h @@ -68,6 +68,8 @@ class Desktop : public Container, gcn::WidgetListener Image *mWallpaper; gcn::Label *mVersionLabel; + gcn::Color mBackgroundColor; + gcn::Color mBackgroundGrayColor; }; #endif // DESKTOP_H diff --git a/src/gui/widgets/dropdown.cpp b/src/gui/widgets/dropdown.cpp index 681d7736e..f01d3fb55 100644 --- a/src/gui/widgets/dropdown.cpp +++ b/src/gui/widgets/dropdown.cpp @@ -101,6 +101,10 @@ DropDown::DropDown(gcn::ListModel *listModel): } instances++; + + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mShadowColor = Theme::getThemeColor(Theme::DROPDOWN_SHADOW); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } DropDown::~DropDown() @@ -163,25 +167,20 @@ void DropDown::draw(gcn::Graphics* graphics) updateAlpha(); const int alpha = static_cast(mAlpha * 255.0f); - gcn::Color faceColor = getBaseColor(); - faceColor.a = alpha; - const gcn::Color *highlightColor = &Theme::getThemeColor(Theme::HIGHLIGHT, - alpha); - gcn::Color shadowColor = faceColor - 0x303030; - shadowColor.a = alpha; + mHighlightColor.a = alpha; + mShadowColor.a = alpha; if (mListBox->getListModel() && mListBox->getSelected() >= 0) { graphics->setFont(getFont()); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); graphics->drawText(mListBox->getListModel()->getElementAt( mListBox->getSelected()), 1, 0); } if (isFocused()) { - if (highlightColor) - graphics->setColor(*highlightColor); + graphics->setColor(mHighlightColor); graphics->drawRectangle(gcn::Rectangle(0, 0, getWidth() - h, h)); } @@ -193,10 +192,9 @@ void DropDown::draw(gcn::Graphics* graphics) // Draw two lines separating the ListBox with selected // element view. - if (highlightColor) - graphics->setColor(*highlightColor); + graphics->setColor(mHighlightColor); graphics->drawLine(0, h, getWidth(), h); - graphics->setColor(shadowColor); + graphics->setColor(mShadowColor); graphics->drawLine(0, h + 1, getWidth(), h + 1); } } diff --git a/src/gui/widgets/dropdown.h b/src/gui/widgets/dropdown.h index d85c3166c..6a22ba497 100644 --- a/src/gui/widgets/dropdown.h +++ b/src/gui/widgets/dropdown.h @@ -87,6 +87,9 @@ class DropDown : public gcn::DropDown */ void drawButton(gcn::Graphics *graphics); + gcn::Color mShadowColor; + gcn::Color mHighlightColor; + // Add own Images. static int instances; static Image *buttons[2][2]; diff --git a/src/gui/widgets/dropshortcutcontainer.cpp b/src/gui/widgets/dropshortcutcontainer.cpp index 92f02c78f..b628cf2d4 100644 --- a/src/gui/widgets/dropshortcutcontainer.cpp +++ b/src/gui/widgets/dropshortcutcontainer.cpp @@ -73,6 +73,8 @@ DropShortcutContainer::DropShortcutContainer(): mBoxHeight = 1; mBoxWidth = 1; } + mEquipedColor = Theme::getThemeColor(Theme::ITEM_EQUIPPED); + mUnEquipedColor = Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED); } DropShortcutContainer::~DropShortcutContainer() @@ -110,12 +112,6 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) if (mBackgroundImg) g->drawImage(mBackgroundImg, itemX, itemY); -/* // Draw item keyboard shortcut. - const char *key = SDL_GetKeyName( - (SDLKey) keyboard.getKeyValue(keyboard.KEY_SHORTCUT_1 + i)); - graphics->setColor(guiPalette->getColor(Palette::TEXT)); - g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); -*/ if (dropShortcut->getItem(i) < 0) continue; @@ -142,11 +138,11 @@ void DropShortcutContainer::draw(gcn::Graphics *graphics) image->setAlpha(1.0f); g->drawImage(image, itemX, itemY); if (item->isEquipped()) - g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); + g->setColor(mEquipedColor); else - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(mUnEquipedColor); g->drawText(caption, itemX + mBoxWidth / 2, - itemY + mBoxHeight - 14, gcn::Graphics::CENTER); + itemY + mBoxHeight - 14, gcn::Graphics::CENTER); } } } diff --git a/src/gui/widgets/dropshortcutcontainer.h b/src/gui/widgets/dropshortcutcontainer.h index 723b215cf..b2d63a7dd 100644 --- a/src/gui/widgets/dropshortcutcontainer.h +++ b/src/gui/widgets/dropshortcutcontainer.h @@ -84,6 +84,8 @@ class DropShortcutContainer : public ShortcutContainer Item *mItemMoved; ItemPopup *mItemPopup; + gcn::Color mEquipedColor; + gcn::Color mUnEquipedColor; }; #endif diff --git a/src/gui/widgets/emoteshortcutcontainer.cpp b/src/gui/widgets/emoteshortcutcontainer.cpp index 5bb972adc..5aced193f 100644 --- a/src/gui/widgets/emoteshortcutcontainer.cpp +++ b/src/gui/widgets/emoteshortcutcontainer.cpp @@ -80,6 +80,7 @@ EmoteShortcutContainer::EmoteShortcutContainer(): mBoxHeight = 1; mBoxWidth = 1; } + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } EmoteShortcutContainer::~EmoteShortcutContainer() @@ -118,20 +119,9 @@ void EmoteShortcutContainer::draw(gcn::Graphics *graphics) std::string key = keyboard.getKeyValueString( keyboard.KEY_EMOTE_1 + i); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); g->drawText(key, emoteX + 2, emoteY + 2, gcn::Graphics::LEFT); -/* - if (emoteShortcut->getEmote(i) - && static_cast(emoteShortcut->getEmote(i)) - 1 - < mEmoteImg.size() - && mEmoteImg[emoteShortcut->getEmote(i) - 1]) - { - mEmoteImg[emoteShortcut->getEmote(i) - 1]->draw(g, emoteX + 2, - emoteY + 10); - } -*/ - if (i < mEmoteImg.size() && mEmoteImg[i] && mEmoteImg[i]->sprite) mEmoteImg[i]->sprite->draw(g, emoteX + 2, emoteY + 10); } diff --git a/src/gui/widgets/guitable.cpp b/src/gui/widgets/guitable.cpp index e25e0bb8c..e02eda88c 100644 --- a/src/gui/widgets/guitable.cpp +++ b/src/gui/widgets/guitable.cpp @@ -88,17 +88,17 @@ void GuiTableActionListener::action(const gcn::ActionEvent } -GuiTable::GuiTable(TableModel *initial_model, gcn::Color background, - bool opacity) : +GuiTable::GuiTable(TableModel *initial_model, bool opacity) : mLinewiseMode(false), mWrappingEnabled(false), mOpaque(opacity), - mBackgroundColor(background), mModel(NULL), mSelectedRow(0), mSelectedColumn(0), mTopWidget(NULL) { + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); setModel(initial_model); setFocusable(true); @@ -292,8 +292,8 @@ void GuiTable::draw(gcn::Graphics* graphics) if (mOpaque) { - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND, - static_cast(mAlpha * 255.0f))); + mBackgroundColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mBackgroundColor); graphics->fillRectangle(gcn::Rectangle(0, 0, getWidth(), getHeight())); } @@ -304,7 +304,7 @@ void GuiTable::draw(gcn::Graphics* graphics) first_row = 0; unsigned rows_nr = 1 + (getHeight() / getRowHeight()); // May overestimate - // by one. + // by one. unsigned max_rows_nr; if (mModel->getRows() < first_row) @@ -343,8 +343,8 @@ void GuiTable::draw(gcn::Graphics* graphics) widget->setDimension(bounds); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); if (mSelectedRow > 0) { diff --git a/src/gui/widgets/guitable.h b/src/gui/widgets/guitable.h index c4fab6a0d..d248c4820 100644 --- a/src/gui/widgets/guitable.h +++ b/src/gui/widgets/guitable.h @@ -58,7 +58,6 @@ class GuiTable : public gcn::Widget, public: GuiTable(TableModel * initial_model = NULL, - gcn::Color background = 0xffffff, bool opacity = true); virtual ~GuiTable(); @@ -190,6 +189,8 @@ private: /** Vector for compactness; used as a list in practice. */ std::vector mActionListeners; + + gcn::Color mHighlightColor; }; diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index c28e4fb4c..91b674018 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -118,6 +118,9 @@ ItemContainer::ItemContainer(Inventory *inventory, bool forceQuantity): if (!mSelImg) logger->log1("Error: Unable to load selection.png"); + mEquipedColor = Theme::getThemeColor(Theme::ITEM_EQUIPPED); + mUnEquipedColor = Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED); + addKeyListener(this); addMouseListener(this); addWidgetListener(this); @@ -204,9 +207,9 @@ void ItemContainer::draw(gcn::Graphics *graphics) caption = "Eq."; if (item->isEquipped()) - g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); + g->setColor(mEquipedColor); else - g->setColor(Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED)); + g->setColor(mUnEquipedColor); g->drawText(caption, itemX + BOX_WIDTH / 2, itemY + BOX_HEIGHT - 14, gcn::Graphics::CENTER); diff --git a/src/gui/widgets/itemcontainer.h b/src/gui/widgets/itemcontainer.h index 5fd897a29..df7de63ee 100644 --- a/src/gui/widgets/itemcontainer.h +++ b/src/gui/widgets/itemcontainer.h @@ -202,6 +202,8 @@ class ItemContainer : public gcn::Widget, typedef SelectionListenerList::iterator SelectionListenerIterator; SelectionListenerList mSelectionListeners; + gcn::Color mEquipedColor; + gcn::Color mUnEquipedColor; }; #endif diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 328d5ae4d..79685fe45 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -77,6 +77,9 @@ ItemShortcutContainer::ItemShortcutContainer(unsigned number): mBoxHeight = 1; mBoxWidth = 1; } + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + mEquipedColor = Theme::getThemeColor(Theme::ITEM_EQUIPPED); + mUnEquipedColor = Theme::getThemeColor(Theme::ITEM_NOT_EQUIPPED); } ItemShortcutContainer::~ItemShortcutContainer() @@ -119,7 +122,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) // Draw item keyboard shortcut. std::string key = keyboard.getKeyValueString( keyboard.KEY_SHORTCUT_1 + i); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); g->drawText(key, itemX + 2, itemY + 2, gcn::Graphics::LEFT); @@ -154,14 +157,9 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) image->setAlpha(1.0f); g->drawImage(image, itemX, itemY); if (item->isEquipped()) - { - g->setColor(Theme::getThemeColor( - Theme::ITEM_EQUIPPED)); - } + g->setColor(mEquipedColor); else - { - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); - } + g->setColor(mUnEquipedColor); g->drawText(caption, itemX + mBoxWidth / 2, itemY + mBoxHeight - 14, gcn::Graphics::CENTER); } diff --git a/src/gui/widgets/itemshortcutcontainer.h b/src/gui/widgets/itemshortcutcontainer.h index 7eac431ec..e6b32c6f8 100644 --- a/src/gui/widgets/itemshortcutcontainer.h +++ b/src/gui/widgets/itemshortcutcontainer.h @@ -88,7 +88,8 @@ class ItemShortcutContainer : public ShortcutContainer ItemPopup *mItemPopup; SpellPopup *mSpellPopup; + gcn::Color mEquipedColor; + gcn::Color mUnEquipedColor; }; -//extern SpellManager *spellManager; #endif diff --git a/src/gui/widgets/listbox.cpp b/src/gui/widgets/listbox.cpp index de8707406..53299ca46 100644 --- a/src/gui/widgets/listbox.cpp +++ b/src/gui/widgets/listbox.cpp @@ -41,6 +41,8 @@ float ListBox::mAlpha = 1.0; ListBox::ListBox(gcn::ListModel *listModel): gcn::ListBox(listModel) { + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } ListBox::~ListBox() @@ -63,8 +65,8 @@ void ListBox::draw(gcn::Graphics *graphics) updateAlpha(); - graphics->setColor(Theme::getThemeColor(Theme::HIGHLIGHT, - static_cast(mAlpha * 255.0f))); + mHighlightColor.a = static_cast(mAlpha * 255.0f); + graphics->setColor(mHighlightColor); graphics->setFont(getFont()); const int height = getRowHeight(); @@ -77,7 +79,7 @@ void ListBox::draw(gcn::Graphics *graphics) } // Draw the list elements - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); for (int i = 0, y = 0; i < mListModel->getNumberOfElements(); ++i, y += height) { diff --git a/src/gui/widgets/listbox.h b/src/gui/widgets/listbox.h index 5f8c20059..418b83f58 100644 --- a/src/gui/widgets/listbox.h +++ b/src/gui/widgets/listbox.h @@ -73,6 +73,7 @@ class ListBox : public gcn::ListBox void mouseDragged(gcn::MouseEvent &event); protected: + gcn::Color mHighlightColor; static float mAlpha; }; diff --git a/src/gui/widgets/scrollarea.cpp b/src/gui/widgets/scrollarea.cpp index 3e90bf4c7..2796d3ab2 100644 --- a/src/gui/widgets/scrollarea.cpp +++ b/src/gui/widgets/scrollarea.cpp @@ -73,7 +73,6 @@ ScrollArea::ScrollArea(gcn::Widget *widget): mDrawWidth(0), mDrawHeight(0) { -// addWidgetListener(this); init(); } @@ -219,6 +218,9 @@ void ScrollArea::init() } instances++; + + mGray = Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32); + mBackground = Theme::getThemeColor(Theme::BACKGROUND); } void ScrollArea::logic() @@ -439,17 +441,17 @@ void ScrollArea::drawRightButton(gcn::Graphics *graphics) void ScrollArea::drawVBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getVerticalBarDimension(); - graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); + graphics->setColor(mGray); graphics->fillRectangle(dim); - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); + graphics->setColor(mBackground); } void ScrollArea::drawHBar(gcn::Graphics *graphics) { const gcn::Rectangle dim = getHorizontalBarDimension(); - graphics->setColor(Theme::getThemeColor(Theme::SCROLLBAR_GRAY, 32)); + graphics->setColor(mGray); graphics->fillRectangle(dim); - graphics->setColor(Theme::getThemeColor(Theme::BACKGROUND)); + graphics->setColor(mBackground); } void ScrollArea::drawVMarker(gcn::Graphics *graphics) diff --git a/src/gui/widgets/scrollarea.h b/src/gui/widgets/scrollarea.h index 440fcec15..095010f3c 100644 --- a/src/gui/widgets/scrollarea.h +++ b/src/gui/widgets/scrollarea.h @@ -156,6 +156,9 @@ class ScrollArea : public gcn::ScrollArea, public gcn::WidgetListener int mYOffset; int mDrawWidth; int mDrawHeight; + + gcn::Color mGray; + gcn::Color mBackground; }; #endif diff --git a/src/gui/widgets/shoplistbox.cpp b/src/gui/widgets/shoplistbox.cpp index 2fe28181b..793491808 100644 --- a/src/gui/widgets/shoplistbox.cpp +++ b/src/gui/widgets/shoplistbox.cpp @@ -50,9 +50,7 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel): mShopItems(0) { mRowHeight = getFont()->getHeight(); - mPriceCheck = true; - - mItemPopup = new ItemPopup; + init(); } ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel): @@ -61,9 +59,17 @@ ShopListBox::ShopListBox(gcn::ListModel *listModel, ShopItems *shopListModel): mShopItems(shopListModel) { mRowHeight = std::max(getFont()->getHeight(), ITEM_ICON_SIZE); - mPriceCheck = true; + init(); +} +void ShopListBox::init() +{ + mPriceCheck = true; mItemPopup = new ItemPopup; + mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); + mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); + mWarningColor = Theme::getThemeColor(Theme::SHOP_WARNING); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } void ShopListBox::setPlayersMoney(int money) @@ -80,8 +86,7 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) mAlpha = Client::getGuiAlpha(); int alpha = static_cast(mAlpha * 255.0f); - const gcn::Color* highlightColor = - &Theme::getThemeColor(Theme::HIGHLIGHT, alpha); + mHighlightColor.a = alpha; Graphics *graphics = static_cast(gcnGraphics); @@ -93,29 +98,30 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) ++i, y += mRowHeight) { gcn::Color temp; - const gcn::Color* backgroundColor = - &Theme::getThemeColor(Theme::BACKGROUND, alpha); + gcn::Color* backgroundColor = &mBackgroundColor; + mBackgroundColor.a = alpha; if (mShopItems && mShopItems->at(i) && mPlayerMoney < mShopItems->at(i)->getPrice() && mPriceCheck) { if (i != mSelected) { - backgroundColor = &Theme::getThemeColor(Theme::SHOP_WARNING, - alpha); + backgroundColor = &mWarningColor; + backgroundColor->a = alpha; } else { - temp = Theme::getThemeColor(Theme::SHOP_WARNING, alpha); - temp.r = (temp.r + highlightColor->r) / 2; - temp.g = (temp.g + highlightColor->g) / 2; - temp.b = (temp.g + highlightColor->b) / 2; + temp = mWarningColor; + temp.r = (temp.r + mHighlightColor.r) / 2; + temp.g = (temp.g + mHighlightColor.g) / 2; + temp.b = (temp.g + mHighlightColor.b) / 2; + temp.a = alpha; backgroundColor = &temp; } } else if (i == mSelected) { - backgroundColor = highlightColor; + backgroundColor = &mHighlightColor; } graphics->setColor(*backgroundColor); @@ -130,9 +136,9 @@ void ShopListBox::draw(gcn::Graphics *gcnGraphics) graphics->drawImage(icon, 1, y); } } - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); graphics->drawText(mListModel->getElementAt(i), ITEM_ICON_SIZE + 5, - y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); + y + (ITEM_ICON_SIZE - getFont()->getHeight()) / 2); } } diff --git a/src/gui/widgets/shoplistbox.h b/src/gui/widgets/shoplistbox.h index 917f46729..38e238f20 100644 --- a/src/gui/widgets/shoplistbox.h +++ b/src/gui/widgets/shoplistbox.h @@ -85,6 +85,8 @@ class ShopListBox : public ListBox void mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED); private: + void init(); + int mPlayerMoney; /** @@ -100,6 +102,10 @@ class ShopListBox : public ListBox static float mAlpha; bool mPriceCheck; + + gcn::Color mHighlightColor; + gcn::Color mBackgroundColor; + gcn::Color mWarningColor; }; #endif // SHOPLISTBOX_H diff --git a/src/gui/widgets/spellshortcutcontainer.cpp b/src/gui/widgets/spellshortcutcontainer.cpp index 7e19b0348..8abe727b5 100644 --- a/src/gui/widgets/spellshortcutcontainer.cpp +++ b/src/gui/widgets/spellshortcutcontainer.cpp @@ -81,6 +81,7 @@ SpellShortcutContainer::SpellShortcutContainer(unsigned number): mBoxHeight = 1; mBoxWidth = 1; } + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } SpellShortcutContainer::~SpellShortcutContainer() @@ -109,7 +110,7 @@ void SpellShortcutContainer::draw(gcn::Graphics *graphics) graphics->setFont(getFont()); int selectedId = spellShortcut->getSelectedItem(); - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(getForegroundColor()); for (unsigned i = 0; i < mMaxItems; i++) { diff --git a/src/gui/widgets/tab.cpp b/src/gui/widgets/tab.cpp index b7d6b4458..530f1ac82 100644 --- a/src/gui/widgets/tab.cpp +++ b/src/gui/widgets/tab.cpp @@ -77,6 +77,8 @@ Tab::Tab() : gcn::Tab(), mMode(0) { init(); + mFlashColor = Theme::getThemeColor(Theme::TAB_FLASH); + mPlayerFlashColor = Theme::getThemeColor(Theme::TAB_PLAYER_FLASH); } Tab::~Tab() @@ -177,12 +179,10 @@ void Tab::draw(gcn::Graphics *graphics) switch (mFlash) { case 1: - mLabel->setForegroundColor(Theme::getThemeColor( - Theme::TAB_FLASH)); + mLabel->setForegroundColor(mFlashColor); break; case 2: - mLabel->setForegroundColor(Theme::getThemeColor( - Theme::TAB_PLAYER_FLASH)); + mLabel->setForegroundColor(mPlayerFlashColor); break; default: break; diff --git a/src/gui/widgets/tab.h b/src/gui/widgets/tab.h index 5847bd505..ba51e6c74 100644 --- a/src/gui/widgets/tab.h +++ b/src/gui/widgets/tab.h @@ -91,6 +91,8 @@ class Tab : public gcn::Tab, public gcn::WidgetListener GraphicsVertexes *mVertexes; bool mRedraw; int mMode; + gcn::Color mFlashColor; + gcn::Color mPlayerFlashColor; }; #endif diff --git a/src/gui/widgets/textfield.cpp b/src/gui/widgets/textfield.cpp index f80039650..2729e5407 100644 --- a/src/gui/widgets/textfield.cpp +++ b/src/gui/widgets/textfield.cpp @@ -59,6 +59,8 @@ TextField::TextField(const std::string &text, bool loseFocusOnTab, mLoseFocusOnTab = loseFocusOnTab; + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); + if (instances == 0) { // Load the skin @@ -136,7 +138,7 @@ void TextField::draw(gcn::Graphics *graphics) mXScroll); } - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + graphics->setColor(getForegroundColor()); graphics->setFont(getFont()); graphics->drawText(mText, 1 - mXScroll, 1); } diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 9a7c689e6..cdb9d3d55 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -95,6 +95,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, addWidgetListener(this); mCaptionFont = getFont(); + setForegroundColor(Theme::getThemeColor(Theme::TEXT)); } Window::~Window() @@ -146,15 +147,10 @@ void Window::draw(gcn::Graphics *graphics) g->drawImageRect2(mVertexes, mSkin->getBorder()); -/* - g->drawImageRect(0, 0, getWidth(), - getHeight(), mSkin->getBorder()); -*/ - // Draw title if (mShowTitle) { - g->setColor(Theme::getThemeColor(Theme::TEXT)); + g->setColor(getForegroundColor()); g->setFont(mCaptionFont); g->drawText(getCaption(), 7, 5, gcn::Graphics::LEFT); } -- cgit v1.2.3-70-g09d2 From 9505e3789cc9db6a10a68b9794a586604271b76f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 23 Aug 2011 01:48:25 +0300 Subject: Add protection against infinite loop in viewport and add debug message if some thing wrong happend. --- src/gui/viewport.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'src/gui') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 70d02b016..a5b541a8e 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -145,8 +145,10 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) if (mScrollLaziness < 1) mScrollLaziness = 1; // Avoids division by zero + int cnt = 0; + // Apply lazy scrolling - while (lastTick < tick_time) + while (lastTick < tick_time && cnt < 32) { if (player_x > static_cast(mPixelViewX) + mScrollRadius) { @@ -172,19 +174,26 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) - static_cast(mPixelViewY) + mScrollRadius) / static_cast(mScrollLaziness); } - lastTick++; + lastTick ++; + cnt ++; } // Auto center when player is off screen - if (player_x - static_cast(mPixelViewX) > graphics->mWidth / 2 - || static_cast(mPixelViewX) - player_x > graphics->mWidth / 2 - || static_cast(mPixelViewY) - player_y - > graphics->getHeight() / 2 - || player_y - static_cast(mPixelViewY) - > graphics->getHeight() / 2) + if (cnt > 30 || player_x - static_cast(mPixelViewX) + > graphics->mWidth / 2 || static_cast(mPixelViewX) + - player_x > graphics->mWidth / 2 || static_cast(mPixelViewY) + - player_y > graphics->getHeight() / 2 || player_y + - static_cast(mPixelViewY) > graphics->getHeight() / 2) { mPixelViewX = static_cast(player_x); mPixelViewY = static_cast(player_y); + if (player_x <= 0 || player_y <= 0) + { + if (debugChatTab) + debugChatTab->chatLog("incorrect player position!"); + logger->log("incorrect player position: %d, %d", + player_x, player_y); + } }; // Don't move camera so that the end of the map is on screen -- cgit v1.2.3-70-g09d2 From 4d8ed7fdb14bea874a9385a6808d27caced9802a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 24 Aug 2011 21:45:16 +0300 Subject: Fix copyright in sdlinput.cpp. --- src/gui/sdlinput.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gui') diff --git a/src/gui/sdlinput.cpp b/src/gui/sdlinput.cpp index a48f35be8..7c5ddb055 100644 --- a/src/gui/sdlinput.cpp +++ b/src/gui/sdlinput.cpp @@ -8,6 +8,7 @@ * * Copyright (c) 2004, 2005, 2006, 2007 Olof Naessén and Per Larsson * Copyright (C) 2007-2010 The Mana World Development Team + * Copyright (C) 2011 The ManaPlus Developers * * Js_./ * Per Larsson a.k.a finalman _RqZ{a<^_aa -- cgit v1.2.3-70-g09d2 From 2e7bfc350d38e16b3d340f8e4ea69e6ff6748f5c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 26 Aug 2011 18:25:58 +0300 Subject: Add auction buttons in shop window for send buy or sell list to auction bot. --- src/gui/shopwindow.cpp | 14 ++++++++++++++ src/gui/shopwindow.h | 2 ++ 2 files changed, 16 insertions(+) (limited to 'src/gui') diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 4311a04d2..0988ef759 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -119,9 +119,11 @@ ShopWindow::ShopWindow(): mBuyAddButton = new Button(_("Add"), "add buy", this); mBuyDeleteButton = new Button(_("Delete"), "delete buy", this); mBuyAnnounceButton = new Button(_("Announce"), "announce buy", this); + mBuyAuctionButton = new Button(_("Auction"), "auction buy", this); mSellAddButton = new Button(_("Add"), "add sell", this); mSellDeleteButton = new Button(_("Delete"), "delete sell", this); mSellAnnounceButton = new Button(_("Announce"), "announce sell", this); + mSellAuctionButton = new Button(_("Auction"), "auction sell", this); mAnnounceLinks = new CheckBox(_("Show links in announce"), false, this, "link announce"); @@ -135,9 +137,11 @@ ShopWindow::ShopWindow(): place(0, 6, mBuyAddButton); place(1, 6, mBuyDeleteButton); place(3, 6, mBuyAnnounceButton); + place(4, 6, mBuyAuctionButton); place(8, 6, mSellAddButton); place(9, 6, mSellDeleteButton); place(11, 6, mSellAnnounceButton); + place(12, 6, mSellAuctionButton); place(0, 7, mAnnounceLinks, 8); place(15, 7, mCloseButton); @@ -207,6 +211,16 @@ void ShopWindow::action(const gcn::ActionEvent &event) { announce(mSellShopItems, SELL); } + else if (event.getId() == "auction buy" && mBuyShopItems + && mBuyShopItems->getNumberOfElements() > 0) + { + Net::getChatHandler()->privateMessage("AuctionBot", "!pull4144 seek"); + } + else if (event.getId() == "auction sell" && mSellShopItems + && mSellShopItems->getNumberOfElements() > 0) + { + Net::getChatHandler()->privateMessage("AuctionBot", "!pull4144 offer"); + } if (mSelectedItem < 1) return; diff --git a/src/gui/shopwindow.h b/src/gui/shopwindow.h index e3fd9a5ca..8b170f31e 100644 --- a/src/gui/shopwindow.h +++ b/src/gui/shopwindow.h @@ -151,9 +151,11 @@ class ShopWindow : public Window, public gcn::ActionListener, gcn::Button *mBuyAddButton; gcn::Button *mBuyDeleteButton; gcn::Button *mBuyAnnounceButton; + gcn::Button *mBuyAuctionButton; gcn::Button *mSellAddButton; gcn::Button *mSellDeleteButton; gcn::Button *mSellAnnounceButton; + gcn::Button *mSellAuctionButton; gcn::CheckBox *mAnnounceLinks; ShopItems *mBuyShopItems; -- cgit v1.2.3-70-g09d2 From 12bf548533867a2eb3a1c354b778ef7f9157322a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 26 Aug 2011 16:57:05 +0300 Subject: Basic support for guild bot integration. Not working context menu actions, chat commands, auto complete. --- manaplus.cbp | 4 + src/CMakeLists.txt | 4 + src/Makefile.am | 4 + src/being.cpp | 6 +- src/client.cpp | 16 +++ src/client.h | 2 + src/game.cpp | 24 ++-- src/gui/chatwindow.cpp | 6 +- src/gui/popupmenu.cpp | 77 ++++++++--- src/gui/setup_other.cpp | 6 + src/gui/socialwindow.cpp | 111 +++++++++++++++- src/gui/widgets/guildtab.cpp | 127 ++++++++++++++++++ src/gui/widgets/guildtab.h | 52 ++++++++ src/guild.cpp | 6 +- src/guild.h | 9 +- src/guildmanager.cpp | 309 +++++++++++++++++++++++++++++++++++++++++++ src/guildmanager.h | 81 ++++++++++++ src/net/ea/chathandler.cpp | 7 + src/net/ea/guildhandler.cpp | 1 + src/utils/stringutils.cpp | 54 ++++++++ src/utils/stringutils.h | 8 ++ 21 files changed, 878 insertions(+), 36 deletions(-) create mode 100644 src/gui/widgets/guildtab.cpp create mode 100644 src/gui/widgets/guildtab.h create mode 100644 src/guildmanager.cpp create mode 100644 src/guildmanager.h (limited to 'src/gui') diff --git a/manaplus.cbp b/manaplus.cbp index 8ed18dbed..d05cccd3b 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -310,6 +310,8 @@ + + @@ -394,6 +396,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 413a72f65..7f59135b8 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,6 +137,8 @@ SET(SRCS gui/widgets/emoteshortcutcontainer.h gui/widgets/flowcontainer.cpp gui/widgets/flowcontainer.h + gui/widgets/guildtab.cpp + gui/widgets/guildtab.h gui/widgets/horizontcontainer.cpp gui/widgets/horizontcontainer.h gui/widgets/icon.cpp @@ -508,6 +510,8 @@ SET(SRCS guichanfwd.h guild.cpp guild.h + guildmanager.cpp + guildmanager.h imageparticle.cpp imageparticle.h imagesprite.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 57bb4e620..7d0c1634b 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -140,6 +140,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/emoteshortcutcontainer.h \ gui/widgets/flowcontainer.cpp \ gui/widgets/flowcontainer.h \ + gui/widgets/guildtab.cpp \ + gui/widgets/guildtab.h \ gui/widgets/horizontcontainer.cpp \ gui/widgets/horizontcontainer.h \ gui/widgets/icon.cpp \ @@ -515,6 +517,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ guichanfwd.h \ guild.cpp \ guild.h \ + guildmanager.cpp \ + guildmanager.h \ imageparticle.cpp \ imageparticle.h \ imagesprite.cpp \ diff --git a/src/being.cpp b/src/being.cpp index cc88d8f6e..1924a8944 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -871,8 +871,12 @@ void Being::updateGuild() return; } if (guild->getMember(getName())) + { setGuild(guild); - updateColors(); + if (!guild->getName().empty()) + mGuildName = guild->getName(); + updateColors(); + } } void Being::setGuild(Guild *guild) diff --git a/src/client.cpp b/src/client.cpp index 0e871ed91..385af99ad 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -30,6 +30,7 @@ #include "event.h" #include "game.h" #include "guild.h" +#include "guildmanager.h" #include "graphicsvertexes.h" #include "itemshortcut.h" #include "keyboardconfig.h" @@ -793,6 +794,10 @@ int Client::exec() if (mumbleManager) mumbleManager->setServer(mCurrentServer.hostname); + if (!guildManager) + guildManager = new GuildManager(); + guildManager->init(); + if (!mConfigAutoSaved) { mConfigAutoSaved = true; @@ -2180,3 +2185,14 @@ void Client::closeDialogs() NpcDialog::closeAll(); SellDialog::closeAll(); } + +bool Client::isTmw() +{ + if (getServerName() == "server.themanaworld.org" + || Client::getServerName() == "themanaworld.org" + || Client::getServerName() == "81.161.192.4") + { + return true; + } + return false; +} diff --git a/src/client.h b/src/client.h index 986e06cfb..3edf12674 100644 --- a/src/client.h +++ b/src/client.h @@ -260,6 +260,8 @@ public: static void setFramerate(int fpsLimit); + static bool isTmw(); + void optionChanged(const std::string &name); void action(const gcn::ActionEvent &event); diff --git a/src/game.cpp b/src/game.cpp index 82f919976..c933378e6 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -31,14 +31,13 @@ #include "client.h" #include "commandhandler.h" #include "configuration.h" +#include "dropshortcut.h" #include "effectmanager.h" -#include "event.h" -#include "spellmanager.h" #include "emoteshortcut.h" +#include "event.h" +#include "guildmanager.h" #include "graphics.h" #include "itemshortcut.h" -#include "dropshortcut.h" -#include "spellshortcut.h" #include "joystick.h" #include "keyboardconfig.h" #include "localplayer.h" @@ -47,6 +46,8 @@ #include "particle.h" #include "playerrelations.h" #include "sound.h" +#include "spellmanager.h" +#include "spellshortcut.h" #include "gui/botcheckerwindow.h" #include "gui/buyselldialog.h" @@ -156,6 +157,7 @@ Particle *particleEngine = NULL; EffectManager *effectManager = NULL; SpellManager *spellManager = NULL; Viewport *viewport = NULL; /**< Viewport on the map. */ +GuildManager *guildManager = NULL; ChatTab *localChatTab = NULL; ChatTab *debugChatTab = NULL; @@ -175,6 +177,8 @@ static void initEngines() commandHandler = new CommandHandler; channelManager = new ChannelManager; effectManager = new EffectManager; + if (!guildManager) + guildManager = new GuildManager; particleEngine = new Particle(NULL); particleEngine->setupEngine(); @@ -393,6 +397,9 @@ Game::Game(): setupWindow->setInGame(true); clearKeysArray(); + if (guildManager && guildManager->getEnableGuildBot()) + guildManager->requestGuildInfo(); + Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_CONSTRUCTED)); } @@ -411,16 +418,17 @@ Game::~Game() del_0(actorSpriteManager) if (Client::getState() != STATE_CHANGE_MAP) del_0(player_node) + del_0(guildManager) del_0(channelManager) del_0(commandHandler) - del_0(effectManager); + del_0(effectManager) del_0(joystick) del_0(particleEngine) del_0(viewport) del_0(mCurrentMap) - del_0(spellManager); - del_0(spellShortcut); - del_0(mumbleManager); + del_0(spellManager) + del_0(spellShortcut) + del_0(mumbleManager) Being::clearCache(); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 8896ca028..9c75320a6 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -1459,12 +1459,8 @@ void ChatWindow::saveState() std::string ChatWindow::doReplace(const std::string &msg) { - if (Client::getServerName() == "server.themanaworld.org" - || Client::getServerName() == "themanaworld.org" - || Client::getServerName() == "81.161.192.4") - { + if (Client::isTmw()) return msg; - } std::string str = msg; replaceSpecialChars(str); diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 61769bc7e..a3041fcf7 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -27,6 +27,7 @@ #include "being.h" #include "dropshortcut.h" #include "guild.h" +#include "guildmanager.h" #include "flooritem.h" #include "graphics.h" #include "item.h" @@ -224,14 +225,22 @@ void PopupMenu::showPopup(int x, int y, Being *being) { mBrowserBox->addRow(strprintf( "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@", - _("Change pos in guild"))); + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", + _("Change pos in guild"))); + } } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() + || (guildManager && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } @@ -435,15 +444,26 @@ void PopupMenu::showPlayerPopup(int x, int y, std::string nick) { if (guild2->getMember(mNick)) { - mBrowserBox->addRow(strprintf( - "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf( - "@@guild-pos|%s >@@", _("Change pos in guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + } + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", _("Change pos in guild"))); + } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } @@ -725,16 +745,27 @@ void PopupMenu::showChatPopup(int x, int y, ChatTab *tab) { if (guild1->getId() == guild2->getId()) { - mBrowserBox->addRow(strprintf( - "@@guild-kick|%s@@", _("Kick from guild"))); - mBrowserBox->addRow(strprintf( - "@@guild-pos|%s >@@", _("Change pos in guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + } + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf("@@guild-pos|%s >@@", + _("Change pos in guild"))); + } } } else { - mBrowserBox->addRow(strprintf( - "@@guild|%s@@", _("Invite to guild"))); + if (guild2->getServerGuild() || (guildManager + && guildManager->havePower())) + { + mBrowserBox->addRow(strprintf( + "@@guild|%s@@", _("Invite to guild"))); + } } } } @@ -897,7 +928,12 @@ void PopupMenu::handleLink(const std::string &link, { const Guild *guild = player_node->getGuild(); if (guild) - Net::getGuildHandler()->invite(guild->getId(), mNick); + { + if (guild->getServerGuild()) + Net::getGuildHandler()->invite(guild->getId(), mNick); + else if (guildManager) + guildManager->invite(mNick); + } } } else if (link == "nuke" && being) @@ -1263,7 +1299,12 @@ void PopupMenu::handleLink(const std::string &link, { const Guild *guild = player_node->getGuild(); if (guild) - Net::getGuildHandler()->kick(guild->getMember(mNick)); + { + if (guild->getServerGuild()) + Net::getGuildHandler()->kick(guild->getMember(mNick)); + else if (guildManager) + guildManager->kick(mNick); + } } } else if (link == "enable highlight" && mTab) diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index b405f5045..05ec9d672 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -145,6 +145,12 @@ Setup_Other::Setup_Other() this, "logNpcInGuiEvent"); + new SetupItemLabel(_("Bots support"), "", this); + + new SetupItemCheckBox(_("Enable guild bot support and disable native " + "guild support"), "", "enableGuildBot", this, + "enableGuildBotEvent", false); + new SetupItemLabel(_("Other"), "", this); new SetupItemCheckBox(_("Enable server side attack"), "", diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index e3aa69b30..aa26fa051 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -206,6 +206,109 @@ private: Guild *mGuild; }; +class GuildTab2 : public SocialTab, public gcn::ActionListener +{ +public: + GuildTab2(Guild *guild): + mGuild(guild) + { + setCaption(_("Guild")); + + setTabColor(&Theme::getThemeColor(Theme::GUILD_SOCIAL_TAB)); + + mList = new AvatarListBox(guild); + mScroll = new ScrollArea(mList); + + mScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_AUTO); + mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); + } + + ~GuildTab2() + { + delete mList; + mList = 0; + delete mScroll; + mScroll = 0; + } + + void action(const gcn::ActionEvent &event) + { +/* + if (event.getId() == "do invite") + { + std::string name = mInviteDialog->getText(); + Net::getGuildHandler()->invite(mGuild->getId(), name); + + if (localChatTab) + { + localChatTab->chatLog(strprintf( + _("Invited user %s to guild %s."), + name.c_str(), mGuild->getName().c_str()), BY_SERVER); + } + mInviteDialog = 0; + } + else if (event.getId() == "~do invite") + { + mInviteDialog = 0; + } + else if (event.getId() == "yes") + { + Net::getGuildHandler()->leave(mGuild->getId()); + if (localChatTab) + { + localChatTab->chatLog(strprintf(_("Guild %s quit requested."), + mGuild->getName().c_str()), BY_SERVER); + } + mConfirmDialog = 0; + } + else if (event.getId() == "~yes") + { + mConfirmDialog = 0; + } +*/ + } + + void updateList() + { + } + + void updateAvatar(std::string name A_UNUSED) + { + } + + void resetDamage(std::string name A_UNUSED) + { + } + +protected: + void invite() + { +/* + mInviteDialog = new TextDialog(_("Member Invite to Guild"), + strprintf(_("Who would you like to invite to guild %s?"), + mGuild->getName().c_str()), + socialWindow); + mInviteDialog->setActionEventId("do invite"); + mInviteDialog->addActionListener(this); +*/ + } + + void leave() + { +/* + mConfirmDialog = new ConfirmDialog(_("Leave Guild?"), + strprintf(_("Are you sure you want to leave guild %s?"), + mGuild->getName().c_str()), + socialWindow); + + mConfirmDialog->addActionListener(this); +*/ + } + +private: + Guild *mGuild; +}; + class PartyTab : public SocialTab, public gcn::ActionListener { public: @@ -1106,9 +1209,13 @@ bool SocialWindow::addTab(Guild *guild) if (mGuilds.find(guild) != mGuilds.end()) return false; - GuildTab *tab = new GuildTab(guild); - mGuilds[guild] = tab; + SocialTab *tab = 0; + if (guild->getServerGuild()) + tab = new GuildTab(guild); + else + tab = new GuildTab2(guild); + mGuilds[guild] = tab; mTabs->addTab(tab, tab->mScroll); updateButtons(); diff --git a/src/gui/widgets/guildtab.cpp b/src/gui/widgets/guildtab.cpp new file mode 100644 index 000000000..d9f61cb43 --- /dev/null +++ b/src/gui/widgets/guildtab.cpp @@ -0,0 +1,127 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/widgets/guildtab.h" + +#include "chatlogger.h" +#include "commandhandler.h" +#include "guild.h" +#include "guildmanager.h" +#include "localplayer.h" + +#include "gui/theme.h" + +#include "resources/iteminfo.h" +#include "resources/itemdb.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +GuildTab::GuildTab() : + ChatTab(_("Guild")) +{ + setTabColor(&Theme::getThemeColor(Theme::GUILD_CHAT_TAB)); +} + +GuildTab::~GuildTab() +{ +} + +bool GuildTab::handleCommand(const std::string &type, const std::string &args) +{ + if (type == "help") + { + if (args == "invite") + { + chatLog(_("Command: /invite ")); + chatLog(_("This command invites to the guild you're in.")); + chatLog(_("If the has spaces in it, enclose it in " + "double quotes (\").")); + } + else if (args == "leave") + { + chatLog(_("Command: /leave")); + chatLog(_("This command causes the player to leave the guild.")); + } + else + return false; + } + else if (type == "invite" && guildManager) + { + guildManager->invite(args); + } + else if (type == "leave" && guildManager) + { + guildManager->leave(); + } + else if (type == "kick" && guildManager) + { + guildManager->kick(args); + } + else if (type == "notice" && guildManager) + { + guildManager->notice(args); + } + else + { + return false; + } + + return false; +} + +void GuildTab::handleInput(const std::string &msg) +{ + if (!guildManager) + return; + + if (chatWindow) + guildManager->chat(chatWindow->doReplace(msg)); + else + guildManager->chat(msg); +} + +void GuildTab::showHelp() +{ + chatLog(_("/help > Display this help.")); + chatLog(_("/invite > Invite a player to your guild")); + chatLog(_("/leave > Leave the guild you are in")); + chatLog(_("/kick > Kick some one from the guild you are in")); +} + +void GuildTab::getAutoCompleteList(std::vector &names) const +{ + if (!guildManager) + return; + + guildManager->getNames(names); + names.push_back("/notice "); +} + +void GuildTab::saveToLogFile(std::string &msg) +{ + if (chatLogger) + chatLogger->log("#Guild", msg); +} diff --git a/src/gui/widgets/guildtab.h b/src/gui/widgets/guildtab.h new file mode 100644 index 000000000..a7f0aa766 --- /dev/null +++ b/src/gui/widgets/guildtab.h @@ -0,0 +1,52 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUI_GUILDTAB_H +#define GUI_GUILDTAB_H + +#include "gui/widgets/chattab.h" + +/** + * A tab for a guild chat channel. + */ +class GuildTab : public ChatTab +{ + public: + GuildTab(); + + ~GuildTab(); + + bool handleCommand(const std::string &type, const std::string &args); + + void showHelp(); + + void saveToLogFile(std::string &msg); + + int getType() const { return ChatTab::TAB_GUILD; } + + protected: + void handleInput(const std::string &msg); + + void getAutoCompleteList(std::vector &names) const; +}; + +#endif diff --git a/src/guild.cpp b/src/guild.cpp index b84602858..e36b68863 100644 --- a/src/guild.cpp +++ b/src/guild.cpp @@ -36,6 +36,9 @@ class SortGuildFunctor if (m1->getPos() != m2->getPos()) return m1->getPos() < m2->getPos(); +// if (m1->getOnline() != m2->getOnline()) +// return m1->getOnline() > m2->getOnline(); + return m1->getName() < m2->getName(); } } guildSorter; @@ -66,7 +69,8 @@ Guild::GuildMap Guild::guilds; Guild::Guild(short id): mId(id), mCanInviteUsers(false), - mEmblemId(0) + mEmblemId(0), + mServerGuild(true) { guilds[id] = this; } diff --git a/src/guild.h b/src/guild.h index 7986eb5d3..62135e9ad 100644 --- a/src/guild.h +++ b/src/guild.h @@ -178,11 +178,17 @@ public: void setEmblemId(int id) { mEmblemId = id; } - int getEmblemId() + int getEmblemId() const { return mEmblemId; } static void clearGuilds(); + void setServerGuild(bool b) + { mServerGuild = b; } + + bool getServerGuild() const + { return mServerGuild; } + private: typedef std::map GuildMap; static GuildMap guilds; @@ -199,6 +205,7 @@ private: bool mCanInviteUsers; int mEmblemId; PositionsMap mPositions; + bool mServerGuild; }; #endif // GUILD_H diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp new file mode 100644 index 000000000..ec9de2506 --- /dev/null +++ b/src/guildmanager.cpp @@ -0,0 +1,309 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "guildmanager.h" + +#include "actorspritemanager.h" +#include "client.h" +#include "configuration.h" +#include "guild.h" +#include "localplayer.h" + +#include "gui/socialwindow.h" + +#include "gui/widgets/guildtab.h" + +#include "net/chathandler.h" +#include "net/net.h" + +#include "utils/stringutils.h" + +#include "debug.h" + + +GuildManager::GuildManager() : + mEnableGuildBot(false), + mGotInfo(false), + mGotName(false), + mHavePower(false), + mTab(0), + mRequest(false) +{ +} + +GuildManager::~GuildManager() +{ + mTab = 0; +} + +void GuildManager::init() +{ + int val = serverConfig.getValue("enableGuildBot", -1); + if (val == -1) + { + if (Client::isTmw()) + val = 1; + else + val = 0; + serverConfig.setValue("enableGuildBot", val); + } + mEnableGuildBot = val; +} + +void GuildManager::send(std::string msg) +{ + Net::getChatHandler()->privateMessage("guild", msg); +} + +void GuildManager::chat(std::string msg) +{ + if (!player_node || !mTab) + return; + + Net::getChatHandler()->privateMessage("guild", msg); + mTab->chatLog(player_node->getName(), msg); +} + +void GuildManager::getNames(std::vector &names) +{ +} + +void GuildManager::requestGuildInfo() +{ + if (mRequest) + return; + + if (!mGotName) + { + send("!info"); + mRequest = true; + } + else if (!mGotInfo) + { + send("!getonlineinfo"); + mRequest = true; + } +} + +void GuildManager::updateList() +{ + Guild *guild = Guild::getGuild(1); + if (guild) + { + logger->log("filling player"); + guild->setServerGuild(false); + std::vector::iterator it = mTempList.begin(); + std::vector::iterator it_end = mTempList.end(); + int i = 0; + while (it != it_end) + { + std::string name = *it; + if (name.size() > 1) + { + int status = atoi(name.substr(name.size() - 1).c_str()); + name = name.substr(0, name.size() - 1); + GuildMember *m = guild->addMember(i, 0, name); + if (m) + { + m->setOnline(status & 1); + m->setGender(GENDER_UNSPECIFIED); + } + } + ++ it; + i ++; + } + guild->sort(); + if (actorSpriteManager) + actorSpriteManager->updatePlayerGuild(); + } + mTempList.clear(); + mGotInfo = true; + if (!mTab) + { + mTab = new GuildTab(); + mTab->loadFromLogFile("#Guild"); + if (player_node) + player_node->addGuild(guild); + } +} + +bool GuildManager::processGuildMessage(std::string msg) +{ + bool res = process(msg); + + if (!mRequest) + requestGuildInfo(); + + return res; +} + +bool GuildManager::process(std::string msg) +{ + if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + + Guild *guild = Guild::getGuild(1); + if (!guild) + return false; + + guild->setServerGuild(false); + + if (findCutLast(msg, " is now Offline.")) + { + if (msg.size() < 4) + return false; + if (msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + + GuildMember *m = guild->getMember(msg); + if (m) + m->setOnline(false); + mRequest = false; + return true; + } + else if (findCutLast(msg, " is now Online.")) + { + if (msg.size() < 4) + return false; + if (msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + GuildMember *m = guild->getMember(msg); + if (m) + m->setOnline(true); + mRequest = false; + return true; + } + else if (findCutFirst(msg, "Welcome to the ")) + { + logger->log("welcome message: %s", msg.c_str()); + int pos = msg.find("! ("); + if (pos == (int)std::string::npos) + return false; + msg = msg.substr(0, pos); + guild->setName(msg); + if (player_node) + player_node->setGuildName(msg); + mGotName = true; + mRequest = false; + return true; + } + else if (findCutFirst(msg, "Player name: ")) + { + int pos = msg.find("Access Level: "); + if (pos == (int)std::string::npos) + return false; + + msg = msg.substr(pos); + if (!findCutFirst(msg, "Access Level: ")) + return false; + + pos = msg.find(", Guild:"); + if (pos == (int)std::string::npos) + return false; + + int level = atoi(msg.substr(0, pos).c_str()); + if (level >= 10) + mHavePower = true; + else + mHavePower = false; + + msg = msg.substr(pos + strlen(", Guild:")); + pos = msg.find(", No. Of Online Players: "); + if (pos == (int)std::string::npos) + return false; + + msg = msg.substr(0, pos); +// logger->log("guild name: %s", msg.c_str()); + + guild->setName(msg); + if (player_node) + player_node->setGuildName(msg); + mGotName = true; + mRequest = false; + return true; + } + else if (findCutFirst(msg, "OL#")) + { + logger->log("OL"); + mTempList.clear(); + splitToStringVector(mTempList, msg, '#'); + if (msg.size() < 1 || msg[msg.size() - 1] != '#') + updateList(); + mRequest = false; + return true; + } + else if (findCutFirst(msg, "oL#")) + { + logger->log("oL"); + splitToStringVector(mTempList, msg, '#'); + if (msg.size() < 1 || msg[msg.size() - 1] != '#') + updateList(); + mRequest = false; + return true; + } + else if (msg == "You are currently not in a guild. For more information " + "or to discuss the possibility of adding you own guild " + "please contact Jero.") + { + mRequest = true; + return true; + } + else + { + if (mTab) + { + std::string::size_type pos = msg.find(": ", 0); + if (pos != std::string::npos) + { + std::string sender_name = ((pos == std::string::npos) + ? "" : msg.substr(0, pos)); + + msg.erase(0, pos + 2); + if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#') + msg.erase(0, 3); + + trim(msg); + mTab->chatLog(sender_name, msg); + } + else + { + mTab->chatLog(msg); + } + return true; + } + } + return false; +} + +void GuildManager::kick(std::string msg) +{ +} + +void GuildManager::invite(std::string msg) +{ +} + +void GuildManager::leave() +{ +} + +void GuildManager::notice(std::string msg) +{ +} diff --git a/src/guildmanager.h b/src/guildmanager.h new file mode 100644 index 000000000..f02368ab6 --- /dev/null +++ b/src/guildmanager.h @@ -0,0 +1,81 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUILDMANAGER_H +#define GUILDMANAGER_H + +#include "utils/dtor.h" + +#include +#include +#include + +class GuildTab; + +class GuildManager +{ + public: + GuildManager(); + + ~GuildManager(); + + void init(); + + void chat(std::string msg); + + void send(std::string msg); + + bool processGuildMessage(std::string msg); + + void getNames(std::vector &names); + + void requestGuildInfo(); + + void updateList(); + + bool getEnableGuildBot() + { return mEnableGuildBot; } + + void kick(std::string msg); + + void invite(std::string msg); + + void leave(); + + void notice(std::string msg); + + bool havePower() + { return mHavePower; } + + private: + bool process(std::string msg); + + bool mEnableGuildBot; + bool mGotInfo; + bool mGotName; + bool mHavePower; + std::vector mTempList; + GuildTab *mTab; + bool mRequest; +}; + +extern GuildManager *guildManager; + +#endif // GUILDMANAGER_H diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index c188a2204..e430dfc0f 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -25,6 +25,7 @@ #include "actorspritemanager.h" #include "being.h" #include "configuration.h" +#include "guildmanager.h" #include "localplayer.h" #include "playerrelations.h" #include "logger.h" @@ -161,6 +162,12 @@ void ChatHandler::processWhisper(Net::MessageIn &msg) if (nick != "Server") { + if (guildManager && guildManager->getEnableGuildBot() + && nick == "guild" && guildManager->processGuildMessage(chatMsg)) + { + return; + } + if (player_relations.hasPermission( nick, PlayerRelation::WHISPER)) { diff --git a/src/net/ea/guildhandler.cpp b/src/net/ea/guildhandler.cpp index 0210a76ff..2accb1f1d 100644 --- a/src/net/ea/guildhandler.cpp +++ b/src/net/ea/guildhandler.cpp @@ -125,6 +125,7 @@ void GuildHandler::processGuildPositionInfo(Net::MessageIn &msg) if (!guildTab && chatWindow) { guildTab = new GuildTab(); + guildTab->loadFromLogFile("#Guild"); if (player_node) player_node->addGuild(taGuild); memberList(guildId); diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 0243c4315..317d88f2d 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -524,3 +524,57 @@ void deleteCharLeft(std::string &str, unsigned *pos) break; } } + +bool findLast(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(s1 - s2); + if (tmp == str2) + return true; + return false; +} + +bool findFirst(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(0, s2); + if (tmp == str2) + return true; + return false; +} + +bool findCutLast(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(s1 - s2); + if (tmp == str2) + { + str1 = str1.substr(0, s1 - s2); + return true; + } + return false; +} + +bool findCutFirst(std::string &str1, std::string str2) +{ + const unsigned s1 = str1.size(); + const unsigned s2 = str2.size(); + if (s1 < s2) + return false; + std::string tmp = str1.substr(0, s2); + if (tmp == str2) + { + str1 = str1.substr(s2); + return true; + } + return false; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index 4fe6369e9..25e038a89 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -193,4 +193,12 @@ std::string stringToHexPath(const std::string &str); void deleteCharLeft(std::string &str, unsigned *pos); +bool findLast(std::string &str1, std::string str2); + +bool findFirst(std::string &str1, std::string str2); + +bool findCutLast(std::string &str1, std::string str2); + +bool findCutFirst(std::string &str1, std::string str2); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2 From 96ca346fe114804609acea0b13594422f3f09002 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 27 Aug 2011 17:24:16 +0300 Subject: Impliment additional guild bot intergration functions. --- src/gui/widgets/guildtab.cpp | 2 +- src/guildmanager.cpp | 70 ++++++++++++++++++++++++++++++++++++++------ src/guildmanager.h | 5 ++++ 3 files changed, 67 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/guildtab.cpp b/src/gui/widgets/guildtab.cpp index d9f61cb43..f4288e228 100644 --- a/src/gui/widgets/guildtab.cpp +++ b/src/gui/widgets/guildtab.cpp @@ -89,7 +89,7 @@ bool GuildTab::handleCommand(const std::string &type, const std::string &args) return false; } - return false; + return true; } void GuildTab::handleInput(const std::string &msg) diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 8f480803a..bc4158a12 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -83,6 +83,8 @@ void GuildManager::chat(std::string msg) void GuildManager::getNames(std::vector &names) { + Guild *guild = createGuild(); + guild->getNames(names); } void GuildManager::requestGuildInfo() @@ -117,12 +119,22 @@ void GuildManager::updateList() if (name.size() > 1) { int status = atoi(name.substr(name.size() - 1).c_str()); + name = name.substr(0, name.size() - 1); GuildMember *m = guild->addMember(i, 0, name); if (m) { m->setOnline(status & 1); m->setGender(GENDER_UNSPECIFIED); + if (status & 2) + m->setPos(10); + else + m->setPos(0); + if (player_node && name == player_node->getName()) + { + mHavePower = (status & 2); + m->setOnline(true); + } } } ++ it; @@ -131,9 +143,14 @@ void GuildManager::updateList() guild->sort(); if (actorSpriteManager) actorSpriteManager->updatePlayerGuild(); + createTab(guild); } mTempList.clear(); mGotInfo = true; +} + +void GuildManager::createTab(Guild *guild) +{ if (!mTab) { mTab = new GuildTab(); @@ -143,6 +160,16 @@ void GuildManager::updateList() } } +Guild *GuildManager::createGuild() +{ + Guild *guild = Guild::getGuild(1); + if (!guild) + return 0; + + guild->setServerGuild(false); + return guild; +} + bool GuildManager::processGuildMessage(std::string msg) { bool res = process(msg); @@ -158,14 +185,11 @@ bool GuildManager::process(std::string msg) if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') msg = msg.substr(3); - Guild *guild = Guild::getGuild(1); - if (!guild) - return false; - - guild->setServerGuild(false); - if (findCutLast(msg, " is now Offline.")) { + Guild *guild = createGuild(); + if (!guild) + return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') @@ -180,6 +204,9 @@ bool GuildManager::process(std::string msg) } else if (findCutLast(msg, " is now Online.")) { + Guild *guild = createGuild(); + if (!guild) + return false; if (msg.size() < 4) return false; if (msg[0] == '#' && msg[1] == '#') @@ -193,7 +220,10 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "Welcome to the ")) { - logger->log("welcome message: %s", msg.c_str()); + Guild *guild = createGuild(); + if (!guild) + return false; +// logger->log("welcome message: %s", msg.c_str()); int pos = msg.find("! ("); if (pos == (int)std::string::npos) return false; @@ -207,6 +237,9 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "Player name: ")) { + Guild *guild = createGuild(); + if (!guild) + return false; int pos = msg.find("Access Level: "); if (pos == (int)std::string::npos) return false; @@ -242,7 +275,7 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "OL#")) { - logger->log("OL"); +// logger->log("OL"); mTempList.clear(); splitToStringVector(mTempList, msg, '#'); if (msg.size() < 1 || msg[msg.size() - 1] != '#') @@ -252,7 +285,7 @@ bool GuildManager::process(std::string msg) } else if (findCutFirst(msg, "oL#")) { - logger->log("oL"); +// logger->log("oL"); splitToStringVector(mTempList, msg, '#'); if (msg.size() < 1 || msg[msg.size() - 1] != '#') updateList(); @@ -268,6 +301,13 @@ bool GuildManager::process(std::string msg) } else { + Guild *guild = createGuild(); + if (!guild) + return false; + if (!mTab) + { + createTab(guild); + } if (mTab) { std::string::size_type pos = msg.find(": ", 0); @@ -275,6 +315,11 @@ bool GuildManager::process(std::string msg) { std::string sender_name = ((pos == std::string::npos) ? "" : msg.substr(0, pos)); + if (!guild->getMember(sender_name)) + { + mTab->chatLog(msg); + return true; + } msg.erase(0, pos + 2); if (msg.size() > 3 && msg[0] == '#' && msg[1] == '#') @@ -295,16 +340,23 @@ bool GuildManager::process(std::string msg) void GuildManager::kick(std::string msg) { + send("!remove " + msg); } void GuildManager::invite(std::string msg) { + send("!invite " + msg); } void GuildManager::leave() { + send("!leave"); } void GuildManager::notice(std::string msg) { + if (msg.empty()) + send("!removemotd"); + else + send("!setmotd " + msg); } diff --git a/src/guildmanager.h b/src/guildmanager.h index f02368ab6..a46cba915 100644 --- a/src/guildmanager.h +++ b/src/guildmanager.h @@ -27,6 +27,7 @@ #include #include +class Guild; class GuildTab; class GuildManager @@ -61,6 +62,10 @@ class GuildManager void notice(std::string msg); + void createTab(Guild *guild); + + Guild *createGuild(); + bool havePower() { return mHavePower; } -- cgit v1.2.3-70-g09d2 From 2dc730f9aba84fc9fe684fd2af9864df97580502 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 02:48:00 +0300 Subject: Fix possible conflicts between class names GuildTab, PartyTab and other. --- manaplus.cbp | 4 +- src/CMakeLists.txt | 4 +- src/Makefile.am | 4 +- src/gui/socialwindow.cpp | 56 ++++++++--------- src/gui/widgets/guildchattab.cpp | 127 +++++++++++++++++++++++++++++++++++++++ src/gui/widgets/guildchattab.h | 52 ++++++++++++++++ src/gui/widgets/guildtab.cpp | 127 --------------------------------------- src/gui/widgets/guildtab.h | 52 ---------------- src/guildmanager.cpp | 4 +- src/guildmanager.h | 4 +- 10 files changed, 217 insertions(+), 217 deletions(-) create mode 100644 src/gui/widgets/guildchattab.cpp create mode 100644 src/gui/widgets/guildchattab.h delete mode 100644 src/gui/widgets/guildtab.cpp delete mode 100644 src/gui/widgets/guildtab.h (limited to 'src/gui') diff --git a/manaplus.cbp b/manaplus.cbp index d05cccd3b..992915467 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -310,8 +310,8 @@ - - + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 7f59135b8..49b41f906 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -137,8 +137,8 @@ SET(SRCS gui/widgets/emoteshortcutcontainer.h gui/widgets/flowcontainer.cpp gui/widgets/flowcontainer.h - gui/widgets/guildtab.cpp - gui/widgets/guildtab.h + gui/widgets/guildchattab.cpp + gui/widgets/guildchattab.h gui/widgets/horizontcontainer.cpp gui/widgets/horizontcontainer.h gui/widgets/icon.cpp diff --git a/src/Makefile.am b/src/Makefile.am index 7d0c1634b..ca6dd6bc2 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -140,8 +140,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/emoteshortcutcontainer.h \ gui/widgets/flowcontainer.cpp \ gui/widgets/flowcontainer.h \ - gui/widgets/guildtab.cpp \ - gui/widgets/guildtab.h \ + gui/widgets/guildchattab.cpp \ + gui/widgets/guildchattab.h \ gui/widgets/horizontcontainer.cpp \ gui/widgets/horizontcontainer.h \ gui/widgets/icon.cpp \ diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index aa26fa051..b517911ba 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -108,10 +108,10 @@ protected: AvatarListBox *mList; }; -class GuildTab : public SocialTab, public gcn::ActionListener +class SocialGuildTab : public SocialTab, public gcn::ActionListener { public: - GuildTab(Guild *guild): + SocialGuildTab(Guild *guild): mGuild(guild) { setCaption(_("Guild")); @@ -125,7 +125,7 @@ public: mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); } - ~GuildTab() + ~SocialGuildTab() { delete mList; mList = 0; @@ -206,10 +206,10 @@ private: Guild *mGuild; }; -class GuildTab2 : public SocialTab, public gcn::ActionListener +class SocialGuildTab2 : public SocialTab, public gcn::ActionListener { public: - GuildTab2(Guild *guild): + SocialGuildTab2(Guild *guild): mGuild(guild) { setCaption(_("Guild")); @@ -223,7 +223,7 @@ public: mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); } - ~GuildTab2() + ~SocialGuildTab2() { delete mList; mList = 0; @@ -309,10 +309,10 @@ private: Guild *mGuild; }; -class PartyTab : public SocialTab, public gcn::ActionListener +class SocialPartyTab : public SocialTab, public gcn::ActionListener { public: - PartyTab(Party *party): + SocialPartyTab(Party *party): mParty(party) { setCaption(_("Party")); @@ -326,7 +326,7 @@ public: mScroll->setVerticalScrollPolicy(gcn::ScrollArea::SHOW_ALWAYS); } - ~PartyTab() + ~SocialPartyTab() { delete mList; mList = 0; @@ -443,10 +443,10 @@ public: std::vector mMembers; }; -class PlayersTab : public SocialTab +class SocialPlayersTab : public SocialTab { public: - PlayersTab(std::string name) + SocialPlayersTab(std::string name) { mBeings = new BeingsListModal(); @@ -461,7 +461,7 @@ public: setCaption(name); } - ~PlayersTab() + ~SocialPlayersTab() { delete mList; mList = 0; @@ -608,10 +608,10 @@ private: }; -class NavigationTab : public SocialTab +class SocialNavigationTab : public SocialTab { public: - NavigationTab() + SocialNavigationTab() { mBeings = new BeingsListModal(); @@ -625,7 +625,7 @@ public: } - ~NavigationTab() + ~SocialNavigationTab() { delete mList; mList = 0; @@ -886,10 +886,10 @@ protected: }; -class AttackTab : public SocialTab +class SocialAttackTab : public SocialTab { public: - AttackTab() + SocialAttackTab() { mBeings = new BeingsListModal(); @@ -902,7 +902,7 @@ public: setCaption(_("Atk")); } - ~AttackTab() + ~SocialAttackTab() { delete mList; mList = 0; @@ -1149,15 +1149,15 @@ SocialWindow::SocialWindow() : loadWindowState(); - mPlayers = new PlayersTab("P"); + mPlayers = new SocialPlayersTab("P"); mTabs->addTab(mPlayers, mPlayers->mScroll); - mNavigation = new NavigationTab(); + mNavigation = new SocialNavigationTab(); mTabs->addTab(mNavigation, mNavigation->mScroll); if (config.getBoolValue("enableAttackFilter")) { - mAttackFilter = new AttackTab(); + mAttackFilter = new SocialAttackTab(); mTabs->addTab(mAttackFilter, mAttackFilter->mScroll); } else @@ -1211,9 +1211,9 @@ bool SocialWindow::addTab(Guild *guild) SocialTab *tab = 0; if (guild->getServerGuild()) - tab = new GuildTab(guild); + tab = new SocialGuildTab(guild); else - tab = new GuildTab2(guild); + tab = new SocialGuildTab2(guild); mGuilds[guild] = tab; mTabs->addTab(tab, tab->mScroll); @@ -1243,7 +1243,7 @@ bool SocialWindow::addTab(Party *party) if (mParties.find(party) != mParties.end()) return false; - PartyTab *tab = new PartyTab(party); + SocialPartyTab *tab = new SocialPartyTab(party); mParties[party] = tab; mTabs->addTab(tab, tab->mScroll); @@ -1556,7 +1556,7 @@ void SocialWindow::updatePortals() void SocialWindow::updatePortalNames() { if (mNavigation) - static_cast(mNavigation)->updateNames(); + static_cast(mNavigation)->updateNames(); } void SocialWindow::selectPortal(unsigned num) @@ -1568,7 +1568,7 @@ void SocialWindow::selectPortal(unsigned num) int SocialWindow::getPortalIndex(int x, int y) { if (mNavigation) - return static_cast(mNavigation)->getPortalIndex(x, y); + return static_cast(mNavigation)->getPortalIndex(x, y); else return -1; } @@ -1576,13 +1576,13 @@ int SocialWindow::getPortalIndex(int x, int y) void SocialWindow::addPortal(int x, int y) { if (mNavigation) - static_cast(mNavigation)->addPortal(x, y); + static_cast(mNavigation)->addPortal(x, y); } void SocialWindow::removePortal(int x, int y) { if (mNavigation) - static_cast(mNavigation)->removePortal(x, y); + static_cast(mNavigation)->removePortal(x, y); } void SocialWindow::nextTab() diff --git a/src/gui/widgets/guildchattab.cpp b/src/gui/widgets/guildchattab.cpp new file mode 100644 index 000000000..0d40506dd --- /dev/null +++ b/src/gui/widgets/guildchattab.cpp @@ -0,0 +1,127 @@ +/* + * The ManaPlus Client + * Copyright (C) 2008-2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "gui/widgets/guildchattab.h" + +#include "chatlogger.h" +#include "commandhandler.h" +#include "guild.h" +#include "guildmanager.h" +#include "localplayer.h" + +#include "gui/theme.h" + +#include "resources/iteminfo.h" +#include "resources/itemdb.h" + +#include "utils/dtor.h" +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +GuildChatTab::GuildChatTab() : + ChatTab(_("Guild")) +{ + setTabColor(&Theme::getThemeColor(Theme::GUILD_CHAT_TAB)); +} + +GuildChatTab::~GuildChatTab() +{ +} + +bool GuildChatTab::handleCommand(const std::string &type, const std::string &args) +{ + if (type == "help") + { + if (args == "invite") + { + chatLog(_("Command: /invite ")); + chatLog(_("This command invites to the guild you're in.")); + chatLog(_("If the has spaces in it, enclose it in " + "double quotes (\").")); + } + else if (args == "leave") + { + chatLog(_("Command: /leave")); + chatLog(_("This command causes the player to leave the guild.")); + } + else + return false; + } + else if (type == "invite" && guildManager) + { + guildManager->invite(args); + } + else if (type == "leave" && guildManager) + { + guildManager->leave(); + } + else if (type == "kick" && guildManager) + { + guildManager->kick(args); + } + else if (type == "notice" && guildManager) + { + guildManager->notice(args); + } + else + { + return false; + } + + return true; +} + +void GuildChatTab::handleInput(const std::string &msg) +{ + if (!guildManager) + return; + + if (chatWindow) + guildManager->chat(chatWindow->doReplace(msg)); + else + guildManager->chat(msg); +} + +void GuildChatTab::showHelp() +{ + chatLog(_("/help > Display this help.")); + chatLog(_("/invite > Invite a player to your guild")); + chatLog(_("/leave > Leave the guild you are in")); + chatLog(_("/kick > Kick some one from the guild you are in")); +} + +void GuildChatTab::getAutoCompleteList(std::vector &names) const +{ + if (!guildManager) + return; + + guildManager->getNames(names); + names.push_back("/notice "); +} + +void GuildChatTab::saveToLogFile(std::string &msg) +{ + if (chatLogger) + chatLogger->log("#Guild", msg); +} diff --git a/src/gui/widgets/guildchattab.h b/src/gui/widgets/guildchattab.h new file mode 100644 index 000000000..4f5ee3a8e --- /dev/null +++ b/src/gui/widgets/guildchattab.h @@ -0,0 +1,52 @@ +/* + * The ManaPlus Client + * Copyright (C) 2009 The Mana World Development Team + * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef GUI_GUILDTAB_H +#define GUI_GUILDTAB_H + +#include "gui/widgets/chattab.h" + +/** + * A tab for a guild chat channel. + */ +class GuildChatTab : public ChatTab +{ + public: + GuildChatTab(); + + ~GuildChatTab(); + + bool handleCommand(const std::string &type, const std::string &args); + + void showHelp(); + + void saveToLogFile(std::string &msg); + + int getType() const { return ChatTab::TAB_GUILD; } + + protected: + void handleInput(const std::string &msg); + + void getAutoCompleteList(std::vector &names) const; +}; + +#endif diff --git a/src/gui/widgets/guildtab.cpp b/src/gui/widgets/guildtab.cpp deleted file mode 100644 index f4288e228..000000000 --- a/src/gui/widgets/guildtab.cpp +++ /dev/null @@ -1,127 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2008-2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include "gui/widgets/guildtab.h" - -#include "chatlogger.h" -#include "commandhandler.h" -#include "guild.h" -#include "guildmanager.h" -#include "localplayer.h" - -#include "gui/theme.h" - -#include "resources/iteminfo.h" -#include "resources/itemdb.h" - -#include "utils/dtor.h" -#include "utils/gettext.h" -#include "utils/stringutils.h" - -#include "debug.h" - -GuildTab::GuildTab() : - ChatTab(_("Guild")) -{ - setTabColor(&Theme::getThemeColor(Theme::GUILD_CHAT_TAB)); -} - -GuildTab::~GuildTab() -{ -} - -bool GuildTab::handleCommand(const std::string &type, const std::string &args) -{ - if (type == "help") - { - if (args == "invite") - { - chatLog(_("Command: /invite ")); - chatLog(_("This command invites to the guild you're in.")); - chatLog(_("If the has spaces in it, enclose it in " - "double quotes (\").")); - } - else if (args == "leave") - { - chatLog(_("Command: /leave")); - chatLog(_("This command causes the player to leave the guild.")); - } - else - return false; - } - else if (type == "invite" && guildManager) - { - guildManager->invite(args); - } - else if (type == "leave" && guildManager) - { - guildManager->leave(); - } - else if (type == "kick" && guildManager) - { - guildManager->kick(args); - } - else if (type == "notice" && guildManager) - { - guildManager->notice(args); - } - else - { - return false; - } - - return true; -} - -void GuildTab::handleInput(const std::string &msg) -{ - if (!guildManager) - return; - - if (chatWindow) - guildManager->chat(chatWindow->doReplace(msg)); - else - guildManager->chat(msg); -} - -void GuildTab::showHelp() -{ - chatLog(_("/help > Display this help.")); - chatLog(_("/invite > Invite a player to your guild")); - chatLog(_("/leave > Leave the guild you are in")); - chatLog(_("/kick > Kick some one from the guild you are in")); -} - -void GuildTab::getAutoCompleteList(std::vector &names) const -{ - if (!guildManager) - return; - - guildManager->getNames(names); - names.push_back("/notice "); -} - -void GuildTab::saveToLogFile(std::string &msg) -{ - if (chatLogger) - chatLogger->log("#Guild", msg); -} diff --git a/src/gui/widgets/guildtab.h b/src/gui/widgets/guildtab.h deleted file mode 100644 index a7f0aa766..000000000 --- a/src/gui/widgets/guildtab.h +++ /dev/null @@ -1,52 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2009 The Mana World Development Team - * Copyright (C) 2009-2010 The Mana Developers - * Copyright (C) 2011 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef GUI_GUILDTAB_H -#define GUI_GUILDTAB_H - -#include "gui/widgets/chattab.h" - -/** - * A tab for a guild chat channel. - */ -class GuildTab : public ChatTab -{ - public: - GuildTab(); - - ~GuildTab(); - - bool handleCommand(const std::string &type, const std::string &args); - - void showHelp(); - - void saveToLogFile(std::string &msg); - - int getType() const { return ChatTab::TAB_GUILD; } - - protected: - void handleInput(const std::string &msg); - - void getAutoCompleteList(std::vector &names) const; -}; - -#endif diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 22b9de5a1..624193698 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -28,7 +28,7 @@ #include "gui/socialwindow.h" -#include "gui/widgets/guildtab.h" +#include "gui/widgets/guildchattab.h" #include "net/chathandler.h" #include "net/net.h" @@ -172,7 +172,7 @@ void GuildManager::createTab(Guild *guild) { if (!mTab) { - mTab = new GuildTab(); + mTab = new GuildChatTab(); mTab->loadFromLogFile("#Guild"); if (player_node) player_node->addGuild(guild); diff --git a/src/guildmanager.h b/src/guildmanager.h index 177cec12a..c89cba0a6 100644 --- a/src/guildmanager.h +++ b/src/guildmanager.h @@ -28,7 +28,7 @@ #include class Guild; -class GuildTab; +class GuildChatTab; class GuildManager { @@ -81,7 +81,7 @@ class GuildManager bool mGotName; bool mHavePower; std::vector mTempList; - GuildTab *mTab; + GuildChatTab *mTab; bool mRequest; }; -- cgit v1.2.3-70-g09d2 From 6b6fbd4eb1c0122a1c5346f29d54f2aca9b11009 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 16:45:10 +0300 Subject: Add support for guild invitation in guild bot integration. --- src/gui/socialwindow.cpp | 11 +++++++++-- src/guildmanager.cpp | 18 +++++++++++++++++- src/guildmanager.h | 2 ++ 3 files changed, 28 insertions(+), 3 deletions(-) (limited to 'src/gui') diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index b517911ba..789d98b73 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -23,6 +23,7 @@ #include "actorspritemanager.h" #include "guild.h" +#include "guildmanager.h" #include "keyboardconfig.h" #include "localplayer.h" #include "logger.h" @@ -1310,7 +1311,10 @@ void SocialWindow::action(const gcn::ActionEvent &event) strprintf(_("Accepted guild invite from %s."), mPartyInviter.c_str())); } - Net::getGuildHandler()->inviteResponse(mGuildInvited, true); + if (!guildManager || !guildManager->getEnableGuildBot()) + Net::getGuildHandler()->inviteResponse(mGuildInvited, true); + else + guildManager->inviteResponse(true); } else if (eventId == "no") { @@ -1320,7 +1324,10 @@ void SocialWindow::action(const gcn::ActionEvent &event) strprintf(_("Rejected guild invite from %s."), mPartyInviter.c_str())); } - Net::getGuildHandler()->inviteResponse(mGuildInvited, false); + if (!guildManager || !guildManager->getEnableGuildBot()) + Net::getGuildHandler()->inviteResponse(mGuildInvited, false); + else + guildManager->inviteResponse(false); } mGuildInvited = 0; diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 624193698..12bcf717a 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -318,6 +318,14 @@ bool GuildManager::process(std::string msg) mRequest = true; return true; } + else if (findCutFirst(msg, "You have been invited to the ") + && findCutLast(msg, " guild chat. If you would like to accept " + "this invitation please reply \"yes\" and if not then \"no\" .")) + { + if (socialWindow) + socialWindow->showGuildInvite(msg, 1, ""); + return true; + } else { Guild *guild = createGuild(); @@ -388,4 +396,12 @@ void GuildManager::clear() if (guild) socialWindow->removeTab(guild); } -} \ No newline at end of file +} + +void GuildManager::inviteResponse(bool response) +{ + if (response) + send("yes"); + else + send("no"); +} diff --git a/src/guildmanager.h b/src/guildmanager.h index c89cba0a6..b95583192 100644 --- a/src/guildmanager.h +++ b/src/guildmanager.h @@ -70,6 +70,8 @@ class GuildManager void reload(); + void inviteResponse(bool response); + bool havePower() { return mHavePower; } -- cgit v1.2.3-70-g09d2 From 285db66255e63f3967ae806eb888d4742cff3d9f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 18:50:28 +0300 Subject: Move simple colors to themes. Need add to all themes, or all simple colors will be black. --- data/graphics/gui/colors.xml | 10 ++++++++++ data/themes/blackwood/colors.xml | 10 ++++++++++ data/themes/enchilado/colors.xml | 10 ++++++++++ data/themes/mana/colors.xml | 10 ++++++++++ data/themes/pink/colors.xml | 10 ++++++++++ data/themes/redandblack/colors.xml | 10 ++++++++++ data/themes/wood/colors.xml | 10 ++++++++++ src/gui/theme.cpp | 11 ++++++++++- src/gui/theme.h | 9 +++++++++ src/gui/widgets/browserbox.cpp | 27 ++++++++++++++++++--------- src/gui/widgets/browserbox.h | 30 +++++++++++------------------- 11 files changed, 118 insertions(+), 29 deletions(-) (limited to 'src/gui') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index 2091494b3..4203b482c 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/data/themes/blackwood/colors.xml b/data/themes/blackwood/colors.xml index ef06fdc9f..523d164c7 100644 --- a/data/themes/blackwood/colors.xml +++ b/data/themes/blackwood/colors.xml @@ -48,6 +48,16 @@ + + + + + + + + + + diff --git a/data/themes/enchilado/colors.xml b/data/themes/enchilado/colors.xml index f4ae878e4..0c19f5a47 100644 --- a/data/themes/enchilado/colors.xml +++ b/data/themes/enchilado/colors.xml @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/data/themes/mana/colors.xml b/data/themes/mana/colors.xml index c623b8396..45937e268 100644 --- a/data/themes/mana/colors.xml +++ b/data/themes/mana/colors.xml @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/data/themes/pink/colors.xml b/data/themes/pink/colors.xml index 6be3ab630..f2b20567e 100644 --- a/data/themes/pink/colors.xml +++ b/data/themes/pink/colors.xml @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/data/themes/redandblack/colors.xml b/data/themes/redandblack/colors.xml index 8fe785114..d5e6a7f7b 100644 --- a/data/themes/redandblack/colors.xml +++ b/data/themes/redandblack/colors.xml @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/data/themes/wood/colors.xml b/data/themes/wood/colors.xml index 1f1ac1776..606b45301 100644 --- a/data/themes/wood/colors.xml +++ b/data/themes/wood/colors.xml @@ -49,6 +49,16 @@ + + + + + + + + + + diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index 15554044d..0607564f9 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -644,7 +644,16 @@ static int readColorType(const std::string &type) "SERVER_VERSION_NOT_SUPPORTED", "WARNING", "CHARM", - "PLAYER_ADVANCED" + "PLAYER_ADVANCED", + "RED", + "GREEN", + "BLUE", + "ORANGE", + "YELLOW", + "PINK", + "PURPLE", + "GRAY", + "BROWN" }; if (type.empty()) diff --git a/src/gui/theme.h b/src/gui/theme.h index 4e6a64a6f..fbc6f13da 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -189,6 +189,15 @@ class Theme : public Palette, public ConfigListener WARNING, CHARM, PLAYER_ADVANCED, + RED, + GREEN, + BLUE, + ORANGE, + YELLOW, + PINK, + PURPLE, + GRAY, + BROWN, THEME_COLORS_END }; diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index bb83c1159..65a25363d 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -68,6 +68,15 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque): mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND); mHighlightColor = Theme::getThemeColor(Theme::HIGHLIGHT); mHyperLinkColor = Theme::getThemeColor(Theme::HYPERLINK); + mColors[RED] = Theme::getThemeColor(Theme::RED); + mColors[GREEN] = Theme::getThemeColor(Theme::GREEN); + mColors[BLUE] = Theme::getThemeColor(Theme::BLUE); + mColors[ORANGE] = Theme::getThemeColor(Theme::ORANGE); + mColors[YELLOW] = Theme::getThemeColor(Theme::YELLOW); + mColors[PINK] = Theme::getThemeColor(Theme::PINK); + mColors[PURPLE] = Theme::getThemeColor(Theme::PURPLE); + mColors[GRAY] = Theme::getThemeColor(Theme::GRAY); + mColors[BROWN] = Theme::getThemeColor(Theme::BROWN); } BrowserBox::~BrowserBox() @@ -478,15 +487,15 @@ int BrowserBox::calcHeight() switch (c) { - case '1': selColor = RED; break; - case '2': selColor = GREEN; break; - case '3': selColor = BLUE; break; - case '4': selColor = ORANGE; break; - case '5': selColor = YELLOW; break; - case '6': selColor = PINK; break; - case '7': selColor = PURPLE; break; - case '8': selColor = GRAY; break; - case '9': selColor = BROWN; break; + case '1': selColor = mColors[RED]; break; + case '2': selColor = mColors[GREEN]; break; + case '3': selColor = mColors[BLUE]; break; + case '4': selColor = mColors[ORANGE]; break; + case '5': selColor = mColors[YELLOW]; break; + case '6': selColor = mColors[PINK]; break; + case '7': selColor = mColors[PURPLE]; break; + case '8': selColor = mColors[GRAY]; break; + case '9': selColor = mColors[BROWN]; break; case '0': default: selColor = textColor; diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index 9969bfd3b..cd69ce56f 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -147,27 +147,18 @@ class BrowserBox : public gcn::Widget, AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ }; - /** - * BrowserBox colors. - * - * NOTES (by Javila): - * - color values is "0x" prefix followed by HTML color style. - * - we can add up to 10 different colors: [0..9]. - * - not all colors will be fine with all backgrounds due transparent - * windows and widgets. So, I think it's better keep BrowserBox - * opaque (white background) by default. - */ enum { - RED = 0xff0000, /**< Color 1 */ - GREEN = 0x009000, /**< Color 2 */ - BLUE = 0x0000ff, /**< Color 3 */ - ORANGE = 0xe0980e, /**< Color 4 */ - YELLOW = 0xf1dc27, /**< Color 5 */ - PINK = 0xff00d8, /**< Color 6 */ - PURPLE = 0x8415e2, /**< Color 7 */ - GRAY = 0x919191, /**< Color 8 */ - BROWN = 0x8e4c17 /**< Color 9 */ + RED = 0, + GREEN = 1, + BLUE = 2, + ORANGE = 3, + YELLOW = 4, + PINK = 5, + PURPLE = 6, + GRAY = 7, + BROWN = 8, + COLORS_MAX = 9 }; /** @@ -229,6 +220,7 @@ class BrowserBox : public gcn::Widget, gcn::Color mBackgroundColor; gcn::Color mHighlightColor; gcn::Color mHyperLinkColor; + gcn::Color mColors[COLORS_MAX]; }; #endif -- cgit v1.2.3-70-g09d2 From 1d5e1e10214b2f992888045dc750c8d8b7937b21 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 19:44:25 +0300 Subject: Fix code style. --- src/gui/socialwindow.cpp | 7 ++++++- src/gui/widgets/guildchattab.cpp | 3 ++- 2 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 789d98b73..ca52ea283 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1575,9 +1575,14 @@ void SocialWindow::selectPortal(unsigned num) int SocialWindow::getPortalIndex(int x, int y) { if (mNavigation) - return static_cast(mNavigation)->getPortalIndex(x, y); + { + return static_cast( + mNavigation)->getPortalIndex(x, y); + } else + { return -1; + } } void SocialWindow::addPortal(int x, int y) diff --git a/src/gui/widgets/guildchattab.cpp b/src/gui/widgets/guildchattab.cpp index 0d40506dd..0353ac23f 100644 --- a/src/gui/widgets/guildchattab.cpp +++ b/src/gui/widgets/guildchattab.cpp @@ -49,7 +49,8 @@ GuildChatTab::~GuildChatTab() { } -bool GuildChatTab::handleCommand(const std::string &type, const std::string &args) +bool GuildChatTab::handleCommand(const std::string &type, + const std::string &args) { if (type == "help") { -- cgit v1.2.3-70-g09d2 From a9345c0e74408538488b0a329202ce611a4a0072 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 21:52:49 +0300 Subject: Add support for auto download content fixes. --- src/gui/updaterwindow.cpp | 76 +++++++++++++++++++++++++++++++++++++++++------ src/gui/updaterwindow.h | 13 +++++++- src/utils/stringutils.cpp | 8 +++++ src/utils/stringutils.h | 2 ++ 4 files changed, 89 insertions(+), 10 deletions(-) (limited to 'src/gui') diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index 7534b12a9..ba482919e 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -54,6 +54,7 @@ const std::string xmlUpdateFile = "resources.xml"; const std::string txtUpdateFile = "resources2.txt"; +const std::string updateServer2 = "http://download.evolonline.org/manaplus/updates/"; std::vector loadXMLFile(const std::string &fileName); std::vector loadTxtFile(const std::string &fileName); @@ -137,6 +138,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mDownloadStatus(UPDATE_NEWS), mUpdateHost(updateHost), mUpdatesDir(updatesDir), + mUpdatesDirReal(updatesDir), mCurrentFile("news.txt"), mDownloadProgress(0.0f), mCurrentChecksum(0), @@ -147,6 +149,7 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mMemoryBuffer(NULL), mDownload(NULL), mUpdateIndex(0), + mUpdateIndexOffset(0), mLoadUpdates(applyUpdates), mUpdateType(updateType) { @@ -181,6 +184,10 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, setVisible(true); mCancelButton->requestFocus(); + mUpdateServerPath = mUpdateHost; + removeProtocol(mUpdateServerPath); + logger->log("mUpdateServerPath: %s, %s", mUpdateHost.c_str(), mUpdateServerPath.c_str()); + // Try to download the updates list download(); } @@ -539,8 +546,9 @@ void UpdaterWindow::logic() mProgressBar->setProgress(mDownloadProgress); if (mUpdateFiles.size() && mUpdateIndex <= mUpdateFiles.size()) { - mProgressBar->setText(strprintf("%d/%d", - mUpdateIndex + 1, (int)mUpdateFiles.size() + 1)); + mProgressBar->setText(strprintf("%d/%d", mUpdateIndex + + mUpdateIndexOffset + 1, (int)mUpdateFiles.size() + + (int)mTempUpdateFiles.size() + 1)); } else { @@ -582,13 +590,12 @@ void UpdaterWindow::logic() // Parse current memory buffer as news and dispose of the data loadPatch(); -/* - mCurrentFile = "news.txt"; - mStoreInMemory = true; - mDownloadStatus = UPDATE_NEWS; - download(); // download() changes mDownloadComplete to false -*/ - mDownloadStatus = UPDATE_COMPLETE; + mUpdateHost = updateServer2 + mUpdateServerPath; + mUpdatesDir += "/fix"; + mCurrentFile = xmlUpdateFile; + mStoreInMemory = false; + mDownloadStatus = UPDATE_LIST2; + download(); } break; @@ -681,7 +688,58 @@ void UpdaterWindow::logic() } } break; + case UPDATE_LIST2: + if (mDownloadComplete) + { + if (mCurrentFile == xmlUpdateFile) + { + mTempUpdateFiles = loadXMLFile( + mUpdatesDir + "/" + xmlUpdateFile); + } + mUpdateIndexOffset = mUpdateIndex; + mUpdateIndex = 0; + mStoreInMemory = false; + mDownloadStatus = UPDATE_RESOURCES2; + download(); + } + break; + case UPDATE_RESOURCES2: + if (mDownloadComplete) + { + if (mUpdateIndex < mTempUpdateFiles.size()) + { + updateFile thisFile = mTempUpdateFiles[mUpdateIndex]; + mCurrentFile = thisFile.name; + std::string checksum; + checksum = thisFile.hash; + std::stringstream ss(checksum); + ss >> std::hex >> mCurrentChecksum; + + std::ifstream temp( + (mUpdatesDir + "/" + mCurrentFile).c_str()); + + if (!temp.is_open() || !validateFile(mUpdatesDir + "/" + + mCurrentFile, mCurrentChecksum)) + { + temp.close(); + download(); + } + else + { + temp.close(); + logger->log("%s already here", mCurrentFile.c_str()); + } + mUpdateIndex++; + } + else + { + mUpdatesDir = mUpdatesDirReal; + mDownloadStatus = UPDATE_COMPLETE; + } + } + break; case UPDATE_COMPLETE: + mUpdatesDir = mUpdatesDirReal; enable(); setLabel(_("Completed")); break; diff --git a/src/gui/updaterwindow.h b/src/gui/updaterwindow.h index a1dc556d5..e9a45241f 100644 --- a/src/gui/updaterwindow.h +++ b/src/gui/updaterwindow.h @@ -146,7 +146,9 @@ private: UPDATE_COMPLETE, UPDATE_NEWS, UPDATE_RESOURCES, - UPDATE_PATCH + UPDATE_PATCH, + UPDATE_LIST2, + UPDATE_RESOURCES2 }; /** Status of the current download. */ @@ -158,6 +160,8 @@ private: /** Place where the updates are stored (absolute path). */ std::string mUpdatesDir; + std::string mUpdatesDirReal; + /** The file currently downloading. */ std::string mCurrentFile; @@ -194,9 +198,15 @@ private: /** List of files to download. */ std::vector mUpdateFiles; + /** List of temp files to download. */ + std::vector mTempUpdateFiles; + /** Index of the file to be downloaded. */ unsigned int mUpdateIndex; + /** Index offset for disaplay downloaded file. */ + unsigned int mUpdateIndexOffset; + /** Tells ~UpdaterWindow() if it should load updates */ bool mLoadUpdates; @@ -208,6 +218,7 @@ private: ProgressBar *mProgressBar; /**< Update progress bar. */ BrowserBox *mBrowserBox; /**< Box to display news. */ ScrollArea *mScrollArea; /**< Used to scroll news box. */ + std::string mUpdateServerPath; }; #endif diff --git a/src/utils/stringutils.cpp b/src/utils/stringutils.cpp index 361bc860c..176c5499c 100644 --- a/src/utils/stringutils.cpp +++ b/src/utils/stringutils.cpp @@ -578,3 +578,11 @@ bool findCutFirst(std::string &str1, std::string str2) } return false; } + +std::string &removeProtocol(std::string &url) +{ + int i = url.find("://"); + if (i != (int)std::string::npos) + url = url.substr(i + 3); + return url; +} diff --git a/src/utils/stringutils.h b/src/utils/stringutils.h index c0457bc52..25fe11e2d 100644 --- a/src/utils/stringutils.h +++ b/src/utils/stringutils.h @@ -201,4 +201,6 @@ bool findCutLast(std::string &str1, std::string str2); bool findCutFirst(std::string &str1, std::string str2); +std::string &removeProtocol(std::string &url); + #endif // UTILS_STRINGUTILS_H -- cgit v1.2.3-70-g09d2 From 8002c6f3844e637e246d0bd96dd6253ac91324a3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 28 Aug 2011 23:25:26 +0300 Subject: Fixed invite to guild/kick from guild. Update visible players guild statuses. --- src/gui/popupmenu.cpp | 11 +++++++++++ src/guildmanager.cpp | 17 ++++++++++++++++- 2 files changed, 27 insertions(+), 1 deletion(-) (limited to 'src/gui') diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index a3041fcf7..6db4a408f 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -233,6 +233,17 @@ void PopupMenu::showPopup(int x, int y, Being *being) } } } + else if (guild2->getMember(mNick)) + { + mBrowserBox->addRow(strprintf( + "@@guild-kick|%s@@", _("Kick from guild"))); + if (guild2->getServerGuild()) + { + mBrowserBox->addRow(strprintf( + "@@guild-pos|%s >@@", + _("Change pos in guild"))); + } + } else { if (guild2->getServerGuild() diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 1ce8b9a74..77324e67e 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -161,9 +161,12 @@ void GuildManager::updateList() i ++; } guild->sort(); + createTab(guild); if (actorSpriteManager) + { actorSpriteManager->updatePlayerGuild(); - createTab(guild); + actorSpriteManager->updatePlayerColors(); + } } mTempList.clear(); mGotInfo = true; @@ -346,7 +349,11 @@ bool GuildManager::process(std::string msg) msg, Being::PLAYER); if (b) + { b->clearGuilds(); + b->setGuildName(""); + b->updateColors(); + } } guild->removeMember(msg); @@ -443,6 +450,11 @@ bool GuildManager::afterRemove() return false; guild->removeFromMembers(); guild->clearMembers(); + if (player_node) + { + player_node->setGuildName(""); + player_node->clearGuilds(); + } SERVER_NOTICE(_("You have left the guild.")) delete mTab; mTab = 0; @@ -450,7 +462,10 @@ bool GuildManager::afterRemove() if (socialWindow) socialWindow->removeTab(guild); if (actorSpriteManager) + { + actorSpriteManager->updatePlayerGuild(); actorSpriteManager->updatePlayerColors(); + } reload(); return true; } -- cgit v1.2.3-70-g09d2 From fa57505d930970d38b5f1001f2bfac3a9a45795a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 29 Aug 2011 17:24:52 +0300 Subject: Fix possible crashes in item amount window and spells editor. --- src/gui/itemamountwindow.cpp | 2 +- src/gui/textcommandeditor.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/itemamountwindow.cpp b/src/gui/itemamountwindow.cpp index a3f591634..059f3d785 100644 --- a/src/gui/itemamountwindow.cpp +++ b/src/gui/itemamountwindow.cpp @@ -63,7 +63,7 @@ public: if (i->first < 0) continue; - ItemInfo info = (*i->second); + const ItemInfo &info = (*i->second); std::string name = info.getName(); if (name != "unnamed" && !info.getName().empty() && info.getName() != "unnamed") diff --git a/src/gui/textcommandeditor.cpp b/src/gui/textcommandeditor.cpp index 8cf9fa398..9d759c4a2 100644 --- a/src/gui/textcommandeditor.cpp +++ b/src/gui/textcommandeditor.cpp @@ -71,7 +71,7 @@ public: if (i->first < 0) continue; - ItemInfo info = (*i->second); + const ItemInfo &info = (*i->second); std::string name = info.getName(); if (name != "unnamed" && !info.getName().empty() && info.getName() != "unnamed") -- cgit v1.2.3-70-g09d2 From 9f752d5431364c052b364045015d3574da2c320c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2011 01:57:05 +0300 Subject: Dont create guild manager instance if guild bot support not enabled. --- src/client.cpp | 4 +--- src/game.cpp | 11 ++++------- src/gui/setup_other.cpp | 3 +++ src/gui/socialwindow.cpp | 4 ++-- src/guildmanager.cpp | 7 ++++++- src/guildmanager.h | 6 +++--- src/net/ea/beinghandler.cpp | 2 +- src/net/ea/chathandler.cpp | 2 +- 8 files changed, 21 insertions(+), 18 deletions(-) (limited to 'src/gui') diff --git a/src/client.cpp b/src/client.cpp index 60af41ed3..2e3652188 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -794,9 +794,7 @@ int Client::exec() if (mumbleManager) mumbleManager->setServer(mCurrentServer.hostname); - if (!guildManager) - guildManager = new GuildManager(); - guildManager->init(); + GuildManager::init(); if (!mConfigAutoSaved) { diff --git a/src/game.cpp b/src/game.cpp index 8df48b775..303c59edb 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -177,11 +177,7 @@ static void initEngines() commandHandler = new CommandHandler; channelManager = new ChannelManager; effectManager = new EffectManager; - if (!guildManager) - { - guildManager = new GuildManager; - guildManager->init(); - } + GuildManager::init(); particleEngine = new Particle(NULL); particleEngine->setupEngine(); @@ -338,7 +334,7 @@ static void destroyGuiWindows() Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSUNLOADED)); - if (guildManager && guildManager->getEnableGuildBot()) + if (guildManager && GuildManager::getEnableGuildBot()) guildManager->reload(); } @@ -406,7 +402,7 @@ Game::Game(): setupWindow->setInGame(true); clearKeysArray(); - if (guildManager && guildManager->getEnableGuildBot()) + if (guildManager && GuildManager::getEnableGuildBot()) guildManager->requestGuildInfo(); Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_CONSTRUCTED)); @@ -437,6 +433,7 @@ Game::~Game() del_0(mCurrentMap) del_0(spellManager) del_0(spellShortcut) + del_0(guildManager) del_0(mumbleManager) Being::clearCache(); diff --git a/src/gui/setup_other.cpp b/src/gui/setup_other.cpp index 05ec9d672..1cad4c594 100644 --- a/src/gui/setup_other.cpp +++ b/src/gui/setup_other.cpp @@ -147,6 +147,9 @@ Setup_Other::Setup_Other() new SetupItemLabel(_("Bots support"), "", this); + new SetupItemCheckBox(_("Enable auction bot support"), "", + "enableAuctionBot", this, "enableAuctionBotEvent", false); + new SetupItemCheckBox(_("Enable guild bot support and disable native " "guild support"), "", "enableGuildBot", this, "enableGuildBotEvent", false); diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index ca52ea283..b9c8cb365 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1311,7 +1311,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) strprintf(_("Accepted guild invite from %s."), mPartyInviter.c_str())); } - if (!guildManager || !guildManager->getEnableGuildBot()) + if (!guildManager || !GuildManager::getEnableGuildBot()) Net::getGuildHandler()->inviteResponse(mGuildInvited, true); else guildManager->inviteResponse(true); @@ -1324,7 +1324,7 @@ void SocialWindow::action(const gcn::ActionEvent &event) strprintf(_("Rejected guild invite from %s."), mPartyInviter.c_str())); } - if (!guildManager || !guildManager->getEnableGuildBot()) + if (!guildManager || !GuildManager::getEnableGuildBot()) Net::getGuildHandler()->inviteResponse(mGuildInvited, false); else guildManager->inviteResponse(false); diff --git a/src/guildmanager.cpp b/src/guildmanager.cpp index 77324e67e..2c55caefa 100644 --- a/src/guildmanager.cpp +++ b/src/guildmanager.cpp @@ -38,9 +38,9 @@ #include "debug.h" +bool GuildManager::mEnableGuildBot = false; GuildManager::GuildManager() : - mEnableGuildBot(false), mGotInfo(false), mGotName(false), mHavePower(false), @@ -57,6 +57,9 @@ GuildManager::~GuildManager() void GuildManager::init() { + if (guildManager) + return; + int val = serverConfig.getValue("enableGuildBot", -1); if (val == -1) { @@ -67,6 +70,8 @@ void GuildManager::init() serverConfig.setValue("enableGuildBot", val); } mEnableGuildBot = val; + if (mEnableGuildBot) + guildManager = new GuildManager(); } void GuildManager::reload() diff --git a/src/guildmanager.h b/src/guildmanager.h index d0ee7fb62..80014e352 100644 --- a/src/guildmanager.h +++ b/src/guildmanager.h @@ -37,7 +37,7 @@ class GuildManager ~GuildManager(); - void init(); + static void init(); void chat(std::string msg); @@ -51,7 +51,7 @@ class GuildManager void updateList(); - bool getEnableGuildBot() + static bool getEnableGuildBot() { return mEnableGuildBot; } void kick(std::string msg); @@ -80,7 +80,7 @@ class GuildManager private: bool process(std::string msg); - bool mEnableGuildBot; + static bool mEnableGuildBot; bool mGotInfo; bool mGotName; bool mHavePower; diff --git a/src/net/ea/beinghandler.cpp b/src/net/ea/beinghandler.cpp index 2714f94ce..4a5cfb841 100644 --- a/src/net/ea/beinghandler.cpp +++ b/src/net/ea/beinghandler.cpp @@ -662,7 +662,7 @@ void BeingHandler::processPlayerGuilPartyInfo(Net::MessageIn &msg) if ((dstBeing = actorSpriteManager->findBeing(msg.readInt32()))) { dstBeing->setPartyName(msg.readString(24)); - if (!guildManager || !guildManager->getEnableGuildBot()) + if (!guildManager || !GuildManager::getEnableGuildBot()) dstBeing->setGuildName(msg.readString(24)); dstBeing->setGuildPos(msg.readString(24)); dstBeing->addToCache(); diff --git a/src/net/ea/chathandler.cpp b/src/net/ea/chathandler.cpp index e430dfc0f..5737cc2b2 100644 --- a/src/net/ea/chathandler.cpp +++ b/src/net/ea/chathandler.cpp @@ -162,7 +162,7 @@ void ChatHandler::processWhisper(Net::MessageIn &msg) if (nick != "Server") { - if (guildManager && guildManager->getEnableGuildBot() + if (guildManager && GuildManager::getEnableGuildBot() && nick == "guild" && guildManager->processGuildMessage(chatMsg)) { return; -- cgit v1.2.3-70-g09d2 From 84941829031cbd707ab28802c7423ce19bfba32e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2011 03:26:00 +0300 Subject: Add auction bot support switch. --- manaplus.cbp | 2 ++ src/CMakeLists.txt | 2 ++ src/Makefile.am | 2 ++ src/auctionmanager.cpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/auctionmanager.h | 58 ++++++++++++++++++++++++++++++++ src/client.cpp | 2 ++ src/commandhandler.cpp | 4 ++- src/game.cpp | 11 ++++++- src/gui/shopwindow.cpp | 18 +++++++--- 9 files changed, 182 insertions(+), 6 deletions(-) create mode 100644 src/auctionmanager.cpp create mode 100644 src/auctionmanager.h (limited to 'src/gui') diff --git a/manaplus.cbp b/manaplus.cbp index 992915467..1f7308935 100644 --- a/manaplus.cbp +++ b/manaplus.cbp @@ -109,6 +109,8 @@ + + diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 49b41f906..3b9b41371 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -468,6 +468,8 @@ SET(SRCS animatedsprite.h animationparticle.cpp animationparticle.h + auctionmanager.cpp + auctionmanager.h avatar.cpp avatar.h being.cpp diff --git a/src/Makefile.am b/src/Makefile.am index ca6dd6bc2..45d9df7f0 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -475,6 +475,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ animatedsprite.h \ animationparticle.cpp \ animationparticle.h \ + auctionmanager.cpp \ + auctionmanager.h \ avatar.cpp \ avatar.h \ being.cpp \ diff --git a/src/auctionmanager.cpp b/src/auctionmanager.cpp new file mode 100644 index 000000000..b360279ba --- /dev/null +++ b/src/auctionmanager.cpp @@ -0,0 +1,89 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "auctionmanager.h" + +#include "actorspritemanager.h" +#include "client.h" +#include "configuration.h" +#include "localplayer.h" + +#include "net/chathandler.h" +#include "net/net.h" + +#include "utils/gettext.h" +#include "utils/stringutils.h" + +#include "debug.h" + +bool AuctionManager::mEnableAuctionBot = false; + +AuctionManager::AuctionManager() +{ +} + +AuctionManager::~AuctionManager() +{ +} + +void AuctionManager::init() +{ + if (auctionManager) + return; + + int val = serverConfig.getValue("enableAuctionBot", -1); + if (val == -1) + { + if (Client::isTmw()) + val = 1; + else + val = 0; + serverConfig.setValue("enableAuctionBot", val); + } + mEnableAuctionBot = val; + if (mEnableAuctionBot) + auctionManager = new AuctionManager(); +} + +void AuctionManager::send(std::string msg) +{ + Net::getChatHandler()->privateMessage("AuctionBot", msg); +} + +bool AuctionManager::processAuctionMessage(std::string msg) +{ + if (msg.size() > 4 && msg[0] == '#' && msg[1] == '#') + msg = msg.substr(3); + + return false; +} + +void AuctionManager::clear() +{ +} + +void AuctionManager::reload() +{ +} + +void AuctionManager::sendMail(std::string mail) +{ + Net::getChatHandler()->privateMessage("AuctionBot", "!mail " + mail); +} diff --git a/src/auctionmanager.h b/src/auctionmanager.h new file mode 100644 index 000000000..bdc0497ae --- /dev/null +++ b/src/auctionmanager.h @@ -0,0 +1,58 @@ +/* + * The ManaPlus Client + * Copyright (C) 2011 The ManaPlus Developers + * + * This file is part of The ManaPlus Client. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef AUCTIONMANAGER_H +#define AUCTIONMANAGER_H + +#include "utils/dtor.h" + +#include +#include +#include + +class AuctionManager +{ + public: + AuctionManager(); + + ~AuctionManager(); + + static void init(); + + void send(std::string msg); + + bool processAuctionMessage(std::string msg); + + static bool getEnableAuctionBot() + { return mEnableAuctionBot; } + + void clear(); + + void reload(); + + void sendMail(std::string mail); + + private: + static bool mEnableAuctionBot; +}; + +extern AuctionManager *auctionManager; + +#endif // AUCTIONMANAGER_H diff --git a/src/client.cpp b/src/client.cpp index 2e3652188..403dbd7b3 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -23,6 +23,7 @@ #include "client.h" #include "main.h" +#include "auctionmanager.h" #include "chatlogger.h" #include "configuration.h" #include "dropshortcut.h" @@ -795,6 +796,7 @@ int Client::exec() mumbleManager->setServer(mCurrentServer.hostname); GuildManager::init(); + AuctionManager::init(); if (!mConfigAutoSaved) { diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index 559cfd37e..dc962a17d 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -22,6 +22,7 @@ #include "commandhandler.h" +#include "auctionmanager.h" #include "actorspritemanager.h" #include "channelmanager.h" #include "channel.h" @@ -865,7 +866,8 @@ void CommandHandler::handleHack(const std::string &args, ChatTab *tab A_UNUSED) void CommandHandler::handleMail(const std::string &args, ChatTab *tab A_UNUSED) { - Net::getChatHandler()->privateMessage("AuctionBot", "!mail " + args); + if (auctionManager && auctionManager->getEnableAuctionBot()) + auctionManager->sendMail(args); } void CommandHandler::handlePriceLoad(const std::string &args A_UNUSED, diff --git a/src/game.cpp b/src/game.cpp index 303c59edb..5a372a6bd 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -26,6 +26,7 @@ #include "actorspritemanager.h" #include "actorsprite.h" +#include "auctionmanager.h" #include "being.h" #include "channelmanager.h" #include "client.h" @@ -158,6 +159,7 @@ EffectManager *effectManager = NULL; SpellManager *spellManager = NULL; Viewport *viewport = NULL; /**< Viewport on the map. */ GuildManager *guildManager = NULL; +AuctionManager *auctionManager = NULL; ChatTab *localChatTab = NULL; ChatTab *debugChatTab = NULL; @@ -177,6 +179,7 @@ static void initEngines() commandHandler = new CommandHandler; channelManager = new ChannelManager; effectManager = new EffectManager; + AuctionManager::init(); GuildManager::init(); particleEngine = new Particle(NULL); @@ -298,6 +301,9 @@ static void destroyGuiWindows() if (whoIsOnline) whoIsOnline->setAllowUpdate(false); + if (auctionManager) + auctionManager->clear(); + if (guildManager) guildManager->clear(); @@ -334,6 +340,9 @@ static void destroyGuiWindows() Mana::Event::trigger(CHANNEL_GAME, Mana::Event(EVENT_GUIWINDOWSUNLOADED)); + if (auctionManager && AuctionManager::getEnableAuctionBot()) + auctionManager->reload(); + if (guildManager && GuildManager::getEnableGuildBot()) guildManager->reload(); } @@ -423,7 +432,6 @@ Game::~Game() del_0(actorSpriteManager) if (Client::getState() != STATE_CHANGE_MAP) del_0(player_node) - del_0(guildManager) del_0(channelManager) del_0(commandHandler) del_0(effectManager) @@ -433,6 +441,7 @@ Game::~Game() del_0(mCurrentMap) del_0(spellManager) del_0(spellShortcut) + del_0(auctionManager) del_0(guildManager) del_0(mumbleManager) diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 0988ef759..38985a01c 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -40,6 +40,7 @@ #include "gui/widgets/tradetab.h" #include "actorspritemanager.h" +#include "auctionmanager.h" #include "configuration.h" #include "confirmdialog.h" #include "inventory.h" @@ -119,11 +120,9 @@ ShopWindow::ShopWindow(): mBuyAddButton = new Button(_("Add"), "add buy", this); mBuyDeleteButton = new Button(_("Delete"), "delete buy", this); mBuyAnnounceButton = new Button(_("Announce"), "announce buy", this); - mBuyAuctionButton = new Button(_("Auction"), "auction buy", this); mSellAddButton = new Button(_("Add"), "add sell", this); mSellDeleteButton = new Button(_("Delete"), "delete sell", this); mSellAnnounceButton = new Button(_("Announce"), "announce sell", this); - mSellAuctionButton = new Button(_("Auction"), "auction sell", this); mAnnounceLinks = new CheckBox(_("Show links in announce"), false, this, "link announce"); @@ -137,14 +136,25 @@ ShopWindow::ShopWindow(): place(0, 6, mBuyAddButton); place(1, 6, mBuyDeleteButton); place(3, 6, mBuyAnnounceButton); - place(4, 6, mBuyAuctionButton); place(8, 6, mSellAddButton); place(9, 6, mSellDeleteButton); place(11, 6, mSellAnnounceButton); - place(12, 6, mSellAuctionButton); place(0, 7, mAnnounceLinks, 8); place(15, 7, mCloseButton); + if (auctionManager && auctionManager->getEnableAuctionBot()) + { + mBuyAuctionButton = new Button(_("Auction"), "auction buy", this); + mSellAuctionButton = new Button(_("Auction"), "auction sell", this); + place(4, 6, mBuyAuctionButton); + place(12, 6, mSellAuctionButton); + } + else + { + mBuyAuctionButton = 0; + mSellAuctionButton = 0; + } + Layout &layout = getLayout(); layout.setRowHeight(0, Layout::AUTO_SET); -- cgit v1.2.3-70-g09d2 From 009da07cef098a4ab07cb757950c2a53d6b1ba1a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2011 04:58:32 +0300 Subject: Fix code style and compilation warnings. --- src/client.cpp | 4 ++-- src/gui/updaterwindow.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/client.cpp b/src/client.cpp index bf9e34b00..843f7c961 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -544,7 +544,7 @@ Client::Client(const Options &options): loginData.username = mOptions.username; loginData.password = mOptions.password; - loginData.remember = serverConfig.getValue("remember", true); + loginData.remember = serverConfig.getValue("remember", 1); loginData.registerLogin = false; if (mCurrentServer.hostname.empty()) @@ -790,7 +790,7 @@ int Client::exec() else loginData.username = mOptions.username; - loginData.remember = serverConfig.getValue("remember", true); + loginData.remember = serverConfig.getValue("remember", 1); Net::connectToServer(mCurrentServer); diff --git a/src/gui/updaterwindow.cpp b/src/gui/updaterwindow.cpp index ba482919e..4ba1c9179 100644 --- a/src/gui/updaterwindow.cpp +++ b/src/gui/updaterwindow.cpp @@ -54,7 +54,8 @@ const std::string xmlUpdateFile = "resources.xml"; const std::string txtUpdateFile = "resources2.txt"; -const std::string updateServer2 = "http://download.evolonline.org/manaplus/updates/"; +const std::string updateServer2 + = "http://download.evolonline.org/manaplus/updates/"; std::vector loadXMLFile(const std::string &fileName); std::vector loadTxtFile(const std::string &fileName); @@ -186,7 +187,6 @@ UpdaterWindow::UpdaterWindow(const std::string &updateHost, mUpdateServerPath = mUpdateHost; removeProtocol(mUpdateServerPath); - logger->log("mUpdateServerPath: %s, %s", mUpdateHost.c_str(), mUpdateServerPath.c_str()); // Try to download the updates list download(); -- cgit v1.2.3-70-g09d2 From e4687ac984a6b025548e58bbac8795001d07bff3 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 30 Aug 2011 22:47:15 +0300 Subject: Show guild members on minimap. --- src/gui/minimap.cpp | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'src/gui') diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index c735eec82..dedf8077d 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -279,6 +279,11 @@ void Minimap::draw(gcn::Graphics *graphics) { type = UserPalette::PARTY; } + else if (being->getGuild() == player_node->getGuild() + || being->getGuildName() == player_node->getGuildName()) + { + type = UserPalette::GUILD; + } else if (being) { switch (being->getType()) -- cgit v1.2.3-70-g09d2 From 6d349121a70377723e53b92a8990e56ee3e4fd88 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 31 Aug 2011 01:19:09 +0300 Subject: Always draw party members on same map in minimap. --- src/gui/minimap.cpp | 48 ++++++++++++++++++++++++++++++++++++++++++++---- src/party.h | 6 +++++- 2 files changed, 49 insertions(+), 5 deletions(-) (limited to 'src/gui') diff --git a/src/gui/minimap.cpp b/src/gui/minimap.cpp index dedf8077d..c3a4417f6 100644 --- a/src/gui/minimap.cpp +++ b/src/gui/minimap.cpp @@ -29,6 +29,7 @@ #include "localplayer.h" #include "logger.h" #include "map.h" +#include "party.h" #include "gui/userpalette.h" #include "gui/setup.h" @@ -275,10 +276,6 @@ void Minimap::draw(gcn::Graphics *graphics) { type = UserPalette::GM; } - else if (being->isInParty()) - { - type = UserPalette::PARTY; - } else if (being->getGuild() == player_node->getGuild() || being->getGuildName() == player_node->getGuildName()) { @@ -322,6 +319,49 @@ void Minimap::draw(gcn::Graphics *graphics) dotSize, dotSize)); } + if (player_node->isInParty()) + { + Party *party = player_node->getParty(); + if (party) + { + PartyMember *m = party->getMember(player_node->getName()); + Party::MemberList *members = party->getMembers(); + if (m && members) + { + const std::string curMap = m->getMap(); + Party::MemberList::const_iterator it = members->begin(); + const Party::MemberList::const_iterator + it_end = members->end(); + while (it != it_end) + { + PartyMember *member = *it; + if (member && member->getMap() == curMap + && member->getOnline() && member != m) + { + if (userPalette) + { + graphics->setColor(userPalette->getColor( + UserPalette::PARTY)); + } + + const int offsetHeight = static_cast( + mHeightProportion); + const int offsetWidth = static_cast( + mWidthProportion); + + graphics->fillRectangle(gcn::Rectangle( + static_cast(member->getX() + * mWidthProportion) + mapOriginX - offsetWidth, + static_cast(member->getY() + * mHeightProportion) + mapOriginY - offsetHeight, + 2, 2)); + } + ++ it; + } + } + } + } + const Vector &pos = player_node->getPosition(); // logger->log("width:" + toString(graph->getWidth())); diff --git a/src/party.h b/src/party.h index 466f63a19..e286a794a 100644 --- a/src/party.h +++ b/src/party.h @@ -149,6 +149,11 @@ public: void sort(); + typedef std::vector MemberList; + + MemberList *getMembers() + { return &mMembers; } + static Party *getParty(short id); static void clearParties(); @@ -164,7 +169,6 @@ private: ~Party(); - typedef std::vector MemberList; MemberList mMembers; std::string mName; short mId; -- cgit v1.2.3-70-g09d2 From adeb8e6091694e228f081ca8843e101ae598f26c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Wed, 31 Aug 2011 23:24:57 +0300 Subject: Add ability to lock any window position and size. Using sticky image for this. --- src/gui/botcheckerwindow.cpp | 1 + src/gui/buydialog.cpp | 1 + src/gui/charcreatedialog.cpp | 3 +++ src/gui/chatwindow.cpp | 4 +++- src/gui/debugwindow.cpp | 2 ++ src/gui/didyouknowwindow.cpp | 2 ++ src/gui/equipmentwindow.cpp | 2 ++ src/gui/helpwindow.cpp | 2 ++ src/gui/inventorywindow.cpp | 1 + src/gui/killstats.cpp | 1 + src/gui/npcdialog.cpp | 1 + src/gui/outfitwindow.cpp | 2 ++ src/gui/selldialog.cpp | 1 + src/gui/setup.cpp | 1 + src/gui/shopwindow.cpp | 1 + src/gui/skilldialog.cpp | 1 + src/gui/socialwindow.cpp | 2 ++ src/gui/specialswindow.cpp | 1 + src/gui/statuswindow.cpp | 1 + src/gui/tradewindow.cpp | 1 + src/gui/whoisonline.cpp | 1 + src/gui/widgets/window.cpp | 52 ++++++++++++++++++++++++++++++++++---------- src/gui/widgets/window.h | 15 +++++++++++++ 23 files changed, 86 insertions(+), 13 deletions(-) (limited to 'src/gui') diff --git a/src/gui/botcheckerwindow.cpp b/src/gui/botcheckerwindow.cpp index 4a8f8cf0d..7c0339ead 100644 --- a/src/gui/botcheckerwindow.cpp +++ b/src/gui/botcheckerwindow.cpp @@ -302,6 +302,7 @@ BotCheckerWindow::BotCheckerWindow(): setWindowName("BotCheckerWindow"); setCloseButton(true); + setStickyButtonLock(true); setDefaultSize(w, h, ImageRect::CENTER); playersScrollArea = new ScrollArea(mTable); diff --git a/src/gui/buydialog.cpp b/src/gui/buydialog.cpp index 04dd425c1..8c1ad62ce 100644 --- a/src/gui/buydialog.cpp +++ b/src/gui/buydialog.cpp @@ -72,6 +72,7 @@ void BuyDialog::init() setWindowName("Buy"); setResizable(true); setCloseButton(true); + setStickyButtonLock(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); diff --git a/src/gui/charcreatedialog.cpp b/src/gui/charcreatedialog.cpp index 91c284985..d1773e7f3 100644 --- a/src/gui/charcreatedialog.cpp +++ b/src/gui/charcreatedialog.cpp @@ -60,6 +60,9 @@ CharCreateDialog::CharCreateDialog(CharSelectDialog *parent, int slot): mRace(0), mSlot(slot) { + setStickyButtonLock(true); + setSticky(true); + mPlayer = new Being(0, ActorSprite::PLAYER, mRace, NULL); mPlayer->setGender(GENDER_MALE); diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp index 9c75320a6..784fb812a 100644 --- a/src/gui/chatwindow.cpp +++ b/src/gui/chatwindow.cpp @@ -167,6 +167,8 @@ ChatWindow::ChatWindow(): setResizable(true); setDefaultVisible(true); setSaveVisible(true); + setStickyButtonLock(true); + setDefaultSize(600, 123, ImageRect::LOWER_LEFT); setMinWidth(150); setMinHeight(90); @@ -660,7 +662,7 @@ void ChatWindow::mouseDragged(gcn::MouseEvent &event) if (event.isConsumed()) return; - if (isMovable() && mMoved) + if (canMove() && isMovable() && mMoved) { int newX = std::max(0, getX() + event.getX() - mDragOffsetX); int newY = std::max(0, getY() + event.getY() - mDragOffsetY); diff --git a/src/gui/debugwindow.cpp b/src/gui/debugwindow.cpp index 0b84dda1e..dc540a782 100644 --- a/src/gui/debugwindow.cpp +++ b/src/gui/debugwindow.cpp @@ -60,6 +60,8 @@ DebugWindow::DebugWindow(): setResizable(true); setCloseButton(true); setSaveVisible(true); + setStickyButtonLock(true); + setDefaultSize(400, 150, ImageRect::CENTER); mTabs = new TabbedArea; diff --git a/src/gui/didyouknowwindow.cpp b/src/gui/didyouknowwindow.cpp index 4d89bd924..d62417fc4 100644 --- a/src/gui/didyouknowwindow.cpp +++ b/src/gui/didyouknowwindow.cpp @@ -51,6 +51,8 @@ DidYouKnowWindow::DidYouKnowWindow(): setContentSize(455, 350); setWindowName("DidYouKnow"); setResizable(true); + setStickyButtonLock(true); + setupWindow->registerWindowForReset(this); setDefaultSize(500, 400, ImageRect::CENTER); diff --git a/src/gui/equipmentwindow.cpp b/src/gui/equipmentwindow.cpp index 3abd97c73..0375d096f 100644 --- a/src/gui/equipmentwindow.cpp +++ b/src/gui/equipmentwindow.cpp @@ -80,6 +80,8 @@ EquipmentWindow::EquipmentWindow(Equipment *equipment, Being *being, setCloseButton(true); setSaveVisible(true); + setStickyButtonLock(true); + setDefaultSize(180, 345, ImageRect::CENTER); mBoxes.reserve(13); diff --git a/src/gui/helpwindow.cpp b/src/gui/helpwindow.cpp index 368049389..b772ea36a 100644 --- a/src/gui/helpwindow.cpp +++ b/src/gui/helpwindow.cpp @@ -47,6 +47,8 @@ HelpWindow::HelpWindow(): setContentSize(455, 350); setWindowName("Help"); setResizable(true); + setStickyButtonLock(true); + setupWindow->registerWindowForReset(this); setDefaultSize(500, 400, ImageRect::CENTER); diff --git a/src/gui/inventorywindow.cpp b/src/gui/inventorywindow.cpp index 3b7b7b273..d0454c4e1 100644 --- a/src/gui/inventorywindow.cpp +++ b/src/gui/inventorywindow.cpp @@ -89,6 +89,7 @@ InventoryWindow::InventoryWindow(Inventory *inventory): setResizable(true); setCloseButton(true); setSaveVisible(true); + setStickyButtonLock(true); setDefaultSize(387, 307, ImageRect::CENTER); setMinWidth(316); diff --git a/src/gui/killstats.cpp b/src/gui/killstats.cpp index 05a265da7..b9ce7c2a7 100644 --- a/src/gui/killstats.cpp +++ b/src/gui/killstats.cpp @@ -55,6 +55,7 @@ KillStats::KillStats(): setWindowName("Kill stats"); setCloseButton(true); setResizable(true); + setStickyButtonLock(true); setDefaultSize(250, 250, 350, 300); listen(Mana::CHANNEL_ATTRIBUTES); diff --git a/src/gui/npcdialog.cpp b/src/gui/npcdialog.cpp index 36677446d..0db618d69 100644 --- a/src/gui/npcdialog.cpp +++ b/src/gui/npcdialog.cpp @@ -69,6 +69,7 @@ NpcDialog::NpcDialog(int npcId) setResizable(true); //setupWindow->registerWindowForReset(this); setFocusable(true); + setStickyButtonLock(true); setMinWidth(200); setMinHeight(150); diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index d3bc6a302..3845aaf64 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -72,6 +72,8 @@ OutfitWindow::OutfitWindow(): setWindowName("Outfits"); setResizable(true); setCloseButton(true); + setStickyButtonLock(true); + setDefaultSize(250, 400, 150, 230); setMinWidth(145); setMinHeight(220); diff --git a/src/gui/selldialog.cpp b/src/gui/selldialog.cpp index cf9bfb667..d9030e3fb 100644 --- a/src/gui/selldialog.cpp +++ b/src/gui/selldialog.cpp @@ -69,6 +69,7 @@ void SellDialog::init() //setupWindow->registerWindowForReset(this); setResizable(true); setCloseButton(true); + setStickyButtonLock(true); setMinWidth(260); setMinHeight(230); setDefaultSize(260, 230, ImageRect::CENTER); diff --git a/src/gui/setup.cpp b/src/gui/setup.cpp index 690871189..76e3936c2 100644 --- a/src/gui/setup.cpp +++ b/src/gui/setup.cpp @@ -55,6 +55,7 @@ Setup::Setup(): { setCloseButton(true); setResizable(true); + setStickyButtonLock(true); int width = 620; int height = 450; diff --git a/src/gui/shopwindow.cpp b/src/gui/shopwindow.cpp index 38985a01c..9aaf88bf3 100644 --- a/src/gui/shopwindow.cpp +++ b/src/gui/shopwindow.cpp @@ -86,6 +86,7 @@ ShopWindow::ShopWindow(): setWindowName("Personal Shop"); setResizable(true); setCloseButton(true); + setStickyButtonLock(true); setMinWidth(260); setMinHeight(230); setDefaultSize(380, 300, ImageRect::CENTER); diff --git a/src/gui/skilldialog.cpp b/src/gui/skilldialog.cpp index ff57195a9..bf87e804d 100644 --- a/src/gui/skilldialog.cpp +++ b/src/gui/skilldialog.cpp @@ -279,6 +279,7 @@ SkillDialog::SkillDialog(): setCloseButton(true); setResizable(true); setSaveVisible(true); + setStickyButtonLock(true); setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); setupWindow->registerWindowForReset(this); diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index b9c8cb365..749f26f85 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -1129,6 +1129,8 @@ SocialWindow::SocialWindow() : setResizable(true); setSaveVisible(true); setCloseButton(true); + setStickyButtonLock(true); + setMinWidth(120); setMinHeight(55); setDefaultSize(590, 200, 150, 120); diff --git a/src/gui/specialswindow.cpp b/src/gui/specialswindow.cpp index a5d95c7ff..702c31718 100644 --- a/src/gui/specialswindow.cpp +++ b/src/gui/specialswindow.cpp @@ -82,6 +82,7 @@ SpecialsWindow::SpecialsWindow(): setCloseButton(true); setResizable(true); setSaveVisible(true); + setStickyButtonLock(true); setDefaultSize(windowContainer->getWidth() - 280, 30, 275, 425); setupWindow->registerWindowForReset(this); diff --git a/src/gui/statuswindow.cpp b/src/gui/statuswindow.cpp index 7ab2afa2d..d1fde2dd1 100644 --- a/src/gui/statuswindow.cpp +++ b/src/gui/statuswindow.cpp @@ -132,6 +132,7 @@ StatusWindow::StatusWindow(): setResizable(true); setCloseButton(true); setSaveVisible(true); + setStickyButtonLock(true); setDefaultSize((windowContainer->getWidth() - 365) / 2, (windowContainer->getHeight() - 255) / 2, 365, 275); diff --git a/src/gui/tradewindow.cpp b/src/gui/tradewindow.cpp index d00fb61f4..3c19ee9c2 100644 --- a/src/gui/tradewindow.cpp +++ b/src/gui/tradewindow.cpp @@ -78,6 +78,7 @@ TradeWindow::TradeWindow(): setWindowName("Trade"); setResizable(true); setCloseButton(true); + setStickyButtonLock(true); setDefaultSize(386, 180, ImageRect::CENTER); setMinWidth(386); setMinHeight(180); diff --git a/src/gui/whoisonline.cpp b/src/gui/whoisonline.cpp index 99da53c66..1e9f686e4 100644 --- a/src/gui/whoisonline.cpp +++ b/src/gui/whoisonline.cpp @@ -97,6 +97,7 @@ WhoIsOnline::WhoIsOnline(): // setContentSize(w, h); setCloseButton(true); setResizable(true); + setStickyButtonLock(true); mUpdateButton = new Button(_("Update"), "update", this); mUpdateButton->setEnabled(false); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index cdb9d3d55..9cb7cb620 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -60,6 +60,7 @@ Window::Window(const std::string &caption, bool modal, Window *parent, mSaveVisible(false), mStickyButton(false), mSticky(false), + mStickyButtonLock(false), mMinWinWidth(100), mMinWinHeight(40), mMaxWinWidth(graphics->mWidth), @@ -158,9 +159,9 @@ void Window::draw(gcn::Graphics *graphics) // Draw Close Button if (mCloseButton && mSkin->getCloseImage()) { - g->drawImage(mSkin->getCloseImage(), - getWidth() - mSkin->getCloseImage()->getWidth() - getPadding(), - getPadding()); + Image *button = mSkin->getCloseImage(); + const int x = getWidth() - button->getWidth() - getPadding(); + g->drawImage(button, x, getPadding()); } // Draw Sticky Button @@ -171,7 +172,7 @@ void Window::draw(gcn::Graphics *graphics) { int x = getWidth() - button->getWidth() - getPadding(); if (mCloseButton && mSkin->getCloseImage()) - x -= mSkin->getCloseImage()->getWidth(); + x -= mSkin->getCloseImage()->getWidth() + getPadding(); g->drawImage(button, x, getPadding()); } @@ -399,6 +400,13 @@ void Window::setSticky(bool sticky) mSticky = sticky; } +void Window::setStickyButtonLock(bool lock) +{ + mStickyButtonLock = lock; + mStickyButton = lock; +// mMovable = false; +} + void Window::setVisible(bool visible) { setVisible(visible, false); @@ -413,7 +421,10 @@ void Window::setVisible(bool visible, bool forceSticky) if (visible) checkIfIsOffScreen(); - gcn::Window::setVisible((!forceSticky && isSticky()) || visible); + if (isStickyButtonLock()) + gcn::Window::setVisible(visible); + else + gcn::Window::setVisible((!forceSticky && isSticky()) || visible); } void Window::scheduleDelete() @@ -479,7 +490,10 @@ void Window::mousePressed(gcn::MouseEvent &event) // Handle window resizing mouseResize = getResizeHandles(event); - mMoved = !mouseResize; + if (canMove()) + mMoved = !mouseResize; + else + mMoved = false; } } @@ -541,10 +555,24 @@ void Window::mouseMoved(gcn::MouseEvent &event) viewport->hideBeingPopup(); } +bool Window::canMove() +{ + return !mStickyButtonLock || !mSticky; +} + void Window::mouseDragged(gcn::MouseEvent &event) { - // Let Guichan handle title bar drag - gcn::Window::mouseDragged(event); + if (canMove()) + { + // Let Guichan handle title bar drag + gcn::Window::mouseDragged(event); + } + else + { + if (!event.isConsumed() && event.getSource() == this) + event.consume(); + return; + } // Keep guichan window inside screen when it may be moved if (isMovable() && mMoved) @@ -638,18 +666,18 @@ void Window::loadWindowState() assert(!name.empty()); setPosition(config.getValueInt(name + "WinX", mDefaultX), - config.getValueInt(name + "WinY", mDefaultY)); + config.getValueInt(name + "WinY", mDefaultY)); if (mSaveVisible) { setVisible(config.getValueBool(name - + "Visible", mDefaultVisible)); + + "Visible", mDefaultVisible)); } if (mStickyButton) { setSticky(config.getValueBool(name - + "Sticky", isSticky())); + + "Sticky", isSticky())); } if (mGrip) @@ -811,7 +839,7 @@ void Window::resetToDefaultSize() int Window::getResizeHandles(gcn::MouseEvent &event) { - if (event.getX() < 0 || event.getY() < 0) + if ((mStickyButtonLock && mSticky) || event.getX() < 0 || event.getY() < 0) return 0; int resizeHandles = 0; diff --git a/src/gui/widgets/window.h b/src/gui/widgets/window.h index d36d6c5ad..b9f65dceb 100644 --- a/src/gui/widgets/window.h +++ b/src/gui/widgets/window.h @@ -188,6 +188,17 @@ class Window : public gcn::Window, gcn::WidgetListener bool isSticky() const { return mSticky; } + /** + * Sets whether the window sticky mean window locked or not. + */ + void setStickyButtonLock(bool sticky); + + /** + * Returns whether the window sticky locking window. + */ + bool isStickyButtonLock() const + { return mStickyButtonLock; } + /** * Overloads window setVisible by Guichan to allow sticky window * handling. @@ -387,6 +398,9 @@ class Window : public gcn::Window, gcn::WidgetListener void setCaptionFont(gcn::Font *font) { mCaptionFont = font; } + protected: + bool canMove(); + private: enum ResizeHandles { @@ -423,6 +437,7 @@ class Window : public gcn::Window, gcn::WidgetListener bool mSaveVisible; /**< Window will save visibility */ bool mStickyButton; /**< Window has a sticky button */ bool mSticky; /**< Window resists hiding*/ + bool mStickyButtonLock; /**< Window locked if sticky enabled*/ int mMinWinWidth; /**< Minimum window width */ int mMinWinHeight; /**< Minimum window height */ int mMaxWinWidth; /**< Maximum window width */ -- cgit v1.2.3-70-g09d2 From 5ea9050ac91402262b84749557be61506c4af5d2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2011 04:32:32 +0300 Subject: Fix windows max x and y position. was to one pixel less then screen size. --- src/gui/widgets/window.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 9cb7cb620..7508d4e4b 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -709,10 +709,10 @@ void Window::loadWindowState() int width = getWidth(); int height = getHeight(); - if (getX() + width >= viewport->getWidth()) - width = viewport->getWidth() - getX() - 1; - if (getY() + height >= viewport->getHeight()) - height = viewport->getHeight() - getY() - 1; + if (getX() + width > viewport->getWidth()) + width = viewport->getWidth() - getX(); + if (getY() + height > viewport->getHeight()) + height = viewport->getHeight() - getY(); if (width < 0) width = 0; if (height < 0) -- cgit v1.2.3-70-g09d2 From ab1f66527863c7fcce6c3ccedda0d5560dc063c7 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2011 05:02:40 +0300 Subject: Fix lock window functionality in outfits window. --- src/gui/outfitwindow.cpp | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/gui') diff --git a/src/gui/outfitwindow.cpp b/src/gui/outfitwindow.cpp index 3845aaf64..9601e3ca5 100644 --- a/src/gui/outfitwindow.cpp +++ b/src/gui/outfitwindow.cpp @@ -78,8 +78,6 @@ OutfitWindow::OutfitWindow(): setMinWidth(145); setMinHeight(220); - addMouseListener(this); - mBorderColor = Theme::getThemeColor(Theme::BORDER, 64); mBackgroundColor = Theme::getThemeColor(Theme::BACKGROUND, 32); -- cgit v1.2.3-70-g09d2 From b8cdabbd20690d57930dce9dda949fca21a6233a Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 1 Sep 2011 20:04:35 +0300 Subject: Eliminate asserts from most files. --- src/actorsprite.cpp | 4 ---- src/animatedsprite.cpp | 4 ---- src/being.cpp | 1 - src/client.cpp | 2 -- src/graphics.cpp | 2 -- src/gui/charselectdialog.cpp | 5 ++--- src/gui/popupmenu.cpp | 2 -- src/gui/quitdialog.cpp | 15 +++++---------- src/gui/widgets/layout.cpp | 7 +++++-- src/gui/widgets/window.cpp | 3 ++- src/joystick.cpp | 5 ++--- src/localplayer.cpp | 2 -- src/net/manaserv/messagehandler.cpp | 2 -- src/net/tmwa/generalhandler.cpp | 1 - src/particlecontainer.cpp | 2 -- src/resources/imageloader.cpp | 4 ---- src/resources/itemdb.cpp | 14 +++++++------- src/resources/mapreader.cpp | 6 +++--- src/resources/resource.cpp | 2 -- 19 files changed, 26 insertions(+), 57 deletions(-) (limited to 'src/gui') diff --git a/src/actorsprite.cpp b/src/actorsprite.cpp index 848e84e0f..2b133eca5 100644 --- a/src/actorsprite.cpp +++ b/src/actorsprite.cpp @@ -477,9 +477,6 @@ void ActorSprite::loadTargetCursor(const std::string &filename, if (size < TC_SMALL || size >= NUM_TC) return; -// assert(size > -1); -// assert(size < 3); - ResourceManager *resman = ResourceManager::getInstance(); ImageSet *currentImageSet = resman->getImageSet(filename, width, height); @@ -493,7 +490,6 @@ void ActorSprite::loadTargetCursor(const std::string &filename, for (unsigned int i = 0; i < currentImageSet->size(); ++i) { -// anim->addFrame(currentImageSet->get(i), 0, anim->addFrame(currentImageSet->get(i), 75, (16 - (currentImageSet->getWidth() / 2)), (16 - (currentImageSet->getHeight() / 2)), diff --git a/src/animatedsprite.cpp b/src/animatedsprite.cpp index 7414c94bc..27be02e36 100644 --- a/src/animatedsprite.cpp +++ b/src/animatedsprite.cpp @@ -32,8 +32,6 @@ #include "utils/xml.h" -#include - #include "debug.h" AnimatedSprite::AnimatedSprite(SpriteDef *sprite): @@ -46,8 +44,6 @@ AnimatedSprite::AnimatedSprite(SpriteDef *sprite): mAnimation(0), mFrame(0) { -// assert(mSprite); - mAlpha = 1.0f; // Take possession of the sprite diff --git a/src/being.cpp b/src/being.cpp index 2d9194c6e..6d35f1df0 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -79,7 +79,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include #include #include "debug.h" diff --git a/src/client.cpp b/src/client.cpp index 843f7c961..ab176c00b 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -114,7 +114,6 @@ #endif #include -#include #include #include @@ -260,7 +259,6 @@ Client::Client(const Options &options): mMouseFocused(true), mGuiAlpha(1.0f) { - assert(!mInstance); mInstance = this; logger = new Logger; diff --git a/src/graphics.cpp b/src/graphics.cpp index c5dc38b72..abd7341e2 100644 --- a/src/graphics.cpp +++ b/src/graphics.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#include - #include "graphics.h" #include "graphicsvertexes.h" diff --git a/src/gui/charselectdialog.cpp b/src/gui/charselectdialog.cpp index 28c7a083c..1942ebaeb 100644 --- a/src/gui/charselectdialog.cpp +++ b/src/gui/charselectdialog.cpp @@ -60,7 +60,6 @@ #include #include -#include #include "debug.h" @@ -342,8 +341,8 @@ void CharSelectDialog::setCharacters(const Net::Characters &characters) void CharSelectDialog::lock() { - assert(!mLocked); - setLocked(true); + if (!mLocked) + setLocked(true); } void CharSelectDialog::unlock() diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 6db4a408f..0eac0a4f9 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -78,8 +78,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - #include "debug.h" std::string tradePartnerName(""); diff --git a/src/gui/quitdialog.cpp b/src/gui/quitdialog.cpp index f66872b5d..04f43fb88 100644 --- a/src/gui/quitdialog.cpp +++ b/src/gui/quitdialog.cpp @@ -41,23 +41,17 @@ #include "utils/gettext.h" -#include - #include "debug.h" QuitDialog::QuitDialog(QuitDialog** pointerToMe): Window(_("Quit"), true, NULL), mMyPointer(pointerToMe) { -// int width = 200; -// int height = 120; - mForceQuit = new RadioButton(_("Quit"), "quitdialog"); mLogoutQuit = new RadioButton(_("Quit"), "quitdialog"); mSwitchAccountServer = new RadioButton(_("Switch server"), "quitdialog"); mSwitchCharacter = new RadioButton(_("Switch character"), "quitdialog"); mOkButton = new Button(_("OK"), "ok", this); mCancelButton = new Button(_("Cancel"), "cancel", this); -// setContentSize(width, height); addKeyListener(this); @@ -149,10 +143,11 @@ void QuitDialog::action(const gcn::ActionEvent &event) } else if (mSwitchCharacter->isSelected()) { - assert(Client::getState() == STATE_GAME); - - Net::getCharHandler()->switchCharacter(); - Client::closeDialogs(); + if (Client::getState() == STATE_GAME) + { + Net::getCharHandler()->switchCharacter(); + Client::closeDialogs(); + } } } scheduleDelete(); diff --git a/src/gui/widgets/layout.cpp b/src/gui/widgets/layout.cpp index 382d169dc..a14b416ce 100644 --- a/src/gui/widgets/layout.cpp +++ b/src/gui/widgets/layout.cpp @@ -68,7 +68,9 @@ LayoutArray &LayoutCell::getArray() void LayoutCell::reflow(int nx, int ny, int nw, int nh) { - assert(mType != NONE); + if (mType == NONE) + return; + nx += mHPadding; ny += mVPadding; nw -= 2 * mHPadding; @@ -81,7 +83,8 @@ void LayoutCell::reflow(int nx, int ny, int nw, int nh) void LayoutCell::computeSizes() { - assert(mType == ARRAY); + if (mType != ARRAY) + return; std::vector< std::vector< LayoutCell * > >::iterator i = mArray->mCells.begin(); diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 7508d4e4b..0a3779307 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -663,7 +663,8 @@ void Window::setModal(bool modal) void Window::loadWindowState() { const std::string &name = mWindowName; - assert(!name.empty()); + if (name.empty()) + return; setPosition(config.getValueInt(name + "WinX", mDefaultX), config.getValueInt(name + "WinY", mDefaultY)); diff --git a/src/joystick.cpp b/src/joystick.cpp index 8f808a2d1..f45729351 100644 --- a/src/joystick.cpp +++ b/src/joystick.cpp @@ -24,8 +24,6 @@ #include "joystick.h" #include "logger.h" -#include - #include "debug.h" int Joystick::joystickCount = 0; @@ -48,7 +46,8 @@ Joystick::Joystick(int no): mCalibrating(false), mEnabled(false) { - assert(no < joystickCount); + if (no >= joystickCount) + no = joystickCount; mJoystick = SDL_JoystickOpen(no); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5192390bc..e9386a5ee 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -78,8 +78,6 @@ #include "utils/gettext.h" #include "utils/stringutils.h" -#include - #include "mumblemanager.h" #include "debug.h" diff --git a/src/net/manaserv/messagehandler.cpp b/src/net/manaserv/messagehandler.cpp index 7524c95e8..2e9603f19 100644 --- a/src/net/manaserv/messagehandler.cpp +++ b/src/net/manaserv/messagehandler.cpp @@ -24,8 +24,6 @@ #include "net/manaserv/network.h" -#include - namespace ManaServ { diff --git a/src/net/tmwa/generalhandler.cpp b/src/net/tmwa/generalhandler.cpp index 746cb6620..5ebeb5da9 100644 --- a/src/net/tmwa/generalhandler.cpp +++ b/src/net/tmwa/generalhandler.cpp @@ -67,7 +67,6 @@ #include "utils/gettext.h" -#include #include #include "debug.h" diff --git a/src/particlecontainer.cpp b/src/particlecontainer.cpp index d00c68a63..70b1e2c84 100644 --- a/src/particlecontainer.cpp +++ b/src/particlecontainer.cpp @@ -20,8 +20,6 @@ * along with this program. If not, see . */ -#include - #include "particle.h" #include "particlecontainer.h" diff --git a/src/resources/imageloader.cpp b/src/resources/imageloader.cpp index c63d33c00..72a839573 100644 --- a/src/resources/imageloader.cpp +++ b/src/resources/imageloader.cpp @@ -29,8 +29,6 @@ #include -#include - #include "debug.h" #ifdef free @@ -79,12 +77,10 @@ int ProxyImage::getHeight() const return mImage->mBounds.h; else return 0; -// return mSDLImage ? mSDLImage->h : mImage->getHeight(); } gcn::Color ProxyImage::getPixel(int x, int y) { - assert(mSDLImage); return gcn::SDLgetPixel(mSDLImage, x, y); } diff --git a/src/resources/itemdb.cpp b/src/resources/itemdb.cpp index 394aa74be..733c12958 100644 --- a/src/resources/itemdb.cpp +++ b/src/resources/itemdb.cpp @@ -36,8 +36,6 @@ #include -#include - #include "debug.h" namespace @@ -435,7 +433,8 @@ void ItemDB::unload() bool ItemDB::exists(int id) { - assert(mLoaded); + if (!mLoaded) + return false; ItemInfos::const_iterator i = mItemInfos.find(id); @@ -444,7 +443,8 @@ bool ItemDB::exists(int id) const ItemInfo &ItemDB::get(int id) { - assert(mLoaded); + if (!mLoaded) + load(); ItemInfos::const_iterator i = mItemInfos.find(id); @@ -459,7 +459,8 @@ const ItemInfo &ItemDB::get(int id) const ItemInfo &ItemDB::get(const std::string &name) { - assert(mLoaded); + if (!mLoaded) + load(); NamedItemInfos::const_iterator i = mNamedItemInfos.find(normalize(name)); @@ -597,7 +598,7 @@ void loadSoundRef(ItemInfo *itemInfo, xmlNodePtr node) else { logger->log("ItemDB: Ignoring unknown sound event '%s'", - event.c_str()); + event.c_str()); } } @@ -656,7 +657,6 @@ void loadReplaceSprite(ItemInfo *itemInfo, xmlNodePtr replaceNode) } case -2: { - logger->log("parse -2"); for_each_xml_child_node(itemNode, replaceNode) { if (xmlStrEqual(itemNode->name, BAD_CAST "item")) diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 70c45054f..685d415ff 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -37,7 +37,6 @@ #include "utils/stringutils.h" #include "utils/xml.h" -#include #include #include @@ -110,7 +109,8 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } ret = inflate(&strm, Z_NO_FLUSH); - assert(ret != Z_STREAM_ERROR); + if (ret == Z_STREAM_ERROR) + return ret; switch (ret) { @@ -140,7 +140,7 @@ int inflateMemory(unsigned char *in, unsigned int inLength, } } while (ret != Z_STREAM_END); - assert(strm.avail_in == 0); +// assert(strm.avail_in == 0); outLength = bufferSize - strm.avail_out; (void) inflateEnd(&strm); diff --git a/src/resources/resource.cpp b/src/resources/resource.cpp index b180712c1..552af06ec 100644 --- a/src/resources/resource.cpp +++ b/src/resources/resource.cpp @@ -27,8 +27,6 @@ #include "resources/resourcemanager.h" -#include - #include "debug.h" Resource::~Resource() -- cgit v1.2.3-70-g09d2 From 9a441d3bf00ac6aafd8c3c48160112af2459fa0e Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 2 Sep 2011 03:40:40 +0300 Subject: Add some more debug info in camera moving. --- src/gui/viewport.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index a5b541a8e..b2e9d8d20 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -185,15 +185,20 @@ void Viewport::draw(gcn::Graphics *gcnGraphics) - player_y > graphics->getHeight() / 2 || player_y - static_cast(mPixelViewY) > graphics->getHeight() / 2) { - mPixelViewX = static_cast(player_x); - mPixelViewY = static_cast(player_y); if (player_x <= 0 || player_y <= 0) { if (debugChatTab) debugChatTab->chatLog("incorrect player position!"); - logger->log("incorrect player position: %d, %d", - player_x, player_y); + logger->log("incorrect player position: %d, %d, %d, %d", + player_x, player_y, (int)mPixelViewX, (int)mPixelViewY); + if (player_node) + { + logger->log("tile position: %d, %d", + player_node->getTileX(), player_node->getTileY()); + } } + mPixelViewX = static_cast(player_x); + mPixelViewY = static_cast(player_y); }; // Don't move camera so that the end of the map is on screen -- cgit v1.2.3-70-g09d2 From f117a2b94fcfd67d05652ab8a89cf8d7559b96a9 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 2 Sep 2011 18:26:22 +0300 Subject: Add option to disable self heal with mouse click. --- src/defaults.cpp | 1 + src/gui/setup_players.cpp | 3 +++ src/gui/viewport.cpp | 18 ++++++++++++++---- src/gui/viewport.h | 1 + 4 files changed, 19 insertions(+), 4 deletions(-) (limited to 'src/gui') diff --git a/src/defaults.cpp b/src/defaults.cpp index 16f4620d4..7c0d8148c 100644 --- a/src/defaults.cpp +++ b/src/defaults.cpp @@ -216,6 +216,7 @@ DefaultsData* getConfigDefaults() AddDEF(configData, "disableBeingCaching", false); AddDEF(configData, "enableReorderSprites", true); AddDEF(configData, "showip", false); + AddDEF(configData, "seflMouseHeal", true); return configData; } diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 78c77f6f1..670fc3635 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -78,6 +78,9 @@ Setup_Players::Setup_Players() new SetupItemCheckBox(_("Show ip addresses on screenshots"), "", "showip", this, "showipEvent"); + new SetupItemCheckBox(_("Allow self heal with mouse click"), "", + "selfMouseHeal", this, "selfMouseHealEvent"); + setDimension(gcn::Rectangle(0, 0, 550, 350)); } diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index b2e9d8d20..b6e09c011 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -79,10 +79,12 @@ Viewport::Viewport(): mScrollCenterOffsetX = config.getIntValue("ScrollCenterOffsetX"); mScrollCenterOffsetY = config.getIntValue("ScrollCenterOffsetY"); mShowBeingPopup = config.getBoolValue("showBeingPopup"); + mSelfMouseHeal = config.getBoolValue("selfMouseHeal"); config.addListener("ScrollLaziness", this); config.addListener("ScrollRadius", this); config.addListener("showBeingPopup", this); + config.addListener("selfMouseHeal", this); mPopupMenu = new PopupMenu; mBeingPopup = new BeingPopup; @@ -96,6 +98,7 @@ Viewport::~Viewport() config.removeListener("ScrollLaziness", this); config.removeListener("ScrollRadius", this); config.removeListener("showBeingPopup", this); + config.removeListener("selfMouseHeal", this); delete mPopupMenu; mPopupMenu = 0; @@ -473,17 +476,24 @@ void Viewport::mousePressed(gcn::MouseEvent &event) if (mHoverBeing->getType() == ActorSprite::PLAYER) { if (actorSpriteManager) - actorSpriteManager->heal(player_node, mHoverBeing); + { + if (player_node != mHoverBeing || mSelfMouseHeal) + actorSpriteManager->heal(player_node, mHoverBeing); + } } else if (player_node->withinAttackRange(mHoverBeing) || keyboard.isKeyActive(keyboard.KEY_ATTACK)) { - player_node->attack(mHoverBeing, - !keyboard.isKeyActive(keyboard.KEY_TARGET)); + if (player_node != mHoverBeing) + { + player_node->attack(mHoverBeing, + !keyboard.isKeyActive(keyboard.KEY_TARGET)); + } } else if (!keyboard.isKeyActive(keyboard.KEY_ATTACK)) { - player_node->setGotoTarget(mHoverBeing); + if (player_node != mHoverBeing) + player_node->setGotoTarget(mHoverBeing); } } // Picks up a item if we clicked on one diff --git a/src/gui/viewport.h b/src/gui/viewport.h index d6ee54834..50c81aff4 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -285,6 +285,7 @@ class Viewport : public WindowContainer, public gcn::MouseListener, int mScrollRadius; int mScrollLaziness; bool mShowBeingPopup; + bool mSelfMouseHeal; int mScrollCenterOffsetX; int mScrollCenterOffsetY; int mMouseX; /**< Current mouse position in pixels. */ -- cgit v1.2.3-70-g09d2 From 45a9bbd34cda3c784b935860a4cc616a0314a57c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 2 Sep 2011 20:06:58 +0300 Subject: Replace guichan iterators to const_iterator if need. --- src/gui/widgets/container.cpp | 2 +- src/gui/widgets/container.h | 4 ++++ src/gui/widgets/window.cpp | 2 +- src/guichan/basiccontainer.cpp | 22 +++++++++++----------- src/guichan/include/guichan/basiccontainer.hpp | 10 ++++++++++ src/guichan/widgets/window.cpp | 2 +- 6 files changed, 28 insertions(+), 14 deletions(-) (limited to 'src/gui') diff --git a/src/gui/widgets/container.cpp b/src/gui/widgets/container.cpp index 96cea7119..558257507 100644 --- a/src/gui/widgets/container.cpp +++ b/src/gui/widgets/container.cpp @@ -37,7 +37,7 @@ Container::~Container() bool Container::safeRemove(gcn::Widget* widget) { - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++iter) { if (*iter == widget) diff --git a/src/gui/widgets/container.h b/src/gui/widgets/container.h index 1d8872477..c011b8925 100644 --- a/src/gui/widgets/container.h +++ b/src/gui/widgets/container.h @@ -26,6 +26,10 @@ #include #include +#if !defined USE_INTERNALGUICHAN +typedef std::list::const_iterator WidgetListConstIterator; +#endif + /** * A widget container. * diff --git a/src/gui/widgets/window.cpp b/src/gui/widgets/window.cpp index 0a3779307..4435496a7 100644 --- a/src/gui/widgets/window.cpp +++ b/src/gui/widgets/window.cpp @@ -368,7 +368,7 @@ void Window::widgetHidden(const gcn::Event &event A_UNUSED) if (gui) gui->setCursorType(Gui::CURSOR_POINTER); - WidgetListIterator it; + WidgetListConstIterator it; if (!mFocusHandler) return; diff --git a/src/guichan/basiccontainer.cpp b/src/guichan/basiccontainer.cpp index d51968eb6..439535c9a 100644 --- a/src/guichan/basiccontainer.cpp +++ b/src/guichan/basiccontainer.cpp @@ -110,7 +110,7 @@ namespace gcn void BasicContainer::focusNext() { - WidgetListIterator it; + WidgetListConstIterator it; for (it = mWidgets.begin(); it != mWidgets.end(); ++ it) { @@ -118,7 +118,7 @@ namespace gcn break; } - WidgetListIterator end = it; + WidgetListConstIterator end = it; if (it == mWidgets.end()) it = mWidgets.begin(); @@ -140,7 +140,7 @@ namespace gcn void BasicContainer::focusPrevious() { - WidgetListReverseIterator it; + WidgetListCReverseIterator it; for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it) { @@ -148,7 +148,7 @@ namespace gcn break; } - WidgetListReverseIterator end = it; + WidgetListCReverseIterator end = it; ++ it; @@ -178,7 +178,7 @@ namespace gcn x -= r.x; y -= r.y; - WidgetListReverseIterator it; + WidgetListCReverseIterator it; for (it = mWidgets.rbegin(); it != mWidgets.rend(); ++ it) { if ((*it)->isVisible() && (*it)->getDimension() @@ -203,7 +203,7 @@ namespace gcn if (mInternalFocusHandler != NULL) return; - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) { (*iter)->_setFocusHandler(focusHandler); @@ -243,7 +243,7 @@ namespace gcn void BasicContainer::clear() { - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) { @@ -259,7 +259,7 @@ namespace gcn { graphics->pushClipArea(getChildrenArea()); - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) { if ((*iter)->isVisible()) @@ -289,7 +289,7 @@ namespace gcn void BasicContainer::logicChildren() { - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) (*iter)->logic(); } @@ -324,7 +324,7 @@ namespace gcn { Widget::setInternalFocusHandler(focusHandler); - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) { if (mInternalFocusHandler == NULL) @@ -336,7 +336,7 @@ namespace gcn Widget* BasicContainer::findWidgetById(const std::string& id) { - WidgetListIterator iter; + WidgetListConstIterator iter; for (iter = mWidgets.begin(); iter != mWidgets.end(); ++ iter) { if ((*iter)->getId() == id) diff --git a/src/guichan/include/guichan/basiccontainer.hpp b/src/guichan/include/guichan/basiccontainer.hpp index 998e1f601..6163b6535 100644 --- a/src/guichan/include/guichan/basiccontainer.hpp +++ b/src/guichan/include/guichan/basiccontainer.hpp @@ -167,11 +167,21 @@ namespace gcn */ typedef WidgetList::iterator WidgetListIterator; + /** + * Typedef. + */ + typedef WidgetList::const_iterator WidgetListConstIterator; + /** * Typedef. */ typedef WidgetList::reverse_iterator WidgetListReverseIterator; + /** + * Typedef. + */ + typedef WidgetList::const_reverse_iterator WidgetListCReverseIterator; + /** * Holds all widgets of the basic container. */ diff --git a/src/guichan/widgets/window.cpp b/src/guichan/widgets/window.cpp index 4779fb0ce..7b04981c2 100644 --- a/src/guichan/widgets/window.cpp +++ b/src/guichan/widgets/window.cpp @@ -279,7 +279,7 @@ namespace gcn void Window::resizeToContent() { - WidgetListIterator it; + WidgetListConstIterator it; int w = 0, h = 0; for (it = mWidgets.begin(); it != mWidgets.end(); it++) -- cgit v1.2.3-70-g09d2