Revision 15adc102
Added by Leszek Koltunski over 3 years ago
| src/main/java/org/distorted/objects/MainEntry.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 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.objects; |
|
| 21 |
|
|
| 22 |
import android.app.Activity; |
|
| 23 |
import android.graphics.drawable.Drawable; |
|
| 24 |
import android.widget.ImageButton; |
|
| 25 |
|
|
| 26 |
import org.distorted.main.RubikActivity; |
|
| 27 |
|
|
| 28 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 29 |
|
|
| 30 |
public class MainEntry |
|
| 31 |
{
|
|
| 32 |
public final static int TYPE_OBJECT = 0; |
|
| 33 |
public final static int TYPE_CREATOR = 1; |
|
| 34 |
|
|
| 35 |
private final RubikObject mObject; |
|
| 36 |
private final int mType; |
|
| 37 |
private final int mIconID; |
|
| 38 |
private final int mOridnal; |
|
| 39 |
private Drawable mIconDrawable; |
|
| 40 |
private boolean mPrepared; |
|
| 41 |
|
|
| 42 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 43 |
|
|
| 44 |
MainEntry(RubikObject object, int ordinal) |
|
| 45 |
{
|
|
| 46 |
mType = TYPE_OBJECT; |
|
| 47 |
mIconID = 0; |
|
| 48 |
mOridnal = ordinal; |
|
| 49 |
mIconDrawable = null; |
|
| 50 |
mObject = object; |
|
| 51 |
mPrepared = false; |
|
| 52 |
} |
|
| 53 |
|
|
| 54 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 55 |
|
|
| 56 |
MainEntry(int type, int iconID) |
|
| 57 |
{
|
|
| 58 |
mType = type; |
|
| 59 |
mIconID = iconID; |
|
| 60 |
mOridnal = -1; |
|
| 61 |
mIconDrawable = null; |
|
| 62 |
mObject = null; |
|
| 63 |
mPrepared = false; |
|
| 64 |
} |
|
| 65 |
|
|
| 66 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 67 |
|
|
| 68 |
private void prepare(Activity act) |
|
| 69 |
{
|
|
| 70 |
mIconDrawable = act.getDrawable(mIconID); |
|
| 71 |
mPrepared = true; |
|
| 72 |
} |
|
| 73 |
|
|
| 74 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 75 |
// PUBLIC API |
|
| 76 |
|
|
| 77 |
public void setIconTo(RubikActivity act, ImageButton button) |
|
| 78 |
{
|
|
| 79 |
if( mType==TYPE_OBJECT ) |
|
| 80 |
{
|
|
| 81 |
if( mObject!=null ) mObject.setIconTo(act,button); |
|
| 82 |
else android.util.Log.e("D", "MainListEntry: object null!!");
|
|
| 83 |
} |
|
| 84 |
else if( mType==TYPE_CREATOR ) |
|
| 85 |
{
|
|
| 86 |
if( !mPrepared ) prepare(act); |
|
| 87 |
button.setBackground(mIconDrawable); |
|
| 88 |
} |
|
| 89 |
} |
|
| 90 |
|
|
| 91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 92 |
|
|
| 93 |
public int getType() |
|
| 94 |
{
|
|
| 95 |
return mType; |
|
| 96 |
} |
|
| 97 |
|
|
| 98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 99 |
|
|
| 100 |
public int getOrdinal() |
|
| 101 |
{
|
|
| 102 |
return mOridnal; |
|
| 103 |
} |
|
| 104 |
} |
|
| src/main/java/org/distorted/objects/MainEntryList.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2022 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.objects; |
|
| 21 |
|
|
| 22 |
import org.distorted.main.R; |
|
| 23 |
|
|
| 24 |
import java.util.ArrayList; |
|
| 25 |
|
|
| 26 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 27 |
|
|
| 28 |
public class MainEntryList |
|
| 29 |
{
|
|
| 30 |
private final ArrayList<MainEntry> mList; |
|
| 31 |
private static MainEntryList mThis; |
|
| 32 |
|
|
| 33 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 34 |
|
|
| 35 |
private MainEntryList() |
|
| 36 |
{
|
|
| 37 |
mList = new ArrayList<>(); |
|
| 38 |
|
|
| 39 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 40 |
|
|
| 41 |
for(int i=0; i<numObjects; i++) |
|
| 42 |
{
|
|
| 43 |
RubikObject object = RubikObjectList.getObject(i); |
|
| 44 |
|
|
| 45 |
if( object!=null ) |
|
| 46 |
{
|
|
| 47 |
MainEntry entry = new MainEntry(object,i); |
|
| 48 |
mList.add(entry); |
|
| 49 |
|
|
| 50 |
String name = object.getLowerName(); |
|
| 51 |
|
|
| 52 |
if( name!=null && name.equals("ban4_3") )
|
|
| 53 |
{
|
|
| 54 |
MainEntry creator = new MainEntry(MainEntry.TYPE_CREATOR, R.drawable.plus); |
|
| 55 |
mList.add(creator); |
|
| 56 |
} |
|
| 57 |
} |
|
| 58 |
} |
|
| 59 |
} |
|
| 60 |
|
|
| 61 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 62 |
|
|
| 63 |
public static MainEntryList getInstance() |
|
| 64 |
{
|
|
| 65 |
if( mThis==null ) mThis = new MainEntryList(); |
|
| 66 |
return mThis; |
|
| 67 |
} |
|
| 68 |
|
|
| 69 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 70 |
|
|
| 71 |
public void addEntry(MainEntry entry) |
|
| 72 |
{
|
|
| 73 |
mList.add(entry); |
|
| 74 |
} |
|
| 75 |
|
|
| 76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 77 |
|
|
| 78 |
public int getNumOfEntries() |
|
| 79 |
{
|
|
| 80 |
return mList.size(); |
|
| 81 |
} |
|
| 82 |
|
|
| 83 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 84 |
|
|
| 85 |
public MainEntry getEntry(int index) |
|
| 86 |
{
|
|
| 87 |
return mList.get(index); |
|
| 88 |
} |
|
| 89 |
} |
|
| src/main/java/org/distorted/screens/RubikScreenPlay.java | ||
|---|---|---|
| 54 | 54 |
import org.distorted.helpers.TransparentButton; |
| 55 | 55 |
import org.distorted.helpers.TransparentImageButton; |
| 56 | 56 |
import org.distorted.external.RubikScores; |
| 57 |
import org.distorted.objects.MainEntry; |
|
| 58 |
import org.distorted.objects.MainEntryList; |
|
| 57 | 59 |
import org.distorted.objects.RubikObject; |
| 58 | 60 |
import org.distorted.objects.RubikObjectList; |
| 59 | 61 |
|
| ... | ... | |
| 70 | 72 |
R.string.patterns, |
| 71 | 73 |
R.string.solver, |
| 72 | 74 |
R.string.tutorials, |
| 73 |
R.string.bandaged, |
|
| 74 | 75 |
R.string.about }; |
| 75 | 76 |
private static final int NUM_BUTTONS = BUTTON_LABELS.length; |
| 76 | 77 |
|
| ... | ... | |
| 271 | 272 |
colSpecs[col] = GridLayout.spec(col); |
| 272 | 273 |
} |
| 273 | 274 |
|
| 274 |
int numObjects = RubikObjectList.getNumObjects(); |
|
| 275 |
MainEntryList list = MainEntryList.getInstance(); |
|
| 276 |
int numEntries = list.getNumOfEntries(); |
|
| 275 | 277 |
|
| 276 |
for(int object=0; object<numObjects; object++)
|
|
| 278 |
for(int entry=0; entry<numEntries; entry++)
|
|
| 277 | 279 |
{
|
| 278 |
final int ordinal = object; |
|
| 279 |
final RubikObject rObject = RubikObjectList.getObject(object); |
|
| 280 |
int row = object/NUM_COLUMNS; |
|
| 280 |
final MainEntry mainEntry = list.getEntry(entry); |
|
| 281 |
int row = entry/NUM_COLUMNS; |
|
| 281 | 282 |
ImageButton button = new ImageButton(act); |
| 282 |
if( rObject!=null ) rObject.setIconTo(act,button);
|
|
| 283 |
if( mainEntry!=null ) mainEntry.setIconTo(act,button);
|
|
| 283 | 284 |
|
| 284 | 285 |
button.setOnClickListener( new View.OnClickListener() |
| 285 | 286 |
{
|
| ... | ... | |
| 288 | 289 |
{
|
| 289 | 290 |
if( act.getControl().isUINotBlocked() && ScreenList.getCurrentScreen()== ScreenList.PLAY ) |
| 290 | 291 |
{
|
| 291 |
RubikObjectList.setCurrObject(act,ordinal); |
|
| 292 |
act.changeObject(ordinal,true); |
|
| 293 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
| 294 |
mMovesController.clearMoves(act); |
|
| 292 |
int type = mainEntry!=null ? mainEntry.getType() : -1; |
|
| 293 |
|
|
| 294 |
if( type==MainEntry.TYPE_OBJECT ) |
|
| 295 |
{
|
|
| 296 |
int ordinal = mainEntry.getOrdinal(); |
|
| 297 |
RubikObjectList.setCurrObject(act,ordinal); |
|
| 298 |
act.changeObject(ordinal,true); |
|
| 299 |
if( mPlayLayout!=null ) adjustLevels(act); |
|
| 300 |
mMovesController.clearMoves(act); |
|
| 301 |
} |
|
| 302 |
else if( type==MainEntry.TYPE_CREATOR ) |
|
| 303 |
{
|
|
| 304 |
act.switchToBandagedCreator(); |
|
| 305 |
} |
|
| 295 | 306 |
} |
| 296 | 307 |
|
| 297 | 308 |
if( mObjectPopup!=null ) mObjectPopup.dismiss(); |
| ... | ... | |
| 459 | 470 |
case 3: RubikDialogTutorial tDiag = new RubikDialogTutorial(); |
| 460 | 471 |
tDiag.show( act.getSupportFragmentManager(), RubikDialogTutorial.getDialogTag() ); |
| 461 | 472 |
break; |
| 462 |
case 4: act.switchToBandagedCreator(); |
|
| 463 |
break; |
|
| 464 |
case 5: RubikDialogAbout aDiag = new RubikDialogAbout(); |
|
| 473 |
case 4: RubikDialogAbout aDiag = new RubikDialogAbout(); |
|
| 465 | 474 |
aDiag.show(act.getSupportFragmentManager(), null); |
| 466 | 475 |
break; |
| 467 | 476 |
} |
Also available in: Unified diff
Move 'bandaged' from the main menu to the object popup.