-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgui.c
More file actions
14714 lines (11815 loc) · 355 KB
/
gui.c
File metadata and controls
14714 lines (11815 loc) · 355 KB
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
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Race for the Galaxy AI
*
* Copyright (C) 2009-2011 Keldon Jones
*
* Source file modified by B. Nordli, August 2014.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "rftg.h"
#include "client.h"
#include "comm.h"
/* Apple OS X specific-code */
#ifdef __APPLE__
#include "CoreFoundation/CoreFoundation.h"
#include "gtk-mac-menu.h"
#endif
#define TITLE "Race for the Galaxy " RELEASE
/*
* Our default options.
*/
options opt =
{
3, // num_players
};
/*
* Keyfile with our preferences.
*/
static GKeyFile *pref_file;
/*
* AI verbosity.
*/
int verbose = 0;
/*
* Current (real) game state.
*/
game real_game;
/*
* Flags for game tampered state.
*/
#define TAMPERED_SAVE 0x1
#define TAMPERED_LOAD 0x2
#define TAMPERED_SEED 0x4
#define TAMPERED_UNDO 0x8
#define TAMPERED_LOOK 0x10
#define TAMPERED_MOVE 0x20
/*
* Whether the current game has been "tampered" with in some way.
*/
static int game_tampered;
/*
* Current undo position.
*/
static int num_undo;
/*
* Total number of undo positions saved.
*/
static int max_undo;
/*
* Whether the game is replaying or not.
*/
static int game_replaying;
/*
* Choice logs for each player.
*/
static int *orig_log[MAX_PLAYER];
/*
* Original log sizes for each player.
*/
static int orig_log_size[MAX_PLAYER];
/*
* Games started (used for random sampling)
*/
static int games_started;
/*
* Player we're playing as.
*/
int player_us;
/*
* We have restarted the main game loop.
*/
int restart_loop;
static char *goal_description[MAX_GOAL] =
{
"First to have five VP chips",
"First to have worlds of all four kinds",
"First to have three Alien cards",
"First to discard at end of round",
"First to have powers in all phases, plus Trade",
"First to place a 6-cost development giving ? VPs",
"First to have three Uplift cards",
"First to have four goods",
"First to have eight cards",
"First to have negative Military and two worlds\n"
" or a takeover attack power and two Military worlds",
"First to have two prestige chips and three VP chips",
"First to have three Imperium cards\n"
" or four Military worlds",
"Most total military",
"Most Novelty and/or Rare worlds",
"Most developments",
"Most production worlds",
"Most cards with Explore powers",
"Most Rebel Military worlds",
"Most prestige chips",
"Most cards with Consume powers",
};
/*
* Player names.
*/
static char *player_names[MAX_PLAYER] =
{
"Blue",
"Red",
"Green",
"Yellow",
"Cyan",
"Purple",
};
/*
* Player color names.
*/
static char *player_colors[MAX_PLAYER] =
{
"#8888aa",
"#aa8888",
"#88aa88",
"#aaaa88",
"#88aaaa",
"#aa88aa",
};
/*
* Card image size.
*/
#define CARD_WIDTH 372
#define CARD_HEIGHT 520
/*
* Goal image size.
*/
#define GOALF_WIDTH 260
#define GOALF_HEIGHT 297
#define GOALM_WIDTH 296
#define GOALM_HEIGHT 447
/*
* Colors to highlight with.
*/
#define HIGH_NONE 0
#define HIGH_YELLOW 1
#define HIGH_RED 2
/*
* Information about a displayed card.
*/
typedef struct displayed
{
/* Card's index in the deck */
int index;
/* Card's design pointer */
design *d_ptr;
/* Card is in hand (instead of on table) */
int hand;
/* Card is eligible for being chosen */
int eligible;
/* Card should be seperated from others */
int gapped;
/* Card is selected */
int selected;
/* Card should deselect all others when selected */
int greedy;
/* Card should be highlighted in this color when selected */
int highlight;
/* Card should be highlighted in this color when not selected */
int highlight_else;
/* Card should be "pushed up" when selected */
int push;
/* Card is not eligible for selection, but should be colored anyway */
int color;
/* Card is covered by goods */
int num_goods;
/* Order card was played in (if on table) */
int order;
/* Tooltip to display (if any) */
char *tooltip;
} displayed;
/*
* List of cards in hand.
*/
static displayed hand[MAX_DECK];
static int hand_size;
/*
* List of cards on table (per player).
*/
static displayed table[MAX_PLAYER][MAX_DECK];
static int table_size[MAX_PLAYER];
typedef struct discounts
{
/* The base discount */
int base;
/* The current temporary discount */
int bonus;
/* Additional specific discount */
int specific[6];
/* May discard to place at zero count */
int zero;
/* Additional discount when paying for military */
int pay_discount;
/* May pay for military with 0 discount (Rebel Cantina) */
int non_alien_mil_0;
/* May pay for military with 1 discount (Contact Specialist) */
int non_alien_mil_1;
/* May pay for rebel worlds with 2 discount (Rebel Alliance) */
int rebel_mil_2;
/* May pay for chromosome worlds (Ravaged Uplift World) */
int chromo_mil;
/* May pay for alien worlds (Alien Research Team) */
int alien_mil;
/* May discard to conquer with 0 discount (Imperium Invasion Fleet) */
int conquer_settle_0;
/* May discard to conquer with 2 discount (Imperium Cloaking Tech) */
int conquer_settle_2;
/* Any value is set */
int has_data;
} discounts;
typedef struct mil_strength
{
/* Base military */
int base;
/* Current temporary military */
int bonus;
/* Maximum additional temporary military */
int max_bonus;
/* Additional military against rebel worlds */
int rebel;
/* Additional specific military */
int specific[6];
/* Additional extra defense during takeovers */
int defense;
/* Additional military when using attack imperium TO power */
int attack_imperium;
/* Name of attack imperium TO power */
char imp_card[64];
/* Imperium world played */
int imperium;
/* Rebel military world played */
int military_rebel;
/* Any value is set */
int has_data;
} mil_strength;
/*
* Cached status information to be displayed per player.
*/
typedef struct status_display
{
/* Name to display */
char name[80];
/* Actions */
int action[2];
/* Victory point chips */
int vp;
/* Total victory points */
int end_vp;
/* Cards in hand */
int cards_hand;
/* Prestige */
int prestige;
/* Settle discount */
discounts discount;
/* Military strength */
mil_strength military;
/* Text of VP tooltip */
char vp_tip[1024];
/* Text of discount tooltip */
char discount_tip[1024];
/* Text of military strength tooltip */
char military_tip[1024];
/* Text of prestige tooltip */
char prestige_tip[1024];
/* Array of goals to display */
int goal_display[MAX_GOAL];
/* Array of goals to be grayed out */
int goal_gray[MAX_GOAL];
/* Array of goal tooltips */
char goal_tip[MAX_GOAL][1024];
} status_display;
/*
* Array of displayed status information per player.
*/
static status_display status_player[MAX_PLAYER];
/*
* Other displayed status information.
*/
static int display_deck, display_discard, display_pool;
/*
* Extra text and font string to be drawn on an image.
*/
struct extra_info
{
char text[1024];
char *fontstr;
int border;
int top_left;
};
/*
* Restriction types on action button sensitivity.
*/
#define RESTRICT_NUM 1
#define RESTRICT_BOTH 2
#define RESTRICT_PAY 3
#define RESTRICT_GOOD 4
#define RESTRICT_TAKEOVER 5
#define RESTRICT_DEFEND 6
#define RESTRICT_UPGRADE 7
#define RESTRICT_CONSUME 8
#define RESTRICT_START 9
/*
* Restriction on action button.
*/
static int action_restrict;
static int action_min, action_max, action_payment_which, action_payment_mil;
static int action_payment_bonus;
static int action_cidx, action_oidx;
/*
* Number of icon images.
*/
#define MAX_ICON 25
/*
* Special icon numbers.
*/
#define ICON_NO_ACT 10
#define ICON_HANDSIZE 11
#define ICON_VP 12
#define ICON_MILITARY 13
#define ICON_PRESTIGE 14
#define ICON_WAITING 15
#define ICON_READY 16
#define ICON_OPTION 17
#define ICON_DISCARD 18
#define ICON_VP_EMPTY 19
#define ICON_DISCOUNT 20
#define ICON_DRAW 21
#define ICON_DRAW_EMPTY 22
#define ICON_EXPLORE 23
#define ICON_CONSUME 24
/*
* Number of action card images.
*/
#define MAX_ACT_CARD 11
/*
* Card images.
*/
static GdkPixbuf *image_cache[AVAILABLE_DESIGN];
/*
* Goal card images.
*/
static GdkPixbuf *goal_cache[MAX_GOAL];
/*
* Icon images.
*/
static GdkPixbuf *icon_cache[MAX_ICON];
/*
* Action card images.
*/
static GdkPixbuf *action_cache[MAX_ACT_CARD];
/*
* Card back image.
*/
static GdkPixbuf *card_back;
/*
* Widgets used in multiple functions.
*/
static GtkWidget *full_image;
static GtkWidget *hand_area;
static GtkWidget *player_area[MAX_PLAYER], *orig_area[MAX_PLAYER];
static GtkWidget *player_status[MAX_PLAYER], *orig_status[MAX_PLAYER];
static GtkWidget *player_box[MAX_PLAYER], *player_sep[MAX_PLAYER];
static GtkWidget *goal_area;
static GtkWidget *game_status;
static GtkWidget *main_hbox, *lobby_vbox;
static GtkWidget *phase_box, *action_box;
static GtkWidget *new_item, *new_parameters_item;
static GtkWidget *load_item, *replay_item, *save_item, *export_item;
static GtkWidget *undo_item, *undo_round_item, *undo_game_item;
static GtkWidget *redo_item, *redo_round_item, *redo_game_item;
static GtkWidget *option_item, *advanced_item, *quit_item;
static GtkWidget *debug_card_item, *debug_ai_item, *about_item;
static GtkWidget *connect_item, *disconnect_item, *resign_item;
static GtkWidget *entry_hbox;
/*
* Lists for online functions.
*/
GtkListStore *user_list;
GtkTreeStore *game_list;
/*
* Widgets used by network functions.
*/
GtkWidget *entry_label, *chat_view;
GtkWidget *games_view, *password_entry;
GtkWidget *create_button, *join_button, *leave_button, *kick_button;
GtkWidget *addai_button, *start_button;
GtkWidget *action_prompt, *action_button;
/*
* Keyboard accelerator group for main window.
*/
static GtkAccelGroup *window_accel;
#define MAX_ACCEL 18
/*
* List of accelerator keys.
*/
static unsigned int accel_keys[MAX_ACCEL];
/*
* List of accelerator modifiers.
*/
static GdkModifierType accel_mods[MAX_ACCEL];
/*
* Map from actions to accelerators.
*/
static unsigned int act_to_accel[] = {5, 0, 9, 1, 10, 2, 11, 3, 12, 4};
/*
* Whether user has used accel keys during this choice.
*/
static int accel_used;
/*
* Number of candidates to keep (during search), or save.
* TODO: Make a WHERE_REVEALED location.
*/
static int num_special_cards;
/*
* List of special gui cards.
*/
static card *special_cards[20];
/*
* Text buffer for message area.
*/
GtkWidget *message_view;
/*
* Mark at end of message area text buffer.
*/
GtkTextMark *message_end;
/*
* y-coordinate of line of "last seen" text in buffer.
*/
static int message_last_y;
/*
* Check whether a log position marks a round boundary.
*/
int is_round_boundary(int advanced, int *p)
{
/* Only start and action choices are boundary */
if (*p != CHOICE_START && *p != CHOICE_ACTION) return FALSE;
/* Second choice of Psi-Crystal is not a boundary */
/* XXX This only works in newer save games */
if (advanced && *(p + 1) == 2) return FALSE;
/* Everything else is */
return TRUE;
}
/*
* Add text to the message buffer.
*/
void message_add(game *g, char *msg)
{
GtkTextIter end_iter;
GtkTextBuffer *message_buffer;
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Get end mark */
gtk_text_buffer_get_iter_at_mark(message_buffer, &end_iter,
message_end);
/* Add message */
gtk_text_buffer_insert(message_buffer, &end_iter, msg, -1);
/* Scroll to end mark */
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(message_view),
message_end);
}
/*
* Add formatted text to the message buffer.
*/
void message_add_formatted(game *g, char *msg, char *tag)
{
GtkTextIter end_iter;
GtkTextBuffer *message_buffer;
/* Check for empty tag */
if (!strlen(tag))
{
/* Add unformatted message */
message_add(g, msg);
return;
}
/* Do not log verbose message while verbosity is disabled */
if (!strcmp(tag, FORMAT_VERBOSE) && !opt.verbose_log) return;
/* Do not log draw messages while draw log is disabled */
if (!strcmp(tag, FORMAT_DRAW) && !opt.draw_log) return;
/* Do not log discard messages while discard log is disabled */
if (!strcmp(tag, FORMAT_DISCARD) && !opt.discard_log) return;
/* Check for emphasized message formatting */
if (strcmp(tag, FORMAT_EM) && !opt.colored_log)
{
/* Skip coloring when colored log is off */
message_add(g, msg);
return;
}
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Get end mark */
gtk_text_buffer_get_iter_at_mark(message_buffer, &end_iter,
message_end);
/* Add formatted message */
gtk_text_buffer_insert_with_tags_by_name(message_buffer,
&end_iter,
msg, -1, tag,
NULL);
/* Scroll to end mark */
gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(message_view),
message_end);
}
/*
* Add a private message to the message buffer.
*/
void message_add_private(game *g, int who, char *msg, char *tag)
{
/* Verify we are the correct player */
if (who == player_us)
{
/* Add message */
message_add_formatted(g, msg, tag);
}
}
/*
* Handle an error dialog with a message.
*/
void display_error(char *msg)
{
GtkWidget *alert;
/* Create error dialog */
alert = gtk_message_dialog_new(NULL,
GTK_DIALOG_DESTROY_WITH_PARENT,
GTK_MESSAGE_ERROR,
GTK_BUTTONS_CLOSE,
"%s", msg);
/* Set title */
gtk_window_set_title(GTK_WINDOW(alert), TITLE);
/* Run dialog */
gtk_dialog_run(GTK_DIALOG(alert));
/* Destroy alert dialog */
gtk_widget_destroy(alert);
}
/*
* Use simple random number generator.
*/
int game_rand(game *g)
{
/* Call simple random number generator */
return simple_rand(&g->random_seed);
}
/*
* Clear message log.
*/
static void clear_log(void)
{
GtkTextBuffer *message_buffer;
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Clear text buffer */
gtk_text_buffer_set_text(message_buffer, "", 0);
/* Reset last seen line */
message_last_y = 0;
}
/*
* Draw a line across the message text view.
*/
static gboolean message_view_expose(GtkWidget *text_view, GdkEventExpose *event,
gpointer data)
{
int x, y;
int w;
/* Convert buffer coordinates to window coordinates */
gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(text_view),
GTK_TEXT_WINDOW_WIDGET,
0, message_last_y, &x, &y);
/* Don't draw line at very top of window */
if (!y) return FALSE;
/* Get widget width */
w = text_view->allocation.width;
/* Draw line across window */
gdk_draw_line(event->window, text_view->style->black_gc, 0, y, w, y);
/* Continue handling event */
return FALSE;
}
/*
* Update the card image with the given image.
*/
void update_card(GdkPixbuf *newbuf)
{
static GdkPixbuf *buf;
GdkPixbuf *scaled_buf;
double card_width, card_height;
/* Set image to card back on startup */
if (!buf) buf = card_back;
/* Check if image is updated */
if (newbuf)
{
/* Remember the new image */
buf = newbuf;
}
/* Don't do anything if image hidden */
if (opt.hide_card == 2) return;
/* Compute card width */
card_width = opt.card_size ? opt.card_size : CARD_WIDTH;
/* Compute card height */
card_height = CARD_HEIGHT * (card_width / CARD_WIDTH);
/* Scale image */
scaled_buf = gdk_pixbuf_scale_simple(buf,
(int) card_width, (int) card_height,
GDK_INTERP_BILINEAR);
/* Set image */
gtk_image_set_from_pixbuf(GTK_IMAGE(full_image), scaled_buf);
/* Remove our scaled buffer */
g_object_unref(G_OBJECT(scaled_buf));
}
/*
* Called when mouse moves over the log window.
*/
static gboolean message_motion(GtkWidget *text_view, GdkEventMotion *event,
gpointer data)
{
int window_x, window_y, buffer_x, buffer_y, i;
GtkTextIter iter_start, iter_end;
char *line;
/* Check for hint event */
if (event->is_hint)
{
/* Extract coordinates */
gdk_window_get_pointer(event->window, &window_x, &window_y, NULL);
}
else
{
/* Take coordinates directly */
window_x = (int) event->x;
window_y = (int) event->y;
}
/* Convert window coordinates to buffer coordinates */
gtk_text_view_window_to_buffer_coords(GTK_TEXT_VIEW(message_view),
GTK_TEXT_WINDOW_WIDGET,
window_x, window_y,
&buffer_x, &buffer_y);
/* Get start of line */
gtk_text_view_get_line_at_y(GTK_TEXT_VIEW(message_view),
&iter_start, buffer_y, NULL);
/* Get end of line */
iter_end = iter_start;
gtk_text_iter_forward_line(&iter_end);
/* Get line contents */
line = gtk_text_iter_get_text(&iter_start, &iter_end);
/* Loop over cards in game */
for (i = 0; i < real_game.deck_size; i++)
{
/* Check if card name is found */
if (strstr(line, real_game.deck[i].d_ptr->name))
{
/* Update image */
update_card(image_cache[real_game.deck[i].d_ptr->index]);
/* Card is found */
break;
}
}
/* Destroy line */
g_free(line);
/* Continue handling event */
return FALSE;
}
/*
* Add a separator at the end of all previously seen text.
*/
static void reset_text_separator(void)
{
GtkTextIter end_iter;
GtkTextBuffer *message_buffer;
GdkRectangle rect;
int x, y;
/* Convert current line coordinates to window coordinates */
gtk_text_view_buffer_to_window_coords(GTK_TEXT_VIEW(message_view),
GTK_TEXT_WINDOW_WIDGET,
0, message_last_y, &x, &y);
/* Invalidate old line */
gtk_widget_queue_draw_area(message_view, 0, y,
message_view->allocation.width, 1);
/* Get message buffer */
message_buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(message_view));
/* Get end mark */
gtk_text_buffer_get_iter_at_mark(message_buffer, &end_iter,
message_end);
/* Get location (in buffer coordinates) of end iterator */
gtk_text_view_get_iter_location(GTK_TEXT_VIEW(message_view), &end_iter,
&rect);
/* Remember y-coordinate */
message_last_y = rect.y;
}
/*
* Load pixbufs with card images from image bundle.
*
* The image bundle format is nothing special -- it exists mainly to make
* it difficult for people to get at the images directly.
*
* This was requested by Tom Lehmann.
*/
static void load_image_bundle(void)
{
GFile *bundle;
GInputStream *fs, *ms;
GdkPixbuf **pix_ptr;
GdkPixbuf *tmp_pixbuf;
char buf[1024], *data_buf;
int count, x;
/* Create bundle file handle */
bundle = g_file_new_for_path(RFTGDIR "/images.data");
/* Open file for reading */
fs = G_INPUT_STREAM(g_file_read(bundle, NULL, NULL));
/* Check for error */
if (!fs)
{
/* Try reading from current directory instead */
bundle = g_file_new_for_path("images.data");
/* Open file for reading */
fs = G_INPUT_STREAM(g_file_read(bundle, NULL, NULL));
}
/* Check for error */
if (!fs)
{
/* File not found */
return;
}
/* Read header */
count = g_input_stream_read(fs, buf, 4, NULL, NULL);
/* Check header */
if (strncmp(buf, "RFTG", 4))
{
/* Error */
display_error("Error: Image bundle missing header!\n");
return;
}
/* Loop until end of file */
while (1)
{
/* Get next type of image */
count = g_input_stream_read(fs, buf, 1, NULL, NULL);
/* Check for end of file */
if (buf[0] == 0) break;
/* Check for card image */
if (buf[0] == 1)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 4, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &image_cache[x];
}
/* Check for card back image */
else if (buf[0] == 2)
{
/* Get pointer to pixbuf */
pix_ptr = &card_back;
}
/* Check for goal image */
else if (buf[0] == 3)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 3, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &goal_cache[x];
}
/* Check for icon image */
else if (buf[0] == 4)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 3, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &icon_cache[x];
}
/* Check for action card image */
else if (buf[0] == 5)
{
/* Read card number */
count = g_input_stream_read(fs, buf, 3, NULL, NULL);
/* Convert to integer */
x = strtol(buf, NULL, 10);
/* Get pointer to pixbuf holder */
pix_ptr = &action_cache[x];
}