Skip to content

Commit

Permalink
chore: TransformerWindowManager no longer returns itself on addTransf…
Browse files Browse the repository at this point in the history
…ormer
  • Loading branch information
phinner committed Jun 3, 2024
1 parent cdcebfd commit 9a245d0
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.xpdustry.distributor.api.gui.transform.TransformerWindowManager;
import com.xpdustry.distributor.api.plugin.MindustryPlugin;

public interface TextInputManager extends TransformerWindowManager<TextInputManager, TextInputPane> {
public interface TextInputManager extends TransformerWindowManager<TextInputPane> {

static TextInputManager create(final MindustryPlugin plugin) {
return new TextInputManagerImpl(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.xpdustry.distributor.api.gui.input;

import com.xpdustry.distributor.api.DistributorProvider;
import com.xpdustry.distributor.api.component.Component;
import com.xpdustry.distributor.api.component.render.ComponentStringBuilder;
import com.xpdustry.distributor.api.gui.Window;
Expand All @@ -31,8 +32,7 @@
import mindustry.ui.Menus;
import org.checkerframework.checker.nullness.qual.Nullable;

final class TextInputManagerImpl extends AbstractTransformerWindowManager<TextInputManager, TextInputPane>
implements TextInputManager {
final class TextInputManagerImpl extends AbstractTransformerWindowManager<TextInputPane> implements TextInputManager {

private final int id = Menus.registerTextInput(this::handle);
private final Set<MUUID> visible = new HashSet<>();
Expand Down Expand Up @@ -106,7 +106,10 @@ private void handle(final Player player, final @Nullable String input) {
}

private String render(final Window window, final Component component) {
return ComponentStringBuilder.mindustry(window.getAudience().getMetadata())
return ComponentStringBuilder.mindustry(DistributorProvider.get()
.getAudienceProvider()
.getPlayer(window.getViewer())
.getMetadata())
.append(component)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import com.xpdustry.distributor.api.gui.transform.TransformerWindowManager;
import com.xpdustry.distributor.api.plugin.MindustryPlugin;

public interface MenuManager extends TransformerWindowManager<MenuManager, MenuPane> {
public interface MenuManager extends TransformerWindowManager<MenuPane> {

static MenuManager create(final MindustryPlugin plugin) {
return new MenuManagerImpl(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.xpdustry.distributor.api.gui.menu;

import com.xpdustry.distributor.api.DistributorProvider;
import com.xpdustry.distributor.api.component.Component;
import com.xpdustry.distributor.api.component.render.ComponentStringBuilder;
import com.xpdustry.distributor.api.gui.Window;
Expand All @@ -28,7 +29,7 @@
import mindustry.gen.Player;
import mindustry.ui.Menus;

final class MenuManagerImpl extends AbstractTransformerWindowManager<MenuManager, MenuPane> implements MenuManager {
final class MenuManagerImpl extends AbstractTransformerWindowManager<MenuPane> implements MenuManager {

private final int id = Menus.registerMenu(this::handle);

Expand Down Expand Up @@ -98,7 +99,10 @@ private void handle(final Player player, final int option) {
}

private String render(final Window window, final Component component) {
return ComponentStringBuilder.mindustry(window.getAudience().getMetadata())
return ComponentStringBuilder.mindustry(DistributorProvider.get()
.getAudienceProvider()
.getPlayer(window.getViewer())
.getMetadata())
.append(component)
.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import com.xpdustry.distributor.api.plugin.MindustryPlugin;
import java.time.Duration;

public interface PopupManager extends TransformerWindowManager<PopupManager, PopupPane> {
public interface PopupManager extends TransformerWindowManager<PopupPane> {

static PopupManager create(final MindustryPlugin plugin) {
return new PopupManagerImpl(plugin);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import mindustry.game.EventType;
import mindustry.gen.Call;

final class PopupManagerImpl extends AbstractTransformerWindowManager<PopupManager, PopupPane> implements PopupManager {
final class PopupManagerImpl extends AbstractTransformerWindowManager<PopupPane> implements PopupManager {

private final Interval interval = new Interval();
private Duration updateInterval = Duration.ZERO;
Expand Down Expand Up @@ -66,7 +66,10 @@ protected void onWindowOpen(final SimpleWindow window) {
};
Call.infoPopup(
window.getViewer().con(),
ComponentStringBuilder.mindustry(window.getAudience().getMetadata())
ComponentStringBuilder.mindustry(DistributorProvider.get()
.getAudienceProvider()
.getPlayer(window.getViewer())
.getMetadata())
.append(window.getPane().getContent())
.toString(),
(Time.delta / 60F) * tickUpdateInterval,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
import org.checkerframework.checker.nullness.qual.Nullable;

public abstract class AbstractTransformerWindowManager<T extends TransformerWindowManager<T, P>, P extends Pane>
implements TransformerWindowManager<T, P>, PluginAware {
public abstract class AbstractTransformerWindowManager<P extends Pane>
implements TransformerWindowManager<P>, PluginAware {

private final MindustryPlugin plugin;
private final EventSubscription playerLeaveListener;
Expand Down Expand Up @@ -82,11 +82,9 @@ public Collection<Window> getActiveWindows() {
return Collections.unmodifiableCollection(this.windows.values());
}

@SuppressWarnings("unchecked")
@Override
public final T addTransformer(final Transformer<P> transformer) {
public final void addTransformer(final Transformer<P> transformer) {
transformers.add(Objects.requireNonNull(transformer));
return (T) this;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
import com.xpdustry.distributor.api.gui.Pane;
import com.xpdustry.distributor.api.gui.WindowManager;

public interface TransformerWindowManager<T extends TransformerWindowManager<T, P>, P extends Pane>
extends WindowManager {
public interface TransformerWindowManager<P extends Pane> extends WindowManager {

T addTransformer(final Transformer<P> transformer);
void addTransformer(final Transformer<P> transformer);
}

0 comments on commit 9a245d0

Please sign in to comment.