Files
GladiatorIdle/Mono/Arena/HubScene.Gear.cs

122 lines
6.9 KiB
C#
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Linq;
using GladiatorIdle.Gfx;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using D = GladiatorIdle.Gfx.Draw;
namespace GladiatorIdle.Arena
{
/// Ausrüstung: Inventar mit Detailkarte (anlegen, verkaufen).
internal sealed partial class HubScene
{
long? _sel; // gewähltes Stück (Inventar oder angelegt)
double _sellAllArmed; // "Alle verkaufen": zweiter Klick innerhalb von 4 s
Item? Selected => _sel is long id ? _game.Inventory.FirstOrDefault(i => i.Id == id) ?? _game.Equipped.FirstOrDefault(i => i?.Id == id) : null;
bool SelectedEquipped => _sel is long id && _game.Equipped.Any(i => i?.Id == id);
// ── Kachel und Texte ────────────────────────────────────────
void ItemTile(SpriteBatch sb, RectangleF r, Item? it, bool selected)
{
D.Rect(sb, r, new Color(24, 18, 12) * (it == null ? 0.6f : 0.95f));
var col = it == null ? D.Border : RarityColor(it.Rarity);
if (it != null && Assets.Sprite(it.Def.Icon) is Texture2D icon)
sb.Draw(icon, r.Center, null, Color.White, 0, new Vector2(icon.Width / 2f, icon.Height / 2f), r.Width * 0.82f / icon.Width, SpriteEffects.None, 0);
if (it != null && it.Level > 0)
D.Text(sb, Assets.SansBold, 14, it.Level.ToString(NumberFormat.Culture), new Vector2(r.Right - 6, r.Bottom - 12), Color.White, Align.Right);
D.Frame(sb, r, selected ? Color.White : col, selected ? 3 : 2);
}
/// Hauptwirkung in einer Zeile (Schaden ×…, Leben ×…, Block …), so wie im Slot.
string ItemMain(Item it)
{
var d = it.Def;
double lv = it.EffLevel(_game.SlotLevels[(int)it.Slot]);
var parts = new List<string>();
if (d.Slot == ItemSlot.Shield) parts.Add(string.Format(L.t("item.stat.block"), NumberFormat.Percent(0.5 * lv / (lv + 8))));
if (d.DmgK > 0) parts.Add(string.Format(L.t("item.stat.damage"), NumberFormat.Mult(Math.Pow(Items.LEVEL_GROWTH, lv * d.DmgK))));
if (d.HpK > 0) parts.Add(string.Format(L.t("item.stat.health"), NumberFormat.Mult(Math.Pow(Items.LEVEL_GROWTH, lv * d.HpK))));
return string.Join(" · ", parts); // i18n-ok
}
static IEnumerable<string> ItemAffixes(Item it) => it.Affixes.Select(a => a.Kind == Affix.Agility
? string.Format(L.t("affix.agility"), a.Value.ToString("0.#", NumberFormat.Culture))
: string.Format(L.t("affix." + a.Kind.ToString().ToLowerInvariant()), NumberFormat.Percent(a.Value)));
/// Unterschied in der Kampfkraft, wenn das Stück angelegt würde.
(string, Color) PowerDelta(Item it)
{
double now = _game.Power(), with = _game.PowerWith(it), d = with / now - 1;
if (Math.Abs(d) < 0.005) return (L.t("item.same"), D.Dim);
string pct = (d > 0 ? "+" : "−") + NumberFormat.Percent(Math.Abs(d)); // i18n-ok
return (string.Format(L.t("item.power"), pct), d > 0 ? D.Green : D.Red);
}
// ── Inventar und Detailkarte (Gladiator-Schublade, rechts) ──
void DrawInventory(SpriteBatch sb, RectangleF area)
{
const int COLS = 5;
const float CELL = 76, GAP = 8;
D.Text(sb, Assets.SansBold, 20, string.Format(L.t("char.inventory"), _game.Inventory.Count, Items.INVENTORY),
new Vector2(area.X, area.Y), D.Sand);
// Alle verkaufen (mit Sicherheits-Klick)
_sellAllArmed = Math.Max(0, _sellAllArmed - 1 / 60.0);
bool armed = _sellAllArmed > 0;
string sellText = armed ? string.Format(L.t("char.sellall.confirm"), _game.Inventory.Count)
: string.Format(L.t("char.sellall"), NumberFormat.Format(_game.InventoryValue));
if (_ui.Button(sb, new RectangleF(area.X + 170, area.Y - 18, 250, 36), sellText, _game.Inventory.Count > 0,
selected: armed, size: armed ? 13 : 15, accent: armed ? D.Red : null))
{
if (!armed) _sellAllArmed = 4;
else
{
double got = _game.SellAll();
_sellAllArmed = 0;
if (_sel is long id && !_game.Equipped.Any(i => i?.Id == id)) _sel = null;
if (got > 0) SoundManager.PlayCoins();
}
}
for (int i = 0; i < Items.INVENTORY; i++)
{
var r = new RectangleF(area.X + i % COLS * (CELL + GAP), area.Y + 26 + i / COLS * (CELL + GAP), CELL, CELL);
var it = i < _game.Inventory.Count ? _game.Inventory[i] : null;
ItemTile(sb, r, it, it != null && _sel == it.Id);
if (it != null && (_ui.Hover(r) || false) && _ui.Hit(r)) _sel = it.Id;
}
// Detailkarte
var card = new RectangleF(area.X, area.Y + 26 + 6 * (CELL + GAP) + 10, COLS * (CELL + GAP) - GAP, area.Bottom - (area.Y + 26 + 6 * (CELL + GAP) + 10));
Ui.Panel(sb, card, D.Border, 0.9f);
var sel = Selected;
if (sel == null)
{
D.Text(sb, Assets.Sans, 18, L.t("char.pick"), card.Center, D.Dim, Align.Center);
return;
}
float x = card.X + 16, y = card.Y + 22;
D.Text(sb, Assets.SansBold, 22, ItemName(sel), new Vector2(x, y), RarityColor(sel.Rarity));
D.Text(sb, Assets.Sans, 16, L.t("rarity." + sel.Rarity.ToString().ToLowerInvariant()) + " · " + L.t("slot." + sel.Slot.ToString().ToLowerInvariant()),
new Vector2(x, y + 26), D.Dim); // i18n-ok
D.Text(sb, Assets.Sans, 17, ItemMain(sel), new Vector2(x, y + 54), D.Sand);
float ay = y + 80;
foreach (var a in ItemAffixes(sel)) { D.Text(sb, Assets.Sans, 16, a, new Vector2(x, ay), D.Blue); ay += 22; }
if (SelectedEquipped)
{
D.Text(sb, Assets.SansBold, 17, L.t("char.equipped"), new Vector2(card.Right - 16, y), D.Green, Align.Right);
return;
}
var (delta, dc) = PowerDelta(sel);
D.Text(sb, Assets.SansBold, 17, delta, new Vector2(card.Right - 16, y), dc, Align.Right);
float by = card.Bottom - 54, bw = (card.Width - 44) / 2;
if (_ui.Button(sb, new RectangleF(card.X + 16, by, bw, 42), L.t("char.equip"), size: 18, accent: D.Green))
if (_game.Equip(sel.Id)) SoundManager.PlayEquip();
if (_ui.Button(sb, new RectangleF(card.X + 28 + bw, by, bw, 42), string.Format(L.t("char.sell"), NumberFormat.Format(Items.SellValue(sel))), size: 16))
if (_game.Sell(sel.Id)) { SoundManager.PlayCoins(); _sel = null; }
}
}
}