/** * @brief Draw an item node */ void uiItemNode::draw (uiNode_t* node) { const objDef_t* od; const char* ref = UI_GetReferenceString(node, EXTRADATA(node).model); vec2_t pos; if (Q_strnull(ref)) return; UI_GetNodeAbsPos(node, pos); R_CleanupDepthBuffer(pos[0], pos[1], node->box.size[0], node->box.size[1]); od = INVSH_GetItemByIDSilent(ref); if (od) { Item item(od, nullptr, 1); /* 1 so it's not reddish; fake item anyway */ const char* model = GAME_GetModelForItem(item.def(), nullptr); if (EXTRADATA(node).containerLike || Q_strnull(model)) { const vec4_t color = {1, 1, 1, 1}; vec3_t itemNodePos; /* We position the model of the item ourself (in the middle of the item * node). See the "-1, -1" parameter of UI_DrawItem. */ UI_GetNodeAbsPos(node, itemNodePos); itemNodePos[0] += node->box.size[0] / 2.0; itemNodePos[1] += node->box.size[1] / 2.0; itemNodePos[2] = 0; /** @todo we should not use DrawItem but draw the image with render function (remove dependency with container) */ UI_DrawItem(node, itemNodePos, &item, -1, -1, EXTRADATA(node).scale, color); } else { UI_DrawModelNode(node, model); } } else { GAME_DisplayItemInfo(node, ref); } }
/** * @brief Shows game type specific item information (if it's not resolvable via @c objDef_t). * @param[in] node The menu node to show the information in. * @param[in] string The id of the 'thing' to show information for. */ void GAME_DisplayItemInfo (uiNode_t *node, const char *string) { const cgame_export_t *list = GAME_GetCurrentType(); if (list != NULL && list->GetModelForItem) { const char *model = list->GetModelForItem(string); UI_DrawModelNode(node, model); } }
void uiModelNode::draw (uiNode_t* node) { const char* ref = UI_GetReferenceString(node, EXTRADATA(node).model); char source[MAX_VAR]; if (Q_strnull(ref)) source[0] = '\0'; else Q_strncpyz(source, ref, sizeof(source)); UI_DrawModelNode(node, source); }
/** * @brief Draws an item to the screen * @param[in] node Context node * @param[in] org Node position on the screen (pixel). Single nodes: Use the center of the node. * @param[in] item The item to draw. * @param[in] x Position in container. Set this to -1 if it's drawn in a single container. * @param[in] y Position in container. Set this to -1 if it's drawn in a single container. * @param[in] scale * @param[in] color * @sa 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 */ 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) { const objDef_t *od = item->item; vec4_t col; vec3_t origin; assert(od); assert(org[2] > -1000 && org[2] < 1000); /*< prevent use of vec2_t for org */ Vector4Copy(color, col); /* no ammo in this weapon - highlight this item */ if (od->weapon && od->reload && !item->ammoLeft) { col[1] *= 0.5; col[2] *= 0.5; } VectorCopy(org, origin); /* Calculate correct location of the image or the model (depends on rotation) */ /** @todo Change the rotation of the image as well, right now only the location is changed. * How is image-rotation handled right now? */ if (x >= 0 || y >= 0) { /* Add offset of location in container. */ origin[0] += x * C_UNIT; origin[1] += y * C_UNIT; /* Add offset for item-center (depends on rotation). */ if (item->rotated) { origin[0] += od->sy * C_UNIT / 2.0; origin[1] += od->sx * C_UNIT / 2.0; /** @todo Image size calculation depends on handling of image-rotation. imgWidth = od->sy * C_UNIT; imgHeight = od->sx * C_UNIT; */ } else { origin[0] += od->sx * C_UNIT / 2.0; origin[1] += od->sy * C_UNIT / 2.0; } } /* don't handle the od->tech->image here - it's very ufopedia specific in most cases */ if (od->image[0] != '\0') { const int imgWidth = od->sx * C_UNIT; const int imgHeight = od->sy * C_UNIT; origin[0] -= od->sx * C_UNIT / 2.0; origin[1] -= od->sy * C_UNIT / 2.0; /* Draw the image. */ R_Color(color); UI_DrawNormImageByName(false, origin[0], origin[1], imgWidth, imgHeight, 0, 0, 0, 0, od->image); R_Color(NULL); } else { uiModel_t *model = NULL; const char *modelName = GAME_GetModelForItem(od, &model); /* no model definition in the tech struct, not in the fallback object definition */ if (Q_strnull(modelName)) { Com_Printf("UI_DrawItem: No model given for item: '%s'\n", od->id); return; } if (model && node) { UI_DrawModelNode(node, modelName); } else { modelInfo_t mi; vec3_t angles = {-10, 160, 70}; vec3_t size = {scale[0], scale[1], scale[2]}; vec3_t center; if (item->rotated) angles[0] -= 90; if (od->scale) VectorScale(size, od->scale, size); VectorNegate(od->center, center); OBJZERO(mi); mi.origin = origin; mi.angles = angles; mi.center = center; mi.scale = size; mi.color = col; mi.name = modelName; /* draw the model */ R_DrawModelDirect(&mi, NULL, NULL); } } }