Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.ecsbackgammon;
- import android.content.Context;
- import android.opengl.GLSurfaceView;
- import android.support.annotation.NonNull;
- import android.support.v4.view.MotionEventCompat;
- import android.util.AttributeSet;
- import android.util.Log;
- import android.view.MotionEvent;
- import java.util.Calendar;
- class MyGLSurfaceView extends GLSurfaceView
- {
- private String TAG = "GLSurfaceView";
- private int mActivePointerId = INVALID_POINTER_ID;
- private static final int INVALID_POINTER_ID = -1;
- private static final int MAX_CLICK_DURATION = 800;
- static public int dTouchedTriangleZeroIndexed = 0;
- static public int dSelectedCheckersTriangle = 0;
- static public int dTabSelected = 1;
- private long lStartClickTime;
- static public float fLastTouchX = 0.0f;
- static public float fLastTouchY = 0.0f;
- public MyGLRenderer mRenderer;
- static public IMainMenuActivityEvents IMainActivityEvents;
- public void setIMainMenuActivityEventsListener( IMainMenuActivityEvents param )
- {
- IMainActivityEvents = param;
- }
- public MyGLSurfaceView( Context context )
- {
- super( context );
- setEGLContextClientVersion( 3 );
- Log.d( TAG, "MyGLSurfaceView" );
- }
- @Override
- public boolean onTouchEvent( @NonNull MotionEvent mEvent )
- {
- this.requestFocus( );
- final int dAction = MotionEventCompat.getActionMasked(mEvent);
- switch( dAction )
- {
- case MotionEvent.ACTION_DOWN:
- {
- final int dPointerIndex = MotionEventCompat.getActionIndex( mEvent );
- final float fX = MotionEventCompat.getX( mEvent, dPointerIndex );
- final float fY = MotionEventCompat.getY( mEvent, dPointerIndex );
- fLastTouchX = fX;
- fLastTouchY = fY;
- mActivePointerId = MotionEventCompat.getPointerId( mEvent, 0 );
- lStartClickTime = Calendar.getInstance().getTimeInMillis( );
- Log.d(TAG," ");
- Log.d(TAG,"ACTION_DOWN");
- Log.d(TAG," ");
- }
- break;
- case MotionEvent.ACTION_UP:
- {
- Log.d(TAG, "ACTION_UP");
- mActivePointerId = INVALID_POINTER_ID;
- long lClickDuration = Calendar.getInstance( ).getTimeInMillis( ) - lStartClickTime;
- float fUpY = mEvent.getY( );
- if( lClickDuration < MAX_CLICK_DURATION )
- {
- try
- {
- ActionUp( fLastTouchX, fLastTouchY );
- }
- catch ( CloneNotSupportedException e )
- {
- e.printStackTrace( );
- }
- }
- if( BlogRoll.isStatusTextArrow && Rects.rStatusTextExpansion.contains( fLastTouchX, fLastTouchY ) )
- {
- float dY = fLastTouchY - fUpY;
- int dScrollValueY = (int) dY;
- dScrollValueY = dScrollValueY / 25;
- if ( dScrollValueY < 0 ) {
- if( BlogRoll.dStatusTextScroll + dScrollValueY > 1 )
- BlogRoll.dStatusTextScroll = BlogRoll.dStatusTextScroll + dScrollValueY;
- else
- BlogRoll.dStatusTextScroll = 1;
- }
- else if ( dScrollValueY > 0 )
- {
- if ( BlogRoll.dStatusTextScroll + dScrollValueY > BlogRoll.lSoftwareStatus.size( ) )
- BlogRoll.dStatusTextScroll = BlogRoll.lSoftwareStatus.size( );
- else
- BlogRoll.dStatusTextScroll = BlogRoll.dStatusTextScroll + dScrollValueY;
- }
- }
- }
- break;
- case MotionEvent.ACTION_CANCEL:
- {
- mActivePointerId = INVALID_POINTER_ID;
- Log.d(TAG,"ACTION_CANCEL");
- }
- break;
- case MotionEvent.ACTION_POINTER_UP:
- {
- Log.d(TAG,"ACTION_POINTER_UP");
- final int pointerIndex = MotionEventCompat.getActionIndex( mEvent );
- final int pointerId = MotionEventCompat.getPointerId( mEvent, pointerIndex );
- if ( pointerId == mActivePointerId ) {
- Log.d(TAG,"Active pointer went up...");
- final int newPointerIndex = ( pointerIndex == 0 ) ? 1 : 0;
- fLastTouchX = MotionEventCompat.getX( mEvent, newPointerIndex );
- fLastTouchY = MotionEventCompat.getY( mEvent, newPointerIndex );
- mActivePointerId = MotionEventCompat.getPointerId( mEvent, newPointerIndex );
- }
- }
- break;
- }
- return true;
- }
- final public void ActionUp( float mLastTouchX, float mLastTouchY ) throws CloneNotSupportedException
- {
- boolean isSwitchMe = false;
- fLastTouchX = mLastTouchX;
- fLastTouchY = mLastTouchY;
- dTouchedTriangleZeroIndexed = Helpers.CheckPointOrigins( BoardMetrics.dPointOrigins1 );
- if( dTouchedTriangleZeroIndexed == MainMenuActivity.mGame.NOTINTRIANGLE && !Helpers.CheckPointInOuts( ) )
- MainMenuActivity.mGame.mSelPoint.dSelectedTriangle = Helpers.ClearSelPoint( MainMenuActivity.mGame.mCheckers1.getBarTrigger( ) );
- if( Helpers.CheckSelPointFlags( )
- && MainMenuActivity.mGame.mSelPoint.getSelTri( ) == MainMenuActivity.mGame.SELPOINTINVALID
- && Helpers.IsBetween( dTouchedTriangleZeroIndexed, 24, -1 )
- && !MainMenuActivity.mGame.mSelPoint.isPossiblesShown )
- {
- isSwitchMe = true;
- ActionUp.SelectPoint( );
- }
- if( Helpers.CheckSelPointFlags( )
- && ( Helpers.IsBetween( MainMenuActivity.mGame.mSelPoint.getSelTri( ), 25, -1 ) )
- && ( Helpers.TriangleIsValid( ) )
- && ( dTouchedTriangleZeroIndexed < MainMenuActivity.mGame.mSelPoint.getSelTri( ) )
- && ( MainMenuActivity.mGame.mSelPoint.isInSelPointPossiblesArray( dTouchedTriangleZeroIndexed ) )
- && ( MainMenuActivity.mGame.mSelPoint.isPossiblesShown ) ) {
- isSwitchMe = true;
- ActionUp.MoveCheckerInsideBoard( );
- }
- if(!isSwitchMe
- && Helpers.IsOutShown( )
- && Helpers.CheckPointInOuts( )
- && Helpers.IsBetween( MainMenuActivity.mGame.mSelPoint.getSelTri( ), 6, -1 )) {
- isSwitchMe = true;
- ActionUp.MoveCheckerOut( );
- }
- if( !isSwitchMe
- && !MainMenuActivity.mGame.mDice.isRolled( ) && BoardMetrics.rDiceCup.contains( mLastTouchX, mLastTouchY ) ) {
- isSwitchMe = true;
- ActionUp.RollDice( );
- }
- if( !isSwitchMe
- && Helpers.IsTurnNoDiceRolledNotFirstRoll( ) && BoardMetrics.rDoublingCube.contains( mLastTouchX,mLastTouchY )
- && MainMenuActivity.mGame.isDoublesOwner ) {
- byte[] bDoubleMsg = new byte[3];
- bDoubleMsg[0] = ByteMessage.Messages.DBLACCEPTORDECLINE.getId( );
- IMainActivityEvents.sendMessage( bDoubleMsg );
- MainMenuActivity.mGame.isDoublesOwner = false;
- }
- if( ( MainMenuActivity.mGame.mLastMove1 != null || MainMenuActivity.mGame.mLastMove2 != null || MainMenuActivity.mGame.mLastMove3 != null || MainMenuActivity.mGame.mLastMove4 !=null )
- && Rects.rUndoIcon.contains( mLastTouchX,mLastTouchY ) && !Render.isUtilDialog )
- {
- isSwitchMe = true;
- ActionUp.Undo( );
- BlogRoll.pushTextGreen(Strings.statusyouundo);
- ByteMessage mOpponentUndoMsg = new ByteMessage( 1, ByteMessage.Messages.OPPONENTUNDO.getId( ) );
- IMainActivityEvents.sendMessage( mOpponentUndoMsg.getBytes( ) );
- }
- if( !isSwitchMe
- && Rects.rSpectaclesIcon.contains( mLastTouchX,mLastTouchY ) && !Render.isUtilDialog )
- {
- isSwitchMe = true;
- IMainActivityEvents.showSpectaclesDialog( );
- }
- if( !isSwitchMe && MainMenuActivity.mGame.isFinalGameOver && Rects.rRematchButton.contains( mLastTouchX,mLastTouchY ) )
- {
- MainMenuActivity.mGame.ResetGameVarsRematch( );
- Render.isWaiting = true;
- ByteMessage bMsg = new ByteMessage( 5, ByteMessage.Messages.REMATCH.getId( ) );
- IMainActivityEvents.sendMessage( bMsg.getBytes( ) );
- }
- if( !isSwitchMe && Rects.rStatusTextArrow.contains( mLastTouchX,mLastTouchY ) )
- {
- BlogRoll.isStatusTextArrow = !BlogRoll.isStatusTextArrow;
- BlogRoll.dStatusTextScroll = BlogRoll.lSoftwareStatus.size( );
- }
- if( !isSwitchMe
- && BoardMetrics.rTextStatusArea.contains( mLastTouchX,mLastTouchY )
- && !Rects.rStatusTextArrow.contains( mLastTouchX,mLastTouchY ) )
- {
- IMainActivityEvents.showChatDialog( );
- }
- if(!isSwitchMe && Rects.rSaveIcon.contains( mLastTouchX,mLastTouchY ) && !MainMenuActivity.mGame.isFirstRoll)
- {
- IMainActivityEvents.showSavedGamesUI( );
- isSwitchMe = true;
- }
- if(Rects.rUtilityDialogTab1.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
- {
- isSwitchMe = true;
- dTabSelected = 1;
- }
- if( Rects.rUtilityDialogTab2.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
- {
- isSwitchMe = true;
- dTabSelected = 2;
- }
- if( Rects.rUtilityDialogTab3.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
- {
- isSwitchMe = true;
- if( ECSBackgammon.isDeveloper ) {
- dTabSelected = 3;
- }
- }
- if( !isSwitchMe
- && Rects.rUtilityIcon.contains(mLastTouchX,mLastTouchY) && !Render.isUtilDialog ) {
- isSwitchMe = true;
- Render.isUtilDialog = !Render.isUtilDialog;
- }
- if( Rects.rUtilityDialogX.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
- {
- Render.isUtilDialog = false;
- }
- if( Render.isUtilDialog && dTabSelected == 1 )
- {
- if( Rects.rCheckBoxLayoutStyle1.contains( mLastTouchX,mLastTouchY ))
- {
- if( ECSBackgammon.GetPreferencesLayoutOn( ) ) {
- ECSBackgammon.SetPreferencesLayoutOn( false );
- Render.isBoundsCalculated = false;
- BoardMetrics.CalculateLayout( ECSBackgammon.GetPreferencesLayoutOn( ), true );
- Render.isBoundsCalculated = true;
- }
- }
- if( Rects.rCheckBoxLayoutStyle2.contains( mLastTouchX,mLastTouchY ) )
- {
- if( !ECSBackgammon.GetPreferencesLayoutOn( ) ) {
- ECSBackgammon.SetPreferencesLayoutOn( true );
- Render.isBoundsCalculated = false;
- BoardMetrics.CalculateLayout( ECSBackgammon.GetPreferencesLayoutOn( ), true );
- Render.isBoundsCalculated = true;
- }
- }
- if( Rects.rFrameRateUp.contains( mLastTouchX, mLastTouchY ) )
- {
- if( DrawThread.MAX_FPS < 80 ) {
- DrawThread.MAX_FPS++;
- ECSBackgammon.SetPreferencesFrameRate(DrawThread.MAX_FPS);
- }
- }
- if( Rects.rFrameRateDown.contains( mLastTouchX, mLastTouchY ) )
- {
- if( DrawThread.MAX_FPS > 10 )
- {
- DrawThread.MAX_FPS--;
- ECSBackgammon.SetPreferencesFrameRate( DrawThread.MAX_FPS );
- }
- }
- if( Rects.rCheckBoxGameNotifications.contains( mLastTouchX, mLastTouchY ) )
- {
- if( !ECSBackgammon.GetGameNotificationsOn( ) )
- {
- ECSBackgammon.SetGameNotificationsOn( true );
- }
- else
- {
- ECSBackgammon.SetGameNotificationsOn( false );
- }
- }
- }
- if( Render.isUtilDialog && dTabSelected == 2 )
- {
- if( Rects.rCheckBoxAudio.contains( mLastTouchX,mLastTouchY ) )
- {
- if( ECSBackgammon.GetPreferencesAudioOn( ) ) {
- ECSBackgammon.SetPreferencesAudioOn( false );
- }
- else
- {
- ECSBackgammon.SetPreferencesAudioOn( true );
- }
- }
- if( Rects.rCheckBoxAudibles.contains( mLastTouchX,mLastTouchY ) )
- {
- if( ECSBackgammon.GetPreferencesAudiblesOn( ) ) {
- ECSBackgammon.SetPreferencesAudiblesOn( false );
- }
- else
- {
- ECSBackgammon.SetPreferencesAudiblesOn( true );
- }
- }
- if( Rects.rCheckBoxFarsi.contains( mLastTouchX,mLastTouchY ) )
- {
- if( !ECSBackgammon.GetPreferencesFarsiOn( ) )
- {
- ECSBackgammon.SetPreferencesFarsiOn( true );
- }
- }
- if( Rects.rCheckBoxEnglish.contains( mLastTouchX,mLastTouchY ) )
- {
- if( ECSBackgammon.GetPreferencesFarsiOn() ) {
- ECSBackgammon.SetPreferencesFarsiOn( false );
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement