Revision 8e3898c8
Added by Leszek Koltunski over 4 years ago
src/main/java/org/distorted/dialogs/RubikDialogScoresPagerAdapter.java | ||
---|---|---|
32 | 32 |
import org.distorted.scores.RubikScoresDownloader; |
33 | 33 |
import org.distorted.objects.RubikObjectList; |
34 | 34 |
|
35 |
import static org.distorted.states.RubikStatePlay.MAX_LEVEL; |
|
36 |
|
|
37 | 35 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
38 | 36 |
|
39 | 37 |
class RubikDialogScoresPagerAdapter extends PagerAdapter implements RubikScoresDownloader.Receiver |
... | ... | |
136 | 134 |
|
137 | 135 |
private void addPage(int tab, final RubikDialogScoresView view, final String[][] country, final String[][] name, final float[][] time) |
138 | 136 |
{ |
139 |
for(int i=0; i<MAX_LEVEL; i++) |
|
137 |
int object = RubikObjectList.unpackObject(tab); |
|
138 |
int sizeIndex= RubikObjectList.unpackSizeIndex(tab); |
|
139 |
int maxLevel = RubikObjectList.getMaxLevel(object, sizeIndex); |
|
140 |
|
|
141 |
for(int i=0; i<maxLevel; i++) |
|
140 | 142 |
{ |
141 | 143 |
final LinearLayout section = view.createSection(mAct, tab, i, country[i], name[i], time[i]); |
142 | 144 |
|
src/main/java/org/distorted/dialogs/RubikDialogScoresView.java | ||
---|---|---|
78 | 78 |
Resources res = act.getResources(); |
79 | 79 |
String packageName = act.getPackageName(); |
80 | 80 |
|
81 |
int object = RubikObjectList.unpackObject(tab); |
|
82 |
int size = RubikObjectList.unpackSize(tab);
|
|
81 |
int object = RubikObjectList.unpackObject(tab);
|
|
82 |
int sizeIndex= RubikObjectList.unpackSizeIndex(tab);
|
|
83 | 83 |
RubikScores scores = RubikScores.getInstance(); |
84 | 84 |
|
85 | 85 |
boolean inserted = false; |
86 |
long myRecordInMillis = scores.getRecord(object, size, level); |
|
86 |
long myRecordInMillis = scores.getRecord(object, sizeIndex, level);
|
|
87 | 87 |
float myRecordInSeconds = (myRecordInMillis/100)/10.0f; |
88 |
boolean mySubmitted = scores.isSubmitted(object, size, level); |
|
88 |
boolean mySubmitted = scores.isSubmitted(object, sizeIndex, level);
|
|
89 | 89 |
String myName = scores.getName(); |
90 | 90 |
if( myName.length()==0 ) myName = act.getString(R.string.you); |
91 | 91 |
int myCountryID = res.getIdentifier( scores.getCountry(), "drawable", packageName); |
src/main/java/org/distorted/objects/RubikObjectList.java | ||
---|---|---|
33 | 33 |
{ |
34 | 34 |
CUBE ( |
35 | 35 |
new int[][] { |
36 |
{2 , R.drawable.cube2} , |
|
37 |
{3 , R.drawable.cube3} , |
|
38 |
{4 , R.drawable.cube4} , |
|
39 |
{5 , R.drawable.cube5} |
|
36 |
{2 , 12, R.drawable.cube2} ,
|
|
37 |
{3 , 16, R.drawable.cube3} ,
|
|
38 |
{4 , 20, R.drawable.cube4} ,
|
|
39 |
{5 , 24, R.drawable.cube5}
|
|
40 | 40 |
}, |
41 | 41 |
RubikCube.class, |
42 | 42 |
new RubikCubeMovement() |
... | ... | |
44 | 44 |
|
45 | 45 |
PYRA ( |
46 | 46 |
new int[][] { |
47 |
{3 , R.drawable.pyra3} , |
|
48 |
{4 , R.drawable.pyra4} , |
|
49 |
{5 , R.drawable.pyra5} |
|
47 |
{3 , 10, R.drawable.pyra3} ,
|
|
48 |
{4 , 15, R.drawable.pyra4} ,
|
|
49 |
{5 , 20, R.drawable.pyra5}
|
|
50 | 50 |
}, |
51 | 51 |
RubikPyraminx.class, |
52 | 52 |
new RubikPyraminxMovement() |
... | ... | |
55 | 55 |
|
56 | 56 |
public static final int NUM_OBJECTS = values().length; |
57 | 57 |
public static final int MAX_SIZE; |
58 |
public static final int MAX_LEVEL; |
|
58 | 59 |
|
59 |
private final int[] mObjectSizes, mIconIDs; |
|
60 |
private final int[] mObjectSizes, mMaxLevels, mIconIDs;
|
|
60 | 61 |
private final Class<? extends RubikObject> mObjectClass; |
61 | 62 |
private final RubikObjectMovement mObjectMovementClass; |
62 | 63 |
private static final RubikObjectList[] objects; |
... | ... | |
67 | 68 |
mNumAll = 0; |
68 | 69 |
int size, i = 0; |
69 | 70 |
objects = new RubikObjectList[NUM_OBJECTS]; |
70 |
int maxsize = Integer.MIN_VALUE; |
|
71 |
int maxSize = Integer.MIN_VALUE; |
|
72 |
int maxLevel = Integer.MIN_VALUE; |
|
71 | 73 |
|
72 | 74 |
for(RubikObjectList object: RubikObjectList.values()) |
73 | 75 |
{ |
... | ... | |
75 | 77 |
i++; |
76 | 78 |
size = object.mObjectSizes.length; |
77 | 79 |
mNumAll += size; |
78 |
if( size> maxsize ) maxsize = size; |
|
80 |
if( size> maxSize ) maxSize = size; |
|
81 |
|
|
82 |
for(int j=0; j<size; j++) |
|
83 |
{ |
|
84 |
if( object.mMaxLevels[j] > maxLevel ) maxLevel = object.mMaxLevels[j]; |
|
85 |
} |
|
79 | 86 |
} |
80 | 87 |
|
81 |
MAX_SIZE = maxsize; |
|
88 |
MAX_SIZE = maxSize; |
|
89 |
MAX_LEVEL= maxLevel; |
|
82 | 90 |
} |
83 | 91 |
|
84 | 92 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
100 | 108 |
|
101 | 109 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
102 | 110 |
|
103 |
public static int unpackSize(int number) |
|
111 |
public static int unpackSizeIndex(int number)
|
|
104 | 112 |
{ |
105 | 113 |
int num; |
106 | 114 |
|
... | ... | |
189 | 197 |
return mNumAll; |
190 | 198 |
} |
191 | 199 |
|
200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
201 |
|
|
202 |
public static int getMaxLevel(int ordinal, int sizeIndex) |
|
203 |
{ |
|
204 |
if( ordinal>=0 && ordinal<NUM_OBJECTS ) |
|
205 |
{ |
|
206 |
int num = objects[ordinal].mObjectSizes.length; |
|
207 |
return sizeIndex>=0 && sizeIndex<num ? objects[ordinal].mMaxLevels[sizeIndex] : 0; |
|
208 |
} |
|
209 |
|
|
210 |
return 0; |
|
211 |
} |
|
212 |
|
|
192 | 213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
193 | 214 |
|
194 | 215 |
public static int getOrdinal(String name) |
... | ... | |
249 | 270 |
int length = info.length; |
250 | 271 |
|
251 | 272 |
mObjectSizes= new int[length]; |
273 |
mMaxLevels = new int[length]; |
|
252 | 274 |
mIconIDs = new int[length]; |
253 | 275 |
|
254 | 276 |
for(int i=0; i<length; i++) |
255 | 277 |
{ |
256 | 278 |
mObjectSizes[i] = info[i][0]; |
257 |
mIconIDs[i] = info[i][1]; |
|
279 |
mMaxLevels[i] = info[i][1]; |
|
280 |
mIconIDs[i] = info[i][2]; |
|
258 | 281 |
} |
259 | 282 |
|
260 | 283 |
mObjectClass = object; |
... | ... | |
263 | 286 |
|
264 | 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
265 | 288 |
|
266 |
public int[] getIconIDs()
|
|
289 |
public int[] getSizes()
|
|
267 | 290 |
{ |
268 |
return mIconIDs;
|
|
291 |
return mObjectSizes;
|
|
269 | 292 |
} |
270 | 293 |
|
271 | 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
272 | 295 |
|
273 |
public int[] getSizes()
|
|
296 |
public int[] getMaxLevels()
|
|
274 | 297 |
{ |
275 |
return mObjectSizes; |
|
298 |
return mMaxLevels; |
|
299 |
} |
|
300 |
|
|
301 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
302 |
|
|
303 |
public int[] getIconIDs() |
|
304 |
{ |
|
305 |
return mIconIDs; |
|
276 | 306 |
} |
277 | 307 |
|
278 | 308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/scores/RubikScores.java | ||
---|---|---|
29 | 29 |
|
30 | 30 |
import static org.distorted.objects.RubikObjectList.MAX_SIZE; |
31 | 31 |
import static org.distorted.objects.RubikObjectList.NUM_OBJECTS; |
32 |
import static org.distorted.states.RubikStatePlay.MAX_LEVEL;
|
|
32 |
import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
|
|
33 | 33 |
|
34 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 35 |
// hold my own scores, and some other statistics. |
... | ... | |
111 | 111 |
|
112 | 112 |
for(int size=0; size<length; size++) |
113 | 113 |
{ |
114 |
for(int scramble=0; scramble<MAX_LEVEL; scramble++)
|
|
114 |
for(int level=0; level<MAX_LEVEL; level++)
|
|
115 | 115 |
{ |
116 |
if( mSubmitted[object][size][scramble]==0 && mRecords[object][size][scramble]<NO_RECORD )
|
|
116 |
if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
|
|
117 | 117 |
{ |
118 | 118 |
if( !first ) builder.append(','); |
119 | 119 |
else first=false; |
... | ... | |
124 | 124 |
builder.append("_"); |
125 | 125 |
builder.append(sizes[size]); |
126 | 126 |
break; |
127 |
case 1: builder.append(scramble);
|
|
127 |
case 1: builder.append(level);
|
|
128 | 128 |
break; |
129 |
case 2: builder.append(mRecords[object][size][scramble]);
|
|
129 |
case 2: builder.append(mRecords[object][size][level]);
|
|
130 | 130 |
break; |
131 | 131 |
} |
132 | 132 |
} |
... | ... | |
160 | 160 |
int[] sizes; |
161 | 161 |
int length; |
162 | 162 |
|
163 |
for(int scramble=0; scramble<MAX_LEVEL; scramble++)
|
|
163 |
for(int level=0; level<MAX_LEVEL; level++)
|
|
164 | 164 |
{ |
165 | 165 |
builder.setLength(0); |
166 | 166 |
|
... | ... | |
176 | 176 |
builder.append("_"); |
177 | 177 |
builder.append(sizes[size]); |
178 | 178 |
builder.append("="); |
179 |
builder.append(mRecords[object][size][scramble]);
|
|
179 |
builder.append(mRecords[object][size][level]);
|
|
180 | 180 |
builder.append(","); |
181 |
builder.append(mSubmitted[object][size][scramble]);
|
|
181 |
builder.append(mSubmitted[object][size][level]);
|
|
182 | 182 |
builder.append(" "); |
183 | 183 |
} |
184 | 184 |
} |
185 | 185 |
|
186 |
editor.putString("scores_record"+scramble, builder.toString());
|
|
186 |
editor.putString("scores_record"+level, builder.toString());
|
|
187 | 187 |
} |
188 | 188 |
|
189 | 189 |
editor.putString("scores_name" , mName ); |
... | ... | |
202 | 202 |
int object, sizeIndex, subm; |
203 | 203 |
long time; |
204 | 204 |
|
205 |
for(int scramble=0; scramble<MAX_LEVEL; scramble++)
|
|
205 |
for(int level=0; level<MAX_LEVEL; level++)
|
|
206 | 206 |
{ |
207 | 207 |
start = end = 0; |
208 |
recordStr = preferences.getString("scores_record"+scramble, "");
|
|
208 |
recordStr = preferences.getString("scores_record"+level, "");
|
|
209 | 209 |
|
210 | 210 |
while( end!=-1 ) |
211 | 211 |
{ |
... | ... | |
237 | 237 |
|
238 | 238 |
if( sizeIndex>=0 && sizeIndex<MAX_SIZE && subm>=0 && subm<=1 ) |
239 | 239 |
{ |
240 |
mRecords [object][sizeIndex][scramble] = time;
|
|
241 |
mSubmitted[object][sizeIndex][scramble] = subm;
|
|
240 |
mRecords [object][sizeIndex][level] = time;
|
|
241 |
mSubmitted[object][sizeIndex][level] = subm;
|
|
242 | 242 |
} |
243 | 243 |
else |
244 | 244 |
{ |
... | ... | |
264 | 264 |
|
265 | 265 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
266 | 266 |
|
267 |
public boolean setRecord(int object, int size, int scramble, long timeTaken)
|
|
267 |
public boolean setRecord(int object, int size, int level, long timeTaken)
|
|
268 | 268 |
{ |
269 | 269 |
int maxsize = RubikObjectList.getObject(object).getSizes().length; |
270 | 270 |
|
271 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=1 && scramble<=MAX_LEVEL )
|
|
271 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=1 && level<=MAX_LEVEL )
|
|
272 | 272 |
{ |
273 |
if( mRecords[object][size][scramble-1]> timeTaken )
|
|
273 |
if( mRecords[object][size][level-1]> timeTaken )
|
|
274 | 274 |
{ |
275 |
mRecords [object][size][scramble-1] = timeTaken;
|
|
276 |
mSubmitted[object][size][scramble-1] = 0;
|
|
275 |
mRecords [object][size][level-1] = timeTaken;
|
|
276 |
mSubmitted[object][size][level-1] = 0;
|
|
277 | 277 |
return true; |
278 | 278 |
} |
279 | 279 |
} |
... | ... | |
341 | 341 |
|
342 | 342 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
343 | 343 |
|
344 |
public long getRecord(int object, int size, int scramble)
|
|
344 |
public long getRecord(int object, int size, int level)
|
|
345 | 345 |
{ |
346 | 346 |
int maxsize = RubikObjectList.getObject(object).getSizes().length; |
347 | 347 |
|
348 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_LEVEL )
|
|
348 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=0 && level<MAX_LEVEL )
|
|
349 | 349 |
{ |
350 |
return mRecords[object][size][scramble];
|
|
350 |
return mRecords[object][size][level];
|
|
351 | 351 |
} |
352 | 352 |
|
353 | 353 |
return -1; |
... | ... | |
355 | 355 |
|
356 | 356 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
357 | 357 |
|
358 |
public boolean isSubmitted(int object, int size, int scramble)
|
|
358 |
public boolean isSubmitted(int object, int size, int level)
|
|
359 | 359 |
{ |
360 | 360 |
int maxsize = RubikObjectList.getObject(object).getSizes().length; |
361 | 361 |
|
362 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && scramble>=0 && scramble<MAX_LEVEL )
|
|
362 |
if( object>=0 && object<NUM_OBJECTS && size>=0 && size<maxsize && level>=0 && level<MAX_LEVEL )
|
|
363 | 363 |
{ |
364 |
return mSubmitted[object][size][scramble]==1;
|
|
364 |
return mSubmitted[object][size][level]==1;
|
|
365 | 365 |
} |
366 | 366 |
|
367 | 367 |
return false; |
... | ... | |
422 | 422 |
length = list.getSizes().length; |
423 | 423 |
|
424 | 424 |
for(int size=0; size<length; size++) |
425 |
for(int scramble=0; scramble<MAX_LEVEL; scramble++)
|
|
425 |
for(int level=0; level<MAX_LEVEL; level++)
|
|
426 | 426 |
{ |
427 |
if( mSubmitted[object][size][scramble]==0 && mRecords[object][size][scramble]<NO_RECORD )
|
|
427 |
if( mSubmitted[object][size][level]==0 && mRecords[object][size][level]<NO_RECORD )
|
|
428 | 428 |
{ |
429 | 429 |
return true; |
430 | 430 |
} |
src/main/java/org/distorted/scores/RubikScoresDownloader.java | ||
---|---|---|
29 | 29 |
import java.net.URL; |
30 | 30 |
import java.net.UnknownHostException; |
31 | 31 |
|
32 |
import static org.distorted.states.RubikStatePlay.MAX_LEVEL;
|
|
32 |
import static org.distorted.objects.RubikObjectList.MAX_LEVEL;
|
|
33 | 33 |
|
34 | 34 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
35 | 35 |
|
... | ... | |
185 | 185 |
|
186 | 186 |
if( object>=0 && object<mTotal ) |
187 | 187 |
{ |
188 |
int scramble = Integer.parseInt( row.substring(s1+1,s2) );
|
|
188 |
int level = Integer.parseInt( row.substring(s1+1,s2) );
|
|
189 | 189 |
String name = row.substring(s2+1, s3); |
190 | 190 |
int time = Integer.parseInt( row.substring(s3+1,s4) ); |
191 | 191 |
String country = row.substring(s4+1, s5); |
192 | 192 |
|
193 |
if(scramble>=0 && scramble<MAX_LEVEL)
|
|
193 |
if(level>=0 && level<MAX_LEVEL)
|
|
194 | 194 |
{ |
195 |
int p = mPlaces[object][scramble];
|
|
196 |
mPlaces[object][scramble]++;
|
|
195 |
int p = mPlaces[object][level];
|
|
196 |
mPlaces[object][level]++;
|
|
197 | 197 |
|
198 |
mCountry[object][scramble][p] = country;
|
|
199 |
mName [object][scramble][p] = name;
|
|
200 |
mTime [object][scramble][p] = ((float)(time/100))/10.0f;
|
|
198 |
mCountry[object][level][p] = country;
|
|
199 |
mName [object][level][p] = name;
|
|
200 |
mTime [object][level][p] = ((float)(time/100))/10.0f;
|
|
201 | 201 |
} |
202 | 202 |
} |
203 | 203 |
} |
src/main/java/org/distorted/states/RubikStatePlay.java | ||
---|---|---|
32 | 32 |
import android.widget.ImageButton; |
33 | 33 |
import android.widget.LinearLayout; |
34 | 34 |
import android.widget.PopupWindow; |
35 |
import android.widget.Spinner;
|
|
35 |
import android.support.v7.widget.AppCompatSpinner;
|
|
36 | 36 |
|
37 | 37 |
import org.distorted.main.R; |
38 | 38 |
import org.distorted.main.RubikActivity; |
... | ... | |
43 | 43 |
public class RubikStatePlay extends RubikStateAbstract implements AdapterView.OnItemSelectedListener |
44 | 44 |
{ |
45 | 45 |
private static final int DEF_LEVEL = 1; |
46 |
public static final int MAX_LEVEL = 18; |
|
47 | 46 |
public static final int DEF_OBJECT= RubikObjectList.CUBE.ordinal(); |
48 | 47 |
public static final int DEF_SIZE = 3; |
49 | 48 |
|
... | ... | |
54 | 53 |
private int mSize = DEF_SIZE; |
55 | 54 |
private int mLayoutWidth; |
56 | 55 |
private LinearLayout mLayout; |
57 |
private Spinner mLevelSpinner; |
|
56 |
private AppCompatSpinner mLevelSpinner; |
|
57 |
private ArrayAdapter<String> mSpinnerAdapter; |
|
58 | 58 |
private int mLevelValue; |
59 | 59 |
|
60 | 60 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
143 | 143 |
spinnerLayoutParams.leftMargin = spinnerMargin; |
144 | 144 |
spinnerLayoutParams.rightMargin = 2*spinnerMargin; |
145 | 145 |
|
146 |
mLevelSpinner = new Spinner(act); |
|
146 |
mLevelSpinner = new AppCompatSpinner(act);
|
|
147 | 147 |
mLevelSpinner.setLayoutParams(spinnerLayoutParams); |
148 | 148 |
mLevelSpinner.setPadding(spinnerPadding,0,spinnerPadding,0); |
149 | 149 |
mLevelSpinner.setBackgroundResource(R.drawable.spinner); |
150 | 150 |
mLevelSpinner.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); |
151 | 151 |
|
152 | 152 |
mLevelSpinner.setOnItemSelectedListener(this); |
153 |
String[] levels = new String[MAX_LEVEL]; |
|
153 |
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize); |
|
154 |
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex); |
|
155 |
String[] levels = new String[maxLevel]; |
|
154 | 156 |
|
155 |
for(int i=0; i<MAX_LEVEL; i++)
|
|
157 |
for(int i=0; i<maxLevel; i++)
|
|
156 | 158 |
{ |
157 | 159 |
levels[i] = act.getString(R.string.lv_placeholder,i+1); |
158 | 160 |
} |
159 | 161 |
|
160 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
|
|
161 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
162 |
mLevelSpinner.setAdapter(adapterType);
|
|
162 |
mSpinnerAdapter = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels);
|
|
163 |
mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
|
164 |
mLevelSpinner.setAdapter(mSpinnerAdapter);
|
|
163 | 165 |
mLevelSpinner.setSelection(mLevelValue-1); |
164 | 166 |
} |
165 | 167 |
|
... | ... | |
272 | 274 |
mObject = obj; |
273 | 275 |
mSize = sizes[size]; |
274 | 276 |
act.changeObject(list,sizes[size],null); |
277 |
|
|
278 |
int sizeIndex = RubikObjectList.getSizeIndex(mObject,mSize); |
|
279 |
int maxLevel = RubikObjectList.getMaxLevel(mObject, sizeIndex); |
|
280 |
String[] levels = new String[maxLevel]; |
|
281 |
|
|
282 |
for(int i=0; i<maxLevel; i++) |
|
283 |
{ |
|
284 |
levels[i] = act.getString(R.string.lv_placeholder,i+1); |
|
285 |
} |
|
286 |
|
|
287 |
mSpinnerAdapter = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, levels); |
|
288 |
mSpinnerAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
289 |
mLevelSpinner.setAdapter(mSpinnerAdapter); |
|
275 | 290 |
} |
291 |
|
|
276 | 292 |
mPopup.dismiss(); |
277 | 293 |
} |
278 | 294 |
}); |
Also available in: Unified diff
Each object size now has its own number of levels (not always 18!)