set environment as console if gamepad is detected

This commit is contained in:
minjaesong
2019-02-11 14:54:57 +09:00
parent 21d7b83f96
commit b9fbacad14
4 changed files with 30 additions and 27 deletions

View File

@@ -8,17 +8,22 @@ import com.badlogic.gdx.assets.AssetManager;
import com.badlogic.gdx.audio.AudioDevice;
import com.badlogic.gdx.backends.lwjgl.LwjglApplication;
import com.badlogic.gdx.backends.lwjgl.LwjglApplicationConfiguration;
import com.badlogic.gdx.controllers.Controllers;
import com.badlogic.gdx.graphics.*;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.graphics.glutils.FrameBuffer;
import com.badlogic.gdx.graphics.glutils.ShaderProgram;
import com.badlogic.gdx.utils.ScreenUtils;
import com.github.strikerx3.jxinput.XInputDevice;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.torvald.dataclass.ArrayListMap;
import net.torvald.getcpuname.GetCpuName;
import net.torvald.terrarum.controller.GdxControllerAdapter;
import net.torvald.terrarum.controller.TerrarumController;
import net.torvald.terrarum.controller.XinputControllerAdapter;
import net.torvald.terrarum.gamecontroller.KeyToggler;
import net.torvald.terrarum.imagefont.TinyAlphNum;
import net.torvald.terrarum.modulebasegame.Ingame;
@@ -175,6 +180,7 @@ public class AppLoader implements ApplicationListener {
public static TinyAlphNum fontSmallNumbers;
/** A gamepad. Multiple gamepads may controll this single virtualised gamepad. */
public static TerrarumController gamepad = null;
public static float gamepadDeadzone = 0.2f;
/**
@@ -311,6 +317,24 @@ public class AppLoader implements ApplicationListener {
rendererVendor = Gdx.graphics.getGLVersion().getVendorString();
// make gamepad(s)
if (AppLoader.getConfigBoolean("usexinput")) {
try {
gamepad = new XinputControllerAdapter(XInputDevice.getDeviceFor(0));
}
catch (Throwable e) { }
}
if (gamepad == null) {
try {
gamepad = new GdxControllerAdapter(Controllers.getControllers().get(0));
}
catch (Throwable e) { }
}
if (gamepad != null) {
environment = RunningEnvironment.CONSOLE;
}
// make loading list

View File

@@ -25,7 +25,6 @@ import net.torvald.terrarum.worlddrawer.WorldCamera
import net.torvald.terrarumsansbitmap.gdx.GameFontBase
import net.torvald.terrarumsansbitmap.gdx.TextureRegionPack
import org.lwjgl.BufferUtils
import org.lwjgl.input.Controllers
import java.io.File
import kotlin.math.absoluteValue
@@ -223,19 +222,6 @@ object Terrarum : Screen {
}
// setting environment as MOBILE precedes this code
//if (environment != RunningEnvironment.MOBILE) {
environment = try {
Controllers.getController(0) // test if controller exists
if (getConfigString("pcgamepadenv") == "console")
RunningEnvironment.CONSOLE
else
RunningEnvironment.PC
}
catch (e: IndexOutOfBoundsException) {
RunningEnvironment.PC
}
//}
}

View File

@@ -1,10 +1,8 @@
package net.torvald.terrarum.modulebasegame
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.controllers.Controllers
import com.badlogic.gdx.graphics.Camera
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.github.strikerx3.jxinput.XInputDevice
import net.torvald.dataclass.CircularArray
import net.torvald.terrarum.*
import net.torvald.terrarum.AppLoader.printdbg
@@ -12,8 +10,6 @@ import net.torvald.terrarum.blockproperties.BlockPropUtil
import net.torvald.terrarum.blockstats.BlockStats
import net.torvald.terrarum.concurrent.ThreadParallel
import net.torvald.terrarum.console.Authenticator
import net.torvald.terrarum.controller.GdxControllerAdapter
import net.torvald.terrarum.controller.XinputControllerAdapter
import net.torvald.terrarum.gameactors.Actor
import net.torvald.terrarum.gameactors.ActorWithBody
import net.torvald.terrarum.gamecontroller.IngameController
@@ -272,13 +268,9 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// make controls work
Gdx.input.inputProcessor = ingameController
ingameController.gamepad =
if (AppLoader.getConfigBoolean("usexinput"))
XinputControllerAdapter(XInputDevice.getDeviceFor(0))
else
GdxControllerAdapter(Controllers.getControllers()[0])
if (AppLoader.gamepad != null) {
ingameController.gamepad = AppLoader.gamepad
}
// init console window
consoleHandler = ConsoleWindow()
@@ -297,7 +289,8 @@ open class Ingame(batch: SpriteBatch) : IngameInstance(batch) {
// >- queue up game UIs that should pause the world -<
uiInventoryPlayer = UIInventoryFull(actorNowPlaying!!,
toggleKeyLiteral = AppLoader.getConfigInt("keyinventory")
toggleKeyLiteral = AppLoader.getConfigInt("keyinventory"),
toggleButtonLiteral = AppLoader.getConfigInt("gamepadstart")
)
uiInventoryPlayer.setPosition(0, 0)

View File

@@ -249,7 +249,7 @@ class BasicDebugInfoWindow : UICanvas() {
(Terrarum.WIDTH - 2 - totalHardwareName.length * 8).toFloat(), Terrarum.HEIGHT - 10f)
}
private val processorName = AppLoader.processor.replace(Regex(""" Processor|( CPU)? @ [0-9.]+GHz"""), "")
private val processorName = AppLoader.processor.replace(Regex(""" Processor|( CPU)? @ [0-9.]+GHz"""), "") + if (AppLoader.is32BitJVM) " (32-bit)" else ""
private val rendererName = AppLoader.renderer
private val totalHardwareName = "$processorName $rendererName"