mirror of
https://github.com/badvision/lawless-legends.git
synced 2025-01-12 12:30:07 +00:00
Fixed dialog issue -- Application quit now works more like it should.
This commit is contained in:
parent
908d248af6
commit
5d11ff7e80
@ -48,16 +48,6 @@ public class Application extends javafx.application.Application {
|
|||||||
@Override
|
@Override
|
||||||
public void handle(final WindowEvent t) {
|
public void handle(final WindowEvent t) {
|
||||||
t.consume();
|
t.consume();
|
||||||
if (quit()) {
|
|
||||||
javafx.application.Platform.exit();
|
|
||||||
// System.exit(0);
|
|
||||||
}
|
|
||||||
javafx.application.Platform.runLater(new Runnable() {
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
getPrimaryStage().show();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
primaryStage.show();
|
primaryStage.show();
|
||||||
|
@ -378,13 +378,18 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onImageDeletePressed(ActionEvent event) {
|
public void onImageDeletePressed(ActionEvent event) {
|
||||||
if (currentImage == null) return;
|
if (currentImage == null) {
|
||||||
if (confirm("Delete image '"+currentImage.getName()+"'. Are you sure?")) {
|
return;
|
||||||
|
}
|
||||||
|
confirm("Delete image '" + currentImage.getName() + "'. Are you sure?", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
Image del = currentImage;
|
Image del = currentImage;
|
||||||
setCurrentImage(null);
|
setCurrentImage(null);
|
||||||
Application.gameData.getImage().remove(del);
|
Application.gameData.getImage().remove(del);
|
||||||
rebuildImageSelector();
|
rebuildImageSelector();
|
||||||
}
|
}
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -415,13 +420,18 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onMapDeletePressed(ActionEvent event) {
|
public void onMapDeletePressed(ActionEvent event) {
|
||||||
if (currentMap == null) return;
|
if (currentMap == null) {
|
||||||
if (confirm("Delete map '"+currentMap.getName()+"'. Are you sure?")) {
|
return;
|
||||||
|
}
|
||||||
|
confirm("Delete map '" + currentMap.getName() + "'. Are you sure?", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
org.badvision.outlaweditor.data.xml.Map del = currentMap;
|
org.badvision.outlaweditor.data.xml.Map del = currentMap;
|
||||||
setCurrentMap(null);
|
setCurrentMap(null);
|
||||||
Application.gameData.getMap().remove(del);
|
Application.gameData.getMap().remove(del);
|
||||||
rebuildMapSelectors();
|
rebuildMapSelectors();
|
||||||
}
|
}
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -491,13 +501,20 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onTileDeletePressed(ActionEvent event) {
|
public void onTileDeletePressed(ActionEvent event) {
|
||||||
if (currentTile == null) return;
|
if (currentTile == null) {
|
||||||
if (confirm("Delete tile '"+currentTile.getName()+"'. Are you sure?")) {
|
return;
|
||||||
|
}
|
||||||
|
confirm("Delete tile '" + currentTile.getName() + "'. Are you sure?", new Runnable() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
Tile del = currentTile;
|
Tile del = currentTile;
|
||||||
setCurrentTile(null);
|
setCurrentTile(null);
|
||||||
Application.gameData.getTile().remove(del);
|
Application.gameData.getTile().remove(del);
|
||||||
rebuildTileSelectors();
|
rebuildTileSelectors();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -778,8 +795,12 @@ public class ApplicationUIControllerImpl extends ApplicationUIController {
|
|||||||
imageSelector.getSelectionModel().select(i);
|
imageSelector.getSelectionModel().select(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static enum TABS{image,map,tile};
|
public static enum TABS {
|
||||||
|
|
||||||
|
image, map, tile
|
||||||
|
};
|
||||||
TABS currentTab;
|
TABS currentTab;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void imageTabActivated(Event event) {
|
public void imageTabActivated(Event event) {
|
||||||
currentTab = TABS.image;
|
currentTab = TABS.image;
|
||||||
|
@ -6,16 +6,27 @@ package org.badvision.outlaweditor;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javafx.application.Platform;
|
import javafx.application.Platform;
|
||||||
import javafx.event.ActionEvent;
|
import javafx.event.ActionEvent;
|
||||||
import javafx.event.EventHandler;
|
import javafx.event.EventHandler;
|
||||||
|
import javafx.geometry.Insets;
|
||||||
|
import javafx.geometry.Pos;
|
||||||
|
import javafx.scene.Scene;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
import javafx.scene.control.Menu;
|
import javafx.scene.control.Menu;
|
||||||
import javafx.scene.control.MenuBar;
|
import javafx.scene.control.MenuBar;
|
||||||
import javafx.scene.control.MenuItem;
|
import javafx.scene.control.MenuItem;
|
||||||
import javafx.scene.image.Image;
|
import javafx.scene.image.Image;
|
||||||
import javafx.scene.image.WritableImage;
|
import javafx.scene.image.WritableImage;
|
||||||
|
import javafx.scene.layout.HBoxBuilder;
|
||||||
|
import javafx.scene.layout.VBoxBuilder;
|
||||||
|
import javafx.scene.text.Text;
|
||||||
|
import javafx.stage.Modality;
|
||||||
|
import javafx.stage.Stage;
|
||||||
import javax.swing.JOptionPane;
|
import javax.swing.JOptionPane;
|
||||||
import javax.xml.bind.JAXB;
|
import javax.xml.bind.JAXB;
|
||||||
import org.badvision.outlaweditor.data.TilesetUtils;
|
import org.badvision.outlaweditor.data.TilesetUtils;
|
||||||
@ -126,12 +137,13 @@ public class UIAction {
|
|||||||
return menu;
|
return menu;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean quit() {
|
public static void quit() {
|
||||||
if (JOptionPane.showConfirmDialog(null, "Quit? Are you sure?") == JOptionPane.OK_OPTION) {
|
confirm("Quit? Are you sure?", new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
Platform.exit();
|
Platform.exit();
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
}, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Image badImage;
|
static Image badImage;
|
||||||
@ -146,7 +158,42 @@ public class UIAction {
|
|||||||
return img;
|
return img;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean confirm(String string) {
|
public static class Choice {
|
||||||
return JOptionPane.showConfirmDialog(null, string) == JOptionPane.YES_OPTION;
|
String text;
|
||||||
|
Runnable handler;
|
||||||
|
public Choice(String text, Runnable handler) {
|
||||||
|
this.text = text;
|
||||||
|
this.handler = handler;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void confirm(String message, Runnable yes, Runnable no) {
|
||||||
|
choose(message, new Choice("Yes", yes), new Choice("No", no));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void choose(String message, Choice... choices) {
|
||||||
|
final Stage dialogStage = new Stage();
|
||||||
|
|
||||||
|
HBoxBuilder options = HBoxBuilder.create().alignment(Pos.CENTER).spacing(10.0).padding(new Insets(5));
|
||||||
|
List<Button> buttons = new ArrayList<>();
|
||||||
|
for (final Choice c : choices) {
|
||||||
|
Button b = new Button(c.text);
|
||||||
|
b.setOnAction(new EventHandler<ActionEvent>() {
|
||||||
|
@Override
|
||||||
|
public void handle(ActionEvent t) {
|
||||||
|
if (c.handler != null) {
|
||||||
|
c.handler.run();
|
||||||
|
}
|
||||||
|
dialogStage.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
buttons.add(b);
|
||||||
|
}
|
||||||
|
options.children(buttons);
|
||||||
|
dialogStage.initModality(Modality.WINDOW_MODAL);
|
||||||
|
dialogStage.setScene(new Scene(VBoxBuilder.create().
|
||||||
|
children(new Text(message), options.build()).
|
||||||
|
alignment(Pos.CENTER).padding(new Insets(5)).build()));
|
||||||
|
dialogStage.show();
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user