Revision 400ff34d
Added by Leszek Koltunski almost 4 years ago
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 35 | 35 |
import android.widget.LinearLayout; |
| 36 | 36 |
import android.widget.PopupWindow; |
| 37 | 37 |
|
| 38 |
import org.distorted.objectlib.main.ObjectConstants; |
|
| 39 | 38 |
import org.distorted.objectlib.main.ObjectControl; |
| 40 | 39 |
|
| 41 | 40 |
import org.distorted.main.R; |
| ... | ... | |
| 58 | 57 |
{
|
| 59 | 58 |
public static final int NUM_COLUMNS = 4; |
| 60 | 59 |
public static final int LEVELS_SHOWN = 10; |
| 61 |
public static final int DEF_OBJECT= ObjectConstants.CUBE_3; |
|
| 62 | 60 |
|
| 63 | 61 |
private static final int[] BUTTON_LABELS = { R.string.scores,
|
| 64 | 62 |
R.string.patterns, |
| ... | ... | |
| 73 | 71 |
private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton; |
| 74 | 72 |
private TransparentButton mPlayButton; |
| 75 | 73 |
private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup; |
| 76 |
private int mObject = DEF_OBJECT;
|
|
| 74 |
private LinearLayout mPlayLayout;
|
|
| 77 | 75 |
private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mPlayLayoutWidth; |
| 78 | 76 |
private int mLevelValue; |
| 79 | 77 |
private float mButtonSize, mMenuItemSize, mMenuTextSize; |
| 80 | 78 |
private int mColCount, mRowCount, mMaxRowCount; |
| 81 |
private LinearLayout mPlayLayout; |
|
| 82 | 79 |
private int mUpperBarHeight; |
| 83 | 80 |
private boolean mShouldReactToEndOfScrambling; |
| 84 | 81 |
|
| ... | ... | |
| 179 | 176 |
final int maxHeight= (int)(0.9f*(height-mUpperBarHeight) ); |
| 180 | 177 |
View popupView = mPlayPopup.getContentView(); |
| 181 | 178 |
popupView.setSystemUiVisibility(RubikActivity.FLAGS); |
| 182 |
final int dbLevel = RubikObjectList.getDBLevel(mObject); |
|
| 179 |
final int object = RubikObjectList.getCurrObject(); |
|
| 180 |
final int dbLevel = RubikObjectList.getDBLevel(object); |
|
| 183 | 181 |
final int levelsShown = Math.min(dbLevel,LEVELS_SHOWN); |
| 184 | 182 |
final int popupHeight = (int)(levelsShown*(mMenuItemSize+margin)+3*margin+mMenuItemSize*(LAST_BUTTON-1.0f)); |
| 185 | 183 |
final int realHeight = Math.min(popupHeight,maxHeight); |
| ... | ... | |
| 268 | 266 |
int iconSize = RubikActivity.getDrawableSize(); |
| 269 | 267 |
int icons = robject==null ? 0 : robject.getIconID(iconSize); |
| 270 | 268 |
int row = object/NUM_COLUMNS; |
| 269 |
final int ordinal = robject==null ? 0 : robject.getOrdinal(); |
|
| 271 | 270 |
|
| 272 | 271 |
ImageButton button = new ImageButton(act); |
| 273 | 272 |
button.setBackgroundResource(icons); |
| ... | ... | |
| 278 | 277 |
{
|
| 279 | 278 |
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
| 280 | 279 |
{
|
| 281 |
mObject = robject==null ? 0 : robject.getOrdinal();
|
|
| 282 |
act.changeObject(mObject, true);
|
|
| 280 |
RubikObjectList.setCurrObject(act,ordinal);
|
|
| 281 |
act.changeObject(ordinal,true);
|
|
| 283 | 282 |
if( mPlayLayout!=null ) adjustLevels(act); |
| 284 | 283 |
mMovesController.clearMoves(act); |
| 285 | 284 |
} |
| ... | ... | |
| 338 | 337 |
@Override |
| 339 | 338 |
public void onClick(View v) |
| 340 | 339 |
{
|
| 341 |
act.switchConfig(mObject); |
|
| 340 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 341 |
act.switchConfig(currObject); |
|
| 342 | 342 |
} |
| 343 | 343 |
}); |
| 344 | 344 |
} |
| ... | ... | |
| 408 | 408 |
switch(button) |
| 409 | 409 |
{
|
| 410 | 410 |
case 0: Bundle sBundle = new Bundle(); |
| 411 |
sBundle.putInt("tab", mObject );
|
|
| 411 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 412 |
sBundle.putInt("tab", currObject );
|
|
| 412 | 413 |
sBundle.putBoolean("submitting", false);
|
| 413 | 414 |
RubikDialogScores scores = new RubikDialogScores(); |
| 414 | 415 |
scores.setArguments(sBundle); |
| ... | ... | |
| 460 | 461 |
@Override |
| 461 | 462 |
public void onClick(View v) |
| 462 | 463 |
{
|
| 463 |
RubikObject object = RubikObjectList.getObject(mObject); |
|
| 464 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 465 |
RubikObject object = RubikObjectList.getObject(currObject); |
|
| 464 | 466 |
int numScrambles = object==null ? 0 : object.getNumScramble(); |
| 465 | 467 |
mShouldReactToEndOfScrambling = false; |
| 466 | 468 |
act.getControl().scrambleObject(numScrambles); |
| ... | ... | |
| 472 | 474 |
|
| 473 | 475 |
public void savePreferences(SharedPreferences.Editor editor) |
| 474 | 476 |
{
|
| 475 |
android.util.Log.e("D", "savePrefs");
|
|
| 476 | 477 |
|
| 477 |
RubikObject object = RubikObjectList.getObject(mObject); |
|
| 478 |
|
|
| 479 |
if( object!=null ) |
|
| 480 |
{
|
|
| 481 |
editor.putString("statePlay_objName", object.getName() );
|
|
| 482 |
} |
|
| 483 | 478 |
} |
| 484 | 479 |
|
| 485 | 480 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 486 | 481 |
|
| 487 | 482 |
public void restorePreferences(SharedPreferences preferences) |
| 488 | 483 |
{
|
| 489 |
RubikObject object = RubikObjectList.getObject(DEF_OBJECT); |
|
| 490 |
String defName = object==null ? "CUBE_3" : object.getName(); |
|
| 491 |
String objName= preferences.getString("statePlay_objName",defName);
|
|
| 492 |
mObject = RubikObjectList.getOrdinal(objName); |
|
| 493 | 484 |
|
| 494 |
if( mObject<0 || mObject>=RubikObjectList.getNumObjects() ) mObject = DEF_OBJECT; |
|
| 495 | 485 |
} |
| 496 | 486 |
|
| 497 | 487 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 498 | 488 |
|
| 499 |
public boolean setObject(RubikActivity act, int ordinal)
|
|
| 489 |
public void setCurrObject(RubikActivity act)
|
|
| 500 | 490 |
{
|
| 501 |
if( mObject!=ordinal ) |
|
| 502 |
{
|
|
| 503 |
mObject = ordinal; |
|
| 504 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
| 505 |
return true; |
|
| 506 |
} |
|
| 507 |
|
|
| 508 |
return false; |
|
| 491 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
| 509 | 492 |
} |
| 510 | 493 |
|
| 511 | 494 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| ... | ... | |
| 557 | 540 |
|
| 558 | 541 |
public void adjustSolvedIcons() |
| 559 | 542 |
{
|
| 560 |
int dbLevel = RubikObjectList.getDBLevel(mObject); |
|
| 543 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 544 |
int dbLevel = RubikObjectList.getDBLevel(currObject); |
|
| 561 | 545 |
int numLevel= Math.min(dbLevel, LEVELS_SHOWN); |
| 562 | 546 |
RubikScores scores = RubikScores.getInstance(); |
| 563 | 547 |
|
| ... | ... | |
| 565 | 549 |
{
|
| 566 | 550 |
int level = i<numLevel-1 ? i+1 : dbLevel; |
| 567 | 551 |
Button button = (Button)mPlayLayout.getChildAt(i); |
| 568 |
int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
| 552 |
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
| 569 | 553 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
| 570 | 554 |
} |
| 571 | 555 |
} |
| ... | ... | |
| 574 | 558 |
|
| 575 | 559 |
private void adjustLevels(final RubikActivity act) |
| 576 | 560 |
{
|
| 577 |
int dbLevel = RubikObjectList.getDBLevel(mObject); |
|
| 578 |
RubikObject object = RubikObjectList.getObject(mObject); |
|
| 561 |
int currObject = RubikObjectList.getCurrObject(); |
|
| 562 |
int dbLevel = RubikObjectList.getDBLevel(currObject); |
|
| 563 |
RubikObject object = RubikObjectList.getObject(currObject); |
|
| 579 | 564 |
int numScrambles = object==null ? 0 : object.getNumScramble(); |
| 580 | 565 |
int numLevel = Math.min(dbLevel, LEVELS_SHOWN); |
| 581 | 566 |
String[] levels = new String[numLevel]; |
| ... | ... | |
| 623 | 608 |
button.setText(levels[i]); |
| 624 | 609 |
button.setTextSize(TypedValue.COMPLEX_UNIT_PX, mMenuTextSize); |
| 625 | 610 |
|
| 626 |
int icon = scores.isSolved(mObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
| 611 |
int icon = scores.isSolved(currObject, level-1) ? R.drawable.ui_solved : R.drawable.ui_notsolved;
|
|
| 627 | 612 |
button.setCompoundDrawablesWithIntrinsicBounds(icon,0,0,0); |
| 628 | 613 |
|
| 629 | 614 |
button.setOnClickListener( new View.OnClickListener() |
| ... | ... | |
| 660 | 645 |
{
|
| 661 | 646 |
return mShouldReactToEndOfScrambling; |
| 662 | 647 |
} |
| 663 |
|
|
| 664 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 665 |
|
|
| 666 |
public int getObject() |
|
| 667 |
{
|
|
| 668 |
return mObject; |
|
| 669 |
} |
|
| 670 | 648 |
} |
Also available in: Unified diff
Move the 'currObject' from RubikScreenPlay (WTF?) to RubikObjectList.