kopia lustrzana https://github.com/jameshball/osci-render
Save font family and font style with project
rodzic
cf56c510ea
commit
4464d97d6d
|
@ -30,6 +30,7 @@ import java.util.concurrent.*;
|
|||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
import java.util.logging.Level;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import javafx.fxml.FXML;
|
||||
import javafx.fxml.Initializable;
|
||||
|
@ -462,12 +463,12 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
} else {
|
||||
fontFamilyListView.getSelectionModel().select(installedFonts[0]);
|
||||
}
|
||||
fontFamilyListView.getSelectionModel().selectedItemProperty().addListener((e, old, family) -> updateFileData(openFiles.get(currentFrameSource), frameSourcePaths.get(currentFrameSource)));
|
||||
fontFamilyListView.getSelectionModel().selectedItemProperty().addListener((e, old, family) -> updateTextFiles());
|
||||
|
||||
|
||||
fontStyleComboBox.setItems(FXCollections.observableList(Arrays.stream(FontStyle.values()).toList()));
|
||||
fontStyleComboBox.setValue(FontStyle.PLAIN);
|
||||
fontStyleComboBox.valueProperty().addListener((e, old, family) -> updateFileData(openFiles.get(currentFrameSource), frameSourcePaths.get(currentFrameSource)));
|
||||
fontStyleComboBox.valueProperty().addListener((e, old, family) -> updateTextFiles());
|
||||
|
||||
sliderMinTextField.focusedProperty().addListener((e, old, focused) -> {
|
||||
String text = sliderMinTextField.getText();
|
||||
|
@ -529,6 +530,15 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
brightnessSlider.valueProperty().addListener((e, old, brightness) -> audioPlayer.setBrightness(brightness.doubleValue()));
|
||||
}
|
||||
|
||||
private void updateTextFiles() {
|
||||
List<Integer> textFrameSources = frameSourcePaths.stream()
|
||||
.filter(path -> path.endsWith(".txt"))
|
||||
.map(path -> frameSourcePaths.indexOf(path))
|
||||
.toList();
|
||||
|
||||
textFrameSources.forEach(i -> updateFileData(openFiles.get(i), frameSourcePaths.get(i), false));
|
||||
}
|
||||
|
||||
public void setLuaVariable(String variableName, Object value) {
|
||||
sampleParsers.forEach(sampleParser -> {
|
||||
if (sampleParser instanceof LuaParser luaParser) {
|
||||
|
@ -775,7 +785,7 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
Platform.runLater(() -> generalController.showMultiFileTooltip(frameSources.size() > 1));
|
||||
}
|
||||
|
||||
public void updateFileData(byte[] file, String name) {
|
||||
public void updateFileData(byte[] file, String name, boolean updateUnsavedFiles) {
|
||||
int index = frameSourcePaths.indexOf(name);
|
||||
if (index == -1) {
|
||||
throw new RuntimeException("Can't find open file with name: " + name);
|
||||
|
@ -798,8 +808,10 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
sampleParsers.set(index, null);
|
||||
}
|
||||
|
||||
unsavedFileNames.add(name);
|
||||
setUnsavedFileWarning();
|
||||
if (updateUnsavedFiles) {
|
||||
unsavedFileNames.add(name);
|
||||
setUnsavedFileWarning();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
logger.log(Level.SEVERE, e.getMessage(), e);
|
||||
}
|
||||
|
@ -1192,6 +1204,14 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
frameSource.appendChild(document.createTextNode(String.valueOf(currentFrameSource)));
|
||||
root.appendChild(frameSource);
|
||||
|
||||
Element fontFamily = document.createElement("fontFamily");
|
||||
fontFamily.appendChild(document.createTextNode(fontFamilyListView.getSelectionModel().getSelectedItem()));
|
||||
root.appendChild(fontFamily);
|
||||
|
||||
Element fontStyle = document.createElement("fontStyle");
|
||||
fontStyle.appendChild(document.createTextNode(String.valueOf(fontStyleComboBox.getValue().style)));
|
||||
root.appendChild(fontStyle);
|
||||
|
||||
TransformerFactory transformerFactory = TransformerFactory.newInstance();
|
||||
Transformer transformer = transformerFactory.newTransformer();
|
||||
DOMSource domSource = new DOMSource(document);
|
||||
|
@ -1369,6 +1389,16 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
updateFiles(files, fileNames, 0);
|
||||
}
|
||||
|
||||
Element fontFamily = (Element) root.getElementsByTagName("fontFamily").item(0);
|
||||
if (fontFamily != null) {
|
||||
fontFamilyListView.getSelectionModel().select(fontFamily.getTextContent());
|
||||
}
|
||||
|
||||
Element fontStyle = (Element) root.getElementsByTagName("fontStyle").item(0);
|
||||
if (fontStyle != null) {
|
||||
fontStyleComboBox.setValue(FontStyle.getStyle(Integer.parseInt(fontStyle.getTextContent())));
|
||||
}
|
||||
|
||||
luaController.updateLuaVariables();
|
||||
|
||||
openProjectPath = projectFileName;
|
||||
|
@ -1443,7 +1473,7 @@ public class MainController implements Initializable, FrequencyListener, MidiLis
|
|||
} else if (SvgParser.isSvgFile(name)) {
|
||||
mimeType = "text/html";
|
||||
}
|
||||
launchCodeEditor(code, frameSourcePaths.get(currentFrameSource), mimeType, this::updateFileData);
|
||||
launchCodeEditor(code, frameSourcePaths.get(currentFrameSource), mimeType, (data, fileName) -> updateFileData(data, fileName, true));
|
||||
}
|
||||
|
||||
private void updateTitle(String message, String projectName) {
|
||||
|
|
|
@ -32,6 +32,9 @@ public class LuaSampleSource implements FrameSource<Vector2> {
|
|||
@Override
|
||||
public Vector2 next() {
|
||||
LuaValue result = executor.execute();
|
||||
if (result.isnil()) {
|
||||
return new Vector2();
|
||||
}
|
||||
return new Vector2(result.get(1).checkdouble(), result.get(2).checkdouble());
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,9 @@
|
|||
package sh.ball.parser.txt;
|
||||
|
||||
import java.awt.*;
|
||||
import java.util.logging.Level;
|
||||
|
||||
import static sh.ball.gui.Gui.logger;
|
||||
|
||||
public enum FontStyle {
|
||||
PLAIN(Font.PLAIN),
|
||||
|
@ -13,6 +16,24 @@ public enum FontStyle {
|
|||
this.style = style;
|
||||
}
|
||||
|
||||
public static FontStyle getStyle(int style) {
|
||||
switch (style) {
|
||||
case Font.PLAIN -> {
|
||||
return PLAIN;
|
||||
}
|
||||
case Font.BOLD -> {
|
||||
return BOLD;
|
||||
}
|
||||
case Font.ITALIC -> {
|
||||
return ITALIC;
|
||||
}
|
||||
default -> {
|
||||
logger.log(Level.WARNING, "Unknown font style: " + style);
|
||||
return PLAIN;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return name().substring(0, 1).toUpperCase() + name().substring(1).toLowerCase();
|
||||
|
|
Ładowanie…
Reference in New Issue