Skip to content

Commit

Permalink
添加功能,关闭图标缓存
Browse files Browse the repository at this point in the history
  • Loading branch information
TartaricAcid committed Sep 30, 2024
1 parent 539be7a commit f29cd26
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.model.AbstractModelGui;
import com.github.tartaricacid.touhoulittlemaid.client.resource.CustomPackLoader;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.MaidModelInfo;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.tileentity.TileEntityModelSwitcher;
import com.github.tartaricacid.touhoulittlemaid.util.EntityCacheUtil;
Expand Down Expand Up @@ -47,7 +48,7 @@ protected void drawLeftEntity(GuiGraphics graphics, int middleX, int middleY, fl
protected void drawRightEntity(GuiGraphics graphics, int posX, int posY, MaidModelInfo modelItem) {
ResourceLocation cacheIconId = modelItem.getCacheIconId();
var allTextures = Minecraft.getInstance().textureManager.byPath;
if (allTextures.containsKey(cacheIconId)) {
if (MiscConfig.MODEL_ICON_CACHE.get() && allTextures.containsKey(cacheIconId)) {
int textureSize = 24;
graphics.blit(cacheIconId, posX - textureSize / 2, posY - textureSize, textureSize, textureSize, 0, 0, textureSize, textureSize, textureSize, textureSize);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.ChairModelInfo;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.CustomModelPack;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.MaidModelInfo;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.init.InitEntities;
Expand Down Expand Up @@ -42,31 +43,31 @@ public static void addChairPack(CustomModelPack<ChairModelInfo> customModelPack)

public static void openMaidModelGui(EntityMaid maid) {
MaidModelGui maidModelGui = new MaidModelGui(maid);
if (MAID_CACHE_QUEUE.isEmpty()) {
Minecraft.getInstance().setScreen(maidModelGui);
} else {
if (MiscConfig.MODEL_ICON_CACHE.get() && !MAID_CACHE_QUEUE.isEmpty()) {
var maidCacheScreen = getMaidCacheScreen(maidModelGui);
Minecraft.getInstance().setScreen(maidCacheScreen);
} else {
Minecraft.getInstance().setScreen(maidModelGui);
}
}

public static void openChairModelGui(EntityChair chair) {
ChairModelGui chairModelGui = new ChairModelGui(chair);
if (CHAIR_CACHE_QUEUE.isEmpty()) {
Minecraft.getInstance().setScreen(chairModelGui);
} else {
if (MiscConfig.MODEL_ICON_CACHE.get() && !CHAIR_CACHE_QUEUE.isEmpty()) {
var chairCacheScreen = getChairCacheScreen(chairModelGui);
Minecraft.getInstance().setScreen(chairCacheScreen);
} else {
Minecraft.getInstance().setScreen(chairModelGui);
}
}

public static void openModelSwitcherModelGui(EntityMaid maid, TileEntityModelSwitcher.ModeInfo info, ModelSwitcherGui modelSwitcherGui) {
ModelSwitcherModelGui switcherModelGui = new ModelSwitcherModelGui(maid, info, modelSwitcherGui);
if (MAID_CACHE_QUEUE.isEmpty()) {
Minecraft.getInstance().setScreen(switcherModelGui);
} else {
if (MiscConfig.MODEL_ICON_CACHE.get() && !MAID_CACHE_QUEUE.isEmpty()) {
var maidCacheScreen = getMaidCacheScreen(switcherModelGui);
Minecraft.getInstance().setScreen(maidCacheScreen);
} else {
Minecraft.getInstance().setScreen(switcherModelGui);
}
}

Expand All @@ -81,8 +82,8 @@ private static CacheScreen<EntityMaid, MaidModelInfo> getMaidCacheScreen(Abstrac
int scale = scaleModified / 2;
InventoryScreen.renderEntityInInventoryFollowsMouse(graphics,
posX + scale,
posY + scaleModified - 5,
(int) (scale * modelInfo.getRenderItemScale() * 0.9),
posY + scaleModified,
(int) (scale * modelInfo.getRenderItemScale()),
-25, -20, maid);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@
import com.github.tartaricacid.touhoulittlemaid.client.renderer.texture.SizeTexture;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.CustomModelPack;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.IModelInfo;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig;
import com.github.tartaricacid.touhoulittlemaid.util.ParseI18n;
import com.google.common.collect.Lists;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.components.Checkbox;
import net.minecraft.client.gui.components.ImageButton;
import net.minecraft.client.gui.components.Renderable;
import net.minecraft.client.gui.screens.Screen;
Expand Down Expand Up @@ -127,6 +129,18 @@ public void init() {

// 模型包翻页
addScrollButton(startX, startY);

// 添加开启、关闭模型包图标缓存的按钮
MutableComponent enableCache = Component.translatable("gui.touhou_little_maid.skin.enable_cache");
int checkBoxWidth = font.width(enableCache) + 20;
int xOffset = (startX - 256 / 2) / 2 - checkBoxWidth / 2;
this.addRenderableWidget(new Checkbox(xOffset, startY - 101, 20, 20, enableCache, MiscConfig.MODEL_ICON_CACHE.get()) {
@Override
public void onPress() {
super.onPress();
MiscConfig.MODEL_ICON_CACHE.set(this.selected());
}
});
}

private void addModelButton(int startX, int startY) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.detail.ChairModelDetailsGui;
import com.github.tartaricacid.touhoulittlemaid.client.resource.CustomPackLoader;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.ChairModelInfo;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.item.EntityChair;
import com.github.tartaricacid.touhoulittlemaid.network.NetworkHandler;
import com.github.tartaricacid.touhoulittlemaid.network.message.ChairModelMessage;
Expand Down Expand Up @@ -38,7 +39,7 @@ protected void drawLeftEntity(GuiGraphics graphics, int middleX, int middleY, fl
protected void drawRightEntity(GuiGraphics graphics, int posX, int posY, ChairModelInfo modelItem) {
ResourceLocation cacheIconId = modelItem.getCacheIconId();
var allTextures = Minecraft.getInstance().textureManager.byPath;
if (allTextures.containsKey(cacheIconId)) {
if (MiscConfig.MODEL_ICON_CACHE.get() && allTextures.containsKey(cacheIconId)) {
int textureSize = 24;
graphics.blit(cacheIconId, posX - textureSize / 2, posY - textureSize, textureSize, textureSize, 0, 0, textureSize, textureSize, textureSize, textureSize);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.detail.MaidModelDetailsGui;
import com.github.tartaricacid.touhoulittlemaid.client.resource.CustomPackLoader;
import com.github.tartaricacid.touhoulittlemaid.client.resource.pojo.MaidModelInfo;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.MiscConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import com.github.tartaricacid.touhoulittlemaid.network.NetworkHandler;
import com.github.tartaricacid.touhoulittlemaid.network.message.MaidModelMessage;
Expand Down Expand Up @@ -45,7 +46,7 @@ protected void drawLeftEntity(GuiGraphics graphics, int middleX, int middleY, fl
protected void drawRightEntity(GuiGraphics graphics, int posX, int posY, MaidModelInfo modelItem) {
ResourceLocation cacheIconId = modelItem.getCacheIconId();
var allTextures = Minecraft.getInstance().textureManager.byPath;
if (allTextures.containsKey(cacheIconId)) {
if (MiscConfig.MODEL_ICON_CACHE.get() && allTextures.containsKey(cacheIconId)) {
int textureSize = 24;
graphics.blit(cacheIconId, posX - textureSize / 2, posY - textureSize, textureSize, textureSize, 0, 0, textureSize, textureSize, textureSize, textureSize);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public final class MiscConfig {
public static ForgeConfigSpec.BooleanValue CLOSE_OPTIFINE_WARNING;
public static ForgeConfigSpec.IntValue SCARECROW_RANGE;
public static ForgeConfigSpec.BooleanValue USE_NEW_MAID_FAIRY_MODEL;
public static ForgeConfigSpec.BooleanValue MODEL_ICON_CACHE;

public static void init(ForgeConfigSpec.Builder builder) {
builder.push("misc");
Expand Down Expand Up @@ -62,6 +63,9 @@ public static void init(ForgeConfigSpec.Builder builder) {
builder.comment("Whether to use the new version of the Fairy Maid model");
USE_NEW_MAID_FAIRY_MODEL = builder.define("UseNewMaidFairyModel", true);

builder.comment("Whether to enable model icon caching");
MODEL_ICON_CACHE = builder.define("ModelIconCache", true);

builder.pop();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"gui.touhou_little_maid.skin.button.close": "Close",
"gui.touhou_little_maid.skin.tooltips.show_details": "Shift Click To Open The Details GUI",
"gui.touhou_little_maid.skin.tooltips.maid_use_sound_pack_id": "Use Sound Pack: %s",
"gui.touhou_little_maid.skin.enable_cache": "Icon Cache",
"gui.touhou_little_maid.button.home.true": "Home Mode Is Enable",
"gui.touhou_little_maid.button.home.false": "Home Mode Is Disable",
"gui.touhou_little_maid.button.home.desc": "§7Click this button to set whether the maid will follow the player.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@
"gui.touhou_little_maid.skin.button.close": "关闭",
"gui.touhou_little_maid.skin.tooltips.show_details": "Shift 点击打开详情界面",
"gui.touhou_little_maid.skin.tooltips.maid_use_sound_pack_id": "使用声音包:%s",
"gui.touhou_little_maid.skin.enable_cache": "图标缓存",
"gui.touhou_little_maid.button.home.true": "Home 模式已开启(不跟随玩家)",
"gui.touhou_little_maid.button.home.false": "Home 模式已关闭(跟随玩家)",
"gui.touhou_little_maid.button.home.desc": "§7点击此按钮可以设置女仆是否跟随玩家",
Expand Down

0 comments on commit f29cd26

Please sign in to comment.