ManaPlus
emoteshortcut.cpp
Go to the documentation of this file.
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 
24 
25 #include "configuration.h"
26 #include "settings.h"
27 
28 #include "being/localplayer.h"
29 
30 #include "net/homunculushandler.h"
31 #include "net/mercenaryhandler.h"
32 #include "net/pethandler.h"
33 
34 #include "resources/db/emotedb.h"
35 
36 #include "debug.h"
37 
39 
41  mEmoteSelected(0)
42 {
43  for (int i = 0; i < SHORTCUT_EMOTES; i++)
44  mEmotes[i] = 0;
45 }
46 
48 {
49  save();
50 }
51 
53 {
54  for (unsigned char i = 0, j = 0,
55  fsz = CAST_U8(EmoteDB::getLast());
56  i <= fsz && j < SHORTCUT_EMOTES;
57  i++)
58  {
59  const EmoteSprite *const sprite = EmoteDB::getSprite(i, true);
60  if (sprite != nullptr)
61  {
62  mEmotes[j] = CAST_U8(i + 1);
63  j ++;
64  }
65  }
66 }
67 
68 void EmoteShortcut::save() const
69 {
70  for (int i = 0; i < SHORTCUT_EMOTES; i++)
71  {
72  const unsigned char emoteId = mEmotes[i] != 0U ? mEmotes[i]
73  : CAST_U8(0);
74  serverConfig.setValue("emoteshortcut" + toString(i),
75  CAST_U32(emoteId));
76  }
77 }
78 
79 void EmoteShortcut::useEmotePlayer(const size_t index) const
80 {
81  if (index <= CAST_SIZE(SHORTCUT_EMOTES))
82  {
83  if (mEmotes[index - 1] > 0)
84  LocalPlayer::emote(mEmotes[index - 1]);
85  }
86 }
87 
88 void EmoteShortcut::useEmote(const size_t index) const
89 {
90  if (localPlayer == nullptr)
91  return;
92 
93  if (index <= CAST_SIZE(SHORTCUT_EMOTES))
94  {
95  if (mEmotes[index - 1] > 0)
96  {
97  const uint8_t emote = mEmotes[index - 1];
98  switch (settings.emoteType)
99  {
100  case EmoteType::Player:
101  default:
103  break;
104  case EmoteType::Pet:
106  break;
109  break;
112  break;
113  }
114  }
115  }
116 }
#define CAST_U32
Definition: cast.h:31
#define CAST_SIZE
Definition: cast.h:34
#define CAST_U8
Definition: cast.h:27
void setValue(const std::string &key, const std::string &value)
unsigned char mEmotes[SHORTCUT_EMOTES]
void useEmotePlayer(const size_t index) const
void save() const
void useEmote(const size_t index) const
static bool emote(const uint8_t emotion)
virtual void emote(const uint8_t emoteId) const =0
virtual void emote(const uint8_t emoteId) const =0
virtual void emote(const uint8_t emoteId)=0
EmoteTypeT emoteType
Definition: settings.h:152
Configuration serverConfig
static const int SHORTCUT_EMOTES
Definition: emoteshortcut.h:25
EmoteShortcut * emoteShortcut
Net::HomunculusHandler * homunculusHandler
Definition: net.cpp:112
LocalPlayer * localPlayer
Net::MercenaryHandler * mercenaryHandler
Definition: net.cpp:118
bool emote(InputEvent &event)
Definition: actions.cpp:31
std::string toString(T const &value)
converts any type to a string
Definition: catch.hpp:1774
const int & getLast() A_CONST
Definition: emotedb.cpp:301
const EmoteSprite * getSprite(const int id, const bool allowNull)
Definition: emotedb.cpp:292
@ Mercenary
Definition: emotetype.h:31
@ Homunculus
Definition: emotetype.h:30
Net::PetHandler * petHandler
Definition: net.cpp:95
Settings settings
Definition: settings.cpp:32