Skip to content

Commit 5184273

Browse files
Added loading screen to building.
1 parent dc3c910 commit 5184273

File tree

13 files changed

+410
-28
lines changed

13 files changed

+410
-28
lines changed

src/main/java/com/codingpupper3033/codebtekml/CodeBTEKMLMod.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
99
import org.apache.logging.log4j.Logger;
1010

11+
import javax.swing.*;
12+
1113
/**
1214
* The mod itself
1315
* @author Joshua Miller
@@ -25,6 +27,14 @@ public class CodeBTEKMLMod
2527
public void preInit(FMLPreInitializationEvent event)
2628
{
2729
logger = event.getModLog();
30+
31+
// Make Look and Feel be better
32+
try {
33+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
34+
System.out.println("obamna");
35+
}catch(Exception ex) {
36+
ex.printStackTrace();
37+
}
2838
}
2939

3040
@EventHandler
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package com.codingpupper3033.codebtekml.gui.screens;
2+
3+
import com.codingpupper3033.codebtekml.gui.widgets.ProgressBar;
4+
import com.codingpupper3033.codebtekml.helpers.map.Placemark;
5+
import com.codingpupper3033.codebtekml.helpers.map.placemark.DrawListener;
6+
import com.codingpupper3033.codebtekml.helpers.map.placemark.PlacemarkFactory;
7+
import net.minecraft.client.Minecraft;
8+
import net.minecraft.client.gui.GuiScreen;
9+
import net.minecraft.client.resources.I18n;
10+
11+
/**
12+
* Shows a loading screen while building
13+
* @author Joshua Miller
14+
*/
15+
public class GuiBuilding extends GuiScreen {
16+
17+
public static final int[] DONE_POS = {0,90};
18+
public static final int DONE_COLOR = 0xFFFFFF;
19+
public static final String DONE_TEXT = I18n.format("gui.done"+ "!");
20+
public static final int[] PROGRESS_BAR_POS = {-150,100};
21+
public static final int[] PROGRESS_BAR_SIZE = {300,20};
22+
private final String blockName;
23+
private ProgressBar progressBar;
24+
private float progress = 0f;
25+
26+
private boolean started = false;
27+
private boolean finished = false;
28+
29+
public boolean doProgress = true;
30+
31+
Placemark[] placemarks;
32+
33+
public GuiBuilding(Placemark[] placemarks, String blockName) {
34+
this.placemarks = placemarks;
35+
this.blockName = blockName;
36+
}
37+
38+
@Override
39+
public void initGui() {
40+
super.initGui();
41+
42+
// Helper variables for adding gui elements
43+
int guiMiddleX = width/2;
44+
int guiStartY = height/6;
45+
46+
progressBar = new ProgressBar(PROGRESS_BAR_POS[0]+guiMiddleX,PROGRESS_BAR_POS[1]+guiStartY,PROGRESS_BAR_SIZE[0], PROGRESS_BAR_SIZE[1]);
47+
48+
}
49+
50+
@Override
51+
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
52+
drawDefaultBackground(); // It greyish :)
53+
54+
// Helper variables for adding gui elements
55+
int guiMiddleX = width/2;
56+
int guiStartY = height/6;
57+
58+
if (!started) { // Start the drawing now
59+
started = true;
60+
new Thread(() -> { // New thread as to allow for loading screen
61+
if (doProgress) {
62+
PlacemarkFactory.drawPlacemarks(placemarks, blockName, new DrawListener() {
63+
64+
@Override
65+
public void subsectionDrawn(int subsection, int totalSubsections, int placemark, int totalPlacemarks) {
66+
float singularPlacemarkPercent = 1f/totalPlacemarks;
67+
float placemarkCompletion = 1f*subsection/totalSubsections;
68+
progress = singularPlacemarkPercent*(placemark-1)+singularPlacemarkPercent*placemarkCompletion;
69+
}
70+
}); // Draw!
71+
} else {
72+
PlacemarkFactory.drawPlacemarks(placemarks, blockName);
73+
}
74+
75+
finished = true;
76+
77+
// Done Drawing, close after a bit
78+
try {
79+
Thread.sleep(500);
80+
} catch (InterruptedException e) {
81+
throw new RuntimeException(e);
82+
}
83+
Minecraft.getMinecraft().displayGuiScreen(null);
84+
}).start();
85+
}
86+
87+
// Draw progress
88+
if (doProgress) progressBar.drawProgress(progress);
89+
90+
// Draw Done
91+
drawCenteredString(Minecraft.getMinecraft().fontRenderer, DONE_TEXT, guiMiddleX+DONE_POS[0],guiStartY+DONE_POS[1], DONE_COLOR);
92+
93+
super.drawScreen(mouseX, mouseY, partialTicks);
94+
}
95+
}

src/main/java/com/codingpupper3033/codebtekml/gui/screens/GuiDrawKML.java

Lines changed: 40 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
package com.codingpupper3033.codebtekml.gui.screens;
22

33
import com.codingpupper3033.codebtekml.KeyInit;
4-
import com.codingpupper3033.codebtekml.gui.buttons.IconButton;
54
import com.codingpupper3033.codebtekml.gui.widgets.BlockPreview;
5+
import com.codingpupper3033.codebtekml.gui.widgets.buttons.IconButton;
66
import com.codingpupper3033.codebtekml.helpers.block.BlockNameConverter;
77
import com.codingpupper3033.codebtekml.helpers.kmlfile.KMLParser;
88
import com.codingpupper3033.codebtekml.helpers.map.Placemark;
99
import com.codingpupper3033.codebtekml.helpers.map.altitude.GoundLevelProcessor;
1010
import com.codingpupper3033.codebtekml.helpers.map.placemark.PlacemarkFactory;
11+
import net.minecraft.client.Minecraft;
1112
import net.minecraft.client.gui.GuiButton;
1213
import net.minecraft.client.gui.GuiScreen;
1314
import net.minecraft.client.gui.GuiTextField;
@@ -31,12 +32,16 @@ public class GuiDrawKML extends GuiScreen {
3132
// Parent
3233
private final GuiScreen parentScreen;
3334

35+
// File Chooser
36+
final static JFileChooser FILE_CHOOSER = new JFileChooser();
37+
3438
// File Name Text Box
3539
public static final int FILE_NAME_TEXT_BOX_ID = 1;
36-
public static final String DEFAULT_FILE_NAME_TEXT_BOX_TEXT = javax.swing.filechooser.FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath(); // Default path is Desktop cause why not
40+
//public static final String DEFAULT_FILE_NAME_TEXT_BOX_TEXT = javax.swing.filechooser.FileSystemView.getFileSystemView().getHomeDirectory().getAbsolutePath(); // Default path is Desktop cause why not
3741
public static final int MAX_FILE_PATH_CHARACTERS = 260; // windows limit according to the first bing result, TODO maybe change to programmatic, but like very insignificant as you just shouldn't need this many characters bro.
3842
private static final int[] FILE_NAME_TEXT_BOX_POS = {-155,0};
3943
public static final int[] FILE_NAME_TEXT_BOX_SIZE = {280,20};
44+
private static String lastFileName = null;
4045
private GuiTextField fileNameTextBox;
4146

4247
// Select File Button
@@ -100,6 +105,11 @@ public GuiDrawKML(GuiScreen parentScreen) {
100105
public void initGui() {
101106
super.initGui();
102107

108+
// Set up the filter for the file viewer
109+
FileNameExtensionFilter filter = new FileNameExtensionFilter("kmz or kml file","kmz","kml"); // Files generally supported (but not enforced)
110+
FILE_CHOOSER.setFileFilter(filter); // Set filter to kmz/kml
111+
FILE_CHOOSER.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES); // Allow directories
112+
103113
// Helper variables for adding gui elements
104114
int guiMiddleX = width/2;
105115
int guiStartY = height/6;
@@ -118,8 +128,14 @@ public void initGui() {
118128

119129
// File Name Text Box
120130
fileNameTextBox = new GuiTextField(FILE_NAME_TEXT_BOX_ID, mc.fontRenderer, guiMiddleX+FILE_NAME_TEXT_BOX_POS[0],guiStartY+FILE_NAME_TEXT_BOX_POS[1], FILE_NAME_TEXT_BOX_SIZE[0], FILE_NAME_TEXT_BOX_SIZE[1]);
121-
fileNameTextBox.setText(DEFAULT_FILE_NAME_TEXT_BOX_TEXT);
122131
fileNameTextBox.setMaxStringLength(MAX_FILE_PATH_CHARACTERS);
132+
if (lastFileName != null) {
133+
fileNameTextBox.setText(lastFileName);
134+
FILE_CHOOSER.setSelectedFile(null);
135+
} else {
136+
updateFileNameText(); // Set text to what the file chooser thinks it should be
137+
}
138+
123139

124140
// Select File Button
125141
selectFileButton = new IconButton(IconButton.ICON.FILE, SELECT_FILE_BUTTON_ID, guiMiddleX+ SELECT_FILE_BUTTON_POS[0],guiStartY+ SELECT_FILE_BUTTON_POS[1]);
@@ -238,24 +254,14 @@ protected void actionPerformed(GuiButton button) throws IOException {
238254

239255
switch (button.id) { // Who did it?
240256
case SELECT_FILE_BUTTON_ID: // Selecting a file time
241-
// Make open file dialog not look like as shit
242-
try {
243-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
244-
}catch(Exception ex) {
245-
ex.printStackTrace();
246-
}
247-
FileNameExtensionFilter filter = new FileNameExtensionFilter("kmz or kml file","kmz","kml"); // Files generally supported (but not enforced)
248-
249-
//Create a file chooser
250-
final JFileChooser fc = new JFileChooser();
251-
fc.setFileFilter(filter); // Set filter to kmz/kml
252-
253-
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
257+
JFrame parent = new JFrame();
258+
parent.setAlwaysOnTop(true); // can't hide the box, messing up minecraft
259+
if (FILE_CHOOSER.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) {
254260
// Set file name textbox to file name from dialog
255-
fileNameTextBox.setText(fc.getSelectedFile().getAbsolutePath());
261+
updateFileNameText();
256262
}
257263
break;
258-
case API_CHECK_BOX_ID: // Api setting
264+
case API_CHECK_BOX_ID: // API setting
259265
GoundLevelProcessor.defaultProcessor.enabled = apiCheckBox.isChecked(); // Can my boi process altitudes (using the internet)
260266
break;
261267
case BUILD_BUTTON_ID: // Do ya thing!
@@ -287,15 +293,28 @@ public void build() {
287293
Placemark[] placemarks = PlacemarkFactory.getPlacemarks(documents);
288294

289295
// Process Altitudes
290-
PlacemarkFactory.proccessPlacemarks(placemarks);
296+
PlacemarkFactory.processPlacemarks(placemarks);
297+
291298

292-
close(); // Should have successfully processed the file, gui is not needed now
293-
PlacemarkFactory.drawPlacemarks(placemarks, blockNameTextBox.getText()); // Draw!
299+
// Should have successfully processed the file, gui is not needed now
300+
// Open loading screen
301+
Minecraft.getMinecraft().displayGuiScreen(new GuiBuilding(placemarks, blockNameTextBox.getText()));
294302
}).start();
295303
}
296304

297305
// Bye bye!
298306
public void close() {
299307
mc.displayGuiScreen(parentScreen);
300308
}
309+
310+
public void updateFileNameText() {
311+
File file;
312+
if (FILE_CHOOSER.getSelectedFile() != null) { // Get File
313+
file = FILE_CHOOSER.getSelectedFile();
314+
} else { // Get directory
315+
file = FILE_CHOOSER.getCurrentDirectory();
316+
}
317+
fileNameTextBox.setText(file.getAbsolutePath());
318+
lastFileName = fileNameTextBox.getText();
319+
}
301320
}

0 commit comments

Comments
 (0)