2 "$Id: inventory.c 9201 2008-06-01 17:32:45Z anmaster $";
35 #include <glade/glade.h>
43 #include "../../pixmaps/all.xpm"
44 #include "../../pixmaps/coin.xpm"
45 #include "../../pixmaps/hand.xpm"
46 #include "../../pixmaps/hand2.xpm"
47 #include "../../pixmaps/lock.xpm"
48 #include "../../pixmaps/mag.xpm"
49 #include "../../pixmaps/nonmag.xpm"
50 #include "../../pixmaps/skull.xpm"
51 #include "../../pixmaps/unlock.xpm"
63 #define MAX_INV_COLUMNS 20
64 #define MAX_INV_ROWS 100
74 "inv_magical",
"inv_cursed",
"inv_unpaid",
"inv_locked",
"inv_applied"
85 #define NUM_INV_LISTS 10
86 #define INV_SHOW_ITEM 0x1
87 #define INV_SHOW_COLOR 0x2
99 const char *
const *
xpm;
141 #define ITEM_INVENTORY 0x1
142 #define ITEM_GROUND 0x2
143 #define ITEM_IN_CONTAINER 0x4
159 if (it->
env == NULL)
return 0;
178 if (event->button == 1) {
179 if (event->state & GDK_SHIFT_MASK)
184 else if (event->button == 2) {
185 if (event->state & GDK_SHIFT_MASK)
190 else if (event->button == 3) {
192 draw_info (
"This item is locked. To drop it, first unlock by shift+leftclicking on it.",
238 GtkTreeSelection *selection,
241 gboolean path_currently_selected,
245 GdkEventButton *
event;
248 event = (GdkEventButton*)gtk_get_current_event();
250 LOG(
LOG_ERROR,
"inventory.c:list_selection_func",
"Unable to get event structure\n");
254 if (gtk_tree_model_get_iter(model, &iter, path)) {
257 gtk_tree_model_get(model, &iter,
LIST_OBJECT, &tmp, -1);
260 LOG(
LOG_ERROR,
"inventory.c:list_selection_func",
"Unable to get item structure\n");
290 model = gtk_tree_view_get_model(treeview);
292 gtk_tree_model_get(GTK_TREE_MODEL(model), iter,
LIST_OBJECT, &tmp, -1);
302 GtkCellRenderer *renderer;
303 GtkTreeViewColumn *column;
304 GtkTreeSelection *selection;
314 renderer = gtk_cell_renderer_text_new ();
315 column = gtk_tree_view_column_new_with_attributes (
"", renderer,
318 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
319 gtk_tree_view_column_set_visible(column,
FALSE);
320 gtk_tree_view_set_expander_column(GTK_TREE_VIEW (treeview), column);
323 renderer = gtk_cell_renderer_pixbuf_new ();
331 g_object_set (G_OBJECT (renderer),
"xalign", 0.0,
333 column = gtk_tree_view_column_new_with_attributes (
"?", renderer,
338 gtk_tree_view_column_set_min_width(column,
image_size);
339 gtk_tree_view_column_set_sort_column_id(column,
LIST_TYPE);
340 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
342 renderer = gtk_cell_renderer_text_new ();
343 column = gtk_tree_view_column_new_with_attributes (
"Name", renderer,
346 gtk_tree_view_column_set_expand(column,
TRUE);
347 gtk_tree_view_column_set_sort_column_id(column,
LIST_BASENAME);
349 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
350 gtk_tree_view_column_add_attribute(column, renderer,
"background-gdk",
LIST_BACKGROUND);
351 gtk_tree_view_column_add_attribute(column, renderer,
"foreground-gdk",
LIST_FOREGROUND);
352 gtk_tree_view_column_add_attribute(column, renderer,
"font-desc",
LIST_FONT);
353 gtk_tree_view_set_expander_column(GTK_TREE_VIEW (treeview), column);
354 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
356 renderer = gtk_cell_renderer_text_new ();
357 column = gtk_tree_view_column_new_with_attributes (
"Weight", renderer,
368 gtk_tree_view_column_set_min_width(column, 64);
369 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_FIXED);
371 gtk_tree_view_column_set_sort_column_id(column,
LIST_WEIGHT);
372 gtk_tree_view_append_column (GTK_TREE_VIEW (treeview), column);
373 gtk_tree_view_column_add_attribute(column, renderer,
"background-gdk",
LIST_BACKGROUND);
374 gtk_tree_view_column_add_attribute(column, renderer,
"foreground-gdk",
LIST_FOREGROUND);
375 gtk_tree_view_column_add_attribute(column, renderer,
"font-desc",
LIST_FONT);
382 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(treeview));
402 tmp_style = gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL,
Style_Names[i],
408 LOG(
LOG_INFO,
"inventory.c::inventory_get_styles",
"Unable to find style for %s",
428 xml_tree = glade_get_widget_tree(GTK_WIDGET(window_root));
430 inv_notebook = glade_xml_get_widget(xml_tree,
"notebook_inv");
431 treeview_look = glade_xml_get_widget(xml_tree,
"treeview_look");
432 weight_label = glade_xml_get_widget(xml_tree,
"label_inv_weight");
433 inv_table = glade_xml_get_widget(xml_tree,
"inv_table");
435 g_signal_connect((gpointer)
inv_notebook,
"switch_page",
437 g_signal_connect((gpointer)
inv_table,
"expose_event",
457 PANGO_TYPE_FONT_DESCRIPTION);
459 gtk_tree_view_set_model(GTK_TREE_VIEW(treeview_look), GTK_TREE_MODEL(
store_look));
473 GtkWidget *swindow, *image;
475 if (inv_notebooks[i].type ==
INV_TREE) {
476 swindow = gtk_scrolled_window_new(NULL, NULL);
477 gtk_widget_show(swindow);
478 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(swindow),
479 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
480 image = gtk_image_new_from_pixbuf(
481 gdk_pixbuf_new_from_xpm_data((
const char**)inv_notebooks[i].xpm));
483 if (inv_notebooks[i].tooltip) {
486 eb=gtk_event_box_new();
489 gtk_container_add(GTK_CONTAINER(eb), image);
490 gtk_widget_show(image);
496 gtk_notebook_insert_page(GTK_NOTEBOOK(inv_notebook), swindow, image, i);
508 PANGO_TYPE_FONT_DESCRIPTION);
510 inv_notebooks[i].
treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(
511 inv_notebooks[i].treestore));
513 g_signal_connect ((gpointer) inv_notebooks[i].treeview,
"row_collapsed",
514 G_CALLBACK (list_row_collapse), NULL);
517 gtk_widget_show(inv_notebooks[i].treeview);
518 gtk_container_add(GTK_CONTAINER(swindow), inv_notebooks[i].treeview);
524 gtk_notebook_set_current_page(GTK_NOTEBOOK(inv_notebook), 0);
529 "num_inv_notebook_pages (%d) does not match NUM_INV_LISTS(%d)\n",
593 if (!strncmp(params, inv_notebooks[i].
name, strlen(params))) {
598 snprintf(buf,
sizeof(buf),
"Unknown notebook page %s\n", params);
675 GtkTreeIter *
new, GtkTreeIter *parent,
int color)
677 char buf[256], buf1[256];
679 PangoFontDescription *
font=NULL;
685 snprintf(buf,
sizeof(buf),
"%6.1f" ,it->
nrof * it->
weight);
687 snprintf(buf1, 255,
"%s %s", it->
d_name, it->
flags);
695 foreground = &row_style->text[GTK_STATE_NORMAL];
696 background = &row_style->base[GTK_STATE_NORMAL];
697 font = row_style->font_desc;
701 gtk_tree_store_append (store,
new, parent);
702 gtk_tree_store_set (store,
new,
738 for (tmp2 = tmp->
inv; tmp2; tmp2=tmp2->
next) {
741 path = gtk_tree_model_get_path(GTK_TREE_MODEL(
store_look), &iter);
743 gtk_tree_path_free (path);
766 gtk_tree_store_clear(inv_notebooks[tab].treestore);
769 rowflag = inv_notebooks[tab].
show_func(tmp);
779 for (tmp2 = tmp->
inv; tmp2; tmp2=tmp2->
next) {
792 if (!(rowflag & INV_SHOW_ITEM))
continue;
794 rowflag & INV_SHOW_COLOR);
796 path = gtk_tree_model_get_path(GTK_TREE_MODEL(inv_notebooks[tab].treestore), &iter);
797 gtk_tree_view_expand_row(GTK_TREE_VIEW(inv_notebooks[tab].treeview), path,
FALSE);
798 gtk_tree_path_free (path);
812 GdkEventButton *
event,
828 GdkEventExpose *
event,
833 tmp = (
item*)user_data;
835 gdk_window_clear(widget->window);
841 gdk_draw_pixbuf(widget->window, NULL,
847 #define INVHELPTEXT "Left click examines the object. Middle click applies \
848 the object. Right click drops the object. Shift left click locks/unlocks the \
849 object. Shift middle click marks the object"
859 int x, y, rows, columns, num_items, i;
860 static int max_drawn=0;
873 if (num_items > columns * rows) {
874 rows = num_items / columns;
875 if (num_items % columns) rows++;
879 gtk_table_resize(GTK_TABLE(
inv_table), rows, columns);
890 x, x+1, y, y+1, GTK_FILL, GTK_FILL, 0, 0);
919 G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
927 G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
958 snprintf(buf, 255,
"%s %s", tmp->
d_name, tmp->
flags);
975 for (i=num_items; i<=max_drawn; i++) {
980 G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
988 G_SIGNAL_MATCH_FUNC, 0, 0, NULL,
1003 max_drawn = num_items;
1020 if (inv_notebooks[tab].type ==
INV_TREE)
1022 else if (inv_notebooks[tab].type ==
INV_TABLE)
1066 GtkNotebookPage *page,
1072 oldpage = gtk_notebook_get_current_page(GTK_NOTEBOOK(notebook));
1073 if (oldpage != page_num && inv_notebooks[oldpage].type ==
INV_TREE)
1074 gtk_tree_store_clear(inv_notebooks[oldpage].treestore);
1087 GdkEventExpose *
event,
1103 GtkTreeStore *store;
1104 static int inv_tick=0;
1118 if (inv_tick < 12)
return;
1122 page = gtk_notebook_get_current_page(GTK_NOTEBOOK(
inv_notebook));
1125 if (inv_notebooks[page].type ==
INV_TABLE) {
1133 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(store), &iter);
1136 gtk_tree_model_get (GTK_TREE_MODEL(store), &iter,
1153 gtk_tree_store_set(store, &iter,
1158 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(store), &iter);
1170 static int inv_tick=0;
1184 if (inv_tick < 12)
return;
1189 valid = gtk_tree_model_get_iter_first (GTK_TREE_MODEL(
store_look), &iter);
1192 gtk_tree_model_get (GTK_TREE_MODEL(
store_look), &iter,
1214 valid = gtk_tree_model_iter_next (GTK_TREE_MODEL(
store_look), &iter);
Animations animations[MAXANIM]
static XFontStruct * font
void list_row_collapse(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data)
void item_event_item_changed(item *op)
static int show_unapplied(item *it)
void set_show_icon(const char *s)
static int num_inv_notebook_pages
static const char * Style_Names[Style_Last]
GtkWidget * treeview_look
void command_show(const char *params)
static int show_magical(item *it)
GtkWidget * spinbutton_count
gboolean list_selection_func(GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer userdata)
void draw_look_list(void)
snd_pcm_hw_params_t * params
void inventory_tick(void)
struct item_struct * next
static unsigned long background
static int show_applied(item *it)
GtkWidget * inv_table_children[MAX_INV_ROWS][MAX_INV_COLUMNS]
void draw_inv_table(int animate)
void item_event_item_deleting(item *op)
void animate_inventory(void)
static GtkStyle * get_row_style(item *it)
static GtkStyle * inv_styles[Style_Last]
int(* show_func)(item *it)
static int show_all(item *it)
void inventory_get_styles(void)
static void list_item_action(GdkEventButton *event, item *tmp)
PixmapInfo * pixmaps[MAXPIXMAPNUM]
Notebook_Info inv_notebooks[NUM_INV_LISTS]
gboolean on_inv_table_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
void LOG(LogLevel level, const char *origin, const char *format,...)
void client_send_apply(int tag)
void set_show_weight(const char *s)
GtkTreeStore * store_look
void set_weight_limit(uint32 wlim)
void close_container(item *op)
static int show_unpaid(item *it)
static unsigned long foreground
gboolean drawingarea_inventory_table_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data)
void item_event_container_clearing(item *op)
static int show_nonmagical(item *it)
void client_send_move(int loc, int tag, int nrof)
static GtkTooltips * inv_table_tooltips
static void add_object_to_store(item *it, GtkTreeStore *store, GtkTreeIter *new, GtkTreeIter *parent, int color)
static void setup_list_columns(GtkWidget *treeview)
void send_mark_obj(item *op)
void toggle_locked(item *op)
gboolean drawingarea_inventory_table_expose_event(GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
static int show_unlocked(item *it)
void draw_inv_list(int tab)
void inventory_init(GtkWidget *window_root)
void client_send_examine(int tag)
void draw_info(const char *str, int color)
static double weight_limit
#define ITEM_IN_CONTAINER
void on_notebook_switch_page(GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data)
static int show_cursed(item *it)
void open_container(item *op)
const char *const rcsid_gtk2_inventory_c
static int get_item_env(item *it)
static int show_locked(item *it)