KeyBindsList.java
net.minecraft.client.gui.screens.options.controls.KeyBindsList
信息
- 全限定名:net.minecraft.client.gui.screens.options.controls.KeyBindsList
- 类型:public class
- 包:net.minecraft.client.gui.screens.options.controls
- 源码路径:src/main/java/net/minecraft/client/gui/screens/options/controls/KeyBindsList.java
- 起始行号:L24
- 继承:ContainerObjectSelectionList<KeyBindsList.Entry>
- 职责:
TODO
字段/常量
-
ITEM_HEIGHT- 类型:
int - 修饰符:
private static final - 源码定位:
L25 - 说明:
TODO
- 类型:
-
keyBindsScreen- 类型:
KeyBindsScreen - 修饰符:
private final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
maxNameWidth- 类型:
int - 修饰符:
private - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.client.gui.screens.options.controls.KeyBindsList.CategoryEntry- 类型:
class - 修饰符:
public - 源码定位:
L68 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.options.controls.KeyBindsList.Entry- 类型:
class - 修饰符:
public abstract static - 源码定位:
L103 - 说明:
TODO
- 类型:
-
net.minecraft.client.gui.screens.options.controls.KeyBindsList.KeyEntry- 类型:
class - 修饰符:
public - 源码定位:
L108 - 说明:
TODO
- 类型:
构造器
public KeyBindsList(KeyBindsScreen keyBindsScreen, Minecraft minecraft) @ L29
- 构造器名:KeyBindsList
- 源码定位:L29
- 修饰符:public
参数:
- keyBindsScreen: KeyBindsScreen
- minecraft: Minecraft
说明:
TODO
方法
下面的方法块按源码顺序生成。
public void resetMappingAndUpdateButtons() @ L53
- 方法名:resetMappingAndUpdateButtons
- 源码定位:L53
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public void refreshEntries() @ L58
- 方法名:refreshEntries
- 源码定位:L58
- 返回类型:void
- 修饰符:public
参数:
- 无
说明:
TODO
public int getRowWidth() @ L62
- 方法名:getRowWidth
- 源码定位:L62
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
代码
@OnlyIn(Dist.CLIENT)
public class KeyBindsList extends ContainerObjectSelectionList<KeyBindsList.Entry> {
private static final int ITEM_HEIGHT = 20;
private final KeyBindsScreen keyBindsScreen;
private int maxNameWidth;
public KeyBindsList(KeyBindsScreen keyBindsScreen, Minecraft minecraft) {
super(minecraft, keyBindsScreen.width, keyBindsScreen.layout.getContentHeight(), keyBindsScreen.layout.getHeaderHeight(), 20);
this.keyBindsScreen = keyBindsScreen;
KeyMapping[] keyMappings = ArrayUtils.clone((KeyMapping[])minecraft.options.keyMappings);
Arrays.sort((Object[])keyMappings);
KeyMapping.Category previousCategory = null;
for (KeyMapping key : keyMappings) {
KeyMapping.Category category = key.getCategory();
if (category != previousCategory) {
previousCategory = category;
this.addEntry(new KeyBindsList.CategoryEntry(category));
}
Component name = Component.translatable(key.getName());
int width = minecraft.font.width(name);
if (width > this.maxNameWidth) {
this.maxNameWidth = width;
}
this.addEntry(new KeyBindsList.KeyEntry(key, name));
}
}
public void resetMappingAndUpdateButtons() {
KeyMapping.resetMapping();
this.refreshEntries();
}
public void refreshEntries() {
this.children().forEach(KeyBindsList.Entry::refreshEntry);
}
@Override
public int getRowWidth() {
return 340;
}
@OnlyIn(Dist.CLIENT)
public class CategoryEntry extends KeyBindsList.Entry {
private final FocusableTextWidget categoryName;
public CategoryEntry(KeyMapping.Category category) {
Objects.requireNonNull(KeyBindsList.this);
super();
this.categoryName = FocusableTextWidget.builder(category.label(), KeyBindsList.this.minecraft.font)
.alwaysShowBorder(false)
.backgroundFill(FocusableTextWidget.BackgroundFill.ON_FOCUS)
.build();
}
@Override
public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
this.categoryName
.setPosition(KeyBindsList.this.width / 2 - this.categoryName.getWidth() / 2, this.getContentBottom() - this.categoryName.getHeight());
this.categoryName.extractRenderState(graphics, mouseX, mouseY, a);
}
@Override
public List<? extends GuiEventListener> children() {
return List.of(this.categoryName);
}
@Override
public List<? extends NarratableEntry> narratables() {
return List.of(this.categoryName);
}
@Override
protected void refreshEntry() {
}
}
@OnlyIn(Dist.CLIENT)
public abstract static class Entry extends ContainerObjectSelectionList.Entry<KeyBindsList.Entry> {
abstract void refreshEntry();
}
@OnlyIn(Dist.CLIENT)
public class KeyEntry extends KeyBindsList.Entry {
private static final Component RESET_BUTTON_TITLE = Component.translatable("controls.reset");
private static final int PADDING = 10;
private final KeyMapping key;
private final Component name;
private final Button changeButton;
private final Button resetButton;
private boolean hasCollision;
private KeyEntry(KeyMapping key, Component name) {
Objects.requireNonNull(KeyBindsList.this);
super();
this.hasCollision = false;
this.key = key;
this.name = name;
this.changeButton = Button.builder(name, button -> {
KeyBindsList.this.keyBindsScreen.selectedKey = key;
KeyBindsList.this.resetMappingAndUpdateButtons();
})
.bounds(0, 0, 75, 20)
.createNarration(
defaultNarrationSupplier -> key.isUnbound()
? Component.translatable("narrator.controls.unbound", name)
: Component.translatable("narrator.controls.bound", name, defaultNarrationSupplier.get())
)
.build();
this.resetButton = Button.builder(RESET_BUTTON_TITLE, button -> {
key.setKey(key.getDefaultKey());
KeyBindsList.this.resetMappingAndUpdateButtons();
}).bounds(0, 0, 50, 20).createNarration(defaultNarrationSupplier -> Component.translatable("narrator.controls.reset", name)).build();
this.refreshEntry();
}
@Override
public void extractContent(GuiGraphicsExtractor graphics, int mouseX, int mouseY, boolean hovered, float a) {
int resetButtonX = KeyBindsList.this.scrollBarX() - this.resetButton.getWidth() - 10;
int buttonY = this.getContentY() - 2;
this.resetButton.setPosition(resetButtonX, buttonY);
this.resetButton.extractRenderState(graphics, mouseX, mouseY, a);
int changeButtonX = resetButtonX - 5 - this.changeButton.getWidth();
this.changeButton.setPosition(changeButtonX, buttonY);
this.changeButton.extractRenderState(graphics, mouseX, mouseY, a);
graphics.text(KeyBindsList.this.minecraft.font, this.name, this.getContentX(), this.getContentYMiddle() - 9 / 2, -1);
if (this.hasCollision) {
int stripeWidth = 3;
int stripeLeft = this.changeButton.getX() - 6;
graphics.fill(stripeLeft, this.getContentY() - 1, stripeLeft + 3, this.getContentBottom(), -256);
}
}
@Override
public List<? extends GuiEventListener> children() {
return ImmutableList.of(this.changeButton, this.resetButton);
}
@Override
public List<? extends NarratableEntry> narratables() {
return ImmutableList.of(this.changeButton, this.resetButton);
}
@Override
protected void refreshEntry() {
this.changeButton.setMessage(this.key.getTranslatedKeyMessage());
this.resetButton.active = !this.key.isDefault();
this.hasCollision = false;
MutableComponent tooltip = Component.empty();
if (!this.key.isUnbound()) {
for (KeyMapping otherKey : KeyBindsList.this.minecraft.options.keyMappings) {
if (otherKey != this.key && this.key.same(otherKey) && (!otherKey.isDefault() || !this.key.isDefault())) {
if (this.hasCollision) {
tooltip.append(", ");
}
this.hasCollision = true;
tooltip.append(Component.translatable(otherKey.getName()));
}
}
}
if (this.hasCollision) {
this.changeButton
.setMessage(
Component.literal("[ ")
.append(this.changeButton.getMessage().copy().withStyle(ChatFormatting.WHITE))
.append(" ]")
.withStyle(ChatFormatting.YELLOW)
);
this.changeButton.setTooltip(Tooltip.create(Component.translatable("controls.keybinds.duplicateKeybinds", tooltip)));
} else {
this.changeButton.setTooltip(null);
}
if (KeyBindsList.this.keyBindsScreen.selectedKey == this.key) {
this.changeButton
.setMessage(
Component.literal("> ")
.append(this.changeButton.getMessage().copy().withStyle(ChatFormatting.WHITE, ChatFormatting.UNDERLINE))
.append(" <")
.withStyle(ChatFormatting.YELLOW)
);
}
}
}
}引用的其他类
-
- 引用位置:
方法调用 - 关联成员:
KeyMapping.resetMapping()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Button.builder()
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FocusableTextWidget.builder()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Tooltip.create()
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Component.empty(), Component.literal(), Component.translatable()
- 引用位置: