mirror of
https://github.com/TeamMidnightDust/MidnightControls.git
synced 2025-12-13 15:25:08 +01:00
- Added #40 (Modded keybind support) - Added #20 (Touchscreen support) - Improved #13 (Sodium screen controller support) - Attempt to fix #31 & #38 (Jittery input on low FPS) - Fixed #35 (Front placing being broken) - Fixed #32 (Option to disable double tap to sprint) - Fixed #27 (Auto-adapt controller icons) - Fixed #19 (HUD-scaling on big scales) - Fixed #36 (Crash on game load) - Fixed reset option - Fixed scrolling in trading screens - Disable features that might be considered as cheats (install MidnightControlsExtra to enable)
74 lines
2.2 KiB
Java
74 lines
2.2 KiB
Java
/*
|
|
* Copyright © 2021 LambdAurora <aurora42lambda@gmail.com>
|
|
*
|
|
* This file is part of midnightcontrols.
|
|
*
|
|
* Licensed under the MIT license. For more information,
|
|
* see the LICENSE file.
|
|
*/
|
|
|
|
package eu.midnightdust.midnightcontrols.client.ring;
|
|
|
|
import com.electronwill.nightconfig.core.Config;
|
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsClient;
|
|
import eu.midnightdust.midnightcontrols.client.MidnightControlsConfig;
|
|
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
|
import org.jetbrains.annotations.NotNull;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.Collections;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
|
|
/**
|
|
* Represents a key binding ring.
|
|
*
|
|
* @author LambdAurora
|
|
* @version 1.7.0
|
|
* @since 1.4.0
|
|
*/
|
|
public final class MidnightRing {
|
|
public static final int ELEMENT_SIZE = 50;
|
|
|
|
private final Map<String, RingAction.Factory> actionFactories = new Object2ObjectOpenHashMap<>();
|
|
private final List<RingPage> pages = new ArrayList<>(Collections.singletonList(RingPage.DEFAULT));
|
|
private final MidnightControlsClient mod;
|
|
private int currentPage = 0;
|
|
|
|
public MidnightRing(@NotNull MidnightControlsClient mod) {
|
|
this.mod = mod;
|
|
}
|
|
|
|
public void registerAction(@NotNull String name, @NotNull RingAction.Factory factory) {
|
|
if (this.actionFactories.containsKey(name)) {
|
|
this.mod.warn("Tried to register twice a ring action: \"" + name + "\".");
|
|
return;
|
|
}
|
|
this.actionFactories.put(name, factory);
|
|
}
|
|
|
|
/**
|
|
* Loads the ring from configuration.
|
|
*/
|
|
public void load() {
|
|
List<Config> configPages = null;
|
|
if (configPages != null) {
|
|
this.pages.clear();
|
|
for (var configPage : configPages) {
|
|
RingPage.parseRingPage(configPage).ifPresent(this.pages::add);
|
|
}
|
|
}
|
|
if (this.pages.isEmpty()) {
|
|
this.pages.add(RingPage.DEFAULT);
|
|
}
|
|
}
|
|
|
|
public @NotNull RingPage getCurrentPage() {
|
|
if (this.currentPage >= this.pages.size())
|
|
this.currentPage = this.pages.size() - 1;
|
|
else if (this.currentPage < 0)
|
|
this.currentPage = 0;
|
|
return this.pages.get(this.currentPage);
|
|
}
|
|
}
|