extends CanvasLayer @onready var bg = $BG as TextureRect var mahjongs = { "三条1": preload("uid://b2ectbek7vksi"), "三条2": preload("uid://ca5j182ppemi3"), "三条3": preload("uid://cd6d3xjx5o6gg"), "三条4": preload("uid://bl20arldcd04c"), "三条5": preload("uid://dtkl36brvsget"), "三筒": preload("uid://b2pypf81rgqkw"), "九筒1": preload("uid://dis6qtf1hvop2"), "九筒2": preload("uid://2chok0puqbuu"), "二筒": preload("uid://doxc87cp3e8i4"), "伍万1": preload("uid://bo4hrg3sqpoou"), "伍万2": preload("uid://e86x6j8wu7sw"), "伍万3": preload("uid://q4vs78ohnnhw"), "一条": preload("uid://dduhqah1p81tb"), "一筒": preload("uid://dwyk0e1c2eg37") } @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", %"14"] @onready var hand_mahjongs = [] @onready var box_mahjongs = [] var freezing = true var success = false func _ready() -> void: layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME box_init_btn.pressed.connect(_start_game) box_init_btn.mouse_entered.connect(_toggle_activation_modulate.bind(box_init_btn, true)) box_init_btn.mouse_exited.connect(_toggle_activation_modulate.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)) _toggle_activation_for_all(false) func _start_game() -> void: $SfxStart.play() %"14".visible = true 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_modulate(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_modulate(btn, false) _toggle_activation_modulate(activated_btn, false) activated_btn = null else: $SfxSelect.play() _toggle_activation_modulate(btn, true) activated_btn = btn else: $SfxSelect.play() _toggle_activation_modulate(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_modulate(btn: TextureButton, activated: bool) -> void: if null == btn: return if activated: btn.modulate = Color.WHITE else: btn.modulate = Color.GRAY func _toggle_activation_for_all(activated: bool) -> void: if box_init_btn: _toggle_activation_modulate(box_init_btn, activated) for b in box_mahjongs_btn: _toggle_activation_modulate(b, activated) for b in hand_mahjongs_btn: _toggle_activation_modulate(b, activated) func _check_if_success() -> void: if success: $SfxSuccess.play() freezing = true