Skip to content

Commit

Permalink
Merge pull request #81 from mint-choc-chip-skyblade/feat/tracker/map-ui
Browse files Browse the repository at this point in the history
Implement a basic reusable Map node for changing scenes
  • Loading branch information
TBPixel authored Oct 22, 2023
2 parents 680e97d + 1a75fbd commit a9f27b0
Show file tree
Hide file tree
Showing 14 changed files with 246 additions and 3 deletions.
18 changes: 18 additions & 0 deletions tracker/Game.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
extends Node


@onready var current_scene: Node = $CurrentScene


func _ready() -> void:
Messenger.transition_scene.connect(_on_transition_root_scene)


func _on_transition_root_scene(scene: PackedScene) -> void:
var next_scene := scene.instantiate()
var prev_scene := current_scene.get_child(0)
if prev_scene:
prev_scene.queue_free()

current_scene.add_child(next_scene)
Messenger.transitioned_scene.emit()
Binary file added tracker/assets/images/skyloft.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tracker/assets/images/skyloft.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bidhkqygbohc"
path="res://.godot/imported/skyloft.png-a9b93c32edea3815085410cb6a1c50dd.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/images/skyloft.png"
dest_files=["res://.godot/imported/skyloft.png-a9b93c32edea3815085410cb6a1c50dd.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
Binary file added tracker/assets/images/ss-map.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions tracker/assets/images/ss-map.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://bq13h60eeg7bw"
path="res://.godot/imported/ss-map.png-6da2b8cf834318882b6eb66b6748ab36.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://assets/images/ss-map.png"
dest_files=["res://.godot/imported/ss-map.png-6da2b8cf834318882b6eb66b6748ab36.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
9 changes: 9 additions & 0 deletions tracker/default_bus_layout.tres
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
[gd_resource type="AudioBusLayout" format=3 uid="uid://0grn00ls457b"]

[resource]
bus/1/name = &"SFX"
bus/1/solo = false
bus/1/mute = false
bus/1/bypass_fx = false
bus/1/volume_db = 0.0
bus/1/send = &"Master"
10 changes: 9 additions & 1 deletion tracker/game.tscn
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
[gd_scene format=3 uid="uid://if1s7c1cbddo"]
[gd_scene load_steps=3 format=3 uid="uid://if1s7c1cbddo"]

[ext_resource type="Script" path="res://Game.gd" id="1_rn7ya"]
[ext_resource type="PackedScene" uid="uid://bjly5ntj2jhfn" path="res://scenes/maps/world.tscn" id="1_tsgx8"]

[node name="Game" type="Node"]
script = ExtResource("1_rn7ya")

[node name="CurrentScene" type="Node" parent="."]

[node name="World" parent="CurrentScene" instance=ExtResource("1_tsgx8")]
23 changes: 22 additions & 1 deletion tracker/project.godot
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ boot_splash/show_image=false

[autoload]

Startup="*res://systems/startup.gd"
Startup="*res://systems/Startup.gd"
Messenger="*res://systems/Messenger.gd"

[display]

Expand All @@ -29,6 +30,26 @@ window/size/viewport_height=720

run/main_run_args="-- --seed=TEST"

[input]

interact={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(158, 21),"global_position":Vector2(162, 62),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
zoom_in={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":8,"position":Vector2(116, 16),"global_position":Vector2(120, 57),"factor":1.0,"button_index":4,"canceled":false,"pressed":true,"double_click":false,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":1,"position":Vector2(557, 28),"global_position":Vector2(565, 108),"factor":1.0,"button_index":1,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}
zoom_out={
"deadzone": 0.5,
"events": [Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":16,"position":Vector2(219, 15),"global_position":Vector2(223, 56),"factor":1.0,"button_index":5,"canceled":false,"pressed":true,"double_click":false,"script":null)
, Object(InputEventMouseButton,"resource_local_to_scene":false,"resource_name":"","device":-1,"window_id":0,"alt_pressed":false,"shift_pressed":false,"ctrl_pressed":false,"meta_pressed":false,"button_mask":2,"position":Vector2(696, 15),"global_position":Vector2(704, 95),"factor":1.0,"button_index":2,"canceled":false,"pressed":true,"double_click":false,"script":null)
]
}

[rendering]

textures/canvas_textures/default_texture_filter=0
Expand Down
58 changes: 58 additions & 0 deletions tracker/scenes/maps/Map.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@tool
extends CanvasLayer
class_name Map


# child_scene specifies the target that this scene
# will transition into when entered.
@export_file var child_scene: String
# parent_scene specifies the target parent that
# this scene will transition to when exited.
@export_file var parent_scene: String


# interactable_area is the child interaction zone for this node.
#
# When an interaction occurs within this area, the node should act.
@onready var interactable_area: Area2D = find_child("Area2D")


func _ready() -> void:
# if we have a child_scene and an interactable area, listen to events
if child_scene && interactable_area:
interactable_area.connect("input_event", _on_area_2d_input_event)


func _get_configuration_warnings() -> PackedStringArray:
var warnings = []

if child_scene && !interactable_area:
warnings.append("Map's with a child_scene must have an Area2D")

# Returning an empty array means "no warning".
return warnings


func _on_area_2d_input_event(_viewport: Node, event: InputEvent, _shape_idx: int) -> void:
if event.is_action_pressed("zoom_in"):
open_child_map()


func _input(event: InputEvent) -> void:
if event.is_action("zoom_out"):
close_child_map()



func close_child_map() -> void:
if !parent_scene:
return

Messenger.transition_scene.emit(load(parent_scene))


func open_child_map() -> void:
if !child_scene:
return

Messenger.transition_scene.emit(load(child_scene))
6 changes: 6 additions & 0 deletions tracker/scenes/maps/map.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://bjeedodu068xb"]

[ext_resource type="Script" path="res://scenes/maps/Map.gd" id="1_wjh8i"]

[node name="Map" type="CanvasLayer"]
script = ExtResource("1_wjh8i")
21 changes: 21 additions & 0 deletions tracker/scenes/maps/skyloft/skyloft.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[gd_scene load_steps=3 format=3 uid="uid://cmugiqudyuot6"]

[ext_resource type="Texture2D" uid="uid://bidhkqygbohc" path="res://assets/images/skyloft.png" id="1_vyvj7"]
[ext_resource type="Script" path="res://scenes/maps/Map.gd" id="2_5nb6n"]

[node name="Skyloft" type="Node"]

[node name="Map" type="CanvasLayer" parent="."]
script = ExtResource("2_5nb6n")
parent_scene = "res://scenes/maps/world.tscn"

[node name="TextureRect" type="TextureRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_vyvj7")
expand_mode = 1
stretch_mode = 5
metadata/_edit_lock_ = true
30 changes: 30 additions & 0 deletions tracker/scenes/maps/world.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[gd_scene load_steps=4 format=3 uid="uid://bjly5ntj2jhfn"]

[ext_resource type="Texture2D" uid="uid://bq13h60eeg7bw" path="res://assets/images/ss-map.png" id="1_uijf8"]
[ext_resource type="Script" path="res://scenes/maps/Map.gd" id="2_c7043"]

[sub_resource type="CircleShape2D" id="CircleShape2D_lsvye"]
radius = 96.421

[node name="World" type="Node"]

[node name="TextureRect" type="TextureRect" parent="."]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
texture = ExtResource("1_uijf8")
expand_mode = 1
stretch_mode = 5

[node name="Skyloft" type="CanvasLayer" parent="."]
script = ExtResource("2_c7043")
child_scene = "res://scenes/maps/skyloft/skyloft.tscn"

[node name="Area2D" type="Area2D" parent="Skyloft"]
position = Vector2(640, 333)
metadata/_edit_lock_ = true

[node name="CollisionShape2D" type="CollisionShape2D" parent="Skyloft/Area2D"]
shape = SubResource("CircleShape2D_lsvye")
4 changes: 4 additions & 0 deletions tracker/systems/Messenger.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
extends Node

signal transition_scene(scene: PackedScene)
signal transitioned_scene
2 changes: 1 addition & 1 deletion tracker/systems/startup.gd
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var ARGS := {
"seed": ""
}

func _ready():
func _ready() -> void:
for argument in OS.get_cmdline_user_args():
if argument.find("=") > -1:
var key_value = argument.split("=")
Expand Down

0 comments on commit a9f27b0

Please sign in to comment.