forked from nuvie/nuvie
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommandBarNewUI.cpp
319 lines (281 loc) · 8.33 KB
/
CommandBarNewUI.cpp
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
/*
* CommandBarNewUI.cpp
* Nuvie
*
* Created by Eric Fry on Sun Oct 7 2012.
* Copyright (c) 2012 The Nuvie Team. All rights reserved.
*
* 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 2
* 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*
*/
#include <cassert>
#include "SDL.h"
#include "Configuration.h"
#include "nuvieDefs.h"
#include "U6misc.h"
#include "Game.h"
#include "Screen.h"
#include "Event.h"
#include "TileManager.h"
#include "Font.h"
#include "FontManager.h"
#include "GameClock.h"
#include "GamePalette.h"
#include "CommandBarNewUI.h"
#include "Weather.h"
#include "Party.h"
#include "Player.h"
#include "Objlist.h"
#include "NuvieIO.h"
#include "Background.h"
#include "Keys.h"
using std::string;
#define btn_size 17
#define SELECTED_COLOR 248
#define table_size_U6 13
#define table_size_SE 12
#define table_size_MD 11
static const char *U6_mode_name_tbl[table_size_U6] = {"Attack", "Cast", "Talk", "Look", "Get", "Drop", "Move", "Use", "Rest", "Combat mode", "Load/Save", "Quick save", "Quick load"};
static const char *SE_mode_name_tbl[table_size_SE] = {"Move", "Get", "Drop", "Use", "Talk", "Look", "Attack", "Rest", "Combat mode", "Load/Save", "Quick save", "Quick load"};
static const char *MD_mode_name_tbl[table_size_MD] = {"Attack", "Talk", "Look", "Get", "Drop", "Move", "Use", "Combat mode", "Load/Save", "Quick save", "Quick load"};
static const char *mode_name_tbl[table_size_U6];
CommandBarNewUI::CommandBarNewUI(Game *g) : CommandBar()
{
game = g;
background = NULL;
Weather *weather;
uint16 x_off = game->get_game_x_offset();
uint16 y_off = game->get_game_y_offset();
icon_w = 5;
icon_h = 3;
uint8 text_height;
uint16 map_width;
uint16 map_height;
offset = OBJLIST_OFFSET_U6_COMMAND_BAR;
if(game->get_game_type() == NUVIE_GAME_U6)
{
num_icons = table_size_U6;
for (uint8 i = 0; i < table_size_U6; i++)
mode_name_tbl[i] = U6_mode_name_tbl[i];
}
else if(game->get_game_type() == NUVIE_GAME_SE)
{
num_icons = table_size_SE;
for (uint8 i = 0; i < table_size_SE; i++)
mode_name_tbl[i] = SE_mode_name_tbl[i];
}
else // MD
{
num_icons = table_size_MD;
for (uint8 i = 0; i < table_size_MD; i++)
mode_name_tbl[i] = MD_mode_name_tbl[i];
}
if(game->is_orig_style())
{
text_height = 8;
icon_y_offset = 0;
map_width = 176;
map_height = 176;
}
else
{
if(game->get_game_type() == NUVIE_GAME_U6)
{
text_height = 17;
icon_y_offset = 9;
} else {
text_height = 8;
icon_y_offset = 0;
}
if(game->is_original_plus())
map_width = game->get_game_width() - game->get_background()->get_border_width();
else
map_width = game->get_game_width();
map_height = game->get_game_height();
}
uint8 command_width = btn_size * icon_w;
uint8 command_height = btn_size * icon_h + text_height;
Init(NULL, (map_width - command_width)/2 + x_off, (map_height - command_height)/2 + y_off, 0, 0);
area.w = command_width; // space for 5x3 icons
area.h = command_height;
event = NULL; // it's not set yet
weather = game->get_weather();
selected_action = -1;
combat_mode = false;
wind = weather->get_wind_dir_str();
bg_color = game->get_palette()->get_bg_color();
init_buttons();
if(game->get_game_type() == NUVIE_GAME_U6 && !game->is_orig_style())
weather->add_wind_change_notification_callback((CallBack *)this); //we want to know when the wind direction changes.
cur_pos = 0;
font = game->get_font_manager()->get_conv_font();
}
CommandBarNewUI::~CommandBarNewUI()
{
}
GUI_status CommandBarNewUI::MouseDown(int x, int y, int button)
{
if(HitRect(x, y))
{
x -= area.x;
y -= area.y;
if(y >= icon_y_offset)
{
uint8 pos = ((y - icon_y_offset) / btn_size) * icon_w;
pos += x / btn_size;
if(pos < num_icons)
{
cur_pos = pos;
hit((sint8)cur_pos);
#ifdef HAVE_JOYSTICK_SUPPORT
Game::get_game()->get_keybinder()->set_enable_joy_repeat(true);
#endif
Hide();
}
}
}
return(GUI_YUM);
}
GUI_status CommandBarNewUI::MouseUp(int x, int y, int button)
{
/*
if(HitRect(x, y))
{
x -= area.x;
y -= area.y;
if(y >= icon_y_offset && y < icon_y_offset + icon_h * btn_size)
{
hit((sint8)cur_pos);
Hide();
}
}
*/
return(GUI_YUM);
}
GUI_status CommandBarNewUI::KeyDown(SDL_Keysym key)
{
KeyBinder *keybinder = Game::get_game()->get_keybinder();
ActionType a = keybinder->get_ActionType(key);
switch(keybinder->GetActionKeyType(a))
{
case NORTH_KEY:
do
{
if(cur_pos - icon_w < 0)
cur_pos = icon_w * icon_h - (icon_w - cur_pos%icon_w);
else
cur_pos -= icon_w;
} while(cur_pos >= num_icons);
break;
case SOUTH_KEY:
do
{
cur_pos = (cur_pos + icon_w) % (icon_w * icon_h);
} while(cur_pos >= num_icons);
break;
case WEST_KEY:
do
{
if(cur_pos%icon_w == 0)
cur_pos = (cur_pos/icon_w)*icon_w+icon_w-1;
else
cur_pos--;
} while(cur_pos >= num_icons);
break;
case EAST_KEY:
do
{
cur_pos = (cur_pos/icon_w)*icon_w + (cur_pos+1) % icon_w;
} while(cur_pos >= num_icons);
break;
case DO_ACTION_KEY:
if(cur_pos < num_icons)
{
hit((sint8)cur_pos);
#ifdef HAVE_JOYSTICK_SUPPORT
keybinder->set_enable_joy_repeat(true);
#endif
Hide();
}
break;
case CANCEL_ACTION_KEY:
case NEW_COMMAND_BAR_KEY:
#ifdef HAVE_JOYSTICK_SUPPORT
keybinder->set_enable_joy_repeat(true);
#endif
Hide();
break;
default : keybinder->handle_always_available_keys(a);
break;
}
return GUI_YUM;
}
void CommandBarNewUI::Display(bool full_redraw)
{
Screen *screen = game->get_screen();
//if(full_redraw || update_display)
// {
update_display = false;
if(game->get_game_type() == NUVIE_GAME_U6)
{
//screen->fill(bg_color, area.x, area.y, area.w, area.h);
if(!game->is_orig_style())
{
//display_information();
string infostring(game->get_clock()->get_date_string());
infostring += " Wind:";
infostring += wind;
font->drawString(screen, infostring.c_str(), area.x -13, area.y); // sort of center
}
}
uint8 i=0;
for(uint8 y=0; y < icon_h; y++)
{
for(uint8 x = 0; x < icon_w && i < num_icons; x++,i++)
{
screen->blit(area.x+x*btn_size, icon_y_offset+area.y+y*btn_size, icon[i]->data, 8, 16, 16, 16);
if(i == cur_pos)
{
screen->stipple_8bit(SELECTED_COLOR, area.x+x*btn_size, icon_y_offset+area.y+y*btn_size, 16, 16);
}
}
}
if(game->get_game_type() == NUVIE_GAME_U6) // FIXME use new icon instead
{
font->drawString(screen, "QS", area.x + 2 + btn_size, icon_y_offset + area.y + 2 * btn_size + 4);
font->drawString(screen, "QL", area.x + 2 + 2 * btn_size, icon_y_offset + area.y + 2 * btn_size + 4);
}
font->drawString(screen, get_command_name(cur_pos), area.x, area.y + icon_y_offset + icon_h * btn_size);
if(game->get_game_type() == NUVIE_GAME_U6 && !game->is_orig_style())
screen->update(area.x-13, area.y, area.w+26, area.h); // need to have edges of text update
else
screen->update(area.x, area.y, area.w, area.h);
// }
}
const char *CommandBarNewUI::get_command_name(sint8 command_num)
{
if(command_num < 0 || command_num >= num_icons)
return "";
return mode_name_tbl[command_num];
}
/*
void CommandBarNewUI::display_information()
{
string infostring(game->get_clock()->get_date_string());
infostring += " Wind:";
infostring += wind;
text->drawString(screen, infostring.c_str(), area.x + 8, area.y, 0);
}
*/