From 22beaaecc27af035e1b5abb8cd2adb19227992bb Mon Sep 17 00:00:00 2001 From: c-my Date: Fri, 20 Mar 2020 18:39:10 +0800 Subject: [PATCH] fixed ChowPanel --- Constants.gd | 9 ++++++++- Table/ChowPanel.gd | 7 ++++--- Table/LeftChow.gd | 3 +++ Table/LeftDropArea.gd | 1 - Table/MidChow.gd | 3 +++ Table/OppoShown.gd | 2 +- Table/RightChow.gd | 3 +++ Table/Table.gd | 19 +++++++++++++------ Table/Table.tscn | 25 +++++++++++++------------ 9 files changed, 48 insertions(+), 24 deletions(-) diff --git a/Constants.gd b/Constants.gd index 3cb2b6f..260ef4e 100644 --- a/Constants.gd +++ b/Constants.gd @@ -11,9 +11,12 @@ class Tile: const HEIGHT = 118*BOTTOM_HAND_SCALE const WIDTH = 76*BOTTOM_HAND_SCALE const SELECT_HEIGHT = 30 - const CHOW_WIDTH = 76 + const CHOW_SCALE = 1.3 + const CHOW_WIDTH = 76*CHOW_SCALE + const CHOW_HEIGHT = 118*CHOW_SCALE const OPPOSITE_HAND_WIDTH = 79 + const OPPOSITE_HAND_HEIGHT = 120 const OPPOSITE_DROP_WIDTH = 76 const OPPOSITE_DROP_HEIGHT = 118 @@ -51,6 +54,10 @@ class Table: class Timer_Table: enum DIRECTION {NONE, BOTTOM, RIGHT, OPPOSITE, LEFT} + +class Chow_Panel: + const SEPARATION = 30 + const MARGIN_BOTTOM = 350 # Called when the node enters the scene tree for the first time. diff --git a/Table/ChowPanel.gd b/Table/ChowPanel.gd index a33814d..6764a4c 100644 --- a/Table/ChowPanel.gd +++ b/Table/ChowPanel.gd @@ -1,6 +1,5 @@ extends Node2D -var sep = 10 # Declare member variables here. Examples: # var a = 2 @@ -13,7 +12,7 @@ func _ready(): func show_panel(suit, number, types): - if len(types)==1: + if types.size()==1: hide() hide_all() for t in types: @@ -27,7 +26,9 @@ func show_panel(suit, number, types): for child in get_children(): if child.visible: child.position = Vector2(pos, 0) - pos += sep+3*Constants.Tile.CHOW_WIDTH + pos += Constants.Chow_Panel.SEPARATION+3*Constants.Tile.CHOW_WIDTH + position = Vector2((Constants.Screen.WIDTH-pos)/2, Constants.Screen.HEIGHT - Constants.Chow_Panel.MARGIN_BOTTOM - Constants.Tile.CHOW_HEIGHT) + show() func hide_all(): $LeftChow.hide() diff --git a/Table/LeftChow.gd b/Table/LeftChow.gd index 6bc2e26..e29794f 100644 --- a/Table/LeftChow.gd +++ b/Table/LeftChow.gd @@ -26,6 +26,7 @@ func get_tile_instance(suit, number): tile.vframes = 5 tile.hframes = 9 tile.frame_coords = Vector2(number-1, suit) + tile.scale = Vector2(Constants.Tile.CHOW_SCALE, Constants.Tile.CHOW_SCALE) return tile @@ -35,6 +36,8 @@ func clear_tiles(): child.queue_free() func _input(event): + if !visible: + return if (event is InputEventMouseButton or event is InputEventScreenTouch) and event.pressed: if Rect2(0,0,Constants.Tile.CHOW_WIDTH*3, Constants.Tile.HEIGHT).has_point(to_local(event.position)): emit_signal("pressed") diff --git a/Table/LeftDropArea.gd b/Table/LeftDropArea.gd index 3526001..eb0f38a 100644 --- a/Table/LeftDropArea.gd +++ b/Table/LeftDropArea.gd @@ -32,7 +32,6 @@ func show_tiles(): for i in range(get_children().size()): get_children()[i].position = Vector2(-i*Constants.Tile.SIDE_DROP_DIFF, i*(Constants.Tile.SIDE_DROP_HEIGHT-Constants.Tile.SIDE_DROP_THICK)) - pass func clear_tiles(): for tile in get_children(): diff --git a/Table/MidChow.gd b/Table/MidChow.gd index 4fc6caf..dfc7c60 100644 --- a/Table/MidChow.gd +++ b/Table/MidChow.gd @@ -26,6 +26,7 @@ func get_tile_instance(suit, number): tile.vframes = 5 tile.hframes = 9 tile.frame_coords = Vector2(number-1, suit) + tile.scale = Vector2(Constants.Tile.CHOW_SCALE, Constants.Tile.CHOW_SCALE) return tile @@ -35,6 +36,8 @@ func clear_tiles(): child.queue_free() func _input(event): + if !visible: + return if (event is InputEventMouseButton or event is InputEventScreenTouch) and event.pressed: if Rect2(0,0,Constants.Tile.CHOW_WIDTH*3, Constants.Tile.HEIGHT).has_point(to_local(event.position)): emit_signal("pressed") diff --git a/Table/OppoShown.gd b/Table/OppoShown.gd index ad820bc..cea085d 100644 --- a/Table/OppoShown.gd +++ b/Table/OppoShown.gd @@ -15,7 +15,7 @@ func _ready(): hide_texture = ImageTexture.new() hide_texture = load("res://Asset/Tile/HideTileBottom.png") position = Vector2(Constants.Screen.WIDTH-Constants.Table.BOTTOM_SHOWN_MARGIN_X- - 3*Constants.Tile.BOTTOM_DROP_WIDTH, Constants.Table.BOTTOM_SHOWN_MARGIN_Y) + 3*Constants.Tile.BOTTOM_DROP_WIDTH, Constants.Table.BOTTOM_SHOWN_MARGIN_Y+Constants.Tile.OPPOSITE_HAND_HEIGHT) func show_tiles(tiles): diff --git a/Table/RightChow.gd b/Table/RightChow.gd index 557c95c..6d6a641 100644 --- a/Table/RightChow.gd +++ b/Table/RightChow.gd @@ -26,6 +26,7 @@ func get_tile_instance(suit, number): tile.vframes = 5 tile.hframes = 9 tile.frame_coords = Vector2(number-1, suit) + tile.scale = Vector2(Constants.Tile.CHOW_SCALE, Constants.Tile.CHOW_SCALE) return tile @@ -35,6 +36,8 @@ func clear_tiles(): child.queue_free() func _input(event): + if !visible: + return if (event is InputEventMouseButton or event is InputEventScreenTouch) and event.pressed: if Rect2(0,0,Constants.Tile.CHOW_WIDTH*3, Constants.Tile.HEIGHT).has_point(to_local(event.position)): emit_signal("pressed") diff --git a/Table/Table.gd b/Table/Table.gd index 9a4b45a..3773e68 100644 --- a/Table/Table.gd +++ b/Table/Table.gd @@ -37,7 +37,7 @@ func handle_game_msg(msg): set_chow_panel() current_msg = msg just_clicked = false - # 处理逻辑 + func handle_chow(): var chow_types = current_msg["chow_types"] @@ -48,19 +48,26 @@ func handle_chow(): else: # show chow panel var suit = current_msg["current_tile"]["suit"] var number = current_msg["current_tile"]["number"] + print_debug("show chow panel: ", suit, number,"types: ",chow_types) $ChowPanel.show_panel(suit, number, chow_types) func handle_left_chow(): + if current_msg == null: + return var suit = current_msg["current_tile"]["suit"] var number = current_msg["current_tile"]["number"] ConnManager.send_chow({"suit":suit,"number":number}, my_table_order ,Message.chow_type.LEFT) func handle_mid_chow(): + if current_msg == null: + return var suit = current_msg["current_tile"]["suit"] var number = current_msg["current_tile"]["number"] ConnManager.send_chow({"suit":suit,"number":number}, my_table_order ,Message.chow_type.MID) func handle_right_chow(): + if current_msg == null: + return var suit = current_msg["current_tile"]["suit"] var number = current_msg["current_tile"]["number"] ConnManager.send_chow({"suit":suit,"number":number}, my_table_order ,Message.chow_type.RIGHT) @@ -239,25 +246,25 @@ func _on_righthand_pressed(): func _on_bottomdrop_pressed(): - $BottomDropArea.add_tile(randi()%3, randi()%9) + $BottomDropArea.add_tile(randi()%3, randi()%9+1) $BottomDropArea.show_tiles() func _on_leftdrop_pressed(): - $LeftDropArea.add_tile(randi()%3, randi()%9) + $LeftDropArea.add_tile(randi()%3, randi()%9+1) $LeftDropArea.show_tiles() func _on_rightdrop_pressed(): - $RightDropArea.add_tile(randi()%3, randi()%9) + $RightDropArea.add_tile(randi()%3, randi()%9+1) $RightDropArea.show_tiles() func _on_oppodrop_pressed(): $RightDropArea.clear_tiles(); - $OppositeDropArea.add_tile(randi()%3, randi()%9) + $OppositeDropArea.add_tile(randi()%3, randi()%9+1) $OppositeDropArea.show_tiles() - $ChowPanel.show_panel(1,3,[0,1,2]) + $ChowPanel.show_panel(0,6,[0,1,2]) func _on_bottomshown_pressed(): diff --git a/Table/Table.tscn b/Table/Table.tscn index 9dbe2b6..4f44368 100644 --- a/Table/Table.tscn +++ b/Table/Table.tscn @@ -177,6 +177,19 @@ margin_right = 765.0 margin_bottom = 115.0 texture_normal = ExtResource( 11 ) +[node name="ChowPanel" type="Node2D" parent="."] +position = Vector2( 684.956, 530.841 ) +script = ExtResource( 30 ) + +[node name="LeftChow" type="Node2D" parent="ChowPanel"] +script = ExtResource( 27 ) + +[node name="MidChow" type="Node2D" parent="ChowPanel"] +script = ExtResource( 28 ) + +[node name="RightChow" type="Node2D" parent="ChowPanel"] +script = ExtResource( 29 ) + [node name="VBoxContainer" type="VBoxContainer" parent="."] margin_right = 40.0 margin_bottom = 40.0 @@ -291,18 +304,6 @@ margin_left = 681.0 margin_right = 782.0 margin_bottom = 20.0 text = "BottomShown" - -[node name="ChowPanel" type="Node2D" parent="."] -script = ExtResource( 30 ) - -[node name="LeftChow" type="Node2D" parent="ChowPanel"] -script = ExtResource( 27 ) - -[node name="MidChow" type="Node2D" parent="ChowPanel"] -script = ExtResource( 28 ) - -[node name="RightChow" type="Node2D" parent="ChowPanel"] -script = ExtResource( 29 ) [connection signal="pressed" from="VBoxContainer/TestButtons/One" to="." method="_on_Button4_pressed"] [connection signal="pressed" from="VBoxContainer/TestButtons/Two" to="." method="_on_Button5_pressed"] [connection signal="pressed" from="VBoxContainer/TestButtons/Three" to="." method="_on_Button6_pressed"]