Revision a7a7cc9c
Added by Leszek Koltunski over 5 years ago
| src/main/java/org/distorted/magic/RubikActivity.java | ||
|---|---|---|
| 39 | 39 |
{
|
| 40 | 40 |
static final int DEFAULT_SIZE = 3; |
| 41 | 41 |
private static final int SMALLEST_SIZE = 2; |
| 42 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4};
|
|
| 42 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4, R.id.rubikSize5};
|
|
| 43 | 43 |
|
| 44 | 44 |
public static final int MIN_SCRAMBLE = 1; |
| 45 | 45 |
public static final int DEF_SCRAMBLE = 3; |
| ... | ... | |
| 167 | 167 |
settings.show(getSupportFragmentManager(), null); |
| 168 | 168 |
} |
| 169 | 169 |
|
| 170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 171 |
|
|
| 172 |
public void Scores(View v) |
|
| 173 |
{
|
|
| 174 |
RubikScores scores = new RubikScores(); |
|
| 175 |
scores.show(getSupportFragmentManager(), null); |
|
| 176 |
} |
|
| 177 |
|
|
| 170 | 178 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 171 | 179 |
|
| 172 | 180 |
public void About(View v) |
| src/main/java/org/distorted/magic/RubikRenderer.java | ||
|---|---|---|
| 229 | 229 |
// various things are done here delayed, 'after the next render' as not to be done mid-render and |
| 230 | 230 |
// cause artifacts. |
| 231 | 231 |
|
| 232 |
@Override
|
|
| 233 |
public void onDrawFrame(GL10 glUnused)
|
|
| 234 |
{
|
|
| 235 |
mScreen.render( System.currentTimeMillis() );
|
|
| 232 |
@Override |
|
| 233 |
public void onDrawFrame(GL10 glUnused)
|
|
| 234 |
{
|
|
| 235 |
mScreen.render( System.currentTimeMillis() ); |
|
| 236 | 236 |
|
| 237 |
if( mSetQuatCurrent )
|
|
| 238 |
{
|
|
| 239 |
mSetQuatCurrent = false;
|
|
| 240 |
mView.setQuatCurrent();
|
|
| 241 |
}
|
|
| 237 |
if( mSetQuatCurrent ) |
|
| 238 |
{
|
|
| 239 |
mSetQuatCurrent = false; |
|
| 240 |
mView.setQuatCurrent(); |
|
| 241 |
} |
|
| 242 | 242 |
|
| 243 |
if( mSetQuatAccumulated )
|
|
| 244 |
{
|
|
| 245 |
mSetQuatAccumulated = false;
|
|
| 246 |
mView.setQuatAccumulated();
|
|
| 247 |
}
|
|
| 243 |
if( mSetQuatAccumulated ) |
|
| 244 |
{
|
|
| 245 |
mSetQuatAccumulated = false; |
|
| 246 |
mView.setQuatAccumulated(); |
|
| 247 |
} |
|
| 248 | 248 |
|
| 249 |
if( mFinishRotation )
|
|
| 250 |
{
|
|
| 251 |
mFinishRotation = false;
|
|
| 252 |
mCanRotate = false;
|
|
| 253 |
mCanUI = false;
|
|
| 254 |
mRotationFinishedID = mNewCube.finishRotationNow(this);
|
|
| 255 |
}
|
|
| 249 |
if( mFinishRotation ) |
|
| 250 |
{
|
|
| 251 |
mFinishRotation = false; |
|
| 252 |
mCanRotate = false; |
|
| 253 |
mCanUI = false; |
|
| 254 |
mRotationFinishedID = mNewCube.finishRotationNow(this); |
|
| 255 |
} |
|
| 256 | 256 |
|
| 257 |
if( mRemoveRotation ) |
|
| 258 |
{
|
|
| 259 |
mRemoveRotation=false; |
|
| 260 |
mNewCube.removeRotationNow(); |
|
| 261 |
|
|
| 262 |
boolean solved = mNewCube.isSolved(); |
|
| 263 |
|
|
| 264 |
if( solved && !mIsSolved ) |
|
| 265 |
{
|
|
| 266 |
mCanDrag = false; |
|
| 267 |
mCanRotate = false; |
|
| 268 |
mCanUI = false; |
|
| 269 |
doEffectNow( BaseEffect.Type.WIN ); |
|
| 270 |
} |
|
| 271 |
else |
|
| 272 |
{
|
|
| 273 |
mCanRotate = true; |
|
| 274 |
mCanUI = true; |
|
| 275 |
} |
|
| 276 |
|
|
| 277 |
mIsSolved = solved; |
|
| 278 |
} |
|
| 257 |
if( mRemoveRotation ) |
|
| 258 |
{
|
|
| 259 |
mRemoveRotation=false; |
|
| 260 |
mNewCube.removeRotationNow(); |
|
| 279 | 261 |
|
| 280 |
if( mSizeChangeCube ) |
|
| 281 |
{
|
|
| 282 |
mSizeChangeCube = false; |
|
| 283 |
mCanDrag = false; |
|
| 284 |
mCanRotate = false; |
|
| 285 |
mCanUI = false; |
|
| 286 |
createCubeNow(mNextCubeSize); |
|
| 287 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
|
| 288 |
} |
|
| 262 |
boolean solved = mNewCube.isSolved(); |
|
| 289 | 263 |
|
| 290 |
if( mSolveCube ) |
|
| 291 |
{
|
|
| 292 |
mSolveCube = false; |
|
| 293 |
mCanDrag = false; |
|
| 294 |
mCanRotate = false; |
|
| 295 |
mCanUI = false; |
|
| 296 |
doEffectNow( BaseEffect.Type.SOLVE ); |
|
| 297 |
} |
|
| 264 |
if( solved && !mIsSolved ) |
|
| 265 |
{
|
|
| 266 |
mCanDrag = false; |
|
| 267 |
mCanRotate = false; |
|
| 268 |
mCanUI = false; |
|
| 269 |
doEffectNow( BaseEffect.Type.WIN ); |
|
| 270 |
} |
|
| 271 |
else |
|
| 272 |
{
|
|
| 273 |
mCanRotate = true; |
|
| 274 |
mCanUI = true; |
|
| 275 |
} |
|
| 298 | 276 |
|
| 299 |
if( mScrambleCube ) |
|
| 300 |
{
|
|
| 301 |
mScrambleCube = false; |
|
| 302 |
mCanDrag = false; |
|
| 303 |
mCanRotate = false; |
|
| 304 |
mCanUI = false; |
|
| 305 |
doEffectNow( BaseEffect.Type.SCRAMBLE ); |
|
| 306 |
} |
|
| 307 |
} |
|
| 277 |
mIsSolved = solved; |
|
| 278 |
} |
|
| 279 |
|
|
| 280 |
if( mSizeChangeCube ) |
|
| 281 |
{
|
|
| 282 |
mSizeChangeCube = false; |
|
| 283 |
mCanDrag = false; |
|
| 284 |
mCanRotate = false; |
|
| 285 |
mCanUI = false; |
|
| 286 |
createCubeNow(mNextCubeSize); |
|
| 287 |
doEffectNow( BaseEffect.Type.SIZECHANGE ); |
|
| 288 |
} |
|
| 289 |
|
|
| 290 |
if( mSolveCube ) |
|
| 291 |
{
|
|
| 292 |
mSolveCube = false; |
|
| 293 |
mCanDrag = false; |
|
| 294 |
mCanRotate = false; |
|
| 295 |
mCanUI = false; |
|
| 296 |
doEffectNow( BaseEffect.Type.SOLVE ); |
|
| 297 |
} |
|
| 298 |
|
|
| 299 |
if( mScrambleCube ) |
|
| 300 |
{
|
|
| 301 |
mScrambleCube = false; |
|
| 302 |
mCanDrag = false; |
|
| 303 |
mCanRotate = false; |
|
| 304 |
mCanUI = false; |
|
| 305 |
doEffectNow( BaseEffect.Type.SCRAMBLE ); |
|
| 306 |
} |
|
| 307 |
} |
|
| 308 | 308 |
|
| 309 | 309 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 310 | 310 |
|
| src/main/java/org/distorted/magic/RubikScores.java | ||
|---|---|---|
| 1 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 2 |
// Copyright 2019 Leszek Koltunski // |
|
| 3 |
// // |
|
| 4 |
// This file is part of Distorted. // |
|
| 5 |
// // |
|
| 6 |
// Distorted 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 |
// Distorted 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 Distorted. If not, see <http://www.gnu.org/licenses/>. // |
|
| 18 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 19 |
|
|
| 20 |
package org.distorted.magic; |
|
| 21 |
|
|
| 22 |
import android.support.v7.app.AppCompatDialogFragment; |
|
| 23 |
|
|
| 24 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 25 |
|
|
| 26 |
public class RubikScores extends AppCompatDialogFragment |
|
| 27 |
{
|
|
| 28 |
|
|
| 29 |
} |
|
| src/main/res/layout/main.xml | ||
|---|---|---|
| 6 | 6 |
|
| 7 | 7 |
<LinearLayout |
| 8 | 8 |
android:layout_width="fill_parent" |
| 9 |
android:layout_height="wrap_content"
|
|
| 9 |
android:layout_height="50dp"
|
|
| 10 | 10 |
android:gravity="center|fill_horizontal" > |
| 11 | 11 |
|
| 12 |
<Button
|
|
| 13 |
android:id="@+id/rubikSettings"
|
|
| 12 |
<Button |
|
| 13 |
android:id="@+id/rubikScramble"
|
|
| 14 | 14 |
android:layout_width="wrap_content" |
| 15 |
android:layout_height="64dp"
|
|
| 15 |
android:layout_height="fill_parent"
|
|
| 16 | 16 |
android:layout_weight="0.5" |
| 17 |
android:onClick="Settings"
|
|
| 17 |
android:onClick="Scramble"
|
|
| 18 | 18 |
android:paddingLeft="5dp" |
| 19 | 19 |
android:paddingRight="5dp" |
| 20 |
android:text="@string/settings" /> |
|
| 20 |
android:text="@string/scramble" /> |
|
| 21 |
|
|
| 22 |
<org.distorted.component.HorizontalNumberPicker |
|
| 23 |
android:id="@+id/rubikNumberPicker" |
|
| 24 |
android:layout_width="192dp" |
|
| 25 |
android:layout_height="fill_parent"/> |
|
| 26 |
|
|
| 27 |
<Button |
|
| 28 |
android:id="@+id/rubikSolve" |
|
| 29 |
android:layout_width="wrap_content" |
|
| 30 |
android:layout_height="fill_parent" |
|
| 31 |
android:layout_weight="0.5" |
|
| 32 |
android:onClick="Solve" |
|
| 33 |
android:paddingLeft="5dp" |
|
| 34 |
android:paddingRight="5dp" |
|
| 35 |
android:text="@string/solve" /> |
|
| 36 |
|
|
| 37 |
</LinearLayout> |
|
| 38 |
|
|
| 39 |
<org.distorted.magic.RubikSurfaceView |
|
| 40 |
android:id="@+id/rubikSurfaceView" |
|
| 41 |
android:layout_width="fill_parent" |
|
| 42 |
android:layout_height="0dp" |
|
| 43 |
android:layout_weight="1" /> |
|
| 44 |
|
|
| 45 |
<LinearLayout |
|
| 46 |
android:layout_width="match_parent" |
|
| 47 |
android:layout_height="wrap_content" |
|
| 48 |
android:gravity="center" > |
|
| 21 | 49 |
|
| 22 | 50 |
<ImageButton |
| 23 | 51 |
android:id="@+id/rubikSize2" |
| 24 | 52 |
android:layout_width="64dp" |
| 25 | 53 |
android:layout_height="64dp" |
| 26 | 54 |
android:onClick="setSize" |
| 27 |
android:paddingLeft="5dp"
|
|
| 28 |
android:paddingRight="5dp"
|
|
| 29 |
android:src="@drawable/button2"/> |
|
| 55 |
android:paddingLeft="3dp"
|
|
| 56 |
android:paddingRight="3dp"
|
|
| 57 |
android:src="@drawable/button2" />
|
|
| 30 | 58 |
|
| 31 | 59 |
<ImageButton |
| 32 | 60 |
android:id="@+id/rubikSize3" |
| 33 | 61 |
android:layout_width="64dp" |
| 34 | 62 |
android:layout_height="64dp" |
| 35 | 63 |
android:onClick="setSize" |
| 36 |
android:paddingLeft="5dp"
|
|
| 37 |
android:paddingRight="5dp"
|
|
| 38 |
android:src="@drawable/button3"/> |
|
| 64 |
android:paddingLeft="3dp"
|
|
| 65 |
android:paddingRight="3dp"
|
|
| 66 |
android:src="@drawable/button3" />
|
|
| 39 | 67 |
|
| 40 | 68 |
<ImageButton |
| 41 | 69 |
android:id="@+id/rubikSize4" |
| 42 | 70 |
android:layout_width="64dp" |
| 43 | 71 |
android:layout_height="64dp" |
| 44 | 72 |
android:onClick="setSize" |
| 45 |
android:paddingLeft="5dp"
|
|
| 46 |
android:paddingRight="5dp"
|
|
| 47 |
android:src="@drawable/button4"/> |
|
| 73 |
android:paddingLeft="3dp"
|
|
| 74 |
android:paddingRight="3dp"
|
|
| 75 |
android:src="@drawable/button4" />
|
|
| 48 | 76 |
|
| 49 |
<Button |
|
| 50 |
android:id="@+id/rubikAbout"
|
|
| 51 |
android:layout_width="wrap_content"
|
|
| 77 |
<ImageButton
|
|
| 78 |
android:id="@+id/rubikSize5"
|
|
| 79 |
android:layout_width="64dp"
|
|
| 52 | 80 |
android:layout_height="64dp" |
| 53 |
android:layout_weight="0.5" |
|
| 54 |
android:onClick="About" |
|
| 55 |
android:paddingLeft="5dp" |
|
| 56 |
android:paddingRight="5dp" |
|
| 57 |
android:text="@string/about" /> |
|
| 58 |
|
|
| 81 |
android:onClick="setSize" |
|
| 82 |
android:paddingLeft="3dp" |
|
| 83 |
android:paddingRight="3dp" |
|
| 84 |
android:src="@drawable/button5" /> |
|
| 59 | 85 |
</LinearLayout> |
| 60 | 86 |
|
| 61 | 87 |
<LinearLayout |
| 62 | 88 |
android:layout_width="fill_parent" |
| 63 |
android:layout_height="64dp"
|
|
| 89 |
android:layout_height="50dp"
|
|
| 64 | 90 |
android:gravity="center|fill_horizontal" > |
| 65 | 91 |
|
| 66 | 92 |
<Button |
| 67 |
android:id="@+id/rubikScramble"
|
|
| 93 |
android:id="@+id/rubikSettings"
|
|
| 68 | 94 |
android:layout_width="wrap_content" |
| 69 | 95 |
android:layout_height="fill_parent" |
| 70 |
android:layout_weight="0.5"
|
|
| 71 |
android:onClick="Scramble"
|
|
| 72 |
android:paddingLeft="5dp"
|
|
| 73 |
android:paddingRight="5dp"
|
|
| 74 |
android:text="@string/scramble" />
|
|
| 96 |
android:layout_weight="1"
|
|
| 97 |
android:onClick="Settings"
|
|
| 98 |
android:paddingLeft="3dp"
|
|
| 99 |
android:paddingRight="3dp"
|
|
| 100 |
android:text="@string/settings" />
|
|
| 75 | 101 |
|
| 76 |
<org.distorted.component.HorizontalNumberPicker |
|
| 77 |
android:id="@+id/rubikNumberPicker" |
|
| 78 |
android:layout_width="192dp" |
|
| 79 |
android:layout_height="fill_parent"/> |
|
| 102 |
<Button |
|
| 103 |
android:id="@+id/rubikScores" |
|
| 104 |
android:layout_width="wrap_content" |
|
| 105 |
android:layout_height="fill_parent" |
|
| 106 |
android:layout_weight="1" |
|
| 107 |
android:onClick="Scores" |
|
| 108 |
android:paddingLeft="3dp" |
|
| 109 |
android:paddingRight="3dp" |
|
| 110 |
android:text="@string/scores" /> |
|
| 80 | 111 |
|
| 81 | 112 |
<Button |
| 82 |
android:id="@+id/rubikSolve"
|
|
| 113 |
android:id="@+id/rubikAbout"
|
|
| 83 | 114 |
android:layout_width="wrap_content" |
| 84 | 115 |
android:layout_height="fill_parent" |
| 85 |
android:layout_weight="0.5"
|
|
| 86 |
android:onClick="Solve"
|
|
| 87 |
android:paddingLeft="5dp"
|
|
| 88 |
android:paddingRight="5dp"
|
|
| 89 |
android:text="@string/solve" />
|
|
| 116 |
android:layout_weight="1"
|
|
| 117 |
android:onClick="About"
|
|
| 118 |
android:paddingLeft="3dp"
|
|
| 119 |
android:paddingRight="3dp"
|
|
| 120 |
android:text="@string/about" />
|
|
| 90 | 121 |
|
| 91 | 122 |
</LinearLayout> |
| 92 | 123 |
|
| 93 |
<org.distorted.magic.RubikSurfaceView |
|
| 94 |
android:id="@+id/rubikSurfaceView" |
|
| 95 |
android:layout_width="fill_parent" |
|
| 96 |
android:layout_height="0dp" |
|
| 97 |
android:layout_weight="1" /> |
|
| 98 |
|
|
| 99 | 124 |
</LinearLayout> |
| src/main/res/layout/numberpicker.xml | ||
|---|---|---|
| 10 | 10 |
android:layout_height="match_parent" |
| 11 | 11 |
android:layout_weight="1" |
| 12 | 12 |
android:text="-" |
| 13 |
android:textSize="30sp" />
|
|
| 13 |
android:textSize="24sp" />
|
|
| 14 | 14 |
|
| 15 | 15 |
<TextView |
| 16 | 16 |
android:id="@+id/textNumber" |
| ... | ... | |
| 18 | 18 |
android:layout_height="match_parent" |
| 19 | 19 |
android:layout_weight="1" |
| 20 | 20 |
android:textAlignment="center" |
| 21 |
android:textSize="46sp" />
|
|
| 21 |
android:textSize="36sp" />
|
|
| 22 | 22 |
|
| 23 | 23 |
<Button |
| 24 | 24 |
android:id="@+id/buttonMore" |
| ... | ... | |
| 26 | 26 |
android:layout_height="match_parent" |
| 27 | 27 |
android:layout_weight="1" |
| 28 | 28 |
android:text="+" |
| 29 |
android:textSize="30sp" />
|
|
| 29 |
android:textSize="24sp" />
|
|
| 30 | 30 |
</LinearLayout> |
| src/main/res/values/strings.xml | ||
|---|---|---|
| 5 | 5 |
<string name="scramble">Scramble</string> |
| 6 | 6 |
<string name="solve">Solve</string> |
| 7 | 7 |
<string name="settings">Settings</string> |
| 8 |
<string name="scores">Scores</string> |
|
| 8 | 9 |
<string name="about">About</string> |
| 9 | 10 |
<string name="save">SAVE</string> |
| 10 | 11 |
<string name="ok">OK</string> |
Also available in: Unified diff
Add a 5x5x5 cube.