|
33 | 33 | import codechicken.lib.render.pipeline.IVertexOperation; |
34 | 34 | import codechicken.lib.vec.Matrix4; |
35 | 35 | import com.cleanroommc.modularui.api.drawable.IKey; |
| 36 | +import com.cleanroommc.modularui.api.widget.IGuiAction; |
36 | 37 | import com.cleanroommc.modularui.api.widget.IWidget; |
37 | 38 | import com.cleanroommc.modularui.api.widget.Interactable; |
| 39 | +import com.cleanroommc.modularui.drawable.GuiTextures; |
38 | 40 | import com.cleanroommc.modularui.drawable.ItemDrawable; |
39 | 41 | import com.cleanroommc.modularui.factory.PosGuiData; |
40 | 42 | import com.cleanroommc.modularui.factory.SidedPosGuiData; |
41 | 43 | import com.cleanroommc.modularui.screen.ModularPanel; |
| 44 | +import com.cleanroommc.modularui.utils.Alignment; |
42 | 45 | import com.cleanroommc.modularui.value.sync.PanelSyncManager; |
43 | 46 | import com.cleanroommc.modularui.value.sync.SyncHandlers; |
44 | 47 | import com.cleanroommc.modularui.widgets.ButtonWidget; |
45 | 48 | import com.cleanroommc.modularui.widgets.ItemSlot; |
46 | 49 | import com.cleanroommc.modularui.widgets.layout.Column; |
47 | 50 | import com.cleanroommc.modularui.widgets.layout.Grid; |
| 51 | +import com.cleanroommc.modularui.widgets.layout.Row; |
48 | 52 | import org.apache.commons.lang3.tuple.Pair; |
49 | 53 | import org.jetbrains.annotations.NotNull; |
50 | 54 | import org.jetbrains.annotations.Nullable; |
@@ -159,73 +163,80 @@ public ModularPanel buildUI(PosGuiData guiData, PanelSyncManager guiSyncManager) |
159 | 163 | .slotGroup("item_inv"))); |
160 | 164 | } |
161 | 165 | } |
162 | | - ModularPanel panel = GTGuis.createPanel(this, rowSize * 18 + 14, 18 + 4 * 18 + 5 + 14 + 18 * rows) |
163 | | - .child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5)) |
| 166 | + var panel = GTGuis.createPanel(this, rowSize * 18 + 14, 18 + 4 * 18 + 5 + 14 + 18 * rows); |
| 167 | + |
| 168 | + return panel.child(IKey.lang(getMetaFullName()).asWidget().pos(5, 5)) |
164 | 169 | .bindPlayerInventory() |
| 170 | + .childIf(hasAnyCover(), createCoverWidgets(guiData, guiSyncManager, panel)) |
165 | 171 | .child(new Grid() |
166 | 172 | .top(18).left(7).right(7).height(rows * 18) |
167 | 173 | .minElementMargin(0, 0) |
168 | 174 | .minColWidth(18).minRowHeight(18) |
169 | 175 | .matrix(widgets)); |
170 | | - if (hasAnyCover()) { |
171 | | - createCoverWidgets(panel, guiData, guiSyncManager); |
172 | | - } |
173 | | - |
174 | | - return panel; |
175 | 176 | } |
176 | 177 |
|
177 | | - private void createCoverWidgets(ModularPanel mainPanel, PosGuiData guiData, PanelSyncManager guiSyncManager) { |
178 | | - Column leftCoverColumn = new Column(); |
179 | | - Column rightCoverColumn = new Column(); |
180 | | - int numCovers = 0; |
| 178 | + private Row createCoverWidgets(PosGuiData data, PanelSyncManager manager, ModularPanel mainPanel) { |
| 179 | + Column leftCoverColumn = new Column() |
| 180 | + .background(GuiTextures.MC_BACKGROUND) |
| 181 | + .crossAxisAlignment(Alignment.CrossAxis.CENTER) |
| 182 | + .padding(4) |
| 183 | + .coverChildrenWidth() |
| 184 | + .topRel(0.25f) |
| 185 | + .left(-20) |
| 186 | + .height(24 * 3); |
| 187 | + Column rightCoverColumn = new Column() |
| 188 | + .background(GuiTextures.MC_BACKGROUND) |
| 189 | + .crossAxisAlignment(Alignment.CrossAxis.CENTER) |
| 190 | + .padding(4) |
| 191 | + .coverChildrenWidth() |
| 192 | + .topRel(0.25f) |
| 193 | + .right(-20) |
| 194 | + .height(24 * 3); |
181 | 195 |
|
| 196 | + int numCovers = 0; |
182 | 197 | for (EnumFacing side : EnumFacing.VALUES) { |
183 | | - if (hasCover(side) && getCoverAtSide(side) instanceof CoverWithUI cover) { |
184 | | - if (cover.shouldShowSmallUI()) { |
185 | | - numCovers++; |
186 | | - SidedPosGuiData sideData = new SidedPosGuiData(guiData.getPlayer(), guiData.getX(), |
187 | | - guiData.getY(), guiData.getZ(), side); |
188 | | - |
189 | | - // guiSyncManager.panel("cover_" + numCovers, mainPanel, ); |
190 | | - /* |
191 | | - * PanelSyncHandler coverSyncHandler = new PanelSyncHandler(mainPanel, |
192 | | - * (syncManager, syncHandler) -> cover.getSmallGUI(sideData, syncManager)); |
193 | | - * |
194 | | - * guiSyncManager.syncValue("cover_" + numCovers, coverSyncHandler); |
195 | | - */ |
196 | | - |
197 | | - // Use the left side for the first three covers |
198 | | - if (numCovers <= 3) { |
199 | | - // guiSyncManager.panel("cover_" + numCovers, mainPanel, ); |
200 | | - |
201 | | - leftCoverColumn.child(new ButtonWidget<>().top(20 * numCovers + 5).size(20, 20) |
202 | | - .background(GTGuiTextures.SLOT).onMousePressed(i -> { |
203 | | - |
204 | | - ModularPanel coverPanel = cover.getSmallGUI(sideData, guiSyncManager); |
205 | | - if (!coverPanel.isOpen()) { |
206 | | - coverPanel.onOpen(mainPanel.getScreen()); |
207 | | - } |
208 | | - /* |
209 | | - * if (coverSyncHandler.isPanelOpen()) { |
210 | | - * coverSyncHandler.closePanel(); |
211 | | - * } else { |
212 | | - * coverSyncHandler.openPanel(); |
213 | | - * } |
214 | | - */ |
215 | | - Interactable.playButtonClickSound(); |
216 | | - return true; |
217 | | - }) |
218 | | - .overlay(new ItemDrawable(cover.getPickItem()).asIcon())); |
| 198 | + if (getCoverAtSide(side) instanceof CoverWithUI cover) { |
| 199 | + if (!cover.shouldShowSmallUI()) continue; |
| 200 | + |
| 201 | + SidedPosGuiData sideData = new SidedPosGuiData(data.getPlayer(), data.getX(), |
| 202 | + data.getY(), data.getZ(), side); |
| 203 | + |
| 204 | + // todo better key for this? |
| 205 | + var panel = manager.panel("cover at side: " + side.getName(), mainPanel, |
| 206 | + (syncManager, syncHandler) -> cover.getSmallGUI(sideData, syncManager)); |
| 207 | + |
| 208 | + IGuiAction.MousePressed handlePanel = i -> { |
| 209 | + if (!panel.isPanelOpen()) { |
| 210 | + panel.openPanel(); |
219 | 211 | } else { |
220 | | - rightCoverColumn.child(new ButtonWidget<>().top(20 * numCovers + 5).size(20, 20) |
221 | | - .background(GTGuiTextures.SLOT) |
222 | | - .overlay(new ItemDrawable(cover.getPickItem()).asIcon())); |
| 212 | + panel.closePanel(); |
223 | 213 | } |
| 214 | + Interactable.playButtonClickSound(); |
| 215 | + return true; |
| 216 | + }; |
| 217 | + |
| 218 | + // Use the left side for the first three covers |
| 219 | + if (numCovers++ < 3) { |
| 220 | + leftCoverColumn.child(new ButtonWidget<>() |
| 221 | + .size(20, 20) |
| 222 | + .marginBottom(2) |
| 223 | + .background(GTGuiTextures.SLOT) |
| 224 | + .onMousePressed(handlePanel) |
| 225 | + .overlay(new ItemDrawable(cover.getPickItem()).asIcon())); |
| 226 | + } else { |
| 227 | + rightCoverColumn.child(new ButtonWidget<>() |
| 228 | + .size(20, 20) |
| 229 | + .marginBottom(2) |
| 230 | + .background(GTGuiTextures.SLOT) |
| 231 | + .onMousePressed(handlePanel) |
| 232 | + .overlay(new ItemDrawable(cover.getPickItem()).asIcon())); |
224 | 233 | } |
225 | 234 | } |
226 | 235 | } |
227 | | - mainPanel.child(leftCoverColumn.left(-20)); |
228 | | - mainPanel.child(rightCoverColumn.right(mainPanel.getDefaultWidth())); |
| 236 | + return new Row() |
| 237 | + .expanded() |
| 238 | + .child(leftCoverColumn) |
| 239 | + .child(rightCoverColumn); |
229 | 240 | } |
230 | 241 |
|
231 | 242 | @Override |
|
0 commit comments