Skip to content

Commit 26f4f9c

Browse files
committed
基本完善插件子UI
1 parent 442c94c commit 26f4f9c

42 files changed

Lines changed: 1161 additions & 232 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package com.circulation.circulation_networks.api;
2+
3+
import com.circulation.circulation_networks.api.node.IHubNode;
4+
import net.minecraft.inventory.IInventory;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
public interface IHubNodeBlockEntity extends INodeBlockEntity {
8+
9+
@Override
10+
@NotNull IHubNode getNode();
11+
12+
//? if <1.20 {
13+
IInventory getPlugins();
14+
//?} else {
15+
/*Container getPlugins();
16+
*///
17+
}

src/main/java/com/circulation/circulation_networks/api/node/IHubNode.java

Lines changed: 11 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import com.circulation.circulation_networks.api.hub.ChargingPreference;
55
import com.circulation.circulation_networks.api.hub.PermissionMode;
66
//? if <1.20 {
7-
import net.minecraft.item.ItemStack;
7+
import net.minecraft.inventory.IInventory;
88
//?} else {
99
/*import net.minecraft.world.item.ItemStack;
1010
*///?}
@@ -26,78 +26,37 @@ public interface IHubNode extends IEnergySupplyNode, IChargingNode {
2626

2727
int PLUGIN_SLOTS = 5;
2828

29-
/**
30-
* 获取权限模式 / Get permission mode
31-
*/
3229
PermissionMode getPermissionMode();
3330

34-
/**
35-
* 设置权限模式 / Set permission mode
36-
*/
3731
void setPermissionMode(PermissionMode mode);
3832

39-
/**
40-
* 获取所有插件槽位 / Get all plugin slots
41-
*
42-
* @return 长度为 {@link #PLUGIN_SLOTS} 的数组,空槽位为 {@link ItemStack#EMPTY}
43-
*/
44-
ItemStack[] getPlugins();
45-
46-
/**
47-
* 设置指定槽位的插件 / Set plugin in specified slot
48-
*/
49-
void setPlugin(int slot, ItemStack stack);
50-
51-
/**
52-
* 获取所属频道的UUID
53-
* <p>
54-
* Get the channel UUID this hub belongs to.
55-
*
56-
* @return 频道UUID,无频道时返回 null
57-
*/
58-
@Nullable
33+
//? if <1.20 {
34+
IInventory getPlugins();
35+
//?} else {
36+
/*Container getPlugins();
37+
*///
38+
39+
@Nonnull
5940
UUID getChannelId();
6041

61-
void setChannelId(@Nullable UUID channelId);
42+
void setChannelId(@Nonnull UUID channelId);
6243

63-
@Nullable
44+
@Nonnull
6445
String getChannelName();
6546

66-
void setChannelName(@Nullable String channelName);
47+
void setChannelName(@Nonnull String channelName);
6748

68-
/**
69-
* 获取指定玩家的充能偏好 / Get charging preference for specified player
70-
*
71-
* @return 若未设置则返回null,无中枢时使用默认全部充能
72-
*/
7349
@Nonnull
7450
ChargingPreference getChargingPreference(UUID playerId);
7551

76-
/**
77-
* 设置指定玩家的充能偏好 / Set charging preference for specified player
78-
*/
7952
void setChargingPreference(UUID playerId, ChargingPreference preference);
8053

81-
/**
82-
* 获取指定玩家的充能偏好 / Get charging preference for specified player
83-
*
84-
* @return 若未设置则返回null,无中枢时使用默认全部充能
85-
*/
8654
boolean getChargingState(UUID playerId, ChargingDefinition preference);
8755

88-
/**
89-
* 设置指定玩家的充能偏好 / Set charging preference for specified player
90-
*/
9156
void setChargingState(UUID playerId, ChargingDefinition preference, boolean value);
9257

93-
/**
94-
* 获取中枢所有者 / Get hub owner
95-
*/
9658
@Nullable
9759
UUID getOwner();
9860

99-
/**
100-
* 设置中枢所有者 / Set hub owner
101-
*/
10261
void setOwner(@Nullable UUID owner);
10362
}

src/main/java/com/circulation/circulation_networks/container/CFNBaseContainer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ protected void registerLayout(ComponentSlotLayout layout) {
6767
registerLayoutInternal(layout, false);
6868
}
6969

70-
protected ComponentSlotLayout registerPlayerLayout(ComponentSlotLayout layout) {
70+
public ComponentSlotLayout registerPlayerLayout(ComponentSlotLayout layout) {
7171
registerLayoutInternal(layout, true);
7272
return layout;
7373
}

src/main/java/com/circulation/circulation_networks/container/ComponentSlotLayout.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ public static ComponentSlotLayout playerInventory(InventoryPlayer inventoryPlaye
4242
return layout;
4343
}
4444

45+
public ComponentSlotLayout build(CFNBaseContainer container) {
46+
container.registerPlayerLayout(this);
47+
return this;
48+
}
49+
4550
//? if <1.20 {
4651
public ComponentSlotLayout addSlot(IInventory inventory, int index, int relX, int relY) {
4752
//?} else {

src/main/java/com/circulation/circulation_networks/gui/CFNBaseGui.java

Lines changed: 96 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,22 @@
44
import com.circulation.circulation_networks.container.CFNBaseContainer;
55
import com.circulation.circulation_networks.gui.component.base.Component;
66
import com.circulation.circulation_networks.gui.component.base.ComponentAtlas;
7-
import com.circulation.circulation_networks.gui.component.base.ComponentGuiContext;
87
import com.circulation.circulation_networks.gui.component.base.ComponentScreenController;
98
import com.circulation.circulation_networks.gui.component.base.RenderPhase;
109
//? if <1.20 {
1110
import com.circulation.circulation_networks.packets.ContainerProgressBar;
1211
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
12+
import net.minecraft.client.Minecraft;
1313
import net.minecraft.client.gui.inventory.GuiContainer;
1414
import net.minecraft.client.renderer.GlStateManager;
15+
import net.minecraft.client.renderer.OpenGlHelper;
16+
import net.minecraft.client.renderer.RenderHelper;
17+
import net.minecraft.inventory.Slot;
18+
import net.minecraft.item.ItemStack;
1519
import net.minecraftforge.fml.relauncher.Side;
1620
import net.minecraftforge.fml.relauncher.SideOnly;
1721
import org.lwjgl.input.Mouse;
22+
import org.lwjgl.opengl.GL11;
1823
//?} else if <1.21 {
1924
/*import net.minecraft.client.gui.GuiGraphics;
2025
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
@@ -32,6 +37,7 @@
3237
*///?}
3338

3439
import javax.annotation.Nonnull;
40+
import javax.annotation.Nullable;
3541
//? if <1.20 {
3642
import java.awt.Rectangle;
3743
import java.io.IOException;
@@ -46,12 +52,11 @@
4652
* <p>Rendering layers (bottom → top):
4753
* <ol>
4854
* <li>Background texture — implement {@link #drawBG}.</li>
49-
* <li>Slots &amp; item stacks — handled automatically by the parent screen.</li>
55+
* <li>Component-owned slot and item rendering.</li>
5056
* <li>Foreground labels — implement {@link #drawFG}.</li>
5157
* <li>Component layer — all {@link Component} instances registered via
5258
* {@link #buildComponents}, sorted ascending by z-index.</li>
5359
* <li>Component tooltip — collected from the topmost hovered component.</li>
54-
* <li>Slot tooltip — vanilla hover-text for inventory slots (rendered last).</li>
5560
* </ol>
5661
*
5762
* <p>Event routing: Mouse and key events are delivered to components in descending
@@ -62,13 +67,15 @@
6267
@SuppressWarnings("unused")
6368
//? if <1.20 {
6469
@SideOnly(Side.CLIENT)
65-
public abstract class CFNBaseGui<T extends CFNBaseContainer> extends GuiContainer implements ComponentGuiContext {
70+
public abstract class CFNBaseGui<T extends CFNBaseContainer> extends GuiContainer {
6671
//?} else {
6772
/*@OnlyIn(Dist.CLIENT)
6873
public abstract class CFNBaseGui extends AbstractContainerScreen<CFNBaseContainer> implements ComponentGuiContext {
6974
*///?}
7075

7176
protected final T container;
77+
@Nullable
78+
protected Slot hoveredSlot;
7279

7380
private final ComponentScreenController componentController = new ComponentScreenController();
7481

@@ -88,7 +95,6 @@ protected CFNBaseGui(@Nonnull T container) {
8895
}
8996
*///?}
9097

91-
@Override
9298
public int getGuiLeft() {
9399
//? if <1.20 {
94100
return guiLeft;
@@ -97,7 +103,6 @@ public int getGuiLeft() {
97103
*///?}
98104
}
99105

100-
@Override
101106
public int getGuiTop() {
102107
//? if <1.20 {
103108
return guiTop;
@@ -106,6 +111,14 @@ public int getGuiTop() {
106111
*///?}
107112
}
108113

114+
public void setHoveredSlot(@Nullable Slot hoveredSlot) {
115+
this.hoveredSlot = hoveredSlot;
116+
}
117+
118+
public boolean isTopComponent(Component component, int mouseX, int mouseY) {
119+
return componentController.getTopComponentAt(mouseX, mouseY) == component;
120+
}
121+
109122
// -------------------------------------------------------------------------
110123
// Component registration
111124
// -------------------------------------------------------------------------
@@ -181,6 +194,57 @@ private void renderComponentTooltip(int mouseX, int mouseY) {
181194
*///?}
182195
}
183196

197+
private void renderCarriedStack(int mouseX, int mouseY) {
198+
ItemStack carried = Minecraft.getMinecraft().player.inventory.getItemStack();
199+
if (carried.isEmpty()) return;
200+
201+
float prevZLevel = this.itemRender.zLevel;
202+
resetGuiRenderState();
203+
GlStateManager.enableRescaleNormal();
204+
OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, 240.0F, 240.0F);
205+
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
206+
RenderHelper.enableGUIStandardItemLighting();
207+
GlStateManager.pushMatrix();
208+
GlStateManager.translate(0.0F, 0.0F, 200.0F);
209+
this.itemRender.zLevel = 200.0F;
210+
this.itemRender.renderItemAndEffectIntoGUI(Minecraft.getMinecraft().player, carried, mouseX - 8, mouseY - 8);
211+
this.itemRender.renderItemOverlayIntoGUI(this.fontRenderer, carried, mouseX - 8, mouseY - 8, null);
212+
this.itemRender.zLevel = prevZLevel;
213+
GlStateManager.popMatrix();
214+
resetGuiRenderState();
215+
}
216+
217+
private void resetGuiRenderState() {
218+
RenderHelper.disableStandardItemLighting();
219+
GlStateManager.disableLighting();
220+
GlStateManager.disableDepth();
221+
GlStateManager.disableRescaleNormal();
222+
GlStateManager.depthMask(true);
223+
GlStateManager.enableAlpha();
224+
GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1F);
225+
GlStateManager.enableBlend();
226+
GlStateManager.tryBlendFuncSeparate(
227+
GL11.GL_SRC_ALPHA,
228+
GL11.GL_ONE_MINUS_SRC_ALPHA,
229+
GL11.GL_ONE,
230+
GL11.GL_ZERO
231+
);
232+
GlStateManager.colorMask(true, true, true, true);
233+
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
234+
235+
GlStateManager.setActiveTexture(OpenGlHelper.lightmapTexUnit);
236+
GlStateManager.enableTexture2D();
237+
GlStateManager.matrixMode(GL11.GL_TEXTURE);
238+
GlStateManager.loadIdentity();
239+
GlStateManager.disableTexture2D();
240+
241+
GlStateManager.setActiveTexture(OpenGlHelper.defaultTexUnit);
242+
GlStateManager.enableTexture2D();
243+
GlStateManager.matrixMode(GL11.GL_TEXTURE);
244+
GlStateManager.loadIdentity();
245+
GlStateManager.matrixMode(GL11.GL_MODELVIEW);
246+
}
247+
184248
//? if <1.20 {
185249
@Override
186250
protected final void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) {
@@ -199,13 +263,37 @@ protected final void drawGuiContainerForegroundLayer(int mouseX, int mouseY) {
199263
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
200264
this.drawDefaultBackground();
201265
componentController.handleActiveDrag(mouseX, mouseY);
266+
this.hoveredSlot = null;
267+
resetGuiRenderState();
268+
269+
renderBGPhase(mouseX, mouseY, partialTicks);
202270
resetColor();
271+
this.drawBG(this.guiLeft, this.guiTop, mouseX, mouseY);
272+
273+
resetGuiRenderState();
274+
203275
componentController.renderPhase(RenderPhase.NORMAL, mouseX, mouseY, partialTicks);
204-
super.drawScreen(mouseX, mouseY, partialTicks);
276+
277+
resetGuiRenderState();
278+
resetColor();
279+
this.drawFG(this.guiLeft, this.guiTop, mouseX, mouseY);
280+
RenderHelper.enableGUIStandardItemLighting();
281+
net.minecraftforge.common.MinecraftForge.EVENT_BUS.post(new net.minecraftforge.client.event.GuiContainerEvent.DrawForeground(this, mouseX, mouseY));
282+
283+
resetGuiRenderState();
205284
resetColor();
206285
componentController.renderPhase(RenderPhase.FOREGROUND, mouseX, mouseY, partialTicks);
286+
renderCarriedStack(mouseX, mouseY);
287+
resetGuiRenderState();
207288
renderComponentTooltip(mouseX, mouseY);
208-
this.renderHoveredToolTip(mouseX, mouseY);
289+
GlStateManager.enableLighting();
290+
GlStateManager.enableDepth();
291+
RenderHelper.enableStandardItemLighting();
292+
}
293+
294+
@Override
295+
public Slot getSlotUnderMouse() {
296+
return this.hoveredSlot;
209297
}
210298

211299
@Override

src/main/java/com/circulation/circulation_networks/gui/component/ButtonComponent.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package com.circulation.circulation_networks.gui.component;
22

3+
import com.circulation.circulation_networks.gui.CFNBaseGui;
34
import com.circulation.circulation_networks.gui.component.base.Component;
45
import com.circulation.circulation_networks.gui.component.base.ComponentAtlas;
5-
import com.circulation.circulation_networks.gui.component.base.ComponentGuiContext;
66

77
@SuppressWarnings("unused")
88
public class ButtonComponent extends Component {
@@ -20,7 +20,7 @@ public class ButtonComponent extends Component {
2020
private boolean pressed = false;
2121
private Runnable run;
2222

23-
public ButtonComponent(int x, int y, int width, int height, ComponentGuiContext gui, String sprite, Runnable run) {
23+
public ButtonComponent(int x, int y, int width, int height, CFNBaseGui<?> gui, String sprite, Runnable run) {
2424
super(x, y, width, height, gui);
2525
this.normalSprite = sprite;
2626
this.hoveredSprite = normalSprite + "_hovered";
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package com.circulation.circulation_networks.gui.component;
2+
3+
import com.circulation.circulation_networks.gui.CFNBaseGui;
4+
import com.circulation.circulation_networks.gui.component.base.Component;
5+
6+
public class CloseButtonComponent extends ButtonComponent {
7+
8+
public static final String DEFAULT_SPRITE = "ui_close";
9+
private Component mutuallyExclusiveComponent;
10+
11+
public CloseButtonComponent(int x, int y, int width, int height, CFNBaseGui<?> gui) {
12+
super(x, y, width, height, gui, DEFAULT_SPRITE, EMPTY);
13+
}
14+
15+
public CloseButtonComponent(int x, int y, int width, int height, CFNBaseGui<?> gui, String sprite) {
16+
super(x, y, width, height, gui, sprite, EMPTY);
17+
}
18+
19+
public CloseButtonComponent setMutuallyComponent(Component component) {
20+
this.mutuallyExclusiveComponent = component;
21+
return this;
22+
}
23+
24+
public Component getMutuallyExclusiveComponent() {
25+
return mutuallyExclusiveComponent;
26+
}
27+
28+
@Override
29+
protected void onClick() {
30+
Component parent = getParent();
31+
if (parent != null) {
32+
parent.setVisible(false);
33+
if (mutuallyExclusiveComponent != null) {
34+
mutuallyExclusiveComponent.setEnabled(true);
35+
}
36+
return;
37+
}
38+
closeCurrentGui();
39+
}
40+
41+
private void closeCurrentGui() {
42+
//? if <1.20 {
43+
this.gui.mc.player.closeScreen();
44+
//?} else {
45+
/*this.gui.minecraft.player.closeContainer();
46+
*///?}
47+
}
48+
}

0 commit comments

Comments
 (0)