1 /* 2 * The ManaPlus Client 3 * Copyright (C) 2009 Aethyra Development Team 4 * Copyright (C) 2011-2019 The ManaPlus Developers 5 * Copyright (C) 2019-2021 Andrei Karas 6 * 7 * This file is part of The ManaPlus Client. 8 * 9 * This program is free software; you can redistribute it and/or modify 10 * it under the terms of the GNU General Public License as published by 11 * the Free Software Foundation; either version 2 of the License, or 12 * any later version. 13 * 14 * This program is distributed in the hope that it will be useful, 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 * GNU General Public License for more details. 18 * 19 * You should have received a copy of the GNU General Public License 20 * along with this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef GUI_SHORTCUT_EMOTESHORTCUT_H 24 #define GUI_SHORTCUT_EMOTESHORTCUT_H 25 26 #include "const/emoteshortcut.h" 27 28 #include "utils/cast.h" 29 30 #include "localconsts.h" 31 32 /** 33 * The class which keeps track of the emote shortcuts. 34 */ 35 class EmoteShortcut final 36 { 37 public: 38 /** 39 * Constructor. 40 */ 41 EmoteShortcut(); 42 43 A_DELETE_COPY(EmoteShortcut) 44 45 /** 46 * Destructor. 47 */ 48 ~EmoteShortcut(); 49 50 /** 51 * Load the configuration information. 52 */ 53 void load(); 54 55 /** 56 * Returns the shortcut Emote ID specified by the index. 57 * 58 * @param index Index of the shortcut Emote. 59 */ getEmote(const size_t index)60 unsigned char getEmote(const size_t index) const A_WARN_UNUSED 61 { return mEmotes[index]; } 62 63 /** 64 * Returns the amount of shortcut Emotes. 65 */ getEmoteCount()66 static unsigned int getEmoteCount() A_WARN_UNUSED 67 { return SHORTCUT_EMOTES; } 68 69 /** 70 * Returns the emote ID that is currently selected. 71 */ getEmoteSelected()72 unsigned char getEmoteSelected() const noexcept2 A_WARN_UNUSED 73 { return mEmoteSelected; } 74 75 /** 76 * Adds the selected emote ID to the emotes specified by the index. 77 * 78 * @param index Index of the emotes. 79 */ setEmote(const size_t index)80 void setEmote(const size_t index) 81 { mEmotes[index] = mEmoteSelected; } 82 83 /** 84 * Adds a emoticon to the emotes store specified by the index. 85 * 86 * @param index Index of the emote. 87 * @param emoteId ID of the emote. 88 */ setEmotes(const size_t index,const unsigned char emoteId)89 void setEmotes(const size_t index, 90 const unsigned char emoteId) 91 { mEmotes[index] = emoteId; } 92 93 /** 94 * Set the Emote that is selected. 95 * 96 * @param emoteId The ID of the emote that is to be assigned. 97 */ setEmoteSelected(const unsigned char emoteId)98 void setEmoteSelected(const unsigned char emoteId) 99 { mEmoteSelected = emoteId; } 100 101 /** 102 * A flag to check if the Emote is selected. 103 */ isEmoteSelected()104 bool isEmoteSelected() const noexcept2 A_WARN_UNUSED 105 { return mEmoteSelected != 0U; } 106 107 /** 108 * Remove a Emote from the shortcut. 109 */ removeEmote(const size_t index)110 void removeEmote(const size_t index) 111 { if (index < CAST_SIZE(SHORTCUT_EMOTES)) mEmotes[index] = 0; } 112 113 /** 114 * Try to use the Emote specified by the index. 115 * 116 * @param index Index of the emote shortcut. 117 */ 118 void useEmote(const size_t index) const; 119 120 void useEmotePlayer(const size_t index) const; 121 122 private: 123 /** 124 * Save the configuration information. 125 */ 126 void save() const; 127 128 unsigned char mEmotes[SHORTCUT_EMOTES]; // The emote stored. 129 unsigned char mEmoteSelected; // The emote held by cursor. 130 }; 131 132 extern EmoteShortcut *emoteShortcut; 133 134 #endif // GUI_SHORTCUT_EMOTESHORTCUT_H 135