mirror of
https://github.com/wheremyfoodat/Panda3DS.git
synced 2025-04-21 12:04:58 +00:00
Add change gamepad positions: part 2
This commit is contained in:
parent
0811e174e3
commit
7c1623c2cf
15 changed files with 163 additions and 160 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.panda3ds.pandroid.app.preferences;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
|
|
|
@ -14,10 +14,10 @@ import androidx.fragment.app.Fragment;
|
|||
import com.panda3ds.pandroid.R;
|
||||
import com.panda3ds.pandroid.app.BaseActivity;
|
||||
import com.panda3ds.pandroid.app.base.BottomAlertDialog;
|
||||
import com.panda3ds.pandroid.view.controller.map.ControllerMapper;
|
||||
import com.panda3ds.pandroid.view.controller.map.ControllerProfileManager;
|
||||
import com.panda3ds.pandroid.view.controller.map.NodeID;
|
||||
import com.panda3ds.pandroid.view.controller.map.Profile;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.ControllerMapper;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.ControllerProfileManager;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.ControllerItem;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.Profile;
|
||||
|
||||
public class ControllerMapperPreferences extends Fragment {
|
||||
|
||||
|
@ -47,13 +47,13 @@ public class ControllerMapperPreferences extends Fragment {
|
|||
BottomAlertDialog builder = new BottomAlertDialog(v.getContext());
|
||||
builder.setTitle("Visibility");
|
||||
boolean[] visibleList = {
|
||||
currentProfile.isVisible(NodeID.START),
|
||||
currentProfile.isVisible(NodeID.SELECT),
|
||||
currentProfile.isVisible(NodeID.L),
|
||||
currentProfile.isVisible(NodeID.R),
|
||||
currentProfile.isVisible(NodeID.DPAD),
|
||||
currentProfile.isVisible(NodeID.JOYSTICK),
|
||||
currentProfile.isVisible(NodeID.GAMEPAD),
|
||||
currentProfile.isVisible(ControllerItem.START),
|
||||
currentProfile.isVisible(ControllerItem.SELECT),
|
||||
currentProfile.isVisible(ControllerItem.L),
|
||||
currentProfile.isVisible(ControllerItem.R),
|
||||
currentProfile.isVisible(ControllerItem.DPAD),
|
||||
currentProfile.isVisible(ControllerItem.JOYSTICK),
|
||||
currentProfile.isVisible(ControllerItem.GAMEPAD),
|
||||
};
|
||||
builder.setMultiChoiceItems(new CharSequence[]{
|
||||
"Start", "Select", "L", "R", "Dpad", getString(R.string.axis), "A/B/X/Y"
|
||||
|
@ -63,13 +63,13 @@ public class ControllerMapperPreferences extends Fragment {
|
|||
|
||||
saveButton.setVisibility(View.VISIBLE);
|
||||
|
||||
currentProfile.setVisible(NodeID.START, visibleList[0]);
|
||||
currentProfile.setVisible(NodeID.SELECT, visibleList[1]);
|
||||
currentProfile.setVisible(NodeID.L, visibleList[2]);
|
||||
currentProfile.setVisible(NodeID.R, visibleList[3]);
|
||||
currentProfile.setVisible(NodeID.DPAD, visibleList[4]);
|
||||
currentProfile.setVisible(NodeID.JOYSTICK, visibleList[5]);
|
||||
currentProfile.setVisible(NodeID.GAMEPAD, visibleList[6]);
|
||||
currentProfile.setVisible(ControllerItem.START, visibleList[0]);
|
||||
currentProfile.setVisible(ControllerItem.SELECT, visibleList[1]);
|
||||
currentProfile.setVisible(ControllerItem.L, visibleList[2]);
|
||||
currentProfile.setVisible(ControllerItem.R, visibleList[3]);
|
||||
currentProfile.setVisible(ControllerItem.DPAD, visibleList[4]);
|
||||
currentProfile.setVisible(ControllerItem.JOYSTICK, visibleList[5]);
|
||||
currentProfile.setVisible(ControllerItem.GAMEPAD, visibleList[6]);
|
||||
|
||||
mapper.refreshLayout();
|
||||
}).setNegativeButton(android.R.string.cancel, (dialog, which) -> dialog.dismiss());
|
||||
|
@ -88,8 +88,8 @@ public class ControllerMapperPreferences extends Fragment {
|
|||
requireActivity().finish();
|
||||
});
|
||||
|
||||
view.findViewById(R.id.rotate).setOnClickListener(v->{
|
||||
requireActivity().setRequestedOrientation(mapper.getCurrentWidth() > mapper.getCurrentHeight() ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||
view.findViewById(R.id.rotate).setOnClickListener(v -> {
|
||||
requireActivity().setRequestedOrientation(mapper.getCurrentWidth() > mapper.getCurrentHeight() ? ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT : ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
||||
});
|
||||
|
||||
view.findViewById(R.id.delete).setVisibility(ControllerProfileManager.getProfileCount() > 1 ? View.VISIBLE : View.GONE);
|
||||
|
@ -97,7 +97,7 @@ public class ControllerMapperPreferences extends Fragment {
|
|||
saveButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
public void onLocationChanged(NodeID id) {
|
||||
public void onLocationChanged(ControllerItem id) {
|
||||
saveButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,12 +1,9 @@
|
|||
package com.panda3ds.pandroid.app.preferences;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Activity;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.preference.Preference;
|
||||
import androidx.preference.PreferenceCategory;
|
||||
|
@ -16,18 +13,24 @@ import com.panda3ds.pandroid.app.BaseActivity;
|
|||
import com.panda3ds.pandroid.app.PreferenceActivity;
|
||||
import com.panda3ds.pandroid.app.base.BasePreferenceFragment;
|
||||
import com.panda3ds.pandroid.app.base.BottomAlertDialog;
|
||||
import com.panda3ds.pandroid.view.controller.map.ControllerProfileManager;
|
||||
import com.panda3ds.pandroid.view.controller.map.Profile;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.ControllerProfileManager;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.Profile;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
public class InputPreferences extends BasePreferenceFragment {
|
||||
|
||||
public static final String ID_DEFAULT_CONTROLLER_PROFILE = "defaultControllerProfile";
|
||||
public static final String ID_INPUT_MAP = "inputMap";
|
||||
public static final String ID_CREATE_PROFILE = "createProfile";
|
||||
private static final CharSequence ID_GAMEPAD_PROFILE_LIST = "gamepadProfileList";
|
||||
|
||||
@Override
|
||||
public void onCreatePreferences(@Nullable Bundle savedInstanceState, @Nullable String rootKey) {
|
||||
setPreferencesFromResource(R.xml.input_preference, rootKey);
|
||||
setItemClick("inputMap", (item) -> PreferenceActivity.launch(requireContext(), InputMapPreferences.class));
|
||||
setItemClick("add_screen_profile", (item) -> {
|
||||
setItemClick(ID_INPUT_MAP, (item) -> PreferenceActivity.launch(requireContext(), InputMapPreferences.class));
|
||||
setItemClick(ID_CREATE_PROFILE, (item) -> {
|
||||
new BottomAlertDialog(requireContext())
|
||||
.setTextInput(getString(R.string.name), (name) -> {
|
||||
name = formatName(name);
|
||||
|
@ -40,33 +43,26 @@ public class InputPreferences extends BasePreferenceFragment {
|
|||
}).setTitle(R.string.create_profile).show();
|
||||
});
|
||||
|
||||
setItemClick("defaultControllerProfile", (item)->{
|
||||
setItemClick(ID_DEFAULT_CONTROLLER_PROFILE, (item) -> {
|
||||
List<Profile> profiles = ControllerProfileManager.listAll();
|
||||
String defaultProfileId = ControllerProfileManager.getDefaultProfile().getId();
|
||||
int defaultProfileIndex = 0;
|
||||
CharSequence[] names = new CharSequence[profiles.size()];
|
||||
for (int i = 0; i < names.length; i++){
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
names[i] = profiles.get(i).getName();
|
||||
if (Objects.equals(profiles.get(i).getId(), defaultProfileId)){
|
||||
if (Objects.equals(profiles.get(i).getId(), defaultProfileId)) {
|
||||
defaultProfileIndex = i;
|
||||
}
|
||||
}
|
||||
new BottomAlertDialog(item.getContext())
|
||||
.setSingleChoiceItems(names, defaultProfileIndex, (dialog, which) -> {
|
||||
dialog.dismiss();
|
||||
ControllerProfileManager.setDefaultId(profiles.get(which).getId());
|
||||
ControllerProfileManager.setDefaultProfileId(profiles.get(which).getId());
|
||||
item.setSummary(profiles.get(which).getName());
|
||||
}).setTitle(R.string.pref_default_controller_title).show();
|
||||
});
|
||||
|
||||
((BaseActivity)requireActivity()).getSupportActionBar().setTitle(R.string.input);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refresh();
|
||||
((BaseActivity) requireActivity()).getSupportActionBar().setTitle(R.string.input);
|
||||
}
|
||||
|
||||
public String formatName(String name) {
|
||||
|
@ -82,13 +78,13 @@ public class InputPreferences extends BasePreferenceFragment {
|
|||
}
|
||||
|
||||
private void refresh() {
|
||||
findPreference("defaultControllerProfile").setSummary(ControllerProfileManager.getDefaultProfile().getName());
|
||||
findPreference(ID_DEFAULT_CONTROLLER_PROFILE).setSummary(ControllerProfileManager.getDefaultProfile().getName());
|
||||
refreshScreenProfileList();
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
private void refreshScreenProfileList() {
|
||||
PreferenceCategory category = findPreference("screenGamepadProfiles");
|
||||
PreferenceCategory category = findPreference(ID_GAMEPAD_PROFILE_LIST);
|
||||
Preference add = category.getPreference(category.getPreferenceCount() - 1);
|
||||
category.removeAll();
|
||||
category.setOrderingAsAdded(true);
|
||||
|
@ -109,4 +105,10 @@ public class InputPreferences extends BasePreferenceFragment {
|
|||
add.setOrder(category.getPreferenceCount());
|
||||
category.addPreference(add);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
refresh();
|
||||
}
|
||||
}
|
|
@ -25,5 +25,5 @@ public class Constants {
|
|||
public static final String PREF_GLOBAL_CONFIG = "app.GlobalConfig";
|
||||
public static final String PREF_GAME_UTILS = "app.GameUtils";
|
||||
public static final String PREF_INPUT_MAP = "app.InputMap";
|
||||
public static final String PREF_SCREEN_CONTROLLER_PROFILES = "app.input.overlay";
|
||||
public static final String PREF_SCREEN_CONTROLLER_PROFILES = "app.input.ScreenControllerManager";
|
||||
}
|
||||
|
|
|
@ -6,9 +6,9 @@ import com.panda3ds.pandroid.AlberDriver;
|
|||
import com.panda3ds.pandroid.R;
|
||||
import com.panda3ds.pandroid.utils.Constants;
|
||||
import com.panda3ds.pandroid.view.controller.ControllerLayout;
|
||||
import com.panda3ds.pandroid.view.controller.map.ControllerProfileManager;
|
||||
import com.panda3ds.pandroid.view.controller.map.NodeID;
|
||||
import com.panda3ds.pandroid.view.controller.map.Profile;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.ControllerProfileManager;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.ControllerItem;
|
||||
import com.panda3ds.pandroid.view.controller.mapping.Profile;
|
||||
import com.panda3ds.pandroid.view.controller.nodes.Button;
|
||||
import com.panda3ds.pandroid.view.controller.nodes.Joystick;
|
||||
|
||||
|
@ -68,12 +68,12 @@ public class PandaLayoutController extends ControllerLayout {
|
|||
|
||||
private void applyProfileMap() {
|
||||
Profile profile = ControllerProfileManager.getDefaultProfile();
|
||||
profile.applyToView(NodeID.L,findViewById(R.id.button_l), width, height);
|
||||
profile.applyToView(NodeID.R, findViewById(R.id.button_r), width, height);
|
||||
profile.applyToView(NodeID.START, findViewById(R.id.button_start), width, height);
|
||||
profile.applyToView(NodeID.SELECT, findViewById(R.id.button_select), width, height);
|
||||
profile.applyToView(NodeID.JOYSTICK, findViewById(R.id.left_analog), width, height);
|
||||
profile.applyToView(NodeID.GAMEPAD, findViewById(R.id.gamepad), width, height);
|
||||
profile.applyToView(NodeID.DPAD, findViewById(R.id.dpad), width, height);
|
||||
profile.applyToView(ControllerItem.L,findViewById(R.id.button_l), width, height);
|
||||
profile.applyToView(ControllerItem.R, findViewById(R.id.button_r), width, height);
|
||||
profile.applyToView(ControllerItem.START, findViewById(R.id.button_start), width, height);
|
||||
profile.applyToView(ControllerItem.SELECT, findViewById(R.id.button_select), width, height);
|
||||
profile.applyToView(ControllerItem.JOYSTICK, findViewById(R.id.left_analog), width, height);
|
||||
profile.applyToView(ControllerItem.GAMEPAD, findViewById(R.id.gamepad), width, height);
|
||||
profile.applyToView(ControllerItem.DPAD, findViewById(R.id.dpad), width, height);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
package com.panda3ds.pandroid.view.controller.map;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Layout {
|
||||
private final Map<NodeID, Location> mapLocations = new HashMap<>();
|
||||
public void setLocation(NodeID id, Location location) {
|
||||
mapLocations.put(id, location);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location getLocation(NodeID id) {
|
||||
if (!mapLocations.containsKey(id)) {
|
||||
setLocation(id, new Location());
|
||||
}
|
||||
return Objects.requireNonNull(mapLocations.get(id));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Layout clone() {
|
||||
Layout cloned = new Layout();
|
||||
for (NodeID key : mapLocations.keySet()){
|
||||
cloned.setLocation(key, getLocation(key).clone());
|
||||
}
|
||||
return cloned;
|
||||
}
|
||||
}
|
|
@ -1,9 +0,0 @@
|
|||
package com.panda3ds.pandroid.view.controller.map;
|
||||
|
||||
public enum NodeID {
|
||||
START,
|
||||
SELECT,
|
||||
L,R,
|
||||
GAMEPAD,
|
||||
DPAD, JOYSTICK
|
||||
}
|
|
@ -0,0 +1,9 @@
|
|||
package com.panda3ds.pandroid.view.controller.mapping;
|
||||
|
||||
public enum ControllerItem {
|
||||
START,
|
||||
SELECT,
|
||||
L,R,
|
||||
GAMEPAD,
|
||||
DPAD, JOYSTICK
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.panda3ds.pandroid.view.controller.map;
|
||||
package com.panda3ds.pandroid.view.controller.mapping;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
@ -28,7 +28,7 @@ public class ControllerMapper extends FrameLayout {
|
|||
private final Paint selectionPaint = new Paint(Paint.ANTI_ALIAS_FLAG);
|
||||
private int width = -1;
|
||||
private int height = -1;
|
||||
private Function<NodeID> changeListener;
|
||||
private Function<ControllerItem> changeListener;
|
||||
|
||||
public ControllerMapper(@NonNull Context context) {
|
||||
this(context, null);
|
||||
|
@ -53,19 +53,19 @@ public class ControllerMapper extends FrameLayout {
|
|||
selectionPaint.setPathEffect(new DashPathEffect(new float[]{dp * 10, dp * 10}, 0.0f));
|
||||
}
|
||||
|
||||
public void initialize(Function<NodeID> changeListener, Profile profile) {
|
||||
public void initialize(Function<ControllerItem> changeListener, Profile profile) {
|
||||
this.profile = profile;
|
||||
this.changeListener = changeListener;
|
||||
|
||||
measure(MeasureSpec.EXACTLY, MeasureSpec.EXACTLY);
|
||||
|
||||
new MoveElementListener(NodeID.L, findViewById(R.id.button_l));
|
||||
new MoveElementListener(NodeID.R, findViewById(R.id.button_r));
|
||||
new MoveElementListener(NodeID.START, findViewById(R.id.button_start));
|
||||
new MoveElementListener(NodeID.SELECT, findViewById(R.id.button_select));
|
||||
new MoveElementListener(NodeID.DPAD, findViewById(R.id.dpad));
|
||||
new MoveElementListener(NodeID.GAMEPAD, findViewById(R.id.gamepad));
|
||||
new MoveElementListener(NodeID.JOYSTICK, findViewById(R.id.left_analog));
|
||||
new MoveElementListener(ControllerItem.L, findViewById(R.id.button_l));
|
||||
new MoveElementListener(ControllerItem.R, findViewById(R.id.button_r));
|
||||
new MoveElementListener(ControllerItem.START, findViewById(R.id.button_start));
|
||||
new MoveElementListener(ControllerItem.SELECT, findViewById(R.id.button_select));
|
||||
new MoveElementListener(ControllerItem.DPAD, findViewById(R.id.dpad));
|
||||
new MoveElementListener(ControllerItem.GAMEPAD, findViewById(R.id.gamepad));
|
||||
new MoveElementListener(ControllerItem.JOYSTICK, findViewById(R.id.left_analog));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,13 +134,13 @@ public class ControllerMapper extends FrameLayout {
|
|||
|
||||
public void refreshLayout() {
|
||||
if (profile != null) {
|
||||
profile.applyToView(NodeID.L, findViewById(R.id.button_l), width, height);
|
||||
profile.applyToView(NodeID.R, findViewById(R.id.button_r), width, height);
|
||||
profile.applyToView(NodeID.START, findViewById(R.id.button_start), width, height);
|
||||
profile.applyToView(NodeID.SELECT, findViewById(R.id.button_select), width, height);
|
||||
profile.applyToView(NodeID.DPAD, findViewById(R.id.dpad), width, height);
|
||||
profile.applyToView(NodeID.GAMEPAD, findViewById(R.id.gamepad), width, height);
|
||||
profile.applyToView(NodeID.JOYSTICK, findViewById(R.id.left_analog), width, height);
|
||||
profile.applyToView(ControllerItem.L, findViewById(R.id.button_l), width, height);
|
||||
profile.applyToView(ControllerItem.R, findViewById(R.id.button_r), width, height);
|
||||
profile.applyToView(ControllerItem.START, findViewById(R.id.button_start), width, height);
|
||||
profile.applyToView(ControllerItem.SELECT, findViewById(R.id.button_select), width, height);
|
||||
profile.applyToView(ControllerItem.DPAD, findViewById(R.id.dpad), width, height);
|
||||
profile.applyToView(ControllerItem.GAMEPAD, findViewById(R.id.gamepad), width, height);
|
||||
profile.applyToView(ControllerItem.JOYSTICK, findViewById(R.id.left_analog), width, height);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -153,12 +153,12 @@ public class ControllerMapper extends FrameLayout {
|
|||
}
|
||||
|
||||
public class MoveElementListener implements OnTouchListener {
|
||||
private final NodeID id;
|
||||
private final ControllerItem id;
|
||||
private final View view;
|
||||
private final Vector2 downPosition = new Vector2(0.0f, 0.0f);
|
||||
private boolean down = false;
|
||||
|
||||
public MoveElementListener(NodeID id, View view) {
|
||||
public MoveElementListener(ControllerItem id, View view) {
|
||||
this.view = view;
|
||||
this.id = id;
|
||||
this.view.setOnTouchListener(this);
|
||||
|
@ -181,7 +181,7 @@ public class ControllerMapper extends FrameLayout {
|
|||
profile.setLocation(id, x, y, width, height);
|
||||
profile.applyToView(id, view, width, height);
|
||||
|
||||
if(changeListener != null){
|
||||
if (changeListener != null) {
|
||||
changeListener.run(id);
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
package com.panda3ds.pandroid.view.controller.map;
|
||||
package com.panda3ds.pandroid.view.controller.mapping;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.view.Gravity;
|
||||
|
@ -19,35 +19,35 @@ public class ControllerProfileManager {
|
|||
private static final DataModel data;
|
||||
|
||||
static {
|
||||
parser = new GsonConfigParser(Constants.PREF_SCREEN_CONTROLLER_PROFILES);
|
||||
parser = new GsonConfigParser(Constants.PREF_SCREEN_CONTROLLER_PROFILES);
|
||||
data = parser.load(DataModel.class);
|
||||
if (data.profiles.size() == 0){
|
||||
if (data.profiles.size() == 0) {
|
||||
add(makeDefaultProfile());
|
||||
}
|
||||
}
|
||||
|
||||
public static void remove(String id){
|
||||
public static void remove(String id) {
|
||||
data.profiles.remove(id);
|
||||
save();
|
||||
}
|
||||
|
||||
public static void add(Profile profile){
|
||||
public static void add(Profile profile) {
|
||||
data.profiles.put(profile.getId(), profile);
|
||||
save();
|
||||
}
|
||||
|
||||
public static List<Profile> listAll(){
|
||||
public static List<Profile> listAll() {
|
||||
return new ArrayList<>(data.profiles.values());
|
||||
}
|
||||
|
||||
public static int getProfileCount(){
|
||||
public static int getProfileCount() {
|
||||
return data.profiles.size();
|
||||
}
|
||||
|
||||
public static Profile getDefaultProfile(){
|
||||
if (data.profiles.containsKey(data.profileId)){
|
||||
public static Profile getDefaultProfile() {
|
||||
if (data.profiles.containsKey(data.profileId)) {
|
||||
return data.profiles.get(data.profileId);
|
||||
} else if (getProfileCount() > 0){
|
||||
} else if (getProfileCount() > 0) {
|
||||
data.profileId = data.profiles.keySet().iterator().next();
|
||||
save();
|
||||
return getDefaultProfile();
|
||||
|
@ -57,36 +57,40 @@ public class ControllerProfileManager {
|
|||
}
|
||||
}
|
||||
|
||||
private static void save(){
|
||||
if ((!data.profiles.containsKey(data.profileId)) && getProfileCount() > 0){
|
||||
private static void save() {
|
||||
if ((!data.profiles.containsKey(data.profileId)) && getProfileCount() > 0) {
|
||||
data.profileId = data.profiles.keySet().iterator().next();
|
||||
}
|
||||
parser.save(data);
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
public static Profile makeDefaultProfile() {
|
||||
return new Profile(UUID.randomUUID().toString(), "Default", createDefaultLayout(), createDefaultLayout());
|
||||
}
|
||||
|
||||
@SuppressLint("RtlHardcoded")
|
||||
public static Layout createDefaultLayout() {
|
||||
Layout layout = new Layout();
|
||||
|
||||
layout.setLocation(NodeID.L, new Location(39, 145, Gravity.LEFT, true));
|
||||
layout.setLocation(NodeID.R, new Location(39, 145, Gravity.RIGHT, true));
|
||||
layout.setLocation(ControllerItem.L, new Location(39, 145, Gravity.LEFT, true));
|
||||
layout.setLocation(ControllerItem.R, new Location(39, 145, Gravity.RIGHT, true));
|
||||
|
||||
layout.setLocation(NodeID.SELECT, new Location(32, 131, Gravity.LEFT, true));
|
||||
layout.setLocation(NodeID.START, new Location(32, 131, Gravity.RIGHT, true));
|
||||
layout.setLocation(ControllerItem.SELECT, new Location(32, 131, Gravity.LEFT, true));
|
||||
layout.setLocation(ControllerItem.START, new Location(32, 131, Gravity.RIGHT, true));
|
||||
|
||||
layout.setLocation(NodeID.DPAD, new Location(42, 90, Gravity.LEFT, true));
|
||||
layout.setLocation(NodeID.JOYSTICK, new Location(74, 45, Gravity.LEFT, true));
|
||||
layout.setLocation(NodeID.GAMEPAD, new Location(42, 75, Gravity.RIGHT, true));
|
||||
layout.setLocation(ControllerItem.DPAD, new Location(42, 90, Gravity.LEFT, true));
|
||||
layout.setLocation(ControllerItem.JOYSTICK, new Location(74, 45, Gravity.LEFT, true));
|
||||
layout.setLocation(ControllerItem.GAMEPAD, new Location(42, 75, Gravity.RIGHT, true));
|
||||
|
||||
return new Profile(UUID.randomUUID().toString(),"Default",layout, layout);
|
||||
return layout;
|
||||
}
|
||||
|
||||
public static Profile get(String profile) {
|
||||
return data.profiles.getOrDefault(profile, null);
|
||||
}
|
||||
|
||||
public static void setDefaultId(String id) {
|
||||
if (data.profiles.containsKey(id) && !Objects.equals(id, data.profileId)){
|
||||
public static void setDefaultProfileId(String id) {
|
||||
if (data.profiles.containsKey(id) && !Objects.equals(id, data.profileId)) {
|
||||
data.profileId = id;
|
||||
save();
|
||||
}
|
|
@ -0,0 +1,36 @@
|
|||
package com.panda3ds.pandroid.view.controller.mapping;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
|
||||
public class Layout {
|
||||
private final Map<ControllerItem, Location> mapLocations = new HashMap<>();
|
||||
|
||||
public void setLocation(ControllerItem item, Location location) {
|
||||
mapLocations.put(item, location);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public Location getLocation(ControllerItem item) {
|
||||
if (!mapLocations.containsKey(item)) {
|
||||
setLocation(item, new Location());
|
||||
}
|
||||
return Objects.requireNonNull(mapLocations.get(item));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public Layout clone() {
|
||||
Layout cloned = new Layout();
|
||||
for (ControllerItem key : mapLocations.keySet()) {
|
||||
cloned.setLocation(key, getLocation(key).clone());
|
||||
}
|
||||
return cloned;
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.panda3ds.pandroid.view.controller.map;
|
||||
package com.panda3ds.pandroid.view.controller.mapping;
|
||||
|
||||
import android.view.Gravity;
|
||||
|
||||
|
@ -55,4 +55,4 @@ public class Location {
|
|||
return new Location(x, y, gravity, visible);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package com.panda3ds.pandroid.view.controller.map;
|
||||
package com.panda3ds.pandroid.view.controller.mapping;
|
||||
|
||||
import android.view.Gravity;
|
||||
import android.view.View;
|
||||
|
@ -17,10 +17,6 @@ public class Profile {
|
|||
private final Layout portraitLayout;
|
||||
private String name;
|
||||
|
||||
public Profile() {
|
||||
this(UUID.randomUUID().toString(), PandroidApplication.getAppContext().getString(R.string.unknown), new Layout(), new Layout());
|
||||
}
|
||||
|
||||
public Profile(String id, String name, Layout landscape, Layout portrait) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
|
@ -28,7 +24,7 @@ public class Profile {
|
|||
this.portraitLayout = portrait;
|
||||
}
|
||||
|
||||
public void applyToView(NodeID id, View view, int viewportWidth, int viewportHeight) {
|
||||
public void applyToView(ControllerItem id, View view, int viewportWidth, int viewportHeight) {
|
||||
float pt = view.getResources().getDimension(R.dimen.SizePt);
|
||||
|
||||
int width = view.getLayoutParams().width;
|
||||
|
@ -43,7 +39,7 @@ public class Profile {
|
|||
int y = Math.round(location.getY() * pt);
|
||||
|
||||
params.gravity = location.getGravity() | Gravity.BOTTOM;
|
||||
params.bottomMargin = Math.max(Math.min(y - (height / 2), viewportHeight-height), 0);
|
||||
params.bottomMargin = Math.max(Math.min(y - (height / 2), viewportHeight - height), 0);
|
||||
|
||||
int gravity = location.getGravity() & Gravity.HORIZONTAL_GRAVITY_MASK;
|
||||
if (gravity == Gravity.RIGHT) {
|
||||
|
@ -56,11 +52,11 @@ public class Profile {
|
|||
view.setLayoutParams(params);
|
||||
}
|
||||
|
||||
public void setLocation(NodeID id, int x, int y, int viewportWidth, int viewportHeight) {
|
||||
public void setLocation(ControllerItem item, int x, int y, int viewportWidth, int viewportHeight) {
|
||||
float pt = PandroidApplication.getAppContext().getResources().getDimension(R.dimen.SizePt);
|
||||
|
||||
Layout layout = getLayoutBySize(viewportWidth, viewportHeight);
|
||||
Location location = layout.getLocation(id);
|
||||
Location location = layout.getLocation(item);
|
||||
|
||||
y = viewportHeight - y;
|
||||
|
||||
|
@ -68,7 +64,7 @@ public class Profile {
|
|||
location.setGravity(Gravity.LEFT);
|
||||
location.setPosition(x / pt, y / pt);
|
||||
} else {
|
||||
x = (viewportWidth/2) - (x - (viewportWidth / 2));
|
||||
x = (viewportWidth / 2) - (x - (viewportWidth / 2));
|
||||
location.setGravity(Gravity.RIGHT);
|
||||
location.setPosition(x / pt, y / pt);
|
||||
}
|
||||
|
@ -79,10 +75,11 @@ public class Profile {
|
|||
this.name = name;
|
||||
}
|
||||
|
||||
public void setVisible(NodeID id, boolean visible) {
|
||||
public void setVisible(ControllerItem id, boolean visible) {
|
||||
landscapeLayout.getLocation(id).setVisible(visible);
|
||||
portraitLayout.getLocation(id).setVisible(visible);
|
||||
}
|
||||
|
||||
private Layout getLayoutBySize(int width, int height) {
|
||||
return width > height ? landscapeLayout : portraitLayout;
|
||||
}
|
||||
|
@ -101,7 +98,7 @@ public class Profile {
|
|||
return new Profile(id, name, landscapeLayout.clone(), portraitLayout.clone());
|
||||
}
|
||||
|
||||
public boolean isVisible(NodeID id) {
|
||||
public boolean isVisible(ControllerItem id) {
|
||||
return landscapeLayout.getLocation(id).isVisible();
|
||||
}
|
||||
}
|
|
@ -5,7 +5,7 @@
|
|||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
|
||||
<com.panda3ds.pandroid.view.controller.map.ControllerMapper
|
||||
<com.panda3ds.pandroid.view.controller.mapping.ControllerMapper
|
||||
android:id="@+id/mapper"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent">
|
||||
|
@ -26,7 +26,7 @@
|
|||
|
||||
</FrameLayout>
|
||||
|
||||
</com.panda3ds.pandroid.view.controller.map.ControllerMapper>
|
||||
</com.panda3ds.pandroid.view.controller.mapping.ControllerMapper>
|
||||
|
||||
<androidx.appcompat.widget.LinearLayoutCompat
|
||||
android:layout_width="wrap_content"
|
||||
|
|
|
@ -15,12 +15,12 @@
|
|||
android:summary="-"/>
|
||||
|
||||
<PreferenceCategory
|
||||
android:key="screenGamepadProfiles"
|
||||
android:key="gamepadProfileList"
|
||||
android:title="@string/pref_screen_controllers_title"
|
||||
app:iconSpaceReserved="false">
|
||||
|
||||
<Preference
|
||||
android:key="add_screen_profile"
|
||||
android:key="createProfile"
|
||||
app:icon="@drawable/ic_add"
|
||||
app:title="@string/create_profile"
|
||||
app:allowDividerBelow="true"
|
||||
|
|
Loading…
Add table
Reference in a new issue