Skip to content

Commit

Permalink
Merge pull request #414 from snipercup/move-overmapvisualization
Browse files Browse the repository at this point in the history
Move overmap visualization to overmap area editor
  • Loading branch information
snipercup authored Oct 17, 2024
2 parents 27a1b71 + 6188c87 commit e63ebbe
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 144 deletions.
96 changes: 54 additions & 42 deletions Scenes/ContentManager/Custom_Editors/OvermapAreaEditor.tscn
Original file line number Diff line number Diff line change
@@ -1,78 +1,86 @@
[gd_scene load_steps=3 format=3 uid="uid://b3ggaal1e2obk"]
[gd_scene load_steps=4 format=3 uid="uid://b3ggaal1e2obk"]

[ext_resource type="Script" path="res://Scenes/ContentManager/Custom_Editors/Scripts/OvermapAreaEditor.gd" id="1_g1n4r"]
[ext_resource type="PackedScene" uid="uid://2kp6gjwaextr" path="res://Scenes/ContentManager/Custom_Widgets/Overmap_Area_Region_editor.tscn" id="2_jtxai"]
[ext_resource type="PackedScene" uid="uid://neuhnehifngf" path="res://Scenes/ContentManager/OtherTools/overmap_area_visualization.tscn" id="3_y3jo3"]

[node name="OvermapAreaEditor" type="Control" node_paths=PackedStringArray("IDTextLabel", "NameTextEdit", "DescriptionTextEdit", "min_width_spin_box", "min_height_spin_box", "max_width_spin_box", "max_height_spin_box", "region_name_text_edit", "region_v_box_container")]
[node name="OvermapAreaEditor" type="Control" node_paths=PackedStringArray("IDTextLabel", "NameTextEdit", "DescriptionTextEdit", "min_width_spin_box", "min_height_spin_box", "max_width_spin_box", "max_height_spin_box", "region_name_text_edit", "region_v_box_container", "overmap_area_visualization")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_g1n4r")
IDTextLabel = NodePath("VBoxContainer/FormGrid/IDTextLabel")
NameTextEdit = NodePath("VBoxContainer/FormGrid/NameTextEdit")
DescriptionTextEdit = NodePath("VBoxContainer/FormGrid/DescriptionTextEdit")
min_width_spin_box = NodePath("VBoxContainer/FormGrid/DimensionsHBoxContainer/MinWidthSpinBox")
min_height_spin_box = NodePath("VBoxContainer/FormGrid/DimensionsHBoxContainer/MinHeightSpinBox")
max_width_spin_box = NodePath("VBoxContainer/FormGrid/DimensionsHBoxContainer/MaxWidthSpinBox")
max_height_spin_box = NodePath("VBoxContainer/FormGrid/DimensionsHBoxContainer/MaxHeightSpinBox")
region_name_text_edit = NodePath("VBoxContainer/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer/RegionNameTextEdit")
region_v_box_container = NodePath("VBoxContainer/FormGrid/RegionsVBoxContainer/RegionVBoxContainer")
IDTextLabel = NodePath("TabContainer/General/FormGrid/IDTextLabel")
NameTextEdit = NodePath("TabContainer/General/FormGrid/NameTextEdit")
DescriptionTextEdit = NodePath("TabContainer/General/FormGrid/DescriptionTextEdit")
min_width_spin_box = NodePath("TabContainer/General/FormGrid/DimensionsHBoxContainer/MinWidthSpinBox")
min_height_spin_box = NodePath("TabContainer/General/FormGrid/DimensionsHBoxContainer/MinHeightSpinBox")
max_width_spin_box = NodePath("TabContainer/General/FormGrid/DimensionsHBoxContainer/MaxWidthSpinBox")
max_height_spin_box = NodePath("TabContainer/General/FormGrid/DimensionsHBoxContainer/MaxHeightSpinBox")
region_name_text_edit = NodePath("TabContainer/General/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer/RegionNameTextEdit")
region_v_box_container = NodePath("TabContainer/General/FormGrid/RegionsVBoxContainer/RegionVBoxContainer")
overmap_area_region_editor = ExtResource("2_jtxai")
overmap_area_visualization = NodePath("TabContainer/Generate")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
[node name="TabContainer" type="TabContainer" parent="."]
layout_mode = 1
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
current_tab = 1

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
[node name="General" type="VBoxContainer" parent="TabContainer"]
visible = false
layout_mode = 2
metadata/_tab_index = 0

[node name="CloseButton" type="Button" parent="VBoxContainer/HBoxContainer"]
[node name="HBoxContainer" type="HBoxContainer" parent="TabContainer/General"]
layout_mode = 2

[node name="CloseButton" type="Button" parent="TabContainer/General/HBoxContainer"]
layout_mode = 2
text = "Close"

[node name="SaveButton" type="Button" parent="VBoxContainer/HBoxContainer"]
[node name="SaveButton" type="Button" parent="TabContainer/General/HBoxContainer"]
layout_mode = 2
text = "Save"

[node name="FormGrid" type="GridContainer" parent="VBoxContainer"]
[node name="FormGrid" type="GridContainer" parent="TabContainer/General"]
layout_mode = 2
size_flags_vertical = 3
columns = 2

[node name="IDLabel" type="Label" parent="VBoxContainer/FormGrid"]
[node name="IDLabel" type="Label" parent="TabContainer/General/FormGrid"]
layout_mode = 2
text = "ID:"

[node name="IDTextLabel" type="Label" parent="VBoxContainer/FormGrid"]
[node name="IDTextLabel" type="Label" parent="TabContainer/General/FormGrid"]
custom_minimum_size = Vector2(0, 30)
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.1

[node name="NameLabel" type="Label" parent="VBoxContainer/FormGrid"]
[node name="NameLabel" type="Label" parent="TabContainer/General/FormGrid"]
layout_mode = 2
text = "Name"

[node name="NameTextEdit" type="TextEdit" parent="VBoxContainer/FormGrid"]
[node name="NameTextEdit" type="TextEdit" parent="TabContainer/General/FormGrid"]
custom_minimum_size = Vector2(0, 30)
layout_mode = 2
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.1
focus_next = NodePath("../DescriptionTextEdit")
placeholder_text = "City"

[node name="DescriptionLabel" type="Label" parent="VBoxContainer/FormGrid"]
[node name="DescriptionLabel" type="Label" parent="TabContainer/General/FormGrid"]
layout_mode = 2
text = "Description"

[node name="DescriptionTextEdit" type="TextEdit" parent="VBoxContainer/FormGrid"]
[node name="DescriptionTextEdit" type="TextEdit" parent="TabContainer/General/FormGrid"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3
Expand All @@ -81,76 +89,80 @@ focus_previous = NodePath("../NameTextEdit")
placeholder_text = "Creates a bunch of shops and houses representing a city"
wrap_mode = 1

[node name="DimensionsLabel" type="Label" parent="VBoxContainer/FormGrid"]
[node name="DimensionsLabel" type="Label" parent="TabContainer/General/FormGrid"]
layout_mode = 2
text = "Dimensions"

[node name="DimensionsHBoxContainer" type="HBoxContainer" parent="VBoxContainer/FormGrid"]
[node name="DimensionsHBoxContainer" type="HBoxContainer" parent="TabContainer/General/FormGrid"]
layout_mode = 2

[node name="MinWidthLabel" type="Label" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MinWidthLabel" type="Label" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
text = "Min width:"

[node name="MinWidthSpinBox" type="SpinBox" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MinWidthSpinBox" type="SpinBox" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
step = 4.0
value = 4.0

[node name="MinHeightLabel" type="Label" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MinHeightLabel" type="Label" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
text = "Min height:"

[node name="MinHeightSpinBox" type="SpinBox" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MinHeightSpinBox" type="SpinBox" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
step = 4.0
value = 4.0

[node name="MaxWidthLabel" type="Label" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MaxWidthLabel" type="Label" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
text = "Max width"

[node name="MaxWidthSpinBox" type="SpinBox" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MaxWidthSpinBox" type="SpinBox" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
step = 4.0
value = 16.0

[node name="MaxHeightLabel" type="Label" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MaxHeightLabel" type="Label" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
text = "Max height:"

[node name="MaxHeightSpinBox" type="SpinBox" parent="VBoxContainer/FormGrid/DimensionsHBoxContainer"]
[node name="MaxHeightSpinBox" type="SpinBox" parent="TabContainer/General/FormGrid/DimensionsHBoxContainer"]
layout_mode = 2
step = 4.0
value = 16.0

[node name="RegionsLabel" type="Label" parent="VBoxContainer/FormGrid"]
[node name="RegionsLabel" type="Label" parent="TabContainer/General/FormGrid"]
layout_mode = 2
text = "Regions:"

[node name="RegionsVBoxContainer" type="VBoxContainer" parent="VBoxContainer/FormGrid"]
[node name="RegionsVBoxContainer" type="VBoxContainer" parent="TabContainer/General/FormGrid"]
layout_mode = 2
size_flags_horizontal = 3
size_flags_vertical = 3

[node name="RegionAddControlsHBoxContainer" type="HBoxContainer" parent="VBoxContainer/FormGrid/RegionsVBoxContainer"]
[node name="RegionAddControlsHBoxContainer" type="HBoxContainer" parent="TabContainer/General/FormGrid/RegionsVBoxContainer"]
layout_mode = 2

[node name="RegionNameLabel" type="Label" parent="VBoxContainer/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer"]
[node name="RegionNameLabel" type="Label" parent="TabContainer/General/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer"]
layout_mode = 2
text = "Region name:"

[node name="RegionNameTextEdit" type="TextEdit" parent="VBoxContainer/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer"]
[node name="RegionNameTextEdit" type="TextEdit" parent="TabContainer/General/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer"]
custom_minimum_size = Vector2(160, 30)
layout_mode = 2

[node name="RegionAddButton" type="Button" parent="VBoxContainer/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer"]
[node name="RegionAddButton" type="Button" parent="TabContainer/General/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer"]
layout_mode = 2
text = "Add"

[node name="RegionVBoxContainer" type="VBoxContainer" parent="VBoxContainer/FormGrid/RegionsVBoxContainer"]
[node name="RegionVBoxContainer" type="VBoxContainer" parent="TabContainer/General/FormGrid/RegionsVBoxContainer"]
layout_mode = 2

[node name="Generate" parent="TabContainer" instance=ExtResource("3_y3jo3")]
layout_mode = 2
metadata/_tab_index = 1

[connection signal="button_up" from="VBoxContainer/HBoxContainer/CloseButton" to="." method="_on_close_button_button_up"]
[connection signal="button_up" from="VBoxContainer/HBoxContainer/SaveButton" to="." method="_on_save_button_button_up"]
[connection signal="button_up" from="VBoxContainer/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer/RegionAddButton" to="." method="_on_region_add_button_button_up"]
[connection signal="button_up" from="TabContainer/General/HBoxContainer/CloseButton" to="." method="_on_close_button_button_up"]
[connection signal="button_up" from="TabContainer/General/HBoxContainer/SaveButton" to="." method="_on_save_button_button_up"]
[connection signal="button_up" from="TabContainer/General/FormGrid/RegionsVBoxContainer/RegionAddControlsHBoxContainer/RegionAddButton" to="." method="_on_region_add_button_button_up"]
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ extends Control
@export var max_height_spin_box: SpinBox = null # The maximum height of the area in tiles
@export var region_name_text_edit: TextEdit = null # Allows the user to enter a new region name
@export var region_v_box_container: VBoxContainer = null # Contains region editing controls
@export var overmap_area_region_editor: PackedScene = null
@export var overmap_area_region_editor: PackedScene = null # Sub-scene for editing a region
@export var overmap_area_visualization: Control = null # Sub-scene for area visualization


# This signal will be emitted when the user presses the save button
# This signal should alert Gamedata that the overmaparea data array should be saved to disk
signal data_changed()

var olddata: DOvermaparea # Remember what the value of the data was before editing
Expand Down Expand Up @@ -142,13 +142,16 @@ func load_overmaparea_data() -> void:
# Set the region name and values for the region editor
region_editor.set_region_name(region_key)
region_editor.set_values(region_instance.get_data()) # Using get_data() to get the region's dictionary representation

overmap_area_visualization.set_area(dovermaparea)


# The editor is closed, destroy the instance
# TODO: Check for unsaved changes
func _on_close_button_button_up() -> void:
queue_free()


# This function takes all data from the form elements and stores them in the DOvermaparea instance
# Since dovermaparea is a reference to an item in Gamedata.overmapareas
# the central array for overmaparea data is updated with the changes as well
Expand Down
31 changes: 11 additions & 20 deletions Scenes/ContentManager/OtherTools/overmap_area_visualization.gd
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,10 @@ extends Control
@export var width_spin_box: SpinBox = null
@export var height_spin_box: SpinBox = null
@export var max_iterations_spin_box: SpinBox = null
@export var area_option_button: OptionButton = null


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
# Refresh the area_option_button by clearing any existing items
area_option_button.clear()

# Add all overmap area keys to the area_option_button as options
var area_keys = Gamedata.overmapareas.get_all().keys()
for area_key in area_keys:
area_option_button.add_item(area_key)


func _on_back_button_button_up() -> void:
get_tree().change_scene_to_file("res://Scenes/ContentManager/othertools.tscn")
# Variable to store the area
var myovermaparea: DOvermaparea


func _on_generate_button_button_up() -> void:
Expand All @@ -31,10 +19,7 @@ func _on_generate_button_button_up() -> void:
func generate_grid():
visual_grid.set("theme_override_constants/h_separation", 0)
visual_grid.set("theme_override_constants/v_separation", 0)
var mymaxiterations: int = max_iterations_spin_box.value
# Define the dimensions of the grid as 20x20 units
var myareaname: String = area_option_button.get_item_text(area_option_button.selected)
var myovermaparea: DOvermaparea = Gamedata.overmapareas.by_id(myareaname)
var mymaxiterations: int = int(max_iterations_spin_box.value)
var mydimensions = set_area_dimensions(myovermaparea)

# Create a new instance of OvermapAreaGenerator and generate the area grid
Expand Down Expand Up @@ -70,8 +55,8 @@ func generate_grid():

# Function to set the dimensions for the area generator based on the dovermaparea data
func set_area_dimensions(dovermaparea: DOvermaparea) -> Vector2:
var mywidth: int = width_spin_box.value
var myheight: int = height_spin_box.value
var mywidth: int = int(width_spin_box.value)
var myheight: int = int(height_spin_box.value)
# Check if the dimensions are already set to a non-default value
if not mywidth == 0 and not myheight == 0:
return Vector2(mywidth,myheight) # Terminate if no dimensions are set
Expand All @@ -85,3 +70,9 @@ func set_area_dimensions(dovermaparea: DOvermaparea) -> Vector2:
var random_width = randi() % (dovermaparea.max_width - dovermaparea.min_width + 1) + dovermaparea.min_width
var random_height = randi() % (dovermaparea.max_height - dovermaparea.min_height + 1) + dovermaparea.min_height
return Vector2(random_width, random_height)



# Setter method to update the selected area
func set_area(newarea: DOvermaparea) -> void:
myovermaparea = newarea
14 changes: 1 addition & 13 deletions Scenes/ContentManager/OtherTools/overmap_area_visualization.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[ext_resource type="Script" path="res://Scenes/ContentManager/OtherTools/overmap_area_visualization.gd" id="1_8wpup"]
[ext_resource type="PackedScene" uid="uid://budsoodfdkaea" path="res://Scenes/Overmap/OvermapTile.tscn" id="2_3b74b"]

[node name="OvermapAreaVisualization" type="Control" node_paths=PackedStringArray("visual_grid", "width_spin_box", "height_spin_box", "max_iterations_spin_box", "area_option_button")]
[node name="OvermapAreaVisualization" type="Control" node_paths=PackedStringArray("visual_grid", "width_spin_box", "height_spin_box", "max_iterations_spin_box")]
layout_mode = 3
anchors_preset = 15
anchor_right = 1.0
Expand All @@ -16,7 +16,6 @@ tileScene = ExtResource("2_3b74b")
width_spin_box = NodePath("VBoxContainer/HBoxContainer/WidthSpinBox")
height_spin_box = NodePath("VBoxContainer/HBoxContainer/HeightSpinBox")
max_iterations_spin_box = NodePath("VBoxContainer/HBoxContainer/MaxIterationsSpinBox")
area_option_button = NodePath("VBoxContainer/HBoxContainer/AreaOptionButton")

[node name="VBoxContainer" type="VBoxContainer" parent="."]
layout_mode = 1
Expand All @@ -26,19 +25,9 @@ anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2

[node name="BackButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
text = "Back"

[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
layout_mode = 2

[node name="AreaOptionButton" type="OptionButton" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
selected = 0
item_count = 1
popup/item_0/text = "city"

[node name="WidthLabel" type="Label" parent="VBoxContainer/HBoxContainer"]
layout_mode = 2
text = "Width:"
Expand Down Expand Up @@ -72,5 +61,4 @@ layout_mode = 2
size_flags_horizontal = 0
columns = 20

[connection signal="button_up" from="VBoxContainer/BackButton" to="." method="_on_back_button_button_up"]
[connection signal="button_up" from="VBoxContainer/HBoxContainer/GenerateButton" to="." method="_on_generate_button_button_up"]
4 changes: 0 additions & 4 deletions Scenes/ContentManager/Scripts/contentmanager.gd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,3 @@ func _on_content_editor_button_button_up():

func _on_mod_manager_button_button_up():
get_tree().change_scene_to_file("res://Scenes/ContentManager/modmanager.tscn")


func _on_other_tools_button_button_up() -> void:
get_tree().change_scene_to_file("res://Scenes/ContentManager/othertools.tscn")
18 changes: 0 additions & 18 deletions Scenes/ContentManager/Scripts/othertools.gd

This file was deleted.

6 changes: 0 additions & 6 deletions Scenes/ContentManager/contentmanager.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,11 @@ layout_mode = 2
theme_override_font_sizes/font_size = 36
text = "Content editor"

[node name="OtherToolsButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 36
text = "Other tools"

[node name="BackButton" type="Button" parent="VBoxContainer"]
layout_mode = 2
theme_override_font_sizes/font_size = 36
text = "Back"

[connection signal="button_up" from="VBoxContainer/ModManagerButton" to="." method="_on_mod_manager_button_button_up"]
[connection signal="button_up" from="VBoxContainer/ContentEditorButton" to="." method="_on_content_editor_button_button_up"]
[connection signal="button_up" from="VBoxContainer/OtherToolsButton" to="." method="_on_other_tools_button_button_up"]
[connection signal="button_up" from="VBoxContainer/BackButton" to="." method="_on_back_button_button_up"]
Loading

0 comments on commit e63ebbe

Please sign in to comment.