Add skill upgrade system and refactor skill components for enhanced functionality; update resource paths and configurations

This commit is contained in:
2025-08-26 23:48:59 +02:00
parent afca70e6c6
commit 55c3ae212b
20 changed files with 212 additions and 76 deletions

View File

@@ -35,12 +35,12 @@ public partial class Marketplace : Control
var unlockedSkills = _gameManager.GetUnlockedSkills();
foreach (var skill in unlockedSkills) CreateSkillButton(skill);
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocker;
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
}
public override void _ExitTree()
{
SkillUnlockerComponent.SkillUnlocked -= OnSkillUnlocker;
SkillUnlockerComponent.SkillUnlocked -= OnSkillUnlocked;
}
public override void _Input(InputEvent @event)
@@ -59,21 +59,24 @@ public partial class Marketplace : Control
}
}
private string GetButtonText(SkillData skill)
private void OnSkillUnlocked(SkillData skill)
{
return $"{Tr(skill.Name)} {skill.Cost}";
}
private void OnSkillUnlocker(SkillData skill)
{
if (_skillButtons.Count == 0) CreateSkillButton(skill);
var buttonExists = false;
foreach (var existingButton in _skillButtons)
{
if (existingButton.Name == skill.Name)
{
buttonExists = true;
break;
}
}
if (!buttonExists) CreateSkillButton(skill);
foreach (var btn in _skillButtons)
{
if (btn.Data.IsActive)
btn.Activate();
else
btn.Deactivate();
if (btn.Data.IsActive) btn.Activate();
else btn.Deactivate();
}
}
@@ -93,7 +96,6 @@ public partial class Marketplace : Control
private void CreateUpgradeButton(SkillData skill)
{
var button = MarketplaceButtonScene.Instantiate<MarketplaceButton>();
button.Text = GetButtonText(skill);
button.Data = skill;
button.Icon = skill.Icon;
button.Pressed += () => OnUpgradeButtonPressed(skill);
@@ -123,18 +125,6 @@ public partial class Marketplace : Control
}
}
private void RemoveButton(SkillData skill)
{
foreach (var node in ToUnlockGrid.GetChildren())
{
var child = (Button)node;
if (child.Text != GetButtonText(skill)) continue;
child.QueueFree();
break;
}
}
private void OnSkillButtonPressed(SkillButton button)
{
SkillUnlockerComponent.SkillManager.ToggleSkillActivation(button.Data);

View File

@@ -18,45 +18,73 @@ public partial class MarketplaceButton : Button
public override void _Ready()
{
_gameManager = GetNode<GameManager>("/root/GameManager");
Setup();
var player = _gameManager.Player;
var skillUnlockerComponent = player?.GetNodeOrNull<SkillUnlockerComponent>("SkillUnlockerComponent");
if (skillUnlockerComponent == null) return;
if (player == null) return;
skillUnlockerComponent.SkillUnlocked += OnSkillUnlock;
_skillUnlockerComponent = player.GetNodeOrNull<SkillUnlockerComponent>("SkillUnlockerComponent");
if (_skillUnlockerComponent != null)
{
_skillUnlockerComponent.SkillUnlocked += OnSkillStateChanged;
}
UpdateButtonState();
}
public override void _ExitTree()
{
_skillUnlockerComponent.SkillUnlocked -= OnSkillUnlock;
if (_skillUnlockerComponent != null)
{
_skillUnlockerComponent.SkillUnlocked -= OnSkillStateChanged;
}
}
private void OnSkillStateChanged(SkillData skill)
{
if (skill.Name == Data.Name)
{
UpdateButtonState();
}
}
private void Setup()
private void UpdateButtonState()
{
if (Data == null) return;
if (Data == null || Data.Upgrades.Count == 0)
{
Visible = false;
return;
}
var isUnlocked = _gameManager.IsSkillUnlocked(Data);
for (var i = 0; i < SkillLevelContainer.GetChildCount(); i++)
{
SkillLevelContainer.GetChild(i).QueueFree();
}
for (var i = 0; i < Data.MaxLevel; i++)
{
var icon = new TextureRect()
{
Texture = i < Data.Level ? UnlockedSkillIcon : LockedSkillIcon,
Texture = (isUnlocked && i < Data.Level) ? UnlockedSkillIcon : LockedSkillIcon,
ExpandMode = TextureRect.ExpandModeEnum.FitWidthProportional
};
SkillLevelContainer.AddChild(icon);
}
}
private void OnSkillUnlock(SkillData skill)
{
if (skill.Name != Data.Name) return;
for (var i = 0; i < Data.MaxLevel; i++)
if (!isUnlocked)
{
var icon = SkillLevelContainer.GetChildOrNull<TextureRect>(i);
if (icon == null) continue;
icon.Texture = i < Data.Level ? UnlockedSkillIcon : LockedSkillIcon;
Disabled = i >= Data.Level;
Text = $"{Tr(Data.Name)} ({Data.Upgrades[0].Cost})";
Disabled = false;
}
else if (Data.Level < Data.MaxLevel)
{
Text = $"{Tr(Data.Name)} ({Data.Upgrades[Data.Level].Cost})";
Disabled = false;
}
else
{
Text = $"{Tr(Data.Name)} (MAX)";
Disabled = true;
}
}
}