simple button behaviour

This commit is contained in:
Linus Vogel 2025-12-08 22:47:00 +01:00
parent f59723e43f
commit 4f6832b658
5 changed files with 57 additions and 24 deletions

View File

@ -3,10 +3,27 @@ using System;
public partial class Controller : Window
{
private double _closeTime = 0;
private bool _screenReady = true;
private Button _btnScene1;
private Button _btnScene2;
private Button _btnScene3;
private Button _btnScene4;
private Button _btnScreen;
private Button _btnClose;
// Called when the node enters the scene tree for the first time.
public override void _Ready()
{
this._btnScene1 = this.GetNode<Button>("BtnScene1");
this._btnScene2 = this.GetNode<Button>("BtnScene2");
this._btnScene3 = this.GetNode<Button>("BtnScene3");
this._btnScene4 = this.GetNode<Button>("BtnScene4");
this._btnScreen = this.GetNode<Button>("BtnScreen");
this._btnClose = this.GetNode<Button>("BtnClose");
}
@ -17,27 +34,35 @@ public partial class Controller : Window
Vector2 rasterSize = this.Size / 4;
Vector2 btnSize = rasterSize - 2 * border;
Button btnScene1 = this.GetNode<Button>("BtnScene1");
Button btnScene2 = this.GetNode<Button>("BtnScene2");
Button btnScene3 = this.GetNode<Button>("BtnScene3");
Button btnScene4 = this.GetNode<Button>("BtnScene4");
this._btnScene1.Position = border + (new Vector2(0, 0)*rasterSize);
this._btnScene2.Position = border + (new Vector2(1, 0)*rasterSize);
this._btnScene3.Position = border + (new Vector2(2, 0)*rasterSize);
this._btnScene4.Position = border + (new Vector2(3, 0)*rasterSize);
this._btnScene1.Size = btnSize;
this._btnScene2.Size = btnSize;
this._btnScene3.Size = btnSize;
this._btnScene4.Size = btnSize;
this._btnScreen.Size = btnSize;
this._btnScreen.Position = border + (new Vector2(3, 3)*rasterSize);
this._btnClose.Size = btnSize * new Vector2(3, 1) + border * new Vector2(4, 0);
this._btnClose.Position = border + (new Vector2(0, 3)*rasterSize);
// handle close button
if (this._btnClose.IsPressed())
this._closeTime += delta;
else
this._closeTime = 0;
Button btnScreen = this.GetNode<Button>("BtnScreen");
Button btnClose = this.GetNode<Button>("BtnClose");
btnScene1.Position = border + (new Vector2(0, 0)*rasterSize);
btnScene2.Position = border + (new Vector2(1, 0)*rasterSize);
btnScene3.Position = border + (new Vector2(2, 0)*rasterSize);
btnScene4.Position = border + (new Vector2(3, 0)*rasterSize);
btnScene1.Size = btnSize;
btnScene2.Size = btnSize;
btnScene3.Size = btnSize;
btnScene4.Size = btnSize;
btnScreen.Size = btnSize;
btnScreen.Position = border + (new Vector2(3, 3)*rasterSize);
btnClose.Size = btnSize * new Vector2(3, 1) + border * new Vector2(4, 0);
btnClose.Position = border + (new Vector2(0, 3)*rasterSize);
this._btnClose.AddThemeColorOverride("font_pressed_color", new Color((float)this._closeTime, 0, 0));
if (this._closeTime > 1) this.GetTree().Quit();
if (this._btnScreen.IsPressed() && this._screenReady)
{
this.GetTree().GetRoot().GetNode<MainScript>("Main").SetFullScreen();
this._screenReady = false;
}
else this._screenReady = true;
}
}

View File

@ -1,7 +1,7 @@
using Godot;
using System;
public partial class Main : Node2D
public partial class MainScript : Node2D
{
// Called when the node enters the scene tree for the first time.
@ -13,4 +13,12 @@ public partial class Main : Node2D
public override void _Process(double delta)
{
}
public void SetFullScreen()
{
Window window = this.GetTree().GetRoot().GetNode<Window>("Main.Projection");
window.SetCurrentScreen(1);
window.Borderless = true;
}
}

View File

@ -11,6 +11,6 @@ public partial class Projection : Window
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
GD.Print("Projection process");
}
}

View File

@ -4,7 +4,7 @@
[ext_resource type="Script" uid="uid://dg0qtnm4epowu" path="res://Controller.cs" id="1_wtcfe"]
[ext_resource type="Script" uid="uid://criv4i3x63akl" path="res://Projection.cs" id="2_0e48y"]
[node name="Node2D" type="Node2D"]
[node name="Main" type="Node2D"]
script = ExtResource("1_0e48y")
[node name="Controller" type="Window" parent="."]