Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue-46: Map Display #58

Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions #Scenes/MapUI.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[gd_scene load_steps=3 format=3 uid="uid://ki060lfrgty4"]

[ext_resource type="Script" path="res://UI/MapUI.gd" id="1_enf2f"]
[ext_resource type="Script" path="res://addons/SmoothScroll/SmoothScrollContainer.gd" id="2_2gata"]

[node name="MapUi" 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_enf2f")

[node name="ColorRect" type="ColorRect" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
color = Color(0, 0, 0, 0.309804)

[node name="SmoothScrollContainer" type="ScrollContainer" parent="."]
layout_mode = 0
offset_left = 223.0
offset_top = 60.0
offset_right = 1123.0
offset_bottom = 660.0
script = ExtResource("2_2gata")
speed = 2.0
allow_overdragging = false

[node name="RoomContainer" type="ColorRect" parent="SmoothScrollContainer"]
clip_contents = true
custom_minimum_size = Vector2(900, 600)
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
layout_mode = 2
mouse_filter = 1
color = Color(0.498039, 0.498039, 0.498039, 1)

[node name="Button" type="Button" parent="."]
layout_mode = 0
offset_left = 4.0
offset_top = 550.0
offset_right = 65.0
offset_bottom = 581.0
text = "Return"

[connection signal="pressed" from="Button" to="." method="_on_return_button_press"]
23 changes: 22 additions & 1 deletion #Scenes/TestingScene.tscn
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[gd_scene load_steps=22 format=3 uid="uid://b60uabg68ra1l"]
[gd_scene load_steps=25 format=3 uid="uid://b60uabg68ra1l"]

[ext_resource type="Script" path="res://Map/MapManager.gd" id="2_50npk"]
[ext_resource type="PackedScene" uid="uid://clmg3l3n28x38" path="res://Entity/Player/Player.tscn" id="3_4psp7"]
[ext_resource type="PackedScene" uid="uid://dpjfy4pv0vxst" path="res://Cards/CardContainer.tscn" id="3_e7sws"]
[ext_resource type="Resource" uid="uid://dxgoopi1roxu4" path="res://Cards/Resource/Card_Damage.tres" id="4_wvn3v"]
Expand All @@ -19,6 +20,8 @@
[ext_resource type="Script" path="res://UI/EndTurnButton.gd" id="14_dpe64"]
[ext_resource type="Texture2D" uid="uid://hqkt8t1v2f5h" path="res://Cards/deck_pile.png" id="18_b54hn"]
[ext_resource type="Script" path="res://UI/DeckPileUISetter.gd" id="19_ucc6f"]
[ext_resource type="Texture2D" uid="uid://cjlatwiw7r80d" path="res://Map/map_icon.png" id="20_tiho6"]
[ext_resource type="Script" path="res://UI/MapButton.gd" id="22_druf4"]

[sub_resource type="Resource" id="Resource_82ci8"]
script = ExtResource("10_qowiy")
Expand All @@ -39,6 +42,9 @@ metadata/_edit_vertical_guides_ = [1216.0]

[node name="Battler" parent="." instance=ExtResource("8_qtw1k")]

[node name="TestMap" type="Node2D" parent="."]
script = ExtResource("2_50npk")

[node name="Player" parent="." instance=ExtResource("3_4psp7")]
position = Vector2(595, 284)

Expand Down Expand Up @@ -169,4 +175,19 @@ stretch_mode = 0
script = ExtResource("19_ucc6f")
metadata/_edit_use_anchors_ = true

[node name="MapIcon" type="TextureButton" parent="CanvasLayer/UIControl"]
layout_mode = 0
offset_left = 1174.0
offset_top = 31.0
offset_right = 1214.0
offset_bottom = 71.0
texture_normal = ExtResource("20_tiho6")
texture_pressed = ExtResource("20_tiho6")
texture_hover = ExtResource("20_tiho6")
texture_disabled = ExtResource("20_tiho6")
texture_focused = ExtResource("20_tiho6")
ignore_texture_size = true
stretch_mode = 0
script = ExtResource("22_druf4")

[connection signal="pressed" from="CanvasLayer/UIControl/EndTurnButton" to="CanvasLayer/UIControl/EndTurnButton" method="_on_pressed"]
9 changes: 9 additions & 0 deletions Map/MapManager.gd
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
extends Node2D
## Class to manage backend for rooms (generation and such)

var current_map: MapBase
var map_width_array: Array[int] = [1, 3, 5, 7, 9, 11, 9, 7, 5, 3, 1]

#map_floors_width changes the width of the map's floors
static func create_map(map_floors_width: Array[int]) -> MapBase: ## Generates and Populates a map with rooms that have random room types. More in depth algorithms will be added in the future
Expand All @@ -26,3 +29,9 @@ static func create_map(map_floors_width: Array[int]) -> MapBase: ## Generates an
_grid[index_height].append_array(_padding)
_map.rooms = _grid
return _map as MapBase

func _ready():
current_map = MapManager.create_map(map_width_array)
Turtyo marked this conversation as resolved.
Show resolved Hide resolved

func is_map_initialized() -> bool:
return current_map != null
12 changes: 12 additions & 0 deletions Map/RoomBase.gd
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,15 @@ class_name RoomBase

func _to_string() -> String:
return "RoomBase"

func get_room_abbreviation() -> String:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
if room_event is EventHeal:
return "H"
elif room_event is EventMob:
return "M"
elif room_event is EventRandom:
return "R"
elif room_event is EventShop:
return "S"
else:
return ""
10 changes: 10 additions & 0 deletions Map/RoomUI.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
extends Control

var room: RoomBase
var label: Label
cheesefrycook marked this conversation as resolved.
Show resolved Hide resolved

func _ready():
label = get_child(0).get_child(0)

func set_label(title: String):
label.set_text(title)
26 changes: 26 additions & 0 deletions Map/RoomUI.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
[gd_scene load_steps=3 format=3 uid="uid://ck87o46d1kvpu"]

[ext_resource type="Script" path="res://Map/RoomUI.gd" id="1_n442j"]
[ext_resource type="Texture2D" uid="uid://dxpg0rdhgt587" path="res://Map/room_icon.png" id="2_mdfia"]

[node name="RoomUI" type="Control"]
layout_mode = 3
anchors_preset = 0
size_flags_horizontal = 4
size_flags_vertical = 4
script = ExtResource("1_n442j")

[node name="RoomEdge" type="TextureRect" parent="."]
layout_mode = 0
offset_right = 50.0
offset_bottom = 50.0
texture = ExtResource("2_mdfia")
expand_mode = 1

[node name="Label" type="Label" parent="RoomEdge"]
layout_mode = 0
offset_right = 50.0
offset_bottom = 50.0
text = "A"
horizontal_alignment = 1
vertical_alignment = 1
Binary file added Map/map_icon.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 Map/map_icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://cjlatwiw7r80d"
path="res://.godot/imported/map_icon.png-ca4387eafbb70e74b0ffbb41a9cb9905.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Map/map_icon.png"
dest_files=["res://.godot/imported/map_icon.png-ca4387eafbb70e74b0ffbb41a9cb9905.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 Map/room_icon.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 Map/room_icon.png.import
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
[remap]

importer="texture"
type="CompressedTexture2D"
uid="uid://dxpg0rdhgt587"
path="res://.godot/imported/room_icon.png-92b66821e87e400c614959fc9bbfa774.ctex"
metadata={
"vram_texture": false
}

[deps]

source_file="res://Map/room_icon.png"
dest_files=["res://.godot/imported/room_icon.png-92b66821e87e400c614959fc9bbfa774.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
11 changes: 11 additions & 0 deletions UI/MapButton.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
extends TextureButton
# Button to bring up the map UI

@onready var map_scene: PackedScene = preload("res://#Scenes/MapUI.tscn")

func _pressed():
assert(MapManager.is_map_initialized(), "Please instantiate map")
var parent: Control = $".."
var map: Control = map_scene.instantiate()

parent.add_child(map)
70 changes: 70 additions & 0 deletions UI/MapUI.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
extends Control

var map_scene: PackedScene = preload("res://#Scenes/CardScrollUI.tscn")
var room_ui: PackedScene = load("res://Map/RoomUI.tscn")
var _padding_offset = 20

func _input(_inputevent: InputEvent) -> void:
if Input.is_key_pressed(KEY_ESCAPE):
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
queue_free()


func _on_return_button_press():
queue_free()


var _ROOM_TEXTURE_INDEX = 0
var _COLOR_RECT_INDEX = 0
var _SCROLL_CONTAINER_INDEX = 1
var _ROOM_CONTAINER_INDEX = 0

func _ready():
var current_map: MapBase = MapManager.current_map

# Create New Room Object to append to the room container
var new_room: Control = room_ui.instantiate()
var new_room_size: Vector2 = new_room.get_child(_ROOM_TEXTURE_INDEX).get_size()

# Get the objets of the Map UI Scene
var color_rect: ColorRect = get_child(_COLOR_RECT_INDEX)
var scroll_container: SmoothScrollContainer = get_child(_SCROLL_CONTAINER_INDEX)
var vertical_scroll_bar: VScrollBar = scroll_container.get_v_scroll_bar()
var room_container: ColorRect = scroll_container.get_child(_ROOM_CONTAINER_INDEX)
cheesefrycook marked this conversation as resolved.
Show resolved Hide resolved

# Calculate the height of the container where the rooms will reside in. This will be dynamic based on the map array that we have.
# The array we have in MapManager, each element will increase the height of the map display,
# multiply by the size of a room w/ some offset to dynamically set the size of the container of which we will be scrolling.
var room_container_height: float = MapManager.map_width_array.size() * (new_room_size.y + _padding_offset)
room_container.set_custom_minimum_size(Vector2(room_container.get_custom_minimum_size().x, room_container_height))

# Get the x coordinate of the halfway point of the room container
var room_container_halfway_position_x: float = room_container.position.x + room_container.get_size().x / 2

# Get the width of the floor that has the most rooms, by getting the size of what a room is w/ some offset, then
var longest_floor_size_width: float = (new_room_size.x + _padding_offset) * MapManager.map_width_array.max()

var scroll_container_bottom_y_position: float = scroll_container.position.y + scroll_container.get_size().y

# Starting positions for the next room to be generated
# X = the Halfway position of room container - half the size of the longest floor to account for centering the all of the rooms.
# Add a little padding to push it away from the right edge.
# Y = Height of the Room Container that was calculated in room_container_height - (Screen Height - scroll container's bottom y position)
var start_position_for_next_room_x: float = room_container_halfway_position_x - longest_floor_size_width / 2 + _padding_offset
var start_position_for_next_room_y: float = room_container.get_custom_minimum_size().y - (color_rect.get_size().y - scroll_container_bottom_y_position)
var position_for_next_room: Vector2 = Vector2(start_position_for_next_room_x, start_position_for_next_room_y)

for floor: Array in current_map.rooms:
Turtyo marked this conversation as resolved.
Show resolved Hide resolved
# When we're done populating a floor and we go to the next index, reset the X start position
position_for_next_room.x = start_position_for_next_room_x
for room: RoomBase in floor:
if (room != null):
var room_display: Control = room_ui.instantiate()
room_container.add_child(room_display)
room_display.set_label(room.get_room_abbreviation())
room_display.position = position_for_next_room
# When we go through the array of a floor to put a room down,
# increase the X position to the new potential area the room will be displayed on.
position_for_next_room.x += new_room_size.x + _padding_offset
# When we finish the array for a floor we need to go to the next floor up,
# so increase the Y position to the new area the room will be displayed on.
position_for_next_room.y -= new_room_size.y + _padding_offset
Loading
Loading