extends CanvasLayer signal exit(success: bool) var c03_dialog = preload("uid://b66v5hsf3tdox") var mahjongs = { "三条": preload("uid://b2ectbek7vksi"), "三筒": preload("uid://b2pypf81rgqkw"), "九筒": preload("uid://dis6qtf1hvop2"), "二筒": preload("uid://doxc87cp3e8i4"), "伍万": preload("uid://bo4hrg3sqpoou"), "一条": preload("uid://dduhqah1p81tb"), "一筒": preload("uid://dwyk0e1c2eg37") } var answer_of_in_hand_mahjongs = { preload("uid://bo4hrg3sqpoou"): "伍万", preload("uid://b2ectbek7vksi"): "三条" } @onready var box_init_btn = %"0" @onready var box_mahjongs_btn: Array[TextureButton] = [%"1", %"2", %"3", %"4", %"5", %"6", %"7", %"8", %"9", %"10", %"11"] @onready var hand_mahjongs_btn: Array[TextureButton] = [%"12", %"13"] var freezing = true var success = false func _ready() -> void: layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME _toggle_activation_for_all(false) if not SceneManager.has_prop("prop_麻将2"): %"12".visible = false SceneManager.pop_center_notification("input_麻将游戏_麻将不足") await Util.wait(3.0) exit.emit(false) return box_init_btn.pressed.connect(_start_game) box_init_btn.mouse_entered.connect(_toggle_activation.bind(box_init_btn, true)) box_init_btn.mouse_exited.connect(_toggle_activation.bind(box_init_btn, false)) for b in box_mahjongs_btn: b.mouse_entered.connect(_toggel_hover.bind(b, true)) b.mouse_exited.connect(_toggel_hover.bind(b, false)) b.pressed.connect(_on_btn_pressed.bind(b)) for b in hand_mahjongs_btn: b.mouse_entered.connect(_toggel_hover.bind(b, true)) b.mouse_exited.connect(_toggel_hover.bind(b, false)) b.pressed.connect(_on_btn_pressed.bind(b)) func _start_game() -> void: $SfxStart.play() SceneManager.pop_center_notification("input_麻将游戏_操作规则") box_init_btn.queue_free() freezing = false func _toggel_hover(btn: TextureButton, hovering: bool) -> void: if freezing: return if activated_btn and btn == activated_btn: return _toggle_activation(btn, hovering) var activated_btn: TextureButton func _on_btn_pressed(btn: TextureButton) -> void: if freezing: return if btn != activated_btn: if activated_btn: _exchange_texture(btn, activated_btn) _toggle_activation(btn, false) _toggle_activation(activated_btn, false) activated_btn = null else: $SfxSelect.play() _toggle_activation(btn, true) activated_btn = btn else: $SfxSelect.play() _toggle_activation(btn, false) activated_btn = null _check_if_success() func _exchange_texture(btn1: TextureButton, btn2: TextureButton) -> void: if btn1 and btn2: $SfxSwitch.play() var texture = btn1.texture_normal btn1.texture_normal = btn2.texture_normal btn2.texture_normal = texture func _toggle_activation(btn: TextureButton, hightlight: bool) -> void: if null == btn: return btn.get_node("光束").enabled = hightlight func _toggle_activation_for_all(activated: bool) -> void: if box_init_btn: _toggle_activation(box_init_btn, activated) for b in box_mahjongs_btn: _toggle_activation(b, activated) for b in hand_mahjongs_btn: _toggle_activation(b, activated) func _check_if_success() -> void: success = true for hb in hand_mahjongs_btn: if not hb.texture_normal in answer_of_in_hand_mahjongs: success = false break if success: var animation_player = $AnimationPlayer as AnimationPlayer $SfxSuccess.play() freezing = true SceneManager.disable_prop_item("prop_麻将") SceneManager.disable_prop_item("prop_麻将2") # 下一阶段 EventManager.set_stage_if_greater("c03_mahjong_game", 1) DialogueManager.show_dialogue_balloon(c03_dialog, "c03_s04_整理麻将游戏0") animation_player.play("take_to_the_desk") await DialogueManager.dialogue_ended if animation_player.is_playing(): await animation_player.animation_finished DialogueManager.show_dialogue_balloon(c03_dialog, "c03_s04_整理麻将游戏1", [GlobalConfig.DIALOG_IGNORE_INPUT]) SceneManager.black_transition(0.7, 7.0) ArchiveManager.runtime_set("c03_mahjong_game_black_transition_time", 7.0) await Util.wait(1.0) exit.emit(true)