changes UI to a global singleton
This commit is contained in:
parent
aa4afc4c4b
commit
e3aec75404
16 changed files with 371 additions and 119 deletions
BIN
assets/textures/Backgrounds/meadow2.jpg
Normal file
BIN
assets/textures/Backgrounds/meadow2.jpg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 2.3 MiB |
34
assets/textures/Backgrounds/meadow2.jpg.import
Normal file
34
assets/textures/Backgrounds/meadow2.jpg.import
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://da7o6lfuoliid"
|
||||
path="res://.godot/imported/meadow2.jpg-a2c56367f6dea92f74977abc7eb0e749.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://assets/textures/Backgrounds/meadow2.jpg"
|
||||
dest_files=["res://.godot/imported/meadow2.jpg-a2c56367f6dea92f74977abc7eb0e749.ctex"]
|
||||
|
||||
[params]
|
||||
|
||||
compress/mode=0
|
||||
compress/high_quality=false
|
||||
compress/lossy_quality=0.7
|
||||
compress/hdr_compression=1
|
||||
compress/normal_map=0
|
||||
compress/channel_pack=0
|
||||
mipmaps/generate=false
|
||||
mipmaps/limit=-1
|
||||
roughness/mode=0
|
||||
roughness/src_normal=""
|
||||
process/fix_alpha_border=true
|
||||
process/premult_alpha=false
|
||||
process/normal_map_invert_y=false
|
||||
process/hdr_as_srgb=false
|
||||
process/hdr_clamp_exposure=false
|
||||
process/size_limit=0
|
||||
detect_3d/compress_to=1
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
extends Node
|
||||
|
||||
# SIGNALS
|
||||
signal inventory_changed
|
||||
|
||||
# The players current monsters in the inventory are saved here
|
||||
var monsters: Array
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
setup_new_inventory()
|
||||
|
||||
func setup_new_inventory() -> void:
|
||||
var data = MonsterData.new()
|
||||
data.set_data("debuggy", {}, 5)
|
||||
print("After setting it in inventory: ", data.display_name)
|
||||
|
||||
monsters.append(data)
|
||||
# debug timeout to wait for the debug UI
|
||||
await get_tree().create_timer(2.0).timeout
|
||||
inventory_changed.emit()
|
||||
|
|
@ -4,9 +4,6 @@ extends Node
|
|||
const SAVE_GAME_PATH := "user://savegame.save"
|
||||
const VERSION: int = 1
|
||||
|
||||
# List all the nodes and resouces to save
|
||||
var save_data: Resource = SaveData.new()
|
||||
|
||||
func save() -> void:
|
||||
var save_file = FileAccess.open(SAVE_GAME_PATH, FileAccess.WRITE)
|
||||
|
||||
|
|
@ -19,25 +16,25 @@ func save() -> void:
|
|||
}
|
||||
var meta_json_string = JSON.stringify(meta_data)
|
||||
save_file.store_line(meta_json_string)
|
||||
|
||||
# Save the player node's position
|
||||
var player = get_tree().get_root().find_child("Player", true, false)
|
||||
var player_node_data = player.save()
|
||||
var player_json = JSON.stringify(player_node_data)
|
||||
save_file.store_line(player_json)
|
||||
|
||||
# for now, only save the savedata resource from above
|
||||
if !save_data.has_method("save"):
|
||||
print("Resource '%s' is missing a save() function, skipped" %save_data.resource_name)
|
||||
return
|
||||
|
||||
# Call the node's / resource's save function
|
||||
var node_data = save_data.call("save")
|
||||
|
||||
# Serialize the JSON string
|
||||
var json_string = JSON.stringify(node_data)
|
||||
|
||||
# Store the save dictionary as a new line in the save file
|
||||
# Save all other stuff from the SaveData
|
||||
var save_data = SaveData.call("save")
|
||||
var json_string = JSON.stringify(save_data)
|
||||
save_file.store_line(json_string)
|
||||
|
||||
func load() -> void:
|
||||
if not FileAccess.file_exists(SAVE_GAME_PATH):
|
||||
print("No save file exists.")
|
||||
return
|
||||
|
||||
# NEXT STEP: How to load correctly and in which order?
|
||||
# first the current world, then the player and their position and then the inventory?
|
||||
|
||||
# Load the save file line by line and process the dictionary to restore
|
||||
# the object it represents
|
||||
|
|
@ -57,17 +54,17 @@ func load() -> void:
|
|||
# Get the data from the JSON object
|
||||
var node_data = json.get_data()
|
||||
|
||||
if node_data.has("meta"):
|
||||
print("Meta data ignored.")
|
||||
|
||||
# handle the player data (name, money, etc.)
|
||||
if node_data.has("player_data"):
|
||||
print("save_game.gd: ", node_data)
|
||||
|
||||
# Firstly, we need to create the object and add it to the tree and set its position.
|
||||
#var new_object = load(node_data["filename"]).instantiate()
|
||||
#get_node(node_data["parent"]).add_child(new_object)
|
||||
#new_object.position = Vector2(node_data["pos_x"], node_data["pos_y"])
|
||||
var world_to_load = load(node_data["player_data"].world)
|
||||
var instance = world_to_load.instantiate()
|
||||
instance.add_child(load("res://scenes/player/player.tscn").instantiate())
|
||||
var level_container = get_tree().get_root().find_child("CurrentLevel", true, false)
|
||||
level_container.add_child(instance)
|
||||
|
||||
# Now we set the remaining variables.
|
||||
#for i in node_data.keys():
|
||||
# if i == "filename" or i == "parent" or i == "pos_x" or i == "pos_y":
|
||||
# continue
|
||||
# new_object.set(i, node_data[i])
|
||||
|
||||
func savegame_exists() -> bool:
|
||||
return FileAccess.file_exists(SAVE_GAME_PATH)
|
||||
|
|
|
|||
|
|
@ -18,8 +18,9 @@ config/icon="res://assets/logo/logo.png"
|
|||
|
||||
[autoload]
|
||||
|
||||
Inventory="*res://globals/inventory.gd"
|
||||
UI="*res://scenes/ui/ui.gd"
|
||||
SaveGame="*res://globals/save_game.gd"
|
||||
SaveData="*res://resources/save_data.gd"
|
||||
|
||||
[display]
|
||||
|
||||
|
|
@ -29,6 +30,10 @@ window/stretch/mode="canvas_items"
|
|||
window/stretch/aspect="expand"
|
||||
window/handheld/orientation=1
|
||||
|
||||
[global_group]
|
||||
|
||||
Persist="Contains all nodes that need to be saved"
|
||||
|
||||
[input]
|
||||
|
||||
joystick_right_right={
|
||||
|
|
@ -41,6 +46,16 @@ joystick_right_left={
|
|||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":2,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
joystick_right_up={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":-1.0,"script":null)
|
||||
]
|
||||
}
|
||||
joystick_right_down={
|
||||
"deadzone": 0.5,
|
||||
"events": [Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":-1,"axis":3,"axis_value":1.0,"script":null)
|
||||
]
|
||||
}
|
||||
|
||||
[input_devices]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,11 +1,19 @@
|
|||
class_name SaveData
|
||||
extends Resource
|
||||
extends Node
|
||||
|
||||
# SIGNALS
|
||||
signal inventory_changed
|
||||
|
||||
# Player data
|
||||
var player_name: String = "Player"
|
||||
var money: int = 0
|
||||
var world: String = "res://scenes/worlds/debug_level.tscn"
|
||||
|
||||
# Inventory data
|
||||
# Items with their unique id and amount
|
||||
|
||||
# Monster Party data
|
||||
# monster with their values (unique id, atk, def, tmp for now)
|
||||
var monsters: Array
|
||||
|
||||
func _init() -> void:
|
||||
set_name("SaveData")
|
||||
|
|
@ -13,7 +21,8 @@ func _init() -> void:
|
|||
func save():
|
||||
var player_data = {
|
||||
"player_name": player_name,
|
||||
"money": money
|
||||
"money": money,
|
||||
"world": world
|
||||
}
|
||||
|
||||
# Collect all data to save in one dictionary
|
||||
|
|
@ -22,3 +31,11 @@ func save():
|
|||
}
|
||||
|
||||
return save_dict
|
||||
|
||||
func setup_new_inventory() -> void:
|
||||
var data = MonsterData.new()
|
||||
data.set_data("debuggy", {}, 5)
|
||||
print("After setting it in inventory: ", data.display_name)
|
||||
|
||||
monsters.append(data)
|
||||
inventory_changed.emit()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,34 @@
|
|||
extends Node3D
|
||||
# Game.gd - Main Entrypoint for the game
|
||||
|
||||
@onready var ui: UI = $UI
|
||||
@export var skip_menu: bool = true
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
|
||||
# Skip the menu for development
|
||||
if skip_menu == true:
|
||||
UI.show_ingame_controls(!skip_menu)
|
||||
UI.show_main_menu(!skip_menu)
|
||||
_on_ui_on_new_game_started()
|
||||
return
|
||||
|
||||
# On start of the game, the main menu is shown
|
||||
UI.show_main_menu()
|
||||
|
||||
# this event comes from the MainMenu Node in the UI
|
||||
func _on_ui_on_new_game_started() -> void:
|
||||
var world = preload("res://scenes/worlds/debug_level.tscn").instantiate()
|
||||
UI.show_ingame_controls()
|
||||
|
||||
# Add the starting world
|
||||
%CurrentLevel.add_child(world)
|
||||
|
||||
# Add the starting player to the starting world
|
||||
var player = preload("res://scenes/player/player.tscn").instantiate()
|
||||
world.add_child(player)
|
||||
|
||||
# event comes from the MainMenu Node in the UI
|
||||
func _on_ui_on_game_continued() -> void:
|
||||
SaveGame.load()
|
||||
# Update the UI when the Inventory (global) changes
|
||||
Inventory.inventory_changed.connect(ui._update_ui)
|
||||
UI.show_ingame_controls()
|
||||
|
|
|
|||
|
|
@ -1,14 +1,12 @@
|
|||
[gd_scene load_steps=4 format=3 uid="uid://cswuap81n7t3f"]
|
||||
[gd_scene load_steps=3 format=3 uid="uid://cswuap81n7t3f"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://p8agd0dfam0p" path="res://scenes/worlds/debug_level.tscn" id="1_j851n"]
|
||||
[ext_resource type="Script" path="res://scenes/game.gd" id="1_mfbtr"]
|
||||
[ext_resource type="PackedScene" uid="uid://b5y7pdfe6ougf" path="res://scenes/ui/ui.tscn" id="2_ynhuf"]
|
||||
|
||||
[node name="Game" type="Node3D"]
|
||||
script = ExtResource("1_mfbtr")
|
||||
|
||||
[node name="CurrentLevel" type="Node3D" parent="."]
|
||||
|
||||
[node name="DebugLevel" parent="CurrentLevel" instance=ExtResource("1_j851n")]
|
||||
|
||||
[node name="UI" parent="." instance=ExtResource("2_ynhuf")]
|
||||
|
||||
[node name="CurrentLevel" type="Node3D" parent="."]
|
||||
unique_name_in_owner = true
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ func _physics_process(delta: float) -> void:
|
|||
|
||||
# Camera rotation
|
||||
var camera_input_dir := Input.get_vector("joystick_right_left", "joystick_right_right", "joystick_right_left", "joystick_right_right")
|
||||
$CameraRoot.rotation.y += camera_input_dir.x * 0.2
|
||||
$CameraRoot.rotation.y += camera_input_dir.x
|
||||
|
||||
# Get the input direction and handle the movement / deceleration.
|
||||
# As good practice, you should replace UI actions with custom gameplay actions.
|
||||
|
|
@ -74,3 +74,16 @@ func start_battle(enemy: Node3D, player_position: Vector3) -> void:
|
|||
await get_tree().create_timer(2.0).timeout
|
||||
print("timer over")
|
||||
in_battle = false
|
||||
|
||||
func save() -> Dictionary:
|
||||
var save_dict = {
|
||||
"player_transform": {
|
||||
"pos_x": global_position.x,
|
||||
"pos_y": global_position.y,
|
||||
"pos_z": global_position.z,
|
||||
"rot_x": global_rotation.x,
|
||||
"rot_y": global_rotation.y,
|
||||
"rot_z": global_rotation.z
|
||||
}
|
||||
}
|
||||
return save_dict
|
||||
|
|
|
|||
|
|
@ -12,12 +12,12 @@ func _on_close_button_pressed() -> void:
|
|||
pass # Replace with function body.
|
||||
|
||||
func _update_monster_list() -> void:
|
||||
for i in Inventory.monsters.size():
|
||||
var monster = Inventory.monsters[i]
|
||||
for i in SaveData.monsters.size():
|
||||
var monster = SaveData.monsters[i]
|
||||
var entry = monster_list_entry.instantiate()
|
||||
|
||||
# populate the new entry
|
||||
entry.populate(Inventory.monsters[i])
|
||||
entry.populate(SaveData.monsters[i])
|
||||
|
||||
# add it to the list
|
||||
monster_list_entry_container.add_child(entry)
|
||||
|
|
|
|||
33
scenes/ui/main_menu.gd
Normal file
33
scenes/ui/main_menu.gd
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
extends Control
|
||||
|
||||
signal on_new_game_started
|
||||
signal on_game_continued
|
||||
|
||||
# On ready, check which buttons to show
|
||||
func _ready() -> void:
|
||||
if SaveGame.savegame_exists():
|
||||
%ContinueGameButton.visible = true
|
||||
%NewGameButton.visible = false
|
||||
|
||||
func _on_new_game_button_pressed() -> void:
|
||||
# Hide the main menu
|
||||
self.visible = false
|
||||
|
||||
# emit the new game signal
|
||||
on_new_game_started.emit()
|
||||
|
||||
func _on_continue_game_button_pressed() -> void:
|
||||
# Hide the main menu
|
||||
self.visible = false
|
||||
|
||||
# emit the continue game signal
|
||||
on_game_continued.emit()
|
||||
|
||||
func _on_options_button_pressed() -> void:
|
||||
print("TODO")
|
||||
|
||||
func _on_licenses_button_pressed() -> void:
|
||||
print("TODO")
|
||||
|
||||
func _on_exit_button_pressed() -> void:
|
||||
get_tree().quit()
|
||||
|
|
@ -1,16 +1,79 @@
|
|||
[gd_scene load_steps=3 format=3 uid="uid://dt00rjsodtady"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://dt00rjsodtady"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://b6ylra30qxf30" path="res://assets/logo/logo.png" id="1_1fmce"]
|
||||
[ext_resource type="Script" path="res://scenes/ui/main_menu.gd" id="1_5gs73"]
|
||||
[ext_resource type="FontFile" uid="uid://bjaavdnopfh0q" path="res://assets/fonts/aoboshi_one/AoboshiOne-Regular.ttf" id="2_aqmkw"]
|
||||
[ext_resource type="Texture2D" uid="uid://da7o6lfuoliid" path="res://assets/textures/Backgrounds/meadow2.jpg" id="2_bb61v"]
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_7grw7"]
|
||||
content_margin_left = 20.0
|
||||
content_margin_right = 20.0
|
||||
content_margin_bottom = 5.0
|
||||
bg_color = Color(0.799841, 0.529277, 0.323387, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_xjg0j"]
|
||||
content_margin_left = 20.0
|
||||
content_margin_right = 20.0
|
||||
content_margin_bottom = 5.0
|
||||
bg_color = Color(0.799841, 0.529277, 0.323387, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_3y6oq"]
|
||||
content_margin_left = 20.0
|
||||
content_margin_right = 20.0
|
||||
content_margin_bottom = 5.0
|
||||
bg_color = Color(0.799841, 0.529277, 0.323387, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_cnake"]
|
||||
content_margin_left = 20.0
|
||||
content_margin_right = 20.0
|
||||
content_margin_bottom = 5.0
|
||||
bg_color = Color(0.799841, 0.529277, 0.323387, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[sub_resource type="StyleBoxFlat" id="StyleBoxFlat_0d7mr"]
|
||||
content_margin_left = 20.0
|
||||
content_margin_right = 20.0
|
||||
content_margin_bottom = 5.0
|
||||
bg_color = Color(0.799841, 0.529277, 0.323387, 1)
|
||||
corner_radius_top_left = 5
|
||||
corner_radius_top_right = 5
|
||||
corner_radius_bottom_right = 5
|
||||
corner_radius_bottom_left = 5
|
||||
|
||||
[node name="MainMenu" type="Control"]
|
||||
visible = false
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
script = ExtResource("1_5gs73")
|
||||
|
||||
[node name="Background" type="TextureRect" parent="."]
|
||||
layout_mode = 1
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
texture = ExtResource("2_bb61v")
|
||||
expand_mode = 3
|
||||
stretch_mode = 6
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="."]
|
||||
layout_mode = 1
|
||||
|
|
@ -22,7 +85,9 @@ grow_vertical = 2
|
|||
theme_override_constants/separation = 50
|
||||
|
||||
[node name="Logo" type="TextureRect" parent="VBoxContainer"]
|
||||
custom_minimum_size = Vector2(600, 600)
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
texture = ExtResource("1_1fmce")
|
||||
expand_mode = 4
|
||||
stretch_mode = 5
|
||||
|
|
@ -46,22 +111,88 @@ FANGEN"
|
|||
horizontal_alignment = 1
|
||||
max_lines_visible = 2
|
||||
|
||||
[node name="MenuButtons" type="VBoxContainer" parent="VBoxContainer"]
|
||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 3
|
||||
theme_override_constants/margin_left = 50
|
||||
theme_override_constants/margin_top = 20
|
||||
theme_override_constants/margin_right = 50
|
||||
theme_override_constants/margin_bottom = 50
|
||||
|
||||
[node name="MenuButtons" type="VBoxContainer" parent="VBoxContainer/MarginContainer"]
|
||||
layout_mode = 2
|
||||
size_flags_horizontal = 4
|
||||
size_flags_vertical = 3
|
||||
|
||||
[node name="NewGameButton" type="Button" parent="VBoxContainer/MenuButtons"]
|
||||
[node name="NewGameButton" type="Button" parent="VBoxContainer/MarginContainer/MenuButtons"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.355673, 0.203473, 0.0399276, 1)
|
||||
theme_override_fonts/font = ExtResource("2_aqmkw")
|
||||
theme_override_font_sizes/font_size = 45
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_7grw7")
|
||||
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_xjg0j")
|
||||
theme_override_styles/hover = SubResource("StyleBoxFlat_3y6oq")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_cnake")
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_0d7mr")
|
||||
text = "New Game"
|
||||
|
||||
[node name="ContinueGameButton" type="Button" parent="VBoxContainer/MenuButtons"]
|
||||
[node name="ContinueGameButton" type="Button" parent="VBoxContainer/MarginContainer/MenuButtons"]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.356863, 0.203922, 0.0392157, 1)
|
||||
theme_override_fonts/font = ExtResource("2_aqmkw")
|
||||
theme_override_font_sizes/font_size = 45
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_0d7mr")
|
||||
text = "Continue"
|
||||
|
||||
[node name="OptionsButton" type="Button" parent="VBoxContainer/MenuButtons"]
|
||||
[node name="OptionsButton" type="Button" parent="VBoxContainer/MarginContainer/MenuButtons"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.356863, 0.203922, 0.0392157, 1)
|
||||
theme_override_fonts/font = ExtResource("2_aqmkw")
|
||||
theme_override_font_sizes/font_size = 45
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_0d7mr")
|
||||
text = "Options"
|
||||
|
||||
[node name="ExitButton" type="Button" parent="VBoxContainer/MenuButtons"]
|
||||
[node name="LicensesButton" type="Button" parent="VBoxContainer/MarginContainer/MenuButtons"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
theme_override_colors/font_color = Color(0.356863, 0.203922, 0.0392157, 1)
|
||||
theme_override_fonts/font = ExtResource("2_aqmkw")
|
||||
theme_override_font_sizes/font_size = 45
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_0d7mr")
|
||||
text = "Licenses"
|
||||
|
||||
[node name="ExitButton" type="Button" parent="VBoxContainer/MarginContainer/MenuButtons"]
|
||||
unique_name_in_owner = true
|
||||
layout_mode = 2
|
||||
size_flags_vertical = 10
|
||||
theme_override_colors/font_color = Color(0.356863, 0.203922, 0.0392157, 1)
|
||||
theme_override_fonts/font = ExtResource("2_aqmkw")
|
||||
theme_override_font_sizes/font_size = 45
|
||||
theme_override_styles/focus = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover_pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/hover = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/pressed = SubResource("StyleBoxFlat_0d7mr")
|
||||
theme_override_styles/normal = SubResource("StyleBoxFlat_0d7mr")
|
||||
text = "Exit"
|
||||
|
||||
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuButtons/NewGameButton" to="." method="_on_new_game_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuButtons/ContinueGameButton" to="." method="_on_continue_game_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuButtons/OptionsButton" to="." method="_on_options_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuButtons/LicensesButton" to="." method="_on_licenses_button_pressed"]
|
||||
[connection signal="pressed" from="VBoxContainer/MarginContainer/MenuButtons/ExitButton" to="." method="_on_exit_button_pressed"]
|
||||
|
|
|
|||
|
|
@ -1,16 +1,35 @@
|
|||
extends CanvasLayer
|
||||
class_name UI
|
||||
extends Node
|
||||
|
||||
@onready var ingame_menu: MarginContainer = %IngameMenu
|
||||
# these two signals come from the MainMenu and start / continue the game
|
||||
# gets sent to the main.gd scene
|
||||
signal on_new_game_started
|
||||
signal on_game_continued
|
||||
|
||||
@onready var root: CanvasLayer = $/root/Game/UI
|
||||
@onready var main_menu: Control = $/root/Game/UI/MainMenu
|
||||
@onready var ingame_controls: MarginContainer = $/root/Game/UI/IngameControls
|
||||
@onready var ingame_menu: Control = $/root/Game/UI/IngameMenu
|
||||
@onready var camera_control_area : Control = $/root/Game/UI/CameraControlArea
|
||||
@onready var save_ui : Control = $/root/Game/UI/SaveUI
|
||||
|
||||
# Called when the node enters the scene tree for the first time.
|
||||
func _ready() -> void:
|
||||
pass # Replace with function body.
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
main_menu.connect("on_game_continued", _on_main_menu_on_game_continued)
|
||||
main_menu.connect("on_new_game_started", _on_main_menu_on_new_game_started)
|
||||
|
||||
ingame_controls.connect("menu_button_clicked", _on_ingame_controls_menu_button_clicked)
|
||||
ingame_controls.connect("save_button_clicked", _on_ingame_controls_save_button_clicked)
|
||||
ingame_controls.connect("save_button_released", _on_ingame_controls_save_button_released)
|
||||
ingame_controls.connect("save_timer_incremented", _on_ingame_controls_save_timer_incremented)
|
||||
ingame_controls.connect("save_timer_reached", _on_ingame_controls_save_timer_reached)
|
||||
|
||||
pass
|
||||
|
||||
func show_main_menu(p_visible = true) -> void:
|
||||
main_menu.visible = p_visible
|
||||
|
||||
func show_ingame_controls(p_visible = true) -> void:
|
||||
ingame_controls.visible = p_visible
|
||||
|
||||
func _on_ingame_controls_menu_button_clicked() -> void:
|
||||
ingame_menu.visible = true
|
||||
|
||||
|
|
@ -26,19 +45,28 @@ func _update_ui() -> void:
|
|||
|
||||
|
||||
func _on_ingame_controls_save_button_clicked() -> void:
|
||||
%SaveUI.visible = true
|
||||
save_ui.visible = true
|
||||
|
||||
func _on_ingame_controls_save_button_released() -> void:
|
||||
%SaveUI.visible = false
|
||||
save_ui.visible = false
|
||||
|
||||
func _on_ingame_controls_save_timer_incremented(value) -> void:
|
||||
%SavePercentage.text = str(value)
|
||||
save_ui.get_node("SavePercentage").text = str(value)
|
||||
|
||||
|
||||
func _on_ingame_controls_save_timer_reached() -> void:
|
||||
%SavePercentage.text = "Saved!"
|
||||
%IngameControls.disable_save_button()
|
||||
save_ui.get_node("SavePercentage").text = "Saved!"
|
||||
ingame_controls.disable_save_button()
|
||||
await get_tree().create_timer(1.0).timeout
|
||||
%IngameControls.enable_save_button()
|
||||
$SaveUI.visible = false
|
||||
%SavePercentage.text = "0%"
|
||||
ingame_controls.enable_save_button()
|
||||
save_ui.visible = false
|
||||
save_ui.get_node("SavePercentage").text = "0%"
|
||||
|
||||
|
||||
# sends the signal from the MainMenu node up to the main.gd scene
|
||||
func _on_main_menu_on_new_game_started() -> void:
|
||||
on_new_game_started.emit()
|
||||
|
||||
# sends the signal from the MainMenu node up to the main.gd scene
|
||||
func _on_main_menu_on_game_continued() -> void:
|
||||
on_game_continued.emit()
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
[gd_scene load_steps=6 format=3 uid="uid://b5y7pdfe6ougf"]
|
||||
[gd_scene load_steps=5 format=3 uid="uid://b5y7pdfe6ougf"]
|
||||
|
||||
[ext_resource type="Script" path="res://scenes/ui/ui.gd" id="1_vyi3s"]
|
||||
[ext_resource type="Script" path="res://scripts/camera_controls.gd" id="1_x56x6"]
|
||||
[ext_resource type="PackedScene" uid="uid://dt00rjsodtady" path="res://scenes/ui/main_menu.tscn" id="3_tcmm8"]
|
||||
[ext_resource type="PackedScene" uid="uid://1anjhvi173g3" path="res://scenes/ui/ingame_controls.tscn" id="4_likk0"]
|
||||
[ext_resource type="PackedScene" uid="uid://bbvbnrcjatkrb" path="res://scenes/ui/ingame_menu.tscn" id="5_qjqu1"]
|
||||
|
||||
[node name="UI" type="CanvasLayer"]
|
||||
script = ExtResource("1_vyi3s")
|
||||
|
||||
[node name="CameraControlArea" type="Control" parent="."]
|
||||
layout_mode = 3
|
||||
|
|
@ -52,17 +50,12 @@ horizontal_alignment = 1
|
|||
vertical_alignment = 1
|
||||
|
||||
[node name="MainMenu" parent="." instance=ExtResource("3_tcmm8")]
|
||||
unique_name_in_owner = true
|
||||
|
||||
[node name="IngameControls" parent="." instance=ExtResource("4_likk0")]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
|
||||
[node name="IngameMenu" parent="." instance=ExtResource("5_qjqu1")]
|
||||
unique_name_in_owner = true
|
||||
visible = false
|
||||
|
||||
[connection signal="gui_input" from="CameraControlArea" to="CameraControlArea" method="_on_gui_input"]
|
||||
[connection signal="menu_button_clicked" from="IngameControls" to="." method="_on_ingame_controls_menu_button_clicked"]
|
||||
[connection signal="save_button_clicked" from="IngameControls" to="." method="_on_ingame_controls_save_button_clicked"]
|
||||
[connection signal="save_button_released" from="IngameControls" to="." method="_on_ingame_controls_save_button_released"]
|
||||
[connection signal="save_timer_incremented" from="IngameControls" to="." method="_on_ingame_controls_save_timer_incremented"]
|
||||
[connection signal="save_timer_reached" from="IngameControls" to="." method="_on_ingame_controls_save_timer_reached"]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,5 @@
|
|||
[gd_scene load_steps=11 format=3 uid="uid://p8agd0dfam0p"]
|
||||
[gd_scene load_steps=10 format=3 uid="uid://p8agd0dfam0p"]
|
||||
|
||||
[ext_resource type="PackedScene" uid="uid://be5bc5gjbo875" path="res://scenes/player/player.tscn" id="1_ra6oo"]
|
||||
[ext_resource type="PackedScene" uid="uid://dawpmu4vvv3rs" path="res://scenes/monster_spawnpoint/monster_spawnpoint.tscn" id="3_esgto"]
|
||||
[ext_resource type="Script" path="res://resources/monster_data.gd" id="3_iktqp"]
|
||||
[ext_resource type="Resource" uid="uid://0xqaef8uftnv" path="res://resources/monsters/debuggy.tres" id="4_noslo"]
|
||||
|
|
@ -28,8 +27,6 @@ glow_enabled = true
|
|||
|
||||
[node name="DebugLevel" type="Node3D"]
|
||||
|
||||
[node name="Player" parent="." instance=ExtResource("1_ra6oo")]
|
||||
|
||||
[node name="Floor" type="StaticBody3D" parent="."]
|
||||
metadata/_edit_lock_ = true
|
||||
|
||||
|
|
|
|||
|
|
@ -1,23 +1,14 @@
|
|||
extends Control
|
||||
|
||||
var pressed: bool = false
|
||||
var previous_position: Vector2 = Vector2(0, 0)
|
||||
var touch_delta: Vector2 = Vector2(0, 0)
|
||||
var current_delta: Vector2 = Vector2(0, 0)
|
||||
var dampening_factor: float = 0.8 # Lower values = more dampening (0-1 range)
|
||||
var previous_position : Vector2 = Vector2.ZERO
|
||||
var speed : float = 0.04
|
||||
|
||||
# Called every frame. 'delta' is the elapsed time since the previous frame.
|
||||
func _process(delta: float) -> void:
|
||||
var t = clamp(dampening_factor * delta, 0.0, 1.0) # Clamp to 0-1 range
|
||||
current_delta = lerp(current_delta, Vector2(0, 0), ease(t, -0.5)) # Use easing with lerp
|
||||
pass
|
||||
|
||||
# Simulate joystick motion using the dampened delta.
|
||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -current_delta.x * 0.1, 0)
|
||||
|
||||
# Debug: See the current delta
|
||||
#print(current_delta)
|
||||
|
||||
func _on_gui_input(event: InputEvent) -> void:
|
||||
func _gui_input(event: InputEvent) -> void:
|
||||
# Filter touch or drag events only.
|
||||
if event is not InputEventScreenTouch and event is not InputEventScreenDrag:
|
||||
return
|
||||
|
|
@ -25,16 +16,18 @@ func _on_gui_input(event: InputEvent) -> void:
|
|||
if event is InputEventScreenTouch:
|
||||
if event.is_pressed():
|
||||
pressed = true
|
||||
previous_position = event.position # Initialize previous position on touch start
|
||||
else:
|
||||
pressed = false
|
||||
touch_delta = Vector2(0, 0) # Reset delta on touch release
|
||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, 0, 0)
|
||||
|
||||
if pressed and event is InputEventScreenDrag:
|
||||
# Calculate the delta between the current and previous touch position.
|
||||
touch_delta = event.position - previous_position
|
||||
var delta_position : Vector2 = event.position - previous_position
|
||||
print(delta_position)
|
||||
simulate_joystick_motion(JOY_AXIS_RIGHT_X, -delta_position.x * speed, 0)
|
||||
#simulate_joystick_motion(JOY_AXIS_RIGHT_Y, delta_position.y * speed, 0)
|
||||
|
||||
# finally update the previous position
|
||||
previous_position = event.position
|
||||
current_delta = touch_delta * 0.5 # Update current delta with the new drag value
|
||||
|
||||
func simulate_joystick_motion(axis: int, value: float, device_id: int = 0) -> void:
|
||||
var joystick_event = InputEventJoypadMotion.new()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue