From e750667bd241fa4df353af591adec52427419361 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Tue, 28 Sep 2010 19:18:21 +0200 Subject: Removing click-count Click-count is not double-click, because it does neither check if the clicks happen on the same object nor if the clicks happen in rapid succession. * In the server dialog it can happen that you can get connected by just selecting a server. * In the social window it can happen that you open a chat by just clicking once on a name. * In the inventory window you better only select useable items if you want to use them, because they might get used by just selecting them. * And in case you actually want to use double-click, it often does not work, because click-count is already larger than 2. This reverts the commits: 8b4d9f9b5eaf175baf0c4209c312133bb457742c b1aef06ac85b1ed7db7725e50b2dbfcdfd1a0925 4c27bfbf6ca84546e5b914b7909df14dd2966081 Reviewed-by: Thorbjorn --- src/gui/serverdialog.cpp | 11 ----------- src/gui/serverdialog.h | 3 --- src/gui/widgets/avatarlistbox.cpp | 9 --------- src/gui/widgets/itemcontainer.cpp | 40 ++++----------------------------------- 4 files changed, 4 insertions(+), 59 deletions(-) (limited to 'src') diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index 09ba7cd1..c8a16b35 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -213,7 +213,6 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): mServersListModel = new ServersListModel(&mServers, this); mServersList = new ServersListBox(mServersListModel); - mServersList->addMouseListener(this); ScrollArea *usedScroll = new ScrollArea(mServersList); usedScroll->setHorizontalScrollPolicy(gcn::ScrollArea::SHOW_NEVER); @@ -414,16 +413,6 @@ void ServerDialog::valueChanged(const gcn::SelectionEvent &) mDeleteButton->setEnabled(myServer.save); } -void ServerDialog::mouseClicked(gcn::MouseEvent &mouseEvent) -{ - if (mouseEvent.getClickCount() == 2 && - mouseEvent.getSource() == mServersList) - { - action(gcn::ActionEvent(mConnectButton, - mConnectButton->getActionEventId())); - } -} - void ServerDialog::logic() { { diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index 03ed0f7a..ed733f9c 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -32,7 +32,6 @@ #include #include #include -#include #include #include @@ -136,8 +135,6 @@ class ServerDialog : public Window, */ void valueChanged(const gcn::SelectionEvent &event); - void mouseClicked(gcn::MouseEvent &mouseEvent); - void logic(); protected: diff --git a/src/gui/widgets/avatarlistbox.cpp b/src/gui/widgets/avatarlistbox.cpp index 6ec4d1e8..cc2c7d6a 100644 --- a/src/gui/widgets/avatarlistbox.cpp +++ b/src/gui/widgets/avatarlistbox.cpp @@ -22,7 +22,6 @@ #include "graphics.h" -#include "gui/chat.h" #include "gui/gui.h" #include "gui/palette.h" #include "gui/theme.h" @@ -139,14 +138,6 @@ void AvatarListBox::mousePressed(gcn::MouseEvent &event) int y = event.getY(); setSelected(y / getFont()->getHeight()); distributeActionEvent(); - - if (event.getClickCount() == 2 && mListModel) - { - int selected = getSelected(); - AvatarListModel *model = static_cast(mListModel); - chatWindow->addWhisperTab(model->getAvatarAt(selected)->getName(), - true); - } } // TODO: Add support for context menu else if (event.getButton() == gcn::MouseEvent::RIGHT) diff --git a/src/gui/widgets/itemcontainer.cpp b/src/gui/widgets/itemcontainer.cpp index 7648eb24..fb5105b2 100644 --- a/src/gui/widgets/itemcontainer.cpp +++ b/src/gui/widgets/itemcontainer.cpp @@ -255,46 +255,14 @@ void ItemContainer::mousePressed(gcn::MouseEvent &event) if (mSelectedIndex == index) { - if(event.getClickCount() == 2) - { - if (item->isEquipment()) - { - if (item->isEquipped()) - Net::getInventoryHandler()->unequipItem(item); - else - Net::getInventoryHandler()->equipItem(item); - } - else - Net::getInventoryHandler()->useItem(item); - - } - else - { - mSelectionStatus = SEL_DESELECTING; - } + mSelectionStatus = SEL_DESELECTING; } else if (item && item->getId()) { - if(event.getClickCount() == 2) - { - if (item->isEquipment()) - { - if (item->isEquipped()) - Net::getInventoryHandler()->unequipItem(item); - else - Net::getInventoryHandler()->equipItem(item); - } - else - Net::getInventoryHandler()->useItem(item); + setSelectedIndex(index); + mSelectionStatus = SEL_SELECTING; + itemShortcut->setItemSelected(item->getId()); - } - else - { - setSelectedIndex(index); - mSelectionStatus = SEL_SELECTING; - - itemShortcut->setItemSelected(item->getId()); - } if (item->isEquipment()) outfitWindow->setItemSelected(item->getId()); } -- cgit v1.2.3-70-g09d2 From 0385c87b9ba9ae212004c7f46132ec4cc895dc05 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Wed, 29 Sep 2010 21:07:20 +0200 Subject: Fixing segfault when switching server Reviewed-by: Thorbjorn --- src/net/tmwa/playerhandler.cpp | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src') diff --git a/src/net/tmwa/playerhandler.cpp b/src/net/tmwa/playerhandler.cpp index 16f1ee53..48e7f4b3 100644 --- a/src/net/tmwa/playerhandler.cpp +++ b/src/net/tmwa/playerhandler.cpp @@ -168,6 +168,9 @@ PlayerHandler::PlayerHandler() void PlayerHandler::handleMessage(Net::MessageIn &msg) { + if (!player_node) + return; + switch (msg.getId()) { case SMSG_WALK_RESPONSE: -- cgit v1.2.3-70-g09d2 From 9da7effa3dd8bbacbc58d2be47a17d631e261c81 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 12 Sep 2010 20:49:11 +0300 Subject: Improve chat speed. Parse chat lines in BrowserBox once after changes. Reviewed-by: Thorbjorn --- src/gui/widgets/browserbox.cpp | 260 ++++++++++++----------------------------- src/gui/widgets/browserbox.h | 60 ++++++++-- src/gui/widgets/chattab.cpp | 1 + 3 files changed, 128 insertions(+), 193 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index d43afed7..6ae4c588 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -2,6 +2,7 @@ * The Mana Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2009 Aethyra Development Team * * This file is part of The Mana Client. * @@ -21,6 +22,8 @@ #include "gui/widgets/browserbox.h" +#include "client.h" + #include "gui/theme.h" #include "gui/widgets/linkhandler.h" @@ -40,7 +43,9 @@ BrowserBox::BrowserBox(unsigned int mode, bool opaque): mMaxRows(0), mHeight(0), mWidth(0), - mYStart(0) + mYStart(0), + mUpdateTime(-1), + mAlwaysUpdate(true) { setFocusable(true); addMouseListener(this); @@ -74,13 +79,14 @@ void BrowserBox::addRow(const std::string &row) { std::string tmp = row; std::string newRow; - BROWSER_LINK bLink; std::string::size_type idx1, idx2, idx3; gcn::Font *font = getFont(); // Use links and user defined colors if (mUseLinksAndUserColors) { + BROWSER_LINK bLink; + // Check for links in format "@@link|Caption@@" idx1 = tmp.find("@@"); while (idx1 != std::string::npos) @@ -92,7 +98,7 @@ void BrowserBox::addRow(const std::string &row) break; bLink.link = tmp.substr(idx1 + 2, idx2 - (idx1 + 2)); bLink.caption = tmp.substr(idx2 + 1, idx3 - (idx2 + 1)); - bLink.y1 = mTextRows.size() * font->getHeight(); + bLink.y1 = static_cast(mTextRows.size()) * font->getHeight(); bLink.y2 = bLink.y1 + font->getHeight(); newRow += tmp.substr(0, idx1); @@ -150,7 +156,7 @@ void BrowserBox::addRow(const std::string &row) if (mMode == AUTO_SIZE) { std::string plain = newRow; - for (idx1 = plain.find("##"); idx1 != std::string::npos; idx1 = plain.find("##")) + while ((idx1 = plain.find("##")) != std::string::npos) plain.erase(idx1, 3); // Adjust the BrowserBox size @@ -179,11 +185,11 @@ void BrowserBox::addRow(const std::string &row) // Wraping between words (at blank spaces) if ((nextChar < row.size()) && (row.at(nextChar) == ' ')) { - int nextSpacePos = row.find(" ", (nextChar + 1)); + int nextSpacePos = static_cast( + row.find(" ", (nextChar + 1))); if (nextSpacePos <= 0) - { - nextSpacePos = row.size() - 1; - } + nextSpacePos = static_cast(row.size()) - 1; + int nextWordWidth = font->getWidth( row.substr(nextChar, (nextSpacePos - nextChar))); @@ -204,11 +210,12 @@ void BrowserBox::addRow(const std::string &row) } } - setHeight(font->getHeight() * (mTextRows.size() + y)); + setHeight(font->getHeight() * (static_cast( + mTextRows.size()) + y)); } else { - setHeight(font->getHeight() * mTextRows.size()); + setHeight(font->getHeight() * static_cast(mTextRows.size())); } updateHeight(); } @@ -225,7 +232,9 @@ void BrowserBox::clearRows() struct MouseOverLink { - MouseOverLink(int x, int y) : mX(x),mY(y) { } + MouseOverLink(int x, int y) : mX(x), mY(y) + { } + bool operator() (BROWSER_LINK &link) { return (mX >= link.x1 && mX < link.x2 && @@ -249,7 +258,8 @@ void BrowserBox::mouseMoved(gcn::MouseEvent &event) LinkIterator i = find_if(mLinks.begin(), mLinks.end(), MouseOverLink(event.getX(), event.getY())); - mSelectedLink = (i != mLinks.end()) ? (i - mLinks.begin()) : -1; + mSelectedLink = (i != mLinks.end()) + ? static_cast(i - mLinks.begin()) : -1; } void BrowserBox::draw(gcn::Graphics *graphics) @@ -261,10 +271,7 @@ void BrowserBox::draw(gcn::Graphics *graphics) mYStart = 0; if (getWidth() != mWidth) - { - mWidth = getWidth(); updateHeight(); - } if (mOpaque) { @@ -296,7 +303,28 @@ void BrowserBox::draw(gcn::Graphics *graphics) } } + gcn::Font *font = getFont(); + + for (LinePartIterator i = mLineParts.begin(); + i != mLineParts.end(); + i ++) + { + const LinePart &part = *i; + if (part.getY() + 50 < mYStart) + continue; + if (part.getY() > yEnd) + break; + graphics->setColor(part.getColor()); + font->drawString(graphics, part.getText(), part.getX(), part.getY()); + } + + return; +} + +int BrowserBox::calcHeight() +{ int x = 0, y = 0; + int wrappedLines = 0; int link = 0; gcn::Font *font = getFont(); @@ -305,27 +333,13 @@ void BrowserBox::draw(gcn::Graphics *graphics) char const *hyphen = "~"; int hyphenWidth = font->getWidth(hyphen); - graphics->setColor(Theme::getThemeColor(Theme::TEXT)); + gcn::Color selColor = Theme::getThemeColor(Theme::TEXT); const gcn::Color textColor = Theme::getThemeColor(Theme::TEXT); - TextRowsHeightIterator h = mTextRowsHeights.begin(); - for (TextRowIterator i = mTextRows.begin(); - i != mTextRows.end(); - i++, h++) - { - bool hidden = false; - if (y + 50 < mYStart) - { - y += *(h); - continue; - } - else if (y > yEnd) - { - break; - } + mLineParts.clear(); - gcn::Color selColor = textColor; - gcn::Color prevColor = selColor; + for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++) + { const std::string row = *(i); bool wrapped = false; x = 0; @@ -333,19 +347,19 @@ void BrowserBox::draw(gcn::Graphics *graphics) // Check for separator lines if (row.find("---", 0) == 0) { - if (!hidden) + const int dashWidth = fontWidthMinus; + for (x = 0; x < getWidth(); x++) { - const int dashWidth = fontWidthMinus; - for (x = 0; x < getWidth(); x++) - { - font->drawString(graphics, "-", x, y); - x += dashWidth - 2; - } + mLineParts.push_back(LinePart(x, y, selColor, "-")); + x += dashWidth - 2; } + y += fontHeight; continue; } + gcn::Color prevColor = selColor; + // TODO: Check if we must take texture size limits into account here // TODO: Check if some of the O(n) calls can be removed for (std::string::size_type start = 0, end = std::string::npos; @@ -364,14 +378,14 @@ void BrowserBox::draw(gcn::Graphics *graphics) if (mUseLinksAndUserColors) end = row.find("##", start + 1); - if (!hidden - && (mUseLinksAndUserColors || - (!mUseLinksAndUserColors && (start == 0)))) + if (mUseLinksAndUserColors || + (!mUseLinksAndUserColors && (start == 0))) { // Check for color change in format "##x", x = [L,P,0..9] if (row.find("##", start) == start && row.size() > start + 2) { const char c = row.at(start + 2); + bool valid; const gcn::Color col = Theme::getThemeColor(c, valid); @@ -381,7 +395,6 @@ void BrowserBox::draw(gcn::Graphics *graphics) } else if (c == '<') { - link++; prevColor = selColor; selColor = col; } @@ -408,144 +421,12 @@ void BrowserBox::draw(gcn::Graphics *graphics) selColor = textColor; } } - start += 3; - - if (start == row.size()) - break; - } - graphics->setColor(selColor); - } - - std::string::size_type len = - end == std::string::npos ? end : end - start; - std::string part = row.substr(start, len); - - // Auto wrap mode - if (mMode == AUTO_WRAP && getWidth() > 0 - && font->getWidth(part) > 0 - && (x + font->getWidth(part) + 10) > getWidth()) - { - bool forced = false; - - /* FIXME: This code layout makes it easy to crash remote - clients by talking garbage. Forged long utf-8 characters - will cause either a buffer underflow in substr or an - infinite loop in the main loop. */ - do - { - if (!forced) - end = row.rfind(' ', end); - - // Check if we have to (stupidly) force-wrap - if (end == std::string::npos || end <= start) - { - forced = true; - end = row.size(); - x += hyphenWidth; // Account for the wrap-notifier - continue; - } - - // Skip to the start of the current character - while ((row[end] & 192) == 128) - end--; - end--; // And then to the last byte of the previous one - - part = row.substr(start, end - start + 1); - } - while (end > start && font->getWidth(part) > 0 - && (x + font->getWidth(part) + 10) > getWidth()); - - if (forced) - { - x -= hyphenWidth; // Remove the wrap-notifier accounting - if (y >= mYStart) - { - font->drawString(graphics, hyphen, - getWidth() - hyphenWidth, y); - } - end++; // Skip to the next character - } - else - { - end += 2; // Skip to after the space - } - - wrapped = true; - } - - font->drawString(graphics, part, x, y); - - if (mMode == AUTO_WRAP && font->getWidth(part) == 0) - break; - - x += font->getWidth(part); - } - y += fontHeight; - } - setHeight(mHeight); -} - -int BrowserBox::calcHeight() -{ - int x = 0, y = 0; - int wrappedLines = 0; - int link = 0; - gcn::Font *font = getFont(); - - int fontHeight = font->getHeight(); - int fontWidthMinus = font->getWidth("-"); - char const *hyphen = "~"; - int hyphenWidth = font->getWidth(hyphen); - - mTextRowsHeights.clear(); - - for (TextRowIterator i = mTextRows.begin(); i != mTextRows.end(); i++) - { - const std::string row = *(i); - bool wrapped = false; - int yStart = y; - x = 0; - - // Check for separator lines - if (row.find("---", 0) == 0) - { - const int dashWidth = fontWidthMinus; - for (x = 0; x < getWidth(); x++) - x += dashWidth - 2; - - y += fontHeight; - continue; - } - - // TODO: Check if we must take texture size limits into account here - // TODO: Check if some of the O(n) calls can be removed - for (std::string::size_type start = 0, end = std::string::npos; - start != std::string::npos; - start = end, end = std::string::npos) - { - // Wrapped line continuation shall be indented - if (wrapped) - { - y += fontHeight; - x = 15; - wrapped = false; - } - - // "Tokenize" the string at control sequences - if (mUseLinksAndUserColors) - end = row.find("##", start + 1); - - if (mUseLinksAndUserColors || - (!mUseLinksAndUserColors && (start == 0))) - { - // Check for color change in format "##x", x = [L,P,0..9] - if (row.find("##", start) == start && row.size() > start + 2) - { - const char c = row.at(start + 2); if (c == '<') { - const int size = font->getWidth(mLinks[link].caption) + 1; + const int size = + font->getWidth(mLinks[link].caption) + 1; + mLinks[link].x1 = x; mLinks[link].y1 = y; mLinks[link].x2 = mLinks[link].x1 + size; @@ -605,6 +486,8 @@ int BrowserBox::calcHeight() if (forced) { x -= hyphenWidth; // Remove the wrap-notifier accounting + mLineParts.push_back(LinePart(getWidth() - hyphenWidth, + y, selColor, hyphen)); end++; // Skip to the next character } else @@ -616,19 +499,30 @@ int BrowserBox::calcHeight() wrappedLines++; } + mLineParts.push_back(LinePart(x, y, selColor, part.c_str())); + if (mMode == AUTO_WRAP && font->getWidth(part) == 0) break; x += font->getWidth(part); } y += fontHeight; - mTextRowsHeights.push_back(y - yStart); } - return (mTextRows.size() + wrappedLines) * fontHeight; + return (static_cast(mTextRows.size()) + wrappedLines) * fontHeight; } void BrowserBox::updateHeight() { - mHeight = calcHeight(); - setHeight(mHeight); + if (mAlwaysUpdate || std::abs(mUpdateTime - tick_time) > 10 + || mTextRows.size() < 3) + { + mWidth = getWidth(); + mHeight = calcHeight(); + setHeight(mHeight); + mUpdateTime = tick_time; + } + else if (!mUpdateTime) + { + mUpdateTime = tick_time; + } } diff --git a/src/gui/widgets/browserbox.h b/src/gui/widgets/browserbox.h index b71f30d7..54a2a8cc 100644 --- a/src/gui/widgets/browserbox.h +++ b/src/gui/widgets/browserbox.h @@ -2,6 +2,7 @@ * The Mana Client * Copyright (C) 2004-2009 The Mana World Development Team * Copyright (C) 2009-2010 The Mana Developers + * Copyright (C) 2009 Aethyra Development Team * * This file is part of The Mana Client. * @@ -30,12 +31,39 @@ class LinkHandler; -struct BROWSER_LINK { +struct BROWSER_LINK +{ int x1, x2, y1, y2; /**< Where link is placed */ std::string link; std::string caption; }; +class LinePart +{ + public: + LinePart(int x, int y, gcn::Color color, std::string text) : + mX(x), mY(y), mColor(color), mText(text) + { + } + + int getX() const + { return mX; } + + int getY() const + { return mY; } + + const std::string &getText() const + { return mText; } + + const gcn::Color &getColor() const + { return mColor; } + + private: + int mX, mY; + gcn::Color mColor; + std::string mText; +}; + /** * A simple browser box able to handle links and forward events to the * parent conteiner. @@ -72,7 +100,7 @@ class BrowserBox : public gcn::Widget, /** * Sets the maximum numbers of rows in the browser box. 0 = no limit. */ - void setMaxRow(int max) {mMaxRows = max; }; + void setMaxRow(unsigned max) {mMaxRows = max; }; /** * Disable links & user defined colors to be used in chat input. @@ -111,8 +139,9 @@ class BrowserBox : public gcn::Widget, /** * BrowserBox modes. */ - enum { - AUTO_SIZE, + enum + { + AUTO_SIZE = 0, AUTO_WRAP /**< Maybe it needs a fix or to be redone. */ }; @@ -126,7 +155,8 @@ class BrowserBox : public gcn::Widget, * windows and widgets. So, I think it's better keep BrowserBox * opaque (white background) by default. */ - enum { + enum + { RED = 0xff0000, /**< Color 1 */ GREEN = 0x009000, /**< Color 2 */ BLUE = 0x0000ff, /**< Color 3 */ @@ -142,21 +172,29 @@ class BrowserBox : public gcn::Widget, * Highlight modes for links. * This can be used for a bitmask. */ - enum { + enum + { UNDERLINE = 1, BACKGROUND = 2 }; + typedef std::list TextRows; + + TextRows &getRows() + { return mTextRows; } + + void setAlwaysUpdate(bool n) + { mAlwaysUpdate = n; } + private: int calcHeight(); - typedef std::list TextRows; typedef TextRows::iterator TextRowIterator; TextRows mTextRows; - typedef std::list TextRowsHeights; - typedef TextRowsHeights::iterator TextRowsHeightIterator; - TextRowsHeights mTextRowsHeights; + typedef std::list LinePartList; + typedef LinePartList::iterator LinePartIterator; + LinePartList mLineParts; typedef std::vector Links; typedef Links::iterator LinkIterator; @@ -172,6 +210,8 @@ class BrowserBox : public gcn::Widget, int mHeight; int mWidth; int mYStart; + int mUpdateTime; + bool mAlwaysUpdate; }; #endif diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp index 8bf57508..bbb2b8bb 100644 --- a/src/gui/widgets/chattab.cpp +++ b/src/gui/widgets/chattab.cpp @@ -53,6 +53,7 @@ ChatTab::ChatTab(const std::string &name) : Tab() mTextOutput->setOpaque(false); mTextOutput->setMaxRow((int) config.getValue("ChatLogLength", 0)); mTextOutput->setLinkHandler(chatWindow->mItemLinkHandler); + mTextOutput->setAlwaysUpdate(false); mScrollArea = new ScrollArea(mTextOutput); mScrollArea->setScrollPolicy(gcn::ScrollArea::SHOW_NEVER, -- cgit v1.2.3-70-g09d2 From bf8893f83b4b5e55e74e9b1ed4e8f06bc0315aa7 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Thu, 30 Sep 2010 16:05:39 +0200 Subject: Setting alpha for items in ItemShortcutContainer Reviewed-by: Thorbjorn --- src/gui/widgets/itemshortcutcontainer.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'src') diff --git a/src/gui/widgets/itemshortcutcontainer.cpp b/src/gui/widgets/itemshortcutcontainer.cpp index 83efd4d4..682d71e5 100644 --- a/src/gui/widgets/itemshortcutcontainer.cpp +++ b/src/gui/widgets/itemshortcutcontainer.cpp @@ -109,6 +109,7 @@ void ItemShortcutContainer::draw(gcn::Graphics *graphics) else if (item->isEquipped()) caption = "Eq."; + image->setAlpha(1.0f); g->drawImage(image, itemX, itemY); if (item->isEquipped()) g->setColor(Theme::getThemeColor(Theme::ITEM_EQUIPPED)); -- cgit v1.2.3-70-g09d2 From fd20b774bf057502ea04090051fad2c5c9351c74 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 1 Oct 2010 18:05:31 +0300 Subject: Fix possible invisible chat. Reviewed-by: Thorbjorn --- src/gui/widgets/browserbox.cpp | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/gui/widgets/browserbox.cpp b/src/gui/widgets/browserbox.cpp index 6ae4c588..81f54212 100644 --- a/src/gui/widgets/browserbox.cpp +++ b/src/gui/widgets/browserbox.cpp @@ -217,6 +217,7 @@ void BrowserBox::addRow(const std::string &row) { setHeight(font->getHeight() * static_cast(mTextRows.size())); } + mUpdateTime = 0; updateHeight(); } @@ -513,7 +514,7 @@ int BrowserBox::calcHeight() void BrowserBox::updateHeight() { - if (mAlwaysUpdate || std::abs(mUpdateTime - tick_time) > 10 + if (mAlwaysUpdate || !mUpdateTime || std::abs(mUpdateTime - tick_time) > 10 || mTextRows.size() < 3) { mWidth = getWidth(); @@ -521,8 +522,4 @@ void BrowserBox::updateHeight() setHeight(mHeight); mUpdateTime = tick_time; } - else if (!mUpdateTime) - { - mUpdateTime = tick_time; - } } -- cgit v1.2.3-70-g09d2 From e6acf6e2f17b4177f3f8292f52d83b46822ab9c5 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sat, 2 Oct 2010 15:59:46 +0200 Subject: Avoiding the creation of a party or guild without a name If no name is given, then the player obviously didn't want to create it. Now the empty input is handled just the same way as in the invite dialog. Trivial fix. --- src/gui/socialwindow.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 290fd557..7944e210 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -500,12 +500,13 @@ void SocialWindow::action(const gcn::ActionEvent &event) { localChatTab->chatLog(_("Creating guild failed, please choose a " "shorter name."), BY_SERVER); - return; } - - Net::getGuildHandler()->create(name); - localChatTab->chatLog(strprintf(_("Creating guild called %s."), - name.c_str()), BY_SERVER); + else if (!name.empty()) + { + Net::getGuildHandler()->create(name); + localChatTab->chatLog(strprintf(_("Creating guild called %s."), + name.c_str()), BY_SERVER); + } mGuildCreateDialog = NULL; } @@ -521,12 +522,13 @@ void SocialWindow::action(const gcn::ActionEvent &event) { localChatTab->chatLog(_("Creating party failed, please choose a " "shorter name."), BY_SERVER); - return; } - - Net::getPartyHandler()->create(name); - localChatTab->chatLog(strprintf(_("Creating party called %s."), - name.c_str()), BY_SERVER); + else if (!name.empty()) + { + Net::getPartyHandler()->create(name); + localChatTab->chatLog(strprintf(_("Creating party called %s."), + name.c_str()), BY_SERVER); + } mPartyCreateDialog = NULL; } -- cgit v1.2.3-70-g09d2 From 671ae4cd0e26618c0662123d4b9c0d1c63acb4f6 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 3 Oct 2010 22:53:09 +0200 Subject: Fixing segmentation fault and updating the cursor type after mouse press Until now the being was only set after a mouse move. If the mouse was pressed after the being was out of sight or dead, then a segmentation fault happened. Furthermore, pressing the mouse now updates the cursor type and sets the being popup invisible. Reviewed-by: Thorbjorn --- src/gui/viewport.cpp | 13 +++++++++++++ src/gui/viewport.h | 5 +++++ 2 files changed, 18 insertions(+) (limited to 'src') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 99325db8..ce506ba1 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -349,10 +349,18 @@ void Viewport::mousePressed(gcn::MouseEvent &event) return; mPlayerFollowMouse = false; + mBeingPopup->setVisible(false); const int pixelX = event.getX() + (int) mPixelViewX; const int pixelY = event.getY() + (int) mPixelViewY; + mHoverBeing = beingManager->findBeingByPixel(pixelX, pixelY); + mHoverItem = floorItemManager-> + findByCoordinates(pixelX / mMap->getTileWidth(), + pixelY / mMap->getTileHeight()); + + updateCursorType(); + // Right click might open a popup if (event.getButton() == gcn::MouseEvent::RIGHT) { @@ -517,6 +525,11 @@ void Viewport::mouseMoved(gcn::MouseEvent &event) mHoverItem = floorItemManager->findByCoordinates(x / mMap->getTileWidth(), y / mMap->getTileHeight()); + updateCursorType(); +} + +void Viewport::updateCursorType() +{ if (mHoverBeing) { switch (mHoverBeing->getType()) diff --git a/src/gui/viewport.h b/src/gui/viewport.h index 9658f934..616b88be 100644 --- a/src/gui/viewport.h +++ b/src/gui/viewport.h @@ -182,6 +182,11 @@ class Viewport : public WindowContainer, public gcn::MouseListener, */ void _followMouse(); + /** + * Updates the cursor type + */ + void updateCursorType(); + Map *mMap; /**< The current map. */ int mScrollRadius; -- cgit v1.2.3-70-g09d2 From 7fa20ba5839d8674d9c4023f55419fbc21e00c07 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Tue, 5 Oct 2010 14:00:35 +0200 Subject: Fixing segmentation fault in social window How to reproduce the bug: * Press button Leave in social window. * In the confirm dialog press No. * Then switching character makes the client crash. Trivial fix. --- src/gui/socialwindow.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index 7944e210..ec414836 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -144,7 +144,7 @@ public: mGuild->getName().c_str()), BY_SERVER); mConfirmDialog = NULL; } - else if (event.getId() == "~yes") + else if (event.getId() == "no") { mConfirmDialog = NULL; } @@ -223,7 +223,7 @@ public: mParty->getName().c_str()), BY_SERVER); mConfirmDialog = NULL; } - else if (event.getId() == "~yes") + else if (event.getId() == "no") { mConfirmDialog = NULL; } -- cgit v1.2.3-70-g09d2 From f75c8fac584e1647745c0b5bf1fe8e50fc3209d5 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Tue, 5 Oct 2010 18:30:14 +0200 Subject: Send the server changed player direction if it changes during attack Reviewed-by: Jaxad0127 --- src/localplayer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 9c64c6dc..b4418bbc 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -1007,20 +1007,23 @@ void LocalPlayer::attack(Being *target, bool keep) if (mAction != STAND) return; + Uint8 direction = 0; if (abs(dist_y) >= abs(dist_x)) { if (dist_y > 0) - setDirection(DOWN); + direction = DOWN; else - setDirection(UP); + direction = UP; } else { if (dist_x > 0) - setDirection(RIGHT); + direction = RIGHT; else - setDirection(LEFT); + direction = LEFT; } + Net::getPlayerHandler()->setDirection(direction); + setDirection(direction); mWalkTime = tick_time; mTargetTime = tick_time; -- cgit v1.2.3-70-g09d2 From 94218cc8e93ed7087c4036312fb469d0070802e3 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Wed, 6 Oct 2010 16:06:49 +0200 Subject: Fixing movement with the mouse When a player clicked on a tile in order to go to it, then he went to the wrong tile. Trivial fix. --- src/gui/viewport.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index ce506ba1..0b7cc0f8 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -471,10 +471,8 @@ void Viewport::mouseDragged(gcn::MouseEvent &event) if (mLocalWalkTime != player_node->getWalkTime()) { mLocalWalkTime = player_node->getWalkTime(); - int destX = (event.getX() + mPixelViewX + 16) / - mMap->getTileWidth(); - int destY = (event.getY() + mPixelViewY + 16) / - mMap->getTileHeight(); + int destX = (event.getX() + mPixelViewX) / mMap->getTileWidth(); + int destY = (event.getY() + mPixelViewY) / mMap->getTileHeight(); player_node->setDestination(destX, destY); } } -- cgit v1.2.3-70-g09d2 From c1f6da6a95e2170c15065418d7c66578ca80b85c Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Thu, 7 Oct 2010 23:24:13 +0300 Subject: Disable guilds netcode. Reviewed-by: Jaxad0127 --- src/net/tmwa/guildhandler.cpp | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src') diff --git a/src/net/tmwa/guildhandler.cpp b/src/net/tmwa/guildhandler.cpp index dac57b64..93bc7807 100644 --- a/src/net/tmwa/guildhandler.cpp +++ b/src/net/tmwa/guildhandler.cpp @@ -43,6 +43,7 @@ Guild *taGuild; GuildHandler::GuildHandler() { static const Uint16 _messages[] = { +/* SMSG_GUILD_CREATE_RESPONSE, SMSG_GUILD_POSITION_INFO, SMSG_GUILD_MEMBER_LOGIN, @@ -69,6 +70,7 @@ GuildHandler::GuildHandler() SMSG_GUILD_DEL_ALLIANCE, SMSG_GUILD_OPPOSITION_ACK, SMSG_GUILD_BROKEN, +*/ 0 }; handledMessages = _messages; -- cgit v1.2.3-70-g09d2 From 9defd5c760e3ba0f01078a25a74320a55c1f4d82 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Fri, 8 Oct 2010 19:11:20 +0200 Subject: Fixing pick-up If the player wanted to pick up an item one tile up, then he moved to that tile before he picked it up. The same fix is already used in Game::handleInput() for KEY_PICKUP. TODO: Understand why the position is wrong. As a reminder I made a mantis ticket: http://bugs.manasource.org/view.php?id=249 --- src/localplayer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/localplayer.cpp b/src/localplayer.cpp index b4418bbc..50a9462f 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -707,8 +707,8 @@ void LocalPlayer::setInvItem(int index, int id, int amount) void LocalPlayer::pickUp(FloorItem *item) { - int dx = item->getX() - (int) getPosition().x / 32; - int dy = item->getY() - (int) getPosition().y / 32; + int dx = item->getX() - (int) getPosition().x / mMap->getTileWidth(); + int dy = item->getY() - ((int) getPosition().y - 1) / mMap->getTileHeight(); if (dx * dx + dy * dy < 4) { -- cgit v1.2.3-70-g09d2 From 574bd5fa1ee45a7452d2e85941fa33f946b63eae Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Fri, 8 Oct 2010 23:19:12 +0200 Subject: Remove the following system Removed due to unresolved social issues. In master it had been already removed by Kage in commit 89f192b9039f9c000515f0a12f4bb9fb55c4691c. --- src/game.cpp | 4 ---- src/gui/popupmenu.cpp | 9 --------- src/gui/viewport.cpp | 1 - src/localplayer.cpp | 2 -- src/localplayer.h | 28 ---------------------------- src/net/tmwa/beinghandler.cpp | 21 --------------------- 6 files changed, 65 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 8e856dc0..66b6e3c4 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -778,26 +778,22 @@ void Game::handleInput() (joystick && joystick->isUp())) { direction |= Being::UP; - player_node->cancelFollow(); } else if (keyboard.isKeyActive(keyboard.KEY_MOVE_DOWN) || (joystick && joystick->isDown())) { direction |= Being::DOWN; - player_node->cancelFollow(); } if (keyboard.isKeyActive(keyboard.KEY_MOVE_LEFT) || (joystick && joystick->isLeft())) { direction |= Being::LEFT; - player_node->cancelFollow(); } else if (keyboard.isKeyActive(keyboard.KEY_MOVE_RIGHT) || (joystick && joystick->isRight())) { direction |= Being::RIGHT; - player_node->cancelFollow(); } if (keyboard.isKeyActive(keyboard.KEY_EMOTE) && direction != 0) diff --git a/src/gui/popupmenu.cpp b/src/gui/popupmenu.cpp index 01870e62..409a0eda 100644 --- a/src/gui/popupmenu.cpp +++ b/src/gui/popupmenu.cpp @@ -125,9 +125,6 @@ void PopupMenu::showPopup(int x, int y, Being *being) break; } - mBrowserBox->addRow(strprintf("@@follow|%s@@", - strprintf(_("Follow %s"), - name.c_str()).c_str())); if (player_node->getNumberOfGuilds()) mBrowserBox->addRow(strprintf("@@guild|%s@@", strprintf(_("Invite %s to join your guild"), @@ -249,12 +246,6 @@ void PopupMenu::handleLink(const std::string &link) player_node->inviteToGuild(being); } - // Follow Player action - else if (link == "follow" && being) - { - player_node->setFollow(being->getName()); - } - // Pick Up Floor Item action else if ((link == "pickup") && mFloorItem) { diff --git a/src/gui/viewport.cpp b/src/gui/viewport.cpp index 0b7cc0f8..b18b9b0b 100644 --- a/src/gui/viewport.cpp +++ b/src/gui/viewport.cpp @@ -431,7 +431,6 @@ void Viewport::mousePressed(gcn::MouseEvent &event) else { player_node->stopAttack(); - player_node->cancelFollow(); mPlayerFollowMouse = true; // Make the player go to the mouse position diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 50a9462f..74ca5f0d 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -96,7 +96,6 @@ LocalPlayer::LocalPlayer(int id, int subtype): mHp(1), mMaxHp(1), mSkillPoints(0), mTarget(NULL), - mPlayerFollowed(""), mPickUpTarget(NULL), mTrading(false), mGoingToTarget(false), mKeepAttacking(false), mLastAction(-1), @@ -1432,7 +1431,6 @@ void LocalPlayer::changeAwayMode() mAfkTime = 0; if (mAwayMode) { - cancelFollow(); mAwayDialog = new OkDialog(_("Away"), config.getValue("afkMessage", "I am away from keyboard")); mAwayDialog->addActionListener(mAwayListener); diff --git a/src/localplayer.h b/src/localplayer.h index 2c06dfb5..03fec1f8 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -379,29 +379,6 @@ class LocalPlayer : public Player */ void optionChanged(const std::string &value); - /** - * set a following player by right clicking. - */ - void setFollow(std::string player) { mPlayerFollowed = player; } - - /** - * setting the next destination of the following, in case of warp - */ - void setNextDest(int x, int y) { mNextDestX = x; mNextDestY = y; } - - int getNextDestX() const { return mNextDestX; } - int getNextDestY() const { return mNextDestY; } - - /** - * Stop following a player. - */ - void cancelFollow() { mPlayerFollowed = ""; } - - /** - * Get the playername followed by the current player. - */ - std::string getFollow() const { return mPlayerFollowed; } - /** * Tells the engine wether to check * if the Player Name is to be displayed. @@ -458,11 +435,6 @@ class LocalPlayer : public Player Being *mTarget; - /** Follow system **/ - std::string mPlayerFollowed; - int mNextDestX; - int mNextDestY; - FloorItem *mPickUpTarget; bool mTrading; diff --git a/src/net/tmwa/beinghandler.cpp b/src/net/tmwa/beinghandler.cpp index 889f8777..2fe962c7 100644 --- a/src/net/tmwa/beinghandler.cpp +++ b/src/net/tmwa/beinghandler.cpp @@ -115,7 +115,6 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) Being *srcBeing, *dstBeing; Player *player = 0; int hairStyle, hairColor, flag; - std::string player_followed; switch (msg.getId()) { @@ -280,16 +279,6 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) if (!dstBeing) break; - player_followed = player_node->getFollow(); - - if (!player_followed.empty()) - { - if (dstBeing->getName() == player_followed) - { - player_node->setDestination(player_node->getNextDestX(), player_node->getNextDestY()); - } - } - // If this is player's current target, clear it. if (dstBeing == player_node->getTarget()) player_node->stopAttack(); @@ -595,16 +584,6 @@ void BeingHandler::handleMessage(Net::MessageIn &msg) msg.readCoordinatePair(srcX, srcY, dstX, dstY); dstBeing->setTileCoords(srcX, srcY); dstBeing->setDestination(dstX, dstY); - - player_followed = player_node->getFollow(); - if (!player_followed.empty()) - { - if (dstBeing->getName() == player_followed) - { - player_node->setNextDest(dstX, dstY); - player_node->setDestination(srcX, srcY); - } - } } else { -- cgit v1.2.3-70-g09d2 From cf32b575fd98c29ae5f20b58736acbd5bf4248ef Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 10 Oct 2010 00:48:22 +0200 Subject: Fixing unusable config.xml If config variable screenshotDirectory has national symbols in it, the client could not read cofig.xml, and always used default settings. In order to get ready for a client release, now the config.xml does not save the screenshot folder. The --screenshot-dir commandline option is working as before, the value is just not permanent anymore. This makes actually sense, since the options for update folder and config folder are not permanent either. This resolves http://bugs.manasource.org/view.php?id=112 Reviewed-by: Jaxad0127 --- src/client.cpp | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 8def205b..f1b363e9 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1222,21 +1222,13 @@ void Client::initScreenshotDir() mScreenshotDir = mOptions.screenshotDir; else { - std::string configScreenshotDir = - config.getValue("screenshotDirectory", ""); - if (!configScreenshotDir.empty()) - mScreenshotDir = configScreenshotDir; - else - { #ifdef WIN32 - mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); - if (mScreenshotDir.empty()) - mScreenshotDir = getSpecialFolderLocation(CSIDL_DESKTOP); + mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); + if (mScreenshotDir.empty()) + mScreenshotDir = getSpecialFolderLocation(CSIDL_DESKTOP); #else - mScreenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop"; + mScreenshotDir = std::string(PHYSFS_getUserDir()) + "Desktop"; #endif - } - config.setValue("screenshotDirectory", mScreenshotDir); if (config.getValue("useScreenshotDirectorySuffix", true)) { -- cgit v1.2.3-70-g09d2 From 2fb1520540598a5e6201f722979dada6b3283d0d Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 10 Oct 2010 22:33:24 +0200 Subject: Adding Okdialog if registration is disabled Reviewed-by: Jaxad0127 --- src/gui/login.cpp | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/gui/login.cpp b/src/gui/login.cpp index b243fd04..b12e6a5d 100644 --- a/src/gui/login.cpp +++ b/src/gui/login.cpp @@ -91,8 +91,6 @@ LoginDialog::LoginDialog(LoginData *loginData): mPassField->requestFocus(); mLoginButton->setEnabled(canSubmit()); - mRegisterButton->setEnabled(Net::getLoginHandler() - ->isRegistrationEnabled()); } LoginDialog::~LoginDialog() @@ -120,10 +118,17 @@ void LoginDialog::action(const gcn::ActionEvent &event) } else if (event.getId() == "register") { - mLoginData->username = mUserField->getText(); - mLoginData->password = mPassField->getText(); - - Client::setState(STATE_REGISTER_PREP); + if (Net::getLoginHandler()->isRegistrationEnabled()) + { + mLoginData->username = mUserField->getText(); + mLoginData->password = mPassField->getText(); + Client::setState(STATE_REGISTER_PREP); + } + else + { + new OkDialog(_("Registration disabled"), _("You need to use the " + "website to register an account for this server.")); + } } } -- cgit v1.2.3-70-g09d2 From c69866123ba83f9dd4619c81eca312dda0559393 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Mon, 11 Oct 2010 22:05:02 +0200 Subject: Implementing show IP for game masters As an upcoming feature the TMW-Athena server sends IP addresses or IP hashes to game masters. The current client freezes if it receives such a packet, therefor the game masters need to use a new client before the server can use it. Normal players are not affected, because they do not get this packet. Showing the IP is optional and can be enable with the chat command "/showip 1". The IP is then shown behind the players name. Reviewed-by: Bertram --- src/being.cpp | 11 ++++++++--- src/commandhandler.cpp | 34 ++++++++++++++++++++++++++++++++++ src/commandhandler.h | 5 +++++ src/localplayer.cpp | 3 ++- src/localplayer.h | 8 ++++++++ src/net/tmwa/adminhandler.cpp | 9 +++++++++ src/net/tmwa/network.cpp | 4 ++-- src/net/tmwa/protocol.h | 1 + src/player.cpp | 3 ++- src/player.h | 14 ++++++++++++++ 10 files changed, 85 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index d2dfc855..a3e91147 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -987,16 +987,21 @@ void Being::showName() if (getType() == PLAYER) { - if (config.getValue("showgender", false)) + Player* player = static_cast(this); + if (player) { - Player* player = static_cast(this); - if (player) + if (config.getValue("showgender", false)) { if (player->getGender() == GENDER_FEMALE) mDisplayName += " \u2640"; else mDisplayName += " \u2642"; } + if (Net::getNetworkType() == ServerInfo::TMWATHENA && player_node + && player_node->getShowIp() && player->getIp()) + { + mDisplayName += strprintf(" %s", ipToString(player->getIp())); + } } } else if (getType() == MONSTER) diff --git a/src/commandhandler.cpp b/src/commandhandler.cpp index dab51c8f..1c375ad9 100644 --- a/src/commandhandler.cpp +++ b/src/commandhandler.cpp @@ -21,6 +21,7 @@ #include "commandhandler.h" +#include "beingmanager.h" #include "channelmanager.h" #include "channel.h" #include "game.h" @@ -126,6 +127,10 @@ void CommandHandler::handleCommand(const std::string &command, ChatTab *tab) { handleAway(args, tab); } + else if (type == "showip" && Net::getNetworkType() == ServerInfo::TMWATHENA) + { + handleShowIp(args, tab); + } else { tab->chatLog(_("Unknown command.")); @@ -479,6 +484,35 @@ void CommandHandler::handleToggle(const std::string &args, ChatTab *tab) } } +void CommandHandler::handleShowIp(const std::string &args, ChatTab *tab) +{ + if (args.empty()) + { + tab->chatLog(player_node->getShowIp() ? + _("Show IP: On") : _("Show IP: Off")); + return; + } + + char opt = parseBoolean(args); + + switch (opt) + { + case 0: + tab->chatLog(_("Show IP: Off")); + player_node->setShowIp(false); + break; + case 1: + tab->chatLog(_("Show IP: On")); + player_node->setShowIp(true); + break; + case -1: + tab->chatLog(strprintf(BOOLEAN_OPTIONS, "showip")); + return; + } + + beingManager->updatePlayerNames(); +} + void CommandHandler::handlePresent(const std::string &args, ChatTab *tab) { chatWindow->doPresent(); diff --git a/src/commandhandler.h b/src/commandhandler.h index c65c3670..c14305e1 100644 --- a/src/commandhandler.h +++ b/src/commandhandler.h @@ -147,6 +147,11 @@ class CommandHandler * Handle away command. */ void handleAway(const std::string &args, ChatTab *tab); + + /* + * Handle showip command. + */ + void handleShowIp(const std::string &args, ChatTab *tab); }; extern CommandHandler *commandHandler; diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 74ca5f0d..5f5f44ae 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -106,7 +106,8 @@ LocalPlayer::LocalPlayer(int id, int subtype): mMessageTime(0), mAwayDialog(0), mAfkTime(0), - mAwayMode(false) + mAwayMode(false), + mShowIp(false) { mAwayListener = new AwayListener(); diff --git a/src/localplayer.h b/src/localplayer.h index 03fec1f8..7706caeb 100644 --- a/src/localplayer.h +++ b/src/localplayer.h @@ -354,6 +354,12 @@ class LocalPlayer : public Player std::pair getExperience(int skill); + void setShowIp(bool show) + { mShowIp = show; } + + bool getShowIp() const + { return mShowIp; } + /** Tells that the path has been set by mouse. */ void pathSetByMouse() { mPathSetByMouse = true; } @@ -476,6 +482,8 @@ class LocalPlayer : public Player int mAfkTime; bool mAwayMode; + + bool mShowIp; }; extern LocalPlayer *player_node; diff --git a/src/net/tmwa/adminhandler.cpp b/src/net/tmwa/adminhandler.cpp index e56d5a44..c75ec217 100644 --- a/src/net/tmwa/adminhandler.cpp +++ b/src/net/tmwa/adminhandler.cpp @@ -24,6 +24,7 @@ #include "being.h" #include "beingmanager.h" #include "game.h" +#include "player.h" #include "playerrelations.h" #include "gui/widgets/chattab.h" @@ -46,6 +47,7 @@ AdminHandler::AdminHandler() { static const Uint16 _messages[] = { SMSG_ADMIN_KICK_ACK, + SMSG_ADMIN_IP, 0 }; handledMessages = _messages; @@ -64,6 +66,13 @@ void AdminHandler::handleMessage(Net::MessageIn &msg) else localChatTab->chatLog(_("Kick succeeded!"), BY_SERVER); break; + case SMSG_ADMIN_IP: + id = msg.readInt32(); + int ip = msg.readInt32(); + Player *player = (Player *)beingManager->findBeing(id); + player->setIp(ip); + player->updateName(); + break; } } diff --git a/src/net/tmwa/network.cpp b/src/net/tmwa/network.cpp index aff19b11..4d2073a0 100644 --- a/src/net/tmwa/network.cpp +++ b/src/net/tmwa/network.cpp @@ -77,8 +77,8 @@ short packet_lengths[] = { 8, 14, 10, 35, 6, 8, 4, 11, 54, 53, 60, 2, -1, 47, 33, 6, 30, 8, 34, 14, 2, 6, 26, 2, 28, 81, 6, 10, 26, 2, -1, -1, -1, -1, 20, 10, 32, 9, 34, 14, 2, 6, 48, 56, -1, 4, 5, 10, -// #0x2000 - 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 0, 0, 0, 0, +// #0x0200 + 26, 0, 0, 0, 18, 0, 0, 0, 0, 0, 0, 19, 10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, }; diff --git a/src/net/tmwa/protocol.h b/src/net/tmwa/protocol.h index 21d562bc..0a768d5d 100644 --- a/src/net/tmwa/protocol.h +++ b/src/net/tmwa/protocol.h @@ -181,6 +181,7 @@ static const int STORAGE_OFFSET = 1; #define SMSG_PLAYER_STORAGE_CLOSE 0x00f8 /**< Storage access closed */ #define SMSG_ADMIN_KICK_ACK 0x00cd +#define SMSG_ADMIN_IP 0x020c #define SMSG_GUILD_CREATE_RESPONSE 0x0167 #define SMSG_GUILD_POSITION_INFO 0x016c diff --git a/src/player.cpp b/src/player.cpp index e6102b6a..a5a79ff1 100644 --- a/src/player.cpp +++ b/src/player.cpp @@ -47,7 +47,8 @@ Player::Player(int id, int subtype, Map *map, bool isNPC): Being(id, subtype, map), mGender(GENDER_UNSPECIFIED), mParty(NULL), - mIsGM(false) + mIsGM(false), + mIp(0) { if (!isNPC) { diff --git a/src/player.h b/src/player.h index e75870a0..4ac9d0eb 100644 --- a/src/player.h +++ b/src/player.h @@ -138,6 +138,18 @@ class Player : public Being */ virtual void optionChanged(const std::string &value); + /* + * Sets the IP or an IP hash. + * The TMW-Athena server sends this information only to GMs. + */ + void setIp(int ip) { mIp = ip; } + + /** + * Returns the player's IP or an IP hash. + * Value is 0 if not set by the server. + */ + int getIp() const { return mIp; } + protected: /** * Gets the way the monster blocks pathfinding for other objects. @@ -156,6 +168,8 @@ class Player : public Being Party *mParty; bool mIsGM; + + int mIp; }; #endif -- cgit v1.2.3-70-g09d2 From 55b10186e4a2ae7f5f1021041a10a3d20502b588 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Tue, 12 Oct 2010 15:19:24 +0200 Subject: Little setup tweaks * Shortening option names that got cropped in video setup * Moving options to the left hand side in player setup, because they looked like they belong to the "when ignoring" part. Reviewed-by: Bertram --- src/gui/setup_players.cpp | 4 ++-- src/gui/setup_video.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/setup_players.cpp b/src/gui/setup_players.cpp index 802a5b2e..93551689 100644 --- a/src/gui/setup_players.cpp +++ b/src/gui/setup_players.cpp @@ -291,8 +291,8 @@ Setup_Players::Setup_Players(): place(0, 6, mShowGenderCheckBox, 2).setPadding(2); place(2, 5, ignore_action_label); place(2, 6, mIgnoreActionChoicesBox, 2).setPadding(2); - place(2, 7, mDefaultTrading); - place(2, 8, mDefaultWhisper); + place(0, 7, mDefaultTrading); + place(0, 8, mDefaultWhisper); place(0, 9, mWhisperTabCheckBox, 4).setPadding(4); player_relations.addListener(this); diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index b14a8654..ba967275 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -224,7 +224,7 @@ Setup_Video::Setup_Video(): mParticleEffectsCheckBox(new CheckBox(_("Particle effects"), mParticleEffectsEnabled)), mNameCheckBox(new CheckBox(_("Show own name"), mNameEnabled)), - mNPCLogCheckBox(new CheckBox(_("Log NPC interactions"), mNPCLogEnabled)), + mNPCLogCheckBox(new CheckBox(_("Log NPC dialogue"), mNPCLogEnabled)), mPickupNotifyLabel(new Label(_("Show pickup notification"))), // TRANSLATORS: Refers to "Show pickup notification" mPickupChatCheckBox(new CheckBox(_("in chat"), mPickupChatEnabled)), @@ -247,7 +247,7 @@ Setup_Video::Setup_Video(): { setName(_("Video")); - mShowMonsterDamageCheckBox = new CheckBox(_("Show monster damage"), + mShowMonsterDamageCheckBox = new CheckBox(_("Show damage"), mShowMonsterDamageEnabled); ScrollArea *scrollArea = new ScrollArea(mModeList); -- cgit v1.2.3-70-g09d2 From f9ca4759d3dab9515bc3c1cb9b7e2bac97d1f71f Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Wed, 13 Oct 2010 13:19:40 +0200 Subject: Hiding Manaserv from the player on TMW-Athena only release With the preprocessor definition MANASERV_SUPPORT the manaserv support is avaible as before. * Removing server type from server dialog GUI. * Ignoring Manaserv entries in serverlist.xml. * In order not to lose Manaserv CustomServers from the config.xml, they get stored in mManaservServers. * The entries in mManaservServers are saved in config.xml again. But they are now behind the TMWA-Athena servers. * For custom server the GUI sets 6901 as default value for port. * If the server type is unknown, then we use TMW-Athena. This is relevant, if the client is started with command line options for server. Reviewed-by: Bertram --- src/gui/serverdialog.cpp | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ src/gui/serverdialog.h | 3 +++ src/net/net.cpp | 4 ++++ 3 files changed, 58 insertions(+) (limited to 'src') diff --git a/src/gui/serverdialog.cpp b/src/gui/serverdialog.cpp index c8a16b35..abe898b0 100644 --- a/src/gui/serverdialog.cpp +++ b/src/gui/serverdialog.cpp @@ -198,13 +198,18 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): mDownloadStatus(DOWNLOADING_PREPARING), mDownloadProgress(-1.0f), mServers(ServerInfos()), +#ifndef MANASERV_SUPPORT + mManaservServers(ServerInfos()), +#endif mServerInfo(serverInfo) { setWindowName("ServerDialog"); Label *serverLabel = new Label(_("Server:")); Label *portLabel = new Label(_("Port:")); +#ifdef MANASERV_SUPPORT Label *typeLabel = new Label(_("Server type:")); +#endif mServerNameField = new TextField(mServerInfo->hostname); mPortField = new TextField(toString(mServerInfo->port)); @@ -242,6 +247,7 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): place(1, 0, mServerNameField, 4).setPadding(3); place(0, 1, portLabel); place(1, 1, mPortField, 4).setPadding(3); +#ifdef MANASERV_SUPPORT place(0, 2, typeLabel); place(1, 2, mTypeField, 4).setPadding(3); place(0, 3, usedScroll, 5, 5).setPadding(3); @@ -250,6 +256,14 @@ ServerDialog::ServerDialog(ServerInfo *serverInfo, const std::string &dir): place(1, 9, mDeleteButton); place(3, 9, mQuitButton); place(4, 9, mConnectButton); +#else + place(0, 2, usedScroll, 5, 5).setPadding(3); + place(0, 7, mDescription, 5); + place(0, 8, mManualEntryButton); + place(1, 8, mDeleteButton); + place(3, 8, mQuitButton); + place(4, 8, mConnectButton); +#endif // Make sure the list has enough height getLayout().setRowHeight(3, 80); @@ -454,7 +468,11 @@ void ServerDialog::setFieldsReadOnly(bool readOnly) mServersList->setSelected(-1); mServerNameField->setText(std::string()); +#ifdef MANASERV_SUPPORT mPortField->setText(std::string()); +#else + mPortField->setText(std::string("6901")); +#endif mServerNameField->requestFocus(); } @@ -576,7 +594,11 @@ void ServerDialog::loadServers() } } +#ifdef MANASERV_SUPPORT if (!found) +#else + if (!found && server.type != ServerInfo::MANASERV) +#endif mServers.push_back(server); } } @@ -602,7 +624,15 @@ void ServerDialog::loadCustomServers() break; server.save = true; + +#ifdef MANASERV_SUPPORT mServers.push_back(server); +#else + if (server.type == ServerInfo::MANASERV) + mManaservServers.push_back(server); + else + mServers.push_back(server); +#endif } } @@ -645,6 +675,27 @@ void ServerDialog::saveCustomServers(const ServerInfo ¤tServer) ++savedServerCount; } +#ifndef MANASERV_SUPPORT + for (unsigned i = 0; + i < mManaservServers.size() && savedServerCount < MAX_SERVERLIST; ++i) + { + const ServerInfo &server = mManaservServers.at(i); + + // Only save servers that were loaded from settings + if (!(server.save && server.isValid())) + continue; + + const std::string index = toString(savedServerCount); + const std::string nameKey = "MostUsedServerName" + index; + const std::string typeKey = "MostUsedServerType" + index; + const std::string portKey = "MostUsedServerPort" + index; + + config.setValue(nameKey, toString(server.hostname)); + config.setValue(typeKey, serverTypeToString(server.type)); + config.setValue(portKey, toString(server.port)); + ++savedServerCount; + } +#endif // Insert an invalid entry at the end to make the loading stop there if (savedServerCount < MAX_SERVERLIST) config.setValue("MostUsedServerName" + toString(savedServerCount), ""); diff --git a/src/gui/serverdialog.h b/src/gui/serverdialog.h index ed733f9c..aae8b2e0 100644 --- a/src/gui/serverdialog.h +++ b/src/gui/serverdialog.h @@ -191,6 +191,9 @@ class ServerDialog : public Window, float mDownloadProgress; ServerInfos mServers; +#ifndef MANASERV_SUPPORT + ServerInfos mManaservServers; +#endif ServerInfo *mServerInfo; }; diff --git a/src/net/net.cpp b/src/net/net.cpp index 7e7395a6..25dcd981 100644 --- a/src/net/net.cpp +++ b/src/net/net.cpp @@ -134,12 +134,16 @@ void connectToServer(ServerInfo &server) // TODO: Query the server about itself and choose the netcode based on // that +#ifndef MANASERV_SUPPORT + server.type = ServerInfo::TMWATHENA; +#else if (server.port == 6901) server.type = ServerInfo::TMWATHENA; else if (server.port == 9601) server.type = ServerInfo::MANASERV; else logger->error(_("Unknown Server Type! Exiting.")); +#endif } if (networkType == server.type && getGeneralHandler() != NULL) -- cgit v1.2.3-70-g09d2 From c1b7d619971ea3dc7f644c86090a9ac518e44fb1 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Wed, 13 Oct 2010 13:40:41 +0200 Subject: Fixing switch login Switch login gets you stuck at the ConnectionDialog. That happens because logout is not implemented. TODO: Implementing proper logout. This resolves http://bugs.manasource.org/view.php?id=225 --- src/client.cpp | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index f1b363e9..9bf761a0 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -532,12 +532,7 @@ int Client::exec() Net::getLoginHandler()->disconnect(); } else if (mState == STATE_CONNECT_SERVER && - mOldState == STATE_CHOOSE_SERVER) - { - Net::connectToServer(mCurrentServer); - } - else if (mState == STATE_CONNECT_SERVER && - mOldState != STATE_CHOOSE_SERVER && + mOldState == STATE_CONNECT_SERVER && Net::getLoginHandler()->isConnected()) { mState = STATE_LOGIN; @@ -632,6 +627,9 @@ int Client::exec() case STATE_CONNECT_SERVER: logger->log("State: CONNECT SERVER"); + + Net::connectToServer(mCurrentServer); + mCurrentDialog = new ConnectionDialog( _("Connecting to server"), STATE_SWITCH_SERVER); break; @@ -924,9 +922,9 @@ int Client::exec() case STATE_SWITCH_LOGIN: logger->log("State: SWITCH LOGIN"); - Net::getLoginHandler()->logout(); + Net::getLoginHandler()->disconnect(); - mState = STATE_LOGIN; + mState = STATE_CONNECT_SERVER; break; case STATE_SWITCH_CHARACTER: -- cgit v1.2.3-70-g09d2 From 1d16b34c14a3b2deff084757f2b583d54b4741ce Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Wed, 13 Oct 2010 17:32:41 +0200 Subject: Adding theme colors for party tabs Following Rotonen's advise to "make anything and everything you can think of recolorable", a theme can now define colors for PARTY_CHAT_TAB and PARTY_SOCIAL_TAB. This was badly needed, because the requirements for a color of a chat tab and of a player name are quite different. TODO: When guild support gets enabled, then have a look at the colors for guilds. Reviewed-by: 4144 --- data/graphics/gui/colors.xml | 2 ++ src/gui/socialwindow.cpp | 2 +- src/gui/theme.cpp | 2 ++ src/gui/theme.h | 2 ++ src/net/tmwa/gui/partytab.cpp | 2 +- 5 files changed, 8 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/data/graphics/gui/colors.xml b/data/graphics/gui/colors.xml index 546ad5ea..4a35d081 100644 --- a/data/graphics/gui/colors.xml +++ b/data/graphics/gui/colors.xml @@ -6,6 +6,8 @@ + + diff --git a/src/gui/socialwindow.cpp b/src/gui/socialwindow.cpp index ec414836..d52e073c 100644 --- a/src/gui/socialwindow.cpp +++ b/src/gui/socialwindow.cpp @@ -184,7 +184,7 @@ public: { setCaption(party->getName()); - setTabColor(&Theme::getThemeColor(Theme::PARTY)); + setTabColor(&Theme::getThemeColor(Theme::PARTY_SOCIAL_TAB)); mList = new AvatarListBox(party); mScroll = new ScrollArea(mList); diff --git a/src/gui/theme.cpp b/src/gui/theme.cpp index f80fa272..3d0bd5d3 100644 --- a/src/gui/theme.cpp +++ b/src/gui/theme.cpp @@ -398,6 +398,8 @@ static int readColorType(const std::string &type) "BUTTON", "BUTTON_DISABLED", "TAB", + "PARTY_CHAT_TAB", + "PARTY_SOCIAL_TAB", "BACKGROUND", "HIGHLIGHT", "TAB_FLASH", diff --git a/src/gui/theme.h b/src/gui/theme.h index 6798bed5..3a5aa41a 100644 --- a/src/gui/theme.h +++ b/src/gui/theme.h @@ -127,6 +127,8 @@ class Theme : public Palette, public ConfigListener BUTTON, BUTTON_DISABLED, TAB, + PARTY_CHAT_TAB, + PARTY_SOCIAL_TAB, BACKGROUND, HIGHLIGHT, TAB_FLASH, diff --git a/src/net/tmwa/gui/partytab.cpp b/src/net/tmwa/gui/partytab.cpp index 03dadb04..b541c498 100644 --- a/src/net/tmwa/gui/partytab.cpp +++ b/src/net/tmwa/gui/partytab.cpp @@ -42,7 +42,7 @@ namespace TmwAthena { PartyTab::PartyTab() : ChatTab(_("Party")) { - setTabColor(&Theme::getThemeColor(Theme::PARTY)); + setTabColor(&Theme::getThemeColor(Theme::PARTY_CHAT_TAB)); } PartyTab::~PartyTab() -- cgit v1.2.3-70-g09d2 From c3370ee4b57d18a62510240f105791ca3b403224 Mon Sep 17 00:00:00 2001 From: MadCamel Date: Thu, 14 Oct 2010 10:38:04 +0200 Subject: Disable showing of IP addresses while taking a screenshot This could potentially leak confidential information. Reviewed-by: cody --- src/game.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 66b6e3c4..270affb5 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -279,8 +279,23 @@ static bool saveScreenshot() { static unsigned int screenshotCount = 0; + // We don't want to show IP addresses in screenshots + const bool showip = player_node->getShowIp(); + if (showip) + { + player_node->setShowIp(false); + beingManager->updatePlayerNames(); + gui->draw(); + } + SDL_Surface *screenshot = graphics->getScreenshot(); + if (showip) + { + player_node->setShowIp(true); + beingManager->updatePlayerNames(); + } + // Search for an unused screenshot name std::stringstream filenameSuffix; std::stringstream filename; -- cgit v1.2.3-70-g09d2 From bdf409c9c4ce083881133879947cc0a6c2cce0f1 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sat, 16 Oct 2010 17:57:12 +0200 Subject: Fixing wrong SpriteDirection of attacking monsters Reviewed-by: Bertram --- src/being.cpp | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index a3e91147..f2d95c4a 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -448,22 +448,20 @@ void Being::setAction(Action action, int attackType) void Being::setDirection(Uint8 direction) { - if (mDirection == direction) - return; + if (Net::getNetworkType() == ServerInfo::MANASERV) + { + if (mDirection == direction) + return; + } mDirection = direction; - // if the direction does not change much, keep the common component - int mFaceDirection = mDirection & direction; - if (!mFaceDirection) - mFaceDirection = direction; - SpriteDirection dir; - if (mFaceDirection & UP) + if (mDirection & UP) dir = DIRECTION_UP; - else if (mFaceDirection & DOWN) + else if (mDirection & DOWN) dir = DIRECTION_DOWN; - else if (mFaceDirection & RIGHT) + else if (mDirection & RIGHT) dir = DIRECTION_RIGHT; else dir = DIRECTION_LEFT; -- cgit v1.2.3-70-g09d2 From 0d3d7c908ef6d294b14f55f09c9d83767fbc5f32 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 12 Oct 2010 19:59:25 +0300 Subject: Implement opacity cache for SDL surfaces. Enabled by default. Can be disabled in configuration option "alphaCache" if set it to 0. Reviewed-by: Bertram --- src/client.cpp | 2 + src/gui/gui.cpp | 3 ++ src/resources/image.cpp | 94 ++++++++++++++++++++++++++++++++++++--- src/resources/image.h | 25 +++++++++-- src/resources/resourcemanager.cpp | 15 +++++++ src/resources/resourcemanager.h | 6 +++ 6 files changed, 135 insertions(+), 10 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 9bf761a0..2d5bdc3f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -251,6 +251,8 @@ Client::Client(const Options &options): "Exiting.", mLocalDataDir.c_str())); } + Image::setEnableAlphaCache(config.getValue("alphaCache", true)); + #if defined __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); diff --git a/src/gui/gui.cpp b/src/gui/gui.cpp index df2ddadf..75f67435 100644 --- a/src/gui/gui.cpp +++ b/src/gui/gui.cpp @@ -160,6 +160,9 @@ Gui::~Gui() void Gui::logic() { + ResourceManager *resman = ResourceManager::getInstance(); + resman->clearScheduled(); + // Fade out mouse cursor after extended inactivity if (mMouseInactivityTimer < 100 * 15) { diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 82799bce..cd6bda15 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -22,6 +22,7 @@ #include "resources/image.h" #include "resources/dye.h" +#include "resources/resourcemanager.h" #ifdef USE_OPENGL #include "openglgraphics.h" @@ -37,6 +38,7 @@ bool Image::mUseOpenGL = false; int Image::mTextureType = 0; int Image::mTextureSize = 0; #endif +bool Image::mEnableAlphaCache = false; Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): mAlpha(1.0f), @@ -48,6 +50,8 @@ Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): mGLImage = 0; #endif + mUseAlphaCache = Image::mEnableAlphaCache; + mBounds.x = 0; mBounds.y = 0; @@ -71,6 +75,7 @@ Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight) mHasAlphaChannel(true), mSDLSurface(0), mAlphaChannel(0), + mUseAlphaCache(false), mGLImage(glimage), mTexWidth(texWidth), mTexHeight(texHeight) @@ -166,12 +171,28 @@ Image *Image::load(SDL_Surface *tmpImage) return _SDLload(tmpImage); } +void Image::cleanCache() +{ + ResourceManager *resman = ResourceManager::getInstance(); + + for (std::map::iterator + i = mAlphaCache.begin(), i_end = mAlphaCache.end(); + i != i_end; ++i) + { + if (mSDLSurface != i->second) + resman->scheduleDelete(i->second); + i->second = 0; + } + mAlphaCache.clear(); +} + void Image::unload() { mLoaded = false; if (mSDLSurface) { + cleanCache(); // Free the image surface. SDL_FreeSurface(mSDLSurface); mSDLSurface = NULL; @@ -211,6 +232,14 @@ bool Image::hasAlphaChannel() return false; } +SDL_Surface *Image::getByAlpha(float alpha) +{ + std::map::iterator it = mAlphaCache.find(alpha); + if (it != mAlphaCache.end()) + return (*it).second; + return 0; +} + void Image::setAlpha(float alpha) { if (mAlpha == alpha) @@ -219,10 +248,34 @@ void Image::setAlpha(float alpha) if (alpha < 0.0f || alpha > 1.0f) return; - mAlpha = alpha; - if (mSDLSurface) { + if (mUseAlphaCache) + { + SDL_Surface *surface = getByAlpha(mAlpha); + if (!surface) + { + if (mAlphaCache.size() > 100) + cleanCache(); + + mAlphaCache[mAlpha] = mSDLSurface; + } + surface = getByAlpha(alpha); + if (surface) + { + mAlphaCache.erase(alpha); + mSDLSurface = surface; + mAlpha = alpha; + return; + } + else + { + mSDLSurface = Image::duplicateSurface(mSDLSurface); + } + } + + mAlpha = alpha; + if (!hasAlphaChannel()) { // Set the alpha value this image is drawn at @@ -263,6 +316,10 @@ void Image::setAlpha(float alpha) SDL_UnlockSurface(mSDLSurface); } } + else + { + mAlpha = alpha; + } } Image* Image::SDLmerge(Image *image, int x, int y) @@ -371,6 +428,14 @@ Image* Image::SDLgetScaledImage(int width, int height) return scaledImage; } +SDL_Surface* Image::duplicateSurface(SDL_Surface* tmpImage) +{ + if (!tmpImage || !tmpImage->format) + return NULL; + + return SDL_ConvertSurface(tmpImage, tmpImage->format, SDL_SWSURFACE); +} + Image *Image::_SDLload(SDL_Surface *tmpImage) { if (!tmpImage) @@ -560,25 +625,40 @@ Image *Image::getSubImage(int x, int y, int width, int height) return new SubImage(this, mSDLSurface, x, y, width, height); } +void Image::terminateAlphaCache() +{ + cleanCache(); + mUseAlphaCache = false; +} + //============================================================================ // SubImage Class //============================================================================ SubImage::SubImage(Image *parent, SDL_Surface *image, - int x, int y, int width, int height): + int x, int y, int width, int height): Image(image), mParent(parent) { - mParent->incRef(); - - mHasAlphaChannel = mParent->hasAlphaChannel(); - mAlphaChannel = mParent->SDLgetAlphaChannel(); + if (mParent) + { + mParent->incRef(); + mParent->terminateAlphaCache(); + mHasAlphaChannel = mParent->hasAlphaChannel(); + mAlphaChannel = mParent->SDLgetAlphaChannel(); + } + else + { + mHasAlphaChannel = false; + mAlphaChannel = 0; + } // Set up the rectangle. mBounds.x = x; mBounds.y = y; mBounds.w = width; mBounds.h = height; + mUseAlphaCache = false; } #ifdef USE_OPENGL diff --git a/src/resources/image.h b/src/resources/image.h index 3e8ad551..815b7764 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -39,6 +39,8 @@ #include #endif +#include + class Dye; class Position; @@ -169,6 +171,15 @@ class Image : public Resource Uint8 *SDLgetAlphaChannel() const { return mAlphaChannel; } + SDL_Surface* duplicateSurface(SDL_Surface* tmpImage); + + void cleanCache(); + + void terminateAlphaCache(); + + static void setEnableAlphaCache(bool n) + { mEnableAlphaCache = n; } + #ifdef USE_OPENGL // OpenGL only public functions @@ -208,14 +219,22 @@ class Image : public Resource /** SDL_Surface to SDL_Surface Image loader */ static Image *_SDLload(SDL_Surface *tmpImage); + SDL_Surface *getByAlpha(float alpha); + SDL_Surface *mSDLSurface; /** Alpha Channel pointer used for 32bit based SDL surfaces */ Uint8 *mAlphaChannel; - // ----------------------- - // OpenGL protected members - // ----------------------- + std::map mAlphaCache; + + bool mUseAlphaCache; + + static bool mEnableAlphaCache; + + // ----------------------- + // OpenGL protected members + // ----------------------- #ifdef USE_OPENGL /** * OpenGL Constructor. diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index c63b626e..00e4726e 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -533,3 +533,18 @@ SDL_Surface *ResourceManager::loadSDLSurface(const std::string &filename) return tmp; } + +void ResourceManager::scheduleDelete(SDL_Surface* surface) +{ + mDeletedSurfaces.insert(surface); +} + +void ResourceManager::clearScheduled() +{ + for (std::set::iterator i = mDeletedSurfaces.begin(), + i_end = mDeletedSurfaces.end(); i != i_end; ++i) + { + SDL_FreeSurface(*i); + } + mDeletedSurfaces.clear(); +} diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 28ab4725..870182e4 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -26,6 +26,7 @@ #include #include #include +#include class Image; class ImageSet; @@ -205,6 +206,10 @@ class ResourceManager */ SDL_Surface *loadSDLSurface(const std::string &filename); + void scheduleDelete(SDL_Surface* surface); + + void clearScheduled(); + /** * Returns an instance of the class, creating one if it does not * already exist. @@ -227,6 +232,7 @@ class ResourceManager static ResourceManager *instance; typedef std::map Resources; typedef Resources::iterator ResourceIterator; + std::set mDeletedSurfaces; Resources mResources; Resources mOrphanedResources; time_t mOldestOrphan; -- cgit v1.2.3-70-g09d2 From cbb79bd12979ea8458e934f4ce890660473e3865 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 16 Oct 2010 22:21:16 +0300 Subject: Return to color config options prefix Color. Reviewed-by: cody --- src/gui/userpalette.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index 0f30b752..e5726ada 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -33,21 +33,21 @@ #include const std::string ColorTypeNames[] = { - "Being", - "Player", - "Self", - "GM", - "NPC", - "Monster", - "Party", - "Guild", - "Particle", - "Experience", - "Pickup", - "Hit Player Monster", - "Hit Monster Player", - "Hit Critical", - "Miss" + "ColorBeing", + "ColorPlayer", + "ColorSelf", + "ColorGM", + "ColorNPC", + "ColorMonster", + "ColorParty", + "ColorGuild", + "ColorParticle", + "ColorExperience", + "ColorPickup", + "ColorHitPlayerMonster", + "ColorHitMonsterPlayer", + "ColorHitCritical", + "ColorMiss" }; std::string UserPalette::getConfigName(const std::string &typeName) -- cgit v1.2.3-70-g09d2 From 58f04040cea0c7eb64388925dcdf8de848dd47c2 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sat, 16 Oct 2010 23:22:55 +0300 Subject: Add new three colors. Add colors: Local Player Hits Monster Local Player Critical Hit Local Player Miss Reviewed-by: cody --- src/being.cpp | 23 ++++++++++++++++++++--- src/gui/userpalette.cpp | 12 +++++++++++- src/gui/userpalette.h | 3 +++ 3 files changed, 34 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/being.cpp b/src/being.cpp index f2d95c4a..be8afa79 100644 --- a/src/being.cpp +++ b/src/being.cpp @@ -261,7 +261,15 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) // Selecting the right color if (type == CRITICAL || type == FLEE) { - color = &userPalette->getColor(UserPalette::HIT_CRITICAL); + if (attacker == player_node) + { + color = &userPalette->getColor( + UserPalette::HIT_LOCAL_PLAYER_CRITICAL); + } + else + { + color = &userPalette->getColor(UserPalette::HIT_CRITICAL); + } } else if (!amount) { @@ -269,7 +277,7 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) { // This is intended to be the wrong direction to visually // differentiate between hits and misses - color = &userPalette->getColor(UserPalette::HIT_MONSTER_PLAYER); + color = &userPalette->getColor(UserPalette::HIT_LOCAL_PLAYER_MISS); } else { @@ -278,7 +286,16 @@ void Being::takeDamage(Being *attacker, int amount, AttackType type) } else if (getType() == MONSTER) { - color = &userPalette->getColor(UserPalette::HIT_PLAYER_MONSTER); + if (attacker == player_node) + { + color = &userPalette->getColor( + UserPalette::HIT_LOCAL_PLAYER_MONSTER); + } + else + { + color = &userPalette->getColor( + UserPalette::HIT_PLAYER_MONSTER); + } } else { diff --git a/src/gui/userpalette.cpp b/src/gui/userpalette.cpp index e5726ada..9e202fe9 100644 --- a/src/gui/userpalette.cpp +++ b/src/gui/userpalette.cpp @@ -47,6 +47,9 @@ const std::string ColorTypeNames[] = { "ColorHitPlayerMonster", "ColorHitMonsterPlayer", "ColorHitCritical", + "ColorHitLocalPlayerMonster", + "ColorHitLocalPlayerCritical", + "ColorHitLocalPlayerMiss", "ColorMiss" }; @@ -96,9 +99,16 @@ UserPalette::UserPalette(): addColor(PARTICLE, 0xffffff, STATIC, _("Particle Effects")); addColor(PICKUP_INFO, 0x28dc28, STATIC, _("Pickup Notification")); addColor(EXP_INFO, 0xffff00, STATIC, _("Exp Notification")); - addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, _("Player Hits Monster")); + addColor(HIT_PLAYER_MONSTER, 0x0064ff, STATIC, + _("Other Player Hits Monster")); addColor(HIT_MONSTER_PLAYER, 0xff3232, STATIC, _("Monster Hits Player")); addColor(HIT_CRITICAL, 0xff0000, RAINBOW, _("Critical Hit")); + addColor(HIT_LOCAL_PLAYER_MONSTER, 0x00ff00, STATIC, + _("Local Player Hits Monster")); + addColor(HIT_LOCAL_PLAYER_CRITICAL, 0xff0000, RAINBOW, + _("Local Player Critical Hit")); + addColor(HIT_LOCAL_PLAYER_MISS, 0x00ffa6, STATIC, + _("Local Player Miss")); addColor(MISS, 0xffff00, STATIC, _("Misses")); commit(true); } diff --git a/src/gui/userpalette.h b/src/gui/userpalette.h index 82bcea1c..be02db10 100644 --- a/src/gui/userpalette.h +++ b/src/gui/userpalette.h @@ -49,6 +49,9 @@ class UserPalette : public Palette, public gcn::ListModel HIT_PLAYER_MONSTER, HIT_MONSTER_PLAYER, HIT_CRITICAL, + HIT_LOCAL_PLAYER_MONSTER, + HIT_LOCAL_PLAYER_CRITICAL, + HIT_LOCAL_PLAYER_MISS, MISS, USER_COLOR_LAST }; -- cgit v1.2.3-70-g09d2 From bc409be3aa785f3646ad0f2372a3da9cf0783c77 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 17 Oct 2010 00:05:14 +0200 Subject: Fixing missing translation of direction for tA-server Reviewed-by: Bertram --- src/net/messagein.cpp | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 6a5adbe1..5f1e96b7 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -20,6 +20,7 @@ */ #include "net/messagein.h" +#include "net/net.h" #define MAKEWORD(low,high) \ ((unsigned short)(((unsigned char)(low)) | \ @@ -97,6 +98,12 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) case 7: direction = 9; break; + case 8: + if (Net::getNetworkType() == ServerInfo::TMWATHENA) + { + direction = 8; + break; + } default: // OOPSIE! Impossible or unknown direction = 0; -- cgit v1.2.3-70-g09d2 From 9824ccf5946c86df1cf497b797c5f3da5d481d28 Mon Sep 17 00:00:00 2001 From: "madcamel@gmail.com" Date: Sat, 16 Oct 2010 14:35:24 +0200 Subject: Added Low CPU Mode toggle in video setup. Defaults to On. This disables the Image::setAlpha() function, which uses 60% of the client's CPU cycles. When enabled, visual quality is slightly decreased, especially with the particle system. Toggling this setting On from an Off state requires a client restart or the graphics look quite funny. Bertram's addition: - Renamed 'Low CPU' to 'Disable transparency (Low CPU)' in the gui for better understanding. - Removed the sprite display with 30% opacity when disabling transparency since it made monsters and drops be drawn above all layers at full opacity. - Made the OpenGL mode disable the 'low CPU mode'. - Fixed the GUI logic as much as possible. Please note that the GUI opacity slider stays enabled when transparency is disabled even if told to be disabled in that case. Reviewed-by: CodyMartin, 4144, MadCamel. --- src/client.cpp | 1 + src/gui/setup_video.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++--- src/gui/setup_video.h | 3 +++ src/map.cpp | 24 ++++++++++++--------- src/resources/image.cpp | 4 ++++ 5 files changed, 74 insertions(+), 13 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 2d5bdc3f..0b62a48d 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -1107,6 +1107,7 @@ void Client::initConfiguration() config.setValue("customcursor", true); config.setValue("useScreenshotDirectorySuffix", true); config.setValue("ChatLogLength", 128); + config.setValue("lowcpu", true); // Checking if the configuration file exists... otherwise create it with // default options. diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index ba967275..1a3d15bf 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -211,6 +211,7 @@ Setup_Video::Setup_Video(): mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 60)), + mLowCPUEnabled(config.getValue("lowcpu", true)), mSpeechMode(static_cast( config.getValue("speech", Being::TEXT_OVERHEAD))), mModeListModel(new ModeListModel), @@ -243,7 +244,9 @@ Setup_Video::Setup_Video(): mParticleDetail(3 - (int) config.getValue("particleEmitterSkip", 1)), mParticleDetailSlider(new Slider(0, 3)), mParticleDetailField(new Label), - mFontSize((int) config.getValue("fontSize", 11)) + mFontSize((int) config.getValue("fontSize", 11)), + mLowCPUCheckBox(new CheckBox(_("Disable transparency (Low CPU mode)"), + mLowCPUEnabled)) { setName(_("Video")); @@ -277,6 +280,10 @@ Setup_Video::Setup_Video(): mFpsSlider->setEnabled(mFps > 0); mFpsCheckBox->setSelected(mFps > 0); + // If the openGL Mode is enabled, disabling the transaprency + // is irrelelvant. + mLowCPUCheckBox->setEnabled(!mOpenGLEnabled); + // Pre-select the current video mode. std::string videoMode = toString(graphics->getWidth()) + "x" + toString(graphics->getHeight()); @@ -297,6 +304,7 @@ Setup_Video::Setup_Video(): mFpsSlider->setActionEventId("fpslimitslider"); mOverlayDetailSlider->setActionEventId("overlaydetailslider"); mOverlayDetailField->setActionEventId("overlaydetailfield"); + mOpenGLCheckBox->setActionEventId("opengl"); mParticleDetailSlider->setActionEventId("particledetailslider"); mParticleDetailField->setActionEventId("particledetailfield"); @@ -304,6 +312,7 @@ Setup_Video::Setup_Video(): mCustomCursorCheckBox->addActionListener(this); mShowMonsterDamageCheckBox->addActionListener(this); mVisibleNamesCheckBox->addActionListener(this); + mOpenGLCheckBox->addActionListener(this); mParticleEffectsCheckBox->addActionListener(this); mPickupChatCheckBox->addActionListener(this); mPickupParticleCheckBox->addActionListener(this); @@ -317,6 +326,7 @@ Setup_Video::Setup_Video(): mOverlayDetailField->addKeyListener(this); mParticleDetailSlider->addActionListener(this); mParticleDetailField->addKeyListener(this); + mLowCPUCheckBox->addActionListener(this); mSpeechLabel->setCaption(speechModeToString(mSpeechMode)); mSpeechSlider->setValue(mSpeechMode); @@ -374,6 +384,8 @@ Setup_Video::Setup_Video(): place(1, 11, particleDetailLabel); place(2, 11, mParticleDetailField, 3).setPadding(2); + place(0, 12, mLowCPUCheckBox, 4); + setDimension(gcn::Rectangle(0, 0, 365, 300)); } @@ -444,8 +456,9 @@ void Setup_Video::apply() { new OkDialog(_("Changing to OpenGL"), _("Applying change to OpenGL requires restart. " - "In case OpenGL messes up your game graphics, restart " - "the game with the command line option \"--no-opengl\".")); + "In case OpenGL messes up your game graphics, " + "restart the game with the command line option " + "\"--no-opengl\".")); } else { @@ -454,6 +467,30 @@ void Setup_Video::apply() } } + // If LowCPU is enabled from a disabled state we warn the user + if (mLowCPUCheckBox->isSelected()) + { + if (config.getValue("lowcpu", true) == false) + { + new OkDialog(_("Low CPU Mode Enabled"), + _("You must restart to prevent graphical errors.")); + } + + mLowCPUEnabled = true; + config.setValue("lowcpu", true); + } + else + { + if (config.getValue("lowcpu", true) == true) + { + new OkDialog(_("Low CPU Mode Disabled"), + _("You must restart to apply changes.")); + } + + mLowCPUEnabled = false; + config.setValue("lowcpu", false); + } + mFps = mFpsCheckBox->isSelected() ? (int) mFpsSlider->getValue() : 0; mFpsSlider->setEnabled(mFps > 0); @@ -476,6 +513,7 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", false); mPickupChatEnabled = config.getValue("showpickupchat", true); mPickupParticleEnabled = config.getValue("showpickupparticle", false); + mLowCPUEnabled = config.getValue("lowcpu", true); } void Setup_Video::cancel() @@ -497,6 +535,7 @@ void Setup_Video::cancel() mParticleDetailSlider->setValue(mParticleDetail); std::string text = mFpsCheckBox->isSelected() ? toString(mFps) : _("None"); mFpsLabel->setCaption(text); + mLowCPUCheckBox->setSelected(mLowCPUEnabled); config.setValue("screen", mFullScreenEnabled); @@ -628,4 +667,14 @@ void Setup_Video::action(const gcn::ActionEvent &event) mFpsSlider->setValue(mFps); mFpsSlider->setEnabled(mFps > 0); } + else if (id == "opengl") + { + // Disable low cpu mode when in OpenGL. + mLowCPUCheckBox->setEnabled(!mOpenGLCheckBox->isSelected()); + // Disable gui opacity slider when disabling transparency. + if (mLowCPUCheckBox->isEnabled()) + mAlphaSlider->setEnabled(!mLowCPUCheckBox->isSelected()); + else + mAlphaSlider->setEnabled(true); + } } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index ae0786b1..0f8a1e70 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -62,6 +62,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mPickupParticleEnabled; double mOpacity; int mFps; + bool mLowCPUEnabled; Being::Speech mSpeechMode; ModeListModel *mModeListModel; @@ -106,6 +107,8 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, int mFontSize; gcn::DropDown *mFontSizeDropDown; + + gcn::CheckBox *mLowCPUCheckBox; }; #endif diff --git a/src/map.cpp b/src/map.cpp index f1f8d091..2de0a4a8 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -330,21 +330,25 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) mSprites, mDebugFlags); } - // Draws beings with a lower opacity to make them visible - // even when covered by a wall or some other elements... - MapSprites::const_iterator si = mSprites.begin(); - while (si != mSprites.end()) + // If the transparency hasn't been disabled, + if (config.getValue("opengl", false) || !config.getValue("lowcpu", true)) { - if (Sprite *sprite = *si) + // We draw beings with a lower opacity to make them visible + // even when covered by a wall or some other elements... + MapSprites::const_iterator si = mSprites.begin(); + while (si != mSprites.end()) { - // For now, just draw sprites with only one layer. - if (sprite->getNumberOfLayers() == 1) + if (Sprite *sprite = *si) { - sprite->setAlpha(0.3f); - sprite->draw(graphics, -scrollX, -scrollY); + // For now, just draw sprites with only one layer. + if (sprite->getNumberOfLayers() == 1) + { + sprite->setAlpha(0.3f); + sprite->draw(graphics, -scrollX, -scrollY); + } } + si++; } - si++; } drawAmbientLayers(graphics, FOREGROUND_LAYERS, scrollX, scrollY, diff --git a/src/resources/image.cpp b/src/resources/image.cpp index cd6bda15..42a6ab56 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -29,6 +29,7 @@ #endif #include "log.h" +#include "configuration.h" #include #include @@ -242,6 +243,9 @@ SDL_Surface *Image::getByAlpha(float alpha) void Image::setAlpha(float alpha) { + if (config.getValue("lowcpu", true) == true) + return; + if (mAlpha == alpha) return; -- cgit v1.2.3-70-g09d2 From 02a014605d19d0d38c14cafa462a2539d63950df Mon Sep 17 00:00:00 2001 From: Philipp Sehmisch Date: Sun, 17 Oct 2010 00:47:38 +0200 Subject: Fixed wrong alpha calculation of text particles This resolves: http://bugs.manasource.org/view.php?id=51 Reviewed-by: Bertram --- src/imageparticle.cpp | 10 +--------- src/particle.cpp | 13 +++++++++++++ src/particle.h | 3 +++ src/textparticle.cpp | 10 +--------- 4 files changed, 18 insertions(+), 18 deletions(-) (limited to 'src') diff --git a/src/imageparticle.cpp b/src/imageparticle.cpp index feb9548d..8ef2cce9 100644 --- a/src/imageparticle.cpp +++ b/src/imageparticle.cpp @@ -56,14 +56,6 @@ void ImageParticle::draw(Graphics *graphics, int offsetX, int offsetY) const return; } - float alphafactor = mAlpha; - - if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) - alphafactor *= (float) mLifetimeLeft / (float) mFadeOut; - - if (mLifetimePast < mFadeIn) - alphafactor *= (float) mLifetimePast / (float) mFadeIn; - - mImage->setAlpha(alphafactor); + mImage->setAlpha(getCurrentAlpha()); graphics->drawImage(mImage, screenX, screenY); } diff --git a/src/particle.cpp b/src/particle.cpp index 84161c9f..0c4a7d7e 100644 --- a/src/particle.cpp +++ b/src/particle.cpp @@ -393,6 +393,19 @@ void Particle::adjustEmitterSize(int w, int h) } } +float Particle::getCurrentAlpha() const +{ + float alpha = mAlpha; + + if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) + alpha *= (float)mLifetimeLeft / (float)mFadeOut; + + if (mLifetimePast < mFadeIn) + alpha *= (float)mLifetimePast / (float)mFadeIn; + + return alpha; +} + void Particle::setMap(Map *map) { mMap = map; diff --git a/src/particle.h b/src/particle.h index 0690e8c4..69f8c2be 100644 --- a/src/particle.h +++ b/src/particle.h @@ -286,6 +286,9 @@ class Particle : public Sprite { return 1; } protected: + /** Calculates the current alpha transparency taking current fade status into account*/ + float getCurrentAlpha() const; + bool mAlive; /**< Is the particle supposed to be drawn and updated?*/ Vector mPos; /**< Position in pixels relative to map. */ int mLifetimeLeft; /**< Lifetime left in game ticks*/ diff --git a/src/textparticle.cpp b/src/textparticle.cpp index e6226449..c9b5fc18 100644 --- a/src/textparticle.cpp +++ b/src/textparticle.cpp @@ -44,16 +44,8 @@ void TextParticle::draw(Graphics *graphics, int offsetX, int offsetY) const int screenX = (int) mPos.x + offsetX; int screenY = (int) mPos.y - (int) mPos.z + offsetY; - float alpha = mAlpha * 255.0f; - - if (mLifetimeLeft > -1 && mLifetimeLeft < mFadeOut) - alpha = alpha * mLifetimeLeft / mFadeOut; - - if (mLifetimePast < mFadeIn) - alpha = alpha * mLifetimePast / mFadeIn; - gcn::Color color = *mColor; - color.a = (int)alpha; + color.a = getCurrentAlpha() * 255; TextRenderer::renderText(graphics, mText, screenX, screenY, gcn::Graphics::CENTER, -- cgit v1.2.3-70-g09d2 From b5dc469d6a15403ca0fd8272dc39d83980bdbfba Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 17 Oct 2010 11:37:02 +0200 Subject: Fixing commandline option for local data directory --- src/main.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/main.cpp b/src/main.cpp index fed7db60..c130bba9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -137,7 +137,7 @@ static void parseOptions(int argc, char *argv[], Client::Options &options) case 'v': options.printVersion = true; break; - case 'S': + case 'L': options.localDataDir = optarg; break; case 'O': -- cgit v1.2.3-70-g09d2 From 564d845603964401533922f5c81c99c385817d4b Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Sun, 17 Oct 2010 14:47:34 +0200 Subject: Removed unnecessary condition in net::readCoordinates. It is used only by tmwa handlers. Trivial fix. --- src/net/messagein.cpp | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/net/messagein.cpp b/src/net/messagein.cpp index 5f1e96b7..3c3e9edf 100644 --- a/src/net/messagein.cpp +++ b/src/net/messagein.cpp @@ -20,7 +20,6 @@ */ #include "net/messagein.h" -#include "net/net.h" #define MAKEWORD(low,high) \ ((unsigned short)(((unsigned char)(low)) | \ @@ -99,11 +98,8 @@ void MessageIn::readCoordinates(Uint16 &x, Uint16 &y, Uint8 &direction) direction = 9; break; case 8: - if (Net::getNetworkType() == ServerInfo::TMWATHENA) - { - direction = 8; - break; - } + direction = 8; + break; default: // OOPSIE! Impossible or unknown direction = 0; -- cgit v1.2.3-70-g09d2 From be599ed0d7b1c1e70cb593dcdfae69fad926e6b7 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 17 Oct 2010 21:25:22 +0200 Subject: Changing client version to 0.5 Removing mana-ea.rc, because it was the same as mana.rc. Reviewed-by: Aard, Bertram --- mana.cbp | 3 --- src/main.h | 2 +- src/mana-ea.rc | 23 ----------------------- src/winver.h | 4 ++-- 4 files changed, 3 insertions(+), 29 deletions(-) delete mode 100644 src/mana-ea.rc (limited to 'src') diff --git a/mana.cbp b/mana.cbp index 2c7ea41c..8521355d 100644 --- a/mana.cbp +++ b/mana.cbp @@ -371,9 +371,6 @@ - - diff --git a/src/main.h b/src/main.h index 3f30ef14..679f7c7d 100644 --- a/src/main.h +++ b/src/main.h @@ -55,7 +55,7 @@ #elif defined WIN32 #include "winver.h" #elif defined __APPLE__ -#define PACKAGE_VERSION "1.0.0" +#define PACKAGE_VERSION "0.5.0" #endif #ifdef PACKAGE_VERSION diff --git a/src/mana-ea.rc b/src/mana-ea.rc deleted file mode 100644 index 12068ea2..00000000 --- a/src/mana-ea.rc +++ /dev/null @@ -1,23 +0,0 @@ -#include // include for version info constants - -#include "winver.h" - -A ICON MOVEABLE PURE LOADONCALL DISCARDABLE "../data/icons/mana.ico" - -1 VERSIONINFO -FILEVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD -PRODUCTVERSION VER_MAJOR,VER_MINOR,VER_RELEASE,VER_BUILD -//FILETYPE VFT_APP -{ - BLOCK "StringFileInfo" { - BLOCK "040904E4" { - VALUE "CompanyName", "The Mana Development Team" - VALUE "FileVersion", PACKAGE_VERSION - VALUE "FileDescription", "Mana (Eathena)" - VALUE "LegalCopyright", "2004-2010 (C)" - VALUE "OriginalFilename", "mana-ea.exe" - VALUE "ProductName", "Mana MMORPG Client" - VALUE "ProductVersion", PACKAGE_VERSION - } - } -} diff --git a/src/winver.h b/src/winver.h index 03a0c215..ea8d8e9c 100644 --- a/src/winver.h +++ b/src/winver.h @@ -1,6 +1,6 @@ /* VERSION DEFINITIONS */ #define VER_MAJOR 0 -#define VER_MINOR 1 +#define VER_MINOR 5 #define VER_RELEASE 0 #define VER_BUILD 0 -#define PACKAGE_VERSION "0.1.0.0" +#define PACKAGE_VERSION "0.5.0.0" -- cgit v1.2.3-70-g09d2 From de8317bc5ac2d6ab3d60697a660a7bf49e7dedc5 Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 17 Oct 2010 22:16:01 +0200 Subject: Making the setup for lowcpu robust Reviewed-by: Bertram, Thorbjorn --- src/gui/setup_video.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 1a3d15bf..329b70d1 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -273,6 +273,7 @@ Setup_Video::Setup_Video(): mAlphaSlider->setValue(mOpacity); mAlphaSlider->setWidth(90); + mAlphaSlider->setEnabled(!mLowCPUEnabled); mFpsLabel->setCaption(mFps > 0 ? toString(mFps) : _("None")); mFpsLabel->setWidth(60); @@ -307,6 +308,7 @@ Setup_Video::Setup_Video(): mOpenGLCheckBox->setActionEventId("opengl"); mParticleDetailSlider->setActionEventId("particledetailslider"); mParticleDetailField->setActionEventId("particledetailfield"); + mLowCPUCheckBox->setActionEventId("lowcpu"); mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); @@ -466,9 +468,8 @@ void Setup_Video::apply() _("Applying change to OpenGL requires restart.")); } } - // If LowCPU is enabled from a disabled state we warn the user - if (mLowCPUCheckBox->isSelected()) + else if (mLowCPUCheckBox->isSelected()) { if (config.getValue("lowcpu", true) == false) { @@ -531,11 +532,13 @@ void Setup_Video::cancel() mNameCheckBox->setSelected(mNameEnabled); mNPCLogCheckBox->setSelected(mNPCLogEnabled); mAlphaSlider->setValue(mOpacity); + mAlphaSlider->setEnabled(!mLowCPUEnabled); mOverlayDetailSlider->setValue(mOverlayDetail); mParticleDetailSlider->setValue(mParticleDetail); std::string text = mFpsCheckBox->isSelected() ? toString(mFps) : _("None"); mFpsLabel->setCaption(text); mLowCPUCheckBox->setSelected(mLowCPUEnabled); + mLowCPUCheckBox->setEnabled(!mOpenGLEnabled); config.setValue("screen", mFullScreenEnabled); @@ -559,6 +562,7 @@ void Setup_Video::cancel() config.setValue("opengl", mOpenGLEnabled); config.setValue("showpickupchat", mPickupChatEnabled); config.setValue("showpickupparticle", mPickupParticleEnabled); + config.setValue("lowcpu", mLowCPUEnabled); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -667,10 +671,17 @@ void Setup_Video::action(const gcn::ActionEvent &event) mFpsSlider->setValue(mFps); mFpsSlider->setEnabled(mFps > 0); } - else if (id == "opengl") + else if (id == "opengl" || id == "lowcpu") { // Disable low cpu mode when in OpenGL. - mLowCPUCheckBox->setEnabled(!mOpenGLCheckBox->isSelected()); + if (mOpenGLCheckBox->isSelected()) + { + mLowCPUCheckBox->setSelected(false); + mLowCPUCheckBox->setEnabled(false); + } + else{ + mLowCPUCheckBox->setEnabled(true); + } // Disable gui opacity slider when disabling transparency. if (mLowCPUCheckBox->isEnabled()) mAlphaSlider->setEnabled(!mLowCPUCheckBox->isSelected()); -- cgit v1.2.3-70-g09d2 From 11c6210b6190111657f7cccf33187ac4d7050a1f Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Mon, 18 Oct 2010 00:53:52 +0200 Subject: Fixing saving of lowcpu value in config Trivial fix. --- src/gui/setup_video.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index 329b70d1..fd7022c0 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -476,9 +476,6 @@ void Setup_Video::apply() new OkDialog(_("Low CPU Mode Enabled"), _("You must restart to prevent graphical errors.")); } - - mLowCPUEnabled = true; - config.setValue("lowcpu", true); } else { @@ -487,10 +484,8 @@ void Setup_Video::apply() new OkDialog(_("Low CPU Mode Disabled"), _("You must restart to apply changes.")); } - - mLowCPUEnabled = false; - config.setValue("lowcpu", false); } + config.setValue("lowcpu", mLowCPUCheckBox->isSelected()); mFps = mFpsCheckBox->isSelected() ? (int) mFpsSlider->getValue() : 0; mFpsSlider->setEnabled(mFps > 0); @@ -679,7 +674,8 @@ void Setup_Video::action(const gcn::ActionEvent &event) mLowCPUCheckBox->setSelected(false); mLowCPUCheckBox->setEnabled(false); } - else{ + else + { mLowCPUCheckBox->setEnabled(true); } // Disable gui opacity slider when disabling transparency. -- cgit v1.2.3-70-g09d2 From 82183b30b62e3bc9030e30bbfafdde3846ad9856 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Fri, 15 Oct 2010 22:49:12 +0300 Subject: Add portable support for windows version. Add portable option to windows installer. Reviewed-by: Thorbjorn --- packaging/windows/portable.xml | 6 +++++ packaging/windows/setup.nsi | 6 +++++ src/client.cpp | 60 ++++++++++++++++++++++++++++++++++++++++-- src/client.h | 2 ++ 4 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 packaging/windows/portable.xml (limited to 'src') diff --git a/packaging/windows/portable.xml b/packaging/windows/portable.xml new file mode 100644 index 00000000..0059d109 --- /dev/null +++ b/packaging/windows/portable.xml @@ -0,0 +1,6 @@ + + + diff --git a/packaging/windows/setup.nsi b/packaging/windows/setup.nsi index 9c620f35..602fc29f 100644 --- a/packaging/windows/setup.nsi +++ b/packaging/windows/setup.nsi @@ -229,6 +229,11 @@ Section /o "Music" SecMusic Delete "$TEMP\tmwmusic-0.2.tar.gz" SectionEnd +Section /o "Portable" SecPortable + SetOutPath "$INSTDIR" + File "portable.xml" +SectionEnd + Section "Translations" SecTrans SetOutPath "$INSTDIR" File /nonfatal /r "${SRCDIR}\translations" @@ -238,6 +243,7 @@ SectionEnd !insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN !insertmacro MUI_DESCRIPTION_TEXT ${SecCore} "The core program files." !insertmacro MUI_DESCRIPTION_TEXT ${SecMusic} "Background music. (If selected the music will be downloaded from the internet.)" + !insertmacro MUI_DESCRIPTION_TEXT ${SecPortable} "Portable client. (If selected client will work as portable client.)" !insertmacro MUI_DESCRIPTION_TEXT ${SecTrans} "Translations for the user interface into 23 different languages. Uncheck this component to leave it in English." !insertmacro MUI_FUNCTION_DESCRIPTION_END diff --git a/src/client.cpp b/src/client.cpp index 0b62a48d..2681a254 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -195,6 +195,7 @@ Client *Client::mInstance = 0; Client::Client(const Options &options): mOptions(options), + mRootDir(""), mCurrentDialog(0), mQuitDialog(0), mDesktop(0), @@ -217,6 +218,7 @@ Client::Client(const Options &options): branding.init(options.brandingPath); } + initRootDir(); initHomeDir(); initConfiguration(); @@ -1001,6 +1003,57 @@ void Client::action(const gcn::ActionEvent &event) } } +void Client::initRootDir() +{ + mRootDir = PHYSFS_getBaseDir(); +#ifdef WIN32 + std::string portableName = mRootDir + "portable.xml"; + struct stat statbuf; + + if (!stat(portableName.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) + { + std::string dir; + Configuration portable; + portable.init(portableName); + + logger->log("Portable file: %s", portableName.c_str()); + + if (mOptions.localDataDir.empty()) + { + dir = portable.getValue("dataDir", ""); + if (!dir.empty()) + { + mOptions.localDataDir = mRootDir + dir; + logger->log("Portable data dir: %s", + mOptions.localDataDir.c_str()); + } + } + + if (mOptions.configDir.empty()) + { + dir = portable.getValue("configDir", ""); + if (!dir.empty()) + { + mOptions.configDir = mRootDir + dir; + logger->log("Portable config dir: %s", + mOptions.configDir.c_str()); + } + } + + if (mOptions.screenshotDir.empty()) + { + dir = portable.getValue("screenshotDir", ""); + if (!dir.empty()) + { + mOptions.screenshotDir = mRootDir + dir; + logger->log("Portable screenshot dir: %s", + mOptions.screenshotDir.c_str()); + } + } + } +#endif +} + /** * Initializes the home directory. On UNIX and FreeBSD, ~/.mana is used. On * Windows and other systems we use the current working directory. @@ -1062,7 +1115,8 @@ void Client::initHomeDir() { std::string oldConfigFile = std::string(PHYSFS_getUserDir()) + "/.tmw/config.xml"; - if (!stat(oldConfigFile.c_str(), &statbuf) && S_ISREG(statbuf.st_mode)) + if (mRootDir.empty() && !stat(oldConfigFile.c_str(), &statbuf) + && S_ISREG(statbuf.st_mode)) { std::ifstream oldConfig; std::ofstream newConfig; @@ -1220,8 +1274,10 @@ void Client::initUpdatesDir() void Client::initScreenshotDir() { if (!mOptions.screenshotDir.empty()) + { mScreenshotDir = mOptions.screenshotDir; - else + } + else if (mScreenshotDir.empty()) { #ifdef WIN32 mScreenshotDir = getSpecialFolderLocation(CSIDL_MYPICTURES); diff --git a/src/client.h b/src/client.h index 3c52ea37..f44d8bf2 100644 --- a/src/client.h +++ b/src/client.h @@ -182,6 +182,7 @@ public: void action(const gcn::ActionEvent &event); private: + void initRootDir(); void initHomeDir(); void initConfiguration(); void initUpdatesDir(); @@ -199,6 +200,7 @@ private: std::string mUpdateHost; std::string mUpdatesDir; std::string mScreenshotDir; + std::string mRootDir; ServerInfo mCurrentServer; -- cgit v1.2.3-70-g09d2 From a9bcae9f81d97f67ab21cd26a099449cf0746137 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 19 Oct 2010 01:52:47 +0300 Subject: Fix crash in drawing incorrect strings. Reviewed-by: cody --- src/gui/truetypefont.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'src') diff --git a/src/gui/truetypefont.cpp b/src/gui/truetypefont.cpp index e2ae5b93..ebc01ec7 100644 --- a/src/gui/truetypefont.cpp +++ b/src/gui/truetypefont.cpp @@ -64,8 +64,8 @@ class TextChunk if (!surface) { - throw "Rendering font to surface failed: " + - std::string(TTF_GetError()); + img = 0; + return; } img = Image::load(surface); @@ -108,9 +108,7 @@ TrueTypeFont::~TrueTypeFont() --fontCounter; if (fontCounter == 0) - { TTF_Quit(); - } } void TrueTypeFont::drawString(gcn::Graphics *graphics, @@ -123,9 +121,7 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, Graphics *g = dynamic_cast(graphics); if (!g) - { throw "Not a valid graphics object!"; - } gcn::Color col = g->getColor(); const float alpha = col.a / 255.0f; @@ -154,15 +150,16 @@ void TrueTypeFont::drawString(gcn::Graphics *graphics, if (!found) { if (mCache.size() >= CACHE_SIZE) - { mCache.pop_back(); - } mCache.push_front(chunk); mCache.front().generate(mFont); } - mCache.front().img->setAlpha(alpha); - g->drawImage(mCache.front().img, x, y); + if (mCache.front().img) + { + mCache.front().img->setAlpha(alpha); + g->drawImage(mCache.front().img, x, y); + } } int TrueTypeFont::getWidth(const std::string &text) const @@ -174,7 +171,10 @@ int TrueTypeFont::getWidth(const std::string &text) const // Raise priority: move it to front // Assumption is that TTF::draw will be called next mCache.splice(mCache.begin(), mCache, i); - return i->img->getWidth(); + if (i->img) + return i->img->getWidth(); + else + return 0; } } -- cgit v1.2.3-70-g09d2 From dbac793645654ac6715e6adecfd9d4a4a1fd8551 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 22 Oct 2010 12:52:35 +0200 Subject: Turned the OpenGL and disable transparency options as static members. - Now OpenGL and the transparency disabling are set at startup and not read again for displaying graphics, preventing graphic errors before startup. - We also agreed long time ago that SDL specific functions should have a SDL prefix. The header has been rearranged a bit to do so. - Also fixed a possible discrepancy in the hasAlphaChannel() function. Reviewed-by: CodyMartin. Resolves: Mana-Mantis: #260. --- src/client.cpp | 9 +++++-- src/gui/widgets/desktop.cpp | 4 +-- src/map.cpp | 2 +- src/resources/ambientlayer.cpp | 4 +-- src/resources/ambientoverlay.cpp | 4 +-- src/resources/image.cpp | 35 ++++++++++++++------------ src/resources/image.h | 54 ++++++++++++++++++++++++---------------- 7 files changed, 66 insertions(+), 46 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 2681a254..3ed3fb34 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -253,7 +253,7 @@ Client::Client(const Options &options): "Exiting.", mLocalDataDir.c_str())); } - Image::setEnableAlphaCache(config.getValue("alphaCache", true)); + Image::SDLsetEnableAlphaCache(config.getValue("alphaCache", true)); #if defined __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); @@ -317,9 +317,14 @@ Client::Client(const Options &options): } #endif -#ifdef USE_OPENGL bool useOpenGL = !mOptions.noOpenGL && (config.getValue("opengl", 0) == 1); + // Set up the transparency option for low CPU when not using OpenGL. + if (!useOpenGL && (config.getValue("lowcpu", 0) == 1)) + Image::SDLdisableTransparency(); + +#ifdef USE_OPENGL + // Setup image loading for the right image format Image::setLoadAsOpenGL(useOpenGL); diff --git a/src/gui/widgets/desktop.cpp b/src/gui/widgets/desktop.cpp index 2a80cc11..23dd3eb5 100644 --- a/src/gui/widgets/desktop.cpp +++ b/src/gui/widgets/desktop.cpp @@ -85,7 +85,7 @@ void Desktop::draw(gcn::Graphics *graphics) if (mWallpaper) { - if (!mWallpaper->isAnOpenGLOne()) + if (!mWallpaper->useOpenGL()) g->drawImage(mWallpaper, (getWidth() - mWallpaper->getWidth()) / 2, (getHeight() - mWallpaper->getHeight()) / 2); @@ -114,7 +114,7 @@ void Desktop::setBestFittingWallpaper() if (mWallpaper) mWallpaper->decRef(); - if (!nWallPaper->isAnOpenGLOne() && (nWallPaper->getWidth() != getWidth() + if (!nWallPaper->useOpenGL() && (nWallPaper->getWidth() != getWidth() || nWallPaper->getHeight() != getHeight())) { // We rescale to obtain a fullscreen wallpaper... diff --git a/src/map.cpp b/src/map.cpp index 2de0a4a8..f845f2ff 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -331,7 +331,7 @@ void Map::draw(Graphics *graphics, int scrollX, int scrollY) } // If the transparency hasn't been disabled, - if (config.getValue("opengl", false) || !config.getValue("lowcpu", true)) + if (Image::useOpenGL() || !Image::SDLisTransparencyDisabled()) { // We draw beings with a lower opacity to make them visible // even when covered by a wall or some other elements... diff --git a/src/resources/ambientlayer.cpp b/src/resources/ambientlayer.cpp index 50fe8bd9..b662ddeb 100644 --- a/src/resources/ambientlayer.cpp +++ b/src/resources/ambientlayer.cpp @@ -33,7 +33,7 @@ AmbientLayer::AmbientLayer(Image *img, float parallax, mKeepRatio(keepRatio) { - if (keepRatio && !mImage->isAnOpenGLOne() + if (keepRatio && !mImage->useOpenGL() && defaultScreenWidth != 0 && defaultScreenHeight != 0 && graphics->getWidth() != defaultScreenWidth @@ -92,7 +92,7 @@ void AmbientLayer::update(int timePassed, float dx, float dy) void AmbientLayer::draw(Graphics *graphics, int x, int y) { - if (!mImage->isAnOpenGLOne() || !mKeepRatio) + if (!mImage->useOpenGL() || !mKeepRatio) graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); else diff --git a/src/resources/ambientoverlay.cpp b/src/resources/ambientoverlay.cpp index 64a46676..aba12f84 100644 --- a/src/resources/ambientoverlay.cpp +++ b/src/resources/ambientoverlay.cpp @@ -34,7 +34,7 @@ AmbientOverlay::AmbientOverlay(Image *img, float parallax, mKeepRatio(keepRatio) { - if (keepRatio && !mImage->isAnOpenGLOne() + if (keepRatio && !mImage->useOpenGL() && defaultScreenWidth != 0 && defaultScreenHeight != 0 && graphics->getWidth() != defaultScreenWidth @@ -92,7 +92,7 @@ void AmbientOverlay::update(int timePassed, float dx, float dy) void AmbientOverlay::draw(Graphics *graphics, int x, int y) { - if (!mImage->isAnOpenGLOne() || !mKeepRatio) + if (!mImage->useOpenGL() || !mKeepRatio) graphics->drawImagePattern(mImage, (int) -mPosX, (int) -mPosY, x + (int) mPosX, y + (int) mPosY); else diff --git a/src/resources/image.cpp b/src/resources/image.cpp index 42a6ab56..63f1bd2c 100644 --- a/src/resources/image.cpp +++ b/src/resources/image.cpp @@ -41,11 +41,14 @@ int Image::mTextureSize = 0; #endif bool Image::mEnableAlphaCache = false; +// The low CPU mode is disabled per default +bool Image::mDisableTransparency = false; + Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): mAlpha(1.0f), - mHasAlphaChannel(hasAlphaChannel), mSDLSurface(image), - mAlphaChannel(alphaChannel) + mAlphaChannel(alphaChannel), + mHasAlphaChannel(hasAlphaChannel) { #ifdef USE_OPENGL mGLImage = 0; @@ -73,9 +76,9 @@ Image::Image(SDL_Surface *image, bool hasAlphaChannel, Uint8 *alphaChannel): #ifdef USE_OPENGL Image::Image(GLuint glimage, int width, int height, int texWidth, int texHeight): mAlpha(1.0f), - mHasAlphaChannel(true), mSDLSurface(0), mAlphaChannel(0), + mHasAlphaChannel(true), mUseAlphaCache(false), mGLImage(glimage), mTexWidth(texWidth), @@ -172,7 +175,7 @@ Image *Image::load(SDL_Surface *tmpImage) return _SDLload(tmpImage); } -void Image::cleanCache() +void Image::SDLcleanCache() { ResourceManager *resman = ResourceManager::getInstance(); @@ -193,7 +196,7 @@ void Image::unload() if (mSDLSurface) { - cleanCache(); + SDLcleanCache(); // Free the image surface. SDL_FreeSurface(mSDLSurface); mSDLSurface = NULL; @@ -211,7 +214,7 @@ void Image::unload() #endif } -bool Image::isAnOpenGLOne() const +bool Image::useOpenGL() { #ifdef USE_OPENGL return mUseOpenGL; @@ -222,15 +225,15 @@ bool Image::isAnOpenGLOne() const bool Image::hasAlphaChannel() { - if (mLoaded) - return mHasAlphaChannel; + if (!mLoaded) + return false; #ifdef USE_OPENGL if (mUseOpenGL) return true; #endif - return false; + return mHasAlphaChannel; } SDL_Surface *Image::getByAlpha(float alpha) @@ -243,7 +246,7 @@ SDL_Surface *Image::getByAlpha(float alpha) void Image::setAlpha(float alpha) { - if (config.getValue("lowcpu", true) == true) + if (!useOpenGL() && mDisableTransparency) return; if (mAlpha == alpha) @@ -260,7 +263,7 @@ void Image::setAlpha(float alpha) if (!surface) { if (mAlphaCache.size() > 100) - cleanCache(); + SDLcleanCache(); mAlphaCache[mAlpha] = mSDLSurface; } @@ -274,7 +277,7 @@ void Image::setAlpha(float alpha) } else { - mSDLSurface = Image::duplicateSurface(mSDLSurface); + mSDLSurface = Image::SDLduplicateSurface(mSDLSurface); } } @@ -432,7 +435,7 @@ Image* Image::SDLgetScaledImage(int width, int height) return scaledImage; } -SDL_Surface* Image::duplicateSurface(SDL_Surface* tmpImage) +SDL_Surface* Image::SDLduplicateSurface(SDL_Surface* tmpImage) { if (!tmpImage || !tmpImage->format) return NULL; @@ -629,9 +632,9 @@ Image *Image::getSubImage(int x, int y, int width, int height) return new SubImage(this, mSDLSurface, x, y, width, height); } -void Image::terminateAlphaCache() +void Image::SDLterminateAlphaCache() { - cleanCache(); + SDLcleanCache(); mUseAlphaCache = false; } @@ -647,7 +650,7 @@ SubImage::SubImage(Image *parent, SDL_Surface *image, if (mParent) { mParent->incRef(); - mParent->terminateAlphaCache(); + mParent->SDLterminateAlphaCache(); mHasAlphaChannel = mParent->hasAlphaChannel(); mAlphaChannel = mParent->SDLgetAlphaChannel(); } diff --git a/src/resources/image.h b/src/resources/image.h index 815b7764..1db52ca0 100644 --- a/src/resources/image.h +++ b/src/resources/image.h @@ -113,16 +113,10 @@ class Image : public Resource { return mBounds.h; } /** - * Tells if the image was loaded using OpenGL or SDL + * Tells if the system is using OpenGL or SDL * @return true if OpenGL, false if SDL. */ - bool isAnOpenGLOne() const; - - /** - * Tells if the image has got an alpha channel - * @return true if it's true, false otherwise. - */ - bool hasAlphaChannel(); + static bool useOpenGL(); /** * Sets the alpha value of this image. @@ -143,9 +137,23 @@ class Image : public Resource */ virtual Image *getSubImage(int x, int y, int width, int height); + /** + * Tells if the image has got an alpha channel + * @return true if it's true, false otherwise. + */ + bool hasAlphaChannel(); // SDL only public functions + /** + * Disable the transparency handling (for low CPUs in SDL Mode) + */ + static void SDLdisableTransparency() + { mDisableTransparency = true; } + + static bool SDLisTransparencyDisabled() + { return mDisableTransparency; } + /** * Gets an scaled instance of an image. * @@ -171,13 +179,13 @@ class Image : public Resource Uint8 *SDLgetAlphaChannel() const { return mAlphaChannel; } - SDL_Surface* duplicateSurface(SDL_Surface* tmpImage); + SDL_Surface* SDLduplicateSurface(SDL_Surface* tmpImage); - void cleanCache(); + void SDLcleanCache(); - void terminateAlphaCache(); + void SDLterminateAlphaCache(); - static void setEnableAlphaCache(bool n) + static void SDLsetEnableAlphaCache(bool n) { mEnableAlphaCache = n; } #ifdef USE_OPENGL @@ -199,18 +207,17 @@ class Image : public Resource protected: - // ----------------------- - // Generic protected members - // ----------------------- + // ----------------------- + // Generic protected members + // ----------------------- SDL_Rect mBounds; bool mLoaded; float mAlpha; - bool mHasAlphaChannel; - // ----------------------- - // SDL protected members - // ----------------------- + // ----------------------- + // SDL protected members + // ----------------------- /** SDL Constructor */ Image(SDL_Surface *image, bool hasAlphaChannel = false, @@ -225,13 +232,18 @@ class Image : public Resource /** Alpha Channel pointer used for 32bit based SDL surfaces */ Uint8 *mAlphaChannel; + bool mHasAlphaChannel; + /** Alpha cache: The cache stores a copy of the image + for specific requested opacities, hence, increasing + the image disply speed */ std::map mAlphaCache; - bool mUseAlphaCache; - static bool mEnableAlphaCache; + /** Stores whether the transparency is disabled */ + static bool mDisableTransparency; + // ----------------------- // OpenGL protected members // ----------------------- -- cgit v1.2.3-70-g09d2 From b10fdfddb20f66d2b0c572d91b6b6ec54ae02802 Mon Sep 17 00:00:00 2001 From: Yohann Ferreira Date: Fri, 22 Oct 2010 14:01:34 +0200 Subject: Changed 'Low CPU' options and related gui widgets name to 'Disable transparency'. That name is more explicit about what it actually does. Reviewed-by: CodyMartin. --- src/client.cpp | 4 ++-- src/gui/setup_video.cpp | 60 ++++++++++++++++++++++++++----------------------- src/gui/setup_video.h | 4 ++-- 3 files changed, 36 insertions(+), 32 deletions(-) (limited to 'src') diff --git a/src/client.cpp b/src/client.cpp index 3ed3fb34..110420d5 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -320,7 +320,7 @@ Client::Client(const Options &options): bool useOpenGL = !mOptions.noOpenGL && (config.getValue("opengl", 0) == 1); // Set up the transparency option for low CPU when not using OpenGL. - if (!useOpenGL && (config.getValue("lowcpu", 0) == 1)) + if (!useOpenGL && (config.getValue("disableTransparency", 0) == 1)) Image::SDLdisableTransparency(); #ifdef USE_OPENGL @@ -1166,7 +1166,7 @@ void Client::initConfiguration() config.setValue("customcursor", true); config.setValue("useScreenshotDirectorySuffix", true); config.setValue("ChatLogLength", 128); - config.setValue("lowcpu", true); + config.setValue("disableTransparency", false); // Checking if the configuration file exists... otherwise create it with // default options. diff --git a/src/gui/setup_video.cpp b/src/gui/setup_video.cpp index fd7022c0..1a5e17b6 100644 --- a/src/gui/setup_video.cpp +++ b/src/gui/setup_video.cpp @@ -211,7 +211,7 @@ Setup_Video::Setup_Video(): mPickupParticleEnabled(config.getValue("showpickupparticle", false)), mOpacity(config.getValue("guialpha", 0.8)), mFps((int) config.getValue("fpslimit", 60)), - mLowCPUEnabled(config.getValue("lowcpu", true)), + mSDLTransparencyDisabled(config.getValue("disableTransparency", true)), mSpeechMode(static_cast( config.getValue("speech", Being::TEXT_OVERHEAD))), mModeListModel(new ModeListModel), @@ -245,8 +245,9 @@ Setup_Video::Setup_Video(): mParticleDetailSlider(new Slider(0, 3)), mParticleDetailField(new Label), mFontSize((int) config.getValue("fontSize", 11)), - mLowCPUCheckBox(new CheckBox(_("Disable transparency (Low CPU mode)"), - mLowCPUEnabled)) + mDisableSDLTransparencyCheckBox( + new CheckBox(_("Disable transparency (Low CPU mode)"), + mSDLTransparencyDisabled)) { setName(_("Video")); @@ -273,7 +274,7 @@ Setup_Video::Setup_Video(): mAlphaSlider->setValue(mOpacity); mAlphaSlider->setWidth(90); - mAlphaSlider->setEnabled(!mLowCPUEnabled); + mAlphaSlider->setEnabled(!mSDLTransparencyDisabled); mFpsLabel->setCaption(mFps > 0 ? toString(mFps) : _("None")); mFpsLabel->setWidth(60); @@ -282,8 +283,8 @@ Setup_Video::Setup_Video(): mFpsCheckBox->setSelected(mFps > 0); // If the openGL Mode is enabled, disabling the transaprency - // is irrelelvant. - mLowCPUCheckBox->setEnabled(!mOpenGLEnabled); + // is irrelevant. + mDisableSDLTransparencyCheckBox->setEnabled(!mOpenGLEnabled); // Pre-select the current video mode. std::string videoMode = toString(graphics->getWidth()) + "x" @@ -308,7 +309,7 @@ Setup_Video::Setup_Video(): mOpenGLCheckBox->setActionEventId("opengl"); mParticleDetailSlider->setActionEventId("particledetailslider"); mParticleDetailField->setActionEventId("particledetailfield"); - mLowCPUCheckBox->setActionEventId("lowcpu"); + mDisableSDLTransparencyCheckBox->setActionEventId("disableTransparency"); mModeList->addActionListener(this); mCustomCursorCheckBox->addActionListener(this); @@ -328,7 +329,7 @@ Setup_Video::Setup_Video(): mOverlayDetailField->addKeyListener(this); mParticleDetailSlider->addActionListener(this); mParticleDetailField->addKeyListener(this); - mLowCPUCheckBox->addActionListener(this); + mDisableSDLTransparencyCheckBox->addActionListener(this); mSpeechLabel->setCaption(speechModeToString(mSpeechMode)); mSpeechSlider->setValue(mSpeechMode); @@ -386,7 +387,7 @@ Setup_Video::Setup_Video(): place(1, 11, particleDetailLabel); place(2, 11, mParticleDetailField, 3).setPadding(2); - place(0, 12, mLowCPUCheckBox, 4); + place(0, 12, mDisableSDLTransparencyCheckBox, 4); setDimension(gcn::Rectangle(0, 0, 365, 300)); } @@ -469,23 +470,24 @@ void Setup_Video::apply() } } // If LowCPU is enabled from a disabled state we warn the user - else if (mLowCPUCheckBox->isSelected()) + else if (mDisableSDLTransparencyCheckBox->isSelected()) { - if (config.getValue("lowcpu", true) == false) + if (config.getValue("disableTransparency", true) == false) { - new OkDialog(_("Low CPU Mode Enabled"), - _("You must restart to prevent graphical errors.")); + new OkDialog(_("Transparency disabled"), + _("You must restart to apply changes.")); } } else { - if (config.getValue("lowcpu", true) == true) + if (config.getValue("disableTransparency", true) == true) { - new OkDialog(_("Low CPU Mode Disabled"), + new OkDialog(_("Transparency enabled"), _("You must restart to apply changes.")); } } - config.setValue("lowcpu", mLowCPUCheckBox->isSelected()); + config.setValue("disableTransparency", + mDisableSDLTransparencyCheckBox->isSelected()); mFps = mFpsCheckBox->isSelected() ? (int) mFpsSlider->getValue() : 0; mFpsSlider->setEnabled(mFps > 0); @@ -509,7 +511,7 @@ void Setup_Video::apply() mOpenGLEnabled = config.getValue("opengl", false); mPickupChatEnabled = config.getValue("showpickupchat", true); mPickupParticleEnabled = config.getValue("showpickupparticle", false); - mLowCPUEnabled = config.getValue("lowcpu", true); + mSDLTransparencyDisabled = config.getValue("disableTransparency", true); } void Setup_Video::cancel() @@ -527,13 +529,13 @@ void Setup_Video::cancel() mNameCheckBox->setSelected(mNameEnabled); mNPCLogCheckBox->setSelected(mNPCLogEnabled); mAlphaSlider->setValue(mOpacity); - mAlphaSlider->setEnabled(!mLowCPUEnabled); + mAlphaSlider->setEnabled(!mSDLTransparencyDisabled); mOverlayDetailSlider->setValue(mOverlayDetail); mParticleDetailSlider->setValue(mParticleDetail); std::string text = mFpsCheckBox->isSelected() ? toString(mFps) : _("None"); mFpsLabel->setCaption(text); - mLowCPUCheckBox->setSelected(mLowCPUEnabled); - mLowCPUCheckBox->setEnabled(!mOpenGLEnabled); + mDisableSDLTransparencyCheckBox->setSelected(mSDLTransparencyDisabled); + mDisableSDLTransparencyCheckBox->setEnabled(!mOpenGLEnabled); config.setValue("screen", mFullScreenEnabled); @@ -557,7 +559,7 @@ void Setup_Video::cancel() config.setValue("opengl", mOpenGLEnabled); config.setValue("showpickupchat", mPickupChatEnabled); config.setValue("showpickupparticle", mPickupParticleEnabled); - config.setValue("lowcpu", mLowCPUEnabled); + config.setValue("disableTransparency", mSDLTransparencyDisabled); } void Setup_Video::action(const gcn::ActionEvent &event) @@ -666,21 +668,23 @@ void Setup_Video::action(const gcn::ActionEvent &event) mFpsSlider->setValue(mFps); mFpsSlider->setEnabled(mFps > 0); } - else if (id == "opengl" || id == "lowcpu") + else if (id == "opengl" || id == "disableTransparency") { - // Disable low cpu mode when in OpenGL. + // Disable transparency disabling when in OpenGL. if (mOpenGLCheckBox->isSelected()) { - mLowCPUCheckBox->setSelected(false); - mLowCPUCheckBox->setEnabled(false); + mDisableSDLTransparencyCheckBox->setSelected(false); + mDisableSDLTransparencyCheckBox->setEnabled(false); } else { - mLowCPUCheckBox->setEnabled(true); + mDisableSDLTransparencyCheckBox->setEnabled(true); } + // Disable gui opacity slider when disabling transparency. - if (mLowCPUCheckBox->isEnabled()) - mAlphaSlider->setEnabled(!mLowCPUCheckBox->isSelected()); + if (mDisableSDLTransparencyCheckBox->isEnabled()) + mAlphaSlider->setEnabled( + !mDisableSDLTransparencyCheckBox->isSelected()); else mAlphaSlider->setEnabled(true); } diff --git a/src/gui/setup_video.h b/src/gui/setup_video.h index 0f8a1e70..d0e2c492 100644 --- a/src/gui/setup_video.h +++ b/src/gui/setup_video.h @@ -62,7 +62,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, bool mPickupParticleEnabled; double mOpacity; int mFps; - bool mLowCPUEnabled; + bool mSDLTransparencyDisabled; Being::Speech mSpeechMode; ModeListModel *mModeListModel; @@ -108,7 +108,7 @@ class Setup_Video : public SetupTab, public gcn::ActionListener, int mFontSize; gcn::DropDown *mFontSizeDropDown; - gcn::CheckBox *mLowCPUCheckBox; + gcn::CheckBox *mDisableSDLTransparencyCheckBox; }; #endif -- cgit v1.2.3-70-g09d2 From 1f69108501c4bf51f3adac9ffbf7a7631fb12b9a Mon Sep 17 00:00:00 2001 From: Stefan Dombrowski Date: Sun, 31 Oct 2010 12:11:54 +0100 Subject: Using tile coordinates for pick-up Since the tile coordinates are already avaible the calculation is not needed. Furthermore this avoids the correction of the tile, which was needed because the pixel coordinates are meant as coordinates for drawing the being. This resolves http://bugs.manasource.org/view.php?id=249 Reviewed-by: Thorbjorn --- src/game.cpp | 9 ++------- src/localplayer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/game.cpp b/src/game.cpp index 270affb5..77544058 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -607,13 +607,8 @@ void Game::handleInput() { case KeyboardConfig::KEY_PICKUP: { - const Vector &pos = player_node->getPosition(); - Map *map = viewport->getCurrentMap(); - Uint16 x = (int) pos.x / map->getTileWidth(); - Uint16 y = (int) (pos.y - 1) - / map->getTileHeight(); - // y - 1 needed to fix position, otherwise, it's - // off under eAthena. + int x = player_node->getTileX(); + int y = player_node->getTileY(); FloorItem *item = floorItemManager->findByCoordinates(x, y); diff --git a/src/localplayer.cpp b/src/localplayer.cpp index 5f5f44ae..7826596c 100644 --- a/src/localplayer.cpp +++ b/src/localplayer.cpp @@ -707,8 +707,8 @@ void LocalPlayer::setInvItem(int index, int id, int amount) void LocalPlayer::pickUp(FloorItem *item) { - int dx = item->getX() - (int) getPosition().x / mMap->getTileWidth(); - int dy = item->getY() - ((int) getPosition().y - 1) / mMap->getTileHeight(); + int dx = item->getX() - getTileX(); + int dy = item->getY() - getTileY(); if (dx * dx + dy * dy < 4) { -- cgit v1.2.3-70-g09d2