Advertisement
esepich

Untitled

Jul 3rd, 2015
394
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.02 KB | None | 0 0
  1. package com.ecsbackgammon;
  2.  
  3. import android.content.Context;
  4. import android.opengl.GLSurfaceView;
  5. import android.support.annotation.NonNull;
  6. import android.support.v4.view.MotionEventCompat;
  7. import android.util.AttributeSet;
  8. import android.util.Log;
  9. import android.view.MotionEvent;
  10.  
  11. import java.util.Calendar;
  12.  
  13. class MyGLSurfaceView extends GLSurfaceView
  14. {
  15. private String TAG = "GLSurfaceView";
  16.  
  17. private int mActivePointerId = INVALID_POINTER_ID;
  18.  
  19. private static final int INVALID_POINTER_ID = -1;
  20.  
  21. private static final int MAX_CLICK_DURATION = 800;
  22.  
  23. static public int dTouchedTriangleZeroIndexed = 0;
  24.  
  25. static public int dSelectedCheckersTriangle = 0;
  26.  
  27. static public int dTabSelected = 1;
  28.  
  29. private long lStartClickTime;
  30.  
  31. static public float fLastTouchX = 0.0f;
  32.  
  33. static public float fLastTouchY = 0.0f;
  34.  
  35. public MyGLRenderer mRenderer;
  36.  
  37. static public IMainMenuActivityEvents IMainActivityEvents;
  38.  
  39. public void setIMainMenuActivityEventsListener( IMainMenuActivityEvents param )
  40. {
  41. IMainActivityEvents = param;
  42. }
  43.  
  44. public MyGLSurfaceView( Context context )
  45. {
  46.  
  47. super( context );
  48.  
  49. setEGLContextClientVersion( 3 );
  50.  
  51. Log.d( TAG, "MyGLSurfaceView" );
  52. }
  53.  
  54. @Override
  55. public boolean onTouchEvent( @NonNull MotionEvent mEvent )
  56. {
  57. this.requestFocus( );
  58.  
  59. final int dAction = MotionEventCompat.getActionMasked(mEvent);
  60.  
  61. switch( dAction )
  62. {
  63. case MotionEvent.ACTION_DOWN:
  64. {
  65. final int dPointerIndex = MotionEventCompat.getActionIndex( mEvent );
  66.  
  67. final float fX = MotionEventCompat.getX( mEvent, dPointerIndex );
  68.  
  69. final float fY = MotionEventCompat.getY( mEvent, dPointerIndex );
  70.  
  71. fLastTouchX = fX;
  72.  
  73. fLastTouchY = fY;
  74.  
  75. mActivePointerId = MotionEventCompat.getPointerId( mEvent, 0 );
  76.  
  77. lStartClickTime = Calendar.getInstance().getTimeInMillis( );
  78.  
  79. Log.d(TAG," ");
  80. Log.d(TAG,"ACTION_DOWN");
  81. Log.d(TAG," ");
  82. }
  83. break;
  84.  
  85. case MotionEvent.ACTION_UP:
  86. {
  87. Log.d(TAG, "ACTION_UP");
  88.  
  89. mActivePointerId = INVALID_POINTER_ID;
  90.  
  91. long lClickDuration = Calendar.getInstance( ).getTimeInMillis( ) - lStartClickTime;
  92.  
  93. float fUpY = mEvent.getY( );
  94.  
  95. if( lClickDuration < MAX_CLICK_DURATION )
  96. {
  97. try
  98. {
  99. ActionUp( fLastTouchX, fLastTouchY );
  100. }
  101. catch ( CloneNotSupportedException e )
  102. {
  103. e.printStackTrace( );
  104. }
  105. }
  106.  
  107. if( BlogRoll.isStatusTextArrow && Rects.rStatusTextExpansion.contains( fLastTouchX, fLastTouchY ) )
  108. {
  109. float dY = fLastTouchY - fUpY;
  110.  
  111. int dScrollValueY = (int) dY;
  112.  
  113. dScrollValueY = dScrollValueY / 25;
  114.  
  115. if ( dScrollValueY < 0 ) {
  116.  
  117. if( BlogRoll.dStatusTextScroll + dScrollValueY > 1 )
  118.  
  119. BlogRoll.dStatusTextScroll = BlogRoll.dStatusTextScroll + dScrollValueY;
  120.  
  121. else
  122.  
  123. BlogRoll.dStatusTextScroll = 1;
  124. }
  125. else if ( dScrollValueY > 0 )
  126. {
  127. if ( BlogRoll.dStatusTextScroll + dScrollValueY > BlogRoll.lSoftwareStatus.size( ) )
  128.  
  129. BlogRoll.dStatusTextScroll = BlogRoll.lSoftwareStatus.size( );
  130.  
  131. else
  132.  
  133. BlogRoll.dStatusTextScroll = BlogRoll.dStatusTextScroll + dScrollValueY;
  134. }
  135. }
  136.  
  137. }
  138. break;
  139.  
  140. case MotionEvent.ACTION_CANCEL:
  141. {
  142. mActivePointerId = INVALID_POINTER_ID;
  143.  
  144. Log.d(TAG,"ACTION_CANCEL");
  145.  
  146. }
  147. break;
  148.  
  149. case MotionEvent.ACTION_POINTER_UP:
  150. {
  151. Log.d(TAG,"ACTION_POINTER_UP");
  152.  
  153. final int pointerIndex = MotionEventCompat.getActionIndex( mEvent );
  154.  
  155. final int pointerId = MotionEventCompat.getPointerId( mEvent, pointerIndex );
  156.  
  157. if ( pointerId == mActivePointerId ) {
  158.  
  159. Log.d(TAG,"Active pointer went up...");
  160.  
  161. final int newPointerIndex = ( pointerIndex == 0 ) ? 1 : 0;
  162.  
  163. fLastTouchX = MotionEventCompat.getX( mEvent, newPointerIndex );
  164.  
  165. fLastTouchY = MotionEventCompat.getY( mEvent, newPointerIndex );
  166.  
  167. mActivePointerId = MotionEventCompat.getPointerId( mEvent, newPointerIndex );
  168. }
  169.  
  170. }
  171. break;
  172. }
  173. return true;
  174. }
  175.  
  176. final public void ActionUp( float mLastTouchX, float mLastTouchY ) throws CloneNotSupportedException
  177. {
  178. boolean isSwitchMe = false;
  179.  
  180. fLastTouchX = mLastTouchX;
  181.  
  182. fLastTouchY = mLastTouchY;
  183.  
  184. dTouchedTriangleZeroIndexed = Helpers.CheckPointOrigins( BoardMetrics.dPointOrigins1 );
  185.  
  186. if( dTouchedTriangleZeroIndexed == MainMenuActivity.mGame.NOTINTRIANGLE && !Helpers.CheckPointInOuts( ) )
  187.  
  188. MainMenuActivity.mGame.mSelPoint.dSelectedTriangle = Helpers.ClearSelPoint( MainMenuActivity.mGame.mCheckers1.getBarTrigger( ) );
  189.  
  190. if( Helpers.CheckSelPointFlags( )
  191. && MainMenuActivity.mGame.mSelPoint.getSelTri( ) == MainMenuActivity.mGame.SELPOINTINVALID
  192. && Helpers.IsBetween( dTouchedTriangleZeroIndexed, 24, -1 )
  193. && !MainMenuActivity.mGame.mSelPoint.isPossiblesShown )
  194. {
  195.  
  196. isSwitchMe = true;
  197.  
  198. ActionUp.SelectPoint( );
  199.  
  200. }
  201.  
  202. if( Helpers.CheckSelPointFlags( )
  203. && ( Helpers.IsBetween( MainMenuActivity.mGame.mSelPoint.getSelTri( ), 25, -1 ) )
  204. && ( Helpers.TriangleIsValid( ) )
  205. && ( dTouchedTriangleZeroIndexed < MainMenuActivity.mGame.mSelPoint.getSelTri( ) )
  206. && ( MainMenuActivity.mGame.mSelPoint.isInSelPointPossiblesArray( dTouchedTriangleZeroIndexed ) )
  207. && ( MainMenuActivity.mGame.mSelPoint.isPossiblesShown ) ) {
  208.  
  209. isSwitchMe = true;
  210.  
  211. ActionUp.MoveCheckerInsideBoard( );
  212. }
  213.  
  214. if(!isSwitchMe
  215. && Helpers.IsOutShown( )
  216. && Helpers.CheckPointInOuts( )
  217. && Helpers.IsBetween( MainMenuActivity.mGame.mSelPoint.getSelTri( ), 6, -1 )) {
  218.  
  219. isSwitchMe = true;
  220.  
  221. ActionUp.MoveCheckerOut( );
  222. }
  223.  
  224. if( !isSwitchMe
  225. && !MainMenuActivity.mGame.mDice.isRolled( ) && BoardMetrics.rDiceCup.contains( mLastTouchX, mLastTouchY ) ) {
  226.  
  227. isSwitchMe = true;
  228.  
  229. ActionUp.RollDice( );
  230. }
  231.  
  232. if( !isSwitchMe
  233. && Helpers.IsTurnNoDiceRolledNotFirstRoll( ) && BoardMetrics.rDoublingCube.contains( mLastTouchX,mLastTouchY )
  234. && MainMenuActivity.mGame.isDoublesOwner ) {
  235.  
  236. byte[] bDoubleMsg = new byte[3];
  237.  
  238. bDoubleMsg[0] = ByteMessage.Messages.DBLACCEPTORDECLINE.getId( );
  239.  
  240. IMainActivityEvents.sendMessage( bDoubleMsg );
  241.  
  242. MainMenuActivity.mGame.isDoublesOwner = false;
  243. }
  244.  
  245. if( ( MainMenuActivity.mGame.mLastMove1 != null || MainMenuActivity.mGame.mLastMove2 != null || MainMenuActivity.mGame.mLastMove3 != null || MainMenuActivity.mGame.mLastMove4 !=null )
  246. && Rects.rUndoIcon.contains( mLastTouchX,mLastTouchY ) && !Render.isUtilDialog )
  247. {
  248. isSwitchMe = true;
  249.  
  250. ActionUp.Undo( );
  251.  
  252. BlogRoll.pushTextGreen(Strings.statusyouundo);
  253.  
  254. ByteMessage mOpponentUndoMsg = new ByteMessage( 1, ByteMessage.Messages.OPPONENTUNDO.getId( ) );
  255.  
  256. IMainActivityEvents.sendMessage( mOpponentUndoMsg.getBytes( ) );
  257. }
  258.  
  259. if( !isSwitchMe
  260. && Rects.rSpectaclesIcon.contains( mLastTouchX,mLastTouchY ) && !Render.isUtilDialog )
  261. {
  262. isSwitchMe = true;
  263.  
  264. IMainActivityEvents.showSpectaclesDialog( );
  265. }
  266.  
  267. if( !isSwitchMe && MainMenuActivity.mGame.isFinalGameOver && Rects.rRematchButton.contains( mLastTouchX,mLastTouchY ) )
  268. {
  269. MainMenuActivity.mGame.ResetGameVarsRematch( );
  270.  
  271. Render.isWaiting = true;
  272.  
  273. ByteMessage bMsg = new ByteMessage( 5, ByteMessage.Messages.REMATCH.getId( ) );
  274.  
  275. IMainActivityEvents.sendMessage( bMsg.getBytes( ) );
  276. }
  277.  
  278. if( !isSwitchMe && Rects.rStatusTextArrow.contains( mLastTouchX,mLastTouchY ) )
  279. {
  280. BlogRoll.isStatusTextArrow = !BlogRoll.isStatusTextArrow;
  281.  
  282. BlogRoll.dStatusTextScroll = BlogRoll.lSoftwareStatus.size( );
  283. }
  284.  
  285. if( !isSwitchMe
  286. && BoardMetrics.rTextStatusArea.contains( mLastTouchX,mLastTouchY )
  287. && !Rects.rStatusTextArrow.contains( mLastTouchX,mLastTouchY ) )
  288. {
  289. IMainActivityEvents.showChatDialog( );
  290. }
  291.  
  292. if(!isSwitchMe && Rects.rSaveIcon.contains( mLastTouchX,mLastTouchY ) && !MainMenuActivity.mGame.isFirstRoll)
  293. {
  294. IMainActivityEvents.showSavedGamesUI( );
  295.  
  296. isSwitchMe = true;
  297. }
  298.  
  299. if(Rects.rUtilityDialogTab1.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
  300. {
  301. isSwitchMe = true;
  302.  
  303. dTabSelected = 1;
  304.  
  305. }
  306.  
  307. if( Rects.rUtilityDialogTab2.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
  308. {
  309. isSwitchMe = true;
  310.  
  311. dTabSelected = 2;
  312.  
  313. }
  314.  
  315. if( Rects.rUtilityDialogTab3.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
  316. {
  317. isSwitchMe = true;
  318.  
  319. if( ECSBackgammon.isDeveloper ) {
  320.  
  321. dTabSelected = 3;
  322.  
  323. }
  324. }
  325.  
  326. if( !isSwitchMe
  327. && Rects.rUtilityIcon.contains(mLastTouchX,mLastTouchY) && !Render.isUtilDialog ) {
  328.  
  329. isSwitchMe = true;
  330.  
  331. Render.isUtilDialog = !Render.isUtilDialog;
  332. }
  333.  
  334. if( Rects.rUtilityDialogX.contains( mLastTouchX,mLastTouchY ) && Render.isUtilDialog )
  335. {
  336. Render.isUtilDialog = false;
  337. }
  338.  
  339. if( Render.isUtilDialog && dTabSelected == 1 )
  340. {
  341. if( Rects.rCheckBoxLayoutStyle1.contains( mLastTouchX,mLastTouchY ))
  342. {
  343.  
  344. if( ECSBackgammon.GetPreferencesLayoutOn( ) ) {
  345.  
  346. ECSBackgammon.SetPreferencesLayoutOn( false );
  347.  
  348. Render.isBoundsCalculated = false;
  349.  
  350. BoardMetrics.CalculateLayout( ECSBackgammon.GetPreferencesLayoutOn( ), true );
  351.  
  352. Render.isBoundsCalculated = true;
  353. }
  354. }
  355.  
  356. if( Rects.rCheckBoxLayoutStyle2.contains( mLastTouchX,mLastTouchY ) )
  357. {
  358. if( !ECSBackgammon.GetPreferencesLayoutOn( ) ) {
  359.  
  360. ECSBackgammon.SetPreferencesLayoutOn( true );
  361.  
  362. Render.isBoundsCalculated = false;
  363.  
  364. BoardMetrics.CalculateLayout( ECSBackgammon.GetPreferencesLayoutOn( ), true );
  365.  
  366. Render.isBoundsCalculated = true;
  367. }
  368. }
  369.  
  370. if( Rects.rFrameRateUp.contains( mLastTouchX, mLastTouchY ) )
  371. {
  372. if( DrawThread.MAX_FPS < 80 ) {
  373.  
  374. DrawThread.MAX_FPS++;
  375.  
  376. ECSBackgammon.SetPreferencesFrameRate(DrawThread.MAX_FPS);
  377.  
  378. }
  379. }
  380.  
  381. if( Rects.rFrameRateDown.contains( mLastTouchX, mLastTouchY ) )
  382. {
  383. if( DrawThread.MAX_FPS > 10 )
  384. {
  385. DrawThread.MAX_FPS--;
  386.  
  387. ECSBackgammon.SetPreferencesFrameRate( DrawThread.MAX_FPS );
  388.  
  389. }
  390. }
  391.  
  392. if( Rects.rCheckBoxGameNotifications.contains( mLastTouchX, mLastTouchY ) )
  393. {
  394. if( !ECSBackgammon.GetGameNotificationsOn( ) )
  395. {
  396. ECSBackgammon.SetGameNotificationsOn( true );
  397. }
  398. else
  399. {
  400. ECSBackgammon.SetGameNotificationsOn( false );
  401. }
  402. }
  403. }
  404.  
  405. if( Render.isUtilDialog && dTabSelected == 2 )
  406. {
  407. if( Rects.rCheckBoxAudio.contains( mLastTouchX,mLastTouchY ) )
  408. {
  409.  
  410. if( ECSBackgammon.GetPreferencesAudioOn( ) ) {
  411.  
  412. ECSBackgammon.SetPreferencesAudioOn( false );
  413.  
  414. }
  415. else
  416. {
  417. ECSBackgammon.SetPreferencesAudioOn( true );
  418. }
  419. }
  420.  
  421. if( Rects.rCheckBoxAudibles.contains( mLastTouchX,mLastTouchY ) )
  422. {
  423.  
  424. if( ECSBackgammon.GetPreferencesAudiblesOn( ) ) {
  425.  
  426. ECSBackgammon.SetPreferencesAudiblesOn( false );
  427.  
  428. }
  429. else
  430. {
  431. ECSBackgammon.SetPreferencesAudiblesOn( true );
  432. }
  433. }
  434.  
  435. if( Rects.rCheckBoxFarsi.contains( mLastTouchX,mLastTouchY ) )
  436. {
  437.  
  438. if( !ECSBackgammon.GetPreferencesFarsiOn( ) )
  439. {
  440.  
  441. ECSBackgammon.SetPreferencesFarsiOn( true );
  442. }
  443. }
  444.  
  445. if( Rects.rCheckBoxEnglish.contains( mLastTouchX,mLastTouchY ) )
  446. {
  447.  
  448. if( ECSBackgammon.GetPreferencesFarsiOn() ) {
  449.  
  450. ECSBackgammon.SetPreferencesFarsiOn( false );
  451.  
  452. }
  453. }
  454. }
  455. }
  456. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement