2 "$Id: stats.c 9201 2008-06-01 17:32:45Z anmaster $";
36 #include <glade/glade.h>
44 #define STAT_BAR_GRACE 2
45 #define STAT_BAR_FOOD 3
46 #define STAT_BAR_EXP 4
47 #define MAX_STAT_BARS 5
49 "hp",
"sp",
"grace",
"food",
"exp"
54 #define STYLE_NORMAL 0
57 #define STYLE_GRAD_NORMAL 3
58 #define STYLE_GRAD_LOW 4
59 #define STYLE_GRAD_SUPER 5
67 "bar_normal",
"bar_low",
"bar_super",
68 "gradual_bar_normal",
"gradual_bar_low",
"gradual_bar_super"
83 #define SKILL_BOXES_X 6
84 #define SKILL_BOXES_Y 17
86 #define PROTECTION_BOXES_X 6
87 #define PROTECTION_BOXES_Y 6
90 GtkWidget *playername;
151 for (sub_style=0; sub_style <
NUM_STYLES; sub_style++) {
154 tmp_style = gtk_rc_get_style_by_paths(gtk_settings_get_default(), NULL, buf, G_TYPE_NONE);
161 LOG(
LOG_INFO,
"stats.c::stats_get_styles()",
"Unable to find style '%s'", buf);
166 &tmp_style->base[GTK_STATE_SELECTED],
sizeof(GdkColor));
182 xml_tree = glade_get_widget_tree(GTK_WIDGET(window_root));
185 stat_label[i] = glade_xml_get_widget(xml_tree, buf);
188 stat_bar[i] = glade_xml_get_widget(xml_tree, buf);
195 glade_xml_get_widget(xml_tree,
"label_playername");
197 glade_xml_get_widget(xml_tree,
"label_str");
199 glade_xml_get_widget(xml_tree,
"label_dex");
201 glade_xml_get_widget(xml_tree,
"label_con");
203 glade_xml_get_widget(xml_tree,
"label_int");
205 glade_xml_get_widget(xml_tree,
"label_wis");
207 glade_xml_get_widget(xml_tree,
"label_pow");
209 glade_xml_get_widget(xml_tree,
"label_cha");
211 glade_xml_get_widget(xml_tree,
"label_wc");
213 glade_xml_get_widget(xml_tree,
"label_dam");
215 glade_xml_get_widget(xml_tree,
"label_ac");
217 glade_xml_get_widget(xml_tree,
"label_armor");
219 glade_xml_get_widget(xml_tree,
"label_speed");
221 glade_xml_get_widget(xml_tree,
"label_weapon_speed");
223 glade_xml_get_widget(xml_tree,
"label_range");
225 glade_xml_get_widget(xml_tree,
"label_exp");
227 glade_xml_get_widget(xml_tree,
"label_level");
236 glade_xml_get_widget(xml_tree,
"table_skills_exp");
239 statwindow.
skill_exp[i] = gtk_label_new(
"");
241 x, x+1, y, y+1, GTK_EXPAND, 0, 0, 0);
242 gtk_widget_show(statwindow.
skill_exp[i]);
251 glade_xml_get_widget(xml_tree,
"table_protections");
254 statwindow.
resists[i] = gtk_label_new(
"");
256 x, x+1, y, y+1, GTK_EXPAND, 0, 0, 0);
257 gtk_widget_show(statwindow.
resists[i]);
292 void update_stat(
int stat_no, sint64 max_stat, sint64 current_stat,
293 sint64 statbar_max, sint64 statbar_stat,
const char *
name,
int can_alert)
298 GdkColor ncolor, *set_color=NULL;
301 if (
lastval[stat_no] == current_stat &&
lastmax[stat_no] == max_stat)
304 lastval[stat_no] = current_stat;
307 if (statbar_max > 0) bar = (float) statbar_stat / (
float) statbar_max;
311 if (can_alert && current_stat * 4 < max_stat) is_alert=1;
319 GdkColor *hcolor, *lcolor;
329 if (bar>2.0) bar=2.0;
334 if (bar < 0.0) bar=0.0;
346 if (lcolor && hcolor) {
348 memcpy(&ncolor, lcolor,
sizeof(GdkColor));
350 ncolor.red += (hcolor->red - lcolor->red) * diff;
351 ncolor.green += (hcolor->green - lcolor->green) * diff;
352 ncolor.blue += (hcolor->blue - lcolor->blue) * diff;
377 memcpy(&ncolor, hcolor,
sizeof(GdkColor));
379 if (lcolor->red > hcolor->red)
380 ncolor.red = 2 * lcolor->red * (1.0 - diff);
382 if (lcolor->green > hcolor->green)
383 ncolor.green = 2 * lcolor->green * (1.0 - diff);
385 if (lcolor->blue > hcolor->blue)
386 ncolor.blue = 2 * lcolor->blue * (1.0 - diff);
389 memcpy(&ncolor, lcolor,
sizeof(GdkColor));
391 if (hcolor->red > lcolor->red)
392 ncolor.red = 2 * hcolor->red * diff;
394 if (hcolor->green > lcolor->green)
395 ncolor.green = 2 * hcolor->green * diff;
397 if (hcolor->blue > lcolor->blue)
398 ncolor.blue = 2 * hcolor->blue * diff;
402 fprintf(stderr,
"stat %d, val %d, r/g/b=%d/%d/%d\n",
403 stat_no, current_stat, ncolor.red, ncolor.green, ncolor.blue);
408 if (statbar_stat * 4 < statbar_max)
410 else if (statbar_stat > statbar_max)
415 if (bar > 1.0) bar = 1.0;
416 if (bar < 0.0) bar = 0.0;
424 gtk_widget_modify_base(
stat_bar[stat_no], GTK_STATE_SELECTED, set_color);
426 gtk_progress_set_percentage(GTK_PROGRESS(
stat_bar[stat_no]), bar);
427 snprintf(buf,
sizeof(buf),
"%s %"FMT64
"/%"FMT64, name, current_stat, max_stat);
428 gtk_label_set(GTK_LABEL(
stat_label[stat_no]), buf);
438 static int lastbeep=0;
439 static sint64 level_diff;
483 if (!a->
name)
return 1;
484 if (!b->
name)
return -1;
485 else return strcasecmp(a->
name, b->
name);
496 skill_mapping[i].
value=i;
500 skill_mapping[i].
name = NULL;
502 qsort(skill_mapping, MAX_SKILL,
sizeof(
NameMapping),
506 resist_mapping[i].
value=i;
510 resist_mapping[i].
name = NULL;
512 qsort(resist_mapping, NUM_RESISTS,
sizeof(
NameMapping),
525 static int init_before=0, max_drawn_skill=0, max_drawn_resists=0;
533 memset(&last_stats, 0,
sizeof(
Stats));
545 if (strcmp(
cpl.
title, last_name) || redraw) {
552 snprintf(buff,
sizeof(buff),
"Experience: %5" FMT64 ,
cpl.
stats.
exp);
553 gtk_label_set (GTK_LABEL(statwindow.
exp), buff);
559 gtk_label_set (GTK_LABEL(statwindow.
level), buff);
565 gtk_label_set (GTK_LABEL(statwindow.
Str), buff);
571 gtk_label_set (GTK_LABEL(statwindow.
Dex), buff);
577 gtk_label_set (GTK_LABEL(statwindow.
Con), buff);
583 gtk_label_set (GTK_LABEL(statwindow.
Int), buff);
589 gtk_label_set (GTK_LABEL(statwindow.
Wis), buff);
595 gtk_label_set (GTK_LABEL(statwindow.
Pow), buff);
601 gtk_label_set (GTK_LABEL(statwindow.
Cha), buff);
606 snprintf(buff,
sizeof(buff),
"%3d",
cpl.
stats.
wc);
607 gtk_label_set (GTK_LABEL(statwindow.
wc), buff);
613 gtk_label_set (GTK_LABEL(statwindow.
dam), buff);
618 snprintf(buff,
sizeof(buff),
"%d",
cpl.
stats.
ac);
619 gtk_label_set (GTK_LABEL(statwindow.
ac), buff);
625 gtk_label_set (GTK_LABEL(statwindow.
armor), buff);
631 gtk_label_set (GTK_LABEL(statwindow.
speed), buff);
641 if (redraw || weap_sp !=last_stats.
weapon_sp) {
643 snprintf(buff,
sizeof(buff),
"%3.2f",weap_sp);
644 gtk_label_set (GTK_LABEL(statwindow.
weapon_speed), buff);
647 if(redraw || strcmp(
cpl.
range, last_range)) {
649 snprintf(buff,
sizeof(buff),
"Range: %s",
cpl.
range);
661 sk = skill_mapping[i].
value;
665 gtk_label_set(GTK_LABEL(statwindow.
skill_exp[on_skill++]), skill_mapping[i].
name);
667 gtk_label_set(GTK_LABEL(statwindow.
skill_exp[on_skill++]), buff);
682 if (on_skill < max_drawn_skill) {
685 for (k = on_skill; k <= max_drawn_skill; k++)
686 gtk_label_set(GTK_LABEL(statwindow.
skill_exp[k]),
"");
688 max_drawn_skill = on_skill;
696 sk = resist_mapping[i].
value;
698 gtk_label_set(GTK_LABEL(statwindow.
resists[j]), resist_mapping[i].
name);
701 gtk_label_set(GTK_LABEL(statwindow.
resists[j]), buff);
707 if (j < max_drawn_resists) {
708 for (i=j; i <= max_drawn_resists; i++) {
709 gtk_label_set(GTK_LABEL(statwindow.
resists[i]),
"");
712 max_drawn_resists = j;
void draw_stats(int redraw)
void draw_message_window(int redraw)
static const char *const stat_style_names[NUM_STYLES]
const char *const resists_name[NUM_RESISTS]
sint64 skill_exp[MAX_SKILL]
static GtkWidget * resists[NUM_RESISTS]
#define PROTECTION_BOXES_Y
char * skill_names[MAX_SKILL]
static int lastmax[MAX_STAT_BARS]
GtkWidget * table_protections
void stats_get_styles(void)
void stats_init(GtkWidget *window_root)
void LOG(LogLevel level, const char *origin, const char *format,...)
static int mapping_sort(NameMapping *a, NameMapping *b)
GdkColor * bar_colors[MAX_STAT_BARS][NUM_STYLES]
void clear_stat_mapping(void)
#define STYLE_GRAD_NORMAL
sint16 use_config[CONFIG_NUMS]
NameMapping skill_mapping[MAX_SKILL]
#define PROTECTION_BOXES_X
#define CONFIG_GRAD_COLOR
void update_stat(int stat_no, sint64 max_stat, sint64 current_stat, sint64 statbar_max, sint64 statbar_stat, const char *name, int can_alert)
GtkWidget * stat_bar[MAX_STAT_BARS]
static const char *const stat_bar_names[MAX_STAT_BARS]
NameMapping resist_mapping[NUM_RESISTS]
GtkWidget * stat_label[MAX_STAT_BARS]
static int lastval[MAX_STAT_BARS]
GtkWidget * skill_exp[MAX_SKILL *2]
const char *const rcsid_gtk2_stats_c
GtkWidget * resists[PROTECTION_BOXES_X *PROTECTION_BOXES_Y]
sint16 skill_level[MAX_SKILL]
static StatWindow statwindow
static void update_stat_mapping(void)
GtkWidget * table_skills_exp