some arch changes for better sound support

bottom-bar
Ivory 2023-01-11 03:32:43 -05:00
parent 807e6a2a49
commit 0aed4f8625
6 changed files with 39 additions and 10 deletions

View File

@ -39,6 +39,7 @@ public class BottomBar extends GameObject implements IButtonListener, ITransient
int w = r - l;
Button btn = new SimpleButton(item.getTabName(), l, 576 - bottomBarHeight, w, bottomBarHeight, Layers.BOTTOM_BAR);
if(item.isButtonClickSilent()) btn = btn.setClickSound(false);
btn.registerClickListener(this);
add(btn);

View File

@ -107,7 +107,8 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
private List<ISelectable> selected = new ArrayList<ISelectable>();
private void makeSelection(Vector4f a) {
selected.clear();
List<ISelectable> newSelection = new ArrayList<ISelectable>();
Vector4f normalizedSelectionBoxScreen = sortVector(a);
Vector2f selectionBoxWorldMin = camera.screen2world(normalizedSelectionBoxScreen.x, normalizedSelectionBoxScreen.y);
Vector2f selectionBoxWorldMax = camera.screen2world(normalizedSelectionBoxScreen.z, normalizedSelectionBoxScreen.w);
@ -122,19 +123,19 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
thingBox.x, thingBox.y,
thingBox.z, thingBox.w
)) {
selected.add(thing);
newSelection.add(thing);
}
}
animation = 0;
broadcastSelectionChanged();
updateSelection(newSelection);
}
private void broadcastSelectionChanged() {
Assets.sndSelectionChanged.play();
// if(selected.size() > 0) Assets.sndBubble.play();
// if(selected.size() == 0) Assets.sndCancel.play();
// Assets.sndSelectionChanged.play();
if(selected.size() > 0) Assets.sndBubble.play();
if(selected.size() == 0) Assets.sndCancel.play();
for(ISelectionChangeListener listener : listeners) {
listener.selectionChanged(selected);
@ -142,6 +143,7 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
}
public void updateSelection(List<ISelectable> newSelection) {
if(selected.size() == 0 && newSelection.size() == 0) return;
selected = newSelection;
broadcastSelectionChanged();
}
@ -191,11 +193,16 @@ public class SelectionLayer extends GameObject implements IMouseCaptureArea, ITr
if(selected.size() == 0) {
buildTab.evoke();
} else {
clearSelection();
}
}
}
public void clearSelection() {
if(selected.size() == 0) return;
selected.clear();
broadcastSelectionChanged();
}
}
}
@Override
public void mouseUp(int button) {

View File

@ -135,11 +135,13 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
@Override
public void rise() {
Assets.sndBubble.play();
activate();
}
@Override
public void fall() {
Assets.sndCancel.play();
deactiveate();
}
@ -264,7 +266,7 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
opened.toggle();
if(opened.value()) {
selection.updateSelection(new ArrayList<ISelectable>());
selection.clearSelection();
}
}
@ -336,4 +338,9 @@ public class BuildTab extends Tab implements ISelectionChangeListener, IMouseCap
selectBuildable(newBuildableRecord);
}
}
@Override
public boolean isButtonClickSilent() {
return true;
}
}

View File

@ -18,4 +18,9 @@ public abstract class Tab extends GameObject implements IBottomBarItem, ITransie
protected void start() {
bottombar.registerButton(this);
}
@Override
public boolean isButtonClickSilent() {
return false;
}
}

View File

@ -13,6 +13,8 @@ import xyz.valnet.hadean.util.Assets;
public class Button extends GameObject implements IMouseCaptureArea, ITransient {
private boolean clickSound = true;
private int x, y, width, height;
private String text;
protected Tile9 frame;
@ -42,6 +44,11 @@ public class Button extends GameObject implements IMouseCaptureArea, ITransient
layer = l;
}
public Button setClickSound(boolean b) {
this.clickSound = b;
return this;
}
public String getText() {
return text;
}
@ -146,7 +153,7 @@ public class Button extends GameObject implements IMouseCaptureArea, ITransient
state = HOVER;
}
listener.click(this);
Assets.sndBubble.play();
if (clickSound) Assets.sndBubble.play();
}
} else if (state == ACTIVE_NO_HOVER) {
if(hovered) {

View File

@ -4,4 +4,6 @@ public interface IBottomBarItem {
public void evoke();
public String getTabName();
public boolean isButtonClickSilent();
}