forked from raduprv/Eternal-Lands
/
mapwin.c
296 lines (262 loc) · 7.17 KB
/
mapwin.c
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
#include <stdlib.h>
#include <string.h>
#include <SDL.h>
#include "mapwin.h"
#include "asc.h"
#include "books.h"
#include "console.h"
#include "consolewin.h"
#include "chat.h"
#include "draw_scene.h"
#include "elwindows.h"
#include "gamewin.h"
#include "gl_init.h"
#include "global.h"
#include "hud.h"
#include "init.h"
#include "interface.h"
#include "lights.h"
#include "map.h"
#include "missiles.h"
#include "new_character.h"
#include "pathfinder.h"
#include "textures.h"
#include "eye_candy_wrapper.h"
#include "special_effects.h"
int map_root_win = -1;
int showing_continent = 0;
#ifdef DEBUG_MAP_SOUND
extern int cur_tab_map;
#endif // DEBUG_MAP_SOUND
int mouse_over_minimap = 0;
int reload_tab_map = 0;
int temp_tile_map_size_x = 0;
int temp_tile_map_size_y = 0;
int max_temp_mark = 0;
marking temp_marks[MAX_USER_MARKS];
#define MARK_FILTER_MAX_LEN 40
int mark_filter_active = 0;
char mark_filter_text[MARK_FILTER_MAX_LEN] = "";
int curmark_r=0,curmark_g=255,curmark_b=0;
int click_map_handler (window_info *win, int mx, int my, Uint32 flags)
{
Uint32 ctrl_on = flags & ELW_CTRL;
Uint32 left_click = flags & ELW_LEFT_MOUSE;
Uint32 right_click = flags & ELW_RIGHT_MOUSE;
float scale = (float) (win->len_x-hud_x) / 300.0f;
if (left_click && mx > 0 && mx < 50*scale && my > 0 && my < 55*scale)
{
showing_continent = !showing_continent;
#ifdef NEW_TEXTURES
inspect_map_text = 0;
#else /* NEW_TEXTURES */
if(inspect_map_text != 0)
{
glDeleteTextures(1,&inspect_map_text);
inspect_map_text = 0;
}
#endif /* NEW_TEXTURES */
}
else if (!showing_continent && inspect_map_text == 0)
{
if (left_click)
{
pf_move_to_mouse_position ();
}
else if (right_click)
{
if (!ctrl_on)
put_mark_on_map_on_mouse_position ();
else
delete_mark_on_map_on_mouse_position ();
}
}
else if(showing_continent)
{
if (left_click)
{
int min_mouse_x = (window_width-hud_x)/6;
int min_mouse_y = 0;
int max_mouse_x = min_mouse_x+((window_width-hud_x)/1.5);
int max_mouse_y = window_height - hud_y;
int screen_map_width = max_mouse_x - min_mouse_x;
int screen_map_height = max_mouse_y - min_mouse_y;
int i;
/* Convert mouse coordinates to map coordinates (stolen from pf_get_mouse_position()) */
int m_px = ((mx-min_mouse_x) * 512) / screen_map_width;
int m_py = 512 - ((my * 512) / screen_map_height);
/* Check if we clicked on a map */
for(i = 0; continent_maps[i].name != NULL; i++) {
if(continent_maps[i].cont == continent_maps[cur_map].cont) {
if(m_px > continent_maps[i].x_start && m_px < continent_maps[i].x_end
&& m_py > continent_maps[i].y_start && m_py < continent_maps[i].y_end)
{
/* Load this map's bmp */
if(cur_map != i) {
#ifdef NEW_TEXTURES
inspect_map_text = load_texture_cached(continent_maps[i].name, tt_image);
#else /* NEW_TEXTURES */
texture_cache_struct tex;
size_t name_len;
my_strcp(tex.file_name,continent_maps[i].name);
name_len = strlen(tex.file_name);
sprintf(tex.file_name+name_len-3, "bmp");
inspect_map_text = load_bmp8_fixed_alpha(&tex, 128);
#endif /* NEW_TEXTURES */
}
#ifdef DEBUG_MAP_SOUND
cur_tab_map = i;
#endif // DEBUG_MAP_SOUND
load_marks_to_buffer(continent_maps[i].name, temp_marks, &max_temp_mark);
get_tile_map_sizes(continent_maps[i].name, &temp_tile_map_size_x, &temp_tile_map_size_y);
showing_continent = !showing_continent;
break;
}
}
}
}
}
return 1;
}
int display_map_handler (window_info * win)
{
// are we actively drawing things?
if (SDL_GetAppState () & SDL_APPACTIVE)
{
draw_hud_interface ();
Leave2DMode ();
if(reload_tab_map && map_root_win >= 0 && windows_list.window[map_root_win].displayed){
//need to reload the BMP
switch_from_game_map();
switch_to_game_map();
}
draw_game_map (!showing_continent, mouse_over_minimap);
Enter2DMode ();
CHECK_GL_ERRORS ();
reload_tab_map = 0;
}
if(special_effects){
display_special_effects(0);
}
// remember the time stamp to improve FPS quality when switching modes
next_fps_time=cur_time+1000;
last_count=0;
ec_idle();
missiles_update();
update_camera();
draw_delay = 20;
return 1;
}
int mouseover_map_handler (window_info *win, int mx, int my)
{
float scale = (float) (win->len_x-hud_x) / 300.0f;
if (mx > 0 && mx < 50*scale && my > 0 && my < 55*scale)
{
mouse_over_minimap = 1;
}
else
{
mouse_over_minimap = 0;
}
return mouse_over_minimap;
}
int keypress_map_handler (window_info *win, int mx, int my, Uint32 key, Uint32 unikey)
{
Uint8 ch = key_to_char (unikey);
if (ch == SDLK_RETURN && adding_mark && input_text_line.len > 0)
{
int i;
// if text wrapping just keep the text until the wrap.
for (i = 0; i < input_text_line.len; i++)
{
if (input_text_line.data[i] == '\n')
{
input_text_line.data[i] = '\0';
break;
}
}
put_mark_on_position(mark_x, mark_y, input_text_line.data);
adding_mark = 0;
clear_input_line ();
}
// does the user want to cancel a mapmark?
else if (ch == SDLK_ESCAPE && adding_mark)
{
adding_mark = 0;
clear_input_line ();
}
// enable, disable or reset the mark filter
else if ((key == K_MARKFILTER) || (mark_filter_active && (ch == SDLK_ESCAPE)))
{
if (!mark_filter_active || (ch == SDLK_ESCAPE))
mark_filter_active ^= 1;
memset(mark_filter_text, 0, sizeof(char)*MARK_FILTER_MAX_LEN);
}
// now try the keypress handler for all root windows
else if ( keypress_root_common (key, unikey) )
{
return 1;
}
else if (key == K_MAP)
{
if (keep_grabbing_mouse)
{
toggle_have_mouse();
keep_grabbing_mouse=0;
}
switch_from_game_map ();
hide_window (map_root_win);
show_window (game_root_win);
// Undo stupid quickbar hack
if ( !get_show_window (quickbar_win) )
show_window (quickbar_win);
}
else if (mark_filter_active && !adding_mark)
{
string_input(mark_filter_text, MARK_FILTER_MAX_LEN, ch);
}
else
{
reset_tab_completer();
if (ch == '`' || key == K_CONSOLE)
{
switch_from_game_map ();
hide_window (map_root_win);
show_window (console_root_win);
}
else if ( !text_input_handler (key, unikey) )
{
// nothing we can handle
return 0;
}
}
// we handled it, return 1 to let the window manager know
return 1;
}
int show_map_handler (window_info *win)
{
hide_window(book_win);
hide_window(paper_win);
hide_window(color_race_win);
hide_window(tab_bar_win);
input_widget_move_to_win(win->window_id);
return 1;
}
int hide_map_handler (window_info * win)
{
widget_unset_flags (input_widget->window_id, input_widget->id, WIDGET_INVISIBLE);
return 1;
}
void create_map_root_window (int width, int height)
{
if (map_root_win < 0)
{
map_root_win = create_window ("Map", -1, -1, 0, 0, width, height, ELW_TITLE_NONE|ELW_SHOW_LAST);
set_window_handler (map_root_win, ELW_HANDLER_DISPLAY, &display_map_handler);
set_window_handler (map_root_win, ELW_HANDLER_KEYPRESS, &keypress_map_handler);
set_window_handler (map_root_win, ELW_HANDLER_CLICK, &click_map_handler);
set_window_handler (map_root_win, ELW_HANDLER_MOUSEOVER, &mouseover_map_handler);
set_window_handler (map_root_win, ELW_HANDLER_SHOW, &show_map_handler);
set_window_handler (map_root_win, ELW_HANDLER_HIDE, &hide_map_handler);
}
}