Project

General

Profile

« Previous | Next » 

Revision 1088a219

Added by Leszek Koltunski over 2 years ago

Progress with colors in the Menu Level Buttons

View differences:

src/main/java/org/distorted/objects/RubikObjectList.java
395 395

  
396 396
///////////////////////////////////////////////////////////////////////////////////////////////////
397 397

  
398
  public static boolean setCurrObject(RubikActivity act, int ordinal)
398
  public static boolean setCurrObject(int ordinal)
399 399
    {
400 400
    if( mObject!=ordinal )
401 401
      {
402 402
      mObject = ordinal;
403
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
404
      play.setCurrObject(act);
405 403
      return true;
406 404
      }
407 405

  
src/main/java/org/distorted/screens/RubikScreenPattern.java
62 62
    {
63 63
    int object = RubikPatternList.getObject(mPatternOrdinal);
64 64

  
65
    if( !RubikObjectList.setCurrObject(act,object) )
65
    if( !RubikObjectList.setCurrObject(object) )
66 66
      {
67 67
      act.changeObject(object,false);
68 68
      }
src/main/java/org/distorted/screens/RubikScreenPlay.java
40 40

  
41 41
import org.distorted.dialogs.RubikDialogUpdates;
42 42
import org.distorted.external.RubikNetwork;
43
import org.distorted.external.RubikScores;
43 44
import org.distorted.external.RubikUpdates;
44 45

  
45 46
import org.distorted.main.R;
......
70 71
  private PopupWindow mObjectPopup, mMenuPopup;
71 72
  private WeakReference<RubikActivity> mWeakAct;
72 73
  private TextView mBubbleUpdates;
74
  private Button[] mLevel;
73 75
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mMenuButtonHeight, mMenuTextSize;
74 76
  private int mLevelValue;
75 77
  private int mColCount, mRowCount, mMaxRowCount;
......
170 172
          {
171 173
          View popupView = mMenuPopup.getContentView();
172 174
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
175
          setupLevelColors();
173 176
          displayPopup(act,view,mMenuPopup,mMenuLayoutWidth,mMenuLayoutHeight,(int)(-mMenuLayoutWidth/2 + width/6),0);
174 177
          }
175 178
        }
......
235 238
            if( type==MainEntry.TYPE_OBJECT )
236 239
              {
237 240
              int ordinal = mainEntry.getOrdinal();
238
              RubikObjectList.setCurrObject(act,ordinal);
241
              RubikObjectList.setCurrObject(ordinal);
239 242
              act.changeObject(ordinal,true);
240
              if( mMenuPopup!=null ) adjustLevels(act);
243
              if( mMenuPopup!=null ) setupLevelColors();
241 244
              mMovesController.clearMoves(act);
242 245
              }
243 246
            else if( type==MainEntry.TYPE_CREATOR )
......
458 461
    levels.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
459 462

  
460 463
    setupLevelButtons(act,layout,padding);
464
    setupLevelColors();
461 465
    }
462 466

  
463 467
///////////////////////////////////////////////////////////////////////////////////////////////////
......
469 473
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(sizeW,sizeH);
470 474
    params.setMargins(padding/2,0,padding/2,0);
471 475

  
472
    Button level1 = layout.findViewById(R.id.level1);
473
    level1.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
474
    level1.setLayoutParams(params);
475
    setupLevelButton(act,level1,1);
476
    Button level2 = layout.findViewById(R.id.level2);
477
    level2.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
478
    level2.setLayoutParams(params);
479
    setupLevelButton(act,level2,2);
480
    Button level3 = layout.findViewById(R.id.level3);
481
    level3.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
482
    level3.setLayoutParams(params);
483
    setupLevelButton(act,level3,3);
484
    Button level4 = layout.findViewById(R.id.level4);
485
    level4.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
486
    level4.setLayoutParams(params);
487
    setupLevelButton(act,level4,4);
488
    Button level5 = layout.findViewById(R.id.level5);
489
    level5.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
490
    level5.setLayoutParams(params);
491
    setupLevelButton(act,level5,5);
492
    Button level6 = layout.findViewById(R.id.level6);
493
    level6.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
494
    level6.setLayoutParams(params);
495
    setupLevelButton(act,level6,6);
496
    Button level7 = layout.findViewById(R.id.level7);
497
    level7.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
498
    level7.setLayoutParams(params);
499
    setupLevelButton(act,level7,7);
500
    Button level8 = layout.findViewById(R.id.level8);
501
    level8.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
502
    level8.setLayoutParams(params);
503
    setupLevelButton(act,level8,8);
504
    Button levelM = layout.findViewById(R.id.levelM);
505
    levelM.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
506
    levelM.setLayoutParams(params);
507
    setupLevelButton(act,levelM,9);
508
    }
476
    mLevel = new Button[LEVELS_SHOWN+1];
509 477

  
510
///////////////////////////////////////////////////////////////////////////////////////////////////
478
    mLevel[0] = layout.findViewById(R.id.level1);
479
    mLevel[1] = layout.findViewById(R.id.level2);
480
    mLevel[2] = layout.findViewById(R.id.level3);
481
    mLevel[3] = layout.findViewById(R.id.level4);
482
    mLevel[4] = layout.findViewById(R.id.level5);
483
    mLevel[5] = layout.findViewById(R.id.level6);
484
    mLevel[6] = layout.findViewById(R.id.level7);
485
    mLevel[7] = layout.findViewById(R.id.level8);
486
    mLevel[8] = layout.findViewById(R.id.levelM);
511 487

  
512
  private void setupLevelButton(RubikActivity act, Button button, int level)
513
    {
514
    button.setOnClickListener( new View.OnClickListener()
488
    for(int i=0; i<=LEVELS_SHOWN; i++)
489
      {
490
      final int ii = i;
491
      mLevel[i].setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
492
      mLevel[i].setLayoutParams(params);
493
      mLevel[i].setOnClickListener( new View.OnClickListener()
515 494
        {
516 495
        @Override
517 496
        public void onClick(View v)
......
524 503

  
525 504
            int currObject = RubikObjectList.getCurrObject();
526 505
            RubikObject object = RubikObjectList.getObject(currObject);
527
            final int scrambles = level<=LEVELS_SHOWN ? level : (object==null ? 0 : object.getNumScramble());
528

  
529
            mLevelValue = level;
506
            final int scrambles = ii<LEVELS_SHOWN ? ii+1 : (object==null ? 0 : object.getNumScramble());
507
            mLevelValue = ii+1;
530 508
            mShouldReactToEndOfScrambling = true;
531 509
            control.scrambleObject(scrambles);
532 510
            }
533 511
          }
534 512
        });
513
      }
514
    }
515

  
516
///////////////////////////////////////////////////////////////////////////////////////////////////
517

  
518
  private void setupLevelColors()
519
    {
520
    int currObject = RubikObjectList.getCurrObject();
521
    int dbLevel = RubikObjectList.getDBLevel(currObject);
522
    RubikScores scores = RubikScores.getInstance();
523

  
524
    for(int i=0; i<=LEVELS_SHOWN; i++)
525
      {
526
      int level = i<LEVELS_SHOWN ? i : dbLevel;
527
      boolean isSolved = scores.isSolved(currObject,level);
528
      int icon = isSolved ? R.drawable.ui_solved : R.drawable.ui_notsolved;
529
      mLevel[i].setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
530
      }
535 531
    }
536 532

  
537 533
///////////////////////////////////////////////////////////////////////////////////////////////////
......
561 557

  
562 558
  public void restorePreferences(SharedPreferences preferences)
563 559
    {
564
    mLevelValue    = preferences.getInt("play_LevelValue", 0);
565
    }
566

  
567
///////////////////////////////////////////////////////////////////////////////////////////////////
568

  
569
  public void setCurrObject(RubikActivity act)
570
    {
571
    if( mMenuPopup!=null ) adjustLevels(act);
560
    mLevelValue = preferences.getInt("play_LevelValue", 0);
572 561
    }
573 562

  
574 563
///////////////////////////////////////////////////////////////////////////////////////////////////
......
616 605
      }
617 606
    }
618 607

  
619
///////////////////////////////////////////////////////////////////////////////////////////////////
620
/*
621
  private void adjustSolvedIcons()
622
    {
623
    if( mPlayLayout!=null )
624
      {
625
      int currObject = RubikObjectList.getCurrObject();
626
      int dbLevel = RubikObjectList.getDBLevel(currObject);
627
      int numLevel= Math.min(dbLevel, LEVELS_SHOWN)+1;
628
      RubikScores scores = RubikScores.getInstance();
629

  
630
      for(int i=0; i<numLevel; i++)
631
        {
632
        int level = i<numLevel-1 ? i : dbLevel;
633
        Button button = (Button)mPlayLayout.getChildAt(i);
634
        boolean isSolved = i>0 ? scores.isSolved(currObject, level-1) : hasBeenPlayed();
635
        int icon = isSolved ? R.drawable.ui_solved : R.drawable.ui_notsolved;
636
        button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
637
        }
638
      }
639
    }
640
*/
641
///////////////////////////////////////////////////////////////////////////////////////////////////
642

  
643
  private void adjustLevels(final RubikActivity act)
644
    {
645
    /*
646
    int currObject = RubikObjectList.getCurrObject();
647
    int dbLevel = RubikObjectList.getDBLevel(currObject);
648
    RubikObject object = RubikObjectList.getObject(currObject);
649
    int numScrambles = object==null ? 0 : object.getNumScramble();
650
    int numLevel = Math.min(dbLevel, LEVELS_SHOWN)+1;
651
    String[] levels = new String[numLevel];
652

  
653
    levels[0] = act.getString(R.string.free_play);
654
    for(int i=1; i<numLevel-1; i++) levels[i] = act.getString(R.string.lv_placeholder,i);
655
    levels[numLevel-1] = act.getString(R.string.level_full);
656

  
657
    if( mLevelValue>dbLevel || mLevelValue<1 ||
658
       (mLevelValue<dbLevel || mLevelValue>LEVELS_SHOWN ) ) mLevelValue=1;
659

  
660
    float width  = act.getScreenWidthInPixels();
661
    int margin   = (int)(width*RubikActivity.SMALL_MARGIN);
662
    int padding  = (int)(width*RubikActivity.PADDING);
663
    int butWidth = 0;//mPlayLayoutWidth - 2*padding;
664
    int butHeight= (int)mMenuItemSize;
665
    int bigButH  = (int)(mMenuItemSize*BIG_BUTTON) ;
666

  
667
    LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( butWidth, butHeight );
668
    pM.setMargins(margin, 0, margin, margin);
669
    LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( butWidth, bigButH   );
670
    pB.setMargins(margin, margin, margin, 2*margin);
671

  
672
    mPlayLayout.removeAllViews();
673

  
674
    for(int i=0; i<numLevel; i++)
675
      {
676
      final int level     = i<numLevel-1 ? i : dbLevel;
677
      final int scrambles = i<numLevel-1 ? i : numScrambles;
678
      Button button = new Button(act);
679
      button.setLayoutParams(i==0 ? pB : (i==numLevel-1 ? pB : pM));
680
      button.setText(levels[i]);
681
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
682

  
683
      button.setOnClickListener( new View.OnClickListener()
684
        {
685
        @Override
686
        public void onClick(View v)
687
          {
688
          ObjectControl control = act.getControl();
689

  
690
          if(control.isUINotBlocked())
691
            {
692
            if( mPlayPopup!=null ) mPlayPopup.dismiss();
693

  
694
            if( level>0 )
695
              {
696
              mLevelValue = level;
697
              mShouldReactToEndOfScrambling = true;
698
              control.scrambleObject(scrambles);
699
              }
700
            else
701
              {
702
              addToPlayedObjects();
703
              mShouldReactToEndOfScrambling = false;
704
              ScreenList.switchScreen(act, ScreenList.FREE);
705
              }
706
            }
707
          }
708
        });
709

  
710
      mPlayLayout.addView(button);
711
      }
712

  
713
     */
714
    }
715

  
716 608
///////////////////////////////////////////////////////////////////////////////////////////////////
717 609

  
718 610
  public int getLevel()
src/main/java/org/distorted/screens/RubikScreenSolver.java
87 87
    act.changeIfDifferent(currentObject,control);
88 88
    control.solveOnly();
89 89

  
90
    RubikObjectList.setCurrObject(act, currentObject);
90
    RubikObjectList.setCurrObject(currentObject);
91 91

  
92 92
    generateFaceColors();
93 93

  

Also available in: Unified diff