1
/*
2
 *  Extended support for activating emotes
3
 *  Copyright (C) 2009  Aethyra Development Team
4
 *
5
 *  This file is part of The Mana World.
6
 *
7
 *  This program is free software; you can redistribute it and/or modify
8
 *  it under the terms of the GNU General Public License as published by
9
 *  the Free Software Foundation; either version 2 of the License, or
10
 *  any later version.
11
 *
12
 *  This program is distributed in the hope that it will be useful,
13
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 *  GNU General Public License for more details.
16
 *
17
 *  You should have received a copy of the GNU General Public License
18
 *  along with this program; if not, write to the Free Software
19
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
20
 */
21
22
#include "emoteshortcut.h"
23
24
#include "configuration.h"
25
#include "localplayer.h"
26
27
#include "utils/stringutils.h"
28
29
EmoteShortcut::EmoteShortcut *emoteShortcut;
30
31
EmoteShortcut::EmoteShortcut():
32
    mEmoteSelected(0)
33
{
34
    for (int i = 0; i < SHORTCUT_EMOTES; i++)
35
    {
36
        mEmotes[i] = i + 1;
37
    }
38
    load();
39
}
40
41
EmoteShortcut::~EmoteShortcut()
42
{
43
    save();
44
}
45
46
void EmoteShortcut::load()
47
{
48
    for (int i = 0; i < SHORTCUT_EMOTES; i++)
49
    {
50
        int emoteId = (int) config.getValue("emoteshortcut" + toString(i), i + 1);
51
52
        if (emoteId)
53
        {
54
            mEmotes[i] = emoteId;
55
        }
56
    }
57
}
58
59
void EmoteShortcut::save()
60
{
61
    for (int i = 0; i < SHORTCUT_EMOTES; i++)
62
    {
63
        const int emoteId = mEmotes[i] ? mEmotes[i] : 0;
64
        config.setValue("emoteshortcut" + toString(i), emoteId);
65
    }
66
}
67
68
void EmoteShortcut::useEmote(int index)
69
{
70
    if ((index > 0) && (index <= SHORTCUT_EMOTES))
71
    {
72
       if (mEmotes[index - 1] > 0)
73
       {
74
          player_node->emote(mEmotes[index - 1]);
75
       }
76
    }
77
}