UFO: Alien Invasion
Loading...
Searching...
No Matches
ui_node_item.cpp
Go to the documentation of this file.
1
6
7/*
8Copyright (C) 2002-2025 UFO: Alien Invasion.
9
10This program is free software; you can redistribute it and/or
11modify it under the terms of the GNU General Public License
12as published by the Free Software Foundation; either version 2
13of the License, or (at your option) any later version.
14
15This program is distributed in the hope that it will be useful,
16but WITHOUT ANY WARRANTY; without even the implied warranty of
17MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
19See the GNU General Public License for more details.
20
21You should have received a copy of the GNU General Public License
22along with this program; if not, write to the Free Software
23Foundation, 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"
34
36
37#include "../../cgame/cl_game.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
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}
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
const char * GAME_GetModelForItem(const objDef_t *od, uiModel_t **uiModel)
Get a model for an item.
Definition cl_game.cpp:1534
Shared game type headers.
item instance data, with linked list capability
Definition inv_shared.h:402
const objDef_t * def(void) const
Definition inv_shared.h:469
void draw(uiNode_t *node) override
Draw an item node.
const objDef_t * INVSH_GetItemByIDSilent(const char *id)
Returns the item that belongs to the given id or nullptr if it wasn't found.
void R_CleanupDepthBuffer(int x, int y, int width, int height)
"Clean up" the depth buffer into a rect
Definition r_draw.cpp:596
@ V_BOOL
Definition scripts.h:50
Header for lua script functions.
bool Q_strnull(const char *string)
Definition shared.h:138
extradata for the model node
Defines all attributes of objects used in the inventory.
Definition inv_shared.h:264
node behaviour, how a node work
const char * name
void * lua_SWIG_typeinfo
UINodePtr manager
const char * extends
vec2_t size
Definition ui_nodes.h:52
Atomic structure used to define most of the UI.
Definition ui_nodes.h:80
uiBox_t box
Definition ui_nodes.h:96
vec_t vec3_t[3]
Definition ufotypes.h:39
vec_t vec4_t[4]
Definition ufotypes.h:40
vec_t vec2_t[2]
Definition ufotypes.h:38
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
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:526
SharedPtr< uiNode > UINodePtr
#define EXTRADATA(node)
static const vec3_t scale
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 UI_RegisterItemNode(uiBehaviour_t *behaviour)
void UI_DrawModelNode(uiNode_t *node, const char *source)
const char * UI_GetReferenceString(const uiNode_t *const node, const char *ref)