Skip to content

Commit

Permalink
refactor: reuse toggle wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
isHarryh committed Oct 7, 2024
1 parent 4358d0c commit d913e79
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,7 @@ private void initConfigBehavior() {
app.config.save();
});

toggleConfigDeployPosition.setOnAction(e -> {
if (wrapperConfigDeployPosition.isVisible())
GuiPrefabs.fadeOutNode(wrapperConfigDeployPosition, durationFast, null);
else
GuiPrefabs.fadeInNode(wrapperConfigDeployPosition, durationFast, null);
});
GuiPrefabs.bindToggleAndWrapper(toggleConfigDeployPosition, wrapperConfigDeployPosition, durationFast);
GuiComponents.DotPickerSetup setupDeployPosition = new GuiComponents.DotPickerSetup(configDeployPosition);
setupDeployPosition.setRelXY(app.config.initial_position_x, app.config.initial_position_y);
setupDeployPosition.setOnDotPicked(e -> {
Expand Down
14 changes: 2 additions & 12 deletions desktop/src/cn/harryh/arkpets/controllers/SettingsModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,7 @@ public String getContent() {
app.config.save();
});

toggleConfigRenderOutline.setOnAction(e -> {
if (wrapperConfigRenderOutline.isVisible())
GuiPrefabs.fadeOutNode(wrapperConfigRenderOutline, durationFast, null);
else
GuiPrefabs.fadeInNode(wrapperConfigRenderOutline, durationFast, null);
});
GuiPrefabs.bindToggleAndWrapper(toggleConfigRenderOutline, wrapperConfigRenderOutline, durationFast);
new ComboBoxSetup<>(configRenderOutline).setItems(new NamedItem<>("始终开启", ArkConfig.RenderOutline.ALWAYS.ordinal()),
new NamedItem<>("处于前台时", ArkConfig.RenderOutline.FOCUSED.ordinal()),
new NamedItem<>("点击时", ArkConfig.RenderOutline.PRESSING.ordinal()),
Expand Down Expand Up @@ -204,12 +199,7 @@ public String getContent() {
app.config.save();
});

toggleConfigRenderOpacity.setOnAction(e -> {
if (wrapperConfigRenderOpacity.isVisible())
GuiPrefabs.fadeOutNode(wrapperConfigRenderOpacity, durationFast, null);
else
GuiPrefabs.fadeInNode(wrapperConfigRenderOpacity, durationFast, null);
});
GuiPrefabs.bindToggleAndWrapper(toggleConfigRenderOpacity, wrapperConfigRenderOpacity, durationFast);
final int minOpacity = 10;
GuiComponents.SliderSetup<Integer> setupRenderOpacityDim = new GuiComponents.SimpleIntegerSliderSetup(configRenderOpacityDim);
setupRenderOpacityDim
Expand Down
9 changes: 9 additions & 0 deletions desktop/src/cn/harryh/arkpets/utils/GuiPrefabs.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,15 @@ public static void fadeOutWindow(Window window, Duration duration, EventHandler<
timeline.playFromStart();
}

public static void bindToggleAndWrapper(JFXButton toggle, Node wrapper, Duration duration) {
toggle.setOnAction(e -> {
if (wrapper.isVisible())
GuiPrefabs.fadeOutNode(wrapper, duration, null);
else
GuiPrefabs.fadeInNode(wrapper, duration, null);
});
}

public static void replaceStyleClass(Node node, String from, String to) {
HashSet<String> styleClass = new HashSet<>(Set.copyOf(node.getStyleClass()));
styleClass.remove(from);
Expand Down

0 comments on commit d913e79

Please sign in to comment.