UFO: Alien Invasion
ui_node_container.cpp File Reference

The container node refer to several different nodes merged into a single one. All of them can drag and drop soldier items from one container to another. The first container is a soldier slot. For example, the left arm, the bag pack... The second is the base inventory (which is now an extended node from container). And the last is a floor container used in the battlescape. The node name itself is used to know the container role. More...

#include "../ui_main.h"
#include "../ui_parse.h"
#include "../ui_behaviour.h"
#include "../ui_actions.h"
#include "../ui_dragndrop.h"
#include "../ui_tooltip.h"
#include "../ui_nodes.h"
#include "../ui_input.h"
#include "../ui_render.h"
#include "../ui_lua.h"
#include "ui_node_model.h"
#include "ui_node_container.h"
#include "ui_node_abstractnode.h"
#include "../../client.h"
#include "../../renderer/r_draw.h"
#include "../../renderer/r_mesh.h"
#include "../../cgame/cl_game.h"
#include "../../battlescape/cl_actor.h"
#include "../../cl_inventory.h"
#include "../../../common/scripts_lua.h"
Include dependency graph for ui_node_container.cpp:

Go to the source code of this file.

Macros

#define EXTRADATA_TYPE   containerExtraData_t
 
#define EXTRADATA(node)   UI_EXTRADATA(node, EXTRADATA_TYPE)
 
#define EXTRADATACONST(node)   UI_EXTRADATACONST(node, EXTRADATA_TYPE)
 

Functions

static bool UI_IsScrollContainerNode (const uiNode_t *const node)
 
void UI_ContainerNodeUpdateEquipment (Inventory *inv, const equipDef_t *ed)
 Fills the ground container of the ui_inventory with unused items from a given equipment definition. More...
 
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. More...
 
void UI_GetItemTooltip (const Item &item, char *tooltipText, size_t stringMaxLength)
 Generate tooltip text for an item. More...
 
uiNode_tUI_GetContainerNodeByContainerIDX (const uiNode_t *const parent, const int index)
 Search a child container node by the given container id. More...
 
static void UI_DrawDisabled (const uiNode_t *node)
 Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel) More...
 
static void UI_DrawFree (containerIndex_t container, const uiNode_t *node, int posx, int posy, int sizex, int sizey, bool showTUs)
 Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel) More...
 
static void UI_ContainerNodeDrawFreeSpace (uiNode_t *node, Inventory *inv)
 Draws the free and usable inventory positions when dragging an item. More...
 
static void UI_ContainerNodeDrawSingle (uiNode_t *node, const objDef_t *highlightType)
 Draw a container which only contains one item. More...
 
static void UI_ContainerNodeDrawGrid (uiNode_t *node, const objDef_t *highlightType)
 Draw a grip container. More...
 
static void UI_ContainerNodeDrawDropPreview (uiNode_t *target)
 Draw a preview of the DND item dropped into the node. More...
 
static ItemUI_ContainerNodeGetItemAtPosition (const uiNode_t *const node, int mouseX, int mouseY, int *contX=nullptr, int *contY=nullptr)
 Gets location of the item the mouse is over. More...
 
static bool UI_ContainerNodeAddItem (const invDef_t *container, Item *ic, containerIndex_t containerID, Item **icp)
 
void UI_ContainerNodeAutoPlaceItem (uiNode_t *node, Item *ic)
 Try to autoplace an item from a container. More...
 
static void UI_ContainerNodeAutoPlace (uiNode_t *node, int mouseX, int mouseY)
 Try to autoplace an item at a position when right-click was used in the inventory. More...
 
void UI_RegisterContainerNode (uiBehaviour_t *behaviour)
 

Variables

Inventoryui_inventory = nullptr
 
static int dragInfoFromX = -1
 
static int dragInfoFromY = -1
 
static int dragInfoToX = -1
 
static int dragInfoToY = -1
 
static const ItemdragInfoIC
 
static const vec3_t scale = {3.5, 3.5, 3.5}
 
static const vec4_t colorDefault = {1, 1, 1, 1}
 
static const vec4_t colorLoadable = {0.5, 1, 0.5, 1}
 
static const vec4_t colorDisabled = {0.5, 0.5, 0.5, 1}
 
static const vec4_t colorDisabledLoadable = {0.5, 0.25, 0.25, 1.0}
 
static const vec4_t colorPreview = { 0.5, 0.5, 1, 1 }
 
static int oldMouseX = 0
 
static int oldMouseY = 0
 

Detailed Description

The container node refer to several different nodes merged into a single one. All of them can drag and drop soldier items from one container to another. The first container is a soldier slot. For example, the left arm, the bag pack... The second is the base inventory (which is now an extended node from container). And the last is a floor container used in the battlescape. The node name itself is used to know the container role.

Todo:

Move container role outside of the node name

Link soldier container with a soldier

Link floor container with a map/cell...

Definition in file ui_node_container.cpp.

Macro Definition Documentation

◆ EXTRADATA

#define EXTRADATA (   node)    UI_EXTRADATA(node, EXTRADATA_TYPE)

Definition at line 65 of file ui_node_container.cpp.

◆ EXTRADATA_TYPE

#define EXTRADATA_TYPE   containerExtraData_t

Definition at line 64 of file ui_node_container.cpp.

◆ EXTRADATACONST

#define EXTRADATACONST (   node)    UI_EXTRADATACONST(node, EXTRADATA_TYPE)

Definition at line 66 of file ui_node_container.cpp.

Function Documentation

◆ UI_ContainerNodeAddItem()

static bool UI_ContainerNodeAddItem ( const invDef_t container,
Item ic,
containerIndex_t  containerID,
Item **  icp 
)
static

◆ UI_ContainerNodeAutoPlace()

static void UI_ContainerNodeAutoPlace ( uiNode_t node,
int  mouseX,
int  mouseY 
)
static

Try to autoplace an item at a position when right-click was used in the inventory.

Parameters
[in]nodeThe context node
[in]mouseXX mouse coordinates.
[in]mouseYY mouse coordinates.

Definition at line 795 of file ui_node_container.cpp.

References CL_BattlescapeRunning(), cl_selected, EXTRADATA, cvar_t::integer, UI_ContainerNodeAutoPlaceItem(), UI_ContainerNodeGetItemAtPosition(), and ui_inventory.

Referenced by uiContainerNode::onMouseDown().

◆ UI_ContainerNodeAutoPlaceItem()

void UI_ContainerNodeAutoPlaceItem ( uiNode_t node,
Item ic 
)

◆ UI_ContainerNodeDrawDropPreview()

static void UI_ContainerNodeDrawDropPreview ( uiNode_t target)
static

◆ UI_ContainerNodeDrawFreeSpace()

static void UI_ContainerNodeDrawFreeSpace ( uiNode_t node,
Inventory inv 
)
static

Draws the free and usable inventory positions when dragging an item.

Note
Only call this function in dragging mode

< Get the 'type' of the dragged item.

Definition at line 334 of file ui_node_container.cpp.

References uiNode_t::box, C_UNIT, Inventory::canHoldItem(), Item::def(), dragInfoIC, EXTRADATA, objDef_t::getShapeRotated(), INV_FITS, INV_FITS_ONLY_ROTATED, INVSH_CheckShape(), INVSH_MergeShapes(), OBJZERO, objDef_t::shape, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, uiBox_t::size, UI_DNDGetItem(), UI_DNDIsDragging(), UI_DNDIsSourceNode(), UI_DrawFree(), and UI_GetNodeAbsPos().

Referenced by uiContainerNode::draw().

◆ UI_ContainerNodeDrawGrid()

static void UI_ContainerNodeDrawGrid ( uiNode_t node,
const objDef_t highlightType 
)
static

◆ UI_ContainerNodeDrawSingle()

◆ UI_ContainerNodeGetItemAtPosition()

static Item * UI_ContainerNodeGetItemAtPosition ( const uiNode_t *const  node,
int  mouseX,
int  mouseY,
int contX = nullptr,
int contY = nullptr 
)
static

Gets location of the item the mouse is over.

Parameters
[in]nodeThe container-node.
[in]mouseXX location of the mouse.
[in]mouseYY location of the mouse.
[out]contXX location in the container (index of item in row).
[out]contYY location in the container (row).
See also
UI_ContainerNodeSearchInScrollableContainer

Definition at line 625 of file ui_node_container.cpp.

References C_UNIT, EXTRADATACONST, Inventory::getItemAtPos(), int(), Sys_Error(), UI_GetNodeAbsPos(), ui_inventory, and UI_IsScrollContainerNode().

Referenced by uiContainerNode::drawTooltip(), uiContainerNode::onMouseDown(), and UI_ContainerNodeAutoPlace().

◆ UI_ContainerNodeUpdateEquipment()

void UI_ContainerNodeUpdateEquipment ( Inventory inv,
const equipDef_t ed 
)

Fills the ground container of the ui_inventory with unused items from a given equipment definition.

Todo:
it's not obvious for the caller that ui_inventory pointer must be set
Parameters
[in,out]invThe inventory to add the unused items from ed to
[in]edThe equipment definition to get the used items from that should be added to the ground container of inv
Todo:
not used nor called by the container node; should be move somewhere else

Definition at line 102 of file ui_node_container.cpp.

References InventoryInterface::addToInventory(), CID_EQUIP, cls, csi, Item::def(), FILTER_AIRCRAFT, GAME_ItemIsUseable(), Inventory::getEquipContainer(), client_static_t::i, i, objDef_t::idx, INVDEF, INVSH_GetItemByIDX(), lengthof, MAX_CONTAINERS, Mem_Dup, Mem_Free, NONE, equipDef_t::numItems, csi_t::numODs, Inventory::setContainer(), and ui_inventory.

Referenced by GAME_GetImportData(), and GAME_UpdateInventory().

◆ UI_DrawDisabled()

static void UI_DrawDisabled ( const uiNode_t node)
static

Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel)

Definition at line 300 of file ui_node_container.cpp.

References uiNode_t::box, uiBox_t::size, UI_DrawFill(), and UI_GetNodeAbsPos().

Referenced by UI_ContainerNodeDrawSingle().

◆ UI_DrawFree()

static void UI_DrawFree ( containerIndex_t  container,
const uiNode_t node,
int  posx,
int  posy,
int  sizex,
int  sizey,
bool  showTUs 
)
static

Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel)

Definition at line 312 of file ui_node_container.cpp.

References _, ALIGN_UL, uiNode_t::box, CL_BattlescapeRunning(), invDef_t::in, INVDEF, invDef_t::out, uiBox_t::size, UI_DrawFill(), UI_DrawString(), UI_GetNodeAbsPos(), and va().

Referenced by UI_ContainerNodeDrawFreeSpace().

◆ UI_DrawItem()

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.

Parameters
[in]nodeContext node
[in]orgNode position on the screen (pixel). Single nodes: Use the center of the node.
[in]itemThe item to draw.
[in]x,yPosition in container. Set both to -1 if it's drawn in a single container.
[in]scale
[in]color
See also
SCR_DrawCursor Used to draw an item to the equipment containers. First look whether the objDef_t includes an image - if there is none then draw the model
Todo:
Change the rotation of the image as well, right now only the location is changed. How is image-rotation handled right now?
Todo:
Image size calculation depends on handling of image-rotation. imgWidth = od->sy * C_UNIT; imgHeight = od->sx * C_UNIT;

Definition at line 149 of file ui_node_container.cpp.

References modelInfo_t::angles, C_UNIT, modelInfo_t::center, objDef_t::center, modelInfo_t::color, Com_Printf(), Item::def(), GAME_GetModelForItem(), objDef_t::id, objDef_t::image, Item::mustReload(), modelInfo_t::name, OBJZERO, modelInfo_t::origin, Q_strnull(), R_Color(), R_DrawModelDirect(), Item::rotated, modelInfo_t::scale, scale, objDef_t::scale, objDef_t::sx, objDef_t::sy, UI_DrawModelNode(), UI_DrawNormImageByName(), Vector4Copy, VectorCopy, VectorNegate, VectorScale, and objDef_t::weapon.

Referenced by uiItemNode::draw(), UI_BaseInventoryNodeDrawItems(), UI_ContainerNodeDrawDropPreview(), UI_ContainerNodeDrawGrid(), UI_ContainerNodeDrawSingle(), and UI_DrawDragAndDrop().

◆ UI_GetContainerNodeByContainerIDX()

uiNode_t * UI_GetContainerNodeByContainerIDX ( const uiNode_t *const  parent,
const int  index 
)

Search a child container node by the given container id.

Note
Only search with one depth

Definition at line 290 of file ui_node_container.cpp.

References index, INVDEF, invDef_t::name, and UI_GetNode().

Referenced by UI_ContainerNodeAutoPlaceItem().

◆ UI_GetItemTooltip()

void UI_GetItemTooltip ( const Item item,
char *  tooltipText,
size_t  stringMaxLength 
)

Generate tooltip text for an item.

Parameters
[in]itemThe item we want to generate the tooltip text for.
[in,out]tooltipTextPointer to a string the information should be written into.
[in]stringMaxLengthMax. string size of tooltipText.
Returns
Number of lines

Definition at line 247 of file ui_node_container.cpp.

References _, Item::ammoDef(), Com_sprintf(), Item::def(), GAME_ItemIsUseable(), Item::getAmmoLeft(), Item::getAmount(), i, Item::isWeapon(), objDef_t::name, objDef_t::numWeapons, Q_strcat(), and objDef_t::weapons.

Referenced by uiBaseInventoryNode::drawTooltip(), and uiContainerNode::drawTooltip().

◆ UI_IsScrollContainerNode()

◆ UI_RegisterContainerNode()

Variable Documentation

◆ colorDefault

const vec4_t colorDefault = {1, 1, 1, 1}
static
Todo:
it may be nice to vectorise that

Definition at line 424 of file ui_node_container.cpp.

Referenced by UI_ContainerNodeDrawGrid(), and UI_ContainerNodeDrawSingle().

◆ colorDisabled

const vec4_t colorDisabled = {0.5, 0.5, 0.5, 1}
static

Definition at line 426 of file ui_node_container.cpp.

Referenced by UI_ContainerNodeDrawSingle().

◆ colorDisabledLoadable

const vec4_t colorDisabledLoadable = {0.5, 0.25, 0.25, 1.0}
static

Definition at line 427 of file ui_node_container.cpp.

Referenced by UI_ContainerNodeDrawSingle().

◆ colorLoadable

const vec4_t colorLoadable = {0.5, 1, 0.5, 1}
static

Definition at line 425 of file ui_node_container.cpp.

Referenced by UI_ContainerNodeDrawGrid(), and UI_ContainerNodeDrawSingle().

◆ colorPreview

const vec4_t colorPreview = { 0.5, 0.5, 1, 1 }
static

Make the preview item look bluish

Definition at line 428 of file ui_node_container.cpp.

Referenced by UI_ContainerNodeDrawDropPreview().

◆ dragInfoFromX

int dragInfoFromX = -1
static

self cache for drag item

Note
we can use a global variable because we only can have 1 source node at a time

Definition at line 72 of file ui_node_container.cpp.

Referenced by uiContainerNode::onDndFinished(), and uiContainerNode::onMouseDown().

◆ dragInfoFromY

int dragInfoFromY = -1
static

◆ dragInfoIC

const Item* dragInfoIC
static

The current invList pointer (only used for ignoring the dragged item for finding free space right now)

Definition at line 86 of file ui_node_container.cpp.

Referenced by uiContainerNode::onCapturedMouseMove(), uiContainerNode::onDndMove(), uiContainerNode::onMouseDown(), UI_ContainerNodeDrawDropPreview(), and UI_ContainerNodeDrawFreeSpace().

◆ dragInfoToX

int dragInfoToX = -1
static

self cache for the preview and dropped item

Note
we can use a global variable because we only can have 1 target node at a time

Definition at line 79 of file ui_node_container.cpp.

Referenced by uiContainerNode::onDndFinished(), uiContainerNode::onDndLeave(), uiContainerNode::onDndMove(), and UI_ContainerNodeDrawDropPreview().

◆ dragInfoToY

◆ oldMouseX

int oldMouseX = 0
static

◆ oldMouseY

int oldMouseY = 0
static

◆ scale

const vec3_t scale = {3.5, 3.5, 3.5}
static

◆ ui_inventory