Atrinik Client  4.0
playerinfo.c
Go to the documentation of this file.
1 /*************************************************************************
2  * Atrinik, a Multiplayer Online Role Playing Game *
3  * *
4  * Copyright (C) 2009-2014 Alex Tokar and Atrinik Development Team *
5  * *
6  * Fork from Crossfire (Multiplayer game for X-windows). *
7  * *
8  * This program is free software; you can redistribute it and/or modify *
9  * it under the terms of the GNU General Public License as published by *
10  * the Free Software Foundation; either version 2 of the License, or *
11  * (at your option) any later version. *
12  * *
13  * This program is distributed in the hope that it will be useful, *
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16  * GNU General Public License for more details. *
17  * *
18  * You should have received a copy of the GNU General Public License *
19  * along with this program; if not, write to the Free Software *
20  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. *
21  * *
22  * The author can be reached at admin@atrinik.org *
23  ************************************************************************/
24 
32 #include <global.h>
33 
35 static void
37 {
38  if (!widget->redraw) {
39  return;
40  }
41 
42  SDL_Rect box;
43  box.w = widget->w;
44  box.h = widget->h;
45 
46  text_show_format(widget->surface,
47  FONT_SERIF14,
48  4,
49  0,
52  &box,
53  "[font=arial 11][tooltip_conf=800 300]"
54  "[tooltip=This is your character's action timer, i.e., "
55  "the amount of time before the next skill-based action "
56  "can be performed (such as spell casting or firing a "
57  "bow).][/font]%1.2f[/tooltip]",
59  text_show_format(widget->surface,
60  FONT_SERIF14,
61  0,
62  0,
66  &box,
67  "[b]%s[/b]",
68  cpl.name);
69 
70  char buf[32];
71  snprintf(VS(buf), "[b]%d[/b]", cpl.stats.level);
72  int wd = text_get_width(FONT_SERIF14, buf, TEXT_MARKUP);
73  const char *color =
75  text_show_format(widget->surface,
76  FONT_SERIF14,
77  widget->w - 4 - wd,
78  0,
79  color,
81  &box,
82  "[font=arial 11][tooltip_conf=800 300][tooltip=This is "
83  "your character's main level.][/font]%s[/tooltip]",
84  buf);
85 
87 }
88 
90 static void
91 widget_background (widgetdata *widget, int draw)
92 {
93  static uint32_t action_tick = 0;
94 
95  /* Pre-emptively tick down the skill delay timer */
96  if (cpl.action_timer > 0.0) {
97  if (LastTick - action_tick > 125) {
98  cpl.action_timer -= (LastTick - action_tick) / 1000.0f;
99  if (cpl.action_timer < 0.0) {
100  cpl.action_timer = 0.0;
101  }
102 
103  action_tick = LastTick;
104  WIDGET_REDRAW(widget);
105  }
106  } else {
107  action_tick = LastTick;
108  }
109 }
110 
112 static int
113 widget_event (struct widgetdata *widget, SDL_Event *event)
114 {
115  if (event->type == SDL_MOUSEMOTION) {
116  WIDGET_REDRAW(widget);
117  return 1;
118  }
119 
120  return 0;
121 }
122 
126 void
128 {
129  widget->draw_func = widget_draw;
130  widget->background_func = widget_background;
131  widget->event_func = widget_event;
132 }
float action_timer
Definition: player.h:152
SDL_Surface * surface
Definition: widget.h:110
static void widget_background(widgetdata *widget, int draw)
Definition: playerinfo.c:91
Stats stats
Definition: player.h:167
server_settings * s_settings
#define COLOR_HGOLD
Definition: text.h:319
#define TEXT_MARKUP
Definition: text.h:224
#define TEXT_ALIGN_CENTER
Definition: text.h:230
void widget_playerinfo_init(widgetdata *widget)
Definition: playerinfo.c:127
Client_Player cpl
Definition: client.c:50
static int widget_event(struct widgetdata *widget, SDL_Event *event)
Definition: playerinfo.c:113
char name[40]
Definition: player.h:173
uint8_t redraw
Definition: widget.h:72
#define WIDGET_REDRAW(__tmp)
Definition: widget.h:398
void tooltip_enable_delay(uint32_t delay)
Definition: tooltip.c:82
#define TEXT_OUTLINE
Definition: text.h:255
int w
Definition: widget.h:54
int h
Definition: widget.h:57
static void widget_draw(widgetdata *widget)
Definition: playerinfo.c:36
uint32_t level
Definition: player.h:63
uint32_t LastTick
Definition: main.c:57
int text_get_width(font_struct *font, const char *text, uint64_t flags)
Definition: text.c:2328
void text_show_format(SDL_Surface *surface, font_struct *font, int x, int y, const char *color_notation, uint64_t flags, SDL_Rect *box, const char *format,...)
Definition: text.c:2289
#define TEXT_VALIGN_CENTER
Definition: text.h:246
#define COLOR_WHITE
Definition: text.h:289