P1 iron: nuggets, ore, clay, kiln, smelter, forge, iron tools and arrows, lantern, tool wear and repair

This commit is contained in:
Paul Bailey
2026-11-05 00:31:07 +00:00
parent ab1f417c32
commit 24c280d885
24 changed files with 1334 additions and 43 deletions

View File

@@ -13,6 +13,8 @@ var _key: Label
var _style: StyleBoxFlat
var _selected_style: StyleBoxFlat
var _stack = null
var _wear: ColorRect
var _wear_fill: ColorRect
func _init(i: int = 0, size_px: int = 64, key_label: String = "") -> void:
index = i
@@ -44,17 +46,44 @@ func _init(i: int = 0, size_px: int = 64, key_label: String = "") -> void:
_key.mouse_filter = Control.MOUSE_FILTER_IGNORE
add_child(_key)
_wear = ColorRect.new()
_wear.color = Color(0, 0, 0, 0.6)
_wear.set_anchors_and_offsets_preset(Control.PRESET_BOTTOM_WIDE)
_wear.offset_left = 6
_wear.offset_right = -6
_wear.offset_top = -9
_wear.offset_bottom = -5
_wear.mouse_filter = Control.MOUSE_FILTER_IGNORE
_wear.visible = false
add_child(_wear)
_wear_fill = ColorRect.new()
_wear_fill.anchor_bottom = 1.0
_wear_fill.mouse_filter = Control.MOUSE_FILTER_IGNORE
_wear.add_child(_wear_fill)
func set_stack(stack) -> void:
_stack = stack
if stack == null:
_icon.texture = null
_count.text = ""
tooltip_text = ""
_wear.visible = false
return
_icon.texture = ItemDB.icon(stack.id)
_count.text = str(stack.count) if stack.count > 1 else ""
var def := ItemDB.get_item(stack.id)
tooltip_text = "%s\n%s" % [def.get("name", stack.id), def.get("description", "")]
# Wear: a bar along the bottom once a tool or weapon has been used.
var full := ItemDB.max_durability(stack.id)
var left := ItemDB.durability(stack)
if full > 0 and left < full:
var k := float(left) / full
_wear.visible = true
_wear_fill.anchor_right = k
_wear_fill.color = Color(0.85, 0.25, 0.2) if k < 0.2 else (Color(0.9, 0.75, 0.25) if k < 0.5 else Color(0.45, 0.8, 0.35))
tooltip_text += "\n%d of %d uses left" % [left, full]
else:
_wear.visible = false
func set_selected(on: bool) -> void:
add_theme_stylebox_override("panel", _selected_style if on else _style)