2025-07-09 16:07:36 +00:00
|
|
|
|
extends CanvasLayer
|
|
|
|
|
|
|
|
|
|
signal exit(arg)
|
|
|
|
|
|
|
|
|
|
@onready var bg = $BG as TextureRect
|
2025-07-10 09:13:31 +00:00
|
|
|
|
@onready var front_lay = $MahjongsFrontLay as CanvasItem
|
|
|
|
|
@onready var stand = $Stand as CanvasItem
|
|
|
|
|
@onready var grid = $Stand/MahjongGrid as GridContainer
|
|
|
|
|
|
|
|
|
|
@onready var stand_mahjongs_btn: Array[TextureButton] = [%"1", %"2", %"3", %"4", %"5", %"6", %"7", %"8", %"9", %"10", %"11", %"12", %"13"]
|
|
|
|
|
@onready var stand_right_mahjong: TextureButton = %"14"
|
|
|
|
|
@onready var hand_mahjongs_btn: Array[TextureButton] = [%"15", %"16", %"17"]
|
|
|
|
|
|
|
|
|
|
var mahjongs = {
|
|
|
|
|
"南": preload("uid://6hdekasuabnm"),
|
|
|
|
|
"三万": preload("uid://dc6sj2holh1gn"),
|
|
|
|
|
"五万": preload("uid://bd12rrssmrdbs"),
|
|
|
|
|
"幺鸡": preload("uid://batbu02i8svf6"),
|
|
|
|
|
"二条": preload("uid://cbn74yc8j72v6"),
|
|
|
|
|
"三条": preload("uid://b66kqhy1mmhc5"),
|
|
|
|
|
"二筒": preload("uid://djefka3gyhxsv"),
|
|
|
|
|
"四筒": preload("uid://da50cog64b0tb"),
|
|
|
|
|
"八筒": preload("uid://cr6404ghilc7u"),
|
|
|
|
|
"九筒": preload("uid://iovhne3h5dqe"),
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
# 回合1-3摸牌:南风B、3万、2筒
|
|
|
|
|
# 回合1-3自动打出的牌(不可换):2万、3万、南风A
|
|
|
|
|
# 密码:替换南风B、4筒、2筒
|
|
|
|
|
# 玩家初始牌型(13张):2筒x1,5万x2,南风Ax1,2万x1,4筒x4,1条x1,2条x1,7筒x1,8筒x1
|
|
|
|
|
# 胜利牌型:2筒x2、5万x3、4筒x2、123条x1、789筒x1
|
|
|
|
|
var initial_cards = ["二筒", "五万", "五万", "南", "二条", "四筒", "四筒", "四筒", "四筒", "一条", "二条", "七筒", "八筒"]
|
|
|
|
|
|
|
|
|
|
# 2万
|
|
|
|
|
# 7筒
|
|
|
|
|
|
|
|
|
|
var freezing = false
|
|
|
|
|
var success = false
|
|
|
|
|
var selected_btn: TextureButton
|
2025-07-09 16:07:36 +00:00
|
|
|
|
|
|
|
|
|
func _ready() -> void:
|
|
|
|
|
layer = GlobalConfig.CANVAS_LAYER_LITTLE_GAME
|
2025-07-10 09:13:31 +00:00
|
|
|
|
_toggle_hightlight_for_all(false)
|
|
|
|
|
stand_right_mahjong.pressed.connect(_on_btn_pressed.bind(stand_right_mahjong))
|
|
|
|
|
stand_right_mahjong.mouse_entered.connect(_toggle_hightlight.bind(stand_right_mahjong, true))
|
|
|
|
|
stand_right_mahjong.mouse_exited.connect(_toggle_hightlight.bind(stand_right_mahjong, false))
|
|
|
|
|
for b in stand_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 _toggel_hover(btn: TextureButton, hovering: bool) -> void:
|
|
|
|
|
if freezing:
|
|
|
|
|
return
|
|
|
|
|
_toggle_hightlight(btn, hovering)
|
|
|
|
|
|
|
|
|
|
func _on_btn_pressed(btn: TextureButton) -> void:
|
|
|
|
|
if freezing:
|
|
|
|
|
return
|
|
|
|
|
if btn != selected_btn:
|
|
|
|
|
if selected_btn:
|
|
|
|
|
_toggle_selected(selected_btn, false)
|
|
|
|
|
_exchange_texture(btn, selected_btn)
|
|
|
|
|
selected_btn = null
|
|
|
|
|
else:
|
|
|
|
|
$SfxSelect.play()
|
|
|
|
|
_toggle_selected(btn, true)
|
|
|
|
|
selected_btn = btn
|
|
|
|
|
else:
|
|
|
|
|
$SfxSelect.play()
|
|
|
|
|
_toggle_selected(btn, false)
|
|
|
|
|
selected_btn = null
|
|
|
|
|
_check_if_success()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _toggle_selected(btn:TextureButton, selected: bool) -> void:
|
|
|
|
|
# 1-14 push up. 15-17 in hand, push down.
|
|
|
|
|
var front := int(btn.name) <= 14
|
|
|
|
|
if (front and selected) or (not front and not selected):
|
|
|
|
|
btn.size_flags_vertical = Control.SIZE_SHRINK_BEGIN
|
|
|
|
|
else:
|
|
|
|
|
btn.size_flags_vertical = Control.SIZE_SHRINK_END
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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_hightlight(btn: TextureButton, hightlight: bool) -> void:
|
|
|
|
|
if null == btn:
|
|
|
|
|
return
|
|
|
|
|
btn.get_node("光束").enabled = hightlight
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func _toggle_hightlight_for_all(hightlighted: bool) -> void:
|
|
|
|
|
if stand_right_mahjong:
|
|
|
|
|
_toggle_hightlight(stand_right_mahjong, hightlighted)
|
|
|
|
|
for b in stand_mahjongs_btn:
|
|
|
|
|
_toggle_hightlight(b, hightlighted)
|
|
|
|
|
for b in hand_mahjongs_btn:
|
|
|
|
|
_toggle_hightlight(b, hightlighted)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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:
|
|
|
|
|
# $SfxSuccess.play()
|
|
|
|
|
# freezing = true
|
|
|
|
|
# SceneManager.disable_prop_item("prop_麻将")
|
|
|
|
|
# SceneManager.disable_prop_item("prop_麻将2")
|
|
|
|
|
# # 下一阶段
|
|
|
|
|
# EventManager.set_stage_if_greater("c03_mahjong_game", 1)
|
|
|
|
|
# hand_success.show()
|
|
|
|
|
# hand_success.modulate.a = 0.0
|
|
|
|
|
# var tween = create_tween()
|
|
|
|
|
# tween.tween_property(hand, "modulate:a", 0.0, 1.5)
|
|
|
|
|
# tween.parallel().tween_property(hand_success, "modulate:a", 1.0, 1.5)
|
|
|
|
|
# tween.tween_interval(3.5)
|
|
|
|
|
# await tween.finished
|
|
|
|
|
# exit.emit(true)
|
|
|
|
|
|