Skip to content

Commit

Permalink
Move area showcase changes
Browse files Browse the repository at this point in the history
1. Changed showcase to have a checkbox of whether to bind character and
area together or not.
2. Fix label out of sync when reselecting the showcase.

Fixes #167
  • Loading branch information
tzachshabtay committed Dec 27, 2017
1 parent 86963a3 commit 32abe7b
Showing 1 changed file with 95 additions and 37 deletions.
132 changes: 95 additions & 37 deletions Source/Demo/DemoQuest/GUI/FeaturesWindow/FeaturesMoveAreaPanel.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using AGS.API;
using AGS.Engine;
Expand All @@ -12,10 +13,14 @@ public class FeaturesMoveAreaPanel : IFeaturesPanel
private readonly RotatingCursorScheme _scheme;

private ILabel _label;
private bool _shouldAnimate;
private ICheckBox _checkbox;
private bool _shouldAnimate, _shouldBindAreaToCharacter;
private int _rotationStage;
private PlayerAsFeature _playerAsFeature;

private Tween _currentTween;
private bool _stopped;

public FeaturesMoveAreaPanel(IGame game, IObject parent, RotatingCursorScheme scheme)
{
_game = game;
Expand All @@ -30,8 +35,12 @@ public void Show()
_playerAsFeature = new PlayerAsFeature(player);

var factory = _game.Factory;
_label = factory.UI.GetLabel("MoveAreaLabel", "Try Walking!", 100f, 30f, 0f, _parent.Height - 30f, _parent);
_label.RenderLayer = _parent.RenderLayer;
_label = factory.UI.GetLabel("MoveAreaLabel", "Try Walking!", 100f, 30f, 10f, _parent.Height - 30f, _parent);

_checkbox = factory.UI.GetCheckBox("MoveAreaCheckbox", (ButtonAnimation)null, null, null, null, 10f, _parent.Height - 60f, _parent, "Bind Area & Character", width: 20f, height: 20f);
_checkbox.Checked = true;
_shouldBindAreaToCharacter = true;
_checkbox.OnCheckChanged.Subscribe(onBindChanged);

var parent = factory.Object.GetObject("Elevator Parent");
parent.TreeNode.SetParent(_parent.TreeNode);
Expand Down Expand Up @@ -64,58 +73,107 @@ public void Show()

public async Task Close()
{
_shouldAnimate = false;
_shouldAnimate = false;
stop();
var label = _label;
if (label != null)
{
_game.State.UI.Remove(label);
label.Dispose();
}

var checkbox = _checkbox;
if (checkbox != null)
{
label = checkbox.TextLabel;
if (label != null)
{
_game.State.UI.Remove(label);
label.Dispose();
}
_game.State.UI.Remove(checkbox);
checkbox.Dispose();
}

var playerAsFeature = _playerAsFeature;
if (playerAsFeature != null) await playerAsFeature.Restore();

_scheme.CurrentMode = MouseCursors.POINT_MODE;
}

private void onBindChanged(CheckBoxEventArgs args)
{
_shouldBindAreaToCharacter = args.Checked;
stop();
}

private void stop()
{
_stopped = true;
_game.State.Player.StopWalkingAsync();
_currentTween?.Stop(TweenCompletion.Stay);
}

private async void animate(IObject parent, ITranslateComponent areaTranslate, IRotateComponent areaRotate)
{
if (!_shouldAnimate) return;

_label.Text = "Try Walking! (Moving character and area together)";
await parent.TweenY(200f, 2f).Task;
await parent.TweenX(300f, 2f).Task;
await parent.TweenY(100f, 2f).Task;
await parent.TweenX(200f, 2f).Task;

_label.Text = "Try Walking! (Moving area only)";
await areaTranslate.TweenY(100f, 2f).Task;
await areaTranslate.TweenX(100f, 2f).Task;
await areaTranslate.TweenY(0f, 2f).Task;
await areaTranslate.TweenX(0f, 2f).Task;

switch (_rotationStage)
if (!_shouldAnimate) return;

if (_stopped)
{
parent.X = 200f;
parent.Y = 100f;
parent.Angle = 0f;
areaTranslate.X = 0f;
areaTranslate.Y = 0f;
areaRotate.Angle = 0f;
_rotationStage = 0;
_game.State.Player.X = 50f;
_game.State.Player.Y = 30f;
_stopped = false;
}

if (_shouldBindAreaToCharacter)
{
case 0:
_label.Text = "Try Walking! (Rotating character and area together)";
await parent.TweenAngle(45f, 2f).Task;
break;
case 1:
_label.Text = "Try Walking! (Rotating character and area together)";
await parent.TweenAngle(0f, 2f).Task;
break;
case 2:
_label.Text = "Try Walking! (Rotating area only)";
await areaRotate.TweenAngle(45f, 2f).Task;
break;
case 3:
_label.Text = "Try Walking! (Rotating area only)";
await areaRotate.TweenAngle(0f, 2f).Task;
break;
_label.Text = "Try Walking! (Moving character and area together)";
if (await tween(() => parent.TweenY(200f, 2f)))
if (await tween(() => parent.TweenX(300f, 2f)))
if (await tween(() => parent.TweenY(100f, 2f)))
await tween(() => parent.TweenX(200f, 2f));
}
else
{
_label.Text = "Try Walking! (Moving area only)";
if (await tween(() => areaTranslate.TweenY(100f, 2f)))
if (await tween(() => areaTranslate.TweenX(100f, 2f)))
if (await tween(() => areaTranslate.TweenY(0f, 2f)))
await tween(() => areaTranslate.TweenX(0f, 2f));
}

if (!_stopped)
{
var toRotate = _shouldBindAreaToCharacter ? parent : areaRotate;
_label.Text = _shouldBindAreaToCharacter ? "Try Walking! (Rotating character and area together)" : "Try Walking! (Rotating area only)";
switch (_rotationStage)
{
case 0:
await tween(() => toRotate.TweenAngle(45f, 2f));
break;
case 1:
await tween(() => toRotate.TweenAngle(0f, 2f));
break;
}
_rotationStage = (_rotationStage + 1) % 2;
}
_rotationStage = (_rotationStage + 1) % 4;

animate(parent, areaTranslate, areaRotate);
}

private async Task<bool> tween(Func<Tween> getTween)
{
if (_stopped) return false;
_currentTween = getTween();
await _currentTween.Task;
return !_stopped;
}
}
}

0 comments on commit 32abe7b

Please sign in to comment.