mirror of
https://github.com/AngelAuraMC/Amethyst-Android.git
synced 2026-04-19 17:17:04 -04:00
Feat[remapper]: improve UI, other changes
This commit is contained in:
@@ -198,7 +198,7 @@ public class EfficientAndroidLWJGLKeycode {
|
||||
sendKeyPress(getValueByIndex(index));
|
||||
}
|
||||
|
||||
public static int getValueByIndex(int index) {
|
||||
public static short getValueByIndex(int index) {
|
||||
return sLwjglKeycodes[index];
|
||||
}
|
||||
|
||||
|
||||
@@ -49,29 +49,6 @@ public class GamepadMap {
|
||||
public GamepadButton DPAD_DOWN;
|
||||
public GamepadButton DPAD_LEFT;
|
||||
|
||||
public GamepadMap() {
|
||||
BUTTON_A = new GamepadButton();
|
||||
BUTTON_B = new GamepadButton();
|
||||
BUTTON_X = new GamepadButton();
|
||||
BUTTON_Y = new GamepadButton();
|
||||
BUTTON_START = new GamepadButton();
|
||||
BUTTON_SELECT = new GamepadButton();
|
||||
TRIGGER_RIGHT = new GamepadButton();
|
||||
TRIGGER_LEFT = new GamepadButton();
|
||||
SHOULDER_RIGHT = new GamepadButton();
|
||||
SHOULDER_LEFT = new GamepadButton();
|
||||
DIRECTION_FORWARD = new GamepadEmulatedButton();
|
||||
DIRECTION_BACKWARD = new GamepadEmulatedButton();
|
||||
DIRECTION_RIGHT = new GamepadEmulatedButton();
|
||||
DIRECTION_LEFT = new GamepadEmulatedButton();
|
||||
THUMBSTICK_RIGHT = new GamepadButton();
|
||||
THUMBSTICK_LEFT = new GamepadButton();
|
||||
DPAD_UP = new GamepadButton();
|
||||
DPAD_RIGHT = new GamepadButton();
|
||||
DPAD_DOWN = new GamepadButton();
|
||||
DPAD_LEFT = new GamepadButton();
|
||||
}
|
||||
|
||||
/*
|
||||
* Sets all buttons to a not pressed state, sending an input if needed
|
||||
*/
|
||||
@@ -100,6 +77,37 @@ public class GamepadMap {
|
||||
|
||||
}
|
||||
|
||||
private static GamepadMap createAndInitializeButtons() {
|
||||
GamepadMap gamepadMap = new GamepadMap();
|
||||
gamepadMap.BUTTON_A = new GamepadButton();
|
||||
gamepadMap.BUTTON_B = new GamepadButton();
|
||||
gamepadMap.BUTTON_X = new GamepadButton();
|
||||
gamepadMap.BUTTON_Y = new GamepadButton();
|
||||
|
||||
gamepadMap.BUTTON_START = new GamepadButton();
|
||||
gamepadMap.BUTTON_SELECT = new GamepadButton();
|
||||
|
||||
gamepadMap.TRIGGER_RIGHT = new GamepadButton();
|
||||
gamepadMap.TRIGGER_LEFT = new GamepadButton();
|
||||
|
||||
gamepadMap.SHOULDER_RIGHT = new GamepadButton();
|
||||
gamepadMap.SHOULDER_LEFT = new GamepadButton();
|
||||
|
||||
gamepadMap.DIRECTION_FORWARD = new GamepadEmulatedButton();
|
||||
gamepadMap.DIRECTION_BACKWARD = new GamepadEmulatedButton();
|
||||
gamepadMap.DIRECTION_RIGHT = new GamepadEmulatedButton();
|
||||
gamepadMap.DIRECTION_LEFT = new GamepadEmulatedButton();
|
||||
|
||||
gamepadMap.THUMBSTICK_RIGHT = new GamepadButton();
|
||||
gamepadMap.THUMBSTICK_LEFT = new GamepadButton();
|
||||
|
||||
gamepadMap.DPAD_UP = new GamepadButton();
|
||||
gamepadMap.DPAD_RIGHT = new GamepadButton();
|
||||
gamepadMap.DPAD_DOWN = new GamepadButton();
|
||||
gamepadMap.DPAD_LEFT = new GamepadButton();
|
||||
return gamepadMap;
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a pre-done mapping used when the mouse is grabbed by the game.
|
||||
*/
|
||||
@@ -191,7 +199,7 @@ public class GamepadMap {
|
||||
* Returns an pre-initialized GamepadMap with only empty keycodes
|
||||
*/
|
||||
@SuppressWarnings("unused") public static GamepadMap createEmptyMap(){
|
||||
GamepadMap emptyMap = new GamepadMap();
|
||||
GamepadMap emptyMap = createAndInitializeButtons();
|
||||
for(GamepadEmulatedButton button : emptyMap.getButtons())
|
||||
button.keycodes = new short[] {UNSPECIFIED, UNSPECIFIED, UNSPECIFIED, UNSPECIFIED};
|
||||
return emptyMap;
|
||||
|
||||
@@ -64,10 +64,10 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
||||
mSimulatedGamepadMap.TRIGGER_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.trigger_left, R.string.controller_button_trigger_left);
|
||||
mSimulatedGamepadMap.SHOULDER_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.shoulder_right, R.string.controller_button_shoulder_right);
|
||||
mSimulatedGamepadMap.SHOULDER_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.shoulder_left, R.string.controller_button_shoulder_left);
|
||||
mSimulatedGamepadMap.DIRECTION_FORWARD = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_left, R.string.controller_direction_forward);
|
||||
mSimulatedGamepadMap.DIRECTION_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_left, R.string.controller_direction_right);
|
||||
mSimulatedGamepadMap.DIRECTION_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_left, R.string.controller_direction_left);
|
||||
mSimulatedGamepadMap.DIRECTION_BACKWARD = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_left, R.string.controller_direction_backward);
|
||||
mSimulatedGamepadMap.DIRECTION_FORWARD = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_forward);
|
||||
mSimulatedGamepadMap.DIRECTION_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_right);
|
||||
mSimulatedGamepadMap.DIRECTION_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_left);
|
||||
mSimulatedGamepadMap.DIRECTION_BACKWARD = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right, R.string.controller_direction_backward);
|
||||
mSimulatedGamepadMap.THUMBSTICK_RIGHT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_right_click, R.string.controller_stick_press_r);
|
||||
mSimulatedGamepadMap.THUMBSTICK_LEFT = mRebinderButtons[index++] = new RebinderButton(R.drawable.stick_left_click, R.string.controller_stick_press_l);
|
||||
mSimulatedGamepadMap.DPAD_UP = mRebinderButtons[index++] = new RebinderButton(R.drawable.dpad_up, R.string.controller_dpad_up);
|
||||
@@ -125,9 +125,18 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
||||
return mRebinderButtons.length;
|
||||
}
|
||||
|
||||
private void updateStickIcons() {
|
||||
// Which stick is used for keyboard emulation depends on grab state, so we need
|
||||
// to update the mapper UI icons accordingly
|
||||
int stickIcon = mGrabState ? R.drawable.stick_left : R.drawable.stick_right;
|
||||
((RebinderButton)mSimulatedGamepadMap.DIRECTION_FORWARD).iconResourceId = stickIcon;
|
||||
((RebinderButton)mSimulatedGamepadMap.DIRECTION_BACKWARD).iconResourceId = stickIcon;
|
||||
((RebinderButton)mSimulatedGamepadMap.DIRECTION_RIGHT).iconResourceId = stickIcon;
|
||||
((RebinderButton)mSimulatedGamepadMap.DIRECTION_LEFT).iconResourceId = stickIcon;
|
||||
}
|
||||
|
||||
private class RebinderButton extends GamepadButton {
|
||||
public final int iconResourceId;
|
||||
public int iconResourceId;
|
||||
public final int localeResourceId;
|
||||
private GamepadMapperAdapter.ViewHolder mButtonHolder;
|
||||
|
||||
@@ -222,11 +231,7 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
||||
private void setPressed(boolean pressed) {
|
||||
mClickIndicator.setBackgroundColor(pressed ? Color.GREEN : Color.DKGRAY);
|
||||
}
|
||||
|
||||
private void computeKeycodePosition(short keyCode) {
|
||||
|
||||
}
|
||||
|
||||
private void updateKeycodeLabel() {
|
||||
StringBuilder labelBuilder = new StringBuilder();
|
||||
boolean first = true;
|
||||
@@ -242,17 +247,20 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
|
||||
/*if(mAttachedPosition == -1) return;
|
||||
int[] keycodes = mRealButtons[mAttachedPosition].keycodes;
|
||||
if(keycodes.length < 1) return;
|
||||
int selectedKeycode;
|
||||
if(i < mSpecialKeycodeCount) {
|
||||
selectedKeycode = i - mSpecialKeycodeCount;
|
||||
} else {
|
||||
selectedKeycode = EfficientAndroidLWJGLKeycode.getValueByIndex(i - mSpecialKeycodeCount);
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int selectionIndex, long selectionId) {
|
||||
if(mAttachedPosition == -1) return;
|
||||
short[] keycodes = mRealButtons[mAttachedPosition].keycodes;
|
||||
int editedKeycodeIndex = -1;
|
||||
for(int i = 0; i < mKeySpinners.length && i < keycodes.length; i++) {
|
||||
if(!adapterView.equals(mKeySpinners[i])) continue;
|
||||
editedKeycodeIndex = i;
|
||||
break;
|
||||
}
|
||||
keycodes[0] = selectedKeycode;*/
|
||||
if(editedKeycodeIndex == -1) return;
|
||||
int keycode_offset = selectionIndex - mSpecialKeycodeCount;
|
||||
if(selectionIndex <= mSpecialKeycodeCount) keycodes[editedKeycodeIndex] = (short) (keycode_offset);
|
||||
else keycodes[editedKeycodeIndex] = EfficientAndroidLWJGLKeycode.getValueByIndex(keycode_offset);
|
||||
updateKeycodeLabel();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -308,6 +316,7 @@ public class GamepadMapperAdapter extends RecyclerView.Adapter<GamepadMapperAdap
|
||||
if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState);
|
||||
if(mGrabState == mOldState) return;
|
||||
updateRealButtons();
|
||||
updateStickIcons();
|
||||
notifyDataSetChanged();
|
||||
mOldState = mGrabState;
|
||||
}
|
||||
|
||||
@@ -65,7 +65,7 @@ public class GamepadMapperFragment extends Fragment implements View.OnKeyListene
|
||||
mInputManager = new RemapperManager(view.getContext(), mRemapperViewBuilder);
|
||||
mGrabStateSpinner = view.findViewById(R.id.gamepad_remapper_mode_spinner);
|
||||
ArrayAdapter<String> mGrabStateAdapter = new ArrayAdapter<>(view.getContext(), R.layout.item_centered_textview);
|
||||
mGrabStateAdapter.addAll("INMENU", "INGAME");
|
||||
mGrabStateAdapter.addAll(getString(R.string.customctrl_visibility_in_menus), getString(R.string.customctrl_visibility_ingame));
|
||||
mGrabStateSpinner.setAdapter(mGrabStateAdapter);
|
||||
mGrabStateSpinner.setSelection(0);
|
||||
mGrabStateSpinner.setOnItemSelectedListener(this);
|
||||
|
||||
@@ -483,7 +483,7 @@
|
||||
android:id="@+id/visibility_textview"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="Visibility"
|
||||
android:text="@string/customctrl_visibility_title"
|
||||
app:layout_constraintTop_toBottomOf="@+id/editButtonOpacity_seekbar"
|
||||
tools:layout_editor_absoluteX="6dp" />
|
||||
|
||||
@@ -491,14 +491,14 @@
|
||||
android:id="@+id/visibility_game_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="In game"
|
||||
android:text="@string/customctrl_visibility_ingame"
|
||||
app:layout_constraintTop_toBottomOf="@+id/visibility_textview" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/visibility_menu_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="In Menu"
|
||||
android:text="@string/customctrl_visibility_in_menus"
|
||||
app:layout_constraintTop_toBottomOf="@+id/visibility_game_checkbox" />
|
||||
|
||||
|
||||
|
||||
@@ -6,16 +6,46 @@
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/background_app">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal"
|
||||
app:layout_constraintBottom_toTopOf="@+id/gamepad_remapper_recycler"
|
||||
app:layout_constraintEnd_toStartOf="@+id/guideline4"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent">
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:text="@string/controller_remapper_exit_part1" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/imageView2"
|
||||
android:layout_width="30sp"
|
||||
android:layout_height="30sp"
|
||||
android:layout_gravity="center_vertical"
|
||||
app:srcCompat="@drawable/button_select" />
|
||||
|
||||
<TextView
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center_vertical"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:text="@string/controller_remapper_exit_part2" />
|
||||
</LinearLayout>
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gamepad_remapper_exit_label"
|
||||
android:id="@+id/gamepad_remapper_mode_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="@string/controller_remapper_exit"
|
||||
android:text="@string/controller_remapper_operating_mode"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintBottom_toTopOf="@+id/gamepad_remapper_recycler"
|
||||
app:layout_constraintEnd_toStartOf="@id/guideline4"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/guideline4"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
<androidx.recyclerview.widget.RecyclerView
|
||||
@@ -31,7 +61,7 @@
|
||||
<Spinner
|
||||
android:id="@+id/gamepad_remapper_mode_spinner"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="48dp"
|
||||
android:layout_marginTop="11dp"
|
||||
android:minHeight="48dp"
|
||||
app:layout_constraintEnd_toEndOf="@+id/gamepad_remapper_mode_label"
|
||||
@@ -45,14 +75,6 @@
|
||||
android:orientation="vertical"
|
||||
app:layout_constraintGuide_percent="0.5" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/gamepad_remapper_mode_label"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="8dp"
|
||||
android:text="TextView"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintStart_toEndOf="@id/guideline4"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
|
||||
|
||||
</androidx.constraintlayout.widget.ConstraintLayout>
|
||||
@@ -1,5 +1,5 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<resources xmlns:tools="http://schemas.android.com/tools" tools:ignore="MissingTranslation">
|
||||
<!-- App name part -->
|
||||
<string name="app_name">PojavLauncher (Minecraft: Java Edition for Android)</string>
|
||||
<string name="app_short_name">PojavLauncher</string>
|
||||
@@ -394,15 +394,20 @@
|
||||
<string name="controller_button_trigger_right">Right Trigger</string>
|
||||
<string name="controller_button_shoulder_left">Left Shoulder</string>
|
||||
<string name="controller_button_shoulder_right">Right Shoulder</string>
|
||||
<string name="controller_direction_forward">Walk Forward</string>
|
||||
<string name="controller_direction_backward">Walk Backward</string>
|
||||
<string name="controller_direction_left">Walk Left</string>
|
||||
<string name="controller_direction_right">Walk Right</string>
|
||||
<string name="controller_direction_forward">Stick Up</string>
|
||||
<string name="controller_direction_backward">Stick Down</string>
|
||||
<string name="controller_direction_left">Stick Left</string>
|
||||
<string name="controller_direction_right">Stick Right</string>
|
||||
<string name="controller_stick_press_l">Left Thumbstick (click)</string>
|
||||
<string name="controller_stick_press_r">Right Thumbstick (click)</string>
|
||||
<string name="controller_dpad_up">D-Pad Up</string>
|
||||
<string name="controller_dpad_down">D-Pad Down</string>
|
||||
<string name="controller_dpad_left">D-Pad Left</string>
|
||||
<string name="controller_dpad_right">D-Pad Right</string>
|
||||
<string name="controller_remapper_exit">Hold "Select" to exit</string>
|
||||
<string name="controller_remapper_exit_part1">Hold</string>
|
||||
<string name="controller_remapper_exit_part2">to exit</string>
|
||||
<string name="controller_remapper_operating_mode">Current mode</string>
|
||||
<string name="customctrl_visibility_title">Visibility</string>
|
||||
<string name="customctrl_visibility_ingame">In-game</string>
|
||||
<string name="customctrl_visibility_in_menus">In menus</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user