Freeciv-3.4
Loading...
Searching...
No Matches
helpdlg.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifdef HAVE_CONFIG_H
15#include <fc_config.h>
16#endif
17
18#include <stdio.h>
19#include <stdlib.h>
20#include <string.h>
21#include <math.h> /* sqrt */
22
23#include <gtk/gtk.h>
24
25/* utility */
26#include "fcintl.h"
27#include "mem.h"
28#include "shared.h"
29#include "support.h"
30
31/* common */
32#include "city.h"
33#include "game.h"
34#include "government.h"
35#include "movement.h"
36#include "nation.h"
37#include "specialist.h"
38#include "tech.h"
39#include "unit.h"
40#include "map.h"
41#include "research.h"
42#include "version.h"
43
44/* client */
45#include "client_main.h"
46#include "climisc.h"
47#include "helpdata.h"
48#include "options.h"
49#include "tilespec.h"
50
51/* client/gui-gtk-3.22 */
52#include "colors.h"
53#include "graphics.h"
54#include "gui_main.h"
55#include "gui_stuff.h"
56
57#include "helpdlg.h"
58
59#define TECH_TREE_DEPTH 20
60
61/*
62 * Globals.
63 */
66
68
82
89static GtkWidget *help_ulabel[5][5];
90static GtkWidget *help_tlabel[2][5];
92
93static bool help_advances[A_LAST];
94
97
99{
101 union {
103 const struct requirement *req;
104 } u;
105};
106
107static const char *help_ilabel_name[6] =
108{ N_("Base Cost:"), NULL, N_("Upkeep:"), NULL, N_("Requirement:"), NULL };
110
111static const char *help_wlabel_name[6] =
112{ N_("Base Cost:"), NULL, N_("Requirement:"), NULL, N_("Obsolete by:"), NULL };
114
116
117static const char *help_ulabel_name[5][5] =
118{
119 { N_("Cost:"), NULL, NULL, N_("Attack:"), NULL },
120 { N_("Defense:"), NULL, NULL, N_("Move:"), NULL },
121 { N_("Firepower:"), NULL, NULL, N_("Hitpoints:"), NULL },
122 { N_("Basic Upkeep:"), NULL, NULL, N_("Vision:"), NULL },
123 { N_("Requirement:"), NULL, NULL, N_("Obsolete by:"), NULL }
124};
125
126static const char *help_tlabel_name[2][5] =
127{
128 { N_("Move/Defense:"), NULL, NULL, N_("Food/Res/Trade:"), NULL },
129 { N_("Resources:"), NULL, NULL, NULL, NULL }
130};
131
132static const char *help_elabel_name[6] =
133/* TRANS: Label for build cost for extras in help. Will be followed by
134 * something like "3 MP" (where MP = Movement Points) */
135{ N_("Build:"), NULL,
136/* TRANS: Extra conflicts in help. Will be followed by a list of extras
137 * that can't be built on the same tile as this one. */
138 N_("Conflicts with:"), NULL,
139/* TRANS: Extra bonus in help. Will be followed by food/production/trade
140 * stats like "0/0/+1", "0/+50%/0" */
141 N_("Bonus (F/P/T):"), NULL };
142
143#define REQ_LABEL_NONE _("?tech:None")
144#define REQ_LABEL_NEVER _("(Never)")
145
146static void create_help_dialog(void);
147static void help_update_dialog(const struct help_item *pitem);
148
149static void select_help_item_string(const char *item,
150 enum help_page_type htype);
151static void help_command_update(void);
153
154/**********************************************************************/
169
170/**********************************************************************/
173static void set_title_topic(char *topic)
174{
175 if (strcmp(topic, _(HELP_ABOUT_ITEM)) == 0) {
177 } else {
179 }
180 return;
181}
182
183/**********************************************************************/
192
193/**********************************************************************/
207
208/**********************************************************************/
216
217/**********************************************************************/
226static void create_tech_tree(int tech, int levels, GtkTreeIter *parent)
227{
228 const struct research *presearch;
229 int bg;
230 int turns_to_tech;
231 bool original;
233 GValue value = { 0, };
234 enum tech_state state;
235
236 if (advance_required(tech, AR_ONE) == A_LAST
237 && advance_required(tech, AR_TWO) == A_LAST) {
239
241 help_advances[tech] = TRUE;
242
244 g_value_set_static_string(&value, _("Removed"));
245 gtk_tree_store_set_value(tstore, &l, 0, &value);
246 g_value_unset(&value);
247
249 1, -1,
250 2, tech,
251 3, &get_color(tileset, bg)->color
252 -1);
253 return;
254 }
255
257
258 state = research_invention_state(presearch, tech);
259 if (tech_state_is_valid(state)) {
260 switch (state) {
261 case TECH_UNKNOWN:
263 break;
264 case TECH_KNOWN:
266 break;
269 break;
270 }
271 } else {
273 }
275
276 /* l is the original in the tree. */
277 original = !help_advances[tech];
278
280 help_advances[tech] = TRUE;
281
285 tech));
286 gtk_tree_store_set_value(tstore, &l, 0, &value);
287 g_value_unset(&value);
288
290 1, turns_to_tech,
291 2, tech,
292 3, &get_color(tileset, bg)->color,
293 -1);
294
295 if (--levels <= 0) {
296 return;
297 }
298
299 if (original) {
300 /* Only add children to originals */
301 if (advance_required(tech, AR_ONE) != A_NONE) {
302 create_tech_tree(advance_required(tech, AR_ONE), levels, &l);
303 }
304 if (advance_required(tech, AR_TWO) != A_NONE) {
305 create_tech_tree(advance_required(tech, AR_TWO), levels, &l);
306 }
307 }
308}
309
310/**********************************************************************/
326
327/**********************************************************************/
334
335/**********************************************************************/
342
343/**********************************************************************/
347{
348 const char *s;
349 struct help_page_selection *select;
351
353 select = (struct help_page_selection *)(g_object_get_data(G_OBJECT(w), "page_type"));
354
355 switch (select->type) {
356 case HPAGE_SRC_ENUM:
357 type = select->u.page;
358 break;
359 case HPAGE_SRC_REQ:
361 break;
362 }
363
364 if (type == HELP_LAST) {
365 return;
366 }
367
368 /* FIXME: May be able to skip, or may need to modify, advances[A_NONE]
369 below, depending on which i18n is done elsewhere.
370 */
371 if (strcmp(s, REQ_LABEL_NEVER) != 0
375 }
376}
377
378/**********************************************************************/
382 struct help_page_selection *select)
383{
384 GtkWidget *button;
385
386 button = gtk_button_new();
390 gtk_widget_set_name(label, "help_link");
391 gtk_container_add(GTK_CONTAINER(button), label);
392 gtk_widget_show(button);
393 g_signal_connect_swapped(button, "clicked",
395 g_object_set_data(G_OBJECT(label), "page_type", select);
396
397 return button;
398}
399
400/**********************************************************************/
404 enum help_page_type page)
405{
406 return help_hyperlink_new(label, &(page_selections[page]));
407}
408
409/**********************************************************************/
413 struct help_page_selection *select)
414{
415 GtkWidget *button, *label;
416
417 label = gtk_label_new(txt);
420 button = help_hyperlink_new(label, select);
421
422 return button;
423}
424
425/**********************************************************************/
429 enum help_page_type page)
430{
432}
433
434/**********************************************************************/
457
458/**********************************************************************/
466
467/**********************************************************************/
471{
472 GtkTreePath *path;
474 GtkTreeModel *model;
475 GtkTreeIter it;
476 struct help_item *pitem;
477
479
481 gtk_tree_model_get_iter(model, &it, path);
482 gtk_tree_path_free(path);
483
484 if (!path) {
485 return;
486 }
487
488 gtk_tree_model_get(model, &it, 1, &pitem, -1);
489
490 if (help_history_pos >= 0
492 return;
493 }
494
496
497 /* add to history. */
500 }
502
505}
506
507/**********************************************************************/
510static void create_help_dialog(void)
511{
513 GtkWidget *button;
515 int i, j;
518 GArray *array;
519 GtkTreeStore *store;
520 GtkTreeSelection *selection;
521
523 help_history_pos = -1;
524
525 help_dialog_shell = gtk_dialog_new_with_buttons(_("Freeciv Help Browser"),
526 NULL,
527 0,
528 _("_Back"),
529 1,
530 _("_Forward"),
531 2,
532 _("_Close"),
534 NULL);
539
544
545 hbox = gtk_grid_new();
549
550 /* build tree store. */
552
553 array = g_array_new(FALSE, FALSE, sizeof(GtkTreeIter));
555 GtkTreeIter *it, *parent;
556 const char *s;
557 int depth;
558
559 for (s = pitem->topic; *s == ' '; s++) {
560 /* nothing */
561 }
562 depth = s - pitem->topic;
563
564 array = g_array_set_size(array, depth+1);
565
566 if (depth > 0) {
567 parent = &g_array_index(array, GtkTreeIter, depth-1);
568 } else {
569 parent = NULL;
570 }
571
572 it = &g_array_index(array, GtkTreeIter, depth);
573 gtk_tree_store_append(store, it, parent);
574
575 gtk_tree_store_set(store, it, 0, pitem->topic, 1, pitem, -1);
577
578
579 /* create tree view. */
581 g_object_unref(store);
584
585 g_signal_connect(help_view, "cursor-changed",
587
590
594
603
610
616
619
622
623 for (i = 0; i < 6; i++) {
624 help_ilabel[i] =
627
628 if (i == 5) {
630 gtk_grid_attach(GTK_GRID(help_itable), button, i, 0, 1, 1);
631 } else {
633 gtk_widget_set_name(help_ilabel[i], "help_label");
634 }
635
637 }
638
641
642 for (i = 0; i < 6; i++) {
643 help_wlabel[i] =
646
647 if (i == 3 || i == 5) {
649 gtk_grid_attach(GTK_GRID(help_wtable), button, i, 0, 1, 1);
650 } else {
652 gtk_widget_set_name(help_wlabel[i], "help_label");
653 }
654
656 }
657
660
661 for (i = 0; i < 5; i++) {
662 for (j = 0; j < 5; j++) {
663 help_ulabel[j][i] =
666
667 if (j == 4 && (i == 1 || i == 4)) {
668 if (i == 1) {
670 } else {
672 }
673
674 gtk_grid_attach(GTK_GRID(help_utable), button, i, j, 1, 1);
675 } else {
677 i, j, 1, 1);
678 gtk_widget_set_name(help_ulabel[j][i], "help_label");
679 }
681 }
682 }
683
686
687 for (j = 0; j < 2; j++) {
688 for (i = 0; i < 5; i++) {
689 help_tlabel[j][i] =
692 gtk_widget_set_name(help_tlabel[j][i], "help_label");
693
694 /* Ugly (but these numbers are hardcoded in help_update_terrain() too) */
695 if (j == 1 && i == 1) {
696 /* Extra wide cell for terrain specials */
698 i, j, 4, 1);
700 break; /* skip rest of row */
701 } else {
703 i, j, 1, 1);
705 }
706 }
707 }
708
711
712 for (i = 0; i < 6; i++) {
713 help_elabel[i] =
716 gtk_grid_attach(GTK_GRID(help_etable), help_elabel[i], i % 4, i / 4, 1, 1);
717 gtk_widget_set_name(help_elabel[i], "help_label");
719 }
720
727
735 gtk_widget_set_name(text, "help_text");
738
744
745 /* build tech store. */
747 G_TYPE_STRING, /* tech name */
748 G_TYPE_INT, /* turns to tech */
749 G_TYPE_INT, /* tech id */
750 GDK_TYPE_RGBA); /* color */
756
757 g_signal_connect(help_tree, "row_activated",
759
760
762
767 "text", 0,
768 "background-rgba", 3,
769 NULL);
771 g_object_set(rend, "weight", PANGO_WEIGHT_BOLD, "xalign", 1.0, NULL);
774 "text", 1,
775 "background-rgba", 3,
776 NULL);
777
779
780
787
789 = gtk_button_new_with_label(_("Expand All"));
791
796
802}
803
804/**********************************************************************/
808{
809 if (spr == NULL) {
810 return;
811 }
812
815}
816
817/**********************************************************************/
847
848/**********************************************************************/
875
876/**********************************************************************/
879static void help_update_improvement(const struct help_item *pitem,
880 char *title)
881{
882 char buf[8192];
884
885 if (imp && !is_great_wonder(imp)) {
887 char req_buf[512];
888
891 sprintf(buf, "%d", imp->upkeep);
893
894 /* FIXME: this should show ranges, negated reqs, and all the reqs.
895 * Currently it's limited to 1 req but this code is partially prepared
896 * to be extended. */
899 if (!preq->present) {
900 continue;
901 }
902 req = universal_name_translation(&preq->source, req_buf, sizeof(req_buf));
904 break;
907/* create_tech_tree(help_improvement_tree, 0, imp->tech_req, 3);*/
908 } else {
912/* create_tech_tree(help_improvement_tree, 0, advance_count(), 3);*/
913 }
914
916
918
919 helptext_building(buf, sizeof(buf), client.conn.playing, pitem->text, imp);
922}
923
924/**********************************************************************/
927static void help_update_wonder(const struct help_item *pitem,
928 char *title)
929{
930 char buf[8192];
932
933 if (imp && is_great_wonder(imp)) {
934 int i;
935 char req_buf[512];
936
939
940 /* FIXME: this should show ranges, negated reqs, and all the reqs.
941 * Currently it's limited to 1 req but this code is partially prepared
942 * to be extended. */
943 i = 0;
946 if (!preq->present) {
947 continue;
948 }
951 req_buf, sizeof(req_buf)));
953 i++;
954 break;
956
958 requirement_vector_iterate(&imp->obsolete_by, pobs) {
959 if (pobs->source.kind == VUT_ADVANCE && pobs->present) {
962 (pobs->source.value.advance));
963
964 break;
965 }
967
968/* create_tech_tree(help_improvement_tree, 0, imp->tech_req, 3);*/
969 } else {
970 /* can't find wonder */
974/* create_tech_tree(help_improvement_tree, 0, advance_count(), 3); */
975 }
976
978
980
981 helptext_building(buf, sizeof(buf), client.conn.playing, pitem->text, imp);
984}
985
986/**********************************************************************/
989static void help_update_unit_type(const struct help_item *pitem,
990 char *title)
991{
992 char buf[8192];
994
995 if (utype) {
998 sprintf(buf, "%d", utype->attack_strength);
1000 sprintf(buf, "%d", utype->defense_strength);
1002 sprintf(buf, "%s", move_points_text(utype->move_rate, TRUE));
1004 sprintf(buf, "%d", utype->firepower);
1006 sprintf(buf, "%d", utype->hp);
1010 sprintf(buf, "%d", (int)sqrt((double)utype->vision_radius_sq));
1014/* create_tech_tree(help_improvement_tree, 0, advance_number(utype->require_advance), 3);*/
1015 if (U_NOT_OBSOLETED == utype->obsoleted_by) {
1017 } else {
1020 }
1021
1022 helptext_unit(buf, sizeof(buf), client.conn.playing, pitem->text, utype,
1023 TRUE);
1024
1027
1031 } else {
1040
1042/* create_tech_tree(help_improvement_tree, 0, A_LAST, 3);*/
1044
1047 }
1049}
1050
1051/**********************************************************************/
1054static char *fc_chomp(char *str, size_t len)
1055{
1056 gchar *i;
1057
1058 if (!str || !*str) {
1059 return str;
1060 }
1061
1062 i = str + len;
1063 for (i = g_utf8_find_prev_char(str, i);
1066 *i = '\0';
1067 }
1068 return str;
1069}
1070
1071/**********************************************************************/
1074static void help_update_tech(const struct help_item *pitem, char *title)
1075{
1076 int j;
1077 GtkWidget *w, *hbox;
1078 char buf[8192];
1080
1083 size_t len;
1085
1087
1088 for (j = 0; j < ARRAY_SIZE(help_advances); j++) {
1089 help_advances[j] = FALSE;
1090 }
1095
1096 helptext_advance(buf, sizeof(buf), client.conn.playing, pitem->text, i);
1097 len = strlen(buf);
1098 fc_chomp(buf, len);
1099
1101
1102 w = gtk_text_view_new();
1107 gtk_widget_set_name(w, "help_text");
1111 gtk_widget_show(w);
1112
1114 if (txt) {
1116 }
1117
1119 g_object_set(w, "margin", 5, NULL);
1123 gtk_widget_show(w);
1124
1126 /* FIXME: need a more general mechanism for this, since this
1127 * helptext needs to be shown in all possible req source types. */
1129 if (VUT_ADVANCE == preq->source.kind
1130 && preq->source.value.advance == padvance) {
1131 hbox = gtk_grid_new();
1133 w = gtk_label_new(_("Allows"));
1139 }
1142
1143 improvement_iterate(pimprove) {
1144 if (valid_improvement(pimprove)) {
1145 requirement_vector_iterate(&pimprove->reqs, preq) {
1146 if (VUT_ADVANCE == preq->source.kind
1147 && preq->source.value.advance == padvance) {
1148 hbox = gtk_grid_new();
1150 w = gtk_label_new(_("Allows"));
1153 is_great_wonder(pimprove)
1154 ? HELP_WONDER
1158 }
1160 requirement_vector_iterate(&pimprove->obsolete_by, pobs) {
1161 if (pobs->source.kind == VUT_ADVANCE
1162 && pobs->source.value.advance == padvance
1163 && pobs->present) {
1164 hbox = gtk_grid_new();
1166 w = gtk_label_new(_("Obsoletes"));
1169 is_great_wonder(pimprove)
1170 ? HELP_WONDER
1174 }
1176 }
1178
1180
1182 continue;
1183 }
1184
1185 hbox = gtk_grid_new();
1187 w = gtk_label_new(_("Allows"));
1193
1197 hbox = gtk_grid_new();
1199 w = gtk_label_new(_("Allows"));
1204 } else {
1205 hbox = gtk_grid_new();
1207 w = gtk_label_new(_("Allows"));
1211 w = gtk_label_new(_("with"));
1214 AR_TWO)),
1215 HELP_TECH);
1217 w = gtk_label_new(Q_("?techhelp:"));
1220 }
1221 }
1223 hbox = gtk_grid_new();
1225 w = gtk_label_new(_("Allows"));
1229 w = gtk_label_new(_("with"));
1232 HELP_TECH);
1234 w = gtk_label_new(Q_("?techhelp:"));
1237 }
1240 }
1241}
1242
1243/**********************************************************************/
1265
1266/**********************************************************************/
1270 enum unit_activity act,
1271 char *label)
1272{
1273 enum extra_cause cause = activity_to_extra_cause(act);
1274
1275 extra_type_by_cause_iterate(cause, pextra) {
1276 if (pextra->buildable
1277 && requirement_fulfilled_by_terrain(pterr, &(pextra->reqs))) {
1281 act));
1282 }
1284}
1285
1286/**********************************************************************/
1289static void help_update_terrain(const struct help_item *pitem,
1290 char *title)
1291{
1292 char buf[8192];
1293 struct terrain *pterrain = terrain_by_translated_name(title);
1294
1295 if (pterrain) {
1296 struct universal for_terr = { .kind = VUT_TERRAIN, .value = { .terrain = pterrain }};
1297
1299
1300 {
1301 /* 25 => "1.25"; 50 => "1.5"; 100 => "2.0" */
1302 int defbonus = pterrain->defense_bonus + 100;
1303 int frac = defbonus % 100;
1304
1305 if ((frac % 10) == 0) {
1306 frac /= 10;
1307 }
1308 sprintf(buf, "%d/%d.%d",
1309 pterrain->movement_cost, defbonus / 100, frac);
1310 }
1312
1313 sprintf(buf, "%d/%d/%d",
1314 pterrain->output[O_FOOD],
1315 pterrain->output[O_SHIELD],
1316 pterrain->output[O_TRADE]);
1318
1319 buf[0] = '\0';
1320 if (*(pterrain->resources)) {
1321 struct extra_type **r;
1322
1323 /* TODO: include resource frequency information */
1324 for (r = pterrain->resources; *r; r++) {
1325 /* TRANS: " Whales (2/1/2)," */
1326 sprintf (buf + strlen (buf), " %s (%d/%d/%d),",
1328 pterrain->output[O_FOOD] + (*r)->data.resource->output[O_FOOD],
1329 pterrain->output[O_SHIELD] + (*r)->data.resource->output[O_SHIELD],
1330 pterrain->output[O_TRADE] + (*r)->data.resource->output[O_TRADE]);
1331 }
1332 buf[strlen (buf) - 1] = '.';
1333 } else {
1334 /* TRANS: "Resources: (none)" */
1335 sprintf (buf + strlen (buf), _("(none)"));
1336 }
1338
1340
1341 if (pterrain->cultivate_result != T_NONE
1343 NULL, &for_terr)) {
1344 fc_snprintf(buf, sizeof(buf),
1345 PL_("%d turn", "%d turns", pterrain->cultivate_time),
1346 pterrain->cultivate_time);
1347 add_act_help_for_terrain(_("Cultivate Rslt/Time"),
1349 HELP_TERRAIN, buf);
1350 }
1351
1352 if (pterrain->plant_result != T_NONE
1354 fc_snprintf(buf, sizeof(buf),
1355 PL_("%d turn", "%d turns", pterrain->plant_time),
1356 pterrain->plant_time);
1357 add_act_help_for_terrain(_("Plant Rslt/Time"),
1359 HELP_TERRAIN, buf);
1360 }
1361
1362 if (pterrain->transform_result != T_NONE
1364 NULL, &for_terr)) {
1365 fc_snprintf(buf, sizeof(buf),
1366 PL_("%d turn", "%d turns", pterrain->transform_time),
1367 pterrain->transform_time);
1368 add_act_help_for_terrain(_("Trans. Rslt/Time"),
1370 HELP_TERRAIN, buf);
1371 }
1372
1375 _("Build as irrigation"));
1376 }
1379 _("Build as mine"));
1380 }
1383 _("Build as road"));
1384 }
1387 _("Build as base"));
1388 }
1389
1391 }
1392
1393 helptext_terrain(buf, sizeof(buf), client.conn.playing, pitem->text, pterrain);
1394
1397
1399}
1400
1401/**********************************************************************/
1404static void help_update_extra(const struct help_item *pitem, char *title)
1405{
1406 char buf[8192];
1408
1409 buf[0] = '\0';
1410 if (pextra == NULL) {
1411 strcat(buf, pitem->text);
1412 } else {
1413 struct road_type *proad = extra_road_get(pextra);
1415
1417
1418 /* Cost to build */
1419 if (pextra->buildable) {
1420 if (pextra->build_time != 0) {
1421 /* TRANS: "MP" = movement points */
1422 sprintf(buf, _("%d MP"), pextra->build_time);
1423 } else {
1424 /* TRANS: Build time depends on terrain. */
1425 sprintf(buf, _("Terrain specific"));
1426 }
1427 } else {
1428 sprintf(buf, "-");
1429 }
1431 /* Conflicting extras */
1432 buf[0] = '\0';
1433 if (is_resource) {
1434 /* TRANS: (Resource extra) Conflicts with: */
1435 strcat(buf, _("Other Resources"));
1436 }
1438 if (!can_extras_coexist(pextra, pextra2)
1440 if (buf[0] != '\0') {
1441 strcat(buf, "/");
1442 }
1444 }
1446 /* TRANS: "Conflicts with: (none)" (extras) */
1447 gtk_label_set_text(GTK_LABEL(help_elabel[3]), buf[0] ? buf : _("(none)"));
1448
1449 /* Bonus */
1450 if (proad != NULL) {
1451 const char *bonus = NULL;
1452
1454 if (proad->tile_incr[o] > 0) {
1455 /* TRANS: Road bonus depends on terrain. */
1456 bonus = _("Terrain specific");
1457 break;
1458 }
1460 if (!bonus) {
1462 }
1463 if (!bonus) {
1464 /* TRANS: No output bonus from a road */
1465 bonus = Q_("?bonus:None");
1466 }
1470 } else {
1473 }
1474
1475 helptext_extra(buf, sizeof(buf), client.conn.playing, pitem->text, pextra);
1476 }
1478
1481}
1482
1483/**********************************************************************/
1486static void help_update_goods(const struct help_item *pitem,
1487 char *title)
1488{
1489 char buf[8192];
1491
1492 if (!pgood) {
1493 strcat(buf, pitem->text);
1494 } else {
1495 helptext_goods(buf, sizeof(buf), client.conn.playing, pitem->text,
1496 pgood);
1497 }
1498
1501}
1502
1503/**********************************************************************/
1506static void help_update_specialist(const struct help_item *pitem,
1507 char *title)
1508{
1509 char buf[8192];
1511
1512 if (!pspec) {
1513 strcat(buf, pitem->text);
1514 } else {
1516 pspec);
1517 }
1518
1521}
1522
1523/**********************************************************************/
1526static void help_update_government(const struct help_item *pitem,
1527 char *title)
1528{
1529 char buf[8192];
1531
1532 if (!gov) {
1533 strcat(buf, pitem->text);
1534 } else {
1535 helptext_government(buf, sizeof(buf), client.conn.playing, pitem->text, gov);
1536 }
1537
1540}
1541
1542/**********************************************************************/
1545static void help_update_nation(const struct help_item *pitem, char *title,
1546 struct nation_type *pnation)
1547{
1548 char buf[4096];
1549
1550 if (!pnation) {
1551 strcat(buf, pitem->text);
1552 } else {
1553 helptext_nation(buf, sizeof(buf), pnation, pitem->text);
1554
1556 }
1557
1560}
1561
1562/**********************************************************************/
1565static void help_update_dialog(const struct help_item *pitem)
1566{
1567 char *top;
1568
1569 /* figure out what kind of item is required for pitem ingo */
1570
1571 for (top = pitem->topic; *top == ' '; top++) {
1572 /* nothing */
1573 }
1574
1575 help_box_hide();
1577
1578 switch (pitem->type) {
1579 case HELP_IMPROVEMENT:
1581 break;
1582 case HELP_WONDER:
1584 break;
1585 case HELP_UNIT:
1587 break;
1588 case HELP_TECH:
1589 help_update_tech(pitem, top);
1590 break;
1591 case HELP_TERRAIN:
1593 break;
1594 case HELP_EXTRA:
1596 break;
1597 case HELP_GOODS:
1599 break;
1600 case HELP_SPECIALIST:
1602 break;
1603 case HELP_GOVERNMENT:
1605 break;
1606 case HELP_NATIONS:
1608 break;
1609 case HELP_TEXT:
1610 default:
1611 /* It was a pure text item */
1614 break;
1615 }
1616 set_title_topic(pitem->topic);
1617
1619}
1620
1621/**********************************************************************/
1624static void help_item_zoom(GtkTreePath *path)
1625{
1626 GtkTreeModel *model;
1627 GtkTreeIter it, child, item;
1628 GtkTreeSelection *selection;
1629
1631 gtk_tree_model_get_iter(model, &item, path);
1632
1633 for (child = item; gtk_tree_model_iter_parent(model, &it, &child); child=it) {
1635
1636 it_path = gtk_tree_model_get_path(model, &it);
1639 }
1640
1644 TRUE, 0.0, 0.0);
1645}
1646
1647/**********************************************************************/
1651{
1652 GtkTreePath *path;
1653 bool next;
1654
1655 path = gtk_tree_path_new_first();
1656 next = FALSE;
1658 const char *s;
1659 int depth;
1660
1661 for (s = pitem2->topic; *s == ' '; s++) {
1662 /* nothing */
1663 }
1664 depth = s - pitem2->topic + 1;
1665
1666 while (depth < gtk_tree_path_get_depth(path)) {
1667 gtk_tree_path_up(path);
1668 gtk_tree_path_next(path);
1669 next = FALSE;
1670 }
1671 while (depth > gtk_tree_path_get_depth(path)) {
1672 gtk_tree_path_down(path);
1673 next = FALSE;
1674 }
1675
1676 if (next) {
1677 gtk_tree_path_next(path);
1678 }
1679
1680 if (pitem == pitem2)
1681 break;
1682
1683 next = TRUE;
1685
1686 return path;
1687}
1688
1689/**********************************************************************/
1692static void select_help_item_string(const char *item, enum help_page_type htype)
1693{
1694 const struct help_item *pitem;
1695 int idx;
1696 GtkTreePath *path;
1698
1699 if (!(pitem = get_help_item_spec(item, htype, &idx))) {
1700 return;
1701 }
1702
1703 path = help_item_path(pitem);
1704 help_item_zoom(path);
1705
1708 gtk_tree_path_free(path);
1709}
1710
1711/**********************************************************************/
1714static void help_command_update(void)
1715{
1717
1718 if (help_history_pos < 0) {
1721 } else {
1724
1725 if (help_history_pos == 0) {
1727 }
1728 if (help_history_pos >= help_history->len - 1) {
1730 }
1731 }
1732}
1733
1734/**********************************************************************/
1738{
1739 GtkTreePath *path;
1740 const struct help_item *pitem;
1741
1742 if (response_id == 1) {
1743 if (help_history_pos > 0) {
1745
1747 path = help_item_path(pitem);
1748 help_item_zoom(path);
1751 }
1752 } else if (response_id == 2) {
1755
1757 path = help_item_path(pitem);
1758 help_item_zoom(path);
1761 }
1762 } else {
1763 /* Save size of the dialog. */
1767 }
1768}
#define action_id_univs_not_blocking(act_id, act_uni, tgt_uni)
Definition actions.h:740
#define str
Definition astring.c:76
#define output_type_iterate(output)
Definition city.h:847
#define output_type_iterate_end
Definition city.h:853
struct civclient client
#define client_player()
struct color * get_color(const struct tileset *t, enum color_std stdcolor)
char * incite_cost
Definition comments.c:77
struct extra_type * extra_type_by_translated_name(const char *name)
Definition extras.c:235
enum extra_cause activity_to_extra_cause(enum unit_activity act)
Definition extras.c:1090
bool can_extras_coexist(const struct extra_type *pextra1, const struct extra_type *pextra2)
Definition extras.c:1017
const char * extra_name_translation(const struct extra_type *pextra)
Definition extras.c:194
#define extra_type_iterate(_p)
Definition extras.h:315
#define extra_type_iterate_end
Definition extras.h:321
#define is_extra_caused_by(e, c)
Definition extras.h:203
#define extra_road_get(_e_)
Definition extras.h:191
#define extra_type_by_cause_iterate_end
Definition extras.h:339
#define extra_type_by_cause_iterate(_cause, _extra)
Definition extras.h:333
int Tech_type_id
Definition fc_types.h:238
@ O_SHIELD
Definition fc_types.h:103
@ O_FOOD
Definition fc_types.h:103
@ O_TRADE
Definition fc_types.h:103
const char * skip_intl_qualifier_prefix(const char *str)
Definition fcintl.c:48
#define Q_(String)
Definition fcintl.h:70
#define PL_(String1, String2, n)
Definition fcintl.h:71
#define _(String)
Definition fcintl.h:67
#define N_(String)
Definition fcintl.h:69
const char * government_name_translation(const struct government *pgovern)
Definition government.c:145
struct government * government_by_translated_name(const char *name)
Definition government.c:42
#define governments_iterate(NAME_pgov)
Definition government.h:127
#define governments_iterate_end
Definition government.h:130
#define FC_STATIC_CANVAS_INIT
Definition canvas.h:28
GtkWidget * toplevel
Definition gui_main.c:126
#define GUI_GTK_OPTION(optname)
Definition gui_main.h:32
void set_relative_window_position(GtkWindow *ref, GtkWindow *w, int px, int py)
Definition gui_stuff.c:60
void setup_dialog(GtkWidget *shell, GtkWidget *parent)
Definition gui_stuff.c:287
static GtkWidget * help_tree_sw
Definition helpdlg.c:83
static void set_title_topic(char *topic)
Definition helpdlg.c:173
static void activated_topic(GtkTreeView *view, gpointer data)
Definition helpdlg.c:470
static GtkWidget * help_tree
Definition helpdlg.c:80
static GtkWidget * help_tree_expand
Definition helpdlg.c:84
static GtkWidget * help_ulabel[5][5]
Definition helpdlg.c:89
static void help_update_specialist(const struct help_item *pitem, char *title)
Definition helpdlg.c:1506
static void help_hyperlink_callback(GtkWidget *w)
Definition helpdlg.c:346
static GtkWidget * help_elabel[6]
Definition helpdlg.c:91
static GtkWidget * help_etable
Definition helpdlg.c:79
static void help_destroy_callback(GtkWidget *w, gpointer data)
Definition helpdlg.c:461
static void set_help_tile_from_extra(const struct extra_type *pextra)
Definition helpdlg.c:851
static GtkWidget * help_frame
Definition helpdlg.c:69
static void help_tech_tree_activated_callback(GtkTreeView *view, GtkTreePath *path, GtkTreeViewColumn *col, gpointer data)
Definition helpdlg.c:313
static void help_update_tech(const struct help_item *pitem, char *title)
Definition helpdlg.c:1074
static void help_item_zoom(GtkTreePath *path)
Definition helpdlg.c:1624
static GtkWidget * help_slink_new_page(const gchar *txt, enum help_page_type page)
Definition helpdlg.c:428
static GtkWidget * help_tlabel[2][5]
Definition helpdlg.c:90
static GtkTreePath * help_item_path(const struct help_item *pitem)
Definition helpdlg.c:1650
static GtkWidget * help_tree_collapse
Definition helpdlg.c:85
static void help_update_nation(const struct help_item *pitem, char *title, struct nation_type *pnation)
Definition helpdlg.c:1545
static void create_help_dialog(void)
Definition helpdlg.c:510
static GtkTextBuffer * help_text
Definition helpdlg.c:70
static void help_update_wonder(const struct help_item *pitem, char *title)
Definition helpdlg.c:927
static GtkWidget * help_hyperlink_new_page(GtkWidget *label, enum help_page_type page)
Definition helpdlg.c:403
static GtkWidget * help_dialog_shell
Definition helpdlg.c:64
static GtkWidget * help_text_sw
Definition helpdlg.c:71
static GPtrArray * help_history
Definition helpdlg.c:95
static const char * help_elabel_name[6]
Definition helpdlg.c:132
static void create_tech_tree(int tech, int levels, GtkTreeIter *parent)
Definition helpdlg.c:226
static void help_update_extra(const struct help_item *pitem, char *title)
Definition helpdlg.c:1404
static GtkWidget * help_ilabel[6]
Definition helpdlg.c:87
static void set_help_tile_from_sprite(struct sprite *spr)
Definition helpdlg.c:807
static const char * help_wlabel_name[6]
Definition helpdlg.c:111
static const char * help_ulabel_name[5][5]
Definition helpdlg.c:117
static void help_tech_tree_collapse_callback(GtkWidget *w, gpointer data)
Definition helpdlg.c:338
static void set_help_tile_from_terrain(struct terrain *pterr)
Definition helpdlg.c:820
static GtkWidget * help_view
Definition helpdlg.c:67
static void help_update_goods(const struct help_item *pitem, char *title)
Definition helpdlg.c:1486
void help_system_init(void)
Definition helpdlg.c:157
static void help_box_hide(void)
Definition helpdlg.c:437
static void help_update_unit_type(const struct help_item *pitem, char *title)
Definition helpdlg.c:989
void popdown_help_dialog(void)
Definition helpdlg.c:186
static void help_update_terrain(const struct help_item *pitem, char *title)
Definition helpdlg.c:1289
static void help_update_dialog(const struct help_item *pitem)
Definition helpdlg.c:1565
static char * fc_chomp(char *str, size_t len)
Definition helpdlg.c:1054
void popup_help_dialog_string(const char *item)
Definition helpdlg.c:212
static int help_history_pos
Definition helpdlg.c:96
static struct help_page_selection help_wndr_req
Definition helpdlg.c:113
static GtkWidget * help_wlabel[6]
Definition helpdlg.c:88
static GtkWidget * help_box
Definition helpdlg.c:74
static void help_extras_of_act_for_terrain(struct terrain *pterr, enum unit_activity act, char *label)
Definition helpdlg.c:1269
void popup_help_dialog_typed(const char *item, enum help_page_type htype)
Definition helpdlg.c:196
#define REQ_LABEL_NEVER
Definition helpdlg.c:144
static void help_command_update(void)
Definition helpdlg.c:1714
static struct help_page_selection page_selections[HELP_LAST]
Definition helpdlg.c:115
#define TECH_TREE_DEPTH
Definition helpdlg.c:59
static const char * help_tlabel_name[2][5]
Definition helpdlg.c:126
static struct help_page_selection help_impr_req
Definition helpdlg.c:109
#define REQ_LABEL_NONE
Definition helpdlg.c:143
static GtkWidget * help_wtable
Definition helpdlg.c:76
static GtkWidget * help_slink_new(const gchar *txt, struct help_page_selection *select)
Definition helpdlg.c:412
static GtkWidget * help_vbox
Definition helpdlg.c:72
static void help_tech_tree_expand_callback(GtkWidget *w, gpointer data)
Definition helpdlg.c:330
static GtkWidget * help_tile
Definition helpdlg.c:73
static GtkWidget * help_hyperlink_new(GtkWidget *label, struct help_page_selection *select)
Definition helpdlg.c:381
static void help_update_government(const struct help_item *pitem, char *title)
Definition helpdlg.c:1526
static GtkWidget * help_ttable
Definition helpdlg.c:78
static void help_update_improvement(const struct help_item *pitem, char *title)
Definition helpdlg.c:879
static const char * help_ilabel_name[6]
Definition helpdlg.c:107
static GtkWidget * help_tree_buttons_hbox
Definition helpdlg.c:86
static GtkWidget * help_view_sw
Definition helpdlg.c:65
static void select_help_item_string(const char *item, enum help_page_type htype)
Definition helpdlg.c:1692
static bool help_advances[A_LAST]
Definition helpdlg.c:93
static GtkWidget * help_utable
Definition helpdlg.c:77
static GtkWidget * help_itable
Definition helpdlg.c:75
static GtkTreeStore * tstore
Definition helpdlg.c:81
static void add_act_help_for_terrain(const char *act_label, const char *result_link_label, enum help_page_type result_link_type, const char *descr_label)
Definition helpdlg.c:1246
static void help_command_callback(GtkWidget *w, gint response_id)
Definition helpdlg.c:1737
const char * title
Definition repodlgs.c:1314
GType type
Definition repodlgs.c:1313
void helptext_government(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct government *gov)
Definition helpdata.c:4415
void helptext_advance(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, int i)
Definition helpdata.c:3369
enum help_page_type help_type_by_requirement(const struct requirement *req)
Definition helpdata.c:5282
char * helptext_unit(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct unit_type *utype, bool class_help)
Definition helpdata.c:1992
void helptext_extra(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct extra_type *pextra)
Definition helpdata.c:3864
void helptext_goods(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct goods_type *pgood)
Definition helpdata.c:4329
const char * helptext_road_bonus_str(const struct terrain *pterrain, const struct road_type *proad)
Definition helpdata.c:3700
char * helptext_unit_upkeep_str(const struct unit_type *utype)
Definition helpdata.c:5079
const char * helptext_extra_for_terrain_str(struct extra_type *pextra, struct terrain *pterrain, enum unit_activity act)
Definition helpdata.c:3830
void helptext_specialist(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct specialist *pspec)
Definition helpdata.c:4375
const struct help_item * get_help_item_spec(const char *name, enum help_page_type htype, int *pos)
Definition helpdata.c:1346
char * helptext_building(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, const struct impr_type *pimprove)
Definition helpdata.c:1439
void helptext_terrain(char *buf, size_t bufsz, struct player *pplayer, const char *user_text, struct terrain *pterrain)
Definition helpdata.c:3590
void helptext_nation(char *buf, size_t bufsz, struct nation_type *pnation, const char *user_text)
Definition helpdata.c:5116
#define help_items_iterate(pitem)
Definition helpdata.h:72
#define help_items_iterate_end
Definition helpdata.h:76
#define HELP_ABOUT_ITEM
help_page_type
Definition helpdlg_g.h:20
@ HELP_ANY
Definition helpdlg_g.h:20
@ HELP_TERRAIN
Definition helpdlg_g.h:21
@ HELP_EXTRA
Definition helpdlg_g.h:21
@ HELP_NATIONS
Definition helpdlg_g.h:24
@ HELP_LAST
Definition helpdlg_g.h:25
@ HELP_IMPROVEMENT
Definition helpdlg_g.h:20
@ HELP_UNIT
Definition helpdlg_g.h:20
@ HELP_SPECIALIST
Definition helpdlg_g.h:22
@ HELP_GOVERNMENT
Definition helpdlg_g.h:22
@ HELP_GOODS
Definition helpdlg_g.h:22
@ HELP_WONDER
Definition helpdlg_g.h:21
@ HELP_TECH
Definition helpdlg_g.h:21
@ HELP_TEXT
Definition helpdlg_g.h:20
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
int impr_base_build_shield_cost(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
struct impr_type * improvement_by_translated_name(const char *name)
const char * improvement_name_translation(const struct impr_type *pimprove)
#define improvement_iterate_end
#define improvement_iterate(_p)
void put_drawn_sprites(struct canvas *pcanvas, float zoom, int canvas_x, int canvas_y, int count, struct drawn_sprite *pdrawn, bool fog)
const char * move_points_text(int mp, bool reduce)
Definition movement.c:1066
struct nation_type * nation_by_translated_plural(const char *name)
Definition nation.c:106
int len
Definition packhand.c:128
const char * universal_name_translation(const struct universal *psource, char *buf, size_t bufsz)
#define requirement_fulfilled_by_terrain(_ter_, _rqs_)
#define requirement_vector_iterate_end
#define requirement_vector_iterate(req_vec, preq)
int research_goal_unknown_techs(const struct research *presearch, Tech_type_id goal)
Definition research.c:753
const char * research_advance_name_translation(const struct research *presearch, Tech_type_id tech)
Definition research.c:276
struct research * research_get(const struct player *pplayer)
Definition research.c:130
enum tech_state research_invention_state(const struct research *presearch, Tech_type_id tech)
Definition research.c:622
#define ARRAY_SIZE(x)
Definition shared.h:85
struct specialist * specialist_by_translated_name(const char *name)
Definition specialist.c:141
cairo_surface_t * surface
Definition canvas.h:23
struct connection conn
Definition client_main.h:96
Definition colors.h:21
struct player * playing
Definition connection.h:151
bool buildable
Definition extras.h:116
int build_time
Definition extras.h:118
char * text
Definition helpdata.h:26
enum help_page_type page
Definition helpdlg.c:102
enum help_page_selection::@159 type
union help_page_selection::@160 u
const struct requirement * req
Definition helpdlg.c:103
Definition climisc.h:82
struct terrain * cultivate_result
Definition terrain.h:108
struct extra_type ** resources
Definition terrain.h:97
int plant_time
Definition terrain.h:112
struct terrain * plant_result
Definition terrain.h:111
int defense_bonus
Definition terrain.h:93
int cultivate_time
Definition terrain.h:109
int movement_cost
Definition terrain.h:92
int output[O_LAST]
Definition terrain.h:95
int transform_time
Definition terrain.h:124
struct terrain * transform_result
Definition terrain.h:122
int defense_strength
Definition unittype.h:523
int firepower
Definition unittype.h:532
const struct unit_type * obsoleted_by
Definition unittype.h:536
int vision_radius_sq
Definition unittype.h:529
int move_rate
Definition unittype.h:524
int attack_strength
Definition unittype.h:522
enum universals_n kind
Definition fc_types.h:595
int fc_snprintf(char *str, size_t n, const char *format,...)
Definition support.c:960
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47
struct advance * advance_by_number(const Tech_type_id atype)
Definition tech.c:110
struct advance * advance_by_translated_name(const char *name)
Definition tech.c:190
struct advance * advance_requires(const struct advance *padvance, enum tech_req require)
Definition tech.c:139
const char * advance_name_translation(const struct advance *padvance)
Definition tech.c:305
Tech_type_id advance_required(const Tech_type_id tech, enum tech_req require)
Definition tech.c:124
bool is_regular_advance(struct advance *padvance)
Definition tech.c:295
Tech_type_id advance_number(const struct advance *padvance)
Definition tech.c:100
#define advance_iterate_all_end
Definition tech.h:277
@ AR_TWO
Definition tech.h:109
@ AR_ONE
Definition tech.h:108
#define advance_iterate_all(_p)
Definition tech.h:276
#define A_NONE
Definition tech.h:43
#define A_LAST
Definition tech.h:45
struct terrain * terrain_by_translated_name(const char *name)
Definition terrain.c:204
const char * terrain_name_translation(const struct terrain *pterrain)
Definition terrain.c:240
#define T_NONE
Definition terrain.h:61
struct sprite * get_building_sprite(const struct tileset *t, const struct impr_type *pimprove)
Definition tilespec.c:7033
int fill_basic_extra_sprite_array(const struct tileset *t, struct drawn_sprite *sprs, const struct extra_type *pextra)
Definition tilespec.c:7462
int fill_basic_terrain_layer_sprite_array(struct tileset *t, struct drawn_sprite *sprs, int layer, struct terrain *pterrain)
Definition tilespec.c:7429
int tileset_tile_height(const struct tileset *t)
Definition tilespec.c:791
struct sprite * get_unittype_sprite(const struct tileset *t, const struct unit_type *punittype, enum unit_activity activity, enum direction8 facing)
Definition tilespec.c:7055
struct sprite * get_nation_flag_sprite(const struct tileset *t, const struct nation_type *pnation)
Definition tilespec.c:7006
int tileset_tile_width(const struct tileset *t)
Definition tilespec.c:779
struct sprite * get_tech_sprite(const struct tileset *t, Tech_type_id tech)
Definition tilespec.c:7024
struct goods_type * goods_by_translated_name(const char *name)
bool is_tech_req_for_utype(const struct unit_type *ptype, struct advance *padv)
Definition unittype.c:2756
int utype_build_shield_cost_base(const struct unit_type *punittype)
Definition unittype.c:1493
struct advance * utype_primary_tech_req(const struct unit_type *ptype)
Definition unittype.c:2742
struct unit_type * unit_type_by_translated_name(const char *name)
Definition unittype.c:1778
const char * utype_name_translation(const struct unit_type *punittype)
Definition unittype.c:1586
#define unit_type_iterate(_p)
Definition unittype.h:863
#define unit_type_iterate_end
Definition unittype.h:870
#define U_NOT_OBSOLETED
Definition unittype.h:535
const char * freeciv_name_version(void)
Definition version.c:35