2023-10-10 23:50:24 -07:00
|
|
|
using Godot;
|
|
|
|
|
using System;
|
2023-10-11 02:47:31 -07:00
|
|
|
using System.Linq;
|
|
|
|
|
using WacK;
|
2023-10-10 23:50:24 -07:00
|
|
|
|
2023-10-11 02:57:24 -07:00
|
|
|
namespace WacK.Things.TunnelObjects
|
2023-10-10 23:50:24 -07:00
|
|
|
{
|
2023-10-11 02:57:24 -07:00
|
|
|
public partial class SnapArrows : HBoxContainer
|
2023-10-10 23:50:24 -07:00
|
|
|
{
|
2023-10-11 02:57:24 -07:00
|
|
|
private TextureRect[] arrows = new TextureRect[20];
|
2023-10-10 23:50:24 -07:00
|
|
|
|
2023-10-11 02:57:24 -07:00
|
|
|
// Called when the node enters the scene tree for the first time.
|
|
|
|
|
public override void _Ready()
|
2023-10-11 02:47:31 -07:00
|
|
|
{
|
2023-10-11 02:57:24 -07:00
|
|
|
var c = GetChildren();
|
|
|
|
|
for(int i = 0; i < 20; ++i)
|
2023-10-11 02:47:31 -07:00
|
|
|
{
|
2023-10-11 02:57:24 -07:00
|
|
|
arrows[i] = (TextureRect) c[i];
|
2023-10-11 02:47:31 -07:00
|
|
|
}
|
2023-10-11 02:57:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Make sure to run as CallDeferred if constructing!
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="pos"></param>
|
|
|
|
|
/// <param name="size"></param>
|
|
|
|
|
/// <param name="isIn"></param>
|
|
|
|
|
public void Init(int pos, int size, bool isIn)
|
|
|
|
|
{
|
|
|
|
|
var nVis = Math.Clamp(size / 3, 1, 20);
|
|
|
|
|
|
|
|
|
|
for(int i = 0; i < arrows.Count(); ++i)
|
2023-10-11 02:47:31 -07:00
|
|
|
{
|
2023-10-11 02:57:24 -07:00
|
|
|
if (i < nVis)
|
|
|
|
|
{
|
|
|
|
|
arrows[i].Visible = true;
|
|
|
|
|
((ShaderMaterial)arrows[i].Material)
|
|
|
|
|
.SetShaderParameter("isIn", isIn);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
arrows[i].Visible = false;
|
|
|
|
|
}
|
2023-10-11 02:47:31 -07:00
|
|
|
}
|
|
|
|
|
|
2023-10-11 02:57:24 -07:00
|
|
|
// shrink
|
|
|
|
|
var s = Size;
|
|
|
|
|
s.X = 0;
|
|
|
|
|
Size = s;
|
2023-10-11 02:47:31 -07:00
|
|
|
|
2023-10-11 02:57:24 -07:00
|
|
|
var (posPx, sizePx) = Util.PixelizeNote(pos, size);
|
|
|
|
|
var noteCtrPos = posPx + sizePx / 2;
|
2023-10-11 02:47:31 -07:00
|
|
|
|
2023-10-11 02:57:24 -07:00
|
|
|
// reposition
|
|
|
|
|
var p = Position;
|
|
|
|
|
p.X = -Size.X / 2 + noteCtrPos;
|
|
|
|
|
Position = p;
|
|
|
|
|
}
|
2023-10-10 23:50:24 -07:00
|
|
|
}
|
|
|
|
|
}
|