Files
przygody-pana-cegly/scripts/UI/Marketplace.cs
Gabriel Kaszewski d84f7d1740 Csharp rewrite (#4)
* Implement BeamComponent in C# and enhance marketplace button functionality

* Add core game components including ConfigFileHandler, GameManager, SaveSystem, and UIManager

* cleanup

* Add new components: CanPickUpComponent, CollapsableComponent, DestroyableComponent, EffectInflictorComponent, StatusEffectComponent, and StatusEffectDataResource

* Add new components: EnemyDeathComponent, EnemyWaveTriggerComponent, and ExitDoorComponent

* Add new components: ExplosiveComponent, FadeAwayComponent, FireEffectComponent, FlipComponent, GravityMotionComponent, LaunchComponent, and update PlatformMovement with LastDirection property

* Add new components: HealComponent, HitComponent, HomingMissileMotionComponent, LeverComponent, and TriggerLeverComponent

* Refactor GameManager session state handling and add new components: CanBeLaunchedComponent, IceEffectComponent, JumpPadComponent, KillPlayerOutOfScreenComponent, KnockbackComponent, LifetimeComponent, MagneticSkillComponent, OutOfScreenComponent, PeriodicShootingComponent, PlayerDeathComponent, ProgressiveDamageComponent, ProjectileComponent, ProjectileInitComponent, RequirementComponent, ScoreComponent, ShipMovementComponent, ShipShooterComponent, and SideToSideMovementComponent

* Add new components: CannotStompComponent, SkillUnlockedComponent, SpaceshipEnterComponent, SpaceshipExitComponent, SpinComponent, StompDamageComponent, StraightMotionComponent, TerrainHitFx, TooltipComponent, TrailComponent, and UnlockOnRequirementComponent

* Add new components: BrickThrowComponent, BulletComponent, CageComponent, ChaseLevelComponent, CleanupComponent, and ThrowInputResource classes; implement game saving and loading logic in SaveSystem

* Add audio settings management and platform movement component

* Add ChargeProgressBar, Credits, and GameOverScreen components for UI management

* Add UID files for ConfigFileHandler, GameManager, SaveSystem, and UIManager components

* Add README.md file with game description and features; include project license and contribution guidelines

* Add Hud component for UI management; display health, coins, and lives

* Add MainMenu and Marketplace components; implement game management and skill unlocking features

* Add PauseMenu, SettingsMenu, and SkillButton components; enhance game management and UI functionality
2025-08-15 00:45:57 +02:00

142 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 : Node
{
[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 SkillUnlockedComponent SkillUnlockedComponent { 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()
{
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);
SkillUnlockedComponent.SkillUnlocked += OnSkillUnlocked;
}
public override void _ExitTree()
{
SkillUnlockedComponent.SkillUnlocked -= OnSkillUnlocked;
}
public override void _Input(InputEvent @event)
{
var root = Owner as Control;
if (!@event.IsActionPressed("show_marketplace")) return;
if (root != null && root.IsVisible())
{
root.Hide();
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Inherit;
}
else
{
root?.Show();
foreach (var c in ComponentsToDisable) c.ProcessMode = ProcessModeEnum.Disabled;
}
}
private string GetButtonText(SkillData skill)
{
return $"{Tr(skill.Name)} {skill.Cost}";
}
private void OnSkillUnlocked(SkillData skill)
{
if (_skillButtons.Count == 0) 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.Text = GetButtonText(skill);
button.Data = skill;
button.Icon = skill.Icon;
button.Pressed += () => OnUpgradeButtonPressed(skill);
_unlockButtons.Add(button);
UnlockedGrid.AddChild(button);
UnlockedGrid.QueueSort();
}
private void OnUpgradeButtonPressed(SkillData skill)
{
if (_gameManager.IsSkillUnlocked(skill))
{
if (skill.Level < skill.MaxLevel)
{
SkillUnlockedComponent.TryUpgradeSkill(skill);
if (!skill.IsActive) SkillUnlockedComponent.SkillManager.ToggleSkillActivation(skill);
}
else
{
SkillUnlockedComponent.SkillManager.ToggleSkillActivation(skill);
}
}
else
{
SkillUnlockedComponent.TryUnlockSkill(skill);
}
}
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)
{
SkillUnlockedComponent.SkillManager.ToggleSkillActivation(button.Data);
}
}