exclusivity manager, not applied to selectionui

bottom-bar
Ivory 2023-01-28 03:06:31 -05:00
parent afa487e78d
commit ed9b183c53
3 changed files with 43 additions and 4 deletions

View File

@ -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;
}
}

View File

@ -1,11 +1,12 @@
package xyz.valnet.hadean.gameobjects.ui.tabs;
import static xyz.valnet.engine.util.Math.*;
import xyz.valnet.engine.graphics.ImmediateUI;
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.ui.ExclusivityManager;
import xyz.valnet.hadean.interfaces.IBottomBarItem;
import xyz.valnet.hadean.util.Assets;
import xyz.valnet.hadean.util.Layers;
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;
private float animation = 0f;
private ExclusivityManager exclusivityManager;
@Override
public void update(float dTime) {
animation = lerp(animation, opened ? 1 : 0, dTime / 20);
@ -23,6 +26,7 @@ public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransi
@Override
protected void connect() {
bottombar = get(BottomBar.class);
exclusivityManager = get(ExclusivityManager.class);
}
@Override
@ -56,15 +60,15 @@ public abstract class Tab extends ImmediateUI implements IBottomBarItem, ITransi
public final void open() {
if(opened) return;
Assets.sndBubble.play();
opened = true;
exclusivityManager.switchTo(this);
onOpen();
}
public final void close() {
if(!opened) return;
Assets.sndCancel.play();
opened = false;
exclusivityManager.closeCurrent();
onClose();
}

View File

@ -10,6 +10,7 @@ import xyz.valnet.hadean.gameobjects.SelectionUI;
import xyz.valnet.hadean.gameobjects.Terrain;
import xyz.valnet.hadean.gameobjects.inputlayer.BuildLayer;
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.Popup;
import xyz.valnet.hadean.gameobjects.ui.tabs.BuildTab;
@ -53,6 +54,7 @@ public class GameScene extends SceneGraph {
objects.add(new HoverQuery());
objects.add(new BottomBar());
objects.add(new ExclusivityManager());
objects.add(new BuildTab());
// objects.add(new JobBoardTab());
objects.add(new DebugTab());