Revision f647630d
Added by Leszek Koltunski over 6 years ago
| src/main/java/org/distorted/effect/AppearEffect.java | ||
|---|---|---|
| 22 | 22 |
import org.distorted.library.effect.Effect; |
| 23 | 23 |
import org.distorted.library.main.DistortedScreen; |
| 24 | 24 |
import org.distorted.library.message.EffectListener; |
| 25 |
import org.distorted.library.message.EffectMessage; |
|
| 26 | 25 |
import org.distorted.magic.RubikCube; |
| 27 | 26 |
|
| 28 | 27 |
import java.lang.reflect.Method; |
| ... | ... | |
| 95 | 94 |
|
| 96 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 97 | 96 |
|
| 98 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
|
|
| 97 |
public void effectFinished(final long effectID)
|
|
| 99 | 98 |
{
|
| 100 | 99 |
for(int i=0; i<mCubeEffectNumber; i++) |
| 101 | 100 |
{
|
| ... | ... | |
| 107 | 106 |
|
| 108 | 107 |
if( mCubeEffectReturned == mCubeEffectFinished ) |
| 109 | 108 |
{
|
| 110 |
mListener.effectMessage(null, FAKE_EFFECT_ID, 0); |
|
| 111 |
} |
|
| 112 |
|
|
| 113 |
if( mCubeEffectReturned == mCubeEffectNumber ) |
|
| 114 |
{
|
|
| 115 |
mCube.deregisterForMessages(this); |
|
| 109 |
mListener.effectFinished(FAKE_EFFECT_ID); |
|
| 116 | 110 |
} |
| 117 | 111 |
|
| 118 | 112 |
mCube.remove(id); |
| ... | ... | |
| 143 | 137 |
for(int i=0; i<mCubeEffectNumber; i++) |
| 144 | 138 |
{
|
| 145 | 139 |
mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]); |
| 140 |
mCubeEffects[i].notifyWhenFinished(this); |
|
| 146 | 141 |
} |
| 147 | 142 |
|
| 148 |
mCube.registerForMessages(this); |
|
| 149 | 143 |
mScreen.attach(mCube); |
| 150 | 144 |
|
| 151 | 145 |
return FAKE_EFFECT_ID; |
| src/main/java/org/distorted/effect/DisappearEffect.java | ||
|---|---|---|
| 22 | 22 |
import org.distorted.library.effect.Effect; |
| 23 | 23 |
import org.distorted.library.main.DistortedScreen; |
| 24 | 24 |
import org.distorted.library.message.EffectListener; |
| 25 |
import org.distorted.library.message.EffectMessage; |
|
| 26 | 25 |
import org.distorted.magic.RubikCube; |
| 27 | 26 |
|
| 28 | 27 |
import java.lang.reflect.Method; |
| ... | ... | |
| 95 | 94 |
|
| 96 | 95 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 97 | 96 |
|
| 98 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
|
|
| 97 |
public void effectFinished(final long effectID)
|
|
| 99 | 98 |
{
|
| 100 | 99 |
for(int i=0; i<mCubeEffectNumber; i++) |
| 101 | 100 |
{
|
| ... | ... | |
| 107 | 106 |
|
| 108 | 107 |
if( mCubeEffectReturned == mCubeEffectFinished ) |
| 109 | 108 |
{
|
| 110 |
mListener.effectMessage(null, FAKE_EFFECT_ID, 0);
|
|
| 109 |
mListener.effectFinished(FAKE_EFFECT_ID);
|
|
| 111 | 110 |
} |
| 112 | 111 |
|
| 113 | 112 |
if( mCubeEffectReturned == mCubeEffectNumber ) |
| 114 | 113 |
{
|
| 115 | 114 |
mScreen.detach(mCube); |
| 116 |
mCube.deregisterForMessages(this); |
|
| 117 | 115 |
} |
| 118 | 116 |
|
| 119 | 117 |
mCube.remove(id); |
| ... | ... | |
| 144 | 142 |
for(int i=0; i<mCubeEffectNumber; i++) |
| 145 | 143 |
{
|
| 146 | 144 |
mCube.apply(mCubeEffects[i],mCubeEffectPosition[i]); |
| 145 |
mCubeEffects[i].notifyWhenFinished(this); |
|
| 147 | 146 |
} |
| 148 | 147 |
|
| 149 |
mCube.registerForMessages(this); |
|
| 150 |
|
|
| 151 | 148 |
return FAKE_EFFECT_ID; |
| 152 | 149 |
} |
| 153 | 150 |
|
| src/main/java/org/distorted/magic/RubikCube.java | ||
|---|---|---|
| 63 | 63 |
private Static1D mRotationAngleStatic, mRotationAngleMiddle, mRotationAngleFinal; |
| 64 | 64 |
private Static3D mMove, mScale, mNodeMove, mNodeScale; |
| 65 | 65 |
private DistortedTexture mTexture; |
| 66 |
private DistortedEffects mEffectsListeningForNow; |
|
| 67 | 66 |
|
| 68 | 67 |
private int mRotAxis, mRotRow; |
| 69 | 68 |
private int mSize; |
| ... | ... | |
| 217 | 216 |
return mEffects[0][0][0].getNumEffects(type); |
| 218 | 217 |
} |
| 219 | 218 |
|
| 220 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 221 |
|
|
| 222 |
public void registerForMessages(EffectListener listener) |
|
| 223 |
{
|
|
| 224 |
mEffects[0][0][0].registerForMessages(listener); |
|
| 225 |
} |
|
| 226 |
|
|
| 227 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
| 228 |
|
|
| 229 |
public void deregisterForMessages(EffectListener listener) |
|
| 230 |
{
|
|
| 231 |
mEffects[0][0][0].deregisterForMessages(listener); |
|
| 232 |
} |
|
| 233 |
|
|
| 234 | 219 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 235 | 220 |
// all DistortedTextures, DistortedNodes, DistortedFramebuffers, DistortedScreens and all types of |
| 236 | 221 |
// Meshes HAVE TO be markedForDeletion when they are no longer needed- otherwise we have a major |
| ... | ... | |
| 328 | 313 |
if( first ) |
| 329 | 314 |
{
|
| 330 | 315 |
first = false; |
| 331 |
mEffectsListeningForNow = mEffects[x][y][z]; |
|
| 332 |
mEffectsListeningForNow.registerForMessages(listener); |
|
| 316 |
mRotateEffect[x][y][z].notifyWhenFinished(listener); |
|
| 333 | 317 |
effectID = mRotateEffect[x][y][z].getID(); |
| 334 | 318 |
} |
| 335 | 319 |
} |
| ... | ... | |
| 340 | 324 |
|
| 341 | 325 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 342 | 326 |
|
| 343 |
void removeRotationNow(EffectListener listener)
|
|
| 327 |
void removeRotationNow() |
|
| 344 | 328 |
{
|
| 345 |
mEffectsListeningForNow.deregisterForMessages(listener); |
|
| 346 |
|
|
| 347 | 329 |
int nearestAngleInDegrees = computeNearestAngle(mRotationAngleStatic.get1()); |
| 348 | 330 |
double nearestAngleInRadians = nearestAngleInDegrees*Math.PI/180; |
| 349 | 331 |
float sinA =-(float)Math.sin(nearestAngleInRadians*0.5); |
| src/main/java/org/distorted/magic/RubikRenderer.java | ||
|---|---|---|
| 30 | 30 |
import org.distorted.library.main.DistortedTexture; |
| 31 | 31 |
import org.distorted.library.mesh.MeshQuad; |
| 32 | 32 |
import org.distorted.library.message.EffectListener; |
| 33 |
import org.distorted.library.message.EffectMessage; |
|
| 34 | 33 |
import org.distorted.library.type.Static4D; |
| 35 | 34 |
|
| 36 | 35 |
import javax.microedition.khronos.egl.EGLConfig; |
| ... | ... | |
| 126 | 125 |
if( mRemoveRotation ) |
| 127 | 126 |
{
|
| 128 | 127 |
mRemoveRotation=false; |
| 129 |
mNewCube.removeRotationNow(this);
|
|
| 128 |
mNewCube.removeRotationNow(); |
|
| 130 | 129 |
mCanRotate = true; |
| 131 | 130 |
} |
| 132 | 131 |
|
| ... | ... | |
| 185 | 184 |
|
| 186 | 185 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
| 187 | 186 |
|
| 188 |
public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
|
|
| 187 |
public void effectFinished(final long effectID)
|
|
| 189 | 188 |
{
|
| 190 |
if( effectID == mRotationFinishedID )
|
|
| 189 |
if( effectID == mRotationFinishedID) |
|
| 191 | 190 |
{
|
| 192 | 191 |
mRemoveRotation = true; |
| 193 | 192 |
} |
| src/main/res/layout/numberpicker.xml | ||
|---|---|---|
| 9 | 9 |
android:layout_width="0sp" |
| 10 | 10 |
android:layout_height="match_parent" |
| 11 | 11 |
android:layout_weight="1" |
| 12 |
android:text="-" /> |
|
| 12 |
android:text="-" |
|
| 13 |
android:textSize="30sp" /> |
|
| 13 | 14 |
|
| 14 | 15 |
<TextView |
| 15 | 16 |
android:id="@+id/textNumber" |
| 16 | 17 |
android:layout_width="0sp" |
| 17 | 18 |
android:layout_height="match_parent" |
| 18 | 19 |
android:layout_weight="1" |
| 19 |
android:inputType="number" |
|
| 20 |
android:text="0" |
|
| 21 | 20 |
android:textAlignment="center" |
| 22 |
android:textSize="48sp" />
|
|
| 21 |
android:textSize="46sp" />
|
|
| 23 | 22 |
|
| 24 | 23 |
<Button |
| 25 | 24 |
android:id="@+id/buttonMore" |
| 26 | 25 |
android:layout_width="0sp" |
| 27 | 26 |
android:layout_height="match_parent" |
| 28 | 27 |
android:layout_weight="1" |
| 29 |
android:text="+" /> |
|
| 28 |
android:text="+" |
|
| 29 |
android:textSize="30sp" /> |
|
| 30 | 30 |
</LinearLayout> |
Also available in: Unified diff
Simplify the way applications can get notifications when an effect finishes.
Now, instead of the 'DistortedEffects.(de)registerForNotifications()' 2 APIs, we call a single 'Effect.notifyWhenFinished()'.