Wednesday, 10 September 2025 01:31:36
This commit is contained in:
@@ -1,92 +1,92 @@
|
||||
using Godot;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
// using Godot;
|
||||
// using System;
|
||||
// using System.Collections.Generic;
|
||||
// using System.Linq;
|
||||
|
||||
public partial class Tchotchke : StaticBody2D
|
||||
{
|
||||
public bool _hovered = false, _held = false;
|
||||
public List<Action> _actions = new();
|
||||
public Node _target;
|
||||
// public partial class Tchotchke : StaticBody2D
|
||||
// {
|
||||
// public bool _hovered = false, _held = false;
|
||||
// public List<Action> _actions = new();
|
||||
// public Node _target;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
MouseEntered += OnMouseEntered;
|
||||
MouseExited += OnMouseExited;
|
||||
}
|
||||
// public override void _Ready()
|
||||
// {
|
||||
// MouseEntered += OnMouseEntered;
|
||||
// MouseExited += OnMouseExited;
|
||||
// }
|
||||
|
||||
public override void _Process(double DELTA_)
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
GlobalPosition = GetGlobalMousePosition();
|
||||
if (Input.IsActionJustReleased("left_click"))
|
||||
{
|
||||
Transform2D newTransform = GlobalTransform;
|
||||
newTransform.Origin = Position;
|
||||
GlobalTransform = newTransform;
|
||||
Drop();
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_hovered)
|
||||
{
|
||||
if (Input.IsActionJustPressed("left_click"))
|
||||
{
|
||||
Hold();
|
||||
}
|
||||
if (Input.IsActionJustPressed("scroll_up"))
|
||||
{
|
||||
Rotation -= 1.0f * (float)(Math.PI) / 180.0f;
|
||||
}
|
||||
if (Input.IsActionJustPressed("scroll_down"))
|
||||
{
|
||||
Rotation += 1.0f * (float)(Math.PI) / 180.0f;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// public override void _Process(double DELTA_)
|
||||
// {
|
||||
// if (_held)
|
||||
// {
|
||||
// GlobalPosition = GetGlobalMousePosition();
|
||||
// if (Input.IsActionJustReleased("left_click"))
|
||||
// {
|
||||
// Transform2D newTransform = GlobalTransform;
|
||||
// newTransform.Origin = Position;
|
||||
// GlobalTransform = newTransform;
|
||||
// Drop();
|
||||
// }
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// if (_hovered)
|
||||
// {
|
||||
// if (Input.IsActionJustPressed("left_click"))
|
||||
// {
|
||||
// Hold();
|
||||
// }
|
||||
// if (Input.IsActionJustPressed("scroll_up"))
|
||||
// {
|
||||
// Rotation -= 1.0f * (float)(Math.PI) / 180.0f;
|
||||
// }
|
||||
// if (Input.IsActionJustPressed("scroll_down"))
|
||||
// {
|
||||
// Rotation += 1.0f * (float)(Math.PI) / 180.0f;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
|
||||
public void Drop()
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
_held = false;
|
||||
}
|
||||
}
|
||||
// public void Drop()
|
||||
// {
|
||||
// if (_held)
|
||||
// {
|
||||
// _held = false;
|
||||
// }
|
||||
// }
|
||||
|
||||
public void FireActions(Trigger.On TRIGGER, Node TARGET = null)
|
||||
{
|
||||
List<Action> triggeredActions = _actions.Where(e => e._triggers.IndexOf(TRIGGER) > -1).ToList();
|
||||
for (int i = 0; i < triggeredActions.Count; i++)
|
||||
{
|
||||
triggeredActions[i].Target(TARGET);
|
||||
triggeredActions[i].Fire();
|
||||
}
|
||||
List<Action> expiredActions = _actions.Where(e => e._triggers.IndexOf(TRIGGER) > -1).ToList();
|
||||
_actions.Except(expiredActions);
|
||||
}
|
||||
// public void FireActions(Trigger.On TRIGGER, Node TARGET = null)
|
||||
// {
|
||||
// List<Action> triggeredActions = _actions.Where(e => e._triggers.IndexOf(TRIGGER) > -1).ToList();
|
||||
// for (int i = 0; i < triggeredActions.Count; i++)
|
||||
// {
|
||||
// triggeredActions[i].Target(TARGET);
|
||||
// triggeredActions[i].Fire();
|
||||
// }
|
||||
// List<Action> expiredActions = _actions.Where(e => e._triggers.IndexOf(TRIGGER) > -1).ToList();
|
||||
// _actions.Except(expiredActions);
|
||||
// }
|
||||
|
||||
public void Hold()
|
||||
{
|
||||
if (_held)
|
||||
{
|
||||
return;
|
||||
}
|
||||
_held = true;
|
||||
}
|
||||
// public void Hold()
|
||||
// {
|
||||
// if (_held)
|
||||
// {
|
||||
// return;
|
||||
// }
|
||||
// _held = true;
|
||||
// }
|
||||
|
||||
// PRIVATE METHODS
|
||||
private void OnMouseEntered()
|
||||
{
|
||||
_hovered = true;
|
||||
}
|
||||
// // PRIVATE METHODS
|
||||
// private void OnMouseEntered()
|
||||
// {
|
||||
// _hovered = true;
|
||||
// }
|
||||
|
||||
private void OnMouseExited()
|
||||
{
|
||||
_hovered = false;
|
||||
}
|
||||
// private void OnMouseExited()
|
||||
// {
|
||||
// _hovered = false;
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
// }
|
||||
|
||||
Reference in New Issue
Block a user