bet input now responds to inputs with (error) messages
This commit is contained in:
@@ -186,7 +186,6 @@ disabled = true
|
|||||||
text = "Play Card"
|
text = "Play Card"
|
||||||
|
|
||||||
[node name="BetContainer" type="VBoxContainer" parent="HBoxContainer/GameUI"]
|
[node name="BetContainer" type="VBoxContainer" parent="HBoxContainer/GameUI"]
|
||||||
visible = false
|
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
anchors_preset = 2
|
anchors_preset = 2
|
||||||
anchor_top = 1.0
|
anchor_top = 1.0
|
||||||
@@ -197,7 +196,10 @@ offset_right = 327.0
|
|||||||
offset_bottom = -114.0
|
offset_bottom = -114.0
|
||||||
grow_vertical = 0
|
grow_vertical = 0
|
||||||
|
|
||||||
[node name="BetInput" type="LineEdit" parent="HBoxContainer/GameUI/BetContainer" node_paths=PackedStringArray("submit_button")]
|
[node name="DisallowedBetLabel" type="Label" parent="HBoxContainer/GameUI/BetContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="BetInput" type="LineEdit" parent="HBoxContainer/GameUI/BetContainer" node_paths=PackedStringArray("error_label", "disallowed_bet_label", "submit_button")]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
max_length = 2
|
max_length = 2
|
||||||
context_menu_enabled = false
|
context_menu_enabled = false
|
||||||
@@ -207,12 +209,18 @@ shortcut_keys_enabled = false
|
|||||||
middle_mouse_paste_enabled = false
|
middle_mouse_paste_enabled = false
|
||||||
drag_and_drop_selection_enabled = false
|
drag_and_drop_selection_enabled = false
|
||||||
script = ExtResource("4_vef74")
|
script = ExtResource("4_vef74")
|
||||||
|
error_label = NodePath("../ErrorLabel")
|
||||||
|
disallowed_bet_label = NodePath("../DisallowedBetLabel")
|
||||||
submit_button = NodePath("../SubmitBetButton")
|
submit_button = NodePath("../SubmitBetButton")
|
||||||
|
|
||||||
[node name="SubmitBetButton" type="Button" parent="HBoxContainer/GameUI/BetContainer"]
|
[node name="SubmitBetButton" type="Button" parent="HBoxContainer/GameUI/BetContainer"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
text = "submit bet"
|
text = "submit bet"
|
||||||
|
|
||||||
|
[node name="ErrorLabel" type="Label" parent="HBoxContainer/GameUI/BetContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_colors/font_color = Color(1, 0.21, 0.21, 1)
|
||||||
|
|
||||||
[node name="Label" type="Label" parent="HBoxContainer/GameUI"]
|
[node name="Label" type="Label" parent="HBoxContainer/GameUI"]
|
||||||
visible = false
|
visible = false
|
||||||
layout_mode = 1
|
layout_mode = 1
|
||||||
@@ -303,6 +311,7 @@ playing_card_scene = ExtResource("6_eow3j")
|
|||||||
[connection signal="new_round_started" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
|
[connection signal="new_round_started" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_new_round_started"]
|
||||||
[connection signal="notify_play_card_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
|
[connection signal="notify_play_card_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_notify_play_card_request"]
|
||||||
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI" method="_on_web_client_tcp_received_bet_request"]
|
||||||
|
[connection signal="received_bet_request" from="WebClientTCP" to="HBoxContainer/GameUI/BetContainer/BetInput" method="_on_web_client_tcp_received_bet_request"]
|
||||||
[connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
[connection signal="received_chat_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_chat_message"]
|
||||||
[connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
|
[connection signal="received_client_id" from="WebClientTCP" to="EnvironmentManager" method="_on_web_client_tcp_received_client_id"]
|
||||||
[connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
|
[connection signal="received_connection_message" from="WebClientTCP" to="HBoxContainer/ClientInterface" method="_on_web_client_tcp_received_connection_message"]
|
||||||
|
|||||||
+22
-1
@@ -4,14 +4,35 @@ extends LineEdit
|
|||||||
## Only allows numeric input, discards everything else.
|
## Only allows numeric input, discards everything else.
|
||||||
|
|
||||||
var _regex: RegEx = RegEx.new()
|
var _regex: RegEx = RegEx.new()
|
||||||
|
var _disallowed_bet: String = "3"
|
||||||
|
@export var error_label: Label
|
||||||
|
@export var disallowed_bet_label: Label
|
||||||
@export var submit_button: Button
|
@export var submit_button: Button
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
_regex.compile("[^\\d]")
|
_regex.compile("[^\\d]")
|
||||||
submit_button.disabled = true
|
submit_button.disabled = true
|
||||||
|
|
||||||
|
func set_disallowed_bet(bet: int) -> void:
|
||||||
|
_disallowed_bet = str(bet)
|
||||||
|
|
||||||
func _on_text_changed(new_text: String) -> void:
|
func _on_text_changed(new_text: String) -> void:
|
||||||
if new_text.is_empty() or _regex.search(new_text):
|
if new_text.is_empty():
|
||||||
submit_button.disabled = true
|
submit_button.disabled = true
|
||||||
|
error_label.text = ""
|
||||||
|
elif _regex.search(new_text):
|
||||||
|
submit_button.disabled = true
|
||||||
|
error_label.text = "Numbers only!"
|
||||||
|
elif new_text == _disallowed_bet:
|
||||||
|
submit_button.disabled = true
|
||||||
|
error_label.text = "Not allowed!"
|
||||||
else:
|
else:
|
||||||
submit_button.disabled = false
|
submit_button.disabled = false
|
||||||
|
error_label.text = ""
|
||||||
|
|
||||||
|
func _on_web_client_tcp_received_bet_request(disallowed_bet: int) -> void:
|
||||||
|
set_disallowed_bet(disallowed_bet)
|
||||||
|
if disallowed_bet == -1:
|
||||||
|
disallowed_bet_label.text = "Bet anything"
|
||||||
|
else:
|
||||||
|
disallowed_bet_label.text = "Disallowed bet: {bet}".format({"bet": disallowed_bet})
|
||||||
|
|||||||
Reference in New Issue
Block a user