Add a button for deleting the game icon
This commit is contained in:
@@ -25,11 +25,10 @@ import static org.jackhuang.hmcl.util.i18n.I18n.i18n;
|
|||||||
public final class ImagePickerItem extends BorderPane {
|
public final class ImagePickerItem extends BorderPane {
|
||||||
|
|
||||||
private final ImageView imageView;
|
private final ImageView imageView;
|
||||||
private final JFXButton selectButton;
|
|
||||||
private final Label label;
|
|
||||||
|
|
||||||
private final StringProperty title = new SimpleStringProperty(this, "title");
|
private final StringProperty title = new SimpleStringProperty(this, "title");
|
||||||
private final ObjectProperty<EventHandler<? super MouseEvent>> onSelectButtonClicked = new SimpleObjectProperty<>(this, "onSelectButtonClicked");
|
private final ObjectProperty<EventHandler<? super MouseEvent>> onSelectButtonClicked = new SimpleObjectProperty<>(this, "onSelectButtonClicked");
|
||||||
|
private final ObjectProperty<EventHandler<? super MouseEvent>> onDeleteButtonClicked = new SimpleObjectProperty<>(this, "onDeleteButtonClicked");
|
||||||
private final ObjectProperty<Image> image = new SimpleObjectProperty<>(this, "image");
|
private final ObjectProperty<Image> image = new SimpleObjectProperty<>(this, "image");
|
||||||
|
|
||||||
public ImagePickerItem() {
|
public ImagePickerItem() {
|
||||||
@@ -37,21 +36,26 @@ public final class ImagePickerItem extends BorderPane {
|
|||||||
imageView.setSmooth(false);
|
imageView.setSmooth(false);
|
||||||
imageView.setPreserveRatio(true);
|
imageView.setPreserveRatio(true);
|
||||||
|
|
||||||
selectButton = new JFXButton();
|
JFXButton selectButton = new JFXButton();
|
||||||
selectButton.setGraphic(SVG.pencil(Theme.blackFillBinding(), 15, 15));
|
selectButton.setGraphic(SVG.pencil(Theme.blackFillBinding(), 15, 15));
|
||||||
selectButton.onMouseClickedProperty().bind(onSelectButtonClicked);
|
selectButton.onMouseClickedProperty().bind(onSelectButtonClicked);
|
||||||
selectButton.getStyleClass().add("toggle-icon4");
|
selectButton.getStyleClass().add("toggle-icon4");
|
||||||
|
|
||||||
|
JFXButton deleteButton = new JFXButton();
|
||||||
|
deleteButton.setGraphic(SVG.close(Theme.blackFillBinding(), 15, 15));
|
||||||
|
deleteButton.onMouseClickedProperty().bind(onDeleteButtonClicked);
|
||||||
|
deleteButton.getStyleClass().add("toggle-icon4");
|
||||||
|
|
||||||
FXUtils.installTooltip(selectButton, i18n("button.edit"));
|
FXUtils.installTooltip(selectButton, i18n("button.edit"));
|
||||||
|
|
||||||
HBox hBox = new HBox();
|
HBox hBox = new HBox();
|
||||||
hBox.getChildren().setAll(imageView, selectButton);
|
hBox.getChildren().setAll(imageView, selectButton, deleteButton);
|
||||||
hBox.setAlignment(Pos.CENTER_RIGHT);
|
hBox.setAlignment(Pos.CENTER_RIGHT);
|
||||||
hBox.setSpacing(8);
|
hBox.setSpacing(8);
|
||||||
setRight(hBox);
|
setRight(hBox);
|
||||||
|
|
||||||
VBox vBox = new VBox();
|
VBox vBox = new VBox();
|
||||||
label = new Label();
|
Label label = new Label();
|
||||||
label.textProperty().bind(title);
|
label.textProperty().bind(title);
|
||||||
vBox.getChildren().setAll(label);
|
vBox.getChildren().setAll(label);
|
||||||
vBox.setAlignment(Pos.CENTER_LEFT);
|
vBox.setAlignment(Pos.CENTER_LEFT);
|
||||||
@@ -84,6 +88,18 @@ public final class ImagePickerItem extends BorderPane {
|
|||||||
this.onSelectButtonClicked.set(onSelectButtonClicked);
|
this.onSelectButtonClicked.set(onSelectButtonClicked);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EventHandler<? super MouseEvent> getOnDeleteButtonClicked() {
|
||||||
|
return onDeleteButtonClicked.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public ObjectProperty<EventHandler<? super MouseEvent>> onDeleteButtonClickedProperty() {
|
||||||
|
return onDeleteButtonClicked;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnDeleteButtonClicked(EventHandler<? super MouseEvent> onDeleteButtonClicked) {
|
||||||
|
this.onDeleteButtonClicked.set(onDeleteButtonClicked);
|
||||||
|
}
|
||||||
|
|
||||||
public Image getImage() {
|
public Image getImage() {
|
||||||
return image.get();
|
return image.get();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,6 @@ public final class ProfilePage extends StackPane implements DecoratorPage {
|
|||||||
@FXML private JFXTextField txtProfileName;
|
@FXML private JFXTextField txtProfileName;
|
||||||
@FXML private FileItem gameDir;
|
@FXML private FileItem gameDir;
|
||||||
@FXML private JFXButton btnSave;
|
@FXML private JFXButton btnSave;
|
||||||
@FXML private JFXButton btnDelete;
|
|
||||||
@FXML private JFXCheckBox toggleUseRelativePath;
|
@FXML private JFXCheckBox toggleUseRelativePath;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,9 +71,7 @@ public final class ProfilePage extends StackPane implements DecoratorPage {
|
|||||||
btnSave.setDisable(!txtProfileName.validate() || StringUtils.isBlank(getLocation()));
|
btnSave.setDisable(!txtProfileName.validate() || StringUtils.isBlank(getLocation()));
|
||||||
});
|
});
|
||||||
gameDir.convertToRelativePathProperty().bind(toggleUseRelativePath.selectedProperty());
|
gameDir.convertToRelativePathProperty().bind(toggleUseRelativePath.selectedProperty());
|
||||||
if (profile == null) {
|
if (profile != null) {
|
||||||
btnDelete.setVisible(false);
|
|
||||||
} else {
|
|
||||||
toggleUseRelativePath.setSelected(profile.isUseRelativePath());
|
toggleUseRelativePath.setSelected(profile.isUseRelativePath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -82,6 +82,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
@FXML private JFXTextField txtServerIP;
|
@FXML private JFXTextField txtServerIP;
|
||||||
@FXML private ComponentList advancedSettingsPane;
|
@FXML private ComponentList advancedSettingsPane;
|
||||||
@FXML private ComponentList componentList;
|
@FXML private ComponentList componentList;
|
||||||
|
@FXML private ComponentList iconPickerItemWrapper;
|
||||||
@FXML private JFXComboBox<?> cboLauncherVisibility;
|
@FXML private JFXComboBox<?> cboLauncherVisibility;
|
||||||
@FXML private JFXCheckBox chkFullscreen;
|
@FXML private JFXCheckBox chkFullscreen;
|
||||||
@FXML private Label lblPhysicalMemory;
|
@FXML private Label lblPhysicalMemory;
|
||||||
@@ -152,7 +153,7 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
this.versionId = versionId;
|
this.versionId = versionId;
|
||||||
|
|
||||||
if (versionId == null) {
|
if (versionId == null) {
|
||||||
componentList.getContent().remove(iconPickerItem);
|
rootPane.getChildren().remove(iconPickerItemWrapper);
|
||||||
rootPane.getChildren().remove(settingsTypePane);
|
rootPane.getChildren().remove(settingsTypePane);
|
||||||
chkEnableSpecificSettings.setSelected(true);
|
chkEnableSpecificSettings.setSelected(true);
|
||||||
}
|
}
|
||||||
@@ -283,6 +284,17 @@ public final class VersionSettingsPage extends StackPane implements DecoratorPag
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private void onDeleteIcon() {
|
||||||
|
if (versionId == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
File iconFile = profile.getRepository().getVersionIcon(versionId);
|
||||||
|
if (iconFile.exists())
|
||||||
|
iconFile.delete();
|
||||||
|
loadIcon();
|
||||||
|
}
|
||||||
|
|
||||||
private void loadIcon() {
|
private void loadIcon() {
|
||||||
if (versionId == null) {
|
if (versionId == null) {
|
||||||
iconPickerItem.setImage(new Image("/assets/img/grass.png"));
|
iconPickerItem.setImage(new Image("/assets/img/grass.png"));
|
||||||
|
|||||||
@@ -12,7 +12,13 @@
|
|||||||
xmlns:fx="http://javafx.com/fxml"
|
xmlns:fx="http://javafx.com/fxml"
|
||||||
type="StackPane">
|
type="StackPane">
|
||||||
<ScrollPane fx:id="scroll" fitToHeight="true" fitToWidth="true" vbarPolicy="ALWAYS">
|
<ScrollPane fx:id="scroll" fitToHeight="true" fitToWidth="true" vbarPolicy="ALWAYS">
|
||||||
<VBox fx:id="rootPane" style="-fx-padding: 20;" spacing="8">
|
<VBox fx:id="rootPane" style="-fx-padding: 20;" spacing="12">
|
||||||
|
|
||||||
|
<ComponentList fx:id="iconPickerItemWrapper">
|
||||||
|
<ImagePickerItem fx:id="iconPickerItem" title="%settings.icon" onSelectButtonClicked="#onExploreIcon" onDeleteButtonClicked="#onDeleteIcon">
|
||||||
|
<Image url="/assets/img/icon.png"/>
|
||||||
|
</ImagePickerItem>
|
||||||
|
</ComponentList>
|
||||||
|
|
||||||
<BorderPane fx:id="settingsTypePane">
|
<BorderPane fx:id="settingsTypePane">
|
||||||
<left>
|
<left>
|
||||||
@@ -27,10 +33,6 @@
|
|||||||
|
|
||||||
<ComponentList fx:id="componentList" depth="1">
|
<ComponentList fx:id="componentList" depth="1">
|
||||||
|
|
||||||
<ImagePickerItem fx:id="iconPickerItem" title="%settings.icon" onSelectButtonClicked="#onExploreIcon">
|
|
||||||
<Image url="/assets/img/icon.png"/>
|
|
||||||
</ImagePickerItem>
|
|
||||||
|
|
||||||
<MultiFileItem fx:id="javaItem" title="%settings.game.java_directory" chooserTitle="%settings.game.java_directory.choose"
|
<MultiFileItem fx:id="javaItem" title="%settings.game.java_directory" chooserTitle="%settings.game.java_directory.choose"
|
||||||
hasSubtitle="true" customText="%settings.custom" directory="false" />
|
hasSubtitle="true" customText="%settings.custom" directory="false" />
|
||||||
|
|
||||||
@@ -113,7 +115,7 @@
|
|||||||
</right>
|
</right>
|
||||||
</BorderPane>
|
</BorderPane>
|
||||||
</ComponentList>
|
</ComponentList>
|
||||||
<HBox alignment="CENTER_LEFT" style="-fx-padding: 12 0 4 0;">
|
<HBox alignment="CENTER_LEFT" style="-fx-padding: 8 0 0 0;">
|
||||||
<Label text="%settings.advanced" style="-fx-text-fill: #616161;" />
|
<Label text="%settings.advanced" style="-fx-text-fill: #616161;" />
|
||||||
</HBox>
|
</HBox>
|
||||||
<ComponentList fx:id="advancedSettingsPane" depth="1">
|
<ComponentList fx:id="advancedSettingsPane" depth="1">
|
||||||
|
|||||||
Reference in New Issue
Block a user