Skip to content

Commit 508b6fd

Browse files
committed
Move some classes into the correct packages
Rename base classes to lose the redundant "LP" prefix
1 parent 30b05a1 commit 508b6fd

40 files changed

+403
-284
lines changed

.idea/externalAnnotations/net/minecraft/client/gui/inventory/annotations.xml

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

common/logisticspipes/LogisticsPipes.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,9 +202,9 @@
202202
import network.rs485.logisticspipes.compat.TheOneProbeIntegration;
203203
import network.rs485.logisticspipes.config.ClientConfiguration;
204204
import network.rs485.logisticspipes.config.ServerConfigurationManager;
205-
import network.rs485.logisticspipes.gui.PropertyUpdaterEventListener;
206205
import network.rs485.logisticspipes.gui.font.LPFontRenderer;
207206
import network.rs485.logisticspipes.guidebook.ItemGuideBook;
207+
import network.rs485.logisticspipes.property.PropertyUpdaterEventListener;
208208
import network.rs485.util.SystemUtilKt;
209209

210210
//@formatter:off

common/logisticspipes/gui/GuiCraftingPipe.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
import logisticspipes.utils.gui.GuiGraphics;
4141
import logisticspipes.utils.gui.SmallGuiButton;
4242
import logisticspipes.utils.gui.extention.GuiExtention;
43-
import network.rs485.logisticspipes.gui.widget.module.Label;
43+
import network.rs485.logisticspipes.gui.widget.Label;
4444
import network.rs485.logisticspipes.gui.widget.VerticalLabel;
4545
import network.rs485.logisticspipes.inventory.IItemIdentifierInventory;
4646
import network.rs485.logisticspipes.property.BooleanProperty;

common/logisticspipes/modplugins/jei/JEIPluginLoader.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package logisticspipes.modplugins.jei;
22

3+
import javax.annotation.Nonnull;
4+
35
import net.minecraft.item.ItemStack;
46

57
import net.minecraftforge.fml.relauncher.Side;
@@ -15,7 +17,7 @@
1517
import logisticspipes.utils.gui.LogisticsBaseGuiScreen;
1618
import network.rs485.logisticspipes.compat.JEIAdvancedGuiHandler;
1719
import network.rs485.logisticspipes.compat.JEIGhostIngredientHandler;
18-
import network.rs485.logisticspipes.gui.LPBaseGuiContainer;
20+
import network.rs485.logisticspipes.gui.BaseGuiContainer;
1921

2022
@JEIPlugin
2123
public class JEIPluginLoader implements IModPlugin {
@@ -27,12 +29,12 @@ public void register(IModRegistry registry) {
2729
IRecipeTransferRegistry recipeTransferRegistry = registry.getRecipeTransferRegistry();
2830
recipeTransferRegistry.addUniversalRecipeTransferHandler(new RecipeTransferHandler(registry.getJeiHelpers().recipeTransferHandlerHelper()));
2931
registry.addGhostIngredientHandler(LogisticsBaseGuiScreen.class, new GhostIngredientHandler());
30-
registry.addGhostIngredientHandler(LPBaseGuiContainer.class, new JEIGhostIngredientHandler());
32+
registry.addGhostIngredientHandler(BaseGuiContainer.class, new JEIGhostIngredientHandler());
3133
registry.addAdvancedGuiHandlers(new AdvancedGuiHandler(), new JEIAdvancedGuiHandler());
3234
}
3335

3436
@Override
35-
public void onRuntimeAvailable(IJeiRuntime jeiRuntime) {
37+
public void onRuntimeAvailable(@Nonnull IJeiRuntime jeiRuntime) {
3638
JEIPluginLoader.jeiRuntime = jeiRuntime;
3739
}
3840

common/logisticspipes/network/guis/module/inhand/ItemSinkInHand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
import logisticspipes.utils.StaticResolve;
1212
import logisticspipes.utils.gui.DummyContainer;
1313
import logisticspipes.utils.gui.DummyModuleContainer;
14-
import network.rs485.logisticspipes.gui.widget.module.ItemSinkGui;
14+
import network.rs485.logisticspipes.gui.module.ItemSinkGui;
1515

1616
@StaticResolve
1717
public class ItemSinkInHand extends ModuleInHandGuiProvider {

common/logisticspipes/network/guis/module/inhand/ProviderModuleInHand.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import logisticspipes.utils.gui.DummyModuleContainer;
1111
import net.minecraft.entity.player.EntityPlayer;
1212
import net.minecraft.item.ItemStack;
13-
import network.rs485.logisticspipes.gui.widget.module.ProviderGui;
13+
import network.rs485.logisticspipes.gui.module.ProviderGui;
1414

1515
@StaticResolve
1616
public class ProviderModuleInHand extends ModuleInHandGuiProvider {

common/logisticspipes/network/guis/module/inpipe/ItemSinkSlot.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import logisticspipes.network.abstractguis.GuiProvider;
1313
import logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider;
1414
import logisticspipes.utils.StaticResolve;
15-
import network.rs485.logisticspipes.gui.widget.module.ItemSinkContainer;
16-
import network.rs485.logisticspipes.gui.widget.module.ItemSinkGui;
15+
import network.rs485.logisticspipes.inventory.container.ItemSinkContainer;
16+
import network.rs485.logisticspipes.gui.module.ItemSinkGui;
1717
import network.rs485.logisticspipes.property.PropertyLayer;
1818
import network.rs485.logisticspipes.util.LPDataInput;
1919
import network.rs485.logisticspipes.util.LPDataOutput;

common/logisticspipes/network/guis/module/inpipe/ProviderModuleGuiProvider.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@
1111
import logisticspipes.network.abstractguis.GuiProvider;
1212
import logisticspipes.network.abstractguis.ModuleCoordinatesGuiProvider;
1313
import logisticspipes.utils.StaticResolve;
14-
import network.rs485.logisticspipes.gui.widget.module.ProviderContainer;
15-
import network.rs485.logisticspipes.gui.widget.module.ProviderGui;
14+
import network.rs485.logisticspipes.inventory.container.ProviderContainer;
15+
import network.rs485.logisticspipes.gui.module.ProviderGui;
1616
import network.rs485.logisticspipes.inventory.ProviderMode;
1717
import network.rs485.logisticspipes.util.LPDataInput;
1818
import network.rs485.logisticspipes.util.LPDataOutput;

common/logisticspipes/network/packets/module/ItemSinkImportPacket.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
import logisticspipes.proxy.MainProxy;
1818
import logisticspipes.utils.StaticResolve;
1919
import logisticspipes.utils.item.ItemIdentifier;
20-
import network.rs485.logisticspipes.gui.widget.module.ItemSinkGui;
20+
import network.rs485.logisticspipes.gui.module.ItemSinkGui;
2121
import network.rs485.logisticspipes.util.LPDataInput;
2222
import network.rs485.logisticspipes.util.LPDataOutput;
2323

src/api/kotlin/network/rs485/logisticspipes/gui/SwingStuff.kt

+5-4
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,13 @@
3737

3838
package network.rs485.logisticspipes.gui
3939

40-
import network.rs485.logisticspipes.util.IRectangle
4140
import java.awt.Container
42-
import javax.swing.*
41+
import javax.swing.JButton
42+
import javax.swing.JLabel
43+
import javax.swing.JPanel
4344

4445
interface WidgetRenderer<T : Any> {
45-
fun render(componentContainer: ComponentContainer, body: IRectangle): T
46+
fun render(componentContainer: ComponentContainer): T
4647
}
4748

4849
object SwingRenderer : WidgetRenderer<JPanel> {
@@ -82,7 +83,7 @@ object SwingRenderer : WidgetRenderer<JPanel> {
8283
}
8384
}
8485

85-
override fun render(componentContainer: ComponentContainer, body: IRectangle): JPanel {
86+
override fun render(componentContainer: ComponentContainer): JPanel {
8687
return JPanel().apply {
8788
addContainer(componentContainer)
8889
}

src/main/kotlin/network/rs485/logisticspipes/compat/JEIAdvancedGuiHandler.kt

+4-4
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737

3838
package network.rs485.logisticspipes.compat
3939

40-
import network.rs485.logisticspipes.gui.LPBaseGuiContainer
40+
import network.rs485.logisticspipes.gui.BaseGuiContainer
4141
import mezz.jei.api.gui.IAdvancedGuiHandler
4242
import java.awt.Rectangle
4343

44-
class JEIAdvancedGuiHandler : IAdvancedGuiHandler<LPBaseGuiContainer> {
44+
class JEIAdvancedGuiHandler : IAdvancedGuiHandler<BaseGuiContainer> {
4545

46-
override fun getGuiContainerClass(): Class<LPBaseGuiContainer> = LPBaseGuiContainer::class.java
46+
override fun getGuiContainerClass(): Class<BaseGuiContainer> = BaseGuiContainer::class.java
4747

48-
override fun getGuiExtraAreas(guiContainer: LPBaseGuiContainer): MutableList<Rectangle> =
48+
override fun getGuiExtraAreas(guiContainer: BaseGuiContainer): MutableList<Rectangle> =
4949
guiContainer.getExtraGuiAreas().map { rect ->
5050
Rectangle(rect.roundedLeft, rect.roundedTop, rect.roundedWidth, rect.roundedHeight)
5151
}.toMutableList()

src/main/kotlin/network/rs485/logisticspipes/compat/JEIGhostIngredientHandler.kt

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,13 +37,13 @@
3737

3838
package network.rs485.logisticspipes.compat
3939

40-
import network.rs485.logisticspipes.gui.LPBaseGuiContainer
40+
import network.rs485.logisticspipes.gui.BaseGuiContainer
4141
import mezz.jei.api.gui.IGhostIngredientHandler
4242

43-
class JEIGhostIngredientHandler : IGhostIngredientHandler<LPBaseGuiContainer> {
43+
class JEIGhostIngredientHandler : IGhostIngredientHandler<BaseGuiContainer> {
4444

4545
override fun <I : Any?> getTargets(
46-
gui: LPBaseGuiContainer,
46+
gui: BaseGuiContainer,
4747
ingredient: I,
4848
doStart: Boolean,
4949
): MutableList<IGhostIngredientHandler.Target<I>> = gui.getFilterSlots()

src/main/kotlin/network/rs485/logisticspipes/gui/LPBaseGuiContainer.kt src/main/kotlin/network/rs485/logisticspipes/gui/BaseGuiContainer.kt

+14-69
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,14 @@
3838
package network.rs485.logisticspipes.gui
3939

4040
import network.rs485.logisticspipes.gui.guidebook.Drawable
41-
import network.rs485.logisticspipes.gui.guidebook.MouseHoverable
4241
import network.rs485.logisticspipes.gui.guidebook.MouseInteractable
4342
import network.rs485.logisticspipes.gui.guidebook.Screen
4443
import network.rs485.logisticspipes.gui.widget.FuzzyItemSlot
4544
import network.rs485.logisticspipes.gui.widget.FuzzySelectionWidget
4645
import network.rs485.logisticspipes.gui.widget.GhostSlot
4746
import network.rs485.logisticspipes.gui.widget.Tooltipped
47+
import network.rs485.logisticspipes.inventory.container.LPBaseContainer
4848
import network.rs485.logisticspipes.util.IRectangle
49-
import network.rs485.logisticspipes.util.math.MutableRectangle
5049
import logisticspipes.utils.gui.DummySlot
5150
import mezz.jei.api.gui.IGhostIngredientHandler
5251
import net.minecraft.client.Minecraft
@@ -57,76 +56,29 @@ import net.minecraft.inventory.ClickType
5756
import net.minecraft.inventory.Slot
5857
import kotlin.math.roundToInt
5958

60-
abstract class LPBaseGuiContainer(
59+
abstract class BaseGuiContainer(
6160
private val baseContainer: LPBaseContainer,
62-
private val xOffset: Int = 0,
63-
private val yOffset: Int = 0,
64-
) : GuiContainer(baseContainer), Drawable {
61+
val xOffset: Int = 0,
62+
val yOffset: Int = 0,
63+
private val widgetScreen: WidgetScreen,
64+
) : GuiContainer(baseContainer), Drawable by widgetScreen {
6565

6666
// TODO
6767
// Make it so only the highest "z" widget can be drawn as hovered - hovered state should be managed by gui class.
6868

69-
final override var parent: Drawable? = Screen
70-
final override val relativeBody = MutableRectangle()
71-
private var hoveredWidget: MouseHoverable? = null
72-
73-
protected abstract val widgets: ComponentContainer
74-
private var widgetContainer: WidgetContainer = VerticalWidgetContainer(emptyList(), parent, Margin.DEFAULT, 0)
75-
7669
open val fuzzySelector: FuzzySelectionWidget? = null
7770

7871
override fun initGui() {
79-
// In case the screen size has changed.
80-
Screen.relativeBody.setSize(width, height)
81-
82-
// Create gui widgets from dls components.
83-
widgetContainer = GuiRenderer.render(widgets, relativeBody).also {
84-
it.parent = this@LPBaseGuiContainer
85-
}
86-
87-
// Set position back to 0 before placing children to respect minecraft's gui translation.
88-
widgetContainer.relativeBody.resetPos()
89-
relativeBody.resetPos()
90-
91-
// Initialize every widget and place it relative to its parent.
92-
widgetContainer.apply {
93-
initWidget()
94-
placeChildren()
95-
}
96-
97-
// Set size of the main container to the minimum necessary size to fit all children.
98-
widgetContainer.relativeBody.setSize(
99-
widgetContainer.minWidth,
100-
widgetContainer.minHeight,
101-
).translate(
102-
widgetContainer.margin.left,
103-
widgetContainer.margin.top,
104-
)
105-
106-
// Set the root body of the gui based on the size of the first container
107-
// and taking into account it's margin.
108-
relativeBody.setSizeFromRectangle(
109-
widgetContainer.relativeBody.copy().grow(
110-
widgetContainer.margin.horizontal,
111-
widgetContainer.margin.vertical,
112-
),
113-
)
114-
115-
// Center gui with possible offsets
116-
relativeBody.setPos(
117-
newX = (Screen.xCenter - relativeBody.width / 2) + xOffset,
118-
newY = (Screen.yCenter - relativeBody.height / 2) + yOffset,
119-
)
72+
widgetScreen.initGuiWidget(this@BaseGuiContainer, super<GuiContainer>.width, super<GuiContainer>.height)
12073

12174
// To use minecraft's slot and item rendering. Might remove later.
122-
guiLeft = widgetContainer.absoluteBody.roundedLeft
123-
guiTop = widgetContainer.absoluteBody.roundedTop
75+
guiLeft = widgetScreen.widgetContainer.absoluteBody.roundedLeft
76+
guiTop = widgetScreen.widgetContainer.absoluteBody.roundedTop
12477

12578
// Clear button and widget lists
12679
buttonList.clear()
12780
mc.player.openContainer = inventorySlots
12881
}
129-
13082
/**
13183
* Draw what is supposed to not be important to the gui and is behind everything else.
13284
* Origin is top left corner of the minecraft window.
@@ -136,7 +88,7 @@ abstract class LPBaseGuiContainer(
13688
*/
13789
open fun drawBackgroundLayer(mouseX: Int, mouseY: Int, partialTicks: Float) {
13890
drawDefaultBackground()
139-
helper.drawGuiContainerBackground(absoluteBody, guiLeft to guiTop, inventorySlots)
91+
GuiDrawer.drawGuiContainerBackground(absoluteBody, guiLeft to guiTop, inventorySlots)
14092
}
14193

14294
/**
@@ -156,15 +108,12 @@ abstract class LPBaseGuiContainer(
156108
* @param partialTicks time so animations don't have to depend on game ticks which can be unstable.
157109
*/
158110
open fun drawForegroundLayer(mouseX: Float, mouseY: Float, partialTicks: Float) {
159-
widgetContainer.draw(mouseX, mouseY, partialTicks, Screen.absoluteBody)
160-
(hoveredWidget as? Tooltipped)?.getTooltipText()?.takeIf { it.isNotEmpty() }?.also {
111+
widgetScreen.widgetContainer.draw(mouseX, mouseY, partialTicks, Screen.absoluteBody)
112+
(widgetScreen.hoveredWidget as? Tooltipped)?.getTooltipText()?.takeIf { it.isNotEmpty() }?.also {
161113
drawHoveringText(it, mouseX.roundToInt(), mouseY.roundToInt())
162114
} ?: renderHoveredToolTip(mouseX.roundToInt(), mouseY.roundToInt())
163115
}
164116

165-
private fun getHovered(mouseX: Float, mouseY: Float): MouseHoverable? =
166-
widgetContainer.getHovered(mouseX, mouseY)
167-
168117
// Call super and call all the normally used methods.
169118
override fun drawScreen(mouseX: Int, mouseY: Int, partialTicks: Float) {
170119
super.drawScreen(mouseX, mouseY, partialTicks)
@@ -176,7 +125,7 @@ abstract class LPBaseGuiContainer(
176125
drawFocalgroundLayer(floatMouseX, floatMouseY, partialTicks)
177126
GlStateManager.translate(0.0f, 0.0f, 10.0f)
178127
RenderHelper.disableStandardItemLighting()
179-
hoveredWidget = getHovered(floatMouseX, floatMouseY)
128+
widgetScreen.updateHoveredState(floatMouseX, floatMouseY)
180129
drawForegroundLayer(floatMouseX, floatMouseY, partialTicks)
181130
RenderHelper.disableStandardItemLighting()
182131
fuzzySelector?.let { fuzzySelector ->
@@ -210,7 +159,7 @@ abstract class LPBaseGuiContainer(
210159
) {
211160
return
212161
}
213-
val currentHovered = hoveredWidget
162+
val currentHovered = widgetScreen.hoveredWidget
214163
if (currentHovered is MouseInteractable) {
215164
if (currentHovered.mouseClicked(
216165
mouseX = mouseX.toFloat(),
@@ -244,10 +193,6 @@ abstract class LPBaseGuiContainer(
244193
drawBackgroundLayer(mouseX, mouseY, partialTicks)
245194
}
246195

247-
companion object {
248-
val helper = LPGuiDrawer
249-
}
250-
251196
fun List<Drawable>.draw(mouseX: Float, mouseY: Float, partialTicks: Float, visibleArea: IRectangle) =
252197
forEach {
253198
it.draw(mouseX, mouseY, partialTicks, visibleArea)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
/*
2+
* Copyright (c) 2023 RS485
3+
*
4+
* "LogisticsPipes" is distributed under the terms of the Minecraft Mod Public
5+
* License 1.0.1, or MMPL. Please check the contents of the license located in
6+
* https://github.com/RS485/LogisticsPipes/blob/dev/LICENSE.md
7+
*
8+
* This file can instead be distributed under the license terms of the
9+
* MIT license:
10+
*
11+
* Copyright (c) 2023 RS485
12+
*
13+
* This MIT license was reworded to only match this file. If you use the regular
14+
* MIT license in your project, replace this copyright notice (this line and any
15+
* lines below and NOT the copyright line above) with the lines from the original
16+
* MIT license located here: http://opensource.org/licenses/MIT
17+
*
18+
* Permission is hereby granted, free of charge, to any person obtaining a copy of
19+
* this file and associated documentation files (the "Source Code"), to deal in
20+
* the Source Code without restriction, including without limitation the rights to
21+
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
22+
* of the Source Code, and to permit persons to whom the Source Code is furnished
23+
* to do so, subject to the following conditions:
24+
*
25+
* The above copyright notice and this permission notice shall be included in all
26+
* copies or substantial portions of the Source Code, which also can be
27+
* distributed under the MIT.
28+
*
29+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
30+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
31+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
32+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
33+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
34+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
35+
* SOFTWARE.
36+
*/
37+
38+
package network.rs485.logisticspipes.gui
39+
40+
import network.rs485.logisticspipes.gui.guidebook.Drawable
41+
import net.minecraft.client.gui.GuiScreen
42+
43+
class BaseGuiScreen(private val widgetScreen: WidgetScreen) : GuiScreen(), Drawable by widgetScreen {
44+
45+
override fun initGui() {
46+
widgetScreen.initGuiWidget(this, widgetScreen.width, widgetScreen.height)
47+
48+
// Clear button and widget lists
49+
buttonList.clear()
50+
}
51+
}

src/main/kotlin/network/rs485/logisticspipes/gui/LPGuiDrawer.kt src/main/kotlin/network/rs485/logisticspipes/gui/GuiDrawer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ import kotlin.math.abs
6969
/**
7070
* Drawing methods to help with Guis
7171
*/
72-
object LPGuiDrawer {
72+
object GuiDrawer {
7373

7474
private const val BORDER: Int = 4
7575
private const val NORMAL_SLOT_SIZE = 18

0 commit comments

Comments
 (0)