extends Node signal changed #catalogue unique : action -> libellé affiché const LABELS : Dictionary = { &"player_jump": "Sauter", &"player_dismount": "Descendre", &"player_aim_switch_target": "Changer de cible", &"player_aim_unlock": "Libérer la cible", &"player_throw_cancel": "Annuler le lancer", } var _state_actions : Array = [] # [action, ...] var _context_hints : Dictionary = {} # clé (objet ou StringName) -> {action, text, priority} func label_for(action : StringName) -> String: return LABELS.get(action, String(action)) #sans entrée : le nom de l'action, bien visible #---------- hints d'état (appelés par la StateMachine) ---------- func set_state_hints(actions : Array) -> void: _state_actions = actions changed.emit() #---------- hints de contexte (monture, PNJ, etc.) ---------- #text vide : le libellé vient du catalogue. À renseigner quand le sens dépend du contexte (Grimper / Parler sur la même action) func set_context(source : Variant, action : StringName, text : String = "", priority : int = 0) -> void: var h : Dictionary = {"action": action, "text": text if text != "" else label_for(action), "priority": priority} if _context_hints.get(source) == h: return _context_hints[source] = h changed.emit() func clear_context(source : Variant) -> void: if _context_hints.erase(source): changed.emit() #---------- lecture (par le HUD) ---------- func get_visible() -> Array: for key in _context_hints.keys(): if typeof(key) == TYPE_OBJECT and !is_instance_valid(key): _context_hints.erase(key) var ctx : Array = _context_hints.values() ctx.sort_custom(func(a, b): return a.priority > b.priority) #le contexte passe avant l'état ; une même action n'apparaît qu'une fois var result : Array = [] var used : Dictionary = {} for h in ctx: if used.has(h.action): continue used[h.action] = true result.append(h) for action in _state_actions: if used.has(action): continue used[action] = true result.append({"action": action, "text": label_for(action)}) return result