From c72ad23ad717471c6a8ca1ce9c55da11a63d410b Mon Sep 17 00:00:00 2001 From: Scrappers Date: Mon, 19 Jul 2021 21:38:08 -0500 Subject: [PATCH] fix for uiPager sort/search, added PageDataModel & some fields refractors for GamePadButtons & the speedometer --- .idea/.name | 1 + .../gamePad/ControlButtonsView.java | 157 ++++++++++------- .../menuStates/UiStateManager.java | 25 ++- .../menuStates/uiPager/ActionInjector.java | 2 +- .../menuStates/uiPager/PageDataModel.java | 7 + .../menuStates/uiPager/UiPager.java | 163 +++++++++--------- .../{misc => vehicles}/DrivingWheelView.java | 132 +++++--------- .../{misc => vehicles}/GullWing.java | 20 +-- .../{misc => vehicles}/Tachometer.java | 2 +- .../{misc => vehicles}/UTurnView.java | 7 +- .../JmESurfaceViewExample.java | 22 ++- .../UiTestCase.java | 39 +++-- .../myGame/JmEGamePadExample/GameStick.java | 6 +- .../com/myGame/JmEGamePadExample/JmeGame.java | 59 ++++--- .../src/main/res/layout/activity_example.xml | 2 +- 15 files changed, 332 insertions(+), 312 deletions(-) create mode 100644 .idea/.name create mode 100644 SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/PageDataModel.java rename SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/{misc => vehicles}/DrivingWheelView.java (84%) rename SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/{misc => vehicles}/GullWing.java (90%) rename SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/{misc => vehicles}/Tachometer.java (94%) rename SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/{misc => vehicles}/UTurnView.java (95%) diff --git a/.idea/.name b/.idea/.name new file mode 100644 index 0000000..a77adcb --- /dev/null +++ b/.idea/.name @@ -0,0 +1 @@ +SuperiorExtendedEngine \ No newline at end of file diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/gamePad/ControlButtonsView.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/gamePad/ControlButtonsView.java index 6d9aafe..88a6201 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/gamePad/ControlButtonsView.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/gamePad/ControlButtonsView.java @@ -15,42 +15,68 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RelativeLayout; - import com.scrappers.GamePad.R; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; public class ControlButtonsView extends RelativeLayout { - public static final int GAMEPAD_BUTTON_X = 'X'; - public static final int GAMEPAD_BUTTON_Y = 'Y'; - public static final int GAMEPAD_BUTTON_A = 'A'; - public static final int GAMEPAD_BUTTON_B = 'B'; - public static final int DEFAULT_GAMEPAD_DOMAIN=R.drawable.gamepad_domain; - public static final int DEFAULT_COLOR_STICK_DOMAIN=R.drawable.moving_stick_domain; - public static final int FLIPPED_COLOR_STICK_DOMAIN=R.drawable.moving_stick_flipped_domain; - public static final int OPACIFIED_COLOR_STICK_DOMAIN=R.drawable.opacified_domain; - public static final int NOTHING_IMAGE=R.drawable.nothing; - public static final int DEFAULT_BUTTONS=R.drawable.moving_stick; - public static final int CRYSTAL_BUTTONS= R.drawable.crystal_buttons; - public static final int CRYSTAL_QUADS=R.drawable.crystal_buttons_quad; - public static final int MATERIALISTIC_BUTTONS=R.drawable.material_buttons; - public static final int MATERIALISTIC_QUADS=R.drawable.material_buttons_quad; - public static final int TEAL_HEXAS=R.drawable.teal_hexagons; - public static final int TRIS_BUTTONS=R.drawable.tris_buttons; - public static final int X_BUTTON_ALPHA=R.drawable.x_button_alpha; - public static final int X_BUTTON_OUTLINE=R.drawable.x_button_outline; - public static final int Y_BUTTON_ALPHA=R.drawable.y_button_alpha; - public static final int Y_BUTTON_OUTLINE=R.drawable.y_button_outline; - public static final int A_BUTTON_ALPHA=R.drawable.a_button_alpha; - public static final int A_BUTTON_OUTLINE=R.drawable.a_button_outline; - public static final int B_BUTTON_ALPHA=R.drawable.b_button_alpha; - public static final int B_BUTTON_OUTLINE=R.drawable.b_button_outline; - public static final int STICK_DASHES=R.drawable.stick_dash; + /** + * Grouping up the ButtonSignatures. + * @author pavl_g + */ + public enum ButtonSignature { + GAMEPAD_BUTTON_X('X', "X"), + GAMEPAD_BUTTON_Y('Y', "Y"), + GAMEPAD_BUTTON_A('A', "A"), + GAMEPAD_BUTTON_B('B', "B"); + public final int ID; + public String NAME; + ButtonSignature(final int ID){ + this.ID = ID; + } + ButtonSignature(final int ID, final String NAME){ + this.ID = ID; + this.NAME = NAME; + } + } + + /** + * Grouping up the ButtonIcons. + * @author pavl_g + */ + public enum ButtonIcon { + X_BUTTON_ALPHA(R.drawable.x_button_alpha), X_BUTTON_OUTLINE(R.drawable.x_button_outline), + Y_BUTTON_ALPHA(R.drawable.y_button_alpha), Y_BUTTON_OUTLINE(R.drawable.y_button_outline), + A_BUTTON_ALPHA(R.drawable.a_button_alpha), A_BUTTON_OUTLINE(R.drawable.a_button_outline), + B_BUTTON_ALPHA(R.drawable.b_button_alpha), B_BUTTON_OUTLINE(R.drawable.b_button_outline); + public final int ID; + + ButtonIcon(final int ID){ + this.ID = ID; + } + } + + /** + * Grouping up the ButtonsStyles. + * @author pavl_g + */ + public enum ButtonStyle { + DEFAULT_GAMEPAD_DOMAIN(R.drawable.gamepad_domain), DEFAULT_COLOR_STICK_DOMAIN(R.drawable.moving_stick_domain), + FLIPPED_COLOR_STICK_DOMAIN(R.drawable.moving_stick_flipped_domain), OPACIFIED_COLOR_STICK_DOMAIN(R.drawable.opacified_domain), + NOTHING_IMAGE(R.drawable.nothing), DEFAULT_BUTTONS(R.drawable.moving_stick), CRYSTAL_BUTTONS(R.drawable.crystal_buttons), + CRYSTAL_QUADS(R.drawable.crystal_buttons_quad), MATERIALISTIC_BUTTONS(R.drawable.material_buttons), + TEAL_HEXAS(R.drawable.teal_hexagons), TRIS_BUTTONS(R.drawable.tris_buttons), STICK_DASHES(R.drawable.stick_dash); + + public final int STYLE; + + ButtonStyle(final int STYLE){ + this.STYLE = STYLE; + } + } public ControlButtonsView(@NonNull Context context, @Nullable AttributeSet attrs) { super(context, attrs); @@ -60,60 +86,63 @@ public ControlButtonsView(@NonNull Context context, @Nullable AttributeSet attrs super(context, attrs, defStyleAttr); } - public ImageView addControlButton(String buttonName,int buttonID, int backgroundDrawable, int drawableIcon){ + /** + * Adds a GamePad button & apply the UI. + * @param button the button to add from the enum #{@link ControlButtonsView.ButtonSignature} : eg : #{@link ButtonSignature#GAMEPAD_BUTTON_X},...etc. + * @param backgroundDrawable the drawable style, you can get some from enum : #{@link ControlButtonsView.ButtonStyle} + * @param drawableIcon the button icon, you can get some from enum : #{@link ControlButtonsView.ButtonIcon} + * @return an imageView instance representing the added button. + */ + public ImageView addControlButton(@NonNull ButtonSignature button, int backgroundDrawable, int drawableIcon){ ImageView controlButton = new ImageView(this.getContext()); - ((AppCompatActivity)getContext()).runOnUiThread(()->{ - controlButton.setId(buttonID); - ViewGroup.LayoutParams layoutParams = new LayoutParams(this.getLayoutParams().width /3, this.getLayoutParams().height/3); - controlButton.setLayoutParams(layoutParams); - controlButton.setImageDrawable(ContextCompat.getDrawable(this.getContext(), drawableIcon)); - controlButton.setBackground(ContextCompat.getDrawable(this.getContext(), backgroundDrawable)); - if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.O ){ - controlButton.setTooltipText(buttonName); - } - switch (buttonID){ - case GAMEPAD_BUTTON_X: + ((AppCompatActivity)getContext()).runOnUiThread(()->{ + controlButton.setId(button.ID); + ViewGroup.LayoutParams layoutParams = new LayoutParams(this.getLayoutParams().width /3, this.getLayoutParams().height/3); + controlButton.setLayoutParams(layoutParams); + controlButton.setImageDrawable(ContextCompat.getDrawable(this.getContext(), drawableIcon)); + controlButton.setBackground(ContextCompat.getDrawable(this.getContext(), backgroundDrawable)); + + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.O){ + controlButton.setTooltipText(button.NAME); + } + + if (button == ButtonSignature.GAMEPAD_BUTTON_X){ controlButton.setX(0f); controlButton.setY(layoutParams.height); - break; - case GAMEPAD_BUTTON_B: - controlButton.setX(layoutParams.width*2); + }else if(button == ButtonSignature.GAMEPAD_BUTTON_B){ + controlButton.setX(layoutParams.width * 2); controlButton.setY(layoutParams.height); - break; - - case GAMEPAD_BUTTON_Y: + }else if(button == ButtonSignature.GAMEPAD_BUTTON_Y){ controlButton.setX(layoutParams.width); controlButton.setY(0f); - break; - case GAMEPAD_BUTTON_A: + }else if(button == ButtonSignature.GAMEPAD_BUTTON_A){ controlButton.setX(layoutParams.width); - controlButton.setY(layoutParams.height*2); - break; - } - this.addView(controlButton); - }); + controlButton.setY(layoutParams.height * 2); + } + this.addView(controlButton); + }); return controlButton; } - public void setButtonListener(int buttonID,OnClickListener onClickListener){ - ImageView pushButton=findViewById(buttonID); + public void setButtonListener(@NonNull ButtonSignature button, OnClickListener onClickListener){ + ImageView pushButton=findViewById(button.ID); pushButton.setOnClickListener(onClickListener); } - public void setButtonLongClickListener(int buttonID,OnLongClickListener onLongClickListener){ - ImageView pushButton=findViewById(buttonID); + public void setButtonLongClickListener(@NonNull ButtonSignature button, OnLongClickListener onLongClickListener){ + ImageView pushButton=findViewById(button.ID); pushButton.setOnLongClickListener(onLongClickListener); } - public void setButtonBackgroundDrawable(int buttonID,int drawable){ - (findViewById(buttonID)).setBackground(ContextCompat.getDrawable(getContext(),drawable)); + public void setButtonBackgroundDrawable(@NonNull ButtonSignature button,int drawable){ + (findViewById(button.ID)).setBackground(ContextCompat.getDrawable(getContext(),drawable)); } - public void setButtonSrcDrawable(int buttonID,int drawable){ - ((ImageView)findViewById(buttonID)).setImageDrawable(ContextCompat.getDrawable(getContext(),drawable)); + public void setButtonSrcDrawable(@NonNull ButtonSignature button, int drawable){ + ((ImageView)findViewById(button.ID)).setImageDrawable(ContextCompat.getDrawable(getContext(),drawable)); } - public void setButtonSrcBitmap(int buttonID,String srcPath){ - ((ImageView)findViewById(buttonID)).setImageBitmap(BitmapFactory.decodeFile(srcPath)); + public void setButtonSrcBitmap(@NonNull ButtonSignature button, String srcPath){ + ((ImageView)findViewById(button.ID)).setImageBitmap(BitmapFactory.decodeFile(srcPath)); } - public void setButtonSrcIcon(int buttonID,String srcPath){ + public void setButtonSrcIcon(@NonNull ButtonSignature button, String srcPath){ if ( Build.VERSION.SDK_INT >= Build.VERSION_CODES.M ){ - ((ImageView)findViewById(buttonID)).setImageIcon(Icon.createWithFilePath(srcPath)); + ((ImageView)findViewById(button.ID)).setImageIcon(Icon.createWithFilePath(srcPath)); } } /** diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/UiStateManager.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/UiStateManager.java index 8763ee8..1a8fb8e 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/UiStateManager.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/UiStateManager.java @@ -1,6 +1,8 @@ package com.scrappers.superiorExtendedEngine.menuStates; import android.annotation.SuppressLint; +import android.content.Context; +import android.util.AttributeSet; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; @@ -22,7 +24,7 @@ */ @SuppressLint("ViewConstructor") public class UiStateManager extends RelativeLayout { - private final ViewGroup context; + private ViewGroup context; private int stateIndex=0; private final HashMap uiStates=new HashMap<>(); /** @@ -36,11 +38,22 @@ public UiStateManager(ViewGroup context) { context.addView(this); this.context=context; } - /** - * gets the map of the UiStates stack - * @return a HashMap representing the UiStates stack , - * where the key is the index of the UiState & the value represents the UiState instance. - */ + public UiStateManager(Context context, AttributeSet attrs) { + super(context, attrs); + } + + public UiStateManager(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + } + + public UiStateManager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + /** + * gets the map of the UiStates stack + * @return a HashMap representing the UiStates stack , + * where the key is the index of the UiState & the value represents the UiState instance. + */ public HashMap getUiStates() { return uiStates; } diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/ActionInjector.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/ActionInjector.java index 2526790..358a25d 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/ActionInjector.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/ActionInjector.java @@ -3,5 +3,5 @@ import android.view.View; public interface ActionInjector { - void execute(View uiState, int position, String currentItem); + void execute(View uiState, int position, PageDataModel currentItem); } diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/PageDataModel.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/PageDataModel.java new file mode 100644 index 0000000..5b52681 --- /dev/null +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/PageDataModel.java @@ -0,0 +1,7 @@ +package com.scrappers.superiorExtendedEngine.menuStates.uiPager; + +public abstract class PageDataModel { + public abstract String getComparingData(); + + public abstract String getSortingData(); +} diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/UiPager.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/UiPager.java index 89ba854..657a6a2 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/UiPager.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/menuStates/uiPager/UiPager.java @@ -2,6 +2,7 @@ import android.app.Activity; import android.content.Context; +import android.util.AttributeSet; import android.util.DisplayMetrics; import android.view.View; import android.view.ViewGroup; @@ -9,17 +10,11 @@ import android.widget.ScrollView; import com.scrappers.superiorExtendedEngine.menuStates.UiStateManager; import com.scrappers.superiorExtendedEngine.menuStates.UiStatesLooper; - -import java.lang.reflect.Array; -import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.ConcurrentModificationException; import java.util.HashMap; -import java.util.List; import java.util.concurrent.Executors; import androidx.annotation.IdRes; -import androidx.annotation.Nullable; /** * A UiState Class that could hold multiple UiStates in a list/grid form. @@ -34,7 +29,7 @@ public class UiPager extends GridLayout { private int stateIndex=0; /** - * Create a UiPager UiState group, to hold some UiStates + * Creates a UiPager UiState group, to hold some UiStates * @param context the current context wrapper */ public UiPager(Context context) { @@ -43,9 +38,22 @@ public UiPager(Context context) { ((Activity)getContext()).getWindowManager().getDefaultDisplay().getMetrics(displayMetrics); setLayoutParams(new ViewGroup.LayoutParams(displayMetrics.widthPixels, displayMetrics.heightPixels)); } - /** - * Create a UiPager UiState group, to hold some UiStates, & add that UiPager UiState to another container UiState + * Creates a uiPager for xml custom design. + * @param context the application context. + * @param attributeSet the attrs of xml. + */ + public UiPager(Context context, AttributeSet attributeSet){ + super(context, attributeSet); + } + public UiPager(Context context, AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr, 0); + } + public UiPager(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + } + /** + * Creates a UiPager UiState group, to hold some UiStates, & add that UiPager UiState to another container UiState * @param viewGroup the viewGroup container to add on */ public UiPager(ViewGroup viewGroup) { @@ -186,42 +194,42 @@ public void forEachUiState(UiStatesLooper.Modifiable.Looper uiStatesLooper){ * @param injector injects what you want to do when an item is returned by the search engine. * @return a list of the founded strings from the searchList based on the search keywords. */ - public String[] search(String[] searchList, String[] searchKeyWords, ActionInjector injector) { - String[] resultList = new String[0]; - String[] temp; + public M[] search(M[] searchList, String[] searchKeyWords, ActionInjector injector) { + M[] resultList = (M[]) new PageDataModel[0]; + M[] temp; int index = 0; - //loop over the main list items - for (int i = 0; i < searchList.length; i++) { - //loop over the search keywords - for (String searchKeyWord : searchKeyWords) { - if ( searchList[i].replaceAll(" ", "").trim().toLowerCase().contains( - searchKeyWord.replaceAll(" ", "").trim().toLowerCase()) ){ - //dynamic array conception (expandable by 1 array) & index to keep track of the successful matched string literals - if ( index > resultList.length - 1 ){ - //creating temp pointer producing a deep copy of resultList[0] array - temp = resultList; - //expanding the array through a new wider in size pointer - resultList = new String[temp.length + 1]; - //copy the values of the old contacted array to the new expanded one - int position = 0; - while (position < temp.length) { - resultList[position] = temp[position]; - position++; - } - } - //fill a new item after expanding the pointer - resultList[index] = searchList[i]; - //inject users' actions to execute - if ( injector != null ){ - injector.execute(getChildUiStateByIndex(i), i, resultList[index]); - } - //add 1 to keep track of successful values - index++; - //terminate when a successful condition search has met in the list of search keywords - break; + //loop over the main list items + for (int i = 0; i < searchList.length; i++) { + //loop over the search keywords + for (String searchKeyWord : searchKeyWords) { + if ( searchList[i].getComparingData().replaceAll(" ", "").trim().toLowerCase().contains( + searchKeyWord.replaceAll(" ", "").trim().toLowerCase()) ){ + //dynamic array conception (expandable by 1 array) & index to keep track of the successful matched string literals + if ( index > resultList.length - 1 ){ + //creating temp pointer producing a deep copy of resultList[0] array + temp = resultList; + //expanding the array through a new wider in size pointer + resultList = (M[]) new PageDataModel[temp.length + 1]; + //copy the values of the old contacted array to the new expanded one + int position = 0; + while (position < temp.length) { + resultList[position] = temp[position]; + position++; + } + } + //fill a new item after expanding the pointer + resultList[index] = searchList[i]; + //inject users' actions to execute + if ( injector != null ){ + injector.execute(getChildUiStateByIndex(i), i, resultList[index]); } + //add 1 to keep track of successful values + index++; + //terminate when a successful condition search has met in the list of search keywords + break; } } + } return resultList; } @@ -233,48 +241,41 @@ public String[] search(String[] searchList, String[] searchKeyWords, ActionInjec * @throws Exception if process is interrupted or -1 is returned. * @apiNote you will need to loop over this list to provide the uiStates with new update. */ - public String[] sort(String[] list, int sortAlgorithm) throws Exception { - synchronized(this) { - //to apply the sort change as an external final change on a list copy (warning : ->Internal List change(positions or items count or items values) = Malicious Activity - final String[] copy = Arrays.copyOf(list, list.length); - return Executors.callable(() -> { - String tempPointer = ""; - //main String List looping - for (int i = 0; i < copy.length; i++) { - //looping over the String again to compare each one String member var with the sequence of the String member vars after that item - for(int j = i+1; j < copy.length; j++ ){ - //sort from A-Z ascendingly - if(sortAlgorithm == A_Z){ - //compare 2 strings lexicographically based on their characters, if the (string object > the argument string) then compareTo returns 1 - if ( copy[i].toLowerCase().compareTo(copy[j].toLowerCase()) > 0 ){ - //format the pointer - tempPointer = ""; - //then swap list[i] & list[j] because list[i] is after the list[k] - //store the list[i] inside the tempPointer for later access - tempPointer = copy[i]; - //get the list[i] after - copy[i] = copy[j]; - //get the list[j] before - copy[j] = tempPointer; - } - }else if(sortAlgorithm == Z_A){ - //compare 2 strings lexicographically based on their characters, if the (string object < the argument string) then compareTo returns -1 - if ( copy[i].toLowerCase().compareTo(copy[j].toLowerCase()) < 0){ - //format the pointer - tempPointer = ""; - //then swap list[i] & list[j] because list[i] is before the list[k] - //store the list[j] inside the tempPointer for later access - tempPointer = copy[j]; - //get the list[j] before - copy[j] = copy[i]; - //get the list[i] after - copy[i] = tempPointer; - } + public M[] sort(M[] list, int sortAlgorithm) throws Exception { + //to apply the sort change as an external final change on a list copy (warning : ->Internal List change(positions or items count or items values) = Malicious Activity + final M[] copy = Arrays.copyOf(list, list.length); + M tempPointer; + //main String List looping + for (int i = 0; i < copy.length; i++) { + //looping over the String again to compare each one String member var with the sequence of the String member vars after that item + for(int j = i+1; j < copy.length; j++ ){ + //sort from A-Z ascendingly + if(sortAlgorithm == A_Z){ + //compare 2 strings lexicographically based on their characters, if the (string object > the argument string) then compareTo returns 1 + if ( copy[i].getSortingData().toLowerCase().compareTo(copy[j].getSortingData().toLowerCase()) > 0 ){ + //then swap list[i] & list[j] because list[i] is after the list[k] + //store the list[i] inside the tempPointer for later access + tempPointer = copy[i]; + //get the list[i] after + copy[i] = copy[j]; + //get the list[j] before + copy[j] = tempPointer; } - } + }else if(sortAlgorithm == Z_A){ + //compare 2 strings lexicographically based on their characters, if the (string object < the argument string) then compareTo returns -1 + if ( copy[i].getSortingData().toLowerCase().compareTo(copy[j].getSortingData().toLowerCase()) < 0){ + //then swap list[i] & list[j] because list[i] is before the list[k] + //store the list[j] inside the tempPointer for later access + tempPointer = copy[j]; + //get the list[j] before + copy[j] = copy[i]; + //get the list[i] after + copy[i] = tempPointer; + } + } } - }, copy).call(); - } + } + return copy; } /** * gets the index of the Last UI-State attached to the UI-State-Manager. diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/DrivingWheelView.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/DrivingWheelView.java similarity index 84% rename from SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/DrivingWheelView.java rename to SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/DrivingWheelView.java index 8580417..b280864 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/DrivingWheelView.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/DrivingWheelView.java @@ -1,23 +1,21 @@ -package com.scrappers.superiorExtendedEngine.misc; +package com.scrappers.superiorExtendedEngine.vehicles; import android.annotation.SuppressLint; import android.content.Context; import android.content.res.ColorStateList; -import android.graphics.drawable.GradientDrawable; import android.util.AttributeSet; import android.view.MotionEvent; import android.view.ViewGroup; import android.widget.ImageView; import android.widget.RelativeLayout; -import android.widget.Toast; - import com.scrappers.GamePad.R; import com.scrappers.superiorExtendedEngine.gamePad.ControlButtonsView; -import com.scrappers.superiorExtendedEngine.gamePad.GameStickView; -import androidx.annotation.CallSuper; +import androidx.annotation.IdRes; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.annotation.RawRes; +import androidx.annotation.XmlRes; import androidx.appcompat.app.AppCompatActivity; import androidx.cardview.widget.CardView; import androidx.core.content.ContextCompat; @@ -27,14 +25,6 @@ * @author pavl_g */ public class DrivingWheelView extends RelativeLayout { - private int DRIVING_PADS_TINT = R.color.pureWhite; - private int AXLE_TINT = R.color.pureWhite; - private int DRIVING_WHEEL = R.drawable.driving_wheel; - private int DRIVING_WHEEL_TINT = R.color.fireEngineRed; - private int WHEEL_AXLE = R.drawable.wheel_axle; - private int DRIVING_PADS = R.drawable.driving_pads; - private int HORN_HOLDER = R.drawable.driving_handle; - private int HORN = R.drawable.ic_air_horn; private boolean neutralizeWhenLostFocus=true; private CardView drivingWheel; private CardView hornHolder; @@ -53,6 +43,26 @@ public class DrivingWheelView extends RelativeLayout { private CustomizeDrivingWheel customizeDrivingWheel; private DynamicUTurn dynamicUTurn; + /** + * Driving Handle Style enclosure. + * @author pavl_g + */ + public enum HandleStyles { + //the enums + DRIVING_PADS_TINT(R.color.pureWhite), AXLE_TINT(R.color.pureWhite), DRIVING_WHEEL(R.drawable.driving_wheel), + DRIVING_WHEEL_TINT(R.color.fireEngineRed), WHEEL_AXLE(R.drawable.wheel_axle), DRIVING_PADS(R.drawable.driving_pads), + HORN_HOLDER(R.drawable.driving_handle), HORN(R.drawable.ic_air_horn); + + public final int STYLE; + /** + * Make a call to a constant enum of couple of designs + * @param STYLE the style + */ + HandleStyles(int STYLE){ + this.STYLE = STYLE; + } + } + public DrivingWheelView(@NonNull Context appCompatActivity) { super(appCompatActivity); } @@ -74,13 +84,13 @@ public void initializeWheel(){ xOrigin=getLayoutParams().width/2f; yOrigin=getLayoutParams().height/2f; - setBackground(ContextCompat.getDrawable(this.getContext(), ControlButtonsView.NOTHING_IMAGE)); + setBackground(ContextCompat.getDrawable(this.getContext(), ControlButtonsView.ButtonStyle.NOTHING_IMAGE.STYLE)); /*initialization of drivingWheel*/ drivingWheel =new CardView(getContext()); drivingWheel.setRotationX((float) Math.toDegrees(Math.PI/10)); - drivingWheel.setBackground(ContextCompat.getDrawable(getContext(), DRIVING_WHEEL)); - drivingWheel.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),DRIVING_WHEEL_TINT))); + drivingWheel.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.DRIVING_WHEEL.STYLE)); + drivingWheel.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), HandleStyles.DRIVING_WHEEL_TINT.STYLE))); ViewGroup.LayoutParams drivingWheelParams=new RelativeLayout.LayoutParams(getLayoutParams().width,getLayoutParams().height); drivingWheel.setLayoutParams(drivingWheelParams); drivingWheel.setX(getLayoutParams().width/2f-drivingWheelParams.width/2f); @@ -91,8 +101,8 @@ public void initializeWheel(){ axle=new ImageView(getContext()); axle.setRotationY(60); axle.setRotationX(10); - axle.setBackground(ContextCompat.getDrawable(getContext(),WHEEL_AXLE)); - axle.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),AXLE_TINT))); + axle.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.WHEEL_AXLE.STYLE)); + axle.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), HandleStyles.AXLE_TINT.STYLE))); //total distance of the upper half of the circle = half of the width of the view = half the circumference of the circle // (because we wanna get the exact width of the axle after a rotation by some degree points in the +ve direction of x-axis //general formula = length covered by an angle in unit circle = perimeter of the circle(circle frame length) * (theta/360 or the scaleFactor) @@ -113,8 +123,8 @@ public void initializeWheel(){ axle2=new ImageView(getContext()); axle2.setRotationY(-60); axle2.setRotationX(10); - axle2.setBackground(ContextCompat.getDrawable(getContext(), WHEEL_AXLE)); - axle2.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),AXLE_TINT))); + axle2.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.WHEEL_AXLE.STYLE)); + axle2.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), HandleStyles.AXLE_TINT.STYLE))); ViewGroup.LayoutParams axle2Params=new RelativeLayout.LayoutParams((int) (getLayoutParams().width/2+lengthCoveredByRotationAngle)+strokeWidth ,drivingWheelParams.height/5); axle2.setLayoutParams(axle2Params); @@ -124,8 +134,8 @@ public void initializeWheel(){ drivingWheel.addView(axle2); /*Axle3*/ axle3=new ImageView(getContext()); - axle3.setBackground(ContextCompat.getDrawable(getContext(),WHEEL_AXLE)); - axle3.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),AXLE_TINT))); + axle3.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.WHEEL_AXLE.STYLE)); + axle3.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), HandleStyles.AXLE_TINT.STYLE))); ViewGroup.LayoutParams axle3Params=new RelativeLayout.LayoutParams(getLayoutParams().width,drivingWheelParams.height/5); axle3.setLayoutParams(axle3Params); axle3.setX(drivingWheel.getLayoutParams().width/2f-axle3Params.width/2f); @@ -137,8 +147,8 @@ public void initializeWheel(){ /*define the drivingWheelPads*/ drivingPads=new CardView(getContext()); - drivingPads.setBackground(ContextCompat.getDrawable(getContext(), DRIVING_PADS)); - drivingPads.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),DRIVING_PADS_TINT))); + drivingPads.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.DRIVING_PADS.STYLE)); + drivingPads.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), HandleStyles.DRIVING_PADS_TINT.STYLE))); ViewGroup.LayoutParams drivingPadsParams=new RelativeLayout.LayoutParams(getLayoutParams().width,getLayoutParams().height); drivingPads.setLayoutParams(drivingPadsParams); drivingPads.setX(getLayoutParams().width/2f-drivingWheelParams.width/2f); @@ -148,7 +158,7 @@ public void initializeWheel(){ /*define the hornHolder view*/ hornHolder=new CardView(drivingWheel.getContext()); - hornHolder.setBackground(ContextCompat.getDrawable(getContext(),HORN_HOLDER)); + hornHolder.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.HORN_HOLDER.STYLE)); hornHolder.setRotationX(drivingWheel.getRotationX()); hornHolder.setLayoutParams(new RelativeLayout.LayoutParams(drivingWheelParams.width/3, drivingWheelParams.height/3)); hornHolder.setX(drivingWheel.getLayoutParams().width/2f-hornHolder.getLayoutParams().width/2f); @@ -159,7 +169,7 @@ public void initializeWheel(){ /*define hornHolder image*/ horn=new ImageView(hornHolder.getContext()); - horn.setImageDrawable(ContextCompat.getDrawable(getContext(),HORN)); + horn.setImageDrawable(ContextCompat.getDrawable(getContext(), HandleStyles.HORN.STYLE)); horn.setLayoutParams(new RelativeLayout.LayoutParams(hornHolder.getLayoutParams().width/2,hornHolder.getLayoutParams().height/2)); horn.setX(hornHolder.getLayoutParams().width/2f-horn.getLayoutParams().width/2f); horn.setY(hornHolder.getLayoutParams().height/2f-horn.getLayoutParams().height/2f); @@ -167,8 +177,8 @@ public void initializeWheel(){ /* the driving wheel enclosure is the top part part of the driving wheel with same color*/ drivingWheelEnclosure=new CardView(getContext()); - drivingWheelEnclosure.setBackground(ContextCompat.getDrawable(getContext(), DRIVING_WHEEL)); - drivingWheelEnclosure.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),DRIVING_WHEEL_TINT))); + drivingWheelEnclosure.setBackground(ContextCompat.getDrawable(getContext(), HandleStyles.DRIVING_WHEEL.STYLE)); + drivingWheelEnclosure.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), HandleStyles.DRIVING_WHEEL_TINT.STYLE))); drivingWheelEnclosure.setLayoutParams(drivingWheel.getLayoutParams()); drivingWheelEnclosure.setX(drivingWheel.getX()); drivingWheelEnclosure.setY(drivingWheel.getY()); @@ -262,70 +272,6 @@ public void setDrivingWheelAnimationDuration(long drivingWheelAnimationDuration) this.drivingWheelAnimationDuration = drivingWheelAnimationDuration; } - public int getDRIVING_WHEEL() { - return DRIVING_WHEEL; - } - - public void setDRIVING_WHEEL(int DRIVING_WHEEL) { - this.DRIVING_WHEEL = DRIVING_WHEEL; - } - - public int getDRIVING_WHEEL_TINT() { - return DRIVING_WHEEL_TINT; - } - - public void setDRIVING_WHEEL_TINT(int DRIVING_WHEEL_TINT) { - this.DRIVING_WHEEL_TINT = DRIVING_WHEEL_TINT; - } - - public int getWHEEL_AXLE() { - return WHEEL_AXLE; - } - - public void setWHEEL_AXLE(int WHEEL_AXLE) { - this.WHEEL_AXLE = WHEEL_AXLE; - } - - public int getDRIVING_PADS() { - return DRIVING_PADS; - } - - public void setDRIVING_PADS(int DRIVING_PADS) { - this.DRIVING_PADS = DRIVING_PADS; - } - - public int getHORN_HOLDER() { - return HORN_HOLDER; - } - - public void setHORN_HOLDER(int HORN_HOLDER) { - this.HORN_HOLDER = HORN_HOLDER; - } - - public int getHORN() { - return HORN; - } - - public void setHORN(int HORN) { - this.HORN = HORN; - } - - public void setAXLE_TINT(int AXLE_TINT) { - this.AXLE_TINT = AXLE_TINT; - } - - public int getAXLE_TINT() { - return AXLE_TINT; - } - - public void setDRIVING_PADS_TINT(int DRIVING_PADS_TINT) { - this.DRIVING_PADS_TINT = DRIVING_PADS_TINT; - } - - public int getDRIVING_PADS_TINT() { - return DRIVING_PADS_TINT; - } - public CardView getDrivingWheel() { return drivingWheel; } diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/GullWing.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/GullWing.java similarity index 90% rename from SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/GullWing.java rename to SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/GullWing.java index bdc930f..4c962d8 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/GullWing.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/GullWing.java @@ -1,4 +1,4 @@ -package com.scrappers.superiorExtendedEngine.misc; +package com.scrappers.superiorExtendedEngine.vehicles; import android.content.Context; import android.content.res.ColorStateList; @@ -45,24 +45,24 @@ public synchronized void initializeWheel() { /*customizing the impostorIndicators*/ speedometer.setImpostorIndicatorEnabled(true); for(ImageView imageView : speedometer.getImpostorIndicators()){ - imageView.setBackground(ContextCompat.getDrawable(getContext(),R.drawable.driving_pads)); + imageView.setBackground(ContextCompat.getDrawable(getContext(), R.drawable.driving_pads)); } setCustomizeDrivingWheel(parentView -> { setNeutralizeWhenLostFocus(true); - parentView.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),R.color.transparent))); + parentView.setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.transparent))); GullWing.this.getDrivingWheel().setRotationX(0); - GullWing.this.getDrivingPads().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),R.color.gold))); - GullWing.this.getDrivingWheelEnclosure().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),R.color.transparent))); + GullWing.this.getDrivingPads().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.gold))); + GullWing.this.getDrivingWheelEnclosure().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.transparent))); GullWing.this.getAxle3().setVisibility(INVISIBLE); - GullWing.this.getAxle().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),R.color.lightBlack))); - GullWing.this.getAxle2().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),R.color.lightBlack))); - GullWing.this.getHornHolder().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(),R.color.gold))); - GullWing.this.getHorn().setImageDrawable(ContextCompat.getDrawable(getContext(),ControlButtonsView.TRIS_BUTTONS)); + GullWing.this.getAxle().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.lightBlack))); + GullWing.this.getAxle2().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.lightBlack))); + GullWing.this.getHornHolder().setBackgroundTintList(ColorStateList.valueOf(ContextCompat.getColor(getContext(), R.color.gold))); + GullWing.this.getHorn().setImageDrawable(ContextCompat.getDrawable(getContext(), ControlButtonsView.ButtonStyle.TRIS_BUTTONS.STYLE)); GullWing.this.setDrivingWheelAnimationDuration(1000); getDrivingWheel().addView(speedometer); uTurnView=new UTurnView(getContext()); - uTurnView.setLayoutParams(new LayoutParams(getLayoutParams().width/6,getLayoutParams().height/6)); + uTurnView.setLayoutParams(new LayoutParams(getLayoutParams().width/6, getLayoutParams().height/6)); uTurnView.setScaleX(0f); uTurnView.setScaleY(0f); uTurnView.setBackgroundColor(ContextCompat.getColor(getContext(),R.color.transparent)); diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/Tachometer.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/Tachometer.java similarity index 94% rename from SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/Tachometer.java rename to SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/Tachometer.java index a9c8cb0..035ea4a 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/Tachometer.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/Tachometer.java @@ -1,4 +1,4 @@ -package com.scrappers.superiorExtendedEngine.misc; +package com.scrappers.superiorExtendedEngine.vehicles; import android.content.Context; import android.util.AttributeSet; diff --git a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/UTurnView.java b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/UTurnView.java similarity index 95% rename from SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/UTurnView.java rename to SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/UTurnView.java index bac25d8..d11af67 100644 --- a/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/misc/UTurnView.java +++ b/SuperiorPlugin/src/main/java/com/scrappers/superiorExtendedEngine/vehicles/UTurnView.java @@ -1,4 +1,4 @@ -package com.scrappers.superiorExtendedEngine.misc; +package com.scrappers.superiorExtendedEngine.vehicles; import android.content.Context; import android.graphics.Canvas; @@ -92,8 +92,9 @@ protected void onDraw(Canvas canvas) { super.onDraw(canvas); //draw a path canvas.drawColor(ContextCompat.getColor(getContext(), R.color.transparent)); - for(int index=0;index { + menu.setId('N'); + uiStateManager.getChildUiStateById('N').findViewById(R.id.start).setOnClickListener(v -> { (findViewById(R.id.gameStickView)).setVisibility(View.VISIBLE); (findViewById(R.id.speedometer)).setVisibility(View.VISIBLE); (findViewById(R.id.gamePadbtns)).setVisibility(View.VISIBLE); @@ -149,4 +147,16 @@ public void onBackPressed() { optionPane.getInflater().findViewById(R.id.ignoreError).setOnClickListener(view -> optionPane.getAlertDialog().dismiss()); } + public class test1 { + public void addView(View v){ + + } + } + public class test2 extends test1{ + + public void addView(RelativeLayout v) { + super.addView(v); + } + } + } \ No newline at end of file diff --git a/demoApp/src/main/java/com/myGame/JMESurfaceViewExampleActivity/UiTestCase.java b/demoApp/src/main/java/com/myGame/JMESurfaceViewExampleActivity/UiTestCase.java index 5ad60ce..3b6e6c8 100644 --- a/demoApp/src/main/java/com/myGame/JMESurfaceViewExampleActivity/UiTestCase.java +++ b/demoApp/src/main/java/com/myGame/JMESurfaceViewExampleActivity/UiTestCase.java @@ -8,6 +8,7 @@ import android.widget.Toast; import com.myGame.R; import com.scrappers.superiorExtendedEngine.menuStates.UiStateManager; +import com.scrappers.superiorExtendedEngine.menuStates.uiPager.PageDataModel; import com.scrappers.superiorExtendedEngine.menuStates.uiPager.UiPager; import java.util.Arrays; @@ -20,7 +21,8 @@ public class UiTestCase implements View.OnClickListener { private final UiStateManager uistateManager; private UiPager uiPager; - private String[] sortedList; + private DataModel[] unSortedList = new DataModel[5]; + private final String[] texts = new String[]{"Search", "Revert", "paul", "Dismiss", "Matt"}; public UiTestCase(final UiStateManager uistateManager){ this.uistateManager = uistateManager; } @@ -38,24 +40,23 @@ public void testPagerUiStates() throws Exception { ScrollView scrollView = uiPager.initializeScrollableContainer(); scrollView.setId('J' + 'J'); uistateManager.attachUiState(scrollView); - - //Test Sorting before adding items - sortedList = uiPager.sort(new String[]{"Search Test", "Revert Search", "Pavly", "Thomas","Fady", "Dismiss" }, UiPager.A_Z); + for(int i = 0; i { - System.out.println(Arrays.toString(uiPager.search(sortedList, new String[]{"Search", "PAvlY", "Thomas"}, (uiState, position, currentItem) -> { + System.out.println(Arrays.toString(uiPager.search(unSortedList, new String[]{"Revert","Dismiss"}, (uiState, position, currentItem) -> { uiPager.addView(uiState); uiState.setBackgroundColor(Color.MAGENTA); if ( uiState.getId() == 'P' ){ @@ -83,11 +84,11 @@ public void onClick(View v) { }else if(v.getId() == 'D'){ uiPager.animate().scaleY(0).scaleX(0).rotationY(45).setDuration(800).withEndAction(()->{ uiPager.detachAllUiStates(); - uistateManager.detachUiState(uiPager); + uistateManager.detachUiState((ScrollView) uiPager.getParent()); }).start(); } } - private class DataModel { + private static class DataModel extends PageDataModel { private int id; private String text; @@ -106,6 +107,16 @@ public String getText() { public void setText(String text) { this.text = text; } + + @Override + public String getComparingData() { + return getText(); + } + + @Override + public String getSortingData() { + return getText(); + } } } diff --git a/demoApp/src/main/java/com/myGame/JmEGamePadExample/GameStick.java b/demoApp/src/main/java/com/myGame/JmEGamePadExample/GameStick.java index 512f1b8..a4ce868 100644 --- a/demoApp/src/main/java/com/myGame/JmEGamePadExample/GameStick.java +++ b/demoApp/src/main/java/com/myGame/JmEGamePadExample/GameStick.java @@ -4,10 +4,8 @@ import com.jme3.input.ChaseCamera; import com.jme3.math.FastMath; import com.scrappers.superiorExtendedEngine.gamePad.GameStickView; -import com.scrappers.superiorExtendedEngine.misc.GullWing; -import com.scrappers.superiorExtendedEngine.misc.UTurnView; - -import checkers.quals.DefaultLocation; +import com.scrappers.superiorExtendedEngine.vehicles.GullWing; +import com.scrappers.superiorExtendedEngine.vehicles.UTurnView; public class GameStick implements GameStickView.GameStickListeners, GullWing.OnSteering { diff --git a/demoApp/src/main/java/com/myGame/JmEGamePadExample/JmeGame.java b/demoApp/src/main/java/com/myGame/JmEGamePadExample/JmeGame.java index a0a405e..5403480 100644 --- a/demoApp/src/main/java/com/myGame/JmEGamePadExample/JmeGame.java +++ b/demoApp/src/main/java/com/myGame/JmEGamePadExample/JmeGame.java @@ -2,7 +2,6 @@ import android.content.Intent; import android.graphics.Color; - import com.jme3.app.SimpleApplication; import com.jme3.asset.AssetManager; import com.jme3.bullet.BulletAppState; @@ -42,8 +41,7 @@ import com.scrappers.superiorExtendedEngine.gamePad.ControlButtonsView; import com.scrappers.superiorExtendedEngine.gamePad.GameStickView; import com.scrappers.superiorExtendedEngine.gamePad.Speedometer; -import com.scrappers.superiorExtendedEngine.misc.GullWing; - +import com.scrappers.superiorExtendedEngine.vehicles.GullWing; import androidx.appcompat.app.AppCompatActivity; import androidx.core.content.ContextCompat; @@ -73,45 +71,50 @@ public void simpleInitApp() { createPhysicsTestWorld(rootNode, getAssetManager(), bulletAppState.getPhysicsSpace()); buildPlayer(); // addEnvLightProbe(); + /*LIBRARY CODE*/ /*run the gamePad attachments & listeners from the android activity UI thread */ /* create an instance of a class extending gameStickView to easily handle the listeners */ gameStick = appCompatActivity.findViewById(R.id.gameStickView); - final GameStick gameStick1=new GameStick(); - gameStick1.setChaseCamera(chaseCam); - gameStick1.setVehicleControl(vehicle); - gameStick.setGameStickListeners(gameStick1); + + final GameStick gameStickController=new GameStick(); + gameStickController.setChaseCamera(chaseCam); + gameStickController.setVehicleControl(vehicle); + gameStick.setGameStickListeners(gameStickController); final GullWing drivingWheelView =appCompatActivity.findViewById(R.id.steeringWheel); drivingWheelView.initializeWheel(); drivingWheelView.initializeTachometer(gameStick,this,vehicle,3f); - drivingWheelView.setOnSteering(gameStick1); - + drivingWheelView.setOnSteering(gameStickController); gameStick.initializeStickPath(); gameStick.setMotionPathColor(Color.WHITE); - gameStick.initializeGameStickHolder(ControlButtonsView.NOTHING_IMAGE); - gameStick.initializeGameStick(ControlButtonsView.DEFAULT_BUTTONS,ControlButtonsView.STICK_DASHES,180); - final Speedometer speedometer=appCompatActivity.findViewById(R.id.speedometer); + gameStick.initializeGameStickHolder(ControlButtonsView.ButtonStyle.NOTHING_IMAGE.STYLE); + gameStick.initializeGameStick(ControlButtonsView.ButtonStyle.DEFAULT_BUTTONS.STYLE, ControlButtonsView.ButtonStyle.STICK_DASHES.STYLE,180); + + final Speedometer speedometer = appCompatActivity.findViewById(R.id.speedometer); speedometer.initialize(); speedometer.getSpeedometerDrawable().setStroke(3, ContextCompat.getColor(appCompatActivity,R.color.gold)); gameStick.createSpeedometerLink(speedometer,JmeGame.this,vehicle,1f); - ControlButtonsView controlButtonsView=appCompatActivity.findViewById(R.id.gamePadbtns); - controlButtonsView.addControlButton("X",ControlButtonsView.GAMEPAD_BUTTON_X,ControlButtonsView.DEFAULT_BUTTONS,ControlButtonsView.X_BUTTON_ALPHA) - .setOnClickListener(v -> appCompatActivity.startActivity(new Intent(appCompatActivity.getApplicationContext(), LanLogic.class))); - controlButtonsView.addControlButton("Y",ControlButtonsView.GAMEPAD_BUTTON_Y,ControlButtonsView.DEFAULT_BUTTONS,ControlButtonsView.Y_BUTTON_ALPHA); - controlButtonsView.addControlButton("A",ControlButtonsView.GAMEPAD_BUTTON_A,ControlButtonsView.DEFAULT_BUTTONS,ControlButtonsView.A_BUTTON_ALPHA) - .setOnClickListener(v -> { - vehicle.applyCentralImpulse(jumpForce); - }); - controlButtonsView.addControlButton("B",ControlButtonsView.GAMEPAD_BUTTON_B,ControlButtonsView.DEFAULT_BUTTONS,ControlButtonsView.B_BUTTON_ALPHA) - .setOnClickListener(v -> { - vehicle.applyCentralImpulse(vehicle.getLinearVelocity().mult(150)); - Node nitroNode=((Node)((Node) chassis).getChild("nitro")); - NitroState nitroState=new NitroState(assetManager,nitroNode,Vector3f.UNIT_Z.negate(),"nitroEffect",new ColorRGBA(0f, 1f, 1f, 0.8f),new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.1f)); - nitroState.setViewPort(viewPort); - stateManager.attach(nitroState); - }); + + final ControlButtonsView controlButtonsView = appCompatActivity.findViewById(R.id.gamePadbtns); + + controlButtonsView.addControlButton(ControlButtonsView.ButtonSignature.GAMEPAD_BUTTON_X, ControlButtonsView.ButtonStyle.DEFAULT_BUTTONS.STYLE, ControlButtonsView.ButtonIcon.X_BUTTON_ALPHA.ID) + .setOnClickListener(v -> appCompatActivity.startActivity(new Intent(appCompatActivity.getApplicationContext(), LanLogic.class))); + + controlButtonsView.addControlButton(ControlButtonsView.ButtonSignature.GAMEPAD_BUTTON_Y, ControlButtonsView.ButtonStyle.DEFAULT_BUTTONS.STYLE, ControlButtonsView.ButtonIcon.Y_BUTTON_ALPHA.ID); + + controlButtonsView.addControlButton(ControlButtonsView.ButtonSignature.GAMEPAD_BUTTON_A, ControlButtonsView.ButtonStyle.DEFAULT_BUTTONS.STYLE, ControlButtonsView.ButtonIcon.A_BUTTON_ALPHA.ID) + .setOnClickListener(v -> vehicle.applyCentralImpulse(jumpForce)); + + controlButtonsView.addControlButton(ControlButtonsView.ButtonSignature.GAMEPAD_BUTTON_B, ControlButtonsView.ButtonStyle.DEFAULT_BUTTONS.STYLE, ControlButtonsView.ButtonIcon.B_BUTTON_ALPHA.ID) + .setOnClickListener(v -> { + vehicle.applyCentralImpulse(vehicle.getLinearVelocity().mult(150)); + Node nitroNode=((Node)((Node) chassis).getChild("nitro")); + NitroState nitroState=new NitroState(assetManager,nitroNode,Vector3f.UNIT_Z.negate(),"nitroEffect",new ColorRGBA(0f, 1f, 1f, 0.8f),new ColorRGBA(251f / 255f, 130f / 255f, 0f, 0.1f)); + nitroState.setViewPort(viewPort); + stateManager.attach(nitroState); + }); } @Override diff --git a/demoApp/src/main/res/layout/activity_example.xml b/demoApp/src/main/res/layout/activity_example.xml index e2d31b7..61e9acb 100644 --- a/demoApp/src/main/res/layout/activity_example.xml +++ b/demoApp/src/main/res/layout/activity_example.xml @@ -50,7 +50,7 @@ android:layout_marginStart="0dp" android:layout_marginEnd="0dp" > -