Skip to content

Commit

Permalink
~64 main, option menu
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-cho committed Jun 15, 2024
1 parent 68a3065 commit d3b8d74
Show file tree
Hide file tree
Showing 9 changed files with 304 additions and 13 deletions.
2 changes: 1 addition & 1 deletion project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ config_version=5
[application]

config/name="survivor-tutorial"
run/main_scene="res://scenes/main/main.tscn"
run/main_scene="res://scenes/ui/main_menu.tscn"
config/features=PackedStringArray("4.2", "Forward Plus")
config/icon="res://icon.svg"

Expand Down
2 changes: 2 additions & 0 deletions resources/themes/my_preview.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,11 @@ size_flags_horizontal = 3

[node name="HSlider" type="HSlider" parent="PanelContainer/MarginContainer/HBoxContainer/col2/HBoxContainer/VBoxContainer"]
layout_mode = 2
value = 50.0

[node name="HSlider2" type="HSlider" parent="PanelContainer/MarginContainer/HBoxContainer/col2/HBoxContainer/VBoxContainer"]
layout_mode = 2
value = 50.0
editable = false

[node name="HScrollBar" type="HScrollBar" parent="PanelContainer/MarginContainer/HBoxContainer/col2/HBoxContainer/VBoxContainer"]
Expand Down
42 changes: 41 additions & 1 deletion resources/themes/theme.tres
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[gd_resource type="Theme" load_steps=11 format=3 uid="uid://c3hhobt5yor42"]
[gd_resource type="Theme" load_steps=16 format=3 uid="uid://c3hhobt5yor42"]

[ext_resource type="FontFile" uid="uid://ba3f2bejkjtdg" path="res://resources/themes/Rockboxcond12.ttf" id="1_fxvgl"]
[ext_resource type="Texture2D" uid="uid://m1p3h77wdeke" path="res://assets/ui/ui.png" id="1_vusi2"]
Expand Down Expand Up @@ -41,6 +41,35 @@ texture_margin_right = 3.0
texture_margin_bottom = 3.0
region_rect = Rect2(4, 20, 8, 8)

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_00uaf"]
size = Vector2(0, 0)

[sub_resource type="PlaceholderTexture2D" id="PlaceholderTexture2D_e7ca6"]
size = Vector2(0, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_2jrkf"]
bg_color = Color(0.458824, 0.890196, 1, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0.8, 0.8, 0.8, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_fo5e2"]
bg_color = Color(0.458824, 0.890196, 1, 1)
border_width_left = 2
border_width_top = 2
border_width_right = 2
border_width_bottom = 2
border_color = Color(0.8, 0.8, 0.8, 0)

[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_jlu0t"]
content_margin_left = 2.0
content_margin_top = 6.0
content_margin_right = 2.0
content_margin_bottom = 6.0
bg_color = Color(0.247059, 0.14902, 0.192157, 1)

[sub_resource type="StyleBoxTexture" id="StyleBoxTexture_hjilj"]
texture = ExtResource("1_vusi2")
texture_margin_left = 4.0
Expand All @@ -65,6 +94,12 @@ default_font = ExtResource("1_fxvgl")
default_font_size = 16
AlternatePanelContainer/base_type = &"PanelContainer"
AlternatePanelContainer/styles/panel = SubResource("StyleBoxTexture_bvm1a")
BlueOutlineLabel/base_type = &"Label"
BlueOutlineLabel/colors/font_outline_color = Color(0.14902, 0.168627, 0.266667, 1)
BlueOutlineLabel/colors/font_shadow_color = Color(0.14902, 0.168627, 0.266667, 1)
BlueOutlineLabel/constants/outline_size = 8
BlueOutlineLabel/constants/shadow_offset_x = 0
BlueOutlineLabel/constants/shadow_offset_y = 0
Button/colors/font_color = Color(0.247059, 0.14902, 0.192157, 1)
Button/colors/font_focus_color = Color(0.247059, 0.14902, 0.192157, 1)
Button/colors/font_hover_color = Color(0.741176, 0.423529, 0.290196, 1)
Expand All @@ -73,6 +108,11 @@ Button/styles/focus = SubResource("StyleBoxEmpty_ju7t5")
Button/styles/hover = SubResource("StyleBoxTexture_ipsqo")
Button/styles/normal = SubResource("StyleBoxTexture_ohc1h")
Button/styles/pressed = SubResource("StyleBoxTexture_2e4ds")
HSlider/icons/grabber = SubResource("PlaceholderTexture2D_00uaf")
HSlider/icons/grabber_highlight = SubResource("PlaceholderTexture2D_e7ca6")
HSlider/styles/grabber_area = SubResource("StyleBoxFlat_2jrkf")
HSlider/styles/grabber_area_highlight = SubResource("StyleBoxFlat_fo5e2")
HSlider/styles/slider = SubResource("StyleBoxFlat_jlu0t")
Label/constants/line_spacing = 0
PanelContainer/styles/panel = SubResource("StyleBoxTexture_hjilj")
ProgressBar/styles/background = SubResource("StyleBoxFlat_exix6")
Expand Down
7 changes: 2 additions & 5 deletions scenes/ui/ability_upgrade_card.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,7 @@ theme_type_variation = &"AlternatePanelContainer"
[node name="NameLabel" type="Label" parent="MarginContainer/VBoxContainer/PanelContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_outline_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_override_constants/outline_size = 8
theme_type_variation = &"BlueOutlineLabel"
theme_override_font_sizes/font_size = 32
text = "Test name"
horizontal_alignment = 1
Expand All @@ -251,8 +250,6 @@ autowrap_mode = 2
[node name="DescriptionLabel" type="Label" parent="MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_shadow_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_override_colors/font_outline_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_override_constants/outline_size = 8
theme_type_variation = &"BlueOutlineLabel"
text = "Write Some description here as you write a long description"
autowrap_mode = 2
8 changes: 2 additions & 6 deletions scenes/ui/end_screen.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,9 @@ theme_override_constants/separation = 16
[node name="TitleLabel" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_shadow_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_override_colors/font_outline_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_type_variation = &"BlueOutlineLabel"
theme_override_constants/shadow_offset_x = 0
theme_override_constants/shadow_offset_y = 0
theme_override_constants/outline_size = 8
theme_override_font_sizes/font_size = 32
text = "Victory"
horizontal_alignment = 1
Expand All @@ -130,9 +128,7 @@ vertical_alignment = 1
[node name="DescriptionLabel" type="Label" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
unique_name_in_owner = true
layout_mode = 2
theme_override_colors/font_shadow_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_override_colors/font_outline_color = Color(0.14902, 0.168627, 0.266667, 1)
theme_override_constants/outline_size = 8
theme_type_variation = &"BlueOutlineLabel"
text = "You won!"

[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer/PanelContainer/MarginContainer/VBoxContainer"]
Expand Down
28 changes: 28 additions & 0 deletions scenes/ui/main_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
extends CanvasLayer


var options_scene = preload("res://scenes/ui/options_menu.tscn")


func _ready():
%PlayButton.pressed.connect(on_play_pressed)
%OptionsButton.pressed.connect(on_options_pressed)
%QuitButton.pressed.connect(on_quit_pressed)


func on_play_pressed():
get_tree().change_scene_to_file("res://scenes/main/main.tscn")


func on_options_pressed():
var options_instance = options_scene.instantiate() as OptionsMenu
add_child(options_instance)
options_instance.back_pressed.connect(on_options_closed.bind(options_instance))


func on_quit_pressed():
get_tree().quit()


func on_options_closed(options_instance: OptionsMenu):
options_instance.queue_free()
60 changes: 60 additions & 0 deletions scenes/ui/main_menu.tscn

Large diffs are not rendered by default.

64 changes: 64 additions & 0 deletions scenes/ui/options_menu.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
extends CanvasLayer
class_name OptionsMenu

signal back_pressed

@onready var window_button: Button = %WindowButton
@onready var music_slider: Slider = %MusicSlider
@onready var sfx_slider: Slider = %SfxSlider
@onready var back_button: Button = %BackButton


func _ready():
back_button.pressed.connect(on_back_pressed)
window_button.pressed.connect(on_window_button_pressed)
music_slider.value_changed.connect(on_audio_slider_changed.bind("music"))
sfx_slider.value_changed.connect(on_audio_slider_changed.bind("sfx"))
update_display()


func update_display():
match DisplayServer.window_get_mode():
DisplayServer.WINDOW_MODE_FULLSCREEN:
window_button.text = "Fullscreen"
_:
window_button.text = "Windowed"
music_slider.value = get_bus_volume_percent("music")
sfx_slider.value = get_bus_volume_percent("sfx")


func get_bus_volume_percent(bus_name: String):
var bus_index = AudioServer.get_bus_index(bus_name)
if bus_index == -1:
# TODO: assert or warn
return 0
var volume_db = AudioServer.get_bus_volume_db(bus_index)
return db_to_linear(volume_db)


func set_bus_volume_percent(bus_name: String, percent: float) -> void:
var bus_index = AudioServer.get_bus_index(bus_name)
if bus_index == -1:
# TODO: assert or warn
return
var volume_db = linear_to_db(percent)
AudioServer.set_bus_volume_db(bus_index, volume_db)


func on_window_button_pressed():
var mode := DisplayServer.window_get_mode()
if mode != DisplayServer.WINDOW_MODE_FULLSCREEN:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_FULLSCREEN)
else:
DisplayServer.window_set_mode(DisplayServer.WINDOW_MODE_WINDOWED)

update_display()


func on_audio_slider_changed(value: float, bus_name: String):
set_bus_volume_percent(bus_name, value)



func on_back_pressed():
back_pressed.emit()
104 changes: 104 additions & 0 deletions scenes/ui/options_menu.tscn

Large diffs are not rendered by default.

0 comments on commit d3b8d74

Please sign in to comment.