aboutsummaryrefslogtreecommitdiff
path: root/game/src
diff options
context:
space:
mode:
author George L. Albany <Megacake1234@gmail.com>2023-02-21 08:49:46 +0100
committer GitHub <noreply@github.com>2023-02-21 08:49:46 +0100
commitfb9e316a18139ea6b6ffe3b237796b42d7114738 (patch)
tree7eb315989e19d1e8eabea955330e3a2e5469c876 /game/src
parent0b3f9cb21cfa86e98649066ff7d260b4f9022023 (diff)
Add stylized theme to MainMenu (#12)
* Add stylized theme to MainMenu Increase message queue memory size by 4 Add default_theme.theme Refactor SampleGame.gd to better account for refactoring via @export nodes Properly aligne SampleGame scene Reorganize MainMenu into its own directory Add main_menu_border_paper.png Add main_menu_button.png * Add background image to theme Implement StyleBoxCombinedTexture Allows drawing an array of textures all at once Make MainMenu Panel a PanelContainer for consistency * Implement MainMenu button press, hover, and focus styles Improve MainMenu button disabled style * Add Godot's latest documentation to the README.md
Diffstat (limited to 'game/src')
-rw-r--r--game/src/GameMenu.tscn5
-rw-r--r--game/src/MainMenu.tscn66
-rw-r--r--game/src/MainMenu/MainMenu.gd (renamed from game/src/MainMenu.gd)5
-rw-r--r--game/src/MainMenu/MainMenu.tscn98
-rw-r--r--game/src/SampleGame.gd15
-rw-r--r--game/src/SampleGame.tscn17
-rw-r--r--game/src/Utility/StyleBoxCombinedTexture.gd47
-rw-r--r--game/src/Utility/TextureSetting.gd123
8 files changed, 299 insertions, 77 deletions
diff --git a/game/src/GameMenu.tscn b/game/src/GameMenu.tscn
index 24f1c6c..0c399fb 100644
--- a/game/src/GameMenu.tscn
+++ b/game/src/GameMenu.tscn
@@ -1,7 +1,7 @@
[gd_scene load_steps=5 format=3 uid="uid://b4pg2y2ivib8f"]
[ext_resource type="Script" path="res://src/GameMenu.gd" id="1_cafwe"]
-[ext_resource type="PackedScene" uid="uid://dvoin538iby54" path="res://src/MainMenu.tscn" id="1_y4m2a"]
+[ext_resource type="PackedScene" uid="uid://dvoin538iby54" path="res://src/MainMenu/MainMenu.tscn" id="2_2jbkh"]
[ext_resource type="PackedScene" uid="uid://cnbfxjy1m6wja" path="res://src/OptionMenu/OptionsMenu.tscn" id="3_111lv"]
[ext_resource type="PackedScene" uid="uid://b7oncobnacxmt" path="res://src/LocaleButton.tscn" id="4_jno35"]
@@ -14,8 +14,9 @@ grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_cafwe")
-[node name="MainMenu" parent="." instance=ExtResource("1_y4m2a")]
+[node name="MainMenu" parent="." instance=ExtResource("2_2jbkh")]
layout_mode = 1
+metadata/_edit_vertical_guides_ = [251.0, 269.0, 504.0, 523.0, 15.0, 759.0, 777.0]
[node name="OptionsMenu" parent="." instance=ExtResource("3_111lv")]
visible = false
diff --git a/game/src/MainMenu.tscn b/game/src/MainMenu.tscn
deleted file mode 100644
index 587eb01..0000000
--- a/game/src/MainMenu.tscn
+++ /dev/null
@@ -1,66 +0,0 @@
-[gd_scene load_steps=2 format=3 uid="uid://dvoin538iby54"]
-
-[ext_resource type="Script" path="res://src/MainMenu.gd" id="1_6akq8"]
-
-[node name="MainMenu" type="Control"]
-layout_mode = 3
-anchors_preset = 15
-anchor_right = 1.0
-anchor_bottom = 1.0
-grow_horizontal = 2
-grow_vertical = 2
-script = ExtResource("1_6akq8")
-
-[node name="VBox" type="VBoxContainer" parent="."]
-layout_mode = 1
-anchors_preset = 15
-anchor_right = 1.0
-anchor_bottom = 1.0
-grow_horizontal = 2
-grow_vertical = 2
-
-[node name="TitleLabel" type="Label" parent="VBox"]
-layout_mode = 2
-size_flags_vertical = 6
-size_flags_stretch_ratio = 1.5
-theme_override_font_sizes/font_size = 90
-text = "OpenVic2"
-horizontal_alignment = 1
-vertical_alignment = 1
-
-[node name="Center" type="CenterContainer" parent="VBox"]
-layout_mode = 2
-size_flags_vertical = 2
-
-[node name="VBox" type="VBoxContainer" parent="VBox/Center"]
-layout_mode = 2
-
-[node name="NewGameButton" type="Button" parent="VBox/Center/VBox" node_paths=PackedStringArray("shortcut_context")]
-layout_mode = 2
-focus_neighbor_top = NodePath("../ExitButton")
-shortcut_context = NodePath("")
-text = "New Game"
-
-[node name="ContinueButton" type="Button" parent="VBox/Center/VBox"]
-layout_mode = 2
-disabled = true
-text = "Continue"
-
-[node name="MultiplayerButton" type="Button" parent="VBox/Center/VBox"]
-layout_mode = 2
-text = "Multipayer"
-
-[node name="OptionsButton" type="Button" parent="VBox/Center/VBox"]
-layout_mode = 2
-text = "Options"
-
-[node name="ExitButton" type="Button" parent="VBox/Center/VBox"]
-layout_mode = 2
-focus_neighbor_bottom = NodePath("../NewGameButton")
-text = "Exit"
-
-[connection signal="pressed" from="VBox/Center/VBox/NewGameButton" to="." method="_on_new_game_button_pressed"]
-[connection signal="pressed" from="VBox/Center/VBox/ContinueButton" to="." method="_on_continue_button_pressed"]
-[connection signal="pressed" from="VBox/Center/VBox/MultiplayerButton" to="." method="_on_multi_player_button_pressed"]
-[connection signal="pressed" from="VBox/Center/VBox/OptionsButton" to="." method="_on_options_button_pressed"]
-[connection signal="pressed" from="VBox/Center/VBox/ExitButton" to="." method="_on_exit_button_pressed"]
diff --git a/game/src/MainMenu.gd b/game/src/MainMenu/MainMenu.gd
index de49ec4..000dc69 100644
--- a/game/src/MainMenu.gd
+++ b/game/src/MainMenu/MainMenu.gd
@@ -2,10 +2,13 @@ extends Control
signal options_button_pressed
+@export
+var _new_game_button : BaseButton
+
func _ready():
print("From GDScript")
TestSingleton.hello_singleton()
- $VBox/Center/VBox/NewGameButton.grab_focus()
+ _new_game_button.grab_focus()
func _on_new_game_button_pressed():
diff --git a/game/src/MainMenu/MainMenu.tscn b/game/src/MainMenu/MainMenu.tscn
new file mode 100644
index 0000000..bb47f88
--- /dev/null
+++ b/game/src/MainMenu/MainMenu.tscn
@@ -0,0 +1,98 @@
+[gd_scene load_steps=3 format=3 uid="uid://dvoin538iby54"]
+
+[ext_resource type="Theme" uid="uid://1xrgnmmnrnce" path="res://default_theme.theme" id="1_6d448"]
+[ext_resource type="Script" path="res://src/MainMenu/MainMenu.gd" id="2_nm1fq"]
+
+[node name="MainMenu" type="Control" node_paths=PackedStringArray("_new_game_button")]
+layout_mode = 3
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+theme = ExtResource("1_6d448")
+script = ExtResource("2_nm1fq")
+_new_game_button = NodePath("Panel/VBox/Margin/ButtonList/NewGameButton")
+
+[node name="Panel" type="PanelContainer" parent="."]
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
+theme_type_variation = &"Panel_MainMenu"
+
+[node name="VBox" type="VBoxContainer" parent="Panel"]
+layout_mode = 2
+
+[node name="TitleLabel" type="Label" parent="Panel/VBox"]
+layout_mode = 2
+size_flags_vertical = 6
+size_flags_stretch_ratio = 1.5
+theme_override_font_sizes/font_size = 90
+text = "OpenVic2"
+horizontal_alignment = 1
+vertical_alignment = 1
+
+[node name="Margin" type="MarginContainer" parent="Panel/VBox"]
+layout_mode = 2
+theme_override_constants/margin_left = 15
+theme_override_constants/margin_right = 12
+
+[node name="ButtonList" type="HBoxContainer" parent="Panel/VBox/Margin"]
+custom_minimum_size = Vector2(500, 0)
+layout_mode = 2
+theme_type_variation = &"HBox_MainMenu_ButtonList"
+theme_override_constants/separation = 18
+alignment = 1
+
+[node name="NewGameButton" type="Button" parent="Panel/VBox/Margin/ButtonList" node_paths=PackedStringArray("shortcut_context")]
+layout_mode = 2
+size_flags_horizontal = 3
+focus_neighbor_top = NodePath("../ExitButton")
+shortcut_context = NodePath("")
+theme_type_variation = &"Button_MainMenu"
+text = "New Game"
+clip_text = true
+
+[node name="ContinueButton" type="Button" parent="Panel/VBox/Margin/ButtonList"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_type_variation = &"Button_MainMenu"
+disabled = true
+text = "Continue"
+clip_text = true
+
+[node name="MultiplayerButton" type="Button" parent="Panel/VBox/Margin/ButtonList"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_type_variation = &"Button_MainMenu"
+text = "Multiplayer"
+clip_text = true
+
+[node name="OptionsButton" type="Button" parent="Panel/VBox/Margin/ButtonList"]
+layout_mode = 2
+size_flags_horizontal = 3
+theme_type_variation = &"Button_MainMenu"
+text = "Options"
+clip_text = true
+
+[node name="ExitButton" type="Button" parent="Panel/VBox/Margin/ButtonList"]
+layout_mode = 2
+size_flags_horizontal = 3
+focus_neighbor_bottom = NodePath("../NewGameButton")
+theme_type_variation = &"Button_MainMenu"
+text = "Exit"
+clip_text = true
+
+[node name="BottomSpace" type="Control" parent="Panel/VBox"]
+layout_mode = 2
+size_flags_vertical = 3
+size_flags_stretch_ratio = 0.35
+
+[connection signal="pressed" from="Panel/VBox/Margin/ButtonList/NewGameButton" to="." method="_on_new_game_button_pressed"]
+[connection signal="pressed" from="Panel/VBox/Margin/ButtonList/ContinueButton" to="." method="_on_continue_button_pressed"]
+[connection signal="pressed" from="Panel/VBox/Margin/ButtonList/MultiplayerButton" to="." method="_on_multi_player_button_pressed"]
+[connection signal="pressed" from="Panel/VBox/Margin/ButtonList/OptionsButton" to="." method="_on_options_button_pressed"]
+[connection signal="pressed" from="Panel/VBox/Margin/ButtonList/ExitButton" to="." method="_on_exit_button_pressed"]
diff --git a/game/src/SampleGame.gd b/game/src/SampleGame.gd
index 0e3a61d..589fed2 100644
--- a/game/src/SampleGame.gd
+++ b/game/src/SampleGame.gd
@@ -2,6 +2,15 @@ extends Control
var selectedId = 0
+@export
+var _province_num_display : Label
+
+@export
+var _province_size_display : Label
+
+@export
+var _main_menu_scene : PackedScene
+
# Called when the node enters the scene tree for the first time.
func _ready():
updateVisibleInfo()
@@ -14,8 +23,8 @@ func _ready():
func updateVisibleInfo():
- $CenterContainer/VBoxContainer2/GridContainer/ProvinceNumDisplay.text = str(selectedId)
- $CenterContainer/VBoxContainer2/GridContainer/ProvinceSizeDisplay.text = str(Simulation.queryProvinceSize(selectedId))
+ _province_num_display.text = str(selectedId)
+ _province_size_display.text = str(Simulation.queryProvinceSize(selectedId))
func _on_pass_time_button_pressed():
@@ -37,4 +46,4 @@ func _on_prev_prov_button_pressed():
func _on_to_main_menu_pressed():
- get_tree().change_scene_to_file("res://src/MainMenu.tscn")
+ get_tree().change_scene_to_packed(_main_menu_scene)
diff --git a/game/src/SampleGame.tscn b/game/src/SampleGame.tscn
index 8221857..92603b9 100644
--- a/game/src/SampleGame.tscn
+++ b/game/src/SampleGame.tscn
@@ -1,8 +1,9 @@
-[gd_scene load_steps=2 format=3 uid="uid://bgnupcshe1m7r"]
+[gd_scene load_steps=3 format=3 uid="uid://bgnupcshe1m7r"]
[ext_resource type="Script" path="res://src/SampleGame.gd" id="1_eklvp"]
+[ext_resource type="PackedScene" uid="uid://b4pg2y2ivib8f" path="res://src/GameMenu.tscn" id="2_r7wq5"]
-[node name="SampleGame" type="Control"]
+[node name="SampleGame" type="Control" node_paths=PackedStringArray("_province_num_display", "_province_size_display")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
@@ -10,11 +11,17 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_eklvp")
+_province_num_display = NodePath("CenterContainer/VBoxContainer2/GridContainer/ProvinceNumDisplay")
+_province_size_display = NodePath("CenterContainer/VBoxContainer2/GridContainer/ProvinceSizeDisplay")
+_main_menu_scene = ExtResource("2_r7wq5")
[node name="CenterContainer" type="CenterContainer" parent="."]
-layout_mode = 0
-offset_right = 1152.0
-offset_bottom = 648.0
+layout_mode = 1
+anchors_preset = 15
+anchor_right = 1.0
+anchor_bottom = 1.0
+grow_horizontal = 2
+grow_vertical = 2
[node name="VBoxContainer2" type="VBoxContainer" parent="CenterContainer"]
layout_mode = 2
diff --git a/game/src/Utility/StyleBoxCombinedTexture.gd b/game/src/Utility/StyleBoxCombinedTexture.gd
new file mode 100644
index 0000000..db54da4
--- /dev/null
+++ b/game/src/Utility/StyleBoxCombinedTexture.gd
@@ -0,0 +1,47 @@
+@tool
+extends StyleBox
+class_name StyleBoxCombinedTexture
+
+@export
+var texture_settings : Array[TextureSetting] = []:
+ get: return texture_settings.duplicate()
+ set(v):
+ texture_settings = v
+ for setting in texture_settings:
+ setting.changed.connect(emit_changed)
+ emit_changed()
+
+func _get_draw_rect(rect : Rect2) -> Rect2:
+ var combined_rect : Rect2 = Rect2()
+ for setting in texture_settings:
+ if combined_rect.position.x > setting.expand_margin_left:
+ combined_rect.position.x = setting.expand_margin_left
+ if combined_rect.position.y > setting.expand_margin_top:
+ combined_rect.position.y = setting.expand_margin_top
+ if combined_rect.end.x < setting.expand_margin_right:
+ combined_rect.end.x = setting.expand_margin_right
+ if combined_rect.end.y < setting.expand_margin_bottom:
+ combined_rect.end.y = setting.expand_margin_bottom
+ return rect.grow_individual(combined_rect.position.x, combined_rect.position.y, combined_rect.end.x, combined_rect.end.y)
+
+func _draw(to_canvas_item : RID, rect : Rect2) -> void:
+ for setting in texture_settings:
+ if setting == null or setting.texture == null:
+ continue
+ var inner_rect : Rect2 = rect
+ inner_rect.position.x -= setting.expand_margin_left
+ inner_rect.position.y -= setting.expand_margin_top
+ inner_rect.size.x += setting.expand_margin_left + setting.expand_margin_right
+ inner_rect.size.y += setting.expand_margin_top + setting.expand_margin_bottom
+ RenderingServer.canvas_item_add_nine_patch(
+ to_canvas_item,
+ inner_rect,
+ setting.region_rect,
+ setting.texture.get_rid(),
+ Vector2(setting.texture_margin_left, setting.texture_margin_top),
+ Vector2(setting.texture_margin_right, setting.texture_margin_bottom),
+ setting.axis_stretch_horizontal,
+ setting.axis_stretch_vertical,
+ setting.draw_center,
+ setting.modulate_color
+ )
diff --git a/game/src/Utility/TextureSetting.gd b/game/src/Utility/TextureSetting.gd
new file mode 100644
index 0000000..da9b185
--- /dev/null
+++ b/game/src/Utility/TextureSetting.gd
@@ -0,0 +1,123 @@
+extends Resource
+class_name TextureSetting
+
+@export
+var texture : Texture2D:
+ get: return texture
+ set(v):
+ texture = v
+ emit_changed()
+@export
+var draw_center : bool = true:
+ get: return draw_center
+ set(v):
+ draw_center = v
+ emit_changed()
+
+@export_group("Texture Margins", "texture_margin_")
+@export
+var texture_margin_left : float = 0:
+ get: return texture_margin_left
+ set(v):
+ texture_margin_left = v
+ emit_changed()
+@export
+var texture_margin_top : float = 0:
+ get: return texture_margin_top
+ set(v):
+ texture_margin_top = v
+ emit_changed()
+@export
+var texture_margin_right : float = 0:
+ get: return texture_margin_right
+ set(v):
+ texture_margin_right = v
+ emit_changed()
+@export
+var texture_margin_bottom : float = 0:
+ get: return texture_margin_bottom
+ set(v):
+ texture_margin_bottom = v
+ emit_changed()
+
+@export_group("Expand Margins", "expand_margin_")
+@export
+var expand_margin_left : float = 0:
+ get: return expand_margin_left
+ set(v):
+ expand_margin_left = v
+ emit_changed()
+@export
+var expand_margin_top : float = 0:
+ get: return expand_margin_top
+ set(v):
+ expand_margin_top = v
+ emit_changed()
+@export
+var expand_margin_right : float = 0:
+ get: return expand_margin_right
+ set(v):
+ expand_margin_right = v
+ emit_changed()
+@export
+var expand_margin_bottom : float = 0:
+ get: return expand_margin_bottom
+ set(v):
+ expand_margin_bottom = v
+ emit_changed()
+
+@export_group("Axis Stretch", "axis_stretch_")
+@export
+var axis_stretch_horizontal : RenderingServer.NinePatchAxisMode = RenderingServer.NINE_PATCH_STRETCH:
+ get: return axis_stretch_horizontal
+ set(v):
+ axis_stretch_horizontal = v
+ emit_changed()
+@export
+var axis_stretch_vertical : RenderingServer.NinePatchAxisMode = RenderingServer.NINE_PATCH_STRETCH:
+ get: return axis_stretch_vertical
+ set(v):
+ axis_stretch_vertical = v
+ emit_changed()
+
+@export_group("Sub-Region", "region_")
+@export
+var region_rect : Rect2 = Rect2(0, 0, 0, 0):
+ get: return region_rect
+ set(v):
+ region_rect = v
+ emit_changed()
+
+@export_group("Modulate", "modulate_")
+@export
+var modulate_color : Color = Color(1, 1, 1, 1):
+ get: return modulate_color
+ set(v):
+ modulate_color = v
+ emit_changed()
+
+@export_group("Content Margins", "content_margin_")
+@export
+var content_margin_left : float = -1:
+ get: return content_margin_left
+ set(v):
+ content_margin_left = v
+ emit_changed()
+@export
+var content_margin_top : float = -1:
+ get: return content_margin_top
+ set(v):
+ content_margin_top = v
+ emit_changed()
+@export
+var content_margin_right : float = -1:
+ get: return content_margin_right
+ set(v):
+ content_margin_right = v
+ emit_changed()
+@export
+var content_margin_bottom : float = -1:
+ get: return content_margin_bottom
+ set(v):
+ content_margin_bottom = v
+ emit_changed()