UFO: Alien Invasion
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ui_node_item.cpp
Go to the documentation of this file.
1 
7 /*
8 Copyright (C) 2002-2020 UFO: Alien Invasion.
9 
10 This program is free software; you can redistribute it and/or
11 modify it under the terms of the GNU General Public License
12 as published by the Free Software Foundation; either version 2
13 of the License, or (at your option) any later version.
14 
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 See the GNU General Public License for more details.
20 
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
24 
25 */
26 
27 #include "../ui_nodes.h"
28 #include "../ui_parse.h"
29 #include "../ui_behaviour.h"
30 #include "ui_node_model.h"
31 #include "ui_node_item.h"
32 #include "ui_node_container.h"
33 #include "ui_node_abstractnode.h"
34 
35 #include "../../../common/scripts_lua.h"
36 
37 #include "../../cgame/cl_game.h"
38 #include "../../renderer/r_draw.h"
39 
40 #define EXTRADATA(node) UI_EXTRADATA(node, modelExtraData_t)
41 
46 {
47  const objDef_t* od;
48  const char* ref = UI_GetReferenceString(node, EXTRADATA(node).model);
49  vec2_t pos;
50 
51  if (Q_strnull(ref))
52  return;
53 
54  UI_GetNodeAbsPos(node, pos);
55  R_CleanupDepthBuffer(pos[0], pos[1], node->box.size[0], node->box.size[1]);
56 
57  od = INVSH_GetItemByIDSilent(ref);
58  if (od) {
59  Item item(od, nullptr, 1); /* 1 so it's not reddish; fake item anyway */
60  const char* model = GAME_GetModelForItem(item.def(), nullptr);
61 
62  if (EXTRADATA(node).containerLike || Q_strnull(model)) {
63  const vec4_t color = {1, 1, 1, 1};
64  vec3_t itemNodePos;
65  /* We position the model of the item ourself (in the middle of the item
66  * node). See the "-1, -1" parameter of UI_DrawItem. */
67  UI_GetNodeAbsPos(node, itemNodePos);
68  itemNodePos[0] += node->box.size[0] / 2.0;
69  itemNodePos[1] += node->box.size[1] / 2.0;
70  itemNodePos[2] = 0;
72  UI_DrawItem(node, itemNodePos, &item, -1, -1, EXTRADATA(node).scale, color);
73  } else {
74  UI_DrawModelNode(node, model);
75  }
76  } else {
77  GAME_DisplayItemInfo(node, ref);
78  }
79 }
80 
82 {
83  behaviour->name = "item";
84  behaviour->extends = "model";
85  behaviour->manager = UINodePtr(new uiItemNode());
86  behaviour->lua_SWIG_typeinfo = UI_SWIG_TypeQuery("uiItemNode_t *");
87 
88  /* Display an item like a container node do it */
89  UI_RegisterExtradataNodeProperty(behaviour, "containerlike", V_BOOL, modelExtraData_t, containerLike);
90 }
bool Q_strnull(const char *string)
Definition: shared.h:138
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
Definition: inv_shared.cpp:249
vec2_t size
Definition: ui_nodes.h:52
extradata for the model node
Definition: ui_node_model.h:63
const char * name
Definition: ui_behaviour.h:41
static const vec3_t scale
void UI_DrawModelNode(uiNode_t *node, const char *source)
UINodePtr manager
Definition: ui_behaviour.h:43
void UI_RegisterItemNode(uiBehaviour_t *behaviour)
const objDef_t * def(void) const
Definition: inv_shared.h:469
void draw(uiNode_t *node) override
Draw an item node.
Defines all attributes of objects used in the inventory.
Definition: inv_shared.h:264
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
Definition: ui_behaviour.h:109
item instance data, with linked list capability
Definition: inv_shared.h:402
const char * GAME_GetModelForItem(const objDef_t *od, uiModel_t **uiModel)
Get a model for an item.
Definition: cl_game.cpp:1725
SharedPtr< uiNode > UINodePtr
void * lua_SWIG_typeinfo
Definition: ui_behaviour.h:57
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)
Definition: ui_parse.cpp:1406
#define EXTRADATA(node)
Atomic structure used to define most of the UI.
Definition: ui_nodes.h:80
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
Definition: ui_node.cpp:514
Definition: scripts.h:50
node behaviour, how a node work
Definition: ui_behaviour.h:39
const char * extends
Definition: ui_behaviour.h:42
void GAME_DisplayItemInfo(uiNode_t *node, const char *string)
Shows game type specific item information (if it's not resolvable via objDef_t).
Definition: cl_game.cpp:338
vec_t vec3_t[3]
Definition: ufotypes.h:39
vec_t vec2_t[2]
Definition: ufotypes.h:38
uiBox_t box
Definition: ui_nodes.h:96
void UI_DrawItem(uiNode_t *node, const vec3_t org, const Item *item, int x, int y, const vec3_t scale, const vec4_t color)
Draws an item to the screen.
void R_CleanupDepthBuffer(int x, int y, int width, int height)
"Clean up" the depth buffer into a rect
Definition: r_draw.cpp:596
vec_t vec4_t[4]
Definition: ufotypes.h:40