Feature: ready button

This commit is contained in:
2020-04-30 11:52:13 +08:00
parent 79c20dc78c
commit 46bbfef5cc
4 changed files with 278 additions and 19 deletions
+8
View File
@@ -35,6 +35,14 @@ class Tile:
const BOTTOM_DROP_THICK = 32
const BOTTOM_SHOWN_SEP = 20
const RESULT_SCALE = 0.7
const RESULT_HEIGHT = 120
const RESULT_HAND_HEIGHT = 118*RESULT_SCALE
const RESULT_HAND_WIDTH = 76*RESULT_SCALE
const RESULT_SHOWN_HEIGHT = BOTTOM_DROP_HEIGHT*RESULT_SCALE
const RESULT_SHOWN_WIDTH = BOTTOM_DROP_WIDTH*RESULT_SCALE
class Screen:
const WIDTH = 1920
const HEIGHT = 1080
+153
View File
@@ -0,0 +1,153 @@
extends PopupPanel
var hand_texture
var shown_texture
onready var first_nickname = $Container/First/Label
onready var second_nickname = $Container/Second/Label
onready var third_nickname = $Container/Third/Label
onready var fourth_nickname = $Container/Fourth/Label
# Called when the node enters the scene tree for the first time.
func _ready():
hand_texture = ImageTexture.new()
hand_texture = load("res://Asset/Tile/HandinTilesSheet.png")
shown_texture = Image.new()
shown_texture = load("res://Asset/Tile/DropTileBottom.png")
func show_result(msg):
set_first(msg)
set_second(msg)
set_third(msg)
set_fourth(msg)
popup_centered()
func set_first(msg):
first_nickname.text = msg["user_list"][0]["nickname"]
var hand = msg["player_tile"][0]["hand_tiles"]
var shown = msg["player_tile"][0]["shown_tiles"]
var tile_pos = first_nickname.rect_size.x
for h in hand:
var tile = get_hand_instance(h["suit"], h["number"])
tile.position = Vector2(tile_pos, 0)
$Container/First.add_child(tile)
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
if shown == null:
return
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
for s in shown:
for t in s["tiles"]:
var tile = get_shown_instance(t["suit"], t["number"])
tile.position = Vector2(tile_pos, 0)
$Container/First.add_child(tile)
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
var winner = msg["winner"]
if winner == 0:
pass
func set_second(msg):
var y = 1 * Constants.Tile.RESULT_HEIGHT
second_nickname.text = msg["user_list"][1]["nickname"]
var hand = msg["player_tile"][1]["hand_tiles"]
var shown = msg["player_tile"][1]["shown_tiles"]
var tile_pos = 0
for h in hand:
var tile = get_hand_instance(h["suit"], h["number"])
tile.position = Vector2(tile_pos, y)
$Container/Second.add_child(tile)
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
if shown == null:
return
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
for s in shown:
for t in s["tiles"]:
var tile = get_shown_instance(t["suit"], t["number"])
tile.position = Vector2(tile_pos, y)
$Container/Second.add_child(tile)
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
var winner = msg["winner"]
if winner == 1:
pass
func set_third(msg):
var y = 2 * Constants.Tile.RESULT_HEIGHT
third_nickname.text = msg["user_list"][2]["nickname"]
var hand = msg["player_tile"][2]["hand_tiles"]
var shown = msg["player_tile"][2]["shown_tiles"]
var tile_pos = 0
for h in hand:
var tile = get_hand_instance(h["suit"], h["number"])
tile.position = Vector2(tile_pos, y)
$Container/Third.add_child(tile)
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
if shown == null:
return
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
for s in shown:
for t in s["tiles"]:
var tile = get_shown_instance(t["suit"], t["number"])
tile.position = Vector2(tile_pos, y)
$Container/Third.add_child(tile)
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
var winner = msg["winner"]
if winner == 2:
pass
func set_fourth(msg):
var y = 3 * Constants.Tile.RESULT_HEIGHT
fourth_nickname.text = msg["user_list"][3]["nickname"]
var hand = msg["player_tile"][3]["hand_tiles"]
var shown = msg["player_tile"][3]["shown_tiles"]
var tile_pos = 0
for h in hand:
var tile = get_hand_instance(h["suit"], h["number"])
tile.position = Vector2(tile_pos, y)
$Container/Fourth.add_child(tile)
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
if shown == null:
return
tile_pos += Constants.Tile.RESULT_HAND_WIDTH
for s in shown:
for t in s["tiles"]:
var tile = get_shown_instance(t["suit"], t["number"])
tile.position = Vector2(tile_pos, y)
$Container/Fourth.add_child(tile)
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
tile_pos += Constants.Tile.RESULT_SHOWN_WIDTH
var winner = msg["winner"]
if winner == 3:
pass
func get_hand_instance(suit, number):
var tile = Sprite.new()
tile.texture = hand_texture
tile.vframes = 5
tile.hframes = 9
tile.frame_coords = Vector2(number-1, suit)
tile.scale = Vector2(Constants.Tile.RESULT_SCALE, Constants.Tile.RESULT_SCALE)
return tile
func get_shown_instance(suit, number):
var tile = Sprite.new()
tile.texture = shown_texture
tile.vframes = 5
tile.hframes = 9
tile.frame_coords = Vector2(number-1, suit)
tile.scale = Vector2(Constants.Tile.RESULT_SCALE, Constants.Tile.RESULT_SCALE)
return tile
func get_avatar_path(gender):
var path = ""
if gender == Message.gender.FEMALE:
path = "res://Asset/Avatar/Female.png"
elif gender == Message.gender.MALE:
path = "res://Asset/Avatar/Male.png"
+7 -1
View File
@@ -20,7 +20,6 @@ func _ready():
ConnManager.connect("recv_get_ready_msg", self, "handle_get_ready_msg")
ConnManager.connect("recv_chat_msg", self, "handle_chat_msg")
$ReadyButton.connect("pressed", self, "handle_ready_pressed")
$ChatField.connect("send_chat", self, "handle_send_chat_pressed")
@@ -57,10 +56,13 @@ func handle_table_order_msg(msg):
func handle_game_result_msg(msg):
var winner = int(msg["winner"])
$PopupPanel.show_result(msg)
print_debug("winner: ", winner)
func handle_get_ready_msg(msg):
# TODO: show ready state
if msg["ready_list"][my_table_order]:
$ReadyButton.hide()
$BottomAvatar.show_ready(msg["ready_list"][my_table_order])
$RightAvatar.show_ready(msg["ready_list"][(my_table_order+1)%4])
$OppoAvatar.show_ready(msg["ready_list"][(my_table_order+2)%4])
@@ -475,3 +477,7 @@ func _on_bottomshown_pressed():
$OppoShown.show_tiles(json_tmp.result)
$LeftShown.show_tiles(json_tmp.result)
$RightShown.show_tiles(json_tmp.result)
+110 -18
View File
@@ -1,4 +1,4 @@
[gd_scene load_steps=58 format=2]
[gd_scene load_steps=62 format=2]
[ext_resource path="res://Table/OppositeDropArea.gd" type="Script" id=1]
[ext_resource path="res://Table/PlayerAction.gd" type="Script" id=2]
@@ -51,16 +51,18 @@
[ext_resource path="res://Table/RightAvatar.gd" type="Script" id=49]
[ext_resource path="res://Asset/Chat/OppoChat.png" type="Texture" id=50]
[ext_resource path="res://Table/OppoAvatar.gd" type="Script" id=51]
[ext_resource path="res://Asset/PopupBackground.png" type="Texture" id=52]
[ext_resource path="res://Table/PopupPanel.gd" type="Script" id=53]
[sub_resource type="DynamicFont" id=1]
size = 24
font_data = ExtResource( 41 )
[sub_resource type="DynamicFont" id=5]
[sub_resource type="DynamicFont" id=2]
size = 32
font_data = ExtResource( 41 )
[sub_resource type="DynamicFont" id=6]
[sub_resource type="DynamicFont" id=3]
size = 32
font_data = ExtResource( 41 )
@@ -68,11 +70,19 @@ font_data = ExtResource( 41 )
size = 32
font_data = ExtResource( 41 )
[sub_resource type="StyleBoxTexture" id=2]
[sub_resource type="StyleBoxTexture" id=5]
texture = ExtResource( 44 )
region_rect = Rect2( 0, 0, 660, 60 )
[sub_resource type="DynamicFont" id=3]
[sub_resource type="DynamicFont" id=6]
size = 32
font_data = ExtResource( 41 )
[sub_resource type="StyleBoxTexture" id=7]
texture = ExtResource( 52 )
region_rect = Rect2( 0, 0, 640, 569 )
[sub_resource type="DynamicFont" id=8]
size = 32
font_data = ExtResource( 41 )
@@ -333,14 +343,17 @@ margin_bottom = 37.0
text = "BottomShown"
[node name="ReadyButton" type="TextureButton" parent="."]
visible = false
margin_left = 896.551
margin_top = 603.429
margin_right = 1132.55
margin_bottom = 702.429
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = 833.0
margin_top = 614.0
margin_right = 1069.0
margin_bottom = 713.0
texture_normal = ExtResource( 32 )
__meta__ = {
"_edit_use_anchors_": true
"_edit_use_anchors_": false
}
[node name="ControlButtons" type="HBoxContainer" parent="."]
@@ -447,7 +460,7 @@ margin_left = 17.08
margin_top = 23.0
margin_right = 260.08
margin_bottom = 154.0
custom_fonts/font = SubResource( 5 )
custom_fonts/font = SubResource( 2 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
align = 1
valign = 1
@@ -576,7 +589,7 @@ margin_left = 30.0
margin_top = 75.0
margin_right = 321.0
margin_bottom = 197.0
custom_fonts/font = SubResource( 6 )
custom_fonts/font = SubResource( 3 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
align = 1
valign = 1
@@ -677,19 +690,97 @@ __meta__ = {
}
[node name="LineEdit" type="LineEdit" parent="ChatField"]
margin_right = 422.0
margin_right = 423.0
margin_bottom = 51.0
size_flags_horizontal = 3
custom_styles/normal = SubResource( 2 )
custom_fonts/font = SubResource( 3 )
custom_styles/normal = SubResource( 5 )
custom_fonts/font = SubResource( 6 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
placeholder_text = "按回车发送消息"
[node name="SendButton" type="TextureButton" parent="ChatField"]
margin_left = 430.0
margin_right = 532.0
margin_left = 431.0
margin_right = 533.0
margin_bottom = 51.0
texture_normal = ExtResource( 45 )
[node name="PopupPanel" type="PopupPanel" parent="."]
margin_left = 493.0
margin_top = 251.0
margin_right = 1426.0
margin_bottom = 690.0
custom_styles/panel = SubResource( 7 )
script = ExtResource( 53 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Container" type="VBoxContainer" parent="PopupPanel"]
margin_top = 15.0
margin_right = 933.0
margin_bottom = 454.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="First" type="HBoxContainer" parent="PopupPanel/Container"]
margin_right = 933.0
margin_bottom = 48.0
[node name="Label" type="Label" parent="PopupPanel/Container/First"]
margin_bottom = 48.0
custom_fonts/font = SubResource( 8 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
[node name="New" type="HBoxContainer" parent="PopupPanel/Container/First"]
margin_left = 8.0
margin_right = 8.0
margin_bottom = 48.0
[node name="Second" type="HBoxContainer" parent="PopupPanel/Container"]
margin_top = 56.0
margin_right = 933.0
margin_bottom = 104.0
[node name="Label" type="Label" parent="PopupPanel/Container/Second"]
margin_bottom = 48.0
custom_fonts/font = SubResource( 8 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
[node name="New" type="HBoxContainer" parent="PopupPanel/Container/Second"]
margin_left = 8.0
margin_right = 8.0
margin_bottom = 48.0
[node name="Third" type="HBoxContainer" parent="PopupPanel/Container"]
margin_top = 112.0
margin_right = 933.0
margin_bottom = 160.0
[node name="Label" type="Label" parent="PopupPanel/Container/Third"]
margin_bottom = 48.0
custom_fonts/font = SubResource( 8 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
[node name="New" type="HBoxContainer" parent="PopupPanel/Container/Third"]
margin_left = 8.0
margin_right = 8.0
margin_bottom = 48.0
[node name="Fourth" type="HBoxContainer" parent="PopupPanel/Container"]
margin_top = 168.0
margin_right = 933.0
margin_bottom = 216.0
[node name="Label" type="Label" parent="PopupPanel/Container/Fourth"]
margin_bottom = 48.0
custom_fonts/font = SubResource( 8 )
custom_colors/font_color = Color( 0, 0, 0, 1 )
[node name="New" type="HBoxContainer" parent="PopupPanel/Container/Fourth"]
margin_left = 8.0
margin_right = 8.0
margin_bottom = 48.0
[connection signal="pressed" from="VBoxContainer/TestButtons/StartButton" to="." method="_on_Button9_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button" to="." method="_on_Button_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button3" to="." method="_on_Button3_pressed"]
@@ -700,6 +791,7 @@ texture_normal = ExtResource( 45 )
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button7" to="." method="_on_rightdrop_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button8" to="." method="_on_oppodrop_pressed"]
[connection signal="pressed" from="VBoxContainer/HBoxContainer/Button9" to="." method="_on_bottomshown_pressed"]
[connection signal="pressed" from="ReadyButton" to="." method="handle_ready_pressed"]
[connection signal="pressed" from="ControlButtons/MusicButton" to="." method="handle_music_button_clicked"]
[connection signal="pressed" from="ControlButtons/SoundButton" to="." method="handle_sound_button_clicked"]
[connection signal="timeout" from="RightAvatar/Timer" to="RightAvatar" method="_on_Timer_timeout"]