remove server from client
This commit is contained in:
parent
19f3813338
commit
7cdff9220a
18 changed files with 352 additions and 1216 deletions
|
@ -58,13 +58,13 @@ import game.gui.GuiConsole;
|
||||||
import game.gui.GuiInfo;
|
import game.gui.GuiInfo;
|
||||||
import game.gui.GuiLoading;
|
import game.gui.GuiLoading;
|
||||||
import game.gui.GuiMenu;
|
import game.gui.GuiMenu;
|
||||||
|
import game.gui.GuiServer;
|
||||||
import game.gui.Style;
|
import game.gui.Style;
|
||||||
import game.gui.character.GuiChar;
|
import game.gui.character.GuiChar;
|
||||||
import game.gui.container.GuiContainer;
|
import game.gui.container.GuiContainer;
|
||||||
import game.gui.container.GuiInventory;
|
import game.gui.container.GuiInventory;
|
||||||
import game.gui.element.Textbox;
|
import game.gui.element.Textbox;
|
||||||
import game.gui.ingame.GuiGameOver;
|
import game.gui.ingame.GuiGameOver;
|
||||||
import game.gui.server.GuiConnect;
|
|
||||||
import game.init.BlockRegistry;
|
import game.init.BlockRegistry;
|
||||||
import game.init.Config;
|
import game.init.Config;
|
||||||
import game.init.EntityRegistry;
|
import game.init.EntityRegistry;
|
||||||
|
@ -219,6 +219,12 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class LevelFunction implements EnumFunction<LogLevel> {
|
||||||
|
public void apply(EnumVar cv, LogLevel value) {
|
||||||
|
Log.setLevel(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private interface DebugRunner {
|
private interface DebugRunner {
|
||||||
void execute(Keysym key);
|
void execute(Keysym key);
|
||||||
}
|
}
|
||||||
|
@ -324,7 +330,7 @@ public class Game implements IThreadListener {
|
||||||
|
|
||||||
@Variable(name = "con_timestamps", category = CVarCategory.CONSOLE, display = "Zeiten")
|
@Variable(name = "con_timestamps", category = CVarCategory.CONSOLE, display = "Zeiten")
|
||||||
public boolean conTimestamps = false;
|
public boolean conTimestamps = false;
|
||||||
@Variable(name = "con_loglevel", category = CVarCategory.CONSOLE, display = "Ausgabe")
|
@Variable(name = "con_loglevel", category = CVarCategory.CONSOLE, display = "Ausgabe", callback = LevelFunction.class)
|
||||||
public LogLevel level = LogLevel.INFO;
|
public LogLevel level = LogLevel.INFO;
|
||||||
|
|
||||||
@Variable(name = "win_sync", category = CVarCategory.WINDOW, min = -1, max = 16384, callback = SyncFunction.class, display = "Maximale Bildrate")
|
@Variable(name = "win_sync", category = CVarCategory.WINDOW, min = -1, max = 16384, callback = SyncFunction.class, display = "Maximale Bildrate")
|
||||||
|
@ -392,9 +398,6 @@ public class Game implements IThreadListener {
|
||||||
public float tpsTarget = 20.0f;
|
public float tpsTarget = 20.0f;
|
||||||
@Variable(name = "tic_timeout", category = CVarCategory.SYSTEM, min = 1, max = 60000, display = "Tick-Timeout-Zeit")
|
@Variable(name = "tic_timeout", category = CVarCategory.SYSTEM, min = 1, max = 60000, display = "Tick-Timeout-Zeit")
|
||||||
public int tickTimeout = 2000;
|
public int tickTimeout = 2000;
|
||||||
|
|
||||||
@Variable(name = "srv_port", category = CVarCategory.SYSTEM, min = 0, max = 65535, display = "Standard Hosting-Port")
|
|
||||||
public int port = Config.PORT;
|
|
||||||
|
|
||||||
@Variable(name = "snd_enabled", category = CVarCategory.SOUND, display = "Tonausgabe")
|
@Variable(name = "snd_enabled", category = CVarCategory.SOUND, display = "Tonausgabe")
|
||||||
public boolean soundEnabled = true;
|
public boolean soundEnabled = true;
|
||||||
|
@ -402,12 +405,10 @@ public class Game implements IThreadListener {
|
||||||
public int soundBufferSize = 2048;
|
public int soundBufferSize = 2048;
|
||||||
@Variable(name = "snd_frame_size", category = CVarCategory.SOUND, min = 2, max = 8192, display = "PCM-Intervall")
|
@Variable(name = "snd_frame_size", category = CVarCategory.SOUND, min = 2, max = 8192, display = "PCM-Intervall")
|
||||||
public int soundFrameSize = 32;
|
public int soundFrameSize = 32;
|
||||||
|
|
||||||
private ServerProcess server;
|
|
||||||
private String serverInfo;
|
private String serverInfo;
|
||||||
private int lastTickTime = -1;
|
private int lastTickTime = -1;
|
||||||
private AudioInterface audio;
|
private AudioInterface audio;
|
||||||
private long start;
|
|
||||||
private boolean cfgDirty;
|
private boolean cfgDirty;
|
||||||
private String buffer = "";
|
private String buffer = "";
|
||||||
private boolean waitingForFile;
|
private boolean waitingForFile;
|
||||||
|
@ -2092,7 +2093,6 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
start = Window.getTime();
|
|
||||||
Log.SYSTEM.info("Java " + System.getProperty("java.version"));
|
Log.SYSTEM.info("Java " + System.getProperty("java.version"));
|
||||||
Log.SYSTEM.info(Config.VERSION);
|
Log.SYSTEM.info(Config.VERSION);
|
||||||
if(!Window.createWindow(Config.VERSION, System.getProperty("opengl.debug") != null))
|
if(!Window.createWindow(Config.VERSION, System.getProperty("opengl.debug") != null))
|
||||||
|
@ -2122,7 +2122,7 @@ public class Game implements IThreadListener {
|
||||||
while(!this.interrupted) {
|
while(!this.interrupted) {
|
||||||
PerfSection.swap();
|
PerfSection.swap();
|
||||||
PerfSection.TIMING.enter();
|
PerfSection.TIMING.enter();
|
||||||
Timing.tmr_current = rtime();
|
Timing.tmr_current = Util.rtime();
|
||||||
Timing.tmr_delta = Timing.tmr_current - Timing.tmr_last;
|
Timing.tmr_delta = Timing.tmr_current - Timing.tmr_last;
|
||||||
Timing.tmr_last = Timing.tmr_current;
|
Timing.tmr_last = Timing.tmr_current;
|
||||||
Timing.fdelta = ((float)Timing.tmr_delta) / 1000000.0f;
|
Timing.fdelta = ((float)Timing.tmr_delta) / 1000000.0f;
|
||||||
|
@ -2162,7 +2162,7 @@ public class Game implements IThreadListener {
|
||||||
long now = System.nanoTime();
|
long now = System.nanoTime();
|
||||||
this.addFrame(now - this.startNanoTime);
|
this.addFrame(now - this.startNanoTime);
|
||||||
this.startNanoTime = now;
|
this.startNanoTime = now;
|
||||||
while(this.syncLimited && (rtime() - Timing.tmr_current) < (1000000L / this.syncLimit)) {
|
while(this.syncLimited && (Util.rtime() - Timing.tmr_current) < (1000000L / this.syncLimit)) {
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
Timing.tmr_frames += 1L;
|
Timing.tmr_frames += 1L;
|
||||||
|
@ -2170,7 +2170,6 @@ public class Game implements IThreadListener {
|
||||||
|
|
||||||
Log.SYSTEM.info("Beende ...");
|
Log.SYSTEM.info("Beende ...");
|
||||||
unload(false);
|
unload(false);
|
||||||
this.stopServer(false);
|
|
||||||
this.getSoundManager().unload();
|
this.getSoundManager().unload();
|
||||||
Region.killIO();
|
Region.killIO();
|
||||||
this.renderGlobal.stopChunkBuilders();
|
this.renderGlobal.stopChunkBuilders();
|
||||||
|
@ -2316,7 +2315,7 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTicks() {
|
private void doTicks() {
|
||||||
Timing.tick_stime = rtime();
|
Timing.tick_stime = Util.rtime();
|
||||||
if((Timing.tick_stime - Timing.tick_update) >= 1000000L) {
|
if((Timing.tick_stime - Timing.tick_update) >= 1000000L) {
|
||||||
Timing.tickrate = ((float)Timing.tick_done) * 1000000.0f / ((float)(long)(Timing.tick_stime - Timing.tick_update));
|
Timing.tickrate = ((float)Timing.tick_done) * 1000000.0f / ((float)(long)(Timing.tick_stime - Timing.tick_update));
|
||||||
Timing.tick_done = 0;
|
Timing.tick_done = 0;
|
||||||
|
@ -2331,7 +2330,7 @@ public class Game implements IThreadListener {
|
||||||
Timing.tickFrame += 1;
|
Timing.tickFrame += 1;
|
||||||
Timing.tick_total += 1L;
|
Timing.tick_total += 1L;
|
||||||
Timing.tick_torun -= 1000000L;
|
Timing.tick_torun -= 1000000L;
|
||||||
if((Timing.tick_ftime = (rtime() - Timing.tick_stime)) >= (((long)this.tickTimeout) * 1000L)) {
|
if((Timing.tick_ftime = (Util.rtime() - Timing.tick_stime)) >= (((long)this.tickTimeout) * 1000L)) {
|
||||||
Log.TICK.warn("Ticks benötigten %d ms dieses Frame (maximal %d ms), überspringe %d Ticks", Timing.tick_ftime / 1000L, this.tickTimeout, Timing.tick_torun / 1000000L);
|
Log.TICK.warn("Ticks benötigten %d ms dieses Frame (maximal %d ms), überspringe %d Ticks", Timing.tick_ftime / 1000L, this.tickTimeout, Timing.tick_torun / 1000000L);
|
||||||
Timing.tick_torun = 0L;
|
Timing.tick_torun = 0L;
|
||||||
break;
|
break;
|
||||||
|
@ -2346,7 +2345,7 @@ public class Game implements IThreadListener {
|
||||||
Timing.tickTarget = (int)(tps * 1000.0f);
|
Timing.tickTarget = (int)(tps * 1000.0f);
|
||||||
Timing.tick_torun = 0L;
|
Timing.tick_torun = 0L;
|
||||||
Timing.tick_done = 0L;
|
Timing.tick_done = 0L;
|
||||||
Timing.tick_update = rtime();
|
Timing.tick_update = Util.rtime();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void unload(boolean loading) {
|
public void unload(boolean loading) {
|
||||||
|
@ -2359,46 +2358,46 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
this.displayGuiScreen(GuiMenu.INSTANCE);
|
this.displayGuiScreen(GuiMenu.INSTANCE);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void startServer(File dir) {
|
// public void startServer(File dir) {
|
||||||
if(this.server != null)
|
// if(this.server != null)
|
||||||
return;
|
// return;
|
||||||
server = new ServerProcess(this, dir, 1024, 4096, this.port);
|
// server = new ServerProcess(this, dir, 1024, 4096, this.port);
|
||||||
server.start();
|
// server.start();
|
||||||
this.displayGuiScreen(GuiLoading.makeStartTask(server));
|
// this.displayGuiScreen(GuiLoading.makeStartTask(server));
|
||||||
// while(server != null && !server.isStarted()) {
|
//// while(server != null && !server.isStarted()) {
|
||||||
// try {
|
//// try {
|
||||||
// Thread.sleep(10L);
|
//// Thread.sleep(10L);
|
||||||
// }
|
//// }
|
||||||
// catch(InterruptedException e) {
|
//// catch(InterruptedException e) {
|
||||||
// }
|
//// }
|
||||||
// }
|
//// }
|
||||||
|
//// if(server != null) {
|
||||||
|
//// }
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public void stopServer(boolean display) {
|
||||||
// if(server != null) {
|
// if(server != null) {
|
||||||
// }
|
// server.shutdown();
|
||||||
}
|
// if(display) {
|
||||||
|
// this.displayGuiScreen(GuiLoading.makeStopTask(server));
|
||||||
public void stopServer(boolean display) {
|
// }
|
||||||
if(server != null) {
|
// else {
|
||||||
server.shutdown();
|
// while(!server.isStopped()) {
|
||||||
if(display) {
|
// try {
|
||||||
this.displayGuiScreen(GuiLoading.makeStopTask(server));
|
// Thread.sleep(10L);
|
||||||
}
|
// }
|
||||||
else {
|
// catch(InterruptedException e) {
|
||||||
while(!server.isStopped()) {
|
// }
|
||||||
try {
|
// }
|
||||||
Thread.sleep(10L);
|
// }
|
||||||
}
|
// server = null;
|
||||||
catch(InterruptedException e) {
|
// }
|
||||||
}
|
// }
|
||||||
}
|
//
|
||||||
}
|
// public boolean isServerRunning() {
|
||||||
server = null;
|
// return this.server != null;
|
||||||
}
|
// }
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isServerRunning() {
|
|
||||||
return this.server != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void waitForServer() {
|
public void waitForServer() {
|
||||||
// if(this.server != null)
|
// if(this.server != null)
|
||||||
|
@ -2432,14 +2431,6 @@ public class Game implements IThreadListener {
|
||||||
public AudioInterface getAudioInterface() {
|
public AudioInterface getAudioInterface() {
|
||||||
return audio;
|
return audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
public long rtime() {
|
|
||||||
return Window.getTime() - start;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double ftime() {
|
|
||||||
return ((double)rtime()) / 1000000.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void distance(int distance) {
|
public void distance(int distance) {
|
||||||
if(this.renderGlobal != null)
|
if(this.renderGlobal != null)
|
||||||
|
@ -2652,6 +2643,7 @@ public class Game implements IThreadListener {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
Util.checkOs();
|
Util.checkOs();
|
||||||
|
Log.init(INSTANCE);
|
||||||
Window.init();
|
Window.init();
|
||||||
Registry.setup("Render thread");
|
Registry.setup("Render thread");
|
||||||
INSTANCE.run();
|
INSTANCE.run();
|
||||||
|
@ -2828,7 +2820,7 @@ public class Game implements IThreadListener {
|
||||||
}
|
}
|
||||||
regVars(this);
|
regVars(this);
|
||||||
regVars(Style.CUSTOM);
|
regVars(Style.CUSTOM);
|
||||||
regVars(GuiConnect.INSTANCE);
|
regVars(GuiServer.INSTANCE);
|
||||||
regVars(GuiChar.INSTANCE);
|
regVars(GuiChar.INSTANCE);
|
||||||
|
|
||||||
if(!config.exists())
|
if(!config.exists())
|
||||||
|
@ -2915,11 +2907,6 @@ public class Game implements IThreadListener {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(line.startsWith("!")) {
|
|
||||||
if(this.server != null)
|
|
||||||
this.server.runCommand(line.substring(1));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.thePlayer != null && this.getNetHandler() != null)
|
if(this.thePlayer != null && this.getNetHandler() != null)
|
||||||
this.getNetHandler().addToSendQueue(new CPacketMessage(line.startsWith("/") ? CPacketMessage.Type.COMMAND : CPacketMessage.Type.CHAT, line.startsWith("/") ? line.substring(1) : line));
|
this.getNetHandler().addToSendQueue(new CPacketMessage(line.startsWith("/") ? CPacketMessage.Type.COMMAND : CPacketMessage.Type.CHAT, line.startsWith("/") ? line.substring(1) : line));
|
||||||
// Log.CONSOLE.user("%s", line);
|
// Log.CONSOLE.user("%s", line);
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
package game.gui.world;
|
package game.gui;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import game.color.TextColor;
|
import game.color.TextColor;
|
||||||
import game.gui.GuiMenu;
|
|
||||||
import game.gui.element.ActButton;
|
import game.gui.element.ActButton;
|
||||||
import game.gui.element.ActButton.Mode;
|
import game.gui.element.ActButton.Mode;
|
||||||
import game.gui.element.GuiList;
|
import game.gui.element.GuiList;
|
||||||
import game.gui.element.ListEntry;
|
import game.gui.element.ListEntry;
|
||||||
import game.gui.element.NavButton;
|
import game.gui.element.NavButton;
|
||||||
import game.gui.server.GuiConnect;
|
|
||||||
import game.init.Config;
|
import game.init.Config;
|
||||||
import game.log.Log;
|
import game.log.Log;
|
||||||
import game.network.Player;
|
import game.network.Player;
|
||||||
|
@ -20,7 +18,7 @@ import game.util.FileUtils;
|
||||||
import game.util.Tuple;
|
import game.util.Tuple;
|
||||||
import game.util.Util;
|
import game.util.Util;
|
||||||
|
|
||||||
public class GuiServers extends GuiList<GuiServers.ServerInfo> implements ActButton.Callback {
|
public class GuiConnect extends GuiList<GuiConnect.ServerInfo> implements ActButton.Callback {
|
||||||
public class ServerInfo implements Comparable<ServerInfo>, ListEntry {
|
public class ServerInfo implements Comparable<ServerInfo>, ListEntry {
|
||||||
private String name;
|
private String name;
|
||||||
private String address;
|
private String address;
|
||||||
|
@ -86,13 +84,13 @@ public class GuiServers extends GuiList<GuiServers.ServerInfo> implements ActBut
|
||||||
}
|
}
|
||||||
|
|
||||||
public void select(boolean isDoubleClick, int mouseX, int mouseY) {
|
public void select(boolean isDoubleClick, int mouseX, int mouseY) {
|
||||||
GuiServers.this.selectButton.enabled = true;
|
GuiConnect.this.selectButton.enabled = true;
|
||||||
GuiServers.this.deleteButton.enabled = true;
|
GuiConnect.this.deleteButton.enabled = true;
|
||||||
GuiServers.this.editButton.enabled = true;
|
GuiConnect.this.editButton.enabled = true;
|
||||||
GuiServers.this.copyButton.enabled = true;
|
GuiConnect.this.copyButton.enabled = true;
|
||||||
|
|
||||||
if(isDoubleClick) {
|
if(isDoubleClick) {
|
||||||
GuiServers.this.use(GuiServers.this.selectButton, Mode.PRIMARY);
|
GuiConnect.this.use(GuiConnect.this.selectButton, Mode.PRIMARY);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -103,7 +101,7 @@ public class GuiServers extends GuiList<GuiServers.ServerInfo> implements ActBut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final GuiServers INSTANCE = new GuiServers();
|
public static final GuiConnect INSTANCE = new GuiConnect();
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||||
private static final File SERVERS_FILE = new File("servers.cfg");
|
private static final File SERVERS_FILE = new File("servers.cfg");
|
||||||
|
|
||||||
|
@ -113,12 +111,12 @@ public class GuiServers extends GuiList<GuiServers.ServerInfo> implements ActBut
|
||||||
private ActButton editButton;
|
private ActButton editButton;
|
||||||
private ActButton createButton;
|
private ActButton createButton;
|
||||||
|
|
||||||
private GuiServers() {
|
private GuiConnect() {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(int width, int height) {
|
public void init(int width, int height) {
|
||||||
super.init(width, height);
|
super.init(width, height);
|
||||||
this.setDimensions(width, height, 32, height - 60);
|
this.setDimensions(width, height, 32, height - 32);
|
||||||
this.elements.clear();
|
this.elements.clear();
|
||||||
if(SERVERS_FILE.exists()) {
|
if(SERVERS_FILE.exists()) {
|
||||||
try {
|
try {
|
||||||
|
@ -177,12 +175,12 @@ public class GuiServers extends GuiList<GuiServers.ServerInfo> implements ActBut
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 56, 150, 24, this, "Verbinden"));
|
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Verbinden"));
|
||||||
this.add(this.createButton = new ActButton(width / 2 + 233, height - 56, 150, 24, this, "Hinzufügen ..."));
|
this.add(this.createButton = new ActButton(width - 204, 4, 200, 24, this, "Server hinzufügen ..."));
|
||||||
this.add(this.deleteButton = new ActButton(width / 2 - 229, height - 28, 150, 24, this, "Löschen"));
|
this.add(this.deleteButton = new ActButton(width / 2 - 75, height - 28, 150, 24, this, "Löschen"));
|
||||||
this.add(this.editButton = new ActButton(width / 2 - 75, height - 28, 150, 24, this, "Bearbeiten"));
|
this.add(this.editButton = new ActButton(width / 2 + 79, height - 28, 150, 24, this, "Bearbeiten"));
|
||||||
this.add(this.copyButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Kopieren"));
|
this.add(this.copyButton = new ActButton(width / 2 - 229, height - 28, 150, 24, this, "Kopieren"));
|
||||||
this.add(new NavButton(width / 2 - 75, height - 56, 150, 24, GuiConnect.INSTANCE, "Schnellverbdg."));
|
this.add(new NavButton(4, 4, 200, 24, GuiServer.INSTANCE, "Schnellverbindung ..."));
|
||||||
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
|
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
|
||||||
|
|
||||||
this.selectButton.enabled = false;
|
this.selectButton.enabled = false;
|
||||||
|
@ -251,18 +249,18 @@ public class GuiServers extends GuiList<GuiServers.ServerInfo> implements ActBut
|
||||||
}
|
}
|
||||||
else if(button == this.createButton) {
|
else if(button == this.createButton) {
|
||||||
this.setSelected(-1);
|
this.setSelected(-1);
|
||||||
this.gm.displayGuiScreen(new GuiConnect(new ServerInfo("", "", Config.PORT, "", "", "", -1L)));
|
this.gm.displayGuiScreen(new GuiServer(new ServerInfo("", "", Config.PORT, "", "", "", -1L)));
|
||||||
}
|
}
|
||||||
else if(button == this.editButton) {
|
else if(button == this.editButton) {
|
||||||
ServerInfo server = this.getSelected();
|
ServerInfo server = this.getSelected();
|
||||||
if(server != null)
|
if(server != null)
|
||||||
this.gm.displayGuiScreen(new GuiConnect(server));
|
this.gm.displayGuiScreen(new GuiServer(server));
|
||||||
}
|
}
|
||||||
else if(button == this.copyButton) {
|
else if(button == this.copyButton) {
|
||||||
ServerInfo server = this.getSelected();
|
ServerInfo server = this.getSelected();
|
||||||
if(server != null) {
|
if(server != null) {
|
||||||
this.setSelected(-1);
|
this.setSelected(-1);
|
||||||
this.gm.displayGuiScreen(new GuiConnect(new ServerInfo(server.name, server.address, server.port, server.user, server.address, server.access, -1L)));
|
this.gm.displayGuiScreen(new GuiServer(new ServerInfo(server.name, server.address, server.port, server.user, server.address, server.access, -1L)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
214
java/src/game/gui/GuiConvert.java
Executable file
214
java/src/game/gui/GuiConvert.java
Executable file
|
@ -0,0 +1,214 @@
|
||||||
|
package game.gui;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileFilter;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.Date;
|
||||||
|
import game.Game.FileMode;
|
||||||
|
import game.color.TextColor;
|
||||||
|
import game.dimension.Space;
|
||||||
|
import game.gui.element.ActButton;
|
||||||
|
import game.gui.element.ActButton.Mode;
|
||||||
|
import game.gui.element.GuiList;
|
||||||
|
import game.gui.element.ListEntry;
|
||||||
|
import game.gui.element.NavButton;
|
||||||
|
import game.log.Log;
|
||||||
|
import game.renderer.Drawing;
|
||||||
|
import game.util.FileCallback;
|
||||||
|
import game.world.Converter;
|
||||||
|
import game.world.Converter.SaveVersion;
|
||||||
|
import game.world.Region;
|
||||||
|
import game.world.Region.FolderInfo;
|
||||||
|
import game.world.World;
|
||||||
|
|
||||||
|
public class GuiConvert extends GuiList<GuiConvert.SaveInfo> implements ActButton.Callback
|
||||||
|
{
|
||||||
|
protected class SaveInfo implements Comparable<SaveInfo>, ListEntry {
|
||||||
|
private final String file;
|
||||||
|
private final int dimensions;
|
||||||
|
private final int players;
|
||||||
|
private final long seed;
|
||||||
|
private final FolderInfo info;
|
||||||
|
|
||||||
|
public SaveInfo(String file, int dimensions, int players, long seed, FolderInfo info) {
|
||||||
|
this.file = file;
|
||||||
|
this.dimensions = dimensions;
|
||||||
|
this.players = players;
|
||||||
|
this.seed = seed;
|
||||||
|
this.info = info;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFile() {
|
||||||
|
return this.file;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDimensions() {
|
||||||
|
return this.dimensions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPlayers() {
|
||||||
|
return this.players;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mustConvert() {
|
||||||
|
return this.info.legacy != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return this.info.legacy == null ? (this.info.version == null ? "<Unbekannt>" : this.info.version) : this.info.legacy.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isIncompatible() {
|
||||||
|
return this.info.legacy == SaveVersion.RELEASE_1_13;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getLastPlayed() {
|
||||||
|
return this.info.lastPlayed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getSeed() {
|
||||||
|
return this.seed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(SaveInfo comp) {
|
||||||
|
return this.info.lastPlayed < comp.info.lastPlayed ? 1 : (this.info.lastPlayed > comp.info.lastPlayed ? -1 : this.file.compareTo(comp.file));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void select(boolean isDoubleClick, int mouseX, int mouseY)
|
||||||
|
{
|
||||||
|
boolean use = !this.isIncompatible() && this.mustConvert();
|
||||||
|
GuiConvert.this.selectButton.enabled = use;
|
||||||
|
|
||||||
|
if (isDoubleClick && use)
|
||||||
|
{
|
||||||
|
GuiConvert.this.use(GuiConvert.this.selectButton, Mode.PRIMARY);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover)
|
||||||
|
{
|
||||||
|
Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" :
|
||||||
|
(TextColor.GRAY + " - " + TextColor.RESET + (this.getPlayers() > 0 ? this.getPlayers() + " Spieler" : "Keine Spieler"))),
|
||||||
|
x + 2, y, 0xffffffff);
|
||||||
|
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : (this.getDimensions() <= 0 ? "Keine Dimensionen" : this.getDimensions() + " Dimension" + (this.getDimensions() != 1 ? "en" : "") + " erschaffen"))
|
||||||
|
, x + 2, y + 18, 0xff808080);
|
||||||
|
Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" :
|
||||||
|
"Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") +
|
||||||
|
"Zuletzt gespielt: " + DATE_FORMAT.format(new Date(this.getLastPlayed()))) + " " + TextColor.LGRAY + this.getVersion(), x + 2, y + 18 + 16, 0xff808080);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final GuiConvert INSTANCE = new GuiConvert();
|
||||||
|
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
||||||
|
|
||||||
|
private ActButton selectButton;
|
||||||
|
private File dir = null;
|
||||||
|
|
||||||
|
private GuiConvert()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private void load() {
|
||||||
|
this.elements.clear();
|
||||||
|
if(this.dir == null || !this.dir.exists() || !this.dir.isDirectory())
|
||||||
|
return;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
File[] files = dir.listFiles();
|
||||||
|
if(files == null)
|
||||||
|
throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!");
|
||||||
|
for(File file : files) {
|
||||||
|
if(!file.isDirectory())
|
||||||
|
continue;
|
||||||
|
FolderInfo info = Region.loadWorldInfo(file);
|
||||||
|
if(info == null)
|
||||||
|
info = Converter.convertMapFormat(file, false);
|
||||||
|
if(info == null) {
|
||||||
|
this.elements.add(new SaveInfo(file.getName(), -1, -1,
|
||||||
|
0L, new FolderInfo(World.START_TIME, file.lastModified(), null, null)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
int dims = -1;
|
||||||
|
int players = -1;
|
||||||
|
if(info.legacy == null) {
|
||||||
|
dims = 0;
|
||||||
|
File[] folders = new File(new File(dir, file.getName()), "chunk").listFiles(new FileFilter() {
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
return pathname.isDirectory() && !pathname.getName().equals(Space.INSTANCE.getDimensionName());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
if(folders != null) {
|
||||||
|
for(File sub : folders) {
|
||||||
|
File[] dim = sub.listFiles();
|
||||||
|
if(dim != null && dim.length > 0)
|
||||||
|
dims++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
File[] plrs = new File(new File(dir, file.getName()), "players").listFiles(new FileFilter() {
|
||||||
|
public boolean accept(File pathname) {
|
||||||
|
return pathname.getName().endsWith(".nbt");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
players = plrs == null ? 0 : plrs.length;
|
||||||
|
}
|
||||||
|
this.elements.add(new SaveInfo(file.getName(), dims, players,
|
||||||
|
0L, info));
|
||||||
|
}
|
||||||
|
Collections.sort(this.elements);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Log.IO.error("Konnte Weltliste nicht laden", e);
|
||||||
|
this.elements.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void init(int width, int height)
|
||||||
|
{
|
||||||
|
super.init(width, height);
|
||||||
|
this.setDimensions(width, height, 32, height - 32);
|
||||||
|
|
||||||
|
this.load();
|
||||||
|
|
||||||
|
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Konvertieren"));
|
||||||
|
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
|
||||||
|
|
||||||
|
this.add(new ActButton(4, 4, 200, 24, new ActButton.Callback() {
|
||||||
|
public void use(ActButton elem, ActButton.Mode action) {
|
||||||
|
if(GuiConvert.this.gm.theWorld != null)
|
||||||
|
return;
|
||||||
|
GuiConvert.this.gm.showFileDialog(FileMode.DIRECTORY_LOAD, "Ordner wählen", GuiConvert.this.dir, new FileCallback() {
|
||||||
|
public void selected(File file) {
|
||||||
|
GuiConvert.this.dir = file;
|
||||||
|
GuiConvert.this.gm.displayGuiScreen(GuiConvert.this);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, "Ordner wählen ..."));
|
||||||
|
|
||||||
|
this.selectButton.enabled = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return "Welt auswählen";
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getListWidth()
|
||||||
|
{
|
||||||
|
return 660;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSlotHeight()
|
||||||
|
{
|
||||||
|
return 56;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void use(ActButton button, Mode mode)
|
||||||
|
{
|
||||||
|
String dir = this.getSelected().getFile();
|
||||||
|
File folder = new File(this.dir, dir);
|
||||||
|
if(folder.isDirectory())
|
||||||
|
Converter.convertMapFormat(folder, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,8 +9,6 @@ import game.gui.element.Label;
|
||||||
import game.gui.element.NavButton;
|
import game.gui.element.NavButton;
|
||||||
import game.gui.element.Textbox;
|
import game.gui.element.Textbox;
|
||||||
import game.gui.options.GuiOptions;
|
import game.gui.options.GuiOptions;
|
||||||
import game.gui.world.GuiServers;
|
|
||||||
import game.gui.world.GuiWorlds;
|
|
||||||
import game.init.Config;
|
import game.init.Config;
|
||||||
import game.renderer.Drawing;
|
import game.renderer.Drawing;
|
||||||
import game.rng.Random;
|
import game.rng.Random;
|
||||||
|
@ -61,22 +59,19 @@ public class GuiMenu extends Gui {
|
||||||
GuiMenu.this.hacked++;
|
GuiMenu.this.hacked++;
|
||||||
GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!");
|
GuiMenu.this.splashLabel.setText(TextColor.VIOLET + "Hax!");
|
||||||
}
|
}
|
||||||
else if(GuiMenu.this.gm.isServerRunning()) {
|
|
||||||
GuiMenu.this.gm.stopServer(true);
|
|
||||||
}
|
|
||||||
else {
|
else {
|
||||||
GuiMenu.this.gm.displayGuiScreen(GuiWorlds.INSTANCE);
|
GuiMenu.this.gm.displayGuiScreen(GuiConnect.INSTANCE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, this.gm.isServerRunning() ? "Server beenden" : "Server hosten"));
|
}, "Server beitreten"));
|
||||||
this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() {
|
this.add(new ActButton(0, 28, 400, 24, new ActButton.Callback() {
|
||||||
public void use(ActButton elem, Mode action) {
|
public void use(ActButton elem, Mode action) {
|
||||||
if(GuiMenu.this.hacked == 8)
|
if(GuiMenu.this.hacked == 8)
|
||||||
GuiMenu.this.hacked++;
|
GuiMenu.this.hacked++;
|
||||||
else
|
else
|
||||||
GuiMenu.this.gm.displayGuiScreen(GuiServers.INSTANCE);
|
GuiMenu.this.gm.displayGuiScreen(GuiOptions.getPage());
|
||||||
}
|
}
|
||||||
}, "Server beitreten"));
|
}, "Einstellungen"));
|
||||||
this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() {
|
this.infoButton = this.add(new ActButton(0, 56, 400, 24, new ActButton.Callback() {
|
||||||
public void use(ActButton elem, Mode action) {
|
public void use(ActButton elem, Mode action) {
|
||||||
GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE);
|
GuiMenu.this.gm.displayGuiScreen(GuiMenu.this.hacked == 10 ? GuiInfo.HAX : GuiInfo.INSTANCE);
|
||||||
|
@ -100,7 +95,7 @@ public class GuiMenu extends Gui {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
this.add(new NavButton(0, 102, 196, 24, GuiOptions.getPage(), "Einstellungen"));
|
this.add(new NavButton(0, 102, 196, 24, GuiConvert.INSTANCE, "Welt konvertieren"));
|
||||||
this.add(new ActButton(204, 102, 196, 24, new ActButton.Callback() {
|
this.add(new ActButton(204, 102, 196, 24, new ActButton.Callback() {
|
||||||
public void use(ActButton elem, ActButton.Mode action) {
|
public void use(ActButton elem, ActButton.Mode action) {
|
||||||
GuiMenu.this.gm.interrupted = true;
|
GuiMenu.this.gm.interrupted = true;
|
||||||
|
|
|
@ -1,21 +1,19 @@
|
||||||
package game.gui.server;
|
package game.gui;
|
||||||
|
|
||||||
import game.color.TextColor;
|
import game.color.TextColor;
|
||||||
import game.gui.Gui;
|
import game.gui.GuiConnect.ServerInfo;
|
||||||
import game.gui.element.ActButton;
|
import game.gui.element.ActButton;
|
||||||
import game.gui.element.Label;
|
import game.gui.element.Label;
|
||||||
import game.gui.element.NavButton;
|
import game.gui.element.NavButton;
|
||||||
import game.gui.element.Textbox;
|
import game.gui.element.Textbox;
|
||||||
import game.gui.element.Textbox.Action;
|
import game.gui.element.Textbox.Action;
|
||||||
import game.gui.world.GuiServers;
|
|
||||||
import game.gui.world.GuiServers.ServerInfo;
|
|
||||||
import game.init.Config;
|
import game.init.Config;
|
||||||
import game.network.Player;
|
import game.network.Player;
|
||||||
import game.vars.CVarCategory;
|
import game.vars.CVarCategory;
|
||||||
import game.vars.Variable;
|
import game.vars.Variable;
|
||||||
|
|
||||||
public class GuiConnect extends Gui implements Textbox.Callback {
|
public class GuiServer extends Gui implements Textbox.Callback {
|
||||||
public static final GuiConnect INSTANCE = new GuiConnect(null);
|
public static final GuiServer INSTANCE = new GuiServer(null);
|
||||||
|
|
||||||
private final ServerInfo server;
|
private final ServerInfo server;
|
||||||
|
|
||||||
|
@ -32,7 +30,7 @@ public class GuiConnect extends Gui implements Textbox.Callback {
|
||||||
private Label passLabel;
|
private Label passLabel;
|
||||||
private Label accLabel;
|
private Label accLabel;
|
||||||
|
|
||||||
public GuiConnect(ServerInfo server) {
|
public GuiServer(ServerInfo server) {
|
||||||
this.server = server;
|
this.server = server;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,10 +55,10 @@ public class GuiConnect extends Gui implements Textbox.Callback {
|
||||||
this.accBox = this.add(new Textbox(0, 170, 480, 24, Player.MAX_PASS_LENGTH, true, this, this.server == null ? this.lastAcc : this.server.getAccess()));
|
this.accBox = this.add(new Textbox(0, 170, 480, 24, Player.MAX_PASS_LENGTH, true, this, this.server == null ? this.lastAcc : this.server.getAccess()));
|
||||||
this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() {
|
this.add(new ActButton(0, 220, 480, 24, new ActButton.Callback() {
|
||||||
public void use(ActButton elem, ActButton.Mode action) {
|
public void use(ActButton elem, ActButton.Mode action) {
|
||||||
GuiConnect.this.connect();
|
GuiServer.this.connect();
|
||||||
}
|
}
|
||||||
}, this.server == null ? "Verbinden" : (this.server.getName().isEmpty() ? "Hinzufügen" : "Übernehmen")));
|
}, this.server == null ? "Verbinden" : (this.server.getName().isEmpty() ? "Hinzufügen" : "Übernehmen")));
|
||||||
this.add(new NavButton(0, 250, 480, 24, GuiServers.INSTANCE, "Zurück"));
|
this.add(new NavButton(0, 250, 480, 24, GuiConnect.INSTANCE, "Zurück"));
|
||||||
if(this.server != null)
|
if(this.server != null)
|
||||||
this.nameLabel = this.add(new Label(0, -70, 410, 20, "Name", true));
|
this.nameLabel = this.add(new Label(0, -70, 410, 20, "Name", true));
|
||||||
this.addrLabel = this.add(new Label(0, 0, 410, 20, "Adresse", true));
|
this.addrLabel = this.add(new Label(0, 0, 410, 20, "Adresse", true));
|
||||||
|
@ -125,7 +123,7 @@ public class GuiConnect extends Gui implements Textbox.Callback {
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.server.setData(name, addr, port, user, pass, acc);
|
this.server.setData(name, addr, port, user, pass, acc);
|
||||||
GuiServers.INSTANCE.applyServer(this.server);
|
GuiConnect.INSTANCE.applyServer(this.server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -447,7 +447,7 @@ public class Textbox extends Element {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawOverlay() {
|
public void drawOverlay() {
|
||||||
if(this.editable && this.sel_start >= 0 && this.sel_end == this.sel_start && this.gm.ftime() % 1.0f < 0.5f) {
|
if(this.editable && this.sel_start >= 0 && this.sel_end == this.sel_start && Util.ftime() % 1.0f < 0.5f) {
|
||||||
int x1 = this.pos_x + this.margin_x1;
|
int x1 = this.pos_x + this.margin_x1;
|
||||||
int y1 = this.pos_y + this.margin_y1;
|
int y1 = this.pos_y + this.margin_y1;
|
||||||
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
|
int x2 = this.size_x - (this.margin_x1 + this.margin_x2);
|
||||||
|
|
|
@ -1,38 +0,0 @@
|
||||||
package game.gui.options;
|
|
||||||
|
|
||||||
import game.gui.element.Textbox;
|
|
||||||
import game.gui.element.Label;
|
|
||||||
import game.gui.element.Textbox.Action;
|
|
||||||
|
|
||||||
public class GuiNetwork extends GuiOptions {
|
|
||||||
protected GuiNetwork() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(int width, int height) {
|
|
||||||
this.add(new Label(30, 360, 440, 20, "Server-Port für lokale Welten", true));
|
|
||||||
final Textbox portBox = this.add(new Textbox(30, 380, 440, 24, 5, true, new Textbox.Callback() {
|
|
||||||
public void use(Textbox elem, Action value) {
|
|
||||||
if(value == Action.SEND || value == Action.UNFOCUS) {
|
|
||||||
int port = -1;
|
|
||||||
try {
|
|
||||||
port = Integer.parseInt(elem.getText());
|
|
||||||
}
|
|
||||||
catch(NumberFormatException e) {
|
|
||||||
}
|
|
||||||
if(port < 0 || port > 65535) {
|
|
||||||
elem.setText("" + GuiNetwork.this.gm.port);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
GuiNetwork.this.gm.port = port;
|
|
||||||
GuiNetwork.this.gm.setDirty();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, "" + this.gm.port));
|
|
||||||
super.init(width, height);
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return "Server und Netzwerk";
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -5,7 +5,7 @@ import game.gui.GuiMenu;
|
||||||
import game.gui.element.NavButton;
|
import game.gui.element.NavButton;
|
||||||
|
|
||||||
public abstract class GuiOptions extends Gui {
|
public abstract class GuiOptions extends Gui {
|
||||||
private static final GuiOptions[] PAGES = {lastPage = new GuiBinds(), new GuiStyle(), new GuiDisplay(), new GuiSound(), new GuiNetwork()};
|
private static final GuiOptions[] PAGES = {lastPage = new GuiBinds(), new GuiStyle(), new GuiDisplay(), new GuiSound()};
|
||||||
|
|
||||||
private static GuiOptions lastPage;
|
private static GuiOptions lastPage;
|
||||||
|
|
||||||
|
|
|
@ -1,257 +0,0 @@
|
||||||
package game.gui.world;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import game.color.TextColor;
|
|
||||||
import game.gui.Gui;
|
|
||||||
import game.gui.element.ActButton;
|
|
||||||
import game.gui.element.ActButton.Mode;
|
|
||||||
import game.gui.element.Label;
|
|
||||||
import game.gui.element.NavButton;
|
|
||||||
import game.gui.element.Textbox;
|
|
||||||
import game.gui.element.Textbox.Action;
|
|
||||||
import game.world.Region;
|
|
||||||
|
|
||||||
public class GuiCreate extends Gui implements ActButton.Callback, Textbox.Callback
|
|
||||||
{
|
|
||||||
public static final GuiCreate INSTANCE = new GuiCreate();
|
|
||||||
// private static final String MBASE32_CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ!?-_<3";
|
|
||||||
// private static final String MBASE64A_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-!";
|
|
||||||
// private static final String MBASE64B_CHARS = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz<_";
|
|
||||||
|
|
||||||
private Textbox worldNameField;
|
|
||||||
// private Textbox worldSeedField;
|
|
||||||
private ActButton createButton;
|
|
||||||
private Label actionLabel;
|
|
||||||
private Label nameLabel;
|
|
||||||
// private Label seed;
|
|
||||||
// private Label decoded;
|
|
||||||
|
|
||||||
private boolean alreadyGenerated;
|
|
||||||
private boolean fileExists;
|
|
||||||
|
|
||||||
// private static long getSeed(String str) {
|
|
||||||
// if(str == null || str.isEmpty())
|
|
||||||
// return (new Random()).longv();
|
|
||||||
// try {
|
|
||||||
// return Long.parseLong(str);
|
|
||||||
// }
|
|
||||||
// catch(NumberFormatException e) {
|
|
||||||
// }
|
|
||||||
// long seed = 0L;
|
|
||||||
// if(str.length() <= 9) {
|
|
||||||
// for(int z = 0; z < str.length(); z++) {
|
|
||||||
// seed <<= 7;
|
|
||||||
// char c = str.charAt(z);
|
|
||||||
// if(c >= 0x80) {
|
|
||||||
// seed = -1L;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// seed |= (long)c;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// else if(str.length() == 10) {
|
|
||||||
// String ch = str.indexOf('<') != -1 || str.indexOf('_') != -1 ? MBASE64B_CHARS : MBASE64A_CHARS;
|
|
||||||
// for(int z = 0; z < str.length(); z++) {
|
|
||||||
// seed <<= 6;
|
|
||||||
// int idx = ch.indexOf(str.charAt(z));
|
|
||||||
// if(idx == -1) {
|
|
||||||
// seed = -1L;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// seed |= (long)idx;
|
|
||||||
// }
|
|
||||||
// if(seed != -1L)
|
|
||||||
// seed |= ch == MBASE64B_CHARS ? 0xb000000000000000L : 0xa000000000000000L;
|
|
||||||
// }
|
|
||||||
// else if(str.length() <= 12) {
|
|
||||||
// for(int z = 0; z < str.length(); z++) {
|
|
||||||
// seed <<= 5;
|
|
||||||
// int idx = MBASE32_CHARS.indexOf(Character.toUpperCase(str.charAt(z)));
|
|
||||||
// if(idx == -1) {
|
|
||||||
// seed = -1L;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// seed |= (long)idx;
|
|
||||||
// }
|
|
||||||
// if(seed != -1L)
|
|
||||||
// seed |= str.length() == 12 ? 0x9000000000000000L : 0x8000000000000000L;
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// seed = -1L;
|
|
||||||
// }
|
|
||||||
// if(seed == -1L) {
|
|
||||||
// seed = 0L;
|
|
||||||
// for(int z = 0; z < str.length(); z++) {
|
|
||||||
// seed <<= 7;
|
|
||||||
// seed |= (long)((char)(str.charAt(z) & 0x7f));
|
|
||||||
// }
|
|
||||||
// seed = (seed ^ (((long)str.hashCode()) | (~((long)str.hashCode()) << 32))) | 0xc000000000000000L;
|
|
||||||
// }
|
|
||||||
// return seed;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// private static String decodeSeed(long seed, String def) {
|
|
||||||
// if(seed == 0L)
|
|
||||||
// return (def == null ? ("" + seed) : def);
|
|
||||||
// if((seed & 0x8000000000000000L) == 0L) {
|
|
||||||
// String str = "";
|
|
||||||
// long value = seed;
|
|
||||||
// while(value != 0L) {
|
|
||||||
// char c = (char)(value & 0x7fL);
|
|
||||||
// if(c < 32 || c > 126)
|
|
||||||
// return (def == null ? ("" + seed) : def);
|
|
||||||
// str = c + str;
|
|
||||||
// value >>= 7;
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// Long.parseLong(str);
|
|
||||||
// }
|
|
||||||
// catch(NumberFormatException e) {
|
|
||||||
// return str;
|
|
||||||
// }
|
|
||||||
// return (def == null ? ("" + seed) : def);
|
|
||||||
// }
|
|
||||||
// String chset;
|
|
||||||
// int len;
|
|
||||||
// int shift;
|
|
||||||
// long mask;
|
|
||||||
// long type = (seed >> 60) & 0xf;
|
|
||||||
// switch((int)type) {
|
|
||||||
// case 0x8:
|
|
||||||
// chset = MBASE32_CHARS;
|
|
||||||
// len = 11;
|
|
||||||
// shift = 5;
|
|
||||||
// mask = 0x1fL;
|
|
||||||
// break;
|
|
||||||
// case 0x9:
|
|
||||||
// chset = MBASE32_CHARS;
|
|
||||||
// len = 12;
|
|
||||||
// shift = 5;
|
|
||||||
// mask = 0x1fL;
|
|
||||||
// break;
|
|
||||||
// case 0xa:
|
|
||||||
// chset = MBASE64A_CHARS;
|
|
||||||
// len = 10;
|
|
||||||
// shift = 6;
|
|
||||||
// mask = 0x3fL;
|
|
||||||
// break;
|
|
||||||
// case 0xb:
|
|
||||||
// chset = MBASE64B_CHARS;
|
|
||||||
// len = 10;
|
|
||||||
// shift = 6;
|
|
||||||
// mask = 0x3fL;
|
|
||||||
// break;
|
|
||||||
// default:
|
|
||||||
// return (def == null ? ("" + seed) : def);
|
|
||||||
// }
|
|
||||||
// String str = "";
|
|
||||||
// for(int z = 0; z < len; z++) {
|
|
||||||
// str = chset.charAt((int)(seed & mask)) + str;
|
|
||||||
// seed >>= shift;
|
|
||||||
// }
|
|
||||||
// try {
|
|
||||||
// Long.parseLong(str);
|
|
||||||
// }
|
|
||||||
// catch(NumberFormatException e) {
|
|
||||||
// return str;
|
|
||||||
// }
|
|
||||||
// return (def == null ? ("" + seed) : def);
|
|
||||||
// }
|
|
||||||
|
|
||||||
private GuiCreate()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreen()
|
|
||||||
{
|
|
||||||
// String text = this.worldSeedField.getText();
|
|
||||||
// if(text.isEmpty()) {
|
|
||||||
// this.seed.setText("Startwert [Zufällig]");
|
|
||||||
// this.decoded.setText("Dekodiert: -");
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// this.seed.setText("Startwert [" + getSeed(text) + "]");
|
|
||||||
// try {
|
|
||||||
// this.decoded.setText("Dekodiert: " + decodeSeed(Long.parseLong(text), "-"));
|
|
||||||
// }
|
|
||||||
// catch(NumberFormatException e) {
|
|
||||||
// this.decoded.setText("Dekodiert: " + decodeSeed(getSeed(text), "-"));
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
this.fileExists = false;
|
|
||||||
String text = this.worldNameField.getText().trim();
|
|
||||||
this.createButton.enabled = !text.isEmpty();
|
|
||||||
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
|
|
||||||
this.createButton.enabled = false;
|
|
||||||
this.actionLabel.setText(this.getFolderDesc());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(int width, int height)
|
|
||||||
{
|
|
||||||
// UniverseRegistry.clear();
|
|
||||||
this.alreadyGenerated = false;
|
|
||||||
this.createButton = this.add(new ActButton(0, 340, 160, 24, this, "Welt erstellen"));
|
|
||||||
this.add(new NavButton(164, 340, 160, 24, GuiWorlds.INSTANCE, "Abbrechen"));
|
|
||||||
this.worldNameField = this.add(new Textbox(20, 40, 284, 24, 256, true, this, GuiWorlds.VALID_FILE, ""));
|
|
||||||
this.worldNameField.setSelected();
|
|
||||||
// this.worldSeedField = this.add(new Textbox(20, 140, 284, 24, 256, true, this, ""));
|
|
||||||
// this.worldUserField = this.add(new Textbox(20, 90, 284, 24, Player.MAX_USER_LENGTH, true, this, Player.VALID_USER, ""));
|
|
||||||
this.createButton.enabled = false;
|
|
||||||
this.actionLabel = this.add(new Label(20, 20, 284, 20, this.getFolderDesc(), true));
|
|
||||||
// this.userLabel = this.add(new Label(20, 70, 284, 20, this.getUserDesc(), true));
|
|
||||||
// this.seed = this.add(new Label(20, 120, 284, 20, "", true));
|
|
||||||
// this.decoded = this.add(new Label(20, 164, 284, 20, "", true));
|
|
||||||
this.shift();
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return "Neue Welt erstellen";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void use(ActButton button, Mode mode)
|
|
||||||
{
|
|
||||||
// if (button == this.createButton)
|
|
||||||
// {
|
|
||||||
// this.gm.displayGuiScreen(null);
|
|
||||||
if(this.alreadyGenerated)
|
|
||||||
return;
|
|
||||||
this.alreadyGenerated = true;
|
|
||||||
// Config.clear();
|
|
||||||
// UniverseRegistry.clear();
|
|
||||||
// dim.setSeed(getSeed(this.worldSeedField.getText()));
|
|
||||||
File dir = new File(Region.SAVE_DIR, this.worldNameField.getText().trim());
|
|
||||||
// Dimension[] dims = UniverseRegistry.registerPreset(dim);
|
|
||||||
// Config.set("spawnDim", "" + dims[0].getDimensionId(), null);
|
|
||||||
// Region.saveWorldInfo(dir, World.START_TIME, this.worldUserField.getText());
|
|
||||||
// for(Dimension sdim : dims) {
|
|
||||||
// NBTTagCompound data = new NBTTagCompound();
|
|
||||||
// data.setTag("Generator", sdim.toNbt(true));
|
|
||||||
// File chunkDir = new File(new File(dir, "chunk"), sdim.getDimensionName());
|
|
||||||
// chunkDir.mkdirs();
|
|
||||||
// File file = new File(chunkDir, "data.nbt");
|
|
||||||
// try {
|
|
||||||
// NBTLoader.writeGZip(data, file);
|
|
||||||
// }
|
|
||||||
// catch(Exception e) {
|
|
||||||
// Log.IO.error(e, "Konnte Weltdaten nicht speichern");
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
this.gm.startServer(dir);
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void use(Textbox elem, Action action) {
|
|
||||||
if(action == Action.SEND)
|
|
||||||
this.use(this.createButton, Mode.PRIMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getFolderDesc() {
|
|
||||||
return (this.worldNameField.getText().trim().isEmpty() || this.fileExists ? TextColor.DRED : "")
|
|
||||||
+ "Ordner der Welt" + (this.fileExists ? " - Existiert bereits" : "");
|
|
||||||
}
|
|
||||||
|
|
||||||
// private String getUserDesc() {
|
|
||||||
// return (this.worldUserField.getText().isEmpty() ? TextColor.DRED : "") + "Spielername";
|
|
||||||
// }
|
|
||||||
}
|
|
|
@ -1,141 +0,0 @@
|
||||||
package game.gui.world;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
import game.color.TextColor;
|
|
||||||
import game.gui.Gui;
|
|
||||||
import game.gui.element.ActButton;
|
|
||||||
import game.gui.element.ActButton.Mode;
|
|
||||||
import game.gui.element.Label;
|
|
||||||
import game.gui.element.Textbox;
|
|
||||||
import game.gui.element.Textbox.Action;
|
|
||||||
import game.network.Player;
|
|
||||||
import game.world.Region;
|
|
||||||
|
|
||||||
public class GuiEdit extends Gui implements ActButton.Callback, Textbox.Callback {
|
|
||||||
public static interface Callback {
|
|
||||||
void confirm(String name);
|
|
||||||
}
|
|
||||||
|
|
||||||
private final String original;
|
|
||||||
private final boolean player;
|
|
||||||
private final String title;
|
|
||||||
private final String action;
|
|
||||||
private final String desc;
|
|
||||||
private final Callback callback;
|
|
||||||
|
|
||||||
private Textbox nameField;
|
|
||||||
private ActButton actionButton;
|
|
||||||
private ActButton cancelButton;
|
|
||||||
private Label actionLabel;
|
|
||||||
private boolean fileExists;
|
|
||||||
private boolean noChange;
|
|
||||||
|
|
||||||
public GuiEdit(String original, boolean player, String title, String action, String desc, Callback callback) {
|
|
||||||
this.original = original;
|
|
||||||
this.player = player;
|
|
||||||
this.title = title;
|
|
||||||
this.action = action;
|
|
||||||
this.desc = desc;
|
|
||||||
this.callback = callback;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreen() {
|
|
||||||
this.actionButton.enabled = true;
|
|
||||||
this.fileExists = false;
|
|
||||||
this.noChange = false;
|
|
||||||
String text = this.nameField.getText().trim();
|
|
||||||
if(text.isEmpty() || (this.noChange = (text.equals(this.original) || (!this.player && !text.replaceAll("[\\./\"]", "_")
|
|
||||||
.equals(text))))) {
|
|
||||||
this.actionButton.enabled = false;
|
|
||||||
this.actionLabel.setText(this.getLabelDesc());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(this.player) {
|
|
||||||
this.actionLabel.setText(this.getLabelDesc());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// {
|
|
||||||
// if(!StringValidator.isValidUser(text))
|
|
||||||
// this.actionButton.enabled = false;
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// for(String n : GuiCreate.DISALLOWED_FILES) {
|
|
||||||
// if(text.equalsIgnoreCase(n)) {
|
|
||||||
// this.actionButton.enabled = false;
|
|
||||||
// return;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
if(this.fileExists = (!text.isEmpty() && new File(Region.SAVE_DIR, text).exists()))
|
|
||||||
this.actionButton.enabled = false;
|
|
||||||
this.actionLabel.setText(this.getLabelDesc());
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(int width, int height) {
|
|
||||||
this.actionButton = this.add(new ActButton(width / 2 - 200, height / 4 + 96 + 12, 198, 24, this, this.action));
|
|
||||||
this.cancelButton = this.add(new ActButton(width / 2 + 2, height / 4 + 96 + 12, 198, 24, this, "Abbrechen"));
|
|
||||||
this.nameField = this.add(new Textbox(width / 2 - 200, 60, 400, 24, this.player ? Player.MAX_USER_LENGTH : 256, true, this, this.player ? Player.VALID_USER : GuiWorlds.VALID_FILE, this.original == null ? "" : this.original));
|
|
||||||
this.nameField.setSelected();
|
|
||||||
// if(this.player) {
|
|
||||||
// this.nameField.setMaxStringLength(16);
|
|
||||||
// this.nameField.setValidator(new Predicate<String>() {
|
|
||||||
// public boolean test(String name) {
|
|
||||||
// return NetHandlerPlayServer.isValidUser(name);
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
// else {
|
|
||||||
// this.nameField.setValidator(new Predicate<String>() {
|
|
||||||
// public boolean test(String name) {
|
|
||||||
// for(int z = 0; z < name.length(); z++) {
|
|
||||||
// if(GuiCreate.DISALLOWED_CHARS.contains(name.charAt(z)))
|
|
||||||
// return false;
|
|
||||||
// }
|
|
||||||
// return true;
|
|
||||||
// }
|
|
||||||
// });
|
|
||||||
// }
|
|
||||||
this.actionLabel = this.add(new Label(width / 2 - 250, 20, 500, 24, this.getLabelDesc()));
|
|
||||||
// this.shift();
|
|
||||||
// this.nameField.setText();
|
|
||||||
this.actionButton.enabled = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return "Welt bearbeiten";
|
|
||||||
}
|
|
||||||
|
|
||||||
public void use(ActButton btn, Mode mode) {
|
|
||||||
this.callback.confirm(btn == this.actionButton ? this.nameField.getText().trim() : null);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void use(Textbox elem, Action action) {
|
|
||||||
if(action == Action.SEND)
|
|
||||||
this.use(this.actionButton, Mode.PRIMARY);
|
|
||||||
}
|
|
||||||
|
|
||||||
// protected void actionPerformed(Button button) throws IOException {
|
|
||||||
// if(button.enabled) {
|
|
||||||
// if(button.id == 1) {
|
|
||||||
// }
|
|
||||||
// else if(button.id == 0) {
|
|
||||||
// this.callback.confirm(this.nameField.getText().trim());
|
|
||||||
//// this.gm.displayGuiScreen(this.parent);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
// protected void keyTyped(char typedChar, int keyCode) throws IOException {
|
|
||||||
// ((Button)this.buttonList.get(0)).enabled = this.nameField.getText().trim().length() > 0;
|
|
||||||
////
|
|
||||||
//// if(keyCode == 28 || keyCode == 156) {
|
|
||||||
//// this.actionPerformed((Button)this.buttonList.get(0));
|
|
||||||
//// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private String getLabelDesc() {
|
|
||||||
return (this.actionButton.enabled ? "" : TextColor.DRED) + this.desc +
|
|
||||||
(this.fileExists ? " - Existiert bereits" : (this.noChange ? " - Nicht geändert" : ""));
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,651 +0,0 @@
|
||||||
package game.gui.world;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileFilter;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.nio.file.Files;
|
|
||||||
import java.nio.file.StandardCopyOption;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Date;
|
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
import game.collect.Sets;
|
|
||||||
|
|
||||||
import game.Game.FileMode;
|
|
||||||
import game.color.TextColor;
|
|
||||||
import game.dimension.Space;
|
|
||||||
import game.gui.GuiConfirm;
|
|
||||||
import game.gui.GuiMenu;
|
|
||||||
import game.gui.element.ActButton;
|
|
||||||
import game.gui.element.ActButton.Mode;
|
|
||||||
import game.gui.element.GuiList;
|
|
||||||
import game.gui.element.ListEntry;
|
|
||||||
import game.gui.element.NavButton;
|
|
||||||
import game.gui.world.GuiEdit.Callback;
|
|
||||||
import game.log.Log;
|
|
||||||
import game.nbt.NBTLoader;
|
|
||||||
import game.nbt.NBTTagCompound;
|
|
||||||
import game.renderer.Drawing;
|
|
||||||
import game.util.CharValidator;
|
|
||||||
import game.util.FileCallback;
|
|
||||||
import game.util.FileUtils;
|
|
||||||
import game.window.Window;
|
|
||||||
import game.world.Converter;
|
|
||||||
import game.world.Converter.SaveVersion;
|
|
||||||
import game.world.Region;
|
|
||||||
import game.world.Region.FolderInfo;
|
|
||||||
import game.world.World;
|
|
||||||
|
|
||||||
public class GuiWorlds extends GuiList<GuiWorlds.SaveInfo> implements ActButton.Callback
|
|
||||||
{
|
|
||||||
protected class SaveInfo implements Comparable<SaveInfo>, ListEntry {
|
|
||||||
private final String file;
|
|
||||||
private final int dimensions;
|
|
||||||
private final int players;
|
|
||||||
private final long seed;
|
|
||||||
private final FolderInfo info;
|
|
||||||
|
|
||||||
public SaveInfo(String file, int dimensions, int players, long seed, FolderInfo info) {
|
|
||||||
this.file = file;
|
|
||||||
this.dimensions = dimensions;
|
|
||||||
this.players = players;
|
|
||||||
this.seed = seed;
|
|
||||||
this.info = info;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getFile() {
|
|
||||||
return this.file;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getDimensions() {
|
|
||||||
return this.dimensions;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getPlayers() {
|
|
||||||
return this.players;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean mustConvert() {
|
|
||||||
return this.info.legacy != null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVersion() {
|
|
||||||
return this.info.legacy == null ? (this.info.version == null ? "<Unbekannt>" : this.info.version) : this.info.legacy.toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isIncompatible() {
|
|
||||||
return this.info.legacy == SaveVersion.RELEASE_1_13;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getLastPlayed() {
|
|
||||||
return this.info.lastPlayed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public long getSeed() {
|
|
||||||
return this.seed;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int compareTo(SaveInfo comp) {
|
|
||||||
return this.info.lastPlayed < comp.info.lastPlayed ? 1 : (this.info.lastPlayed > comp.info.lastPlayed ? -1 : this.file.compareTo(comp.file));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void select(boolean isDoubleClick, int mouseX, int mouseY)
|
|
||||||
{
|
|
||||||
boolean use = !this.isIncompatible();
|
|
||||||
boolean cur = use && !this.mustConvert();
|
|
||||||
GuiWorlds.this.selectButton.setText(!use || !cur ? "Konvertieren" : "Server starten");
|
|
||||||
GuiWorlds.this.selectButton.enabled = use;
|
|
||||||
GuiWorlds.this.deleteButton.enabled = true;
|
|
||||||
GuiWorlds.this.pruneButton.enabled = cur;
|
|
||||||
GuiWorlds.this.copyButton.enabled = use;
|
|
||||||
GuiWorlds.this.moveButton.enabled = use;
|
|
||||||
GuiWorlds.this.seedButton.enabled = cur;
|
|
||||||
|
|
||||||
if (isDoubleClick && use)
|
|
||||||
{
|
|
||||||
GuiWorlds.this.playWorld();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void draw(int x, int y, int mouseXIn, int mouseYIn, boolean hover)
|
|
||||||
{
|
|
||||||
Drawing.drawText((this.isIncompatible() ? TextColor.DRED : "") + this.getFile() + (this.mustConvert() ? "" :
|
|
||||||
(TextColor.GRAY + " - " + TextColor.RESET + (this.getPlayers() > 0 ? this.getPlayers() + " Spieler" : "Keine Spieler"))),
|
|
||||||
x + 2, y, 0xffffffff);
|
|
||||||
Drawing.drawText((this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON : "") + this.getVersion() : (this.getDimensions() <= 0 ? "Keine Dimensionen" : this.getDimensions() + " Dimension" + (this.getDimensions() != 1 ? "en" : "") + " erschaffen"))
|
|
||||||
, x + 2, y + 18, 0xff808080);
|
|
||||||
Drawing.drawText(this.mustConvert() ? (this.isIncompatible() ? TextColor.CRIMSON + "Kann nicht konvertiert werden!" :
|
|
||||||
"Muss konvertiert werden!") : ( // "Kreativmodus: " + (info.isNoCreative() ? "Aus" : "An") +
|
|
||||||
"Zuletzt gespielt: " + DATE_FORMAT.format(new Date(this.getLastPlayed()))) + " " + TextColor.LGRAY + this.getVersion(), x + 2, y + 18 + 16, 0xff808080);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static final GuiWorlds INSTANCE = new GuiWorlds();
|
|
||||||
public static final Set<Character> DISALLOWED_CHARS = Sets.newHashSet('/', '\n', '\r', '\t', '\u0000', '\f', '`', '?', '*', '\\',
|
|
||||||
'<', '>', '|', '\"', ':');
|
|
||||||
public static final CharValidator VALID_FILE = new CharValidator() {
|
|
||||||
public boolean valid(char ch) {
|
|
||||||
return !DISALLOWED_CHARS.contains(ch);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
private static final SimpleDateFormat DATE_FORMAT = new SimpleDateFormat("dd.MM.yyyy HH:mm:ss");
|
|
||||||
|
|
||||||
private boolean starting;
|
|
||||||
private int warningTimer;
|
|
||||||
private String warningMessage;
|
|
||||||
private ActButton deleteButton;
|
|
||||||
private ActButton pruneButton;
|
|
||||||
private ActButton selectButton;
|
|
||||||
private ActButton copyButton;
|
|
||||||
private ActButton moveButton;
|
|
||||||
private ActButton seedButton;
|
|
||||||
// private ActButton userButton;
|
|
||||||
// private ActButton dupeButton;
|
|
||||||
private ActButton createButton;
|
|
||||||
|
|
||||||
private GuiWorlds()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void init(int width, int height)
|
|
||||||
{
|
|
||||||
super.init(width, height);
|
|
||||||
this.starting = false;
|
|
||||||
this.setDimensions(width, height, 32, height - 60);
|
|
||||||
boolean create = true;
|
|
||||||
this.elements.clear();
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Region.SAVE_DIR.mkdirs();
|
|
||||||
if(!Region.SAVE_DIR.exists() || !Region.SAVE_DIR.isDirectory())
|
|
||||||
throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!");
|
|
||||||
// java.util.List<SaveInfo> list = Lists.<SaveInfo>newArrayList();
|
|
||||||
File[] files = Region.SAVE_DIR.listFiles();
|
|
||||||
if(files == null)
|
|
||||||
throw new RuntimeException("Kann den Speicherordner für Welten nicht lesen oder öffnen!");
|
|
||||||
for(File file : files) {
|
|
||||||
if(!file.isDirectory())
|
|
||||||
continue;
|
|
||||||
FolderInfo info = Region.loadWorldInfo(file);
|
|
||||||
if(info == null)
|
|
||||||
info = Converter.convertMapFormat(file, false);
|
|
||||||
if(info == null) {
|
|
||||||
this.elements.add(new SaveInfo(file.getName(), -1, -1,
|
|
||||||
0L, new FolderInfo(World.START_TIME, file.lastModified(), null, null)));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
int dims = -1;
|
|
||||||
int players = -1;
|
|
||||||
if(info.legacy == null) {
|
|
||||||
dims = 0;
|
|
||||||
File[] folders = new File(new File(Region.SAVE_DIR, file.getName()), "chunk").listFiles(new FileFilter() {
|
|
||||||
public boolean accept(File pathname) {
|
|
||||||
return pathname.isDirectory() && !pathname.getName().equals(Space.INSTANCE.getDimensionName());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
if(folders != null) {
|
|
||||||
for(File sub : folders) {
|
|
||||||
File[] dim = sub.listFiles();
|
|
||||||
if(dim != null && dim.length > 0)
|
|
||||||
dims++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
File[] plrs = new File(new File(Region.SAVE_DIR, file.getName()), "players").listFiles(new FileFilter() {
|
|
||||||
public boolean accept(File pathname) {
|
|
||||||
return pathname.getName().endsWith(".nbt");
|
|
||||||
}
|
|
||||||
});
|
|
||||||
players = plrs == null ? 0 : plrs.length;
|
|
||||||
}
|
|
||||||
this.elements.add(new SaveInfo(file.getName(), dims, players,
|
|
||||||
0L, info));
|
|
||||||
}
|
|
||||||
// this.saveList = list;
|
|
||||||
Collections.sort(this.elements);
|
|
||||||
}
|
|
||||||
catch (Exception e)
|
|
||||||
{
|
|
||||||
Log.IO.error("Konnte Weltliste nicht laden", e);
|
|
||||||
this.elements.clear();
|
|
||||||
create = false;
|
|
||||||
this.warningTimer = 120;
|
|
||||||
this.warningMessage = "Welten-Ordner nicht lesbar!";
|
|
||||||
}
|
|
||||||
|
|
||||||
this.add(this.selectButton = new ActButton(width / 2 - 383, height - 56, 150, 24, this, "Server starten"));
|
|
||||||
this.add(this.createButton = new ActButton(width / 2 + 233, height - 56, 150, 24, this,
|
|
||||||
(create ? "" : "" + TextColor.DRED) + (create ? "Neue Welt ..." : "Fehler!")));
|
|
||||||
this.add(this.deleteButton = new ActButton(width / 2 - 229, height - 28, 150, 24, this, "Löschen"));
|
|
||||||
this.add(this.pruneButton = new ActButton(width / 2 - 75, height - 28, 150, 24, this, "Leeren"));
|
|
||||||
this.add(this.copyButton = new ActButton(width / 2 - 383, height - 28, 150, 24, this, "Kopieren"));
|
|
||||||
this.add(this.moveButton = new ActButton(width / 2 + 79, height - 28, 150, 24, this, "Verschieben"));
|
|
||||||
this.add(this.seedButton = new ActButton(width / 2 - 75, height - 56, 150, 24, this, "Startwert"));
|
|
||||||
// this.add(this.userButton = new ActButton(width / 2 - 229, height - 56, 150, 24, this, "Spieler"));
|
|
||||||
// this.add(this.dupeButton = new ActButton(width / 2 + 79, height - 56, 150, 24, this, "Duplizieren"));
|
|
||||||
this.add(new NavButton(width / 2 + 233, height - 28, 150, 24, GuiMenu.INSTANCE, "Abbrechen"));
|
|
||||||
|
|
||||||
this.add(new ActButton(4, 4, 200, 24, new ActButton.Callback() {
|
|
||||||
public void use(ActButton elem, ActButton.Mode action) {
|
|
||||||
if(GuiWorlds.this.gm.theWorld != null)
|
|
||||||
return;
|
|
||||||
GuiWorlds.this.gm.showFileDialog(FileMode.DIRECTORY_LOAD, "Welt importieren", Region.SAVE_DIR, new FileCallback() {
|
|
||||||
public void selected(File file) {
|
|
||||||
File parent = file.getParentFile();
|
|
||||||
if(parent != null && Region.SAVE_DIR.getAbsoluteFile().equals(parent.getAbsoluteFile())) {
|
|
||||||
GuiWorlds.this.warningTimer = 120;
|
|
||||||
GuiWorlds.this.warningMessage = "Ordner befindet sich bereits im Weltenorder";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
FolderInfo info = Region.loadWorldInfo(file);
|
|
||||||
if(info == null)
|
|
||||||
info = Converter.convertMapFormat(file, false);
|
|
||||||
if(info == null || info.legacy == SaveVersion.RELEASE_1_13) {
|
|
||||||
GuiWorlds.this.warningTimer = 120;
|
|
||||||
GuiWorlds.this.warningMessage = info == null ? "Keine Weltdaten gefunden" : "Weltdaten haben inkompatible Version";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int n = 0;
|
|
||||||
File newDir;
|
|
||||||
do {
|
|
||||||
newDir = new File(Region.SAVE_DIR, file.getName() + (n > 0 ? "_" + n : ""));
|
|
||||||
n++;
|
|
||||||
}
|
|
||||||
while(newDir.exists());
|
|
||||||
Log.IO.info("Kopiere Welt " + file + " nach " + newDir);
|
|
||||||
if(!copyFiles(file, newDir, file.listFiles()))
|
|
||||||
GuiWorlds.this.displayWarning("Fehler beim Kopieren der Welt, diese könnte unvollständig sein!");
|
|
||||||
else
|
|
||||||
GuiWorlds.this.displayInfo("Welt wurde in den Weltenordner kopiert");
|
|
||||||
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}, "Welt importieren"));
|
|
||||||
|
|
||||||
this.selectButton.enabled = false;
|
|
||||||
this.deleteButton.enabled = false;
|
|
||||||
this.pruneButton.enabled = false;
|
|
||||||
this.copyButton.enabled = false;
|
|
||||||
this.moveButton.enabled = false;
|
|
||||||
this.seedButton.enabled = false;
|
|
||||||
this.createButton.enabled = create;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayWarning(String msg) {
|
|
||||||
this.warningTimer = 120;
|
|
||||||
this.warningMessage = TextColor.DRED + msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void displayInfo(String msg) {
|
|
||||||
this.warningTimer = 40;
|
|
||||||
this.warningMessage = TextColor.DGREEN + msg;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return "Welt auswählen";
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getListWidth()
|
|
||||||
{
|
|
||||||
return 660;
|
|
||||||
}
|
|
||||||
|
|
||||||
public int getSlotHeight()
|
|
||||||
{
|
|
||||||
return 56;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void updateScreen() {
|
|
||||||
super.updateScreen();
|
|
||||||
// this.userField.updateCursorCounter();
|
|
||||||
if(this.warningTimer > 0) {
|
|
||||||
if(--this.warningTimer == 0) {
|
|
||||||
this.warningMessage = null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// /**
|
|
||||||
// * Handles mouse input.
|
|
||||||
// */
|
|
||||||
// public void handleMouseInput() throws IOException
|
|
||||||
// {
|
|
||||||
// super.handleMouseInput();
|
|
||||||
// this.availableWorlds.handleMouseInput();
|
|
||||||
// }
|
|
||||||
|
|
||||||
// private void loadLevelList() {
|
|
||||||
//
|
|
||||||
// }
|
|
||||||
|
|
||||||
private String getSaveAt()
|
|
||||||
{
|
|
||||||
return this.getSelected().getFile();
|
|
||||||
}
|
|
||||||
|
|
||||||
// protected String getNameAt(int index)
|
|
||||||
// {
|
|
||||||
// String s = ((SaveInfo)this.saveList.get(index)).getName();
|
|
||||||
//
|
|
||||||
// if (s == null || s.isEmpty())
|
|
||||||
// {
|
|
||||||
// s = I18n.format("selectWorld.world") + " " + (index + 1);
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// return s;
|
|
||||||
// }
|
|
||||||
|
|
||||||
// public void addWorldSelectionButtons(boolean create)
|
|
||||||
// {
|
|
||||||
//// this.userField = new TextField(this.width / 2 + 4 + 2, 26, 146, 16);
|
|
||||||
//// this.userField.setMaxStringLength(16);
|
|
||||||
//// this.userField.setText(this.gm.localUser);
|
|
||||||
//// this.userField.setValidator(new Predicate<String>()
|
|
||||||
//// {
|
|
||||||
//// public boolean test(String name)
|
|
||||||
//// {
|
|
||||||
//// return StringValidator.isValidUser(name);
|
|
||||||
//// }
|
|
||||||
//// });
|
|
||||||
// }
|
|
||||||
|
|
||||||
public void use(ActButton button, Mode mode)
|
|
||||||
{
|
|
||||||
// if (button.enabled)
|
|
||||||
// {
|
|
||||||
if (button == this.deleteButton)
|
|
||||||
{
|
|
||||||
String s = this.getSaveAt();
|
|
||||||
|
|
||||||
if (s != null)
|
|
||||||
{
|
|
||||||
GuiConfirm guiyesno = makeYesNo(this, s, false);
|
|
||||||
this.gm.displayGuiScreen(guiyesno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (button == this.pruneButton)
|
|
||||||
{
|
|
||||||
String s = this.getSaveAt();
|
|
||||||
|
|
||||||
if (s != null)
|
|
||||||
{
|
|
||||||
GuiConfirm guiyesno = makeYesNo(this, s, true);
|
|
||||||
this.gm.displayGuiScreen(guiyesno);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (button == this.selectButton)
|
|
||||||
{
|
|
||||||
// if(isShiftKeyDown())
|
|
||||||
//
|
|
||||||
// else
|
|
||||||
this.playWorld();
|
|
||||||
}
|
|
||||||
else if (button == this.createButton)
|
|
||||||
{
|
|
||||||
if(GuiWorlds.this.gm.theWorld == null) {
|
|
||||||
if(this.gm.shift()) {
|
|
||||||
// this.gm.displayGuiScreen(null);
|
|
||||||
this.gm.startServer(null);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.gm.displayGuiScreen(GuiCreate.INSTANCE);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else if (button == this.copyButton)
|
|
||||||
{
|
|
||||||
this.gm.displayGuiScreen(new GuiEdit("", false,
|
|
||||||
"Welt '" + this.getSaveAt() + "' kopieren", "Kopieren", "Ordner der Welt", new Callback() {
|
|
||||||
public void confirm(String name) {
|
|
||||||
if(name != null)
|
|
||||||
GuiWorlds.this.copyWorld(name);
|
|
||||||
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
else if (button == this.moveButton)
|
|
||||||
{
|
|
||||||
this.gm.displayGuiScreen(new GuiEdit(this.getSaveAt(), false,
|
|
||||||
"Welt '" + this.getSaveAt() + "' verschieben", "Verschieben", "Ordner der Welt", new Callback() {
|
|
||||||
public void confirm(String name) {
|
|
||||||
if(name != null)
|
|
||||||
GuiWorlds.this.moveWorld(name);
|
|
||||||
GuiWorlds.this.gm.displayGuiScreen(GuiWorlds.this);
|
|
||||||
}
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
else if (button == this.seedButton)
|
|
||||||
{
|
|
||||||
Window.setClipboard("" + this.getSelected().getSeed());
|
|
||||||
this.warningTimer = 40;
|
|
||||||
this.warningMessage = TextColor.DGREEN + "Startwert wurde in die Zwischenablage kopiert";
|
|
||||||
}
|
|
||||||
// else
|
|
||||||
// {
|
|
||||||
// this.availableWorlds.actionPerformed(button);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
|
||||||
|
|
||||||
private void copyWorld(String name) {
|
|
||||||
File oldDir = new File(Region.SAVE_DIR, this.getSaveAt());
|
|
||||||
// String name = this.getSaveAt(this.selectedIndex);
|
|
||||||
// while(new File(Region.SAVE_DIR, name).exists()) {
|
|
||||||
// name = name + "-";
|
|
||||||
// }
|
|
||||||
File newDir = new File(Region.SAVE_DIR, name);
|
|
||||||
Log.IO.info("Kopiere Welt " + oldDir + " nach " + newDir);
|
|
||||||
if(!copyFiles(oldDir, newDir, oldDir.listFiles())) {
|
|
||||||
this.warningTimer = 120;
|
|
||||||
this.warningMessage = "Fehler beim Kopieren der Welt, diese könnte unvollständig sein!";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.displayInfo("Welt wurde kopiert");
|
|
||||||
// try
|
|
||||||
// {
|
|
||||||
// this.loadLevelList();
|
|
||||||
// }
|
|
||||||
// catch (Exception anvilconverterexception)
|
|
||||||
// {
|
|
||||||
// Log.error((String)"Konnte Weltliste nicht laden", (Throwable)anvilconverterexception);
|
|
||||||
// }
|
|
||||||
this.gm.displayGuiScreen(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void moveWorld(String dest) {
|
|
||||||
File oldDir = new File(Region.SAVE_DIR, this.getSaveAt());
|
|
||||||
File newDir = new File(Region.SAVE_DIR, dest);
|
|
||||||
Log.IO.info("Kopiere Welt " + oldDir + " nach " + newDir);
|
|
||||||
if(!copyFiles(oldDir, newDir, oldDir.listFiles())) {
|
|
||||||
this.warningTimer = 120;
|
|
||||||
this.warningMessage = "Fehler beim Kopieren der Welt, diese könnte unvollständig sein!";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if(!this.deleteWorld(false)) {
|
|
||||||
this.warningTimer = 120;
|
|
||||||
this.warningMessage = "Fehler beim Löschen der Welt!";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
this.displayInfo("Welt wurde verschoben");
|
|
||||||
this.gm.displayGuiScreen(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeUser(String user) {
|
|
||||||
File file = new File(new File(Region.SAVE_DIR, this.getSaveAt()), "level.nbt");
|
|
||||||
if(file.exists()) {
|
|
||||||
try {
|
|
||||||
NBTTagCompound tag = NBTLoader.readGZip(file);
|
|
||||||
tag.setString("Owner", user);
|
|
||||||
NBTLoader.writeGZip(tag, file);
|
|
||||||
}
|
|
||||||
catch(Exception e) {
|
|
||||||
Log.IO.error("Fehler beim Verarbeiten von " + file, e);
|
|
||||||
this.displayWarning("Konnte Spielernamen nicht ändern");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.displayInfo("Spielername wurde geändert");
|
|
||||||
}
|
|
||||||
// this.gm.displayGuiScreen(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void playWorld()
|
|
||||||
{
|
|
||||||
if(GuiWorlds.this.gm.theWorld != null)
|
|
||||||
return;
|
|
||||||
// this.gm.displayGuiScreen(null);
|
|
||||||
|
|
||||||
if (!this.starting)
|
|
||||||
{
|
|
||||||
this.starting = true;
|
|
||||||
String dir = this.getSaveAt();
|
|
||||||
File folder = new File(Region.SAVE_DIR, dir);
|
|
||||||
if(folder.isDirectory()) {
|
|
||||||
if(this.getSelected().mustConvert()) {
|
|
||||||
Converter.convertMapFormat(folder, true);
|
|
||||||
this.starting = false;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
this.gm.startServer(folder);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// public void confirmClicked(boolean result)
|
|
||||||
// {
|
|
||||||
// if (this.confirmingDelete >= 0 || this.confirmingPrune >= 0)
|
|
||||||
// {
|
|
||||||
// boolean prune = this.confirmingPrune >= 0;
|
|
||||||
// int id = prune ? this.confirmingPrune : this.confirmingDelete;
|
|
||||||
// this.confirmingDelete = -1;
|
|
||||||
// this.confirmingPrune = -1;
|
|
||||||
//
|
|
||||||
// if (result)
|
|
||||||
// {
|
|
||||||
//// Region.clearCache(true);
|
|
||||||
// if(!this.deleteWorld(prune)) {
|
|
||||||
// this.warningTimer = 120;
|
|
||||||
// this.warningMessage = "Fehler beim " + (prune ? "Leeren" : "Löschen") + " der Welt!";
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
//// try
|
|
||||||
//// {
|
|
||||||
//// this.loadLevelList();
|
|
||||||
//// }
|
|
||||||
//// catch (Exception anvilconverterexception)
|
|
||||||
//// {
|
|
||||||
//// Log.error((String)"Konnte Weltliste nicht laden", (Throwable)anvilconverterexception);
|
|
||||||
//// }
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// this.gm.displayGuiScreen(this);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
private boolean deleteWorld(final boolean pruneOnly)
|
|
||||||
{
|
|
||||||
File worldDir = new File(Region.SAVE_DIR, this.getSaveAt());
|
|
||||||
if (!worldDir.exists())
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
Log.IO.info((pruneOnly ? "Leere" : "Lösche") + " Welt " + worldDir);
|
|
||||||
boolean flag = false;
|
|
||||||
for (int i = 1; i <= 5; ++i)
|
|
||||||
{
|
|
||||||
Log.IO.info("Versuch " + i + "...");
|
|
||||||
|
|
||||||
if (FileUtils.deleteFiles(worldDir.listFiles(new FileFilter() {
|
|
||||||
public boolean accept(File file) {
|
|
||||||
return !pruneOnly || (file.isDirectory() ? file.getName().equals("chunk") : file.getName().equals("signs.nbt"));
|
|
||||||
}
|
|
||||||
})))
|
|
||||||
{
|
|
||||||
flag = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
Log.IO.warn("Konnte Inhalt nicht löschen.");
|
|
||||||
|
|
||||||
if (i < 5)
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
Thread.sleep(500L);
|
|
||||||
}
|
|
||||||
catch (InterruptedException e)
|
|
||||||
{
|
|
||||||
;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return pruneOnly ? flag : worldDir.delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean copyFiles(File source, File dest, File[] files)
|
|
||||||
{
|
|
||||||
dest.mkdirs();
|
|
||||||
if(files == null || !dest.isDirectory()) {
|
|
||||||
Log.IO.warn("Konnte Ordner " + source + " nicht nach " + dest + " kopieren");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
boolean flag = true;
|
|
||||||
for (int i = 0; i < files.length; ++i)
|
|
||||||
{
|
|
||||||
File file = files[i];
|
|
||||||
File nfile = new File(dest, file.getName());
|
|
||||||
Log.IO.info("Kopiere " + file + " nach " + nfile);
|
|
||||||
|
|
||||||
if (file.isDirectory())
|
|
||||||
{
|
|
||||||
flag &= copyFiles(file, nfile, file.listFiles());
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
Files.copy(file.toPath(), nfile.toPath(), StandardCopyOption.REPLACE_EXISTING);
|
|
||||||
// Files.copy(file, nfile);
|
|
||||||
}
|
|
||||||
catch(IOException e) {
|
|
||||||
Log.IO.error("Konnte Datei " + file + " nicht nach " + nfile + " kopieren", e);
|
|
||||||
flag = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return flag;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void drawOverlays()
|
|
||||||
{
|
|
||||||
super.drawOverlays();
|
|
||||||
if(this.warningMessage != null) {
|
|
||||||
Drawing.drawRectBorder(this.gm.fb_x / 2 - 200, this.gm.fb_y - 85, 400, 20, 0xff000000, 0xff202020, 0xffffffff, 0xffa0a0a0);
|
|
||||||
// drawRect(this.gm.fb_x / 2 - 191, this.gm.fb_y - 82, this.gm.fb_x / 2 + 191, this.gm.fb_y - 66, 0xff808080);
|
|
||||||
// drawRect(this.gm.fb_x / 2 - 190, this.gm.fb_y - 81, this.gm.fb_x / 2 + 190, this.gm.fb_y - 67, 0xff000000);
|
|
||||||
Drawing.drawTextCentered(this.warningMessage, this.gm.fb_x / 2, this.gm.fb_y - 84, 0xffff0000);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static GuiConfirm makeYesNo(GuiWorlds selectWorld, String name, boolean prune)
|
|
||||||
{
|
|
||||||
String s = prune ? "Willst du diese Welt wirklich leeren?" : "Bist du sicher, dass du diese Welt löschen möchtest?";
|
|
||||||
String s1 = "\'" + name + "\' " + (prune ? "wird alle Daten außer dem Spieler und Einstellungen verlieren!"
|
|
||||||
: "wird für immer verloren sein! (Eine lange Zeit!)");
|
|
||||||
String s2 = prune ? "Leeren" : "Löschen";
|
|
||||||
String s3 = "Abbrechen";
|
|
||||||
GuiConfirm guiyesno = new GuiConfirm(new GuiConfirm.Callback() {
|
|
||||||
@Override
|
|
||||||
public void confirm(boolean confirmed) {
|
|
||||||
if(confirmed && !selectWorld.deleteWorld(prune)) {
|
|
||||||
selectWorld.warningTimer = 120;
|
|
||||||
selectWorld.warningMessage = "Fehler beim " + (prune ? "Leeren" : "Löschen") + " der Welt!";
|
|
||||||
}
|
|
||||||
else if(confirmed)
|
|
||||||
selectWorld.displayInfo("Welt wurde " + (prune ? "geleert" : "gelöscht"));
|
|
||||||
selectWorld.gm.displayGuiScreen(selectWorld);
|
|
||||||
}
|
|
||||||
}, s, s1, s2, s3);
|
|
||||||
return guiyesno;
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -6,8 +6,10 @@ import java.util.List;
|
||||||
|
|
||||||
import game.collect.Lists;
|
import game.collect.Lists;
|
||||||
|
|
||||||
import game.Game;
|
|
||||||
import game.color.TextColor;
|
import game.color.TextColor;
|
||||||
|
import game.future.ListenableFuture;
|
||||||
|
import game.network.IThreadListener;
|
||||||
|
import game.util.Util;
|
||||||
|
|
||||||
public enum Log {
|
public enum Log {
|
||||||
SYSTEM("System"),
|
SYSTEM("System"),
|
||||||
|
@ -41,6 +43,17 @@ public enum Log {
|
||||||
public static final char CHR_UNK = 0x7f;
|
public static final char CHR_UNK = 0x7f;
|
||||||
|
|
||||||
private static final List<LogMessage> LOG = Lists.newArrayList();
|
private static final List<LogMessage> LOG = Lists.newArrayList();
|
||||||
|
|
||||||
|
private static LogLevel level = LogLevel.INFO;
|
||||||
|
private static IThreadListener sync = new IThreadListener() {
|
||||||
|
public ListenableFuture<Object> schedule(Runnable run) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMainThread() {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
private final String prefix;
|
private final String prefix;
|
||||||
|
|
||||||
|
@ -98,34 +111,42 @@ public enum Log {
|
||||||
return time > 0 ? String.format("%dD+%02d:%02d:%02d", time, hrs, mins, secs) : String.format("%02d:%02d:%02d", hrs, mins, secs);
|
return time > 0 ? String.format("%dD+%02d:%02d:%02d", time, hrs, mins, secs) : String.format("%02d:%02d:%02d", hrs, mins, secs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void init(IThreadListener sync) {
|
||||||
|
Log.sync = sync;
|
||||||
|
}
|
||||||
|
|
||||||
public static void flushLog() {
|
public static void flushLog() {
|
||||||
synchronized(LOG) {
|
synchronized(LOG) {
|
||||||
while(!LOG.isEmpty()) {
|
while(!LOG.isEmpty()) {
|
||||||
LogMessage msg = LOG.remove(0);
|
LogMessage msg = LOG.remove(0);
|
||||||
for(String line : msg.lines) {
|
for(String line : msg.lines) {
|
||||||
line = msg.level.color + line;
|
line = msg.level.color + line;
|
||||||
Game.getGame().log(msg.prefix + line, line);
|
Log.sync.log(msg.prefix + line, line);
|
||||||
logOut(msg.prefix + line);
|
logOut(msg.prefix + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setLevel(LogLevel level) {
|
||||||
|
Log.level = level;
|
||||||
|
}
|
||||||
|
|
||||||
public static LogLevel getLevel() {
|
public static LogLevel getLevel() {
|
||||||
return Game.getGame().level;
|
return Log.level;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void log(LogLevel level, String msg) {
|
public void log(LogLevel level, String msg) {
|
||||||
if(level.ordinal() > Game.getGame().level.ordinal())
|
if(level.ordinal() > Log.level.ordinal())
|
||||||
return;
|
return;
|
||||||
String prefix = String.format(TextColor.DGRAY + "[" + TextColor.GREEN + "%s" + TextColor.DGRAY + "][" + TextColor.LGRAY + "%s" + TextColor.DGRAY + "|" + TextColor.LGRAY + "%s" +
|
String prefix = String.format(TextColor.DGRAY + "[" + TextColor.GREEN + "%s" + TextColor.DGRAY + "][" + TextColor.LGRAY + "%s" + TextColor.DGRAY + "|" + TextColor.LGRAY + "%s" +
|
||||||
TextColor.DGRAY + "][%s%s" + TextColor.DGRAY + "] ",
|
TextColor.DGRAY + "][%s%s" + TextColor.DGRAY + "] ",
|
||||||
str_time(Game.getGame().rtime()), this.prefix, Thread.currentThread().getName(), level.color, level.log);
|
str_time(Util.rtime()), this.prefix, Thread.currentThread().getName(), level.color, level.log);
|
||||||
String[] lines = msg.split("\n");
|
String[] lines = msg.split("\n");
|
||||||
if(/* Game.getGame() == null || */ Game.getGame().isMainThread()) {
|
if(/* Game.getGame() == null || */ Log.sync.isMainThread()) {
|
||||||
for(String line : lines) {
|
for(String line : lines) {
|
||||||
line = level.color + line;
|
line = level.color + line;
|
||||||
Game.getGame().log(prefix + line, line);
|
Log.sync.log(prefix + line, line);
|
||||||
logOut(prefix + line);
|
logOut(prefix + line);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,4 +6,6 @@ public interface IThreadListener
|
||||||
{
|
{
|
||||||
ListenableFuture<Object> schedule(Runnable run);
|
ListenableFuture<Object> schedule(Runnable run);
|
||||||
boolean isMainThread();
|
boolean isMainThread();
|
||||||
|
default void log(String prefixed, String line) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package game.util;
|
package game.util;
|
||||||
|
|
||||||
import game.window.Window;
|
|
||||||
|
|
||||||
public enum PerfSection {
|
public enum PerfSection {
|
||||||
TIMING("Timing"),
|
TIMING("Timing"),
|
||||||
INPUT("Input"),
|
INPUT("Input"),
|
||||||
|
@ -29,7 +27,7 @@ public enum PerfSection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void enter() {
|
public void enter() {
|
||||||
this.time = Window.getTime();
|
this.time = Util.getTime();
|
||||||
if(section != null)
|
if(section != null)
|
||||||
section.last[swap] = section.time = this.time - section.time;
|
section.last[swap] = section.time = this.time - section.time;
|
||||||
section = this;
|
section = this;
|
||||||
|
@ -44,7 +42,7 @@ public enum PerfSection {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void swap() {
|
public static void swap() {
|
||||||
long current = Window.getTime();
|
long current = Util.getTime();
|
||||||
total = current - start;
|
total = current - start;
|
||||||
start = current;
|
start = current;
|
||||||
swap ^= 1;
|
swap ^= 1;
|
||||||
|
|
|
@ -13,6 +13,8 @@ import game.log.Log;
|
||||||
import game.properties.IStringSerializable;
|
import game.properties.IStringSerializable;
|
||||||
|
|
||||||
public abstract class Util {
|
public abstract class Util {
|
||||||
|
private static long start = getTime();
|
||||||
|
|
||||||
public static String strip(String str, int offset, int len, char newl, char tab, char unk) {
|
public static String strip(String str, int offset, int len, char newl, char tab, char unk) {
|
||||||
StringBuilder sb = new StringBuilder();
|
StringBuilder sb = new StringBuilder();
|
||||||
for(int pos = offset; pos < offset + len; pos++) {
|
for(int pos = offset; pos < offset + len; pos++) {
|
||||||
|
@ -375,4 +377,16 @@ int utf_len(const char *str) {
|
||||||
map.put("__pos", list);
|
map.put("__pos", list);
|
||||||
return map;
|
return map;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static long getTime() {
|
||||||
|
return System.nanoTime() / 1000L; // glfwGetTimerValue() / (glfwGetTimerFrequency() / 1000000L);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static long rtime() {
|
||||||
|
return Util.getTime() - start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double ftime() {
|
||||||
|
return ((double)rtime()) / 1000000.0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,9 +30,6 @@ import org.lwjgl.system.APIUtil;
|
||||||
import game.log.Log;
|
import game.log.Log;
|
||||||
|
|
||||||
public abstract class Window {
|
public abstract class Window {
|
||||||
public static long getTime() {
|
|
||||||
return System.nanoTime() / 1000L; // glfwGetTimerValue() / (glfwGetTimerFrequency() / 1000000L);
|
|
||||||
}
|
|
||||||
public static void setWindowed(int xpos, int ypos, int xsize, int ysize) {
|
public static void setWindowed(int xpos, int ypos, int xsize, int ysize) {
|
||||||
if(window != NULL)
|
if(window != NULL)
|
||||||
glfwSetWindowMonitor(window, NULL, xpos, ypos, xsize, ysize, GLFW_DONT_CARE);
|
glfwSetWindowMonitor(window, NULL, xpos, ypos, xsize, ysize, GLFW_DONT_CARE);
|
||||||
|
|
|
@ -57,9 +57,9 @@ import game.entity.animal.EntitySquid;
|
||||||
import game.entity.animal.EntityWolf;
|
import game.entity.animal.EntityWolf;
|
||||||
import game.entity.item.EntityBoat;
|
import game.entity.item.EntityBoat;
|
||||||
import game.entity.item.EntityMinecart;
|
import game.entity.item.EntityMinecart;
|
||||||
|
import game.gui.GuiConvert;
|
||||||
import game.gui.GuiLoading;
|
import game.gui.GuiLoading;
|
||||||
import game.gui.GuiLoading.Callback;
|
import game.gui.GuiLoading.Callback;
|
||||||
import game.gui.world.GuiWorlds;
|
|
||||||
import game.init.BlockRegistry;
|
import game.init.BlockRegistry;
|
||||||
import game.init.Blocks;
|
import game.init.Blocks;
|
||||||
import game.init.Config;
|
import game.init.Config;
|
||||||
|
@ -1405,7 +1405,7 @@ public final class Converter {
|
||||||
Log.IO.info("Welt '" + dir + "' wurde in %d Sekunden konvertiert", (System.currentTimeMillis() - cur) / 1000L);
|
Log.IO.info("Welt '" + dir + "' wurde in %d Sekunden konvertiert", (System.currentTimeMillis() - cur) / 1000L);
|
||||||
Game.getGame().schedule(new Runnable() {
|
Game.getGame().schedule(new Runnable() {
|
||||||
public void run() {
|
public void run() {
|
||||||
Game.getGame().displayGuiScreen(GuiWorlds.INSTANCE);
|
Game.getGame().displayGuiScreen(GuiConvert.INSTANCE);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,8 +69,7 @@ public class Region {
|
||||||
thread.setPriority(1);
|
thread.setPriority(1);
|
||||||
thread.start();
|
thread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static final File SAVE_DIR = new File("saves");
|
|
||||||
private static final Map<String, Region> CACHE = Maps.<String, Region>newHashMap();
|
private static final Map<String, Region> CACHE = Maps.<String, Region>newHashMap();
|
||||||
private static final List<WorldServer> QUEUE = Collections.<WorldServer>synchronizedList(Lists.<WorldServer>newArrayList());
|
private static final List<WorldServer> QUEUE = Collections.<WorldServer>synchronizedList(Lists.<WorldServer>newArrayList());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue