139 lines
6.8 KiB
Java
139 lines
6.8 KiB
Java
/*
|
|
* Decompiled with CFR 0.152.
|
|
*
|
|
* Could not load the following classes:
|
|
* org.jspecify.annotations.Nullable
|
|
*/
|
|
package com.mojang.realmsclient.gui.screens.configuration;
|
|
|
|
import com.mojang.realmsclient.dto.RealmsRegion;
|
|
import com.mojang.realmsclient.dto.RegionSelectionPreference;
|
|
import com.mojang.realmsclient.dto.ServiceQuality;
|
|
import com.mojang.realmsclient.gui.screens.configuration.RealmsSettingsTab;
|
|
import java.util.Map;
|
|
import java.util.Objects;
|
|
import java.util.function.BiConsumer;
|
|
import net.minecraft.client.gui.GuiGraphics;
|
|
import net.minecraft.client.gui.components.AbstractWidget;
|
|
import net.minecraft.client.gui.components.Button;
|
|
import net.minecraft.client.gui.components.ObjectSelectionList;
|
|
import net.minecraft.client.gui.components.StringWidget;
|
|
import net.minecraft.client.gui.layouts.HeaderAndFooterLayout;
|
|
import net.minecraft.client.gui.layouts.LinearLayout;
|
|
import net.minecraft.client.gui.screens.Screen;
|
|
import net.minecraft.client.input.MouseButtonEvent;
|
|
import net.minecraft.client.renderer.RenderPipelines;
|
|
import net.minecraft.network.chat.CommonComponents;
|
|
import net.minecraft.network.chat.Component;
|
|
import org.jspecify.annotations.Nullable;
|
|
|
|
public class RealmsPreferredRegionSelectionScreen
|
|
extends Screen {
|
|
private static final Component REGION_SELECTION_LABEL = Component.translatable("mco.configure.world.region_preference.title");
|
|
private static final int SPACING = 8;
|
|
private final HeaderAndFooterLayout layout = new HeaderAndFooterLayout(this);
|
|
private final Screen parent;
|
|
private final BiConsumer<RegionSelectionPreference, RealmsRegion> applySettings;
|
|
private final Map<RealmsRegion, ServiceQuality> regionServiceQuality;
|
|
private @Nullable RegionSelectionList list;
|
|
private RealmsSettingsTab.RegionSelection selection;
|
|
private @Nullable Button doneButton;
|
|
|
|
public RealmsPreferredRegionSelectionScreen(Screen parent, BiConsumer<RegionSelectionPreference, RealmsRegion> applySettings, Map<RealmsRegion, ServiceQuality> regionServiceQuality, RealmsSettingsTab.RegionSelection currentSelection) {
|
|
super(REGION_SELECTION_LABEL);
|
|
this.parent = parent;
|
|
this.applySettings = applySettings;
|
|
this.regionServiceQuality = regionServiceQuality;
|
|
this.selection = currentSelection;
|
|
}
|
|
|
|
@Override
|
|
public void onClose() {
|
|
this.minecraft.setScreen(this.parent);
|
|
}
|
|
|
|
@Override
|
|
protected void init() {
|
|
LinearLayout header = this.layout.addToHeader(LinearLayout.vertical().spacing(8));
|
|
header.defaultCellSetting().alignHorizontallyCenter();
|
|
header.addChild(new StringWidget(this.getTitle(), this.font));
|
|
this.list = this.layout.addToContents(new RegionSelectionList());
|
|
LinearLayout footer = this.layout.addToFooter(LinearLayout.horizontal().spacing(8));
|
|
this.doneButton = footer.addChild(Button.builder(CommonComponents.GUI_DONE, button -> {
|
|
this.applySettings.accept(this.selection.preference(), this.selection.region());
|
|
this.onClose();
|
|
}).build());
|
|
footer.addChild(Button.builder(CommonComponents.GUI_CANCEL, button -> this.onClose()).build());
|
|
this.list.setSelected((RegionSelectionList.Entry)this.list.children().stream().filter(e -> Objects.equals(e.regionSelection, this.selection)).findFirst().orElse(null));
|
|
this.layout.visitWidgets(x$0 -> {
|
|
AbstractWidget cfr_ignored_0 = (AbstractWidget)this.addRenderableWidget(x$0);
|
|
});
|
|
this.repositionElements();
|
|
}
|
|
|
|
@Override
|
|
protected void repositionElements() {
|
|
this.layout.arrangeElements();
|
|
this.list.updateSize(this.width, this.layout);
|
|
}
|
|
|
|
private void updateButtonValidity() {
|
|
this.doneButton.active = this.list.getSelected() != null;
|
|
}
|
|
|
|
private class RegionSelectionList
|
|
extends ObjectSelectionList<Entry> {
|
|
private RegionSelectionList() {
|
|
super(RealmsPreferredRegionSelectionScreen.this.minecraft, RealmsPreferredRegionSelectionScreen.this.width, RealmsPreferredRegionSelectionScreen.this.height - 77, 40, 16);
|
|
this.addEntry(new Entry(RegionSelectionPreference.AUTOMATIC_PLAYER, null));
|
|
this.addEntry(new Entry(RegionSelectionPreference.AUTOMATIC_OWNER, null));
|
|
RealmsPreferredRegionSelectionScreen.this.regionServiceQuality.keySet().stream().map(region -> new Entry(RegionSelectionPreference.MANUAL, (RealmsRegion)((Object)region))).forEach(x$0 -> this.addEntry(x$0));
|
|
}
|
|
|
|
@Override
|
|
public void setSelected(@Nullable Entry selected) {
|
|
super.setSelected(selected);
|
|
if (selected != null) {
|
|
RealmsPreferredRegionSelectionScreen.this.selection = selected.regionSelection;
|
|
}
|
|
RealmsPreferredRegionSelectionScreen.this.updateButtonValidity();
|
|
}
|
|
|
|
private class Entry
|
|
extends ObjectSelectionList.Entry<Entry> {
|
|
private final RealmsSettingsTab.RegionSelection regionSelection;
|
|
private final Component name;
|
|
|
|
public Entry(@Nullable RegionSelectionPreference preference, RealmsRegion region) {
|
|
this(new RealmsSettingsTab.RegionSelection(preference, region));
|
|
}
|
|
|
|
public Entry(RealmsSettingsTab.RegionSelection regionSelection) {
|
|
this.regionSelection = regionSelection;
|
|
this.name = regionSelection.preference() == RegionSelectionPreference.MANUAL ? (regionSelection.region() != null ? Component.translatable(regionSelection.region().translationKey) : Component.empty()) : Component.translatable(regionSelection.preference().translationKey);
|
|
}
|
|
|
|
@Override
|
|
public Component getNarration() {
|
|
return Component.translatable("narrator.select", this.name);
|
|
}
|
|
|
|
@Override
|
|
public void renderContent(GuiGraphics graphics, int mouseX, int mouseY, boolean hovered, float a) {
|
|
graphics.drawString(RealmsPreferredRegionSelectionScreen.this.font, this.name, this.getContentX() + 5, this.getContentY() + 2, -1);
|
|
if (this.regionSelection.region() != null && RealmsPreferredRegionSelectionScreen.this.regionServiceQuality.containsKey((Object)this.regionSelection.region())) {
|
|
ServiceQuality serviceQuality = RealmsPreferredRegionSelectionScreen.this.regionServiceQuality.getOrDefault((Object)this.regionSelection.region(), ServiceQuality.UNKNOWN);
|
|
graphics.blitSprite(RenderPipelines.GUI_TEXTURED, serviceQuality.getIcon(), this.getContentRight() - 18, this.getContentY() + 2, 10, 8);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public boolean mouseClicked(MouseButtonEvent event, boolean doubleClick) {
|
|
RegionSelectionList.this.setSelected(this);
|
|
return super.mouseClicked(event, doubleClick);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|