* Refactor collectable components to C# and update resource scripts for consistency * Update resource paths and refactor properties for consistency * Refactor UI components to inherit from Control and update node paths for consistency * Update node paths and group assignments for consistency across scenes * Refactor GameManager and PlayerDeathComponent for improved state management and logging; update scene connections for player death handling * Add PhantomCamera components and UI elements for improved scene management; refactor existing components for better integration * Refactor skill components and update resource paths for consistency; enhance skill management in scenes * Add new UID files and update scene configurations for dialogue components; refactor skill management and input handling * Add next level command and refactor player retrieval in GameManager; update scene files for consistency * Add skill upgrade system and refactor skill components for enhanced functionality; update resource paths and configurations * Enhance ChargeProgressBar and Marketplace functionality; add owner exit handling and update skill button states * Refactor ChargeProgressBar and SkillManager; update skill handling and improve component interactions * Refactor player and level configurations; streamline FlipPlayerComponent and reposition Spaceship Enter
140 lines
4.2 KiB
C#
140 lines
4.2 KiB
C#
using System.Collections.Generic;
|
|
using Godot;
|
|
using Godot.Collections;
|
|
using Mr.BrickAdventures.Autoloads;
|
|
using Mr.BrickAdventures.scripts.components;
|
|
using Mr.BrickAdventures.scripts.Resources;
|
|
|
|
namespace Mr.BrickAdventures.scripts.UI;
|
|
|
|
public partial class Marketplace : Control
|
|
{
|
|
[Export] public Array<SkillData> Skills { get; set; } = [];
|
|
[Export] public GridContainer ToUnlockGrid { get; set; }
|
|
[Export] public GridContainer UnlockedGrid { get; set; }
|
|
[Export] public Font Font { get; set; }
|
|
[Export] public SkillUnlockerComponent SkillUnlockerComponent { get; set; }
|
|
[Export] public Array<Node> ComponentsToDisable { get; set; } = [];
|
|
[Export] public PackedScene MarketplaceButtonScene { get; set; }
|
|
[Export] public PackedScene SkillButtonScene { get; set; }
|
|
|
|
private GameManager _gameManager;
|
|
private readonly List<Button> _unlockButtons = [];
|
|
private readonly List<SkillButton> _skillButtons = [];
|
|
|
|
public override void _Ready()
|
|
{
|
|
_gameManager = GetNode<GameManager>("/root/GameManager");
|
|
|
|
var skillsToUnlock = new List<SkillData>();
|
|
|
|
foreach (var skill in Skills) skillsToUnlock.Add(skill);
|
|
|
|
foreach (var skill in skillsToUnlock) CreateUpgradeButton(skill);
|
|
|
|
var unlockedSkills = _gameManager.GetUnlockedSkills();
|
|
foreach (var skill in unlockedSkills) CreateSkillButton(skill);
|
|
|
|
SkillUnlockerComponent.SkillUnlocked += OnSkillUnlocked;
|
|
}
|
|
|
|
public override void _ExitTree()
|
|
{
|
|
SkillUnlockerComponent.SkillUnlocked -= OnSkillUnlocked;
|
|
}
|
|
|
|
public override void _Input(InputEvent @event)
|
|
{
|
|
if (!@event.IsActionPressed("show_marketplace")) return;
|
|
|
|
if (IsVisible())
|
|
{
|
|
Hide();
|
|
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Inherit;
|
|
}
|
|
else
|
|
{
|
|
Show();
|
|
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Disabled;
|
|
}
|
|
}
|
|
|
|
private void OnSkillUnlocked(SkillData 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();
|
|
}
|
|
}
|
|
|
|
private void CreateSkillButton(SkillData skill)
|
|
{
|
|
var button = SkillButtonScene.Instantiate<SkillButton>();
|
|
button.Data = skill;
|
|
button.Setup();
|
|
button.Pressed += () => OnSkillButtonPressed(button);
|
|
button.Activate();
|
|
|
|
_skillButtons.Add(button);
|
|
UnlockedGrid.AddChild(button);
|
|
UnlockedGrid.QueueSort();
|
|
}
|
|
|
|
private void CreateUpgradeButton(SkillData skill)
|
|
{
|
|
var button = MarketplaceButtonScene.Instantiate<MarketplaceButton>();
|
|
button.Data = skill;
|
|
button.Icon = skill.Icon;
|
|
button.Pressed += () => OnUpgradeButtonPressed(skill);
|
|
|
|
_unlockButtons.Add(button);
|
|
ToUnlockGrid.AddChild(button);
|
|
ToUnlockGrid.QueueSort();
|
|
}
|
|
|
|
private void OnUpgradeButtonPressed(SkillData skill)
|
|
{
|
|
if (_gameManager.IsSkillUnlocked(skill))
|
|
{
|
|
if (skill.Level < skill.MaxLevel)
|
|
{
|
|
SkillUnlockerComponent.TryUpgradeSkill(skill);
|
|
if (!skill.IsActive) SkillUnlockerComponent.SkillManager.ToggleSkillActivation(skill);
|
|
}
|
|
else
|
|
{
|
|
SkillUnlockerComponent.SkillManager.ToggleSkillActivation(skill);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
SkillUnlockerComponent.TryUnlockSkill(skill);
|
|
}
|
|
}
|
|
|
|
private void OnSkillButtonPressed(SkillButton button)
|
|
{
|
|
SkillUnlockerComponent.SkillManager.ToggleSkillActivation(button.Data);
|
|
|
|
foreach (var btn in _skillButtons)
|
|
{
|
|
if (btn.Data.IsActive)
|
|
btn.Activate();
|
|
else
|
|
btn.Deactivate();
|
|
}
|
|
}
|
|
} |