Fix[editor]: "SPECIAL_" key name stacking up

This commit is contained in:
Mathias-Boulay 2023-03-11 22:22:34 +01:00
parent c8cf5df4e2
commit 64fc29ce3c
2 changed files with 13 additions and 14 deletions

View File

@ -32,7 +32,7 @@ public class ControlData {
public static final int SPECIALBTN_MENU = -9; public static final int SPECIALBTN_MENU = -9;
private static ControlData[] SPECIAL_BUTTONS; private static ControlData[] SPECIAL_BUTTONS;
private static String[] SPECIAL_BUTTON_NAME_ARRAY; private static List<String> SPECIAL_BUTTON_NAME_ARRAY;
// Internal usage only // Internal usage only
public boolean isHideable; public boolean isHideable;
@ -74,13 +74,14 @@ public class ControlData {
return SPECIAL_BUTTONS; return SPECIAL_BUTTONS;
} }
public static String[] buildSpecialButtonArray() { public static List<String> buildSpecialButtonArray() {
if (SPECIAL_BUTTON_NAME_ARRAY == null) { if (SPECIAL_BUTTON_NAME_ARRAY == null) {
List<String> nameList = new ArrayList<String>(); List<String> nameList = new ArrayList<String>();
for (ControlData btn : getSpecialButtons()) { for (ControlData btn : getSpecialButtons()) {
nameList.add(btn.name); nameList.add("SPECIAL_" + btn.name);
} }
SPECIAL_BUTTON_NAME_ARRAY = nameList.toArray(new String[0]); SPECIAL_BUTTON_NAME_ARRAY = nameList;
Collections.reverse(SPECIAL_BUTTON_NAME_ARRAY);
} }
return SPECIAL_BUTTON_NAME_ARRAY; return SPECIAL_BUTTON_NAME_ARRAY;

View File

@ -42,6 +42,7 @@ import net.kdt.pojavlaunch.customcontrols.buttons.ControlInterface;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.List;
/** /**
* Class providing a sort of popup on top of a Layout, allowing to edit a given ControlButton * Class providing a sort of popup on top of a Layout, allowing to edit a given ControlButton
@ -87,7 +88,7 @@ public class EditControlPopup {
protected TextView mStrokePercentTextView, mCornerRadiusPercentTextView, mAlphaPercentTextView; protected TextView mStrokePercentTextView, mCornerRadiusPercentTextView, mAlphaPercentTextView;
protected TextView mSelectBackgroundColor, mSelectStrokeColor; protected TextView mSelectBackgroundColor, mSelectStrokeColor;
protected ArrayAdapter<String> mAdapter; protected ArrayAdapter<String> mAdapter;
protected String[] mSpecialArray; protected List<String> mSpecialArray;
// Decorative textviews // Decorative textviews
private TextView mOrientationTextView, mMappingTextView, mNameTextView, mCornerRadiusTextView; private TextView mOrientationTextView, mMappingTextView, mNameTextView, mCornerRadiusTextView;
@ -215,10 +216,7 @@ public class EditControlPopup {
//Initialize adapter for keycodes //Initialize adapter for keycodes
mAdapter = new ArrayAdapter<>(mRootView.getContext(), R.layout.item_centered_textview); mAdapter = new ArrayAdapter<>(mRootView.getContext(), R.layout.item_centered_textview);
mSpecialArray = ControlData.buildSpecialButtonArray(); mSpecialArray = ControlData.buildSpecialButtonArray();
for (int i = 0; i < mSpecialArray.length; i++) {
mSpecialArray[i] = "SPECIAL_" + mSpecialArray[i];
}
Collections.reverse(Arrays.asList(mSpecialArray));
mAdapter.addAll(mSpecialArray); mAdapter.addAll(mSpecialArray);
mAdapter.addAll(EfficientAndroidLWJGLKeycode.generateKeyName()); mAdapter.addAll(EfficientAndroidLWJGLKeycode.generateKeyName());
mAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice); mAdapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
@ -278,9 +276,9 @@ public class EditControlPopup {
for(int i = 0; i< data.keycodes.length; i++){ for(int i = 0; i< data.keycodes.length; i++){
if (data.keycodes[i] < 0) { if (data.keycodes[i] < 0) {
mKeycodeSpinners[i].setSelection(data.keycodes[i] + mSpecialArray.length); mKeycodeSpinners[i].setSelection(data.keycodes[i] + mSpecialArray.size());
} else { } else {
mKeycodeSpinners[i].setSelection(EfficientAndroidLWJGLKeycode.getIndexByValue(data.keycodes[i]) + mSpecialArray.length); mKeycodeSpinners[i].setSelection(EfficientAndroidLWJGLKeycode.getIndexByValue(data.keycodes[i]) + mSpecialArray.size());
} }
} }
} }
@ -482,10 +480,10 @@ public class EditControlPopup {
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
// Side note, spinner listeners are fired later than all the other ones. // Side note, spinner listeners are fired later than all the other ones.
// Meaning the internalChanges bool is useless here. // Meaning the internalChanges bool is useless here.
if (position < mSpecialArray.length) { if (position < mSpecialArray.size()) {
mCurrentlyEditedButton.getProperties().keycodes[finalI] = mKeycodeSpinners[finalI].getSelectedItemPosition() - mSpecialArray.length; mCurrentlyEditedButton.getProperties().keycodes[finalI] = mKeycodeSpinners[finalI].getSelectedItemPosition() - mSpecialArray.size();
} else { } else {
mCurrentlyEditedButton.getProperties().keycodes[finalI] = EfficientAndroidLWJGLKeycode.getValueByIndex(mKeycodeSpinners[finalI].getSelectedItemPosition() - mSpecialArray.length); mCurrentlyEditedButton.getProperties().keycodes[finalI] = EfficientAndroidLWJGLKeycode.getValueByIndex(mKeycodeSpinners[finalI].getSelectedItemPosition() - mSpecialArray.size());
} }
} }