StarSkyPresenter/Controller.cs

69 lines
2.1 KiB
C#

using Godot;
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");
}
// Called every frame. 'delta' is the elapsed time since the previous frame.
public override void _Process(double delta)
{
Vector2 border = new Vector2(15, 15);
Vector2 rasterSize = this.Size / 4;
Vector2 btnSize = rasterSize - 2 * border;
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;
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;
}
}