1
/*
2
 *  Custom keyboard shortcuts configuration
3
 *  Copyright (C) 2007  Joshua Langley <joshlangley@optusnet.com.au>
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
#ifndef KEYBOARDCONFIG_H
23
#define KEYBOARDCONFIG_H
24
25
#include <SDL_types.h>
26
#include <string>
27
28
/**
29
 * Each key represents a key function. Such as 'Move up', 'Attack' etc.
30
 */
31
struct KeyFunction
32
{
33
    const char* configField;    /** Field index that is in the config file. */
34
    int defaultValue;           /** The default key value used. */
35
    std::string caption;        /** The caption value for the key function. */
36
    int value;                  /** The actual value that is used. */
37
};
38
39
class Setup_Keyboard;
40
41
class KeyboardConfig
42
{
43
    public:
44
        /**
45
         * Initializes the keyboard config explicitly.
46
         */
47
        void init();
48
49
        /**
50
         * Retrieve the key values from config file.
51
         */
52
        void retrieve();
53
54
        /**
55
         * Store the key values to config file.
56
         */
57
        void store();
58
59
        /**
60
         * Make the keys their default values.
61
         */
62
        void makeDefault();
63
64
        /**
65
         * Determines if any key assignments are the same as each other.
66
         */
67
        bool hasConflicts();
68
69
        /**
70
         * Calls a function back so the key re-assignment(s) can be seen.
71
         */
72
        void callbackNewKey();
73
74
        /**
75
         * Obtain the value stored in memory.
76
         */
77
        int getKeyValue(int index) const
78
        { return mKey[index].value; }
79
80
        /**
81
         * Get the index of the new key to be assigned.
82
         */
83
        int getNewKeyIndex() const
84
        { return mNewKeyIndex; }
85
86
        /**
87
         * Get the enable flag, which will stop the user from doing actions.
88
         */
89
        bool isEnabled() const
90
        { return mEnabled; }
91
92
        /**
93
         * Get the key caption, providing more meaning to the user.
94
         */
95
        const std::string &getKeyCaption(int index) const
96
        { return mKey[index].caption; }
97
98
        /**
99
         * Get the key function index by providing the keys value.
100
         */
101
        int getKeyIndex(int keyValue) const;
102
103
        /**
104
         * Get the key function index for an emote by providing the offset value.
105
         */
106
        int getKeyEmoteOffset(int keyValue) const;
107
108
        /**
109
         * Set the enable flag, which will stop the user from doing actions.
110
         */
111
        void setEnabled(bool flag)
112
        { mEnabled = flag; }
113
114
        /**
115
         * Set the index of the new key to be assigned.
116
         */
117
        void setNewKeyIndex(int value)
118
        { mNewKeyIndex = value; }
119
120
        /**
121
         * Set the value of the new key.
122
         */
123
        void setNewKey(int value)
124
        { mKey[mNewKeyIndex].value = value; }
125
126
        /**
127
         * Set a reference to the key setup window.
128
         */
129
        void setSetupKeyboard(Setup_Keyboard *setupKey)
130
        { mSetupKey = setupKey; }
131
132
        /**
133
         * Checks if the key is active, by providing the key function index.
134
         */
135
        bool isKeyActive(int index) const;
136
137
        /**
138
         * Takes a snapshot of all the active keys.
139
         */
140
        void refreshActiveKeys();
141
142
        /**
143
         * All the key functions.
144
         * KEY_NO_VALUE is used in initialization, and should be unchanged.
145
         * KEY_TOTAL should always be last (used as a conditional in loops).
146
         * The key assignment view gets arranged according to the order of
147
         * these values.
148
         */
149
        enum KeyAction
150
        {
151
            KEY_NO_VALUE = -1,
152
            KEY_MOVE_UP,
153
            KEY_MOVE_DOWN,
154
            KEY_MOVE_LEFT,
155
            KEY_MOVE_RIGHT,
156
            KEY_ATTACK,
157
            KEY_TARGET_ATTACK,
158
            KEY_EMOTE,
159
            KEY_TALK,
160
            KEY_TARGET,
161
            KEY_TARGET_CLOSEST,
162
            KEY_TARGET_NPC,
163
            KEY_TARGET_PLAYER,
164
            KEY_PICKUP,
165
            KEY_HIDE_WINDOWS,
166
            KEY_SIT,
167
            KEY_SCREENSHOT,
168
            KEY_TRADE,
169
            KEY_PATHFIND,
170
            KEY_SHORTCUT_1,
171
            KEY_SHORTCUT_2,
172
            KEY_SHORTCUT_3,
173
            KEY_SHORTCUT_4,
174
            KEY_SHORTCUT_5,
175
            KEY_SHORTCUT_6,
176
            KEY_SHORTCUT_7,
177
            KEY_SHORTCUT_8,
178
            KEY_SHORTCUT_9,
179
            KEY_SHORTCUT_10,
180
            KEY_SHORTCUT_11,
181
            KEY_SHORTCUT_12,
182
            KEY_WINDOW_HELP,
183
            KEY_WINDOW_STATUS,
184
            KEY_WINDOW_INVENTORY,
185
            KEY_WINDOW_EQUIPMENT,
186
            KEY_WINDOW_SKILL,
187
            KEY_WINDOW_MINIMAP,
188
            KEY_WINDOW_CHAT,
189
            KEY_WINDOW_SHORTCUT,
190
            KEY_WINDOW_SETUP,
191
            KEY_WINDOW_DEBUG,
192
            KEY_WINDOW_PARTY,
193
            KEY_WINDOW_EMOTE_SHORTCUT,
194
            KEY_WINDOW_OUTFIT,
195
            KEY_EMOTE_1,
196
            KEY_EMOTE_2,
197
            KEY_EMOTE_3,
198
            KEY_EMOTE_4,
199
            KEY_EMOTE_5,
200
            KEY_EMOTE_6,
201
            KEY_EMOTE_7,
202
            KEY_EMOTE_8,
203
            KEY_EMOTE_9,
204
            KEY_EMOTE_10,
205
            KEY_EMOTE_11,
206
            KEY_EMOTE_12,
207
            KEY_TOGGLE_CHAT,
208
            KEY_SCROLL_CHAT_UP,
209
            KEY_SCROLL_CHAT_DOWN,
210
            KEY_PREV_CHAT_TAB,
211
            KEY_NEXT_CHAT_TAB,
212
            KEY_OK,
213
            KEY_QUIT,
214
            KEY_IGNORE_INPUT_1,
215
            KEY_IGNORE_INPUT_2,
216
            KEY_TOTAL
217
        };
218
219
    private:
220
        int mNewKeyIndex;              /**< Index of new key to be assigned */
221
        bool mEnabled;                 /**< Flag to respond to key input */
222
223
        Setup_Keyboard *mSetupKey;     /**< Reference to setup window */
224
225
        KeyFunction mKey[KEY_TOTAL];   /**< Pointer to all the key data */
226
227
        Uint8 *mActiveKeys;            /**< Stores a list of all the keys */
228
};
229
230
extern KeyboardConfig keyboard;
231
232
#endif