-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Overhaul the waiting lobby user interface (#303)
* Add an event for building waiting lobby user interface layouts * Indicate the requested team in the waiting lobby user interface * Allow accessing extended user interfaces from the waiting lobby user interface * Allow leaving games from the waiting lobby user interface * Fix single extended elements shrinking in waiting lobby user interfaces * Use direction-independent terms for waiting lobby user interface element alignments * Prevent spectators from selecting teams in the waiting lobby user interface * Fix the waiting lobby user interface blocking world interactions
- Loading branch information
Showing
20 changed files
with
859 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/xyz/nucleoid/plasmid/api/game/common/ui/WaitingLobbyUiElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package xyz.nucleoid.plasmid.api.game.common.ui; | ||
|
||
import java.util.List; | ||
import java.util.SequencedCollection; | ||
|
||
import eu.pb4.sgui.api.ClickType; | ||
import eu.pb4.sgui.api.elements.GuiElementInterface; | ||
import eu.pb4.sgui.api.gui.HotbarGui; | ||
import eu.pb4.sgui.api.gui.SlotGuiInterface; | ||
|
||
public interface WaitingLobbyUiElement { | ||
GuiElementInterface createMainElement(); | ||
|
||
default SequencedCollection<GuiElementInterface> createExtendedElements() { | ||
return List.of(this.createMainElement()); | ||
} | ||
|
||
static boolean isClick(ClickType type, SlotGuiInterface gui) { | ||
return type.isRight || !(gui instanceof HotbarGui); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/xyz/nucleoid/plasmid/api/game/common/ui/WaitingLobbyUiLayout.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package xyz.nucleoid.plasmid.api.game.common.ui; | ||
|
||
import eu.pb4.sgui.api.elements.GuiElementInterface; | ||
import xyz.nucleoid.plasmid.impl.game.common.ui.WaitingLobbyUiLayoutImpl; | ||
|
||
import java.util.Objects; | ||
import java.util.function.Consumer; | ||
|
||
public interface WaitingLobbyUiLayout { | ||
void addLeading(WaitingLobbyUiElement element); | ||
|
||
void addTrailing(WaitingLobbyUiElement element); | ||
|
||
void refresh(); | ||
|
||
static WaitingLobbyUiLayout of(Consumer<GuiElementInterface[]> callback) { | ||
return new WaitingLobbyUiLayoutImpl(Objects.requireNonNull(callback)); | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/xyz/nucleoid/plasmid/api/game/event/GameWaitingLobbyEvents.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package xyz.nucleoid.plasmid.api.game.event; | ||
|
||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import xyz.nucleoid.plasmid.api.game.GameActivity; | ||
import xyz.nucleoid.plasmid.api.game.GameSpace; | ||
import xyz.nucleoid.plasmid.api.game.common.GameWaitingLobby; | ||
import xyz.nucleoid.plasmid.api.game.common.ui.WaitingLobbyUiLayout; | ||
import xyz.nucleoid.stimuli.event.StimulusEvent; | ||
|
||
/** | ||
* Events relating to a {@link GameWaitingLobby} applied to a {@link GameActivity} within a {@link GameSpace}. | ||
*/ | ||
public final class GameWaitingLobbyEvents { | ||
/** | ||
* Called when a {@link WaitingLobbyUiLayout} is created for a specific player's waiting lobby UI. | ||
* <p> | ||
* This event should be used to add custom UI elements to the hotbar UI | ||
* used by players before the game begins. | ||
*/ | ||
public static final StimulusEvent<BuildUiLayout> BUILD_UI_LAYOUT = StimulusEvent.create(BuildUiLayout.class, ctx -> (layout, player) -> { | ||
try { | ||
for (var listener : ctx.getListeners()) { | ||
listener.onBuildUiLayout(layout, player); | ||
} | ||
} catch (Throwable throwable) { | ||
ctx.handleException(throwable); | ||
} | ||
}); | ||
|
||
public interface BuildUiLayout { | ||
void onBuildUiLayout(WaitingLobbyUiLayout layout, ServerPlayerEntity player); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/xyz/nucleoid/plasmid/impl/game/common/ui/ExtensionGuiElement.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
package xyz.nucleoid.plasmid.impl.game.common.ui; | ||
|
||
import eu.pb4.sgui.api.elements.GuiElementInterface; | ||
import eu.pb4.sgui.api.gui.SlotGuiInterface; | ||
import net.minecraft.item.ItemStack; | ||
import xyz.nucleoid.plasmid.api.game.common.ui.WaitingLobbyUiElement; | ||
import xyz.nucleoid.plasmid.api.util.Guis; | ||
|
||
public record ExtensionGuiElement(GuiElementInterface delegate, WaitingLobbyUiLayoutEntry entry) implements GuiElementInterface { | ||
@Override | ||
public ItemStack getItemStack() { | ||
return this.delegate.getItemStack(); | ||
} | ||
|
||
@Override | ||
public ClickCallback getGuiCallback() { | ||
return (index, type, action, gui) -> { | ||
if (WaitingLobbyUiElement.isClick(type, gui)) { | ||
this.openExtendedGui(gui); | ||
} | ||
}; | ||
} | ||
|
||
private void openExtendedGui(SlotGuiInterface parent) { | ||
var player = parent.getPlayer(); | ||
var name = this.delegate.getItemStackForDisplay(parent).getName().copy(); | ||
|
||
var ui = Guis.createSelectorGui(player, name, true, gui -> { | ||
if (gui.isOpen()) { | ||
// Refresh elements | ||
this.openExtendedGui(parent); | ||
} | ||
}, gui -> { | ||
parent.open(); | ||
}, this.entry.getElement().createExtendedElements()); | ||
|
||
ui.open(); | ||
} | ||
} |
Oops, something went wrong.