Project

General

Profile

« Previous | Next » 

Revision 7ac0ee88

Added by Leszek Koltunski over 2 years ago

Simplify ObjectList: now there's just one object per size.

View differences:

src/main/java/org/distorted/screens/RubikScreenPlay.java
53 53
public class RubikScreenPlay extends RubikScreenBase
54 54
  {
55 55
  public static final int LEVELS_SHOWN = 10;
56
  public static final int DEF_OBJECT= ObjectList.CUBE.ordinal();
57
  public static final int DEF_SIZE  =  3;
56
  public static final int DEF_OBJECT= ObjectList.CUBE_3.ordinal();
58 57

  
59 58
  private static final int[] BUTTON_LABELS = { R.string.scores,
60 59
                                               R.string.patterns,
......
71 70
  private Button mPlayButton;
72 71
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
73 72
  private int mObject = DEF_OBJECT;
74
  private int mSize   = DEF_SIZE;
75 73
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
76 74
  private int mLevelValue;
77 75
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
......
79 77
  private LinearLayout mPlayLayout;
80 78
  private int mUpperBarHeight;
81 79

  
82
  private boolean mIsFullScreen;
83

  
84 80
///////////////////////////////////////////////////////////////////////////////////////////////////
85 81

  
86 82
  void leaveScreen(RubikActivity act)
......
166 162
          {
167 163
          View popupView = mPlayPopup.getContentView();
168 164
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
169
          final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
170
          final int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
165
          final int dbLevel = ObjectList.getDBLevel(mObject);
171 166
          final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
172 167
          final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
173 168
          final int realHeight = Math.min(popupHeight,maxHeight);
......
205 200

  
206 201
  private void setupObjectWindow(final RubikActivity act, final float width, final float height)
207 202
    {
208
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);
203
    int icon = RubikActivity.getDrawable(R.drawable.small_cube2,R.drawable.medium_cube2, R.drawable.big_cube2, R.drawable.huge_cube2);
209 204

  
210 205
    BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
211 206
    int cubeWidth = bd.getIntrinsicWidth();
......
250 245
    for(int object=0; object< ObjectList.NUM_OBJECTS; object++)
251 246
      {
252 247
      final ObjectList list = ObjectList.getObject(object);
253
      final int[] sizes = list.getSizes();
254 248
      int iconSize = RubikActivity.getDrawableSize();
255
      int[] icons = list.getIconIDs(iconSize);
256
      int len = sizes.length;
249
      int icons = list.getIconID(iconSize);
257 250
      final int obj = object;
258 251
      int row = indices[object];
259 252

  
260
      for(int i=0; i<len; i++)
253
      ImageButton button = new ImageButton(act);
254
      button.setBackgroundResource(icons);
255
      button.setOnClickListener( new View.OnClickListener()
261 256
        {
262
        final int index = i;
263

  
264
        ImageButton button = new ImageButton(act);
265
        button.setBackgroundResource(icons[i]);
266
        button.setOnClickListener( new View.OnClickListener()
257
        @Override
258
        public void onClick(View v)
267 259
          {
268
          @Override
269
          public void onClick(View v)
260
          if( act.getPreRender().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
270 261
            {
271
            if( act.getPreRender().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
272
              {
273
              mObject = obj;
274
              mSize   = sizes[index];
275
              act.changeObject(list,sizes[index], true);
276
              adjustLevels(act);
277
              mController.clearMoves(act);
278
              }
279

  
280
            mObjectPopup.dismiss();
262
            mObject = obj;
263
            act.changeObject(list, true);
264
            adjustLevels(act);
265
            mController.clearMoves(act);
281 266
            }
282
          });
283 267

  
284
        GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
285
        params.bottomMargin = margin;
286
        params.topMargin    = margin;
287
        params.leftMargin   = margin;
288
        params.rightMargin  = margin;
268
          mObjectPopup.dismiss();
269
          }
270
        });
289 271

  
290
        nextInRow[row]++;
272
      GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
273
      params.bottomMargin = margin;
274
      params.topMargin    = margin;
275
      params.leftMargin   = margin;
276
      params.rightMargin  = margin;
291 277

  
292
        objectGrid.addView(button, params);
293
        }
278
      nextInRow[row]++;
279

  
280
      objectGrid.addView(button, params);
294 281
      }
295 282
    }
296 283

  
......
360 347
      {
361 348
      case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
362 349
              int object = play.getObject();
363
              int size   = play.getSize();
364
              int sizeIndex = ObjectList.getSizeIndex(object,size);
365 350
              Bundle sBundle = new Bundle();
366
              sBundle.putInt("tab", ObjectList.pack(object,sizeIndex) );
351
              sBundle.putInt("tab", object );
367 352
              sBundle.putBoolean("submitting", false);
368 353
              RubikDialogScores scores = new RubikDialogScores();
369 354
              scores.setArguments(sBundle);
......
420 405
  public void savePreferences(SharedPreferences.Editor editor)
421 406
    {
422 407
    editor.putInt("statePlay_object", mObject);
423
    editor.putInt("statePlay_size"  , mSize);
424 408

  
425 409
    if( mObjectPopup!=null )
426 410
      {
......
446 430
  public void restorePreferences(SharedPreferences preferences)
447 431
    {
448 432
    mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
449
    mSize  = preferences.getInt("statePlay_size"  , DEF_SIZE  );
450

  
451
    int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
452
    int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
433
    int dbLevel = ObjectList.getDBLevel(mObject);
453 434

  
454 435
    // This means the app has been upgraded to a new version which swapped the
455 436
    // Object for a new one with larger sizeIndex and now getMaxLevel() returns
456 437
    // 0. Reset the object to default, otherwise we'll get a crash later on.
457 438

  
458
    if( dbLevel==0 )
459
      {
460
      mObject = DEF_OBJECT;
461
      mSize   = DEF_SIZE;
462
      }
439
    if( dbLevel==0 ) mObject = DEF_OBJECT;
463 440
    }
464 441

  
465 442
///////////////////////////////////////////////////////////////////////////////////////////////////
466 443

  
467
  public boolean setObjectAndSize(RubikActivity act, ObjectList obj, int size)
444
  public boolean setObject(RubikActivity act, ObjectList obj)
468 445
    {
469
    if( mObject!=obj.ordinal() || mSize != size )
446
    if( mObject!=obj.ordinal() )
470 447
      {
471
      boolean success = false;
472

  
473
      for( int s: obj.getSizes() )
474
        if( s==size )
475
          {
476
          success = true;
477
          break;
478
          }
479

  
480
      if( success )
481
        {
482
        mObject = obj.ordinal();
483
        mSize   = size;
484

  
485
        if( mPlayLayout!=null ) adjustLevels(act);
486
        }
487

  
488
      return success;
448
      mObject = obj.ordinal();
449
      if( mPlayLayout!=null ) adjustLevels(act);
450
      return true;
489 451
      }
490 452

  
491
    return true;
453
    return false;
492 454
    }
493 455

  
494 456
///////////////////////////////////////////////////////////////////////////////////////////////////
......
497 459
  private void displayPopup(RubikActivity act, View view, PopupWindow window, int w, int h, int xoff, int yoff)
498 460
    {
499 461
    View topLayout = act.findViewById(R.id.relativeLayout);
462
    boolean isFullScreen;
500 463

  
501 464
    if( topLayout!=null )
502 465
      {
503 466
      topLayout.getLocationOnScreen(mLocation);
504
      mIsFullScreen = (mLocation[1]==0);
467
      isFullScreen = (mLocation[1]==0);
505 468
      }
506 469
    else
507 470
      {
508
      mIsFullScreen = true;
471
      isFullScreen = true;
509 472
      }
510 473

  
511 474
    // if on Android 11 or we are fullscreen
512
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || mIsFullScreen )
475
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R || isFullScreen )
513 476
      {
514 477
      window.showAsDropDown(view, xoff, yoff, Gravity.CENTER);
515 478
      window.update(view, w, h);
......
531 494

  
532 495
  private void adjustLevels(final RubikActivity act)
533 496
    {
534
    int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
535
    int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
536
    int numScrambles = ObjectList.getNumScramble(mObject, sizeIndex);
497
    int dbLevel = ObjectList.getDBLevel(mObject);
498
    int numScrambles = ObjectList.getNumScramble(mObject);
537 499
    int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
538 500
    String[] levels = new String[numLevel];
539 501

  
......
580 542
      button.setText(levels[i]);
581 543
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
582 544

  
583
      int icon = scores.isSolved(mObject, sizeIndex, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
545
      int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
584 546
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
585 547

  
586 548
      button.setOnClickListener( new View.OnClickListener()
......
616 578
    {
617 579
    return mObject;
618 580
    }
619

  
620
///////////////////////////////////////////////////////////////////////////////////////////////////
621

  
622
  public int getSize()
623
    {
624
    return mSize;
625
    }
626 581
  }

Also available in: Unified diff