feat: Selectable tower on level
This commit is contained in:
parent
1e3ab60051
commit
adc1b9034c
13 changed files with 91 additions and 15 deletions
|
|
@ -1,3 +1,4 @@
|
||||||
|
@tool
|
||||||
extends Node
|
extends Node
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -33,11 +34,11 @@ signal tower_count_changed(_value : int)
|
||||||
|
|
||||||
#Emitter : PlayerManager.gd
|
#Emitter : PlayerManager.gd
|
||||||
#Subscriber : label_team.gd, label_tower_on_terrain.gd
|
#Subscriber : label_team.gd, label_tower_on_terrain.gd
|
||||||
signal team_in_action_changed(_value : Array)
|
signal team_in_action_changed(_value : int)
|
||||||
|
|
||||||
#Emitter : PlayerManager.gd
|
#Emitter : PlayerManager.gd
|
||||||
#Subscriber : label_tower_in_cube.gd
|
#Subscriber : label_tower_in_cube.gd
|
||||||
signal team_in_rest_changed(_value : Array)
|
signal team_in_rest_changed(_value : int)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -59,7 +60,7 @@ signal money_spent(_value : int)
|
||||||
#Subscriber : cube.gd
|
#Subscriber : cube.gd
|
||||||
signal player_has_won()
|
signal player_has_won()
|
||||||
|
|
||||||
#Emitter : WaveManger.gd
|
#Emitter : WaveManager.gd
|
||||||
#Subscriber : cube.gd
|
#Subscriber : cube.gd
|
||||||
signal player_defeated()
|
signal player_defeated()
|
||||||
|
|
||||||
|
|
@ -74,3 +75,7 @@ signal close_shop()
|
||||||
#Emitter : tower.gd
|
#Emitter : tower.gd
|
||||||
#Subscriber : tower button.gd
|
#Subscriber : tower button.gd
|
||||||
signal energy_has_changed(tower : Tower)
|
signal energy_has_changed(tower : Tower)
|
||||||
|
|
||||||
|
#Emitter : WaveManager.gd
|
||||||
|
#Subscriber : gui.gd
|
||||||
|
signal allowedTowerHasChange(allowedTowers : Array[Tower.TYPES])
|
||||||
|
|
|
||||||
|
|
@ -79,4 +79,5 @@ metadata/_custom_type_script = "uid://chu8s12rtdeqx"
|
||||||
script = ExtResource("1_ftl6b")
|
script = ExtResource("1_ftl6b")
|
||||||
waves = Array[ExtResource("2_457yt")]([SubResource("Resource_m6gub"), SubResource("Resource_457yt"), SubResource("Resource_ujs1b")])
|
waves = Array[ExtResource("2_457yt")]([SubResource("Resource_m6gub"), SubResource("Resource_457yt"), SubResource("Resource_ujs1b")])
|
||||||
auto_start = false
|
auto_start = false
|
||||||
|
allowedTowers = Array[int]([1, 2])
|
||||||
metadata/_custom_type_script = "uid://cuhq6u67cbbqm"
|
metadata/_custom_type_script = "uid://cuhq6u67cbbqm"
|
||||||
|
|
|
||||||
|
|
@ -79,4 +79,5 @@ wait_for_enemy_kills = true
|
||||||
script = ExtResource("1_c4t4w")
|
script = ExtResource("1_c4t4w")
|
||||||
waves = Array[ExtResource("2_2ji0m")]([SubResource("Resource_cm6sg"), SubResource("Resource_c4t4w"), SubResource("Resource_s83h5"), SubResource("Resource_xgtww")])
|
waves = Array[ExtResource("2_2ji0m")]([SubResource("Resource_cm6sg"), SubResource("Resource_c4t4w"), SubResource("Resource_s83h5"), SubResource("Resource_xgtww")])
|
||||||
auto_start = false
|
auto_start = false
|
||||||
|
allowedTowers = Array[int]([1, 2])
|
||||||
metadata/_custom_type_script = "uid://cuhq6u67cbbqm"
|
metadata/_custom_type_script = "uid://cuhq6u67cbbqm"
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,13 @@
|
||||||
|
@tool
|
||||||
extends Resource
|
extends Resource
|
||||||
class_name Level
|
class_name Level
|
||||||
|
|
||||||
@export var waves : Array[Wave]
|
@export var waves : Array[Wave]
|
||||||
@export var auto_start : bool = false
|
@export var auto_start : bool = false
|
||||||
|
@export var allowedTowers : Array[Tower.TYPES] : set = allowedTowersHasChanged
|
||||||
|
|
||||||
|
|
||||||
|
func allowedTowersHasChanged(value) -> void:
|
||||||
|
allowedTowers = value
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
EventBus.allowedTowerHasChange.emit(allowedTowers)
|
||||||
|
|
|
||||||
|
|
@ -109,7 +109,6 @@ func build_tower() -> void:
|
||||||
quit_placing()
|
quit_placing()
|
||||||
selected_tower.is_rest = false
|
selected_tower.is_rest = false
|
||||||
|
|
||||||
print(selected_tower.tower_type)
|
|
||||||
move_tower()
|
move_tower()
|
||||||
emitTeamChanges()
|
emitTeamChanges()
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ var wave_on_going : bool = false
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
troopTimer.timeout.connect(spawn_troop)
|
troopTimer.timeout.connect(spawn_troop)
|
||||||
EventBus.player_defeated.connect(clearLevel)
|
EventBus.player_defeated.connect(clearLevel)
|
||||||
|
EventBus.allowedTowerHasChange.emit.call_deferred(level.allowedTowers)
|
||||||
|
|
||||||
|
|
||||||
func _process(delta: float) -> void:
|
func _process(delta: float) -> void:
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
extends StaticBody3D
|
extends StaticBody3D
|
||||||
class_name Tower
|
class_name Tower
|
||||||
|
|
||||||
|
# DANGER NONE Should always be first
|
||||||
enum TYPES { NONE, PIERRE, ALINE, MAXENCE, VICTORIA, EVAN, ALEX }
|
enum TYPES { NONE, PIERRE, ALINE, MAXENCE, VICTORIA, EVAN, ALEX }
|
||||||
|
|
||||||
var bullet : PackedScene = preload("res://Bullets/bullet.tscn")
|
var bullet : PackedScene = preload("res://Bullets/bullet.tscn")
|
||||||
|
|
|
||||||
17
UI/gui.gd
17
UI/gui.gd
|
|
@ -8,8 +8,12 @@ var towerListResource := preload("res://Towers/towers.tres")
|
||||||
|
|
||||||
@onready var buttonContainer = $HBoxContainer/ControlPanelBase/MarginContainer/GridContainer
|
@onready var buttonContainer = $HBoxContainer/ControlPanelBase/MarginContainer/GridContainer
|
||||||
|
|
||||||
|
var allowedTowers : Array[Tower.TYPES]
|
||||||
|
|
||||||
|
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
addTowerButtonNodes()
|
addTowerButtonNodes()
|
||||||
|
EventBus.allowedTowerHasChange.connect(allowedTowerHasChange)
|
||||||
if Engine.is_editor_hint():
|
if Engine.is_editor_hint():
|
||||||
towerListResource.changed.connect(addTowerButtonNodes)
|
towerListResource.changed.connect(addTowerButtonNodes)
|
||||||
|
|
||||||
|
|
@ -25,13 +29,22 @@ func _on_button_quit_level_pressed() -> void:
|
||||||
func _on_button_quit_game_pressed() -> void:
|
func _on_button_quit_game_pressed() -> void:
|
||||||
get_tree().quit()
|
get_tree().quit()
|
||||||
|
|
||||||
|
|
||||||
|
func allowedTowerHasChange(allowedTowers : Array[Tower.TYPES]) -> void:
|
||||||
|
self.allowedTowers = allowedTowers
|
||||||
|
if is_node_ready():
|
||||||
|
addTowerButtonNodes()
|
||||||
|
|
||||||
|
|
||||||
func addTowerButtonNodes() -> void:
|
func addTowerButtonNodes() -> void:
|
||||||
for node in buttonContainer.get_children():
|
for node in buttonContainer.get_children():
|
||||||
if node.has_meta("dynamicButton"):
|
if node.has_meta("dynamicButton"):
|
||||||
node.queue_free()
|
node.queue_free()
|
||||||
|
|
||||||
|
var additionalPlaceholder : int = 0
|
||||||
for towerResource in towerListResource.towers:
|
for towerResource in towerListResource.towers:
|
||||||
if !towerResource || towerResource.towerType == Tower.TYPES.NONE:
|
if !towerResource || not allowedTowers.has(towerResource.towerType):
|
||||||
|
additionalPlaceholder += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
var towerBtn := towerButton.instantiate()
|
var towerBtn := towerButton.instantiate()
|
||||||
|
|
@ -43,7 +56,7 @@ func addTowerButtonNodes() -> void:
|
||||||
tower.queue_free()
|
tower.queue_free()
|
||||||
buttonContainer.add_child(towerBtn)
|
buttonContainer.add_child(towerBtn)
|
||||||
|
|
||||||
for i in BUTTON_QTY - towerListResource.towers.size():
|
for i in BUTTON_QTY - towerListResource.towers.size() + additionalPlaceholder:
|
||||||
var placeholderBtn := Button.new()
|
var placeholderBtn := Button.new()
|
||||||
placeholderBtn.set_meta("dynamicButton", true)
|
placeholderBtn.set_meta("dynamicButton", true)
|
||||||
placeholderBtn.custom_minimum_size = Vector2(80, 80)
|
placeholderBtn.custom_minimum_size = Vector2(80, 80)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ func _on_EventBus_tower_count_changed(_value : int) -> void:
|
||||||
_text[1] = str(_value)
|
_text[1] = str(_value)
|
||||||
text = _text[0] + "/" + _text[1]
|
text = _text[0] + "/" + _text[1]
|
||||||
|
|
||||||
func _on_EventBus_team_in_action_changed(_value : Array) -> void:
|
func _on_EventBus_team_in_action_changed(_value : int) -> void:
|
||||||
var _text = text.rsplit("/")
|
var _text = text.rsplit("/")
|
||||||
_text[0] = str(_value.size())
|
_text[0] = str(_value)
|
||||||
text = _text[0] + "/" + _text[1]
|
text = _text[0] + "/" + _text[1]
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,5 @@ extends Label
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
EventBus.team_in_rest_changed.connect(_on_EventBus_team_in_rest_changed)
|
EventBus.team_in_rest_changed.connect(_on_EventBus_team_in_rest_changed)
|
||||||
|
|
||||||
func _on_EventBus_team_in_rest_changed(_value : Array) -> void:
|
func _on_EventBus_team_in_rest_changed(_value : int) -> void:
|
||||||
text = str(_value.size())
|
text = str(_value)
|
||||||
|
|
|
||||||
|
|
@ -3,5 +3,5 @@ extends Label
|
||||||
func _ready() -> void:
|
func _ready() -> void:
|
||||||
EventBus.team_in_action_changed.connect(_on_EventBus_team_in_action_changed)
|
EventBus.team_in_action_changed.connect(_on_EventBus_team_in_action_changed)
|
||||||
|
|
||||||
func _on_EventBus_team_in_action_changed(_value : Array) -> void:
|
func _on_EventBus_team_in_action_changed(_value : int) -> void:
|
||||||
text = str(_value.size())
|
text = str(_value)
|
||||||
|
|
|
||||||
|
|
@ -21,10 +21,10 @@ enum DIRECTION { UP, DOWN, TOP, LEFT, VERTICAL, HORIZONTAL}
|
||||||
@onready var levelSelect := $VBoxContainer2/HBoxContainer/LevelSelect
|
@onready var levelSelect := $VBoxContainer2/HBoxContainer/LevelSelect
|
||||||
@onready var waveTabContainer := $VBoxContainer2/ScrollContainer/WaveContainer
|
@onready var waveTabContainer := $VBoxContainer2/ScrollContainer/WaveContainer
|
||||||
@onready var waveTimerInput := $VBoxContainer2/ButtonContainer3/WaveTimer
|
@onready var waveTimerInput := $VBoxContainer2/ButtonContainer3/WaveTimer
|
||||||
|
@onready var towerSelector := $VBoxContainer2/ButtonContainer5/TowerSelector
|
||||||
var level : Level
|
var level : Level
|
||||||
var currentWave : int = -1
|
var currentWave : int = -1
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
if !has_focus() || event is not InputEventKey || !event.pressed:
|
if !has_focus() || event is not InputEventKey || !event.pressed:
|
||||||
return
|
return
|
||||||
|
|
@ -34,11 +34,17 @@ func _input(event: InputEvent) -> void:
|
||||||
elif event.keycode == KEY_LEFT && waveTabContainer.current_tab > 0:
|
elif event.keycode == KEY_LEFT && waveTabContainer.current_tab > 0:
|
||||||
waveTabContainer.current_tab -= 1
|
waveTabContainer.current_tab -= 1
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
towerSelector.clear()
|
||||||
|
for towerType : String in Tower.TYPES:
|
||||||
|
if Tower.TYPES.NONE != Tower.TYPES.get(towerType):
|
||||||
|
towerSelector.add_item(towerType)
|
||||||
|
|
||||||
func buildTree() -> void:
|
func buildTree() -> void:
|
||||||
if !level:
|
if !level:
|
||||||
return
|
return
|
||||||
|
|
||||||
|
manageAllowedTowers()
|
||||||
autoLaunchLevel.button_pressed = level.auto_start
|
autoLaunchLevel.button_pressed = level.auto_start
|
||||||
for i in level.waves.size():
|
for i in level.waves.size():
|
||||||
var troopContainer := VBoxContainer.new()
|
var troopContainer := VBoxContainer.new()
|
||||||
|
|
@ -48,12 +54,19 @@ func buildTree() -> void:
|
||||||
waveTabContainer.set_tab_title(i, "Vague N°" + str(i + 1))
|
waveTabContainer.set_tab_title(i, "Vague N°" + str(i + 1))
|
||||||
|
|
||||||
|
|
||||||
|
func manageAllowedTowers() -> void:
|
||||||
|
towerSelector.deselect_all()
|
||||||
|
for towerAllowed in level.allowedTowers:
|
||||||
|
# NOTE minus one is for remove none value
|
||||||
|
towerSelector.select(towerAllowed - 1, false)
|
||||||
|
|
||||||
|
|
||||||
func buildWave(wave : Wave, troopContainer : VBoxContainer) -> void:
|
func buildWave(wave : Wave, troopContainer : VBoxContainer) -> void:
|
||||||
for i in wave.troops.size():
|
for i in wave.troops.size():
|
||||||
var troop : Troop = wave.troops[i]
|
var troop : Troop = wave.troops[i]
|
||||||
|
|
||||||
if i > 0 && !troopContainer.get_child(troopContainer.get_child_count() - 1).has_meta("troop_group") \
|
if troop.spawn_delay > 0 || i > 0 \
|
||||||
|| troop.spawn_delay > 0:
|
&& !troopContainer.get_child(troopContainer.get_child_count() - 1).has_meta("troop_group"):
|
||||||
troopContainer.add_child(HSeparator.new())
|
troopContainer.add_child(HSeparator.new())
|
||||||
|
|
||||||
if troop.spawn_delay:
|
if troop.spawn_delay:
|
||||||
|
|
@ -241,3 +254,12 @@ func _on_new_level_pressed() -> void:
|
||||||
|
|
||||||
func _on_save_pressed() -> void:
|
func _on_save_pressed() -> void:
|
||||||
ResourceSaver.save(level, LEVEL_PATH + "/" + levelSelect.selectedValue, ResourceSaver.FLAG_BUNDLE_RESOURCES)
|
ResourceSaver.save(level, LEVEL_PATH + "/" + levelSelect.selectedValue, ResourceSaver.FLAG_BUNDLE_RESOURCES)
|
||||||
|
|
||||||
|
|
||||||
|
func onSelectedTowerChange(index: int, selected: int) -> void:
|
||||||
|
# NOTE Adding one for taking NONE value in account
|
||||||
|
index += 1
|
||||||
|
if selected:
|
||||||
|
level.allowedTowers.append(index)
|
||||||
|
else:
|
||||||
|
level.allowedTowers.erase(index)
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,7 @@ layout_mode = 2
|
||||||
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
|
[node name="VBoxContainer2" type="VBoxContainer" parent="."]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_horizontal = 3
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
|
||||||
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer2"]
|
[node name="MarginContainer" type="MarginContainer" parent="VBoxContainer2"]
|
||||||
custom_minimum_size = Vector2(0, 20)
|
custom_minimum_size = Vector2(0, 20)
|
||||||
|
|
@ -120,6 +121,29 @@ text = "Timer avant lancement de la vague"
|
||||||
custom_minimum_size = Vector2(0, 30)
|
custom_minimum_size = Vector2(0, 30)
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="ButtonContainer5" type="HBoxContainer" parent="VBoxContainer2"]
|
||||||
|
custom_minimum_size = Vector2(0, 30)
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
|
[node name="TowerSelector" type="ItemList" parent="VBoxContainer2/ButtonContainer5"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
select_mode = 2
|
||||||
|
allow_search = false
|
||||||
|
auto_width = true
|
||||||
|
auto_height = true
|
||||||
|
item_count = 6
|
||||||
|
item_0/text = "PIERRE"
|
||||||
|
item_1/text = "ALINE"
|
||||||
|
item_2/text = "MAXENCE"
|
||||||
|
item_3/text = "VICTORIA"
|
||||||
|
item_4/text = "EVAN"
|
||||||
|
item_5/text = "ALEX"
|
||||||
|
|
||||||
|
[node name="MarginContainer4" type="MarginContainer" parent="VBoxContainer2"]
|
||||||
|
custom_minimum_size = Vector2(0, 30)
|
||||||
|
layout_mode = 2
|
||||||
|
|
||||||
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer2"]
|
[node name="ScrollContainer" type="ScrollContainer" parent="VBoxContainer2"]
|
||||||
layout_mode = 2
|
layout_mode = 2
|
||||||
size_flags_vertical = 3
|
size_flags_vertical = 3
|
||||||
|
|
@ -140,5 +164,6 @@ drag_to_rearrange_enabled = true
|
||||||
[connection signal="pressed" from="VBoxContainer2/ButtonContainer2/RemoveWave" to="." method="removeWave"]
|
[connection signal="pressed" from="VBoxContainer2/ButtonContainer2/RemoveWave" to="." method="removeWave"]
|
||||||
[connection signal="toggled" from="VBoxContainer2/ButtonContainer4/WaitForKill" to="." method="_on_wait_for_kill_toggled"]
|
[connection signal="toggled" from="VBoxContainer2/ButtonContainer4/WaitForKill" to="." method="_on_wait_for_kill_toggled"]
|
||||||
[connection signal="valueHasChanged" from="VBoxContainer2/ButtonContainer3/WaveTimer" to="." method="changeWaveCooldown"]
|
[connection signal="valueHasChanged" from="VBoxContainer2/ButtonContainer3/WaveTimer" to="." method="changeWaveCooldown"]
|
||||||
|
[connection signal="multi_selected" from="VBoxContainer2/ButtonContainer5/TowerSelector" to="." method="onSelectedTowerChange"]
|
||||||
[connection signal="active_tab_rearranged" from="VBoxContainer2/ScrollContainer/WaveContainer" to="." method="changeWaveOrder"]
|
[connection signal="active_tab_rearranged" from="VBoxContainer2/ScrollContainer/WaveContainer" to="." method="changeWaveOrder"]
|
||||||
[connection signal="tab_changed" from="VBoxContainer2/ScrollContainer/WaveContainer" to="." method="tabFocusHaschanged"]
|
[connection signal="tab_changed" from="VBoxContainer2/ScrollContainer/WaveContainer" to="." method="tabFocusHaschanged"]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue