diff --git a/project.godot b/project.godot index 42e8f98..fd1cabf 100644 --- a/project.godot +++ b/project.godot @@ -18,6 +18,7 @@ config/icon="res://icon.svg" [autoload] Grid="*res://scripts/autoloads/grid.gd" +ResourceManager="*res://scripts/autoloads/resource_manager.gd" [debug] @@ -29,6 +30,38 @@ theme/custom="res://data/world_theme.tres" [input] +ui_left={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194319,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":13,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":-1.0,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":65,"key_label":0,"unicode":97,"echo":false,"script":null) +] +} +ui_right={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194321,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":14,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":0,"axis_value":1.0,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":68,"key_label":0,"unicode":100,"echo":false,"script":null) +] +} +ui_up={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194320,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":11,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":-1.0,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":87,"key_label":0,"unicode":119,"echo":false,"script":null) +] +} +ui_down={ +"deadzone": 0.5, +"events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":4194322,"physical_keycode":0,"key_label":0,"unicode":0,"echo":false,"script":null) +, Object(InputEventJoypadButton,"resource_local_to_scene":false,"resource_name":"","device":0,"button_index":12,"pressure":0.0,"pressed":false,"script":null) +, Object(InputEventJoypadMotion,"resource_local_to_scene":false,"resource_name":"","device":0,"axis":1,"axis_value":1.0,"script":null) +, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":83,"key_label":0,"unicode":115,"echo":false,"script":null) +] +} view_right={ "deadzone": 0.5, "events": [Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"pressed":false,"keycode":0,"physical_keycode":4194321,"key_label":0,"unicode":0,"echo":false,"script":null) diff --git a/scene/build_menu.tscn b/scene/build_menu.tscn index 79fc58b..98b14c2 100644 --- a/scene/build_menu.tscn +++ b/scene/build_menu.tscn @@ -36,6 +36,7 @@ size_flags_horizontal = 3 [node name="BuildingGroups" type="ItemList" parent="MarginContainer/PanelContainer/HBoxContainer/ScrollContainer/VBoxContainer"] layout_mode = 2 size_flags_vertical = 3 +allow_search = false auto_height = true [node name="ScrollContainer2" type="ScrollContainer" parent="MarginContainer/PanelContainer/HBoxContainer"] diff --git a/scene/interaction_bar.tscn b/scene/interaction_bar.tscn index 37c4eea..c00926f 100644 --- a/scene/interaction_bar.tscn +++ b/scene/interaction_bar.tscn @@ -3,12 +3,7 @@ [ext_resource type="Script" path="res://scripts/interaction_bar.gd" id="1_qwnlc"] [node name="InteractionBar" type="ProgressBar"] -anchors_preset = 15 -anchor_right = 1.0 -anchor_bottom = 1.0 -offset_right = -1092.0 -offset_bottom = -628.0 -grow_horizontal = 2 -grow_vertical = 2 +offset_right = 60.0 +offset_bottom = 20.0 show_percentage = false script = ExtResource("1_qwnlc") diff --git a/scene/player.tscn b/scene/player.tscn index 9c649cb..4a9c530 100644 --- a/scene/player.tscn +++ b/scene/player.tscn @@ -82,7 +82,6 @@ size = Vector2(40, 45) [node name="Player" type="CharacterBody2D"] motion_mode = 1 script = ExtResource("1_j0htm") -SPEED = null [node name="Sprite" type="AnimatedSprite2D" parent="."] sprite_frames = SubResource("SpriteFrames_tj1nq") diff --git a/scene/world.tscn b/scene/world.tscn index 6514d1e..407286b 100644 --- a/scene/world.tscn +++ b/scene/world.tscn @@ -1,11 +1,10 @@ -[gd_scene load_steps=12 format=3 uid="uid://m0us5xqa3gnk"] +[gd_scene load_steps=11 format=3 uid="uid://m0us5xqa3gnk"] [ext_resource type="Script" path="res://scripts/world.gd" id="1_yf6q1"] [ext_resource type="Resource" uid="uid://dr00rd4f42jqe" path="res://data/game_resources/gem/gem_resource.tres" id="2_rn4a2"] [ext_resource type="TileSet" uid="uid://d1sh6dy2w10b0" path="res://data/scifi_tileset.tres" id="2_sa7dm"] [ext_resource type="Resource" uid="uid://bpjj0x7jr1k6u" path="res://data/game_resources/carbon/carbon_resource.tres" id="3_pq6ic"] [ext_resource type="Script" path="res://scripts/building_manager.gd" id="4_61js3"] -[ext_resource type="Script" path="res://scripts/resource_manager.gd" id="5_k5643"] [ext_resource type="Texture2D" uid="uid://n806c03hgaq1" path="res://assets/scifi_tilesheet@2.png" id="5_qhth7"] [ext_resource type="Script" path="res://scripts/gui.gd" id="6_yuatk"] @@ -41,13 +40,6 @@ layer_4/tile_data = PackedInt32Array() [node name="BuildingManager" type="Node2D" parent="."] script = ExtResource("4_61js3") -[node name="ResourceManager" type="Node2D" parent="."] -script = ExtResource("5_k5643") - -[node name="Timer" type="Timer" parent="ResourceManager"] -wait_time = 5.0 -autostart = true - [node name="CanvasLayer" type="CanvasLayer" parent="."] [node name="GUI" type="Control" parent="CanvasLayer"] @@ -146,6 +138,3 @@ other info here too" layout_mode = 2 size_flags_horizontal = 3 size_flags_stretch_ratio = 2.0 - -[connection signal="changed_resource" from="ResourceManager" to="CanvasLayer/GUI" method="_on_resource_manager_changed_resource"] -[connection signal="timeout" from="ResourceManager/Timer" to="ResourceManager" method="_on_timer_timeout"] diff --git a/scripts/resource_manager.gd b/scripts/autoloads/resource_manager.gd similarity index 93% rename from scripts/resource_manager.gd rename to scripts/autoloads/resource_manager.gd index 6b50340..8238c54 100644 --- a/scripts/resource_manager.gd +++ b/scripts/autoloads/resource_manager.gd @@ -1,9 +1,6 @@ -extends Node2D signal changed_resource -@onready var world: World = $".." - @export var resources := {} func _on_gained_resource(res: GameResource) -> void: diff --git a/scripts/build_menu.gd b/scripts/build_menu.gd index 164208a..5322cd4 100644 --- a/scripts/build_menu.gd +++ b/scripts/build_menu.gd @@ -20,6 +20,7 @@ const BASIC_BUILDING_GROUP = preload("res://data/buildings/basic/basic_building_ func _ready() -> void: _add_building_group(BASIC_BUILDING_GROUP) _add_building_group(ADVANCED_BUILDING_GROUP) + building_groups.set_focus() func _add_building_group(group: BuildingGroup) -> void: building_groups.add_item(group.name, group.atlas_texture) diff --git a/scripts/building_manager.gd b/scripts/building_manager.gd index 7bfe73f..465597e 100644 --- a/scripts/building_manager.gd +++ b/scripts/building_manager.gd @@ -4,11 +4,11 @@ extends Node2D var base = preload("res://scene/base.tscn") var building = preload("res://data/buildings/hub.tres") -func _unhandled_input(event): - if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT: - var build: Base = base.instantiate() - build.position = get_global_mouse_position() - build.world = world - build.building_data = building.duplicate(true) - add_child(build) +#func _unhandled_input(event): + #if event is InputEventMouseButton and event.is_pressed() and event.button_index == MOUSE_BUTTON_LEFT: + #var build: Base = base.instantiate() + #build.position = get_global_mouse_position() + #build.world = world + #build.building_data = building.duplicate(true) + #add_child(build) #world_grid.set_cell(2, world_grid.local_to_map(get_global_mouse_position()), 0, Vector2i(16,2)) diff --git a/scripts/gui.gd b/scripts/gui.gd index 2a27c60..231af5a 100644 --- a/scripts/gui.gd +++ b/scripts/gui.gd @@ -17,11 +17,11 @@ func _on_resource_manager_changed_resource(changed: ResourceChangedSignal) -> vo img.expand_mode = TextureRect.EXPAND_FIT_WIDTH_PROPORTIONAL resource_container.add_child(img) - var label = Label.new() + var label := Label.new() label.text = str(changed.changed_resources[resource]) resource_container.add_child(label) - var data = ResourceData.new() + var data := ResourceData.new() data.image = img data.label = label data.value = changed.changed_resources[resource] diff --git a/scripts/interaction_bar.gd b/scripts/interaction_bar.gd index c34eaf9..f41a482 100644 --- a/scripts/interaction_bar.gd +++ b/scripts/interaction_bar.gd @@ -3,11 +3,17 @@ class_name InteractionBar signal interaction_finished +var grid_position: Vector2i + func _ready() -> void: + position = Grid.grid_to_world_center(grid_position) - Vector2(30,10) + var tween = get_tree().create_tween() tween.tween_property(self, "value", 100, 3) tween.tween_callback(_cleanup_gather) func _cleanup_gather() -> void: interaction_finished.emit() + var res: GameResource = Grid.get_location_data(grid_position).get_resource() + res.gained_resource.emit(res) self.queue_free() diff --git a/scripts/player.gd b/scripts/player.gd index 2a91c31..0f58fae 100644 --- a/scripts/player.gd +++ b/scripts/player.gd @@ -42,9 +42,10 @@ func _input(event: InputEvent) -> void: var build: BuildingBase = BUILDING_BASE.instantiate() build.initialize(_attempting_build, interaction_location) add_sibling(build) - if not _interacting and Grid.get_location_data(interaction_location).is_interactable(): + elif not _interacting and Grid.get_location_data(interaction_location).is_interactable(): var interaction = INTERACTION_BAR.instantiate() - interaction.position = Grid.grid_to_world_center(interaction_location) - Vector2(30,10) + interaction.interaction_finished.connect(_on_interaction_finished) + interaction.grid_position = interaction_location _interacting = true add_sibling(interaction) if event.is_action_pressed("build"): @@ -52,6 +53,9 @@ func _input(event: InputEvent) -> void: build_menu.build.connect(_on_build_menu_build) add_sibling(build_menu) +func _on_interaction_finished() -> void: + _interacting = false + func _on_build_menu_build(building: Building) -> void: print("Building: %s" % building.name) _attempting_build = building