Подведи собственные итоги года совместно с YOUGAME и забери ценные призы! Перейти

Вопрос Bind система zenith norecode

Начинающий
Начинающий
Статус
Оффлайн
Регистрация
23 Мар 2025
Сообщения
36
Реакции
0
всем привет, я как обычно вайб кодил и столкнулся с такой проблемой -
Пожалуйста, авторизуйтесь для просмотра ссылки.

если коротко, в гуи бинд компонент не реагирует на клавиши (только на мышку)
решил спросить у ии но он мне не чем не помог
кто может подсказать или помочь полностью буду очень благодарен

дс xelvoridze


код
Java:
Expand Collapse Copy
package ru.zenith.implement.screens.menu.components.implement.settings;

import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.util.math.ColorHelper;
import org.lwjgl.glfw.GLFW;
import ru.kotopushka.compiler.sdk.annotations.Compile;
import ru.zenith.api.feature.module.setting.implement.BindSetting;
import ru.zenith.api.system.font.Fonts;
import ru.zenith.api.system.shape.ShapeProperties;
import ru.zenith.common.util.color.ColorUtil;
import ru.zenith.common.util.math.MathUtil;
import ru.zenith.common.util.other.StringUtil;

import static ru.zenith.api.system.font.Fonts.Type.BOLD;

public class BindComponent extends AbstractSettingComponent {
    private final BindSetting setting;
    private boolean binding;

    public BindComponent(BindSetting setting) {
        super(setting);
        this.setting = setting;
    }


    @Override
    public void render(DrawContext context, int mouseX, int mouseY, float delta) {
        MatrixStack matrix = context.getMatrices();

        String bindName = StringUtil.getBindName(setting.getKey());
        String name = binding ? "(" + bindName + ") ..." : bindName;
        float stringWidth = Fonts.getSize(13, BOLD).getStringWidth(name) - 2;
        String wrapped = StringUtil.wrap(setting.getDescription(), (int) (width - stringWidth - 28), 12);

        height = (int) (18 + Fonts.getSize(12).getStringHeight(wrapped) / 3);

        rectangle.render(ShapeProperties.create(matrix, x + width - stringWidth - 17, y + 5, stringWidth + 10, 12)
                .round(2).thickness(2).outlineColor(ColorUtil.getOutline()).color(ColorUtil.getGuiRectColor(1F)).build());

        int bindingColor = ColorHelper.getArgb(255, 135, 136, 148);

        Fonts.getSize(13, BOLD).drawString(matrix, name, x + width - 12 - stringWidth - 1, y + 9.5, bindingColor);
        Fonts.getSize(14, BOLD).drawString(matrix, setting.getName(), x + 9, y + 6, 0xFFD4D6E1);
        Fonts.getSize(12).drawString(matrix, wrapped, x + 9, y + 15, 0xFF878894);
    }


    @Compile
    @Override
    public boolean mouseClicked(double mouseX, double mouseY, int button) {
        if (button == 0) {
            if (MathUtil.isHovered(mouseX, mouseY, x, y, width, height)) {
                binding = !binding;
            } else {
                binding = false;
            }
        }

        if (binding && button > 1) {
            setting.setKey(button);
            binding = false;
        }
        return super.mouseClicked(mouseX, mouseY, button);
    }


    @Override
    public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
        int key = keyCode == GLFW.GLFW_KEY_DELETE ? -1 : keyCode;
        if (binding) {
            setting.setKey(key);
            binding = false;
        }

        return super.keyPressed(keyCode, scanCode, modifiers);
    }
}
 
keyPressed у тебя не вызывается
@override
menu screen public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 && shouldCloseOnEsc()) {
SoundManager.playSound(SoundManager.CLOSE_GUI);
animation.setDirection(BACKWARDS);
return true;
}

if (!windowManager.keyPressed(keyCode, scanCode, modifiers)) {
components.forEach(component -> component.keyPressed(keyCode, scanCode, modifiers));
}
return super.keyPressed(keyCode, scanCode, modifiers);
} вызывается же не?
 
@override
menu screen public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 && shouldCloseOnEsc()) {
SoundManager.playSound(SoundManager.CLOSE_GUI);
animation.setDirection(BACKWARDS);
return true;
}

if (!windowManager.keyPressed(keyCode, scanCode, modifiers)) {
components.forEach(component -> component.keyPressed(keyCode, scanCode, modifiers));
}
return super.keyPressed(keyCode, scanCode, modifiers);
} вызывается же не?
screen.keyPressed у тебя вызывается, но BindComponent.keyPressed нет.
 
Скрытое содержимоеможешь дать блок кода и строку?
java:
Expand Collapse Copy
if (!windowManager.keyPressed(keyCode, scanCode, modifiers)) {
    components.forEach(component -> component.keyPressed(keyCode, scanCode, modifiers));
}
Если windowManager.keyPressed возвращает true, то components.keyPressed вообще не вызывается.
 

Пожалуйста, зарегистрируйтесь или авторизуйтесь, чтобы увидеть содержимое.


@override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 && shouldCloseOnEsc()) {
SoundManager.playSound(SoundManager.CLOSE_GUI);
animation.setDirection(BACKWARDS);
return true;
}

if (windowManager.keyPressed(keyCode, scanCode, modifiers)) {
return true;
}

boolean handledByComponent = false;
for (Component component : components) {
if (component.keyPressed(keyCode, scanCode, modifiers)) {
handledByComponent = true;
}
}

if (handledByComponent) {
return true;
}

return super.keyPressed(keyCode, scanCode, modifiers);
} вроде вызвал но все равно не работает
 
Скрытое содержимое
@override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 && shouldCloseOnEsc()) {
SoundManager.playSound(SoundManager.CLOSE_GUI);
animation.setDirection(BACKWARDS);
return true;
}

if (windowManager.keyPressed(keyCode, scanCode, modifiers)) {
return true;
}

boolean handledByComponent = false;
for (Component component : components) {
if (component.keyPressed(keyCode, scanCode, modifiers)) {
handledByComponent = true;
}
}

if (handledByComponent) {
return true;
}

return super.keyPressed(keyCode, scanCode, modifiers);
} вроде вызвал но все равно не работает
Вызвать то ты вызвал, но windowManager.keyPressed перехватывает клавиши раньше бинда,
а BindComponent.keyPressed всегда возвращает false, даже когда обрабатывает клавишу
 

Пожалуйста, зарегистрируйтесь или авторизуйтесь, чтобы увидеть содержимое.


bind component @override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
int key = keyCode == GLFW.GLFW_KEY_DELETE ? -1 : keyCode;
if (binding) {
setting.setKey(key);
binding = true;
}

return super.keyPressed(keyCode, scanCode, modifiers);
}

menu screen
@override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
if (keyCode == 256 && shouldCloseOnEsc()) {
SoundManager.playSound(SoundManager.CLOSE_GUI);
animation.setDirection(BACKWARDS);
return true;
}

for (Component component : components) {
if (component.keyPressed(keyCode, scanCode, modifiers)) {
return true;
}
}

return super.keyPressed(keyCode, scanCode, modifiers);
} ничего не поменялось
 
джава:
Expand Collapse Copy
@Override
public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
    if (!binding) return false;

    int key = keyCode == GLFW.GLFW_KEY_DELETE ? -1 : keyCode;
    setting.setKey(key);
    binding = false;

    return true;
}
вот так попробуй
 

Пожалуйста, зарегистрируйтесь или авторизуйтесь, чтобы увидеть содержимое.

не помогло, этого не было но после того как я сделал что бы в гуи было 3 панели в ряд и переписал категории появилась эта штука, я переносил с дефолт сурсов бинд компонент но не помогло
 
Назад
Сверху Снизу