mirror of
https://github.com/badvision/lawless-legends.git
synced 2024-06-27 23:29:31 +00:00
Fix multiple window issue.
This commit is contained in:
parent
663758bb8a
commit
149c2c8693
|
@ -119,7 +119,7 @@
|
|||
<dependency>
|
||||
<groupId>org.controlsfx</groupId>
|
||||
<artifactId>controlsfx</artifactId>
|
||||
<version>11.1.2</version>
|
||||
<version>11.2.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.openjfx</groupId>
|
||||
|
|
|
@ -39,6 +39,16 @@ public class SheetEditor {
|
|||
return sheet;
|
||||
}
|
||||
|
||||
public boolean isShowing() {
|
||||
return primaryStage != null && primaryStage.isShowing();
|
||||
}
|
||||
|
||||
public void toFront() {
|
||||
if (isShowing()) {
|
||||
primaryStage.toFront();
|
||||
}
|
||||
}
|
||||
|
||||
public void show() {
|
||||
primaryStage = new Stage();
|
||||
FXMLLoader fxmlLoader = new FXMLLoader(getClass().getResource("/SheetEditor.fxml"));
|
||||
|
|
|
@ -10,6 +10,8 @@
|
|||
|
||||
package org.badvision.outlaweditor.ui;
|
||||
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.uppercaseFirst;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
import java.beans.Introspector;
|
||||
|
@ -23,8 +25,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.uppercaseFirst;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.property.adapter.JavaBeanStringPropertyBuilder;
|
||||
import javafx.beans.value.ObservableValue;
|
||||
|
@ -51,6 +51,7 @@ import javafx.util.Callback;
|
|||
* @author blurry
|
||||
*/
|
||||
public class ModalEditor {
|
||||
Dialog dialog;
|
||||
|
||||
public static interface EditControl<V> {
|
||||
|
||||
|
@ -62,7 +63,6 @@ public class ModalEditor {
|
|||
}
|
||||
|
||||
public static class TextControl implements EditControl<String> {
|
||||
|
||||
TextField control = new TextField();
|
||||
|
||||
@Override
|
||||
|
@ -173,7 +173,7 @@ public class ModalEditor {
|
|||
public <T> Optional<T> editObject(T sourceObject, Map<String, EditControl> obj, Class<T> clazz, String title, String header) throws IntrospectionException {
|
||||
BeanInfo info = Introspector.getBeanInfo(clazz);
|
||||
|
||||
Dialog dialog = new Dialog();
|
||||
dialog = new Dialog();
|
||||
dialog.setTitle(title);
|
||||
dialog.setHeaderText(header);
|
||||
|
||||
|
@ -227,4 +227,14 @@ public class ModalEditor {
|
|||
|
||||
return dialog.showAndWait();
|
||||
}
|
||||
|
||||
public boolean isOpen() {
|
||||
return dialog != null && dialog.isShowing();
|
||||
}
|
||||
|
||||
public void close() {
|
||||
if (isOpen()) {
|
||||
dialog.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,12 +15,14 @@ package org.badvision.outlaweditor.ui;
|
|||
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
import org.controlsfx.control.spreadsheet.SpreadsheetColumn;
|
||||
import org.controlsfx.control.spreadsheet.SpreadsheetView;
|
||||
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
import javafx.scene.control.TextField;
|
||||
import org.controlsfx.control.spreadsheet.SpreadsheetColumn;
|
||||
import org.controlsfx.control.spreadsheet.SpreadsheetView;
|
||||
|
||||
/**
|
||||
*
|
||||
|
|
|
@ -295,8 +295,19 @@ public class UIAction {
|
|||
}
|
||||
}
|
||||
|
||||
// Track open editors
|
||||
static Map<Variable, ModalEditor> editors = new LinkedHashMap<>();
|
||||
|
||||
public static Optional<Variable> editAndGetVariable(Variable v) throws IntrospectionException {
|
||||
// Check if editor is already open
|
||||
if (editors.containsKey(v)) {
|
||||
editors.get(v);
|
||||
if (editors.get(v).isOpen()) {
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
ModalEditor editor = new ModalEditor();
|
||||
editors.put(v, editor);
|
||||
Map<String, ModalEditor.EditControl> controls = new LinkedHashMap<>();
|
||||
|
||||
controls.put("name", new ModalEditor.TextControl());
|
||||
|
@ -362,12 +373,19 @@ public class UIAction {
|
|||
return editSheet(sheet);
|
||||
}
|
||||
|
||||
static Map<Sheet, SheetEditor> sheetEditors = new LinkedHashMap<>();
|
||||
public static Sheet editSheet(Sheet item) {
|
||||
if (item == null) {
|
||||
System.err.println("Requested to edit a null sheet object, ignoring!");
|
||||
return null;
|
||||
}
|
||||
// Check if we don't already have an open editor first
|
||||
if (sheetEditors.containsKey(item) && sheetEditors.get(item).isShowing()) {
|
||||
sheetEditors.get(item).toFront();
|
||||
return item;
|
||||
}
|
||||
SheetEditor editor = new SheetEditor(item);
|
||||
sheetEditors.put(item, editor);
|
||||
editor.show();
|
||||
return item;
|
||||
}
|
||||
|
|
|
@ -9,18 +9,13 @@
|
|||
*/
|
||||
package org.badvision.outlaweditor.ui.impl;
|
||||
|
||||
import static org.badvision.outlaweditor.ui.UIAction.editScript;
|
||||
|
||||
import java.beans.IntrospectionException;
|
||||
import java.util.Optional;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
|
||||
import org.badvision.outlaweditor.TransferHelper;
|
||||
import org.badvision.outlaweditor.api.ApplicationState;
|
||||
import org.badvision.outlaweditor.data.DataUtilities;
|
||||
|
@ -30,9 +25,14 @@ import org.badvision.outlaweditor.data.xml.UserType;
|
|||
import org.badvision.outlaweditor.data.xml.Variable;
|
||||
import org.badvision.outlaweditor.ui.GlobalEditorTabController;
|
||||
import org.badvision.outlaweditor.ui.UIAction;
|
||||
import static org.badvision.outlaweditor.ui.UIAction.editScript;
|
||||
|
||||
import jakarta.xml.bind.JAXBException;
|
||||
import javafx.application.Platform;
|
||||
import javafx.event.ActionEvent;
|
||||
import javafx.scene.control.ListCell;
|
||||
import javafx.scene.control.Tooltip;
|
||||
import javafx.scene.text.Font;
|
||||
import javafx.scene.text.FontWeight;
|
||||
|
||||
public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
|
||||
|
||||
|
@ -56,6 +56,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
|
|||
|
||||
@Override
|
||||
public void startEdit() {
|
||||
Platform.runLater(()->variableList.getSelectionModel().clearSelection());
|
||||
UIAction.editVariable(getItem(), ApplicationState.getInstance().getGameData().getGlobal());
|
||||
cancelEdit();
|
||||
updateItem(getItem(), false);
|
||||
|
@ -75,6 +76,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
|
|||
|
||||
@Override
|
||||
public void startEdit() {
|
||||
Platform.runLater(()->globalScriptList.getSelectionModel().clearSelection());
|
||||
UIAction.editScript(getItem(), ApplicationState.getInstance().getGameData().getGlobal());
|
||||
cancelEdit();
|
||||
updateItem(getItem(), false);
|
||||
|
@ -97,6 +99,7 @@ public class GlobalEditorTabControllerImpl extends GlobalEditorTabController {
|
|||
|
||||
@Override
|
||||
public void startEdit() {
|
||||
Platform.runLater(()->dataTypeList.getSelectionModel().clearSelection());
|
||||
UIAction.editUserType(getItem());
|
||||
cancelEdit();
|
||||
updateItem(getItem(), false);
|
||||
|
|
|
@ -15,6 +15,9 @@
|
|||
*/
|
||||
package org.badvision.outlaweditor.ui.impl;
|
||||
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.getValue;
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.setValue;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
|
@ -27,8 +30,6 @@ import java.util.stream.Collectors;
|
|||
import org.badvision.outlaweditor.SheetEditor;
|
||||
import org.badvision.outlaweditor.TransferHelper;
|
||||
import org.badvision.outlaweditor.data.DataUtilities;
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.getValue;
|
||||
import static org.badvision.outlaweditor.data.DataUtilities.setValue;
|
||||
import org.badvision.outlaweditor.data.xml.Columns;
|
||||
import org.badvision.outlaweditor.data.xml.Rows;
|
||||
import org.badvision.outlaweditor.data.xml.Rows.Row;
|
||||
|
|
Loading…
Reference in New Issue
Block a user