Revision 3b12e641
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/effect/ScrambleEffect.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.effect; |
|
21 |
|
|
22 |
import org.distorted.library.effect.Effect; |
|
23 |
import org.distorted.library.main.DistortedEffects; |
|
24 |
import org.distorted.library.main.DistortedScreen; |
|
25 |
import org.distorted.library.message.EffectListener; |
|
26 |
import org.distorted.magic.RubikCube; |
|
27 |
|
|
28 |
import java.lang.reflect.Method; |
|
29 |
|
|
30 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
31 |
|
|
32 |
public abstract class ScrambleEffect implements EffectListener |
|
33 |
{ |
|
34 |
public enum Type |
|
35 |
{ |
|
36 |
NONE (ScrambleEffectNone.class ), |
|
37 |
; |
|
38 |
|
|
39 |
final Class<? extends ScrambleEffect> effect; |
|
40 |
|
|
41 |
Type(Class<? extends ScrambleEffect> effect) |
|
42 |
{ |
|
43 |
this.effect= effect; |
|
44 |
} |
|
45 |
} |
|
46 |
|
|
47 |
private static int NUM_EFFECTS = Type.values().length; |
|
48 |
private static final int NUM_PHASES = 2; |
|
49 |
private static final int FAKE_EFFECT_ID = -3; |
|
50 |
private static final Type[] types; |
|
51 |
|
|
52 |
static |
|
53 |
{ |
|
54 |
int i=0; |
|
55 |
types = new Type[NUM_EFFECTS]; |
|
56 |
|
|
57 |
for(Type type: Type.values()) |
|
58 |
{ |
|
59 |
types[i++] = type; |
|
60 |
} |
|
61 |
} |
|
62 |
|
|
63 |
private EffectListener mListener; |
|
64 |
private int mDuration; |
|
65 |
private int mEffectReturned; |
|
66 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
67 |
private int mPhase; |
|
68 |
private RubikCube mCube; |
|
69 |
private DistortedScreen mScreen; |
|
70 |
|
|
71 |
Effect[][] mNodeEffects; |
|
72 |
int[][] mNodeEffectPosition; |
|
73 |
Effect[][] mCubeEffects; |
|
74 |
int[][] mCubeEffectPosition; |
|
75 |
|
|
76 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
77 |
|
|
78 |
ScrambleEffect() |
|
79 |
{ |
|
80 |
mPhase = 0; |
|
81 |
|
|
82 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
83 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
84 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
85 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
86 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
87 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
88 |
} |
|
89 |
|
|
90 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
91 |
|
|
92 |
public static Type getType(int ordinal) |
|
93 |
{ |
|
94 |
return types[ordinal]; |
|
95 |
} |
|
96 |
|
|
97 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
98 |
|
|
99 |
public static String[] getNames() |
|
100 |
{ |
|
101 |
String[] names = new String[NUM_EFFECTS]; |
|
102 |
|
|
103 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
104 |
{ |
|
105 |
names[i] = types[i].name(); |
|
106 |
} |
|
107 |
|
|
108 |
return names; |
|
109 |
} |
|
110 |
|
|
111 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
112 |
|
|
113 |
public static ScrambleEffect create(Type type) throws InstantiationException, IllegalAccessException |
|
114 |
{ |
|
115 |
return type.effect.newInstance(); |
|
116 |
} |
|
117 |
|
|
118 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
119 |
|
|
120 |
abstract void createEffectsPhase0(int duration); |
|
121 |
abstract void createEffectsPhase1(int duration); |
|
122 |
|
|
123 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
124 |
|
|
125 |
public void effectFinished(final long effectID) |
|
126 |
{ |
|
127 |
int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase]; |
|
128 |
|
|
129 |
for(int i=0; i<mCubeEffectNumber[mPhase]; i++) |
|
130 |
{ |
|
131 |
long id = mCubeEffects[mPhase][i].getID(); |
|
132 |
|
|
133 |
if( effectID == id ) |
|
134 |
{ |
|
135 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
136 |
mCube.remove(id); |
|
137 |
return; |
|
138 |
} |
|
139 |
} |
|
140 |
for(int i=0; i<mNodeEffectNumber[mPhase]; i++) |
|
141 |
{ |
|
142 |
long id = mNodeEffects[mPhase][i].getID(); |
|
143 |
|
|
144 |
if( effectID == id ) |
|
145 |
{ |
|
146 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
147 |
mCube.getEffects().abortById(id); |
|
148 |
return; |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
|
|
153 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
154 |
|
|
155 |
private void effectAction(int phase) |
|
156 |
{ |
|
157 |
switch(phase) |
|
158 |
{ |
|
159 |
case 0: mEffectReturned = 0; |
|
160 |
mPhase = 1; |
|
161 |
mCube.unscramble(); |
|
162 |
createEffectsPhase1(mDuration); |
|
163 |
assignEffects(mPhase); |
|
164 |
break; |
|
165 |
case 1: mListener.effectFinished(FAKE_EFFECT_ID); |
|
166 |
break; |
|
167 |
} |
|
168 |
} |
|
169 |
|
|
170 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
171 |
|
|
172 |
public long start(int duration, DistortedScreen screen, RubikCube cube, int numScrambles, EffectListener listener) |
|
173 |
{ |
|
174 |
mScreen = screen; |
|
175 |
mCube = cube; |
|
176 |
mListener = listener; |
|
177 |
mDuration = duration; |
|
178 |
|
|
179 |
createEffectsPhase0(mDuration); |
|
180 |
assignEffects(mPhase); |
|
181 |
|
|
182 |
return FAKE_EFFECT_ID; |
|
183 |
} |
|
184 |
|
|
185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
186 |
|
|
187 |
private void assignEffects(int phase) |
|
188 |
{ |
|
189 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0; |
|
190 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0; |
|
191 |
|
|
192 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 ) |
|
193 |
{ |
|
194 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!"); |
|
195 |
} |
|
196 |
|
|
197 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
198 |
{ |
|
199 |
mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]); |
|
200 |
mCubeEffects[phase][i].notifyWhenFinished(this); |
|
201 |
} |
|
202 |
|
|
203 |
DistortedEffects nodeEffects = mCube.getEffects(); |
|
204 |
|
|
205 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
206 |
{ |
|
207 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]); |
|
208 |
mNodeEffects[phase][i].notifyWhenFinished(this); |
|
209 |
} |
|
210 |
} |
|
211 |
|
|
212 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
213 |
|
|
214 |
@SuppressWarnings("unused") |
|
215 |
public static void enableEffects() |
|
216 |
{ |
|
217 |
Method method; |
|
218 |
|
|
219 |
for(Type type: Type.values()) |
|
220 |
{ |
|
221 |
try |
|
222 |
{ |
|
223 |
method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod |
|
224 |
} |
|
225 |
catch(NoSuchMethodException ex) |
|
226 |
{ |
|
227 |
android.util.Log.e("ScrambleEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage()); |
|
228 |
method = null; |
|
229 |
} |
|
230 |
|
|
231 |
try |
|
232 |
{ |
|
233 |
if( method!=null ) method.invoke(null); |
|
234 |
} |
|
235 |
catch(Exception ex) |
|
236 |
{ |
|
237 |
android.util.Log.e("ScrambleEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage()); |
|
238 |
} |
|
239 |
} |
|
240 |
} |
|
241 |
} |
src/main/java/org/distorted/effect/ScrambleEffectNone.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.effect; |
|
21 |
|
|
22 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
23 |
|
|
24 |
import org.distorted.library.effect.Effect; |
|
25 |
import org.distorted.library.effect.MatrixEffectMove; |
|
26 |
import org.distorted.library.type.Dynamic3D; |
|
27 |
import org.distorted.library.type.Static3D; |
|
28 |
|
|
29 |
public class ScrambleEffectNone extends ScrambleEffect |
|
30 |
{ |
|
31 |
public void createEffectsPhase0(int duration) |
|
32 |
{ |
|
33 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
34 |
d0.add(new Static3D(0,0,0)); |
|
35 |
|
|
36 |
mCubeEffectPosition[0] = new int[] {-1}; |
|
37 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
38 |
mCubeEffects[0][0] = new MatrixEffectMove(d0); |
|
39 |
} |
|
40 |
|
|
41 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
42 |
|
|
43 |
public void createEffectsPhase1(int duration) |
|
44 |
{ |
|
45 |
Dynamic3D d0 = new Dynamic3D(1,0.5f); |
|
46 |
d0.add(new Static3D(0,0,0)); |
|
47 |
|
|
48 |
mCubeEffectPosition[1] = new int[] {-1}; |
|
49 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
50 |
mCubeEffects[1][0] = new MatrixEffectMove(d0); |
|
51 |
} |
|
52 |
|
|
53 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
54 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
55 |
|
|
56 |
@SuppressWarnings("unused") |
|
57 |
static void enable() |
|
58 |
{ |
|
59 |
|
|
60 |
} |
|
61 |
} |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
30 | 30 |
import android.view.View; |
31 | 31 |
|
32 | 32 |
import org.distorted.component.HorizontalNumberPicker; |
33 |
import org.distorted.effect.ScrambleEffect; |
|
33 | 34 |
import org.distorted.effect.SizeChangeEffect; |
34 | 35 |
import org.distorted.effect.UnscrambleEffect; |
35 | 36 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
44 | 45 |
|
45 | 46 |
public static final int DEFAULT_SIZECHANGE_POS = 20; |
46 | 47 |
public static final int DEFAULT_UNSCRAMBLE_POS = 20; |
48 |
public static final int DEFAULT_SCRAMBLE_POS = 20; |
|
47 | 49 |
public static final int DEFAULT_SIZECHANGE_TYPE= 1; |
48 | 50 |
public static final int DEFAULT_UNSCRAMBLE_TYPE= 1; |
51 |
public static final int DEFAULT_SCRAMBLE_TYPE = 0; |
|
49 | 52 |
|
50 | 53 |
public static final int MIN_SCRAMBLE = 1; |
51 | 54 |
public static final int MAX_SCRAMBLE = 10; |
52 | 55 |
|
53 | 56 |
private static int mSize = DEFAULT_SIZE; |
54 | 57 |
|
55 |
private int mSizeChangePos, mUnscramblePos; |
|
56 |
private int mSizeChangeType, mUnscrambleType; |
|
58 |
private int mSizeChangePos, mUnscramblePos, mScramblePos;
|
|
59 |
private int mSizeChangeType, mUnscrambleType, mScrambleType;
|
|
57 | 60 |
|
58 | 61 |
private HorizontalNumberPicker mPicker; |
59 | 62 |
|
... | ... | |
121 | 124 |
|
122 | 125 |
args.putInt("sizechangePos" , mSizeChangePos ); |
123 | 126 |
args.putInt("unscramblePos" , mUnscramblePos ); |
127 |
args.putInt("scramblePos" , mScramblePos ); |
|
124 | 128 |
args.putInt("sizechangeType", mSizeChangeType); |
125 | 129 |
args.putInt("unscrambleType", mUnscrambleType); |
130 |
args.putInt("scrambleType" , mScrambleType ); |
|
126 | 131 |
|
127 | 132 |
RubikSettings settings = new RubikSettings(); |
128 | 133 |
settings.setArguments(args); |
... | ... | |
157 | 162 |
|
158 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
159 | 164 |
|
160 |
public void onComplete(int sP, int uP, int sT, int uT )
|
|
165 |
public void onComplete(int sizeP, int unscP, int scraP, int sizeT, int unscT, int scraT )
|
|
161 | 166 |
{ |
162 |
mSizeChangePos = sP; |
|
163 |
mUnscramblePos = uP; |
|
164 |
mSizeChangeType= sT; |
|
165 |
mUnscrambleType= uT; |
|
167 |
mSizeChangePos = sizeP; |
|
168 |
mUnscramblePos = unscP; |
|
169 |
mScramblePos = scraP; |
|
170 |
mSizeChangeType= sizeT; |
|
171 |
mUnscrambleType= unscT; |
|
172 |
mScrambleType = scraT; |
|
166 | 173 |
|
167 | 174 |
applyPreferences(); |
168 | 175 |
} |
... | ... | |
219 | 226 |
|
220 | 227 |
editor.putInt("sizechangePos" , mSizeChangePos ); |
221 | 228 |
editor.putInt("unscramblePos" , mUnscramblePos ); |
229 |
editor.putInt("scramblePos" , mScramblePos ); |
|
222 | 230 |
editor.putInt("sizechangeType", mSizeChangeType); |
223 | 231 |
editor.putInt("unscrambleType", mUnscrambleType); |
232 |
editor.putInt("scrambleType" , mScrambleType ); |
|
224 | 233 |
editor.putInt("scramble" , mPicker.getValue() ); |
225 | 234 |
|
226 | 235 |
editor.apply(); |
... | ... | |
234 | 243 |
|
235 | 244 |
mSizeChangePos = preferences.getInt("sizechangePos" , DEFAULT_SIZECHANGE_POS ); |
236 | 245 |
mUnscramblePos = preferences.getInt("unscramblePos" , DEFAULT_UNSCRAMBLE_POS ); |
246 |
mScramblePos = preferences.getInt("scramblePos" , DEFAULT_SCRAMBLE_POS ); |
|
237 | 247 |
mSizeChangeType= preferences.getInt("sizechangeType", DEFAULT_SIZECHANGE_TYPE); |
238 | 248 |
mUnscrambleType= preferences.getInt("unscrambleType", DEFAULT_UNSCRAMBLE_TYPE); |
249 |
mScrambleType = preferences.getInt("scrambleType" , DEFAULT_SCRAMBLE_TYPE ); |
|
239 | 250 |
int scramble = preferences.getInt("scramble" , MIN_SCRAMBLE ); |
240 | 251 |
|
241 | 252 |
mPicker.setValue(scramble); |
... | ... | |
250 | 261 |
|
251 | 262 |
renderer.setSizeChangeDuration(translateDuration(mSizeChangePos)+1); |
252 | 263 |
renderer.setUnscrambleDuration(translateDuration(mUnscramblePos)+1); |
264 |
renderer.setScrambleDuration(translateDuration(mScramblePos)+1); |
|
253 | 265 |
renderer.setSizeChangeType(SizeChangeEffect.getType(mSizeChangeType)); |
254 | 266 |
renderer.setUnscrambleType(UnscrambleEffect.getType(mUnscrambleType)); |
267 |
renderer.setScrambleType(ScrambleEffect.getType(mScrambleType)); |
|
255 | 268 |
} |
256 | 269 |
|
257 | 270 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
23 | 23 |
|
24 | 24 |
import org.distorted.effect.SizeChangeEffect; |
25 | 25 |
import org.distorted.effect.UnscrambleEffect; |
26 |
import org.distorted.effect.ScrambleEffect; |
|
26 | 27 |
import org.distorted.library.effect.VertexEffectSink; |
27 | 28 |
import org.distorted.library.main.DistortedEffects; |
28 | 29 |
import org.distorted.library.main.DistortedLibrary; |
... | ... | |
48 | 49 |
private Static4D mQuatCurrent, mQuatAccumulated; |
49 | 50 |
private Static4D mTempCurrent, mTempAccumulated; |
50 | 51 |
private float mCubeSizeInScreenSpace; |
51 |
private int mNextCubeSize; |
|
52 |
private long mRotationFinishedID, mSizeChangeEffectID, mUnscrambleEffectID; |
|
53 |
private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated, mSolveCube; |
|
52 |
private int mNextCubeSize, mScrambleCubeNum;
|
|
53 |
private long mRotationFinishedID, mSizeChangeEffectID, mUnscrambleEffectID, mScrambleEffectID;
|
|
54 |
private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated, mSolveCube, mScrambleCube;
|
|
54 | 55 |
private boolean mCanRotate, mCanDrag; |
55 | 56 |
private RubikCube mOldCube, mNewCube; |
56 | 57 |
private int mScreenWidth, mScreenHeight; |
57 | 58 |
private MeshFlat mMesh; |
58 | 59 |
private SizeChangeEffect.Type mSizeChangeType; |
59 | 60 |
private UnscrambleEffect.Type mUnscrambleType; |
60 |
private int mSizeChangeDuration, mUnscrambleDuration; |
|
61 |
private ScrambleEffect.Type mScrambleType; |
|
62 |
private int mSizeChangeDuration, mUnscrambleDuration, mScrambleDuration; |
|
61 | 63 |
|
62 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
63 | 65 |
|
... | ... | |
76 | 78 |
mQuatAccumulated = new Static4D(0,0,0,1); |
77 | 79 |
|
78 | 80 |
mScreenWidth = mScreenHeight = 0; |
81 |
mScrambleCubeNum = 0; |
|
79 | 82 |
|
80 | 83 |
mFinishRotation = false; |
81 | 84 |
mRemoveRotation = false; |
82 | 85 |
mFinishDragCurrent = false; |
83 | 86 |
mFinishDragAccumulated = false; |
84 | 87 |
mSolveCube = false; |
88 |
mScrambleCube = false; |
|
85 | 89 |
|
86 | 90 |
mCanRotate = true; |
87 | 91 |
mCanDrag = true; |
88 | 92 |
|
89 | 93 |
mSizeChangeType = SizeChangeEffect.Type.TRANSPARENCY; |
90 | 94 |
mUnscrambleType = UnscrambleEffect.Type.SPIN; |
95 |
mScrambleType = ScrambleEffect.Type.NONE; |
|
96 |
|
|
91 | 97 |
mSizeChangeDuration= 1000; |
92 | 98 |
mUnscrambleDuration= 1000; |
99 |
mScrambleDuration = 1000; |
|
93 | 100 |
|
94 | 101 |
mMesh= new MeshFlat(20,20); |
95 | 102 |
mNextCubeSize =RubikActivity.getSize(); |
... | ... | |
148 | 155 |
mCanRotate = false; |
149 | 156 |
unscrambleCubeNow(); |
150 | 157 |
} |
158 |
|
|
159 |
if( mScrambleCube ) |
|
160 |
{ |
|
161 |
mScrambleCube = false; |
|
162 |
mCanDrag = false; |
|
163 |
mCanRotate = false; |
|
164 |
scrambleCubeNow(); |
|
165 |
} |
|
151 | 166 |
} |
152 | 167 |
|
153 | 168 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
178 | 193 |
{ |
179 | 194 |
VertexEffectSink.enable(); |
180 | 195 |
SizeChangeEffect.enableEffects(); |
196 |
ScrambleEffect.enableEffects(); |
|
197 |
UnscrambleEffect.enableEffects(); |
|
181 | 198 |
|
182 | 199 |
try |
183 | 200 |
{ |
... | ... | |
207 | 224 |
mCanRotate = true; |
208 | 225 |
mCanDrag = true; |
209 | 226 |
} |
227 |
else if( effectID == mScrambleEffectID ) |
|
228 |
{ |
|
229 |
mCanRotate = true; |
|
230 |
mCanDrag = true; |
|
231 |
} |
|
210 | 232 |
} |
211 | 233 |
|
212 | 234 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
259 | 281 |
mUnscrambleDuration = duration; |
260 | 282 |
} |
261 | 283 |
|
284 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
285 |
|
|
286 |
void setScrambleDuration(int duration) |
|
287 |
{ |
|
288 |
mScrambleDuration = duration; |
|
289 |
} |
|
290 |
|
|
262 | 291 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
263 | 292 |
|
264 | 293 |
void setSizeChangeType(SizeChangeEffect.Type type) |
... | ... | |
273 | 302 |
mUnscrambleType = type; |
274 | 303 |
} |
275 | 304 |
|
305 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
306 |
|
|
307 |
void setScrambleType(ScrambleEffect.Type type) |
|
308 |
{ |
|
309 |
mScrambleType = type; |
|
310 |
} |
|
311 |
|
|
276 | 312 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
277 | 313 |
|
278 | 314 |
boolean createCube(int newSize) |
... | ... | |
321 | 357 |
|
322 | 358 |
void scrambleCube(int num) |
323 | 359 |
{ |
324 |
android.util.Log.e("renderer","scrambling "+num+" times"); |
|
360 |
mScrambleCube = true; |
|
361 |
mScrambleCubeNum = num; |
|
362 |
} |
|
363 |
|
|
364 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
365 |
|
|
366 |
private void scrambleCubeNow() |
|
367 |
{ |
|
368 |
try |
|
369 |
{ |
|
370 |
ScrambleEffect effect = ScrambleEffect.create(mScrambleType); |
|
371 |
mScrambleEffectID = effect.start(mScrambleDuration,mScreen,mNewCube,mScrambleCubeNum,this); |
|
372 |
} |
|
373 |
catch(Exception ex) |
|
374 |
{ |
|
375 |
android.util.Log.e("Renderer", "failed to create ScrambleEffect, exception: "+ex.getMessage()); |
|
376 |
|
|
377 |
mCanRotate = true; |
|
378 |
mCanDrag = true; |
|
379 |
} |
|
325 | 380 |
} |
326 | 381 |
|
327 | 382 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/magic/RubikSettings.java | ||
---|---|---|
38 | 38 |
|
39 | 39 |
import org.distorted.effect.SizeChangeEffect; |
40 | 40 |
import org.distorted.effect.UnscrambleEffect; |
41 |
import org.distorted.effect.ScrambleEffect; |
|
41 | 42 |
|
42 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
43 | 44 |
|
... | ... | |
45 | 46 |
{ |
46 | 47 |
public interface OnCompleteListener |
47 | 48 |
{ |
48 |
void onComplete(int sP, int uP, int sT, int uT);
|
|
49 |
void onComplete(int sizeP, int uscrP, int scraP, int sizeT, int unscT, int scraT);
|
|
49 | 50 |
} |
50 | 51 |
|
51 | 52 |
private OnCompleteListener mListener; |
52 |
private int mSizeChangePos, mUnscramblePos; |
|
53 |
private int mSizeChangeType, mUnscrambleType; |
|
54 |
private TextView mSizeChangeDuration, mUnscrambleDuration; |
|
53 |
private int mSizeChangePos, mUnscramblePos, mScramblePos;
|
|
54 |
private int mSizeChangeType, mUnscrambleType, mScrambleType;
|
|
55 |
private TextView mSizeChangeDuration, mUnscrambleDuration, mScrambleDuration;
|
|
55 | 56 |
|
56 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
57 | 58 |
|
... | ... | |
83 | 84 |
{ |
84 | 85 |
mSizeChangePos = args.getInt("sizechangePos"); |
85 | 86 |
mUnscramblePos = args.getInt("unscramblePos"); |
87 |
mScramblePos = args.getInt("scramblePos"); |
|
86 | 88 |
mSizeChangeType= args.getInt("sizechangeType"); |
87 | 89 |
mUnscrambleType= args.getInt("unscrambleType"); |
90 |
mScrambleType = args.getInt("scrambleType"); |
|
88 | 91 |
} |
89 | 92 |
catch(NullPointerException ex) |
90 | 93 |
{ |
91 | 94 |
mSizeChangePos = RubikActivity.DEFAULT_SIZECHANGE_POS; |
92 | 95 |
mUnscramblePos = RubikActivity.DEFAULT_UNSCRAMBLE_POS; |
96 |
mScramblePos = RubikActivity.DEFAULT_SCRAMBLE_POS; |
|
93 | 97 |
mSizeChangeType= RubikActivity.DEFAULT_SIZECHANGE_TYPE; |
94 | 98 |
mUnscrambleType= RubikActivity.DEFAULT_UNSCRAMBLE_TYPE; |
99 |
mScrambleType = RubikActivity.DEFAULT_SCRAMBLE_TYPE; |
|
95 | 100 |
} |
96 | 101 |
} |
97 | 102 |
|
... | ... | |
118 | 123 |
final View view = inflater.inflate(R.layout.settings, null); |
119 | 124 |
builder.setView(view); |
120 | 125 |
|
121 |
mSizeChangeDuration= view.findViewById(R.id.sizechangeDurationText); |
|
126 |
mSizeChangeDuration = view.findViewById(R.id.sizechangeDurationText);
|
|
122 | 127 |
mUnscrambleDuration = view.findViewById(R.id.unscrambleDurationText); |
128 |
mScrambleDuration = view.findViewById(R.id.scrambleDurationText); |
|
123 | 129 |
|
130 |
/// SIZE CHANGE /////////////////////////////////////////////////////// |
|
124 | 131 |
Spinner sizechangeTypeSpinner = view.findViewById(R.id.sizechangeType); |
125 | 132 |
|
126 | 133 |
if( sizechangeTypeSpinner!=null ) |
... | ... | |
145 | 152 |
sizechangeBar.setOnSeekBarChangeListener(this); |
146 | 153 |
sizechangeBar.setProgress(mSizeChangePos); |
147 | 154 |
|
155 |
/// UNSCRAMBLE //////////////////////////////////////////////////////// |
|
148 | 156 |
Spinner unscrambleTypeSpinner = view.findViewById(R.id.unscrambleType); |
149 | 157 |
|
150 | 158 |
if( unscrambleTypeSpinner!=null ) |
... | ... | |
169 | 177 |
unscrambleBar.setOnSeekBarChangeListener(this); |
170 | 178 |
unscrambleBar.setProgress(mUnscramblePos); |
171 | 179 |
|
180 |
/// SCRAMBLE ////////////////////////////////////////////////////////// |
|
181 |
Spinner scrambleTypeSpinner = view.findViewById(R.id.scrambleType); |
|
182 |
|
|
183 |
if( scrambleTypeSpinner!=null ) |
|
184 |
{ |
|
185 |
scrambleTypeSpinner.setOnItemSelectedListener(this); |
|
186 |
String[] scramble = ScrambleEffect.getNames(); |
|
187 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, scramble); |
|
188 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
|
189 |
scrambleTypeSpinner.setAdapter(adapterType); |
|
190 |
|
|
191 |
if(mScrambleType>=0 && mScrambleType<scramble.length) |
|
192 |
{ |
|
193 |
scrambleTypeSpinner.setSelection(mScrambleType); |
|
194 |
} |
|
195 |
} |
|
196 |
else |
|
197 |
{ |
|
198 |
android.util.Log.e("dialog", "SCRAMBLE TYPE SPINNER NULL!!"); |
|
199 |
} |
|
200 |
|
|
201 |
SeekBar scrambleBar = view.findViewById(R.id.scrambleDuration); |
|
202 |
scrambleBar.setOnSeekBarChangeListener(this); |
|
203 |
scrambleBar.setProgress(mScramblePos); |
|
204 |
|
|
172 | 205 |
return builder.create(); |
173 | 206 |
} |
174 | 207 |
|
... | ... | |
176 | 209 |
|
177 | 210 |
private void saveOptions() |
178 | 211 |
{ |
179 |
mListener.onComplete(mSizeChangePos, mUnscramblePos, mSizeChangeType, mUnscrambleType);
|
|
212 |
mListener.onComplete(mSizeChangePos, mUnscramblePos, mScramblePos, mSizeChangeType, mUnscrambleType, mScrambleType);
|
|
180 | 213 |
} |
181 | 214 |
|
182 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
187 | 220 |
{ |
188 | 221 |
case R.id.sizechangeType: mSizeChangeType= pos; break; |
189 | 222 |
case R.id.unscrambleType: mUnscrambleType= pos; break; |
223 |
case R.id.scrambleType : mScrambleType = pos; break; |
|
190 | 224 |
} |
191 | 225 |
} |
192 | 226 |
|
... | ... | |
204 | 238 |
int unscramble_ms= RubikActivity.translateDuration(mUnscramblePos); |
205 | 239 |
mUnscrambleDuration.setText(getString(R.string.ms_placeholder,unscramble_ms)); |
206 | 240 |
break; |
241 |
case R.id.scrambleDuration : mScramblePos= progress; |
|
242 |
int scramble_ms= RubikActivity.translateDuration(mScramblePos); |
|
243 |
mScrambleDuration.setText(getString(R.string.ms_placeholder,scramble_ms)); |
|
244 |
break; |
|
207 | 245 |
} |
208 | 246 |
} |
209 | 247 |
|
src/main/res/layout/settings.xml | ||
---|---|---|
172 | 172 |
</LinearLayout> |
173 | 173 |
</LinearLayout> |
174 | 174 |
|
175 |
<TextView |
|
176 |
android:layout_width="fill_parent" |
|
177 |
android:layout_height="48dp" |
|
178 |
android:paddingStart="15dp" |
|
179 |
android:paddingEnd="15dp" |
|
180 |
android:gravity="start|center" |
|
181 |
android:text="@string/scramble_effect" |
|
182 |
android:textAppearance="?android:attr/textAppearanceMedium" /> |
|
183 |
|
|
184 |
<LinearLayout |
|
185 |
android:layout_width="fill_parent" |
|
186 |
android:layout_height="fill_parent" |
|
187 |
android:layout_weight="0.5" |
|
188 |
android:gravity="center|fill_horizontal" |
|
189 |
android:layout_marginLeft="10dp" |
|
190 |
android:layout_marginRight="10dp" |
|
191 |
android:background="@color/grey" |
|
192 |
android:orientation="vertical"> |
|
193 |
|
|
194 |
<LinearLayout |
|
195 |
android:layout_width="fill_parent" |
|
196 |
android:layout_height="36dp" |
|
197 |
android:gravity="center|fill_horizontal" |
|
198 |
android:orientation="horizontal"> |
|
199 |
|
|
200 |
<TextView |
|
201 |
android:layout_weight="0.2" |
|
202 |
android:layout_width="0dp" |
|
203 |
android:layout_height="fill_parent" |
|
204 |
android:paddingStart="5dp" |
|
205 |
android:paddingEnd="5dp" |
|
206 |
android:gravity="start|center" |
|
207 |
android:text="@string/duration" |
|
208 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
209 |
|
|
210 |
<TextView |
|
211 |
android:id="@+id/scrambleDurationText" |
|
212 |
android:layout_weight="0.2" |
|
213 |
android:layout_width="0dp" |
|
214 |
android:layout_height="fill_parent" |
|
215 |
android:paddingStart="5dp" |
|
216 |
android:paddingEnd="5dp" |
|
217 |
android:gravity="end|center" |
|
218 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
219 |
|
|
220 |
<SeekBar |
|
221 |
android:id="@+id/scrambleDuration" |
|
222 |
android:layout_weight="0.6" |
|
223 |
android:layout_width="0dp" |
|
224 |
android:layout_height="fill_parent" |
|
225 |
android:paddingLeft="10dp" |
|
226 |
android:paddingRight="10dp" /> |
|
227 |
|
|
228 |
</LinearLayout> |
|
229 |
|
|
230 |
<LinearLayout |
|
231 |
android:layout_width="fill_parent" |
|
232 |
android:layout_height="36dp" |
|
233 |
android:gravity="center|fill_horizontal" |
|
234 |
android:orientation="horizontal"> |
|
235 |
|
|
236 |
<TextView |
|
237 |
android:layout_weight="0.4" |
|
238 |
android:layout_width="0dp" |
|
239 |
android:layout_height="fill_parent" |
|
240 |
android:paddingStart="5dp" |
|
241 |
android:paddingEnd="5dp" |
|
242 |
android:gravity="start|center" |
|
243 |
android:text="@string/type" |
|
244 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
|
245 |
|
|
246 |
<Spinner |
|
247 |
android:id="@+id/scrambleType" |
|
248 |
android:layout_weight="0.6" |
|
249 |
android:layout_width="0dp" |
|
250 |
android:layout_height="fill_parent" |
|
251 |
android:textAlignment="center" |
|
252 |
android:paddingLeft="10dp" |
|
253 |
android:paddingRight="10dp" /> |
|
254 |
|
|
255 |
</LinearLayout> |
|
256 |
</LinearLayout> |
|
175 | 257 |
</LinearLayout> |
src/main/res/values/strings.xml | ||
---|---|---|
10 | 10 |
<string name="ok">OK</string> |
11 | 11 |
<string name="sizechange_effect">Cube Size Change Effect:</string> |
12 | 12 |
<string name="unscramble_effect">Cube Unscramble Effect:</string> |
13 |
<string name="scramble_effect">Cube Scramble Effect:</string> |
|
13 | 14 |
<string name="duration">Duration:</string> |
14 | 15 |
<string name="type">Type:</string> |
15 | 16 |
<string name="credits1">Open Source app developed using the Distorted graphics library. </string> |
Also available in: Unified diff
Add a skeleton of ScrambleEffects