feat(studio): refine Play workspace and project preferences (WRK-001D)
This commit is contained in:
@@ -22,9 +22,21 @@ development gallery** demonstrates components, validation, progress, both fonts
|
||||
configurable text scale. Gallery actions operate on sample text only.
|
||||
|
||||
The product project chooser contains identity, the project list and project
|
||||
commands only. It inherits presentation settings; language, theme, typeface and
|
||||
scale selectors remain in the project window. From the repository root, an
|
||||
unqualified `run` starts the product and skips the foundation demo. Launch the
|
||||
commands and access to **Prometeu Studio > Preferences**. The brand appears only in
|
||||
that menu, without a second identity block in the chooser. It inherits presentation settings;
|
||||
appearance selectors and the default runtime live in that separate dialog.
|
||||
**Project > Settings** contains a nullable runtime override and save media choices.
|
||||
The project shell places global Play/Stop and Pause/Resume controls on the right above a Gameplay
|
||||
tab, alongside the left-aligned Prometeu Studio menu and golden-square mark. A small
|
||||
project header and equally sized contextual footer frame the workspace. The product
|
||||
workspace is plain, with balanced top/bottom margins; the standalone foundation
|
||||
keeps its decorative panel. Native tabs
|
||||
use stepped upper corners, an open flat base and Studio theme colors; Gameplay supplies scale information to the
|
||||
footer and owns automatic/manual image scaling, not execution lifetime. From the repository root, an
|
||||
unqualified `run` starts the product and skips the foundation demo. The gold tab
|
||||
outline encloses the content; Gameplay splits game and logs with a draggable
|
||||
horizontal divider. Automatic scale follows this resize, while manual scale stays
|
||||
fixed. Header/footer remain outside the split. Launch the
|
||||
foundation with the explicit module command above (or from that module directory).
|
||||
|
||||
```sh
|
||||
@@ -61,7 +73,7 @@ Semantic theme colors are in `styles/dark.css` and `styles/light.css`. Component
|
||||
|
||||
`UserSettingsStore` uses the Java Preferences node `p/studio/ui/javafx2` for theme, language, bundled typeface and text scale (75–200%). Startup uses dark, Departure Mono and 100%; a supported system locale chooses pt-BR, otherwise English. Invalid individual values fall back independently with diagnostics.
|
||||
|
||||
Load preferences and font/bundle resources before composing views. `SettingsPersistence` debounces writes on its worker, flushes the last choice asynchronously on close, and shuts the worker down. It never writes from the FX thread. Project-window geometry is restored per project through `WindowStateStore`, with IO off the FX thread. Previous frontend presentation preferences are not migrated.
|
||||
Load preferences and font/bundle resources before composing views. `SettingsPersistence` debounces writes on its worker, flushes the last choice asynchronously on close, and shuts the worker down. It never writes from the FX thread. `WindowStateStore` persists launcher and per-project normal geometry plus maximization. Geometry snapshots are stabilized on FX and written serially off FX, with orderly close awaiting pending writes. Placement considers the matching monitor and recovers onto an available display. Previous frontend presentation preferences are not migrated.
|
||||
|
||||
All interface messages live in UTF-8 `messages_en.properties` and `messages_pt_BR.properties`. Missing translations diagnose and fall back to English; an absent English key displays `[key]`. Bundle parity is checked by unit tests. Dynamic feedback retains its key/arguments and is reformatted on locale changes; user-authored text retains its value.
|
||||
|
||||
|
||||
+14
-4
@@ -7,13 +7,23 @@ import javafx.scene.shape.Polygon;
|
||||
final class PixelGeometry {
|
||||
private PixelGeometry() { }
|
||||
static void apply(Region region) {
|
||||
Polygon outline = new Polygon();
|
||||
region.setShape(outline); region.setScaleShape(false); region.setCenterShape(false); region.setPickOnBounds(true);
|
||||
apply(region,false);
|
||||
}
|
||||
/** Tab edges meet the content surface; only the upper corners step inward. */
|
||||
static void applyTab(Region region) {
|
||||
apply(region,true);
|
||||
}
|
||||
private static void apply(Region region,boolean tab) {
|
||||
region.setScaleShape(false); region.setCenterShape(false); region.setPickOnBounds(true);
|
||||
Runnable update = () -> {
|
||||
double w = region.getWidth(), h = region.getHeight(), s = Math.min(4, Math.min(w,h)/6);
|
||||
outline.getPoints().setAll(2*s,0., w-2*s,0., w-2*s,s, w-s,s, w-s,2*s, w,2*s,
|
||||
if(w<=0||h<=0)return;
|
||||
// Publish a new shape so the Region invalidates its cached outline/bounds after resize.
|
||||
region.setShape(tab?new Polygon(2*s,0., w-2*s,0., w-2*s,s, w-s,s, w-s,2*s,
|
||||
w,2*s, w,h, 0.,h, 0.,2*s, s,2*s, s,s, 2*s,s):
|
||||
new Polygon(2*s,0., w-2*s,0., w-2*s,s, w-s,s, w-s,2*s, w,2*s,
|
||||
w,h-2*s, w-s,h-2*s, w-s,h-s, w-2*s,h-s, w-2*s,h, 2*s,h, 2*s,h-s,
|
||||
s,h-s, s,h-2*s, 0.,h-2*s, 0.,2*s, s,2*s, s,s, 2*s,s);
|
||||
s,h-s, s,h-2*s, 0.,h-2*s, 0.,2*s, s,2*s, s,s, 2*s,s));
|
||||
};
|
||||
region.widthProperty().addListener((o,b,a) -> update.run());
|
||||
region.heightProperty().addListener((o,b,a) -> update.run());
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package p.studio.ui.javafx2.components;
|
||||
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.Region;
|
||||
import javafx.scene.shape.*;
|
||||
import java.util.ArrayList;
|
||||
|
||||
/** Native tabs with stepped upper corners and a flat base joined to the content surface. */
|
||||
public final class StudioTabs extends TabPane {
|
||||
private static final Object OUTLINE=new Object();
|
||||
private final Path contentOutline=new Path();
|
||||
public StudioTabs(Tab... tabs){
|
||||
super(tabs);getStyleClass().add("studio-tabs");
|
||||
contentOutline.setId("tab-content-outline");contentOutline.getStyleClass().add("studio-tab-content-outline");
|
||||
contentOutline.setManaged(false);contentOutline.setMouseTransparent(true);contentOutline.setFill(null);
|
||||
contentOutline.setViewOrder(-1);
|
||||
}
|
||||
@Override protected double computeMinHeight(double width){
|
||||
double header=0;var area=lookup(".tab-header-area");
|
||||
if(area instanceof Region region)header=region.prefHeight(width);
|
||||
var selected=getSelectionModel().getSelectedItem();double content=0;
|
||||
if(selected!=null&&selected.getContent() instanceof Region region)
|
||||
content=region.getParent() instanceof Region contentArea?contentArea.minHeight(width):region.minHeight(width);
|
||||
return Math.max(super.computeMinHeight(width),snappedTopInset()+snappedBottomInset()+header+content);
|
||||
}
|
||||
@Override protected void layoutChildren(){
|
||||
super.layoutChildren();
|
||||
for(var node:lookupAll(".tab"))if(node instanceof Region header&&!header.getProperties().containsKey(OUTLINE)){
|
||||
header.getProperties().put(OUTLINE,Boolean.TRUE);PixelGeometry.applyTab(header);
|
||||
}
|
||||
if(!getChildren().contains(contentOutline))getChildren().add(contentOutline);
|
||||
layoutContentOutline();
|
||||
}
|
||||
private void layoutContentOutline(){
|
||||
var selected=getSelectionModel().getSelectedItem();var content=selected==null?null:selected.getContent();
|
||||
var area=content==null?null:content.getParent();
|
||||
if(area==null||!area.isVisible()){contentOutline.setVisible(false);return;}
|
||||
var bounds=sceneToLocal(area.localToScene(area.getLayoutBounds()));
|
||||
if(bounds.getWidth()<=2||bounds.getHeight()<=2){contentOutline.setVisible(false);return;}
|
||||
double left=bounds.getMinX()+1,right=bounds.getMaxX()-1,top=bounds.getMinY()+1,bottom=bounds.getMaxY()-1;
|
||||
var edges=new ArrayList<PathElement>();
|
||||
edges.add(new MoveTo(left,top));edges.add(new LineTo(left,bottom));edges.add(new LineTo(right,bottom));edges.add(new LineTo(right,top));
|
||||
var header=lookup(".tab:selected");
|
||||
if(header==null){edges.add(new LineTo(left,top));}
|
||||
else{
|
||||
var tab=sceneToLocal(header.localToScene(header.getLayoutBounds()));
|
||||
double openingLeft=Math.max(left,Math.min(right,tab.getMinX()+1));
|
||||
double openingRight=Math.max(openingLeft,Math.min(right,tab.getMaxX()-1));
|
||||
double join=Math.min(top,tab.getMaxY()-1);
|
||||
edges.add(new LineTo(openingRight,top));edges.add(new LineTo(openingRight,join));
|
||||
edges.add(new MoveTo(left,top));edges.add(new LineTo(openingLeft,top));edges.add(new LineTo(openingLeft,join));
|
||||
}
|
||||
contentOutline.getElements().setAll(edges);contentOutline.setOpacity(selected.isDisable()?.45:1);contentOutline.setVisible(true);
|
||||
}
|
||||
}
|
||||
+33
-7
@@ -1,6 +1,8 @@
|
||||
package p.studio.ui.javafx2.play;
|
||||
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.beans.property.ReadOnlyDoubleProperty;
|
||||
import javafx.beans.property.ReadOnlyDoubleWrapper;
|
||||
import javafx.scene.control.ScrollPane;
|
||||
import javafx.scene.image.*;
|
||||
import javafx.scene.input.*;
|
||||
@@ -9,16 +11,20 @@ import p.studio.api.execution.*;
|
||||
import java.util.*;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
/** Logical-pixel viewport. Reception never waits for the JavaFX pulse. */
|
||||
/** Adaptable presentation surface. Reception never waits for the JavaFX pulse. */
|
||||
public final class PlaybackViewport extends BorderPane implements AutoCloseable {
|
||||
private final ImageView image=new ImageView();
|
||||
private final StackPane surface=new StackPane(image);
|
||||
private final ScrollPane scroll=new ScrollPane(surface);
|
||||
private final ReadOnlyDoubleWrapper scale=new ReadOnlyDoubleWrapper(0);
|
||||
private final Supplier<ExecutionController> controller;
|
||||
private final Supplier<ExecutionState> state;
|
||||
private final EnumSet<KeyCode> pressed=EnumSet.noneOf(KeyCode.class);
|
||||
private final AnimationTimer timer;
|
||||
private WritableImage writable;
|
||||
private int zoom=1,width=0,height=0,touchX=-1,touchY=-1;
|
||||
private int width=0,height=0,touchX=-1,touchY=-1;
|
||||
private boolean manual;
|
||||
private double requestedScale=1;
|
||||
private boolean touching;
|
||||
private long painted,lastFrame;
|
||||
private final long[] latencies=new long[2048];
|
||||
@@ -27,7 +33,8 @@ public final class PlaybackViewport extends BorderPane implements AutoCloseable
|
||||
this.controller=controller;this.state=state;setId("play-viewport");
|
||||
image.setId("game-image");image.setSmooth(false);image.setPreserveRatio(false);
|
||||
surface.setId("game-surface");surface.setFocusTraversable(true);surface.setStyle("-fx-background-color: #080a0a;");
|
||||
ScrollPane scroll=new ScrollPane(surface);scroll.setFitToWidth(true);scroll.setFitToHeight(true);setCenter(scroll);resizeImage();
|
||||
scroll.setFitToWidth(true);scroll.setFitToHeight(true);scroll.setMinSize(0,0);setCenter(scroll);setMinSize(0,0);
|
||||
scroll.viewportBoundsProperty().addListener((o,a,b)->resizeImage());resizeImage();
|
||||
surface.addEventFilter(KeyEvent.KEY_PRESSED,e->key(e,true));
|
||||
surface.addEventFilter(KeyEvent.KEY_RELEASED,e->key(e,false));
|
||||
surface.focusedProperty().addListener((o,a,b)->{if(!b)neutralize();});
|
||||
@@ -37,9 +44,26 @@ public final class PlaybackViewport extends BorderPane implements AutoCloseable
|
||||
surface.addEventFilter(MouseEvent.MOUSE_RELEASED,e->{if(e.getButton()==MouseButton.PRIMARY)touch(e,false);});
|
||||
timer=new AnimationTimer(){@Override public void handle(long now){paint();}};timer.start();
|
||||
}
|
||||
public void zoom(int value){if(value!=1&&value!=2&&value!=4)throw new IllegalArgumentException("Zoom");zoom=value;resizeImage();}
|
||||
public int zoom(){return zoom;}
|
||||
private void resizeImage(){image.setFitWidth(width*zoom);image.setFitHeight(height*zoom);surface.setMinSize(width*zoom,height*zoom);}
|
||||
public ReadOnlyDoubleProperty scaleProperty(){return scale.getReadOnlyProperty();}
|
||||
public double scale(){return scale.get();}
|
||||
public boolean manual(){return manual;}
|
||||
public void setManual(boolean value){
|
||||
if(value&&!manual)requestedScale=Math.max(.25,Math.min(4,scale.get()>0?scale.get():1));
|
||||
manual=value;resizeImage();
|
||||
}
|
||||
public void setScale(double value){
|
||||
if(!Double.isFinite(value)||value<.25||value>4)throw new IllegalArgumentException("Scale must be between 25% and 400%");
|
||||
requestedScale=value;resizeImage();
|
||||
}
|
||||
private void resizeImage(){
|
||||
scroll.setHbarPolicy(manual?ScrollPane.ScrollBarPolicy.AS_NEEDED:ScrollPane.ScrollBarPolicy.NEVER);
|
||||
scroll.setVbarPolicy(manual?ScrollPane.ScrollBarPolicy.AS_NEEDED:ScrollPane.ScrollBarPolicy.NEVER);
|
||||
double factor=manual?requestedScale:ViewportTransform.fit(width,height,scroll.getViewportBounds().getWidth(),scroll.getViewportBounds().getHeight());
|
||||
if(width<=0||height<=0||factor<=0)return;
|
||||
image.setFitWidth(width*factor);image.setFitHeight(height*factor);
|
||||
surface.setMinSize(manual?width*factor:0,manual?height*factor:0);
|
||||
surface.setPrefSize(manual?width*factor:0,manual?height*factor:0);scale.set(factor);
|
||||
}
|
||||
private void paint(){
|
||||
ExecutionController c=controller.get();if(c==null)return;
|
||||
try(ExecutionFrame frame=c.acquireLatestFrame()){
|
||||
@@ -65,7 +89,9 @@ public final class PlaybackViewport extends BorderPane implements AutoCloseable
|
||||
// After leaving the image, dragging back with the button held cannot recapture.
|
||||
if(down&&!touching&&event.getEventType()!=MouseEvent.MOUSE_PRESSED)return;
|
||||
var p=image.sceneToLocal(event.getSceneX(),event.getSceneY());
|
||||
int x=(int)Math.floor(p.getX()/zoom),y=(int)Math.floor(p.getY()/zoom);
|
||||
var bounds=image.getBoundsInLocal();
|
||||
int x=ViewportTransform.coordinate(p.getX()-bounds.getMinX(),bounds.getWidth(),width);
|
||||
int y=ViewportTransform.coordinate(p.getY()-bounds.getMinY(),bounds.getHeight(),height);
|
||||
touching=down&&state.get()==ExecutionState.RUNNING&&x>=0&&y>=0&&x<width&&y<height;
|
||||
touchX=touching?x:-1;touchY=touching?y:-1;send();event.consume();
|
||||
}
|
||||
|
||||
+13
@@ -0,0 +1,13 @@
|
||||
package p.studio.ui.javafx2.play;
|
||||
|
||||
final class ViewportTransform {
|
||||
private ViewportTransform() { }
|
||||
static double fit(int width,int height,double availableWidth,double availableHeight){
|
||||
if(width<=0||height<=0||availableWidth<=0||availableHeight<=0)return 0;
|
||||
return Math.min(availableWidth/width,availableHeight/height);
|
||||
}
|
||||
static int coordinate(double local,double displayed,int nativeSize){
|
||||
if(!Double.isFinite(local)||displayed<=0||nativeSize<=0||local<0||local>=displayed)return -1;
|
||||
return (int)Math.floor(local/displayed*nativeSize);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package p.studio.ui.javafx2.shell;
|
||||
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.geometry.Pos;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.scene.text.Text;
|
||||
import p.studio.ui.javafx2.appearance.AppearanceContext;
|
||||
|
||||
/** Keeps navigation on the left and a stable command pair on the right. */
|
||||
public final class ExecutionBar extends Region {
|
||||
private static final double GAP=12;
|
||||
private final MenuBar navigation;
|
||||
private final HBox commands;
|
||||
public ExecutionBar(AppearanceContext context,MenuBar navigation,ButtonBase play,ButtonBase pause){
|
||||
this.navigation=navigation;commands=new HBox(10,play,pause);commands.setAlignment(Pos.CENTER);
|
||||
getChildren().addAll(navigation,commands);getStyleClass().add("studio-execution-bar");setId("execution-toolbar");
|
||||
Runnable measure=()->{
|
||||
double width=0;
|
||||
for(var button:new ButtonBase[]{play,pause})for(String key:new String[]{"play.start","play.stop","play.pause","play.resume"}){
|
||||
var text=new Text(context.text(key));text.setFont(button.getFont());
|
||||
width=Math.max(width,text.getLayoutBounds().getWidth()+button.getPadding().getLeft()+button.getPadding().getRight()+12);
|
||||
}
|
||||
double slot=Math.ceil(width);
|
||||
for(var button:new ButtonBase[]{play,pause}){button.setMinWidth(slot);button.setPrefWidth(slot);button.setMaxWidth(slot);}
|
||||
requestLayout();
|
||||
};
|
||||
ChangeListener<Object> changed=(o,a,b)->measure.run();
|
||||
play.fontProperty().addListener(changed);pause.fontProperty().addListener(changed);
|
||||
play.paddingProperty().addListener(changed);pause.paddingProperty().addListener(changed);
|
||||
context.observe(measure);
|
||||
context.onClose(()->{play.fontProperty().removeListener(changed);pause.fontProperty().removeListener(changed);
|
||||
play.paddingProperty().removeListener(changed);pause.paddingProperty().removeListener(changed);});
|
||||
}
|
||||
private boolean beside(double width){return width>=navigation.prefWidth(-1)+GAP+commands.prefWidth(-1);}
|
||||
@Override public javafx.geometry.Orientation getContentBias(){return javafx.geometry.Orientation.HORIZONTAL;}
|
||||
@Override protected double computeMinWidth(double height){return snappedLeftInset()+snappedRightInset()+Math.max(navigation.minWidth(-1),commands.minWidth(-1));}
|
||||
@Override protected double computePrefWidth(double height){return snappedLeftInset()+snappedRightInset()+navigation.prefWidth(-1)+GAP+commands.prefWidth(-1);}
|
||||
@Override protected double computePrefHeight(double width){
|
||||
double inner=width<0?computePrefWidth(-1):Math.max(0,width-snappedLeftInset()-snappedRightInset());
|
||||
double menu=navigation.prefHeight(inner),buttons=commands.prefHeight(-1);
|
||||
return snappedTopInset()+snappedBottomInset()+(beside(inner)?Math.max(menu,buttons):menu+4+buttons);
|
||||
}
|
||||
@Override protected void layoutChildren(){
|
||||
double x=snappedLeftInset(),y=snappedTopInset(),width=Math.max(0,getWidth()-x-snappedRightInset());
|
||||
double menuWidth=Math.min(width,navigation.prefWidth(-1)),menuHeight=navigation.prefHeight(menuWidth);
|
||||
double commandWidth=commands.prefWidth(-1),commandHeight=commands.prefHeight(commandWidth);
|
||||
boolean oneRow=beside(width);double rowHeight=Math.max(menuHeight,commandHeight);
|
||||
navigation.resizeRelocate(x,y+(oneRow?(rowHeight-menuHeight)/2:0),menuWidth,menuHeight);
|
||||
commands.resizeRelocate(x+width-commandWidth,y+(oneRow?(rowHeight-commandHeight)/2:menuHeight+4),commandWidth,commandHeight);
|
||||
}
|
||||
}
|
||||
+11
-4
@@ -11,11 +11,17 @@ import p.studio.ui.javafx2.i18n.StudioLanguage;
|
||||
|
||||
/** Shared shell: identity, presentation selectors and a workspace supplied by its coordinator. */
|
||||
public final class MinimalShell extends BorderPane {
|
||||
private final StudioPanel workspace = new StudioPanel();
|
||||
private final StackPane workspace;
|
||||
private final StudioSelect<Theme> theme;
|
||||
private final StudioSelect<StudioLanguage> language;
|
||||
public MinimalShell(AppearanceContext context) {
|
||||
this(context,true);
|
||||
}
|
||||
/** Product shell delegates navigation and presentation preferences to its coordinator. */
|
||||
public MinimalShell(AppearanceContext context, boolean foundationSelectors) {
|
||||
workspace=foundationSelectors?new StudioPanel():new StackPane();
|
||||
setId("studio-shell"); getStyleClass().add("studio-shell"); context.attach(this);
|
||||
if(!foundationSelectors){getStyleClass().add("studio-project-shell");setMinSize(0,0);workspace.setMinSize(0,0);}
|
||||
theme = new StudioSelect<>(context,"theme.label",item -> context.text(item.labelKey()),Theme.values());
|
||||
theme.setId("theme-select"); theme.connect(() -> context.settings().theme(), value -> context.update(context.settings().withTheme(value)));
|
||||
language = new StudioSelect<>(context,"language.label",StudioLanguage::label,StudioLanguage.values());
|
||||
@@ -29,15 +35,16 @@ public final class MinimalShell extends BorderPane {
|
||||
labeled(context,"font.label",typeface),labeled(context,"scale.label",scale));
|
||||
selectors.setPrefWrapLength(680);
|
||||
PresentationToolbar toolbar = new PresentationToolbar(identity,selectors);
|
||||
setTop(toolbar); workspace.setId("empty-workspace"); workspace.getStyleClass().add("workspace");
|
||||
if(foundationSelectors)setTop(toolbar);
|
||||
workspace.setId("empty-workspace"); workspace.getStyleClass().add("workspace");
|
||||
context.observe(() -> workspace.setAccessibleText(context.text("workspace.empty")));
|
||||
setMargin(workspace,new Insets(18,18,0,18)); setCenter(workspace);
|
||||
setMargin(workspace,foundationSelectors?new Insets(18,18,0,18):new Insets(18)); setCenter(workspace);
|
||||
}
|
||||
public static VBox labeled(AppearanceContext context, String key, Node input) {
|
||||
Label label = new StudioText(context,key); label.setLabelFor(input);
|
||||
VBox box = new VBox(6,label,input); box.setFillWidth(true); return box;
|
||||
}
|
||||
public StudioPanel workspace() { return workspace; }
|
||||
public StackPane workspace() { return workspace; }
|
||||
public StudioSelect<Theme> themeSelector() { return theme; }
|
||||
public StudioSelect<StudioLanguage> languageSelector() { return language; }
|
||||
}
|
||||
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package p.studio.ui.javafx2.shell;
|
||||
|
||||
import javafx.beans.value.*;
|
||||
import javafx.collections.ListChangeListener;
|
||||
import javafx.scene.control.*;
|
||||
import java.util.*;
|
||||
|
||||
/** A small view-owned registration; unregistered tabs never inherit another tab's status. */
|
||||
public final class TabStatusFooter extends Label implements AutoCloseable {
|
||||
private final TabPane tabs;
|
||||
private final Map<Tab,ObservableStringValue> information=new HashMap<>();
|
||||
private final ChangeListener<Tab> selected=(o,a,b)->refresh();
|
||||
private final ListChangeListener<Tab> removed=change->{while(change.next())for(Tab tab:change.getRemoved())information.remove(tab);refresh();};
|
||||
public TabStatusFooter(TabPane tabs){
|
||||
this.tabs=tabs;setId("studio-footer");getStyleClass().addAll("studio-information-strip","studio-footer");
|
||||
setMaxWidth(Double.MAX_VALUE);setWrapText(false);
|
||||
tabs.getSelectionModel().selectedItemProperty().addListener(selected);tabs.getTabs().addListener(removed);
|
||||
var tooltip=new Tooltip();tooltip.textProperty().bind(textProperty());setTooltip(tooltip);
|
||||
}
|
||||
public void information(Tab tab,ObservableStringValue value){information.put(tab,value);refresh();}
|
||||
private void refresh(){
|
||||
textProperty().unbind();var value=information.get(tabs.getSelectionModel().getSelectedItem());
|
||||
if(value==null)setText("");else textProperty().bind(value);
|
||||
}
|
||||
@Override public void close(){
|
||||
textProperty().unbind();tabs.getSelectionModel().selectedItemProperty().removeListener(selected);tabs.getTabs().removeListener(removed);
|
||||
getTooltip().hide();getTooltip().textProperty().unbind();information.clear();
|
||||
}
|
||||
}
|
||||
+8
-7
@@ -52,16 +52,17 @@ final class ProjectChooser extends BorderPane {
|
||||
list.getSelectionModel().selectedItemProperty().addListener((o,a,b)->refresh());
|
||||
list.setOnMouseClicked(event->{if(event.getClickCount()==2)selected.run();});
|
||||
list.setOnKeyPressed(event->{if(event.getCode()==KeyCode.ENTER){selected.run();event.consume();}});
|
||||
FlowPane actions=new FlowPane(12,10,open,add,create,forget,retry);
|
||||
VBox content=new VBox(14,new StudioText(context,"projects.title").title(),list,actions);
|
||||
content.setPadding(new Insets(12));VBox.setVgrow(list,Priority.ALWAYS);
|
||||
HBox identity=new HBox(12,new StudioIcon(),new StudioText(context,"brand").title());
|
||||
identity.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||
FlowPane actions=new FlowPane(12,12,open,add,create,forget,retry);
|
||||
VBox content=new VBox(18,new StudioText(context,"projects.title").title(),list,actions);
|
||||
VBox.setVgrow(list,Priority.ALWAYS);
|
||||
StudioPanel frame=new StudioPanel(content);frame.setId("projects-frame");
|
||||
VBox layout=new VBox(20,identity,frame);layout.setPadding(new Insets(24));VBox.setVgrow(frame,Priority.ALWAYS);
|
||||
frame.getStyleClass().add("studio-window-panel");
|
||||
VBox layout=new VBox(frame);layout.setPadding(new Insets(18));VBox.setVgrow(frame,Priority.ALWAYS);
|
||||
layout.setMinHeight(Region.USE_PREF_SIZE);
|
||||
ScrollPane page=new ScrollPane(layout);page.setFitToWidth(true);page.setFitToHeight(true);page.setId("launcher-scroll");setCenter(page);
|
||||
message.setId("launcher-notice");message.setWrapText(true);setBottom(message);BorderPane.setMargin(message,new Insets(12,24,12,24));
|
||||
message.setId("launcher-notice");message.setWrapText(true);
|
||||
message.visibleProperty().bind(message.textProperty().isNotEmpty());message.managedProperty().bind(message.visibleProperty());
|
||||
setBottom(message);BorderPane.setMargin(message,new Insets(0,18,18,18));
|
||||
context.observe(()->{if(messageKey!=null)message.setText(context.text(messageKey,messageArguments));});refresh();
|
||||
}
|
||||
private Button action(AppearanceContext context,String key,String id,Runnable action) {
|
||||
|
||||
+112
@@ -0,0 +1,112 @@
|
||||
package p.studio.ui.javafx2.window;
|
||||
|
||||
import javafx.application.Platform;
|
||||
import javafx.geometry.*;
|
||||
import javafx.scene.Scene;
|
||||
import javafx.scene.control.*;
|
||||
import javafx.scene.layout.*;
|
||||
import javafx.stage.*;
|
||||
import p.studio.api.preferences.RuntimeSettingsStore;
|
||||
import p.studio.api.project.*;
|
||||
import p.studio.ui.javafx2.appearance.*;
|
||||
import p.studio.ui.javafx2.components.*;
|
||||
import p.studio.ui.javafx2.i18n.StudioLanguage;
|
||||
import p.studio.ui.javafx2.shell.MinimalShell;
|
||||
import java.util.concurrent.*;
|
||||
import java.util.function.*;
|
||||
|
||||
/** Separate scopes, draft form state and asynchronous Apply. No filesystem orchestration in the UI. */
|
||||
final class SettingsDialogs {
|
||||
record ProjectSettings(ProjectLocalStudioSetup setup, boolean disposable) { }
|
||||
private SettingsDialogs() { }
|
||||
static Stage preferences(Stage owner,WindowResources resources,AppearanceContext parent,String currentRuntime,
|
||||
boolean runtimeLocked,RuntimeSettingsStore store,Executor executor,Consumer<String> applied,Consumer<Boolean> working) {
|
||||
var context=resources.draft(parent);
|
||||
var dialog=new Form(owner,context,"preferences.title",executor,working);
|
||||
var theme=new StudioSelect<Theme>(context,"theme.label",v->context.text(v.labelKey()),Theme.values());
|
||||
theme.setId("theme-select");theme.connect(()->context.settings().theme(),v->context.update(context.settings().withTheme(v)));
|
||||
var language=new StudioSelect<StudioLanguage>(context,"language.label",StudioLanguage::label,StudioLanguage.values());
|
||||
language.setId("language-select");language.connect(()->context.settings().language(),v->context.update(context.settings().withLanguage(v)));
|
||||
var font=new StudioSelect<Typeface>(context,"font.label",Typeface::family,Typeface.values());
|
||||
font.setId("typeface-select");font.connect(()->context.settings().typeface(),v->context.update(context.settings().withTypeface(v)));
|
||||
var scale=new StudioSelect<Double>(context,"scale.label",v->context.text("scale.value",v),.75,1.,1.25,1.5,2.);
|
||||
scale.setId("scale-select");scale.connect(()->context.settings().scale(),v->context.update(context.settings().withScale(v)));
|
||||
var runtime=new StudioTextField();runtime.setId("global-runtime-path");runtime.setText(currentRuntime);
|
||||
var runtimeRow=directory(context,dialog.stage,runtime);runtimeRow.setDisable(runtimeLocked);
|
||||
dialog.fields.getChildren().addAll(new StudioText(context,"preferences.appearance").title(),
|
||||
MinimalShell.labeled(context,"theme.label",theme),MinimalShell.labeled(context,"language.label",language),
|
||||
MinimalShell.labeled(context,"font.label",font),MinimalShell.labeled(context,"scale.label",scale),
|
||||
new Separator(),MinimalShell.labeled(context,"preferences.runtime",runtimeRow));
|
||||
dialog.apply.setOnAction(e->{
|
||||
String path=normalize(runtime.getText());var settings=context.settings();
|
||||
dialog.submit(()->{if(!runtimeLocked)store.save(path);},()->{parent.update(settings);if(!runtimeLocked)applied.accept(path);});
|
||||
});
|
||||
dialog.stage.show();return dialog.stage;
|
||||
}
|
||||
static Stage project(Stage owner,WindowResources resources,AppearanceContext parent,ProjectReference project,
|
||||
ProjectLocalStudioSetup setup,boolean discard,String globalRuntime,RuntimeSettingsStore store,
|
||||
BiConsumer<ProjectReference,ProjectLocalStudioSetup> saver,Executor executor,
|
||||
Consumer<ProjectSettings> applied,Consumer<Boolean> working,boolean savingSection) {
|
||||
var context=resources.child(parent);var dialog=new Form(owner,context,"project.settings.title",executor,working);
|
||||
var inherit=new CheckBox();context.bindText(inherit,"project.runtime.inherit");inherit.setId("runtime-inherit");inherit.setSelected(setup.prometeuRuntimePath()==null);
|
||||
var runtime=new StudioTextField();runtime.setId("runtime-path");runtime.setText(setup.prometeuRuntimePath());
|
||||
var runtimeRow=directory(context,dialog.stage,runtime);runtimeRow.disableProperty().bind(inherit.selectedProperty());
|
||||
var effective=new Label();effective.setWrapText(true);effective.setId("effective-runtime");
|
||||
Runnable update=()->effective.setText(context.text(inherit.isSelected()?"project.runtime.global":"project.runtime.override",
|
||||
inherit.isSelected()?(globalRuntime==null?context.text("settings.unset"):globalRuntime):runtime.getText()));
|
||||
inherit.selectedProperty().addListener((o,a,b)->update.run());runtime.textProperty().addListener((o,a,b)->update.run());context.observe(update);
|
||||
var save=new StudioTextField();save.setId("memcard-path");save.setText(setup.memcardPath());
|
||||
var disposable=new CheckBox();context.bindText(disposable,"play.disposable");disposable.setId("disposable-save");disposable.setSelected(discard);
|
||||
var saveRow=new HBox(12,save,button(context,"play.browse","memcard-browse",()->{
|
||||
var picker=new FileChooser();var file=picker.showOpenDialog(dialog.stage);if(file!=null){save.setText(file.getAbsolutePath());disposable.setSelected(false);}
|
||||
}));HBox.setHgrow(save,Priority.ALWAYS);saveRow.disableProperty().bind(disposable.selectedProperty());
|
||||
dialog.fields.getChildren().addAll(new StudioText(context,"project.execution").title(),inherit,
|
||||
MinimalShell.labeled(context,"play.runtime",runtimeRow),effective);
|
||||
if(project.memcardSlots()!=null)dialog.fields.getChildren().addAll(new Separator(),new StudioText(context,"project.saving").title(),
|
||||
MinimalShell.labeled(context,"play.memcard",saveRow),disposable,new StudioText(context,"project.disposable.temporary"));
|
||||
dialog.apply.setOnAction(e->{
|
||||
var value=new ProjectLocalStudioSetup(inherit.isSelected()?null:normalize(runtime.getText()),setup.editorIndentation(),setup.agentIntegration(),normalize(save.getText()));
|
||||
boolean temporary=project.memcardSlots()!=null&&disposable.isSelected();
|
||||
if(!inherit.isSelected()&&value.prometeuRuntimePath()==null){dialog.feedback.setText(context.text("play.runtime.required"));return;}
|
||||
dialog.submit(()->{if(value.prometeuRuntimePath()!=null)store.validate(value.prometeuRuntimePath());saver.accept(project,value);},
|
||||
()->applied.accept(new ProjectSettings(value,temporary)));
|
||||
});
|
||||
dialog.stage.show();if(savingSection&&project.memcardSlots()!=null)Platform.runLater(()->{dialog.page.setVvalue(1);save.requestFocus();});
|
||||
return dialog.stage;
|
||||
}
|
||||
private static String normalize(String text){return text==null||text.isBlank()?null:text.trim();}
|
||||
private static HBox directory(AppearanceContext context,Stage owner,TextField path){
|
||||
var row=new HBox(12,path,button(context,"play.browse",path.getId()+"-browse",()->{
|
||||
var picker=new DirectoryChooser();var file=picker.showDialog(owner);if(file!=null)path.setText(file.getAbsolutePath());
|
||||
}));HBox.setHgrow(path,Priority.ALWAYS);return row;
|
||||
}
|
||||
private static Button button(AppearanceContext context,String key,String id,Runnable action){
|
||||
var button=new StudioButton(context,key,false);button.setId(id);button.setOnAction(e->action.run());return button;
|
||||
}
|
||||
private static final class Form {
|
||||
final Stage stage=new Stage();final VBox fields=new VBox(12);final Label feedback=new Label();
|
||||
final Button apply;final ScrollPane page=new ScrollPane(fields);
|
||||
private final Executor executor;private final Consumer<Boolean> working;private boolean busy;
|
||||
Form(Stage owner,AppearanceContext context,String title,Executor executor,Consumer<Boolean> working){
|
||||
this.executor=executor;this.working=working;stage.initOwner(owner);stage.initModality(Modality.WINDOW_MODAL);
|
||||
context.observe(()->stage.setTitle(context.text(title)));fields.setPadding(new Insets(20));
|
||||
page.setFitToWidth(true);page.setMinWidth(0);feedback.setWrapText(true);feedback.setId("settings-feedback");
|
||||
apply=button(context,"settings.apply","settings-apply",()->{});apply.setDefaultButton(true);
|
||||
var cancel=button(context,"settings.cancel","settings-cancel",stage::close);cancel.setCancelButton(true);
|
||||
var actions=new HBox(12,cancel,apply);actions.setAlignment(Pos.CENTER_RIGHT);
|
||||
var bottom=new VBox(12,feedback,actions);bottom.setPadding(new Insets(16,20,20,20));
|
||||
var root=new BorderPane(page,null,null,bottom,null);context.attach(root);root.setId("settings-dialog");
|
||||
var screen=Screen.getScreensForRectangle(owner.getX(),owner.getY(),Math.max(1,owner.getWidth()),Math.max(1,owner.getHeight())).stream().findFirst().orElse(Screen.getPrimary()).getVisualBounds();
|
||||
stage.setScene(new Scene(root,Math.min(680,screen.getWidth()*.9),Math.min(660,screen.getHeight()*.85)));
|
||||
stage.setOnCloseRequest(e->{if(busy)e.consume();});stage.setOnHidden(e->context.close());
|
||||
}
|
||||
void submit(Runnable io,Runnable applied){
|
||||
if(busy)return;busy=true;working.accept(true);apply.setDisable(true);fields.setDisable(true);feedback.setText("");
|
||||
try{CompletableFuture.runAsync(io,executor).whenComplete((v,f)->Platform.runLater(()->{
|
||||
busy=false;apply.setDisable(false);fields.setDisable(false);
|
||||
if(f==null){applied.run();stage.close();}else feedback.setText(ProjectOpening.unwrap(f).getMessage());
|
||||
working.accept(false);
|
||||
}));}catch(RuntimeException failure){busy=false;apply.setDisable(false);fields.setDisable(false);feedback.setText(failure.getMessage());working.accept(false);}
|
||||
}
|
||||
}
|
||||
}
|
||||
+202
-76
@@ -3,6 +3,7 @@ package p.studio.ui.javafx2.window;
|
||||
import javafx.animation.AnimationTimer;
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.binding.Bindings;
|
||||
import javafx.util.Duration;
|
||||
import javafx.geometry.Insets;
|
||||
import javafx.scene.Scene;
|
||||
@@ -17,6 +18,8 @@ import p.studio.ui.javafx2.appearance.AppearanceContext;
|
||||
import p.studio.ui.javafx2.components.*;
|
||||
import p.studio.ui.javafx2.play.PlaybackViewport;
|
||||
import p.studio.ui.javafx2.shell.MinimalShell;
|
||||
import p.studio.ui.javafx2.shell.ExecutionBar;
|
||||
import p.studio.ui.javafx2.shell.TabStatusFooter;
|
||||
import java.nio.file.Path;
|
||||
import java.util.*;
|
||||
import java.util.concurrent.*;
|
||||
@@ -29,6 +32,15 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
private Stage loadingStage;
|
||||
private final ProjectLanguageCatalog languages;
|
||||
private final WindowStateStore windows;
|
||||
private final RuntimeSettingsStore runtimeSettings;
|
||||
private String defaultRuntime;
|
||||
private ProjectLocalStudioSetup localSetup;
|
||||
private boolean disposableSave;
|
||||
private final ExecutorService geometryWorker=Executors.newSingleThreadExecutor(r->new Thread(r,"studio-window-state"));
|
||||
private final java.util.concurrent.atomic.AtomicReference<Throwable> geometryFailure=new java.util.concurrent.atomic.AtomicReference<>();
|
||||
private WindowGeometryBinding launcherGeometry,projectGeometry;
|
||||
private boolean launcherLoading;
|
||||
private Stage settingsStage;
|
||||
private final AppearanceContext launcherContext;
|
||||
private AppearanceContext loadingContext;
|
||||
private final ProjectChooser chooser;
|
||||
@@ -53,14 +65,18 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
private AppearanceContext viewContext;
|
||||
private final MinimalShell shell;
|
||||
private final Label notice=new Label();
|
||||
private VBox feedback;
|
||||
private final VBox bottom=new VBox();
|
||||
private final AnimationTimer lifecycle;
|
||||
private ProjectSession project;
|
||||
private ExecutionController controller;
|
||||
private PlaybackViewport viewport;
|
||||
private VBox configuration;
|
||||
private StudioTextField runtimePath,savePath;
|
||||
private CheckBox disposable;
|
||||
private Button play,pause,resume,stop,closeProject;
|
||||
private Button play;
|
||||
private ToggleButton pause;
|
||||
private MenuItem closeProject,projectSettings;
|
||||
private Button configurationAction;
|
||||
private TabPane tabs;
|
||||
private Tab gameplay;
|
||||
private Label stateLabel;
|
||||
private TextArea logs;
|
||||
private long lastLog=-1;
|
||||
@@ -78,19 +94,35 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
public StudioWindowCoordinator2(Stage stage,ProjectCatalog catalog,KnownProjects known,ProjectSessionFactory sessions,
|
||||
ExecutionControllerFactory executions,BiConsumer<ProjectReference,ProjectLocalStudioSetup> saveSetup,
|
||||
Executor executor,WindowResources resources,ProjectLanguageCatalog languages,WindowStateStore windows) {
|
||||
this(stage,catalog,known,sessions,executions,saveSetup,executor,resources,languages,windows,new RuntimeSettingsStore(){
|
||||
private String value; public String load(){return value;} public void save(String path){value=path;}
|
||||
},null);
|
||||
}
|
||||
public StudioWindowCoordinator2(Stage stage,ProjectCatalog catalog,KnownProjects known,ProjectSessionFactory sessions,
|
||||
ExecutionControllerFactory executions,BiConsumer<ProjectReference,ProjectLocalStudioSetup> saveSetup,
|
||||
Executor executor,WindowResources resources,ProjectLanguageCatalog languages,WindowStateStore windows,
|
||||
RuntimeSettingsStore runtimeSettings,String initialRuntime) {
|
||||
this.stage=stage;this.catalog=catalog;this.known=known;this.sessions=sessions;this.executions=executions;
|
||||
this.languages=languages;this.windows=windows;
|
||||
this.runtimeSettings=runtimeSettings;this.defaultRuntime=initialRuntime;
|
||||
this.saveSetup=saveSetup;this.executor=executor;this.resources=resources;
|
||||
context=resources.context();shell=new MinimalShell(context);notice.setWrapText(true);notice.setId("studio-notice");
|
||||
context=resources.context();shell=new MinimalShell(context,false);notice.setWrapText(true);notice.setId("studio-notice");
|
||||
context.observe(()->shell.workspace().setAccessibleText(project==null?context.text("projects.title"):project.projectReference().name()));
|
||||
shell.setBottom(notice);BorderPane.setMargin(notice,new Insets(10,18,12,18));
|
||||
configurationAction=button(context,"settings.open","configure-action",()->{});configurationAction.setVisible(false);configurationAction.setManaged(false);
|
||||
configurationAction.textProperty().unbind();
|
||||
feedback=new VBox(8,notice,configurationAction);feedback.setPadding(new Insets(8,18,12,18));
|
||||
bottom.getChildren().add(feedback);shell.setBottom(bottom);
|
||||
feedback.visibleProperty().bind(notice.textProperty().isNotEmpty().or(configurationAction.visibleProperty()));
|
||||
feedback.managedProperty().bind(feedback.visibleProperty());
|
||||
shell.setTop(menus(context,false));
|
||||
stage.setScene(new Scene(shell,1200,850));stage.setTitle("Prometeu Studio");stage.setMinWidth(680);stage.setMinHeight(480);
|
||||
Platform.setImplicitExit(false);
|
||||
stage.setOnCloseRequest(e->{e.consume();requestCloseProject();});
|
||||
launcherContext=resources.child(context);
|
||||
chooser=new ProjectChooser(launcherContext,p->safe(()->openProject(p)),()->safe(this::addExisting),
|
||||
()->safe(this::newProject),ref->safe(()->forget(ref)),()->openingRetry());
|
||||
launcherStage.setScene(new Scene(chooser,960,720));launcherStage.setMinWidth(600);launcherStage.setMinHeight(440);
|
||||
var launcherRoot=new BorderPane(chooser,menus(launcherContext,false),null,null,null);launcherContext.attach(launcherRoot);
|
||||
launcherStage.setScene(new Scene(launcherRoot,960,720));launcherStage.setMinWidth(600);launcherStage.setMinHeight(440);
|
||||
context.observe(()->{launcherStage.setTitle(context.text("brand"));stage.setTitle(project==null?context.text("brand"):project.projectReference().name()+" · "+context.text("brand"));});
|
||||
launcherStage.setOnCloseRequest(e->{e.consume();exitPlatform=true;exitRequested=true;requestCloseProject();});
|
||||
opening=new ProjectOpening(catalog,known,sessions,windows,executor,Platform::runLater,System::nanoTime,(nanos,action)->{
|
||||
@@ -100,7 +132,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
public void resolved(ProjectReference reference){loadingProject.setText(reference.name());}
|
||||
public void prepare(ProjectSession session,WindowGeometry geometry){project=session;showProject();restoreGeometry(geometry);}
|
||||
public void present(){stage.setTitle(project.projectReference().name()+" · "+context.text("brand"));stage.show();stage.toFront();hideLoading();createdProject=null;refresh();}
|
||||
public void discard(){stage.hide();project=null;play=null;if(viewport!=null){viewport.close();viewport=null;}if(viewContext!=null){viewContext.close();viewContext=null;}shell.workspace().getChildren().clear();}
|
||||
public void discard(){if(projectGeometry!=null){projectGeometry.close();projectGeometry=null;}stage.hide();project=null;play=null;if(viewport!=null){viewport.close();viewport=null;}if(viewContext!=null){viewContext.close();viewContext=null;}shell.workspace().getChildren().clear();}
|
||||
public void failed(Throwable failure,boolean cleanupRequired){hideLoading();showChooser();
|
||||
String detail=diagnostic(failure);
|
||||
chooser.feedback(cleanupRequired?"projects.cleanupFailed":createdProject==null?"projects.openFailed":"projects.createdOpenFailed",cleanupRequired,detail);
|
||||
@@ -135,8 +167,20 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
catch(RuntimeException failure){if(!closed)result.accept(null,failure);}
|
||||
}
|
||||
private void showChooser(){
|
||||
stage.hide();launcherStage.show();launcherStage.centerOnScreen();launcherStage.toFront();
|
||||
reloadProjects(null);
|
||||
stage.hide();
|
||||
if(launcherGeometry==null){
|
||||
if(launcherLoading)return;launcherLoading=true;
|
||||
background(()->windows.loadLauncher().orElse(null),(saved,failure)->{
|
||||
launcherLoading=false;if(exitRequested)return;
|
||||
launcherGeometry=new WindowGeometryBinding(launcherStage,saved,960,720,geometryWorker,windows::saveLauncher,this::geometryError);
|
||||
if(project==null&&!opening.busy()){launcherStage.show();launcherStage.toFront();reloadProjects(null);if(failure!=null)error(failure);}
|
||||
});
|
||||
}else {launcherStage.show();launcherStage.toFront();reloadProjects(null);}
|
||||
}
|
||||
private void geometryError(Throwable failure){
|
||||
geometryFailure.set(failure);
|
||||
if(Platform.isFxApplicationThread()){if(!closed)error(failure);}
|
||||
else Platform.runLater(()->{if(!closed)error(failure);});
|
||||
}
|
||||
private void reloadProjects(Path selection){
|
||||
chooser.busy(true);
|
||||
@@ -187,9 +231,12 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
String versionText=System.getProperty("prometeu.studio.version",Optional.ofNullable(getClass().getPackage().getImplementationVersion()).orElse("dev"));
|
||||
Label version=new Label();loadingContext.observe(()->version.setText(context.text("projects.version",versionText)));
|
||||
loadingProject=new Label(path.getFileName()==null?path.toString():path.getFileName().toString());loadingProject.setWrapText(true);
|
||||
VBox body=new VBox(16,new HBox(12,new StudioIcon(),new StudioText(loadingContext,"brand").title()),version,loadingProject,loadingStatus,loadingFeedback);
|
||||
body.setPadding(new Insets(28));StudioPanel frame=new StudioPanel(body);loadingContext.attach(frame);
|
||||
ScrollPane page=new ScrollPane(frame);page.setFitToWidth(true);loadingContext.attach(page);
|
||||
var identity=new HBox(12,new StudioIcon(),new StudioText(loadingContext,"brand").title());identity.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||
VBox body=new VBox(18,identity,version,loadingProject,loadingStatus,loadingFeedback);
|
||||
body.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||
StudioPanel frame=new StudioPanel(body);frame.getStyleClass().add("studio-window-panel");loadingContext.attach(frame);
|
||||
VBox layout=new VBox(frame);layout.setPadding(new Insets(18));layout.setMinHeight(Region.USE_PREF_SIZE);VBox.setVgrow(frame,Priority.ALWAYS);
|
||||
ScrollPane page=new ScrollPane(layout);page.setFitToWidth(true);page.setFitToHeight(true);loadingContext.attach(page);
|
||||
double scale=context.settings().scale();var bounds=Screen.getPrimary().getVisualBounds();
|
||||
loadingStage.setScene(new Scene(page,Math.min(bounds.getWidth()*.9,560*scale),Math.min(bounds.getHeight()*.85,340*scale)));loadingStage.setResizable(false);
|
||||
loadingStage.setOnCloseRequest(e->{e.consume();exitPlatform=true;exitRequested=true;requestCloseProject();});
|
||||
@@ -200,74 +247,138 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
private void hideLoading(){if(loadingStage!=null){loadingStage.hide();loadingStage.setOnCloseRequest(null);loadingStage=null;}
|
||||
if(loadingContext!=null){loadingContext.close();loadingContext=null;}loadingStatus=null;loadingProject=null;loadingFeedback=null;}
|
||||
private void restoreGeometry(WindowGeometry geometry){
|
||||
stage.setMaximized(false);stage.setWidth(1200);stage.setHeight(850);
|
||||
if(geometry==null){stage.centerOnScreen();return;}
|
||||
var bounds=Screen.getPrimary().getVisualBounds();
|
||||
double width=Double.isFinite(geometry.width())?Math.max(680,Math.min(geometry.width(),bounds.getWidth())):1200;
|
||||
double height=Double.isFinite(geometry.height())?Math.max(480,Math.min(geometry.height(),bounds.getHeight())):850;
|
||||
stage.setWidth(width);stage.setHeight(height);
|
||||
boolean visible=Screen.getScreens().stream().anyMatch(screen->screen.getVisualBounds().intersects(geometry.x(),geometry.y(),width,height));
|
||||
if(visible&&Double.isFinite(geometry.x())&&Double.isFinite(geometry.y())){stage.setX(geometry.x());stage.setY(geometry.y());}else stage.centerOnScreen();
|
||||
stage.setMaximized(geometry.maximized());
|
||||
if(projectGeometry!=null)projectGeometry.close();
|
||||
var reference=project.projectReference();
|
||||
projectGeometry=new WindowGeometryBinding(stage,geometry,1200,850,geometryWorker,g->windows.save(reference,g),this::geometryError);
|
||||
}
|
||||
private MenuBar menus(AppearanceContext c,boolean withProject){
|
||||
var studio=new Menu();studio.setGraphic(new StudioIcon());var preferences=new MenuItem();preferences.setId("studio-preferences");
|
||||
c.observe(()->{studio.setText(c.text("menu.studio"));preferences.setText(c.text("preferences.title"));});
|
||||
preferences.setOnAction(e->safe(this::openPreferences));studio.getItems().add(preferences);
|
||||
var bar=new MenuBar(studio);bar.setId("studio-menus");bar.getStyleClass().add("studio-navigation");
|
||||
if(withProject){
|
||||
var menu=new Menu();projectSettings=new MenuItem();projectSettings.setId("project-settings");
|
||||
closeProject=new MenuItem();closeProject.setId("close-project");
|
||||
c.observe(()->{menu.setText(c.text("menu.project"));projectSettings.setText(c.text("project.settings.title"));closeProject.setText(c.text("projects.close"));});
|
||||
projectSettings.setOnAction(e->safe(()->openProjectSettings(false)));closeProject.setOnAction(e->requestCloseProject());
|
||||
menu.getItems().addAll(projectSettings,new SeparatorMenuItem(),closeProject);bar.getMenus().add(menu);
|
||||
}
|
||||
return bar;
|
||||
}
|
||||
private void settingsWorking(boolean working){
|
||||
busy=working;refresh();
|
||||
if(!working&&(projectCloseRequested||exitRequested))requestCloseProject();
|
||||
}
|
||||
public void openPreferences(){
|
||||
if(closed||closing||busy)return;if(settingsStage!=null&&settingsStage.isShowing()){settingsStage.toFront();return;}
|
||||
Stage owner=launcherStage.isShowing()?launcherStage:stage;
|
||||
settingsStage=SettingsDialogs.preferences(owner,resources,context,defaultRuntime,
|
||||
controller!=null&&controller.ownsExecution(),runtimeSettings,executor,value->defaultRuntime=value,this::settingsWorking);
|
||||
}
|
||||
public void openProjectSettings(boolean savingSection){
|
||||
if(project==null||closed||closing||busy||controller!=null&&controller.ownsExecution())return;
|
||||
if(settingsStage!=null&&settingsStage.isShowing()){settingsStage.toFront();return;}
|
||||
var owner=project;
|
||||
settingsStage=SettingsDialogs.project(stage,resources,context,project.projectReference(),localSetup,disposableSave,
|
||||
defaultRuntime,runtimeSettings,saveSetup,executor,value->{if(project==owner){localSetup=value.setup();disposableSave=value.disposable();notice.setText("");configurationAction.setVisible(false);configurationAction.setManaged(false);}},
|
||||
this::settingsWorking,savingSection);
|
||||
}
|
||||
private void configurationNeeded(String message,boolean global,boolean savingSection){
|
||||
notice.setText(message);configurationAction.setVisible(true);configurationAction.setManaged(true);
|
||||
configurationAction.setText(context.text(global?"settings.open.preferences":"settings.open.project"));
|
||||
configurationAction.setOnAction(e->safe(()->{if(global)openPreferences();else openProjectSettings(savingSection);}));
|
||||
}
|
||||
|
||||
public void openProject(Path path){
|
||||
if(closed||exitRequested||busy||project!=null||closing||opening.busy())return;
|
||||
if(!path.equals(createdProject))createdProject=null;
|
||||
chooser.message("",false);chooser.busy(true);showLoading(path);opening.start(path);
|
||||
}
|
||||
private void showProject(){
|
||||
var c=beginView();var ref=project.projectReference();var setup=project.projectLocalStudioSetup();
|
||||
shell.workspace().setAccessibleText(ref.name());
|
||||
Label title=new Label(ref.name());title.getStyleClass().add("studio-title");HBox.setHgrow(title,Priority.ALWAYS);
|
||||
closeProject=button(c,"projects.close","close-project",this::requestCloseProject);
|
||||
HBox heading=new HBox(18,title,closeProject);
|
||||
runtimePath=new StudioTextField();runtimePath.setId("runtime-path");runtimePath.setText(setup.prometeuRuntimePath());
|
||||
Button browseRuntime=button(c,"play.browse","runtime-browse",()->{
|
||||
DirectoryChooser chooser=new DirectoryChooser();var chosen=chooser.showDialog(stage);if(chosen!=null)runtimePath.setText(chosen.getAbsolutePath());});
|
||||
HBox runtimeRow=new HBox(12,runtimePath,browseRuntime);HBox.setHgrow(runtimePath,Priority.ALWAYS);
|
||||
configuration=new VBox(8,MinimalShell.labeled(c,"play.runtime",runtimeRow));
|
||||
disposable=new CheckBox();c.bindText(disposable,"play.disposable");disposable.setId("disposable-save");
|
||||
savePath=new StudioTextField();savePath.setId("memcard-path");savePath.setText(setup.memcardPath());
|
||||
if(ref.memcardSlots()!=null){
|
||||
Button browseSave=button(c,"play.browse","memcard-browse",()->{
|
||||
FileChooser chooser=new FileChooser();var chosen=chooser.showOpenDialog(stage);if(chosen!=null){savePath.setText(chosen.getAbsolutePath());disposable.setSelected(false);}});
|
||||
HBox row=new HBox(12,savePath,browseSave);HBox.setHgrow(savePath,Priority.ALWAYS);
|
||||
disposable.selectedProperty().addListener((o,a,b)->row.setDisable(b));
|
||||
configuration.getChildren().addAll(MinimalShell.labeled(c,"play.memcard",row),disposable);
|
||||
}
|
||||
play=button(c,"play.start","play",this::play);
|
||||
pause=button(c,"play.pause","pause",()->{viewport.neutralize();observe(controller.pause().completion());});
|
||||
resume=button(c,"play.resume","resume",()->{observe(controller.resume().completion());viewport.focusGame();});
|
||||
stop=button(c,"play.stop","stop",()->{viewport.neutralize();observe(controller.stopAsync());});
|
||||
StudioSelect<Integer> zoom=new StudioSelect<>(c,"play.zoom",n->"x"+n,1,2,4);zoom.setId("viewport-zoom");zoom.setValue(1);
|
||||
var c=beginView();var ref=project.projectReference();localSetup=project.projectLocalStudioSetup();disposableSave=false;
|
||||
shell.workspace().setAccessibleText(ref.name());notice.setText("");configurationAction.setVisible(false);configurationAction.setManaged(false);
|
||||
play=button(c,"play.start","play",()->{
|
||||
if(controller!=null&&controller.ownsExecution()){viewport.neutralize();observe(controller.stopAsync());}else play();
|
||||
});
|
||||
play.textProperty().unbind();
|
||||
pause=new StudioToggle(c,"play.pause");pause.setId("pause");
|
||||
pause.textProperty().unbind();
|
||||
var playTip=new Tooltip();playTip.textProperty().bind(play.textProperty());play.setTooltip(playTip);
|
||||
var pauseTip=new Tooltip();pauseTip.textProperty().bind(pause.textProperty());pause.setTooltip(pauseTip);
|
||||
c.onClose(()->{playTip.hide();pauseTip.hide();playTip.textProperty().unbind();pauseTip.textProperty().unbind();});
|
||||
pause.setOnAction(e->safe(()->{
|
||||
var state=project.executionSession().snapshot().state();
|
||||
if(state==ExecutionState.RUNNING){viewport.neutralize();observe(controller.pause().completion());}
|
||||
else if(state==ExecutionState.PAUSED){observe(controller.resume().completion());viewport.focusGame();}
|
||||
refresh();
|
||||
}));
|
||||
stateLabel=new Label();stateLabel.setId("execution-state");stateLabel.setWrapText(false);
|
||||
var identity=new Label(ref.name()+" · "+ref.version());identity.setId("project-information");identity.setMaxWidth(Double.MAX_VALUE);
|
||||
HBox.setHgrow(identity,Priority.ALWAYS);HBox.setHgrow(stateLabel,Priority.SOMETIMES);
|
||||
var header=new HBox(16,identity,stateLabel);header.setAlignment(javafx.geometry.Pos.CENTER_LEFT);
|
||||
header.setId("studio-header");header.getStyleClass().addAll("studio-information-strip","studio-header");
|
||||
var identityTip=new Tooltip();identityTip.textProperty().bind(identity.textProperty());identity.setTooltip(identityTip);
|
||||
var stateTip=new Tooltip();stateTip.textProperty().bind(stateLabel.textProperty());stateLabel.setTooltip(stateTip);
|
||||
c.onClose(()->{identityTip.hide();stateTip.hide();identityTip.textProperty().unbind();stateTip.textProperty().unbind();});
|
||||
shell.setTop(new VBox(new ExecutionBar(c,menus(c,true),play,pause),header));
|
||||
viewport=new PlaybackViewport(()->controller,()->project.executionSession().snapshot().state());
|
||||
zoom.setOnAction(e->{if(zoom.getValue()!=null)viewport.zoom(zoom.getValue());});
|
||||
stateLabel=new Label();stateLabel.setId("execution-state");
|
||||
c.observe(()->{displayedState=null;refresh();});
|
||||
FlowPane controls=new FlowPane(12,10,play,pause,resume,stop,zoom,stateLabel);
|
||||
logs=new TextArea();logs.setId("execution-logs");logs.setEditable(false);logs.setPrefRowCount(4);logs.setWrapText(true);
|
||||
VBox top=new VBox(14,heading,configuration,controls);top.setPadding(new Insets(16));
|
||||
BorderPane body=new BorderPane(viewport,top,null,logs,null);body.setId("project-play");
|
||||
shell.workspace().getChildren().setAll(body);lastLog=-1;refresh();
|
||||
var manual=new CheckBox();c.bindText(manual,"play.scale.manual");manual.setId("manual-scale");
|
||||
var slider=new Slider(25,400,100);slider.setId("game-scale");slider.setBlockIncrement(5);slider.setPrefWidth(210);
|
||||
slider.setAccessibleText(c.text("play.scale.manual"));slider.disableProperty().bind(manual.selectedProperty().not());
|
||||
manual.setOnAction(e->{viewport.setManual(manual.isSelected());if(manual.isSelected())slider.setValue(viewport.scale()>0?viewport.scale()*100:100);});
|
||||
slider.valueProperty().addListener((o,a,b)->{if(manual.isSelected())viewport.setScale(b.doubleValue()/100);});
|
||||
var localControls=new FlowPane(12,10,manual,slider);localControls.setPadding(new Insets(10));
|
||||
var game=new BorderPane(viewport,localControls,null,null,null);game.setId("project-play");
|
||||
viewport.setMinHeight(64);
|
||||
logs=new TextArea();logs.setId("execution-logs");logs.setEditable(false);logs.setPrefRowCount(4);logs.setWrapText(true);logs.setMinHeight(64);
|
||||
var split=new SplitPane(game,logs);split.setId("gameplay-split");split.getStyleClass().add("studio-gameplay-split");
|
||||
split.setOrientation(javafx.geometry.Orientation.VERTICAL);split.setDividerPositions(.8);
|
||||
// Apply the initial ratio after the native window has received its actual size.
|
||||
var initialSplit=new AnimationTimer(){@Override public void handle(long now){
|
||||
if(stage.isShowing()&&split.getHeight()>0){split.setDividerPositions(.8);stop();}
|
||||
}};
|
||||
initialSplit.start();c.onClose(initialSplit::stop);
|
||||
gameplay=new Tab(c.text("gameplay.title"),split);gameplay.setId("gameplay-tab");gameplay.setClosable(false);
|
||||
tabs=new StudioTabs(gameplay);tabs.setId("project-tabs");
|
||||
var statusFooter=new TabStatusFooter(tabs);
|
||||
var gameplayInfo=Bindings.createStringBinding(()->viewport.scale()>0?
|
||||
c.text("gameplay.footer",c.text("play.scale.value",viewport.scale()*100,viewport.scale())):c.text("gameplay.footer.waiting"),
|
||||
viewport.scaleProperty(),c.settingsProperty());
|
||||
statusFooter.information(gameplay,gameplayInfo);
|
||||
var stripHeight=Bindings.createDoubleBinding(()->Math.ceil(identity.getFont().getSize()*1.7),identity.fontProperty());
|
||||
for(var strip:new Region[]{header,statusFooter}){
|
||||
strip.minHeightProperty().bind(stripHeight);strip.prefHeightProperty().bind(stripHeight);strip.maxHeightProperty().bind(stripHeight);
|
||||
}
|
||||
c.onClose(()->{statusFooter.close();gameplayInfo.dispose();
|
||||
for(var strip:new Region[]{header,statusFooter}){strip.minHeightProperty().unbind();strip.prefHeightProperty().unbind();strip.maxHeightProperty().unbind();}
|
||||
stripHeight.dispose();});
|
||||
// Keep reusable feedback in the same themed parent across project views.
|
||||
if(bottom.getChildren().size()>1)bottom.getChildren().remove(1);
|
||||
bottom.getChildren().add(statusFooter);
|
||||
c.observe(()->{gameplay.setText(c.text("gameplay.title"));displayedState=null;refresh();});
|
||||
var page=new ScrollPane(tabs);page.setFitToWidth(true);page.setFitToHeight(true);page.setMinSize(0,0);
|
||||
shell.workspace().getChildren().setAll(page);lastLog=-1;refresh();
|
||||
}
|
||||
private void play(){
|
||||
if(busy||closing||controller!=null&&controller.ownsExecution())return;
|
||||
var original=project.projectLocalStudioSetup();var ref=project.projectReference();
|
||||
String runtime=runtimePath.getText();if(runtime==null||runtime.isBlank())throw new IllegalArgumentException(context.text("play.runtime.required"));
|
||||
boolean discard=ref.memcardSlots()!=null&&disposable.isSelected();
|
||||
if(ref.memcardSlots()!=null&&!discard&&(savePath.getText()==null||savePath.getText().isBlank()))
|
||||
throw new IllegalArgumentException(context.text("play.memcard.required"));
|
||||
var setup=new ProjectLocalStudioSetup(runtime,original.editorIndentation(),original.agentIntegration(),savePath.getText());
|
||||
busy=true;refresh();notice.setText("");
|
||||
background(()->{saveSetup.accept(ref,setup);return setup;},(saved,failure)->{
|
||||
busy=false;if(failure!=null){error(failure);if(exitRequested||projectCloseRequested)requestCloseProject();return;}
|
||||
var original=localSetup;var ref=project.projectReference();boolean discard=ref.memcardSlots()!=null&&disposableSave;
|
||||
if(ref.memcardSlots()!=null&&!discard&&(original.memcardPath()==null||original.memcardPath().isBlank())){
|
||||
configurationNeeded(context.text("play.memcard.required"),false,true);return;
|
||||
}
|
||||
busy=true;refresh();notice.setText("");configurationAction.setVisible(false);configurationAction.setManaged(false);
|
||||
background(()->new ProjectLocalStudioSetup(runtimeSettings.resolve(original.prometeuRuntimePath()),original.editorIndentation(),
|
||||
original.agentIntegration(),original.memcardPath()),(effective,failure)->{
|
||||
busy=false;
|
||||
if(failure!=null){configurationNeeded(context.text("feedback.error",diagnostic(failure)),original.prometeuRuntimePath()==null,false);
|
||||
refresh();if(exitRequested||projectCloseRequested)requestCloseProject();return;}
|
||||
if(closing||exitRequested||projectCloseRequested){requestCloseProject();return;}
|
||||
safe(()->{if(controller!=null)controller.close();
|
||||
controller=executions.create(ref,saved,project.executionSession(),new PlayOptions(discard));
|
||||
observe(controller.play().completion());viewport.focusGame();
|
||||
controller=executions.create(ref,effective,project.executionSession(),new PlayOptions(discard));
|
||||
tabs.getSelectionModel().select(gameplay);observe(controller.play().completion());viewport.focusGame();
|
||||
if(stage.isIconified()||!Window.getWindows().stream().anyMatch(w->w.isFocused()&&belongsToStudio(w)))pauseForFocus();refresh();});
|
||||
});
|
||||
}
|
||||
|
||||
private void observe(CompletionStage<?> operation){
|
||||
ProjectSession originProject=project;ExecutionController originController=controller;
|
||||
long command=++operationSequence;
|
||||
@@ -288,11 +399,16 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
private void refresh(){
|
||||
if(project==null||play==null||closed)return;
|
||||
var snapshot=project.executionSession().snapshot();var state=snapshot.state();boolean owned=controller!=null&&controller.ownsExecution();
|
||||
configuration.setDisable(busy||closing||owned);configuration.setVisible(!owned);configuration.setManaged(!owned);
|
||||
play.setDisable(busy||closing||owned);
|
||||
pause.setDisable(closing||state!=ExecutionState.RUNNING);resume.setDisable(closing||state!=ExecutionState.PAUSED);
|
||||
stop.setDisable(closing||!owned||state==ExecutionState.STOPPING);closeProject.setDisable(closing);
|
||||
if(displayedState!=state){displayedState=state;stateLabel.setText(viewContext.text("state."+state.name()));
|
||||
play.setText(context.text(owned?"play.stop":"play.start"));play.setAccessibleText(play.getText());
|
||||
play.setDisable(busy||closing||state==ExecutionState.STOPPING);
|
||||
pause.setDisable(busy||closing||state!=ExecutionState.RUNNING&&state!=ExecutionState.PAUSED);
|
||||
pause.setSelected(state==ExecutionState.PAUSED||state==ExecutionState.PAUSING);
|
||||
pause.setText(context.text(state==ExecutionState.PAUSED?"play.resume":"play.pause"));pause.setAccessibleText(pause.getText());
|
||||
if(closeProject!=null)closeProject.setDisable(closing||busy);
|
||||
if(projectSettings!=null)projectSettings.setDisable(closing||busy||owned);
|
||||
if(displayedState!=state){displayedState=state;
|
||||
stateLabel.setText(viewContext.text("state."+state.name())+(owned&&disposableSave?" · "+context.text("play.disposable.short"):""));
|
||||
play.getTooltip().hide();pause.getTooltip().hide();
|
||||
if(state!=ExecutionState.RUNNING&&viewport!=null)viewport.neutralize();}
|
||||
long sequence=snapshot.logs().isEmpty()?0:snapshot.logs().getLast().sequence();
|
||||
if(logs!=null&&lastLog!=sequence){lastLog=sequence;StringBuilder text=new StringBuilder();
|
||||
@@ -300,6 +416,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
for(var entry:snapshot.logs().subList(start,snapshot.logs().size()))text.append(entry.severity()).append(" · ").append(entry.message()).append('\n');
|
||||
logs.setText(text.toString());logs.positionCaret(logs.getLength());}
|
||||
}
|
||||
|
||||
public void requestCloseProject(){
|
||||
if(closed||closing)return;
|
||||
projectCloseRequested=true;
|
||||
@@ -313,6 +430,7 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
}
|
||||
if(busy){if(exitRequested)notice.setText(context.text("feedback.busy"));return;}
|
||||
if(project==null){projectCloseRequested=false;if(exitRequested)finishExit();return;}
|
||||
if(settingsStage!=null&&settingsStage.isShowing())settingsStage.close();
|
||||
closing=true;refresh();if(viewport!=null)viewport.neutralize();
|
||||
CompletionStage<Void> stopping;
|
||||
try{stopping=controller==null?CompletableFuture.completedFuture(null):controller.stopAsync();}
|
||||
@@ -320,8 +438,8 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
stopping.whenComplete((v,f)->Platform.runLater(()->{
|
||||
if(f!=null){closing=false;exitRequested=false;projectCloseRequested=false;error(f);refresh();return;}
|
||||
var oldProject=project;var oldController=controller;
|
||||
var geometry=new WindowGeometry(stage.getX(),stage.getY(),stage.getWidth(),stage.getHeight(),stage.isMaximized());
|
||||
background(()->closeOwned(oldProject,oldController,geometry),(warning,failure)->{
|
||||
if(projectGeometry!=null){projectGeometry.close();projectGeometry=null;}
|
||||
background(()->closeOwned(oldProject,oldController),(warning,failure)->{
|
||||
if(failure!=null){closing=false;exitRequested=false;projectCloseRequested=false;error(failure);refresh();return;}
|
||||
project=null;controller=null;closing=false;projectCloseRequested=false;play=null;notice.setText("");
|
||||
if(viewport!=null){viewport.close();viewport=null;}if(viewContext!=null){viewContext.close();viewContext=null;}shell.workspace().getChildren().clear();
|
||||
@@ -329,20 +447,28 @@ public final class StudioWindowCoordinator2 implements AutoCloseable {
|
||||
});
|
||||
}));
|
||||
}
|
||||
private Throwable closeOwned(ProjectSession session,ExecutionController execution,WindowGeometry geometry){
|
||||
private Throwable closeOwned(ProjectSession session,ExecutionController execution){
|
||||
RuntimeException warning=null,failure=null;
|
||||
try{windows.save(session.projectReference(),geometry);}catch(RuntimeException error){warning=error;}
|
||||
try{if(execution!=null)execution.close();}catch(RuntimeException error){failure=error;}
|
||||
try{session.close();}catch(RuntimeException error){if(failure==null)failure=error;else failure.addSuppressed(error);}
|
||||
if(failure!=null){if(warning!=null)failure.addSuppressed(warning);throw failure;}return warning;
|
||||
}
|
||||
private void finishExit(){
|
||||
if(closed)return;closed=true;lifecycle.stop();hideLoading();stage.hide();launcherStage.hide();
|
||||
if(closed)return;
|
||||
if(projectGeometry!=null){projectGeometry.close();projectGeometry=null;}
|
||||
if(launcherGeometry!=null){launcherGeometry.close();launcherGeometry=null;}
|
||||
if(settingsStage!=null&&settingsStage.isShowing())settingsStage.close();
|
||||
closed=true;lifecycle.stop();hideLoading();stage.hide();launcherStage.hide();
|
||||
if(viewport!=null){viewport.close();viewport=null;}
|
||||
if(viewContext!=null)viewContext.close();launcherContext.close();context.close();
|
||||
stage.setOnCloseRequest(null);launcherStage.setOnCloseRequest(null);
|
||||
// Preference persistence may flush pending IO; keep it off the FX thread too.
|
||||
try{CompletableFuture.runAsync(resources::close,executor).whenComplete((v,f)->Platform.runLater(()->{
|
||||
try{CompletableFuture.runAsync(()->{
|
||||
geometryWorker.shutdown();
|
||||
try{if(!geometryWorker.awaitTermination(10,TimeUnit.SECONDS))throw new IllegalStateException("Window state did not finish saving");}
|
||||
catch(InterruptedException failure){Thread.currentThread().interrupt();throw new CompletionException(failure);}
|
||||
resources.close();if(geometryFailure.get()!=null)throw new CompletionException(geometryFailure.get());
|
||||
},executor).whenComplete((v,f)->Platform.runLater(()->{
|
||||
if(f==null)shutdown.complete(null);else shutdown.completeExceptionally(f);
|
||||
if(exitPlatform)Platform.exit();
|
||||
}));}catch(RuntimeException failure){shutdown.completeExceptionally(failure);if(exitPlatform)Platform.exit();}
|
||||
|
||||
+88
@@ -0,0 +1,88 @@
|
||||
package p.studio.ui.javafx2.window;
|
||||
|
||||
import javafx.animation.PauseTransition;
|
||||
import javafx.application.Platform;
|
||||
import javafx.beans.value.ChangeListener;
|
||||
import javafx.stage.*;
|
||||
import javafx.util.Duration;
|
||||
import p.studio.api.preferences.WindowGeometry;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Consumer;
|
||||
|
||||
/** FX snapshot and worker persistence. Width/height always describe the normal window. */
|
||||
final class WindowGeometryBinding implements AutoCloseable {
|
||||
private final Stage stage;
|
||||
private final Executor worker;
|
||||
private final Consumer<WindowGeometry> save;
|
||||
private final Consumer<Throwable> failure;
|
||||
private final PauseTransition settle = new PauseTransition(Duration.millis(220));
|
||||
private final PauseTransition activation = new PauseTransition(Duration.millis(250));
|
||||
private WindowGeometry normal;
|
||||
private boolean restoring, closed, restoreNormal;
|
||||
private javafx.event.EventHandler<WindowEvent> shown;
|
||||
private final ChangeListener<Number> geometryListener = (o,a,b) -> changed();
|
||||
private final ChangeListener<Boolean> maximizeListener = (o,a,b) -> {
|
||||
if(!restoring)restoreNormal=!b;
|
||||
changed();
|
||||
};
|
||||
WindowGeometryBinding(Stage stage, WindowGeometry saved, double defaultWidth,double defaultHeight,
|
||||
Executor worker,Consumer<WindowGeometry> save,Consumer<Throwable> failure) {
|
||||
this.stage=stage;this.worker=worker;this.save=save;this.failure=failure;
|
||||
normal=WindowPlacement.fit(saved,Screen.getScreens().stream().map(Screen::getVisualBounds).toList(),
|
||||
stage.getMinWidth(),stage.getMinHeight(),defaultWidth,defaultHeight);
|
||||
restoring=true;stage.setMaximized(false);
|
||||
var screen=Screen.getScreens().stream().filter(s->s.getVisualBounds().contains(normal.x(),normal.y())).findFirst().orElse(Screen.getPrimary());
|
||||
stage.setMinWidth(Math.min(stage.getMinWidth(),screen.getVisualBounds().getWidth()));
|
||||
stage.setMinHeight(Math.min(stage.getMinHeight(),screen.getVisualBounds().getHeight()));
|
||||
applyNormal();stage.setMaximized(normal.maximized());
|
||||
stage.xProperty().addListener(geometryListener);stage.yProperty().addListener(geometryListener);
|
||||
stage.widthProperty().addListener(geometryListener);stage.heightProperty().addListener(geometryListener);
|
||||
stage.maximizedProperty().addListener(maximizeListener);
|
||||
settle.setOnFinished(e -> {
|
||||
if(restoreNormal&&!stage.isMaximized()){
|
||||
restoring=true;applyNormal();restoring=false;restoreNormal=false;
|
||||
}
|
||||
snapshot();
|
||||
});
|
||||
// Native show/geometry notifications can briefly report an unmaximized window.
|
||||
// Do not treat those acknowledgements as a user request to restore normal bounds.
|
||||
activation.setOnFinished(e->{if(!closed){restoring=false;snapshot();}});
|
||||
if(stage.isShowing())activation.play();
|
||||
else {shown=new javafx.event.EventHandler<WindowEvent>(){
|
||||
@Override public void handle(WindowEvent event){
|
||||
stage.removeEventHandler(WindowEvent.WINDOW_SHOWN,this);
|
||||
if(normal.maximized())stage.setMaximized(true);
|
||||
activation.play();
|
||||
}
|
||||
};stage.addEventHandler(WindowEvent.WINDOW_SHOWN,shown);}
|
||||
}
|
||||
private void applyNormal() {
|
||||
stage.setX(normal.x());stage.setY(normal.y());stage.setWidth(normal.width());stage.setHeight(normal.height());
|
||||
}
|
||||
private void changed() { if (!closed && !restoring && stage.isShowing()) settle.playFromStart(); }
|
||||
private void snapshot() {
|
||||
if (restoring || !stage.isShowing() || stage.isIconified()) return;
|
||||
if (!stage.isMaximized()) normal=new WindowGeometry(stage.getX(),stage.getY(),stage.getWidth(),stage.getHeight(),false);
|
||||
var value=new WindowGeometry(normal.x(),normal.y(),normal.width(),normal.height(),stage.isMaximized());
|
||||
try { worker.execute(() -> { try { save.accept(value); } catch (RuntimeException error) { failure.accept(error); } }); }
|
||||
catch (RuntimeException error) { failure.accept(error); }
|
||||
}
|
||||
void flush() {
|
||||
settle.stop();
|
||||
if(restoreNormal&&!stage.isMaximized()){
|
||||
restoring=true;applyNormal();restoring=false;restoreNormal=false;
|
||||
}
|
||||
if(restoring&&normal.maximized()){
|
||||
var value=normal;
|
||||
try{worker.execute(()->{try{save.accept(value);}catch(RuntimeException error){failure.accept(error);}});}
|
||||
catch(RuntimeException error){failure.accept(error);}
|
||||
}else {restoring=false;snapshot();}
|
||||
}
|
||||
@Override public void close() {
|
||||
if (closed) return;flush();closed=true;activation.stop();
|
||||
if(shown!=null)stage.removeEventHandler(WindowEvent.WINDOW_SHOWN,shown);
|
||||
stage.xProperty().removeListener(geometryListener);stage.yProperty().removeListener(geometryListener);
|
||||
stage.widthProperty().removeListener(geometryListener);stage.heightProperty().removeListener(geometryListener);
|
||||
stage.maximizedProperty().removeListener(maximizeListener);
|
||||
}
|
||||
}
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
package p.studio.ui.javafx2.window;
|
||||
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import p.studio.api.preferences.WindowGeometry;
|
||||
import java.util.*;
|
||||
|
||||
/** Pure placement calculation; negative coordinates on an attached display are valid. */
|
||||
final class WindowPlacement {
|
||||
private WindowPlacement() { }
|
||||
static WindowGeometry fit(WindowGeometry saved, List<Rectangle2D> screens, double minWidth, double minHeight,
|
||||
double defaultWidth, double defaultHeight) {
|
||||
Rectangle2D bounds = screens.getFirst();
|
||||
if (saved != null && Double.isFinite(saved.x()) && Double.isFinite(saved.y())) {
|
||||
double best = 0;
|
||||
for (var screen : screens) {
|
||||
double area = Math.max(0, Math.min(saved.x()+positive(saved.width(),defaultWidth),screen.getMaxX())-Math.max(saved.x(),screen.getMinX()))
|
||||
* Math.max(0,Math.min(saved.y()+positive(saved.height(),defaultHeight),screen.getMaxY())-Math.max(saved.y(),screen.getMinY()));
|
||||
if (area > best) { best = area; bounds = screen; }
|
||||
}
|
||||
}
|
||||
double width = Math.min(bounds.getWidth(),Math.max(minWidth,saved == null ? defaultWidth : positive(saved.width(),defaultWidth)));
|
||||
double height = Math.min(bounds.getHeight(),Math.max(minHeight,saved == null ? defaultHeight : positive(saved.height(),defaultHeight)));
|
||||
double x = saved == null || !Double.isFinite(saved.x()) ? bounds.getMinX()+(bounds.getWidth()-width)/2 : saved.x();
|
||||
double y = saved == null || !Double.isFinite(saved.y()) ? bounds.getMinY()+(bounds.getHeight()-height)/2 : saved.y();
|
||||
return new WindowGeometry(Math.max(bounds.getMinX(),Math.min(x,bounds.getMaxX()-width)),
|
||||
Math.max(bounds.getMinY(),Math.min(y,bounds.getMaxY()-height)),width,height,saved != null && saved.maximized());
|
||||
}
|
||||
private static double positive(double value,double fallback) { return Double.isFinite(value) && value > 0 ? value : fallback; }
|
||||
}
|
||||
+1
@@ -23,6 +23,7 @@ public final class WindowResources implements AutoCloseable {
|
||||
fonts=FontResources.load(System.err::println);messages=Messages.load(System.err::println);
|
||||
}
|
||||
public AppearanceContext context(){return new AppearanceContext(initial,messages,fonts,persistence::changed);}
|
||||
public AppearanceContext draft(AppearanceContext parent){return new AppearanceContext(parent.settings(),messages,fonts,value -> { });}
|
||||
public AppearanceContext child(AppearanceContext parent){
|
||||
var child=new AppearanceContext(parent.settings(),messages,fonts,parent::update);
|
||||
javafx.beans.value.ChangeListener<PresentationSettings> listener=(o,a,b)->child.update(b);
|
||||
|
||||
+28
@@ -97,3 +97,31 @@ fonts.title=TEXT COMPARISON
|
||||
fonts.input=Text to compare
|
||||
fonts.sample=Creation starts with an idea. Organize your scenes, adjust the characters and bring the adventure to life. Action, music and imagination: you choose the next step.
|
||||
fonts.licenses=Departure Mono and Roboto Mono · SIL Open Font License 1.1 · Full notices are bundled in the fonts resource directory.
|
||||
|
||||
menu.studio=Prometeu Studio
|
||||
menu.project=Project
|
||||
preferences.title=Studio preferences…
|
||||
preferences.appearance=Appearance
|
||||
preferences.runtime=Default runtime installation
|
||||
project.settings.title=Project settings…
|
||||
project.execution=Execution
|
||||
project.saving=Saving
|
||||
project.runtime.inherit=Use Studio default runtime
|
||||
project.runtime.global=Studio default: {0}
|
||||
project.runtime.override=Project override: {0}
|
||||
project.disposable.temporary=Disposable mode applies only while this project is open.
|
||||
settings.unset=Not configured
|
||||
settings.apply=Apply
|
||||
settings.cancel=Cancel
|
||||
settings.open=Open settings
|
||||
settings.open.preferences=Open Studio preferences
|
||||
settings.open.project=Open project settings
|
||||
gameplay.title=Gameplay
|
||||
play.disposable.short=Disposable save
|
||||
play.scale.manual=Manual scale
|
||||
|
||||
play.scale.value={0,number,0.#}% · {1,number,0.##}×
|
||||
play.scale.waiting=Waiting for image
|
||||
|
||||
gameplay.footer=Gameplay · {0}
|
||||
gameplay.footer.waiting=Gameplay · Waiting for image
|
||||
|
||||
+28
@@ -97,3 +97,31 @@ fonts.title=COMPARAÇÃO DE TEXTO
|
||||
fonts.input=Texto para comparar
|
||||
fonts.sample=A criação começa com uma ideia. Organize suas cenas, ajuste os personagens e dê vida à aventura. Ação, música e imaginação: você escolhe o próximo passo.
|
||||
fonts.licenses=Departure Mono e Roboto Mono · SIL Open Font License 1.1 · Avisos completos incluídos no diretório de recursos de fontes.
|
||||
|
||||
menu.studio=Prometeu Studio
|
||||
menu.project=Projeto
|
||||
preferences.title=Preferências do Studio…
|
||||
preferences.appearance=Aparência
|
||||
preferences.runtime=Instalação padrão do runtime
|
||||
project.settings.title=Configurações do projeto…
|
||||
project.execution=Execução
|
||||
project.saving=Salvamento
|
||||
project.runtime.inherit=Usar runtime padrão do Studio
|
||||
project.runtime.global=Padrão do Studio: {0}
|
||||
project.runtime.override=Específico do projeto: {0}
|
||||
project.disposable.temporary=O modo descartável vale somente enquanto este projeto estiver aberto.
|
||||
settings.unset=Não configurado
|
||||
settings.apply=Aplicar
|
||||
settings.cancel=Cancelar
|
||||
settings.open=Abrir configurações
|
||||
settings.open.preferences=Abrir preferências do Studio
|
||||
settings.open.project=Abrir configurações do projeto
|
||||
gameplay.title=Gameplay
|
||||
play.disposable.short=Save descartável
|
||||
play.scale.manual=Escala manual
|
||||
|
||||
play.scale.value={0,number,0.#}% · {1,number,0.##}×
|
||||
play.scale.waiting=Aguardando imagem
|
||||
|
||||
gameplay.footer=Gameplay · {0}
|
||||
gameplay.footer.waiting=Gameplay · Aguardando imagem
|
||||
|
||||
+40
-1
@@ -23,6 +23,7 @@
|
||||
-fx-background-color: -studio-border, -studio-highlight, -studio-shadow, -studio-workspace;
|
||||
-fx-background-insets: 0, 3, 3 6 6 3, 6;
|
||||
}
|
||||
.studio-window-panel { -fx-padding: 18; }
|
||||
.studio-shell { -fx-padding: 0 0 18 0; }
|
||||
.studio-shell > .workspace { -fx-border-insets: 18; }
|
||||
.studio-button, .studio-toggle {
|
||||
@@ -41,7 +42,7 @@
|
||||
.studio-button.primary:hover { -fx-background-color: -studio-border, -studio-on-accent, derive(-studio-accent, 40%), derive(-studio-accent, 8%); }
|
||||
.studio-button:armed, .studio-toggle:armed { -fx-background-insets: 0, 3, 6 3 3 6, 6; }
|
||||
.studio-button:disabled, .studio-toggle:disabled { -fx-opacity: .45; -fx-cursor: default; }
|
||||
.studio-button:focused, .studio-toggle:focused { -fx-border-color: -studio-focus; -fx-border-width: 2; -fx-border-insets: -4; }
|
||||
.studio-button:focused, .studio-toggle:focused { -fx-border-color: -studio-focus; -fx-border-width: 2; -fx-border-insets: 1; }
|
||||
.studio-field, .studio-select {
|
||||
-fx-background-color: -studio-border, -studio-shadow, -studio-field;
|
||||
-fx-background-insets: 0, 3, 5;
|
||||
@@ -76,3 +77,41 @@
|
||||
.studio-root .scroll-pane, .studio-root .scroll-pane > .viewport { -fx-background-color: -studio-background; }
|
||||
.studio-root .scroll-bar { -fx-background-color: -studio-background; }
|
||||
.studio-root .scroll-bar .thumb { -fx-background-color: -studio-border; -fx-background-radius: 0; }
|
||||
|
||||
.studio-project-shell { -fx-padding: 0; }
|
||||
.studio-execution-bar { -fx-padding: 6 12; -fx-background-color: -studio-surface; }
|
||||
.studio-navigation { -fx-background-color: -studio-surface; -fx-padding: 0; }
|
||||
.studio-navigation .menu { -fx-padding: .45em .65em; }
|
||||
.studio-navigation .menu .label { -fx-text-fill: -studio-text; }
|
||||
.studio-navigation .menu:hover, .studio-navigation .menu:showing { -fx-background-color: -studio-field; }
|
||||
.studio-information-strip { -fx-background-color: -studio-surface; -fx-padding: 4 14; }
|
||||
.studio-header { -fx-border-color: -studio-border; -fx-border-width: 1 0 1 0; }
|
||||
.studio-footer { -fx-border-color: -studio-border; -fx-border-width: 1 0 0 0; -fx-text-fill: -studio-muted; }
|
||||
.studio-tabs > .tab-header-area { -fx-padding: 0; }
|
||||
.studio-tabs > .tab-header-area > .tab-header-background { -fx-background-color: -studio-surface; }
|
||||
.studio-tabs > .tab-content-area { -fx-background-color: -studio-workspace; -fx-padding: 2; }
|
||||
.studio-tab-content-outline { -fx-fill: transparent; -fx-stroke: -studio-accent; -fx-stroke-width: 2; }
|
||||
.studio-gameplay-split { -fx-background-color: transparent; -fx-padding: 0; }
|
||||
.studio-gameplay-split:vertical > .split-pane-divider {
|
||||
/* The native skin uses preferred width as divider thickness in both orientations. */
|
||||
-fx-background-color: -studio-border; -fx-padding: 0 4;
|
||||
-fx-pref-width: 8; -fx-cursor: v-resize;
|
||||
}
|
||||
.studio-gameplay-split > .split-pane-divider:hover { -fx-background-color: -studio-accent; }
|
||||
.studio-gameplay-split > .split-pane-divider > .vertical-grabber { -fx-background-color: -studio-highlight; -fx-padding: 1 14; }
|
||||
.studio-tabs > .tab-header-area > .headers-region > .tab {
|
||||
-fx-background-color: -studio-border, -studio-surface;
|
||||
-fx-background-insets: 0, 2 2 0 2;
|
||||
-fx-background-radius: 0; -fx-padding: .4em .9em; -fx-border-width: 0;
|
||||
}
|
||||
.studio-tabs > .tab-header-area > .headers-region > .tab:hover {
|
||||
-fx-background-color: -studio-border, derive(-studio-surface, 12%);
|
||||
}
|
||||
.studio-tabs > .tab-header-area > .headers-region > .tab:selected {
|
||||
-fx-background-color: -studio-accent, -studio-workspace;
|
||||
}
|
||||
.studio-tabs > .tab-header-area > .headers-region > .tab:disabled { -fx-opacity: .45; }
|
||||
.studio-tabs .tab-label { -fx-text-fill: -studio-text; }
|
||||
.studio-tabs:focused > .tab-header-area > .headers-region > .tab:selected .focus-indicator {
|
||||
-fx-border-color: -studio-focus; -fx-border-width: 1; -fx-border-insets: 0; -fx-border-radius: 0;
|
||||
}
|
||||
|
||||
+19
@@ -0,0 +1,19 @@
|
||||
package p.studio.ui.javafx2.play;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class ViewportTransformTest {
|
||||
@Test void fitExpandsOrShrinksUniformlyAndWaitsForFrameDimensions(){
|
||||
assertEquals(1.5,ViewportTransform.fit(640,360,1100,540));
|
||||
assertEquals(.5,ViewportTransform.fit(640,360,320,500));
|
||||
assertEquals(0,ViewportTransform.fit(0,0,1000,600));
|
||||
}
|
||||
@Test void fractionalInputRejectsMarginsAndRightEdgeRatherThanClamping(){
|
||||
assertEquals(320,ViewportTransform.coordinate(480,960,640));
|
||||
assertEquals(639,ViewportTransform.coordinate(959.9,960,640));
|
||||
assertEquals(-1,ViewportTransform.coordinate(-.01,960,640));
|
||||
assertEquals(-1,ViewportTransform.coordinate(960,960,640));
|
||||
assertEquals(-1,ViewportTransform.coordinate(Double.NaN,960,640));
|
||||
}
|
||||
}
|
||||
+25
@@ -0,0 +1,25 @@
|
||||
package p.studio.ui.javafx2.window;
|
||||
|
||||
import javafx.geometry.Rectangle2D;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import p.studio.api.preferences.WindowGeometry;
|
||||
import java.util.List;
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
|
||||
class WindowPlacementTest {
|
||||
@Test void preservesNegativeMonitorAndUsesItsSizeInsteadOfPrimary() {
|
||||
var screens=List.of(new Rectangle2D(0,30,1280,700),new Rectangle2D(-2560,-1440,2560,1440));
|
||||
var result=WindowPlacement.fit(new WindowGeometry(-2400,-1300,2000,1100,true),screens,680,480,1200,850);
|
||||
assertEquals(2000,result.width());assertEquals(-2400,result.x());assertTrue(result.maximized());
|
||||
}
|
||||
@Test void removedMonitorAndTinyScreenKeepWholeWindowReachable() {
|
||||
var result=WindowPlacement.fit(new WindowGeometry(-2400,-1300,2000,1100,false),
|
||||
List.of(new Rectangle2D(0,20,640,400)),680,480,1200,850);
|
||||
assertEquals(new WindowGeometry(0,20,640,400,false),result);
|
||||
}
|
||||
@Test void invalidDimensionsAndCoordinatesUseSafeDefaults() {
|
||||
var result=WindowPlacement.fit(new WindowGeometry(Double.NaN,Double.POSITIVE_INFINITY,-2,Double.NaN,false),
|
||||
List.of(new Rectangle2D(0,30,1920,1000)),680,480,1200,850);
|
||||
assertTrue(Double.isFinite(result.x()));assertTrue(result.y()>=30);assertEquals(1200,result.width());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user