Skip to content

Commit fc8e438

Browse files
chore: dejankening
1 parent e7c4e93 commit fc8e438

15 files changed

+244
-258
lines changed

src/client/java/dev/spiritstudios/snapper/SnapperConfig.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package dev.spiritstudios.snapper;
22

3-
import dev.spiritstudios.snapper.gui.screen.ScreenshotViewerScreen;
3+
import dev.spiritstudios.snapper.gui.screen.ScreenshotScreen;
44
import dev.spiritstudios.snapper.util.SnapperUtil;
55
import dev.spiritstudios.snapper.util.config.DirectoryConfigUtil;
66
import dev.spiritstudios.snapper.util.uploading.AxolotlClientApi;
@@ -29,7 +29,7 @@ public final class SnapperConfig extends Config<SnapperConfig> {
2929
.comment("Whether to show Snapper button in game menu.")
3030
.build();
3131

32-
public final Value<ScreenshotViewerScreen.ViewMode> viewMode = enumValue(ScreenshotViewerScreen.ViewMode.GRID, ScreenshotViewerScreen.ViewMode.class)
32+
public final Value<ScreenshotScreen.ViewMode> viewMode = enumValue(ScreenshotScreen.ViewMode.GRID, ScreenshotScreen.ViewMode.class)
3333
.comment("Whether to show screenshot menu with grid or list.")
3434
.build();
3535

@@ -41,7 +41,7 @@ public final class SnapperConfig extends Config<SnapperConfig> {
4141
.comment("Whether to use a custom screenshot folder instead of Minecraft's default")
4242
.build();
4343

44-
public final Value<Path> customScreenshotFolder = value(Path.of(SnapperUtil.getOSUnifiedFolder().toString()), DirectoryConfigUtil.PATH_CODEC)
44+
public final Value<Path> customScreenshotFolder = value(SnapperUtil.UNIFIED_FOLDER, DirectoryConfigUtil.PATH_CODEC)
4545
.comment("What folder to use if custom screenshot folders are enabled.")
4646
.build();
47-
}
47+
}

src/client/java/dev/spiritstudios/snapper/SnapperKeybindings.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
import dev.spiritstudios.snapper.gui.screen.ScreenshotScreen;
44
import dev.spiritstudios.snapper.gui.screen.ScreenshotViewerScreen;
5+
import dev.spiritstudios.snapper.util.DynamicTexture;
56
import dev.spiritstudios.snapper.util.ScreenshotActions;
6-
import dev.spiritstudios.snapper.util.ScreenshotImage;
77
import dev.spiritstudios.specter.api.core.client.event.ClientKeybindEvents;
88
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper;
99
import net.minecraft.client.MinecraftClient;
@@ -69,7 +69,7 @@ private static void openRecentScreenshot(MinecraftClient client) {
6969
}
7070

7171
Path latestPath = screenshots.getFirst();
72-
ScreenshotImage.createScreenshot(client.getTextureManager(), latestPath)
72+
DynamicTexture.createScreenshot(client.getTextureManager(), latestPath)
7373
.ifPresentOrElse(
7474
image -> {
7575
client.setScreen(new ScreenshotViewerScreen(

src/client/java/dev/spiritstudios/snapper/gui/overlay/ExternalDialogOverlay.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {
4646
if (InputUtil.isKeyPressed(client.getWindow().getHandle(), InputUtil.GLFW_KEY_ESCAPE)) close();
4747
}
4848

49-
5049
public void close() {
5150
this.client.setOverlay(null);
5251
}

src/client/java/dev/spiritstudios/snapper/gui/screen/PanoramaViewerScreen.java

Lines changed: 14 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package dev.spiritstudios.snapper.gui.screen;
22

33
import dev.spiritstudios.snapper.Snapper;
4+
import dev.spiritstudios.snapper.util.DynamicTexture;
45
import dev.spiritstudios.snapper.util.SafeFiles;
5-
import dev.spiritstudios.snapper.util.ScreenshotImage;
66
import dev.spiritstudios.snapper.util.SnapperUtil;
77
import net.minecraft.client.MinecraftClient;
88
import net.minecraft.client.gui.CubeMapRenderer;
@@ -12,9 +12,9 @@
1212
import net.minecraft.client.gui.widget.ButtonWidget;
1313
import net.minecraft.screen.ScreenTexts;
1414
import net.minecraft.text.Text;
15-
import net.minecraft.util.Identifier;
1615
import net.minecraft.util.Util;
1716
import org.jetbrains.annotations.Nullable;
17+
import org.jetbrains.annotations.Unmodifiable;
1818

1919
import java.io.IOException;
2020
import java.nio.file.Files;
@@ -25,14 +25,14 @@
2525
import java.util.stream.Stream;
2626

2727
public class PanoramaViewerScreen extends Screen {
28-
protected static final CubeMapRenderer PANORAMA_RENDERER = new CubeMapRenderer(Identifier.ofVanilla("screenshots/panorama/panorama"));
28+
protected static final CubeMapRenderer PANORAMA_RENDERER = new CubeMapRenderer(Snapper.id("screenshots/panorama/panorama"));
2929

30-
protected static final RotatingCubeMapRenderer PANORAMA_RENDERER_CUBE = new RotatingCubeMapRenderer(PANORAMA_RENDERER);
30+
protected static final RotatingCubeMapRenderer ROTATING_PANORAMA_RENDERER = new RotatingCubeMapRenderer(PANORAMA_RENDERER);
3131

3232
private final String title;
3333
private final Screen parent;
3434

35-
private final List<ScreenshotImage> images = new ArrayList<>();
35+
private final List<DynamicTexture> images = new ArrayList<>();
3636

3737
protected PanoramaViewerScreen(String title, Screen parent) {
3838
super(Text.translatable("menu.snapper.viewer_menu"));
@@ -41,15 +41,16 @@ protected PanoramaViewerScreen(String title, Screen parent) {
4141
this.client = MinecraftClient.getInstance();
4242
assert this.client != null;
4343

44-
List<Path> panorama = this.getImagePaths();
45-
if (panorama == null) {
44+
List<Path> facePaths = this.getImagePaths();
45+
46+
if (facePaths == null) {
4647
Snapper.LOGGER.error("No panorama found");
4748
close();
4849
return;
4950
}
5051

51-
for (Path path : panorama) {
52-
ScreenshotImage.createPanoramaFace(this.client.getTextureManager(), path)
52+
for (Path path : facePaths) {
53+
DynamicTexture.createPanoramaFace(this.client.getTextureManager(), path)
5354
.ifPresent(screenshotImage -> {
5455
images.add(screenshotImage);
5556
screenshotImage
@@ -59,8 +60,8 @@ protected PanoramaViewerScreen(String title, Screen parent) {
5960
}
6061
}
6162

62-
@Nullable
63-
private List<Path> getImagePaths() {
63+
64+
private @Nullable @Unmodifiable List<Path> getImagePaths() {
6465
Objects.requireNonNull(this.client);
6566

6667
Path panoramaDir = SnapperUtil.getConfiguredScreenshotDirectory().resolve("panorama");
@@ -84,7 +85,7 @@ private List<Path> getImagePaths() {
8485
public void close() {
8586
Objects.requireNonNull(this.client);
8687

87-
for (ScreenshotImage image : images) {
88+
for (DynamicTexture image : images) {
8889
image.close();
8990
}
9091

@@ -97,12 +98,6 @@ protected void init() {
9798

9899
Path panoramaPath = Path.of(client.runDirectory.getPath(), "screenshots", "panorama");
99100
addDrawableChild(ButtonWidget.builder(Text.translatable("button.snapper.folder"), button -> {
100-
if (!SafeFiles.createDirectories(panoramaPath)) {
101-
Snapper.LOGGER.error("Failed to create directory \"{}\"", panoramaPath);
102-
close();
103-
return;
104-
}
105-
106101
Util.getOperatingSystem().open(panoramaPath);
107102
}).dimensions(width / 2 - 150 - 4, height - 32, 150, 20).build());
108103

@@ -114,7 +109,7 @@ protected void init() {
114109

115110
@Override
116111
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
117-
PANORAMA_RENDERER_CUBE.render(context, this.width, this.height, 1.0F, delta);
112+
ROTATING_PANORAMA_RENDERER.render(context, this.width, this.height, 1.0F, delta);
118113

119114
context.drawCenteredTextWithShadow(
120115
this.textRenderer,

src/client/java/dev/spiritstudios/snapper/gui/screen/ScreenshotScreen.java

Lines changed: 43 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,34 +25,36 @@
2525

2626
import java.nio.file.Path;
2727

28-
import static dev.spiritstudios.snapper.Snapper.MODID;
29-
3028
public 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

Comments
 (0)