hotbar resize

This commit is contained in:
Rendo 2025-07-21 03:18:01 +05:00
commit 1cd9ef3f3a
9 changed files with 55 additions and 23 deletions

View file

@ -19,5 +19,9 @@ public partial class Cheats : Node
GetTree().CurrentScene.AddChild(spawner);
}
if (@event.IsActionPressed("cheat_unlock_all"))
{
PlayerProgress.Instance.PlayerPlants = GameRegistry.GetPlants();
}
}
}

View file

@ -1,5 +1,6 @@
using Godot;
using Godot.Collections;
using Newlon.Components.Level;
using Newlon.Systems.Effects;
namespace Newlon.Components;
@ -58,22 +59,30 @@ public partial class Entity : Node2D
#region Brain
[Export] private AnimationPlayer _player;
[Export] private AnimationTree _tree;
public virtual void DisableBrain()
private bool forceToggledBrain = false;
private bool brainEnabled = true;
public virtual void DisableBrain(bool force = true)
{
if (brainEnabled == false) return;
if (_player != null)
_player.ProcessMode = ProcessModeEnum.Pausable;
if (_tree != null)
_tree.ProcessMode = ProcessModeEnum.Pausable;
ProcessMode = ProcessModeEnum.Disabled;
forceToggledBrain = force;
brainEnabled = false;
}
public virtual void EnableBrain()
public virtual void EnableBrain(bool force = true)
{
if (brainEnabled) return;
if (_player != null)
_player.ProcessMode = ProcessModeEnum.Inherit;
if (_tree != null)
_tree.ProcessMode = ProcessModeEnum.Inherit;
ProcessMode = ProcessModeEnum.Inherit;
forceToggledBrain = force;
brainEnabled = true;
}
#endregion
#region Effects
@ -171,6 +180,11 @@ public partial class Entity : Node2D
public override void _Ready()
{
HP = MaxHP;
if (RuntimeLevelData.Instance != null)
{
if (RuntimeLevelData.Instance.GetLevelState() != RuntimeLevelData.LevelStates.Game) DisableBrain(false);
}
}
#endregion
}

View file

@ -0,0 +1,24 @@
using Godot;
using Newlon.Components.Level;
using System;
public partial class PlantHotbarSize : PanelContainer
{
const int MARGIN = 4;
const int PACKET_WIDTH = 41;
const int MINIMUM_Y = 64;
public override void _Ready()
{
CustomMinimumSize = new Vector2(MARGIN * 2 + PACKET_WIDTH * PlayerProgress.Instance.MaxSeedpackets, MINIMUM_Y);
RuntimeLevelData.Instance.OnLevelStateChanged += OnLevelStateChanged;
}
public void OnLevelStateChanged(RuntimeLevelData.LevelStates state)
{
if (state != RuntimeLevelData.LevelStates.ChooseYourSeeds)
{
CustomMinimumSize = new Vector2(0, MINIMUM_Y);
}
}
}

View file

@ -0,0 +1 @@
uid://bygqu13os20wi

View file

@ -24,11 +24,12 @@ public partial class RewardScene : Node
}
var rewardedObject = reward.GetPreview().Instantiate();
subviewport.AddChild(rewardedObject);
if (rewardedObject is Entity entity)
{
entity.DisableBrain();
}
subviewport.AddChild(rewardedObject);
}
}

View file

@ -13,9 +13,6 @@ public partial class LevelController : Node
public static LevelController Instance { get; private set; }
public RewardResource Reward { get; private set; }
private string pathToInitiator;
private bool _isLevelRunning = false;
public override void _EnterTree()
{
Instance = this;
@ -32,16 +29,10 @@ public partial class LevelController : Node
/// <param name="levelResource">Execution of level</param>
public void StartLevel(PackedScene levelTileset, AdventureLevelResource levelResource)
{
if (_isLevelRunning)
return;
pathToInitiator = GetTree().CurrentScene.SceneFilePath;
RuntimeLevelData.LevelResource = levelResource;
GetTree().ChangeSceneToPacked(levelTileset);
_isLevelRunning = true;
}
public void RestartLevel()
{
@ -51,13 +42,8 @@ public partial class LevelController : Node
}
public void EndLevel()
{
if (_isLevelRunning == false)
return;
RuntimeLevelData.LevelResource = null;
_isLevelRunning = false;
if (Reward != null)
{
GetTree().ChangeSceneToFile(REWARD_SCENE_UID);
@ -72,7 +58,6 @@ public partial class LevelController : Node
if (pathToInitiator == null) return;
GetTree().ChangeSceneToFile(pathToInitiator);
pathToInitiator = null;
}

View file

@ -92,10 +92,6 @@ public partial class RuntimeLevelData : Node
{
return _currentState;
}
public override void _ExitTree()
{
LevelController.Instance.EndLevel();
}
//private Array<PlantResource> _selectedPlants;