mirror of
https://github.com/HMCL-dev/HMCL.git
synced 2025-09-23 03:04:07 -04:00
修复滚动切换游戏实例/账户功能 (#4466)
This commit is contained in:
parent
356960cc82
commit
60ff34a587
@ -78,15 +78,22 @@ public class AccountAdvancedListItem extends AdvancedListItem {
|
||||
setActionButtonVisible(false);
|
||||
|
||||
setOnScroll(event -> {
|
||||
double deltaY = event.getDeltaY();
|
||||
if (deltaY == 0)
|
||||
return;
|
||||
|
||||
Account current = account.get();
|
||||
if (current == null) return;
|
||||
|
||||
ObservableList<Account> accounts = Accounts.getAccounts();
|
||||
int currentIndex = accounts.indexOf(account.get());
|
||||
if (event.getDeltaY() > 0) { // up
|
||||
int currentIndex = accounts.indexOf(current);
|
||||
if (currentIndex < 0) return;
|
||||
|
||||
if (deltaY > 0) // up
|
||||
currentIndex--;
|
||||
} else { // down
|
||||
else // down
|
||||
currentIndex++;
|
||||
}
|
||||
|
||||
Accounts.setSelectedAccount(accounts.get((currentIndex + accounts.size()) % accounts.size()));
|
||||
});
|
||||
}
|
||||
|
@ -69,6 +69,7 @@ import org.jackhuang.hmcl.upgrade.RemoteVersion;
|
||||
import org.jackhuang.hmcl.upgrade.UpdateChecker;
|
||||
import org.jackhuang.hmcl.upgrade.UpdateHandler;
|
||||
import org.jackhuang.hmcl.util.Holder;
|
||||
import org.jackhuang.hmcl.util.Lang;
|
||||
import org.jackhuang.hmcl.util.StringUtils;
|
||||
import org.jackhuang.hmcl.util.TaskCancellationAction;
|
||||
import org.jackhuang.hmcl.util.javafx.BindingMapping;
|
||||
@ -79,7 +80,6 @@ import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.CancellationException;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
import static org.jackhuang.hmcl.download.RemoteVersion.Type.RELEASE;
|
||||
import static org.jackhuang.hmcl.setting.ConfigHolder.config;
|
||||
@ -209,15 +209,17 @@ public final class MainPage extends StackPane implements DecoratorPage {
|
||||
launchPane.setMaxWidth(230);
|
||||
launchPane.setMaxHeight(55);
|
||||
launchPane.setOnScroll(event -> {
|
||||
int index = IntStream.range(0, versions.size())
|
||||
.filter(i -> versions.get(i).getId().equals(getCurrentGame()))
|
||||
.findFirst().orElse(-1);
|
||||
double deltaY = event.getDeltaY();
|
||||
if (deltaY == 0)
|
||||
return;
|
||||
|
||||
String currentId = getCurrentGame();
|
||||
int index = Lang.indexWhere(versions, instance -> instance.getId().equals(currentId));
|
||||
if (index < 0) return;
|
||||
if (event.getDeltaY() > 0) {
|
||||
if (deltaY > 0) // up
|
||||
index--;
|
||||
} else {
|
||||
else // down
|
||||
index++;
|
||||
}
|
||||
profile.setSelectedVersion(versions.get((index + versions.size()) % versions.size()).getId());
|
||||
});
|
||||
StackPane.setAlignment(launchPane, Pos.BOTTOM_RIGHT);
|
||||
|
@ -48,9 +48,10 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Construct a mutable map by given key-value pairs.
|
||||
*
|
||||
* @param pairs entries in the new map
|
||||
* @param <K> the type of keys
|
||||
* @param <V> the type of values
|
||||
* @param <K> the type of keys
|
||||
* @param <V> the type of values
|
||||
* @return the map which contains data in {@code pairs}.
|
||||
*/
|
||||
@SafeVarargs
|
||||
@ -60,9 +61,10 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Construct a mutable map by given key-value pairs.
|
||||
*
|
||||
* @param pairs entries in the new map
|
||||
* @param <K> the type of keys
|
||||
* @param <V> the type of values
|
||||
* @param <K> the type of keys
|
||||
* @param <V> the type of values
|
||||
* @return the map which contains data in {@code pairs}.
|
||||
*/
|
||||
public static <K, V> Map<K, V> mapOf(Iterable<Pair<K, V>> pairs) {
|
||||
@ -122,9 +124,10 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Cast {@code obj} to V dynamically.
|
||||
* @param obj the object reference to be cast.
|
||||
*
|
||||
* @param obj the object reference to be cast.
|
||||
* @param clazz the class reference of {@code V}.
|
||||
* @param <V> the type that {@code obj} is being cast to.
|
||||
* @param <V> the type that {@code obj} is being cast to.
|
||||
* @return {@code obj} in the type of {@code V}.
|
||||
*/
|
||||
public static <V> Optional<V> tryCast(Object obj, Class<V> clazz) {
|
||||
@ -154,8 +157,8 @@ public final class Lang {
|
||||
/**
|
||||
* Join two collections into one list.
|
||||
*
|
||||
* @param a one collection, to be joined.
|
||||
* @param b another collection to be joined.
|
||||
* @param a one collection, to be joined.
|
||||
* @param b another collection to be joined.
|
||||
* @param <T> the super type of elements in {@code a} and {@code b}
|
||||
* @return the joint collection
|
||||
*/
|
||||
@ -172,6 +175,16 @@ public final class Lang {
|
||||
return list == null ? null : list.isEmpty() ? null : new ArrayList<>(list);
|
||||
}
|
||||
|
||||
public static <T> int indexWhere(List<T> list, Predicate<T> predicate) {
|
||||
int idx = 0;
|
||||
for (T value : list) {
|
||||
if (predicate.test(value))
|
||||
return idx;
|
||||
idx++;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
public static void executeDelayed(Runnable runnable, TimeUnit timeUnit, long timeout, boolean isDaemon) {
|
||||
thread(() -> {
|
||||
try {
|
||||
@ -185,6 +198,7 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Start a thread invoking {@code runnable} immediately.
|
||||
*
|
||||
* @param runnable code to run.
|
||||
* @return the reference of the started thread
|
||||
*/
|
||||
@ -194,8 +208,9 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Start a thread invoking {@code runnable} immediately.
|
||||
*
|
||||
* @param runnable code to run
|
||||
* @param name the name of thread
|
||||
* @param name the name of thread
|
||||
* @return the reference of the started thread
|
||||
*/
|
||||
public static Thread thread(Runnable runnable, String name) {
|
||||
@ -204,8 +219,9 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Start a thread invoking {@code runnable} immediately.
|
||||
*
|
||||
* @param runnable code to run
|
||||
* @param name the name of thread
|
||||
* @param name the name of thread
|
||||
* @param isDaemon true if thread will be terminated when only daemon threads are running.
|
||||
* @return the reference of the started thread
|
||||
*/
|
||||
@ -258,7 +274,8 @@ public final class Lang {
|
||||
|
||||
/**
|
||||
* Find the first non-null reference in given list.
|
||||
* @param t nullable references list.
|
||||
*
|
||||
* @param t nullable references list.
|
||||
* @param <T> the type of nullable references
|
||||
* @return the first non-null reference.
|
||||
*/
|
||||
|
Loading…
x
Reference in New Issue
Block a user