diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-08-01 12:43:06 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-08-01 13:37:39 +0300 |
commit | 1c87a896376d62131d9df1fee1bd7cec79e21aa6 (patch) | |
tree | 9852dd6458abc9eba4448120793b437ecf38a3e6 | |
parent | b1555ac1dae6f0e0aaa88ca7dd1431de87a8e811 (diff) | |
download | plus-1c87a896376d62131d9df1fee1bd7cec79e21aa6.tar.gz plus-1c87a896376d62131d9df1fee1bd7cec79e21aa6.tar.bz2 plus-1c87a896376d62131d9df1fee1bd7cec79e21aa6.tar.xz plus-1c87a896376d62131d9df1fee1bd7cec79e21aa6.zip |
add gui for in chat emotes.
For add in chat emote press F1 inside opened chat,
then select and click emote.
-rw-r--r-- | src/CMakeLists.txt | 4 | ||||
-rw-r--r-- | src/Makefile.am | 4 | ||||
-rw-r--r-- | src/game.cpp | 4 | ||||
-rw-r--r-- | src/gui/chatwindow.cpp | 20 | ||||
-rw-r--r-- | src/gui/chatwindow.h | 1 | ||||
-rw-r--r-- | src/gui/emotewindow.cpp | 106 | ||||
-rw-r--r-- | src/gui/emotewindow.h | 59 | ||||
-rw-r--r-- | src/gui/widgets/emotepage.cpp | 106 | ||||
-rw-r--r-- | src/gui/widgets/emotepage.h | 58 | ||||
-rw-r--r-- | src/resources/imageset.h | 3 |
10 files changed, 365 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b1935f3b1..238407ffb 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -156,6 +156,8 @@ SET(SRCS gui/widgets/itemlinkhandler.h gui/widgets/dropshortcutcontainer.cpp gui/widgets/dropshortcutcontainer.h + gui/widgets/emotepage.cpp + gui/widgets/emotepage.h gui/widgets/itemshortcutcontainer.cpp gui/widgets/itemshortcutcontainer.h gui/widgets/spellshortcutcontainer.cpp @@ -271,6 +273,8 @@ SET(SRCS gui/didyouknowwindow.h gui/editserverdialog.cpp gui/editserverdialog.h + gui/emotewindow.cpp + gui/emotewindow.h gui/equipmentwindow.cpp gui/equipmentwindow.h gui/focushandler.cpp diff --git a/src/Makefile.am b/src/Makefile.am index b97cdbcec..2875c2eda 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -157,6 +157,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/widgets/itemlinkhandler.h \ gui/widgets/dropshortcutcontainer.cpp \ gui/widgets/dropshortcutcontainer.h \ + gui/widgets/emotepage.cpp \ + gui/widgets/emotepage.h \ gui/widgets/itemshortcutcontainer.cpp \ gui/widgets/itemshortcutcontainer.h \ gui/widgets/spellshortcutcontainer.cpp \ @@ -270,6 +272,8 @@ manaplus_SOURCES += gui/widgets/avatarlistbox.cpp \ gui/didyouknowwindow.h \ gui/editserverdialog.cpp \ gui/editserverdialog.h \ + gui/emotewindow.cpp \ + gui/emotewindow.h \ gui/equipmentwindow.cpp \ gui/equipmentwindow.h \ gui/focushandler.cpp \ diff --git a/src/game.cpp b/src/game.cpp index 08544e8eb..8c7fbf868 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -46,6 +46,7 @@ #include "gui/botcheckerwindow.h" #include "gui/debugwindow.h" #include "gui/didyouknowwindow.h" +#include "gui/emotewindow.h" #include "gui/equipmentwindow.h" #include "gui/gui.h" #include "gui/helpwindow.h" @@ -116,6 +117,7 @@ QuitDialog *quitDialog = nullptr; Window *disconnectedDialog = nullptr; ChatWindow *chatWindow = nullptr; +EmoteWindow *emoteWindow = nullptr; StatusWindow *statusWindow = nullptr; MiniStatusWindow *miniStatusWindow = nullptr; InventoryWindow *inventoryWindow = nullptr; @@ -198,6 +200,7 @@ static void createGuiWindows() emoteShortcut->load(); // Create dialogs + emoteWindow = new EmoteWindow; chatWindow = new ChatWindow; chatWindow->updateVisibility(); tradeWindow = new TradeWindow; @@ -339,6 +342,7 @@ static void destroyGuiWindows() del_0(battleChatTab) del_0(gmChatTab); logger->log("start deleting"); + del_0(emoteWindow); del_0(chatWindow) logger->log("end deleting"); del_0(statusWindow) 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 diff --git a/src/resources/imageset.h b/src/resources/imageset.h index 140232af0..e8e4438b6 100644 --- a/src/resources/imageset.h +++ b/src/resources/imageset.h @@ -81,6 +81,9 @@ class ImageSet : public Resource void setOffsetY(const int n) { mOffsetY = n; } + const std::vector<Image*> &getImages() const + { return mImages; } + private: std::vector<Image*> mImages; |