Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

An animation system for NUI #2306

Merged
merged 35 commits into from
May 13, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
cac4b91
Planning animation system
viveret Apr 3, 2016
435c3c0
Fixed checkstyle and build errors
viveret Apr 3, 2016
456416a
Expanded interfaces and classes, added interpolators
viveret Apr 3, 2016
2c5cb96
Trying to hook animations into the engine
viveret Apr 3, 2016
ee2ebb2
Working on animation JSON format and system
viveret Apr 4, 2016
90970bb
Fixed compile errors
viveret Apr 4, 2016
66dee80
For the most part finished, need to find a way to test
viveret Apr 5, 2016
ab72558
Switching to desktop
viveret Apr 6, 2016
e182fbf
Animations finally working, layout screens have opening animation
viveret Apr 6, 2016
9b0036b
Default open / close animations part of UIScreenLayer, NUIManager now…
viveret Apr 6, 2016
1bc18db
fixed setRepeat to use repeat mode and positive count, fixed accelera…
viveret Apr 7, 2016
2786810
Cleaned up and documented
viveret Apr 8, 2016
c55ed40
Refactor UI animation system
msteiger Apr 18, 2016
38806c0
Rough sketch of the NUI animation system for menus
msteiger Apr 18, 2016
c19367d
Experimental animation of title image
msteiger Apr 23, 2016
682103d
Support animation groups
msteiger Apr 23, 2016
1a769fd
Reconfigure animation system to MainMenu
msteiger Apr 23, 2016
43fb950
First draft for screen swipe animations
msteiger May 1, 2016
0092c36
Implement reverse animations
msteiger May 1, 2016
616e61a
Complete demonstration animations
msteiger May 1, 2016
bec5c6a
Configure swipe animations for main menu screens
msteiger Apr 30, 2016
503c0e4
Apply swipe animations to main menu screens only
msteiger Apr 30, 2016
7deddd3
Make ESC to close check internal to CoreScreenLayer
msteiger Apr 30, 2016
298f41b
Add animation to ConsoleScreen
msteiger Apr 30, 2016
6f8e227
Separate 'create' and 'open' screen
msteiger May 1, 2016
4df7a2a
Stop NUI animations on ESC
msteiger May 1, 2016
4ed5e9f
Add Javadoc for TimeModifiers
msteiger May 1, 2016
fd31ac6
Add compatibility mode for NUI overlays
msteiger May 2, 2016
bd12125
Add configurable menu animations
msteiger May 2, 2016
39ae57d
Skip intro animation for main menu
msteiger May 5, 2016
fbd8420
Initialise overlays properly
msteiger May 7, 2016
c0bc543
Deprecate UIElement-based methods in NUIManager
msteiger May 7, 2016
84b866a
Merge branch 'develop' of github.com:MovingBlocks/Terasology into ui_…
msteiger May 8, 2016
88e6c83
Use isLoaded check in NUIManagerInternal
msteiger May 8, 2016
ff340ab
Use existing methods to dispose obsolete NUI elements
msteiger May 11, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright 2016 MovingBlocks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.terasology.rendering.animation;

import org.junit.Assert;
import org.junit.Test;
import org.mockito.Mockito;

/**
* Tests the {@link Animation} class
*/
public class AnimationTest {

private static final float EPS = 0.001f;

private Container c = new Container();

@Test
public void startEndOnce() {
Animation ani = once();
AnimationListener listener = Mockito.mock(AnimationListener.class);
ani.addListener(listener);
ani.start();
ani.update(2.5f);
Mockito.verify(listener, Mockito.times(1)).onStart();
Mockito.verify(listener, Mockito.times(1)).onEnd();
}

@Test
public void startEndValuesOnce() {
Animation ani = once().start();
Assert.assertEquals(0.0f, c.value, 0.0f);
ani.update(2.5f);
Assert.assertEquals(1.0f, c.value, 0.0f);
}

@Test
public void startEndValuesInfinite() {
Animation ani = infinite().start();
Assert.assertEquals(0.0f, c.value, 0.0f);
ani.update(2.5f);
Assert.assertEquals(.25f, c.value, EPS); // (2.5 % 2) / 2
}

@Test
public void overflowInfinite() {
Animation ani = infinite().start();
Assert.assertEquals(0.0f, c.value, 0.0f);
ani.update(112.5f);
Assert.assertEquals(.25f, c.value, EPS); // (112.5 % 2) / 2
}

@Test
public void updates() {
Animation ani = once();
ani.update(2.5f); // ignored
Assert.assertEquals(0f, c.value, 0f);
ani.start();
ani.update(0.5f);
Assert.assertEquals(0.25f, c.value, EPS); // 0.5 / 2
ani.pause();
ani.update(0.5f); // ignored
Assert.assertEquals(0.25f, c.value, EPS); // same
ani.resume();
ani.update(1.0f);
Assert.assertEquals(0.75f, c.value, EPS); // 1.5 / 2
ani.update(1.0f);
Assert.assertEquals(1.00f, c.value, 0f); // 2.5 / 2 -> capped
ani.update(1.0f); // ignored
Assert.assertEquals(1.00f, c.value, 0f); // same
}

@Test
public void startEndOnceReverse() {
Animation ani = once().setReverseMode();
AnimationListener listener = Mockito.mock(AnimationListener.class);
ani.addListener(listener);
ani.start();
ani.update(2.5f);
Mockito.verify(listener, Mockito.times(1)).onStart();
Mockito.verify(listener, Mockito.times(1)).onEnd();
}

@Test
public void updatesReverse() {
Animation ani = once().setReverseMode();
ani.update(2.5f); // ignored
Assert.assertEquals(0f, c.value, 0f);
ani.start();
ani.update(0.5f);
Assert.assertEquals(0.75f, c.value, EPS); // 1 - 0.5 / 2
ani.pause();
ani.update(0.5f); // ignored
Assert.assertEquals(0.75f, c.value, EPS); // same
ani.resume();
ani.update(1.0f);
Assert.assertEquals(0.25f, c.value, EPS); // 1 - 1.5 / 2
ani.update(1.0f);
Assert.assertEquals(0.00f, c.value, 0f); // 1 - 2.5 / 2 -> capped
ani.update(1.0f); // ignored
Assert.assertEquals(0.00f, c.value, 0f); // same
}

private Animation once() {
return Animation.once(v -> c.value = v, 2f, TimeModifiers.linear());
}

private Animation infinite() {
return Animation.infinite(v -> c.value = v, 2f, TimeModifiers.linear());
}

private static class Container {
float value;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class RenderingConfig {
private int windowWidth;
private int windowHeight;
private boolean fullscreen;
private boolean animatedMenu;
private ViewDistance viewDistance;
private boolean flickeringLight;
private boolean animateGrass;
Expand Down Expand Up @@ -138,6 +139,14 @@ public void setFullscreen(boolean fullscreen) {
this.fullscreen = fullscreen;
}

public boolean isAnimatedMenu() {
return animatedMenu;
}

public void setAnimatedMenu(boolean animatedMenu) {
this.animatedMenu = animatedMenu;
}

public ViewDistance getViewDistance() {
return viewDistance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import org.terasology.logic.console.suggesters.ScreenSuggester;
import org.terasology.utilities.Assets;
import org.terasology.assets.ResourceUrn;
import org.terasology.assets.management.AssetManager;
import org.terasology.config.Config;
import org.terasology.engine.GameEngine;
Expand Down Expand Up @@ -74,6 +75,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import java.util.concurrent.Callable;
import java.util.stream.Collectors;
import java.util.stream.StreamSupport;
Expand Down Expand Up @@ -213,19 +215,20 @@ public String showScreen(@CommandParam(value="uri", suggester = ScreenSuggester.

@Command(shortDescription = "Reloads a ui screen")
public String reloadScreen(@CommandParam("ui") String ui) {
Optional<UIElement> uiData = assetManager.getAsset(ui, UIElement.class);
if (uiData.isPresent()) {
boolean wasOpen = nuiManager.isOpen(uiData.get().getUrn());
Set<ResourceUrn> urns = assetManager.resolve(ui, UIElement.class);
if (urns.size() == 1) {
ResourceUrn urn = urns.iterator().next();
boolean wasOpen = nuiManager.isOpen(urn);
if (wasOpen) {
nuiManager.closeScreen(uiData.get().getUrn());
nuiManager.closeScreen(urn);
}

if (wasOpen) {
nuiManager.pushScreen(uiData.get());
nuiManager.pushScreen(urn);
}
return "Success";
} else {
return "Unable to resolve ui '" + ui + "'";
return "No unique resource found";
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@
import org.terasology.rendering.nui.BaseInteractionListener;
import org.terasology.rendering.nui.CoreScreenLayer;
import org.terasology.rendering.nui.InteractionListener;
import org.terasology.rendering.nui.animation.MenuAnimationSystems;
import org.terasology.rendering.nui.animation.SwipeMenuAnimationSystem;
import org.terasology.rendering.nui.animation.SwipeMenuAnimationSystem.Direction;
import org.terasology.rendering.nui.databinding.ReadOnlyBinding;
import org.terasology.rendering.nui.events.NUIMouseClickEvent;
import org.terasology.rendering.nui.layouts.ScrollableArea;
Expand Down Expand Up @@ -57,6 +60,9 @@ public boolean onMouseClick(NUIMouseClickEvent event) {

@Override
public void initialise() {

setAnimationSystem(new SwipeMenuAnimationSystem(0.2f, Direction.TOP_TO_BOTTOM));

final ScrollableArea scrollArea = find("scrollArea", ScrollableArea.class);
scrollArea.moveToBottom();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ public boolean canBeFocus() {
}

@Override
public boolean isEscapeToCloseAllowed() {
protected boolean isEscapeToCloseAllowed() {
return false;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class DebugProperties extends CoreHudWidget {
private PropertyLayout propertyLayout;

@Override
protected void initialise() {
public void initialise() {
container = find("container", ColumnLayout.class);
propertyLayout = find("properties", PropertyLayout.class);
}
Expand Down
Loading