5
5
import dev .spiritstudios .snapper .SnapperConfig ;
6
6
import dev .spiritstudios .snapper .gui .screen .ScreenshotScreen ;
7
7
import dev .spiritstudios .snapper .gui .screen .ScreenshotViewerScreen ;
8
+ import dev .spiritstudios .snapper .mixin .EntryListWidgetAccessor ;
8
9
import dev .spiritstudios .snapper .util .ScreenshotActions ;
9
10
import dev .spiritstudios .snapper .util .ScreenshotImage ;
10
11
import dev .spiritstudios .specter .api .core .exception .UnreachableException ;
@@ -51,6 +52,8 @@ public class ScreenshotListWidget extends AlwaysSelectedEntryListWidget<Screensh
51
52
52
53
public final CompletableFuture <List <ScreenshotEntry >> loadFuture ;
53
54
55
+ private final int gridItemHeight = 48 ;
56
+ private final int listItemHeight = 36 ;
54
57
private boolean showGrid = false ;
55
58
56
59
public ScreenshotListWidget (MinecraftClient client , int width , int height , int y , int itemHeight , @ Nullable ScreenshotListWidget previous , Screen parent ) {
@@ -72,6 +75,7 @@ public ScreenshotListWidget(MinecraftClient client, int width, int height, int y
72
75
});
73
76
74
77
this .showGrid = SnapperConfig .INSTANCE .viewMode .get ();
78
+ ((EntryListWidgetAccessor ) (Object ) this ).setItemHeight (this .showGrid ? this .gridItemHeight : this .listItemHeight );
75
79
}
76
80
77
81
@ Override
@@ -107,7 +111,8 @@ private void setEntrySelected(@Nullable ScreenshotEntry entry) {
107
111
108
112
@ Override
109
113
protected void renderList (DrawContext context , int mouseX , int mouseY , float delta ) {
110
- if (showGrid ) {int rowLeft = this .getRowLeft ();
114
+ if (showGrid ) {
115
+ int rowLeft = this .getRowLeft ();
111
116
int rowWidth = this .getRowWidth ();
112
117
int entryHeight = this .itemHeight - 4 ;
113
118
int entryWidth = showGrid ? entryHeight : rowWidth ;
@@ -146,6 +151,7 @@ protected int getMaxPosition() {
146
151
147
152
public void toggleGrid () {
148
153
this .showGrid = !this .showGrid ;
154
+ ((EntryListWidgetAccessor ) (Object ) this ).setItemHeight (this .showGrid ? this .gridItemHeight : this .listItemHeight );
149
155
for (var entry : this .children ()) if (entry instanceof ScreenshotEntry sc ) sc .setShowGrid (this .showGrid );
150
156
151
157
SnapperConfig .INSTANCE .viewMode .set (this .showGrid );
@@ -157,12 +163,12 @@ public void toggleGrid() {
157
163
158
164
int rowWidth = this .getRowWidth ();
159
165
int relX = MathHelper .floor (x - this .getRowLeft ());
160
- int relY = MathHelper .floor (y - (double )this .getY ()) - this .headerHeight ;
166
+ int relY = MathHelper .floor (y - (double ) this .getY ()) - this .headerHeight ;
161
167
162
168
if (relX < 0 || relX > rowWidth || relY < 0 || relY > getBottom ()) return null ;
163
169
164
- int rowIndex = (relY + (int )this .getScrollAmount ()) / this .itemHeight ;
165
- int colIndex = MathHelper .floor (((float )relX / (float )rowWidth ) * (float )NUM_COLUMNS );
170
+ int rowIndex = (relY + (int ) this .getScrollAmount ()) / this .itemHeight ;
171
+ int colIndex = MathHelper .floor (((float ) relX / (float ) rowWidth ) * (float ) NUM_COLUMNS );
166
172
int entryIndex = rowIndex * NUM_COLUMNS + colIndex ;
167
173
168
174
return entryIndex >= 0 && entryIndex < getEntryCount () ? getEntry (entryIndex ) : null ;
@@ -304,6 +310,80 @@ public void setShowGrid(boolean showGrid) {
304
310
305
311
@ Override
306
312
public void render (DrawContext context , int index , int y , int x , int entryWidth , int entryHeight , int mouseX , int mouseY , boolean hovered , float tickDelta ) {
313
+ if (this .showGrid ) {
314
+ renderGrid (context , index , y , x , entryWidth , entryHeight , mouseX , mouseY , hovered , tickDelta );
315
+ return ;
316
+ }
317
+ renderList (context , index , y , x , entryWidth , entryHeight , mouseX , mouseY , hovered , tickDelta );
318
+ }
319
+
320
+ public void renderList (DrawContext context , int index , int y , int x , int entryWidth , int entryHeight , int mouseX , int mouseY , boolean hovered , float tickDelta ) {
321
+ String fileName = this .iconFileName ;
322
+ String creationString = "undefined" ;
323
+
324
+ long creationTime = 0 ;
325
+ try {
326
+ creationTime = Files .readAttributes (iconPath , BasicFileAttributes .class ).creationTime ().toMillis ();
327
+ } catch (IOException e ) {
328
+ client .setScreen (new ScreenshotScreen (screenParent ));
329
+ }
330
+
331
+ if (creationTime != -1L )
332
+ creationString = Text .translatable ("text.snapper.created" ).getString () + " " + DATE_FORMAT .format (Instant .ofEpochMilli (creationTime ));
333
+
334
+ if (StringHelper .isEmpty (fileName ))
335
+ fileName = Text .translatable ("text.snapper.generic" ) + " " + (index + 1 );
336
+
337
+ context .drawText (
338
+ this .client .textRenderer ,
339
+ fileName ,
340
+ x + 32 + 3 ,
341
+ y + 1 ,
342
+ 0xFFFFFF ,
343
+ false
344
+ );
345
+
346
+ context .drawText (
347
+ this .client .textRenderer ,
348
+ creationString ,
349
+ x + 35 ,
350
+ y + 12 ,
351
+ Colors .GRAY ,
352
+ false
353
+ );
354
+
355
+
356
+ if (this .icon != null ) {
357
+ RenderSystem .enableBlend ();
358
+ context .drawTexture (
359
+ this .icon .getTextureId (),
360
+ x ,
361
+ y ,
362
+ entryHeight ,
363
+ entryHeight ,
364
+ (icon .getHeight ()) / 3.0F + 32 ,
365
+ 0 ,
366
+ icon .getHeight (),
367
+ icon .getHeight (),
368
+ icon .getWidth (),
369
+ icon .getHeight ()
370
+ );
371
+ RenderSystem .disableBlend ();
372
+ }
373
+
374
+ if (this .client .options .getTouchscreen ().getValue () || hovered ) {
375
+ context .fill (x , y , x + 32 , y + 32 , 0xA0909090 );
376
+ context .drawGuiTexture (
377
+ mouseX - x < 32 && this .icon != null ? ScreenshotListWidget .VIEW_HIGHLIGHTED_TEXTURE : ScreenshotListWidget .VIEW_TEXTURE ,
378
+ x ,
379
+ y ,
380
+ 32 ,
381
+ 32
382
+ );
383
+ }
384
+ }
385
+
386
+ public void renderGrid (DrawContext context , int index , int y , int x , int entryWidth , int entryHeight , int mouseX , int mouseY , boolean hovered , float tickDelta ) {
307
387
if (!this .showGrid ) {
308
388
String fileName = this .iconFileName ;
309
389
String creationString = "undefined" ;
@@ -342,13 +422,12 @@ public void render(DrawContext context, int index, int y, int x, int entryWidth,
342
422
343
423
if (this .icon != null ) {
344
424
RenderSystem .enableBlend ();
345
- int iconSize = entryHeight ;
346
425
context .drawTexture (
347
426
this .icon .getTextureId (),
348
427
x ,
349
428
y ,
350
- iconSize ,
351
- iconSize ,
429
+ entryHeight ,
430
+ entryHeight ,
352
431
(icon .getHeight ()) / 3.0F + 32 ,
353
432
0 ,
354
433
icon .getHeight (),
0 commit comments