Crossfire Client, Trunk  R20507
Data Structures | Macros | Enumerations | Functions | Variables
inventory.c File Reference

Draw inventory and 'look' windows. More...

#include "client.h"
#include <gtk/gtk.h>
#include "image.h"
#include "main.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 "../../pixmaps/unidentified.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 MAX_INV_COLUMNS   20
 
#define MAX_INV_ROWS   100
 
#define NUM_INV_LISTS   11
 

Enumerations

enum  display_type { INV_TREE, INV_TABLE }
 Indicate how an inventory tab should be drawn. More...
 
enum  item_env { ITEM_INVENTORY = 0x1, ITEM_GROUND = 0x2, ITEM_IN_CONTAINER = 0x4 }
 Describe where an item is. More...
 
enum  list_property {
  LIST_NONE, LIST_ICON, LIST_NAME, LIST_WEIGHT,
  LIST_OBJECT, LIST_BACKGROUND, LIST_TYPE, LIST_BASENAME,
  LIST_FOREGROUND, LIST_FONT, LIST_NUM_COLUMNS
}
 Constants used to refer to columns in the inventory list view. More...
 
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)
 Adds a row to the treestore. More...
 
static void animate_inventory ()
 
static void animate_look ()
 
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. More...
 
void command_show (const char *params)
 
static void draw_inv (int tab)
 Draws the inventory and updates the encumbrance statistics display in the client. More...
 
static void draw_inv_list (int tab)
 Draws the inventory window. More...
 
static void draw_inv_table (int animate)
 Draws the table of image icons. More...
 
static void draw_inv_table_icon (GdkWindow *dst, const void *image)
 
void draw_lists ()
 Redraws inventory and look windows when necessary. More...
 
void draw_look_list ()
 Draws the objects beneath the player. More...
 
static gboolean drawingarea_inventory_table_button_press_event (GtkWidget *widget, GdkEventButton *event, gpointer user_data)
 
static gboolean drawingarea_inventory_table_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 
static int get_item_env (item *it)
 Returns information on the environment of the item, using the return values below. More...
 
static GtkStyle * get_row_style (item *it)
 
void inventory_get_styles ()
 Gets the style information for the inventory windows. More...
 
void inventory_init (GtkWidget *window_root)
 Set up the inventory viewer. More...
 
void inventory_tick ()
 This is called periodically from main.c - basically a timeout, used to animate the inventory. More...
 
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)
 
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. More...
 
static 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. More...
 
static gboolean on_inv_table_expose_event (GtkWidget *widget, GdkEventExpose *event, gpointer user_data)
 
static void on_switch_page (GtkNotebook *notebook, gpointer *page, guint page_num, gpointer user_data)
 People are likely go to the different tabs much less often than their inventory changes. More...
 
void open_container (item *op)
 
void set_weight_limit (guint32 wlim)
 No reason to divide by 1000 everytime we do the display, so do it once and store it here. More...
 
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_unidentified (item *it)
 
static int show_unlocked (item *it)
 
static int show_unpaid (item *it)
 

Variables

static const GdkColor applied_color = {0, 50000, 50000, 50000}
 Color to use to indicate that an item is applied. More...
 
static GtkWidget * encumbrance_current
 
static GtkWidget * encumbrance_max
 
static GtkWidget * inv_notebook
 
static Notebook_Info inv_notebooks [NUM_INV_LISTS]
 
static GtkStyle * inv_styles [Style_Last]
 
static GtkWidget * inv_table
 
static GtkWidget * inv_table_children [MAX_INV_ROWS][MAX_INV_COLUMNS]
 
static int num_inv_notebook_pages = 0
 
static GtkTreeStore * store_look
 
static const char * Style_Names [Style_Last]
 
GtkWidget * treeview_look
 
static double weight_limit
 

Detailed Description

Draw inventory and 'look' windows.

Definition in file inventory.c.

Macro Definition Documentation

#define INV_SHOW_COLOR   0x2

Definition at line 80 of file inventory.c.

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

#define INV_SHOW_ITEM   0x1
#define MAX_INV_COLUMNS   20

Definition at line 56 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

#define MAX_INV_ROWS   100

Definition at line 57 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

#define NUM_INV_LISTS   11

Definition at line 78 of file inventory.c.

Referenced by command_show(), and inventory_init().

Enumeration Type Documentation

Indicate how an inventory tab should be drawn.

Enumerator
INV_TREE 
INV_TABLE 

Definition at line 86 of file inventory.c.

enum item_env

Describe where an item is.

These constants must be kept as-is for use in a few bitwise operations.

Enumerator
ITEM_INVENTORY 
ITEM_GROUND 
ITEM_IN_CONTAINER 

Definition at line 180 of file inventory.c.

Constants used to refer to columns in the inventory list view.

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 170 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 61 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 696 of file inventory.c.

References item_struct::d_name, item_struct::face, item_struct::flags, 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:

static void animate_inventory ( )
static
static void animate_look ( )
static
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 573 of file inventory.c.

References draw_lists().

Referenced by item_actions().

Here is the call graph for this function:

Here is the caller graph for this function:

void command_show ( const char *  params)
Parameters
params

Definition at line 589 of file inventory.c.

References draw_ext_info(), inv_notebook, MAX_BUF, MSG_TYPE_CLIENT, MSG_TYPE_CLIENT_ERROR, name, NDI_RED, NUM_INV_LISTS, and num_inv_notebook_pages.

Here is the call graph for this function:

static void draw_inv ( int  tab)
static

Draws the inventory and updates the encumbrance statistics display in the client.

Have to determine how to draw it.

Parameters
tab

Definition at line 1057 of file inventory.c.

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

Referenced by draw_lists().

Here is the call graph for this function:

Here is the caller graph for this function:

static void draw_inv_list ( int  tab)
static

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 774 of file inventory.c.

References add_object_to_store(), Player_Struct::container, cpl, 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:

static void draw_inv_table ( int  animate)
static

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 878 of file inventory.c.

References item_struct::anim_speed, item_struct::anim_state, item_struct::animation_id, animations, item_struct::applied, applied_color, cpl, item_struct::d_name, draw_inv_table_icon(), 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, 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:

static void draw_inv_table_icon ( GdkWindow *  dst,
const void *  image 
)
static

Definition at line 839 of file inventory.c.

Referenced by draw_inv_table(), and drawingarea_inventory_table_expose_event().

Here is the caller graph for this function:

void draw_lists ( void  )

Redraws inventory and look windows when necessary.

Definition at line 1075 of file inventory.c.

References Player_Struct::below, Player_Struct::container, cpl, draw_inv(), draw_look_list(), item_struct::env, inv_notebook, item_struct::inv_updated, and Player_Struct::ob.

Referenced by close_container(), do_network(), load_theme(), open_container(), and redraw().

Here is the call graph for this function:

Here is the caller graph for this function:

void draw_look_list ( void  )

Draws the objects beneath the player.

Definition at line 739 of file inventory.c.

References add_object_to_store(), Player_Struct::below, Player_Struct::container, cpl, 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:

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

Definition at line 833 of file inventory.c.

References list_item_action().

Referenced by draw_inv_table().

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 855 of file inventory.c.

References draw_inv_table_icon(), item_struct::face, PixmapInfo::icon_image, and pixmaps.

Referenced by draw_inv_table().

Here is the call graph for this function:

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 194 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 630 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 425 of file inventory.c.

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

Referenced by 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 452 of file inventory.c.

References encumbrance_current, encumbrance_max, inv_notebook, inv_table, inv_table_children, INV_TREE, 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_switch_page(), setup_list_columns(), store_look, Notebook_Info::treestore, Notebook_Info::treeview, treeview_look, and window_xml.

Referenced by init_ui().

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 1265 of file inventory.c.

References animate_inventory(), and animate_look().

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 677 of file inventory.c.

Referenced by remove_item_inventory().

Here is the caller graph for this function:

void item_event_item_changed ( item it)

Definition at line 680 of file inventory.c.

Referenced by set_item_values().

Here is the caller graph for this function:

void item_event_item_deleting ( item it)

Definition at line 674 of file inventory.c.

Referenced by remove_item().

Here is the caller graph for this function:

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

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 321 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:

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

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 281 of file inventory.c.

References 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:

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

Definition at line 1126 of file inventory.c.

References draw_inv_table().

Referenced by inventory_init().

Here is the call graph for this function:

Here is the caller graph for this function:

static void on_switch_page ( GtkNotebook *  notebook,
gpointer *  page,
guint  page_num,
gpointer  user_data 
)
static

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 1108 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 581 of file inventory.c.

References draw_lists().

Referenced by item_actions().

Here is the call graph for this function:

Here is the caller graph for this function:

void set_weight_limit ( guint32  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 621 of file inventory.c.

References weight_limit.

Referenced by StatsCmd().

Here is the caller graph for this function:

static void setup_list_columns ( GtkWidget *  treeview)
static
Parameters
treeview

Definition at line 336 of file inventory.c.

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

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 112 of file inventory.c.

References INV_SHOW_COLOR, and INV_SHOW_ITEM.

static int show_applied ( item it)
static

Definition at line 116 of file inventory.c.

References item_struct::applied, and INV_SHOW_ITEM.

static int show_cursed ( item it)
static

Definition at line 128 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 140 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 132 of file inventory.c.

References INV_SHOW_ITEM, and item_struct::magical.

static int show_nonmagical ( item it)
static

Definition at line 136 of file inventory.c.

References INV_SHOW_ITEM, and item_struct::magical.

static int show_unapplied ( item it)
static

Definition at line 120 of file inventory.c.

References item_struct::applied, and INV_SHOW_ITEM.

static int show_unidentified ( item it)
static

Definition at line 148 of file inventory.c.

References F_UNIDENTIFIED, item_struct::flagsval, and INV_SHOW_ITEM.

static int show_unlocked ( item it)
static

Definition at line 144 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 124 of file inventory.c.

References INV_SHOW_ITEM, and item_struct::unpaid.

Variable Documentation

const GdkColor applied_color = {0, 50000, 50000, 50000}
static

Color to use to indicate that an item is applied.

Definition at line 41 of file inventory.c.

Referenced by draw_inv_table().

GtkWidget* encumbrance_current
static

Definition at line 44 of file inventory.c.

Referenced by draw_inv(), and inventory_init().

GtkWidget* encumbrance_max
static

Definition at line 45 of file inventory.c.

Referenced by draw_inv(), and inventory_init().

GtkWidget* inv_notebook
static

Definition at line 46 of file inventory.c.

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

Notebook_Info inv_notebooks[NUM_INV_LISTS]
static
Initial value:
= {
{"all", "All", all_xpm, show_all, INV_TREE},
{"applied", "Applied", hand_xpm, show_applied, INV_TREE},
{"unapplied", "Unapplied", hand2_xpm, show_unapplied, INV_TREE},
{"unpaid", "Unpaid", coin_xpm, show_unpaid, INV_TREE},
{"cursed", "Cursed", skull_xpm, show_cursed, INV_TREE},
{"magical", "Magical", mag_xpm, show_magical, INV_TREE},
{"nonmagical", "Non-magical", nonmag_xpm, show_nonmagical, INV_TREE},
{"locked", "Locked", lock_xpm, show_locked, INV_TREE},
{"unlocked", "Unlocked", unlock_xpm, show_unlocked, INV_TREE},
{"unidentified", "Unidentified", unidentified_xpm, show_unidentified, INV_TREE},
{"icons", "Icon View", NULL, show_all, INV_TABLE}
}
static int show_magical(item *it)
Definition: inventory.c:132
static int show_locked(item *it)
Definition: inventory.c:140
static int show_unpaid(item *it)
Definition: inventory.c:124
static int show_unidentified(item *it)
Definition: inventory.c:148
static int show_unapplied(item *it)
Definition: inventory.c:120
static int show_all(item *it)
Definition: inventory.c:112
static int show_applied(item *it)
Definition: inventory.c:116
static int show_unlocked(item *it)
Definition: inventory.c:144
static int show_nonmagical(item *it)
Definition: inventory.c:136
static int show_cursed(item *it)
Definition: inventory.c:128

Definition at line 152 of file inventory.c.

GtkStyle* inv_styles[Style_Last]
static

Definition at line 71 of file inventory.c.

Referenced by get_row_style(), and inventory_get_styles().

GtkWidget* inv_table
static

Definition at line 47 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

GtkWidget* inv_table_children[MAX_INV_ROWS][MAX_INV_COLUMNS]
static

Definition at line 58 of file inventory.c.

Referenced by draw_inv_table(), and inventory_init().

int num_inv_notebook_pages = 0
static

Definition at line 90 of file inventory.c.

Referenced by command_show(), and inventory_init().

GtkTreeStore* store_look
static

Definition at line 43 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 66 of file inventory.c.

Referenced by inventory_get_styles().

GtkWidget* treeview_look
double weight_limit
static

Definition at line 49 of file inventory.c.

Referenced by draw_inv(), and set_weight_limit().