Atrinik Client  4.0
protections.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 #include <toolkit/string.h>
34 
36 static void widget_draw(widgetdata *widget)
37 {
38  size_t i, j;
39  SDL_Rect box[4];
40  char buf[HUGE_BUF];
41  const char *color;
42 
43  if (!widget->redraw) {
44  return;
45  }
46 
47  for (i = 0; i < arraysize(cpl.stats.protection) / 5; i++) {
48 #define PAD_BORDER 10
49 #define PADX_BOX 10
50 #define PADY_BOX 5
51  box[i].w = (widget->w - PAD_BORDER * 2 - PADX_BOX) / 2;
52  box[i].h = (widget->h - PAD_BORDER * 2 - PADY_BOX) / 2;
53  box[i].x = PAD_BORDER + (box[i].w + PADX_BOX) * ((i % 2));
54  box[i].y = PAD_BORDER + (box[i].h + PADY_BOX) * (i / 2);
55 #undef PAD_BORDER
56 #undef PADX_BOX
57 #undef PADY_BOX
58 
59  snprintf(buf, sizeof(buf),
60  "[o=#000000][center][font=serif][size=+3]%s[/size][/font]"
61  "[/center][/o]", s_settings->protection_groups[i]);
62 
63  for (j = 0; j < 5; j++) {
64  if (cpl.stats.protection[i * 5 + j] == 0) {
65  color = COLOR_GRAY;
66  } else if (cpl.stats.protection[i * 5 + j] < 0) {
67  color = COLOR_RED;
68  } else if (cpl.stats.protection[i * 5 + j] >= 100) {
69  color = COLOR_ORANGE;
70  } else {
71  color = COLOR_WHITE;
72  }
73 
74  snprintfcat(buf, sizeof(buf),
75  "\n%s[c=#%s][right][font=mono]%02d[/font][/right][/c]",
76  s_settings->protection_full[i * 5 + j], color,
77  cpl.stats.protection[i * 5 + j]);
78  }
79 
80  text_show(widget->surface, FONT("serif", 11), buf, box[i].x, box[i].y,
81  COLOR_HGOLD, TEXT_MARKUP, &box[i]);
82  }
83 }
84 
89 {
90  widget->draw_func = widget_draw;
91 }
#define FONT(font_name, font_size)
Definition: text.h:63
SDL_Surface * surface
Definition: widget.h:110
int8_t protection[CS_STAT_PROT_END-CS_STAT_PROT_START+1]
Definition: player.h:96
void text_show(SDL_Surface *surface, font_struct *font, const char *text, int x, int y, const char *color_notation, uint64_t flags, SDL_Rect *box)
Definition: text.c:1983
Stats stats
Definition: player.h:167
server_settings * s_settings
#define COLOR_HGOLD
Definition: text.h:319
void widget_protections_init(widgetdata *widget)
Definition: protections.c:88
char * protection_full[20]
#define COLOR_ORANGE
Definition: text.h:291
#define TEXT_MARKUP
Definition: text.h:224
#define COLOR_RED
Definition: text.h:295
#define COLOR_GRAY
Definition: text.h:301
Client_Player cpl
Definition: client.c:50
char * protection_groups[5]
uint8_t redraw
Definition: widget.h:72
int w
Definition: widget.h:54
int h
Definition: widget.h:57
static void widget_draw(widgetdata *widget)
Definition: protections.c:36
#define COLOR_WHITE
Definition: text.h:289