Пример #1
0
//Wyrmgus start
static void DrawUnitInfo_inventory(CUnit &unit)
{
	CUnit *uins = unit.UnitInside;
	size_t j = 0;

	for (int i = 0; i < unit.InsideCount; ++i, uins = uins->NextContained) {
		if (!uins->Type->BoolFlag[ITEM_INDEX].value || j >= UI.InventoryButtons.size()) {
			continue;
		}
		CIcon &icon = *uins->Type->Icon.Icon;
		int flag = (ButtonAreaUnderCursor == ButtonAreaInventory && static_cast<size_t>(ButtonUnderCursor) == j) ?
				   IconActive : 0;
		if (flag && ((MouseButtons & LeftButton) || (MouseButtons & RightButton))) {
			flag |= IconClicked;
		}
		flag |= IconCommandButton;
		if (unit.IsItemEquipped(uins)) {
			flag |= IconSelected;
		}
		const PixelPos pos(UI.InventoryButtons[j].X, UI.InventoryButtons[j].Y);
		uins->GetIcon().Icon->DrawUnitIcon(*UI.InventoryButtons[j].Style, flag, pos, "", unit.Player->Index);
		if (ButtonAreaUnderCursor == ButtonAreaInventory
			&& static_cast<size_t>(ButtonUnderCursor) == j) {
			//Wyrmgus start
//			UI.StatusLine.Set(uins->Type->Name);
			if (!Preference.NoStatusLineTooltips) {
				UI.StatusLine.Set(uins->GetTypeName());
			}
			//hackish way to make the popup appear correctly for the inventory item
			ButtonAction *ba = new ButtonAction;
			if (!uins->Name.empty()) {
				ba->Hint = uins->Name;
			} else {
				ba->Hint = uins->GetTypeName();
			}
			ba->Pos = j;
			ba->Level = unit.Type->ButtonLevelForInventory;
			ba->Action = ButtonUnit;
			ba->Value = UnitNumber(*uins);
			ba->Popup = "popup-item-inventory";
			DrawPopup(*ba, UI.InventoryButtons[j], UI.InventoryButtons[j].X, UI.InventoryButtons[j].Y);
			delete ba;
			LastDrawnButtonPopup = NULL;
			//Wyrmgus end
		}
		++j;
	}
}
Пример #2
0
/**
**  Draw text with variable.
**
**  @param unit         unit with variable to show.
**  @param defaultfont  default font if no specific font in extra data.
*/
/* virtual */ void CContentTypeText::Draw(const CUnit &unit, CFont *defaultfont) const
{
	std::string text;       // Optional text to display.
	int x = this->Pos.x;
	int y = this->Pos.y;
	CFont &font = this->Font ? *this->Font : *defaultfont;

	Assert(&font);
	Assert(this->Index == -1 || ((unsigned int) this->Index < UnitTypeVar.GetNumberVariable()));

	//Wyrmgus start
//	CLabel label(font);
	CLabel label(font, this->TextColor, this->HighlightColor);
	//Wyrmgus end

	if (this->Text) {
		text = EvalString(this->Text);
		std::string::size_type pos;
		if ((pos = text.find("~|")) != std::string::npos) {
			x += (label.Draw(x - font.getWidth(text.substr(0, pos)), y, text) - font.getWidth(text.substr(0, pos)));
		} else if (this->Centered) {
			x += (label.DrawCentered(x, y, text) * 2);
		} else {
			x += label.Draw(x, y, text);
		}
	}

	if (this->ShowName) {
		//Wyrmgus start
//		label.DrawCentered(x, y, unit.Type->Name);
		label.DrawCentered(x, y, unit.GetTypeName());
		//Wyrmgus end
		return;
	}

	if (this->Index != -1) {
		if (!this->Stat) {
			EnumVariable component = this->Component;
			switch (component) {
				case VariableValue:
				case VariableMax:
				case VariableIncrease:
				case VariableDiff:
				case VariablePercent:
					label.Draw(x, y, GetComponent(unit, this->Index, component, 0).i);
					break;
				case VariableName:
					label.Draw(x, y, GetComponent(unit, this->Index, component, 0).s);
					break;
				default:
					Assert(0);
			}
		} else {
			int value = unit.Type->MapDefaultStat.Variables[this->Index].Value;
			int diff = unit.Stats->Variables[this->Index].Value - value;

			if (!diff) {
				label.Draw(x, y, value);
			} else {
				char buf[64];
				snprintf(buf, sizeof(buf), diff > 0 ? "%d~<+%d~>" : "%d~<-%d~>", value, diff);
				label.Draw(x, y, buf);
			}
		}
	}
}