feat: update addon

This commit is contained in:
Varylios 2025-09-01 20:17:43 +02:00
parent 2497befa7c
commit d295900122
9 changed files with 154 additions and 109 deletions

View file

@ -2,7 +2,7 @@
extends LineEdit
class_name CustomLineEdit
signal valueHasChanged(newValue)
signal valueHasChanged(newValue : Variant)
enum TYPE { INT, TEXT, FLOAT }
@ -10,7 +10,7 @@ enum TYPE { INT, TEXT, FLOAT }
@export var step : float = 1
var oldValue : String = ""
var value:
var value : Variant :
get:
return getTypedValue(text)
@ -40,7 +40,7 @@ func valueUpdated(newText : String) -> void:
valueHasChanged.emit(value)
func setValue(value) -> void:
func setValue(value : Variant) -> void:
text = str(getTypedValue(str(value)))

View file

@ -0,0 +1,78 @@
[gd_scene load_steps=4 format=3 uid="uid://djrbvm8gmhly3"]
[ext_resource type="Script" uid="uid://1kvxw2v3htp3" path="res://addons/LevelEditor/UI/Troop/TroopMaker.gd" id="1_0rptq"]
[ext_resource type="Script" uid="uid://bpv75ucqoy446" path="res://addons/LevelEditor/UI/CustomLineEdit.gd" id="2_f48bo"]
[ext_resource type="Script" uid="uid://b47p2u458hsn0" path="res://addons/LevelEditor/UI/CustomOptionButton.gd" id="3_dvkum"]
[node name="Troop" type="VBoxContainer"]
anchors_preset = 15
anchor_right = 1.0
anchor_bottom = 1.0
grow_horizontal = 2
grow_vertical = 2
script = ExtResource("1_0rptq")
[node name="HBC" type="HBoxContainer" parent="."]
visible = false
layout_mode = 2
[node name="DelayEdit" type="LineEdit" parent="HBC"]
layout_mode = 2
script = ExtResource("2_f48bo")
inputType = 2
step = 0.2
metadata/_custom_type_script = "uid://bpv75ucqoy446"
[node name="Label" type="Label" parent="HBC"]
layout_mode = 2
text = " .secondes"
[node name="HBC2" type="HBoxContainer" parent="."]
layout_mode = 2
[node name="TroopLabel" type="Label" parent="HBC2"]
layout_mode = 2
[node name="RemoveButton" type="Button" parent="HBC2"]
layout_mode = 2
text = "Supprimer"
[node name="HBC3" type="HBoxContainer" parent="."]
layout_mode = 2
[node name="Quantity" type="LineEdit" parent="HBC3"]
layout_mode = 2
script = ExtResource("2_f48bo")
metadata/_custom_type_script = "uid://bpv75ucqoy446"
[node name="Label" type="Label" parent="HBC3"]
layout_mode = 2
text = " x "
[node name="EnemySelect" type="OptionButton" parent="HBC3"]
layout_mode = 2
allow_reselect = true
script = ExtResource("3_dvkum")
metadata/_custom_type_script = "uid://b47p2u458hsn0"
[node name="HBC4" type="HBoxContainer" parent="."]
visible = false
layout_mode = 2
[node name="Label" type="Label" parent="HBC4"]
layout_mode = 2
text = "Voie : "
[node name="SpawnSelect" type="OptionButton" parent="HBC4"]
layout_mode = 2
allow_reselect = true
script = ExtResource("3_dvkum")
metadata/_custom_type_script = "uid://b47p2u458hsn0"
[node name="HBC5" type="HBoxContainer" parent="."]
visible = false
layout_mode = 2
[node name="SplitTroopButton" type="Button" parent="HBC5"]
layout_mode = 2
text = "Séparer"

View file

@ -0,0 +1,62 @@
@tool
extends VBoxContainer
class_name TroopMaker
signal troopDeleted
signal troopChanged
var troop : Troop
var troopNumber : int
var amountOfSpawns : int
@onready var delayEdit : CustomLineEdit = $HBC/DelayEdit
@onready var qtyEdit : CustomLineEdit = $HBC3/Quantity
@onready var enemySelect : CustomOptionButton = $HBC3/EnemySelect
@onready var spawnSelect : CustomOptionButton = $HBC4/SpawnSelect
func _ready() -> void:
$HBC2/RemoveButton.pressed.connect(troopDeleted.emit)
$HBC5/SplitTroopButton.pressed.connect(delayHasChanged.bind(1))
delayEdit.valueHasChanged.connect(delayHasChanged)
qtyEdit.valueHasChanged.connect(func(value): troop.number_to_spawn = value)
enemySelect.onValueChanged.connect(func(value): troop.enemy = value)
spawnSelect.onValueChanged.connect(func(value): troop.lane_to_spawn = int(value))
initTrop.call_deferred()
func delayHasChanged(newTime : float) -> void:
$HBC5.visible = newTime == 0
$HBC.visible = !$HBC5.visible
var oldTime : float = troop.spawn_delay
troop.spawn_delay = newTime
if !newTime || !oldTime:
troopChanged.emit()
func setTroop(_troop : Troop, _troopNumber : int, _amountOfSpawns : int) -> void:
troop = _troop
troopNumber = _troopNumber + 1
amountOfSpawns = _amountOfSpawns
func initTrop():
if amountOfSpawns - 1:
$HBC4.visible = true
for i in amountOfSpawns:
spawnSelect.addOption(str(i), str(i + 1))
delayEdit.setValue(troop.spawn_delay)
$HBC2/TroopLabel.text = "Troop N°" + str(troopNumber)
qtyEdit.setValue(troop.number_to_spawn)
print(troop.spawn_delay == 0)
$HBC5.visible = troop.spawn_delay == 0
$HBC.visible = !$HBC5.visible
var mainMenu : WaveMaker = EditorInterface.get_editor_main_screen().get_node("Menu")
enemySelect.setOptions(mainMenu.enemies)

View file

@ -0,0 +1 @@
uid://1kvxw2v3htp3

View file

@ -1,7 +0,0 @@
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://s1lfc81j20la"]
[ext_resource type="FontFile" uid="uid://dv7ow5e7jj355" path="res://Assets/Fonts/Grandstander/static/Grandstander-Light.ttf" id="1_r6cgw"]
[resource]
font = ExtResource("1_r6cgw")
font_size = 24

View file

@ -1,4 +0,0 @@
[gd_resource type="Theme" format=3 uid="uid://bvji8e8p2d72y"]
[resource]
default_font_size = 20

View file

@ -1,7 +0,0 @@
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://bee458c1kc0j7"]
[ext_resource type="FontFile" uid="uid://ctmfgwv1dwdyg" path="res://Assets/Fonts/Grandstander/static/Grandstander-BoldItalic.ttf" id="1_kyxue"]
[resource]
font = ExtResource("1_kyxue")
font_size = 24

View file

@ -1,7 +0,0 @@
[gd_resource type="LabelSettings" load_steps=2 format=3 uid="uid://cafoo04y1t31t"]
[ext_resource type="FontFile" uid="uid://byqqml5g6dwil" path="res://Assets/Fonts/Grandstander/static/Grandstander-BlackItalic.ttf" id="1_m52f8"]
[resource]
font = ExtResource("1_m52f8")
font_size = 32

View file

@ -1,5 +1,7 @@
@tool
extends Control
class_name WaveMaker
const LEVEL_PATH : String = "res://Levels/"
const LEVEL_REGEX_PATERN : String = "(level_.*)\\.tres$"
@ -8,9 +10,7 @@ const LEVEL_PATH_REGEX_PATERN : String = "res://Levels/[^/]*/$"
const ENEMY_PATH : String = "res://enemies/"
const ENEMY_REGEX_PATERN : String = "(enemy.*)\\.tscn$"
const BASE_LABEL_SETTINGS = preload("res://addons/LevelEditor/UI/baseLabel.tres")
const WAVE_LABEL_SETTINGS = preload("res://addons/LevelEditor/UI/waveLabel.tres")
const TROOP_LABEL_SETTINGS = preload("res://addons/LevelEditor/UI/troopLabel.tres")
const TROOP_SCENE = preload("res://addons/LevelEditor/UI/Troop/Troop.tscn")
const space_multiplicator : int = 10
enum DIRECTION { UP, DOWN, TOP, LEFT, VERTICAL, HORIZONTAL}
@ -76,18 +76,6 @@ func buildWave(wave : Wave) -> VBoxContainer:
!troopContainer.get_child(troopContainer.get_child_count() - 1).has_meta("troop_group"):
troopContainer.add_child(HSeparator.new())
if troop.spawn_delay:
var timeSeparator : HBoxContainer = buildInputLabel(
func(newValue):
troop.spawn_delay = newValue
if newValue == 0:
refreshWaveNode(level.waves[currentWave], currentWave),
troop.spawn_delay,
CustomLineEdit.TYPE.FLOAT,
"sec."
)
troopContainer.add_child(timeSeparator)
var nodeToAppend : BoxContainer = troopContainer
if i < wave.troops.size() -1 && wave.troops[i + 1].spawn_delay == 0:
if i == 0 || !troopContainer.get_child(troopContainer.get_child_count() - 1).has_meta("troop_group"):
@ -100,21 +88,8 @@ func buildWave(wave : Wave) -> VBoxContainer:
nodeToAppend = troopContainer.get_child(troopContainer.get_child_count() - 1)
nodeToAppend.add_child(VSeparator.new())
var ennemyContainer : VBoxContainer = VBoxContainer.new()
ennemyContainer.add_child(createSection("Troop N°" + str(i + 1), removeTroop.bind(troop, wave), TROOP_LABEL_SETTINGS))
nodeToAppend.add_child(createTroop(troop, wave))
if troop.spawn_delay == 0:
var button : Button = Button.new()
button.text = "Séparer"
button.pressed.connect(
func():
troop.spawn_delay = 1
refreshWaveNode(level.waves[currentWave], currentWave),
)
ennemyContainer.add_child(button)
buildTroop(troop, ennemyContainer)
nodeToAppend.add_child(ennemyContainer)
var addTroopBtn : Button = Button.new()
addTroopBtn.text = "Ajouter une troupe"
@ -124,59 +99,13 @@ func buildWave(wave : Wave) -> VBoxContainer:
return troopContainer
func createTroop(troop : Troop, wave : Wave) -> TroopMaker:
var enemyContainer : TroopMaker = TROOP_SCENE.instantiate()
enemyContainer.setTroop(troop, wave.troops.find(troop), level.laneCount)
enemyContainer.troopDeleted.connect(removeTroop.bind(troop, wave))
enemyContainer.troopChanged.connect(refreshWaveNode.bind(wave, level.waves.find(wave)))
func buildTroop(troop : Troop, ennemyContainer : VBoxContainer) -> void:
var qtyEdit : HBoxContainer = buildInputLabel(
func(newValue): troop.number_to_spawn = newValue,
troop.number_to_spawn,
CustomLineEdit.TYPE.INT,
"x"
)
var enemySelector : CustomOptionButton = CustomOptionButton.new()
enemySelector.onValueChanged.connect(func(resourcePath): troop.enemy = resourcePath)
enemySelector.setOptions(enemies, troop.enemy)
qtyEdit.add_child(enemySelector)
ennemyContainer.add_child(qtyEdit)
func buildInputLabel(updateCallback : Callable, delay : float, type : CustomLineEdit.TYPE, text : String = "") -> HBoxContainer:
var container : HBoxContainer = HBoxContainer.new()
container.size_flags_vertical = Control.SIZE_SHRINK_CENTER
container.alignment = BoxContainer.ALIGNMENT_CENTER
var timeEdit : CustomLineEdit = CustomLineEdit.new()
timeEdit.inputType = type
timeEdit.setValue(delay)
timeEdit.valueHasChanged.connect(updateCallback)
container.add_child(timeEdit)
if text:
var label : Label = Label.new()
label.text = text
label.horizontal_alignment = HORIZONTAL_ALIGNMENT_CENTER
label.label_settings = BASE_LABEL_SETTINGS
container.add_child(label)
return container
func createSection(sectionName : String, BtnCallback : Callable, settings : LabelSettings = BASE_LABEL_SETTINGS) -> HSplitContainer :
var container : HSplitContainer = HSplitContainer.new()
var label : Label = Label.new()
label.text = sectionName
label.label_settings = settings
var button : Button = Button.new()
button.text = "Supprimer"
button.pressed.connect(BtnCallback)
container.add_child(label)
container.add_child(button)
return container
return enemyContainer
func cleanMenu() -> void: