1 | /********************************************************************** <BR>
|
---|
2 | This file is part of Crack dot Com's free source code release of
|
---|
3 | Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for
|
---|
4 | information about compiling & licensing issues visit this URL</a>
|
---|
5 | <PRE> If that doesn't help, contact Jonathan Clark at
|
---|
6 | golgotha_source@usa.net (Subject should have "GOLG" in it)
|
---|
7 | ***********************************************************************/
|
---|
8 |
|
---|
9 | #include "border_frame.hh"
|
---|
10 | #include "loaders/load.hh"
|
---|
11 | #include "image/image.hh"
|
---|
12 | #include "device/keys.hh"
|
---|
13 | #include "device/kernel.hh"
|
---|
14 | #include "resources.hh"
|
---|
15 | #include "time/profile.hh"
|
---|
16 | #include "window/colorwin.hh"
|
---|
17 | #include "gui/button.hh"
|
---|
18 | #include "gui/image_win.hh"
|
---|
19 | #include "human.hh"
|
---|
20 | #include "mess_id.hh"
|
---|
21 | #include "objs/map_piece.hh"
|
---|
22 | #include "g1_render.hh"
|
---|
23 | #include "r1_api.hh"
|
---|
24 | #include "r1_win.hh"
|
---|
25 | #include "r1_clip.hh"
|
---|
26 | #include "objs/stank.hh"
|
---|
27 | #include "options.hh"
|
---|
28 | #include "app/app.hh"
|
---|
29 | #include "gui/gradiant.hh"
|
---|
30 | #include "device/device.hh"
|
---|
31 | #include "g1_texture_id.hh"
|
---|
32 | #include "g1_speed.hh"
|
---|
33 | #include "input.hh"
|
---|
34 | #include "player.hh"
|
---|
35 | #include "sound_man.hh"
|
---|
36 | #include "app/app.hh"
|
---|
37 | #include "lisp/li_class.hh"
|
---|
38 | #include "lisp/li_load.hh"
|
---|
39 | #include "lisp/li_init.hh"
|
---|
40 | #include "li_objref.hh"
|
---|
41 | #include "map_man.hh"
|
---|
42 | #include "map_view.hh"
|
---|
43 | #include "gui/deco_win.hh"
|
---|
44 | #include "controller.hh"
|
---|
45 | #include "device/key_man.hh"
|
---|
46 | #include "tick_count.hh"
|
---|
47 | #include "map_view.hh"
|
---|
48 | #include "demo.hh"
|
---|
49 | #include "window/win_evt.hh"
|
---|
50 | #include "image_man.hh"
|
---|
51 | #include "window/wmanager.hh"
|
---|
52 |
|
---|
53 |
|
---|
54 | S1_SFX(press_tab_to_switch_to_strategy_mode,"computer_voice/press_tab_to_switch_to_strategy_mode_22khz.wav",S1_STREAMED, 200);
|
---|
55 | S1_SFX(press_tab_to_switch_to_action_mode, "computer_voice/press_tab_to_switch_to_action_mode_22khz.wav", S1_STREAMED, 200);
|
---|
56 |
|
---|
57 |
|
---|
58 | class i4_profile_class pf_border_draw("border frame draw");
|
---|
59 |
|
---|
60 |
|
---|
61 | class g1_amount_display_class : public i4_window_class
|
---|
62 | {
|
---|
63 | public:
|
---|
64 | int last_amount, last_max;
|
---|
65 | i4_image_class *im, *dark_im;
|
---|
66 | i4_bool refresh_as_text;
|
---|
67 |
|
---|
68 | g1_amount_display_class(int w, int h)
|
---|
69 | : i4_window_class(w,h)
|
---|
70 | {
|
---|
71 | refresh_as_text=i4_T;
|
---|
72 | im=dark_im=0;
|
---|
73 | last_amount=0;
|
---|
74 | last_max=1;
|
---|
75 | }
|
---|
76 |
|
---|
77 | g1_amount_display_class(char *image_name=0)
|
---|
78 | : i4_window_class(0,0)
|
---|
79 | {
|
---|
80 | if (image_name)
|
---|
81 | {
|
---|
82 | char fn[100];
|
---|
83 | sprintf(fn, "bitmaps/stank/frame_%s.tga", image_name);
|
---|
84 | im=i4_load_image(fn);
|
---|
85 | sprintf(fn, "bitmaps/stank/dark_%s.tga", image_name);
|
---|
86 | dark_im=i4_load_image(fn);
|
---|
87 | }
|
---|
88 | else im=dark_im=0;
|
---|
89 |
|
---|
90 | last_amount=1;
|
---|
91 | last_max=1;
|
---|
92 | refresh_as_text=i4_F;
|
---|
93 |
|
---|
94 | if (im)
|
---|
95 | resize(im->width(), im->height());
|
---|
96 | else
|
---|
97 | resize(10,5);
|
---|
98 | }
|
---|
99 |
|
---|
100 | void update(int new_amount, int max_amount=1)
|
---|
101 | {
|
---|
102 | if (new_amount!=last_amount || last_max!=max_amount)
|
---|
103 | {
|
---|
104 | last_amount=new_amount;
|
---|
105 | last_max=max_amount;
|
---|
106 | request_redraw(i4_F);
|
---|
107 | }
|
---|
108 | }
|
---|
109 |
|
---|
110 | void draw(i4_draw_context_class &context)
|
---|
111 | {
|
---|
112 | if (refresh_as_text)
|
---|
113 | {
|
---|
114 | local_image->clear(0, context);
|
---|
115 | i4_font_class *fnt=i4_current_app->get_style()->font_hint->normal_font;
|
---|
116 | fnt->set_color(0x00ff00);
|
---|
117 | char str[30];
|
---|
118 | sprintf(str, "%d", last_amount);
|
---|
119 | fnt->put_string(local_image, width()-fnt->width(str),
|
---|
120 | height()/2-fnt->height(str)/2,
|
---|
121 | str, context);
|
---|
122 |
|
---|
123 | }
|
---|
124 | else
|
---|
125 | {
|
---|
126 | int midx=width()*last_amount/last_max;
|
---|
127 | if (midx>=width())
|
---|
128 | midx=width()-1;
|
---|
129 |
|
---|
130 | if (im)
|
---|
131 | im->put_part(local_image, 0,0, 0,0, midx, height()-1, context);
|
---|
132 | else
|
---|
133 | local_image->bar(0,0, midx, height()-1, 0xff0000, context);
|
---|
134 |
|
---|
135 | if (dark_im)
|
---|
136 | dark_im->put_part(local_image, midx,0, midx, 0, width()-1, height()-1, context);
|
---|
137 | else
|
---|
138 | local_image->bar(midx, 0, width()-1, height()-1, 0, context);
|
---|
139 | }
|
---|
140 | }
|
---|
141 |
|
---|
142 | ~g1_amount_display_class()
|
---|
143 | {
|
---|
144 | if (im) delete im;
|
---|
145 | if (dark_im) delete dark_im;
|
---|
146 | }
|
---|
147 |
|
---|
148 | char *name() { return "amount_display"; }
|
---|
149 | };
|
---|
150 |
|
---|
151 | i4_event_handler_reference_class<g1_border_frame_class> g1_border;
|
---|
152 | i4_event_handler_reference_class<g1_strategy_screen_class> g1_strategy_screen;
|
---|
153 |
|
---|
154 | static i4_event_handler_reference_class<g1_amount_display_class> g1_lives,
|
---|
155 | g1_chain, g1_missiles, g1_main, g1_health, g1_money;
|
---|
156 |
|
---|
157 |
|
---|
158 | class g1_object_stats_window_class : public i4_window_class
|
---|
159 | {
|
---|
160 | public:
|
---|
161 | const char *object_name;
|
---|
162 | i4_image_class *logo;
|
---|
163 |
|
---|
164 | char *name() { return "g1_object_stats"; }
|
---|
165 | i4_graphical_style_class *style;
|
---|
166 |
|
---|
167 | g1_object_stats_window_class(const char *object_name,
|
---|
168 | i4_image_class *logo,
|
---|
169 | i4_graphical_style_class *style)
|
---|
170 | : object_name(object_name), logo(logo),
|
---|
171 | style(style),
|
---|
172 | i4_window_class(200,170)
|
---|
173 | {
|
---|
174 | if (logo)
|
---|
175 | resize(logo->width(), logo->height());
|
---|
176 | }
|
---|
177 |
|
---|
178 | void draw(i4_draw_context_class &context)
|
---|
179 | {
|
---|
180 | if (logo)
|
---|
181 | logo->put_image(local_image,0,0, context);
|
---|
182 | else
|
---|
183 | i4_gradiant_bar(local_image, 1,1, width()-2, height()-2, 0x7f0000, 0, context);
|
---|
184 |
|
---|
185 |
|
---|
186 | g1_object_defaults_struct *odef=g1_get_object_defaults(object_name, i4_F);
|
---|
187 | if (odef)
|
---|
188 | {
|
---|
189 | i4_font_class *fnt=style->font_hint->normal_font;
|
---|
190 |
|
---|
191 | char *fmt="Name\nCost\nArmor\nSpeed\nDamage\nRange\nRate";
|
---|
192 |
|
---|
193 | int x=-20,y=10,w=97;
|
---|
194 |
|
---|
195 | fnt->set_color(0);
|
---|
196 | fnt->put_paragraph(local_image, x+1,y+1, i4_const_str(fmt), context,0,
|
---|
197 | i4_font_class::RIGHT, w);
|
---|
198 | fnt->set_color(0xffff00);
|
---|
199 | fnt->put_paragraph(local_image, x,y, i4_const_str(fmt), context,0,
|
---|
200 | i4_font_class::RIGHT, w);
|
---|
201 |
|
---|
202 | char fmt2[256];
|
---|
203 |
|
---|
204 | sprintf(fmt2, "%s\n$%d\n", odef->object_name, odef->cost);
|
---|
205 |
|
---|
206 | if (!odef->health)
|
---|
207 | strcat(fmt2, "special\n");
|
---|
208 | else
|
---|
209 | sprintf(fmt2+strlen(fmt2), "%d hp\n", odef->health);
|
---|
210 |
|
---|
211 | sprintf(fmt2+strlen(fmt2), "%3.3g mph\n",
|
---|
212 | odef->speed * 100.0 * G1_HZ * 3600.0 / 5280.0);
|
---|
213 |
|
---|
214 | int wtype=0, damage=-1;
|
---|
215 | if (odef->fire_type && odef->fire_type!=li_nil)
|
---|
216 | wtype=g1_get_object_type(odef->fire_type);
|
---|
217 |
|
---|
218 | if (wtype)
|
---|
219 | damage=g1_object_type_array[wtype]->get_damage_map()->default_damage;
|
---|
220 |
|
---|
221 | if (damage == -1)
|
---|
222 | strcat(fmt2, "special\n"); // damage
|
---|
223 | else
|
---|
224 | sprintf(fmt2+strlen(fmt2), "%d hp\n", damage);
|
---|
225 |
|
---|
226 | sprintf(fmt2+strlen(fmt2), "%4.4g ft\n%3.3g shots/s",
|
---|
227 | odef->detection_range * 100.0, (double)G1_HZ/(1.0+odef->fire_delay));
|
---|
228 |
|
---|
229 | i4_const_str *st=new i4_const_str(fmt2);
|
---|
230 |
|
---|
231 | fnt->set_color(0);
|
---|
232 | fnt->put_paragraph(local_image, x+w+6+1,y+1, *st, context);
|
---|
233 | fnt->set_color(0xffffff);
|
---|
234 | fnt->put_paragraph(local_image, x+w+6,y, *st, context);
|
---|
235 | delete st;
|
---|
236 | }
|
---|
237 | }
|
---|
238 |
|
---|
239 | };
|
---|
240 |
|
---|
241 |
|
---|
242 |
|
---|
243 | class g1_build_but : public i4_button_class
|
---|
244 | {
|
---|
245 | public:
|
---|
246 | i4_image_class *norm_im, *act_im, *press_im;
|
---|
247 |
|
---|
248 | const char *object_name;
|
---|
249 | i4_graphical_style_class *style;
|
---|
250 |
|
---|
251 | g1_build_but(const char *object_name,
|
---|
252 | i4_event_reaction_class *press,
|
---|
253 | i4_event_reaction_class *active,
|
---|
254 | i4_graphical_style_class *style,
|
---|
255 | i4_image_class *_norm_im,
|
---|
256 | i4_image_class *_act_im,
|
---|
257 | i4_image_class *_press_im)
|
---|
258 |
|
---|
259 | : i4_button_class(0, 0, style, press, 0, active, 0),
|
---|
260 | object_name(object_name),
|
---|
261 | style(style)
|
---|
262 | {
|
---|
263 | char image_name[256];
|
---|
264 | sprintf(image_name, "bitmaps/build/build_%s.tga", object_name);
|
---|
265 |
|
---|
266 | i4_image_class *button_image = i4_load_image(image_name);
|
---|
267 | norm_im=_norm_im->copy();
|
---|
268 | act_im=_act_im->copy();
|
---|
269 | press_im=_press_im->copy();
|
---|
270 |
|
---|
271 | i4_draw_context_class context(0,0,_norm_im->width()-1,_norm_im->height()-1);
|
---|
272 |
|
---|
273 | if (button_image)
|
---|
274 | {
|
---|
275 |
|
---|
276 | int wid=button_image->width()-1, hi=button_image->height()-1;
|
---|
277 | button_image->put_image(norm_im, 0, 0, context);
|
---|
278 | button_image->put_image(act_im, 0, 0, context);
|
---|
279 | button_image->put_image(press_im, 0, 0, context);
|
---|
280 | delete button_image;
|
---|
281 | }
|
---|
282 |
|
---|
283 | resize(_norm_im->width(), _norm_im->height());
|
---|
284 | }
|
---|
285 |
|
---|
286 | ~g1_build_but()
|
---|
287 | {
|
---|
288 | if (norm_im)
|
---|
289 | {
|
---|
290 | delete norm_im;
|
---|
291 | norm_im = 0;
|
---|
292 | }
|
---|
293 |
|
---|
294 | if (act_im)
|
---|
295 | {
|
---|
296 | delete act_im;
|
---|
297 | act_im = 0;
|
---|
298 | }
|
---|
299 |
|
---|
300 | if (press_im)
|
---|
301 | {
|
---|
302 | delete press_im;
|
---|
303 | press_im = 0;
|
---|
304 | }
|
---|
305 | }
|
---|
306 |
|
---|
307 | char *name() { return "g1_build_but"; }
|
---|
308 |
|
---|
309 | virtual void parent_draw(i4_draw_context_class &context)
|
---|
310 | {
|
---|
311 | if (pressed)
|
---|
312 | press_im->put_image(local_image, 0,0, context);
|
---|
313 | else if (active)
|
---|
314 | act_im->put_image(local_image, 0,0, context);
|
---|
315 | else
|
---|
316 | norm_im->put_image(local_image, 0,0, context);
|
---|
317 |
|
---|
318 | i4_parent_window_class::parent_draw(context); // skip button draw
|
---|
319 | }
|
---|
320 |
|
---|
321 | void do_idle()
|
---|
322 | {
|
---|
323 | if (context_help_window.get()) return ;
|
---|
324 |
|
---|
325 | i4_str *fn=i4gets("object_logo_fmt").sprintf(100,object_name);
|
---|
326 | i4_file_class *fp=i4_open(*fn);
|
---|
327 | delete fn;
|
---|
328 |
|
---|
329 | i4_image_class *im=0;
|
---|
330 | if (fp)
|
---|
331 | {
|
---|
332 | im=i4_load_image(fp);
|
---|
333 | delete fp;
|
---|
334 | }
|
---|
335 |
|
---|
336 | context_help_window=new g1_object_stats_window_class(object_name, im, style);
|
---|
337 | i4_current_app->get_root_window()->add_child(x(), y()+height()+5, context_help_window.get());
|
---|
338 | }
|
---|
339 |
|
---|
340 | };
|
---|
341 |
|
---|
342 | void g1_add_build_buttons(i4_parent_window_class *parent, i4_event_handler_class *send_to,
|
---|
343 | int build_first, int active_first)
|
---|
344 | {
|
---|
345 |
|
---|
346 | }
|
---|
347 |
|
---|
348 |
|
---|
349 | void g1_border_frame_class::relocate(i4_parent_window_class *w, char *loc,
|
---|
350 | int dx, int dy)
|
---|
351 | {
|
---|
352 | i4_window_class *wins[6]={g1_lives.get(), g1_money.get(), g1_main.get(),
|
---|
353 | g1_missiles.get(), g1_chain.get(), g1_health.get() };
|
---|
354 |
|
---|
355 | int i=0;
|
---|
356 | for (li_object *o=li_get_value(loc); o; o=li_cdr(o,0), i++)
|
---|
357 | {
|
---|
358 | li_object *v=li_car(o,0);
|
---|
359 | int x=li_get_int(li_first(v,0),0), y=li_get_int(li_second(v,0),0);
|
---|
360 |
|
---|
361 | if (wins[i])
|
---|
362 | {
|
---|
363 | if (wins[i]->get_parent())
|
---|
364 | wins[i]->get_parent()->remove_child(wins[i]);
|
---|
365 |
|
---|
366 | w->add_child(x+dx,y+dy, wins[i]);
|
---|
367 | }
|
---|
368 | }
|
---|
369 |
|
---|
370 |
|
---|
371 |
|
---|
372 |
|
---|
373 | }
|
---|
374 |
|
---|
375 | int g1_border_frame_class::border_x()
|
---|
376 | {
|
---|
377 | return width()/2-frame->width()/2;
|
---|
378 | }
|
---|
379 |
|
---|
380 | int g1_border_frame_class::border_y()
|
---|
381 | {
|
---|
382 | return height()-frame->height();
|
---|
383 | }
|
---|
384 |
|
---|
385 | g1_border_frame_class::g1_border_frame_class()
|
---|
386 | : i4_color_window_class(i4_current_app->get_window_manager()->width(),
|
---|
387 | i4_current_app->get_window_manager()->height(), 0,
|
---|
388 | i4_current_app->get_style())
|
---|
389 | {
|
---|
390 | frame=i4_load_image("bitmaps/stank/status_bar.jpg");
|
---|
391 | refresh=REFRESH_ALL;
|
---|
392 |
|
---|
393 | mouse_grabbed=i4_F;
|
---|
394 | strategy_window=0;
|
---|
395 | shrink=0;
|
---|
396 |
|
---|
397 |
|
---|
398 | g1_money=new g1_amount_display_class(63,13);
|
---|
399 | g1_health=new g1_amount_display_class("reactive");
|
---|
400 | g1_lives=new g1_amount_display_class("strategy_lives");
|
---|
401 | g1_chain=new g1_amount_display_class("minigun");
|
---|
402 | g1_missiles=new g1_amount_display_class("guided");
|
---|
403 | g1_main=new g1_amount_display_class("120mm");
|
---|
404 |
|
---|
405 |
|
---|
406 | set_cursor(0);
|
---|
407 |
|
---|
408 |
|
---|
409 | // create the main 3d view window
|
---|
410 | r1_render_window_class *rwin;
|
---|
411 | r1_expand_type expand=(r1_expand_type) g1_resources.render_window_expand_mode;
|
---|
412 |
|
---|
413 | int cw=width(), ch=height()-frame->height();
|
---|
414 | rwin=g1_render.r_api->create_render_window(cw,ch, expand);
|
---|
415 |
|
---|
416 | g1_object_controller_class *view=new g1_object_controller_class(cw,ch, style);
|
---|
417 |
|
---|
418 | g1_current_controller=view;
|
---|
419 |
|
---|
420 | rwin->add_child(0,0, view);
|
---|
421 |
|
---|
422 | add_child(0, 0, rwin);
|
---|
423 | controller_window=rwin;
|
---|
424 | strategy_on_top=i4_F;
|
---|
425 |
|
---|
426 | view->view.view_mode=G1_ACTION_MODE;
|
---|
427 | i4_key_man.set_context("action");
|
---|
428 |
|
---|
429 |
|
---|
430 | relocate(this, "action_mode_locations", border_x(), border_y());
|
---|
431 | }
|
---|
432 |
|
---|
433 |
|
---|
434 | void g1_border_frame_class::reparent(i4_image_class *draw_area, i4_parent_window_class *parent)
|
---|
435 | {
|
---|
436 | i4_parent_window_class::reparent(draw_area, parent);
|
---|
437 | if (parent)
|
---|
438 | set_strategy_on_top(i4_F);
|
---|
439 |
|
---|
440 | if (g1_current_controller.get())
|
---|
441 | g1_current_controller->view.view_mode=G1_ACTION_MODE;
|
---|
442 |
|
---|
443 | i4_key_man.set_context("action");
|
---|
444 | }
|
---|
445 |
|
---|
446 | void g1_border_frame_class::set_strategy_on_top(i4_bool v)
|
---|
447 | {
|
---|
448 | strategy_on_top=v;
|
---|
449 |
|
---|
450 | if (!v && !mouse_grabbed)
|
---|
451 | {
|
---|
452 | // i4_current_app->get_display()->set_mouse_raw_mode(i4_T);
|
---|
453 | mouse_grabbed=i4_T;
|
---|
454 | }
|
---|
455 |
|
---|
456 | if (parent)
|
---|
457 | {
|
---|
458 | i4_window_request_key_grab_class kgrab(this);
|
---|
459 | i4_kernel.send_event(parent, &kgrab);
|
---|
460 | }
|
---|
461 | }
|
---|
462 |
|
---|
463 |
|
---|
464 | void g1_border_frame_class::receive_event(i4_event *ev)
|
---|
465 | {
|
---|
466 | CAST_PTR(uev, i4_user_message_event_class, ev);
|
---|
467 | if (ev->type()==i4_event::USER_MESSAGE)
|
---|
468 | {
|
---|
469 | int t=uev->sub_type;
|
---|
470 |
|
---|
471 | if (t==OPTIONS)
|
---|
472 | {
|
---|
473 | // g1_sound_man.que_narative(g1_purchase_button_click_wav);
|
---|
474 | if (!g1_options_window.get())
|
---|
475 | {
|
---|
476 | g1_options_window=new g1_option_window(style);
|
---|
477 | add_child(-g1_options_window->width(), 0, g1_options_window.get());
|
---|
478 | }
|
---|
479 | else
|
---|
480 | {
|
---|
481 | i4_user_message_event_class uev(g1_option_window::SLIDE_AWAY);
|
---|
482 | i4_kernel.send_event(g1_options_window.get(), &uev);
|
---|
483 | }
|
---|
484 | }
|
---|
485 | }
|
---|
486 | else if (ev->type()==i4_event::MOUSE_MOVE)
|
---|
487 | {
|
---|
488 | if (!strategy_on_top)
|
---|
489 | {
|
---|
490 | CAST_PTR(mev,i4_mouse_move_event_class,ev);
|
---|
491 | i4_float heh;
|
---|
492 | heh = (((sw32)mev->y - (sw32)mev->ly)*0.01);
|
---|
493 | g1_human->mouse_look_increment_y += heh;
|
---|
494 |
|
---|
495 | heh = (((sw32)mev->x - (sw32)mev->lx)*0.01);
|
---|
496 | g1_human->mouse_look_increment_x += heh;
|
---|
497 | }
|
---|
498 |
|
---|
499 | i4_parent_window_class::receive_event(ev);
|
---|
500 | }
|
---|
501 | else if (ev->type()==i4_event::KEY_PRESS || ev->type()==i4_event::WINDOW_MESSAGE)
|
---|
502 | g1_input.receive_event(ev);
|
---|
503 | else
|
---|
504 | i4_parent_window_class::receive_event(ev);
|
---|
505 |
|
---|
506 | }
|
---|
507 |
|
---|
508 | void g1_border_frame_class::draw(i4_draw_context_class &context)
|
---|
509 | {
|
---|
510 | if (g1_render.main_draw)
|
---|
511 | i4_parent_window_class::draw(context);
|
---|
512 | }
|
---|
513 |
|
---|
514 |
|
---|
515 | void g1_border_frame_class::parent_draw(i4_draw_context_class &context)
|
---|
516 | {
|
---|
517 | pf_border_draw.start();
|
---|
518 |
|
---|
519 |
|
---|
520 | i4_color_window_class::parent_draw(context);
|
---|
521 |
|
---|
522 | if (!g1_map_is_loaded())
|
---|
523 | return ;
|
---|
524 |
|
---|
525 |
|
---|
526 | if ((refresh & REFRESH_FRAME) || !undrawn_area.empty())
|
---|
527 | {
|
---|
528 | if (frame)
|
---|
529 | frame->put_image(local_image, border_x(), border_y(), context);
|
---|
530 |
|
---|
531 | refresh |= REFRESH_ALL;
|
---|
532 | }
|
---|
533 |
|
---|
534 |
|
---|
535 | i4_window_class::draw(context);
|
---|
536 | refresh=0;
|
---|
537 |
|
---|
538 | pf_border_draw.stop();
|
---|
539 | }
|
---|
540 |
|
---|
541 |
|
---|
542 | static int first_start=1;
|
---|
543 | static int first_strategy=1;
|
---|
544 |
|
---|
545 |
|
---|
546 | void g1_border_frame_class::update() // check for changes in the game
|
---|
547 | {
|
---|
548 | if (first_start)
|
---|
549 | {
|
---|
550 | first_start=0;
|
---|
551 | press_tab_to_switch_to_strategy_mode.play();
|
---|
552 | }
|
---|
553 |
|
---|
554 |
|
---|
555 | if (!g1_map_is_loaded())
|
---|
556 | return ;
|
---|
557 |
|
---|
558 | g1_player_info_class *p=g1_player_man.get_local();
|
---|
559 |
|
---|
560 |
|
---|
561 | g1_money->update(p->money());
|
---|
562 | g1_lives->update(p->num_stank_lives(), 5);
|
---|
563 |
|
---|
564 |
|
---|
565 | g1_player_piece_class *stank=p->get_commander();
|
---|
566 | if (stank)
|
---|
567 | {
|
---|
568 | g1_main->update(stank->ammo[0].amount, stank->ammo[0].ammo_type->max_amount);
|
---|
569 | g1_missiles->update(stank->ammo[1].amount, stank->ammo[1].ammo_type->max_amount);
|
---|
570 | g1_chain->update(stank->ammo[2].amount, stank->ammo[2].ammo_type->max_amount);
|
---|
571 | g1_health->update(stank->health, stank->ammo[3].ammo_type->max_amount);
|
---|
572 | }
|
---|
573 |
|
---|
574 |
|
---|
575 | if (g1_current_controller.get() && strategy_on_top)
|
---|
576 | {
|
---|
577 | // so that sound will work...
|
---|
578 | i4_transform_class transform;
|
---|
579 | g1_current_controller->view.calc_transform(transform);
|
---|
580 | }
|
---|
581 |
|
---|
582 | }
|
---|
583 |
|
---|
584 |
|
---|
585 | g1_border_frame_class::~g1_border_frame_class()
|
---|
586 | {
|
---|
587 | if (frame)
|
---|
588 | {
|
---|
589 | delete frame;
|
---|
590 | frame = 0;
|
---|
591 | }
|
---|
592 |
|
---|
593 | if (mouse_grabbed)
|
---|
594 | {
|
---|
595 | // i4_current_app->get_display()->set_mouse_raw_mode(i4_F);
|
---|
596 | mouse_grabbed=i4_F;
|
---|
597 | }
|
---|
598 | }
|
---|
599 |
|
---|
600 |
|
---|
601 |
|
---|
602 |
|
---|
603 |
|
---|
604 |
|
---|
605 | g1_help_screen_class::g1_help_screen_class(w16 w, w16 h,
|
---|
606 | i4_graphical_style_class *style,
|
---|
607 | const i4_const_str &image_name,
|
---|
608 | w32 mess_id_to_send)
|
---|
609 | : i4_parent_window_class(w,h),
|
---|
610 | mess_id_to_send(mess_id_to_send)
|
---|
611 |
|
---|
612 | {
|
---|
613 | help=i4_load_image(image_name);
|
---|
614 |
|
---|
615 | }
|
---|
616 |
|
---|
617 |
|
---|
618 | void g1_help_screen_class::parent_draw(i4_draw_context_class &context)
|
---|
619 | {
|
---|
620 | if (help)
|
---|
621 | help->put_image(local_image, 0,0, context);
|
---|
622 | }
|
---|
623 |
|
---|
624 | void g1_help_screen_class::receive_event(i4_event *ev)
|
---|
625 | {
|
---|
626 | if (ev->type()==i4_event::MOUSE_BUTTON_DOWN || ev->type()==i4_event::KEY_PRESS)
|
---|
627 | {
|
---|
628 | i4_user_message_event_class u(mess_id_to_send);
|
---|
629 | i4_kernel.send_event(i4_current_app, &u);
|
---|
630 | }
|
---|
631 | }
|
---|
632 |
|
---|
633 | g1_help_screen_class::~g1_help_screen_class()
|
---|
634 | {
|
---|
635 | if (help)
|
---|
636 | delete help;
|
---|
637 | }
|
---|
638 |
|
---|
639 |
|
---|
640 | w32 g1_get_upgrade_color(int upgrade_level) // used for font colors & border edges
|
---|
641 | {
|
---|
642 | upgrade_level++;
|
---|
643 | li_object *o=li_get_value("upgrade_colors");
|
---|
644 | while (li_cdr(o,0) && upgrade_level)
|
---|
645 | {
|
---|
646 | upgrade_level--;
|
---|
647 | o=li_cdr(o,0);
|
---|
648 | }
|
---|
649 |
|
---|
650 | return li_get_int(li_car(o,0),0);
|
---|
651 | }
|
---|
652 |
|
---|
653 |
|
---|
654 | li_object *g1_redraw(li_object *o, li_environment *env)
|
---|
655 | {
|
---|
656 | if (g1_current_controller.get())
|
---|
657 | g1_current_controller->request_redraw(i4_F);
|
---|
658 | return 0;
|
---|
659 | }
|
---|
660 |
|
---|
661 | li_object *g1_redraw_all(li_object *o, li_environment *env)
|
---|
662 | {
|
---|
663 | if (g1_current_controller.get())
|
---|
664 | g1_current_controller->request_redraw(i4_F);
|
---|
665 | return 0;
|
---|
666 | }
|
---|
667 |
|
---|
668 | li_automatic_add_function(g1_redraw, "redraw");
|
---|
669 | li_automatic_add_function(g1_redraw_all, "redraw_all");
|
---|
670 |
|
---|
671 |
|
---|
672 | li_object *g1_strategy_on_top(li_object *o, li_environment *env)
|
---|
673 | {
|
---|
674 | if (first_strategy)
|
---|
675 | {
|
---|
676 | first_strategy=0;
|
---|
677 | press_tab_to_switch_to_action_mode.play();
|
---|
678 | g1_current_controller->scroll_message(i4gets("switch_to_action"));
|
---|
679 | }
|
---|
680 |
|
---|
681 |
|
---|
682 | if (!g1_border.get() || g1_border->strategy_on_top)
|
---|
683 | return 0;
|
---|
684 |
|
---|
685 | if (g1_border->mouse_grabbed)
|
---|
686 | {
|
---|
687 | // i4_current_app->get_display()->set_mouse_raw_mode(i4_F);
|
---|
688 | g1_border->mouse_grabbed=i4_F;
|
---|
689 | }
|
---|
690 |
|
---|
691 | g1_border->add_child(0,0, g1_strategy_screen.get());
|
---|
692 |
|
---|
693 | g1_border->remove_child(g1_border->controller_window);
|
---|
694 | g1_strategy_screen->add_child(0,0, g1_border->controller_window);
|
---|
695 |
|
---|
696 | g1_demo_script_add("(strategy_on_top)");
|
---|
697 | g1_border->set_strategy_on_top(i4_T);
|
---|
698 |
|
---|
699 | g1_border->resize_controller(0);
|
---|
700 |
|
---|
701 | g1_current_controller->view.view_mode=G1_STRATEGY_MODE;
|
---|
702 | i4_key_man.set_context("strategy");
|
---|
703 |
|
---|
704 |
|
---|
705 | g1_border->relocate(g1_strategy_screen.get(), "strategy_mode_locations",
|
---|
706 | g1_strategy_screen->border_x(),
|
---|
707 | g1_strategy_screen->border_y());
|
---|
708 |
|
---|
709 | return 0;
|
---|
710 | }
|
---|
711 |
|
---|
712 |
|
---|
713 | li_object *g1_strategy_on_bottom(li_object *o, li_environment *env)
|
---|
714 | {
|
---|
715 | if (!g1_border.get() || !g1_border->strategy_on_top)
|
---|
716 | return 0;
|
---|
717 |
|
---|
718 | g1_demo_script_add("(strategy_on_bottom)");
|
---|
719 | i4_window_class *cw=g1_border->controller_window;
|
---|
720 |
|
---|
721 |
|
---|
722 | g1_border->remove_child(g1_strategy_screen.get());
|
---|
723 |
|
---|
724 |
|
---|
725 |
|
---|
726 |
|
---|
727 | g1_strategy_screen->remove_child(g1_border->controller_window);
|
---|
728 | g1_border->add_child(0,0, g1_border->controller_window);
|
---|
729 |
|
---|
730 | g1_border->set_strategy_on_top(i4_F);
|
---|
731 | g1_border->resize_controller(0);
|
---|
732 |
|
---|
733 | g1_current_controller->view.view_mode=G1_ACTION_MODE;
|
---|
734 | i4_key_man.set_context("action");
|
---|
735 |
|
---|
736 | g1_border->relocate(g1_border.get(), "action_mode_locations",
|
---|
737 | g1_border->border_x(),
|
---|
738 | g1_border->border_y());
|
---|
739 |
|
---|
740 |
|
---|
741 | return 0;
|
---|
742 | }
|
---|
743 |
|
---|
744 | li_object *g1_strategy_toggle(li_object *o, li_environment *env)
|
---|
745 | {
|
---|
746 | if (g1_border.get())
|
---|
747 | if (g1_border->strategy_on_top)
|
---|
748 | g1_strategy_on_bottom(0,0);
|
---|
749 | else
|
---|
750 | g1_strategy_on_top(0,0);
|
---|
751 | return 0;
|
---|
752 |
|
---|
753 | }
|
---|
754 |
|
---|
755 | int g1_strategy_screen_class::border_x()
|
---|
756 | {
|
---|
757 | return width()-frame->width();
|
---|
758 | }
|
---|
759 |
|
---|
760 | int g1_strategy_screen_class::border_y()
|
---|
761 | {
|
---|
762 | return height()-frame->height();
|
---|
763 | }
|
---|
764 |
|
---|
765 |
|
---|
766 | void g1_strategy_screen_class::parent_draw(i4_draw_context_class &context)
|
---|
767 | {
|
---|
768 | i4_color_window_class::parent_draw(context);
|
---|
769 | if (!frame)
|
---|
770 | return ;
|
---|
771 |
|
---|
772 |
|
---|
773 | frame->put_image(local_image, border_x(), border_y(), context);
|
---|
774 | }
|
---|
775 |
|
---|
776 | g1_strategy_screen_class::g1_strategy_screen_class()
|
---|
777 | : build_buttons(0,16),
|
---|
778 | i4_color_window_class(i4_current_app->get_window_manager()->width(),
|
---|
779 | i4_current_app->get_window_manager()->height(),
|
---|
780 | 0,
|
---|
781 | i4_current_app->get_style())
|
---|
782 | {
|
---|
783 | shrink=0;
|
---|
784 | frame=i4_load_image("bitmaps/options/strategy_layout.jpg");
|
---|
785 |
|
---|
786 | i4_window_class *strategy_window;
|
---|
787 |
|
---|
788 | int rw=frame->width(), rh=height()-frame->height();
|
---|
789 |
|
---|
790 | strategy_window=g1_create_radar_view(rw,
|
---|
791 | rh,
|
---|
792 | G1_RADAR_DRAW_UNHIDDEN_PATHS |
|
---|
793 | G1_RADAR_CLICK_SELECTS_PATH |
|
---|
794 | G1_RADAR_INTERLACED |
|
---|
795 | G1_RADAR_USE_ICONS);
|
---|
796 | add_child(width() - rw, 0, strategy_window);
|
---|
797 |
|
---|
798 | if (g1_map_is_loaded())
|
---|
799 | create_build_buttons();
|
---|
800 |
|
---|
801 |
|
---|
802 | }
|
---|
803 |
|
---|
804 |
|
---|
805 | void g1_strategy_screen_class::create_build_buttons()
|
---|
806 | {
|
---|
807 | for (int i=0; i<build_buttons.size(); i++)
|
---|
808 | {
|
---|
809 | remove_child(build_buttons[i]);
|
---|
810 | delete build_buttons[i];
|
---|
811 | }
|
---|
812 |
|
---|
813 | build_buttons.uninit();
|
---|
814 |
|
---|
815 |
|
---|
816 | i4_image_class *build_back=i4_load_image("bitmaps/build/build_button.tga");
|
---|
817 | i4_image_class *build_active=i4_load_image("bitmaps/build/build_button_highlight.tga");
|
---|
818 | i4_image_class *build_selected=i4_load_image("bitmaps/build/build_button_select.tga");
|
---|
819 |
|
---|
820 | int x1=g1_resources.build_buttons.x1, y1=g1_resources.build_buttons.y1,
|
---|
821 | x2=g1_resources.build_buttons.x2, y2=g1_resources.build_buttons.y2;
|
---|
822 |
|
---|
823 | int x=x1, y=y1;
|
---|
824 | int max_line_height=build_back->height();
|
---|
825 | int bw=build_back->width();
|
---|
826 |
|
---|
827 | for (li_object *o=li_get_value("player_buildable"); o; o=li_cdr(o,0))
|
---|
828 | {
|
---|
829 | int type=g1_get_object_type(li_symbol::get(li_car(o,0),0));
|
---|
830 |
|
---|
831 | if (g1_object_type_array[type] &&
|
---|
832 | g1_object_type_array[type]->defaults &&
|
---|
833 | g1_object_type_array[type]->defaults->cost)
|
---|
834 | {
|
---|
835 | i4_event_reaction_class *re=new i4_event_reaction_class(this, BUILD+type);
|
---|
836 | i4_event_reaction_class *cost_re=new i4_event_reaction_class(this, ACTIVE+type);
|
---|
837 |
|
---|
838 |
|
---|
839 | g1_build_but *b = new g1_build_but(g1_object_type_array[type]->name(), re, cost_re,
|
---|
840 | i4_current_app->get_style(),
|
---|
841 | build_back, build_active, build_selected);
|
---|
842 | build_buttons.add(b);
|
---|
843 |
|
---|
844 | b->set_popup(i4_T);
|
---|
845 |
|
---|
846 | if (x+bw > x2)
|
---|
847 | {
|
---|
848 | x=x1;
|
---|
849 | y+=max_line_height;
|
---|
850 | }
|
---|
851 |
|
---|
852 | add_child(x,y,b);
|
---|
853 |
|
---|
854 | x+=bw;
|
---|
855 | }
|
---|
856 | }
|
---|
857 |
|
---|
858 |
|
---|
859 | // add blank buttons for the rest to even out the screen
|
---|
860 | while (x+bw<=x2)
|
---|
861 | {
|
---|
862 | i4_event_reaction_class *re=new i4_event_reaction_class(this, 0xffff);
|
---|
863 | g1_build_but *b = new g1_build_but("no_vehicle", re, 0,
|
---|
864 | i4_current_app->get_style(),
|
---|
865 | build_back, build_active, build_selected);
|
---|
866 | build_buttons.add(b);
|
---|
867 | b->set_popup(i4_T);
|
---|
868 | add_child(x,y,b);
|
---|
869 | x+=bw;
|
---|
870 | }
|
---|
871 |
|
---|
872 |
|
---|
873 | delete build_back;
|
---|
874 | delete build_active;
|
---|
875 | delete build_selected;
|
---|
876 |
|
---|
877 |
|
---|
878 | }
|
---|
879 |
|
---|
880 |
|
---|
881 | void g1_strategy_screen_class::receive_event(i4_event *ev)
|
---|
882 | {
|
---|
883 | if (ev->type()==i4_event::USER_MESSAGE)
|
---|
884 | {
|
---|
885 | CAST_PTR(uev, i4_user_message_event_class, ev);
|
---|
886 | int t=uev->sub_type;
|
---|
887 |
|
---|
888 | if (t>=BUILD && t<ACTIVE)
|
---|
889 | g1_human->build_unit((g1_object_type)(t-BUILD));
|
---|
890 | else if (t>ACTIVE)
|
---|
891 | {
|
---|
892 | t-=ACTIVE;
|
---|
893 | if (g1_object_type_array[t])
|
---|
894 | {
|
---|
895 | // last.cost=g1_object_type_array[t]->defaults->cost;
|
---|
896 | // refresh|=REFRESH_COST;
|
---|
897 | }
|
---|
898 | }
|
---|
899 |
|
---|
900 | if (t==OPTIONS)
|
---|
901 | {
|
---|
902 | if (!g1_options_window.get())
|
---|
903 | {
|
---|
904 | g1_options_window=new g1_option_window(i4_current_app->get_style());
|
---|
905 | add_child(-g1_options_window->width(),
|
---|
906 | height()-g1_options_window->height(),
|
---|
907 | g1_options_window.get());
|
---|
908 | }
|
---|
909 | else
|
---|
910 | {
|
---|
911 | i4_user_message_event_class uev(g1_option_window::SLIDE_AWAY);
|
---|
912 | i4_kernel.send_event(g1_options_window.get(), &uev);
|
---|
913 | }
|
---|
914 | }
|
---|
915 |
|
---|
916 | }
|
---|
917 | else i4_parent_window_class::receive_event(ev);
|
---|
918 | }
|
---|
919 |
|
---|
920 | enum {xa=20, ya=10 };
|
---|
921 |
|
---|
922 | void g1_border_frame_class::resize_controller(int shrink_add)
|
---|
923 | {
|
---|
924 | if (!g1_border->strategy_on_top)
|
---|
925 | {
|
---|
926 | shrink+=shrink_add;
|
---|
927 |
|
---|
928 | int cw=width()-shrink*2;
|
---|
929 | int ch=height()-frame->height()-shrink*2;
|
---|
930 |
|
---|
931 | remove_child(controller_window);
|
---|
932 | controller_window->resize(cw,ch);
|
---|
933 | add_child(width()/2-cw/2, (height()-frame->height())/2-ch/2, controller_window);
|
---|
934 | }
|
---|
935 | else
|
---|
936 | {
|
---|
937 | int s=g1_strategy_screen->shrink;
|
---|
938 | s+=shrink_add;
|
---|
939 | g1_strategy_screen->shrink=s;
|
---|
940 |
|
---|
941 | int cw=width()-g1_strategy_screen->frame->width()-s*2;
|
---|
942 | int ch=height()-s*2;
|
---|
943 |
|
---|
944 |
|
---|
945 | g1_strategy_screen->remove_child(controller_window);
|
---|
946 | controller_window->resize(cw,ch);
|
---|
947 | g1_strategy_screen->add_child((width()-g1_strategy_screen->frame->width())/2-cw/2,
|
---|
948 | height()/2-ch/2, controller_window);
|
---|
949 | }
|
---|
950 | }
|
---|
951 |
|
---|
952 |
|
---|
953 | li_object *g1_shrink_screen(li_object *o, li_environment *env)
|
---|
954 | {
|
---|
955 | if (!g1_border.get())
|
---|
956 | return 0;
|
---|
957 |
|
---|
958 |
|
---|
959 |
|
---|
960 | if (!g1_border->strategy_on_top)
|
---|
961 | {
|
---|
962 | if (g1_border->width()-g1_border->shrink*2>80)
|
---|
963 | g1_border->resize_controller(xa);
|
---|
964 | }
|
---|
965 | else
|
---|
966 | {
|
---|
967 | if (g1_strategy_screen->width()-g1_strategy_screen->shrink*2>80)
|
---|
968 | g1_border->resize_controller(xa);
|
---|
969 |
|
---|
970 | }
|
---|
971 | return 0;
|
---|
972 | }
|
---|
973 |
|
---|
974 |
|
---|
975 |
|
---|
976 |
|
---|
977 | li_object *g1_grow_screen(li_object *o, li_environment *env)
|
---|
978 | {
|
---|
979 | if (!g1_border.get())
|
---|
980 | return 0;
|
---|
981 |
|
---|
982 | int xa=20, ya=10;
|
---|
983 |
|
---|
984 | if (!g1_border->strategy_on_top)
|
---|
985 | {
|
---|
986 | if (g1_border->shrink-xa>=0)
|
---|
987 | g1_border->resize_controller(-xa);
|
---|
988 | }
|
---|
989 | else
|
---|
990 | {
|
---|
991 | if (g1_strategy_screen->shrink-xa>=0)
|
---|
992 | g1_border->resize_controller(-xa);
|
---|
993 | }
|
---|
994 | return 0;
|
---|
995 | }
|
---|
996 |
|
---|
997 |
|
---|
998 | li_automatic_add_function(g1_strategy_on_top, "strategy_on_top");
|
---|
999 | li_automatic_add_function(g1_strategy_on_bottom, "strategy_on_bottom");
|
---|
1000 | li_automatic_add_function(g1_strategy_toggle, "strategy_toggle");
|
---|
1001 |
|
---|
1002 | li_automatic_add_function(g1_shrink_screen, "shrink_screen");
|
---|
1003 | li_automatic_add_function(g1_grow_screen, "grow_screen");
|
---|
1004 |
|
---|
1005 |
|
---|