Sun, Shovel, Fastforward, GUI Improvements
This commit is contained in:
parent
26c3aeb7e9
commit
63935d5978
28 changed files with 546 additions and 45 deletions
31
scripts/components/gui/FastForwardButton.cs
Normal file
31
scripts/components/gui/FastForwardButton.cs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class FastForwardButton : TextureButton
|
||||
{
|
||||
[Export] private Texture2D firstSpeed;
|
||||
[Export] private Texture2D secondSpeed;
|
||||
[Export] private Texture2D thirdSpeed;
|
||||
|
||||
private int speed = 1;
|
||||
|
||||
public void OnPressed()
|
||||
{
|
||||
speed = Mathf.Wrap(speed+1, 1, 4);
|
||||
|
||||
switch (speed)
|
||||
{
|
||||
case 1:
|
||||
TextureNormal = firstSpeed;
|
||||
break;
|
||||
case 2:
|
||||
TextureNormal = secondSpeed;
|
||||
break;
|
||||
case 3:
|
||||
TextureNormal = thirdSpeed;
|
||||
break;
|
||||
}
|
||||
|
||||
Engine.TimeScale = speed;
|
||||
}
|
||||
}
|
||||
|
|
@ -8,11 +8,21 @@ public partial class PlantSlot : TextureButton
|
|||
[Export] private TextureRect _icon;
|
||||
[Export] private Timer _timer;
|
||||
|
||||
private bool _recharging;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
if (_resource != null)
|
||||
UpdateContents();
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
if (_resource != null)
|
||||
{
|
||||
Disabled = _recharging || LevelController.Instance.LevelData.SunCount < _resource.Cost;
|
||||
FocusMode = Disabled ? FocusModeEnum.None : FocusModeEnum.All;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetPlantResource( PlantResource resource )
|
||||
{
|
||||
|
|
@ -43,8 +53,7 @@ public partial class PlantSlot : TextureButton
|
|||
|
||||
public void Recharge()
|
||||
{
|
||||
Disabled = true;
|
||||
FocusMode = FocusModeEnum.None;
|
||||
_recharging = true;
|
||||
|
||||
ReleaseFocus();
|
||||
|
||||
|
|
@ -53,7 +62,6 @@ public partial class PlantSlot : TextureButton
|
|||
|
||||
private void Timeout()
|
||||
{
|
||||
Disabled = false;
|
||||
FocusMode = FocusModeEnum.All;
|
||||
_recharging = false;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
39
scripts/components/gui/ShovelButton.cs
Normal file
39
scripts/components/gui/ShovelButton.cs
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
using Godot;
|
||||
using System;
|
||||
|
||||
public partial class ShovelButton : TextureButton
|
||||
{
|
||||
private RayCast2D _shovelCast;
|
||||
public override void _Ready()
|
||||
{
|
||||
_shovelCast = GetNode<RayCast2D>("RayCast2D");
|
||||
_shovelCast.CallDeferred("reparent", GetTree().CurrentScene);
|
||||
}
|
||||
private void OnFocusExited()
|
||||
{
|
||||
ButtonPressed = false;
|
||||
}
|
||||
public override void _Process(double delta)
|
||||
{
|
||||
_shovelCast.GlobalPosition = _shovelCast.GetGlobalMousePosition();
|
||||
}
|
||||
public override void _Toggled(bool toggledOn)
|
||||
{
|
||||
_shovelCast.Enabled = toggledOn;
|
||||
|
||||
Cursor.Instance.shovel = toggledOn;
|
||||
Cursor.Instance.UpdateCursor();
|
||||
}
|
||||
|
||||
public override void _Input(InputEvent @event)
|
||||
{
|
||||
if (@event.IsActionPressed("primary_action"))
|
||||
{
|
||||
if (_shovelCast.IsColliding() && (_shovelCast.GetCollider() as CollisionObject2D).GetParent() is RuntimePlantData plant)
|
||||
{
|
||||
plant.Kill();
|
||||
}
|
||||
ButtonPressed = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue