Skip to content

Commit

Permalink
Merge pull request #154 from MASSHUU12/more-options-for-yat-window
Browse files Browse the repository at this point in the history
More options for yat window
  • Loading branch information
MASSHUU12 authored Jan 15, 2024
2 parents 1a92394 + 44d1094 commit e9a1e3f
Show file tree
Hide file tree
Showing 9 changed files with 77 additions and 12 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file.

## [Unreleased]

### Added

- Ability for YatWindows to set default window position.
- Reset command.
- PositionResetRequested & SizeResetRequested signal for BaseTerminal.

## [1.17.0-beta 2024-01-12]

### Added
Expand Down
1 change: 1 addition & 0 deletions addons/yat/docs/BUILTIN_COMMANDS.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,4 @@
| stats | st | Manages the game monitor. |
| cs | N/A | Changes the scene. |
| wenv | N/A | Manages the world environment. |
| reset | N/A | Resets the terminal to its default position and/or size. |
10 changes: 6 additions & 4 deletions addons/yat/docs/TERMINAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ $ qc add -name="Red Hello" -command="echo [color=red]Hello[/color]"

### Signals

| Name | Arguments | Description |
| -------------------- | -------------- | -------------------------------------------------- |
| CloseRequested | N/A | Sent when terminal is requested to close. |
| TitleChangeRequested | title (string) | Sent when change to terminal's title is requested. |
| Name | Arguments | Description |
| ---------------------- | -------------- | -------------------------------------------------- |
| CloseRequested | N/A | Sent when terminal is requested to close. |
| TitleChangeRequested | title (string) | Sent when change to terminal's title is requested. |
| PositionResetRequested | N/A | Sent when terminal position reset is requested. |
| SizeResetRequested | N/A | Sent when terminal size reset is requested. |
1 change: 1 addition & 0 deletions addons/yat/src/YAT.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ public override void _Ready()
AddCommand(new Pause());
AddCommand(new Watch());
AddCommand(new Stats());
AddCommand(new Reset());
AddCommand(new Cowsay());
AddCommand(new Options());
AddCommand(new Restart());
Expand Down
36 changes: 36 additions & 0 deletions addons/yat/src/commands/builtin/Reset.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
using YAT.Attributes;
using YAT.Enums;
using YAT.Interfaces;

namespace YAT.Commands
{
[Command(
"reset",
"Resets the terminal to its default position and/or size.",
"[b]reset[/b] [i]action[/i]"
)]
[Argument("action", "[all, position, size]", "The action to perform.")]
public sealed class Reset : ICommand
{
public CommandResult Execute(CommandArguments args)
{
var action = (string)args.ConvertedArgs["action"];

switch (action)
{
case "size":
args.Terminal.EmitSignal(nameof(args.Terminal.SizeResetRequested));
break;
case "position":
args.Terminal.EmitSignal(nameof(args.Terminal.PositionResetRequested));
break;
case "all":
args.Terminal.EmitSignal(nameof(args.Terminal.SizeResetRequested));
args.Terminal.EmitSignal(nameof(args.Terminal.PositionResetRequested));
break;
}

return CommandResult.Success;
}
}
}
2 changes: 2 additions & 0 deletions addons/yat/src/scenes/base_terminal/BaseTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public partial class BaseTerminal : Control
{
[Signal] public delegate void CloseRequestedEventHandler();
[Signal] public delegate void TitleChangeRequestedEventHandler(string title);
[Signal] public delegate void PositionResetRequestedEventHandler();
[Signal] public delegate void SizeResetRequestedEventHandler();

public Input Input { get; private set; }
public TerminalContext Context { get; private set; }
Expand Down
2 changes: 2 additions & 0 deletions addons/yat/src/scenes/game_terminal/GameTerminal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public override void _Ready()

BaseTerminal = GetNode<BaseTerminal.BaseTerminal>("Content/BaseTerminal");
BaseTerminal.TitleChangeRequested += title => Title = title;
BaseTerminal.PositionResetRequested += ResetPosition;
BaseTerminal.SizeResetRequested += () => Size = InitialSize;
CloseRequested += _yat.CloseTerminal;

MoveToCenter();
Expand Down
2 changes: 1 addition & 1 deletion addons/yat/src/scenes/monitor/Monitor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public override void _Ready()
_timer = GetNode<Timer>("Timer");
_components = GetNode<VBoxContainer>("%Components");

Move(WindowPosition.TopLeft, 16);
Move(EWindowPosition.TopLeft, 16);
}

/// <summary>
Expand Down
27 changes: 20 additions & 7 deletions addons/yat/src/scenes/yat_window/YatWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,15 @@ public partial class YatWindow : Window
[Export(PropertyHint.Range, "0, 128, 1")]
public int ViewportEdgeOffset = 48;

[Export] public EWindowPosition DefaultWindowPosition = EWindowPosition.Center;
[Export] public bool AllowToGoOffscreen = true; // TODO: Implement this

public Vector2I InitialSize { get; set; }

private YAT _yat;
private Viewport _viewport;

public enum WindowPosition
public enum EWindowPosition
{
TopLeft,
TopRight,
Expand All @@ -25,9 +30,17 @@ public override void _Ready()
_viewport = _yat.GetTree().Root.GetViewport();
_viewport.SizeChanged += OnViewportSizeChanged;

InitialSize = Size;

Move(DefaultWindowPosition, (uint)ViewportEdgeOffset);
OnViewportSizeChanged();
}

public void ResetPosition()
{
Move(DefaultWindowPosition, (uint)ViewportEdgeOffset);
}

private void OnViewportSizeChanged()
{
var viewportSize = (Vector2I)_viewport.GetVisibleRect().Size;
Expand All @@ -39,23 +52,23 @@ private void OnViewportSizeChanged()
};
}

public void Move(WindowPosition position, uint offset = 0)
public void Move(EWindowPosition position, uint offset = 0)
{
switch (position)
{
case WindowPosition.TopLeft:
case EWindowPosition.TopLeft:
MoveTopLeft(offset);
break;
case WindowPosition.TopRight:
case EWindowPosition.TopRight:
MoveTopRight(offset);
break;
case WindowPosition.BottomRight:
case EWindowPosition.BottomRight:
MoveBottomRight(offset);
break;
case WindowPosition.BottomLeft:
case EWindowPosition.BottomLeft:
MoveBottomLeft(offset);
break;
case WindowPosition.Center:
case EWindowPosition.Center:
MoveToTheCenter();
break;
}
Expand Down

0 comments on commit e9a1e3f

Please sign in to comment.