ui_node_container.c File Reference

The container node refer to 3 different nodes merged into a singler one. Both can drag and drop solider items from a container to another one. The first container is a soldier slot. For example, the left arm, the bag pack... The second is the base item list. And the last it a floor container used into the battlescape. The node name itself is used to know the container role. More...

#include "../ui_main.h"
#include "../ui_parse.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_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 "../../cl_game.h"
#include "../../cl_team.h"
#include "../../battlescape/cl_actor.h"
#include "../../cl_inventory.h"
Include dependency graph for ui_node_container.c:

Go to the source code of this file.

Defines

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

Functions

static invList_tUI_ContainerNodeGetExistingItem (const uiNode_t *node, objDef_t *item, const itemFilterTypes_t filterType)
 Searches if there is an item at location (x/y) in a scrollable container. You can also provide an item to search for directly (x/y is ignored in that case).
static void UI_ContainerNodeUpdateScroll (uiNode_t *node)
 Update display of scroll buttons.
static qboolean UI_IsScrollContainerNode (const uiNode_t *const node)
void UI_ContainerNodeUpdateEquipment (inventory_t *inv, equipDef_t *ed)
 Fills the ground container of the ui_inventory with unused items from a given equipment definition.
void UI_DrawItem (uiNode_t *node, const vec3_t org, const item_t *item, int x, int y, const vec3_t scale, const vec4_t color)
 Draws an item to the screen.
static void UI_GetItemTooltip (item_t item, char *tooltipText, size_t stringMaxLength)
 Generate tooltip text for an item.
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).
static void UI_DrawFree (containerIndex_t container, const uiNode_t *node, int posx, int posy, int sizex, int sizey, qboolean showTUs)
 Draws the rectangle in a 'free' style on position posx/posy (pixel) in the size sizex/sizey (pixel).
static void UI_ContainerNodeDrawFreeSpace (uiNode_t *node, inventory_t *inv)
 Draws the free and usable inventory positions when dragging an item.
static void UI_ContainerNodeLoaded (uiNode_t *const node)
 Calculates the size of a container node and links the container into the node (uses the invDef_t shape bitmask to determine the size).
static void UI_ContainerNodeDrawSingle (uiNode_t *node, objDef_t *highlightType)
 Draw a container which only contains one item.
static void UI_ContainerNodeDrawGrid (uiNode_t *node, objDef_t *highlightType)
 Draw a grip container.
static void UI_ContainerNodeDrawDropPreview (uiNode_t *target)
 Draw a preview of the DND item dropped into the node.
static void UI_ContainerNodeDraw (uiNode_t *node)
 Main function to draw a container node.
static invList_tUI_ContainerNodeGetItemAtPosition (const uiNode_t *const node, int mouseX, int mouseY, int *contX, int *contY)
 Gets location of the item the mouse is over.
static void UI_ContainerNodeDrawTooltip (uiNode_t *node, int x, int y)
 Custom tooltip for container node.
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.
static void UI_ContainerNodeCapturedMouseMove (uiNode_t *node, int x, int y)
static void UI_ContainerNodeMouseDown (uiNode_t *node, int x, int y, int button)
static void UI_ContainerNodeMouseUp (uiNode_t *node, int x, int y, int button)
static void UI_ContainerNodeWheel (uiNode_t *node, qboolean down, int x, int y)
static void UI_ContainerNodeLoading (uiNode_t *node)
static qboolean UI_ContainerNodeDNDEnter (uiNode_t *target)
 Call when a DND enter into the node.
static qboolean UI_ContainerNodeDNDMove (uiNode_t *target, int x, int y)
 Call into the target when the DND hover it.
static void UI_ContainerNodeDNDLeave (uiNode_t *node)
 Call when a DND enter into the node.
static qboolean UI_ContainerNodeDNDFinished (uiNode_t *source, qboolean isDropped)
 Call into the source when the DND end.
void UI_RegisterContainerNode (uiBehaviour_t *behaviour)

Variables

inventory_tui_inventory = NULL
static int dragInfoFromX = -1
static int dragInfoFromY = -1
static int dragInfoToX = -1
static int dragInfoToY = -1
static const invList_tdragInfoIC
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 colorDisabledHiden = {0.5, 0.5, 0.5, 0.5}
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
static const value_t properties []

Detailed Description

The container node refer to 3 different nodes merged into a singler one. Both can drag and drop solider items from a container to another one. The first container is a soldier slot. For example, the left arm, the bag pack... The second is the base item list. And the last it a floor container used into the battlescape. The node name itself is used to know the container role.

Todo:

Move base container list outside

Move container role outside of the node name

Link soldier container with a soldier

Link base container with a base

Link floor container with a map/cell...

Definition in file ui_node_container.c.


Define Documentation

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

Definition at line 62 of file ui_node_container.c.

#define EXTRADATA_TYPE   containerExtraData_t

Definition at line 61 of file ui_node_container.c.

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

Definition at line 63 of file ui_node_container.c.


Function Documentation

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] node The context node
[in] mouseX X mouse coordinates.
[in] mouseY Y mouse coordinates.
Todo:
None generic function. Not sure we can do it in a generic way

HACK: Hard to know where the item is located now, but if its an armor we fire the change event of the armour container. At least to update the actor skin. The right way is to compute the source and the target container and fire the change event for both

Definition at line 697 of file ui_node_container.c.

References item_s::a, CL_BattlescapeRunning(), cl_selected, Com_DPrintf(), csi, DEBUG_CLIENT, EXTRADATA, objDef_s::fireTwoHanded, objDef_s::headgear, id, csi_s::idArmour, csi_s::idBackpack, csi_s::idBelt, csi_s::idEquip, csi_s::idHeadgear, csi_s::idHolster, csi_s::idLeft, csi_s::idRight, objDef_s::idx, cvar_s::integer, INV_IsAmmo, INV_IsArmour, INV_LoadWeapon(), INV_MoveItem(), INV_UnloadWeapon(), INVDEF, INVSH_FindSpace(), INVSH_SearchInInventory(), invList_s::item, item_s::m, NONE, uiNode_s::onChange, qfalse, uiNode_s::root, item_s::t, UI_ContainerNodeGetItemAtPosition(), UI_ContainerNodeUpdateScroll(), UI_ExecuteEventActions(), UI_GetNode(), UI_IsScrollContainerNode(), and objDef_s::weapon.

Referenced by UI_ContainerNodeMouseDown().

static void UI_ContainerNodeCapturedMouseMove ( uiNode_t node,
int  x,
int  y 
) [static]
static qboolean UI_ContainerNodeDNDEnter ( uiNode_t target  )  [static]

Call when a DND enter into the node.

Definition at line 922 of file ui_node_container.c.

References DND_ITEM, EXTRADATA, UI_DNDGetSourceNode(), UI_DNDGetType(), and UI_IsScrollContainerNode().

Referenced by UI_RegisterContainerNode().

static qboolean UI_ContainerNodeDNDFinished ( uiNode_t source,
qboolean  isDropped 
) [static]

Call into the source when the DND end.

Todo:
Is filterEquipType needed here?, we can use anyway INVSH_SearchInInventory if we disable dragInfoFromX/Y when we start DND
Todo:
We must split the move in two. Here, we should not know how to add the item to the target (see dndDrop)

Definition at line 1018 of file ui_node_container.c.

References item_s::a, CL_ActorInvMove(), CL_BattlescapeRunning(), dragInfoFromX, dragInfoFromY, dragInfoToX, dragInfoToY, EXTRADATA, EXTRADATACONST, INV_LoadWeapon(), INV_MoveItem(), INV_UnloadWeapon(), INVSH_SearchInInventory(), invList_s::item, item_s::m, uiNode_s::onChange, qfalse, qtrue, selActor, item_s::t, UI_ContainerNodeGetExistingItem(), UI_DNDGetItem(), UI_DNDGetTargetNode(), UI_ExecuteEventActions(), UI_IsScrollContainerNode(), and objDef_s::weapon.

Referenced by UI_RegisterContainerNode().

static void UI_ContainerNodeDNDLeave ( uiNode_t node  )  [static]

Call when a DND enter into the node.

Definition at line 1009 of file ui_node_container.c.

References dragInfoToX, and dragInfoToY.

Referenced by UI_RegisterContainerNode().

static qboolean UI_ContainerNodeDNDMove ( uiNode_t target,
int  x,
int  y 
) [static]

Call into the target when the DND hover it.

Returns:
True if the DND is accepted

We calculate the position of the top-left corner of the dragged item in oder to compensate for the centered-drawn cursor-item. Or to be more exact, we calculate the relative offset from the cursor location to the middle of the top-left square of the item.

See also:
UI_LeftClick

Definition at line 932 of file ui_node_container.c.

References C_UNIT, dragInfoToX, dragInfoToY, EXTRADATA, INV_DOES_NOT_FIT, INV_IsEquipDef(), INV_IsFloorDef(), INVSH_CheckToInventory(), INVSH_ExistsInInventory(), INVSH_FindSpace(), INVSH_LoadableInWeapon(), INVSH_SearchInInventory(), invList_s::item, mousePosX, mousePosY, qfalse, qtrue, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, objDef_s::sx, objDef_s::sy, item_s::t, UI_DNDGetItem(), UI_GetNodeAbsPos(), and UI_IsScrollContainerNode().

Referenced by UI_RegisterContainerNode().

static void UI_ContainerNodeDraw ( uiNode_t node  )  [static]
static void UI_ContainerNodeDrawDropPreview ( uiNode_t target  )  [static]
static void UI_ContainerNodeDrawFreeSpace ( uiNode_t node,
inventory_t 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 351 of file ui_node_container.c.

References C_UNIT, EXTRADATA, INV_FITS, INV_FITS_ONLY_ROTATED, INVSH_CheckShape(), INVSH_CheckToInventory(), INVSH_MergeShapes(), INVSH_ShapeRotate(), qfalse, qtrue, objDef_s::shape, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, uiNode_s::size, item_s::t, UI_DNDGetItem(), UI_DNDIsDragging(), UI_DNDIsSourceNode(), UI_DrawFree(), and UI_GetNodeAbsPos().

Referenced by UI_ContainerNodeDraw().

static void UI_ContainerNodeDrawGrid ( uiNode_t node,
objDef_t highlightType 
) [static]
static void UI_ContainerNodeDrawSingle ( uiNode_t node,
objDef_t highlightType 
) [static]
static void UI_ContainerNodeDrawTooltip ( uiNode_t node,
int  x,
int  y 
) [static]

Custom tooltip for container node.

Parameters:
[in] node Node we request to draw tooltip
[in] x Position x of the mouse
[in] y Position y of the mouse

Definition at line 665 of file ui_node_container.c.

References invList_s::item, MAX_VAR, Q_strcat(), UI_ContainerNodeGetItemAtPosition(), UI_DrawTooltip(), UI_GetItemTooltip(), UI_GetNodeAbsPos(), va(), invList_s::x, and invList_s::y.

Referenced by UI_RegisterContainerNode().

static invList_t* UI_ContainerNodeGetExistingItem ( const uiNode_t node,
objDef_t item,
const itemFilterTypes_t  filterType 
) [static]

Searches if there is an item at location (x/y) in a scrollable container. You can also provide an item to search for directly (x/y is ignored in that case).

Note:
x = x-th item in a row, y = row. i.e. x/y does not equal the "grid" coordinates as used in those containers.
Parameters:
[in] node Context node
[in] item Item requested
[in] filterType Filter used.
Todo:
Remove filter it is not a generic concept, and here it mean nothing
Returns:
invList_t Pointer to the invList_t/item that is located at x/y or equals "item".
See also:
INVSH_SearchInInventory

Definition at line 95 of file ui_node_container.c.

References EXTRADATACONST, INVSH_SearchInInventoryWithFilter(), and NONE.

Referenced by UI_ContainerNodeDNDFinished().

static invList_t* UI_ContainerNodeGetItemAtPosition ( const uiNode_t *const   node,
int  mouseX,
int  mouseY,
int *  contX,
int *  contY 
) [static]

Gets location of the item the mouse is over.

Parameters:
[in] node The container-node.
[in] mouseX X location of the mouse.
[in] mouseY Y location of the mouse.
[out] contX X location in the container (index of item in row).
[out] contY Y location in the container (row).
See also:
UI_ContainerNodeSearchInScrollableContainer

Definition at line 635 of file ui_node_container.c.

References C_UNIT, EXTRADATACONST, int(), INVSH_SearchInInventory(), qfalse, UI_GetNodeAbsPos(), and UI_IsScrollContainerNode().

Referenced by UI_ContainerNodeAutoPlace(), UI_ContainerNodeDrawTooltip(), and UI_ContainerNodeMouseDown().

static void UI_ContainerNodeLoaded ( uiNode_t *const   node  )  [static]

Calculates the size of a container node and links the container into the node (uses the invDef_t shape bitmask to determine the size).

Parameters:
[in,out] node The node to get the size for

Todo:
find a better way to add more equip node, without this hack

Definition at line 402 of file ui_node_container.c.

References C_UNIT, EXTRADATA, i, INVSH_GetInventoryDefinitionByID(), uiNode_s::name, name, invDef_s::shape, SHAPE_BIG_MAX_HEIGHT, SHAPE_BIG_MAX_WIDTH, uiNode_s::size, and UI_IsScrollContainerNode().

Referenced by UI_RegisterContainerNode().

static void UI_ContainerNodeLoading ( uiNode_t node  )  [static]

Definition at line 912 of file ui_node_container.c.

References uiNode_s::color, and EXTRADATA.

Referenced by UI_RegisterContainerNode().

static void UI_ContainerNodeMouseDown ( uiNode_t node,
int  x,
int  y,
int  button 
) [static]
static void UI_ContainerNodeMouseUp ( uiNode_t node,
int  x,
int  y,
int  button 
) [static]
void UI_ContainerNodeUpdateEquipment ( inventory_t inv,
equipDef_t ed 
)

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

Note:
Keep in mind that ed is changed here - so items are removed and the ground container of a inventory definition is in general a temp container - that means you should make a copy of the equipDef_t you want to add to the temp ground container of the given inv
Todo:
it's not obvious for the caller that ui_inventory pointer must be set
Parameters:
[in,out] inv The inventory to add the unused items from ed to
[in,out] ed The equipment definition to get the used items from that should be added to the ground container of inv
Todo:
dont use, and dont called by the container node; should we move it outside?

Definition at line 130 of file ui_node_container.c.

References inventoryInterface_s::AddToInventory, inventory_s::c, cls, csi, FILTER_AIRCRAFT, GAME_ItemIsUseable(), client_static_s::i, i, csi_s::idEquip, objDef_s::idx, INVDEF, INVSH_GetItemByIDX(), MAX_CONTAINERS, NONE, NONE_AMMO, equipDef_s::numItems, csi_s::numODs, and item_s::t.

Referenced by CL_UpdateEquipmentMenuParameters_f(), and MP_GetEquipment().

static void UI_ContainerNodeUpdateScroll ( uiNode_t node  )  [static]

Update display of scroll buttons.

Note:
The cvars "mn_cont_scroll_prev_hover" and "mn_cont_scroll_next_hover" are set by the "in" and "out" functions of the scroll buttons.
Parameters:
[in] node Context node

Definition at line 106 of file ui_node_container.c.

References EXTRADATA, and UI_ExecuteEventActions().

Referenced by UI_ContainerNodeAutoPlace(), and UI_ContainerNodeWheel().

static void UI_ContainerNodeWheel ( uiNode_t node,
qboolean  down,
int  x,
int  y 
) [static]
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 317 of file ui_node_container.c.

References uiIcon_s::color, uiNode_s::size, UI_DrawFill(), and UI_GetNodeAbsPos().

Referenced by UI_ContainerNodeDrawSingle().

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

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

Definition at line 329 of file ui_node_container.c.

References _, ALIGN_UL, CL_BattlescapeRunning(), uiIcon_s::color, invDef_s::in, INVDEF, invDef_s::out, qfalse, uiNode_s::size, UI_DrawFill(), UI_DrawString(), UI_GetNodeAbsPos(), and va().

Referenced by UI_ContainerNodeDrawFreeSpace().

void UI_DrawItem ( uiNode_t node,
const vec3_t  org,
const item_t item,
int  x,
int  y,
const vec3_t  scale,
const vec4_t  color 
)

Draws an item to the screen.

Parameters:
[in] node Context node
[in] org Node position on the screen (pixel). Single nodes: Use the center of the node.
[in] item The item to draw.
[in] x Position in container. Set this to -1 if it's drawn in a single container.
[in] y Position in container. Set this 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 174 of file ui_node_container.c.

References item_s::a, modelInfo_t::angles, C_UNIT, modelInfo_t::center, objDef_s::center, modelInfo_t::color, Com_Printf(), GAME_GetModelForItem(), objDef_s::id, objDef_s::image, modelInfo_t::name, modelInfo_t::origin, R_Color(), R_DrawModelDirect(), objDef_s::reload, item_s::rotated, modelInfo_t::scale, objDef_s::scale, objDef_s::sx, objDef_s::sy, item_s::t, UI_DrawModelNode(), UI_DrawNormImageByName(), Vector4Copy, VectorCopy, VectorNegate, VectorScale, and objDef_s::weapon.

Referenced by UI_BaseInventoryNodeDrawItems(), UI_ContainerNodeDrawDropPreview(), UI_ContainerNodeDrawGrid(), UI_ContainerNodeDrawSingle(), UI_DrawDragAndDrop(), and UI_ItemNodeDraw().

static void UI_GetItemTooltip ( item_t  item,
char *  tooltipText,
size_t  stringMaxLength 
) [static]

Generate tooltip text for an item.

Parameters:
[in] item The item we want to generate the tooltip text for.
[in,out] tooltipText Pointer to a string the information should be written into.
[in] stringMaxLength Max. string size of tooltipText.
Returns:
Number of lines

Definition at line 272 of file ui_node_container.c.

References _, item_s::a, item_s::amount, Com_sprintf(), GAME_ItemIsUseable(), i, item_s::m, objDef_s::name, objDef_s::numWeapons, Q_strcat(), item_s::t, va(), objDef_s::weapon, and objDef_s::weapons.

Referenced by UI_ContainerNodeDrawTooltip().

static qboolean UI_IsScrollContainerNode ( const uiNode_t *const   node  )  [inline, static]
void UI_RegisterContainerNode ( uiBehaviour_t behaviour  ) 

Variable Documentation

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

Definition at line 442 of file ui_node_container.c.

Referenced by UI_ContainerNodeDrawGrid(), and UI_ContainerNodeDrawSingle().

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

Definition at line 444 of file ui_node_container.c.

Referenced by UI_ContainerNodeDrawSingle().

const vec4_t colorDisabledHiden = {0.5, 0.5, 0.5, 0.5} [static]

Definition at line 445 of file ui_node_container.c.

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

Definition at line 446 of file ui_node_container.c.

Referenced by UI_ContainerNodeDrawSingle().

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

Definition at line 443 of file ui_node_container.c.

Referenced by UI_ContainerNodeDrawGrid(), and UI_ContainerNodeDrawSingle().

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

Make the preview item look bluish

Definition at line 447 of file ui_node_container.c.

Referenced by UI_ContainerNodeDrawDropPreview().

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 69 of file ui_node_container.c.

Referenced by UI_ContainerNodeDNDFinished(), and UI_ContainerNodeMouseDown().

int dragInfoFromY = -1 [static]

Definition at line 70 of file ui_node_container.c.

Referenced by UI_ContainerNodeDNDFinished(), and UI_ContainerNodeMouseDown().

const invList_t* dragInfoIC [static]

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

Definition at line 83 of file ui_node_container.c.

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 76 of file ui_node_container.c.

Referenced by UI_ContainerNodeDNDFinished(), UI_ContainerNodeDNDLeave(), UI_ContainerNodeDNDMove(), and UI_ContainerNodeDrawDropPreview().

int dragInfoToY = -1 [static]
int oldMouseX = 0 [static]
int oldMouseY = 0 [static]
const value_t properties[] [static]

Definition at line 1074 of file ui_node_container.c.

const vec3_t scale = {3.5, 3.5, 3.5} [static]
Todo:
need refactoring to remove, reduce use... of that var Global access to many node content like that is very bad.

Definition at line 59 of file ui_node_container.c.

Referenced by CL_ActorEquipmentSelect_f(), CL_ActorSelect(), CL_UpdateEquipmentMenuParameters_f(), MP_GetEquipment(), UI_BaseInventoryNodeDraw(), UI_ContainerNodeAutoPlace(), and UI_ContainerNodeGetExistingItem().


Generated by  doxygen 1.6.2