Skip to content

Commit

Permalink
Add New Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Mar 30, 2023
1 parent 01e962e commit c0c3c33
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 27 deletions.
18 changes: 16 additions & 2 deletions assets/UI/Homepage.fxml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<Label layoutX="10.0" layoutY="15.0" styleClass="config-group-title" text="模型选择"/>
<ImageView fx:id="selectedModelView" fitHeight="140.0" fitWidth="140.0" layoutX="15.0" layoutY="85.0"
pickOnBounds="true" preserveRatio="true"/>
<VBox layoutX="15.0" layoutY="205.0" prefHeight="140.0" prefWidth="140.0">
<VBox layoutX="15.0" layoutY="200.0" prefHeight="140.0" prefWidth="140.0">
<children>
<Label fx:id="selectedModelName" styleClass="Info-primary" text="Name"/>
<Label fx:id="selectedModelAppellation" styleClass="Info-secondary" text="Appellation"/>
Expand All @@ -121,6 +121,20 @@
</Label>
</children>
</VBox>
<HBox layoutX="10.0" layoutY="325.0" prefHeight="40.0" prefWidth="150.0">
<children>
<Label id="Info-filter-label" prefWidth="55.0" text="筛选" translateX="-10.0">
<graphic>
<AnchorPane prefHeight="10.0" prefWidth="0.0" translateX="5.0">
<children>
<SVGPath content="M1 0h22l-9 15.094v8.906l-4-3v-5.906z" scaleX="0.5" scaleY="0.5"/>
</children>
</AnchorPane>
</graphic>
</Label>
<JFXComboBox fx:id="searchModelFilter" id="Info-filter-box" prefWidth="95.0"/>
</children>
</HBox>
<Pane id="Search-models-bar" layoutX="15.0" layoutY="40.0" prefHeight="36.0" prefWidth="430.0">
<JFXTextField id="Search-models-input" fx:id="searchModelInput" layoutX="70.0" layoutY="7.0"
prefHeight="23.0" prefWidth="170.0"/>
Expand Down Expand Up @@ -204,7 +218,7 @@
<JFXListView id="Search-models-list" fx:id="searchModelList" layoutX="165.0" layoutY="85.0" prefHeight="265.0"
prefWidth="280.0"/>
<VBox id="Loading-failure-tip" fx:id="loadFailureTip" alignment="CENTER" layoutX="1.0" layoutY="85.0"
prefHeight="285.0" prefWidth="458.0" spacing="5.0">
prefHeight="285.0" prefWidth="458.0" spacing="5.0" visible="false">
<children>
<SVGPath
content="M11.5 23l-8.5-4.535v-3.953l5.4 3.122 3.1-3.406v8.772zm1-.001v-8.806l3.162 3.343 5.338-2.958v3.887l-8.5 4.534zm-10.339-10.125l-2.161-1.244 3-3.302-3-2.823 8.718-4.505 3.215 2.385 3.325-2.385 8.742 4.561-2.995 2.771 2.995 3.443-2.242 1.241v-.001l-5.903 3.27-3.348-3.541 7.416-3.962-7.922-4.372-7.923 4.372 7.422 3.937v.024l-3.297 3.622-5.203-3.008-.16-.092-.679-.393v.002z"
Expand Down
34 changes: 29 additions & 5 deletions assets/UI/Main.css
Original file line number Diff line number Diff line change
Expand Up @@ -237,16 +237,40 @@ Button:focused {
-fx-text-fill: #606060;
}

.Search-models-item-active .Search-models-label-primary {
.Search-models-list .Search-models-item-active .Search-models-label-primary {
-fx-font-size: 13px;
-fx-text-fill: #303030;
}

.Search-models-list .Search-models-item-active .Search-models-label-secondary {
-fx-font-size: 12px;
-fx-text-fill: #606060;
}

.Search-models-list:focused .Search-models-item-active .Search-models-label-primary {
-fx-font-size: 13px;
-fx-text-fill: #FFFFFF;
}

.Search-models-item-active .Search-models-label-secondary {
.Search-models-list:focused .Search-models-item-active .Search-models-label-secondary {
-fx-font-size: 12px;
-fx-text-fill: #FFFFFF;
}

#Info-filter-label {
-fx-font-size: 12px;
-fx-text-fill: #204880;
}

#Info-filter-label SVGPath {
-fx-fill: #204880;
}

#Info-filter-box {
-fx-font-size: 11px;
-fx-text-fill: #606060;
}

.Info-primary {
-fx-font-size: 16px;
-fx-text-fill: #202020;
Expand Down Expand Up @@ -333,13 +357,13 @@ Button:focused {
******************************************************************************/

.scroll-bar:vertical > .track-background, .scroll-bar:horizontal > .track-background {
-fx-background-color: #F1F1F1;
-fx-background-color: #F1F1F5;
-fx-background-insets: 0;
-fx-background-radius: 1px;
}

.scroll-bar:vertical > .thumb, .scroll-bar:horizontal > .thumb {
-fx-background-color: #BCBCBC;
-fx-background-color: #BCBCC2;
-fx-background-insets: 0;
-fx-background-radius: 2px;
}
Expand All @@ -358,7 +382,7 @@ Button:focused {
}

.scroll-bar > .increment-button > .increment-arrow, .scroll-bar > .decrement-button > .decrement-arrow {
-fx-background-color: #969696;
-fx-background-color: #9696A0;
}

/* Up Arrow */
Expand Down
77 changes: 57 additions & 20 deletions desktop/src/com/isharryh/arkpets/controllers/Homepage.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@
import com.isharryh.arkpets.ArkHomeFX;
import com.isharryh.arkpets.utils.*;
import com.isharryh.arkpets.utils.IOUtils.*;

import static com.isharryh.arkpets.utils.PopupUtils.*;

import com.alibaba.fastjson.JSONException;
import com.alibaba.fastjson.JSONObject;
import com.jfoenix.controls.*;
import org.apache.log4j.Level;

import javafx.animation.FadeTransition;
import javafx.application.Platform;
import javafx.collections.ListChangeListener;
import javafx.concurrent.ScheduledService;
Expand Down Expand Up @@ -48,6 +48,7 @@ public class Homepage {

private boolean isHttpsTrustAll = false;
private boolean isDelayTested = false;
private boolean isNoFilter = true;
public JavaProcess.UnexpectedExitCodeException lastLaunchFailed = null;

private final String urlApi = "https://arkpets.tfev.top/p/arkpets/client/api.php";
Expand Down Expand Up @@ -92,7 +93,9 @@ public class Homepage {
@FXML
private JFXTextField searchModelInput;
@FXML
private JFXListView searchModelList;
private JFXListView<JFXListCell<AssetCtrl>> searchModelList;
@FXML
private JFXComboBox<String> searchModelFilter;
@FXML
private Label selectedModelName;
@FXML
Expand Down Expand Up @@ -138,7 +141,6 @@ public class Homepage {
@FXML
private Label aboutVisitWebsite;

private AssetCtrl selectedModelAsset;
private ListCell<AssetCtrl> selectedModelItem;
private AssetCtrl[] foundModelAssets = {};
private JFXListCell[] foundModelItems = {};
Expand All @@ -158,6 +160,8 @@ public void initialize() {
initWrapper(1);
initModelSearch();
initModelManage();
initConfigBehavior();
initConfigDisplay();
initConfigAdvanced();
initAbout();
initLaunchingStatusListener();
Expand Down Expand Up @@ -191,11 +195,23 @@ private void initMenuBtn(Button $menuBtn, int $boundIdx) {
}

private void initWrapper(int $activeIdx) {
wrapper1.setVisible(wrapper1.getId().contains(String.valueOf($activeIdx)));
wrapper2.setVisible(wrapper2.getId().contains(String.valueOf($activeIdx)));
wrapper3.setVisible(wrapper3.getId().contains(String.valueOf($activeIdx)));
initConfigBehavior();
initConfigDisplay();
Duration duration = new Duration(500);
List<Node> wrappers = Arrays.asList(null, wrapper1, wrapper2, wrapper3);
for (short i = 0; i < wrappers.size(); i++) {
if (wrappers.get(i) != null) {
FadeTransition fadeT = new FadeTransition(duration, wrappers.get(i));
if ($activeIdx == i) {
// Show
wrappers.get(i).setVisible(true);
fadeT.setFromValue(0.025);
fadeT.setToValue(1);
fadeT.playFromStart();
} else {
// Hide
wrappers.get(i).setVisible(false);
}
}
}
}

private void initModelSearch() {
Expand All @@ -205,9 +221,31 @@ private void initModelSearch() {
dealModelSearch(searchModelInput.getText());
});
searchModelConfirm.setOnAction(e -> dealModelSearch(searchModelInput.getText()));
searchModelReset.setOnAction(e -> dealModelSearch(""));
searchModelReset.setOnAction(e -> {
searchModelInput.setText("");
searchModelInput.requestFocus();
searchModelFilter.getSelectionModel().select(0);
dealModelSearch("");
});
searchModelRandom.setOnAction(e -> dealModelRandom());
searchModelReload.setOnAction(e -> dealModelReload());

searchModelFilter.getItems().setAll("全部");
searchModelFilter.getSelectionModel().select(0);
if (initModelAssets(false)) {
Set<String> filterTags = modelsDatasetFull.getJSONObject("storageDirectory").keySet();
for (String s : filterTags) {
searchModelFilter.getItems().add(s);
}
}
searchModelFilter.valueProperty().addListener(observable -> {
if (searchModelFilter.getValue() != null) {
isNoFilter = searchModelFilter.getSelectionModel().getSelectedIndex() == 0;
Logger.info("ModelList", "Filter \"" + searchModelFilter.getValue() + "\"");
dealModelSearch(searchModelInput.getText());
searchModelFilter.getSelectionModel().clearAndSelect(searchModelFilter.getSelectionModel().getSelectedIndex());
}
});
}

private boolean initModelDataset(boolean $doPopNotice) {
Expand Down Expand Up @@ -253,8 +291,8 @@ private boolean initModelAssets(boolean $doPopNotice) {
throw new RuntimeException("Found no assets in the target directories.");
// Models to menu items.
ArrayList<JFXListCell<AssetCtrl>> foundModelItemsL = new ArrayList<>();
searchModelList.getSelectionModel().getSelectedItems().addListener((ListChangeListener<ListCell<AssetCtrl>>)(observable -> {
observable.getList().forEach((Consumer<ListCell<AssetCtrl>>) cell -> {
searchModelList.getSelectionModel().getSelectedItems().addListener((ListChangeListener<JFXListCell<AssetCtrl>>)(observable -> {
observable.getList().forEach((Consumer<JFXListCell<AssetCtrl>>) cell -> {
selectModel(cell.getItem(), cell);
});
}));
Expand Down Expand Up @@ -954,13 +992,13 @@ public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) th
}

private void dealModelSearch(String $keyWords) {
searchModelInput.setText($keyWords);
searchModelList.getItems().clear();
AssetCtrl[] result = AssetCtrl.searchByKeyWords($keyWords, foundModelAssets);
String[] assetIdList = AssetCtrl.getAssetIdList(result);
for (ListCell<AssetCtrl> item : foundModelItems) {
for (JFXListCell<AssetCtrl> item : foundModelItems) {
for (String assetId : assetIdList) {
if (item.getId().equals(assetId)) {
if (item.getId().equals(assetId) &&
(isNoFilter || searchModelFilter.getValue().equals(item.getItem().type))) {
searchModelList.getItems().add(item);
break;
}
Expand All @@ -973,7 +1011,7 @@ private void dealModelSearch(String $keyWords) {
private void dealModelRandom() {
if (!assertModelLoaded(true))
return;
int idx = (int)(Math.random() * (foundModelItems.length - 1));
int idx = (int)(Math.random() * (searchModelList.getItems().size() - 1));
searchModelList.scrollTo(idx);
searchModelList.getSelectionModel().select(idx);
searchModelList.requestFocus();
Expand All @@ -988,22 +1026,22 @@ private void dealModelReload() {
Logger.info("ModelList", "Reloaded");
}

private JFXListCell<AssetCtrl> getMenuItem(AssetCtrl $assetCtrl, JFXListView<AssetCtrl> $container) {
private JFXListCell<AssetCtrl> getMenuItem(AssetCtrl $assetCtrl, JFXListView<JFXListCell<AssetCtrl>> $container) {
double width = $container.getPrefWidth();
width -= $container.getPadding().getLeft() + $container.getPadding().getRight();
width *= 0.75;
double height = 30;
final double divide = 0.5;
double divide = 0.5;
JFXListCell<AssetCtrl> item = new JFXListCell<>();
item.getStyleClass().addAll("Search-models-item", "scroll-v");
Label name = new Label($assetCtrl.toString());
name.getStyleClass().addAll("Search-models-label", "Search-models-label-primary");
name.setPrefSize(width * divide, height);
name.setPrefSize($assetCtrl.skinGroupName == null ? width : width * divide, height);
name.setLayoutX(0);
Label alias1 = new Label($assetCtrl.skinGroupName);
alias1.getStyleClass().addAll("Search-models-label", "Search-models-label-secondary");
alias1.setPrefSize(width * (1 - divide), height);
alias1.setLayoutX(width * divide);
alias1.setLayoutX($assetCtrl.skinGroupName == null ? 0 : width * (1 - divide));

item.setPrefSize(width, height);
item.setGraphic(new Group(name, alias1));
Expand All @@ -1016,7 +1054,6 @@ private void selectModel(AssetCtrl $asset, ListCell<AssetCtrl> $item) {
// Reset
if (selectedModelItem != null)
selectedModelItem.getStyleClass().setAll("Search-models-item");
selectedModelAsset = $asset;
selectedModelItem = $item;
selectedModelItem.getStyleClass().add("Search-models-item-active");
// Display details
Expand Down

0 comments on commit c0c3c33

Please sign in to comment.