exclusivity manager, not applied to selectionui
parent
afa487e78d
commit
ed9b183c53
|
|
@ -0,0 +1,33 @@
|
||||||
|
package xyz.valnet.hadean.gameobjects.ui;
|
||||||
|
|
||||||
|
import xyz.valnet.engine.scenegraph.GameObject;
|
||||||
|
import xyz.valnet.hadean.gameobjects.ui.tabs.Tab;
|
||||||
|
import xyz.valnet.hadean.util.Assets;
|
||||||
|
|
||||||
|
public class ExclusivityManager extends GameObject {
|
||||||
|
private Tab current = null;
|
||||||
|
|
||||||
|
private boolean switching = false;
|
||||||
|
|
||||||
|
public void switchTo(Tab tab) {
|
||||||
|
if(tab == current) return;
|
||||||
|
if(tab == null) {
|
||||||
|
closeCurrent();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Assets.sndBubble.play();
|
||||||
|
switching = true;
|
||||||
|
if(current != null) current.close();
|
||||||
|
current = tab;
|
||||||
|
current.open();
|
||||||
|
switching = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void closeCurrent() {
|
||||||
|
if(switching) return;
|
||||||
|
Assets.sndCancel.play();
|
||||||
|
current.close();
|
||||||
|
current = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -1,11 +1,12 @@
|
||||||
package xyz.valnet.hadean.gameobjects.ui.tabs;
|
package xyz.valnet.hadean.gameobjects.ui.tabs;
|
||||||
|
|
||||||
|
import static xyz.valnet.engine.util.Math.*;
|
||||||
|
|
||||||
import xyz.valnet.engine.graphics.ImmediateUI;
|
import xyz.valnet.engine.graphics.ImmediateUI;
|
||||||
import xyz.valnet.engine.scenegraph.ITransient;
|
import xyz.valnet.engine.scenegraph.ITransient;
|
||||||
import static xyz.valnet.engine.util.Math.lerp;
|
|
||||||
import xyz.valnet.hadean.gameobjects.BottomBar;
|
import xyz.valnet.hadean.gameobjects.BottomBar;
|
||||||
|
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
|
||||||
import xyz.valnet.hadean.interfaces.IBottomBarItem;
|
import xyz.valnet.hadean.interfaces.IBottomBarItem;
|
||||||
import xyz.valnet.hadean.util.Assets;
|
|
||||||
import xyz.valnet.hadean.util.Layers;
|
import xyz.valnet.hadean.util.Layers;
|
||||||
|
|
||||||
public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransient {
|
public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransient {
|
||||||
|
|
@ -15,6 +16,8 @@ public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransi
|
||||||
protected boolean opened = false;
|
protected boolean opened = false;
|
||||||
private float animation = 0f;
|
private float animation = 0f;
|
||||||
|
|
||||||
|
private ExclusivityManager exclusivityManager;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void update(float dTime) {
|
public void update(float dTime) {
|
||||||
animation = lerp(animation, opened ? 1 : 0, dTime / 20);
|
animation = lerp(animation, opened ? 1 : 0, dTime / 20);
|
||||||
|
|
@ -23,6 +26,7 @@ public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransi
|
||||||
@Override
|
@Override
|
||||||
protected void connect() {
|
protected void connect() {
|
||||||
bottombar = get(BottomBar.class);
|
bottombar = get(BottomBar.class);
|
||||||
|
exclusivityManager = get(ExclusivityManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -56,15 +60,15 @@ public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransi
|
||||||
|
|
||||||
public final void open() {
|
public final void open() {
|
||||||
if(opened) return;
|
if(opened) return;
|
||||||
Assets.sndBubble.play();
|
|
||||||
opened = true;
|
opened = true;
|
||||||
|
exclusivityManager.switchTo(this);
|
||||||
onOpen();
|
onOpen();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void close() {
|
public final void close() {
|
||||||
if(!opened) return;
|
if(!opened) return;
|
||||||
Assets.sndCancel.play();
|
|
||||||
opened = false;
|
opened = false;
|
||||||
|
exclusivityManager.closeCurrent();
|
||||||
onClose();
|
onClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@ import xyz.valnet.hadean.gameobjects.SelectionUI;
|
||||||
import xyz.valnet.hadean.gameobjects.Terrain;
|
import xyz.valnet.hadean.gameobjects.Terrain;
|
||||||
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
|
||||||
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
import xyz.valnet.hadean.gameobjects.inputlayer.SelectionLayer;
|
||||||
|
import xyz.valnet.hadean.gameobjects.ui.ExclusivityManager;
|
||||||
import xyz.valnet.hadean.gameobjects.ui.HoverQuery;
|
import xyz.valnet.hadean.gameobjects.ui.HoverQuery;
|
||||||
import xyz.valnet.hadean.gameobjects.ui.Popup;
|
import xyz.valnet.hadean.gameobjects.ui.Popup;
|
||||||
import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
|
import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
|
||||||
|
|
@ -53,6 +54,7 @@ public class GameScene extends SceneGraph {
|
||||||
objects.add(new HoverQuery());
|
objects.add(new HoverQuery());
|
||||||
|
|
||||||
objects.add(new BottomBar());
|
objects.add(new BottomBar());
|
||||||
|
objects.add(new ExclusivityManager());
|
||||||
objects.add(new BuildTab());
|
objects.add(new BuildTab());
|
||||||
// objects.add(new JobBoardTab());
|
// objects.add(new JobBoardTab());
|
||||||
objects.add(new DebugTab());
|
objects.add(new DebugTab());
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue