Update game UI from OptionButton to LineEdit

Replaced multiple OptionButton instances with LineEdit for input fields, including three_of_a_kind, four_of_a_kind, and chance. Updated related scoring logic and adjusted UI themes and assets to reflect the new input method.
This commit is contained in:
Yadciel 2024-09-21 12:30:37 +02:00
parent 59b62d0e72
commit 59f13e7318
6 changed files with 76 additions and 43 deletions

View File

@ -8,13 +8,13 @@ var three : OptionButton
var four : OptionButton
var five : OptionButton
var six : OptionButton
var three_of_a_kind : OptionButton
var four_of_a_kind : OptionButton
var three_of_a_kind : LineEdit
var four_of_a_kind : LineEdit
var full_house : OptionButton
var small_straight : OptionButton
var large_straight : OptionButton
var yahtzee : Button
var chance : OptionButton
var chance : LineEdit
var bonus : Label
var score : Label
@ -31,10 +31,8 @@ func _ready():
four = get_node("ScrollContainer/VBoxContainer/Four/HBoxContainer/OptionButton")
five = get_node("ScrollContainer/VBoxContainer/Five/HBoxContainer/OptionButton")
six = get_node("ScrollContainer/VBoxContainer/Six/HBoxContainer/OptionButton")
three_of_a_kind = get_node("ScrollContainer/VBoxContainer/Three_of_a_kind/HBoxContainer/OptionButton")
add_items(three_of_a_kind)
four_of_a_kind = get_node("ScrollContainer/VBoxContainer/Four_of_a_Kind/HBoxContainer/OptionButton")
add_items(four_of_a_kind)
three_of_a_kind = get_node("ScrollContainer/VBoxContainer/Three_of_a_kind/HBoxContainer/LineEdit")
four_of_a_kind = get_node("ScrollContainer/VBoxContainer/Four_of_a_Kind/HBoxContainer/LineEdit")
full_house = get_node("ScrollContainer/VBoxContainer/Full_House/HBoxContainer/OptionButton")
full_house.add_item("")
full_house.add_item("-")
@ -45,8 +43,7 @@ func _ready():
add_items_to_large_straight(large_straight)
yahtzee = get_node("ScrollContainer/VBoxContainer/yahtzee/HBoxContainer/ButtonYahtzee")
bonus = get_node("ScrollContainer/VBoxContainer/Bonus/HBoxContainer/LabelScore")
chance = get_node("ScrollContainer/VBoxContainer/chance/HBoxContainer/OptionButton")
add_items(chance)
chance = get_node("ScrollContainer/VBoxContainer/chance/HBoxContainer/LineEdit")
score = get_node("ScrollContainer/VBoxContainer/Score/HBoxContainer/LabelScore")
pass # Replace with function body.
@ -90,13 +87,13 @@ func calc_score():
int(four.get_item_text(four.get_selected_id())) +
int(five.get_item_text(five.get_selected_id())) +
int(six.get_item_text(six.get_selected_id())) +
int(three_of_a_kind.get_item_text(three_of_a_kind.get_selected_id())) +
int(four_of_a_kind.get_item_text(four_of_a_kind.get_selected_id())) +
int(three_of_a_kind.get_text()) +
int(four_of_a_kind.get_text()) +
int(full_house.get_item_text(full_house.get_selected_id())) +
int(small_straight.get_item_text(small_straight.get_selected_id())) +
int(large_straight.get_item_text(large_straight.get_selected_id())) +
int(yahtzee.text) +
int(chance.get_item_text(chance.get_selected_id())) +
int(chance.get_text()) +
int(bonus.text))
score.text = str(players[currentPlayer].score)
@ -108,13 +105,16 @@ func load_stats():
four.select(players[currentPlayer].four)
five.select(players[currentPlayer].five)
six.select(players[currentPlayer].six)
three_of_a_kind.select(players[currentPlayer].three_of_a_kind)
four_of_a_kind.select(players[currentPlayer].four_of_a_kind)
three_of_a_kind.text = str(players[currentPlayer].three_of_a_kind)
four_of_a_kind.text = str(players[currentPlayer].four_of_a_kind)
full_house.select(players[currentPlayer].full_house)
small_straight.select(players[currentPlayer].small_straight)
large_straight.select(players[currentPlayer].large_straight)
yahtzee.text = str(players[currentPlayer].yahtzee)
chance.select(players[currentPlayer].chance)
if(players[currentPlayer].yahtzee != 0):
yahtzee.text = str(players[currentPlayer].yahtzee)
else:
yahtzee.text = str("+")
chance.text = str(players[currentPlayer].chance)
bonus.text = str(players[currentPlayer].bonus)
pass
@ -126,15 +126,28 @@ func save():
players[currentPlayer].four = four.get_selected_id()
players[currentPlayer].five = five.get_selected_id()
players[currentPlayer].six = six.get_selected_id()
players[currentPlayer].three_of_a_kind = int(three_of_a_kind.get_selected_id())
players[currentPlayer].four_of_a_kind = int(four_of_a_kind.get_selected_id())
players[currentPlayer].three_of_a_kind = three_of_a_kind.get_text()
players[currentPlayer].four_of_a_kind = four_of_a_kind.get_text()
players[currentPlayer].full_house = int(full_house.get_selected_id())
players[currentPlayer].small_straight = int(small_straight.get_selected_id())
players[currentPlayer].large_straight = int(large_straight.get_selected_id())
players[currentPlayer].yahtzee = int(yahtzee.text)
players[currentPlayer].bonus = int(bonus.text)
players[currentPlayer].chance = int(chance.get_selected_id())
players[currentPlayer].score = players[currentPlayer].one + players[currentPlayer].two + players[currentPlayer].three + players[currentPlayer].four + players[currentPlayer].five + players[currentPlayer].six + players[currentPlayer].three_of_a_kind + players[currentPlayer].four_of_a_kind + players[currentPlayer].full_house + players[currentPlayer].small_straight + players[currentPlayer].large_straight + players[currentPlayer].yahtzee + players[currentPlayer].chance + players[currentPlayer].bonus
players[currentPlayer].chance = chance.get_text()
players[currentPlayer].score = (players[currentPlayer].one +
players[currentPlayer].two +
players[currentPlayer].three +
players[currentPlayer].four +
players[currentPlayer].five +
players[currentPlayer].six +
int(players[currentPlayer].three_of_a_kind) +
int(players[currentPlayer].four_of_a_kind) +
players[currentPlayer].full_house +
players[currentPlayer].small_straight +
players[currentPlayer].large_straight +
players[currentPlayer].yahtzee +
int(players[currentPlayer].chance) +
players[currentPlayer].bonus)
pass
func _on_button_left_pressed():
@ -158,6 +171,7 @@ func add_items_to_large_straight(oButton: OptionButton):
oButton.add_item("-")
oButton.add_item("40")
pass # Replace with function body.
func add_items(oButton: OptionButton):
oButton.add_item("")
oButton.add_item("-")
@ -243,7 +257,10 @@ func _on_button_yahtzee_pressed():
func _on_button_yahtzee_minus_pressed():
Player_Manger.get_players()[currentPlayer].yahtzee -= 50
yahtzee.text = str(Player_Manger.get_players()[currentPlayer].yahtzee)
if(Player_Manger.get_players()[currentPlayer].yahtzee != 0):
yahtzee.text = str(Player_Manger.get_players()[currentPlayer].yahtzee)
else:
yahtzee.text = str("+")
pass # Replace with function body.

View File

@ -41,6 +41,7 @@ offset_top = -1.44002
offset_right = 8.0
grow_horizontal = 2
grow_vertical = 2
theme = ExtResource("3_hdjql")
follow_focus = true
horizontal_scroll_mode = 0
script = ExtResource("2_xxo3x")
@ -437,14 +438,13 @@ text = "Three of a kind"
horizontal_alignment = 1
vertical_alignment = 1
[node name="OptionButton" type="OptionButton" parent="ScrollContainer/VBoxContainer/Three_of_a_kind/HBoxContainer"]
[node name="LineEdit" type="LineEdit" parent="ScrollContainer/VBoxContainer/Three_of_a_kind/HBoxContainer"]
custom_minimum_size = Vector2(250, 150)
layout_mode = 2
theme = ExtResource("3_hdjql")
theme_override_font_sizes/font_size = 50
alignment = 1
clip_text = true
allow_reselect = true
virtual_keyboard_type = 2
[node name="Four_of_a_Kind" type="Panel" parent="ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(1080, 150)
@ -472,14 +472,13 @@ text = "Four of a kind"
horizontal_alignment = 1
vertical_alignment = 1
[node name="OptionButton" type="OptionButton" parent="ScrollContainer/VBoxContainer/Four_of_a_Kind/HBoxContainer"]
[node name="LineEdit" type="LineEdit" parent="ScrollContainer/VBoxContainer/Four_of_a_Kind/HBoxContainer"]
custom_minimum_size = Vector2(250, 150)
layout_mode = 2
theme = ExtResource("3_hdjql")
theme_override_font_sizes/font_size = 50
alignment = 1
clip_text = true
allow_reselect = true
virtual_keyboard_type = 2
[node name="Full_House" type="Panel" parent="ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(1080, 150)
@ -624,6 +623,7 @@ clip_text = true
custom_minimum_size = Vector2(250, 150)
layout_mode = 2
theme_override_font_sizes/font_size = 50
text = "+"
clip_text = true
[node name="chance" type="Panel" parent="ScrollContainer/VBoxContainer"]
@ -652,14 +652,13 @@ text = "Chance"
horizontal_alignment = 1
vertical_alignment = 1
[node name="OptionButton" type="OptionButton" parent="ScrollContainer/VBoxContainer/chance/HBoxContainer"]
[node name="LineEdit" type="LineEdit" parent="ScrollContainer/VBoxContainer/chance/HBoxContainer"]
custom_minimum_size = Vector2(250, 150)
layout_mode = 2
theme = ExtResource("3_hdjql")
theme_override_font_sizes/font_size = 50
alignment = 1
clip_text = true
allow_reselect = true
virtual_keyboard_type = 2
[node name="Score" type="Panel" parent="ScrollContainer/VBoxContainer"]
custom_minimum_size = Vector2(0, 150)

View File

@ -1,4 +1,20 @@
[gd_resource type="Theme" format=3 uid="uid://dt11061t2etln"]
[gd_resource type="Theme" load_steps=2 format=3 uid="uid://dt11061t2etln"]
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_j73w3"]
content_margin_left = 20.0
content_margin_top = 20.0
content_margin_right = 20.0
content_margin_bottom = 20.0
border_width_left = 5
border_width_top = 5
border_width_right = 5
border_width_bottom = 5
border_blend = true
corner_radius_top_left = 20
corner_radius_top_right = 20
corner_radius_bottom_right = 20
corner_radius_bottom_left = 20
[resource]
PopupMenu/font_sizes/font_size = 50
VScrollBar/styles/scroll = SubResource("StyleBoxFlat_j73w3")

View File

@ -7,13 +7,13 @@ var three : int
var four : int
var five : int
var six : int
var three_of_a_kind : int
var four_of_a_kind : int
var three_of_a_kind : String
var four_of_a_kind : String
var full_house : int
var small_straight : int
var large_straight : int
var yahtzee : int
var chance : int
var chance : String
var bonus : int
var score: int
@ -25,13 +25,13 @@ func _init(name: String):
self.four = 0
self.five = 0
self.six = 0
self.three_of_a_kind = 0
self.four_of_a_kind = 0
self.three_of_a_kind = ""
self.four_of_a_kind = ""
self.full_house = 0
self.small_straight = 0
self.large_straight = 0
self.yahtzee = 0
self.chance = 0
self.chance = ""
self.bonus = 0
self.score = 0

View File

@ -8,7 +8,7 @@ custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="./Kniffel.apk"
export_path="android export/Yahtzee.apk"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
@ -37,9 +37,9 @@ package/exclude_from_recents=false
package/show_in_android_tv=false
package/show_in_app_library=true
package/show_as_launcher_app=false
launcher_icons/main_192x192=""
launcher_icons/adaptive_foreground_432x432=""
launcher_icons/adaptive_background_432x432=""
launcher_icons/main_192x192="res://android export/Yahtzee.png"
launcher_icons/adaptive_foreground_432x432="res://android export/Yahtzee.png"
launcher_icons/adaptive_background_432x432="res://android export/Yahtzee.png"
graphics/opengl_debug=false
xr_features/xr_mode=0
screen/immersive_mode=true

View File

@ -10,11 +10,12 @@ config_version=5
[application]
config/name="Kniffel"
config/name="Yahtzee"
run/main_scene="res://MainMenu.tscn"
config/features=PackedStringArray("4.2", "Mobile")
run/low_processor_mode=true
config/icon="res://icon.svg"
boot_splash/image="res://android export/Yahtzee.png"
config/icon="res://android export/Yahtzee.png"
[autoload]