Crossfire Client, Branch
R11627
|
Covers drawing of the inventory and look windows. More...
#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"
Go to the source code of this file.
Data Structures | |
struct | Notebook_Info |
Defines | |
#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) |
Adds a row to the treestore. | |
void | animate_inventory (void) |
void | animate_look (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. | |
void | command_show (const char *params) |
void | draw_inv (int tab) |
Draws the inventory. | |
void | draw_inv_list (int tab) |
Draws the inventory window. | |
void | draw_inv_table (int animate) |
Draws the table of image icons. | |
void | draw_lists (void) |
Redraws inventory and look windows when necessary. | |
void | draw_look_list (void) |
Draws the objects beneath the player. | |
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) |
Returns information on the environment of the item, using the return values below. | |
static GtkStyle * | get_row_style (item *it) |
void | inventory_get_styles (void) |
Gets the style information for the inventory windows. | |
void | inventory_init (GtkWidget *window_root) |
Set up the inventory viewer. | |
void | inventory_tick (void) |
This is called periodically from main.c - basically a timeout, used to animate the inventory. | |
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) |
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. | |
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. | |
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) |
People are likely go to the different tabs much less often than their inventory changes. | |
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) |
No reason to divide by 1000 everytime we do the display, so do it once and store it here. | |
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 = "$Id: inventory.c 9201 2008-06-01 17:32:45Z anmaster $" |
GtkTreeStore * | store_look |
static const char * | Style_Names [Style_Last] |
GtkWidget * | treeview_look |
GtkWidget * | weight_label |
static double | weight_limit |
Covers drawing of the inventory and look windows.
Definition in file inventory.c.
#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 INV_SHOW_ITEM 0x1 |
Definition at line 86 of file inventory.c.
Referenced by draw_inv_list(), show_all(), show_applied(), show_cursed(), show_locked(), show_magical(), show_nonmagical(), show_unapplied(), show_unlocked(), and show_unpaid().
#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().
anonymous enum |
Definition at line 89 of file inventory.c.
anonymous enum |
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 |
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.
static void add_object_to_store | ( | item * | it, |
GtkTreeStore * | store, | ||
GtkTreeIter * | new, | ||
GtkTreeIter * | parent, | ||
int | color | ||
) | [static] |
Adds a row to the treestore.
it | the object to add |
store | The TreeStore object. |
new | Returns the iter used/updated for the store |
parent | The parent iter (can be null). If non null, then this creates a real tree, for things like containers. |
color | If 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().
void animate_inventory | ( | void | ) |
Definition at line 1097 of file inventory.c.
References item_struct::anim_speed, item_struct::anim_state, item_struct::animation_id, animations, draw_inv_table(), item_struct::face, Animations::faces, PixmapInfo::icon_image, inv_notebook, INV_TABLE, item_struct::last_anim, LIST_ICON, LIST_OBJECT, Animations::num_animations, pixmaps, tick, and Notebook_Info::treestore.
Referenced by inventory_tick().
void animate_look | ( | void | ) |
Definition at line 1165 of file inventory.c.
References item_struct::anim_speed, item_struct::anim_state, item_struct::animation_id, animations, item_struct::face, Animations::faces, PixmapInfo::icon_image, item_struct::last_anim, LIST_ICON, LIST_OBJECT, Animations::num_animations, pixmaps, store_look, and tick.
Referenced by inventory_tick().
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.
op |
Definition at line 559 of file inventory.c.
References draw_lists().
void command_show | ( | const char * | params | ) |
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.
void draw_inv | ( | int | tab | ) |
Draws the inventory.
Have to determine how to draw it.
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().
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.
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().
void draw_inv_table | ( | int | animate | ) |
Draws the table of image icons.
animate | If 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().
void draw_lists | ( | void | ) |
Redraws inventory and look windows when necessary.
Definition at line 1029 of file inventory.c.
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().
gboolean drawingarea_inventory_table_button_press_event | ( | GtkWidget * | widget, |
GdkEventButton * | event, | ||
gpointer | user_data | ||
) |
widget | |
event | |
user_data |
Definition at line 811 of file inventory.c.
References list_item_action(), and TRUE.
Referenced by draw_inv_table().
gboolean drawingarea_inventory_table_expose_event | ( | GtkWidget * | widget, |
GdkEventExpose * | event, | ||
gpointer | user_data | ||
) |
widget | |
event | |
user_data |
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().
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.
it |
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().
static GtkStyle* get_row_style | ( | item * | it | ) | [static] |
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().
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().
void inventory_init | ( | GtkWidget * | window_root | ) |
Set up the inventory viewer.
window_root | The 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().
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().
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] |
event | |
tmp |
Definition at line 168 of file inventory.c.
References client_send_apply(), client_send_examine(), client_send_move(), Player_Struct::container, Player_Struct::count, cpl, draw_info(), get_item_env(), ITEM_GROUND, ITEM_IN_CONTAINER, ITEM_INVENTORY, item_struct::locked, NDI_BLACK, Player_Struct::ob, send_mark_obj(), spinbutton_count, item_struct::tag, and toggle_locked().
Referenced by drawingarea_inventory_table_button_press_event(), and list_selection_func().
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.
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().
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.
selection | |
model | |
path | |
path_currently_selected | |
userdata |
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().
gboolean on_inv_table_expose_event | ( | GtkWidget * | widget, |
GdkEventExpose * | event, | ||
gpointer | user_data | ||
) |
widget | |
event | |
user_data |
Definition at line 1086 of file inventory.c.
References draw_inv_table(), and TRUE.
Referenced by inventory_init().
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
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().
void open_container | ( | item * | op | ) |
op |
Definition at line 568 of file inventory.c.
References draw_lists().
void set_show_icon | ( | const char * | s | ) |
s |
Definition at line 539 of file inventory.c.
void set_show_weight | ( | const char * | s | ) |
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.
wlim |
Definition at line 609 of file inventory.c.
References weight_limit.
static void setup_list_columns | ( | GtkWidget * | treeview | ) | [static] |
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().
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.
GtkWidget* inv_notebook |
Definition at line 53 of file inventory.c.
Referenced by animate_inventory(), command_show(), draw_lists(), and inventory_init().
{ {"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} }
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 = "$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] |
{ "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().