Project

General

Profile

« Previous | Next » 

Revision 4888e97c

Added by Leszek Koltunski over 4 years ago

Major restructuring around making it possible to include different kinds of RubikObjects in the UI.

View differences:

src/main/java/org/distorted/dialog/RubikDialogScores.java
103 103
    tabLayout.setupWithViewPager(viewPager);
104 104

  
105 105
    viewPager.setCurrentItem(curTab);
106
    RubikObjectList list;
106 107

  
107
    for (int i = 0; i< RubikObjectList.LENGTH; i++)
108
    for (int object=0; object<RubikObjectList.NUM_OBJECTS; object++)
108 109
      {
109
      ImageView imageView = new ImageView(act);
110
      imageView.setImageResource(RubikObjectList.getObject(i).getIconID());
111
      TabLayout.Tab tab = tabLayout.getTabAt(i);
112
      if(tab!=null) tab.setCustomView(imageView);
110
      list = RubikObjectList.getObject(object);
111
      int[] iconID = list.getIconIDs();
112
      int len = list.getSizes().length;
113

  
114
      for(int size=0; size<len; size++)
115
        {
116
        int t = RubikObjectList.pack(object,size);
117
        ImageView imageView = new ImageView(act);
118
        imageView.setImageResource(iconID[size]);
119
        TabLayout.Tab tab = tabLayout.getTabAt(t);
120
        if(tab!=null) tab.setCustomView(imageView);
121
        }
113 122
      }
114 123

  
115 124
    return builder.create();
src/main/java/org/distorted/dialog/RubikDialogScoresPagerAdapter.java
28 28
import android.widget.LinearLayout;
29 29

  
30 30
import org.distorted.network.RubikScoresDownloader;
31
import static org.distorted.object.RubikObjectList.LENGTH;
31
import org.distorted.object.RubikObjectList;
32

  
32 33
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
33 34

  
34 35
///////////////////////////////////////////////////////////////////////////////////////////////////
......
38 39
  private FragmentActivity mAct;
39 40
  private RubikDialogScoresView[] mViews;
40 41
  private ViewPager mViewPager;
42
  private int mNumTabs;
41 43

  
42 44
///////////////////////////////////////////////////////////////////////////////////////////////////
43 45

  
......
49 51

  
50 52
    addPage(mViews[c],country[c],name[c],time[c]);
51 53

  
52
    for(int i=0; i<LENGTH; i++)
54
    for(int i=0; i<mNumTabs; i++)
53 55
      {
54 56
      if( i==c ) continue;
55 57

  
......
66 68
      @Override
67 69
      public void run()
68 70
        {
69
        for(int i=0; i<LENGTH; i++)
71
        for(int i=0; i<mNumTabs; i++)
70 72
          {
71 73
          mViews[i].prepareView(mAct);
72 74
          }
......
119 121
      @Override
120 122
      public void run()
121 123
        {
122
        for(int i=0; i<LENGTH; i++)
124
        for(int i=0; i<mNumTabs; i++)
123 125
          {
124 126
          mViews[i].exception(exce);
125 127
          }
......
132 134
  RubikDialogScoresPagerAdapter(FragmentActivity act, ViewPager viewPager)
133 135
    {
134 136
    mAct = act;
135
    mViews = new RubikDialogScoresView[LENGTH];
137
    mNumTabs = RubikObjectList.getTotal();
138
    mViews = new RubikDialogScoresView[mNumTabs];
136 139
    mViewPager = viewPager;
137 140

  
138 141
    viewPager.setAdapter(this);
139
    viewPager.setOffscreenPageLimit(LENGTH-1);
142
    viewPager.setOffscreenPageLimit(mNumTabs-1);
140 143
    }
141 144

  
142 145
///////////////////////////////////////////////////////////////////////////////////////////////////
......
150 153

  
151 154
    boolean allCreated = true;
152 155

  
153
    for(int i=0; i<LENGTH; i++)
156
    for(int i=0; i<mNumTabs; i++)
154 157
      {
155 158
      if( mViews[i]==null )
156 159
        {
......
181 184
  @Override
182 185
  public int getCount()
183 186
    {
184
    return LENGTH;
187
    return mNumTabs;
185 188
    }
186 189

  
187 190
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/magic/RubikActivity.java
73 73
      restorePreferences();
74 74
      RubikState.setState(this);
75 75
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
76
      int ordinal = play.getButton();
77
      view.getRenderer().createObject(RubikObjectList.getObject(ordinal));
76

  
77
      int object = play.getObject();
78
      int size   = play.getSize();
79
      RubikObjectList obj = RubikObjectList.getObject(object);
80
      int objectSize = obj.getSizes()[size];
81

  
82
      view.getRenderer().createObject( obj, objectSize );
78 83
      }
79 84
    
80 85
///////////////////////////////////////////////////////////////////////////////////////////////////
......
93 98
      {
94 99
      int id = v.getId();
95 100

  
96
      if( id>=0 && id< RubikObjectList.LENGTH )
101
      if( id>=0 && id< RubikObjectList.getTotal() )
97 102
        {
98
        RubikObjectList object = RubikObjectList.getObject(id);
103
        int object = RubikObjectList.unpackObject(id);
104
        int size= RubikObjectList.unpackSize(id);
105

  
106
        RubikObjectList obj = RubikObjectList.getObject(object);
107
        int objectSize = obj.getSizes()[size];
99 108

  
100 109
        RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
101
        boolean success = view.getRenderer().createObject(object);
110
        boolean success = view.getRenderer().createObject(obj,objectSize);
102 111

  
103 112
        if( success )
104 113
          {
105 114
          RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
106
          play.markButton(this,id);
115
          play.markButton(this,object,size);
107 116
          }
108 117
        }
109 118

  
......
181 190
    public void Scores(View v)
182 191
      {
183 192
      RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
184
      int tab = play.getButton();
193
      int object = play.getObject();
194
      int size   = play.getSize();
185 195

  
186 196
      Bundle bundle = new Bundle();
187
      bundle.putInt("tab", tab);
197
      bundle.putInt("tab", RubikObjectList.pack(object,size) );
188 198

  
189 199
      RubikDialogScores scores = new RubikDialogScores();
190 200
      scores.setArguments(bundle);
src/main/java/org/distorted/magic/RubikRenderer.java
44 44
    private RubikSurfaceView mView;
45 45
    private DistortedScreen mScreen;
46 46
    private RubikObjectList mNextObject;
47
    private int mNextSize;
47 48
    private int mScrambleObjectNum;
48 49
    private long mRotationFinishedID;
49 50
    private long[] mEffectID;
......
85 86

  
86 87
///////////////////////////////////////////////////////////////////////////////////////////////////
87 88

  
88
   private void createObjectNow(RubikObjectList object)
89
   private void createObjectNow(RubikObjectList object, int size)
89 90
     {
90 91
     boolean firstTime = (mNewObject==null);
91 92

  
92 93
     if( mOldObject!=null ) mOldObject.releaseResources();
93 94
     mOldObject = mNewObject;
94 95

  
95
     mNewObject = object.create(mView.getQuatCurrent(), mView.getQuatAccumulated());
96
     mNewObject = object.create(size, mView.getQuatCurrent(), mView.getQuatAccumulated());
96 97
     mNewObject.createTexture();
97 98
     mView.setMovement(object.getObjectMovementClass());
98 99

  
......
154 155

  
155 156
///////////////////////////////////////////////////////////////////////////////////////////////////
156 157

  
157
   boolean createObject(RubikObjectList object)
158
   boolean createObject(RubikObjectList object, int size)
158 159
     {
159
     if( mCanDrag && mCanRotate && object!=mNextObject )
160
     if( mCanDrag && mCanRotate && (object!=mNextObject || mNextSize!=size) && size>0 )
160 161
       {
161 162
       mChangeObject = true;
162 163
       mNextObject = object;
164
       mNextSize   = size;
163 165
       return true;
164 166
       }
165 167

  
......
286 288
       mCanDrag      = false;
287 289
       mCanRotate    = false;
288 290
       mCanUI        = false;
289
       createObjectNow(mNextObject);
291
       createObjectNow(mNextObject, mNextSize);
290 292
       doEffectNow( BaseEffect.Type.SIZECHANGE );
291 293
       }
292 294

  
src/main/java/org/distorted/network/RubikScoresDownloader.java
19 19

  
20 20
package org.distorted.network;
21 21

  
22
import org.distorted.object.RubikObjectList;
23

  
22 24
import java.io.InputStream;
23 25
import java.net.HttpURLConnection;
24 26
import java.net.URL;
25 27
import java.net.UnknownHostException;
26 28

  
27
import static org.distorted.object.RubikObjectList.LENGTH;
28 29
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
29 30

  
30 31
///////////////////////////////////////////////////////////////////////////////////////////////////
......
86 87
  private static String mUserName, mVersion;
87 88
  private static int mNumRuns;
88 89

  
90
  private static int mTotal = RubikObjectList.getTotal();
89 91
  private static String mScores = "";
90
  private static String[][][] mCountry = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
91
  private static String[][][] mName    = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
92
  private static String[][][] mTime    = new String[LENGTH][MAX_SCRAMBLE][MAX_PLACES];
92
  private static String[][][] mCountry = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
93
  private static String[][][] mName    = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
94
  private static String[][][] mTime    = new String[mTotal][MAX_SCRAMBLE][MAX_PLACES];
93 95

  
94
  private static int[][] mPlaces = new int[LENGTH][MAX_SCRAMBLE];
96
  private static int[][] mPlaces = new int[mTotal][MAX_SCRAMBLE];
95 97

  
96 98
///////////////////////////////////////////////////////////////////////////////////////////////////
97 99

  
......
99 101
    {
100 102
    int begin=-1 ,end, len = mScores.length();
101 103

  
102
    for(int i=0; i<LENGTH; i++)
104
    for(int i=0; i<mTotal; i++)
103 105
      for(int j=0; j<MAX_SCRAMBLE; j++)
104 106
        {
105 107
        mPlaces[i][j] = 0;
......
127 129

  
128 130
    if( s5>s4 && s4>s3 && s3>s2 && s2>s1 && s1>0 )
129 131
      {
130
      int size = Integer.valueOf( row.substring(0,s1) );
132
      int size = Integer.parseInt( row.substring(0,s1) );
131 133

  
132
      if( size>=0 && size<LENGTH )
134
      if( size>=0 && size<mTotal )
133 135
        {
134
        int level      = Integer.valueOf( row.substring(s1+1,s2) );
135
        int place      = Integer.valueOf( row.substring(s2+1,s3) );
136
        int level      = Integer.parseInt( row.substring(s1+1,s2) );
137
        int place      = Integer.parseInt( row.substring(s2+1,s3) );
136 138
        String name    = row.substring(s3+1, s4);
137
        int time       = Integer.valueOf( row.substring(s4+1,s5) );
139
        int time       = Integer.parseInt( row.substring(s4+1,s5) );
138 140
        String country = row.substring(s5+1, s6);
139 141
        String realTime= String.valueOf(time/10.0f);
140 142

  
src/main/java/org/distorted/object/RubikCube.java
80 80

  
81 81
  RubikCube(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
82 82
    {
83
    super(size,quatCur,quatAcc,texture,mesh,effects);
83
    super(size, 60, quatCur,quatAcc,texture,mesh,effects);
84 84
    }
85 85

  
86 86
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/object/RubikObject.java
73 73

  
74 74
///////////////////////////////////////////////////////////////////////////////////////////////////
75 75

  
76
  RubikObject(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, MeshRectangles nodeMesh, DistortedEffects nodeEffects)
76
  RubikObject(int size, int fov, Static4D quatCur, Static4D quatAcc, DistortedTexture nodeTexture, MeshRectangles nodeMesh, DistortedEffects nodeEffects)
77 77
    {
78 78
    super(nodeTexture,nodeEffects,nodeMesh);
79 79

  
......
122 122
      attach(mCubits[i].mNode);
123 123
      }
124 124

  
125
    setProjection(30, 0.1f);
125
    setProjection(fov, 0.1f);
126 126
    }
127 127

  
128 128
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/object/RubikObjectList.java
29 29

  
30 30
public enum RubikObjectList
31 31
  {
32
  CUBE2 ( 2, R.drawable.cube2, RubikCube.class, RubikCubeMovement.class),
33
  CUBE3 ( 3, R.drawable.cube3, RubikCube.class, RubikCubeMovement.class),
34
  CUBE4 ( 4, R.drawable.cube4, RubikCube.class, RubikCubeMovement.class),
35
  CUBE5 ( 5, R.drawable.cube5, RubikCube.class, RubikCubeMovement.class),
32
  CUBE     ( new int[] {2,3,4},
33
             new int[] {R.drawable.cube2,R.drawable.cube3,R.drawable.cube4},
34
             new RubikCubeMovement() ),
35
  PYRAMINX ( new int[] {3,4},
36
             new int[] {R.drawable.pyra3,R.drawable.pyra4},
37
             new RubikPyraminxMovement() ),
36 38
  ;
37 39

  
38
  public static final int LENGTH = values().length;
39
  private final int mObjectSize, mIconID;
40
  final Class<? extends RubikObject> mObjectClass;
41
  final Class<? extends RubikObjectMovement> mObjectMovementClass;
40
  public static final int NUM_OBJECTS = values().length;
41
  public static final int MAX_SIZE;
42

  
43
  private final int[] mObjectSizes, mIconIDs;
44
  final RubikObjectMovement mObjectMovementClass;
42 45
  private static final RubikObjectList[] objects;
46
  private static int mNumAll;
43 47

  
44 48
  static
45 49
    {
46
    int i = 0;
47
    objects = new RubikObjectList[LENGTH];
50
    mNumAll = 0;
51
    int size, i = 0;
52
    objects = new RubikObjectList[NUM_OBJECTS];
53
    int maxsize = Integer.MIN_VALUE;
48 54

  
49
    for(RubikObjectList size: RubikObjectList.values())
55
    for(RubikObjectList object: RubikObjectList.values())
50 56
      {
51
      objects[i] = size;
57
      objects[i] = object;
52 58
      i++;
59
      size = object.mObjectSizes.length;
60
      mNumAll += size;
61
      if( size> maxsize ) maxsize = size;
53 62
      }
63

  
64
    MAX_SIZE = maxsize;
54 65
    }
55 66

  
56 67
///////////////////////////////////////////////////////////////////////////////////////////////////
......
62 73

  
63 74
///////////////////////////////////////////////////////////////////////////////////////////////////
64 75

  
65
  RubikObjectList(int size, int iconID, Class<? extends RubikObject > object, Class<? extends RubikObjectMovement> movement)
76
  public static int pack(int object, int size)
77
    {
78
    int ret = 0;
79
    for(int i=0; i<object; i++) ret += objects[i].mObjectSizes.length;
80

  
81
    return ret+size;
82
    }
83

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  public static int unpackSize(int number)
87
    {
88
    int num;
89

  
90
    for(int i=0; i<NUM_OBJECTS; i++)
91
      {
92
      num = objects[i].mObjectSizes.length;
93
      if( number<num ) return number;
94
      number -= num;
95
      }
96

  
97
    return -1;
98
    }
99

  
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

  
102
  public static int unpackObject(int number)
66 103
    {
67
    mObjectSize = size;
68
    mIconID     = iconID;
69
    mObjectClass= object;
104
    int num;
105

  
106
    for(int i=0; i<NUM_OBJECTS; i++)
107
      {
108
      num = objects[i].mObjectSizes.length;
109
      if( number<num ) return i;
110
      number -= num;
111
      }
112

  
113
    return -1;
114
    }
115

  
116
///////////////////////////////////////////////////////////////////////////////////////////////////
117

  
118
  public static int getTotal()
119
    {
120
    return mNumAll;
121
    }
122

  
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124

  
125
  RubikObjectList(int[] sizes, int[] iconIDs, RubikObjectMovement movement)
126
    {
127
    mObjectSizes= sizes;
128
    mIconIDs    = iconIDs;
70 129
    mObjectMovementClass = movement;
71 130
    }
72 131

  
73 132
///////////////////////////////////////////////////////////////////////////////////////////////////
74 133

  
75
  public int getIconID()
134
  public int[] getIconIDs()
76 135
    {
77
    return mIconID;
136
    return mIconIDs;
78 137
    }
79 138

  
80 139
///////////////////////////////////////////////////////////////////////////////////////////////////
81
// TODO - currently all objects in the list are RubikCubes of various sizes
82 140

  
83
  public RubikObject create(Static4D quatCur, Static4D quatAcc)
141
  public int[] getSizes()
142
    {
143
    return mObjectSizes;
144
    }
145

  
146
///////////////////////////////////////////////////////////////////////////////////////////////////
147

  
148
  public RubikObject create(int size, Static4D quatCur, Static4D quatAcc)
84 149
    {
85 150
    DistortedTexture texture = new DistortedTexture();
86 151
    DistortedEffects effects = new DistortedEffects();
87 152
    MeshRectangles mesh      = new MeshRectangles(20,20);   // mesh of the node, not of the cubits
88 153

  
89
    return new RubikPyraminx(mObjectSize, quatCur, quatAcc, texture, mesh, effects);
154
    switch(ordinal())
155
      {
156
      case 0: return new RubikCube    (size, quatCur, quatAcc, texture, mesh, effects);
157
      case 1: return new RubikPyraminx(size, quatCur, quatAcc, texture, mesh, effects);
158
      }
159

  
160
    return null;
90 161
    }
91 162

  
92 163
///////////////////////////////////////////////////////////////////////////////////////////////////
93
// TODO - currently all objects in the list are RubikCubes of various sizes
94 164

  
95 165
  public RubikObjectMovement getObjectMovementClass()
96 166
    {
97
    return new RubikPyraminxMovement();
167
    return mObjectMovementClass;
98 168
    }
99 169
  }
src/main/java/org/distorted/object/RubikPyraminx.java
85 85

  
86 86
  RubikPyraminx(int size, Static4D quatCur, Static4D quatAcc, DistortedTexture texture, MeshRectangles mesh, DistortedEffects effects)
87 87
    {
88
    super(size,quatCur,quatAcc,texture,mesh,effects);
88
    super(size, 30, quatCur,quatAcc,texture,mesh,effects);
89 89
    }
90 90

  
91 91
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/uistate/RubikStatePlay.java
43 43
  private static final int MIN_SCRAMBLE =  1;
44 44
  private static final int DEF_SCRAMBLE =  1;
45 45
  public  static final int MAX_SCRAMBLE = 18;
46
  private static final int DEF_BUTTON   = RubikObjectList.CUBE3.ordinal();
46
  private static final int DEF_OBJECT   = RubikObjectList.CUBE.ordinal();
47
  private static final int DEF_SIZE     =  1;  // i.e. the second from the list of CUBE's sizes
47 48

  
48 49
  private HorizontalNumberPicker mPicker;
49 50
  private int mPickerValue;
50
  private int mButton = DEF_BUTTON;
51
  private int mObject = DEF_OBJECT;
52
  private int mSize   = DEF_SIZE;
51 53

  
52 54
///////////////////////////////////////////////////////////////////////////////////////////////////
53 55

  
......
79 81
    int padding = (int)(3*scale + 0.5f);
80 82
    ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(size,size);
81 83

  
82
    for(int i = 0; i< RubikObjectList.LENGTH; i++)
84
    for(int i=0; i< RubikObjectList.NUM_OBJECTS; i++)
83 85
      {
84
      ImageButton button = new ImageButton(act);
85
      button.setLayoutParams(params);
86
      button.setId(i);
87
      button.setPadding(padding,0,padding,0);
88
      int iconID = RubikObjectList.getObject(i).getIconID();
89
      button.setImageResource(iconID);
90
      button.setOnClickListener(act);
91
      layoutBot.addView(button);
86
      int[] iconIDs = RubikObjectList.getObject(i).getIconIDs();
87
      int len = iconIDs.length;
88

  
89
      for(int s=0; s<len; s++)
90
        {
91
        ImageButton button = new ImageButton(act);
92
        button.setLayoutParams(params);
93
        button.setId(RubikObjectList.pack(i,s));
94
        button.setPadding(padding,0,padding,0);
95
        button.setImageResource(iconIDs[s]);
96
        button.setOnClickListener(act);
97
        layoutBot.addView(button);
98
        }
92 99
      }
93 100

  
94 101
    ViewGroup.LayoutParams params2 = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,size);
......
101 108
    button.setOnClickListener(act);
102 109
    layoutBot.addView(button);
103 110

  
104
    markButton(act,mButton);
111
    markButton(act,mObject,mSize);
105 112

  
106 113
    mPicker = act.findViewById(R.id.rubikNumberPicker);
107 114

  
......
119 126
    {
120 127
    if( mPicker!=null )
121 128
      {
122
      editor.putInt("scramble", mPicker.getValue() );
129
      editor.putInt("statePlay_scramble", mPicker.getValue() );
123 130
      }
124 131

  
125
    editor.putInt("button", mButton);
132
    editor.putInt("statePlay_object", mObject);
133
    editor.putInt("statePlay_size"  , mSize);
126 134
    }
127 135

  
128 136
///////////////////////////////////////////////////////////////////////////////////////////////////
129 137

  
130 138
  public void restorePreferences(SharedPreferences preferences)
131 139
    {
132
    mPickerValue= preferences.getInt("scramble", DEF_SCRAMBLE);
133
    mButton     = preferences.getInt("button"  , DEF_BUTTON  );
140
    mPickerValue= preferences.getInt("statePlay_scramble", DEF_SCRAMBLE);
141
    mObject     = preferences.getInt("statePlay_object"  , DEF_OBJECT  );
142
    mSize       = preferences.getInt("statePlay_size"    , DEF_SIZE    );
134 143
    }
135 144

  
136 145
///////////////////////////////////////////////////////////////////////////////////////////////////
......
142 151

  
143 152
///////////////////////////////////////////////////////////////////////////////////////////////////
144 153

  
145
  public int getButton()
154
  public int getObject()
146 155
    {
147
    return mButton;
156
    return mObject;
148 157
    }
149 158

  
150 159
///////////////////////////////////////////////////////////////////////////////////////////////////
151 160

  
152
  public void markButton(RubikActivity act, int button)
161
  public int getSize()
153 162
    {
154
    mButton = button;
163
    return mSize;
164
    }
165

  
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167

  
168
  public void markButton(RubikActivity act, int object, int size)
169
    {
170
    mObject = object;
171
    mSize   = size;
172

  
173
    int lookingFor = RubikObjectList.pack(object,size);
174
    int len = RubikObjectList.getTotal();
155 175

  
156
    for(int b = 0; b< RubikObjectList.LENGTH; b++)
176
    for(int button=0; button<len; button++)
157 177
      {
158
      Drawable d = act.findViewById(b).getBackground();
178
      Drawable d = act.findViewById(button).getBackground();
159 179

  
160
      if( b==button )
180
      if( button==lookingFor )
161 181
        {
162 182
        d.setColorFilter(ContextCompat.getColor(act,R.color.red), PorterDuff.Mode.MULTIPLY);
163 183
        }
src/main/java/org/distorted/uistate/RubikStateSolving.java
28 28

  
29 29
import org.distorted.magic.R;
30 30
import org.distorted.magic.RubikActivity;
31
import org.distorted.object.RubikObjectList;
31 32

  
32 33
import java.util.Timer;
33 34
import java.util.TimerTask;
34 35

  
35 36
import static android.view.View.INVISIBLE;
36
import static org.distorted.object.RubikObjectList.LENGTH;
37
import static org.distorted.object.RubikObjectList.NUM_OBJECTS;
38
import static org.distorted.object.RubikObjectList.MAX_SIZE;
37 39
import static org.distorted.uistate.RubikStatePlay.MAX_SCRAMBLE;
38 40

  
39 41
///////////////////////////////////////////////////////////////////////////////////////////////////
......
47 49
  private long mStartTime;
48 50
  private boolean mRunning;
49 51

  
50
  private long[][] mRecords;
52
  private long[][][] mRecords;
51 53

  
52 54
///////////////////////////////////////////////////////////////////////////////////////////////////
53 55

  
54 56
  RubikStateSolving()
55 57
    {
56
    mRecords = new long[LENGTH][MAX_SCRAMBLE];
58
    mRecords = new long[NUM_OBJECTS][MAX_SIZE][MAX_SCRAMBLE];
57 59

  
58
    for(int i=0; i<LENGTH; i++)
59
      for(int j=0; j<MAX_SCRAMBLE; j++)
60
        {
61
        mRecords[i][j] = NO_RECORD;
62
        }
60
    for(int i=0; i<NUM_OBJECTS; i++)
61
      for(int j=0; j<MAX_SIZE; j++)
62
        for(int k=0; k<MAX_SCRAMBLE; k++)
63
          {
64
          mRecords[i][j][k] = NO_RECORD;
65
          }
63 66
    }
64 67

  
65 68
///////////////////////////////////////////////////////////////////////////////////////////////////
......
115 118

  
116 119
  public void savePreferences(SharedPreferences.Editor editor)
117 120
    {
118
    for(int i=0; i<LENGTH; i++)
119
      for(int j=0; j<MAX_SCRAMBLE; j++)
120
        {
121
        if( mRecords[i][j]!=NO_RECORD)
121
    for(int i=0; i<NUM_OBJECTS; i++)
122
      for(int j=0; j<MAX_SIZE; j++)
123
        for(int k=0; k<MAX_SCRAMBLE; k++)
122 124
          {
123
          editor.putLong("record_"+i+"_"+j, mRecords[i][j]);
125
          if( mRecords[i][j][k]!=NO_RECORD)
126
            {
127
            editor.putLong("record_"+i+"_"+j+"_"+k, mRecords[i][j][k]);
128
            }
124 129
          }
125
        }
126 130
    }
127 131

  
128 132
///////////////////////////////////////////////////////////////////////////////////////////////////
129 133

  
130 134
  public void restorePreferences(SharedPreferences preferences)
131 135
    {
132
    for(int i=0; i<LENGTH; i++)
133
      for(int j=0; j<MAX_SCRAMBLE; j++)
134
        {
135
        mRecords[i][j] = preferences.getLong("record_"+i+"_"+j, NO_RECORD );
136
        }
136
    for(int i=0; i<NUM_OBJECTS; i++)
137
      for(int j=0; j<MAX_SIZE; j++)
138
        for(int k=0; k<MAX_SCRAMBLE; k++)
139
          {
140
          mRecords[i][j][k] = preferences.getLong("record_"+i+"_"+j+"_"+k, NO_RECORD );
141
          }
137 142
    }
138 143

  
139 144
///////////////////////////////////////////////////////////////////////////////////////////////////
......
181 186
      long timeTaken = System.currentTimeMillis()-mStartTime;
182 187

  
183 188
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
184
      int object  = play.getButton();
189
      int object  = play.getObject();
190
      int size    = play.getSize();
185 191
      int scramble= play.getPicker();
192
      int maxsize = RubikObjectList.getObject(object).getSizes().length;
186 193

  
187
      if( object>=0 && object<LENGTH && scramble>=0 && scramble<MAX_SCRAMBLE )
194
      if( object>=0 && object< NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_SCRAMBLE )
188 195
        {
189
        if( mRecords[object][scramble]> timeTaken )
196
        if( mRecords[object][size][scramble]> timeTaken )
190 197
          {
191
          mRecords[object][scramble] = timeTaken;
198
          mRecords[object][size][scramble] = timeTaken;
192 199
          android.util.Log.e("solv","new record!");
193 200
          }
194 201
        }

Also available in: Unified diff