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 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648
|
/* ---------------------------------------------------------------------- *
* lchelp.c
* This file is part of lincity.
* Lincity is copyright (c) I J Peters 1995-1997, (c) Greg Sharp 1997-2001.
* ---------------------------------------------------------------------- */
#include "lcconfig.h"
#include <stdio.h>
#include <stdlib.h>
#include "lcstring.h"
#include <ctype.h>
#include "common.h"
#include "lctypes.h"
#include "fileutil.h"
#include "lin-city.h"
#include "lchelp.h"
#include "mouse.h"
#include "geometry.h"
#include "lcintl.h"
#include "module_buttons.h"
#include "screen.h"
/* About help history:
History count starts at 0, but is immediately incremented to 1.
Current page is stored at help_button_history[help_history_count-1],
which is the top of the stack. When "back" is clicked, history count
is decremented by 2, and then incremented by one.
*/
void
activate_help (char *hp)
{
help_flag = 1;
help_history_count = 0;
help_return_val = 0;
#ifdef USE_EXPANDED_FONT
Fgl_setwritemode (WRITEMODE_MASKED | FONT_EXPANDED);
#else
Fgl_setfontcolors (HELPBACKGROUNDCOLOUR, TEXT_FG_COLOUR);
#endif
draw_help_page (hp);
}
void
do_help_mouse (int x, int y, int mbutton)
{
Rect* mw = &scr.main_win;
if (mouse_in_rect(mw, x, y)) {
do_help_buttons (x, y);
return;
}
if (block_help_exit)
return;
help_flag = 0;
#ifdef USE_EXPANDED_FONT
Fgl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED);
#else
Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
#endif
refresh_main_screen ();
}
void
draw_help_page (char *helppage)
{
Rect* mw = &scr.main_win;
char *helppage_full, *helppage_short;
int i, y;
FILE *inf;
char help_line[MAX_HELP_LINE];
/* In ask-dir page if user presses "yes" create directory in main loop */
#if defined (commentout)
if ((strcmp (helppage, "opening.hlp") == 0)
&& (strcmp (help_button_history[help_history_count - 1],
"ask-dir.hlp") == 0)) {
make_dir_ok_flag = 1;
}
#endif
/* Return pages have arguments. It is always true that "-2" means "Out"
and "-1" means "Back". Semantics for other arguments depend upon
the name of the source page (e.g. load game or choose residence).
Most of the times (except "Back"), this will exit the help system. */
if (strncmp (helppage, "return", 6) == 0) {
sscanf (&(helppage[6]), "%d", &help_return_val);
/* If "Back" was clicked */
if (help_return_val == -1 && help_history_count > 1) {
strcpy (helppage, help_button_history[help_history_count - 2]);
help_history_count -= 2;
goto continue_with_help;
}
/* XXX: WCK: residential selection is really ugly */
if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"res.tmp") == 0)
{
switch (help_return_val) {
case (-2):
case (-1):
case (0):
#if defined (commentout)
case (1):
selected_module_type = CST_RESIDENCE_LL;
selected_module_cost = get_group_cost (GROUP_RESIDENCE_LL);
break;
case (2):
selected_module_type = CST_RESIDENCE_ML;
selected_module_cost = get_group_cost (GROUP_RESIDENCE_ML);
break;
case (3):
selected_module_type = CST_RESIDENCE_HL;
selected_module_cost = get_group_cost (GROUP_RESIDENCE_HL);
break;
case (4):
selected_module_type = CST_RESIDENCE_LH;
selected_module_cost = get_group_cost (GROUP_RESIDENCE_LH);
break;
case (5):
selected_module_type = CST_RESIDENCE_MH;
selected_module_cost = get_group_cost (GROUP_RESIDENCE_MH);
break;
case (6):
selected_module_type = CST_RESIDENCE_HH;
selected_module_cost = get_group_cost (GROUP_RESIDENCE_HH);
break;
#endif
case (1):
set_selected_module (CST_RESIDENCE_LL);
break;
case (2):
set_selected_module (CST_RESIDENCE_ML);
break;
case (3):
set_selected_module (CST_RESIDENCE_HL);
break;
case (4):
set_selected_module (CST_RESIDENCE_LH);
break;
case (5):
set_selected_module (CST_RESIDENCE_MH);
break;
case (6):
set_selected_module (CST_RESIDENCE_HH);
break;
}
}
else if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"menu.hlp") == 0)
{
switch (help_return_val) {
case 1:
save_flag = 1;
break;
case 2:
prefs_flag = 1;
break;
case 3:
quit_flag = 1;
break;
}
}
else if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"opening.hlp") == 0)
{
switch (help_return_val)
{
case (-2):
case (-1):
case (0):
/* Random villiage */
new_city (&main_screen_originx, &main_screen_originy, 1);
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (1):
/* Bare board */
new_city (&main_screen_originx, &main_screen_originy, 0);
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (2):
/* Network start */
network_flag = 1;
break;
}
}
else if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"newgame.hlp") == 0)
{
switch (help_return_val)
{
case (0):
/* Random villiage */
new_city (&main_screen_originx, &main_screen_originy, 1);
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (1):
/* Bare board */
new_city (&main_screen_originx, &main_screen_originy, 0);
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (2):
/* Network start */
network_flag = 1;
break;
}
}
else if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"openload.hlp") == 0)
{
switch (help_return_val)
{
case (-2):
case (-1):
case (0):
new_city (&main_screen_originx, &main_screen_originy, 1);
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (1):
redraw_mouse ();
load_opening_city ("good_times.scn");
adjust_main_origin (main_screen_originx,main_screen_originy,0);
hide_mouse ();
break;
case (2):
load_opening_city ("bad_times.scn");
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (9):
load_flag = 1;
break;
}
}
else if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"loadgame.hlp") == 0)
{
switch (help_return_val)
{
case (1):
redraw_mouse ();
load_opening_city ("good_times.scn");
adjust_main_origin (main_screen_originx,main_screen_originy,0);
hide_mouse ();
break;
case (2):
load_opening_city ("bad_times.scn");
adjust_main_origin (main_screen_originx,main_screen_originy,0);
break;
case (9):
load_flag = 1;
break;
}
}
#if defined (commentout)
else if (help_history_count > 0 &&
strcmp (help_button_history[help_history_count - 1],
"ask-dir.hlp") == 0)
{
if (help_return_val == 1) {
/* Clicking "no" means no directory is created */
do_error (_("Sorry, lincity cannot run without this directory. Exiting."));
} else if (help_return_val == -2) {
/* Clicking "out" means we want to create directory,
and then go to opening screen. */
/* Warning: Note that "opening.hlp" is the same length
as "ask-dir.hlp". */
make_dir_ok_flag = 1;
strcpy (helppage, "opening.hlp");
goto continue_with_help;
}
}
#endif
block_help_exit = 0;
help_flag = 0;
/* GCS Remove overlay */
if (main_screen_flag == MAIN_SCREEN_EQUALS_MINI) {
main_screen_flag = MAIN_SCREEN_NORMAL_FLAG;
}
/* Fix origin */
#ifdef USE_EXPANDED_FONT
Fgl_setwritemode (WRITEMODE_OVERWRITE | FONT_EXPANDED);
#else
Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
#endif
refresh_main_screen ();
return;
}
continue_with_help:
/* This buffer is just a copy of helppage. Sometimes helppage is an
entry within help_button_s[], which gets overwritten when the page
is parsed. */
if ((helppage_short = (char*) malloc (strlen(helppage) + 1)) == 0) {
malloc_failure ();
}
strcpy (helppage_short, helppage);
/* Right click on mini-screen */
if (strncmp (helppage, "mini-screen.hlp", 15) == 0) {
draw_big_mini_screen ();
} else if (strncmp (helppage, "mini-in-main.hlp", 17) == 0) {
/* do nothing */
} else {
/* This buffer is for the full path of the help file.
The file might be either in the help directory (most cases),
or in the temp directory (dynamically created pages). */
if ((helppage_full = (char *) malloc (lc_save_dir_len
+ strlen (help_path)
+ strlen(helppage) + 2)) == 0) {
malloc_failure ();
}
/* Open the file */
sprintf (helppage_full, "%s%s", help_path, helppage);
if ((inf = fopen (helppage_full, "r")) == 0) {
sprintf (helppage_full, "%s%c%s", lc_save_dir,
PATH_SLASH, helppage);
if ((inf = fopen (helppage_full, "r")) == 0) {
sprintf (helppage_full, "%s%s", help_path, HELPERRORPAGE);
if ((inf = fopen (helppage_full, "r")) == 0)
do_error ("Help error");
}
}
/* Parse and render help file */
numof_help_buttons = 0;
Fgl_fillbox (mw->x, mw->y, mw->w, mw->h, HELPBACKGROUNDCOLOUR);
while (feof (inf) == 0) {
if (fgets (help_line, MAX_HELP_LINE, inf) == 0)
break;
undosify_string (help_line); /* GCS testing... */
parse_helpline (help_line);
}
fclose (inf);
/* For ask-dir, we add path info */
if (strncmp (helppage_short, "ask-dir.hlp", 11) == 0) {
parse_helpline ("tcolour 0 255");
y = 100;
for (i = 0; i < askdir_lines; i++) {
sprintf (help_line, "text -1 %d %s", y, askdir_path[i]);
parse_helpline (help_line);
y += 14;
}
}
free (helppage_full);
}
/* At this point, most of the page has been rendered. Now we have
to draw in the "BACK" and "OUT" buttons. */
if (help_history_count > 0) {
parse_helpline ("tcolour 122 153");
/* TRANSLATOR: Only translate "BACK" */
parse_helpline (_("tbutton 4 387 return-1 BACK"));
}
parse_helpline ("tcolour 188 153");
/* TRANSLATOR: Only translate "OUT" */
parse_helpline (_("tbutton 370 387 return-2 OUT"));
parse_helpline ("tcolour -1 -1");
/* Add help page to history. If history is going to overflow,
throw out oldest page. */
strcpy (help_button_history[help_history_count], helppage_short);
help_history_count++;
if (help_history_count >= MAX_HELP_HISTORY) {
for (i = 0; i < (MAX_HELP_HISTORY - 1); i++)
strcpy (help_button_history[i], help_button_history[i + 1]);
help_history_count--;
}
free (helppage_short);
}
void
refresh_help_page (void)
{
help_history_count -= 1;
draw_help_page (help_button_history[help_history_count]);
}
void
parse_helpline (char *s)
{
if (strncmp (s, "text", 4) == 0)
parse_textline (s);
else if (strncmp (s, "icon", 4) == 0)
parse_iconline (s);
else if (strncmp (s, "button", 6) == 0)
parse_buttonline (s);
else if (strncmp (s, "tbutton", 7) == 0)
parse_tbuttonline (s);
else if (strncmp (s, "tcolour", 7) == 0)
parse_tcolourline (s);
}
void
parse_tcolourline (char *st)
{
char s[100];
int f, b;
strcpy (s, st); /* hpux fix? we can live with this. */
sscanf (s, "tcolour %d %d", &f, &b);
if (f < 0 || b < 0)
Fgl_setfontcolors (TEXT_BG_COLOUR, TEXT_FG_COLOUR);
else
Fgl_setfontcolors (b, f);
}
void
parse_textline (char *st)
{
Rect* mw = &scr.main_win;
int i, j, x, y;
sscanf (st, "text %d %d", &x, &y);
/* find start of string */
i = 0;
for (j = 0; j < 3; j++)
{
while (isspace (st[i]) == 0)
{
if (st[i] == 0)
return; /* just silently ignore */
i++;
}
while (isspace (st[i]) != 0)
{
if (st[i] == 0)
return;
i++;
}
}
st += i;
/* get rid of the newline */
if (st[strlen (st) - 1] == 0xa)
st[strlen (st) - 1] = 0;
if (x < 0) {
/* centre text if x is negative */
x = (mw->w / 2) - (strlen (st) * 4);
if (x < 0)
return; /* line was too long */
} else {
/* otherwise adjust x location to within center zone */
x = x + (mw->w - 440) / 2;
}
/* check to see if text runs off the end */
if ((int) (strlen (st) * 8) > (mw->w - x))
return;
Fgl_write (mw->x + x, mw->y + y, st);
}
void
parse_iconline (char *st)
{
int i, j, x, y;
sscanf (st, "icon %d %d", &x, &y);
/* find start of string */
i = 0;
for (j = 0; j < 3; j++)
{
while (isspace (st[i]) == 0)
{
if (st[i] == 0)
return; /* just silently ignore */
i++;
}
while (isspace (st[i]) != 0)
{
if (st[i] == 0)
return;
i++;
}
}
st += i;
/* get rid of the newline */
if (st[strlen (st) - 1] == 0xa)
st[strlen (st) - 1] = 0;
draw_help_icon (x, y, st);
}
void
draw_help_icon (int x, int y, char *icon)
{
Rect* mw = &scr.main_win;
int i, l, w, h;
char ss[LC_PATH_MAX];
FILE *inf;
strcpy (ss, graphic_path);
strcat (ss, icon);
if ((inf = fopen (ss, "rb")) == NULL) {
return;
}
fseek (inf, 0L, SEEK_END);
l = ftell (inf);
fseek (inf, 0L, SEEK_SET);
if (l == 256)
w = h = 16;
else if (l == 1024)
w = h = 32;
else if (l == 2304)
w = h = 48;
else if (l == 4096)
w = h = 64;
else
{
fclose (inf);
return;
}
for (i = 0; i < l; i++)
*(help_graphic + i) = fgetc (inf);
fclose (inf);
/* Adjust x location to within center zone */
x = x + (mw->w - 440) / 2;
if (x > 0 && y > 0 && ((x + w) < mw->w) && ((y + h) < mw->h))
Fgl_putbox (mw->x + x, mw->y + y, w, h, help_graphic);
return;
}
void
parse_buttonline (char *st)
{
Rect* mw = &scr.main_win;
int i, j, x, y, w, h;
sscanf (st, "button %d %d %d %d", &x, &y, &w, &h);
/* find start of string */
i = 0;
for (j = 0; j < 5; j++)
{
while (isspace (st[i]) == 0)
{
if (st[i] == 0)
return; /* just silently ignore */
i++;
}
while (isspace (st[i]) != 0)
{
if (st[i] == 0)
return;
i++;
}
}
st += i;
/* get rid of the newline */
if (st[strlen (st) - 1] == 0xa)
st[strlen (st) - 1] = 0;
if (x < 0) {
/* centre x of box if x is negative */
x = (mw->w / 2) - (w / 2);
if (x < 0)
return; /* line was too long */
} else {
/* otherwise adjust x location to within center zone */
x = x + (mw->w - 440) / 2;
}
/* see if the button runs off the end */
if ((x + w) > mw->w)
return;
if (numof_help_buttons >= MAX_NUMOF_HELP_BUTTONS)
return;
help_button_x[numof_help_buttons] = x + mw->x;
help_button_y[numof_help_buttons] = y + mw->y;
help_button_w[numof_help_buttons] = w;
help_button_h[numof_help_buttons] = h;
if (strlen (st) >= MAX_LENOF_HELP_FILENAME)
return;
strcpy (help_button_s[numof_help_buttons], st);
numof_help_buttons++;
/* draw the box */
Fgl_hline (mw->x + x, mw->y + y,
mw->x + x + w, HELPBUTTON_COLOUR);
Fgl_hline (mw->x + x, mw->y + y + h,
mw->x + x + w, HELPBUTTON_COLOUR);
Fgl_line (mw->x + x, mw->y + y,
mw->x + x, mw->y + y + h, HELPBUTTON_COLOUR);
Fgl_line (mw->x + x + w, mw->y + y,
mw->x + x + w, mw->y + y + h, HELPBUTTON_COLOUR);
}
void
do_help_buttons (int x, int y)
{
int i;
if (numof_help_buttons <= 0)
return;
for (i = 0; i < numof_help_buttons; i++)
if (x > help_button_x[i]
&& x < (help_button_x[i] + help_button_w[i])
&& y > help_button_y[i]
&& y < (help_button_y[i] + help_button_h[i]))
{
hide_mouse ();
draw_help_page (help_button_s[i]);
redraw_mouse ();
break;
}
}
void
parse_tbuttonline (char *st)
{
char s[100], ss[120], s1[100];
int i, j, x, y;
strcpy (s1, st); /* hpux fix? we can live with this. */
sscanf (s1, "tbutton %d %d %s", &x, &y, s);
/* find start of string */
i = 0;
for (j = 0; j < 4; j++) {
while (isspace (st[i]) == 0) {
if (st[i] == 0)
return; /* just silently ignore */
i++;
}
while (isspace (st[i]) != 0) {
if (st[i] == 0)
return;
i++;
}
}
st += i;
/* get rid of the newline */
if (st[strlen (st) - 1] == 0xa)
st[strlen (st) - 1] = 0;
if (x < 0)
x -= 2; /* needed to keep text centred */
sprintf (ss, "text %d %d ", x + 2, y + 2);
strcat (ss, st);
parse_textline (ss);
sprintf (ss, "button %d %d %d %d %s", x, y, (strlen (st) * 8) + 4, 12, s);
parse_buttonline (ss);
}
|