Files
mtgodot-poc/project/ui/view_equipment_ui.gd
T
shenandClaude Sonnet 5 47baf6c0c6 Metin2 game client (P0–P11) + mobile asset pipeline
Networked client on the existing Godot 4.7 + libgr2 renderer:
- net: m2dev wire protocol (libsodium KX + XChaCha20), auth/select/game
  phases, EntityStore world model, ~all GC/CG headers. char create/delete,
  private shop / mall / cube, SHOP_GC_START_EX, guild, party (+ CG_PARTY_SET_STATE),
  quests, dragon soul, refine, safebox, exchange.
- UI: in-game windows migrated 1:1 from the reference uiscript/root .py —
  char status (/stat), inventory+equipment, select-item ([SELECT_ITEM] quest
  token), system-option + game-option + ESC system menu, private-shop 39-grid,
  party info board, shop tabs, atlas, minimap, quickbar, chat, …
- EterGrnLib polish: GR2 material blend/two-sided, LOD crossfade, motion-event
  dispatch, contact shadow, ray-AABB picking, weapon grip pre-transform.

Portable asset IO (A1) — all extension/libgr2/formats/mtproto reads routed
through godot::FileAccess (res:// PCK works on iOS/Android); standalone-lib
*_path() kept for the non-Godot CTests. AssetResolver + PropertyRegistry
switched to a baked index (bake_asset_index.gd) instead of std::filesystem.

Mobile builds: build-{android,ios}.sh, export-android.sh, pack-assets.sh,
gen-debug-keystore.sh. Assets ship as a zip mounted at runtime by
project/asset_pack.gd (adb push now; HTTP download is a drop-in later).

ctest 10/10, 34 GDScript suites, macOS/iOS/Android all build.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013EJxkHiNKS4kybHS3XKyAJ
2026-08-31 20:02:12 +09:00

104 lines
3.3 KiB
GDScript
Raw 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.
# ViewEquipmentUI — GC_VIEW_EQUIP 的装备查看窗。
# 服务器推送某个角色的 11 个传统可见装备位后自动刷新并置顶。
extends Node
const WEAR_NAMES := ["身体", "头部", "鞋子", "护腕", "武器", "项链", "耳环", "盾牌", "饰品 1", "饰品 2", "箭矢"]
var client: Node
var ui: CanvasLayer
var proto: Node
var item_list: RefCounted
var _window: Control
func setup(m2client: Node, manager: CanvasLayer, proto_node: Node = null, il: RefCounted = null) -> void:
client = m2client
ui = manager
proto = proto_node
item_list = il
if client.has_signal("view_equipment"):
client.view_equipment.connect(show_for)
func show_for(vid: int) -> void:
if client == null or not client.has_method("get_view_equipment"):
return
var equipment: Array = client.get_view_equipment(vid)
if equipment.is_empty():
return
if is_instance_valid(_window):
ui.close(_window)
_window = _build_window(vid, equipment)
ui.open(_window)
func _build_window(vid: int, equipment: Array) -> Control:
var win := Panel.new()
win.name = "ViewEquipment"
win.position = Vector2(1280, 180)
win.size = Vector2(280, 390)
var bg := StyleBoxFlat.new()
bg.bg_color = Color(0.05, 0.06, 0.09, 0.94)
bg.border_color = Color(0.65, 0.5, 0.2, 0.9)
bg.set_border_width_all(1)
bg.set_corner_radius_all(5)
win.add_theme_stylebox_override("panel", bg)
var title := Label.new()
title.position = Vector2(12, 8)
title.size = Vector2(220, 26)
title.text = "%s 的装备" % _character_name(vid)
title.add_theme_font_size_override("font_size", 16)
win.add_child(title)
var close := Button.new()
close.text = "×"
close.position = Vector2(238, 4)
close.size = Vector2(34, 30)
close.pressed.connect(func():
if is_instance_valid(_window):
ui.close(_window)
_window = null)
win.add_child(close)
var list := VBoxContainer.new()
list.position = Vector2(12, 42)
list.size = Vector2(256, 336)
list.add_theme_constant_override("separation", 3)
win.add_child(list)
for d in equipment:
var wear := int(d.get("wear", 0))
var line := Label.new()
line.text = "%s: %s" % [_wear_name(wear), _item_name(int(d.get("vnum", 0)), int(d.get("count", 0)))]
line.tooltip_text = _item_tooltip(d)
line.autowrap_mode = TextServer.AUTOWRAP_WORD_SMART
list.add_child(line)
return win
func _character_name(vid: int) -> String:
if client.has_method("get_entity"):
var entity: Dictionary = client.get_entity(vid)
if not entity.is_empty() and not String(entity.get("name", "")).is_empty():
return String(entity["name"])
return "角色 #%d" % vid
func _wear_name(wear: int) -> String:
return WEAR_NAMES[wear] if wear >= 0 and wear < WEAR_NAMES.size() else "装备 %d" % wear
func _item_name(vnum: int, count: int) -> String:
if vnum == 0:
return "(空)"
var name := "物品 #%d" % vnum
if proto:
var pd: Dictionary = proto.item(vnum)
if not pd.is_empty():
name = String(pd.get("locale_name", pd.get("name", name)))
elif item_list and item_list.has(vnum):
name = item_list.type_of(vnum)
return "%s x%d" % [name, count] if count > 1 else name
func _item_tooltip(d: Dictionary) -> String:
var attrs: Array = d.get("attrs", [])
if attrs.is_empty():
return ""
var lines := []
for attr in attrs:
lines.append("属性 %d: %+d" % [int(attr.get("type", 0)), int(attr.get("value", 0))])
return "\n".join(lines)