38
38
package network.rs485.logisticspipes.gui
39
39
40
40
import network.rs485.logisticspipes.gui.guidebook.Drawable
41
- import network.rs485.logisticspipes.gui.guidebook.MouseHoverable
42
41
import network.rs485.logisticspipes.gui.guidebook.MouseInteractable
43
42
import network.rs485.logisticspipes.gui.guidebook.Screen
44
43
import network.rs485.logisticspipes.gui.widget.FuzzyItemSlot
45
44
import network.rs485.logisticspipes.gui.widget.FuzzySelectionWidget
46
45
import network.rs485.logisticspipes.gui.widget.GhostSlot
47
46
import network.rs485.logisticspipes.gui.widget.Tooltipped
47
+ import network.rs485.logisticspipes.inventory.container.LPBaseContainer
48
48
import network.rs485.logisticspipes.util.IRectangle
49
- import network.rs485.logisticspipes.util.math.MutableRectangle
50
49
import logisticspipes.utils.gui.DummySlot
51
50
import mezz.jei.api.gui.IGhostIngredientHandler
52
51
import net.minecraft.client.Minecraft
@@ -57,76 +56,29 @@ import net.minecraft.inventory.ClickType
57
56
import net.minecraft.inventory.Slot
58
57
import kotlin.math.roundToInt
59
58
60
- abstract class LPBaseGuiContainer (
59
+ abstract class BaseGuiContainer (
61
60
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 {
65
65
66
66
// TODO
67
67
// Make it so only the highest "z" widget can be drawn as hovered - hovered state should be managed by gui class.
68
68
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
-
76
69
open val fuzzySelector: FuzzySelectionWidget ? = null
77
70
78
71
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)
120
73
121
74
// 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
124
77
125
78
// Clear button and widget lists
126
79
buttonList.clear()
127
80
mc.player.openContainer = inventorySlots
128
81
}
129
-
130
82
/* *
131
83
* Draw what is supposed to not be important to the gui and is behind everything else.
132
84
* Origin is top left corner of the minecraft window.
@@ -136,7 +88,7 @@ abstract class LPBaseGuiContainer(
136
88
*/
137
89
open fun drawBackgroundLayer (mouseX : Int , mouseY : Int , partialTicks : Float ) {
138
90
drawDefaultBackground()
139
- helper .drawGuiContainerBackground(absoluteBody, guiLeft to guiTop, inventorySlots)
91
+ GuiDrawer .drawGuiContainerBackground(absoluteBody, guiLeft to guiTop, inventorySlots)
140
92
}
141
93
142
94
/* *
@@ -156,15 +108,12 @@ abstract class LPBaseGuiContainer(
156
108
* @param partialTicks time so animations don't have to depend on game ticks which can be unstable.
157
109
*/
158
110
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 {
161
113
drawHoveringText(it, mouseX.roundToInt(), mouseY.roundToInt())
162
114
} ? : renderHoveredToolTip(mouseX.roundToInt(), mouseY.roundToInt())
163
115
}
164
116
165
- private fun getHovered (mouseX : Float , mouseY : Float ): MouseHoverable ? =
166
- widgetContainer.getHovered(mouseX, mouseY)
167
-
168
117
// Call super and call all the normally used methods.
169
118
override fun drawScreen (mouseX : Int , mouseY : Int , partialTicks : Float ) {
170
119
super .drawScreen(mouseX, mouseY, partialTicks)
@@ -176,7 +125,7 @@ abstract class LPBaseGuiContainer(
176
125
drawFocalgroundLayer(floatMouseX, floatMouseY, partialTicks)
177
126
GlStateManager .translate(0.0f , 0.0f , 10.0f )
178
127
RenderHelper .disableStandardItemLighting()
179
- hoveredWidget = getHovered (floatMouseX, floatMouseY)
128
+ widgetScreen.updateHoveredState (floatMouseX, floatMouseY)
180
129
drawForegroundLayer(floatMouseX, floatMouseY, partialTicks)
181
130
RenderHelper .disableStandardItemLighting()
182
131
fuzzySelector?.let { fuzzySelector ->
@@ -210,7 +159,7 @@ abstract class LPBaseGuiContainer(
210
159
) {
211
160
return
212
161
}
213
- val currentHovered = hoveredWidget
162
+ val currentHovered = widgetScreen. hoveredWidget
214
163
if (currentHovered is MouseInteractable ) {
215
164
if (currentHovered.mouseClicked(
216
165
mouseX = mouseX.toFloat(),
@@ -244,10 +193,6 @@ abstract class LPBaseGuiContainer(
244
193
drawBackgroundLayer(mouseX, mouseY, partialTicks)
245
194
}
246
195
247
- companion object {
248
- val helper = LPGuiDrawer
249
- }
250
-
251
196
fun List<Drawable>.draw (mouseX : Float , mouseY : Float , partialTicks : Float , visibleArea : IRectangle ) =
252
197
forEach {
253
198
it.draw(mouseX, mouseY, partialTicks, visibleArea)
0 commit comments