mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-22 10:43:57 -04:00
Code cleaup.
This commit is contained in:
parent
bdd105cb1b
commit
91c897dab8
@ -68,19 +68,9 @@ public final class TerracottaManager {
|
|||||||
LOG.warning("Terracotta hasn't support your OS: " + org.jackhuang.hmcl.util.platform.Platform.SYSTEM_PLATFORM);
|
LOG.warning("Terracotta hasn't support your OS: " + org.jackhuang.hmcl.util.platform.Platform.SYSTEM_PLATFORM);
|
||||||
} else {
|
} else {
|
||||||
switch (TerracottaMetadata.PROVIDER.status()) {
|
switch (TerracottaMetadata.PROVIDER.status()) {
|
||||||
case NOT_EXIST: {
|
case NOT_EXIST -> setState(new TerracottaState.Uninitialized(false));
|
||||||
setState(new TerracottaState.Uninitialized(false));
|
case LEGACY_VERSION -> setState(new TerracottaState.Uninitialized(true));
|
||||||
break;
|
case READY -> launch(setState(new TerracottaState.Launching()));
|
||||||
}
|
|
||||||
case LEGACY_VERSION: {
|
|
||||||
setState(new TerracottaState.Uninitialized(true));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case READY: {
|
|
||||||
TerracottaState.Launching launching = new TerracottaState.Launching();
|
|
||||||
setState(launching);
|
|
||||||
launch(launching);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).whenComplete(exception -> {
|
}).whenComplete(exception -> {
|
||||||
@ -110,7 +100,7 @@ public final class TerracottaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
int port = ((TerracottaState.PortSpecific) state).port;
|
int port = ((TerracottaState.PortSpecific) state).port;
|
||||||
int index = state instanceof TerracottaState.Ready ? ((TerracottaState.Ready) state).index : Integer.MIN_VALUE;
|
int index = state instanceof TerracottaState.Ready ready ? ready.index : Integer.MIN_VALUE;
|
||||||
|
|
||||||
TerracottaState next;
|
TerracottaState next;
|
||||||
try {
|
try {
|
||||||
@ -218,21 +208,14 @@ public final class TerracottaManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
switch (Objects.requireNonNull(TerracottaMetadata.PROVIDER).status()) {
|
return switch (Objects.requireNonNull(TerracottaMetadata.PROVIDER).status()) {
|
||||||
case NOT_EXIST:
|
case NOT_EXIST, LEGACY_VERSION -> install(file);
|
||||||
case LEGACY_VERSION: {
|
case READY -> {
|
||||||
return install(file);
|
TerracottaState.Launching launching = setState(new TerracottaState.Launching());
|
||||||
}
|
|
||||||
case READY: {
|
|
||||||
TerracottaState.Launching launching = new TerracottaState.Launching();
|
|
||||||
setState(launching);
|
|
||||||
launch(launching);
|
launch(launching);
|
||||||
return launching;
|
yield launching;
|
||||||
}
|
}
|
||||||
default: {
|
};
|
||||||
throw new AssertionError();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NullPointerException | IOException e) {
|
} catch (NullPointerException | IOException e) {
|
||||||
LOG.warning("Cannot determine Terracotta state.", e);
|
LOG.warning("Cannot determine Terracotta state.", e);
|
||||||
return setState(new TerracottaState.Fatal(TerracottaState.Fatal.Type.UNKNOWN));
|
return setState(new TerracottaState.Fatal(TerracottaState.Fatal.Type.UNKNOWN));
|
||||||
@ -274,8 +257,8 @@ public final class TerracottaManager {
|
|||||||
|
|
||||||
public static TerracottaState.Waiting setWaiting() {
|
public static TerracottaState.Waiting setWaiting() {
|
||||||
TerracottaState state = STATE_V.get();
|
TerracottaState state = STATE_V.get();
|
||||||
if (state instanceof TerracottaState.PortSpecific) {
|
if (state instanceof TerracottaState.PortSpecific portSpecific) {
|
||||||
new GetTask(URI.create(String.format("http://127.0.0.1:%d/state/ide", ((TerracottaState.PortSpecific) state).port)))
|
new GetTask(URI.create(String.format("http://127.0.0.1:%d/state/ide", portSpecific.port)))
|
||||||
.setSignificance(Task.TaskSignificance.MINOR)
|
.setSignificance(Task.TaskSignificance.MINOR)
|
||||||
.start();
|
.start();
|
||||||
return new TerracottaState.Waiting(-1, -1, null);
|
return new TerracottaState.Waiting(-1, -1, null);
|
||||||
@ -290,9 +273,9 @@ public final class TerracottaManager {
|
|||||||
|
|
||||||
public static TerracottaState.HostScanning setScanning() {
|
public static TerracottaState.HostScanning setScanning() {
|
||||||
TerracottaState state = STATE_V.get();
|
TerracottaState state = STATE_V.get();
|
||||||
if (state instanceof TerracottaState.PortSpecific) {
|
if (state instanceof TerracottaState.PortSpecific portSpecific) {
|
||||||
new GetTask(NetworkUtils.toURI(String.format(
|
new GetTask(NetworkUtils.toURI(String.format(
|
||||||
"http://127.0.0.1:%d/state/scanning?player=%s", ((TerracottaState.PortSpecific) state).port, getPlayerName()))
|
"http://127.0.0.1:%d/state/scanning?player=%s", portSpecific.port, getPlayerName()))
|
||||||
).setSignificance(Task.TaskSignificance.MINOR).start();
|
).setSignificance(Task.TaskSignificance.MINOR).start();
|
||||||
|
|
||||||
return new TerracottaState.HostScanning(-1, -1, null);
|
return new TerracottaState.HostScanning(-1, -1, null);
|
||||||
@ -302,9 +285,9 @@ public final class TerracottaManager {
|
|||||||
|
|
||||||
public static Task<TerracottaState.GuestStarting> setGuesting(String room) {
|
public static Task<TerracottaState.GuestStarting> setGuesting(String room) {
|
||||||
TerracottaState state = STATE_V.get();
|
TerracottaState state = STATE_V.get();
|
||||||
if (state instanceof TerracottaState.PortSpecific) {
|
if (state instanceof TerracottaState.PortSpecific portSpecific) {
|
||||||
return new GetTask(NetworkUtils.toURI(String.format(
|
return new GetTask(NetworkUtils.toURI(String.format(
|
||||||
"http://127.0.0.1:%d/state/guesting?room=%s&player=%s", ((TerracottaState.PortSpecific) state).port, room, getPlayerName()
|
"http://127.0.0.1:%d/state/guesting?room=%s&player=%s", portSpecific.port, room, getPlayerName()
|
||||||
)))
|
)))
|
||||||
.setSignificance(Task.TaskSignificance.MINOR)
|
.setSignificance(Task.TaskSignificance.MINOR)
|
||||||
.thenSupplyAsync(() -> new TerracottaState.GuestStarting(-1, -1, null))
|
.thenSupplyAsync(() -> new TerracottaState.GuestStarting(-1, -1, null))
|
||||||
|
@ -129,7 +129,7 @@ final class ComponentListCell extends StackPane {
|
|||||||
groupNode.getChildren().add(headerRippler);
|
groupNode.getChildren().add(headerRippler);
|
||||||
|
|
||||||
VBox container = new VBox();
|
VBox container = new VBox();
|
||||||
boolean hasPadding = !content.getProperties().containsKey("ComponentSubList.noPadding");
|
boolean hasPadding = !(list instanceof ComponentSublist subList) || subList.hasMargin();
|
||||||
if (hasPadding) {
|
if (hasPadding) {
|
||||||
container.setPadding(new Insets(8, 16, 10, 16));
|
container.setPadding(new Insets(8, 16, 10, 16));
|
||||||
}
|
}
|
||||||
@ -151,7 +151,8 @@ final class ComponentListCell extends StackPane {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Platform.runLater(() -> {
|
Platform.runLater(() -> {
|
||||||
double newAnimatedHeight = (list.prefHeight(list.getWidth()) + (hasPadding ? 8 + 10 : 0)) * (expanded ? 1 : -1);
|
// FIXME: ComponentSubList without padding must have a 4 pixel padding for displaying a border radius.
|
||||||
|
double newAnimatedHeight = (list.prefHeight(list.getWidth()) + (hasPadding ? 8 + 10 : 4)) * (expanded ? 1 : -1);
|
||||||
double newHeight = expanded ? getHeight() + newAnimatedHeight : prefHeight(list.getWidth());
|
double newHeight = expanded ? getHeight() + newAnimatedHeight : prefHeight(list.getWidth());
|
||||||
double contentHeight = expanded ? newAnimatedHeight : 0;
|
double contentHeight = expanded ? newAnimatedHeight : 0;
|
||||||
|
|
||||||
|
@ -18,7 +18,9 @@
|
|||||||
package org.jackhuang.hmcl.ui.construct;
|
package org.jackhuang.hmcl.ui.construct;
|
||||||
|
|
||||||
import javafx.beans.DefaultProperty;
|
import javafx.beans.DefaultProperty;
|
||||||
|
import javafx.beans.property.BooleanProperty;
|
||||||
import javafx.beans.property.ObjectProperty;
|
import javafx.beans.property.ObjectProperty;
|
||||||
|
import javafx.beans.property.SimpleBooleanProperty;
|
||||||
import javafx.beans.property.SimpleObjectProperty;
|
import javafx.beans.property.SimpleObjectProperty;
|
||||||
import javafx.scene.Node;
|
import javafx.scene.Node;
|
||||||
|
|
||||||
@ -27,6 +29,7 @@ public class ComponentSublist extends ComponentList {
|
|||||||
|
|
||||||
private final ObjectProperty<Node> headerLeft = new SimpleObjectProperty<>(this, "headerLeft");
|
private final ObjectProperty<Node> headerLeft = new SimpleObjectProperty<>(this, "headerLeft");
|
||||||
private final ObjectProperty<Node> headerRight = new SimpleObjectProperty<>(this, "headerRight");
|
private final ObjectProperty<Node> headerRight = new SimpleObjectProperty<>(this, "headerRight");
|
||||||
|
private final BooleanProperty margin = new SimpleBooleanProperty(this, "padding", true);
|
||||||
|
|
||||||
public ComponentSublist() {
|
public ComponentSublist() {
|
||||||
super();
|
super();
|
||||||
@ -55,4 +58,16 @@ public class ComponentSublist extends ComponentList {
|
|||||||
public void setHeaderRight(Node headerRight) {
|
public void setHeaderRight(Node headerRight) {
|
||||||
this.headerRight.set(headerRight);
|
this.headerRight.set(headerRight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean hasMargin() {
|
||||||
|
return margin.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public BooleanProperty marginProperty() {
|
||||||
|
return margin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMargin(boolean margin) {
|
||||||
|
this.margin.set(margin);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -477,7 +477,7 @@ public class TerracottaControllerPage extends StackPane {
|
|||||||
|
|
||||||
private ComponentList getThirdPartyDownloadNodes() {
|
private ComponentList getThirdPartyDownloadNodes() {
|
||||||
ComponentSublist locals = new ComponentSublist();
|
ComponentSublist locals = new ComponentSublist();
|
||||||
locals.getProperties().put("ComponentSubList.noPadding", true);
|
locals.setMargin(false);
|
||||||
|
|
||||||
LineButton header = LineButton.of(false);
|
LineButton header = LineButton.of(false);
|
||||||
header.setLeftImage(FXUtils.newBuiltinImage("/assets/img/terracotta.png"));
|
header.setLeftImage(FXUtils.newBuiltinImage("/assets/img/terracotta.png"));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user