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