mirror of
https://gitlab.com/MaddoScientisto/cirnogodot.git
synced 2026-06-01 10:35:34 +00:00
Mouse cursor resizing
This commit is contained in:
parent
543f5f0d6b
commit
1d3349f7e0
9 changed files with 80 additions and 3 deletions
|
|
@ -1,3 +1,4 @@
|
|||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using Cirno.Scripts.Resources;
|
||||
using Cirno.Scripts.Utils;
|
||||
|
|
@ -20,6 +21,12 @@ public partial class GlobalState : Node
|
|||
|
||||
private Control _loadingPlaque;
|
||||
|
||||
private readonly StringName _menuMouseTexturePath = "uid://d3oxwik1uoe4j";
|
||||
private readonly StringName _reticuleMouseTexturePath = "uid://8nns6w0skiy3";
|
||||
|
||||
private Texture2D _menuMouseTexture;
|
||||
private Image _menuMouseImage;
|
||||
|
||||
public override void _Ready()
|
||||
{
|
||||
Instance = this;
|
||||
|
|
@ -32,9 +39,28 @@ public partial class GlobalState : Node
|
|||
|
||||
_fader = CreateFader();
|
||||
|
||||
_menuMouseTexture =ResourceLoader.Load<Texture2D>(_menuMouseTexturePath);
|
||||
_menuMouseImage = _menuMouseTexture.GetImage();
|
||||
|
||||
GetTree().GetRoot().SizeChanged += OnSizeChanged;
|
||||
//_mouseTexture =
|
||||
OnSizeChanged();
|
||||
//LoadPlaque();
|
||||
}
|
||||
|
||||
private void OnSizeChanged()
|
||||
{
|
||||
var root = GetTree().GetRoot();
|
||||
var baseSize = root.ContentScaleSize;
|
||||
var newSize = root.Size;
|
||||
|
||||
int scaleX = newSize.X / baseSize.X;
|
||||
int scaleY = newSize.Y / baseSize.Y;
|
||||
int scale = Math.Min(scaleX, scaleY); // Ensure pixel-perfect scaling
|
||||
|
||||
ResizeCursor(scale / 2);
|
||||
}
|
||||
|
||||
public void GotoScene(string path)
|
||||
{
|
||||
// This function will usually be called from a signal callback,
|
||||
|
|
@ -176,9 +202,21 @@ public partial class GlobalState : Node
|
|||
|
||||
saveFile.StoreLine(jsonString);
|
||||
}
|
||||
|
||||
|
||||
public void LoadGame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void ResizeCursor(float scale)
|
||||
{
|
||||
var scaled = (Image)_menuMouseImage.Duplicate();
|
||||
|
||||
var size = (Vector2I)(scale * _menuMouseTexture.GetSize());
|
||||
|
||||
scaled.Resize(size.X, size.Y, Image.Interpolation.Nearest);
|
||||
|
||||
DisplayServer.CursorSetCustomImage(scaled);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue