Atrinik Client 2.5
gui/protections.c
Go to the documentation of this file.
00001 /************************************************************************
00002 *            Atrinik, a Multiplayer Online Role Playing Game            *
00003 *                                                                       *
00004 *    Copyright (C) 2009-2011 Alex Tokar and Atrinik Development Team    *
00005 *                                                                       *
00006 * Fork from Daimonin (Massive Multiplayer Online Role Playing Game)     *
00007 * and Crossfire (Multiplayer game for X-windows).                       *
00008 *                                                                       *
00009 * This program is free software; you can redistribute it and/or modify  *
00010 * it under the terms of the GNU General Public License as published by  *
00011 * the Free Software Foundation; either version 2 of the License, or     *
00012 * (at your option) any later version.                                   *
00013 *                                                                       *
00014 * This program is distributed in the hope that it will be useful,       *
00015 * but WITHOUT ANY WARRANTY; without even the implied warranty of        *
00016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
00017 * GNU General Public License for more details.                          *
00018 *                                                                       *
00019 * You should have received a copy of the GNU General Public License     *
00020 * along with this program; if not, write to the Free Software           *
00021 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.             *
00022 *                                                                       *
00023 * The author can be reached at admin@atrinik.org                        *
00024 ************************************************************************/
00025 
00030 #include <global.h>
00031 
00035 void widget_show_resist(widgetdata *widget)
00036 {
00037     SDL_Rect box;
00038     size_t i;
00039     int x = 5, y = 2, mx, my;
00040 
00041     if (!widget->widgetSF)
00042     {
00043         widget->widgetSF = SDL_ConvertSurface(Bitmaps[BITMAP_RESIST_BG]->bitmap, Bitmaps[BITMAP_RESIST_BG]->bitmap->format, Bitmaps[BITMAP_RESIST_BG]->bitmap->flags);
00044     }
00045 
00046     if (widget->redraw)
00047     {
00048         _BLTFX bltfx;
00049 
00050         bltfx.surface = widget->widgetSF;
00051         bltfx.flags = 0;
00052         bltfx.alpha = 0;
00053 
00054         sprite_blt(Bitmaps[BITMAP_RESIST_BG], 0, 0, NULL, &bltfx);
00055         string_blt(widget->widgetSF, FONT_SERIF10, "Protection Table", x, y, COLOR_HGOLD, TEXT_OUTLINE, NULL);
00056     }
00057 
00058     SDL_GetMouseState(&mx, &my);
00059 
00060     for (i = 0; i < sizeof(cpl.stats.protection) / sizeof(*cpl.stats.protection); i++)
00061     {
00062         if (!(i % 5))
00063         {
00064             y += 15;
00065             x = 5;
00066         }
00067 
00068         if (widget->redraw)
00069         {
00070             const char *color;
00071 
00072             /* Figure out color for the protection value. */
00073             if (!cpl.stats.protection[i])
00074             {
00075                 color = COLOR_GRAY;
00076             }
00077             else if (cpl.stats.protection[i] < 0)
00078             {
00079                 color = COLOR_RED;
00080             }
00081             else if (cpl.stats.protection[i] >= 100)
00082             {
00083                 color = COLOR_ORANGE;
00084             }
00085             else
00086             {
00087                 color = COLOR_WHITE;
00088             }
00089 
00090             string_blt_format(widget->widgetSF, FONT_MONO9, x, y + 1, color, TEXT_MARKUP, NULL, "<c=#d4d553>%s</c>%s %02d", s_settings->protection_letters[i], s_settings->protection_letters[i][1] == '\0' ? " " : "", cpl.stats.protection[i]);
00091         }
00092 
00093         /* Show a tooltip with the protection's full name. */
00094         if (mx >= widget->x1 + x && mx < widget->x1 + x + 38 && my >= widget->y1 + y && my < widget->y1 + y + 15)
00095         {
00096             tooltip_create(mx, my, FONT_ARIAL10, s_settings->protection_full[i]);
00097         }
00098 
00099         x += 38;
00100     }
00101 
00102     widget->redraw = 0;
00103     box.x = widget->x1;
00104     box.y = widget->y1;
00105     SDL_BlitSurface(widget->widgetSF, NULL, ScreenSurface, &box);
00106 }