forked from TheSuperHackers/GeneralsGameCode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHotKey.cpp
More file actions
231 lines (203 loc) · 7.3 KB
/
HotKey.cpp
File metadata and controls
231 lines (203 loc) · 7.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
/*
** Command & Conquer Generals Zero Hour(tm)
** Copyright 2025 Electronic Arts Inc.
**
** This program is free software: you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation, either version 3 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
////////////////////////////////////////////////////////////////////////////////
// //
// (c) 2001-2003 Electronic Arts Inc. //
// //
////////////////////////////////////////////////////////////////////////////////
// FILE: HotKey.cpp /////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//
// Electronic Arts Pacific.
//
// Confidential Information
// Copyright (C) 2002 - All Rights Reserved
//
//-----------------------------------------------------------------------------
//
// created: Sep 2002
//
// Filename: HotKey.cpp
//
// author: Chris Huybregts
//
// purpose:
//
//-----------------------------------------------------------------------------
///////////////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
// SYSTEM INCLUDES ////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#include "PreRTS.h" // This must go first in EVERY cpp file in the GameEngine
//-----------------------------------------------------------------------------
// USER INCLUDES //////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
#include "GameClient/HotKey.h"
#include "GameClient/KeyDefs.h"
#include "GameClient/MetaEvent.h"
#include "GameClient/GameWindow.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/Keyboard.h"
#include "GameClient/GameText.h"
#include "Common/AudioEventRTS.h"
//-----------------------------------------------------------------------------
// DEFINES ////////////////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
GameMessageDisposition HotKeyTranslator::translateGameMessage(const GameMessage *msg)
{
GameMessageDisposition disp = KEEP_MESSAGE;
GameMessage::Type t = msg->getType();
if ( t == GameMessage::MSG_RAW_KEY_UP)
{
//char key = msg->getArgument(0)->integer;
Int keyState = msg->getArgument(1)->integer;
// for our purposes here, we don't care to distinguish between right and left keys,
// so just fudge a little to simplify things.
Int newModState = 0;
if( keyState & KEY_STATE_CONTROL )
{
newModState |= CTRL;
}
if( keyState & KEY_STATE_SHIFT )
{
newModState |= SHIFT;
}
if( keyState & KEY_STATE_ALT )
{
newModState |= ALT;
}
if(newModState != 0)
return disp;
WideChar key = TheKeyboard->getPrintableKey((KeyDefType)msg->getArgument(0)->integer, 0);
UnicodeString uKey;
uKey.concat(key);
AsciiString aKey;
aKey.translate(uKey);
if(TheHotKeyManager && TheHotKeyManager->executeHotKey(aKey))
disp = DESTROY_MESSAGE;
}
return disp;
}
//-----------------------------------------------------------------------------
HotKey::HotKey()
{
m_win = nullptr;
m_key.clear();
}
//-----------------------------------------------------------------------------
HotKeyManager::HotKeyManager()
{
}
//-----------------------------------------------------------------------------
HotKeyManager::~HotKeyManager()
{
m_hotKeyMap.clear();
}
//-----------------------------------------------------------------------------
void HotKeyManager::init()
{
m_hotKeyMap.clear();
}
//-----------------------------------------------------------------------------
void HotKeyManager::reset()
{
m_hotKeyMap.clear();
}
//-----------------------------------------------------------------------------
void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn)
{
AsciiString key = keyIn;
key.toLower();
HotKeyMap::iterator it = m_hotKeyMap.find(key);
if( it != m_hotKeyMap.end() )
{
DEBUG_CRASH(("Hotkey %s is already mapped to window %s, current window is %s", key.str(), it->second.m_win->winGetInstanceData()->m_decoratedNameString.str(), win->winGetInstanceData()->m_decoratedNameString.str()));
return;
}
HotKey newHK;
newHK.m_key.set(key);
newHK.m_win = win;
m_hotKeyMap[key] = newHK;
}
//-----------------------------------------------------------------------------
Bool HotKeyManager::executeHotKey( const AsciiString& keyIn )
{
AsciiString key = keyIn;
key.toLower();
HotKeyMap::iterator it = m_hotKeyMap.find(key);
if( it == m_hotKeyMap.end() )
return FALSE;
GameWindow *win = it->second.m_win;
if( !win )
return FALSE;
if( !BitIsSet( win->winGetStatus(), WIN_STATUS_HIDDEN ) )
{
if( BitIsSet( win->winGetStatus(), WIN_STATUS_ENABLED ) )
{
TheWindowManager->winSendSystemMsg( win->winGetParent(), GBM_SELECTED, (WindowMsgData)win, win->winGetWindowId() );
// here we make the same click sound that the GUI uses when you click a button
AudioEventRTS buttonClick("GUIClick");
if( TheAudio )
{
TheAudio->addAudioEvent( &buttonClick );
}
return TRUE;
}
AudioEventRTS disabledClick( "GUIClickDisabled" );
if( TheAudio )
{
TheAudio->addAudioEvent( &disabledClick );
}
}
return FALSE;
}
//-----------------------------------------------------------------------------
AsciiString HotKeyManager::searchHotKey( const AsciiString& label)
{
return searchHotKey(TheGameText->fetch(label));
}
//-----------------------------------------------------------------------------
AsciiString HotKeyManager::searchHotKey( const UnicodeString& uStr )
{
if(uStr.isEmpty())
return AsciiString::TheEmptyString;
const WideChar *marker = (const WideChar *)uStr.str();
while (marker && *marker)
{
if (*marker == L'&')
{
// found a '&' - now look for the next char
UnicodeString tmp = UnicodeString::TheEmptyString;
tmp.concat(*(marker+1));
AsciiString retStr;
retStr.translate(tmp);
return retStr;
}
marker++;
}
return AsciiString::TheEmptyString;
}
//-----------------------------------------------------------------------------
HotKeyManager *TheHotKeyManager = nullptr;
//-----------------------------------------------------------------------------
// PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
//-----------------------------------------------------------------------------