close screen to parent
This commit is contained in:
parent
48c46e2105
commit
fa4e086220
4 changed files with 44 additions and 21 deletions
|
@ -9,6 +9,7 @@ import net.minecraft.client.gui.components.events.GuiEventListener;
|
||||||
import net.minecraft.client.gui.narration.NarratableEntry;
|
import net.minecraft.client.gui.narration.NarratableEntry;
|
||||||
import net.minecraft.client.gui.screens.Screen;
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
|
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
|
||||||
|
|
||||||
|
|
||||||
|
@ -18,23 +19,43 @@ public abstract class GridScreen extends Screen {
|
||||||
public final int topPadding;
|
public final int topPadding;
|
||||||
public final int sidePadding;
|
public final int sidePadding;
|
||||||
public final boolean centerVertically;
|
public final boolean centerVertically;
|
||||||
|
@Nullable
|
||||||
|
public final Screen parent;
|
||||||
|
|
||||||
public GridScreen(Component title) {
|
public GridScreen(Component title) {
|
||||||
this(title, 0, true);
|
this(null, title);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GridScreen(@Nullable Screen parent, Component title){
|
||||||
|
this(parent, title, 0, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridScreen(Component title, int topPadding, boolean centerVertically) {
|
public GridScreen(Component title, int topPadding, boolean centerVertically) {
|
||||||
this(title, topPadding, 20, centerVertically);
|
this(null, title, topPadding, 20, centerVertically);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GridScreen(@Nullable Screen parent, Component title, int topPadding, boolean centerVertically) {
|
||||||
|
this(parent, title, topPadding, 20, centerVertically);
|
||||||
}
|
}
|
||||||
|
|
||||||
public GridScreen(Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
public GridScreen(Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
||||||
|
this(null, title, topPadding, sidePadding, centerVertically);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GridScreen(@Nullable Screen parent, Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
||||||
super(title);
|
super(title);
|
||||||
|
|
||||||
|
this.parent = parent;
|
||||||
this.topPadding = topPadding;
|
this.topPadding = topPadding;
|
||||||
this.sidePadding = sidePadding;
|
this.sidePadding = sidePadding;
|
||||||
this.centerVertically = centerVertically;
|
this.centerVertically = centerVertically;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onClose() {
|
||||||
|
this.minecraft.setScreen(parent);
|
||||||
|
}
|
||||||
|
|
||||||
public Font getFont(){
|
public Font getFont(){
|
||||||
return this.font;
|
return this.font;
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,8 +3,10 @@ package ru.bclib.gui.screens;
|
||||||
import com.mojang.blaze3d.vertex.PoseStack;
|
import com.mojang.blaze3d.vertex.PoseStack;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
|
import net.minecraft.client.gui.screens.Screen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import ru.bclib.BCLib;
|
import ru.bclib.BCLib;
|
||||||
import ru.bclib.gui.gridlayout.GridLayout.GridValueType;
|
import ru.bclib.gui.gridlayout.GridLayout.GridValueType;
|
||||||
import ru.bclib.gui.gridlayout.GridLayout.VerticalAlignment;
|
import ru.bclib.gui.gridlayout.GridLayout.VerticalAlignment;
|
||||||
|
@ -19,14 +21,27 @@ abstract class BCLibScreen extends GridScreen {
|
||||||
super(title);
|
super(title);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BCLibScreen(@Nullable Screen parent, Component title){
|
||||||
|
super(parent, title);
|
||||||
|
}
|
||||||
|
|
||||||
public BCLibScreen(Component title, int topPadding, boolean centerVertically) {
|
public BCLibScreen(Component title, int topPadding, boolean centerVertically) {
|
||||||
super(title, topPadding, centerVertically);
|
super(title, topPadding, 20, centerVertically);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BCLibScreen(@Nullable Screen parent, Component title, int topPadding, boolean centerVertically) {
|
||||||
|
super(parent, title, topPadding, centerVertically);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BCLibScreen(Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
public BCLibScreen(Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
||||||
super(title, topPadding, sidePadding, centerVertically);
|
super(title, topPadding, sidePadding, centerVertically);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BCLibScreen(@Nullable Screen parent, Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
||||||
|
super(parent, title, topPadding, sidePadding, centerVertically);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void addTitle(){
|
protected void addTitle(){
|
||||||
GridRow row = grid.addRow(VerticalAlignment.CENTER);
|
GridRow row = grid.addRow(VerticalAlignment.CENTER);
|
||||||
row.addFiller();
|
row.addFiller();
|
||||||
|
|
|
@ -14,16 +14,12 @@ import ru.bclib.gui.gridlayout.GridRow;
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
public class ConfirmFixScreen extends BCLibScreen {
|
public class ConfirmFixScreen extends BCLibScreen {
|
||||||
|
|
||||||
@Nullable
|
|
||||||
private final Screen lastScreen;
|
|
||||||
protected final ConfirmFixScreen.Listener listener;
|
protected final ConfirmFixScreen.Listener listener;
|
||||||
private final Component description;
|
private final Component description;
|
||||||
protected int id;
|
protected int id;
|
||||||
|
|
||||||
public ConfirmFixScreen(@Nullable Screen screen, ConfirmFixScreen.Listener listener) {
|
public ConfirmFixScreen(@Nullable Screen parent, ConfirmFixScreen.Listener listener) {
|
||||||
super(new TranslatableComponent("bclib.datafixer.backupWarning.title"));
|
super(parent, new TranslatableComponent("bclib.datafixer.backupWarning.title"));
|
||||||
this.lastScreen = screen;
|
|
||||||
this.listener = listener;
|
this.listener = listener;
|
||||||
|
|
||||||
this.description = new TranslatableComponent("bclib.datafixer.backupWarning.message");
|
this.description = new TranslatableComponent("bclib.datafixer.backupWarning.message");
|
||||||
|
@ -48,7 +44,7 @@ public class ConfirmFixScreen extends BCLibScreen {
|
||||||
row = grid.addRow();
|
row = grid.addRow();
|
||||||
row.addFiller();
|
row.addFiller();
|
||||||
row.addButton(CommonComponents.GUI_CANCEL, BUTTON_HEIGHT, this.font, (button) -> {
|
row.addButton(CommonComponents.GUI_CANCEL, BUTTON_HEIGHT, this.font, (button) -> {
|
||||||
this.minecraft.setScreen(this.lastScreen);
|
onClose();
|
||||||
});
|
});
|
||||||
row.addSpacer();
|
row.addSpacer();
|
||||||
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, this.font, (button) -> {
|
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, this.font, (button) -> {
|
||||||
|
@ -58,16 +54,7 @@ public class ConfirmFixScreen extends BCLibScreen {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean shouldCloseOnEsc() {
|
public boolean shouldCloseOnEsc() {
|
||||||
return false;
|
return true;
|
||||||
}
|
|
||||||
|
|
||||||
public boolean keyPressed(int i, int j, int k) {
|
|
||||||
if (i == 256) {
|
|
||||||
this.minecraft.setScreen(this.lastScreen);
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return super.keyPressed(i, j, k);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Environment(EnvType.CLIENT)
|
@Environment(EnvType.CLIENT)
|
||||||
|
|
|
@ -34,7 +34,7 @@ public class ConfirmRestartScreen extends BCLibScreen {
|
||||||
|
|
||||||
GridRow row = grid.addRow();
|
GridRow row = grid.addRow();
|
||||||
row.addFiller();
|
row.addFiller();
|
||||||
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, (button) -> {
|
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, font, (button) -> {
|
||||||
listener.proceed();
|
listener.proceed();
|
||||||
});
|
});
|
||||||
row.addFiller();
|
row.addFiller();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue