add sticky builder menu.
@ -0,0 +1,89 @@
|
||||
[gd_scene load_steps=9 format=3 uid="uid://h4a5rdfug811"]
|
||||
|
||||
[ext_resource type="Texture2D" uid="uid://x76da5uk737u" path="res://sprites/sticky_builder_icons/residential.png" id="1_mhep0"]
|
||||
[ext_resource type="Texture2D" uid="uid://ebradvwxmo3s" path="res://sprites/sticky_builder_icons/commercial.png" id="2_jwyv3"]
|
||||
[ext_resource type="Script" uid="uid://dpud3hbf66hn7" path="res://scenes/ui/sticky_builder/pop-up-menu-generator.gd" id="2_sqdls"]
|
||||
[ext_resource type="Texture2D" uid="uid://b6iwpx5ct6rfn" path="res://sprites/sticky_builder_icons/industrial.png" id="4_ebilp"]
|
||||
[ext_resource type="Texture2D" uid="uid://b8dtgbrvgfv6t" path="res://sprites/sticky_builder_icons/landscape.png" id="5_46yqr"]
|
||||
[ext_resource type="Texture2D" uid="uid://dnbpauf3umjin" path="res://sprites/sticky_builder_icons/roads.png" id="6_46yqr"]
|
||||
[ext_resource type="Texture2D" uid="uid://c1moa65wd6m5f" path="res://sprites/sticky_builder_icons/power_plant.png" id="6_r3beh"]
|
||||
|
||||
[sub_resource type="Theme" id="Theme_r3beh"]
|
||||
|
||||
[node name="StickyBuilder" type="Control"]
|
||||
layout_mode = 3
|
||||
anchors_preset = 15
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
grow_horizontal = 2
|
||||
grow_vertical = 2
|
||||
|
||||
[node name="Panel" type="Panel" parent="."]
|
||||
layout_mode = 0
|
||||
offset_right = 154.0
|
||||
offset_bottom = 242.0
|
||||
theme = SubResource("Theme_r3beh")
|
||||
|
||||
[node name="VBoxContainer" type="VBoxContainer" parent="Panel"]
|
||||
layout_mode = 2
|
||||
offset_right = 148.0
|
||||
offset_bottom = 224.0
|
||||
|
||||
[node name="Row_1_HBoxContainer" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Roads" type="MenuButton" parent="Panel/VBoxContainer/Row_1_HBoxContainer"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Residential Structures"
|
||||
icon = ExtResource("6_46yqr")
|
||||
item_count = 1
|
||||
popup/item_0/text = "Residential"
|
||||
popup/item_0/id = 0
|
||||
script = ExtResource("2_sqdls")
|
||||
|
||||
[node name="Residential" type="MenuButton" parent="Panel/VBoxContainer/Row_1_HBoxContainer"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Residential Structures"
|
||||
icon = ExtResource("1_mhep0")
|
||||
item_count = 1
|
||||
popup/item_0/text = "Residential"
|
||||
popup/item_0/id = 0
|
||||
script = ExtResource("2_sqdls")
|
||||
filter_type = 1
|
||||
|
||||
[node name="Row_2_HBoxContainer2" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Commercial" type="MenuButton" parent="Panel/VBoxContainer/Row_2_HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Commercial Structures"
|
||||
icon = ExtResource("2_jwyv3")
|
||||
script = ExtResource("2_sqdls")
|
||||
filter_type = 2
|
||||
|
||||
[node name="Industrial" type="MenuButton" parent="Panel/VBoxContainer/Row_2_HBoxContainer2"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Residential Structures"
|
||||
icon = ExtResource("4_ebilp")
|
||||
item_count = 1
|
||||
popup/item_0/text = "Residential"
|
||||
popup/item_0/id = 0
|
||||
script = ExtResource("2_sqdls")
|
||||
filter_type = 3
|
||||
|
||||
[node name="Row_3_HBoxContainer3" type="HBoxContainer" parent="Panel/VBoxContainer"]
|
||||
layout_mode = 2
|
||||
|
||||
[node name="Power" type="MenuButton" parent="Panel/VBoxContainer/Row_3_HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Commercial Structures"
|
||||
icon = ExtResource("6_r3beh")
|
||||
script = ExtResource("2_sqdls")
|
||||
filter_type = 6
|
||||
|
||||
[node name="Landscape" type="MenuButton" parent="Panel/VBoxContainer/Row_3_HBoxContainer3"]
|
||||
layout_mode = 2
|
||||
tooltip_text = "Commercial Structures"
|
||||
icon = ExtResource("5_46yqr")
|
||||
script = ExtResource("2_sqdls")
|
||||
filter_type = 5
|
||||
@ -0,0 +1,141 @@
|
||||
extends MenuButton
|
||||
class_name MenuItemGenerator
|
||||
|
||||
# Export a filter type property that uses the Structure.StructureType enum
|
||||
@export var filter_type: Structure.StructureType
|
||||
# Private variable to store loaded structures
|
||||
var _structures = []
|
||||
# Icons for locked/unlocked status (set these in _ready)
|
||||
var _lock_icon: Texture2D
|
||||
var _unlock_icon: Texture2D
|
||||
|
||||
func _ready():
|
||||
# Connect the signal for item selection
|
||||
get_popup().id_pressed.connect(_on_item_selected)
|
||||
|
||||
# Add to group for easy refreshing of all structure menus
|
||||
add_to_group("structure_menus")
|
||||
|
||||
# Load icons (you'll need to create or find these icons)
|
||||
_lock_icon = load("res://sprites/sticky_builder_icons/lock.png") if ResourceLoader.exists("res://sprites/sticky_builder_icons/lock.png") else null
|
||||
if(_lock_icon):
|
||||
_lock_icon = _get_scaled_icon(_lock_icon,32)
|
||||
# Load all structures and populate the menu
|
||||
_load_structures()
|
||||
_populate_menu()
|
||||
|
||||
# Load all structure resources from the structures directory
|
||||
func _load_structures():
|
||||
_structures.clear()
|
||||
|
||||
var dir = DirAccess.open("res://structures")
|
||||
if not dir:
|
||||
push_error("Failed to access the structures directory")
|
||||
return
|
||||
|
||||
dir.list_dir_begin()
|
||||
var file_name = dir.get_next()
|
||||
|
||||
while file_name != "":
|
||||
if not dir.current_is_dir() and file_name.ends_with(".tres"):
|
||||
var structure = load("res://structures/" + file_name)
|
||||
|
||||
# Only add structures that match our filter type
|
||||
if structure is Structure and structure.type == filter_type:
|
||||
_structures.append(structure)
|
||||
|
||||
file_name = dir.get_next()
|
||||
|
||||
# Sort structures by size category first (small to large), then by title
|
||||
_structures.sort_custom(func(a, b):
|
||||
# First compare by size category
|
||||
if a.size_category != b.size_category:
|
||||
return a.size_category < b.size_category
|
||||
# If same size category, sort by title
|
||||
return a.title < b.title)
|
||||
|
||||
# Populate the menu with the loaded structures
|
||||
func _populate_menu():
|
||||
var popup = get_popup()
|
||||
popup.clear()
|
||||
|
||||
var current_size_category = -1
|
||||
|
||||
for i in range(_structures.size()):
|
||||
var structure = _structures[i]
|
||||
# Add separator between size categories
|
||||
if structure.size_category != current_size_category:
|
||||
if i > 0:
|
||||
popup.add_separator()
|
||||
current_size_category = structure.size_category
|
||||
|
||||
# Add size category header (optional)
|
||||
#var category_name = ""
|
||||
#match current_size_category:
|
||||
#Structure.SizeCategory.SMALL: category_name = "Small"
|
||||
#Structure.SizeCategory.MEDIUM: category_name = "Medium"
|
||||
#Structure.SizeCategory.LARGE: category_name = "Large"
|
||||
#
|
||||
#if category_name != "":
|
||||
#popup.add_item(category_name, -1)
|
||||
#popup.set_item_disabled(popup.item_count - 1, true)
|
||||
|
||||
# Add the structure item with price in the name
|
||||
var item_text = structure.title
|
||||
if structure.price > 0:
|
||||
item_text += " ($" + str(structure.price) + ")"
|
||||
|
||||
|
||||
# Add lock/unlock icon if we're showing all structures
|
||||
if not structure.unlocked:
|
||||
if _lock_icon:
|
||||
|
||||
popup.add_icon_item(_lock_icon, item_text)
|
||||
popup.set_item_disabled(popup.item_count - 1, true)
|
||||
else:
|
||||
popup.add_item(item_text, i)
|
||||
|
||||
|
||||
|
||||
# Handle the menu item selection
|
||||
func _on_item_selected(id: int):
|
||||
if id >= 0 and id < _structures.size():
|
||||
var selected_structure = _structures[id]
|
||||
# Get the original structure index in the builder's structure array
|
||||
var structure_resource_path = selected_structure.resource_path
|
||||
Globals.set_structure(selected_structure)
|
||||
|
||||
# Method to manually refresh the menu items
|
||||
func refresh():
|
||||
_load_structures()
|
||||
_populate_menu()
|
||||
|
||||
# Method to unlock a structure by resource path and refresh the menu
|
||||
func unlock_structure(resource_path: String):
|
||||
var structure = load(resource_path)
|
||||
if structure is Structure and not structure.unlocked:
|
||||
structure.unlocked = true
|
||||
structure.resource_changed.emit()
|
||||
|
||||
# Save the resource
|
||||
ResourceSaver.save(structure, resource_path)
|
||||
|
||||
# Refresh the menu
|
||||
refresh()
|
||||
|
||||
return true
|
||||
|
||||
return false
|
||||
|
||||
func _get_scaled_icon(texture: Texture2D, target_height: int) -> Texture2D:
|
||||
if texture == null:
|
||||
return null
|
||||
|
||||
var img = texture.get_image()
|
||||
var scale = target_height / float(img.get_height())
|
||||
var new_width = int(img.get_width() * scale)
|
||||
|
||||
img.resize(new_width, target_height, Image.INTERPOLATE_LANCZOS)
|
||||
|
||||
var new_texture = ImageTexture.create_from_image(img)
|
||||
return new_texture
|
||||
@ -0,0 +1 @@
|
||||
uid://dpud3hbf66hn7
|
||||
|
After Width: | Height: | Size: 8.1 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://ebradvwxmo3s"
|
||||
path="res://.godot/imported/commercial.png-c7351ecf8f43d4710e78aada7553faea.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/commercial.png"
|
||||
dest_files=["res://.godot/imported/commercial.png-c7351ecf8f43d4710e78aada7553faea.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
|
||||
|
After Width: | Height: | Size: 4.6 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b6iwpx5ct6rfn"
|
||||
path="res://.godot/imported/industrial.png-337a1ff1161d1fe85c77f2960366bd99.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/industrial.png"
|
||||
dest_files=["res://.godot/imported/industrial.png-337a1ff1161d1fe85c77f2960366bd99.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
|
||||
|
After Width: | Height: | Size: 4.7 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://b8dtgbrvgfv6t"
|
||||
path="res://.godot/imported/landscape.png-4100953829b90500e627ab137eb8b831.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/landscape.png"
|
||||
dest_files=["res://.godot/imported/landscape.png-4100953829b90500e627ab137eb8b831.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
|
||||
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://qct4wg050b8t"
|
||||
path="res://.godot/imported/lock.jpg-1d14c2fcd1b6c530830e6d171b854c03.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/lock.jpg"
|
||||
dest_files=["res://.godot/imported/lock.jpg-1d14c2fcd1b6c530830e6d171b854c03.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
|
||||
|
After Width: | Height: | Size: 8.7 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://bhirwotya28tp"
|
||||
path="res://.godot/imported/lock.png-3bb15a91918dca57b868d97e7e5c1760.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/lock.png"
|
||||
dest_files=["res://.godot/imported/lock.png-3bb15a91918dca57b868d97e7e5c1760.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
|
||||
|
After Width: | Height: | Size: 4.3 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://c1moa65wd6m5f"
|
||||
path="res://.godot/imported/power_plant.png-3169ad219b01a6309d8edadae8e53f70.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/power_plant.png"
|
||||
dest_files=["res://.godot/imported/power_plant.png-3169ad219b01a6309d8edadae8e53f70.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
|
||||
|
After Width: | Height: | Size: 7.8 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://x76da5uk737u"
|
||||
path="res://.godot/imported/residential.png-a0a319ba8916f7a485ae6c08054fb548.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/residential.png"
|
||||
dest_files=["res://.godot/imported/residential.png-a0a319ba8916f7a485ae6c08054fb548.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
|
||||
|
After Width: | Height: | Size: 5.0 KiB |
@ -0,0 +1,34 @@
|
||||
[remap]
|
||||
|
||||
importer="texture"
|
||||
type="CompressedTexture2D"
|
||||
uid="uid://dnbpauf3umjin"
|
||||
path="res://.godot/imported/roads.png-e7ed12eaeee16a42d36da0f2ccc77851.ctex"
|
||||
metadata={
|
||||
"vram_texture": false
|
||||
}
|
||||
|
||||
[deps]
|
||||
|
||||
source_file="res://sprites/sticky_builder_icons/roads.png"
|
||||
dest_files=["res://.godot/imported/roads.png-e7ed12eaeee16a42d36da0f2ccc77851.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
|
||||