From: Jordi Albornoz Date: Sun, 20 Oct 2002 10:03:01 +0000 (+0000) Subject: patches from James Antill: change the attack/defense box's minimum size, to avoid... X-Git-Url: https://hydra-www.ietfng.org/gitweb/?a=commitdiff_plain;h=99bfa966012d0204bbe675fb959bdf55a9dc6fe7;p=gtetrinet patches from James Antill: change the attack/defense box's minimum size, to avoid message wraps as much as possible. Change the toggle page keybinds from F1, F2 and F3 to Alt+1,2,3 as the previous ones were normally captured by window managers. Add different colours for events in attacks/defenses. Fix the random order of added special blocks when the player just has one. --- diff --git a/ChangeLog b/ChangeLog index 9f01c9d..c0d923a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,20 @@ +2002-10-20 Jordi Mallach + + * Patches from James Antill with the following fixes. + * src/fields.c (fields_page_contents): change the attack/defense + box's minimum size, to avoid message wraps as much as possible. + * src/gtetrinet.c (keypress): check for modifier states. + (gtetrinet_key): change the toggle page keybinds from F1, F2 and F3 + to Alt+1,2,3. The previous ones were normally captured by window + managers. + * src/misc.c (textbox_addtext): add continue in next:. + * src/misc.h: define colours for attack/defense messages... + * src/tetrinet.c (tetrinet_dospecial): ... and use them here, + depending on to whom affects the special and its type. + (tetrinet_addspecial): Fix the random order of added special blocks + when the player just has one. + Shorten attack/defense messages. + 2002-10-19 Jordi Mallach * Patch from Cougar which adds IPv6 support. diff --git a/src/fields.c b/src/fields.c index bfc8472..bcd6038 100644 --- a/src/fields.c +++ b/src/fields.c @@ -184,7 +184,7 @@ GtkWidget *fields_page_contents (void) widget = leftlabel_new (_("Next piece:")); gtk_widget_show (widget); - gtk_box_pack_start (GTK_BOX(box), widget, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(box), widget, TRUE, TRUE, 0); /* box that displays the next block */ border = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME(border), GTK_SHADOW_IN); @@ -228,7 +228,7 @@ GtkWidget *fields_page_contents (void) gtk_widget_show (activewidget); gtk_table_attach_defaults (GTK_TABLE(table2), activewidget, 1, 2, 3, 4); gtk_widget_show (table2); - gtk_box_pack_start (GTK_BOX(box), table2, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(box), table2, TRUE, TRUE, 0); gtk_widget_show (box); /* align it */ @@ -243,7 +243,7 @@ GtkWidget *fields_page_contents (void) speciallabel = gtk_label_new (""); gtk_widget_show (speciallabel); fields_setspeciallabel (NULL); - gtk_box_pack_start (GTK_BOX(box), speciallabel, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(box), speciallabel, TRUE, TRUE, 0); border = gtk_frame_new (NULL); gtk_frame_set_shadow_type (GTK_FRAME(border), GTK_SHADOW_IN); specialwidget = gtk_drawing_area_new (); @@ -267,9 +267,9 @@ GtkWidget *fields_page_contents (void) box = gtk_vbox_new (FALSE, 0); widget = gtk_label_new (_("Attacks and defenses:")); gtk_widget_show (widget); - gtk_box_pack_start (GTK_BOX(box), widget, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(box), widget, TRUE, TRUE, 0); attdefwidget = gtk_text_new (NULL, NULL); - gtk_widget_set_usize (attdefwidget, BLOCKSIZE*12, BLOCKSIZE*10); + gtk_widget_set_usize (attdefwidget, MAX(22*12, BLOCKSIZE*12), BLOCKSIZE*10); gtk_text_set_word_wrap (GTK_TEXT(attdefwidget), TRUE); GTK_WIDGET_UNSET_FLAGS (attdefwidget, GTK_CAN_FOCUS); gtk_widget_show (attdefwidget); @@ -279,7 +279,7 @@ GtkWidget *fields_page_contents (void) GTK_POLICY_AUTOMATIC); gtk_container_add (GTK_CONTAINER(scroll), attdefwidget); gtk_widget_show (scroll); - gtk_box_pack_start (GTK_BOX(box), scroll, FALSE, FALSE, 0); + gtk_box_pack_start (GTK_BOX(box), scroll, TRUE, TRUE, 0); gtk_widget_show (box); align = gtk_alignment_new (0.5, 0.5, 0.5, 0.0); gtk_container_add (GTK_CONTAINER(align), box); @@ -289,7 +289,7 @@ GtkWidget *fields_page_contents (void) /* game messages */ table2 = gtk_table_new (1, 2, FALSE); gmsgtext = gtk_text_new (NULL, NULL); - gtk_widget_set_usize (gmsgtext, 0, 46); + gtk_widget_set_usize (gmsgtext, 0, 48); gtk_widget_show (gmsgtext); GTK_WIDGET_UNSET_FLAGS (gmsgtext, GTK_CAN_FOCUS); scroll = gtk_scrolled_window_new (NULL, NULL); diff --git a/src/gtetrinet.c b/src/gtetrinet.c index 7ffe535..afe8b6e 100644 --- a/src/gtetrinet.c +++ b/src/gtetrinet.c @@ -45,7 +45,7 @@ #include "images/winlist.xpm" static GtkWidget *pixmapdata_label (char **d, char *str); -static int gtetrinet_key (int keyval); +static int gtetrinet_key (int keyval, int mod); gint keypress (GtkWidget *widget, GdkEventKey *key); gint keyrelease (GtkWidget *widget, GdkEventKey *key); @@ -266,7 +266,10 @@ gint keypress (GtkWidget *widget, GdkEventKey *key) gtk_timeout_remove (keytimeoutid); if (tetrinet_key (key->keyval, key->string)) goto keyprocessed; } - if (gtetrinet_key(key->keyval)) goto keyprocessed; + if (gtetrinet_key(key->keyval, key->state & (GDK_MOD1_MASK | + GDK_CONTROL_MASK | + GDK_SHIFT_MASK))) + goto keyprocessed; return FALSE; keyprocessed: gtk_signal_emit_stop_by_name (GTK_OBJECT(widget), "key_press_event"); @@ -306,16 +309,19 @@ gint keyrelease (GtkWidget *widget, GdkEventKey *key) /* TODO: make this switch between detached pages too */ -int gtetrinet_key (int keyval) +static int gtetrinet_key (int keyval, int mod) { + if (mod != GDK_MOD1_MASK) + return (FALSE); + switch (keyval) { - case GDK_F1: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 0); break; - case GDK_F2: + case GDK_1: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 0); break; + case GDK_2: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 1); partyline_entryfocus(); break; - case GDK_F3: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 2); break; + case GDK_3: gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 2); break; default: return FALSE; } diff --git a/src/misc.c b/src/misc.c index eb5da18..d611096 100644 --- a/src/misc.c +++ b/src/misc.c @@ -44,7 +44,8 @@ void leftlabel_set (GtkWidget *align, char *str) gtk_label_set (GTK_LABEL(GTK_BIN(align)->child), str); } -/* returns a random number in the range 0 to n-1 */ +/* returns a random number in the range 0 to n-1 -- + * Note both n==0 and n==1 always return 0 */ int randomnum (int n) { return (float)n*rand()/(RAND_MAX+1.0); @@ -159,6 +160,7 @@ void textbox_addtext (GtkText *textbox, unsigned char *text) } else gtk_text_insert (textbox, fonts[attr], color, NULL, &text[i], 1); next: + continue; } /* scroll to bottom */ gtk_text_thaw (textbox); diff --git a/src/misc.h b/src/misc.h index 7a247a6..7dae59c 100644 --- a/src/misc.h +++ b/src/misc.h @@ -1,4 +1,5 @@ #include + extern GtkWidget *leftlabel_new (char *str); extern void leftlabel_set (GtkWidget *align, char *str); extern int randomnum (int n); @@ -8,3 +9,31 @@ extern void textbox_addtext (GtkText *textbox, unsigned char *text); extern void adjust_bottom (GtkAdjustment *adj); extern char *nocolor (char *str); extern GtkWidget *pixmap_label (GdkPixmap *pm, GdkBitmap *mask, char *str); + +/* textbox codes ... */ +#define TETRI_TB_BOLD 0x2 +#define TETRI_TB_UNDERLINE 0x16 + +/* colors... see colors[] in misc.c */ +#define TETRI_TB_C_CYAN 3 +#define TETRI_TB_C_BLACK 4 +#define TETRI_TB_C_BRIGHT_BLUE 5 +#define TETRI_TB_C_GREY 6 + +#define TETRI_TB_C_MAGENTA 8 + +/* #define TETRI_TB_C_GREY 11 -- dup */ +#define TETRI_TB_C_DARK_GREEN 12 + +#define TETRI_TB_C_BRIGHT_GREEN 14 +#define TETRI_TB_C_LIGHT_GREY 15 +#define TETRI_TB_C_DARK_RED 16 +#define TETRI_TB_C_DARK_BLUE 17 +#define TETRI_TB_C_BROWN 18 +#define TETRI_TB_C_PURPLE 19 +#define TETRI_TB_C_BRIGHT_RED 20 +/* #define TETRI_TB_C_LIGHT_GREY 21 -- dup */ + +#define TETRI_TB_C_DARK_CYAN 23 +#define TETRI_TB_C_WHITE 24 +#define TETRI_TB_C_YELLOW 25 diff --git a/src/tetrinet.c b/src/tetrinet.c index db5392b..b1ffa03 100644 --- a/src/tetrinet.c +++ b/src/tetrinet.c @@ -105,15 +105,15 @@ struct sb { #define S_BLOCKBOMB 11 struct sb sbinfo[] = { - {"cs1", -1, "1 Line Added to All"}, - {"cs2", -1, "2 Lines Added to All"}, - {"cs4", -1, "4 Lines Added to All"}, + {"cs1", -1, "1 Line Added"}, + {"cs2", -1, "2 Lines Added"}, + {"cs4", -1, "4 Lines Added"}, {"a", 6, "Add Line"}, {"c", 7, "Clear Line"}, {"n", 8, "Nuke Field"}, - {"r", 9, "Clear Random Blocks"}, + {"r", 9, "Clear Random"}, {"s", 10, "Switch Fields"}, - {"b", 11, "Clear Special Blocks"}, + {"b", 11, "Clear Specials"}, {"g", 12, "Block Gravity"}, {"q", 13, "Blockquake"}, {"o", 14, "Block Bomb"}, @@ -615,6 +615,7 @@ void tetrinet_inmessage (enum inmsg_type msgtype, char *data) } break; default: + break; } } @@ -752,12 +753,13 @@ static void tetrinet_addspecial (char sb) { int l, i; if (specialblocknum >= specialcapacity) return; /* too many ! */ - /* add to a random location */ - l = randomnum(specialblocknum); + + /* add to a random location between, 0 and last offset. + * Ie. If you have X sps already it gets added between 0 and X */ + l = randomnum(++specialblocknum); for (i = specialblocknum; i > l; i --) specialblocks[i] = specialblocks[i-1]; specialblocks[l] = sb; - specialblocknum ++; tetrinet_setspeciallabel (specialblocks[0]); } @@ -809,6 +811,7 @@ static void tetrinet_addsbtofield (int count) n --; } next: + /* fall through */ ; } } end: @@ -820,15 +823,120 @@ void tetrinet_dospecial (int from, int to, int type) { FIELD field; int x, y, i; - char buf[256], buf2[256]; + char buf[512], buf2[256]; + + switch (type) + { + case S_ADDALL1: + case S_ADDALL2: + case S_ADDALL4: /* bad for everyone ... */ + g_assert(!to); + if (from == playernum) + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BLACK, + sbinfo[type].info, + TETRI_TB_C_BLACK, + TETRI_TB_BOLD); + else + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BRIGHT_RED, + sbinfo[type].info, + TETRI_TB_C_BRIGHT_RED, + TETRI_TB_BOLD); + break; + + case S_ADDLINE: + case S_CLEARBLOCKS: + case S_CLEARSPECIAL: + case S_BLOCKQUAKE: + case S_BLOCKBOMB: /* badish stuff for someone */ + if (to == playernum) + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BRIGHT_RED, + sbinfo[type].info, + TETRI_TB_C_BRIGHT_RED, + TETRI_TB_BOLD); + else if (from == playernum) + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BLACK, + sbinfo[type].info, + TETRI_TB_C_BLACK, + TETRI_TB_BOLD); + else + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_DARK_RED, + sbinfo[type].info, + TETRI_TB_C_DARK_RED, + TETRI_TB_BOLD); + break; - sprintf (buf, "\02\023%s\023\02", sbinfo[type].info); + case S_CLEARLINE: + case S_NUKEFIELD: + case S_SWITCH: + case S_GRAVITY: /* goodish stuff for someone */ + if (to == playernum) + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BRIGHT_GREEN, + sbinfo[type].info, + TETRI_TB_C_BRIGHT_GREEN, + TETRI_TB_BOLD); + else + sprintf (buf, "%c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_DARK_GREEN, + sbinfo[type].info, + TETRI_TB_C_DARK_GREEN, + TETRI_TB_BOLD); + break; + + default: + g_assert_not_reached(); + } + if (to) { - sprintf (buf2, " on \02\021%s\021\02", playernames[to]); + if (to == playernum) + sprintf (buf2, " on %c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BRIGHT_BLUE, + playernames[to], + TETRI_TB_C_BRIGHT_BLUE, + TETRI_TB_BOLD); + else + sprintf (buf2, " on %c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_DARK_BLUE, + playernames[to], + TETRI_TB_C_DARK_BLUE, + TETRI_TB_BOLD); strcat (buf, buf2); } + else + { + sprintf (buf2, " to All"); + strcat (buf, buf2); + } + if (from) { - sprintf (buf2, " by \02\021%s\021\02", playernames[from]); + if (from == playernum) + sprintf (buf2, " by %c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_BRIGHT_BLUE, + playernames[from], + TETRI_TB_C_BRIGHT_BLUE, + TETRI_TB_BOLD); + else + sprintf (buf2, " by %c%c%s%c%c", + TETRI_TB_BOLD, + TETRI_TB_C_DARK_BLUE, + playernames[from], + TETRI_TB_C_DARK_BLUE, + TETRI_TB_BOLD); strcat (buf, buf2); } fields_attdefmsg (buf); @@ -1256,6 +1364,7 @@ int tetrinet_removelines () tetrinet_dospecial (playernum, 0, sbnum); } endremovelines: + /* end of if */ ; } /* give it a little delay in drawing */ gtk_timeout_add (40, (GtkFunction)tetrinet_removelinestimeout,