Revision 2ecf0c21
Added by Leszek Koltunski almost 5 years ago
src/main/java/org/distorted/effect/ScrambleEffect.java | ||
---|---|---|
173 | 173 |
mNumScramblesLeft--; |
174 | 174 |
if( absAngle==2 ) mNumDoubleScramblesLeft--; |
175 | 175 |
|
176 |
if( mNumScramblesLeft==0 && mNumDoubleScramblesLeft!=0 ) |
|
177 |
{ |
|
178 |
android.util.Log.e("effect", "ERROR: "+mNumDoubleScramblesLeft); |
|
179 |
} |
|
180 |
|
|
176 | 181 |
mCurrentBaseEffectID = mCube.addNewRotation(mLastVector, row, angle*90, durationMillis, this ); |
177 | 182 |
} |
178 | 183 |
else |
... | ... | |
182 | 187 |
} |
183 | 188 |
|
184 | 189 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
185 |
// TODO; |
|
186 | 190 |
|
187 | 191 |
private int randomizeAngle() |
188 | 192 |
{ |
189 |
return 1; |
|
193 |
int random = mRnd.nextInt(mNumScramblesLeft); |
|
194 |
int result = random<mNumDoubleScramblesLeft ? 2:1; |
|
195 |
int sign = mRnd.nextInt(2); |
|
196 |
|
|
197 |
return sign==0 ? result : -result; |
|
190 | 198 |
} |
191 | 199 |
|
192 | 200 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/effect/SolveEffect.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.main.DistortedEffects; |
|
26 |
import org.distorted.library.main.DistortedScreen; |
|
27 |
import org.distorted.library.message.EffectListener; |
|
28 |
import org.distorted.magic.RubikCube; |
|
29 |
|
|
30 |
import java.lang.reflect.Method; |
|
31 |
|
|
32 |
public abstract class SolveEffect implements EffectListener |
|
33 |
{ |
|
34 |
public enum Type |
|
35 |
{ |
|
36 |
NONE (SolveEffectNone.class), |
|
37 |
SPIN (SolveEffectSpin.class), |
|
38 |
; |
|
39 |
|
|
40 |
final Class<? extends SolveEffect> effect; |
|
41 |
|
|
42 |
Type(Class<? extends SolveEffect> effect) |
|
43 |
{ |
|
44 |
this.effect = effect; |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
private static final int NUM_EFFECTS = Type.values().length; |
|
49 |
private static final int NUM_PHASES = 2; |
|
50 |
private static final int FAKE_EFFECT_ID = -2; |
|
51 |
private static final Type[] types; |
|
52 |
|
|
53 |
static |
|
54 |
{ |
|
55 |
int i=0; |
|
56 |
types = new Type[NUM_EFFECTS]; |
|
57 |
|
|
58 |
for(Type type: Type.values()) |
|
59 |
{ |
|
60 |
types[i++] = type; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
private EffectListener mListener; |
|
65 |
private int mDuration; |
|
66 |
private int mEffectReturned; |
|
67 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
68 |
private int mPhase; |
|
69 |
|
|
70 |
RubikCube mCube; |
|
71 |
DistortedScreen mScreen; |
|
72 |
Effect[][] mCubeEffects; |
|
73 |
int[][] mCubeEffectPosition; |
|
74 |
Effect[][] mNodeEffects; |
|
75 |
int[][] mNodeEffectPosition; |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
SolveEffect() |
|
80 |
{ |
|
81 |
mPhase = 0; |
|
82 |
|
|
83 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
84 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
85 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
86 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
87 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
88 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
public static Type getType(int ordinal) |
|
94 |
{ |
|
95 |
return types[ordinal]; |
|
96 |
} |
|
97 |
|
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
public static String[] getNames() |
|
101 |
{ |
|
102 |
String[] names = new String[NUM_EFFECTS]; |
|
103 |
|
|
104 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
105 |
{ |
|
106 |
names[i] = types[i].name(); |
|
107 |
} |
|
108 |
|
|
109 |
return names; |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
|
|
114 |
public static SolveEffect create(Type type) throws InstantiationException, IllegalAccessException |
|
115 |
{ |
|
116 |
return type.effect.newInstance(); |
|
117 |
} |
|
118 |
|
|
119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
|
|
121 |
abstract void createEffectsPhase0(int duration); |
|
122 |
abstract void createEffectsPhase1(int duration); |
|
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
|
126 |
public void effectFinished(final long effectID) |
|
127 |
{ |
|
128 |
int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase]; |
|
129 |
|
|
130 |
for(int i=0; i<mCubeEffectNumber[mPhase]; i++) |
|
131 |
{ |
|
132 |
long id = mCubeEffects[mPhase][i].getID(); |
|
133 |
|
|
134 |
if( effectID == id ) |
|
135 |
{ |
|
136 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
137 |
mCube.remove(id); |
|
138 |
return; |
|
139 |
} |
|
140 |
} |
|
141 |
for(int i=0; i<mNodeEffectNumber[mPhase]; i++) |
|
142 |
{ |
|
143 |
long id = mNodeEffects[mPhase][i].getID(); |
|
144 |
|
|
145 |
if( effectID == id ) |
|
146 |
{ |
|
147 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
148 |
mCube.getEffects().abortById(id); |
|
149 |
return; |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 |
|
|
156 |
private void effectAction(int phase) |
|
157 |
{ |
|
158 |
switch(phase) |
|
159 |
{ |
|
160 |
case 0: mEffectReturned = 0; |
|
161 |
mPhase = 1; |
|
162 |
mCube.solve(); |
|
163 |
createEffectsPhase1(mDuration); |
|
164 |
assignEffects(mPhase); |
|
165 |
break; |
|
166 |
case 1: mListener.effectFinished(FAKE_EFFECT_ID); |
|
167 |
break; |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener) |
|
174 |
{ |
|
175 |
mScreen = screen; |
|
176 |
mCube = cube; |
|
177 |
mListener = listener; |
|
178 |
mDuration = duration; |
|
179 |
|
|
180 |
createEffectsPhase0(mDuration); |
|
181 |
assignEffects(mPhase); |
|
182 |
|
|
183 |
return FAKE_EFFECT_ID; |
|
184 |
} |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
private void assignEffects(int phase) |
|
189 |
{ |
|
190 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0; |
|
191 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0; |
|
192 |
|
|
193 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 ) |
|
194 |
{ |
|
195 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!"); |
|
196 |
} |
|
197 |
|
|
198 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
199 |
{ |
|
200 |
mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]); |
|
201 |
mCubeEffects[phase][i].notifyWhenFinished(this); |
|
202 |
} |
|
203 |
|
|
204 |
DistortedEffects nodeEffects = mCube.getEffects(); |
|
205 |
|
|
206 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
207 |
{ |
|
208 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]); |
|
209 |
mNodeEffects[phase][i].notifyWhenFinished(this); |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
@SuppressWarnings("unused") |
|
216 |
public static void enableEffects() |
|
217 |
{ |
|
218 |
Method method; |
|
219 |
|
|
220 |
for(Type type: Type.values()) |
|
221 |
{ |
|
222 |
try |
|
223 |
{ |
|
224 |
method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod |
|
225 |
} |
|
226 |
catch(NoSuchMethodException ex) |
|
227 |
{ |
|
228 |
android.util.Log.e("SolveEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage()); |
|
229 |
method = null; |
|
230 |
} |
|
231 |
|
|
232 |
try |
|
233 |
{ |
|
234 |
if( method!=null ) method.invoke(null); |
|
235 |
} |
|
236 |
catch(Exception ex) |
|
237 |
{ |
|
238 |
android.util.Log.e("SolveEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage()); |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
} |
src/main/java/org/distorted/effect/SolveEffectNone.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 SolveEffectNone extends SolveEffect |
|
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/effect/SolveEffectSpin.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.MatrixEffectRotate; |
|
26 |
import org.distorted.library.type.Dynamic; |
|
27 |
import org.distorted.library.type.Dynamic1D; |
|
28 |
import org.distorted.library.type.Static1D; |
|
29 |
import org.distorted.library.type.Static3D; |
|
30 |
|
|
31 |
public class SolveEffectSpin extends SolveEffect |
|
32 |
{ |
|
33 |
public void createEffectsPhase0(int duration) |
|
34 |
{ |
|
35 |
mCubeEffectPosition[0] = new int[] {3}; |
|
36 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
37 |
|
|
38 |
Static3D axis = new Static3D(1,0,0); |
|
39 |
Static3D center= new Static3D(0,0,0); |
|
40 |
|
|
41 |
Dynamic1D d0 = new Dynamic1D(duration/2, 1.0f); |
|
42 |
d0.setMode(Dynamic.MODE_JUMP); |
|
43 |
d0.setConvexity(0.0f); // otherwise speed of the rotation would be strangely uneven |
|
44 |
d0.add(new Static1D( 0*36)); |
|
45 |
d0.add(new Static1D( 1*36)); |
|
46 |
d0.add(new Static1D( 3*36)); |
|
47 |
d0.add(new Static1D( 6*36)); |
|
48 |
d0.add(new Static1D(10*36)); |
|
49 |
mCubeEffects[0][0] = new MatrixEffectRotate(d0,axis,center); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public void createEffectsPhase1(int duration) |
|
55 |
{ |
|
56 |
mCubeEffectPosition[1] = new int[] {3}; |
|
57 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
58 |
|
|
59 |
Static3D axis = new Static3D(1,0,0); |
|
60 |
Static3D center= new Static3D(0,0,0); |
|
61 |
|
|
62 |
Dynamic1D d1 = new Dynamic1D(duration/2, 1.0f); |
|
63 |
d1.setMode(Dynamic.MODE_JUMP); |
|
64 |
d1.setConvexity(0.0f); |
|
65 |
d1.add(new Static1D( 0*36)); |
|
66 |
d1.add(new Static1D( 4*36)); |
|
67 |
d1.add(new Static1D( 7*36)); |
|
68 |
d1.add(new Static1D( 9*36)); |
|
69 |
d1.add(new Static1D(10*36)); |
|
70 |
mCubeEffects[1][0] = new MatrixEffectRotate(d1,axis,center); |
|
71 |
} |
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
75 |
|
|
76 |
@SuppressWarnings("unused") |
|
77 |
static void enable() |
|
78 |
{ |
|
79 |
|
|
80 |
} |
|
81 |
} |
src/main/java/org/distorted/effect/UnscrambleEffect.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.main.DistortedEffects; |
|
26 |
import org.distorted.library.main.DistortedScreen; |
|
27 |
import org.distorted.library.message.EffectListener; |
|
28 |
import org.distorted.magic.RubikCube; |
|
29 |
|
|
30 |
import java.lang.reflect.Method; |
|
31 |
|
|
32 |
public abstract class UnscrambleEffect implements EffectListener |
|
33 |
{ |
|
34 |
public enum Type |
|
35 |
{ |
|
36 |
NONE (UnscrambleEffectNone.class), |
|
37 |
SPIN (UnscrambleEffectSpin.class), |
|
38 |
; |
|
39 |
|
|
40 |
final Class<? extends UnscrambleEffect> effect; |
|
41 |
|
|
42 |
Type(Class<? extends UnscrambleEffect> effect) |
|
43 |
{ |
|
44 |
this.effect = effect; |
|
45 |
} |
|
46 |
} |
|
47 |
|
|
48 |
private static final int NUM_EFFECTS = Type.values().length; |
|
49 |
private static final int NUM_PHASES = 2; |
|
50 |
private static final int FAKE_EFFECT_ID = -2; |
|
51 |
private static final Type[] types; |
|
52 |
|
|
53 |
static |
|
54 |
{ |
|
55 |
int i=0; |
|
56 |
types = new Type[NUM_EFFECTS]; |
|
57 |
|
|
58 |
for(Type type: Type.values()) |
|
59 |
{ |
|
60 |
types[i++] = type; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
private EffectListener mListener; |
|
65 |
private int mDuration; |
|
66 |
private int mEffectReturned; |
|
67 |
private int[] mCubeEffectNumber, mNodeEffectNumber; |
|
68 |
private int mPhase; |
|
69 |
|
|
70 |
RubikCube mCube; |
|
71 |
DistortedScreen mScreen; |
|
72 |
Effect[][] mCubeEffects; |
|
73 |
int[][] mCubeEffectPosition; |
|
74 |
Effect[][] mNodeEffects; |
|
75 |
int[][] mNodeEffectPosition; |
|
76 |
|
|
77 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
78 |
|
|
79 |
UnscrambleEffect() |
|
80 |
{ |
|
81 |
mPhase = 0; |
|
82 |
|
|
83 |
mCubeEffectNumber = new int[NUM_PHASES]; |
|
84 |
mNodeEffectNumber = new int[NUM_PHASES]; |
|
85 |
mCubeEffectPosition = new int[NUM_PHASES][]; |
|
86 |
mNodeEffectPosition = new int[NUM_PHASES][]; |
|
87 |
mCubeEffects = new Effect[NUM_PHASES][]; |
|
88 |
mNodeEffects = new Effect[NUM_PHASES][]; |
|
89 |
} |
|
90 |
|
|
91 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
92 |
|
|
93 |
public static Type getType(int ordinal) |
|
94 |
{ |
|
95 |
return types[ordinal]; |
|
96 |
} |
|
97 |
|
|
98 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
99 |
|
|
100 |
public static String[] getNames() |
|
101 |
{ |
|
102 |
String[] names = new String[NUM_EFFECTS]; |
|
103 |
|
|
104 |
for( int i=0; i<NUM_EFFECTS; i++) |
|
105 |
{ |
|
106 |
names[i] = types[i].name(); |
|
107 |
} |
|
108 |
|
|
109 |
return names; |
|
110 |
} |
|
111 |
|
|
112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
113 |
|
|
114 |
public static UnscrambleEffect create(Type type) throws InstantiationException, IllegalAccessException |
|
115 |
{ |
|
116 |
return type.effect.newInstance(); |
|
117 |
} |
|
118 |
|
|
119 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
120 |
|
|
121 |
abstract void createEffectsPhase0(int duration); |
|
122 |
abstract void createEffectsPhase1(int duration); |
|
123 |
|
|
124 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
125 |
|
|
126 |
public void effectFinished(final long effectID) |
|
127 |
{ |
|
128 |
int total = mCubeEffectNumber[mPhase]+mNodeEffectNumber[mPhase]; |
|
129 |
|
|
130 |
for(int i=0; i<mCubeEffectNumber[mPhase]; i++) |
|
131 |
{ |
|
132 |
long id = mCubeEffects[mPhase][i].getID(); |
|
133 |
|
|
134 |
if( effectID == id ) |
|
135 |
{ |
|
136 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
137 |
mCube.remove(id); |
|
138 |
return; |
|
139 |
} |
|
140 |
} |
|
141 |
for(int i=0; i<mNodeEffectNumber[mPhase]; i++) |
|
142 |
{ |
|
143 |
long id = mNodeEffects[mPhase][i].getID(); |
|
144 |
|
|
145 |
if( effectID == id ) |
|
146 |
{ |
|
147 |
if( ++mEffectReturned == total ) effectAction(mPhase); |
|
148 |
mCube.getEffects().abortById(id); |
|
149 |
return; |
|
150 |
} |
|
151 |
} |
|
152 |
} |
|
153 |
|
|
154 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
155 |
|
|
156 |
private void effectAction(int phase) |
|
157 |
{ |
|
158 |
switch(phase) |
|
159 |
{ |
|
160 |
case 0: mEffectReturned = 0; |
|
161 |
mPhase = 1; |
|
162 |
mCube.unscramble(); |
|
163 |
createEffectsPhase1(mDuration); |
|
164 |
assignEffects(mPhase); |
|
165 |
break; |
|
166 |
case 1: mListener.effectFinished(FAKE_EFFECT_ID); |
|
167 |
break; |
|
168 |
} |
|
169 |
} |
|
170 |
|
|
171 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
172 |
|
|
173 |
public long start(int duration, DistortedScreen screen, RubikCube cube, EffectListener listener) |
|
174 |
{ |
|
175 |
mScreen = screen; |
|
176 |
mCube = cube; |
|
177 |
mListener = listener; |
|
178 |
mDuration = duration; |
|
179 |
|
|
180 |
createEffectsPhase0(mDuration); |
|
181 |
assignEffects(mPhase); |
|
182 |
|
|
183 |
return FAKE_EFFECT_ID; |
|
184 |
} |
|
185 |
|
|
186 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
187 |
|
|
188 |
private void assignEffects(int phase) |
|
189 |
{ |
|
190 |
mCubeEffectNumber[phase] = ( mCubeEffects[phase]!=null ) ? mCubeEffects[phase].length : 0; |
|
191 |
mNodeEffectNumber[phase] = ( mNodeEffects[phase]!=null ) ? mNodeEffects[phase].length : 0; |
|
192 |
|
|
193 |
if( mCubeEffectNumber[phase]==0 && mNodeEffectNumber[phase]==0 ) |
|
194 |
{ |
|
195 |
throw new RuntimeException("Cube and Node Effects ("+phase+" phase) both not created!"); |
|
196 |
} |
|
197 |
|
|
198 |
for(int i=0; i<mCubeEffectNumber[phase]; i++) |
|
199 |
{ |
|
200 |
mCube.apply(mCubeEffects[phase][i],mCubeEffectPosition[phase][i]); |
|
201 |
mCubeEffects[phase][i].notifyWhenFinished(this); |
|
202 |
} |
|
203 |
|
|
204 |
DistortedEffects nodeEffects = mCube.getEffects(); |
|
205 |
|
|
206 |
for(int i=0; i<mNodeEffectNumber[phase]; i++) |
|
207 |
{ |
|
208 |
nodeEffects.apply(mNodeEffects[phase][i],mNodeEffectPosition[phase][i]); |
|
209 |
mNodeEffects[phase][i].notifyWhenFinished(this); |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
214 |
|
|
215 |
@SuppressWarnings("unused") |
|
216 |
public static void enableEffects() |
|
217 |
{ |
|
218 |
Method method; |
|
219 |
|
|
220 |
for(Type type: Type.values()) |
|
221 |
{ |
|
222 |
try |
|
223 |
{ |
|
224 |
method = type.effect.getDeclaredMethod("enable"); // enable not public, thus getDeclaredMethod |
|
225 |
} |
|
226 |
catch(NoSuchMethodException ex) |
|
227 |
{ |
|
228 |
android.util.Log.e("UnscrambleEffect", type.effect.getSimpleName()+": exception getting method: "+ex.getMessage()); |
|
229 |
method = null; |
|
230 |
} |
|
231 |
|
|
232 |
try |
|
233 |
{ |
|
234 |
if( method!=null ) method.invoke(null); |
|
235 |
} |
|
236 |
catch(Exception ex) |
|
237 |
{ |
|
238 |
android.util.Log.e("UnscrambleEffect", type.effect.getSimpleName()+": exception invoking method: "+ex.getMessage()); |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
} |
src/main/java/org/distorted/effect/UnscrambleEffectNone.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 UnscrambleEffectNone extends UnscrambleEffect |
|
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/effect/UnscrambleEffectSpin.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.MatrixEffectRotate; |
|
26 |
import org.distorted.library.type.Dynamic; |
|
27 |
import org.distorted.library.type.Dynamic1D; |
|
28 |
import org.distorted.library.type.Static1D; |
|
29 |
import org.distorted.library.type.Static3D; |
|
30 |
|
|
31 |
public class UnscrambleEffectSpin extends UnscrambleEffect |
|
32 |
{ |
|
33 |
public void createEffectsPhase0(int duration) |
|
34 |
{ |
|
35 |
mCubeEffectPosition[0] = new int[] {3}; |
|
36 |
mCubeEffects[0] = new Effect[mCubeEffectPosition[0].length]; |
|
37 |
|
|
38 |
Static3D axis = new Static3D(1,0,0); |
|
39 |
Static3D center= new Static3D(0,0,0); |
|
40 |
|
|
41 |
Dynamic1D d0 = new Dynamic1D(duration/2, 1.0f); |
|
42 |
d0.setMode(Dynamic.MODE_JUMP); |
|
43 |
d0.setConvexity(0.0f); // otherwise speed of the rotation would be strangely uneven |
|
44 |
d0.add(new Static1D( 0*36)); |
|
45 |
d0.add(new Static1D( 1*36)); |
|
46 |
d0.add(new Static1D( 3*36)); |
|
47 |
d0.add(new Static1D( 6*36)); |
|
48 |
d0.add(new Static1D(10*36)); |
|
49 |
mCubeEffects[0][0] = new MatrixEffectRotate(d0,axis,center); |
|
50 |
} |
|
51 |
|
|
52 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
53 |
|
|
54 |
public void createEffectsPhase1(int duration) |
|
55 |
{ |
|
56 |
mCubeEffectPosition[1] = new int[] {3}; |
|
57 |
mCubeEffects[1] = new Effect[mCubeEffectPosition[1].length]; |
|
58 |
|
|
59 |
Static3D axis = new Static3D(1,0,0); |
|
60 |
Static3D center= new Static3D(0,0,0); |
|
61 |
|
|
62 |
Dynamic1D d1 = new Dynamic1D(duration/2, 1.0f); |
|
63 |
d1.setMode(Dynamic.MODE_JUMP); |
|
64 |
d1.setConvexity(0.0f); |
|
65 |
d1.add(new Static1D( 0*36)); |
|
66 |
d1.add(new Static1D( 4*36)); |
|
67 |
d1.add(new Static1D( 7*36)); |
|
68 |
d1.add(new Static1D( 9*36)); |
|
69 |
d1.add(new Static1D(10*36)); |
|
70 |
mCubeEffects[1][0] = new MatrixEffectRotate(d1,axis,center); |
|
71 |
} |
|
72 |
|
|
73 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
74 |
// Enable all effects used in this Effect. Called by reflection from the parent class. |
|
75 |
|
|
76 |
@SuppressWarnings("unused") |
|
77 |
static void enable() |
|
78 |
{ |
|
79 |
|
|
80 |
} |
|
81 |
} |
src/main/java/org/distorted/magic/RubikActivity.java | ||
---|---|---|
32 | 32 |
import org.distorted.component.HorizontalNumberPicker; |
33 | 33 |
import org.distorted.effect.ScrambleEffect; |
34 | 34 |
import org.distorted.effect.SizeChangeEffect; |
35 |
import org.distorted.effect.UnscrambleEffect;
|
|
35 |
import org.distorted.effect.SolveEffect;
|
|
36 | 36 |
import org.distorted.library.main.DistortedLibrary; |
37 | 37 |
|
38 | 38 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
44 | 44 |
private static final int[] button_ids = {R.id.rubikSize2, R.id.rubikSize3, R.id.rubikSize4}; |
45 | 45 |
|
46 | 46 |
public static final int DEFAULT_SIZECHANGE_POS = 20; |
47 |
public static final int DEFAULT_UNSCRAMBLE_POS = 20;
|
|
47 |
public static final int DEFAULT_SOLVE_POS = 20;
|
|
48 | 48 |
public static final int DEFAULT_SCRAMBLE_POS =100; |
49 | 49 |
public static final int DEFAULT_SIZECHANGE_TYPE= 1; |
50 |
public static final int DEFAULT_UNSCRAMBLE_TYPE= 1;
|
|
50 |
public static final int DEFAULT_SOLVE_TYPE = 1;
|
|
51 | 51 |
public static final int DEFAULT_SCRAMBLE_TYPE = 0; |
52 | 52 |
|
53 | 53 |
public static final int MIN_SCRAMBLE = 1; |
... | ... | |
55 | 55 |
|
56 | 56 |
private static int mSize = DEFAULT_SIZE; |
57 | 57 |
|
58 |
private int mSizeChangePos, mUnscramblePos, mScramblePos;
|
|
59 |
private int mSizeChangeType, mUnscrambleType, mScrambleType;
|
|
58 |
private int mSizeChangePos, mSolvePos, mScramblePos;
|
|
59 |
private int mSizeChangeType, mSolveType, mScrambleType;
|
|
60 | 60 |
|
61 | 61 |
private HorizontalNumberPicker mPicker; |
62 | 62 |
|
... | ... | |
123 | 123 |
Bundle args = new Bundle(); |
124 | 124 |
|
125 | 125 |
args.putInt("sizechangePos" , mSizeChangePos ); |
126 |
args.putInt("unscramblePos" , mUnscramblePos );
|
|
126 |
args.putInt("solvePos" , mSolvePos );
|
|
127 | 127 |
args.putInt("scramblePos" , mScramblePos ); |
128 | 128 |
args.putInt("sizechangeType", mSizeChangeType); |
129 |
args.putInt("unscrambleType", mUnscrambleType);
|
|
129 |
args.putInt("solveType" , mSolveType );
|
|
130 | 130 |
args.putInt("scrambleType" , mScrambleType ); |
131 | 131 |
|
132 | 132 |
RubikSettings settings = new RubikSettings(); |
... | ... | |
154 | 154 |
|
155 | 155 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
156 | 156 |
|
157 |
public void Unscramble(View v)
|
|
157 |
public void Solve(View v)
|
|
158 | 158 |
{ |
159 | 159 |
RubikSurfaceView view = findViewById(R.id.rubikSurfaceView); |
160 |
view.getRenderer().unscrambleCube();
|
|
160 |
view.getRenderer().solveCube();
|
|
161 | 161 |
} |
162 | 162 |
|
163 | 163 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
165 | 165 |
public void onComplete(int sizeP, int unscP, int scraP, int sizeT, int unscT, int scraT ) |
166 | 166 |
{ |
167 | 167 |
mSizeChangePos = sizeP; |
168 |
mUnscramblePos = unscP;
|
|
168 |
mSolvePos = unscP;
|
|
169 | 169 |
mScramblePos = scraP; |
170 | 170 |
mSizeChangeType= sizeT; |
171 |
mUnscrambleType= unscT;
|
|
171 |
mSolveType = unscT;
|
|
172 | 172 |
mScrambleType = scraT; |
173 | 173 |
|
174 | 174 |
applyPreferences(); |
... | ... | |
225 | 225 |
SharedPreferences.Editor editor = preferences.edit(); |
226 | 226 |
|
227 | 227 |
editor.putInt("sizechangePos" , mSizeChangePos ); |
228 |
editor.putInt("unscramblePos" , mUnscramblePos );
|
|
228 |
editor.putInt("solvePos" , mSolvePos );
|
|
229 | 229 |
editor.putInt("scramblePos" , mScramblePos ); |
230 | 230 |
editor.putInt("sizechangeType", mSizeChangeType); |
231 |
editor.putInt("unscrambleType", mUnscrambleType);
|
|
231 |
editor.putInt("solveType" , mSolveType );
|
|
232 | 232 |
editor.putInt("scrambleType" , mScrambleType ); |
233 | 233 |
editor.putInt("scramble" , mPicker.getValue() ); |
234 | 234 |
|
... | ... | |
242 | 242 |
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this); |
243 | 243 |
|
244 | 244 |
mSizeChangePos = preferences.getInt("sizechangePos" , DEFAULT_SIZECHANGE_POS ); |
245 |
mUnscramblePos = preferences.getInt("unscramblePos" , DEFAULT_UNSCRAMBLE_POS );
|
|
245 |
mSolvePos = preferences.getInt("solvePos" , DEFAULT_SOLVE_POS );
|
|
246 | 246 |
mScramblePos = preferences.getInt("scramblePos" , DEFAULT_SCRAMBLE_POS ); |
247 | 247 |
mSizeChangeType= preferences.getInt("sizechangeType", DEFAULT_SIZECHANGE_TYPE); |
248 |
mUnscrambleType= preferences.getInt("unscrambleType", DEFAULT_UNSCRAMBLE_TYPE);
|
|
248 |
mSolveType = preferences.getInt("solveType" , DEFAULT_SOLVE_TYPE );
|
|
249 | 249 |
mScrambleType = preferences.getInt("scrambleType" , DEFAULT_SCRAMBLE_TYPE ); |
250 | 250 |
int scramble = preferences.getInt("scramble" , MIN_SCRAMBLE ); |
251 | 251 |
|
... | ... | |
260 | 260 |
RubikRenderer renderer = view.getRenderer(); |
261 | 261 |
|
262 | 262 |
renderer.setSizeChangeDuration(translateDuration(mSizeChangePos)+1); |
263 |
renderer.setUnscrambleDuration(translateDuration(mUnscramblePos)+1);
|
|
263 |
renderer.setSolveDuration(translateDuration(mSolvePos)+1);
|
|
264 | 264 |
renderer.setScrambleDuration(translateDuration(mScramblePos)+1); |
265 | 265 |
renderer.setSizeChangeType(SizeChangeEffect.getType(mSizeChangeType)); |
266 |
renderer.setUnscrambleType(UnscrambleEffect.getType(mUnscrambleType));
|
|
266 |
renderer.setSolveType(SolveEffect.getType(mSolveType));
|
|
267 | 267 |
renderer.setScrambleType(ScrambleEffect.getType(mScrambleType)); |
268 | 268 |
} |
269 | 269 |
|
src/main/java/org/distorted/magic/RubikCube.java | ||
---|---|---|
217 | 217 |
|
218 | 218 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
219 | 219 |
|
220 |
public void unscramble()
|
|
220 |
public void solve()
|
|
221 | 221 |
{ |
222 | 222 |
for(int x=0; x<mSize; x++) |
223 | 223 |
for(int y=0; y<mSize; y++) |
src/main/java/org/distorted/magic/RubikRenderer.java | ||
---|---|---|
22 | 22 |
import android.opengl.GLSurfaceView; |
23 | 23 |
|
24 | 24 |
import org.distorted.effect.SizeChangeEffect; |
25 |
import org.distorted.effect.UnscrambleEffect;
|
|
25 |
import org.distorted.effect.SolveEffect;
|
|
26 | 26 |
import org.distorted.effect.ScrambleEffect; |
27 | 27 |
import org.distorted.library.effect.VertexEffectSink; |
28 | 28 |
import org.distorted.library.main.DistortedEffects; |
... | ... | |
50 | 50 |
private Static4D mTempCurrent, mTempAccumulated; |
51 | 51 |
private float mCubeSizeInScreenSpace; |
52 | 52 |
private int mNextCubeSize, mScrambleCubeNum; |
53 |
private long mRotationFinishedID, mSizeChangeEffectID, mUnscrambleEffectID, mScrambleEffectID;
|
|
53 |
private long mRotationFinishedID, mSizeChangeEffectID, mSolveEffectID, mScrambleEffectID;
|
|
54 | 54 |
private boolean mFinishRotation, mRemoveRotation, mFinishDragCurrent, mFinishDragAccumulated, mSolveCube, mScrambleCube; |
55 |
private boolean mCanRotate, mCanDrag; |
|
55 |
private boolean mCanRotate, mCanDrag, mCanScramble, mCanSolve;
|
|
56 | 56 |
private RubikCube mOldCube, mNewCube; |
57 | 57 |
private int mScreenWidth, mScreenHeight; |
58 | 58 |
private MeshFlat mMesh; |
59 | 59 |
private SizeChangeEffect.Type mSizeChangeType; |
60 |
private UnscrambleEffect.Type mUnscrambleType;
|
|
60 |
private SolveEffect.Type mSolveType;
|
|
61 | 61 |
private ScrambleEffect.Type mScrambleType; |
62 |
private int mSizeChangeDuration, mUnscrambleDuration, mScrambleDuration;
|
|
62 |
private int mSizeChangeDuration, mSolveDuration, mScrambleDuration;
|
|
63 | 63 |
|
64 | 64 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
65 | 65 |
|
... | ... | |
87 | 87 |
mSolveCube = false; |
88 | 88 |
mScrambleCube = false; |
89 | 89 |
|
90 |
mCanRotate = true; |
|
91 |
mCanDrag = true; |
|
90 |
mCanRotate = true; |
|
91 |
mCanDrag = true; |
|
92 |
mCanScramble = true; |
|
93 |
mCanSolve = true; |
|
92 | 94 |
|
93 |
mSizeChangeType = SizeChangeEffect.Type.TRANSPARENCY;
|
|
94 |
mUnscrambleType = UnscrambleEffect.Type.SPIN;
|
|
95 |
mScrambleType = ScrambleEffect.Type.NONE;
|
|
95 |
mSizeChangeType= SizeChangeEffect.Type.TRANSPARENCY; |
|
96 |
mSolveType = SolveEffect.Type.SPIN;
|
|
97 |
mScrambleType = ScrambleEffect.Type.NONE; |
|
96 | 98 |
|
97 | 99 |
mSizeChangeDuration= 1000; |
98 |
mUnscrambleDuration= 1000;
|
|
100 |
mSolveDuration = 1000;
|
|
99 | 101 |
mScrambleDuration = 1000; |
100 | 102 |
|
101 | 103 |
mMesh= new MeshFlat(20,20); |
... | ... | |
150 | 152 |
|
151 | 153 |
if( mSolveCube ) |
152 | 154 |
{ |
153 |
mSolveCube = false; |
|
154 |
mCanDrag = false; |
|
155 |
mCanRotate = false; |
|
156 |
unscrambleCubeNow(); |
|
155 |
mSolveCube = false; |
|
156 |
mCanDrag = false; |
|
157 |
mCanRotate = false; |
|
158 |
mCanScramble = false; |
|
159 |
mCanSolve = false; |
|
160 |
solveCubeNow(); |
|
157 | 161 |
} |
158 | 162 |
|
159 | 163 |
if( mScrambleCube ) |
... | ... | |
161 | 165 |
mScrambleCube = false; |
162 | 166 |
mCanDrag = false; |
163 | 167 |
mCanRotate = false; |
168 |
mCanScramble = false; |
|
169 |
mCanSolve = false; |
|
164 | 170 |
scrambleCubeNow(); |
165 | 171 |
} |
166 | 172 |
} |
... | ... | |
194 | 200 |
VertexEffectSink.enable(); |
195 | 201 |
SizeChangeEffect.enableEffects(); |
196 | 202 |
ScrambleEffect.enableEffects(); |
197 |
UnscrambleEffect.enableEffects();
|
|
203 |
SolveEffect.enableEffects();
|
|
198 | 204 |
|
199 | 205 |
try |
200 | 206 |
{ |
... | ... | |
210 | 216 |
|
211 | 217 |
public void effectFinished(final long effectID) |
212 | 218 |
{ |
213 |
if( effectID == mRotationFinishedID )
|
|
219 |
if( effectID == mRotationFinishedID ) |
|
214 | 220 |
{ |
215 | 221 |
mRemoveRotation = true; |
216 | 222 |
} |
217 |
else if( effectID == mSizeChangeEffectID )
|
|
223 |
else if( effectID == mSizeChangeEffectID ) |
|
218 | 224 |
{ |
219 |
mCanRotate = true; |
|
220 |
mCanDrag = true; |
|
225 |
mCanRotate = true;
|
|
226 |
mCanDrag = true;
|
|
221 | 227 |
} |
222 |
else if( effectID == mUnscrambleEffectID )
|
|
228 |
else if( effectID == mSolveEffectID )
|
|
223 | 229 |
{ |
224 |
mCanRotate = true; |
|
225 |
mCanDrag = true; |
|
230 |
mCanRotate = true; |
|
231 |
mCanDrag = true; |
|
232 |
mCanSolve = true; |
|
233 |
mCanScramble = true; |
|
226 | 234 |
} |
227 |
else if( effectID == mScrambleEffectID )
|
|
235 |
else if( effectID == mScrambleEffectID ) |
|
228 | 236 |
{ |
229 |
mCanRotate = true; |
|
230 |
mCanDrag = true; |
|
237 |
mCanRotate = true; |
|
238 |
mCanDrag = true; |
|
239 |
mCanSolve = true; |
|
240 |
mCanScramble = true; |
|
231 | 241 |
} |
232 | 242 |
} |
233 | 243 |
|
... | ... | |
276 | 286 |
|
277 | 287 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
278 | 288 |
|
279 |
void setUnscrambleDuration(int duration)
|
|
289 |
void setSolveDuration(int duration)
|
|
280 | 290 |
{ |
281 |
mUnscrambleDuration = duration;
|
|
291 |
mSolveDuration = duration;
|
|
282 | 292 |
} |
283 | 293 |
|
284 | 294 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
297 | 307 |
|
298 | 308 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
299 | 309 |
|
300 |
void setUnscrambleType(UnscrambleEffect.Type type)
|
|
310 |
void setSolveType(SolveEffect.Type type)
|
|
301 | 311 |
{ |
302 |
mUnscrambleType = type;
|
|
312 |
mSolveType = type;
|
|
303 | 313 |
} |
304 | 314 |
|
305 | 315 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
357 | 367 |
|
358 | 368 |
void scrambleCube(int num) |
359 | 369 |
{ |
360 |
mScrambleCube = true; |
|
361 |
mScrambleCubeNum = num; |
|
370 |
if( mCanScramble ) |
|
371 |
{ |
|
372 |
mScrambleCube = true; |
|
373 |
mScrambleCubeNum = num; |
|
374 |
} |
|
362 | 375 |
} |
363 | 376 |
|
364 | 377 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
381 | 394 |
|
382 | 395 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
383 | 396 |
|
384 |
void unscrambleCube()
|
|
397 |
void solveCube()
|
|
385 | 398 |
{ |
386 |
mSolveCube = true; |
|
399 |
if( mCanSolve ) |
|
400 |
{ |
|
401 |
mSolveCube = true; |
|
402 |
} |
|
387 | 403 |
} |
388 | 404 |
|
389 | 405 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
390 | 406 |
|
391 |
private void unscrambleCubeNow()
|
|
407 |
private void solveCubeNow()
|
|
392 | 408 |
{ |
393 | 409 |
try |
394 | 410 |
{ |
395 |
UnscrambleEffect effect = UnscrambleEffect.create(mUnscrambleType);
|
|
396 |
mUnscrambleEffectID = effect.start(mUnscrambleDuration,mScreen,mNewCube,this);
|
|
411 |
SolveEffect effect = SolveEffect.create(mSolveType);
|
|
412 |
mSolveEffectID = effect.start(mSolveDuration,mScreen,mNewCube,this);
|
|
397 | 413 |
} |
398 | 414 |
catch(Exception ex) |
399 | 415 |
{ |
400 |
android.util.Log.e("Renderer", "failed to create UnscrambleEffect, exception: "+ex.getMessage());
|
|
416 |
android.util.Log.e("Renderer", "failed to create SolveEffect, exception: "+ex.getMessage());
|
|
401 | 417 |
|
402 |
mNewCube.unscramble(); //
|
|
403 |
mCanRotate = true; // just unscramble the cube
|
|
404 |
mCanDrag = true; //
|
|
418 |
mNewCube.solve(); //
|
|
419 |
mCanRotate = true; // just solve the cube
|
|
420 |
mCanDrag = true; // |
|
405 | 421 |
} |
406 | 422 |
} |
407 | 423 |
|
src/main/java/org/distorted/magic/RubikSettings.java | ||
---|---|---|
37 | 37 |
import android.widget.TextView; |
38 | 38 |
|
39 | 39 |
import org.distorted.effect.SizeChangeEffect; |
40 |
import org.distorted.effect.UnscrambleEffect;
|
|
40 |
import org.distorted.effect.SolveEffect;
|
|
41 | 41 |
import org.distorted.effect.ScrambleEffect; |
42 | 42 |
|
43 | 43 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
50 | 50 |
} |
51 | 51 |
|
52 | 52 |
private OnCompleteListener mListener; |
53 |
private int mSizeChangePos, mUnscramblePos, mScramblePos;
|
|
54 |
private int mSizeChangeType, mUnscrambleType, mScrambleType;
|
|
55 |
private TextView mSizeChangeDuration, mUnscrambleDuration, mScrambleDuration;
|
|
53 |
private int mSizeChangePos, mSolvePos, mScramblePos;
|
|
54 |
private int mSizeChangeType, mSolveType, mScrambleType;
|
|
55 |
private TextView mSizeChangeDuration, mSolveDuration, mScrambleDuration;
|
|
56 | 56 |
|
57 | 57 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
58 | 58 |
|
... | ... | |
83 | 83 |
try |
84 | 84 |
{ |
85 | 85 |
mSizeChangePos = args.getInt("sizechangePos"); |
86 |
mUnscramblePos = args.getInt("unscramblePos");
|
|
86 |
mSolvePos = args.getInt("solvePos");
|
|
87 | 87 |
mScramblePos = args.getInt("scramblePos"); |
88 | 88 |
mSizeChangeType= args.getInt("sizechangeType"); |
89 |
mUnscrambleType= args.getInt("unscrambleType");
|
|
89 |
mSolveType = args.getInt("solveType");
|
|
90 | 90 |
mScrambleType = args.getInt("scrambleType"); |
91 | 91 |
} |
92 | 92 |
catch(NullPointerException ex) |
93 | 93 |
{ |
94 | 94 |
mSizeChangePos = RubikActivity.DEFAULT_SIZECHANGE_POS; |
95 |
mUnscramblePos = RubikActivity.DEFAULT_UNSCRAMBLE_POS;
|
|
95 |
mSolvePos = RubikActivity.DEFAULT_SOLVE_POS;
|
|
96 | 96 |
mScramblePos = RubikActivity.DEFAULT_SCRAMBLE_POS; |
97 | 97 |
mSizeChangeType= RubikActivity.DEFAULT_SIZECHANGE_TYPE; |
98 |
mUnscrambleType= RubikActivity.DEFAULT_UNSCRAMBLE_TYPE;
|
|
98 |
mSolveType = RubikActivity.DEFAULT_SOLVE_TYPE;
|
|
99 | 99 |
mScrambleType = RubikActivity.DEFAULT_SCRAMBLE_TYPE; |
100 | 100 |
} |
101 | 101 |
} |
... | ... | |
124 | 124 |
builder.setView(view); |
125 | 125 |
|
126 | 126 |
mSizeChangeDuration = view.findViewById(R.id.sizechangeDurationText); |
127 |
mUnscrambleDuration = view.findViewById(R.id.unscrambleDurationText);
|
|
127 |
mSolveDuration = view.findViewById(R.id.solveDurationText);
|
|
128 | 128 |
mScrambleDuration = view.findViewById(R.id.scrambleDurationText); |
129 | 129 |
|
130 | 130 |
/// SIZE CHANGE /////////////////////////////////////////////////////// |
... | ... | |
152 | 152 |
sizechangeBar.setOnSeekBarChangeListener(this); |
153 | 153 |
sizechangeBar.setProgress(mSizeChangePos); |
154 | 154 |
|
155 |
/// UNSCRAMBLE ////////////////////////////////////////////////////////
|
|
156 |
Spinner unscrambleTypeSpinner = view.findViewById(R.id.unscrambleType);
|
|
155 |
/// SOLVE /////////////////////////////////////////////////////////////
|
|
156 |
Spinner solveTypeSpinner = view.findViewById(R.id.solveType);
|
|
157 | 157 |
|
158 |
if( unscrambleTypeSpinner!=null )
|
|
158 |
if( solveTypeSpinner!=null )
|
|
159 | 159 |
{ |
160 |
unscrambleTypeSpinner.setOnItemSelectedListener(this);
|
|
161 |
String[] unscramble = UnscrambleEffect.getNames();
|
|
162 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, unscramble);
|
|
160 |
solveTypeSpinner.setOnItemSelectedListener(this);
|
|
161 |
String[] solve = SolveEffect.getNames();
|
|
162 |
ArrayAdapter<String> adapterType = new ArrayAdapter<>(act,android.R.layout.simple_spinner_item, solve);
|
|
163 | 163 |
adapterType.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item); |
164 |
unscrambleTypeSpinner.setAdapter(adapterType);
|
|
164 |
solveTypeSpinner.setAdapter(adapterType);
|
|
165 | 165 |
|
166 |
if(mUnscrambleType>=0 && mUnscrambleType<unscramble.length)
|
|
166 |
if(mSolveType>=0 && mSolveType<solve.length)
|
|
167 | 167 |
{ |
168 |
unscrambleTypeSpinner.setSelection(mUnscrambleType);
|
|
168 |
solveTypeSpinner.setSelection(mSolveType);
|
|
169 | 169 |
} |
170 | 170 |
} |
171 | 171 |
else |
172 | 172 |
{ |
173 |
android.util.Log.e("dialog", "UNSCRAMBLE TYPE SPINNER NULL!!");
|
|
173 |
android.util.Log.e("dialog", "SOLVE TYPE SPINNER NULL!!");
|
|
174 | 174 |
} |
175 | 175 |
|
176 |
SeekBar unscrambleBar = view.findViewById(R.id.unscrambleDuration);
|
|
177 |
unscrambleBar.setOnSeekBarChangeListener(this);
|
|
178 |
unscrambleBar.setProgress(mUnscramblePos);
|
|
176 |
SeekBar solveBar = view.findViewById(R.id.solveDuration);
|
|
177 |
solveBar.setOnSeekBarChangeListener(this);
|
|
178 |
solveBar.setProgress(mSolvePos);
|
|
179 | 179 |
|
180 | 180 |
/// SCRAMBLE ////////////////////////////////////////////////////////// |
181 | 181 |
Spinner scrambleTypeSpinner = view.findViewById(R.id.scrambleType); |
... | ... | |
209 | 209 |
|
210 | 210 |
private void saveOptions() |
211 | 211 |
{ |
212 |
mListener.onComplete(mSizeChangePos, mUnscramblePos, mScramblePos, mSizeChangeType, mUnscrambleType, mScrambleType);
|
|
212 |
mListener.onComplete(mSizeChangePos, mSolvePos, mScramblePos, mSizeChangeType, mSolveType, mScrambleType);
|
|
213 | 213 |
} |
214 | 214 |
|
215 | 215 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
... | ... | |
219 | 219 |
switch(parent.getId()) |
220 | 220 |
{ |
221 | 221 |
case R.id.sizechangeType: mSizeChangeType= pos; break; |
222 |
case R.id.unscrambleType: mUnscrambleType= pos; break;
|
|
222 |
case R.id.solveType : mSolveType = pos; break;
|
|
223 | 223 |
case R.id.scrambleType : mScrambleType = pos; break; |
224 | 224 |
} |
225 | 225 |
} |
... | ... | |
234 | 234 |
int sizechange_ms= RubikActivity.translateDuration(mSizeChangePos); |
235 | 235 |
mSizeChangeDuration.setText(getString(R.string.ms_placeholder,sizechange_ms)); |
236 | 236 |
break; |
237 |
case R.id.unscrambleDuration: mUnscramblePos= progress;
|
|
238 |
int unscramble_ms= RubikActivity.translateDuration(mUnscramblePos);
|
|
239 |
mUnscrambleDuration.setText(getString(R.string.ms_placeholder,unscramble_ms));
|
|
237 |
case R.id.solveDuration : mSolvePos= progress;
|
|
238 |
int solve_ms= RubikActivity.translateDuration(mSolvePos);
|
|
239 |
mSolveDuration.setText(getString(R.string.ms_placeholder,solve_ms));
|
|
240 | 240 |
break; |
241 | 241 |
case R.id.scrambleDuration : mScramblePos= progress; |
242 | 242 |
int scramble_ms= RubikActivity.translateDuration(mScramblePos); |
src/main/res/layout/main.xml | ||
---|---|---|
83 | 83 |
android:layout_width="wrap_content" |
84 | 84 |
android:layout_height="fill_parent" |
85 | 85 |
android:layout_weight="0.5" |
86 |
android:onClick="Unscramble"
|
|
86 |
android:onClick="Solve"
|
|
87 | 87 |
android:paddingLeft="5dp" |
88 | 88 |
android:paddingRight="5dp" |
89 | 89 |
android:text="@string/solve" /> |
src/main/res/layout/settings.xml | ||
---|---|---|
126 | 126 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
127 | 127 |
|
128 | 128 |
<TextView |
129 |
android:id="@+id/unscrambleDurationText"
|
|
129 |
android:id="@+id/solveDurationText"
|
|
130 | 130 |
android:layout_weight="0.2" |
131 | 131 |
android:layout_width="0dp" |
132 | 132 |
android:layout_height="fill_parent" |
... | ... | |
136 | 136 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
137 | 137 |
|
138 | 138 |
<SeekBar |
139 |
android:id="@+id/unscrambleDuration"
|
|
139 |
android:id="@+id/solveDuration"
|
|
140 | 140 |
android:layout_weight="0.6" |
141 | 141 |
android:layout_width="0dp" |
142 | 142 |
android:layout_height="fill_parent" |
... | ... | |
162 | 162 |
android:textAppearance="?android:attr/textAppearanceSmall" /> |
163 | 163 |
|
164 | 164 |
<Spinner |
165 |
android:id="@+id/unscrambleType"
|
|
165 |
android:id="@+id/solveType"
|
|
166 | 166 |
android:layout_weight="0.6" |
167 | 167 |
android:layout_width="0dp" |
168 | 168 |
android:layout_height="fill_parent" |
Also available in: Unified diff
RubikCube: progress with scrambling