34 #include "../ui_main.h"
35 #include "../ui_parse.h"
36 #include "../ui_behaviour.h"
37 #include "../ui_actions.h"
38 #include "../ui_dragndrop.h"
39 #include "../ui_tooltip.h"
40 #include "../ui_nodes.h"
41 #include "../ui_input.h"
42 #include "../ui_render.h"
43 #include "../ui_lua.h"
49 #include "../../client.h"
50 #include "../../renderer/r_draw.h"
51 #include "../../renderer/r_mesh.h"
52 #include "../../cgame/cl_game.h"
53 #include "../../battlescape/cl_actor.h"
54 #include "../../cl_inventory.h"
56 #include "../../../common/scripts_lua.h"
64 #define EXTRADATA_TYPE containerExtraData_t
65 #define EXTRADATA(node) UI_EXTRADATA(node, EXTRADATA_TYPE)
66 #define EXTRADATACONST(node) UI_EXTRADATACONST(node, EXTRADATA_TYPE)
119 while (numItems[
i]) {
125 numItems[item.
def()->
idx]--;
156 assert(org[2] > -1000 && org[2] < 1000);
170 if (x >= 0 || y >= 0) {
177 origin[0] += od->
sy * C_UNIT / 2.0;
178 origin[1] += od->
sx * C_UNIT / 2.0;
184 origin[0] += od->
sx * C_UNIT / 2.0;
185 origin[1] += od->
sy * C_UNIT / 2.0;
190 if (od->
image[0] !=
'\0') {
191 const int imgWidth = od->
sx *
C_UNIT;
192 const int imgHeight = od->
sy *
C_UNIT;
206 Com_Printf(
"UI_DrawItem: No model given for item: '%s'\n", od->
id);
214 vec3_t angles = {-10, 160, 70};
274 Q_strcat(tooltipText, stringMaxLength,
_(
"Usable in:\n"));
278 Q_strcat(tooltipText, stringMaxLength,
"* %s\n",
_(weapon->
name));
294 return containerNode;
302 const vec4_t color = { 0.3f, 0.3f, 0.3f, 0.7f };
314 const vec4_t color = { 0.0f, 1.0f, 0.0f, 0.7f };
325 nodepos[0] + 3, node->
box.
size[0] - 6, 0,
326 va(
_(
"In: %i Out: %i"), inv->
in, inv->
out));
395 if (container ==
nullptr)
407 if (container->
shape[j] & (1 << i))
409 if (j < SHAPE_BIG_MAX_HEIGHT)
416 if (container->
shape[i] & ~0x0)
441 pos[0] += node->
box.
size[0] / 2.0;
442 pos[1] += node->
box.
size[1] / 2.0;
463 bool disabled =
false;
510 Item* item =
nullptr;
559 if (
EXTRADATA(target).container->single) {
560 origine[0] += target->
box.
size[0] / 2.0;
561 origine[1] += target->
box.
size[1] / 2.0;
568 origine[1] += (dragInfoToY + previewItem.
def()->
sx / 2.0) *
C_UNIT;
571 origine[1] += (dragInfoToY + previewItem.
def()->
sy / 2.0) *
C_UNIT;
583 const objDef_t* highlightType =
nullptr;
590 if (node->
color[3] < 0.001)
632 Sys_Error(
"UI_ContainerNodeGetItemAtPosition is not usable for scrollable containers!");
638 const int fromX = (
int) (mouseX - nodepos[0]) /
C_UNIT;
639 const int fromY = (
int) (mouseY - nodepos[1]) /
C_UNIT;
660 static char tooltiptext[
MAX_VAR * 2];
661 const int itemToolTipWidth = 250;
667 Q_strcat(tooltiptext,
sizeof(tooltiptext),
"\n%i/%i", itemHover->
getX(), itemHover->
getY());
677 ui_inventory->
findSpace(target, ic, &px, &py,
nullptr);
678 return INV_MoveItem(ui_inventory, target, px, py, container, ic, icp);
690 bool ammoChanged =
false;
700 if (!ammoChanged && !ic->
ammoDef()) {
716 for (
int i = 0;
i <
size;
i++) {
717 target = idxArray[
i];
733 Item* tItem =
nullptr;
734 for (
int i = 0;
i <
size;
i++) {
735 target = idxArray[
i];
753 if (
EXTRADATA(node).lua_onSelect != LUA_NOREF) {
764 if (targetNode !=
nullptr && node != targetNode) {
774 if (ic->
def()->
isAmmo() || ammoChanged) {
777 if (ammoNode !=
nullptr && node != ammoNode) {
846 if (
EXTRADATA(node).lua_onSelect != LUA_NOREF) {
880 EXTRADATA(node).lua_onSelect = LUA_NOREF;
886 node->
color[3] = 1.0;
921 if (dragItem->
def()) {
943 if (!exists && dragItem->
def() && (containerType->
single
971 if (containerType->
single)
999 assert(sourceContainer);
1005 assert(targetContainer);
1015 assert(targetContainer);
1029 const bool rotated = fItem->
rotated;
1046 INV_LoadWeapon(tItem, ui_inventory, sourceContainer, targetContainer);
1056 if (source != target) {
1074 behaviour->
name =
"container";
#define EXTRADATACONST(node)
bool Q_strnull(const char *string)
void onCapturedMouseMove(uiNode_t *node, int x, int y) override
static void UI_ContainerNodeDrawFreeSpace(uiNode_t *node, Inventory *inv)
Draws the free and usable inventory positions when dragging an item.
#define SHAPE_BIG_MAX_HEIGHT
defines the max height of an inventory container
#define VectorCopy(src, dest)
int UI_DNDGetType(void)
Return the current type of the dragging object, else DND_NOTHING.
uiNode_t * UI_DNDGetTargetNode(void)
Return target of the DND.
void Sys_Error(const char *error,...)
void CL_ActorInvMove(const le_t *le, containerIndex_t fromContainer, int fromX, int fromY, containerIndex_t toContainer, int toX, int toY)
Sends an inventory move event to the server.
void initNode(uiNode_t *node) override
void onDndLeave(uiNode_t *node) override
Call when a DND enter into the node.
static const vec4_t colorDisabledLoadable
static const vec4_t colorDisabled
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...
struct uiAction_s * onChange
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_DNDDragItem(uiNode_t *node, const Item *item)
Start to drag an item.
Item * getContainer2(const containerIndex_t idx) const
bool Com_sprintf(char *dest, size_t size, const char *fmt,...)
copies formatted string with buffer-size checking
void UI_DrawModelNode(uiNode_t *node, const char *source)
void UI_DNDAbort(void)
Drop the object at the current position.
#define VectorNegate(src, dest)
void drawTooltip(const uiNode_t *node, int x, int y) const override
Custom tooltip for container node.
Item * getLeftHandContainer() const
bool isRightDef() const
Checks whether the inventory definition is the right Hand.
bool UI_ExecuteLuaEventScript(uiNode_t *node, LUA_EVENT event)
Executes a lua event handler.
const objDef_t * def(void) const
bool onDndEnter(uiNode_t *node) override
Call when a DND enter into the node.
void onMouseDown(uiNode_t *node, int x, int y, int button) override
bool isLeftDef() const
Checks whether a given inventory definition is of special type.
static const Item * dragInfoIC
static uiNode_t * targetNode
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...
typedef int(ZCALLBACK *close_file_func) OF((voidpf opaque
void Com_Printf(const char *const fmt,...)
Defines all attributes of objects used in the inventory.
#define VectorScale(in, scale, out)
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.
void R_Color(const vec4_t rgba)
Change the color to given value.
void R_DrawModelDirect(modelInfo_t *mi, modelInfo_t *pmi, const char *tagname)
Draws a model in 2d mode (for rendering model data from the ui)
bool containsItem(const containerIndex_t contId, const Item *const item) const
Searches if there is a specific item already in the inventory&container.
item instance data, with linked list capability
inventory definition with all its containers
void INVSH_MergeShapes(uint32_t *shape, const uint32_t itemShape, const int x, const int y)
Will merge the second shape (=itemShape) into the first one (=big container shape) on the position x/...
const char * GAME_GetModelForItem(const objDef_t *od, uiModel_t **uiModel)
Get a model for an item.
#define C_UNIT
One unit in the containers is 25x25.
const image_t * UI_DrawNormImageByName(bool flip, float x, float y, float w, float h, float sh, float th, float sl, float tl, const char *name)
Draws an image or parts of it.
#define SHAPE_BIG_MAX_WIDTH
32 bit mask
void findSpace(const invDef_t *container, const Item *item, int *const px, int *const py, const Item *ignoredItem) const
Finds space for item in inv at container.
Item * getRightHandContainer() const
static const vec4_t colorLoadable
uiNode_t * UI_GetContainerNodeByContainerIDX(const uiNode_t *const parent, const int index)
Search a child container node by the given container id.
SharedPtr< uiNode > UINodePtr
const invDef_t * INVSH_GetInventoryDefinitionByID(const char *id)
char const * Q_strstart(char const *str, char const *start)
Matches the start of a string.
bool UI_DNDIsTargetNode(uiNode_t *node)
Return true if the requested node is the current target of the DND.
int canHoldItem(const invDef_t *container, const objDef_t *od, const int x, const int y, const Item *ignoredItem) const
uint32_t getShapeRotated() const
Rotates a shape definition 90 degree to the left (CCW)
void UI_ExecuteEventActions(uiNode_t *source, const uiAction_t *firstAction)
#define INVDEF(containerID)
Item * getEquipContainer() const
Item * getNextItem(const Item *prev) const
Atomic structure used to define most of the UI.
bool INV_MoveItem(Inventory *inv, const invDef_t *toContainer, int toX, int toY, const invDef_t *fromContainer, Item *fItem, Item **uponItem)
Move item between containers.
void * UI_SWIG_TypeQuery(const char *name)
This function queries the SWIG type table for a type information structure. It is used in combination...
bool CL_BattlescapeRunning(void)
Check whether we already have actors spawned on the battlefield.
void UI_GetNodeAbsPos(const uiNode_t *node, vec2_t pos)
Returns the absolute position of a node.
static Item * UI_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.
static const vec3_t scale
const Container & getContainer(const containerIndex_t idx) const
void UI_ContainerNodeAutoPlaceItem(uiNode_t *node, Item *ic)
Try to autoplace an item from a container.
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) ...
uint32_t shape[SHAPE_BIG_MAX_HEIGHT]
bool isFloorDef() const
Checks whether the inventory definition is the floor.
bool isLoadableInWeapon(const objDef_s *weapon) const
Checks if an item can be used to reload a weapon.
static const vec4_t colorPreview
Item * addToInventory(Inventory *const inv, const Item *const item, const invDef_t *container, int x, int y, int amount) __attribute__((warn_unused_result))
Add an item to a specified container in a given inventory.
bool Key_IsDown(unsigned int key)
Checks whether a given key is currently pressed.
static void UI_ContainerNodeDrawSingle(uiNode_t *node, const objDef_t *highlightType)
Draw a container which only contains one item.
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...
virtual void initNode(uiNode_t *node)
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) ...
void UI_GetItemTooltip(const Item &item, char *tooltipText, size_t stringMaxLength)
Generate tooltip text for an item.
static bool UI_IsScrollContainerNode(const uiNode_t *const node)
uiNode_t * UI_GetNode(const uiNode_t *node, const char *name)
Search a child node by given name.
node behaviour, how a node work
bool onDndMove(uiNode_t *node, int x, int y) override
Call into the target when the DND hover it.
int numItems[MAX_OBJDEFS]
void UI_RegisterContainerNode(uiBehaviour_t *behaviour)
QGL_EXTERN GLuint GLsizei GLsizei GLint GLenum GLchar * name
void onMouseUp(uiNode_t *node, int x, int y, int button) override
Item * getItemAtPos(const invDef_t *container, const int x, const int y) const
Searches if there is an item at location (x,y) in a container.
bool UI_DNDIsSourceNode(uiNode_t *node)
Return true if the requested node is the source of the DND.
void Q_strcat(char *dest, size_t destsize, const char *format,...)
Safely (without overflowing the destination buffer) concatenates two strings.
static const vec4_t colorDefault
bool isHeldTwoHanded() const
const objDef_t * ammoDef(void) const
inventory definition for our menus
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)
bool INVSH_CheckShape(const uint32_t *shape, const int x, const int y)
Checks the shape if there is a 1-bit on the position x/y.
bool isEquipDef() const
Checks whether a given inventory definition is of special type.
void onLoading(uiNode_t *node) override
bool GAME_ItemIsUseable(const objDef_t *od)
void UI_DrawFill(int x, int y, int w, int h, const vec4_t color)
Fills a box of pixels with a single color.
Model that have more than one part (top and down part of an aircraft)
bool UI_DNDIsDragging(void)
Return true if we are dragging something.
bool INV_LoadWeapon(const Item *weaponList, Inventory *inv, const invDef_t *srcContainer, const invDef_t *destContainer)
Load a weapon with ammo.
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...
static void UI_ContainerNodeDrawGrid(uiNode_t *node, const objDef_t *highlightType)
Draw a grip container.
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.
#define Mem_Dup(type, in, n)
#define Vector4Copy(src, dest)
static void UI_ContainerNodeDrawDropPreview(uiNode_t *target)
Draw a preview of the DND item dropped into the node.
void UI_DNDDrop(void)
Drop the object at the current position.
bool INV_UnloadWeapon(Item *weapon, Inventory *inv, const invDef_t *container)
Unload a weapon and put the ammo in a container.
static bool UI_ContainerNodeAddItem(const invDef_t *container, Item *ic, containerIndex_t containerID, Item **icp)
void setContainer(const containerIndex_t idx, Item *cont)
const struct objDef_s * weapons[MAX_WEAPONS_PER_OBJDEF]
void draw(uiNode_t *node) override
Main function to draw a container node.
bool onDndFinished(uiNode_t *node, bool isDroped) override
Call into the source when the DND end.