Atrinik Client 2.5
gui/range.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 
00033 #define ICONDEFLEN 32
00034 
00041 void widget_range_event(widgetdata *widget, int x, int y, SDL_Event event, int MEvent)
00042 {
00043     if (x > widget->x1 + 5 && x < widget->x1 + 38 && y >= widget->y1 + 3 && y <= widget->y1 + 33)
00044     {
00045         if (MEvent == MOUSE_DOWN)
00046         {
00047             if (event.button.button == SDL_BUTTON_LEFT)
00048             {
00049                 keybind_process_command("?RANGE");
00050             }
00051             /* Mousewheel up */
00052             else if (event.button.button == 4)
00053             {
00054                 keybind_process_command("?RANGE");
00055             }
00056         }
00057         else if (MEvent == MOUSE_UP)
00058         {
00059             if (draggingInvItem(DRAG_GET_STATUS) > DRAG_IWIN_BELOW)
00060             {
00061                 /* KEYFUNC_APPLY and KEYFUNC_DROP works only if cpl.inventory_win = IWIN_INV. The tag must
00062                  * be placed in cpl.win_inv_tag. So we do this and after DnD we restore the old values. */
00063                 int old_inv_win = cpl.inventory_win;
00064                 int old_inv_tag = cpl.win_inv_tag;
00065 
00066                 cpl.inventory_win = IWIN_INV;
00067 
00068                 /* Range field */
00069                 if (draggingInvItem(DRAG_GET_STATUS) == DRAG_IWIN_INV && x >= widget->x1 && x <= widget->x1 + 78 && y >= widget->y1 && y <= widget->y1 + 35)
00070                 {
00071                     RangeFireMode = 4;
00072 
00073                     /* Drop to player doll. */
00074                     keybind_process_command("?APPLY");
00075                 }
00076 
00077                 cpl.inventory_win = old_inv_win;
00078                 cpl.win_inv_tag = old_inv_tag;
00079             }
00080         }
00081     }
00082 }
00083 
00087 void widget_show_range(widgetdata *widget)
00088 {
00089     char buf[MAX_BUF];
00090     object *tmp;
00091 
00092     fire_mode_tab[FIRE_MODE_BOW].item = FIRE_ITEM_NO;
00093     fire_mode_tab[FIRE_MODE_WAND].item = FIRE_ITEM_NO;
00094 
00095     for (tmp = cpl.ob->inv; tmp; tmp = tmp->next)
00096     {
00097         if (tmp->flags & F_APPLIED)
00098         {
00099             if (tmp->itype == TYPE_BOW)
00100             {
00101                 fire_mode_tab[FIRE_MODE_BOW].item = tmp->tag;
00102             }
00103             else if (tmp->itype == TYPE_WAND || tmp->itype == TYPE_ROD || tmp->itype == TYPE_HORN)
00104             {
00105                 fire_mode_tab[FIRE_MODE_WAND].item = tmp->tag;
00106             }
00107         }
00108     }
00109 
00110     sprite_blt(Bitmaps[BITMAP_RANGE], widget->x1 - 2, widget->y1, NULL, NULL);
00111 
00112     switch (RangeFireMode)
00113     {
00114         case FIRE_MODE_BOW:
00115             if (fire_mode_tab[FIRE_MODE_BOW].item != FIRE_ITEM_NO)
00116             {
00117                 tmp = object_find_object(cpl.ob, fire_mode_tab[RangeFireMode].item);
00118 
00119                 blt_inv_item_centered(tmp, widget->x1 + 3, widget->y1 + 2);
00120                 string_blt(ScreenSurface, FONT_SANS10, tmp->s_name, widget->x1 + 3, widget->y1 + 35, COLOR_WHITE, 0, NULL);
00121 
00122                 if (fire_mode_tab[FIRE_MODE_BOW].amun != FIRE_ITEM_NO && (tmp = object_find_object(cpl.ob, fire_mode_tab[FIRE_MODE_BOW].amun)))
00123                 {
00124                     if (tmp->itype == TYPE_ARROW)
00125                     {
00126                         snprintf(buf, sizeof(buf), "%s (%d)", tmp->s_name, tmp->nrof);
00127                     }
00128                     else
00129                     {
00130                         snprintf(buf, sizeof(buf), "%s (%4.3f kg)", tmp->s_name, tmp->weight);
00131                     }
00132 
00133                     blt_inv_item_centered(tmp, widget->x1 + 43, widget->y1 + 2);
00134                     string_blt(ScreenSurface, FONT_SANS10, buf, widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00135                 }
00136             }
00137             else
00138             {
00139                 string_blt(ScreenSurface, FONT_SANS10, "no range weapon applied", widget->x1 + 3, widget->y1 + 35, COLOR_WHITE, 0, NULL);
00140             }
00141 
00142             sprite_blt(Bitmaps[BITMAP_RANGE_MARKER], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00143             break;
00144 
00145         /* Wands, staves, rods and horns */
00146         case FIRE_MODE_WAND:
00147             if (fire_mode_tab[FIRE_MODE_WAND].item != FIRE_ITEM_NO && (tmp = object_find_object(cpl.ob, fire_mode_tab[FIRE_MODE_WAND].item)))
00148             {
00149                 string_blt(ScreenSurface, FONT_SANS10, tmp->s_name, widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00150                 sprite_blt(Bitmaps[BITMAP_RANGE_TOOL], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00151                 blt_inv_item_centered(tmp, widget->x1 + 43, widget->y1 + 2);
00152             }
00153             else
00154             {
00155                 sprite_blt(Bitmaps[BITMAP_RANGE_TOOL_NO], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00156                 string_blt(ScreenSurface, FONT_SANS10, "nothing applied", widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00157             }
00158 
00159             string_blt(ScreenSurface, FONT_SANS10, "use range tool", widget->x1 + 3, widget->y1 + 35, COLOR_WHITE, 0, NULL);
00160             break;
00161 
00162         /* These are client only, no server signal needed */
00163         case FIRE_MODE_SKILL:
00164             if (fire_mode_tab[FIRE_MODE_SKILL].skill)
00165             {
00166                 sprite_blt(Bitmaps[BITMAP_RANGE_SKILL], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00167                 blit_face(fire_mode_tab[FIRE_MODE_SKILL].skill->icon, widget->x1 + 43, widget->y1 + 2);
00168                 string_blt(ScreenSurface, FONT_SANS10, fire_mode_tab[FIRE_MODE_SKILL].skill->name, widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00169             }
00170             else
00171             {
00172                 sprite_blt(Bitmaps[BITMAP_RANGE_SKILL_NO], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00173                 string_blt(ScreenSurface, FONT_SANS10, "no skill selected", widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00174             }
00175 
00176             string_blt(ScreenSurface, FONT_SANS10, "use skill", widget->x1 + 3, widget->y1 + 35, COLOR_WHITE, 0, NULL);
00177             break;
00178 
00179         case FIRE_MODE_SPELL:
00180             if (fire_mode_tab[FIRE_MODE_SPELL].spell)
00181             {
00182                 sprite_blt(Bitmaps[BITMAP_RANGE_WIZARD], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00183                 blit_face(fire_mode_tab[FIRE_MODE_SPELL].spell->icon, widget->x1 + 43, widget->y1 + 2);
00184                 string_blt(ScreenSurface, FONT_SANS10, fire_mode_tab[FIRE_MODE_SPELL].spell->name, widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00185             }
00186             else
00187             {
00188                 sprite_blt(Bitmaps[BITMAP_RANGE_WIZARD_NO], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00189                 string_blt(ScreenSurface, FONT_SANS10, "no spell selected", widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00190             }
00191 
00192             string_blt(ScreenSurface, FONT_SANS10, "cast spell", widget->x1 + 3, widget->y1 + 35, COLOR_WHITE, 0, NULL);
00193             break;
00194 
00195         case FIRE_MODE_THROW:
00196             if (fire_mode_tab[FIRE_MODE_THROW].item != FIRE_ITEM_NO && (tmp = object_find_object(cpl.ob, fire_mode_tab[FIRE_MODE_THROW].item)))
00197             {
00198                 sprite_blt(Bitmaps[BITMAP_RANGE_THROW], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00199                 blt_inv_item_centered(tmp, widget->x1 + 43, widget->y1 + 2);
00200 
00201                 if (tmp->nrof > 1)
00202                 {
00203                     if (tmp->nrof > 9999)
00204                     {
00205                         snprintf(buf, sizeof(buf), "many");
00206                     }
00207                     else
00208                     {
00209                         snprintf(buf, sizeof(buf), "%d", tmp->nrof);
00210                     }
00211 
00212                     string_blt(ScreenSurface, FONT_SANS7, buf, widget->x1 + 43 + ICONDEFLEN / 2 - string_get_width(FONT_SANS7, buf, TEXT_OUTLINE) / 2, widget->y1 + 2 + ICONDEFLEN - FONT_HEIGHT(FONT_SANS7), COLOR_WHITE, TEXT_OUTLINE, NULL);
00213                 }
00214 
00215                 string_blt(ScreenSurface, FONT_SANS10, tmp->s_name, widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00216             }
00217             else
00218             {
00219                 sprite_blt(Bitmaps[BITMAP_RANGE_THROW_NO], widget->x1 + 3, widget->y1 + 2, NULL, NULL);
00220                 string_blt(ScreenSurface, FONT_SANS10, "no item ready", widget->x1 + 3, widget->y1 + 46, COLOR_WHITE, 0, NULL);
00221             }
00222 
00223             string_blt(ScreenSurface, FONT_SANS10, "throw item", widget->x1 + 3, widget->y1 + 35, COLOR_WHITE, 0, NULL);
00224             break;
00225     }
00226 }