xiandie/scene/ground/script/c03/s04_closeup整理麻将游戏.gd

127 lines
3.6 KiB
GDScript3
Raw Normal View History

2025-07-09 15:04:08 +00:00
extends CanvasLayer
2025-07-09 16:07:36 +00:00
signal exit(success: bool)
2025-07-09 15:04:08 +00:00
@onready var bg = $BG as TextureRect
var mahjongs = {
2025-07-09 16:07:36 +00:00
"三条": preload("uid://b2ectbek7vksi"),
2025-07-09 15:04:08 +00:00
"三筒": preload("uid://b2pypf81rgqkw"),
2025-07-09 16:07:36 +00:00
"九筒": preload("uid://dis6qtf1hvop2"),
2025-07-09 15:04:08 +00:00
"二筒": preload("uid://doxc87cp3e8i4"),
2025-07-09 16:07:36 +00:00
"伍万": preload("uid://bo4hrg3sqpoou"),
2025-07-09 15:04:08 +00:00
"一条": preload("uid://dduhqah1p81tb"),
"一筒": preload("uid://dwyk0e1c2eg37")
}
2025-07-09 16:07:36 +00:00
var answer_of_in_hand_mahjongs = {
preload("uid://bo4hrg3sqpoou"): "伍万",
preload("uid://b2ectbek7vksi"): "三条"
}
2025-07-09 15:04:08 +00:00
@onready var box_init_btn = %"0"
@onready var box_mahjongs_btn: Array[TextureButton] = [%"1", %"2", %"3", %"4", %"5", %"6", %"7", %"8", %"9", %"10", %"11"]
2025-07-09 16:07:36 +00:00
@onready var hand_mahjongs_btn: Array[TextureButton] = [%"12", %"13"]
2025-07-09 15:04:08 +00:00
var freezing = true
var success = false
func _ready() -> void:
layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME
2025-07-09 16:07:36 +00:00
_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
2025-07-09 15:04:08 +00:00
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))
func _start_game() -> void:
$SfxStart.play()
2025-07-09 16:07:36 +00:00
SceneManager.pop_center_notification("input_麻将游戏_操作规则")
2025-07-09 15:04:08 +00:00
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
2025-07-09 16:07:36 +00:00
btn.get_node("光束").enabled = activated
2025-07-09 15:04:08 +00:00
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:
2025-07-09 16:07:36 +00:00
success = true
for hb in hand_mahjongs_btn:
if not hb.texture_normal in answer_of_in_hand_mahjongs:
success = false
break
2025-07-09 15:04:08 +00:00
if success:
$SfxSuccess.play()
freezing = true
2025-07-09 16:07:36 +00:00
SceneManager.disable_prop_item("prop_麻将")
SceneManager.disable_prop_item("prop_麻将2")
# 下一阶段
EventManager.set_stage_if_greater("c03_mahjong_game", 1)
await Util.wait(3.0)
exit.emit(true)