nodes/item_tooltip.pyΒΆ
Part of Dungeon Explorer.
1"""Item tooltip: hover panel showing item details with rarity-coloured stats."""
2
3from scripts.item import Item
4
5from simvx.core import Node2D, Vec2
6
7
8class ItemTooltip(Node2D):
9 """Floating tooltip panel for item details."""
10
11 def __init__(self, **kwargs):
12 super().__init__(name="ItemTooltip", **kwargs)
13 self._item: Item | None = None
14 self._pos = Vec2()
15 self._visible_flag = False
16
17 def show_item(self, item: Item, screen_x: float, screen_y: float) -> None:
18 self._item = item
19 self._pos = Vec2(screen_x, screen_y)
20 self._visible_flag = True
21
22 def hide(self) -> None:
23 self._visible_flag = False
24 self._item = None
25
26 def on_draw(self, renderer):
27 if not self._visible_flag or self._item is None:
28 return
29
30 item = self._item
31 x, y = float(self._pos.x), float(self._pos.y)
32 w = 220
33 line_h = 18
34
35 # Collect lines
36 lines: list[tuple[str, tuple]] = []
37 lines.append((item.display_name, item.colour))
38 lines.append((f"{item.rarity_name} {item.slot.title()}", (0.6, 0.6, 0.6, 1.0)))
39 lines.append((f"Item Level: {item.ilvl}", (0.5, 0.5, 0.5, 1.0)))
40 lines.append(("", (0, 0, 0, 0))) # Spacer
41
42 # Base stats
43 for key, val in item.base_stats.items():
44 if isinstance(val, float) and val < 1:
45 lines.append((f" {key.replace('_', ' ').title()}: {val:.0%}", (0.8, 0.8, 0.8, 1.0)))
46 else:
47 lines.append((f" {key.replace('_', ' ').title()}: {int(val)}", (0.8, 0.8, 0.8, 1.0)))
48
49 # Affixes
50 for affix in item.prefixes + item.suffixes:
51 lines.append((f" {affix.display_text()}", (0.4, 0.9, 0.4, 1.0)))
52
53 h = len(lines) * line_h + 16
54
55 # Clamp to screen
56 if x + w > 1280:
57 x = x - w - 10
58 if y + h > 720:
59 y = 720 - h
60
61 # Background
62 renderer.draw_rect((x, y), (w, h), colour=(0.08, 0.08, 0.12, 0.95), filled=True)
63 renderer.draw_rect((x, y), (w, 2), colour=item.colour, filled=True)
64
65 # Text
66 ty = y + 8
67 for text, colour in lines:
68 if text:
69 renderer.draw_text(text, (x + 8, ty), scale=0.9, colour=colour)
70 ty += line_h