extends RefCounted ## Blacksmith / Refine window v2 (Boss 2026-10-17, docs/research/LORDNINE_REFINE_CRAFT.md 4.3; rules scripts/refine.gd, ## CharacterState.refine_item / repair_item). Fills hud.bodies["refine"] (the painted v4 window hud.gd builds): ## left - every worn / bag piece that can be refined: icon, +level, forge heat, cracked mark; click = select ## right - the selected piece: current -> next level + risk zone, the stat change, the anvil (hammer / result ## animation), the EXACT odds (success / no change / drop a level / crack / +2), the forge-heat bar, the ## helper check boxes (Sparkle Ore, Blessing Water, Steady Powder, Crackward Charm), the cost, Refine / Repair ## bottom - Purify Rough Ores + the failure rules in one line. ## Text: English keys translated through MsgTh (data/i18n_th.json whole texts, data/msg_th.json formats). ## Animation: press -> ~0.9 s of hammer strikes (click the anvil to skip) -> the command -> the result burst ## (gold / rainbow +2 / grey smoke / shaking drop / crack lines / repair glow) + sound (Sfx message hooks) + 3D fx. ## The state lives in static vars so the window can be rebuilt (hud dirty) mid-animation. const Refine = preload("res://scripts/refine.gd") const UiSkin = preload("res://scripts/ui/ui_skin.gd") const MsgTh = preload("res://scripts/ui/msg_th.gd") const Icons = preload("res://scripts/icons.gd") const ItemSlot = preload("res://scripts/item_slot.gd") const Fx = preload("res://scripts/fx.gd") const INK := Color("#4a3320") const INK_SOFT := Color("#86694a") const GOOD := Color("#2f7a3a") const BAD := Color("#b3261e") const ZONE_COL := {"safe": Color("#3f9a45"), "keep": Color("#d39a12"), "down": Color("#e06a1c"), "crack": Color("#c8321e")} const ZONE_NAME := {"safe": "Safe", "keep": "Low risk", "down": "Medium risk", "crack": "High risk"} const HELP_ICON := {"sparkle": "sparkle_ore", "bless": "blessing_water", "hold": "steady_powder", "ward": "crackward_charm"} const HELP_TEXT := {"sparkle": "%d%% of successes jump +2 (up to +%d)", "bless": "+%d%% success chance", "hold": "a failure does not drop a level", "ward": "a failure does not crack the piece"} ## Hammer strikes before the command goes out (seconds) and the result burst. const STRIKE_S := 0.9 const RESULT_S := 1.7 ## uid of the selected piece (0 = the first one) static var sel_uid := 0 ## helper check boxes: key -> on static var want := {} ## "Do not ask again" for orange / red tries (this session) static var no_ask := false ## the animation: {"phase": "idle"|"strike"|, "t0": msec, "id": item id, "from": lv, "to": lv} static var anim := {"phase": "idle", "t0": 0} ## screenshots / tests: a fixed animation progress 0..1 (< 0 = live) static var freeze_t := -1.0 ## the try waiting for the end of the hammer strikes static var _pending := {} static func T(s: String) -> String: return MsgTh.tr_msg(s) static func th() -> bool: return MsgTh.active() static func _ps(): return PlayerState static func selected(hud) -> Dictionary: var items: Array = _ps().refinable_items() for inst in items: if _ps().uid_of(inst) == sel_uid: return inst if items.is_empty(): return {} sel_uid = _ps().uid_of(items[0]) return items[0] static func select(hud, inst: Dictionary) -> void: sel_uid = _ps().uid_of(inst) hud.refine_msg = "" hud.dirty = true static func use_list() -> Array: var out: Array = [] for k in Refine.HELPERS: if bool(want.get(k, false)): out.append(k) return out # ---------------------------------------------------------------- building static func fill(hud) -> void: var body: VBoxContainer = hud.bodies["refine"] hud._clear(body) var ps = _ps() var hint := UiSkin.label(T("Pick a piece on the left. Every chance shown is exact - nothing is hidden."), 14, INK_SOFT, "Regular") hint.name = "RefineHint" body.add_child(hint) var cols := HBoxContainer.new() cols.name = "RefineCols" cols.add_theme_constant_override("separation", 12) body.add_child(cols) _left(hud, cols) var inst := selected(hud) var right := VBoxContainer.new() right.name = "RefineRight" right.add_theme_constant_override("separation", 8) right.custom_minimum_size = Vector2(560, 0) right.size_flags_horizontal = Control.SIZE_EXPAND_FILL cols.add_child(right) if inst.is_empty(): right.add_child(UiSkin.label(T("You have nothing that can be refined."), 16, INK_SOFT, "SemiBold")) else: _detail(hud, right, inst) # purify + the rules var foot := PanelContainer.new() foot.name = "RefineFoot" foot.add_theme_stylebox_override("panel", UiSkin.inset(8.0, 1)) body.add_child(foot) var fv := VBoxContainer.new() fv.add_theme_constant_override("separation", 4) foot.add_child(fv) for ore in Refine.purify_list(): var pf: Dictionary = Refine.purify_list()[ore] var pr: HBoxContainer = hud._row(fv) pr.add_child(hud._shop_icon(str(pf["from"]), ps.count(str(pf["from"])))) pr.add_child(hud._grow(UiSkin.label(T("Purify %d %s -> 1 %s (have %d)" % [int(pf["count"]), GameData.item_name(str(pf["from"])), GameData.item_name(str(ore)), ps.count(str(pf["from"]))]), 14, INK, "Regular"))) var perr: String = ps.purify_check(str(ore)) var pb: Button = hud._button(T("Purify"), hud._on_purify.bind(str(ore)), perr != "", T(perr), "alt") pb.name = "Purify_" + str(ore) pr.add_child(pb) var rules := UiSkin.label(T("A failed refine never destroys anything: up to +8 nothing changes, +9 .. +12 drops one level, +13 .. +15 cracks the piece (it keeps its level; repair it here)."), 13, INK_SOFT, "Regular") rules.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART rules.custom_minimum_size = Vector2(820, 0) fv.add_child(rules) ## Left column: the pieces. static func _left(hud, cols: HBoxContainer) -> void: var ps = _ps() var lp := PanelContainer.new() lp.name = "RefineList" lp.custom_minimum_size = Vector2(286, 0) lp.add_theme_stylebox_override("panel", UiSkin.inset(8.0, 0)) cols.add_child(lp) var lv := VBoxContainer.new() lv.add_theme_constant_override("separation", 4) lp.add_child(lv) lv.add_child(UiSkin.label(T("Your equipment"), 16, Color("#8a4a18"), "Bold")) var sc := ScrollContainer.new() sc.name = "RefineScroll" sc.custom_minimum_size = Vector2(270, 440) sc.horizontal_scroll_mode = ScrollContainer.SCROLL_MODE_DISABLED lv.add_child(sc) var rows := VBoxContainer.new() rows.add_theme_constant_override("separation", 4) rows.size_flags_horizontal = Control.SIZE_EXPAND_FILL sc.add_child(rows) var cur := selected(hud) for inst in ps.refinable_items(): var on: bool = is_same(inst, cur) var b := Button.new() b.name = "Piece%d" % ps.uid_of(inst) b.focus_mode = Control.FOCUS_NONE b.custom_minimum_size = Vector2(258, 54) b.tooltip_text = ps.inst_desc(inst) for s in ["normal", "hover", "pressed", "focus", "disabled"]: b.add_theme_stylebox_override(s, UiSkin.card(on or s == "hover", 6.0)) b.pressed.connect(select.bind(hud, inst)) rows.add_child(b) var h := HBoxContainer.new() h.add_theme_constant_override("separation", 6) h.mouse_filter = Control.MOUSE_FILTER_IGNORE h.position = Vector2(6, 5) h.size = Vector2(246, 44) b.add_child(h) var slot = ItemSlot.new() slot.setup({"id": str(inst["id"]), "inst": inst, "qty": 0}, hud, 42.0, hud.item_frame(str(inst["id"]), inst), 2) slot.draggable = false slot.mouse_filter = Control.MOUSE_FILTER_IGNORE h.add_child(slot) var tv := VBoxContainer.new() tv.add_theme_constant_override("separation", -3) tv.mouse_filter = Control.MOUSE_FILTER_IGNORE tv.size_flags_horizontal = Control.SIZE_EXPAND_FILL h.add_child(tv) var nm := UiSkin.label(MsgTh.name_th(ps.inst_name(inst)), 14, INK, "SemiBold") nm.clip_text = true nm.custom_minimum_size = Vector2(190, 0) tv.add_child(nm) var sub: Array = [] if ps.worn_slot(inst) != "": sub.append(T("worn")) if Refine.is_cracked(inst): sub.append(T("CRACKED")) elif int(inst["refine"]) >= Refine.max_level(): sub.append("MAX") if Refine.heat_of(inst) > 0.0: sub.append(T("heat %d%%" % roundi(Refine.heat_of(inst)))) var sl := UiSkin.label(" · ".join(sub), 12, BAD if Refine.is_cracked(inst) else INK_SOFT, "Regular") tv.add_child(sl) ## Right column: the selected piece. static func _detail(hud, right: VBoxContainer, inst: Dictionary) -> void: var ps = _ps() var k := Refine.kind(str(inst["id"])) var cur := int(inst["refine"]) var mx := cur >= Refine.max_level() var cracked := Refine.is_cracked(inst) var zone := Refine.zone(k, cur) if not mx else "safe" var zc: Color = ZONE_COL.get(zone, INK) # header: icon, name, where it is, current -> next var head := PanelContainer.new() head.name = "RefineHead" head.add_theme_stylebox_override("panel", UiSkin.card(false, 10.0)) right.add_child(head) var hh := HBoxContainer.new() hh.add_theme_constant_override("separation", 10) head.add_child(hh) var big = ItemSlot.new() big.setup({"id": str(inst["id"]), "inst": inst, "qty": 0}, hud, 64.0, hud.item_frame(str(inst["id"]), inst), 2) big.draggable = false hh.add_child(big) var hv := VBoxContainer.new() hv.add_theme_constant_override("separation", -2) hv.size_flags_horizontal = Control.SIZE_EXPAND_FILL hh.add_child(hv) var nm := UiSkin.label(MsgTh.name_th(GameData.item_name(str(inst["id"]))), 20, INK, "Bold") nm.clip_text = true nm.custom_minimum_size = Vector2(250, 0) hv.add_child(nm) var kind_txt: String = T("Armor") if k == "armor" else T("Weapon Lv %s" % k) hv.add_child(UiSkin.label("%s · %s · %s" % [kind_txt, T("worn") if ps.worn_slot(inst) != "" else T("in the bag"), T("safe up to +%d" % Refine.safe_limit(k))], 13, INK_SOFT, "Regular")) var chip := UiSkin.label(T("CRACKED - repair it first") if cracked else (T("MAX") if mx else T(str(ZONE_NAME.get(zone, "")))), 13, Color("#fffaf0"), "Bold", 3, Color(0, 0, 0, 0.35)) var cs := StyleBoxFlat.new() cs.bg_color = BAD if cracked else zc cs.set_corner_radius_all(9) cs.content_margin_left = 10 cs.content_margin_right = 10 cs.content_margin_top = 1 cs.content_margin_bottom = 2 chip.add_theme_stylebox_override("normal", cs) chip.size_flags_horizontal = Control.SIZE_SHRINK_BEGIN hv.add_child(chip) var lvl := UiSkin.label("+%d" % cur if mx or cracked else "+%d → +%d" % [cur, cur + 1], 30, Color("#a0400f"), "Bold", 4, Color(1, 0.96, 0.85, 0.9)) lvl.name = "RefineLevels" lvl.vertical_alignment = VERTICAL_ALIGNMENT_CENTER hh.add_child(lvl) # stat change right.add_child(_stat_line(inst, k, cur, mx or cracked)) # the anvil var av := AnvilView.new() av.name = "Anvil" av.hud = hud av.id = str(inst["id"]) av.lv = cur av.cracked = cracked av.heat = Refine.heat_of(inst) av.zone_col = zc av.custom_minimum_size = Vector2(560, 170) av.tooltip_text = T("Click to skip the hammering.") right.add_child(av) if cracked: _repair_box(hud, right, inst, k) elif mx: right.add_child(UiSkin.label(T("This piece is fully refined."), 16, GOOD, "Bold")) else: _try_box(hud, right, inst, k, cur) if hud.refine_msg != "": var raw: String = hud.refine_msg var good: bool = raw.begins_with("Success!") or raw.begins_with("Repaired") or raw.begins_with("Purified") or raw.begins_with("Refining") var ml := UiSkin.label(T(raw), 15, GOOD if good else BAD, "Bold") ml.name = "RefineMsg" ml.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART ml.custom_minimum_size = Vector2(540, 0) right.add_child(ml) static func _stat_line(inst: Dictionary, k: String, cur: int, same: bool) -> Control: var nx := cur if same else cur + 1 var parts: Array = [] if k == "armor": parts.append(T("Armor DEF from refining +%s → +%s" % [_dec(_armor_pts(cur)), _dec(_armor_pts(nx))])) parts.append(T("CRIT RES +%d → +%d" % [cur, nx])) else: var wl := int(k) parts.append(T("Refine ATK +%d → +%d" % [Refine.weapon_atk(wl, cur), Refine.weapon_atk(wl, nx)])) var o0 := Refine.over_upgrade(wl, cur) var o1 := Refine.over_upgrade(wl, nx) if o1 > 0: parts.append(T("Over-upgrade 1-%d → 1-%d per hit" % [o0, o1]) if o0 > 0 else T("Over-upgrade none → 1-%d per hit" % o1)) parts.append(T("CRIT DMG +%d → +%d" % [3 * cur, 3 * nx])) var l := UiSkin.label(" · ".join(parts), 14, GOOD, "SemiBold") l.name = "RefineStats" l.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART l.custom_minimum_size = Vector2(560, 0) return l static func _armor_pts(r: int) -> float: return float(mini(r, 10)) * float(GameData.refine.get("armor_def_per_refine", 0.7)) + float(maxi(0, r - 10)) * float(GameData.refine.get("armor_def_per_refine_high", 0.35)) static func _dec(v: float) -> String: return String.num(snappedf(v, 0.05), 2).trim_suffix("0").trim_suffix("0").trim_suffix(".") ## Odds, heat, helpers, cost, the Refine button. static func _try_box(hud, right: VBoxContainer, inst: Dictionary, k: String, cur: int) -> void: var ps = _ps() var use: Array = ps.refine_helpers(inst, use_list()) var od := Refine.odds(k, cur, inst, use) var rate := float(od["rate"]) # exact odds: success / what a failure does / +2 var orow := HBoxContainer.new() orow.name = "RefineOdds" orow.add_theme_constant_override("separation", 8) right.add_child(orow) var stxt := T("Success %s%%" % _pct(rate)) if bool(od["sure"]): stxt = T("Guaranteed (forge heat full)") orow.add_child(_pill(stxt, Color("#3f9a45"))) var fk := str(od["fail"]) if rate < 100.0: var ftxt := "" match fk: "keep": ftxt = T("No change %s%%" % _pct(100.0 - rate)) "down": ftxt = T("Drop to +%d %s%%" % [maxi(0, cur - 1), _pct(100.0 - rate)]) "crack": ftxt = T("Crack %s%% (repairable)" % _pct(100.0 - rate)) orow.add_child(_pill(ftxt, ZONE_COL.get(fk, BAD))) if float(od["great"]) > 0.0: orow.add_child(_pill(T("+2 at once %s%%" % _pct(float(od["great"]))), Color("#c08a10"))) # forge heat (pity) var n := Refine.pity_n(cur + 1) if n > 0: var hb := HBoxContainer.new() hb.name = "RefineHeat" hb.add_theme_constant_override("separation", 8) right.add_child(hb) hb.add_child(UiSkin.label(T("Forge heat"), 15, Color("#b0451a"), "Bold")) var bar := HeatBar.new() bar.name = "HeatBar" bar.heat = Refine.heat_of(inst) bar.steps = n bar.custom_minimum_size = Vector2(250, 22) bar.size_flags_vertical = Control.SIZE_SHRINK_CENTER hb.add_child(bar) var left := Refine.fails_left(inst) var ht := T("next try cannot fail!") if left <= 0 else T("guaranteed after %d more failures" % left) hb.add_child(UiSkin.label("%d%% · %s" % [roundi(Refine.heat_of(inst)), ht], 13, INK_SOFT if left > 0 else Color("#c05a10"), "SemiBold")) # helpers var grid := GridContainer.new() grid.name = "RefineHelpers" grid.columns = 2 grid.add_theme_constant_override("h_separation", 10) grid.add_theme_constant_override("v_separation", 2) right.add_child(grid) for key in Refine.HELPERS: var item := Refine.helper_item(key) var have: int = ps.count(item) var why := Refine.helper_use(key, k, cur, inst) var cellp := PanelContainer.new() cellp.add_theme_stylebox_override("panel", UiSkin.card(bool(want.get(key, false)) and have > 0 and why == "", 4.0)) cellp.custom_minimum_size = Vector2(278, 0) grid.add_child(cellp) var cell := HBoxContainer.new() cell.add_theme_constant_override("separation", 4) cellp.add_child(cell) cell.add_child(hud._shop_icon(item, have)) var cb := CheckBox.new() cb.name = "Help_" + key cb.focus_mode = Control.FOCUS_NONE var desc := "" match key: "sparkle": desc = T(HELP_TEXT[key] % [roundi(Refine.great_pct()), Refine.sparkle_cap()]) "bless": desc = T(HELP_TEXT[key] % roundi(Refine.bless_add())) _: desc = T(HELP_TEXT[key]) cb.text = "%s ×%d\n%s" % [MsgTh.name_th(GameData.item_name(item)), have, desc] cb.add_theme_font_size_override("font_size", 13) for st in ["normal", "hover", "pressed", "hover_pressed", "disabled", "focus"]: cb.add_theme_stylebox_override(st, StyleBoxEmpty.new()) for fc in ["font_color", "font_hover_color", "font_pressed_color", "font_hover_pressed_color", "font_focus_color"]: cb.add_theme_color_override(fc, INK) cb.add_theme_constant_override("outline_size", 0) cb.add_theme_color_override("font_disabled_color", Color(INK_SOFT, 0.6)) cb.disabled = have <= 0 or why != "" cb.button_pressed = bool(want.get(key, false)) and not cb.disabled cb.tooltip_text = T(why) if why != "" else (T("You have none - bosses and mini-bosses drop it.") if have <= 0 else GameData.item_desc(item)) var kk: String = key cb.toggled.connect(func(on: bool): want[kk] = on hud.dirty = true) cell.add_child(cb) # cost var cost := HBoxContainer.new() cost.name = "RefineCost" cost.add_theme_constant_override("separation", 6) right.add_child(cost) var mat := Refine.material(k) var need := Refine.ore_count(cur) var fee := Refine.fee_at(k, cur) cost.add_child(UiSkin.label(T("Cost"), 15, INK, "Bold")) cost.add_child(hud._shop_icon(mat, 0)) cost.add_child(UiSkin.label(T("%s x%d (have %d)" % [GameData.item_name(mat), need, ps.count(mat)]), 14, INK if ps.count(mat) >= need else BAD, "SemiBold")) cost.add_child(UiSkin.label(T("Gold %s (have %s)" % [hud._fmt(fee), hud._fmt(ps.zeny)]), 14, INK if ps.zeny >= fee else BAD, "SemiBold")) # action var act := HBoxContainer.new() act.add_theme_constant_override("separation", 10) right.add_child(act) var err: String = ps.refine_check(inst) var busy := str(anim.get("phase", "idle")) == "strike" var b: Button = hud._button(T("Refine to +%d" % (cur + 1)), hud._on_refine_pressed.bind(inst), err != "" or busy, T(err), "danger" if fk in ["down", "crack"] else "ok") b.name = "RefineGo" b.custom_minimum_size = Vector2(240, 46) b.add_theme_font_size_override("font_size", 18) act.add_child(b) if fk in ["down", "crack"]: var na := CheckBox.new() na.name = "NoAsk" na.focus_mode = Control.FOCUS_NONE na.text = T("Do not ask again (this session)") na.add_theme_font_size_override("font_size", 13) for st in ["normal", "hover", "pressed", "hover_pressed", "disabled", "focus"]: na.add_theme_stylebox_override(st, StyleBoxEmpty.new()) for fc in ["font_color", "font_hover_color", "font_pressed_color", "font_hover_pressed_color", "font_focus_color"]: na.add_theme_color_override(fc, INK_SOFT) na.add_theme_constant_override("outline_size", 0) na.button_pressed = no_ask na.toggled.connect(func(on: bool): no_ask = on) act.add_child(na) static func _repair_box(hud, right: VBoxContainer, inst: Dictionary, k: String) -> void: var ps = _ps() var rc := Refine.repair_cost(k) var t := UiSkin.label(T("Cracked: it keeps +%d, but cannot be worn until it is repaired." % int(inst["refine"])), 15, BAD, "SemiBold") t.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART t.custom_minimum_size = Vector2(540, 0) right.add_child(t) var cost := HBoxContainer.new() cost.name = "RepairCost" cost.add_theme_constant_override("separation", 6) right.add_child(cost) cost.add_child(UiSkin.label(T("Repair cost"), 15, INK, "Bold")) cost.add_child(hud._shop_icon(str(rc["item"]), 0)) cost.add_child(UiSkin.label(T("%s x%d (have %d)" % [GameData.item_name(str(rc["item"])), int(rc["n"]), ps.count(str(rc["item"]))]), 14, INK if ps.count(str(rc["item"])) >= int(rc["n"]) else BAD, "SemiBold")) cost.add_child(UiSkin.label(T("Gold %s (have %s)" % [hud._fmt(int(rc["zeny"])), hud._fmt(ps.zeny)]), 14, INK if ps.zeny >= int(rc["zeny"]) else BAD, "SemiBold")) var err: String = ps.repair_check(inst) var b: Button = hud._button(T("Repair"), on_repair.bind(hud, inst), err != "", T(err) if err != "" else T("Mending Coal drops from bosses and mini-bosses."), "ok") b.name = "RepairGo" b.custom_minimum_size = Vector2(240, 46) b.add_theme_font_size_override("font_size", 18) right.add_child(b) static func _pct(v: float) -> String: return String.num(snappedf(v, 0.1), 1).trim_suffix(".0") static func _pill(text: String, col: Color) -> Control: var l := UiSkin.label(text, 15, Color("#fffaf0"), "Bold", 3, Color(0, 0, 0, 0.3)) var s := StyleBoxFlat.new() s.bg_color = col s.set_corner_radius_all(12) s.content_margin_left = 12 s.content_margin_right = 12 s.content_margin_top = 3 s.content_margin_bottom = 4 s.shadow_color = Color(0, 0, 0, 0.18) s.shadow_size = 2 s.shadow_offset = Vector2(0, 2) l.add_theme_stylebox_override("normal", s) return l # ---------------------------------------------------------------- actions ## The Refine button: orange / red tries ask first (unless "do not ask again"), then the hammering starts. static func press(hud, inst: Dictionary) -> void: var ps = _ps() var k := Refine.kind(str(inst["id"])) var cur := int(inst["refine"]) var od := Refine.odds(k, cur, inst, ps.refine_helpers(inst, use_list())) var fk := str(od["fail"]) if fk in ["down", "crack"] and not no_ask: var what := T("If it fails, it drops to +%d." % maxi(0, cur - 1)) if fk == "down" else \ T("If it fails, it CRACKS: it keeps its level, but cannot be worn until repaired with Mending Coal + gold.") hud.ask(T("Refine %s to +%d?\nSuccess chance: %s%%.\n%s" % [MsgTh.name_th(ps.inst_name(inst)), cur + 1, _pct(float(od["rate"])), what]), T("Refine"), start.bind(hud, inst)) else: start(hud, inst) ## Starts the hammering; the command goes out when it ends (or at once in tests / when the anvil is clicked). static func start(hud, inst: Dictionary) -> void: _pending = {"uid": _ps().uid_of(inst), "help": _ps().refine_helpers(inst, use_list())} anim = {"phase": "strike", "t0": Time.get_ticks_msec(), "id": str(inst["id"]), "from": int(inst["refine"]), "to": int(inst["refine"])} hud.refine_msg = "" hud.dirty = true if hud.is_inside_tree(): hud.get_tree().create_timer(STRIKE_S).timeout.connect(send_now.bind(hud)) else: send_now(hud) ## Sends the pending try (once). static func send_now(hud) -> void: if _pending.is_empty(): return var p := _pending _pending = {} var r: Dictionary = hud._send({"t": "refine", "uid": int(p["uid"]), "help": p["help"]}) if r.get("pending", false): # co-op: the host answers with a "result" event (hud.on_refine_result) hud.refine_msg = "Refining..." hud.dirty = true return on_result(hud, r) static func on_repair(hud, inst: Dictionary) -> void: var r: Dictionary = hud._send({"t": "refine", "op": "repair", "uid": _ps().uid_of(inst)}) anim = {"phase": "strike", "t0": Time.get_ticks_msec(), "id": str(inst["id"]), "from": int(inst["refine"]), "to": int(inst["refine"])} if r.get("pending", false): hud.refine_msg = "Refining..." hud.dirty = true return on_result(hud, r) ## The answer (at once in single-player, as a "result" event from the host in co-op). static func on_result(hud, r: Dictionary) -> void: var res := str(r.get("result", "")) # refine_msg stays English (translated when shown); names are the English instance names var nm := str(r.get("name", "")) var now := str(r.get("now", nm)) var from := int(anim.get("from", 0)) anim = {"phase": res if res != "" else "idle", "t0": Time.get_ticks_msec(), "id": str(anim.get("id", "")), "from": from, "to": int(r.get("refine", from))} var col := Color(1, 0.45, 0.4) var txt := "" match res: "success": hud.refine_msg = "Success! Now %s." % now col = Color(0.5, 1, 0.5) txt = T("Refine Success!") "great": hud.refine_msg = "Success! +2 at once - now %s." % now col = Color(1, 0.85, 0.3) txt = T("Great Success! +2") "keep": hud.refine_msg = "Failed... %s is unchanged (ore and gold spent)." % nm txt = T("Refine Failed...") "down": hud.refine_msg = "Failed... dropped to %s." % now txt = T("Dropped a level...") "crack": hud.refine_msg = "Failed... %s CRACKED - it keeps its level. Repair it here." % nm txt = T("Cracked!") "repaired": hud.refine_msg = "Repaired %s." % now col = Color(0.5, 0.95, 1) txt = T("Repaired!") _: hud.refine_msg = "" if txt != "" and hud.player and hud.world: var at: Vector3 = hud.player.global_position + Vector3(0, 2.2, 0) Fx.float_text(hud.world, at, txt, col, 44) if res in ["success", "great", "repaired"]: Fx.flash(hud.world, hud.player.global_position + Vector3(0, 1.0, 0), col, 2.2, 0.5) Fx.ring(hud.world, hud.player.global_position, 1.6, col, 0.6) elif res == "crack": Fx.flash(hud.world, hud.player.global_position + Vector3(0, 1.0, 0), Color(1, 0.3, 0.2), 1.6, 0.35) else: Fx.dust(hud.world, hud.player.global_position) hud.dirty = true # ---------------------------------------------------------------- widgets ## The forge-heat bar: segments = failures to the guarantee, ember gradient fill, flame mark. class HeatBar extends Control: var heat := 0.0 var steps := 1 func _draw() -> void: var r := Rect2(Vector2.ZERO, size) var bg := StyleBoxFlat.new() bg.bg_color = Color("#3a2416") bg.set_corner_radius_all(int(size.y * 0.5)) bg.border_color = Color("#c89a5a") bg.set_border_width_all(2) draw_style_box(bg, r) var f := clampf(heat / 100.0, 0.0, 1.0) if f > 0.0: var w := maxf(size.y, (size.x - 6.0) * f) var n := 24 for i in n: var x0 := 3.0 + w * float(i) / float(n) var x1 := 3.0 + w * float(i + 1) / float(n) var c := Color("#ffd23f").lerp(Color("#ff7a1a"), float(i) / float(n)).lerp(Color("#e8321e"), maxf(0.0, f - 0.6) * float(i) / float(n)) draw_rect(Rect2(x0, 4.0, x1 - x0 + 0.6, size.y - 8.0), c) draw_rect(Rect2(3.0, 4.0, w, (size.y - 8.0) * 0.35), Color(1, 1, 1, 0.25)) for i in range(1, steps): var x := 3.0 + (size.x - 6.0) * float(i) / float(steps) draw_line(Vector2(x, 5), Vector2(x, size.y - 5), Color(0, 0, 0, 0.35), 1.0) # flame mark at the right end var fx := size.x - size.y * 0.5 var fy := size.y * 0.5 var hot := Color("#ffea7a") if f >= 0.999 else Color("#ffb03a") draw_colored_polygon(PackedVector2Array([Vector2(fx, fy - 9), Vector2(fx + 6, fy + 2), Vector2(fx, fy + 7), Vector2(fx - 6, fy + 2)]), hot) ## The anvil: the piece above an iron anvil; hammer strikes with sparks, then the result burst. class AnvilView extends Control: var hud = null var id := "" var lv := 0 var cracked := false var heat := 0.0 var zone_col := Color.WHITE func _ready() -> void: mouse_filter = Control.MOUSE_FILTER_STOP func _gui_input(e: InputEvent) -> void: if e is InputEventMouseButton and e.pressed and e.button_index == MOUSE_BUTTON_LEFT: var RU = load("res://scripts/ui/refine_ui.gd") if str(RU.anim.get("phase", "")) == "strike" and hud != null: RU.send_now(hud) func _process(_d: float) -> void: queue_redraw() func _prog(dur: float) -> float: var RU = load("res://scripts/ui/refine_ui.gd") if float(RU.freeze_t) >= 0.0: return float(RU.freeze_t) return clampf(float(Time.get_ticks_msec() - int(RU.anim.get("t0", 0))) / 1000.0 / dur, 0.0, 1.0) func _draw() -> void: var RU = load("res://scripts/ui/refine_ui.gd") var a: Dictionary = RU.anim var phase := str(a.get("phase", "idle")) if phase != "idle" and str(a.get("id", "")) != id: phase = "idle" var c := size * 0.5 var shake := Vector2.ZERO var t := 0.0 if phase == "strike": t = _prog(RU.STRIKE_S) var beat := fmod(t * 3.0, 1.0) if beat < 0.12: shake = Vector2(sin(t * 90.0) * 2.0, 1.5) elif phase != "idle": t = _prog(RU.RESULT_S) if phase == "down" and t < 0.5: shake = Vector2(sin(t * 80.0) * 5.0 * (1.0 - t * 2.0), 0) if phase == "crack" and t < 0.3: shake = Vector2(sin(t * 120.0) * 4.0, cos(t * 97.0) * 2.0) # backdrop: warm forge glow (stronger with heat) var glow := 0.15 + 0.5 * heat / 100.0 for i in 6: var rr := size.y * (0.9 - i * 0.12) draw_circle(c + Vector2(0, 20), rr, Color(1.0, 0.55, 0.15, glow * 0.05 * (i + 1))) # anvil var ax := c.x var ay := size.y - 26.0 var top := PackedVector2Array([Vector2(ax - 120, ay - 34), Vector2(ax + 92, ay - 34), Vector2(ax + 140, ay - 46), Vector2(ax + 120, ay - 22), Vector2(ax + 70, ay - 18), Vector2(ax - 96, ay - 18), Vector2(ax - 120, ay - 26)]) var waist := PackedVector2Array([Vector2(ax - 60, ay - 18), Vector2(ax + 50, ay - 18), Vector2(ax + 34, ay + 2), Vector2(ax - 44, ay + 2)]) var foot := PackedVector2Array([Vector2(ax - 80, ay + 2), Vector2(ax + 70, ay + 2), Vector2(ax + 82, ay + 18), Vector2(ax - 92, ay + 18)]) draw_colored_polygon(foot, Color("#3b3532")) draw_colored_polygon(waist, Color("#4a423d")) draw_colored_polygon(top, Color("#5c544e")) draw_line(Vector2(ax - 118, ay - 33), Vector2(ax + 92, ay - 33), Color("#9a918a"), 3.0) draw_line(Vector2(ax - 96, ay - 18), Vector2(ax + 70, ay - 18), Color(0, 0, 0, 0.35), 2.0) # the piece var ic := Vector2(ax, ay - 82) + shake var tex: Texture2D = Icons.item_icon(id) var isz := 96.0 if phase in ["success", "great", "repaired"]: isz *= 1.0 + 0.18 * sin(minf(t * 3.0, 1.0) * PI) if tex: draw_texture_rect(tex, Rect2(ic - Vector2(isz, isz) * 0.5, Vector2(isz, isz)), false, Color(1, 0.75, 0.6) if cracked or phase == "crack" else Color.WHITE) else: draw_circle(ic, isz * 0.4, Color(str(GameData.item(id).get("color", "#9a8a70")))) # heat embers (idle) if phase == "idle" and heat > 0.0: var now := Time.get_ticks_msec() / 1000.0 for i in int(4 + heat / 10.0): var ph := fmod(now * (0.4 + 0.05 * i) + i * 0.37, 1.0) var p := Vector2(ax - 100 + fmod(i * 53.0, 200.0), ay - 30 - ph * 90.0) draw_circle(p, 2.0 + (i % 3), Color(1, 0.6 + 0.3 * (1.0 - ph), 0.2, 0.8 * (1.0 - ph))) # cracks (cracked piece / crack result) if cracked or phase == "crack": var k := 1.0 if phase != "crack" else clampf(t * 3.0, 0.0, 1.0) _cracks(ic, isz * 0.55 * k) # level badge var shown := lv if phase in ["success", "great", "down", "repaired", "keep", "crack"]: shown = int(a.get("to", lv)) var f: Font = UiSkin.font("Bold") var badge := "+%d" % shown var bcol := Color("#fff2c8") draw_string_outline(f, ic + Vector2(isz * 0.32, -isz * 0.28), badge, HORIZONTAL_ALIGNMENT_LEFT, -1, 26, 8, Color("#7a2a10")) draw_string(f, ic + Vector2(isz * 0.32, -isz * 0.28), badge, HORIZONTAL_ALIGNMENT_LEFT, -1, 26, bcol) match phase: "strike": _hammer(ic, t) "success", "repaired": _burst(ic, t, Color("#ffd23f") if phase == "success" else Color("#7fe0ff"), false) _big_text(ic + Vector2(190, 14), RU.T("Success!") if phase == "success" else RU.T("Repaired!"), t, Color("#ffe27a") if phase == "success" else Color("#aef0ff")) "great": _burst(ic, t, Color.WHITE, true) _big_text(ic + Vector2(190, 14), "+2 !", t, Color.from_hsv(fmod(t * 1.5, 1.0), 0.55, 1.0)) "keep": _smoke(ic, t) _big_text(ic + Vector2(190, 14), RU.T("No change"), t, Color("#d8d0c8")) "down": _smoke(ic, t) _big_text(ic + Vector2(190, 14), "+%d ↓" % int(a.get("to", lv)), t, Color("#ff9a5a")) "crack": if t < 0.25: draw_rect(Rect2(Vector2.ZERO, size), Color(1, 0.2, 0.1, 0.25 * (1.0 - t * 4.0))) _big_text(ic + Vector2(190, 14), RU.T("Cracked!"), t, Color("#ff6a4a")) func _hammer(ic: Vector2, t: float) -> void: var beat := fmod(t * 3.0, 1.0) var n := int(t * 3.0) # lifted -> swing down -> impact at beat 0 of the next strike var ang := lerpf(-1.25, 0.05, clampf(beat / 0.75, 0.0, 1.0) * clampf(beat / 0.75, 0.0, 1.0)) var pivot := ic + Vector2(110, 10) var head := pivot + Vector2(-cos(ang) * 96.0, -sin(ang) * 96.0 - 30.0) draw_line(pivot, head, Color("#7a4a22"), 7.0) var hd := (head - pivot).normalized() var nrm := Vector2(-hd.y, hd.x) var hpts := PackedVector2Array([head + nrm * 20 - hd * 6, head + nrm * 20 + hd * 16, head - nrm * 20 + hd * 16, head - nrm * 20 - hd * 6]) draw_colored_polygon(hpts, Color("#8d8f96")) draw_line(head + nrm * 20 + hd * 16, head - nrm * 20 + hd * 16, Color("#c9ccd4"), 3.0) # sparks right after each impact if beat > 0.72 or (n > 0 and beat < 0.2): var st: float = (beat - 0.72) / 0.28 if beat > 0.72 else (beat + 0.28) / 0.28 * 0.5 + 0.5 for i in 14: var a := float(i) / 14.0 * TAU + n * 0.7 var d := 14.0 + st * (40.0 + (i % 4) * 12.0) var p := ic + Vector2(cos(a), sin(a) * 0.7) * d + Vector2(0, 10) draw_line(p, p + Vector2(cos(a), sin(a) * 0.7) * 9.0, Color(1, 0.85 - 0.3 * st, 0.3, 1.0 - st), 2.0) func _burst(ic: Vector2, t: float, col: Color, rainbow: bool) -> void: var r := 30.0 + t * 120.0 var al := 1.0 - t for i in 18: var a := float(i) / 18.0 * TAU + t * 0.8 var c2 := Color.from_hsv(float(i) / 18.0, 0.6, 1.0, al) if rainbow else Color(col, al) draw_line(ic + Vector2(cos(a), sin(a)) * r * 0.35, ic + Vector2(cos(a), sin(a)) * r, c2, 4.0) draw_arc(ic, r * 0.8, 0, TAU, 48, Color(col if not rainbow else Color("#fff6c0"), al * 0.8), 5.0) draw_circle(ic, 40.0 * (1.0 - t), Color(1, 1, 0.9, 0.35 * al)) func _smoke(ic: Vector2, t: float) -> void: for i in 7: var p := ic + Vector2(-48 + i * 16, 18 - t * (40.0 + i * 6.0)) draw_circle(p, 10.0 + t * 22.0 + (i % 3) * 3.0, Color(0.55, 0.53, 0.5, 0.45 * (1.0 - t))) func _cracks(ic: Vector2, r: float) -> void: if r <= 1.0: return var rays := [[0.3, [0.35, 0.62, 1.0]], [2.1, [0.4, 0.7, 0.95]], [3.9, [0.3, 0.6, 0.9]], [5.0, [0.45, 1.0]]] for ry in rays: var a0: float = ry[0] var prev := ic var j := 0 for f in ry[1]: j += 1 var a := a0 + (0.35 if j % 2 == 0 else -0.3) var p := ic + Vector2(cos(a), sin(a)) * r * float(f) draw_line(prev, p, Color("#2a0e08"), 3.0) draw_line(prev + Vector2(1, 1), p + Vector2(1, 1), Color(1, 0.55, 0.4, 0.6), 1.0) prev = p func _big_text(at: Vector2, text: String, t: float, col: Color) -> void: var f: Font = UiSkin.font("Bold") var sz := int(30 + 10 * sin(minf(t * 4.0, 1.0) * PI * 0.5)) var w := f.get_string_size(text, HORIZONTAL_ALIGNMENT_LEFT, -1, sz).x var p := at + Vector2(-w * 0.5, -t * 10.0) p.x = clampf(p.x, 6.0, maxf(6.0, size.x - w - 6.0)) var al := 1.0 if t < 0.75 else (1.0 - t) * 4.0 draw_string_outline(f, p, text, HORIZONTAL_ALIGNMENT_LEFT, -1, sz, 10, Color(0.25, 0.08, 0.02, al)) draw_string(f, p, text, HORIZONTAL_ALIGNMENT_LEFT, -1, sz, Color(col, al))