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