chore: add confirm popup
This commit is contained in:
parent
0f3ca8137a
commit
d68f496ad1
10 changed files with 122 additions and 23 deletions
|
|
@ -37,6 +37,9 @@ func _ready() -> void:
|
||||||
|
|
||||||
|
|
||||||
func _input(event: InputEvent) -> void:
|
func _input(event: InputEvent) -> void:
|
||||||
|
if Engine.is_editor_hint():
|
||||||
|
return
|
||||||
|
|
||||||
if event.is_action_pressed("pause_game"):
|
if event.is_action_pressed("pause_game"):
|
||||||
get_tree().paused = not get_tree().paused
|
get_tree().paused = not get_tree().paused
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,10 @@
|
||||||
@tool
|
@tool
|
||||||
class_name Helper
|
class_name Helper
|
||||||
|
|
||||||
|
|
||||||
|
const confirmPopupScene : PackedScene = preload("res://UI/confirm_popup.tscn")
|
||||||
|
|
||||||
|
|
||||||
const SCENE_DIR_PATTERN : String = "res://\\w+/(Scenes|Map \\d+)/$"
|
const SCENE_DIR_PATTERN : String = "res://\\w+/(Scenes|Map \\d+)/$"
|
||||||
const SCENE_FILE_PATTERN : String = "([^/]*)\\.tscn$"
|
const SCENE_FILE_PATTERN : String = "([^/]*)\\.tscn$"
|
||||||
const RESOURCE_FILE_PATTERN : String = "([^/]*)\\.tres$"
|
const RESOURCE_FILE_PATTERN : String = "([^/]*)\\.tres$"
|
||||||
|
|
@ -63,3 +67,16 @@ static func getFileFromDir(path : String, regexPattern : String, pathRegexPatter
|
||||||
files.append(path + file)
|
files.append(path + file)
|
||||||
|
|
||||||
return files
|
return files
|
||||||
|
|
||||||
|
|
||||||
|
static func showConfirmPopup(
|
||||||
|
text : String,
|
||||||
|
nodeToAppend : Node,
|
||||||
|
confirmCallback : Callable,
|
||||||
|
cancelCallback : Callable = func(): null
|
||||||
|
) -> void:
|
||||||
|
var confirmPopup : ConfirmPopup = confirmPopupScene.instantiate()
|
||||||
|
nodeToAppend.add_child(confirmPopup)
|
||||||
|
confirmPopup.label.text = text
|
||||||
|
confirmPopup.confirmed.connect(confirmCallback)
|
||||||
|
confirmPopup.canceled.connect(cancelCallback)
|
||||||
|
|
|
||||||
|
|
@ -29,8 +29,8 @@ baseCost = 20
|
||||||
value = 10.0
|
value = 10.0
|
||||||
maxLevel = 3
|
maxLevel = 3
|
||||||
upgradeDirection = 1
|
upgradeDirection = 1
|
||||||
upgradeScaleType = 1
|
upgradeScaleType = 0
|
||||||
costScaleType = 1
|
costScaleType = 0
|
||||||
costModificator = 30.0
|
costModificator = 30.0
|
||||||
metadata/_custom_type_script = "uid://bg0x4egeu17qb"
|
metadata/_custom_type_script = "uid://bg0x4egeu17qb"
|
||||||
|
|
||||||
|
|
@ -43,8 +43,8 @@ baseCost = 50
|
||||||
value = 2.0
|
value = 2.0
|
||||||
maxLevel = 3
|
maxLevel = 3
|
||||||
upgradeDirection = 1
|
upgradeDirection = 1
|
||||||
upgradeScaleType = 1
|
upgradeScaleType = 0
|
||||||
costScaleType = 1
|
costScaleType = 0
|
||||||
costModificator = 50.0
|
costModificator = 50.0
|
||||||
metadata/_custom_type_script = "uid://bg0x4egeu17qb"
|
metadata/_custom_type_script = "uid://bg0x4egeu17qb"
|
||||||
|
|
||||||
|
|
@ -57,8 +57,8 @@ baseCost = 50
|
||||||
value = 2.0
|
value = 2.0
|
||||||
maxLevel = 3
|
maxLevel = 3
|
||||||
upgradeDirection = 1
|
upgradeDirection = 1
|
||||||
upgradeScaleType = 1
|
upgradeScaleType = 0
|
||||||
costScaleType = 1
|
costScaleType = 0
|
||||||
costModificator = 50.0
|
costModificator = 50.0
|
||||||
|
|
||||||
[sub_resource type="Resource" id="Resource_wnw3f"]
|
[sub_resource type="Resource" id="Resource_wnw3f"]
|
||||||
|
|
@ -71,7 +71,7 @@ value = 0.2
|
||||||
maxLevel = 2
|
maxLevel = 2
|
||||||
upgradeDirection = 1
|
upgradeDirection = 1
|
||||||
upgradeScaleType = 0
|
upgradeScaleType = 0
|
||||||
costScaleType = 1
|
costScaleType = 0
|
||||||
costModificator = 0.0
|
costModificator = 0.0
|
||||||
|
|
||||||
[sub_resource type="ViewportTexture" id="ViewportTexture_r52mr"]
|
[sub_resource type="ViewportTexture" id="ViewportTexture_r52mr"]
|
||||||
|
|
@ -94,3 +94,4 @@ texture = SubResource("ViewportTexture_r52mr")
|
||||||
|
|
||||||
[node name="EnergyBar2D" parent="EnergyBar3D/SubViewport" index="0"]
|
[node name="EnergyBar2D" parent="EnergyBar3D/SubViewport" index="0"]
|
||||||
max_value = 25.0
|
max_value = 25.0
|
||||||
|
value = 25.0
|
||||||
|
|
|
||||||
|
|
@ -146,11 +146,12 @@ func onBodyExited(body: Node3D) -> void:
|
||||||
|
|
||||||
|
|
||||||
func toggleConnection(activate : bool) -> void:
|
func toggleConnection(activate : bool) -> void:
|
||||||
if activate:
|
if activate && not $Range.body_entered.is_connected(onBodyEntered):
|
||||||
$Range.body_entered.connect(onBodyEntered)
|
$Range.body_entered.connect(onBodyEntered)
|
||||||
$Range.body_exited.connect(onBodyExited)
|
$Range.body_exited.connect(onBodyExited)
|
||||||
else:
|
else:
|
||||||
$Range.body_entered.disconnect(onBodyEntered)
|
if $Range.body_entered.is_connected(onBodyEntered):
|
||||||
$Range.body_exited.disconnect(onBodyExited)
|
$Range.body_entered.disconnect(onBodyEntered)
|
||||||
|
$Range.body_exited.disconnect(onBodyExited)
|
||||||
availableTargets.clear()
|
availableTargets.clear()
|
||||||
target = null
|
target = null
|
||||||
|
|
|
||||||
18
UI/ConfirmPopup.gd
Normal file
18
UI/ConfirmPopup.gd
Normal file
|
|
@ -0,0 +1,18 @@
|
||||||
|
extends PanelContainer
|
||||||
|
class_name ConfirmPopup
|
||||||
|
|
||||||
|
|
||||||
|
signal confirmed
|
||||||
|
signal canceled
|
||||||
|
|
||||||
|
@onready var label : Label = $MarginContainer/ConfirmPrompt/Label
|
||||||
|
|
||||||
|
|
||||||
|
func _ready() -> void:
|
||||||
|
%CancelBtn.pressed.connect(emitPressedButton.bind(canceled))
|
||||||
|
%ConfirmBtn.pressed.connect(emitPressedButton.bind(confirmed))
|
||||||
|
|
||||||
|
|
||||||
|
func emitPressedButton(state : Signal) -> void:
|
||||||
|
state.emit()
|
||||||
|
queue_free()
|
||||||
1
UI/ConfirmPopup.gd.uid
Normal file
1
UI/ConfirmPopup.gd.uid
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
uid://8c1ej1k0vbmn
|
||||||
51
UI/confirm_popup.tscn
Normal file
51
UI/confirm_popup.tscn
Normal file
|
|
@ -0,0 +1,51 @@
|
||||||
|
[gd_scene load_steps=3 format=3 uid="uid://cxn3x8dq8vawa"]
|
||||||
|
|
||||||
|
[ext_resource type="Script" uid="uid://8c1ej1k0vbmn" path="res://UI/ConfirmPopup.gd" id="1_8vkfp"]
|
||||||
|
[ext_resource type="Theme" uid="uid://bbp4qcbwkeg7x" path="res://default_theme.tres" id="1_x7bkm"]
|
||||||
|
|
||||||
|
[node name="Panel" type="PanelContainer"]
|
||||||
|
anchors_preset = 8
|
||||||
|
anchor_left = 0.5
|
||||||
|
anchor_top = 0.5
|
||||||
|
anchor_right = 0.5
|
||||||
|
anchor_bottom = 0.5
|
||||||
|
offset_left = -194.0
|
||||||
|
offset_right = 194.0
|
||||||
|
offset_bottom = 128.0
|
||||||
|
grow_horizontal = 2
|
||||||
|
grow_vertical = 2
|
||||||
|
size_flags_horizontal = 3
|
||||||
|
size_flags_vertical = 3
|
||||||
|
theme = ExtResource("1_x7bkm")
|
||||||
|
script = ExtResource("1_8vkfp")
|
||||||
|
|
||||||
|
[node name="MarginContainer" type="MarginContainer" parent="."]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/margin_left = 50
|
||||||
|
theme_override_constants/margin_top = 50
|
||||||
|
theme_override_constants/margin_right = 50
|
||||||
|
theme_override_constants/margin_bottom = 25
|
||||||
|
|
||||||
|
[node name="ConfirmPrompt" type="VBoxContainer" parent="MarginContainer"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 50
|
||||||
|
|
||||||
|
[node name="Label" type="Label" parent="MarginContainer/ConfirmPrompt"]
|
||||||
|
layout_mode = 2
|
||||||
|
size_flags_vertical = 6
|
||||||
|
horizontal_alignment = 1
|
||||||
|
|
||||||
|
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/ConfirmPrompt"]
|
||||||
|
layout_mode = 2
|
||||||
|
theme_override_constants/separation = 50
|
||||||
|
|
||||||
|
[node name="ConfirmBtn" type="Button" parent="MarginContainer/ConfirmPrompt/HBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Confirm"
|
||||||
|
|
||||||
|
[node name="CancelBtn" type="Button" parent="MarginContainer/ConfirmPrompt/HBoxContainer"]
|
||||||
|
unique_name_in_owner = true
|
||||||
|
layout_mode = 2
|
||||||
|
text = "Cancel
|
||||||
|
"
|
||||||
|
|
@ -21,8 +21,8 @@ func _ready() -> void:
|
||||||
EventBus.wave_has_change.connect(onWaveChange)
|
EventBus.wave_has_change.connect(onWaveChange)
|
||||||
%NextWaveBtn.pressed.connect(EventBus.lauch_next_wave.emit)
|
%NextWaveBtn.pressed.connect(EventBus.lauch_next_wave.emit)
|
||||||
$WaveCooldown/Timer.timeout.connect(updateWaveCooldownLabel)
|
$WaveCooldown/Timer.timeout.connect(updateWaveCooldownLabel)
|
||||||
%QuitLevelBtn.pressed.connect(Game.quitLevel)
|
%QuitLevelBtn.pressed.connect(Helper.showConfirmPopup.bind("Quit level ?", self, Game.quitLevel))
|
||||||
%QuitGameBtn.pressed.connect(Game.quitGame)
|
%QuitGameBtn.pressed.connect(Helper.showConfirmPopup.bind("Quit game ?", self, Game.quitGame))
|
||||||
$TowerInfoPanel.visible = false
|
$TowerInfoPanel.visible = false
|
||||||
|
|
||||||
if Engine.is_editor_hint():
|
if Engine.is_editor_hint():
|
||||||
|
|
|
||||||
|
|
@ -18,17 +18,22 @@ func towerLinked(value) -> void:
|
||||||
$LeFond/Label.text = "%d €" % tower.price
|
$LeFond/Label.text = "%d €" % tower.price
|
||||||
toggle_mode = true
|
toggle_mode = true
|
||||||
add_theme_stylebox_override("pressed", GameStyleBoxFlat.createWithColor(GameColor.COLOR.SELECTED))
|
add_theme_stylebox_override("pressed", GameStyleBoxFlat.createWithColor(GameColor.COLOR.SELECTED))
|
||||||
tower.changed.connect(towerChanged)
|
tower.changed.connect(onTowerChanged)
|
||||||
tower.energy_changed.connect(func(): $EnergyBar.value = tower.energy)
|
tower.energy_changed.connect(func(): $EnergyBar.value = tower.energy)
|
||||||
|
Game.money_changed.connect(onMoneyChanged)
|
||||||
EventBus.tower_selected.connect(func(_type): set_pressed_no_signal(_type == tower.type))
|
EventBus.tower_selected.connect(func(_type): set_pressed_no_signal(_type == tower.type))
|
||||||
toggled.connect(func(state): EventBus.tower_selected.emit(tower.type if state else Tower.TYPE.NONE))
|
toggled.connect(func(state): EventBus.tower_selected.emit(tower.type if state else Tower.TYPE.NONE))
|
||||||
tooltip_text = tower.name
|
tooltip_text = tower.name
|
||||||
texture = tower.icone
|
texture = tower.icone
|
||||||
towerChanged()
|
onTowerChanged()
|
||||||
|
|
||||||
|
|
||||||
func towerChanged() -> void :
|
func onTowerChanged() -> void :
|
||||||
disabled = not tower.builded && Game.money < tower.price
|
disabled = not tower.builded && Game.money < tower.price
|
||||||
$EnergyBar.max_value = tower.max_energy
|
$EnergyBar.max_value = tower.max_energy
|
||||||
$EnergyBar.visible = tower.builded
|
$EnergyBar.visible = tower.builded
|
||||||
$LeFond.visible = not tower.builded
|
$LeFond.visible = not tower.builded
|
||||||
|
|
||||||
|
|
||||||
|
func onMoneyChanged() -> void:
|
||||||
|
disabled = not tower.builded && Game.money < tower.price
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ extends Resource
|
||||||
class_name Upgrade
|
class_name Upgrade
|
||||||
|
|
||||||
|
|
||||||
enum SCALE_TYPE { NONE, LINEAR, EXP, LOG }
|
enum SCALE_TYPE { LINEAR, EXP, LOG }
|
||||||
enum UPGRADE_DIRECTION { INCREASE = 1, DECREASE = -1 }
|
enum UPGRADE_DIRECTION { INCREASE = 1, DECREASE = -1 }
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -17,7 +17,7 @@ enum UPGRADE_DIRECTION { INCREASE = 1, DECREASE = -1 }
|
||||||
|
|
||||||
@export_group("Upgrade Scaling")
|
@export_group("Upgrade Scaling")
|
||||||
@export var upgradeDirection : UPGRADE_DIRECTION = UPGRADE_DIRECTION.INCREASE
|
@export var upgradeDirection : UPGRADE_DIRECTION = UPGRADE_DIRECTION.INCREASE
|
||||||
@export var upgradeScaleType : SCALE_TYPE = SCALE_TYPE.NONE
|
@export var upgradeScaleType : SCALE_TYPE = SCALE_TYPE.LINEAR
|
||||||
@export var costScaleType : SCALE_TYPE = SCALE_TYPE.LINEAR
|
@export var costScaleType : SCALE_TYPE = SCALE_TYPE.LINEAR
|
||||||
@export var costModificator : float
|
@export var costModificator : float
|
||||||
|
|
||||||
|
|
@ -29,20 +29,22 @@ var isLevelMax : bool :
|
||||||
|
|
||||||
|
|
||||||
func upgradeProperty(subject: Variant, property: String) -> void:
|
func upgradeProperty(subject: Variant, property: String) -> void:
|
||||||
subject.set(property, getNextValue(subject.get(property)))
|
subject.set(property, getNextValue(subject.get(property), value, upgradeScaleType))
|
||||||
|
|
||||||
|
|
||||||
func upgradeUpgrade() -> void:
|
func upgradeUpgrade() -> void:
|
||||||
level += 1
|
level += 1
|
||||||
Game.money -= cost
|
Game.money -= cost
|
||||||
cost += costModificator
|
cost = getNextValue(cost, costModificator, costScaleType)
|
||||||
|
|
||||||
|
|
||||||
func canUpgrade():
|
func canUpgrade():
|
||||||
return not isLevelMax && Game.money >= cost
|
return not isLevelMax && Game.money >= cost
|
||||||
|
|
||||||
|
|
||||||
func getNextValue(oldValue):
|
func getNextValue(oldValue, baseValue, scaleType : SCALE_TYPE):
|
||||||
match upgradeScaleType:
|
match scaleType:
|
||||||
SCALE_TYPE.NONE: return oldValue + value
|
SCALE_TYPE.LINEAR: return oldValue + value
|
||||||
SCALE_TYPE.LINEAR: return oldValue + (value * upgradeDirection * level)
|
_:
|
||||||
|
push_warning("Upgrade scale type not defined !")
|
||||||
|
return oldValue
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue