Project

General

Profile

« Previous | Next » 

Revision 400ff34d

Added by Leszek Koltunski over 2 years ago

Move the 'currObject' from RubikScreenPlay (WTF?) to RubikObjectList.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogNewRecord.java
38 38
import org.distorted.main.R;
39 39
import org.distorted.main.RubikActivity;
40 40
import org.distorted.network.RubikScores;
41
import org.distorted.objects.RubikObjectList;
41 42
import org.distorted.screens.ScreenList;
42 43
import org.distorted.screens.RubikScreenPlay;
43 44

  
......
78 79

  
79 80
        if( name.length()>0 )
80 81
          {
81
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
82
          int object = play.getObject();
82
          int object = RubikObjectList.getCurrObject();
83 83

  
84 84
          bundle.putInt("tab", object );
85 85
          bundle.putBoolean("submitting", true);
src/main/java/org/distorted/dialogs/RubikDialogPattern.java
131 131

  
132 132
  private int getPatternOrdinal()
133 133
    {
134
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
135
    int obj  = play.getObject();
134
    int obj = RubikObjectList.getCurrObject();
136 135
    int ret = RubikPatternList.getOrdinal(obj);
137 136

  
138 137
    if( ret<0 )
139 138
      {
140
      ret = RubikPatternList.getOrdinal(RubikScreenPlay.DEF_OBJECT);
139
      ret = RubikPatternList.getOrdinal(RubikObjectList.DEF_OBJECT);
141 140
      }
142 141

  
143 142
    return ret;
src/main/java/org/distorted/dialogs/RubikDialogSetName.java
41 41
import org.distorted.main.R;
42 42
import org.distorted.main.RubikActivity;
43 43
import org.distorted.network.RubikScores;
44
import org.distorted.objects.RubikObjectList;
44 45
import org.distorted.screens.ScreenList;
45 46
import org.distorted.screens.RubikScreenPlay;
46 47

  
......
145 146
          RubikActivity act = (RubikActivity)getActivity();
146 147
          ScreenList.switchScreen(act, ScreenList.PLAY);
147 148
          RubikScores.getInstance().setName(name);
148
          RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
149 149

  
150 150
          Bundle bundle = new Bundle();
151
          bundle.putInt("tab", play.getObject() );
151
          bundle.putInt("tab", RubikObjectList.getCurrObject() );
152 152
          bundle.putBoolean("submitting", true);
153 153

  
154 154
          RubikDialogScores scores = new RubikDialogScores();
src/main/java/org/distorted/dialogs/RubikDialogTutorial.java
43 43

  
44 44
import org.distorted.main.R;
45 45
import org.distorted.main.RubikActivity;
46
import org.distorted.objects.RubikObjectList;
46 47
import org.distorted.screens.RubikScreenPlay;
47 48
import org.distorted.screens.ScreenList;
48 49
import org.distorted.tutorials.TutorialList;
......
128 129

  
129 130
  private int getTutorialOrdinal()
130 131
    {
131
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
132
    int obj = play.getObject();
133

  
132
    int obj = RubikObjectList.getCurrObject();
134 133
    int ret = TutorialList.getOrdinal(obj);
135 134

  
136 135
    if( ret<0 )
137 136
      {
138
      ret = TutorialList.getOrdinal(RubikScreenPlay.DEF_OBJECT);
137
      ret = TutorialList.getOrdinal(RubikObjectList.DEF_OBJECT);
139 138
      }
140 139

  
141 140
    return ret;
src/main/java/org/distorted/main/RubikActivity.java
256 256
        scores.setCountry(this);
257 257
        }
258 258

  
259
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
260
      int object = play.getObject();
259
      int object = RubikObjectList.getCurrObject();
261 260
      changeIfDifferent(object,view.getObjectControl());
262 261

  
263 262
      if( mIsChinese && !mPolicyAccepted ) PrivacyPolicy();
......
307 306
        ScreenList.getScreen(i).getScreenClass().savePreferences(editor);
308 307
        }
309 308

  
309
      RubikObjectList.savePreferences(editor);
310 310
      ScreenList.savePreferences(editor);
311 311
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
312 312
      view.getObjectControl().savePreferences(editor);
......
333 333
        ScreenList.getScreen(i).getScreenClass().restorePreferences(preferences);
334 334
        }
335 335

  
336
      RubikObjectList.restorePreferences(preferences);
336 337
      ScreenList.restorePreferences(preferences);
337 338

  
338 339
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
src/main/java/org/distorted/main/RubikObjectLibInterface.java
100 100
    {
101 101
    RubikScreenPlay play= (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
102 102
    RubikScores scores  = RubikScores.getInstance();
103

  
104
    int object  = play.getObject();
103
    int object  = RubikObjectList.getCurrObject();
105 104
    int level   = play.getLevel();
106 105
    String name = scores.getName();
107 106
    RubikObject obj = RubikObjectList.getObject(object);
......
433 432
    {
434 433
    RubikScreenSolver solver = (RubikScreenSolver) ScreenList.SVER.getScreenClass();
435 434
    int color = solver.getCurrentColor();
436
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
437
    int currObject = play.getObject();
435
    int currObject = RubikObjectList.getCurrObject();
438 436
    mLastCubitColor = SolverMain.cubitIsLocked(currObject,cubit);
439 437
    mLastCubit = cubit;
440 438
    mLastCubitFace = face;
src/main/java/org/distorted/objects/RubikObjectList.java
19 19

  
20 20
package org.distorted.objects;
21 21

  
22
import android.content.SharedPreferences;
23

  
24
import org.distorted.main.RubikActivity;
22 25
import org.distorted.objectlib.main.ObjectConstants;
23 26
import org.distorted.objectlib.main.ObjectType;
27
import org.distorted.screens.RubikScreenPlay;
28
import org.distorted.screens.ScreenList;
24 29

  
25 30
import java.util.ArrayList;
26 31
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
......
29 34

  
30 35
public class RubikObjectList
31 36
{
37
  public static final int DEF_OBJECT= ObjectConstants.CUBE_3;
38

  
32 39
  public static int MAX_LEVEL;
33 40

  
34 41
  private static RubikObjectList mType;
35 42
  private static int mNumObjects;
36 43
  private static ArrayList<RubikObject> mObjects;
44
  private static int mObject = DEF_OBJECT;
37 45

  
38 46
  static
39 47
    {
......
99 107
    return type.getNumScramble();
100 108
    }
101 109

  
110
///////////////////////////////////////////////////////////////////////////////////////////////////
111

  
112
  public static void savePreferences(SharedPreferences.Editor editor)
113
    {
114
    RubikObject object = getObject(mObject);
115

  
116
    if( object!=null )
117
      {
118
      editor.putString("statePlay_objName", object.getName() );
119
      }
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
  public static void restorePreferences(SharedPreferences preferences)
125
    {
126
    RubikObject object = getObject(DEF_OBJECT);
127
    String defName = object==null ? "CUBE_3" : object.getName();
128
    String objName= preferences.getString("statePlay_objName",defName);
129
    mObject = getOrdinal(objName);
130

  
131
    if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT;
132
    }
133

  
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  public static boolean setCurrObject(RubikActivity act, int ordinal)
137
    {
138
    if( mObject!=ordinal )
139
      {
140
      mObject = ordinal;
141
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
142
      play.setCurrObject(act);
143
      return true;
144
      }
145

  
146
    return false;
147
    }
148

  
149
///////////////////////////////////////////////////////////////////////////////////////////////////
150

  
151
  public static int getCurrObject()
152
    {
153
    return mObject;
154
    }
155

  
102 156
///////////////////////////////////////////////////////////////////////////////////////////////////
103 157

  
104 158
  public static RubikObject getObject(int ordinal)
src/main/java/org/distorted/screens/RubikScreenPattern.java
34 34
import org.distorted.dialogs.RubikDialogPattern;
35 35
import org.distorted.helpers.TransparentImageButton;
36 36
import org.distorted.main.RubikActivity;
37
import org.distorted.objects.RubikObjectList;
37 38
import org.distorted.patterns.RubikPattern;
38 39
import org.distorted.patterns.RubikPatternList;
39 40

  
......
59 60

  
60 61
  void leaveScreen(RubikActivity act)
61 62
    {
62
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
63 63
    int object = RubikPatternList.getObject(mPatternOrdinal);
64 64

  
65
    if( !play.setObject(act,object) )
65
    if( !RubikObjectList.setCurrObject(act,object) )
66 66
      {
67 67
      act.changeObject(object,false);
68 68
      }
src/main/java/org/distorted/screens/RubikScreenPlay.java
35 35
import android.widget.LinearLayout;
36 36
import android.widget.PopupWindow;
37 37

  
38
import org.distorted.objectlib.main.ObjectConstants;
39 38
import org.distorted.objectlib.main.ObjectControl;
40 39

  
41 40
import org.distorted.main.R;
......
58 57
  {
59 58
  public static final int NUM_COLUMNS  = 4;
60 59
  public static final int LEVELS_SHOWN = 10;
61
  public static final int DEF_OBJECT= ObjectConstants.CUBE_3;
62 60

  
63 61
  private static final int[] BUTTON_LABELS = { R.string.scores,
64 62
                                               R.string.patterns,
......
73 71
  private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
74 72
  private TransparentButton mPlayButton;
75 73
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
76
  private int mObject = DEF_OBJECT;
74
  private LinearLayout mPlayLayout;
77 75
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
78 76
  private int mLevelValue;
79 77
  private float mButtonSize, mMenuItemSize, mMenuTextSize;
80 78
  private int mColCount, mRowCount, mMaxRowCount;
81
  private LinearLayout mPlayLayout;
82 79
  private int mUpperBarHeight;
83 80
  private boolean mShouldReactToEndOfScrambling;
84 81

  
......
179 176
          final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) );
180 177
          View popupView = mPlayPopup.getContentView();
181 178
          popupView.setSystemUiVisibility(RubikActivity.FLAGS);
182
          final int dbLevel = RubikObjectList.getDBLevel(mObject);
179
          final int object  = RubikObjectList.getCurrObject();
180
          final int dbLevel = RubikObjectList.getDBLevel(object);
183 181
          final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
184 182
          final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
185 183
          final int realHeight = Math.min(popupHeight,maxHeight);
......
268 266
      int iconSize = RubikActivity.getDrawableSize();
269 267
      int icons = robject==null ? 0 : robject.getIconID(iconSize);
270 268
      int row = object/NUM_COLUMNS;
269
      final int ordinal = robject==null ? 0 : robject.getOrdinal();
271 270

  
272 271
      ImageButton button = new ImageButton(act);
273 272
      button.setBackgroundResource(icons);
......
278 277
          {
279 278
          if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
280 279
            {
281
            mObject = robject==null ? 0 : robject.getOrdinal();
282
            act.changeObject(mObject, true);
280
            RubikObjectList.setCurrObject(act,ordinal);
281
            act.changeObject(ordinal,true);
283 282
            if( mPlayLayout!=null ) adjustLevels(act);
284 283
            mMovesController.clearMoves(act);
285 284
            }
......
338 337
      @Override
339 338
      public void onClick(View v)
340 339
        {
341
        act.switchConfig(mObject);
340
        int currObject = RubikObjectList.getCurrObject();
341
        act.switchConfig(currObject);
342 342
        }
343 343
      });
344 344
    }
......
408 408
    switch(button)
409 409
      {
410 410
      case 0: Bundle sBundle = new Bundle();
411
              sBundle.putInt("tab", mObject );
411
              int currObject = RubikObjectList.getCurrObject();
412
              sBundle.putInt("tab", currObject );
412 413
              sBundle.putBoolean("submitting", false);
413 414
              RubikDialogScores scores = new RubikDialogScores();
414 415
              scores.setArguments(sBundle);
......
460 461
      @Override
461 462
      public void onClick(View v)
462 463
        {
463
        RubikObject object = RubikObjectList.getObject(mObject);
464
        int currObject = RubikObjectList.getCurrObject();
465
        RubikObject object = RubikObjectList.getObject(currObject);
464 466
        int numScrambles = object==null ? 0 : object.getNumScramble();
465 467
        mShouldReactToEndOfScrambling = false;
466 468
        act.getControl().scrambleObject(numScrambles);
......
472 474

  
473 475
  public void savePreferences(SharedPreferences.Editor editor)
474 476
    {
475
    android.util.Log.e("D", "savePrefs");
476 477

  
477
    RubikObject object = RubikObjectList.getObject(mObject);
478

  
479
    if( object!=null )
480
      {
481
      editor.putString("statePlay_objName", object.getName() );
482
      }
483 478
    }
484 479

  
485 480
///////////////////////////////////////////////////////////////////////////////////////////////////
486 481

  
487 482
  public void restorePreferences(SharedPreferences preferences)
488 483
    {
489
    RubikObject object = RubikObjectList.getObject(DEF_OBJECT);
490
    String defName = object==null ? "CUBE_3" : object.getName();
491
    String objName= preferences.getString("statePlay_objName",defName);
492
    mObject = RubikObjectList.getOrdinal(objName);
493 484

  
494
    if( mObject<0 || mObject>=RubikObjectList.getNumObjects() ) mObject = DEF_OBJECT;
495 485
    }
496 486

  
497 487
///////////////////////////////////////////////////////////////////////////////////////////////////
498 488

  
499
  public boolean setObject(RubikActivity act, int ordinal)
489
  public void setCurrObject(RubikActivity act)
500 490
    {
501
    if( mObject!=ordinal )
502
      {
503
      mObject = ordinal;
504
      if( mPlayLayout!=null ) adjustLevels(act);
505
      return true;
506
      }
507

  
508
    return false;
491
    if( mPlayLayout!=null ) adjustLevels(act);
509 492
    }
510 493

  
511 494
///////////////////////////////////////////////////////////////////////////////////////////////////
......
557 540

  
558 541
  public void adjustSolvedIcons()
559 542
    {
560
    int dbLevel = RubikObjectList.getDBLevel(mObject);
543
    int currObject = RubikObjectList.getCurrObject();
544
    int dbLevel = RubikObjectList.getDBLevel(currObject);
561 545
    int numLevel= Math.min(dbLevel, LEVELS_SHOWN);
562 546
    RubikScores scores = RubikScores.getInstance();
563 547

  
......
565 549
      {
566 550
      int level = i<numLevel-1 ? i+1 : dbLevel;
567 551
      Button button = (Button)mPlayLayout.getChildAt(i);
568
      int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
552
      int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
569 553
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
570 554
      }
571 555
    }
......
574 558

  
575 559
  private void adjustLevels(final RubikActivity act)
576 560
    {
577
    int dbLevel = RubikObjectList.getDBLevel(mObject);
578
    RubikObject object = RubikObjectList.getObject(mObject);
561
    int currObject = RubikObjectList.getCurrObject();
562
    int dbLevel = RubikObjectList.getDBLevel(currObject);
563
    RubikObject object = RubikObjectList.getObject(currObject);
579 564
    int numScrambles = object==null ? 0 : object.getNumScramble();
580 565
    int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
581 566
    String[] levels = new String[numLevel];
......
623 608
      button.setText(levels[i]);
624 609
      button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
625 610

  
626
      int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
611
      int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
627 612
      button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
628 613

  
629 614
      button.setOnClickListener( new View.OnClickListener()
......
660 645
    {
661 646
    return mShouldReactToEndOfScrambling;
662 647
    }
663

  
664
///////////////////////////////////////////////////////////////////////////////////////////////////
665

  
666
  public int getObject()
667
    {
668
    return mObject;
669
    }
670 648
  }
src/main/java/org/distorted/screens/RubikScreenSolver.java
40 40
import org.distorted.helpers.TransparentImageButton;
41 41
import org.distorted.main.R;
42 42
import org.distorted.main.RubikActivity;
43
import org.distorted.objects.RubikObjectList;
43 44
import org.distorted.solvers.ImplementedSolversList;
44 45
import org.distorted.solvers.SolverMain;
45 46

  
......
86 87
    act.changeIfDifferent(currentObject,control);
87 88
    control.solveOnly();
88 89

  
89
    RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
90
    play.setObject(act, currentObject);
90
    RubikObjectList.setCurrObject(act, currentObject);
91 91

  
92 92
    generateFaceColors();
93 93

  
src/main/java/org/distorted/screens/RubikScreenSolving.java
34 34
import org.distorted.main.R;
35 35
import org.distorted.main.RubikActivity;
36 36
import org.distorted.network.RubikScores;
37
import org.distorted.objects.RubikObjectList;
37 38

  
38 39
///////////////////////////////////////////////////////////////////////////////////////////////////
39 40

  
......
185 186
      mElapsed = System.currentTimeMillis()-mStartTime;
186 187

  
187 188
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
188
      int object = play.getObject();
189
      int object = RubikObjectList.getCurrObject();
189 190
      int level = play.getLevel();
190 191
      boolean isNew = mScores.setRecord(object, level, mElapsed);
191 192

  
src/main/java/org/distorted/tutorials/TutorialScreen.java
75 75
      @Override
76 76
      public void onClick(View v)
77 77
        {
78
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
79
        int object = play.getObject();
78
        int object = RubikObjectList.getCurrObject();
80 79
        RubikObject obj = RubikObjectList.getObject(object);
81 80
        int numScrambles = obj==null ? 0 : obj.getNumScramble();
82 81
        act.getControl().scrambleObject(numScrambles);

Also available in: Unified diff