Skip to content

Commit

Permalink
Feat[remapper]: improve UI, other changes
Browse files Browse the repository at this point in the history
  • Loading branch information
artdeell committed Aug 22, 2024
1 parent 80c5ea8 commit 0d48477
Show file tree
Hide file tree
Showing 7 changed files with 114 additions and 70 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ public static void execKeyIndex(int index){
sendKeyPress(getValueByIndex(index));
}

public static int getValueByIndex(int index) {
public static short getValueByIndex(int index) {
return sLwjglKeycodes[index];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -100,6 +77,37 @@ public void resetPressedState(){

}

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.
*/
Expand Down Expand Up @@ -191,7 +199,7 @@ public GamepadEmulatedButton[] getButtons(){
* 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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ private void createRebinderMap() {
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);
Expand Down Expand Up @@ -125,9 +125,18 @@ public int getItemCount() {
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;

Expand Down Expand Up @@ -222,11 +231,7 @@ private void detach() {
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;
Expand All @@ -242,17 +247,20 @@ private void updateKeycodeLabel() {
}

@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
Expand Down Expand Up @@ -308,6 +316,7 @@ public void setGrabState(boolean newState) {
if(mGamepadGrabListener != null) mGamepadGrabListener.onGrabState(newState);
if(mGrabState == mOldState) return;
updateRealButtons();
updateStickIcons();
notifyDataSetChanged();
mOldState = mGrabState;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,22 +483,22 @@
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" />

<CheckBox
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" />


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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"
Expand All @@ -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>
17 changes: 11 additions & 6 deletions app_pojavlauncher/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -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>
Expand Down Expand Up @@ -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>

0 comments on commit 0d48477

Please sign in to comment.