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.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.gui.gridlayout.GridLayout.Alignment;
|
||||
|
||||
|
||||
|
@ -18,23 +19,43 @@ public abstract class GridScreen extends Screen {
|
|||
public final int topPadding;
|
||||
public final int sidePadding;
|
||||
public final boolean centerVertically;
|
||||
@Nullable
|
||||
public final Screen parent;
|
||||
|
||||
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) {
|
||||
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) {
|
||||
this(null, title, topPadding, sidePadding, centerVertically);
|
||||
}
|
||||
|
||||
public GridScreen(@Nullable Screen parent, Component title, int topPadding, int sidePadding, boolean centerVertically) {
|
||||
super(title);
|
||||
|
||||
this.parent = parent;
|
||||
this.topPadding = topPadding;
|
||||
this.sidePadding = sidePadding;
|
||||
this.centerVertically = centerVertically;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClose() {
|
||||
this.minecraft.setScreen(parent);
|
||||
}
|
||||
|
||||
public Font getFont(){
|
||||
return this.font;
|
||||
}
|
||||
|
|
|
@ -3,8 +3,10 @@ package ru.bclib.gui.screens;
|
|||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import net.fabricmc.api.EnvType;
|
||||
import net.fabricmc.api.Environment;
|
||||
import net.minecraft.client.gui.screens.Screen;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import ru.bclib.BCLib;
|
||||
import ru.bclib.gui.gridlayout.GridLayout.GridValueType;
|
||||
import ru.bclib.gui.gridlayout.GridLayout.VerticalAlignment;
|
||||
|
@ -19,14 +21,27 @@ abstract class BCLibScreen extends GridScreen {
|
|||
super(title);
|
||||
}
|
||||
|
||||
public BCLibScreen(@Nullable Screen parent, Component title){
|
||||
super(parent, title);
|
||||
}
|
||||
|
||||
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) {
|
||||
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(){
|
||||
GridRow row = grid.addRow(VerticalAlignment.CENTER);
|
||||
row.addFiller();
|
||||
|
|
|
@ -14,16 +14,12 @@ import ru.bclib.gui.gridlayout.GridRow;
|
|||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public class ConfirmFixScreen extends BCLibScreen {
|
||||
|
||||
@Nullable
|
||||
private final Screen lastScreen;
|
||||
protected final ConfirmFixScreen.Listener listener;
|
||||
private final Component description;
|
||||
protected int id;
|
||||
|
||||
public ConfirmFixScreen(@Nullable Screen screen, ConfirmFixScreen.Listener listener) {
|
||||
super(new TranslatableComponent("bclib.datafixer.backupWarning.title"));
|
||||
this.lastScreen = screen;
|
||||
public ConfirmFixScreen(@Nullable Screen parent, ConfirmFixScreen.Listener listener) {
|
||||
super(parent, new TranslatableComponent("bclib.datafixer.backupWarning.title"));
|
||||
this.listener = listener;
|
||||
|
||||
this.description = new TranslatableComponent("bclib.datafixer.backupWarning.message");
|
||||
|
@ -48,7 +44,7 @@ public class ConfirmFixScreen extends BCLibScreen {
|
|||
row = grid.addRow();
|
||||
row.addFiller();
|
||||
row.addButton(CommonComponents.GUI_CANCEL, BUTTON_HEIGHT, this.font, (button) -> {
|
||||
this.minecraft.setScreen(this.lastScreen);
|
||||
onClose();
|
||||
});
|
||||
row.addSpacer();
|
||||
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, this.font, (button) -> {
|
||||
|
@ -58,16 +54,7 @@ public class ConfirmFixScreen extends BCLibScreen {
|
|||
}
|
||||
|
||||
public boolean shouldCloseOnEsc() {
|
||||
return false;
|
||||
}
|
||||
|
||||
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)
|
||||
|
|
|
@ -34,7 +34,7 @@ public class ConfirmRestartScreen extends BCLibScreen {
|
|||
|
||||
GridRow row = grid.addRow();
|
||||
row.addFiller();
|
||||
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, (button) -> {
|
||||
row.addButton(CommonComponents.GUI_PROCEED, BUTTON_HEIGHT, font, (button) -> {
|
||||
listener.proceed();
|
||||
});
|
||||
row.addFiller();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue