summaryrefslogtreecommitdiff
path: root/src/gui
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2013-08-01 12:43:06 +0300
committerAndrei Karas <akaras@inbox.ru>2013-08-01 13:37:39 +0300
commit1c87a896376d62131d9df1fee1bd7cec79e21aa6 (patch)
tree9852dd6458abc9eba4448120793b437ecf38a3e6 /src/gui
parentb1555ac1dae6f0e0aaa88ca7dd1431de87a8e811 (diff)
downloadmanaverse-1c87a896376d62131d9df1fee1bd7cec79e21aa6.tar.gz
manaverse-1c87a896376d62131d9df1fee1bd7cec79e21aa6.tar.bz2
manaverse-1c87a896376d62131d9df1fee1bd7cec79e21aa6.tar.xz
manaverse-1c87a896376d62131d9df1fee1bd7cec79e21aa6.zip
add gui for in chat emotes.
For add in chat emote press F1 inside opened chat, then select and click emote.
Diffstat (limited to 'src/gui')
-rw-r--r--src/gui/chatwindow.cpp20
-rw-r--r--src/gui/chatwindow.h1
-rw-r--r--src/gui/emotewindow.cpp106
-rw-r--r--src/gui/emotewindow.h59
-rw-r--r--src/gui/widgets/emotepage.cpp106
-rw-r--r--src/gui/widgets/emotepage.h58
6 files changed, 350 insertions, 0 deletions
diff --git a/src/gui/chatwindow.cpp b/src/gui/chatwindow.cpp
index fe6194b23..521877ca3 100644
--- a/src/gui/chatwindow.cpp
+++ b/src/gui/chatwindow.cpp
@@ -37,6 +37,7 @@
#include "spellshortcut.h"
#include "soundmanager.h"
+#include "gui/emotewindow.h"
#include "gui/gui.h"
#include "gui/setup.h"
#include "gui/sdlfont.h"
@@ -251,6 +252,9 @@ ChatWindow::ChatWindow():
setTitleBarHeight(getPadding() + getTitlePadding());
+ if (emoteWindow)
+ emoteWindow->addListeners(this);
+
mChatTabs->enableScrollButtons(true);
mChatTabs->setFollowDownScroll(true);
mChatTabs->setResizeHeight(false);
@@ -481,6 +485,18 @@ void ChatWindow::action(const gcn::ActionEvent &event)
setVisible(false);
}
}
+ else if (eventId == "emote")
+ {
+ if (emoteWindow)
+ {
+ const std::string str = emoteWindow->getSelectedEmote();
+ if (!str.empty())
+ {
+ addInputText(str, false);
+ emoteWindow->clearEmote();
+ }
+ }
+ }
else if (eventId == ACTION_COLOR_PICKER)
{
if (mColorPicker)
@@ -849,6 +865,10 @@ void ChatWindow::keyPressed(gcn::KeyEvent &event)
std::string temp;
switch (key)
{
+ case Key::F1:
+ if (emoteWindow)
+ emoteWindow->show();
+ break;
caseKey(Key::F2, "\u2318");
caseKey(Key::F3, "\u263A");
caseKey(Key::F4, "\u2665");
diff --git a/src/gui/chatwindow.h b/src/gui/chatwindow.h
index 85856776a..67f87be1a 100644
--- a/src/gui/chatwindow.h
+++ b/src/gui/chatwindow.h
@@ -46,6 +46,7 @@ class Channel;
class ChatInput;
class ColorListModel;
class DropDown;
+class EmoteWindow;
class ScrollArea;
class TabbedArea;
class ItemLinkHandler;
diff --git a/src/gui/emotewindow.cpp b/src/gui/emotewindow.cpp
new file mode 100644
index 000000000..a66cecf87
--- /dev/null
+++ b/src/gui/emotewindow.cpp
@@ -0,0 +1,106 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/emotewindow.h"
+
+#include "gui/chatwindow.h"
+#include "gui/gui.h"
+
+#include "gui/widgets/emotepage.h"
+#include "gui/widgets/layouthelper.h"
+#include "gui/widgets/scrollarea.h"
+#include "gui/widgets/tabbedarea.h"
+
+#include "units.h"
+
+#include "utils/gettext.h"
+
+#include <guichan/font.hpp>
+
+#include "debug.h"
+
+EmoteWindow::EmoteWindow() :
+ // TRANSLATORS: emotes window name
+ Window(_("Emotes"), false, nullptr, "emotes.xml"),
+ mTabs(new TabbedArea(this)),
+ mEmotePage(new EmotePage(this)),
+ mScrollEmotePage(new ScrollArea(mEmotePage, false, "emotepage.xml"))
+{
+ setShowTitle(false);
+
+ addMouseListener(this);
+ const int pad2 = mPadding * 2;
+ const int sz = 150;
+ setWidth(sz + pad2);
+ setHeight(sz + pad2);
+ add(mTabs);
+ mTabs->setPosition(mPadding, mPadding);
+ mTabs->setWidth(sz);
+ mTabs->setHeight(sz);
+ center();
+
+ setTitleBarHeight(getPadding() + getTitlePadding());
+ // TRANSLATORS: emotes tab name
+ mTabs->addTab(_("Emotes"), mEmotePage);
+
+ mEmotePage->setActionEventId("emote");
+}
+
+EmoteWindow::~EmoteWindow()
+{
+ mTabs->removeTab(mTabs->getTabByIndex(0));
+ delete mScrollEmotePage;
+ mScrollEmotePage = nullptr;
+}
+
+void EmoteWindow::show()
+{
+ setVisible(true);
+}
+
+void EmoteWindow::hide()
+{
+ setVisible(false);
+}
+
+std::string EmoteWindow::getSelectedEmote() const
+{
+ const int index = mEmotePage->getSelectedIndex();
+ if (index < 0)
+ return std::string();
+
+ char chr[2];
+ chr[0] = '0' + index;
+ chr[1] = 0;
+ return std::string("%%").append(&chr[0]);
+}
+
+void EmoteWindow::clearEmote()
+{
+ const int index = mEmotePage->getSelectedIndex();
+ mEmotePage->resetAction();
+ if (index >= 0)
+ setVisible(false);
+}
+
+void EmoteWindow::addListeners(gcn::ActionListener *const listener)
+{
+ mEmotePage->addActionListener(listener);
+}
diff --git a/src/gui/emotewindow.h b/src/gui/emotewindow.h
new file mode 100644
index 000000000..69a646bd8
--- /dev/null
+++ b/src/gui/emotewindow.h
@@ -0,0 +1,59 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_EMOTEWINDOW_H
+#define GUI_EMOTEWINDOW_H
+
+#include "gui/widgets/window.h"
+
+#include <guichan/mouselistener.hpp>
+
+class EmotePage;
+class ScrollArea;
+class TabbedArea;
+
+class EmoteWindow final : public Window
+{
+ public:
+ EmoteWindow();
+
+ A_DELETE_COPY(EmoteWindow)
+
+ ~EmoteWindow();
+
+ void show();
+
+ void hide();
+
+ std::string getSelectedEmote() const;
+
+ void clearEmote();
+
+ void addListeners(gcn::ActionListener *const listener);
+
+ private:
+ TabbedArea *mTabs;
+ EmotePage *mEmotePage;
+ ScrollArea *mScrollEmotePage;
+};
+
+extern EmoteWindow *emoteWindow;
+
+#endif // GUI_EMOTEWINDOW_H
diff --git a/src/gui/widgets/emotepage.cpp b/src/gui/widgets/emotepage.cpp
new file mode 100644
index 000000000..8fd9a3cbb
--- /dev/null
+++ b/src/gui/widgets/emotepage.cpp
@@ -0,0 +1,106 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "gui/widgets/emotepage.h"
+
+#include "resources/imageset.h"
+#include "resources/resourcemanager.h"
+
+#include "debug.h"
+
+namespace
+{
+ static const unsigned int emoteWidth = 17;
+ static const unsigned int emoteHeight = 18;
+} // namespace
+
+EmotePage::EmotePage(const Widget2 *const widget) :
+ gcn::Widget(),
+ Widget2(widget),
+ mEmotes(ResourceManager::getInstance()->getImageSet(
+ "graphics/sprites/chatemotes.png", emoteWidth, emoteHeight)),
+ mSelectedIndex(-1)
+{
+ addMouseListener(this);
+}
+
+EmotePage::~EmotePage()
+{
+ if (mEmotes)
+ {
+ mEmotes->decRef();
+ mEmotes = nullptr;
+ }
+}
+
+void EmotePage::draw(gcn::Graphics *graphics)
+{
+ BLOCK_START("EmotePage::draw")
+
+ if (!mEmotes)
+ return;
+
+ const std::vector<Image*> &images = mEmotes->getImages();
+
+ Graphics *const g = static_cast<Graphics*>(graphics);
+ const unsigned int width = mDimension.width;
+ unsigned int x = 0;
+ unsigned int y = 0;
+
+ FOR_EACH(std::vector<Image*>::const_iterator, it, images)
+ {
+ const Image *const image = *it;
+ if (image)
+ {
+ g->drawImage(image, x, y);
+ x += emoteWidth;
+ if (x + emoteWidth > width)
+ {
+ x = 0;
+ y += emoteHeight;
+ }
+ }
+ }
+
+ BLOCK_END("EmotePage::draw")
+}
+
+void EmotePage::mousePressed(gcn::MouseEvent &mouseEvent)
+{
+ mSelectedIndex = getIndexFromGrid(mouseEvent.getX(), mouseEvent.getY());
+ distributeActionEvent();
+}
+
+int EmotePage::getIndexFromGrid(const int x, const int y) const
+{
+ const int width = mDimension.width;
+ if (x < 0 || x > width || y < 0 || y > mDimension.height)
+ return -1;
+ const int cols = width / emoteWidth;
+ const unsigned int index = (y / emoteHeight) * cols + (x / emoteWidth);
+ if (index >= mEmotes->size())
+ return -1;
+ return index;
+}
+
+void EmotePage::resetAction()
+{
+ mSelectedIndex = -1;
+}
diff --git a/src/gui/widgets/emotepage.h b/src/gui/widgets/emotepage.h
new file mode 100644
index 000000000..7fc399ead
--- /dev/null
+++ b/src/gui/widgets/emotepage.h
@@ -0,0 +1,58 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2013 The ManaPlus Developers
+ *
+ * This file is part of The ManaPlus Client.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef GUI_WIDGETS_EMOTEPAGE_H
+#define GUI_WIDGETS_EMOTEPAGE_H
+
+#include "gui/widgets/widget2.h"
+
+#include <guichan/mouselistener.hpp>
+#include <guichan/widget.hpp>
+
+#include "localconsts.h"
+
+class EmotePage final : public gcn::Widget,
+ public Widget2,
+ public gcn::MouseListener
+{
+ public:
+ EmotePage(const Widget2 *const widget);
+
+ A_DELETE_COPY(EmotePage)
+
+ ~EmotePage();
+
+ void draw(gcn::Graphics *graphics) override;
+
+ void mousePressed(gcn::MouseEvent &mouseEvent) override;
+
+ int getIndexFromGrid(const int x, const int y) const;
+
+ void resetAction();
+
+ int getSelectedIndex()
+ { return mSelectedIndex; }
+
+ private:
+ ImageSet *mEmotes;
+ int mSelectedIndex;
+};
+
+#endif // GUI_WIDGETS_EMOTEPAGE_H