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 |
|
|
#include "gui/shortcut/emoteshortcut.h" |
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 |
|
|
|
38 |
|
|
EmoteShortcut *emoteShortcut = nullptr; |
39 |
|
|
|
40 |
|
|
EmoteShortcut::EmoteShortcut() : |
41 |
|
|
mEmoteSelected(0) |
42 |
|
|
{ |
43 |
|
|
for (int i = 0; i < SHORTCUT_EMOTES; i++) |
44 |
|
|
mEmotes[i] = 0; |
45 |
|
|
} |
46 |
|
|
|
47 |
|
|
EmoteShortcut::~EmoteShortcut() |
48 |
|
|
{ |
49 |
|
|
save(); |
50 |
|
|
} |
51 |
|
|
|
52 |
|
|
void EmoteShortcut::load() |
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: |
102 |
|
|
LocalPlayer::emote(emote); |
103 |
|
|
break; |
104 |
|
|
case EmoteType::Pet: |
105 |
|
|
petHandler->emote(emote); |
106 |
|
|
break; |
107 |
|
|
case EmoteType::Homunculus: |
108 |
|
|
homunculusHandler->emote(emote); |
109 |
|
|
break; |
110 |
|
|
case EmoteType::Mercenary: |
111 |
|
|
mercenaryHandler->emote(emote); |
112 |
|
|
break; |
113 |
|
|
} |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
2 |
} |