00001
00002
00003
00004
00005
00006 #include "lcconfig.h"
00007 #include <stdio.h>
00008 #include <stdlib.h>
00009 #include "lcstring.h"
00010 #include <ctype.h>
00011 #include "common.h"
00012 #include "lctypes.h"
00013 #include "fileutil.h"
00014 #include "lin-city.h"
00015 #include "lchelp.h"
00016 #include "mouse.h"
00017 #include "geometry.h"
00018 #include "lcintl.h"
00019 #include "module_buttons.h"
00020 #include "screen.h"
00021
00022
00023
00024
00025
00026
00027
00028
00029 void
00030 activate_help (char *hp)
00031 {
00032 help_flag = 1;
00033 help_history_count = 0;
00034 help_return_val = 0;
00035 #ifdef USE_EXPANDED_FONT
00036 Fgl_setwritemode (WRITEMODE_MASKED | FONT_EXPANDED);
00037 #else
00038 Fgl_setfontcolors (HELPBACKGROUNDCOLOUR, TEXT_FG_COLOUR);
00039 #endif
00040 draw_help_page (hp);
00041 }
00042
00043 void
00044 do_help_mouse (int x, int y, int mbutton)
00045 {
00046 Rect* mw = &scr.main_win;
00047 if (mouse_in_rect(mw, x, y)) {
00048 do_help_buttons (x, y);
00049 return;
00050 }
00051 if (block_help_exit)
00052 return;
00053
00054 help_flag = 0;
00055 #ifdef USE_EXPANDED_FONT
00056 Fgl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED);
00057 #else
00058 Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
00059 #endif
00060 refresh_main_screen ();
00061 }
00062
00063 void
00064 draw_help_page (char *helppage)
00065 {
00066 Rect* mw = &scr.main_win;
00067 char *helppage_full, *helppage_short;
00068 int i, y;
00069 FILE *inf;
00070 char help_line[MAX_HELP_LINE];
00071
00072
00073 #if defined (commentout)
00074 if ((strcmp (helppage, "opening.hlp") == 0)
00075 && (strcmp (help_button_history[help_history_count - 1],
00076 "ask-dir.hlp") == 0)) {
00077 make_dir_ok_flag = 1;
00078 }
00079 #endif
00080
00081
00082
00083
00084
00085 if (strncmp (helppage, "return", 6) == 0) {
00086 sscanf (&(helppage[6]), "%d", &help_return_val);
00087
00088
00089 if (help_return_val == -1 && help_history_count > 1) {
00090 strcpy (helppage, help_button_history[help_history_count - 2]);
00091 help_history_count -= 2;
00092 goto continue_with_help;
00093 }
00094
00095
00096 if (help_history_count > 0 &&
00097 strcmp (help_button_history[help_history_count - 1],
00098 "res.tmp") == 0)
00099 {
00100 switch (help_return_val) {
00101 case (-2):
00102 case (-1):
00103 case (0):
00104 #if defined (commentout)
00105 case (1):
00106 selected_module_type = CST_RESIDENCE_LL;
00107 selected_module_cost = get_group_cost (GROUP_RESIDENCE_LL);
00108 break;
00109 case (2):
00110 selected_module_type = CST_RESIDENCE_ML;
00111 selected_module_cost = get_group_cost (GROUP_RESIDENCE_ML);
00112 break;
00113 case (3):
00114 selected_module_type = CST_RESIDENCE_HL;
00115 selected_module_cost = get_group_cost (GROUP_RESIDENCE_HL);
00116 break;
00117 case (4):
00118 selected_module_type = CST_RESIDENCE_LH;
00119 selected_module_cost = get_group_cost (GROUP_RESIDENCE_LH);
00120 break;
00121 case (5):
00122 selected_module_type = CST_RESIDENCE_MH;
00123 selected_module_cost = get_group_cost (GROUP_RESIDENCE_MH);
00124 break;
00125 case (6):
00126 selected_module_type = CST_RESIDENCE_HH;
00127 selected_module_cost = get_group_cost (GROUP_RESIDENCE_HH);
00128 break;
00129 #endif
00130 case (1):
00131 set_selected_module (CST_RESIDENCE_LL);
00132 break;
00133 case (2):
00134 set_selected_module (CST_RESIDENCE_ML);
00135 break;
00136 case (3):
00137 set_selected_module (CST_RESIDENCE_HL);
00138 break;
00139 case (4):
00140 set_selected_module (CST_RESIDENCE_LH);
00141 break;
00142 case (5):
00143 set_selected_module (CST_RESIDENCE_MH);
00144 break;
00145 case (6):
00146 set_selected_module (CST_RESIDENCE_HH);
00147 break;
00148 }
00149 }
00150 else if (help_history_count > 0 &&
00151 strcmp (help_button_history[help_history_count - 1],
00152 "menu.hlp") == 0)
00153 {
00154 switch (help_return_val) {
00155 case 1:
00156 save_flag = 1;
00157 break;
00158 case 2:
00159 prefs_flag = 1;
00160 break;
00161 case 3:
00162 quit_flag = 1;
00163 break;
00164 }
00165 }
00166 else if (help_history_count > 0 &&
00167 strcmp (help_button_history[help_history_count - 1],
00168 "opening.hlp") == 0)
00169 {
00170 switch (help_return_val)
00171 {
00172 case (-2):
00173 case (-1):
00174 case (0):
00175
00176 new_city (&main_screen_originx, &main_screen_originy, 1);
00177 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00178 break;
00179 case (1):
00180
00181 new_city (&main_screen_originx, &main_screen_originy, 0);
00182 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00183 break;
00184 case (2):
00185
00186 network_flag = 1;
00187 break;
00188 }
00189 }
00190 else if (help_history_count > 0 &&
00191 strcmp (help_button_history[help_history_count - 1],
00192 "newgame.hlp") == 0)
00193 {
00194 switch (help_return_val)
00195 {
00196 case (0):
00197
00198 new_city (&main_screen_originx, &main_screen_originy, 1);
00199 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00200 break;
00201 case (1):
00202
00203 new_city (&main_screen_originx, &main_screen_originy, 0);
00204 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00205 break;
00206 case (2):
00207
00208 network_flag = 1;
00209 break;
00210 }
00211 }
00212 else if (help_history_count > 0 &&
00213 strcmp (help_button_history[help_history_count - 1],
00214 "openload.hlp") == 0)
00215 {
00216 switch (help_return_val)
00217 {
00218 case (-2):
00219 case (-1):
00220 case (0):
00221 new_city (&main_screen_originx, &main_screen_originy, 1);
00222 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00223 break;
00224 case (1):
00225 redraw_mouse ();
00226 load_opening_city ("good_times.scn");
00227 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00228 hide_mouse ();
00229 break;
00230 case (2):
00231 load_opening_city ("bad_times.scn");
00232 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00233 break;
00234 case (9):
00235 load_flag = 1;
00236 break;
00237 }
00238 }
00239 else if (help_history_count > 0 &&
00240 strcmp (help_button_history[help_history_count - 1],
00241 "loadgame.hlp") == 0)
00242 {
00243 switch (help_return_val)
00244 {
00245 case (1):
00246 redraw_mouse ();
00247 load_opening_city ("good_times.scn");
00248 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00249 hide_mouse ();
00250 break;
00251 case (2):
00252 load_opening_city ("bad_times.scn");
00253 adjust_main_origin (main_screen_originx,main_screen_originy,0);
00254 break;
00255 case (9):
00256 load_flag = 1;
00257 break;
00258 }
00259 }
00260 #if defined (commentout)
00261 else if (help_history_count > 0 &&
00262 strcmp (help_button_history[help_history_count - 1],
00263 "ask-dir.hlp") == 0)
00264 {
00265 if (help_return_val == 1) {
00266
00267 do_error (_("Sorry, lincity cannot run without this directory. Exiting."));
00268 } else if (help_return_val == -2) {
00269
00270
00271
00272
00273 make_dir_ok_flag = 1;
00274 strcpy (helppage, "opening.hlp");
00275 goto continue_with_help;
00276 }
00277 }
00278 #endif
00279
00280 block_help_exit = 0;
00281 help_flag = 0;
00282
00283
00284 if (main_screen_flag == MAIN_SCREEN_EQUALS_MINI) {
00285 main_screen_flag = MAIN_SCREEN_NORMAL_FLAG;
00286 }
00287
00288
00289 #ifdef USE_EXPANDED_FONT
00290 Fgl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED);
00291 #else
00292 Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
00293 #endif
00294 refresh_main_screen ();
00295 return;
00296 }
00297
00298 continue_with_help:
00299
00300
00301
00302 if ((helppage_short = (char*) malloc (strlen(helppage) + 1)) == 0) {
00303 malloc_failure ();
00304 }
00305 strcpy (helppage_short, helppage);
00306
00307
00308 if (strncmp (helppage, "mini-screen.hlp", 15) == 0) {
00309 draw_big_mini_screen ();
00310 } else if (strncmp (helppage, "mini-in-main.hlp", 17) == 0) {
00311
00312 } else {
00313
00314
00315
00316 if ((helppage_full = (char *) malloc (lc_save_dir_len
00317 + strlen (help_path)
00318 + strlen(helppage) + 2)) == 0) {
00319 malloc_failure ();
00320 }
00321
00322
00323 sprintf (helppage_full, "%s%s", help_path, helppage);
00324 if ((inf = fopen (helppage_full, "r")) == 0) {
00325 sprintf (helppage_full, "%s%c%s", lc_save_dir,
00326 PATH_SLASH, helppage);
00327 if ((inf = fopen (helppage_full, "r")) == 0) {
00328 sprintf (helppage_full, "%s%s", help_path, HELPERRORPAGE);
00329 if ((inf = fopen (helppage_full, "r")) == 0)
00330 do_error ("Help error");
00331 }
00332 }
00333
00334
00335 numof_help_buttons = 0;
00336 Fgl_fillbox (mw->x, mw->y, mw->w, mw->h, HELPBACKGROUNDCOLOUR);
00337 while (feof (inf) == 0) {
00338 if (fgets (help_line, MAX_HELP_LINE, inf) == 0)
00339 break;
00340 undosify_string (help_line);
00341 parse_helpline (help_line);
00342 }
00343 fclose (inf);
00344
00345
00346 if (strncmp (helppage_short, "ask-dir.hlp", 11) == 0) {
00347 parse_helpline ("tcolour 0 255");
00348 y = 100;
00349 for (i = 0; i < askdir_lines; i++) {
00350 sprintf (help_line, "text -1 %d %s", y, askdir_path[i]);
00351 parse_helpline (help_line);
00352 y += 14;
00353 }
00354 }
00355 free (helppage_full);
00356 }
00357
00358
00359
00360 if (help_history_count > 0) {
00361 parse_helpline ("tcolour 122 153");
00362
00363 parse_helpline (_("tbutton 4 387 return-1 BACK"));
00364 }
00365 parse_helpline ("tcolour 188 153");
00366
00367 parse_helpline (_("tbutton 370 387 return-2 OUT"));
00368 parse_helpline ("tcolour -1 -1");
00369
00370
00371
00372 strcpy (help_button_history[help_history_count], helppage_short);
00373 help_history_count++;
00374 if (help_history_count >= MAX_HELP_HISTORY) {
00375 for (i = 0; i < (MAX_HELP_HISTORY - 1); i++)
00376 strcpy (help_button_history[i], help_button_history[i + 1]);
00377 help_history_count--;
00378 }
00379
00380 free (helppage_short);
00381 }
00382
00383 void
00384 refresh_help_page (void)
00385 {
00386 help_history_count -= 1;
00387 draw_help_page (help_button_history[help_history_count]);
00388 }
00389
00390 void
00391 parse_helpline (char *s)
00392 {
00393 if (strncmp (s, "text", 4) == 0)
00394 parse_textline (s);
00395 else if (strncmp (s, "icon", 4) == 0)
00396 parse_iconline (s);
00397 else if (strncmp (s, "button", 6) == 0)
00398 parse_buttonline (s);
00399 else if (strncmp (s, "tbutton", 7) == 0)
00400 parse_tbuttonline (s);
00401 else if (strncmp (s, "tcolour", 7) == 0)
00402 parse_tcolourline (s);
00403 }
00404
00405 void
00406 parse_tcolourline (char *st)
00407 {
00408 char s[100];
00409 int f, b;
00410 strcpy (s, st);
00411
00412 sscanf (s, "tcolour %d %d", &f, &b);
00413 if (f < 0 || b < 0)
00414 Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
00415 else
00416 Fgl_setfontcolors (b, f);
00417 }
00418
00419 void
00420 parse_textline (char *st)
00421 {
00422 Rect* mw = &scr.main_win;
00423 int i, j, x, y;
00424 sscanf (st, "text %d %d", &x, &y);
00425
00426 i = 0;
00427 for (j = 0; j < 3; j++)
00428 {
00429 while (isspace (st[i]) == 0)
00430 {
00431 if (st[i] == 0)
00432 return;
00433
00434 i++;
00435 }
00436 while (isspace (st[i]) != 0)
00437 {
00438 if (st[i] == 0)
00439 return;
00440 i++;
00441 }
00442 }
00443 st += i;
00444
00445 if (st[strlen (st) - 1] == 0xa)
00446 st[strlen (st) - 1] = 0;
00447 if (x < 0) {
00448
00449 x = (mw->w / 2) - (strlen (st) * 4);
00450 if (x < 0)
00451 return;
00452 } else {
00453
00454 x = x + (mw->w - 440) / 2;
00455 }
00456
00457 if ((int) (strlen (st) * 8) > (mw->w - x))
00458 return;
00459 Fgl_write (mw->x + x, mw->y + y, st);
00460 }
00461
00462
00463 void
00464 parse_iconline (char *st)
00465 {
00466 int i, j, x, y;
00467 sscanf (st, "icon %d %d", &x, &y);
00468
00469 i = 0;
00470 for (j = 0; j < 3; j++)
00471 {
00472 while (isspace (st[i]) == 0)
00473 {
00474 if (st[i] == 0)
00475 return;
00476 i++;
00477 }
00478 while (isspace (st[i]) != 0)
00479 {
00480 if (st[i] == 0)
00481 return;
00482 i++;
00483 }
00484 }
00485 st += i;
00486
00487 if (st[strlen (st) - 1] == 0xa)
00488 st[strlen (st) - 1] = 0;
00489 draw_help_icon (x, y, st);
00490 }
00491
00492 void
00493 draw_help_icon (int x, int y, char *icon)
00494 {
00495 Rect* mw = &scr.main_win;
00496 int i, l, w, h;
00497 char ss[LC_PATH_MAX];
00498 FILE *inf;
00499 strcpy (ss, graphic_path);
00500 strcat (ss, icon);
00501 if ((inf = fopen (ss, "rb")) == NULL) {
00502 return;
00503 }
00504 fseek (inf, 0L, SEEK_END);
00505 l = ftell (inf);
00506 fseek (inf, 0L, SEEK_SET);
00507 if (l == 256)
00508 w = h = 16;
00509 else if (l == 1024)
00510 w = h = 32;
00511 else if (l == 2304)
00512 w = h = 48;
00513 else if (l == 4096)
00514 w = h = 64;
00515 else
00516 {
00517 fclose (inf);
00518 return;
00519 }
00520 for (i = 0; i < l; i++)
00521 *(help_graphic + i) = fgetc (inf);
00522 fclose (inf);
00523
00524
00525 x = x + (mw->w - 440) / 2;
00526
00527 if (x > 0 && y > 0 && ((x + w) < mw->w) && ((y + h) < mw->h))
00528 Fgl_putbox (mw->x + x, mw->y + y, w, h, help_graphic);
00529 return;
00530 }
00531
00532 void
00533 parse_buttonline (char *st)
00534 {
00535 Rect* mw = &scr.main_win;
00536 int i, j, x, y, w, h;
00537 sscanf (st, "button %d %d %d %d", &x, &y, &w, &h);
00538
00539 i = 0;
00540 for (j = 0; j < 5; j++)
00541 {
00542 while (isspace (st[i]) == 0)
00543 {
00544 if (st[i] == 0)
00545 return;
00546
00547 i++;
00548 }
00549 while (isspace (st[i]) != 0)
00550 {
00551 if (st[i] == 0)
00552 return;
00553 i++;
00554 }
00555 }
00556 st += i;
00557
00558 if (st[strlen (st) - 1] == 0xa)
00559 st[strlen (st) - 1] = 0;
00560
00561 if (x < 0) {
00562
00563 x = (mw->w / 2) - (w / 2);
00564 if (x < 0)
00565 return;
00566 } else {
00567
00568 x = x + (mw->w - 440) / 2;
00569 }
00570
00571
00572 if ((x + w) > mw->w)
00573 return;
00574 if (numof_help_buttons >= MAX_NUMOF_HELP_BUTTONS)
00575 return;
00576 help_button_x[numof_help_buttons] = x + mw->x;
00577 help_button_y[numof_help_buttons] = y + mw->y;
00578 help_button_w[numof_help_buttons] = w;
00579 help_button_h[numof_help_buttons] = h;
00580 if (strlen (st) >= MAX_LENOF_HELP_FILENAME)
00581 return;
00582 strcpy (help_button_s[numof_help_buttons], st);
00583 numof_help_buttons++;
00584
00585 Fgl_hline (mw->x + x, mw->y + y,
00586 mw->x + x + w, HELPBUTTON_COLOUR);
00587 Fgl_hline (mw->x + x, mw->y + y + h,
00588 mw->x + x + w, HELPBUTTON_COLOUR);
00589 Fgl_line (mw->x + x, mw->y + y,
00590 mw->x + x, mw->y + y + h, HELPBUTTON_COLOUR);
00591 Fgl_line (mw->x + x + w, mw->y + y,
00592 mw->x + x + w, mw->y + y + h, HELPBUTTON_COLOUR);
00593 }
00594
00595 void
00596 do_help_buttons (int x, int y)
00597 {
00598 int i;
00599 if (numof_help_buttons <= 0)
00600 return;
00601 for (i = 0; i < numof_help_buttons; i++)
00602 if (x > help_button_x[i]
00603 && x < (help_button_x[i] + help_button_w[i])
00604 && y > help_button_y[i]
00605 && y < (help_button_y[i] + help_button_h[i]))
00606 {
00607 hide_mouse ();
00608 draw_help_page (help_button_s[i]);
00609 redraw_mouse ();
00610 break;
00611 }
00612 }
00613
00614 void
00615 parse_tbuttonline (char *st)
00616 {
00617 char s[100], ss[120], s1[100];
00618 int i, j, x, y;
00619 strcpy (s1, st);
00620
00621 sscanf (s1, "tbutton %d %d %s", &x, &y, s);
00622
00623 i = 0;
00624 for (j = 0; j < 4; j++) {
00625 while (isspace (st[i]) == 0) {
00626 if (st[i] == 0)
00627 return;
00628 i++;
00629 }
00630 while (isspace (st[i]) != 0) {
00631 if (st[i] == 0)
00632 return;
00633 i++;
00634 }
00635 }
00636 st += i;
00637
00638 if (st[strlen (st) - 1] == 0xa)
00639 st[strlen (st) - 1] = 0;
00640 if (x < 0)
00641 x -= 2;
00642
00643 sprintf (ss, "text %d %d ", x + 2, y + 2);
00644 strcat (ss, st);
00645 parse_textline (ss);
00646 sprintf (ss, "button %d %d %d %d %s", x, y, (strlen (st) * 8) + 4, 12, s);
00647 parse_buttonline (ss);
00648 }