Skip to content

⌨️ Navegação por Teclado & Acessibilidade

ParâmetroEspecificação
Classe do ComponenteCollapsibleCategoryRuleEntry
Interface de Acessibilidadenet.minecraft.client.gui.narration.NarratableEntry
Prioridade de NarraçãoNarrationPriority.HOVERED
Elemento NarradoNarratedElementType.TITLE
Teclas de AlternânciaGLFW_KEY_SPACE, GLFW_KEY_ENTER, GLFW_KEY_KP_ENTER
Tecla de RecolhimentoGLFW_KEY_LEFT (Apenas quando expandido)
Tecla de ExpansãoGLFW_KEY_RIGHT (Apenas quando recolhido)
Retorno SonoroSoundEvents.UI_BUTTON_CLICK (1.0F)

📖 Visão Geral

O Collapsible Game Rules oferece suporte completo à navegação por teclado e leitura de tela, garantindo que jogadores possam configurar o mundo usando teclado, controles ou leitores de tela sem necessidade do mouse.


⌨️ Tabela de Atalhos de Teclado

Quando um cabeçalho está em foco no RuleList, o método keyPressed(KeyEvent event) gerencia as seguintes teclas:

TeclaConstante GLFWAção ExecutadaCondiçãoRetorno Sonoro
EspaçoGLFW_KEY_SPACEAlternar EstadoSempreUI_BUTTON_CLICK
EnterGLFW_KEY_ENTERAlternar EstadoSempreUI_BUTTON_CLICK
Enter NuméricoGLFW_KEY_KP_ENTERAlternar EstadoSempreUI_BUTTON_CLICK
Seta Esquerda (←)GLFW_KEY_LEFTRecolher CategoriaApenas se expanded == trueUI_BUTTON_CLICK
Seta Direita (→)GLFW_KEY_RIGHTExpandir CategoriaApenas se expanded == falseUI_BUTTON_CLICK

⚙️ Implementação Técnica

1. Processamento das Setas

Segue o padrão clássico de árvores hierárquicas de sistemas operacionais:

java
@Override
public boolean keyPressed(KeyEvent event) {
    int keyCode = event.key();
    if (keyCode == GLFW.GLFW_KEY_ENTER || keyCode == GLFW.GLFW_KEY_KP_ENTER || keyCode == GLFW.GLFW_KEY_SPACE) {
        this.toggleAction.run();
        Minecraft.getInstance().getSoundManager()
                .play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
        return true;
    } else if (keyCode == GLFW.GLFW_KEY_LEFT && this.expanded) {
        this.toggleAction.run();
        Minecraft.getInstance().getSoundManager()
                .play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
        return true;
    } else if (keyCode == GLFW.GLFW_KEY_RIGHT && !this.expanded) {
        this.toggleAction.run();
        Minecraft.getInstance().getSoundManager()
                .play(SimpleSoundInstance.forUI(SoundEvents.UI_BUTTON_CLICK, 1.0F));
        return true;
    }
    return super.keyPressed(event);
}

2. Leitor de Tela (updateNarration)

java
@Override
public NarrationPriority narrationPriority() {
    return NarrationPriority.HOVERED;
}

@Override
public void updateNarration(NarrationElementOutput output) {
    output.add(NarratedElementType.TITLE, this.label);
}

🔗 Documentação Relacionada

Official documentation & web portal for Dasik Igaijinn mods.