ui_node_item.c

Go to the documentation of this file.
00001 
00007 /*
00008 Copyright (C) 2002-2010 UFO: Alien Invasion.
00009 
00010 This program is free software; you can redistribute it and/or
00011 modify it under the terms of the GNU General Public License
00012 as published by the Free Software Foundation; either version 2
00013 of the License, or (at your option) any later version.
00014 
00015 This program is distributed in the hope that it will be useful,
00016 but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00018 
00019 See the GNU General Public License for more details.
00020 
00021 You should have received a copy of the GNU General Public License
00022 along with this program; if not, write to the Free Software
00023 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00024 
00025 */
00026 
00027 #include "../ui_nodes.h"
00028 #include "../ui_parse.h"
00029 #include "ui_node_model.h"
00030 #include "ui_node_item.h"
00031 #include "ui_node_container.h"
00032 #include "ui_node_abstractnode.h"
00033 
00034 #include "../../client.h"
00035 #include "../../cl_game.h"
00036 #include "../../renderer/r_draw.h"
00037 
00038 #define EXTRADATA(node) UI_EXTRADATA(node, modelExtraData_t)
00039 
00043 static void UI_ItemNodeDraw (uiNode_t *node)
00044 {
00045     const objDef_t *od;
00046     const char* ref = UI_GetReferenceString(node, EXTRADATA(node).model);
00047     vec2_t pos;
00048 
00049     if (!ref || ref[0] == '\0')
00050         return;
00051 
00052     UI_GetNodeAbsPos(node, pos);
00053     R_CleanupDepthBuffer(pos[0], pos[1], node->size[0], node->size[1]);
00054 
00055     od = INVSH_GetItemByIDSilent(ref);
00056     if (od) {
00057         item_t item = {1, NULL, NULL, 0, 0}; /* 1 so it's not reddish; fake item anyway */
00058         const vec4_t color = {1, 1, 1, 1};
00059         vec3_t pos;
00060         item.t = INVSH_GetItemByIDX(od->idx);
00061 
00062         if (EXTRADATA(node).containerLike || INV_IsArmour(item.t)) {
00063             /* We position the model of the item ourself (in the middle of the item
00064              * node). See the "-1, -1" parameter of UI_DrawItem. */
00065             UI_GetNodeAbsPos(node, pos);
00066             pos[0] += node->size[0] / 2.0;
00067             pos[1] += node->size[1] / 2.0;
00068             pos[2] = 0;
00070             UI_DrawItem(node, pos, &item, -1, -1, EXTRADATA(node).scale, color);
00071         } else {
00072             UI_DrawModelNode(node, GAME_GetModelForItem(item.t, NULL));
00073         }
00074     } else {
00075         GAME_DisplayItemInfo(node, ref);
00076     }
00077 }
00078 
00080 static const value_t properties[] = {
00081     /* Display an item like a container node do it */
00082     {"containerlike", V_BOOL, UI_EXTRADATA_OFFSETOF(modelExtraData_t, containerLike), MEMBER_SIZEOF(modelExtraData_t, containerLike)},
00083 
00084     {NULL, V_NULL, 0, 0}
00085 };
00086 
00087 void UI_RegisterItemNode (uiBehaviour_t *behaviour)
00088 {
00089     behaviour->name = "item";
00090     behaviour->properties = properties;
00091     behaviour->extends = "model";
00092     behaviour->draw = UI_ItemNodeDraw;
00093 }

Generated by  doxygen 1.6.2