-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexplorer.pde
254 lines (202 loc) · 7.27 KB
/
explorer.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import java.awt.Desktop;
public class Explorer extends Screen {
//private String currentDir = DEFAULT_DIR;
private final String[] DEFAULT_CODE_NEON = {
"public void start() {",
" ",
"}",
"",
"public void run() {",
" g.background(120, 100, 140);",
" sprite(\"neon\");",
" ",
"}"
};
private final String[] DEFAULT_CODE = {
"public void start() {",
" ",
"}",
"",
"public void run() {",
" g.background(120, 100, 140);",
" sprite(\"neon\");",
" ",
"}"
};
//DisplayableFile backButtonDisplayable = null;
SpriteSystemPlaceholder gui;
private float scrollBottom = 0.0;
public Explorer(TWEngine engine) {
super(engine);
file.openDirInNewThread(engine.DEFAULT_DIR);
gui = new SpriteSystemPlaceholder(engine, engine.APPPATH+engine.PATH_SPRITES_ATTRIB()+"gui/explorer/");
gui.repositionSpritesToScale();
gui.interactable = false;
//myLowerBarColor = color(120);
//myUpperBarColor = color(120);
myBackgroundColor = color(0);
}
// Sorry for code duplication!
public Explorer(TWEngine engine, String dir) {
super(engine);
file.openDirInNewThread(dir);
gui = new SpriteSystemPlaceholder(engine, engine.APPPATH+engine.PATH_SPRITES_ATTRIB()+"gui/explorer/");
gui.repositionSpritesToScale();
gui.interactable = false;
//myLowerBarColor = color(120);
//myUpperBarColor = color(120);
myBackgroundColor = color(0);
//engine.openDir(dir);
}
// This method shall render all the files in the current dir
private void renderDir() {
final float TEXT_SIZE = 50;
final float BOTTOM_SCROLL_EXTEND = 300; // The scroll doesn't go all the way down to the bottom for whatever reason.
// So let's add a little more room to scroll down to the bottom.
app.textFont(engine.DEFAULT_FONT, 50);
app.textSize(TEXT_SIZE);
for (int i = 0; i < file.currentFiles.length; i++) {
float textHeight = app.textAscent() + app.textDescent();
float x = 50;
float wi = TEXT_SIZE + 20;
float y = 150 + i*TEXT_SIZE+input.scrollOffset;
// Sorry not sorry
try {
if (file.currentFiles[i] != null) {
if (!engine.inputPromptShown && engine.mouseX() > x && engine.mouseX() < x + app.textWidth(file.currentFiles[i].filename) + wi && engine.mouseY() > y && engine.mouseY() < textHeight + y) {
// if mouse is overing over text, change the color of the text
app.fill(100, 0, 255);
app.tint(100, 0, 255);
// if mouse is hovering over text and left click is pressed, go to this directory/open the file
if (input.primaryOnce) {
if (file.currentFiles[i].isDirectory())
input.scrollOffset = 0.;
file.open(file.currentFiles[i]);
}
} else {
app.noTint();
app.fill(255);
}
if (file.currentFiles[i].icon != null)
display.img(file.currentFiles[i].icon, 50, y, TEXT_SIZE, TEXT_SIZE);
app.textAlign(LEFT, TOP);
app.text(file.currentFiles[i].filename, x + wi, y);
app.noTint();
}
}
catch (ArrayIndexOutOfBoundsException e) {
}
catch (NullPointerException ex) {
}
}
scrollBottom = max(0, (file.currentFiles.length*TEXT_SIZE-HEIGHT+BOTTOM_SCROLL_EXTEND));
}
private void renderGui() {
ui.useSpriteSystem(gui);
// Buttons
// Return here to not render them
if (engine.inputPromptShown) return;
//************NEW FOLDER************
if (ui.button("new_folder", "new_folder_128", "New folder")) {
Runnable r = new Runnable() {
public void run() {
if (input.keyboardMessage.length() <= 1) {
console.log("Please enter a valid folder name!");
return;
}
String foldername = file.currentDir+input.keyboardMessage;
new File(foldername).mkdirs();
refreshDir();
}
};
engine.beginInputPrompt("Folder name:", r);
}
//************NEW SKETCHIO PROJECT************
if (ui.button("new_project", "new_entry_128", "New project")) {
Runnable r = new Runnable() {
public void run() {
if (input.keyboardMessage.length() <= 1) {
console.log("Please enter a valid project name!");
return;
}
String name = file.currentDir+input.keyboardMessage;
createNewProject(name);
refreshDir();
file.open(name+"."+engine.SKETCHIO_EXTENSION);
}
};
engine.beginInputPrompt("Project name:", r);
}
gui.updateSpriteSystem();
}
public void createNewProject(String path) {
// .sketchio
try {
if (!path.substring(path.length()-9).equals(".sketchio")) {
path += ".sketchio";
}
}
catch (StringIndexOutOfBoundsException e) {
path += ".sketchio";
}
file.mkdir(path);
path += "/";
file.mkdir(path+"img");
file.mkdir(path+"music");
file.mkdir(path+"scripts");
file.mkdir(path+"shaders");
file.mkdir(path+"sprites");
if (file.exists(engine.APPPATH+"engine/other/neon.png")) {
file.copy(engine.APPPATH+"engine/other/neon.png", path+"img/neon.png");
app.saveStrings(path+"scripts/main.java", DEFAULT_CODE_NEON);
}
else {
app.saveStrings(path+"scripts/main.java", DEFAULT_CODE);
}
}
// Just use the default background
public void backg() {
app.fill(myBackgroundColor);
app.noStroke();
app.rect(0, 0, WIDTH, HEIGHT);
}
public void upperBar() {
display.shader("fabric", "color", 0.5,0.5,0.5,1., "intensity", 0.1);
super.upperBar();
app.resetShader();
renderGui();
app.textAlign(LEFT, TOP);
app.fill(0);
app.textFont(engine.DEFAULT_FONT, 36);
app.textFont(engine.DEFAULT_FONT, 36);
app.text(file.currentDir, 10, 10);
}
public void lowerBar() {
display.shader("fabric", "color", 0.5,0.5,0.5,1., "intensity", 0.1);
super.lowerBar();
display.defaultShader();
}
public void refreshDir() {
file.openDirInNewThread(file.currentDir);
}
// Let's render our stuff.
public void content() {
// TODO: Should have a function with this to remove code bloat?
if (file.loading) {
ui.loadingIcon(WIDTH/2, HEIGHT/2);
}
else {
input.processScroll(0., scrollBottom+1.0);
renderDir();
}
((IOEngine)engine).displaySketchioInput();
// Render this on top.
app.noStroke();
app.fill(0);
app.rect(0, 0, WIDTH, myUpperBarWeight+100);
app.fill(255);
app.textFont(engine.DEFAULT_FONT, 70);
app.textAlign(LEFT, TOP);
app.text("Explorer", 50, 80);
}
}