Project

General

Profile

Download (5.04 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / effect / TransitionEffectDisappear.java @ 434f2f5a

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.FragmentEffectAlpha;
23
import org.distorted.library.main.DistortedScreen;
24
import org.distorted.library.message.EffectListener;
25
import org.distorted.library.message.EffectMessage;
26
import org.distorted.library.type.Dynamic1D;
27
import org.distorted.library.type.Static1D;
28
import org.distorted.magic.RubikCube;
29

    
30
///////////////////////////////////////////////////////////////////////////////////////////////////
31

    
32
class TransitionEffectDisappear extends TransitionEffect implements EffectListener
33
  {
34
  private static final int DURATION_IN_MILLIS = 1000;
35

    
36
  private EffectListener mListener;
37
  private FragmentEffectAlpha mDisappear, mAppear;
38
  private DistortedScreen mScreen;
39
  private RubikCube mOld, mNew;
40

    
41
  private long mDisappearID;
42

    
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44

    
45
  TransitionEffectDisappear()
46
    {
47

    
48
    }
49

    
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51
// enable all effects we are using in this Transition.
52
// called by reflection from the parent class.
53

    
54
  @SuppressWarnings("unused")
55
  static void enable()
56
    {
57
    FragmentEffectAlpha.enable();
58
    }
59

    
60
///////////////////////////////////////////////////////////////////////////////////////////////////
61

    
62
  public long prepare(EffectListener listener)
63
    {
64
    mListener = listener;
65

    
66
    Dynamic1D disappearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f);  // this means - linearily change the
67
    disappearDyn.add(new Static1D(1.0f));                              // alpha of the old cube from 1.0 (100%)
68
    disappearDyn.add(new Static1D(0.0f));                              // to 0.0 (0%) within DURATION millisecs.
69
    mDisappear = new FragmentEffectAlpha(disappearDyn);
70

    
71
    Dynamic1D appearDyn = new Dynamic1D(DURATION_IN_MILLIS, 0.5f);     // the opposite - make the new cube
72
    appearDyn.add(new Static1D(0.0f));                                 // more and more opaque.
73
    appearDyn.add(new Static1D(1.0f));                                 //
74
    mAppear = new FragmentEffectAlpha(appearDyn);
75

    
76
    mDisappearID = mDisappear.getID();
77

    
78
    return mAppear.getID();
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82
// At the start, oldCube is attached to the screen, new is not.
83
// Gradually make the old cube disappear and wait for the message that this is done.
84

    
85
  public void start(DistortedScreen screen, RubikCube oldCube, RubikCube newCube)
86
    {
87
    mScreen = screen;
88
    mNew    = newCube;
89
    mOld    = oldCube;
90

    
91
    mOld.apply(mDisappear);
92
    mOld.registerForMessages(this);
93
    }
94

    
95
///////////////////////////////////////////////////////////////////////////////////////////////////
96
// whenever we get the message that the old cube completely disappeared, make the new one appear
97
// The calling RubikRenderer will get the message that this (final) transition is over and do whatever
98
// it wants to do with this.
99

    
100
  public void effectMessage(final EffectMessage em, final long effectID, final long objectID)
101
    {
102
    if( effectID == mDisappearID )
103
      {
104
      mScreen.detachAll();
105
      mNew.attachToScreen(mScreen);
106
      mNew.apply(mAppear);
107
      mOld.deregisterForMessages(this);
108
      mNew.registerForMessages(mListener);
109
      }
110
    }
111
  }
(2-2/3)