Skip to content

Commit

Permalink
MidnightControls 0.3.0 - Automatic mapping downloading
Browse files Browse the repository at this point in the history
- Automatic downloading of mappings from https://github.com/gabomdq/SDL_GameControllerDB
- Change some default settings
- Fix OkZoomer compat by @akemin-dayo
- German translations (by myself)
- Add contributors to fabric.mod.json
- Fix some issues
  • Loading branch information
Motschen committed May 3, 2022
1 parent b982772 commit cac23d1
Show file tree
Hide file tree
Showing 17 changed files with 191 additions and 43 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[![GitHub license](https://img.shields.io/github/license/TeamMidnightDust/MidnightControls?style=flat-square)](https://raw.githubusercontent.com/TeamMidnightDust/MidnightControls/master/LICENSE)
![Environment: Client](https://img.shields.io/badge/environment-client-1976d2?style=flat-square)
[![Mod loader: Quilt/Fabric]][quilt] <!-- modrinth_exclude.start -->
![Version](https://img.shields.io/github/v/tag/TeamMidnightDust/MidnightControls?label=version&style=flat-square)
[![Version](https://img.shields.io/github/v/tag/TeamMidnightDust/MidnightControls?label=version&style=flat-square)](https://github.com/TeamMidnightDust/MidnightControls/releases)
[![CurseForge](http://cf.way2muchnoise.eu/title/354231.svg)](https://www.curseforge.com/minecraft/mc-mods/midnightcontrols)
<!-- modrinth_exclude.end -->

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ yarn_mappings=1.18.1+build.22
loader_version=0.13.3

# Mod Properties
mod_version = 0.2.0
mod_version = 0.3.0
maven_group = eu.midnightdust
archives_base_name = midnightcontrols
modrinth_id=W1D3UXEc
modrinth_id=bXX9h73M

# Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public class MidnightControlsConstants {
public static final String NAMESPACE = "midnightcontrols";
public static final Identifier CONTROLS_MODE_CHANNEL = new Identifier(NAMESPACE, "controls_mode");
public static final Identifier FEATURE_CHANNEL = new Identifier(NAMESPACE, "feature");
public static final Identifier HELLO_CHANNEL = new Identifier(NAMESPACE, "hello");
public static final Identifier HELLO_CHANNEL = new Identifier("lambdacontrols", "hello");
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public class MidnightControlsClient extends MidnightControls implements ClientMo
public static final Identifier CONTROLLER_EXPANDED = new Identifier(MidnightControlsConstants.NAMESPACE, "textures/gui/controller_expanded.png");
public static final Identifier CONTROLLER_AXIS = new Identifier(MidnightControlsConstants.NAMESPACE, "textures/gui/controller_axis.png");
public static final Identifier CURSOR_TEXTURE = new Identifier(MidnightControlsConstants.NAMESPACE, "textures/gui/cursor.png");
public final static File MAPPINGS_FILE = new File("config/gamecontrollerdb.txt");
public final static File MAPPINGS_FILE = new File("config/gamecontrollercustommappings.txt");
public final MidnightInput input = new MidnightInput();
public final MidnightRing ring = new MidnightRing(this);
public final MidnightReacharound reacharound = new MidnightReacharound();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,10 @@
public class MidnightControlsConfig extends MidnightConfig {
// General
@Entry public static ControlsMode controlsMode = ControlsMode.DEFAULT;
@Entry public static boolean autoSwitchMode = false;
@Entry public static boolean autoSwitchMode = true;
@Entry public static boolean debug = false;
// HUD
@Entry public static boolean hudEnable = true;
@Entry public static boolean hudAlwaysShow = true; // Enabled by default so that users migrating from LambdaControls will have a consistent experience.
@Entry public static HudSide hudSide = HudSide.LEFT;
// Gameplay
@Entry public static boolean analogMovement = true;
Expand All @@ -58,18 +57,11 @@ public class MidnightControlsConfig extends MidnightConfig {
@Entry public static boolean unfocusedInput = false;
@Entry public static boolean virtualMouse = false;
@Entry public static VirtualMouseSkin virtualMouseSkin = VirtualMouseSkin.DEFAULT_LIGHT;
// @Entry public static List<Pages> ringPages = new ArrayList<String>();
// @Entry public static double maxAnalog1 = 1;
// @Entry public static double maxAnalog2 = 1;
// @Entry public static double maxAnalog3 = 1;
// @Entry public static double maxAnalog4 = 1;
@Entry public static Object controllerID = 0;
@Entry public static Object secondControllerID = -1;
@Entry public static Map<String, String> BINDINGS = Map.of();

private static final Pattern BUTTON_BINDING_PATTERN = Pattern.compile("(-?\\d+)\\+?");
// Gameplay.
// Controller settings
@Entry public static double[] maxAnalogValues = new double[]{DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE, DEFAULT_MAX_VALUE};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import net.minecraft.client.gui.Element;
import net.minecraft.client.gui.ParentElement;
import net.minecraft.client.gui.screen.Screen;
import net.minecraft.client.gui.screen.TitleScreen;
import net.minecraft.client.gui.screen.advancement.AdvancementTab;
import net.minecraft.client.gui.screen.advancement.AdvancementsScreen;
import net.minecraft.client.gui.screen.ingame.CreativeInventoryScreen;
Expand Down Expand Up @@ -312,7 +313,7 @@ private void handleButton(@NotNull MinecraftClient client, int button, int actio
}

if (button == GLFW.GLFW_GAMEPAD_BUTTON_B) {
if (client.currentScreen != null) {
if (client.currentScreen != null && client.currentScreen.getClass() != TitleScreen.class) {
if (!MidnightControlsCompat.handleMenuBack(client, client.currentScreen))
if (!this.tryGoBack(client.currentScreen))
client.currentScreen.onClose();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
import org.lwjgl.system.MemoryStack;
import org.lwjgl.system.MemoryUtil;

import java.io.IOException;
import java.io.*;
import java.net.URL;
import java.nio.ByteBuffer;
import java.nio.file.Files;
import java.nio.file.Paths;
Expand Down Expand Up @@ -145,9 +146,23 @@ private static ByteBuffer ioResourceToBuffer(String resource, int bufferSize) th
*/
public static void updateMappings() {
try {
MidnightControlsClient.get().log("Updating controller mappings...");
File databaseFile = new File("config/gamecontrollerdatabase.txt");
try {
BufferedInputStream in = new BufferedInputStream(new URL("https://raw.githubusercontent.com/gabomdq/SDL_GameControllerDB/master/gamecontrollerdb.txt").openStream());

BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(databaseFile));
byte[] dataBuffer = new byte[1024];
int bytesRead;
while ((bytesRead = in.read(dataBuffer, 0, 1024)) != -1) {
out.write(dataBuffer, 0, bytesRead);
}
out.close();
} catch (Exception ignored) {/* Just continue when internet connection is not available */}
var database = ioResourceToBuffer(databaseFile.getPath(), 1024);
GLFW.glfwUpdateGamepadMappings(database);
if (!MidnightControlsClient.MAPPINGS_FILE.exists())
return;
MidnightControlsClient.get().log("Updating controller mappings...");
var buffer = ioResourceToBuffer(MidnightControlsClient.MAPPINGS_FILE.getPath(), 1024);
GLFW.glfwUpdateGamepadMappings(buffer);
} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,11 @@ public void init(@NotNull MinecraftClient client, int screenWidth, int screenHei
@Override
public void render(MatrixStack matrices, float tickDelta) {
if (MidnightControlsConfig.controlsMode == ControlsMode.CONTROLLER && this.client.currentScreen == null) {
if (MidnightControlsConfig.hudAlwaysShow || (MidnightControlsConfig.getController().isConnected() && MidnightControlsConfig.getController().isGamepad())) {
int y = bottom(2);
this.renderFirstIcons(matrices, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
this.renderSecondIcons(matrices, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
this.renderFirstSection(matrices, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
this.renderSecondSection(matrices, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
}
int y = bottom(2);
this.renderFirstIcons(matrices, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
this.renderSecondIcons(matrices, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
this.renderFirstSection(matrices, MidnightControlsConfig.hudSide == HudSide.LEFT ? 2 : client.getWindow().getScaledWidth() - 2, y);
this.renderSecondSection(matrices, MidnightControlsConfig.hudSide == HudSide.RIGHT ? 2 : client.getWindow().getScaledWidth() - 2, y);
}

if (this.mod.reacharound.isLastReacharoundVertical()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ public class MidnightControlsSettingsScreen extends SpruceScreen {
private final SpruceOption controllerTypeOption;
private final SpruceOption virtualMouseSkinOption;
private final SpruceOption hudEnableOption;
private final SpruceOption hudAlwaysShowOption;
private final SpruceOption hudSideOption;
// Controller options
private final SpruceOption controllerOption =
Expand Down Expand Up @@ -213,8 +212,6 @@ public MidnightControlsSettingsScreen(Screen parent, boolean hideControls) {
null);
this.hudEnableOption = new SpruceToggleBooleanOption("midnightcontrols.menu.hud_enable", () -> MidnightControlsConfig.hudEnable,
this.mod::setHudEnabled, new TranslatableText("midnightcontrols.tooltip.hud_enable"));
this.hudAlwaysShowOption = new SpruceToggleBooleanOption("midnightcontrols.menu.hud_always_show", () -> MidnightControlsConfig.hudAlwaysShow,
value -> MidnightControlsConfig.hudAlwaysShow = value, new TranslatableText("midnightcontrols.tooltip.hud_always_show"));
this.hudSideOption = new SpruceCyclingOption("midnightcontrols.menu.hud_side",
amount -> MidnightControlsConfig.hudSide = MidnightControlsConfig.hudSide.next(),
option -> option.getDisplayText(MidnightControlsConfig.hudSide.getTranslatedText()),
Expand Down Expand Up @@ -261,6 +258,7 @@ private int getTextHeight() {
@Override
protected void init() {
super.init();
Controller.updateMappings();

this.buildTabs();

Expand Down Expand Up @@ -323,7 +321,6 @@ public SpruceOptionListWidget buildVisualTab(int width, int height) {
list.addSingleOptionEntry(this.virtualMouseSkinOption);
list.addSingleOptionEntry(new SpruceSeparatorOption("midnightcontrols.menu.title.hud", true, null));
list.addSingleOptionEntry(this.hudEnableOption);
list.addSingleOptionEntry(this.hudAlwaysShowOption);
list.addSingleOptionEntry(this.hudSideOption);
return list;
}
Expand Down
Loading

0 comments on commit cac23d1

Please sign in to comment.