diff -Naurd ../nethack-3.4.0/win/gnome/gnbind.c ./win/gnome/gnbind.c --- ../nethack-3.4.0/win/gnome/gnbind.c Wed Mar 20 23:44:08 2002 +++ ./win/gnome/gnbind.c Mon Feb 24 15:25:05 2003 @@ -13,6 +13,7 @@ #include "gnyesno.h" GNHWinData gnome_windowlist[MAXWINDOWS]; +winid WIN_WORN = WIN_ERR; extern void tty_raw_print(const char *); extern void tty_raw_print_bold(const char *); @@ -105,6 +106,9 @@ //wizard = TRUE; iflags.window_inited = TRUE; + + /* gnome-specific window creation */ + WIN_WORN = gnome_create_nhwindow(NHW_WORN); } @@ -434,6 +438,13 @@ ghack_main_window_add_status_window( gnome_windowlist[i].win); break; } + case NHW_WORN: + { + gnome_windowlist[i].win = ghack_init_worn_window( ); + gnome_windowlist[i].type = NHW_WORN; + ghack_main_window_add_worn_window(gnome_windowlist[i].win); + break; + } case NHW_MENU: { gnome_windowlist[i].type = NHW_MENU; @@ -502,9 +513,9 @@ */ void gnome_destroy_nhwindow(winid wid) { - if ((wid == NHW_MAP) || - (wid == NHW_MESSAGE) || - (wid == NHW_STATUS)) { + if ((wid == WIN_MAP) || + (wid == WIN_MESSAGE) || + (wid == WIN_STATUS)) { /* no thanks, I'll do these myself */ return; } diff -Naurd ../nethack-3.4.0/win/gnome/gnbind.h ./win/gnome/gnbind.h --- ../nethack-3.4.0/win/gnome/gnbind.h Wed Mar 20 23:44:08 2002 +++ ./win/gnome/gnbind.h Mon Feb 24 15:25:05 2003 @@ -24,6 +24,7 @@ #include "gnmesg.h" #include "gnyesno.h" #include "gnglyph.h" +#include "gnworn.h" /* Create an array to keep track of the various windows */ diff -Naurd ../nethack-3.4.0/win/gnome/gnglyph.c ./win/gnome/gnglyph.c --- ../nethack-3.4.0/win/gnome/gnglyph.c Wed Mar 20 23:44:09 2002 +++ ./win/gnome/gnglyph.c Mon Feb 24 15:25:05 2003 @@ -5,6 +5,9 @@ #include "gnglyph.h" #include "tile2x11.h" +/* from tile.c */ +extern int total_tiles_used; + static GHackGlyphs ghack_glyphs; static GdkImlibImage** ghack_tiles = NULL; @@ -45,38 +48,36 @@ */ int -ghack_init_glyphs( const char *xpmFile) +ghack_init_glyphs(const char *xpmFile) { - ghack_glyphs.im = gdk_imlib_load_image((char *) xpmFile); - if ( ! ghack_glyphs.im ) - { - g_error("Couldn't load required xpmFile!"); - return -1; + ghack_glyphs.im = gdk_imlib_load_image((char *) xpmFile); + if ( ! ghack_glyphs.im ) { + g_error("Couldn't load required xpmFile!"); + return -1; } - gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width, - ghack_glyphs.im->rgb_height); + gdk_imlib_render(ghack_glyphs.im, ghack_glyphs.im->rgb_width, + ghack_glyphs.im->rgb_height); - if (ghack_glyphs.im->rgb_width % TILES_PER_ROW) { - g_error("%s is not a multiple of %d (number of tiles/row) pixels wide", - xpmFile, TILES_PER_ROW); - return -1; - } - ghack_glyphs.width = ghack_glyphs.im->rgb_width / TILES_PER_ROW; - ghack_glyphs.height = ghack_glyphs.width; - ghack_glyphs.count = - (ghack_glyphs.im->rgb_height * ghack_glyphs.im->rgb_width) / - (ghack_glyphs.width * ghack_glyphs.height); + if ((ghack_glyphs.im->rgb_width % TILES_PER_ROW) != 0 || + ghack_glyphs.im->rgb_width <= TILES_PER_ROW) { + g_error("%s is not a multiple of %d (number of tiles/row) pixels wide", + xpmFile, TILES_PER_ROW); + return -1; + } + ghack_glyphs.count = total_tiles_used; + if ((ghack_glyphs.count % TILES_PER_ROW) != 0) { + ghack_glyphs.count += + TILES_PER_ROW - (ghack_glyphs.count % TILES_PER_ROW); + } + ghack_glyphs.width = ghack_glyphs.im->rgb_width / TILES_PER_ROW; + ghack_glyphs.height = + ghack_glyphs.im->rgb_height / (ghack_glyphs.count / TILES_PER_ROW); - /* Assume the tiles are organized in rows of TILES_PER_ROW - * Further, assume that the tiles are SQUARE - */ - ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count ); - if (ghack_tiles == NULL) - return -1; - else - return 0; + /* Assume the tiles are organized in rows of TILES_PER_ROW */ + ghack_tiles = g_new0( GdkImlibImage*, ghack_glyphs.count ); + return (ghack_tiles == NULL) ? -1 : 0; } void @@ -210,8 +211,8 @@ src_y = (tile / TILES_PER_ROW) * ghack_glyphs.height; ghack_tiles[tile] = gdk_imlib_crop_and_clone_image(ghack_glyphs.im, src_x, src_y, - ghack_glyphs.height, - ghack_glyphs.width); + ghack_glyphs.width, + ghack_glyphs.height); } if (ghack_tiles[tile] && (!ghack_tiles[tile]->pixmap || force)) diff -Naurd ../nethack-3.4.0/win/gnome/gnmain.c ./win/gnome/gnmain.c --- ../nethack-3.4.0/win/gnome/gnmain.c Wed Mar 20 23:44:09 2002 +++ ./win/gnome/gnmain.c Mon Feb 24 15:25:05 2003 @@ -750,7 +750,7 @@ /* Put some stuff into our main window */ vBoxMain = gtk_vbox_new (FALSE, 0); - hBoxFirstRow = gtk_hbox_new (TRUE, 0); + hBoxFirstRow = gtk_hbox_new (FALSE, 0); /* pack Boxes into other boxes to produce the right structure */ gtk_box_pack_start (GTK_BOX (vBoxMain), hBoxFirstRow, FALSE, TRUE, 0); @@ -793,7 +793,14 @@ void ghack_main_window_add_status_window(GtkWidget* win) { - gtk_box_pack_start (GTK_BOX (hBoxFirstRow), win, TRUE, TRUE, 2); + gtk_box_pack_start (GTK_BOX (hBoxFirstRow), win, FALSE, TRUE, 2); + gtk_widget_show_all(win); +} + +void +ghack_main_window_add_worn_window(GtkWidget* win) +{ + gtk_box_pack_end (GTK_BOX (hBoxFirstRow), win, FALSE, TRUE, 2); gtk_widget_show_all(win); } @@ -812,10 +819,11 @@ void ghack_main_window_update_inventory() { -/* For now, do nothing. Eventually we may allow the inv. window +/* For now, do very little. Eventually we may allow the inv. window to stay active. When we do this, we'll need to implement this... g_warning("Fixme!!! updateInventory is not yet implemented"); */ + gnome_display_nhwindow(WIN_WORN, FALSE); } GtkWidget* diff -Naurd ../nethack-3.4.0/win/gnome/gnmain.h ./win/gnome/gnmain.h --- ../nethack-3.4.0/win/gnome/gnmain.h Wed Mar 20 23:44:09 2002 +++ ./win/gnome/gnmain.h Mon Feb 24 15:25:05 2003 @@ -14,6 +14,7 @@ void ghack_main_window_add_message_window(GtkWidget* win); void ghack_main_window_add_status_window(GtkWidget* win); void ghack_main_window_add_text_window(GtkWidget *); +void ghack_main_window_add_worn_window(GtkWidget* win); void ghack_main_window_remove_window(GtkWidget *); void ghack_main_window_update_inventory(); void ghack_save_game_cb(GtkWidget *widget, gpointer data); diff -Naurd ../nethack-3.4.0/win/gnome/gnmap.c ./win/gnome/gnmap.c --- ../nethack-3.4.0/win/gnome/gnmap.c Wed Mar 20 23:44:09 2002 +++ ./win/gnome/gnmap.c Mon Feb 24 15:25:05 2003 @@ -221,8 +221,8 @@ gnome_canvas_image_get_type (), "x", (double) x, "y", (double) y, - "width", (double) ghack_glyph_height(), - "height", (double) ghack_glyph_width(), + "width", (double) ghack_glyph_width(), + "height", (double) ghack_glyph_height(), "anchor", GTK_ANCHOR_NORTH_WEST, NULL) ); } @@ -234,8 +234,7 @@ g_warning("Bummer! Failed to load the pet_mark image!"); } else { - gdk_imlib_render(petmark, petmark->rgb_width, - petmark->rgb_height); + gdk_imlib_render(petmark, petmark->rgb_width, petmark->rgb_height); /* ghack_map.overlay is an array of canvas images used to * overlay tile images... @@ -342,22 +341,30 @@ static GnomeCanvasRE *cursor = NULL; double x1, y1, x2, y2; + float hp; + guint r, g, b; x1 = x * ghack_glyph_width() - 1; y1 = y * ghack_glyph_height() - 1; x2 = x1 + ghack_glyph_width() + 2; y2 = y1 + ghack_glyph_height() + 2; + hp = u.mtimedone + ? (u.mhmax ? (float)u.mh/u.mhmax : 1) + : (u.uhpmax ? (float)u.uhp/u.uhpmax : 1); + r = 255; + g = (hp >= 0.75) ? 255 : (hp >= 0.25 ? 255*2*(hp-0.25) : 0); + b = (hp >= 0.75) ? 255*4*(hp-0.75) : (hp >= 0.25 ? 0 : 255*4*(0.25-hp)); group = gnome_canvas_root(GNOME_CANVAS(ghack_map.canvas)); if (!cursor) { cursor = GNOME_CANVAS_RE (gnome_canvas_item_new (group, gnome_canvas_rect_get_type (), - "outline_color", "antiquewhite2", "width_units", 1.0, NULL)); } gnome_canvas_item_set (GNOME_CANVAS_ITEM (cursor), + "outline_color_rgba", GNOME_CANVAS_COLOR(r, g, b), "x1", x1, "y1", y1, "x2", x2, @@ -573,8 +580,8 @@ gnome_canvas_image_get_type (), "x", (double) x, "y", (double) y, - "width", (double) ghack_glyph_height(), - "height", (double) ghack_glyph_width(), + "width", (double) ghack_glyph_width(), + "height", (double) ghack_glyph_height(), "anchor", GTK_ANCHOR_NORTH_WEST, NULL) ); } diff -Naurd ../nethack-3.4.0/win/gnome/gnomeprv.h ./win/gnome/gnomeprv.h --- ../nethack-3.4.0/win/gnome/gnomeprv.h Wed Mar 20 23:44:11 2002 +++ ./win/gnome/gnomeprv.h Mon Feb 24 15:25:05 2003 @@ -10,6 +10,8 @@ #include "dlb.h" #include "patchlevel.h" +#include "winGnome.h" + #endif /* GnomeHack_h */ diff -Naurd ../nethack-3.4.0/win/gnome/gnworn.c ./win/gnome/gnworn.c --- ../nethack-3.4.0/win/gnome/gnworn.c Thu Jan 1 01:00:00 1970 +++ ./win/gnome/gnworn.c Mon Feb 24 15:25:05 2003 @@ -0,0 +1,105 @@ +/* SCCS Id: @(#)gnbind.c 3.4 2002/04/15 */ +/* Copyright (C) 2002, Dylan Alex Simon */ +/* NetHack may be freely redistributed. See license for details. */ + +#include "gnworn.h" +#include "gnglyph.h" +#include "gnsignal.h" +#include "gnomeprv.h" + +#define WORN_WIDTH 3 +#define WORN_HEIGHT 6 + +#ifdef TOURIST +#define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ { \ + { uquiver, uarmh, u.twoweap ? NULL : uswapwep }, \ + { u.twoweap ? uswapwep : NULL, ublindf, uwep }, \ + { uleft, uamul, uright }, \ + { uarms, uarmc, uarmg }, \ + { uarmu, uarm, uskin }, \ + { uball, uarmf, uchain } \ +} +#else +#define WORN_OBJECT_LIST /* struct obj *[WORN_HEIGHT][WORN_WIDTH] = */ { \ + { uquiver, uarmh, u.twoweap ? NULL : uswapwep }, \ + { u.twoweap ? uswapwep : NULL, ublindf, uwep }, \ + { uleft, uamul, uright }, \ + { uarms, uarmc, uarmg }, \ + { NULL, uarm, uskin }, \ + { uball, uarmf, uchain } \ +} +#endif + +static GtkWidget *worn_contents[WORN_HEIGHT][WORN_WIDTH]; +static struct obj *last_worn_objects[WORN_HEIGHT][WORN_WIDTH]; + +GdkImlibImage *image_of_worn_object(struct obj *o); +void ghack_worn_display(GtkWidget *win, boolean block, gpointer data); + +GtkWidget* +ghack_init_worn_window() +{ + GtkWidget *top; + GtkWidget *table; + GtkWidget *tablealign; + GtkWidget *label; + int i,j; + + top = gtk_vbox_new(FALSE, 2); + + table = gtk_table_new(WORN_HEIGHT, WORN_WIDTH, TRUE); + for (i = 0; i < WORN_HEIGHT; i++) { + for (j = 0; j < WORN_WIDTH; j++) { + worn_contents[i][j] = + gnome_pixmap_new_from_imlib(image_of_worn_object(NULL)); + last_worn_objects[i][j] = NULL; /* a pointer that will never be */ + gtk_table_attach(GTK_TABLE(table), GTK_WIDGET(worn_contents[i][j]), + j, j+1, i, i+1, 0, 0, 0, 0); + } + } + tablealign = gtk_alignment_new(0.5, 0.0, 0.0, 1.0); + gtk_box_pack_start(GTK_BOX(top), tablealign, FALSE, FALSE, 0); + gtk_container_add(GTK_CONTAINER(tablealign), table); + + label = gtk_label_new("Equipment"); + gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER); + gtk_box_pack_start(GTK_BOX(top), label, FALSE, FALSE, 0); + + gtk_signal_connect(GTK_OBJECT(top), "ghack_display", + GTK_SIGNAL_FUNC(ghack_worn_display), NULL); + + return top; +} + +GdkImlibImage* +image_of_worn_object(struct obj *o) +{ + int glyph; + GdkImlibImage *im; + + if (o) + glyph = obj_to_glyph(o); + else + glyph = cmap_to_glyph(S_stone); + + im = ghack_image_from_glyph(glyph, FALSE); + + return im; +} + +void +ghack_worn_display(GtkWidget *win, boolean block, gpointer data) +{ + int i, j; + struct obj *worn_objects[WORN_HEIGHT][WORN_WIDTH] = WORN_OBJECT_LIST; + + for (i = 0; i < WORN_HEIGHT; i++) { + for (j = 0; j < WORN_WIDTH; j++) { + if (worn_objects[i][j] != last_worn_objects[i][j]) { + last_worn_objects[i][j] = worn_objects[i][j]; + gnome_pixmap_load_imlib(GNOME_PIXMAP(worn_contents[i][j]), + image_of_worn_object(worn_objects[i][j])); + } + } + } +} diff -Naurd ../nethack-3.4.0/win/gnome/gnworn.h ./win/gnome/gnworn.h --- ../nethack-3.4.0/win/gnome/gnworn.h Thu Jan 1 01:00:00 1970 +++ ./win/gnome/gnworn.h Mon Feb 24 15:25:05 2003 @@ -0,0 +1,14 @@ +/* SCCS Id: @(#)gnbind.c 3.4 2002/04/15 */ +/* Copyright (C) 2002 by Dylan Alex Simon */ +/* NetHack may be freely redistributed. See license for details. */ + +#ifndef GnomeHackWornWindow_h +#define GnomeHackWornWindow_h + +#include +#include "config.h" +#include "global.h" + +GtkWidget* ghack_init_worn_window(); + +#endif /* GnomeHackWornWindow_h */ diff -Naurd ../nethack-3.4.0/include/winGnome.h ./include/winGnome.h --- ../nethack-3.4.0/include/winGnome.h Wed Mar 20 23:42:57 2002 +++ ./include/winGnome.h Mon Feb 24 15:25:05 2003 @@ -12,4 +12,7 @@ #undef E +#define NHW_WORN 6 +extern winid WIN_WORN; + #endif /* WINGNOME_H */