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
|
/* $Header: /home/jcb/newmj/RCS/gui.h,v 11.12 2002/01/05 23:31:26 jcb Rel $
* gui.h
* type defns and forward declarations for the gui module.
*/
/****************** COPYRIGHT STATEMENT **********************
* This file is Copyright (c) 2000 by J. C. Bradfield. *
* Distribution and use is governed by the LICENCE file that *
* accompanies this file. *
* The moral rights of the author are asserted. *
* *
***************** DISCLAIMER OF WARRANTY ********************
* This code is not warranted fit for any purpose. See the *
* LICENCE file for further information. *
* *
*************************************************************/
#include <gtk/gtk.h>
#include <gdk/gdkkeysyms.h>
#include "lazyfixed.h"
#include "vlazyfixed.h"
#include "sysdep.h"
#include <errno.h>
#include "client.h"
#include <math.h>
/*********************
TYPE DEFINITIONS
*********************/
/* a tilesetbox is a TileSet and a widget that boxes it.
The TileSet is stored to avoid unnecessary updating of the box
*/
typedef struct _TileSetBox {
TileSet set;
GtkWidget *widget; /* the widget itself */
GtkWidget *tiles[4]; /* the children buttons */
} TileSetBox;
/* This struct represents the display of a player. It gives
access to relevant widgets without requiring excessive casting
and pointer chasing.
*/
typedef struct _PlayerDisp {
PlayerP player; /* pointer to the game player structure */
/* this is the whole box representing the player */
GtkWidget *widget;
/* the orientation says which way round tiles go
(equivalently, which player we are in the table).
The tilepixmaps are those appropriate assuming that players
look at their own tiles. If the players politely display
their sets to be readable by the others, then the orientation
of exposed tiles is flipped from these.
that the orientations are:
0: upright (for our own tiles)
1: top to left: player to the right (south, when we're east)
2: upside down (player opposite)
3: top to right (north).
*/
int orientation;
/* and accordingly the following macro can be used if concealed
and exposed tiles are oriented differently */
/* # define flipori(ori) ((ori+2)%4) */
#define flipori(ori) ori
/* this is an array of buttons representing the concealed tiles.
For initial size calculation, it should be filled with blanks.
(Ideally, unmapped, but I can't see how to do that.)
They appear from the left in the "concealed" row.
*/
GtkWidget *conc[MAX_CONCEALED];
/* This is an array representing the declared specials
that have overflowed into the concealed row.
Initially, exactly five of these should be shown: that makes
the whole "concealed" row 19 tiles wide, which gives enough
room for reasonable collections of specials, and makes the "exposed"
row big enough for four kongs and a pair.
They appear to the right of the concealed row.
*/
GtkWidget *extras[8];
/* These are the specials that have found room where we want
them, at the end of the exposed row */
GtkWidget *spec[8];
/* each of these is a box representing a declared set.
Each set is packed into the exposed row, from the left,
with a 1/4 tile spacing between them (thus fitting
4 kongs and a pair in exactly).
Size is determined by the concealed row, so there is
no need to show these initially.
*/
/* This is the tong box. It appears to the right of the exposed row specials*/
GtkWidget *tongbox;
TileSetBox esets[MAX_TILESETS];
/* each of these is a box representing a concealed set.
They appear to the left of the concealed tile set, with
the 1/4 tile spacing. They are initially hidden, and
appear only in scoring.
*/
TileSetBox csets[MAX_TILESETS];
/* these is not actually in the player area, but to do with
discards */
GtkWidget *discards[32]; /* buttons for this player's discards */
int dx[32], dy[32]; /* save calculated posns of discard tiles */
int num_discards;
gint16 x,y; /* x and y for next discard */
int row; /* which row is next discard in */
gint16 xmin[5],xmax[5]; /* in each row, first point used, leftmost point free*/
int plane; /* if desperate, we start stacking tiles */
/* This is the window for pung! claims etc. */
GtkWidget *claimw;
GtkWidget *claimlab; /* and the label inside it */
int claim_serial; /* the discard for which this window was popped up */
int claim_time; /* time popped up (in millisecs since start of program) */
} PlayerDisp;
/* This is a one use structure representing the dialog box
used for claiming discards. It has two personalities:
normally it shows buttons
Noclaim Chow Pung Kong MahJong
but after a mahjong claim it shows
Eyes Chow Pung Special Hand
*/
typedef struct {
GtkWidget *widget; /* the box itself */
GtkWidget *tilename; /* the label for the tile name */
GtkWidget *tiles[4]; /* the buttons for the tiles as discarded
by each player. Element 0 is unused. */
/* the various buttons */
GtkWidget *noclaim;
GtkWidget *eyes;
GtkWidget *chow;
GtkWidget *pung;
GtkWidget *special;
GtkWidget *kong;
GtkWidget *mahjong;
GtkWidget *robkong;
int mode; /* 0 normally, 1 in mahjong mode, 2 for robbing kongs */
} DiscardDialog;
/* this is used by functions that display or remove tiles to pass
back information to the animation routines. The structure contains
information about the tiles.
*/
typedef struct {
GtkWidget *target; /* the widget to which this information refers,
if it is being newly displayed. In this case,
the widget is not shown, and it is the animator's
job to show it at the end of animation.
If target is null, then the widget is being
undisplayed. */
Tile t; /* the tile displayed by the widget */
int ori; /* and its orientation */
int x, y; /* x and y coordinates relative to the boardframe */
} AnimInfo;
/* enums used in the dialog popup function to specify position */
typedef enum {
DPCentred, /* centered over main window */
DPOnDiscard, /* bottom left corner in same place as discard dialog */
DPErrorPos, /* for error dialogs: centred over top of main window */
DPNone, /* don't touch the positioning at all */
DPCentredOnce, /* centre it on first popup, then don't fiddle */
DPOnDiscardOnce, /* on discard dialog first time, then don't fiddle */
} DPPosn;
/* Where to put the dialog boxes */
typedef enum {
DialogsUnspecified = 0,
DialogsCentral = 1,
DialogsBelow = 2,
DialogsPopup = 3 } DialogPosition;
/* extra data in the game */
typedef struct {
int orig_live_end; /* value of wall.live_end at start of hand */
} GameExtras;
#define gextras(g) ((GameExtras *)(g->userdata))
/*****************
FORWARD DECLARATIONS
*****************/
/* FUNCTIONS */
void apply_game_prefs(void);
GtkWidget *build_or_refresh_option_panel(GameOptionTable *got,GtkWidget *panel);
GtkWidget *build_or_refresh_prefs_panel(GameOptionTable *got,GtkWidget *panel);
void button_set_tile(GtkWidget *b, Tile t, int ori);
void chow_dialog_init(void);
void close_connection(void);
void close_saving_posn(GtkWidget *w);
void conc_callback(GtkWidget *w, gpointer data);
void continue_dialog_init(void);
void continue_dialog_popup(void);
void create_dialogs(void);
void create_display(void);
void destroy_dialogs(void);
void destroy_display(void);
void dialog_popup(GtkWidget *dialog, DPPosn posn);
void disc_callback(GtkWidget *w, gpointer data);
void discard_dialog_init(void);
void discard_dialog_popup(Tile t, int ori, int mode);
void do_chow(GtkWidget *w, gpointer data);
gint doubleclicked(GtkWidget *w, GdkEventButton *eb,gpointer data);
void ds_dialog_init(void);
void ds_dialog_popup(void);
void error_dialog_init(void);
void error_dialog_popup(char *msg);
void game_option_init(void);
void game_prefs_init(void);
void info_dialog_popup(char *msg);
GtkWidget *menubar_create(void);
GtkWidget *make_or_refresh_option_updater(GameOptionEntry *goe, int prefsp);
void messagewindow_init(void);
void nag_popup(void);
void option_reset_callback(GtkWidget *w, gpointer data);
void option_updater_callback(GtkWidget *w, gpointer data);
void open_connection(GtkWidget *w UNUSED, gpointer data);
void open_dialog_init(char *ht, char *pt, char *ft, char *idt, char *nt, int usehost);
void open_dialog_popup(GtkWidget *w UNUSED, gpointer data);
void prefs_updater_callback(GtkWidget *w, gpointer data);
int read_or_update_rcfile(char *rcfile,
int do_display,
int do_player,
int do_game,
int do_misc);
void scoring_dialog_init(void);
void scoring_dialog_popup(void);
void set_dialog_posn(DialogPosition p);
void set_animation(int a);
void setup_dialogs(void);
void showraise(GtkWidget *w);
void status_init(void);
void status_showraise(void);
void status_update(int game_over);
void textwindow_init(void);
void tilesetbox_highlight_nth(TileSetBox *tb,int n);
void tilesetbox_init(TileSetBox *tb, int ori,GtkSignalFunc func,gpointer func_data);
void tilesetbox_set(TileSetBox *tb, const TileSet *ts, int ori);
void turn_dialog_init(void);
void turn_dialog_popup(void);
void usage(char *pname,char *msg);
/* Convenience function */
#define send_packet(m) client_send_packet(the_game,(PMsgMsg *)m)
/* VARIABLES */
/* in gui.c */
extern int debug;
extern PlayerP our_player;
extern int our_id;
extern seats our_seat; /* our seat in the game */
extern Game *the_game;
extern int selected_button; /* the index of the user's selected
tile, or -1 if none */
extern int ptimeout; /* claim timeout time in milliseconds */
extern GdkPixmap **tilepixmaps[]; /* pixmaps for the tiles */
extern GtkWidget *topwindow; /* main window */
extern GtkWidget *menubar; /* menubar */
extern GtkWidget *board; /* the table area itself */
extern GtkWidget *boardframe; /* fixed widget wrapping the board */
extern GtkWidget *outerframe; /* the outermost frame widget */
extern GtkStyle *tablestyle; /* for the dark green stuff */
extern GtkStyle *highlightstyle; /* to highlight tiles */
extern GtkWidget *highlittile; /* the unique highlighted tile */
extern GdkFont *fixed_font; /* a fixed width font */
extern GdkFont *big_font; /* big font for claim windows */
extern GtkWidget *dialoglowerbox; /* encloses dialogs when dialogs are below */
/* Why an array? So I can pass pointers around */
extern DiscardDialog discard_dialog[1];
/* dialog box for specifying chows */
extern GtkWidget *chow_dialog;
/* dialog box for declaring specials */
extern GtkWidget *ds_dialog;
/* dialog box for continuing with next hand */
extern GtkWidget *continue_dialog;
/* dialog for opening connection */
extern GtkWidget *open_dialog;
extern GtkWidget *openmenuentry, *newgamemenuentry, *resumegamemenuentry,
*savemenuentry, *saveasmenuentry, *closemenuentry, *gameoptionsmenuentry;
extern GtkWidget *openallowdisconnectbutton,*opensaveonexitbutton,*openrandomseatsbutton,
*openplayercheckboxes[3],*openplayernames[3],*openplayeroptions[3],*opentimeoutspinbutton;
/* dialog box for action when it's our turn.
Actions: Discard Kong Add to Pung Mah Jong
*/
extern GtkWidget *turn_dialog;
/* dialog box for closed sets when scoring.
Actions: Eyes Chow Pung Done
*/
extern GtkWidget *scoring_dialog;
/* window for game status display */
extern GtkWidget *status_window;
/* an array of text widgets for displaying scores etc.
Element 4 is for settlements.
The others are for each player: currently, I think
these should be table relative.
*/
extern GtkWidget *scoring_notebook;
extern GtkWidget *textpages[5];
extern GtkWidget *textlabels[5]; /* labels for the pages */
extern GtkWidget *textwindow; /* and the window for it */
/* option stuff */
extern char robot_names[3][128];
/* The window for messages, and the display text widget */
extern GtkWidget *messagewindow, *messagetext;
/* completed games, for nagging */
extern int completed_games;
extern int nag_state; /* has user been nagged to pay? */
/* window to nag for donations */
extern GtkWidget *nag_window;
/* This gives the width of a player display in units
of tiles */
extern int pdispwidth;
extern int square_aspect; /* force a square table */
extern int animate; /* do fancy animation */
extern int tiletips; /* show tiletips constantly */
extern int showwall; /* show the wall or not */
extern int iconify_dialogs_with_main; /* as it says ... */
extern char *tileset, *tileset_path; /* tile sets */
extern int pref_showwall; /* preferred value of showwall */
/* the player display areas */
extern PlayerDisp pdisps[NUM_SEATS];
extern int calling; /* disgusting global flag */
/* the widget in which we put discards */
extern GtkWidget *discard_area;
/* This is an allocation structure in which we
note its allocated size, at some point when we
know the allocation is valid.
*/
extern GtkAllocation discard_area_alloc;
extern GtkWidget *just_doubleclicked; /* yech yech yech. See doubleclicked */
/* space round edge of dialog boxes */
extern const gint dialog_border_width;
/* horiz space between buttons */
extern const gint dialog_button_spacing;
/* vert space between text and buttons etc */
extern const gint dialog_vert_spacing;
/* space around player boxes. N.B. this should only
apply to the outermost boxes */
extern const int player_border_width;
extern DialogPosition dialogs_position;
/* in gui-dial.c */
extern GtkWidget *openfile, *openhost, *openport,
*openfiletext, *openhosttext, *openporttext, *openidtext, *opennametext, *opengamefiletext;
extern GtkWidget *display_option_dialog;
extern GtkWidget *game_option_dialog;
extern GtkWidget *game_prefs_dialog;
extern GtkWidget *game_option_panel;
extern GtkWidget *game_prefs_panel;
extern GameOptionTable prefs_table;
/* static for each module */
#include "version.h"
|