ConfirmLinkScreen.java

net.minecraft.client.gui.screens.ConfirmLinkScreen

信息

  • 全限定名:net.minecraft.client.gui.screens.ConfirmLinkScreen
  • 类型:public class
  • 包:net.minecraft.client.gui.screens
  • 源码路径:src/main/java/net/minecraft/client/gui/screens/ConfirmLinkScreen.java
  • 起始行号:L18
  • 继承:ConfirmScreen
  • 职责:

    TODO

字段/常量

  • WARNING_TEXT

    • 类型: Component
    • 修饰符: private static final
    • 源码定位: L19
    • 说明:

      TODO

  • BUTTON_WIDTH

    • 类型: int
    • 修饰符: private static final
    • 源码定位: L20
    • 说明:

      TODO

  • url

    • 类型: String
    • 修饰符: private final
    • 源码定位: L21
    • 说明:

      TODO

  • showWarning

    • 类型: boolean
    • 修饰符: private final
    • 源码定位: L22
    • 说明:

      TODO

内部类/嵌套类型

构造器

public ConfirmLinkScreen(BooleanConsumer callback, String url, boolean trusted) @ L24

  • 构造器名:ConfirmLinkScreen
  • 源码定位:L24
  • 修饰符:public

参数:

  • callback: BooleanConsumer
  • url: String
  • trusted: boolean

说明:

TODO

public ConfirmLinkScreen(BooleanConsumer callback, Component title, String url, boolean trusted) @ L28

  • 构造器名:ConfirmLinkScreen
  • 源码定位:L28
  • 修饰符:public

参数:

  • callback: BooleanConsumer
  • title: Component
  • url: String
  • trusted: boolean

说明:

TODO

public ConfirmLinkScreen(BooleanConsumer callback, Component title, URI uri, boolean trusted) @ L32

  • 构造器名:ConfirmLinkScreen
  • 源码定位:L32
  • 修饰符:public

参数:

  • callback: BooleanConsumer
  • title: Component
  • uri: URI
  • trusted: boolean

说明:

TODO

public ConfirmLinkScreen(BooleanConsumer callback, Component title, Component message, URI uri, Component noButton, boolean trusted) @ L36

  • 构造器名:ConfirmLinkScreen
  • 源码定位:L36
  • 修饰符:public

参数:

  • callback: BooleanConsumer
  • title: Component
  • message: Component
  • uri: URI
  • noButton: Component
  • trusted: boolean

说明:

TODO

public ConfirmLinkScreen(BooleanConsumer callback, Component title, Component message, String url, Component noButtonComponent, boolean trusted) @ L40

  • 构造器名:ConfirmLinkScreen
  • 源码定位:L40
  • 修饰符:public

参数:

  • callback: BooleanConsumer
  • title: Component
  • message: Component
  • url: String
  • noButtonComponent: Component
  • trusted: boolean

说明:

TODO

方法

下面的方法块按源码顺序生成。

protected static MutableComponent confirmMessage(boolean trusted, String url) @ L48

  • 方法名:confirmMessage
  • 源码定位:L48
  • 返回类型:MutableComponent
  • 修饰符:protected static

参数:

  • trusted: boolean
  • url: String

说明:

TODO

protected static MutableComponent confirmMessage(boolean trusted) @ L52

  • 方法名:confirmMessage
  • 源码定位:L52
  • 返回类型:MutableComponent
  • 修饰符:protected static

参数:

  • trusted: boolean

说明:

TODO

protected void addAdditionalText() @ L56

  • 方法名:addAdditionalText
  • 源码定位:L56
  • 返回类型:void
  • 修饰符:protected

参数:

说明:

TODO

protected void addButtons(LinearLayout buttonLayout) @ L63

  • 方法名:addButtons
  • 源码定位:L63
  • 返回类型:void
  • 修饰符:protected

参数:

  • buttonLayout: LinearLayout

说明:

TODO

public void copyToClipboard() @ L73

  • 方法名:copyToClipboard
  • 源码定位:L73
  • 返回类型:void
  • 修饰符:public

参数:

说明:

TODO

public static void confirmLinkNow(Screen parentScreen, String uri, boolean trusted) @ L77

  • 方法名:confirmLinkNow
  • 源码定位:L77
  • 返回类型:void
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: String
  • trusted: boolean

说明:

TODO

public static void confirmLinkNow(Screen parentScreen, URI uri, boolean trusted) @ L88

  • 方法名:confirmLinkNow
  • 源码定位:L88
  • 返回类型:void
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: URI
  • trusted: boolean

说明:

TODO

public static void confirmLinkNow(Screen parentScreen, URI uri) @ L99

  • 方法名:confirmLinkNow
  • 源码定位:L99
  • 返回类型:void
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: URI

说明:

TODO

public static void confirmLinkNow(Screen parentScreen, String uri) @ L103

  • 方法名:confirmLinkNow
  • 源码定位:L103
  • 返回类型:void
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: String

说明:

TODO

public static Button.OnPress confirmLink(Screen parentScreen, String uri, boolean trusted) @ L107

  • 方法名:confirmLink
  • 源码定位:L107
  • 返回类型:Button.OnPress
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: String
  • trusted: boolean

说明:

TODO

public static Button.OnPress confirmLink(Screen parentScreen, URI uri, boolean trusted) @ L111

  • 方法名:confirmLink
  • 源码定位:L111
  • 返回类型:Button.OnPress
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: URI
  • trusted: boolean

说明:

TODO

public static Button.OnPress confirmLink(Screen parentScreen, String uri) @ L115

  • 方法名:confirmLink
  • 源码定位:L115
  • 返回类型:Button.OnPress
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: String

说明:

TODO

public static Button.OnPress confirmLink(Screen parentScreen, URI uri) @ L119

  • 方法名:confirmLink
  • 源码定位:L119
  • 返回类型:Button.OnPress
  • 修饰符:public static

参数:

  • parentScreen: Screen
  • uri: URI

说明:

TODO

代码

@OnlyIn(Dist.CLIENT)
public class ConfirmLinkScreen extends ConfirmScreen {
    private static final Component WARNING_TEXT = Component.translatable("chat.link.warning").withColor(-13108);
    private static final int BUTTON_WIDTH = 100;
    private final String url;
    private final boolean showWarning;
 
    public ConfirmLinkScreen(BooleanConsumer callback, String url, boolean trusted) {
        this(callback, confirmMessage(trusted), Component.literal(url), url, trusted ? CommonComponents.GUI_CANCEL : CommonComponents.GUI_NO, trusted);
    }
 
    public ConfirmLinkScreen(BooleanConsumer callback, Component title, String url, boolean trusted) {
        this(callback, title, confirmMessage(trusted, url), url, trusted ? CommonComponents.GUI_CANCEL : CommonComponents.GUI_NO, trusted);
    }
 
    public ConfirmLinkScreen(BooleanConsumer callback, Component title, URI uri, boolean trusted) {
        this(callback, title, uri.toString(), trusted);
    }
 
    public ConfirmLinkScreen(BooleanConsumer callback, Component title, Component message, URI uri, Component noButton, boolean trusted) {
        this(callback, title, message, uri.toString(), noButton, true);
    }
 
    public ConfirmLinkScreen(BooleanConsumer callback, Component title, Component message, String url, Component noButtonComponent, boolean trusted) {
        super(callback, title, message);
        this.yesButtonComponent = trusted ? CommonComponents.GUI_OPEN_IN_BROWSER : CommonComponents.GUI_YES;
        this.noButtonComponent = noButtonComponent;
        this.showWarning = !trusted;
        this.url = url;
    }
 
    protected static MutableComponent confirmMessage(boolean trusted, String url) {
        return confirmMessage(trusted).append(CommonComponents.SPACE).append(Component.literal(url));
    }
 
    protected static MutableComponent confirmMessage(boolean trusted) {
        return Component.translatable(trusted ? "chat.link.confirmTrusted" : "chat.link.confirm");
    }
 
    @Override
    protected void addAdditionalText() {
        if (this.showWarning) {
            this.layout.addChild(new StringWidget(WARNING_TEXT, this.font));
        }
    }
 
    @Override
    protected void addButtons(LinearLayout buttonLayout) {
        this.yesButton = buttonLayout.addChild(Button.builder(this.yesButtonComponent, button -> this.callback.accept(true)).width(100).build());
        buttonLayout.addChild(Button.builder(CommonComponents.GUI_COPY_TO_CLIPBOARD, button -> {
            this.copyToClipboard();
            this.callback.accept(false);
        }).width(100).build());
        this.noButton = buttonLayout.addChild(Button.builder(this.noButtonComponent, button -> this.callback.accept(false)).width(100).build());
    }
 
    public void copyToClipboard() {
        this.minecraft.keyboardHandler.setClipboard(this.url);
    }
 
    public static void confirmLinkNow(Screen parentScreen, String uri, boolean trusted) {
        Minecraft minecraft = Minecraft.getInstance();
        minecraft.setScreen(new ConfirmLinkScreen(shouldOpen -> {
            if (shouldOpen) {
                Util.getPlatform().openUri(uri);
            }
 
            minecraft.setScreen(parentScreen);
        }, uri, trusted));
    }
 
    public static void confirmLinkNow(@Nullable Screen parentScreen, URI uri, boolean trusted) {
        Minecraft minecraft = Minecraft.getInstance();
        minecraft.setScreen(new ConfirmLinkScreen(shouldOpen -> {
            if (shouldOpen) {
                Util.getPlatform().openUri(uri);
            }
 
            minecraft.setScreen(parentScreen);
        }, uri.toString(), trusted));
    }
 
    public static void confirmLinkNow(@Nullable Screen parentScreen, URI uri) {
        confirmLinkNow(parentScreen, uri, true);
    }
 
    public static void confirmLinkNow(Screen parentScreen, String uri) {
        confirmLinkNow(parentScreen, uri, true);
    }
 
    public static Button.OnPress confirmLink(Screen parentScreen, String uri, boolean trusted) {
        return button -> confirmLinkNow(parentScreen, uri, trusted);
    }
 
    public static Button.OnPress confirmLink(Screen parentScreen, URI uri, boolean trusted) {
        return button -> confirmLinkNow(parentScreen, uri, trusted);
    }
 
    public static Button.OnPress confirmLink(Screen parentScreen, String uri) {
        return confirmLink(parentScreen, uri, true);
    }
 
    public static Button.OnPress confirmLink(Screen parentScreen, URI uri) {
        return confirmLink(parentScreen, uri, true);
    }
}

引用的其他类

  • Minecraft

    • 引用位置: 方法调用
    • 关联成员: Minecraft.getInstance()
  • Button

    • 引用位置: 方法调用/返回值
    • 关联成员: Button.builder()
  • StringWidget

    • 引用位置: 构造调用
    • 关联成员: StringWidget()
  • LinearLayout

    • 引用位置: 参数
  • ConfirmScreen

    • 引用位置: 继承
  • Screen

    • 引用位置: 参数
  • Component

    • 引用位置: 参数/字段/方法调用
    • 关联成员: Component.literal(), Component.translatable()
  • MutableComponent

    • 引用位置: 返回值
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.getPlatform()