Skip to content

Commit

Permalink
🎨 update
Browse files Browse the repository at this point in the history
  • Loading branch information
kitUIN committed Aug 12, 2024
1 parent 28b78d7 commit c06ef2d
Show file tree
Hide file tree
Showing 7 changed files with 297 additions and 29 deletions.
50 changes: 50 additions & 0 deletions .idea/ModAliasState.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package io.github.kituin.chatimage.gui;

import io.github.kituin.chatimage.widget.SettingSliderWidget;

import java.util.function.Consumer;


public abstract class ConfigRawScreen extends #Screen# {
protected #Screen# parent;

protected ConfigRawScreen(#Component# title, #Screen# screen) {
super(title);
this.parent = screen;
}
public void render(#GuiGraphics# matrixStack, int mouseX, int mouseY, float partialTicks) {
super.render(matrixStack, mouseX, mouseY, partialTicks);
// IF <= forge-1.19
// renderBackground(matrixStack);
// drawCenteredString(matrixStack, this.font,
// title, this.width / 2, this.height / 4 - 16, 16764108);
// ELSE
// renderBackground(matrixStack, mouseX, mouseY, partialTicks);
// matrixStack.drawCenteredString(this.font,
// title, this.width / 2, this.height / 4 - 16, 16764108);
// END IF

}
protected SettingSliderWidget.OnTooltip createSliderTooltip(#Component# text) {
return new SettingSliderWidget.OnTooltip() {
public void onTooltip(SettingSliderWidget p_93753_, #GuiGraphics# p_283427_, int p_281447_, int p_282852_) {
if (text != null) {
// IF <= forge-1.19
// ConfigRawScreen.this.renderTooltip(p_283427_, ConfigRawScreen.this.font.split(text, Math.max(ConfigRawScreen.this.width / 2 - 43, 170)), p_281447_, p_282852_);
// ELSE
// p_283427_.renderTooltip(ConfigRawScreen.this.font, ConfigRawScreen.this.font.split(text, Math.max(ConfigRawScreen.this.width / 2 - 43, 170)), p_281447_, p_282852_);
// END IF
}
}

public void narrateTooltip(Consumer<#Component#> p_168842_) {
p_168842_.accept(text);
}
};
}
// IF <= forge-1.19
// protected #Button.OnTooltip# createButtonTooltip(#Component# text) {
// return new #Button.OnTooltip#() {
// public void onTooltip(#Button# p_93753_, #GuiGraphics# p_93754_, int p_93755_, int p_93756_) {
// if (text != null) {
// ConfigRawScreen.this.renderTooltip(p_93754_, ConfigRawScreen.this.font.split(text, Math.max(ConfigRawScreen.this.width / 2 - 43, 170)), p_93755_, p_93756_);
// }
// }
//
// };
// }
// END IF
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package io.github.kituin.chatimage.gui;

import io.github.kituin.ChatImageCode.ChatImageConfig;
import io.github.kituin.chatimage.widget.GifSlider;
import io.github.kituin.chatimage.widget.TimeOutSlider;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import static io.github.kituin.chatimage.ChatImage.CONFIG;
import static io.github.kituin.chatimage.tool.SimpleUtil.createTranslatableComponent;
import static io.github.kituin.chatimage.tool.SimpleUtil.composeGenericOptionComponent;
import static io.github.kituin.chatimage.tool.SimpleUtil.createButton;
@OnlyIn(Dist.CLIENT)
public class ConfigScreen extends ConfigRawScreen {
public ConfigScreen(#Screen# screen) {
super(createTranslatableComponent("config.chatimage.category"), screen);
}

protected void init() {
super.init();
this.#kituin$addRenderableWidget#(createButton(this.width / 2 - 154, this.height / 4 + 24 - 16, 150, 20, getNsfw(CONFIG.nsfw), (p_96270_) -> {
CONFIG.nsfw = !CONFIG.nsfw;
p_96270_.setMessage(getNsfw(CONFIG.nsfw));
ChatImageConfig.saveConfig(CONFIG);
}, #kituin$createButtonTooltip#(createTranslatableComponent("nsfw.chatimage.tooltip"))));
this.#kituin$addRenderableWidget#(new GifSlider(this.width / 2 + 4, this.height / 4 + 24 - 16, 150, 20, createSliderTooltip(GifSlider.tooltip())));
this.#kituin$addRenderableWidget#(new TimeOutSlider(this.width / 2 - 154, this.height / 4 + 48 - 16, 150, 20, createSliderTooltip(TimeOutSlider.tooltip())));
this.#kituin$addRenderableWidget#(createButton(this.width / 2 + 4, this.height / 4 + 48 - 16, 150, 20,
createTranslatableComponent("padding.chatimage.gui"),
(button) -> {
if (this.minecraft != null) {
this.minecraft.setScreen(new LimitPaddingScreen(this));
}
},
#kituin$createButtonTooltip#(createTranslatableComponent("padding.chatimage.tooltip"))));
this.#kituin$addRenderableWidget#(createButton(this.width / 2 - 154, this.height / 4 + 72 - 16, 150, 20, getCq(CONFIG.cqCode), (button) -> {
CONFIG.cqCode = !CONFIG.cqCode;
button.setMessage(getCq(CONFIG.cqCode));
ChatImageConfig.saveConfig(CONFIG);
}, #kituin$createButtonTooltip#(createTranslatableComponent("cq.chatimage.tooltip"))));
this.#kituin$addRenderableWidget#(createButton(this.width / 2 + 4, this.height / 4 + 72 - 16, 150, 20,getDrag(CONFIG.dragUseCicode), (button) -> {
CONFIG.dragUseCicode = !CONFIG.dragUseCicode;
button.setMessage(getDrag(CONFIG.dragUseCicode));
ChatImageConfig.saveConfig(CONFIG);
},#kituin$createButtonTooltip#(createTranslatableComponent("drag.chatimage.tooltip"))));
this.#kituin$addRenderableWidget#(createButton(this.width / 2 - 154, this.height / 4 + 96 - 16, 150, 20,getUri(CONFIG.checkImageUri), (button) -> {
CONFIG.checkImageUri = !CONFIG.checkImageUri;
button.setMessage(getUri(CONFIG.checkImageUri));
ChatImageConfig.saveConfig(CONFIG);
}));
this.#kituin$addRenderableWidget#(createButton(this.width / 2 - 77, this.height / 4 + 120 - 16, 150, 20,
createTranslatableComponent("gui.back"),
(button) -> {
if (this.minecraft != null) {
this.minecraft.setScreen(this.parent);
}
}));
}

private #MutableComponent# getCq(boolean enable) {
return getEnable( "cq.chatimage.gui", enable);
}
private #MutableComponent# getNsfw(boolean enable) {
return getEnable( "nsfw.chatimage.gui", !enable);
}
private #MutableComponent# getDrag(boolean enable) {
return getEnable("drag.chatimage.gui", enable);
}
private #MutableComponent# getUri(boolean enable) {
return getEnable("uri.chatimage.gui", enable);
}
public static #MutableComponent# getEnable(String key, boolean enable)
{
return composeGenericOptionComponent(createTranslatableComponent(key), createTranslatableComponent((enable ? "open" : "close") + ".chatimage.common"));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package io.github.kituin.chatimage.gui;

import it.unimi.dsi.fastutil.booleans.BooleanConsumer;
import net.minecraft.client.gui.screens.ConfirmScreen;
import net.minecraft.network.chat.CommonComponents;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import static io.github.kituin.chatimage.tool.SimpleUtil.*;

@OnlyIn(Dist.CLIENT)
public class ConfirmNsfwScreen extends ConfirmScreen {

public ConfirmNsfwScreen(BooleanConsumer callback, String link) {
this(callback, createTranslatableComponent("nsfw.chatimage.open"), createLiteralComponent(link));
}

public ConfirmNsfwScreen(BooleanConsumer callback, #Component# title, #Component# message) {
super(callback, title, message);
this.yesButton = CommonComponents.GUI_YES;
this.noButton = CommonComponents.GUI_NO;
}

@Override
protected void addButtons(int y) {
this.#kituin$addRenderableWidget#(createButton(this.width / 2 - 50 - 52, y, 100, 20, this.yesButton,
(button) -> this.callback.accept(true)));
this.#kituin$addRenderableWidget#(createButton(this.width / 2 - 50 + 52, y, 100, 20, this.noButton,
(button) -> this.callback.accept(false)));
}

@Override
public void render(#GuiGraphics# matrixStack, int mouseX, int mouseY, float partialTicks) {
super.render(matrixStack, mouseX, mouseY, partialTicks);
// IF <= forge-1.19
// renderBackground(matrixStack);
// drawCenteredString(matrixStack, this.font,
// title, this.width / 2, this.height / 4 - 16, 16764108);
// ELSE
// renderBackground(matrixStack, mouseX, mouseY, partialTicks);
// matrixStack.drawCenteredString(this.font,
// createTranslatableComponent("nsfw.chatimage.warning"), this.width / 2, 110, 16764108);
// END IF
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package io.github.kituin.chatimage.gui;

import io.github.kituin.chatimage.widget.LimitSlider;
import io.github.kituin.chatimage.widget.PaddingSlider;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;

import static io.github.kituin.chatimage.ChatImage.CONFIG;
import static io.github.kituin.chatimage.tool.SimpleUtil.createTranslatableComponent;
import static io.github.kituin.chatimage.tool.SimpleUtil.createButton;

@OnlyIn(Dist.CLIENT)
public class LimitPaddingScreen extends ConfigRawScreen {


public LimitPaddingScreen(#Screen# screen) {
super(createTranslatableComponent("padding.chatimage.gui"), screen);
}

protected void init() {
super.init();

#kituin$addRenderableWidget#(new PaddingSlider(this.width / 2 - 154, this.height / 4 + 24 + -16, 150, 20, createTranslatableComponent("left.padding.chatimage.gui"),
CONFIG.paddingLeft, (float) this.width / 2, PaddingSlider.PaddingType.LEFT, createSliderTooltip(PaddingSlider.tooltip(PaddingSlider.PaddingType.LEFT))));
#kituin$addRenderableWidget#(new PaddingSlider(this.width / 2 + 4, this.height / 4 + 24 + -16, 150, 20, createTranslatableComponent("right.padding.chatimage.gui"),
CONFIG.paddingRight, (float) this.width / 2, PaddingSlider.PaddingType.RIGHT, createSliderTooltip(PaddingSlider.tooltip(PaddingSlider.PaddingType.RIGHT))));
#kituin$addRenderableWidget#(new PaddingSlider(this.width / 2 - 154, this.height / 4 + 48 + -16, 150, 20, createTranslatableComponent("top.padding.chatimage.gui"),
CONFIG.paddingTop, (float) this.height / 2, PaddingSlider.PaddingType.TOP, createSliderTooltip(PaddingSlider.tooltip(PaddingSlider.PaddingType.TOP))));
#kituin$addRenderableWidget#(new PaddingSlider(this.width / 2 + 4, this.height / 4 + 48 + -16, 150, 20, createTranslatableComponent("bottom.padding.chatimage.gui"),
CONFIG.paddingBottom, (float) this.height / 2, PaddingSlider.PaddingType.BOTTOM, createSliderTooltip(PaddingSlider.tooltip(PaddingSlider.PaddingType.BOTTOM))));
#kituin$addRenderableWidget#(new LimitSlider(this.width / 2 - 154, this.height / 4 + 72 + -16, 150, 20, createTranslatableComponent("width.limit.chatimage.gui"),
CONFIG.limitWidth, this.width, LimitSlider.LimitType.WIDTH, createSliderTooltip(LimitSlider.tooltip(LimitSlider.LimitType.WIDTH))));
#kituin$addRenderableWidget#(new LimitSlider(this.width / 2 + 4, this.height / 4 + 72 + -16, 150, 20, createTranslatableComponent("height.limit.chatimage.gui"),
CONFIG.limitHeight, this.height, LimitSlider.LimitType.HEIGHT, createSliderTooltip(LimitSlider.tooltip(LimitSlider.LimitType.HEIGHT))));
#kituin$addRenderableWidget#(createButton(this.width / 2 - 77, this.height / 4 + 96 - 16, 150, 20,
createTranslatableComponent("gui.back"),
(button) -> {
if (this.minecraft != null) {
this.minecraft.setScreen(this.parent);
}
}));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

// IF forge-1.16.5
//import net.minecraft.util.text.*;
// ELSE IF forge-1.18.2
import net.minecraft.network.chat.*;
// ELSE
//import net.minecraft.network.chat.*;
// END IF

public class SimpleUtil {
Expand Down Expand Up @@ -42,6 +42,22 @@ public class SimpleUtil {
// return new TranslationTextComponent("options.generic_value", text, value);
// ELSE
// return net.minecraft.network.chat.CommonComponents.optionNameValue(text, value);
// END IF
}

public static #Button# createButton(int pX, int pY, int pWidth, int pHeight, #Component# pMessage, #Button#.OnPress pOnPress, #Button.OnTooltip# pOnTooltip){
// IF >= forge-1.20
// return #Button#.builder(pMessage, pOnPress).bounds(pX, pY, pWidth, pHeight).tooltip(pOnTooltip).build();
// ELSE
// return #Button#(pX, pY, pWidth, pHeight, pMessage, pOnPress, pOnTooltip);
// END IF
}

public static #Button# createButton(int pX, int pY, int pWidth, int pHeight, #Component# pMessage, #Button#.OnPress pOnPress){
// IF >= forge-1.20
// return #Button#.builder(pMessage, pOnPress).bounds(pX, pY, pWidth, pHeight).build();
// ELSE
// return #Button#(pX, pY, pWidth, pHeight, pMessage, pOnPress);
// END IF
}
}
Loading

0 comments on commit c06ef2d

Please sign in to comment.