Skip to content

Commit

Permalink
完成女仆 GUI 的修改
Browse files Browse the repository at this point in the history
- GUI 按钮重新调整优化
- 增加女仆配置界面,现在配置界面功能全面,设置仅用于当前女仆
  • Loading branch information
TartaricAcid committed Oct 14, 2024
1 parent 4786d32 commit 5829bc3
Show file tree
Hide file tree
Showing 47 changed files with 920 additions and 518 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.github.tartaricacid.touhoulittlemaid.client.event;

import com.github.tartaricacid.touhoulittlemaid.client.sound.data.MaidSoundInstance;
import com.github.tartaricacid.touhoulittlemaid.config.subconfig.InGameMaidConfig;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.EntityMaid;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.sound.PlaySoundEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
Expand All @@ -12,7 +12,12 @@ public class MaidSoundFreqEvent {
@SubscribeEvent
public static void onPlaySoundEvent(PlaySoundEvent event) {
if (event.getSound() instanceof MaidSoundInstance maidSoundInstance) {
double soundFrequency = InGameMaidConfig.INSTANCE.getSoundFrequency();
EntityMaid maid = maidSoundInstance.getMaid();
if (maid == null) {
event.setSound(null);
return;
}
double soundFrequency = maid.getConfigManager().getSoundFreq();
if (soundFrequency < 1 && !maidSoundInstance.isTestSound()) {
if (Math.random() > soundFrequency) {
event.setSound(null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraft.world.entity.player.Inventory;
import net.minecraftforge.fml.ModList;

import javax.annotation.Nullable;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -59,7 +58,6 @@ public abstract class AbstractMaidContainerGui<T extends AbstractMaidContainer>
private static final int TASK_COUNT_PER_PAGE = 12;
private static int TASK_PAGE = 0;
private static boolean TASK_LIST_OPEN = false;
@Nullable
protected final EntityMaid maid;
protected final IMaidTask task;
private StateSwitchingButton home;
Expand Down Expand Up @@ -610,6 +608,6 @@ private void addSideTabsButton() {

// 绘制侧边栏底部贴图
private void drawSideTabGui(GuiGraphics graphics, float partialTicks, int x, int y) {
graphics.blit(SIDE, leftPos + 251 + 5, topPos + 28 + 9, 235, 107, 21, 99);
graphics.blit(SIDE, leftPos + 251 + 5, topPos + 28 + 9, 235, 107, 21, 50);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid;

import com.github.tartaricacid.touhoulittlemaid.api.event.client.OpenPatchouliBookEvent;
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.task.MaidTaskConfigGui;
import com.github.tartaricacid.touhoulittlemaid.client.gui.mod.ClothConfigScreen;
import com.github.tartaricacid.touhoulittlemaid.client.gui.mod.PatchouliWarningScreen;
import com.github.tartaricacid.touhoulittlemaid.client.gui.widget.button.MaidSideTabButton;
Expand All @@ -10,8 +9,6 @@
import com.github.tartaricacid.touhoulittlemaid.entity.passive.SideTab;
import com.github.tartaricacid.touhoulittlemaid.init.registry.CompatRegistry;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.AbstractMaidContainer;
import com.github.tartaricacid.touhoulittlemaid.network.NetworkHandler;
import com.github.tartaricacid.touhoulittlemaid.network.message.ToggleSideTabMessage;
import net.minecraft.client.gui.components.Button;
import net.minecraft.network.chat.Component;
import net.minecraftforge.common.MinecraftForge;
Expand All @@ -34,17 +31,6 @@ public MaidSideTabs(int entityId, int rightPos, int topPos) {
}

public MaidSideTabButton[] getTabs(AbstractMaidContainerGui<T> screen) {
// 任务配置界面按钮
MaidSideTabButton taskConfig = genSideTabButton(SideTab.TASK_CONFIG, b -> {
EntityMaid maid = screen.getMaid();
if (maid != null) {
NetworkHandler.CHANNEL.sendToServer(new ToggleSideTabMessage(entityId, SideTab.TASK_CONFIG.getIndex(), maid.getTask().getUid()));
}
});
if (screen instanceof MaidTaskConfigGui<?>) {
taskConfig.active = false;
}

// 跳转帕秋莉手册按钮
MaidSideTabButton taskBook = genSideTabButton(SideTab.TASK_BOOK, (b) -> {
if (ModList.get().isLoaded(CompatRegistry.PATCHOULI)) {
Expand All @@ -57,11 +43,6 @@ public MaidSideTabButton[] getTabs(AbstractMaidContainerGui<T> screen) {
}
});

// TODO: 未完成信息界面内容
// 任务信息界面按钮
MaidSideTabButton taskInfo = genSideTabButton(SideTab.TASK_INFO, (b) -> {
});

// 跳转全局配置按钮
MaidSideTabButton globalConfig = genSideTabButton(SideTab.GLOBAL_CONFIG, (b) -> {
if (ModList.get().isLoaded(CompatRegistry.CLOTH_CONFIG)) {
Expand All @@ -71,7 +52,7 @@ public MaidSideTabButton[] getTabs(AbstractMaidContainerGui<T> screen) {
}
});

return new MaidSideTabButton[]{taskConfig, taskBook, taskInfo, globalConfig};
return new MaidSideTabButton[]{taskBook, globalConfig};
}

private MaidSideTabButton genSideTabButton(SideTab sideTab, Button.OnPress onPressIn) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid;

import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.backpack.IBackpackContainerScreen;
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.config.MaidConfigContainerGui;
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.task.MaidTaskConfigGui;
import com.github.tartaricacid.touhoulittlemaid.client.gui.widget.button.MaidTabButton;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.TabIndex;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.AbstractMaidContainer;
Expand All @@ -19,18 +21,24 @@ public MaidTabs(int entityId, int leftPos, int topPos) {
}

public MaidTabButton[] getTabs(AbstractMaidContainerGui<T> screen) {
MaidTabButton main = new MaidTabButton(leftPos + 94, topPos + 5, 107, (b) ->
NetworkHandler.CHANNEL.sendToServer(new ToggleTabMessage(entityId, TabIndex.MAIN)));
MaidTabButton main = new MaidTabButton(leftPos + 94, topPos + 5, 107, "main",
(b) -> NetworkHandler.CHANNEL.sendToServer(new ToggleTabMessage(entityId, TabIndex.MAIN)));
if (screen instanceof IBackpackContainerScreen) {
main.active = false;
}

MaidTabButton config = new MaidTabButton(leftPos + 219, topPos + 5, 232, (b) ->
NetworkHandler.CHANNEL.sendToServer(new ToggleTabMessage(entityId, TabIndex.CONFIG)));
MaidTabButton taskConfig = new MaidTabButton(leftPos + 119, topPos + 5, 132, "task_config",
(b) -> NetworkHandler.CHANNEL.sendToServer(new ToggleTabMessage(entityId, TabIndex.TASK_CONFIG)));
if (screen instanceof MaidTaskConfigGui<?>) {
taskConfig.active = false;
}

MaidTabButton maidConfig = new MaidTabButton(leftPos + 144, topPos + 5, 157, "maid_config",
(b) -> NetworkHandler.CHANNEL.sendToServer(new ToggleTabMessage(entityId, TabIndex.MAID_CONFIG)));
if (screen instanceof MaidConfigContainerGui) {
config.active = false;
maidConfig.active = false;
}

return new MaidTabButton[]{main, config};
return new MaidTabButton[]{main, taskConfig, maidConfig};
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,137 @@
package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.config;

import com.github.tartaricacid.touhoulittlemaid.TouhouLittleMaid;
import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.AbstractMaidContainerGui;
import com.github.tartaricacid.touhoulittlemaid.client.gui.widget.button.MaidConfigButton;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.MaidConfigManager;
import com.github.tartaricacid.touhoulittlemaid.entity.passive.PickType;
import com.github.tartaricacid.touhoulittlemaid.inventory.container.config.MaidConfigContainer;
import com.github.tartaricacid.touhoulittlemaid.network.NetworkHandler;
import com.github.tartaricacid.touhoulittlemaid.network.message.MaidSubConfigMessage;
import net.minecraft.ChatFormatting;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.player.Inventory;
import org.anti_ad.mc.ipn.api.IPNButton;
import org.anti_ad.mc.ipn.api.IPNGuiHint;
import org.anti_ad.mc.ipn.api.IPNPlayerSideOnly;

@IPNPlayerSideOnly
@IPNGuiHint(button = IPNButton.SORT, horizontalOffset = -36, bottom = -12)
@IPNGuiHint(button = IPNButton.SORT_COLUMNS, horizontalOffset = -24, bottom = -24)
@IPNGuiHint(button = IPNButton.SORT_ROWS, horizontalOffset = -12, bottom = -36)
@IPNGuiHint(button = IPNButton.SHOW_EDITOR, horizontalOffset = -5)
@IPNGuiHint(button = IPNButton.SETTINGS, horizontalOffset = -5)
public class MaidConfigContainerGui extends AbstractMaidContainerGui<MaidConfigContainer> {
private static final ResourceLocation ICON = new ResourceLocation(TouhouLittleMaid.MOD_ID, "textures/gui/maid_gui_config.png");
private final MaidConfigManager.SyncNetwork syncNetwork;

public MaidConfigContainerGui(MaidConfigContainer screenContainer, Inventory inv, Component titleIn) {
super(screenContainer, inv, titleIn);
this.syncNetwork = getMaid().getConfigManager().getSyncNetwork();
}

@Override
protected void renderBg(GuiGraphics graphics, float partialTicks, int x, int y) {
super.renderBg(graphics, partialTicks, x, y);
graphics.blit(ICON, leftPos + 80, topPos + 28, 0, 0, imageWidth, imageHeight);
}

@Override
protected void initAdditionWidgets() {
int buttonLeft = leftPos + 86;
int buttonTop = topPos + 52;

this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.show_backpack"),
Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.showBackpack()),
button -> {
this.syncNetwork.setShowBackpack(!this.syncNetwork.showBackpack());
button.setValue(Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.showBackpack()));
}
));
buttonTop += 13;

this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.show_back_item"),
Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.showBackItem()),
button -> {
this.syncNetwork.setShowBackItem(!this.syncNetwork.showBackItem());
button.setValue(Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.showBackItem()));
}
));
buttonTop += 13;

this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.show_chat_bubble"),
Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.showChatBubble()),
button -> {
this.syncNetwork.setShowChatBubble(!this.syncNetwork.showChatBubble());
button.setValue(Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.showChatBubble()));
}
));
buttonTop += 13;


this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.sound_frequency"),
Component.literal(Math.round(this.syncNetwork.soundFreq() * 100) + "%").withStyle(ChatFormatting.YELLOW),
button -> {
this.syncNetwork.setSoundFreq(this.syncNetwork.soundFreq() - 0.1f);
button.setValue(Component.literal(Math.round(this.syncNetwork.soundFreq() * 100) + "%").withStyle(ChatFormatting.YELLOW));
},
button -> {
this.syncNetwork.setSoundFreq(this.syncNetwork.soundFreq() + 0.1f);
button.setValue(Component.literal(Math.round(this.syncNetwork.soundFreq() * 100) + "%").withStyle(ChatFormatting.YELLOW));
}
));
buttonTop += 13;

this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.pick_type"),
Component.translatable(PickType.getTransKey(this.syncNetwork.pickType())).withStyle(ChatFormatting.DARK_RED),
button -> {
this.syncNetwork.setPickType(PickType.getPreviousPickType(this.syncNetwork.pickType()));
button.setValue(Component.translatable(PickType.getTransKey(this.syncNetwork.pickType())).withStyle(ChatFormatting.DARK_RED));
},
button -> {
this.syncNetwork.setPickType(PickType.getNextPickType(this.syncNetwork.pickType()));
button.setValue(Component.translatable(PickType.getTransKey(this.syncNetwork.pickType())).withStyle(ChatFormatting.DARK_RED));
}
));
buttonTop += 13;

this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.open_door"),
Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.openDoor()),
button -> {
this.syncNetwork.setOpenDoor(!this.syncNetwork.openDoor());
button.setValue(Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.openDoor()));
}
));
buttonTop += 13;

this.addRenderableWidget(new MaidConfigButton(buttonLeft, buttonTop,
Component.translatable("gui.touhou_little_maid.maid_config.open_fence_gate"),
Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.openFenceGate()),
button -> {
this.syncNetwork.setOpenFenceGate(!this.syncNetwork.openFenceGate());
button.setValue(Component.translatable("gui.touhou_little_maid.maid_config.value." + this.syncNetwork.openFenceGate()));
}
));
}

@Override
protected void renderAddition(GuiGraphics graphics, int mouseX, int mouseY, float partialTicks) {
graphics.drawString(font, Component.translatable("gui.touhou_little_maid.button.maid_config"), leftPos + 140, topPos + 41, 0xFFFFFF, false);
}

@Override
public void onClose() {
if (this.maid != null) {
NetworkHandler.CHANNEL.sendToServer(new MaidSubConfigMessage(this.maid.getId(), this.syncNetwork));
}
super.onClose();
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid;
package com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.other;

import com.github.tartaricacid.touhoulittlemaid.client.gui.entity.maid.AbstractMaidContainerGui;
import net.minecraft.client.gui.GuiGraphics;
import net.minecraft.client.gui.components.Button;
import net.minecraft.client.gui.screens.Screen;
Expand Down
Loading

0 comments on commit 5829bc3

Please sign in to comment.