-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The `Tab` implementation provides a method to produce a list of `TargetListEntries`. Currently, the only implementation is `PlayerTab`, which provides a list of `PlayerListEntries` & a "perspective" button.
- Loading branch information
1 parent
2cf5176
commit 3ab573a
Showing
6 changed files
with
133 additions
and
42 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
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
27 changes: 27 additions & 0 deletions
27
common/src/main/java/net/xolt/freecam/gui/go/tabs/GotoScreenTab.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,27 @@ | ||
package net.xolt.freecam.gui.go.tabs; | ||
|
||
import net.minecraft.client.gui.components.AbstractButton; | ||
import net.xolt.freecam.gui.go.TargetListEntry; | ||
import net.xolt.freecam.gui.go.TargetListWidget; | ||
|
||
import java.util.List; | ||
|
||
public enum GotoScreenTab implements Tab { | ||
PLAYER(new PlayerTab()); | ||
|
||
private final Tab implementation; | ||
|
||
GotoScreenTab(Tab tab) { | ||
this.implementation = tab; | ||
} | ||
|
||
@Override | ||
public List<TargetListEntry> provideEntriesFor(TargetListWidget widget) { | ||
return implementation.provideEntriesFor(widget); | ||
} | ||
|
||
@Override | ||
public List<AbstractButton> extraButtons() { | ||
return implementation.extraButtons(); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
common/src/main/java/net/xolt/freecam/gui/go/tabs/PlayerTab.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,67 @@ | ||
package net.xolt.freecam.gui.go.tabs; | ||
|
||
import com.google.common.base.Suppliers; | ||
import net.minecraft.client.gui.components.AbstractButton; | ||
import net.minecraft.client.gui.components.CycleButton; | ||
import net.minecraft.client.gui.components.Tooltip; | ||
import net.minecraft.client.player.AbstractClientPlayer; | ||
import net.minecraft.network.chat.Component; | ||
import net.xolt.freecam.config.ModConfig; | ||
import net.xolt.freecam.gui.go.PlayerListEntry; | ||
import net.xolt.freecam.gui.go.TargetListEntry; | ||
import net.xolt.freecam.gui.go.TargetListWidget; | ||
import net.xolt.freecam.util.FreeCamera; | ||
import net.xolt.freecam.variant.api.BuildVariant; | ||
|
||
import java.util.*; | ||
import java.util.function.Function; | ||
import java.util.function.Supplier; | ||
import java.util.stream.Collectors; | ||
|
||
import static net.xolt.freecam.Freecam.MC; | ||
|
||
class PlayerTab implements Tab { | ||
|
||
private final Supplier<CycleButton<ModConfig.Perspective>> perspectiveButton = Suppliers.memoize(() -> CycleButton | ||
.builder((ModConfig.Perspective value) -> Component.translatable(value.getKey())) | ||
.withValues(ModConfig.Perspective.values()) | ||
.withInitialValue(ModConfig.get().hidden.gotoPlayerPerspective) | ||
.withTooltip(value -> Tooltip.create(Component.translatable("gui.freecam.goto.button.perspective.@Tooltip"))) | ||
.displayOnlyValue() | ||
.create(0, 0, 80, 20, Component.empty(), (button, value) -> { | ||
ModConfig.get().hidden.gotoPlayerPerspective = value; | ||
ModConfig.save(); | ||
})); | ||
|
||
@Override | ||
public List<TargetListEntry> provideEntriesFor(TargetListWidget widget) { | ||
// Store the existing entries in a UUID map for easy lookup | ||
Map<UUID, PlayerListEntry> currentEntries = widget.children() | ||
.parallelStream() | ||
.filter(PlayerListEntry.class::isInstance) | ||
.map(PlayerListEntry.class::cast) | ||
.collect(Collectors.toUnmodifiableMap(PlayerListEntry::getUUID, Function.identity())); | ||
|
||
// Map the in-range players into PlayerListEntries | ||
// Use existing entries if possible | ||
return MC.level.players() | ||
.parallelStream() | ||
.filter(player -> !(player instanceof FreeCamera)) | ||
.filter(this::permitted) | ||
.map(player -> Objects.requireNonNullElseGet( | ||
currentEntries.get(player.getUUID()), | ||
() -> new PlayerListEntry(widget, player))) | ||
.map(TargetListEntry.class::cast) | ||
.toList(); | ||
} | ||
|
||
@Override | ||
public List<AbstractButton> extraButtons() { | ||
return Collections.singletonList(perspectiveButton.get()); | ||
} | ||
|
||
private boolean permitted(AbstractClientPlayer player) { | ||
// TODO check if player is visible | ||
return BuildVariant.getInstance().cheatsPermitted() || Objects.equals(MC.player, player); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
common/src/main/java/net/xolt/freecam/gui/go/tabs/Tab.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,14 @@ | ||
package net.xolt.freecam.gui.go.tabs; | ||
|
||
import net.minecraft.client.gui.components.AbstractButton; | ||
import net.xolt.freecam.gui.go.TargetListEntry; | ||
import net.xolt.freecam.gui.go.TargetListWidget; | ||
|
||
import java.util.List; | ||
|
||
interface Tab { | ||
|
||
List<TargetListEntry> provideEntriesFor(TargetListWidget widget); | ||
|
||
List<AbstractButton> extraButtons(); | ||
} |