Search in sources :

Example 21 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project Moonfix by Kingdom-of-Moon.

the class CategoryEntry method render.

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
    // render text
    TextRenderer textRenderer = client.textRenderer;
    int textWidth = client.textRenderer.getWidth(this.title);
    float xPos = client.currentScreen.width / 2f - textWidth / 2f;
    int yPos = y + entryHeight;
    textRenderer.draw(matrices, this.title, xPos, (float) (yPos - 9 - 1), 0xFFFFFF);
}
Also used : TextRenderer(net.minecraft.client.font.TextRenderer)

Example 22 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project Moonfix by Kingdom-of-Moon.

the class EnumEntry method render.

@Override
public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
    // text
    TextRenderer textRenderer = client.textRenderer;
    int posY = y + entryHeight / 2;
    textRenderer.draw(matrices, this.title, (float) x, (float) (posY - 9 / 2), 0xFFFFFF);
    // reset button
    this.reset.x = x + 260;
    this.reset.y = y;
    this.reset.active = !this.config.configValue.equals(this.config.defaultValue);
    this.reset.render(matrices, mouseX, mouseY, tickDelta);
    // toggle button
    this.toggle.x = x + 175;
    this.toggle.y = y;
    this.toggle.setMessage(states.get((int) this.config.configValue % states.size()));
    // if setting is changed
    if ((int) this.config.configValue != this.initValue)
        this.toggle.setMessage(new LiteralText("").styled(ConfigManager.ACCENT_COLOR).append(this.toggle.getMessage()));
    this.toggle.render(matrices, mouseX, mouseY, tickDelta);
}
Also used : TextRenderer(net.minecraft.client.font.TextRenderer) LiteralText(net.minecraft.text.LiteralText)

Example 23 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project RPG-Hud by KurodaAkira.

the class GuiSettingsMod method init.

@Override
public void init() {
    TextRenderer fontRenderer = client.textRenderer;
    if (this.subSetting.equals("")) {
        GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + 0 % 2 * 160, this.height / 6 - 14 + 20 * (0 >> 1), "general", new TranslatableText("gui.rpg.general"), button -> {
            GuiButtonTooltip b = (GuiButtonTooltip) button;
            if (b.enumOptions != null)
                client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
        }).setTooltip(I18n.translate("tooltip.general", new Object[0]));
        this.addDrawableChild(guismallbutton);
        int count = 1;
        for (HudElementType type : HudElementType.values()) {
            List<String> settings = this.settings.getSettingsOf(type);
            if (!settings.isEmpty()) {
                guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + count % 2 * 160, this.height / 6 - 14 + 20 * (count >> 1), type.name(), new TranslatableText(type.getDisplayName()), button -> {
                    GuiButtonTooltip b = (GuiButtonTooltip) button;
                    if (b.enumOptions != null) {
                        this.client.setScreen(new GuiSettingsMod(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
                    }
                }).setTooltip(I18n.translate("tooltip.element", new Object[0]));
                this.addDrawableChild(guismallbutton);
                count++;
            }
        }
    } else {
        List<String> settingList = this.settings.getSettingsOf(this.subSetting);
        for (int i = 0; i < settingList.size(); i++) {
            if (this.settings.getSetting(settingList.get(i)) instanceof SettingPosition) {
                String[] values = ((String) this.settings.getSetting(settingList.get(i)).getValue()).split("_");
                List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
                GuiTextLabel settingLabel = new GuiTextLabel(this.width / 2 - 152 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
                labelList.add(settingLabel);
                TextFieldWidget xPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[0]));
                xPos.setText(values[0]);
                xPos.setMaxLength(6);
                this.addDrawableChild(xPos);
                fields.add(xPos);
                TextFieldWidget yPos = new TextFieldWidgetMod(fontRenderer, ValueType.POSITION, this.width / 2 - 100 + i % 2 * 160 + 48, this.height / 6 - 12 + 20 * (i >> 1), 45, 15, new TranslatableText(values[1]));
                yPos.setText(values[1]);
                yPos.setMaxLength(6);
                this.addDrawableChild(yPos);
                fields.add(yPos);
                textFields.put(settingList.get(i), fields);
            } else if (this.settings.getSetting(settingList.get(i)) instanceof SettingDouble) {
                List<TextFieldWidget> fields = new ArrayList<TextFieldWidget>();
                GuiTextLabel scaleLabel = new GuiTextLabel(this.width / 2 - 151 + i % 2 * 160, this.height / 6 - 8 + 20 * (i >> 1), this.settings.getButtonString(settingList.get(i)));
                TextFieldWidget scale = new TextFieldWidgetMod(fontRenderer, ValueType.DOUBLE, this.width / 2 - 100 + i % 2 * 160 + 3, this.height / 6 - 12 + 20 * (i >> 1), 90, 15, new TranslatableText(String.valueOf(this.settings.getDoubleValue(settingList.get(i)))));
                scale.setText(String.valueOf(this.settings.getDoubleValue(settingList.get(i))));
                labelList.add(scaleLabel);
                this.addDrawableChild(scale);
                fields.add(scale);
                textFields.put(settingList.get(i), fields);
            } else {
                GuiButtonTooltip guismallbutton = new GuiButtonTooltip(this.width / 2 - 155 + i % 2 * 160, this.height / 6 - 14 + 20 * (i >> 1), settingList.get(i), new TranslatableText(this.settings.getButtonString(settingList.get(i))), button -> {
                    GuiButtonTooltip b = (GuiButtonTooltip) button;
                    if (b.enumOptions != null) {
                        if (settings.getSetting(b.enumOptions) instanceof SettingColor) {
                            client.setScreen(new GuiSettingsModColor(instance, b.enumOptions, new TranslatableText("gui.settings.rpghud")));
                        } else {
                            settings.increment(b.enumOptions);
                            button.setMessage(new TranslatableText(settings.getButtonString(b.enumOptions)));
                        }
                    }
                }).setTooltip(this.settings.getSetting(settingList.get(i)).getTooltip());
                this.addDrawableChild(guismallbutton);
            }
        }
    }
    this.addDrawableChild(new ButtonWidget(this.width / 2 - 100, this.height / 6 + 168, 200, 20, new TranslatableText("gui.done"), button -> {
        Settings settings = ModRPGHud.instance.settings;
        for (String settingID : textFields.keySet()) {
            for (TextFieldWidget t : textFields.get(settingID)) {
                if (t instanceof TextFieldWidgetMod) {
                    ValueType type = ((TextFieldWidgetMod) t).getValueType();
                    switch(type) {
                        case DOUBLE:
                            double value;
                            try {
                                value = Double.valueOf(textFields.get(settingID).get(0).getText());
                                this.settings.getSetting(settingID).setValue(value);
                            } catch (NumberFormatException e) {
                            }
                            break;
                        case POSITION:
                            this.settings.getSetting(settingID).setValue(textFields.get(settingID).get(0).getText() + "_" + textFields.get(settingID).get(1).getText());
                            break;
                    }
                }
            }
        }
        settings.saveSettings();
        client.setScreen(parent);
    }));
}
Also used : TranslatableText(net.minecraft.text.TranslatableText) ValueType(net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType) I18n(net.minecraft.client.resource.language.I18n) Environment(net.fabricmc.api.Environment) MatrixStack(net.minecraft.client.util.math.MatrixStack) TranslatableText(net.minecraft.text.TranslatableText) HashMap(java.util.HashMap) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) ArrayList(java.util.ArrayList) List(java.util.List) ModRPGHud(net.spellcraftgaming.rpghud.main.ModRPGHud) SettingColor(net.spellcraftgaming.rpghud.settings.SettingColor) Screen(net.minecraft.client.gui.screen.Screen) Settings(net.spellcraftgaming.rpghud.settings.Settings) DrawableHelper(net.minecraft.client.gui.DrawableHelper) Map(java.util.Map) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) HudElementType(net.spellcraftgaming.rpghud.gui.hud.element.HudElementType) EnvType(net.fabricmc.api.EnvType) SettingPosition(net.spellcraftgaming.rpghud.settings.SettingPosition) Text(net.minecraft.text.Text) TextRenderer(net.minecraft.client.font.TextRenderer) SettingDouble(net.spellcraftgaming.rpghud.settings.SettingDouble) HudElementType(net.spellcraftgaming.rpghud.gui.hud.element.HudElementType) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Settings(net.spellcraftgaming.rpghud.settings.Settings) SettingColor(net.spellcraftgaming.rpghud.settings.SettingColor) ValueType(net.spellcraftgaming.rpghud.gui.TextFieldWidgetMod.ValueType) SettingPosition(net.spellcraftgaming.rpghud.settings.SettingPosition) SettingDouble(net.spellcraftgaming.rpghud.settings.SettingDouble) ButtonWidget(net.minecraft.client.gui.widget.ButtonWidget) TextFieldWidget(net.minecraft.client.gui.widget.TextFieldWidget) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 24 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project KiwiClient by TangyKiwi.

the class InGameHudMixin method render.

@Inject(method = "render", at = @At(value = "TAIL"), cancellable = true)
private void render(CallbackInfo info) {
    if (!MinecraftClient.getInstance().options.debugEnabled) {
        MinecraftClient client = MinecraftClient.getInstance();
        TextRenderer textRenderer = client.textRenderer;
        TextureManager textureManager = client.getTextureManager();
        MatrixStack matrixStack = new MatrixStack();
        RenderSystem.setShaderTexture(0, KiwiClient.DUCK);
        client.inGameHud.drawTexture(matrixStack, 0, 0, 0, 0, 130, 130);
    }
    DrawOverlayEvent event = new DrawOverlayEvent(new MatrixStack());
    KiwiClient.eventBus.post(event);
    if (event.isCancelled())
        info.cancel();
}
Also used : DrawOverlayEvent(com.tangykiwi.kiwiclient.event.DrawOverlayEvent) TextureManager(net.minecraft.client.texture.TextureManager) MatrixStack(net.minecraft.client.util.math.MatrixStack) MinecraftClient(net.minecraft.client.MinecraftClient) TextRenderer(net.minecraft.client.font.TextRenderer)

Example 25 with TextRenderer

use of net.minecraft.client.font.TextRenderer in project meteor-client by MeteorDevelopment.

the class ContainerButtonWidget method renderButton.

@Override
public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
    MinecraftClient minecraftClient = MinecraftClient.getInstance();
    TextRenderer textRenderer = minecraftClient.textRenderer;
    RenderSystem.setShader(GameRenderer::getPositionTexShader);
    RenderSystem.setShaderTexture(0, WIDGETS_TEXTURE);
    RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, alpha);
    RenderSystem.enableBlend();
    RenderSystem.defaultBlendFunc();
    RenderSystem.enableDepthTest();
    int halfWidth = width / 2;
    int halfHeight = height / 2;
    int texY = getYImage(isHovered()) * 20;
    drawTexture(matrices, x, y, 0, 46 + texY, halfWidth, halfHeight);
    drawTexture(matrices, x, y + halfHeight, 0, 46 + texY + 14, halfWidth, halfHeight);
    drawTexture(matrices, x + halfWidth, y, 200 - halfWidth, 46 + texY, halfWidth, halfHeight);
    drawTexture(matrices, x + halfWidth, y + halfHeight, 200 - halfWidth, 46 + texY + 14, halfWidth, halfHeight);
    drawCenteredText(matrices, textRenderer, getMessage(), x + width / 2, (y + height / 2) - 4, active ? 16777215 : 10526880 | MathHelper.ceil(alpha * 255.0F) << 24);
}
Also used : MinecraftClient(net.minecraft.client.MinecraftClient) GameRenderer(net.minecraft.client.render.GameRenderer) TextRenderer(net.minecraft.client.font.TextRenderer)

Aggregations

TextRenderer (net.minecraft.client.font.TextRenderer)45 Point (de.johni0702.minecraft.gui.utils.lwjgl.Point)9 ReadablePoint (de.johni0702.minecraft.gui.utils.lwjgl.ReadablePoint)9 MinecraftClient (net.minecraft.client.MinecraftClient)7 LiteralText (net.minecraft.text.LiteralText)7 Dimension (de.johni0702.minecraft.gui.utils.lwjgl.Dimension)6 ReadableDimension (de.johni0702.minecraft.gui.utils.lwjgl.ReadableDimension)6 TranslatableText (net.minecraft.text.TranslatableText)5 ReadableColor (de.johni0702.minecraft.gui.utils.lwjgl.ReadableColor)3 GameRenderer (net.minecraft.client.render.GameRenderer)3 MatrixStack (net.minecraft.client.util.math.MatrixStack)3 Text (net.minecraft.text.Text)3 ArrayList (java.util.ArrayList)2 List (java.util.List)2 Environment (net.fabricmc.api.Environment)2 InGameHud (net.minecraft.client.gui.hud.InGameHud)2 Screen (net.minecraft.client.gui.screen.Screen)2 BufferBuilder (net.minecraft.client.render.BufferBuilder)2 I18n (net.minecraft.client.resource.language.I18n)2 Sprite (net.minecraft.client.texture.Sprite)2