summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-03-29 01:18:21 +0300
committerAndrei Karas <akaras@inbox.ru>2012-03-29 01:18:21 +0300
commitb0ce837b66ddc34a9b2a9346291b252f748c577f (patch)
tree6bcd1c475d48e2cb12972556a1f62eaf9c392048
parentf474ad785704a904fd2b95d56fa67cccf69c876f (diff)
downloadmanaplus-b0ce837b66ddc34a9b2a9346291b252f748c577f.tar.gz
manaplus-b0ce837b66ddc34a9b2a9346291b252f748c577f.tar.bz2
manaplus-b0ce837b66ddc34a9b2a9346291b252f748c577f.tar.xz
manaplus-b0ce837b66ddc34a9b2a9346291b252f748c577f.zip
Add option to auto hide chat window (chat window visible by default)
Option in chat \ Auto hide chat window.
-rw-r--r--src/defaults.cpp1
-rw-r--r--src/game.cpp1
-rw-r--r--src/gui/chatwindow.cpp65
-rw-r--r--src/gui/chatwindow.h21
-rw-r--r--src/gui/setup_chat.cpp6
-rw-r--r--src/gui/widgets/chattab.cpp8
6 files changed, 100 insertions, 2 deletions
diff --git a/src/defaults.cpp b/src/defaults.cpp
index 8b62f6d02..9451ff2ff 100644
--- a/src/defaults.cpp
+++ b/src/defaults.cpp
@@ -240,6 +240,7 @@ DefaultsData* getConfigDefaults()
AddDEF(configData, "soundrequest", "attention");
AddDEF(configData, "soundguild", "newmessage");
AddDEF(configData, "autohideButtons", true);
+ AddDEF(configData, "autohideChat", false);
return configData;
}
diff --git a/src/game.cpp b/src/game.cpp
index b17646730..e20b6c5df 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -191,6 +191,7 @@ static void createGuiWindows()
// Create dialogs
chatWindow = new ChatWindow;
+ chatWindow->updateVisibility();
tradeWindow = new TradeWindow;
equipmentWindow = new EquipmentWindow(PlayerInfo::getEquipment(),
player_node);
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index 674c34039..528c1e39e 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -94,6 +94,8 @@ class ChatInput : public TextField, public gcn::FocusListener
void focusLost(const gcn::Event &event A_UNUSED)
{
processVisible(false);
+ if (chatWindow)
+ chatWindow->updateVisibility();
}
void processVisible(bool n)
@@ -157,7 +159,9 @@ ChatWindow::ChatWindow():
Window(_("Chat"), false, nullptr, "chat.xml"),
mTmpVisible(false),
mChatHistoryIndex(0),
- mGMLoaded(false)
+ mGMLoaded(false),
+ mHaveMouse(false),
+ mAutoHide(false)
{
listen(CHANNEL_NOTICES);
listen(CHANNEL_ATTRIBUTES);
@@ -222,10 +226,14 @@ ChatWindow::ChatWindow():
initTradeFilter();
loadCustomList();
parseHighlights();
+
+ config.addListener("autohideChat", this);
+ mAutoHide = config.getBoolValue("autohideChat");
}
ChatWindow::~ChatWindow()
{
+ config.removeListener("autohideChat", this);
saveState();
config.setValue("ReturnToggles", mReturnToggles);
removeAllWhispers();
@@ -535,6 +543,7 @@ bool ChatWindow::requestChatFocus()
// Give focus to the chat input
mChatInput->processVisible(true);
+ unHideWindow();
mChatInput->requestFocus();
return true;
}
@@ -1607,3 +1616,57 @@ void ChatWindow::copyToClipboard(int x, int y)
std::string str = text->getTextAtPos(x, y);
sendBuffer(str);
}
+
+void ChatWindow::optionChanged(const std::string &name)
+{
+ if (name == "autohideChat")
+ mAutoHide = config.getBoolValue("autohideChat");
+}
+
+void ChatWindow::mouseMoved(gcn::MouseEvent &event)
+{
+ mHaveMouse = true;
+ gcn::Window::mouseMoved(event);
+}
+
+void ChatWindow::mouseEntered(gcn::MouseEvent& mouseEvent)
+{
+ mHaveMouse = true;
+ gcn::Window::mouseEntered(mouseEvent);
+}
+
+void ChatWindow::mouseExited(gcn::MouseEvent& mouseEvent)
+{
+ updateVisibility();
+ gcn::Window::mouseExited(mouseEvent);
+}
+
+void ChatWindow::draw(gcn::Graphics* graphics)
+{
+ if (!mAutoHide || mHaveMouse)
+ Window::draw(graphics);
+}
+
+void ChatWindow::updateVisibility()
+{
+ int mouseX = 0;
+ int mouseY = 0;
+ int x = 0;
+ int y = 0;
+ SDL_GetMouseState(&mouseX, &mouseY);
+ getAbsolutePosition(x, y);
+ if (mChatInput->isVisible())
+ {
+ mHaveMouse = true;
+ }
+ else
+ {
+ mHaveMouse = mouseX >= x && mouseX <= x + getWidth()
+ && mouseY >= y && mouseY <= y + getHeight();
+ }
+}
+
+void ChatWindow::unHideWindow()
+{
+ mHaveMouse = true;
+}
diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h
index aa56237a2..df452f9a7 100644
--- a/src/gui/chatwindow.h
+++ b/src/gui/chatwindow.h
@@ -25,6 +25,8 @@
#include "listener.h"
+#include "configlistener.h"
+
#include "gui/widgets/window.h"
#include <guichan/actionlistener.hpp>
@@ -80,7 +82,8 @@ struct CHATLOG
class ChatWindow : public Window,
public gcn::ActionListener,
public gcn::KeyListener,
- public Listener
+ public Listener,
+ public ConfigListener
{
public:
/**
@@ -262,6 +265,20 @@ class ChatWindow : public Window,
void copyToClipboard(int x, int y);
+ void optionChanged(const std::string &name);
+
+ void mouseEntered(gcn::MouseEvent& mouseEvent);
+
+ void mouseMoved(gcn::MouseEvent &event);
+
+ void mouseExited(gcn::MouseEvent& mouseEvent A_UNUSED);
+
+ void draw(gcn::Graphics* graphics);
+
+ void updateVisibility();
+
+ void unHideWindow();
+
protected:
friend class ChatTab;
friend class WhisperTab;
@@ -333,6 +350,8 @@ class ChatWindow : public Window,
std::list<std::string> mAwayLog;
std::vector<std::string> mHighlights;
bool mGMLoaded;
+ bool mHaveMouse;
+ bool mAutoHide;
};
extern ChatWindow *chatWindow;
diff --git a/src/gui/setup_chat.cpp b/src/gui/setup_chat.cpp
index 4bfb8928e..9cd164839 100644
--- a/src/gui/setup_chat.cpp
+++ b/src/gui/setup_chat.cpp
@@ -51,6 +51,12 @@ Setup_Chat::Setup_Chat()
ContainerPlacer place = h.getPlacer(0, 0);
place(0, 0, mScroll, 10, 10);
+ new SetupItemLabel(_("Window"), "", this);
+
+ new SetupItemCheckBox(_("Auto hide chat window."), "",
+ "autohideChat", this, "autohideChatEvent");
+
+
new SetupItemLabel(_("Colors"), "", this);
new SetupItemCheckBox(_("Remove colors from received chat messages"), "",
diff --git a/src/gui/widgets/chattab.cpp b/src/gui/widgets/chattab.cpp
index be6a31164..5f1b02d98 100644
--- a/src/gui/widgets/chattab.cpp
+++ b/src/gui/widgets/chattab.cpp
@@ -311,9 +311,17 @@ void ChatTab::chatLog(std::string line, Own own,
&& !Client::getInputFocused()))))
{
if (own == BY_GM)
+ {
+ if (chatWindow)
+ chatWindow->unHideWindow();
sound.playGuiSound(SOUND_GLOBAL);
+ }
else if (own != BY_SERVER)
+ {
+ if (chatWindow)
+ chatWindow->unHideWindow();
playNewMessageSound();
+ }
}
}
}