Crossfire Client, Branches  R11627
inventory.c File Reference
#include <gtk/gtk.h>
#include <glade/glade.h>
#include "client.h"
#include "main.h"
#include "image.h"
#include "gtk2proto.h"
#include "../../pixmaps/all.xpm"
#include "../../pixmaps/coin.xpm"
#include "../../pixmaps/hand.xpm"
#include "../../pixmaps/hand2.xpm"
#include "../../pixmaps/lock.xpm"
#include "../../pixmaps/mag.xpm"
#include "../../pixmaps/nonmag.xpm"
#include "../../pixmaps/skull.xpm"
#include "../../pixmaps/unlock.xpm"
+ Include dependency graph for inventory.c:

Go to the source code of this file.

Data Structures

struct  Notebook_Info
 

Macros

#define INV_SHOW_COLOR   0x2
 
#define INV_SHOW_ITEM   0x1
 
#define INVHELPTEXT   "Left click examines the object. Middle click applies \the object. Right click drops the object. Shift left click locks/unlocks the \object. Shift middle click marks the object"
 
#define ITEM_GROUND   0x2
 
#define ITEM_IN_CONTAINER   0x4
 
#define ITEM_INVENTORY   0x1
 
#define MAX_INV_COLUMNS   20
 
#define MAX_INV_ROWS   100
 
#define NUM_INV_LISTS   10
 

Enumerations

enum  { INV_TREE, INV_TABLE }
 
enum  {
  LIST_NONE, LIST_ICON, LIST_NAME, LIST_WEIGHT,
  LIST_OBJECT, LIST_BACKGROUND, LIST_TYPE, LIST_BASENAME,
  LIST_FOREGROUND, LIST_FONT, LIST_NUM_COLUMNS
}
 
enum  Styles {
  Style_Magical =0, Style_Cursed, Style_Unpaid, Style_Locked,
  Style_Applied, Style_Last, Style_Attuned, Style_Repelled,
  Style_Denied, Style_Normal, Style_Last
}
 

Functions

static void add_object_to_store (item *it, GtkTreeStore *store, GtkTreeIter *new, GtkTreeIter *parent, int color)
 
void animate_inventory (void)
 
void animate_look (void)
 
void close_container (item *op)
 
void command_show (const char *params)
 
void draw_inv (int tab)
 
void draw_inv_list (int tab)
 
void draw_inv_table (int animate)
 
void draw_lists (void)
 
void draw_look_list (void)
 
gboolean drawingarea_inventory_table_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
 
gboolean drawingarea_inventory_table_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 
static int get_item_env (item *it)
 
static GtkStyle * get_row_style (item *it)
 
void inventory_get_styles (void)
 
void inventory_init (GtkWidget *window_root)
 
void inventory_tick (void)
 
void item_event_container_clearing (item *container)
 
void item_event_item_changed (item *it)
 
void item_event_item_deleting (item *it)
 
static void list_item_action (GdkEventButton *event, item *tmp)
 
void list_row_collapse (GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *path, gpointer user_data)
 
gboolean list_selection_func (GtkTreeSelection *selection, GtkTreeModel *model, GtkTreePath *path, gboolean path_currently_selected, gpointer userdata)
 
gboolean on_inv_table_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 
void on_notebook_switch_page (GtkNotebook *notebook, GtkNotebookPage *page, guint page_num, gpointer user_data)
 
void open_container (item *op)
 
void set_show_icon (const char *s)
 
void set_show_weight (const char *s)
 
void set_weight_limit (uint32 wlim)
 
static void setup_list_columns (GtkWidget *treeview)
 
static int show_all (item *it)
 
static int show_applied (item *it)
 
static int show_cursed (item *it)
 
static int show_locked (item *it)
 
static int show_magical (item *it)
 
static int show_nonmagical (item *it)
 
static int show_unapplied (item *it)
 
static int show_unlocked (item *it)
 
static int show_unpaid (item *it)
 

Variables

GtkWidget * inv_notebook
 
Notebook_Info inv_notebooks [NUM_INV_LISTS]
 
static GtkStyle * inv_styles [Style_Last]
 
GtkWidget * inv_table
 
GtkWidget * inv_table_children [MAX_INV_ROWS][MAX_INV_COLUMNS]
 
static GtkTooltips * inv_table_tooltips
 
static int num_inv_notebook_pages =0
 
const char *const rcsid_gtk2_inventory_c
 
GtkTreeStore * store_look
 
static const char * Style_Names [Style_Last]
 
GtkWidget * treeview_look
 
GtkWidget * weight_label
 
static double weight_limit
 

Detailed Description

Covers drawing of the inventory and look windows.

Definition in file inventory.c.

Macro Definition Documentation

#define INV_SHOW_COLOR   0x2

Definition at line 87 of file inventory.c.

Referenced by draw_inv_list(), show_all(), show_locked(), and show_unlocked().

#define INVHELPTEXT   "Left click examines the object. Middle click applies \the object. Right click drops the object. Shift left click locks/unlocks the \object. Shift middle click marks the object"

Definition at line 847 of file inventory.c.

Referenced by draw_inv_table().

#define ITEM_GROUND   0x2

Definition at line 142 of file inventory.c.

Referenced by get_item_env(), and list_item_action().

#define ITEM_IN_CONTAINER   0x4

Definition at line 143 of file inventory.c.

Referenced by get_item_env(), and list_item_action().

#define ITEM_INVENTORY   0x1

Definition at line 141 of file inventory.c.

Referenced by get_item_env(), and list_item_action().

#define MAX_INV_COLUMNS   20

Definition at line 63 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

#define MAX_INV_ROWS   100

Definition at line 64 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

#define NUM_INV_LISTS   10

Definition at line 85 of file inventory.c.

Referenced by command_show(), and inventory_init().

Enumeration Type Documentation

anonymous enum
Enumerator
INV_TREE 
INV_TABLE 

Definition at line 89 of file inventory.c.

anonymous enum
Enumerator
LIST_NONE 
LIST_ICON 
LIST_NAME 
LIST_WEIGHT 
LIST_OBJECT 
LIST_BACKGROUND 
LIST_TYPE 
LIST_BASENAME 
LIST_FOREGROUND 
LIST_FONT 
LIST_NUM_COLUMNS 

Definition at line 136 of file inventory.c.

enum Styles
Enumerator
Style_Magical 
Style_Cursed 
Style_Unpaid 
Style_Locked 
Style_Applied 
Style_Last 
Style_Attuned 
Style_Repelled 
Style_Denied 
Style_Normal 
Style_Last 

Definition at line 68 of file inventory.c.

Function Documentation

static void add_object_to_store ( item it,
GtkTreeStore *  store,
GtkTreeIter *  new,
GtkTreeIter *  parent,
int  color 
)
static

Adds a row to the treestore.

Parameters
itthe object to add
storeThe TreeStore object.
newReturns the iter used/updated for the store
parentThe parent iter (can be null). If non null, then this creates a real tree, for things like containers.
colorIf true, do foreground/background colors, otherwise, just black & white Normally it is set. However, when showing the cursed inv tab, it doesn't make a lot of sense to show them all in the special color, since they all meet that special criteria

Definition at line 674 of file inventory.c.

References background, item_struct::d_name, item_struct::face, item_struct::flags, font, foreground, get_row_style(), PixmapInfo::icon_image, LIST_BACKGROUND, LIST_BASENAME, LIST_FONT, LIST_FOREGROUND, LIST_ICON, LIST_NAME, LIST_OBJECT, LIST_TYPE, LIST_WEIGHT, item_struct::nrof, pixmaps, item_struct::s_name, item_struct::type, and item_struct::weight.

Referenced by draw_inv_list(), and draw_look_list().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void animate_inventory ( void  )
void close_container ( item op)

Open and close_container are now no-ops - since these are now drawn inline as treestores, we don't need to update what we are drawing were. and since the activation of a container will cause the list to be redrawn, don't need to worry about making an explicit call here.

Parameters
op

Definition at line 559 of file inventory.c.

References draw_lists().

+ Here is the call graph for this function:

void command_show ( const char *  params)
Parameters
params

Definition at line 577 of file inventory.c.

References draw_info(), inv_notebook, MAX_BUF, name, NDI_RED, NUM_INV_LISTS, and num_inv_notebook_pages.

+ Here is the call graph for this function:

void draw_inv ( int  tab)

Draws the inventory. Have to determine how to draw it.

Parameters
tab

Definition at line 1013 of file inventory.c.

References cpl, draw_inv_list(), draw_inv_table(), INV_TABLE, INV_TREE, Player_Struct::ob, item_struct::weight, weight_label, and weight_limit.

Referenced by draw_lists().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void draw_inv_list ( int  tab)

Draws the inventory window. tab is the notebook tab we are drawing. Has to be passed in because the callback sets this before the notebook is updated.

Parameters
tab

Definition at line 754 of file inventory.c.

References add_object_to_store(), Player_Struct::container, cpl, FALSE, item_struct::inv, INV_SHOW_COLOR, INV_SHOW_ITEM, item_struct::next, Player_Struct::ob, item_struct::open, and Notebook_Info::show_func.

Referenced by draw_inv().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void draw_inv_table ( int  animate)

Draws the table of image icons.

Parameters
animateIf non-zero, then this is an animation run - flip the animation state of the objects, and only draw those that need to be drawn.

Definition at line 857 of file inventory.c.

References item_struct::anim_speed, item_struct::anim_state, item_struct::animation_id, animations, cpl, item_struct::d_name, drawingarea_inventory_table_button_press_event(), drawingarea_inventory_table_expose_event(), item_struct::face, Animations::faces, item_struct::flags, PixmapInfo::icon_image, image_size, item_struct::inv, inv_table, inv_table_children, inv_table_tooltips, INVHELPTEXT, item_struct::last_anim, MAX_INV_COLUMNS, MAX_INV_ROWS, item_struct::next, Animations::num_animations, Player_Struct::ob, and pixmaps.

Referenced by animate_inventory(), draw_inv(), and on_inv_table_expose_event().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void draw_lists ( void  )

Redraws inventory and look windows when necessary

Definition at line 1029 of file inventory.c.

Referenced by close_container(), and open_container().

+ Here is the caller graph for this function:

void draw_look_list ( void  )

Draws the objects beneath the player.

Definition at line 718 of file inventory.c.

References add_object_to_store(), Player_Struct::below, Player_Struct::container, cpl, FALSE, item_struct::inv, item_struct::next, item_struct::open, store_look, and treeview_look.

Referenced by draw_lists(), and main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

gboolean drawingarea_inventory_table_button_press_event ( GtkWidget *  widget,
GdkEventButton *  event,
gpointer  user_data 
)
Parameters
widget
event
user_data
Returns
TRUE

Definition at line 811 of file inventory.c.

References list_item_action(), and TRUE.

Referenced by draw_inv_table().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

gboolean drawingarea_inventory_table_expose_event ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  user_data 
)
Parameters
widget
event
user_data
Returns
TRUE

Definition at line 827 of file inventory.c.

References item_struct::face, PixmapInfo::icon_image, image_size, pixmaps, and TRUE.

Referenced by draw_inv_table().

+ Here is the caller graph for this function:

static int get_item_env ( item it)
static

Returns information on the environment of the item, using the return values below. Note that there should never be a case where both ITEM_GROUND and ITEM_INVENTORY are returned, but I prefer a more active approach in returning actual values and not presuming that lack of value means it is in the other location.

Parameters
it
Returns

Definition at line 155 of file inventory.c.

References Player_Struct::below, cpl, item_struct::env, ITEM_GROUND, ITEM_IN_CONTAINER, ITEM_INVENTORY, and Player_Struct::ob.

Referenced by list_item_action().

+ Here is the caller graph for this function:

static GtkStyle* get_row_style ( item it)
static
Parameters
it
Returns
a style based on values in it

Definition at line 619 of file inventory.c.

References item_struct::applied, item_struct::cursed, item_struct::damned, inv_styles, item_struct::locked, item_struct::magical, Style_Applied, Style_Cursed, Style_Locked, Style_Magical, Style_Unpaid, and item_struct::unpaid.

Referenced by add_object_to_store().

+ Here is the caller graph for this function:

void inventory_get_styles ( void  )

Gets the style information for the inventory windows. This is a separate function because if the user changes styles, it can be nice to re-load the configuration. The style for the inventory/look is a bit special. That is because with gtk, styles are widget wide - all rows in the widget would use the same style. We want to adjust the styles based on other attributes.

Definition at line 394 of file inventory.c.

References has_init, inv_styles, LOG(), LOG_INFO, Style_Last, and Style_Names.

Referenced by inventory_init(), and load_theme().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void inventory_init ( GtkWidget *  window_root)

Set up the inventory viewer.

Parameters
window_rootThe client main window.

Definition at line 421 of file inventory.c.

References inv_notebook, inv_table, inv_table_children, inv_table_tooltips, INV_TREE, inventory_get_styles(), LIST_NUM_COLUMNS, list_row_collapse(), LOG(), LOG_ERROR, MAX_INV_COLUMNS, MAX_INV_ROWS, NUM_INV_LISTS, num_inv_notebook_pages, on_inv_table_expose_event(), on_notebook_switch_page(), setup_list_columns(), store_look, Notebook_Info::treestore, Notebook_Info::treeview, treeview_look, and weight_label.

Referenced by main().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void inventory_tick ( void  )

This is called periodically from main.c - basically a timeout, used to animate the inventory.

Definition at line 1222 of file inventory.c.

References animate_inventory(), animate_look(), itemview_tick(), and update_lists_labels().

Referenced by client_tick(), and do_timeout().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void item_event_container_clearing ( item container)

Definition at line 658 of file inventory.c.

void item_event_item_changed ( item it)

Definition at line 659 of file inventory.c.

void item_event_item_deleting ( item it)

Definition at line 657 of file inventory.c.

static void list_item_action ( GdkEventButton *  event,
item tmp 
)
static
void list_row_collapse ( GtkTreeView *  treeview,
GtkTreeIter *  iter,
GtkTreePath *  path,
gpointer  user_data 
)

If the player collapses the row with the little icon, we have to unapply the object for things to work 'sanely' (eg, items not go into the container

Parameters
treeview
iter
path
user_data

Definition at line 282 of file inventory.c.

References client_send_apply(), LIST_OBJECT, and item_struct::tag.

Referenced by inventory_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

gboolean list_selection_func ( GtkTreeSelection *  selection,
GtkTreeModel *  model,
GtkTreePath *  path,
gboolean  path_currently_selected,
gpointer  userdata 
)

Used when a button is pressed on the inventory or look list. The parameters are those determined by the callback. Note that this function isn't 100% ideal - some of the events/handling is only relevant for objects in the inventory and not the look window (eg, locking items). OTOH, maybe it is just as well that the behaviour is always consistent.

Parameters
selection
model
path
path_currently_selected
userdata
Returns
FALSE

Definition at line 237 of file inventory.c.

References event, FALSE, list_item_action(), LIST_OBJECT, LOG(), and LOG_ERROR.

Referenced by setup_list_columns().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

gboolean on_inv_table_expose_event ( GtkWidget *  widget,
GdkEventExpose *  event,
gpointer  user_data 
)
Parameters
widget
event
user_data
Returns
TRUE

Definition at line 1086 of file inventory.c.

References draw_inv_table(), and TRUE.

Referenced by inventory_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void on_notebook_switch_page ( GtkNotebook *  notebook,
GtkNotebookPage *  page,
guint  page_num,
gpointer  user_data 
)

People are likely go to the different tabs much less often than their inventory changes. So rather than update all the tabs whenever the players inventory changes, only update the tab the player is viewing, and if they change tabs, draw the new tab and get rid of the old info. Ideally, I'd like to call draw_inv() from this function, but there is some oddity

Parameters
notebook
page
page_num
user_data

Definition at line 1065 of file inventory.c.

References cpl, INV_TREE, item_struct::inv_updated, and Player_Struct::ob.

Referenced by inventory_init().

+ Here is the caller graph for this function:

void open_container ( item op)
Parameters
op

Definition at line 568 of file inventory.c.

References draw_lists().

+ Here is the call graph for this function:

void set_show_icon ( const char *  s)
Parameters
s

Definition at line 539 of file inventory.c.

void set_show_weight ( const char *  s)
Parameters
s

Definition at line 547 of file inventory.c.

void set_weight_limit ( uint32  wlim)

No reason to divide by 1000 everytime we do the display, so do it once and store it here.

Parameters
wlim

Definition at line 609 of file inventory.c.

References weight_limit.

static void setup_list_columns ( GtkWidget *  treeview)
static
Parameters
treeview

Definition at line 300 of file inventory.c.

References FALSE, image_size, LIST_BACKGROUND, LIST_BASENAME, LIST_FONT, LIST_FOREGROUND, LIST_ICON, LIST_NAME, LIST_NONE, list_selection_func(), LIST_TYPE, LIST_WEIGHT, and TRUE.

Referenced by inventory_init().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static int show_all ( item it)
static

Definition at line 113 of file inventory.c.

References INV_SHOW_COLOR, and INV_SHOW_ITEM.

static int show_applied ( item it)
static

Definition at line 114 of file inventory.c.

References item_struct::applied, and INV_SHOW_ITEM.

static int show_cursed ( item it)
static

Definition at line 117 of file inventory.c.

References item_struct::cursed, item_struct::damned, and INV_SHOW_ITEM.

static int show_locked ( item it)
static

Definition at line 120 of file inventory.c.

References INV_SHOW_COLOR, INV_SHOW_ITEM, and item_struct::locked.

static int show_magical ( item it)
static

Definition at line 118 of file inventory.c.

References INV_SHOW_ITEM, and item_struct::magical.

static int show_nonmagical ( item it)
static

Definition at line 119 of file inventory.c.

References INV_SHOW_ITEM, and item_struct::magical.

static int show_unapplied ( item it)
static

Definition at line 115 of file inventory.c.

References item_struct::applied, and INV_SHOW_ITEM.

static int show_unlocked ( item it)
static

Definition at line 121 of file inventory.c.

References INV_SHOW_COLOR, INV_SHOW_ITEM, and item_struct::locked.

static int show_unpaid ( item it)
static

Definition at line 116 of file inventory.c.

References INV_SHOW_ITEM, and item_struct::unpaid.

Variable Documentation

GtkWidget* inv_notebook

Definition at line 53 of file inventory.c.

Referenced by animate_inventory(), command_show(), draw_lists(), and inventory_init().

Notebook_Info inv_notebooks[NUM_INV_LISTS]
Initial value:
= {
{"all", "All Items", all_xpm, show_all, INV_TREE},
{"applied", "Applied Items", hand_xpm, show_applied, INV_TREE},
{"unapplied", "Unapplied Items", hand2_xpm, show_unapplied, INV_TREE},
{"unpaid", "Unpaid items", coin_xpm, show_unpaid, INV_TREE},
{"cursed", "Cursed items", skull_xpm, show_cursed, INV_TREE},
{"magical", "Magical items", mag_xpm, show_magical, INV_TREE},
{"nonmagical", "Nonmagical items", nonmag_xpm, show_nonmagical, INV_TREE},
{"locked", "Inventory locked items", lock_xpm, show_locked, INV_TREE},
{"unlocked", "Inventory unlocked items",unlock_xpm, show_unlocked, INV_TREE},
{"icons", "Quick icon view", NULL, show_all, INV_TABLE}
}
static int show_unapplied(item *it)
Definition: inventory.c:115
static int show_magical(item *it)
Definition: inventory.c:118
static int show_applied(item *it)
Definition: inventory.c:114
static int show_all(item *it)
Definition: inventory.c:113
static int show_unpaid(item *it)
Definition: inventory.c:116
static int show_nonmagical(item *it)
Definition: inventory.c:119
static int show_unlocked(item *it)
Definition: inventory.c:121
static int show_cursed(item *it)
Definition: inventory.c:117
static int show_locked(item *it)
Definition: inventory.c:120

Definition at line 123 of file inventory.c.

GtkStyle* inv_styles[Style_Last]
static

Definition at line 78 of file inventory.c.

Referenced by get_row_style(), and inventory_get_styles().

GtkWidget * inv_table

Definition at line 53 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

GtkWidget* inv_table_children[MAX_INV_ROWS][MAX_INV_COLUMNS]

Definition at line 65 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

GtkTooltips* inv_table_tooltips
static

Definition at line 56 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

int num_inv_notebook_pages =0
static

Definition at line 94 of file inventory.c.

Referenced by command_show(), and inventory_init().

const char* const rcsid_gtk2_inventory_c
Initial value:
=
"$Id: inventory.c 9201 2008-06-01 17:32:45Z anmaster $"

Definition at line 1 of file inventory.c.

GtkTreeStore* store_look

Definition at line 54 of file inventory.c.

Referenced by animate_look(), draw_look_list(), and inventory_init().

const char* Style_Names[Style_Last]
static
Initial value:
= {
"inv_magical", "inv_cursed", "inv_unpaid", "inv_locked", "inv_applied"
}

Definition at line 73 of file inventory.c.

Referenced by inventory_get_styles().

GtkWidget * treeview_look

Definition at line 53 of file inventory.c.

Referenced by draw_look_list(), inventory_init(), and on_entry_commands_activate().

GtkWidget * weight_label

Definition at line 53 of file inventory.c.

Referenced by draw_inv(), and inventory_init().

double weight_limit
static

Definition at line 55 of file inventory.c.

Referenced by draw_inv(), and set_weight_limit().