1
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
2
|
// Copyright 2020 Leszek Koltunski //
|
3
|
// //
|
4
|
// This file is part of Magic Cube. //
|
5
|
// //
|
6
|
// Magic Cube is free software: you can redistribute it and/or modify //
|
7
|
// it under the terms of the GNU General Public License as published by //
|
8
|
// the Free Software Foundation, either version 2 of the License, or //
|
9
|
// (at your option) any later version. //
|
10
|
// //
|
11
|
// Magic Cube is distributed in the hope that it will be useful, //
|
12
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of //
|
13
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the //
|
14
|
// GNU General Public License for more details. //
|
15
|
// //
|
16
|
// You should have received a copy of the GNU General Public License //
|
17
|
// along with Magic Cube. If not, see <http://www.gnu.org/licenses/>. //
|
18
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
19
|
|
20
|
package org.distorted.screens;
|
21
|
|
22
|
import android.content.Context;
|
23
|
import android.content.SharedPreferences;
|
24
|
import android.graphics.drawable.BitmapDrawable;
|
25
|
import android.os.Bundle;
|
26
|
import android.util.TypedValue;
|
27
|
import android.view.LayoutInflater;
|
28
|
import android.view.View;
|
29
|
import android.widget.Button;
|
30
|
import android.widget.GridLayout;
|
31
|
import android.widget.ImageButton;
|
32
|
import android.widget.LinearLayout;
|
33
|
import android.widget.PopupWindow;
|
34
|
import android.widget.ScrollView;
|
35
|
|
36
|
import org.distorted.dialogs.RubikDialogAbout;
|
37
|
import org.distorted.dialogs.RubikDialogPattern;
|
38
|
import org.distorted.dialogs.RubikDialogScores;
|
39
|
import org.distorted.dialogs.RubikDialogTutorial;
|
40
|
import org.distorted.helpers.TransparentButton;
|
41
|
import org.distorted.helpers.TransparentImageButton;
|
42
|
import org.distorted.main.R;
|
43
|
import org.distorted.main.RubikActivity;
|
44
|
import org.distorted.main.RubikPreRender;
|
45
|
import org.distorted.objects.ObjectList;
|
46
|
import org.distorted.network.RubikScores;
|
47
|
|
48
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
49
|
|
50
|
public class RubikScreenPlay extends RubikScreenBase
|
51
|
{
|
52
|
public static final int LEVELS_SHOWN = 10;
|
53
|
public static final int DEF_OBJECT= ObjectList.CUBE.ordinal();
|
54
|
public static final int DEF_SIZE = 3;
|
55
|
|
56
|
private static final int[] BUTTON_LABELS = { R.string.scores,
|
57
|
R.string.patterns,
|
58
|
// R.string.control,
|
59
|
R.string.solver,
|
60
|
R.string.tutorials,
|
61
|
R.string.about };
|
62
|
|
63
|
private static final int NUM_BUTTONS = BUTTON_LABELS.length;
|
64
|
private static final float LAST_BUTTON = 1.5f;
|
65
|
private static final int[] mLocation = new int[2];
|
66
|
|
67
|
private ImageButton mObjButton, mMenuButton, mSolveButton;
|
68
|
private Button mPlayButton;
|
69
|
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
|
70
|
private int mObject = DEF_OBJECT;
|
71
|
private int mSize = DEF_SIZE;
|
72
|
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth;
|
73
|
private int mLevelValue;
|
74
|
private float mButtonSize, mMenuItemSize, mMenuTextSize;
|
75
|
private int mColCount, mRowCount, mMaxRowCount;
|
76
|
private LinearLayout mPlayLayout;
|
77
|
|
78
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
79
|
|
80
|
void leaveScreen(RubikActivity act)
|
81
|
{
|
82
|
|
83
|
}
|
84
|
|
85
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
86
|
|
87
|
void enterScreen(final RubikActivity act)
|
88
|
{
|
89
|
float width = act.getScreenWidthInPixels();
|
90
|
float height= act.getScreenHeightInPixels();
|
91
|
|
92
|
mMenuTextSize = width*RubikActivity.MENU_MED_TEXT_SIZE;
|
93
|
mButtonSize = width*RubikActivity.BUTTON_TEXT_SIZE;
|
94
|
mMenuItemSize = width*RubikActivity.MENU_ITEM_SIZE;
|
95
|
|
96
|
mRowCount = ObjectList.getRowCount();
|
97
|
mColCount = ObjectList.getColumnCount();
|
98
|
|
99
|
// TOP ////////////////////////////
|
100
|
LinearLayout layoutTop = act.findViewById(R.id.upperBar);
|
101
|
layoutTop.removeAllViews();
|
102
|
|
103
|
setupObjectWindow(act,width,height);
|
104
|
setupObjectButton(act,width);
|
105
|
layoutTop.addView(mObjButton);
|
106
|
|
107
|
setupMenuWindow(act,width);
|
108
|
setupMenuButton(act,width);
|
109
|
layoutTop.addView(mMenuButton);
|
110
|
|
111
|
setupPlayWindow(act,width);
|
112
|
setupPlayButton(act,width,height);
|
113
|
layoutTop.addView(mPlayButton);
|
114
|
|
115
|
setupSolveButton(act,width);
|
116
|
createBottomPane(act,width,mSolveButton);
|
117
|
}
|
118
|
|
119
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
120
|
|
121
|
private void setupObjectButton(final RubikActivity act, final float width)
|
122
|
{
|
123
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
124
|
final int upperBarHeight = act.getHeightUpperBar();
|
125
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_menu,R.drawable.ui_medium_cube_menu, R.drawable.ui_big_cube_menu, R.drawable.ui_huge_cube_menu);
|
126
|
|
127
|
mObjButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
|
128
|
|
129
|
mObjButton.setOnClickListener( new View.OnClickListener()
|
130
|
{
|
131
|
@Override
|
132
|
public void onClick(View view)
|
133
|
{
|
134
|
if( mObjectPopup!=null && act.getPreRender().isUINotBlocked())
|
135
|
{
|
136
|
int rowCount = Math.min(mMaxRowCount,mRowCount);
|
137
|
View popupView = mObjectPopup.getContentView();
|
138
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
139
|
|
140
|
view.getLocationOnScreen(mLocation);
|
141
|
final int x = mLocation[0];
|
142
|
final int y = mLocation[1]+upperBarHeight+margin;
|
143
|
|
144
|
mObjectPopup.showAsDropDown(view);
|
145
|
mObjectPopup.update(x,y,mObjectSize*mColCount,mObjectSize*rowCount);
|
146
|
}
|
147
|
}
|
148
|
});
|
149
|
}
|
150
|
|
151
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
152
|
|
153
|
private void setupPlayButton(final RubikActivity act, final float width, final float height)
|
154
|
{
|
155
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
156
|
final int upperBarHeight = act.getHeightUpperBar();
|
157
|
final int maxHeight= (int)(0.9f*(height-upperBarHeight) );
|
158
|
|
159
|
mPlayButton = new TransparentButton(act, R.string.play, mButtonSize, width);
|
160
|
|
161
|
mPlayButton.setOnClickListener( new View.OnClickListener()
|
162
|
{
|
163
|
@Override
|
164
|
public void onClick(View view)
|
165
|
{
|
166
|
if( mPlayPopup!=null && act.getPreRender().isUINotBlocked())
|
167
|
{
|
168
|
View popupView = mPlayPopup.getContentView();
|
169
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
170
|
|
171
|
view.getLocationOnScreen(mLocation);
|
172
|
int width = view.getWidth();
|
173
|
|
174
|
final int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
|
175
|
final int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
|
176
|
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN);
|
177
|
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f));
|
178
|
final int realHeight = Math.min(popupHeight,maxHeight);
|
179
|
final int x = mLocation[0]+width-mPlayLayoutWidth;
|
180
|
final int y = mLocation[1]+upperBarHeight+margin;
|
181
|
|
182
|
mPlayPopup.showAsDropDown(view);
|
183
|
mPlayPopup.update(x,y,mPlayLayoutWidth,realHeight);
|
184
|
}
|
185
|
}
|
186
|
});
|
187
|
}
|
188
|
|
189
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
190
|
|
191
|
private void setupMenuButton(final RubikActivity act, final float width)
|
192
|
{
|
193
|
final int margin = (int)(width*RubikActivity.MARGIN);
|
194
|
final int icon = RubikActivity.getDrawable(R.drawable.ui_small_menu,R.drawable.ui_medium_menu, R.drawable.ui_big_menu, R.drawable.ui_huge_menu);
|
195
|
final int upperBarHeight = act.getHeightUpperBar();
|
196
|
|
197
|
mMenuButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
|
198
|
|
199
|
mMenuButton.setOnClickListener( new View.OnClickListener()
|
200
|
{
|
201
|
@Override
|
202
|
public void onClick(View view)
|
203
|
{
|
204
|
if( mMenuPopup!=null && act.getPreRender().isUINotBlocked())
|
205
|
{
|
206
|
View popupView = mMenuPopup.getContentView();
|
207
|
popupView.setSystemUiVisibility(RubikActivity.FLAGS);
|
208
|
|
209
|
view.getLocationOnScreen(mLocation);
|
210
|
int width = view.getWidth();
|
211
|
final int x = mLocation[0]+(width-mMenuLayoutWidth)/2;
|
212
|
final int y = mLocation[1]+upperBarHeight+margin;
|
213
|
|
214
|
mMenuPopup.showAsDropDown(view);
|
215
|
mMenuPopup.update(x,y,mMenuLayoutWidth,mMenuLayoutHeight);
|
216
|
}
|
217
|
}
|
218
|
});
|
219
|
}
|
220
|
|
221
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
222
|
|
223
|
private void setupObjectWindow(final RubikActivity act, final float width, final float height)
|
224
|
{
|
225
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube2,R.drawable.ui_medium_cube2, R.drawable.ui_big_cube2, R.drawable.ui_huge_cube2);
|
226
|
|
227
|
BitmapDrawable bd = (BitmapDrawable) act.getResources().getDrawable(icon);
|
228
|
int cubeWidth = bd.getIntrinsicWidth();
|
229
|
int margin = (int)(width*RubikActivity.LARGE_MARGIN);
|
230
|
mObjectSize = (int)(cubeWidth + 2*margin + 0.5f);
|
231
|
int upperBarHeight = act.getHeightUpperBar();
|
232
|
mMaxRowCount = (int)(0.9f*(height-upperBarHeight)/mObjectSize);
|
233
|
GridLayout objectGrid = new GridLayout(act);
|
234
|
mObjectPopup = new PopupWindow(act);
|
235
|
mObjectPopup.setFocusable(true);
|
236
|
|
237
|
if( mMaxRowCount<mRowCount )
|
238
|
{
|
239
|
ScrollView scrollView = new ScrollView(act);
|
240
|
scrollView.addView(objectGrid);
|
241
|
mObjectPopup.setContentView(scrollView);
|
242
|
}
|
243
|
else
|
244
|
{
|
245
|
mObjectPopup.setContentView(objectGrid);
|
246
|
}
|
247
|
|
248
|
int[] indices = ObjectList.getIndices();
|
249
|
|
250
|
GridLayout.Spec[] rowSpecs = new GridLayout.Spec[mRowCount];
|
251
|
GridLayout.Spec[] colSpecs = new GridLayout.Spec[mColCount];
|
252
|
|
253
|
objectGrid.setColumnCount(mColCount);
|
254
|
objectGrid.setRowCount(mRowCount);
|
255
|
|
256
|
int[] nextInRow = new int[mRowCount];
|
257
|
|
258
|
for(int row=0; row<mRowCount; row++)
|
259
|
{
|
260
|
rowSpecs[row] = GridLayout.spec(row);
|
261
|
nextInRow[row]= 0;
|
262
|
}
|
263
|
for(int col=0; col<mColCount; col++)
|
264
|
{
|
265
|
colSpecs[col] = GridLayout.spec(col);
|
266
|
}
|
267
|
|
268
|
for(int object=0; object< ObjectList.NUM_OBJECTS; object++)
|
269
|
{
|
270
|
final ObjectList list = ObjectList.getObject(object);
|
271
|
final int[] sizes = list.getSizes();
|
272
|
int[] icons = list.getIconIDs();
|
273
|
int len = sizes.length;
|
274
|
final int obj = object;
|
275
|
int row = indices[object];
|
276
|
|
277
|
for(int i=0; i<len; i++)
|
278
|
{
|
279
|
final int index = i;
|
280
|
|
281
|
ImageButton button = new ImageButton(act);
|
282
|
button.setBackgroundResource(icons[i]);
|
283
|
button.setOnClickListener( new View.OnClickListener()
|
284
|
{
|
285
|
@Override
|
286
|
public void onClick(View v)
|
287
|
{
|
288
|
if( act.getPreRender().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY )
|
289
|
{
|
290
|
mObject = obj;
|
291
|
mSize = sizes[index];
|
292
|
act.changeObject(list,sizes[index], true);
|
293
|
adjustLevels(act);
|
294
|
mController.clearMoves(act);
|
295
|
}
|
296
|
|
297
|
mObjectPopup.dismiss();
|
298
|
}
|
299
|
});
|
300
|
|
301
|
GridLayout.LayoutParams params = new GridLayout.LayoutParams(rowSpecs[row],colSpecs[nextInRow[row]]);
|
302
|
params.bottomMargin = margin;
|
303
|
params.topMargin = margin;
|
304
|
params.leftMargin = margin;
|
305
|
params.rightMargin = margin;
|
306
|
|
307
|
nextInRow[row]++;
|
308
|
|
309
|
objectGrid.addView(button, params);
|
310
|
}
|
311
|
}
|
312
|
}
|
313
|
|
314
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
315
|
|
316
|
private void setupMenuWindow(final RubikActivity act, final float width)
|
317
|
{
|
318
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
319
|
final View layout = layoutInflater.inflate(R.layout.popup_menu, null);
|
320
|
LinearLayout menuLayout = layout.findViewById(R.id.menuGrid);
|
321
|
|
322
|
mMenuPopup = new PopupWindow(act);
|
323
|
mMenuPopup.setContentView(layout);
|
324
|
mMenuPopup.setFocusable(true);
|
325
|
int margin = (int)(width*RubikActivity.MARGIN);
|
326
|
int padding = (int)(width*RubikActivity.PADDING);
|
327
|
|
328
|
mMenuLayoutWidth = (int)(width/2);
|
329
|
mMenuLayoutHeight= (int)(2*margin + NUM_BUTTONS*(mMenuItemSize+margin));
|
330
|
|
331
|
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams( mMenuLayoutWidth - 2*padding, (int)mMenuItemSize);
|
332
|
|
333
|
for(int i=0; i<NUM_BUTTONS; i++)
|
334
|
{
|
335
|
final int but = i;
|
336
|
Button button = new Button(act);
|
337
|
button.setLayoutParams(p);
|
338
|
button.setText(BUTTON_LABELS[i]);
|
339
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
340
|
|
341
|
button.setOnClickListener( new View.OnClickListener()
|
342
|
{
|
343
|
@Override
|
344
|
public void onClick(View v)
|
345
|
{
|
346
|
mMenuPopup.dismiss();
|
347
|
MenuAction(act,but);
|
348
|
}
|
349
|
});
|
350
|
|
351
|
menuLayout.addView(button);
|
352
|
}
|
353
|
}
|
354
|
|
355
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
356
|
|
357
|
private void setupPlayWindow(final RubikActivity act, final float width)
|
358
|
{
|
359
|
LayoutInflater layoutInflater = (LayoutInflater)act.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
|
360
|
final View layout = layoutInflater.inflate(R.layout.popup_play, null);
|
361
|
mPlayLayout = layout.findViewById(R.id.playGrid);
|
362
|
|
363
|
mPlayLayoutWidth = (int)(width*0.4f);
|
364
|
|
365
|
mPlayPopup = new PopupWindow(act);
|
366
|
mPlayPopup.setContentView(layout);
|
367
|
mPlayPopup.setFocusable(true);
|
368
|
|
369
|
adjustLevels(act);
|
370
|
}
|
371
|
|
372
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
373
|
|
374
|
private void MenuAction(RubikActivity act, int button)
|
375
|
{
|
376
|
switch(button)
|
377
|
{
|
378
|
case 0: RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
|
379
|
int object = play.getObject();
|
380
|
int size = play.getSize();
|
381
|
int sizeIndex = ObjectList.getSizeIndex(object,size);
|
382
|
Bundle sBundle = new Bundle();
|
383
|
sBundle.putInt("tab", ObjectList.pack(object,sizeIndex) );
|
384
|
sBundle.putBoolean("submitting", false);
|
385
|
RubikDialogScores scores = new RubikDialogScores();
|
386
|
scores.setArguments(sBundle);
|
387
|
scores.show(act.getSupportFragmentManager(), null);
|
388
|
break;
|
389
|
case 1: RubikDialogPattern pDiag = new RubikDialogPattern();
|
390
|
Bundle pBundle = new Bundle();
|
391
|
int pOrd = getPatternOrdinal();
|
392
|
pBundle.putInt("tab", pOrd );
|
393
|
pDiag.setArguments(pBundle);
|
394
|
pDiag.show( act.getSupportFragmentManager(), RubikDialogPattern.getDialogTag() );
|
395
|
break;
|
396
|
/*
|
397
|
case 2: RubikControl control = RubikControl.getInstance();
|
398
|
//control.animateAll(act);
|
399
|
control.animateRotate(act);
|
400
|
break;
|
401
|
*/
|
402
|
case 2: ScreenList.switchScreen(act, ScreenList.SVER);
|
403
|
break;
|
404
|
case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial();
|
405
|
Bundle tBundle = new Bundle();
|
406
|
int tOrd = getTutorialOrdinal();
|
407
|
tBundle.putInt("tab", tOrd );
|
408
|
tDiag.setArguments(tBundle);
|
409
|
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() );
|
410
|
break;
|
411
|
case 4: RubikDialogAbout aDiag = new RubikDialogAbout();
|
412
|
aDiag.show(act.getSupportFragmentManager(), null);
|
413
|
break;
|
414
|
}
|
415
|
}
|
416
|
|
417
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
418
|
|
419
|
void setupSolveButton(final RubikActivity act, final float width)
|
420
|
{
|
421
|
int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
|
422
|
mSolveButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
|
423
|
|
424
|
mSolveButton.setOnClickListener( new View.OnClickListener()
|
425
|
{
|
426
|
@Override
|
427
|
public void onClick(View v)
|
428
|
{
|
429
|
act.getPreRender().solveObject();
|
430
|
mController.clearMoves(act);
|
431
|
}
|
432
|
});
|
433
|
}
|
434
|
|
435
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
436
|
|
437
|
public void savePreferences(SharedPreferences.Editor editor)
|
438
|
{
|
439
|
editor.putInt("statePlay_object", mObject);
|
440
|
editor.putInt("statePlay_size" , mSize);
|
441
|
|
442
|
if( mObjectPopup!=null )
|
443
|
{
|
444
|
mObjectPopup.dismiss();
|
445
|
mObjectPopup = null;
|
446
|
}
|
447
|
|
448
|
if( mMenuPopup!=null )
|
449
|
{
|
450
|
mMenuPopup.dismiss();
|
451
|
mMenuPopup = null;
|
452
|
}
|
453
|
|
454
|
if( mPlayPopup!=null )
|
455
|
{
|
456
|
mPlayPopup.dismiss();
|
457
|
mPlayPopup = null;
|
458
|
}
|
459
|
}
|
460
|
|
461
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
462
|
|
463
|
public void restorePreferences(SharedPreferences preferences)
|
464
|
{
|
465
|
mObject= preferences.getInt("statePlay_object", DEF_OBJECT);
|
466
|
mSize = preferences.getInt("statePlay_size" , DEF_SIZE );
|
467
|
|
468
|
int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
|
469
|
int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
|
470
|
|
471
|
// This means the app has been upgraded to a new version which swapped the
|
472
|
// Object for a new one with larger sizeIndex and now getMaxLevel() returns
|
473
|
// 0. Reset the object to default, otherwise we'll get a crash later on.
|
474
|
|
475
|
if( dbLevel==0 )
|
476
|
{
|
477
|
mObject = DEF_OBJECT;
|
478
|
mSize = DEF_SIZE;
|
479
|
}
|
480
|
}
|
481
|
|
482
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
483
|
|
484
|
public boolean setObjectAndSize(RubikActivity act, ObjectList obj, int size)
|
485
|
{
|
486
|
if( mObject!=obj.ordinal() || mSize != size )
|
487
|
{
|
488
|
boolean success = false;
|
489
|
|
490
|
for( int s: obj.getSizes() )
|
491
|
if( s==size )
|
492
|
{
|
493
|
success = true;
|
494
|
break;
|
495
|
}
|
496
|
|
497
|
if( success )
|
498
|
{
|
499
|
mObject = obj.ordinal();
|
500
|
mSize = size;
|
501
|
|
502
|
if( mPlayLayout!=null ) adjustLevels(act);
|
503
|
}
|
504
|
|
505
|
return success;
|
506
|
}
|
507
|
|
508
|
return true;
|
509
|
}
|
510
|
|
511
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
512
|
|
513
|
private void adjustLevels(final RubikActivity act)
|
514
|
{
|
515
|
int sizeIndex = ObjectList.getSizeIndex(mObject,mSize);
|
516
|
int dbLevel = ObjectList.getDBLevel(mObject, sizeIndex);
|
517
|
int numScrambles = ObjectList.getNumScramble(mObject, sizeIndex);
|
518
|
int numLevel = Math.min(dbLevel, LEVELS_SHOWN);
|
519
|
String[] levels = new String[numLevel];
|
520
|
|
521
|
for(int i=0; i<numLevel-1; i++)
|
522
|
{
|
523
|
levels[i] = act.getString(R.string.lv_placeholder,i+1);
|
524
|
}
|
525
|
|
526
|
if( numLevel>0 )
|
527
|
{
|
528
|
levels[numLevel-1] = act.getString(R.string.level_full);
|
529
|
}
|
530
|
|
531
|
if( mLevelValue>dbLevel || mLevelValue<1 ||
|
532
|
(mLevelValue<dbLevel || mLevelValue>LEVELS_SHOWN ) )
|
533
|
{
|
534
|
mLevelValue=1;
|
535
|
}
|
536
|
|
537
|
float width = act.getScreenWidthInPixels();
|
538
|
int margin = (int)(width*RubikActivity.MARGIN);
|
539
|
int padding = (int)(width*RubikActivity.PADDING);
|
540
|
int butWidth = mPlayLayoutWidth - 2*padding;
|
541
|
int butHeight= (int)mMenuItemSize;
|
542
|
int lastButH = (int)(mMenuItemSize*LAST_BUTTON) ;
|
543
|
|
544
|
LinearLayout.LayoutParams pM = new LinearLayout.LayoutParams( butWidth, butHeight );
|
545
|
pM.setMargins(margin, 0, margin, margin);
|
546
|
LinearLayout.LayoutParams pT = new LinearLayout.LayoutParams( butWidth, butHeight );
|
547
|
pT.setMargins(margin, margin, margin, margin);
|
548
|
LinearLayout.LayoutParams pB = new LinearLayout.LayoutParams( butWidth, lastButH );
|
549
|
pB.setMargins(margin, margin, margin, 2*margin);
|
550
|
|
551
|
mPlayLayout.removeAllViews();
|
552
|
|
553
|
RubikScores scores = RubikScores.getInstance();
|
554
|
|
555
|
for(int i=0; i<numLevel; i++)
|
556
|
{
|
557
|
final int level = i<numLevel-1 ? i+1 : dbLevel;
|
558
|
final int scrambles = i<numLevel-1 ? i+1 : numScrambles;
|
559
|
Button button = new Button(act);
|
560
|
button.setLayoutParams(i==0 ? pT : (i==numLevel-1 ? pB : pM));
|
561
|
button.setText(levels[i]);
|
562
|
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize);
|
563
|
|
564
|
int icon = scores.isSolved(mObject, sizeIndex, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
565
|
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0);
|
566
|
|
567
|
button.setOnClickListener( new View.OnClickListener()
|
568
|
{
|
569
|
@Override
|
570
|
public void onClick(View v)
|
571
|
{
|
572
|
RubikPreRender pre = act.getPreRender();
|
573
|
|
574
|
if(pre.isUINotBlocked())
|
575
|
{
|
576
|
if( mPlayPopup!=null ) mPlayPopup.dismiss();
|
577
|
mLevelValue = level;
|
578
|
pre.scrambleObject(scrambles);
|
579
|
}
|
580
|
}
|
581
|
});
|
582
|
|
583
|
mPlayLayout.addView(button);
|
584
|
}
|
585
|
}
|
586
|
|
587
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
588
|
|
589
|
public int getLevel()
|
590
|
{
|
591
|
return mLevelValue;
|
592
|
}
|
593
|
|
594
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
595
|
|
596
|
public int getObject()
|
597
|
{
|
598
|
return mObject;
|
599
|
}
|
600
|
|
601
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
602
|
|
603
|
public int getSize()
|
604
|
{
|
605
|
return mSize;
|
606
|
}
|
607
|
}
|