28 #include "../ui_main.h"
29 #include "../ui_parse.h"
30 #include "../ui_behaviour.h"
31 #include "../ui_actions.h"
32 #include "../ui_dragndrop.h"
33 #include "../ui_tooltip.h"
34 #include "../ui_nodes.h"
35 #include "../ui_input.h"
36 #include "../ui_render.h"
37 #include "../ui_lua.h"
45 #include "../../cl_shared.h"
46 #include "../../cgame/cl_game.h"
47 #include "../../input/cl_keys.h"
48 #include "../../cl_inventory.h"
50 #include "../../../common/scripts_lua.h"
52 #define EXTRADATA_TYPE baseInventoryExtraData_t
53 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
54 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
85 Com_Printf(
"ERROR: UI Inventory is not initialized in UI_ContainerNodeGetExistingItem!\n");
94 #define CII_AMMOONLY 0x01
95 #define CII_WEAPONONLY 0x02
96 #define CII_AVAILABLEONLY 0x04
97 #define CII_NOTAVAILABLEONLY 0x08
98 #define CII_IMPLANTONLY 0x10
137 const bool isArmour = obj->
isArmour();
139 const bool isWeapon = obj->
weapon || obj->
isMisc || isArmour;
140 const bool isImplant = obj->
implant;
179 iterator->
node = node;
223 else if (
EXTRADATA(node).lua_onViewChange != LUA_NOREF) {
251 bool outOfNode =
false;
257 int currentHeight = 0;
262 const int id = iterator.
itemID;
264 Item tempItem(obj,
nullptr, 1);
268 bool isHighlight =
false;
270 const int col = items %
EXTRADATA(node).columns;
275 if (outOfNode || currentHeight <
EXTRADATA(node).scrollY.viewPos) {
278 cellWidth - 5,
LONGLINES_WRAP,
nullptr, &height,
nullptr,
nullptr);
280 if (height > rowHeight)
283 if (outOfNode || currentHeight + rowHeight <
EXTRADATA(node).scrollY.viewPos) {
284 if (col ==
EXTRADATA(node).columns - 1) {
285 currentHeight += rowHeight;
294 pos[0] += cellWidth * col;
295 pos[1] += currentHeight -
EXTRADATA(node).scrollY.viewPos;
305 if (icItem !=
nullptr) {
328 pos[0] + obj->
sx *
C_UNIT / 2.0, cellWidth - 5,
329 0,
va(
"x%i", amount));
337 ammopos[0] += obj->
sx *
C_UNIT + 10;
342 pos[0], cellWidth - 5,
347 for (
int ammoIdx = 0; ammoIdx < obj->
numAmmos; ammoIdx++) {
351 if (obj == tempItem.
def())
369 ammopos[0] + icItem->
def()->
sx *
C_UNIT / 2.0, cellWidth - 5 - ammopos[0],
377 if (cellHeight > rowHeight) {
378 rowHeight = cellHeight;
382 if (col ==
EXTRADATA(node).columns - 1) {
383 currentHeight += rowHeight;
393 if (rowHeight != 0) {
394 currentHeight += rowHeight;
396 return currentHeight;
404 bool updateScroll =
false;
405 int visibleHeight = 0;
415 visibleHeight = node->
box.
size[1];
421 0,
va(
"%i %i/%i",
EXTRADATA(node).scrollCur, visibleRows, totalRows), 0, 0,
nullptr,
false, 0);
425 if (visibleHeight !=
EXTRADATA(node).scrollY.viewSize || needHeight !=
EXTRADATA(node).scrollY.fullSize) {
426 EXTRADATA(node).scrollY.fullSize = needHeight;
427 EXTRADATA(node).scrollY.viewSize = visibleHeight;
430 if (
EXTRADATA(node).scrollY.viewPos > needHeight - visibleHeight) {
431 EXTRADATA(node).scrollY.viewPos = needHeight - visibleHeight;
434 if (
EXTRADATA(node).scrollY.viewPos < 0) {
445 EXTRADATA(node).lua_onViewChange = LUA_NOREF;
453 const objDef_t* highlightType =
nullptr;
460 if (node->
color[3] < 0.001)
476 bool outOfNode =
false;
483 int currentHeight = 0;
494 const int id = iterator.
itemID;
504 if (outOfNode || currentHeight <
EXTRADATACONST(node).scrollY.viewPos) {
507 cellWidth - 5,
LONGLINES_WRAP,
nullptr, &outHeight,
nullptr,
nullptr);
509 if (outHeight > rowHeight)
510 rowHeight = outHeight;
512 if (outOfNode || currentHeight + rowHeight <
EXTRADATACONST(node).scrollY.viewPos) {
514 currentHeight += rowHeight;
523 pos[0] += cellWidth * col;
529 if (mouseX >= pos[0] && mouseX < pos[0] + obj->
sx *
C_UNIT
530 && mouseY >= pos[1] && mouseY < pos[1] + obj->
sy *
C_UNIT) {
532 *contX = icItem->
getX();
533 *contY = icItem->
getY();
543 ammopos[0] += obj->
sx *
C_UNIT + 10;
547 cellWidth - 5,
LONGLINES_WRAP,
nullptr, &height,
nullptr,
nullptr);
548 cellHeight += height;
552 for (
int ammoIdx = 0; ammoIdx < obj->
numAmmos; ammoIdx++) {
565 if (mouseX < ammopos[0] || mouseY >= ammopos[1])
567 if (mouseX >= ammopos[0] && mouseX < ammopos[0] + objammo->
sx *
C_UNIT
568 && mouseY >= ammopos[1] - objammo->
sy *
C_UNIT && mouseY < ammopos[1]) {
569 *contX = icItem->
getX();
570 *contY = icItem->
getY();
578 if (cellHeight > rowHeight) {
579 rowHeight = cellHeight;
584 currentHeight += rowHeight;
611 static char tooltiptext[
MAX_VAR * 2];
612 const int itemToolTipWidth = 250;
618 Q_strcat(tooltiptext,
sizeof(tooltiptext),
"\n%i/%i", itemHover->
getX(), itemHover->
getY());
639 const int sel = cl_selected->
integer;
647 Com_DPrintf(
DEBUG_CLIENT,
"UI_ContainerNodeAutoPlace: item %i/%i selected from scrollable container.\n", fromX, fromY);
686 if (
EXTRADATA(node).super.lua_onSelect != LUA_NOREF) {
722 if (
EXTRADATA(node).scrollY.moveDelta(deltaY * 20)) {
731 EXTRADATA(node).super.container =
nullptr;
733 node->
color[3] = 1.0;
742 if (
EXTRADATA(target).super.container ==
nullptr)
773 behaviour->
name =
"baseinventory";
774 behaviour->
extends =
"container";
itemFilterTypes_t filterEquipType
#define EXTRADATACONST(node)
static const Item * dragInfoIC
int UI_DNDGetType(void)
Return the current type of the dragging object, else DND_NOTHING.
void UI_PopClipRect(void)
void initNode(uiNode_t *node) override
bool INV_ItemMatchesFilter(const objDef_t *obj, const itemFilterTypes_t filterType)
Checks if the given object/item matched the given filter type.
static Item * UI_ContainerNodeGetExistingItem(const uiNode_t *node, const 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 ite...
Item * UI_DNDGetItem(void)
const char * va(const char *format,...)
does a varargs printf into a temp buffer, so I don't need to have varargs versions of all text functi...
int R_FontDrawString(const char *fontId, align_t align, int x, int y, int absX, int maxWidth, int lineHeight, const char *c, int boxHeight, int scrollPos, int *curLine, longlines_t method)
static const vec3_t scale
This is a cvar definition. Cvars can be user modified and used in our menus e.g.
void draw(uiNode_t *node) override
Main function to draw a container node.
static void UI_ContainerItemIteratorInit(containerItemIterator_t *iterator, const uiNode_t *const node)
Use a container node to init an item iterator.
void UI_DNDDragItem(uiNode_t *node, const Item *item)
Start to drag an item.
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.
void UI_DNDAbort(void)
Drop the object at the current position.
static const vec4_t colorDefault
void onCapturedMouseMove(uiNode_t *node, int x, int y) override
#define CII_AMMOONLY
Flag for containerItemIterator_t (CII) groupSteps.
void onMouseDown(uiNode_t *node, int x, int y, int button) override
itemFilterTypes_t
A list of filter types in the market and production view.
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
const objDef_t * def(void) const
void initNode(uiNode_t *node) override
void onLoading(uiNode_t *node) override
void Com_Printf(const char *const fmt,...)
void setDef(const objDef_t *objDef)
const struct objDef_s * ammos[MAX_AMMOS_PER_OBJDEF]
Defines all attributes of objects used in the inventory.
void onWindowOpened(uiNode_t *node, linkedList_t *params) override
Call when we open the window containing the node.
static const vec4_t colorDisabledHiden
#define CII_NOTAVAILABLEONLY
uiNode_t * UI_DNDGetSourceNode(void)
Return source of the DND.
#define UI_RegisterExtradataNodeProperty(BEHAVIOUR, NAME, TYPE, EXTRADATATYPE, ATTRIBUTE)
Initialize a property from extradata of node.
item instance data, with linked list capability
void onMouseUp(uiNode_t *node, int x, int y, int button) override
void R_FontTextSize(const char *fontId, const char *text, int maxWidth, longlines_t method, int *width, int *height, int *lines, bool *isTruncated)
Supply information about the size of the text when it is linewrapped and rendered, without actually rendering it. Any of the output parameters may be nullptr.
#define C_UNIT
One unit in the containers is 25x25.
SharedPtr< uiNode > UINodePtr
const invDef_t * INVSH_GetInventoryDefinitionByID(const char *id)
void onDndLeave(uiNode_t *node) override
Call when a DND enter into the node.
static void UI_ContainerItemIteratorNext(containerItemIterator_t *iterator)
Compute the next itemID.
bool onScroll(uiNode_t *node, int deltaX, int deltaY) override
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
void Com_DPrintf(int level, const char *fmt,...)
A Com_Printf that only shows up if the "developer" cvar is set.
static const vec4_t colorDisabledLoadable
bool CL_BattlescapeRunning(void)
Check whether we already have actors spawned on the battlefield.
Atomic structure used to define most of the UI.
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 Com_RegisterConstInt(const char *name, int value)
Register mappings between script strings and enum values for values of the type V_INT.
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
bool onDndEnter(uiNode_t *node) override
Call when a DND enter into the node.
void UI_ContainerNodeAutoPlaceItem(uiNode_t *node, Item *ic)
Try to autoplace an item from a container.
bool isLoadableInWeapon(const objDef_s *weapon) const
Checks if an item can be used to reload a weapon.
void onLoaded(uiNode_t *node) override
Calculates the size of a container node and links the container into the node (uses the invDef_t shap...
static const vec4_t colorLoadable
void UI_GetItemTooltip(const Item &item, char *tooltipText, size_t stringMaxLength)
Generate tooltip text for an item.
void UI_RegisterBaseInventoryNode(uiBehaviour_t *behaviour)
node behaviour, how a node work
#define CII_AVAILABLEONLY
bool onDndMove(uiNode_t *node, int x, int y) override
Call into the target when the DND hover it.
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
#define Vector2Copy(src, dest)
void UI_PushClipRect(int x, int y, int width, int height)
const objDef_t * INVSH_GetItemByIDX(int index)
Returns the item that belongs to the given index or nullptr if the index is invalid.
int UI_DrawString(const char *fontID, align_t align, int x, int y, int absX, int maxWidth, int lineHeight, const char *c, int boxHeight, int scrollPos, int *curLine, bool increaseLine, longlines_t method)
static Item * UI_BaseInventoryNodeGetItem(const uiNode_t *const node, int mouseX, int mouseY, int *contX, int *contY)
static void UI_BaseInventoryNodeUpdateScroll(uiNode_t *node)
Update display of scroll buttons.
bool GAME_ItemIsUseable(const objDef_t *od)
bool UI_DNDIsDragging(void)
Return true if we are dragging something.
static void UI_BaseInventoryNodeDraw2(uiNode_t *node, const objDef_t *highlightType)
Draw the inventory of the base.
Item * INV_SearchInInventoryWithFilter(const Inventory *const inv, const invDef_t *container, const objDef_t *itemType, const itemFilterTypes_t filterType)
Searches if there is an item at location (x/y) in a scrollable container. You can also provide an ite...
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_DNDDrop(void)
Drop the object at the current position.
void drawTooltip(const uiNode_t *node, int x, int y) const override
Custom tooltip for container node.
void UI_GetNodeScreenPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node in the screen. Screen position is not used for the node rende...
static int UI_BaseInventoryNodeDrawItems(uiNode_t *node, const objDef_t *highlightType)
Draw the base inventory.