2525
2626import java .nio .file .Path ;
2727
28- import static dev .spiritstudios .snapper .Snapper .MODID ;
29-
3028public class ScreenshotScreen extends Screen {
31- private static final Identifier PANORAMA_BUTTON_ICON = Identifier .of (MODID , "screenshots/panorama" );
32- private static final Identifier PANORAMA_BUTTON_DISABLED_ICON = Identifier .of (MODID , "screenshots/panorama_disabled" );
29+ private static final Identifier PANORAMA_BUTTON_ICON = Snapper .id ("screenshots/panorama" );
30+ private static final Identifier PANORAMA_BUTTON_DISABLED_ICON = Snapper .id ("screenshots/panorama_disabled" );
31+
32+ private static final Identifier SETTINGS_ICON = Snapper .id ("screenshots/settings" );
33+
34+ private static final Identifier VIEW_MODE_ICON_LIST = Snapper .id ("screenshots/show_list" );
35+
36+ private static final Identifier VIEW_MODE_ICON_GRID = Snapper .id ("screenshots/show_grid" );
3337
34- private static final Identifier SETTINGS_ICON = Identifier .of (MODID , "screenshots/settings" );
35- private static Identifier VIEW_MODE_ICON ;
3638 private final Screen parent ;
37- ScreenshotListWidget screenshotList ;
39+ private final boolean isOffline ;
40+
41+ private ScreenshotListWidget screenshotList ;
3842 private ButtonWidget deleteButton ;
3943 private ButtonWidget renameButton ;
4044 private ButtonWidget viewButton ;
4145 private ButtonWidget copyButton ;
4246 private ButtonWidget openButton ;
4347 private ButtonWidget uploadButton ;
4448 private TextIconButtonWidget viewModeButton ;
45- private ScreenshotListWidget . @ Nullable ScreenshotEntry selectedScreenshot = null ;
49+ private @ Nullable ScreenshotListWidget . ScreenshotEntry selectedScreenshot = null ;
4650 private boolean showGrid ;
47- private final boolean isOffline ;
4851
4952 public ScreenshotScreen (Screen parent ) {
5053 super (Text .translatable ("menu.snapper.screenshot_menu" ));
5154 this .parent = parent ;
5255
53- this .showGrid = SnapperConfig .INSTANCE .viewMode .get ().equals (ScreenshotViewerScreen . ViewMode .GRID );
56+ this .showGrid = SnapperConfig .INSTANCE .viewMode .get ().equals (ViewMode .GRID );
5457 this .isOffline = SnapperUtil .isOfflineAccount ();
55- VIEW_MODE_ICON = showGrid ? Identifier .of (MODID , "screenshots/show_list" ) : Identifier .of (MODID , "screenshots/show_grid" );
5658 }
5759
5860 @ Override
@@ -79,8 +81,9 @@ protected void init() {
7981 this .openButton = addDrawableChild (ButtonWidget .builder (
8082 Text .translatable ("button.snapper.open" ),
8183 button -> {
82- if (selectedScreenshot != null )
83- Util .getOperatingSystem ().open (selectedScreenshot .icon .getPath ());
84+ if (selectedScreenshot != null ) {
85+ Util .getOperatingSystem ().open (selectedScreenshot .icon .getPath ());
86+ }
8487 }
8588 ).width (secondRowButtonWidth ).build ());
8689
@@ -94,36 +97,40 @@ protected void init() {
9497 this .deleteButton = addDrawableChild (ButtonWidget .builder (
9598 Text .translatable ("button.snapper.delete" ),
9699 button -> {
97- if (selectedScreenshot != null )
98- ScreenshotActions .deleteScreenshot (selectedScreenshot .icon .getPath (), this );
100+ if (selectedScreenshot != null ) {
101+ ScreenshotActions .deleteScreenshot (selectedScreenshot .icon .getPath (), this );
102+ }
99103 }
100104 ).width (firstRowButtonWidth ).build ());
101105
102106 this .renameButton = addDrawableChild (ButtonWidget .builder (
103107 Text .translatable ("button.snapper.rename" ),
104108 button -> {
105- if (this .selectedScreenshot != null )
106- client .setScreen (new RenameScreenshotScreen (this .selectedScreenshot .icon .getPath (), this ));
109+ if (this .selectedScreenshot != null ) {
110+ client .setScreen (new RenameScreenshotScreen (this .selectedScreenshot .icon .getPath (), this ));
111+ }
107112 }
108113 ).width (firstRowButtonWidth ).build ());
109114
110115 this .copyButton = addDrawableChild (ButtonWidget .builder (
111116 Text .translatable ("button.snapper.copy" ),
112117 button -> {
113- if (selectedScreenshot != null )
114- Snapper .getPlatformHelper ().copyScreenshot (selectedScreenshot .icon .getPath ());
118+ if (selectedScreenshot != null ) {
119+ Snapper .getPlatformHelper ().copyScreenshot (selectedScreenshot .icon .getPath ());
120+ }
115121 }
116122 ).width (firstRowButtonWidth ).build ());
117123
118124 this .viewButton = addDrawableChild (ButtonWidget .builder (
119125 Text .translatable ("button.snapper.view" ),
120126 button -> {
121- if (selectedScreenshot != null )
122- this .client .setScreen (new ScreenshotViewerScreen (
123- selectedScreenshot .icon ,
124- selectedScreenshot .icon .getPath (),
125- selectedScreenshot .screenParent
126- ));
127+ if (selectedScreenshot != null ) {
128+ this .client .setScreen (new ScreenshotViewerScreen (
129+ selectedScreenshot .icon ,
130+ selectedScreenshot .icon .getPath (),
131+ selectedScreenshot .screenParent
132+ ));
133+ }
127134 }
128135 ).width (firstRowButtonWidth ).build ());
129136
@@ -139,7 +146,8 @@ protected void init() {
139146 this .uploadButton .setTooltip (Tooltip .of (Text .translatable ("button.snapper.upload.tooltip" )));
140147 }
141148
142- DirectionalLayoutWidget verticalButtonLayout = DirectionalLayoutWidget .vertical ().spacing (4 );
149+ DirectionalLayoutWidget verticalButtonLayout = DirectionalLayoutWidget .vertical ()
150+ .spacing (4 );
143151
144152 AxisGridWidget firstRowWidget = verticalButtonLayout .add (new AxisGridWidget (
145153 308 ,
@@ -180,7 +188,7 @@ protected void init() {
180188 Text .translatable ("config.snapper.snapper.viewMode" ),
181189 button -> this .toggleGrid (),
182190 true
183- ).width (20 ).texture (VIEW_MODE_ICON , 15 , 15 ).build ());
191+ ).width (20 ).texture (showGrid ? VIEW_MODE_ICON_LIST : VIEW_MODE_ICON_GRID , 15 , 15 ).build ());
184192
185193 viewModeButton .setPosition (width / 2 - 178 , height - 56 );
186194
@@ -219,14 +227,13 @@ public void toggleGrid() {
219227 screenshotList .toggleGrid ();
220228 screenshotList .refreshScroll ();
221229 this .showGrid = !this .showGrid ;
222- VIEW_MODE_ICON = showGrid ? Identifier .of (MODID , "screenshots/show_list" ) : Identifier .of (MODID , "screenshots/show_grid" );
223230
224231 remove (this .viewModeButton );
225232 this .viewModeButton = addDrawableChild (TextIconButtonWidget .builder (
226233 Text .translatable ("config.snapper.snapper.viewMode" ),
227234 button -> this .toggleGrid (),
228235 true
229- ).width (20 ).texture (VIEW_MODE_ICON , 15 , 15 ).build ());
236+ ).width (20 ).texture (showGrid ? VIEW_MODE_ICON_LIST : VIEW_MODE_ICON_GRID , 15 , 15 ).build ());
230237 viewModeButton .setPosition (width / 2 - 178 , height - 56 );
231238 }
232239
@@ -236,7 +243,6 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
236243 if (client == null ) return false ;
237244
238245 if (keyCode == GLFW .GLFW_KEY_F5 ) {
239-
240246 client .setScreen (new ScreenshotScreen (this .parent ));
241247 return true ;
242248 }
@@ -250,7 +256,8 @@ public boolean keyPressed(int keyCode, int scanCode, int modifiers) {
250256
251257 if (keyCode == GLFW .GLFW_KEY_ENTER ) {
252258 client .setScreen (new ScreenshotViewerScreen (selectedScreenshot .icon , selectedScreenshot .icon .getPath (), this ));
253- }
259+ return true ;
260+ }
254261
255262 return false ;
256263 }
@@ -266,4 +273,9 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
266273 super .render (context , mouseX , mouseY , delta );
267274 context .drawCenteredTextWithShadow (this .textRenderer , this .title , this .width / 2 , 20 , 0xffffff );
268275 }
276+
277+ public enum ViewMode {
278+ LIST ,
279+ GRID
280+ }
269281}
0 commit comments