Project

General

Profile

« Previous | Next » 

Revision 211b48f2

Added by Leszek Koltunski over 4 years ago

Separate the States (and also Dialogues) into their own package.

View differences:

src/main/java/org/distorted/magic/RubikActivity.java
25 25
import android.support.v7.app.AppCompatActivity;
26 26
import android.view.View;
27 27

  
28
import org.distorted.dialog.RubikDialogAbout;
29
import org.distorted.dialog.RubikDialogScores;
30
import org.distorted.dialog.RubikDialogSettings;
28 31
import org.distorted.effect.BaseEffect;
29 32
import org.distorted.library.main.DistortedLibrary;
30 33

  
34
import org.distorted.uistate.RubikState;
35
import org.distorted.uistate.RubikStateAbstract;
36
import org.distorted.uistate.RubikStatePlay;
37

  
31 38
///////////////////////////////////////////////////////////////////////////////////////////////////
32 39

  
33 40
public class RubikActivity extends AppCompatActivity implements View.OnClickListener
34 41
{
35
    RubikState mCurrentState;
36

  
37
///////////////////////////////////////////////////////////////////////////////////////////////////
38

  
39 42
    @Override
40 43
    protected void onCreate(Bundle savedState)
41 44
      {
......
66 69
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
67 70
      view.onResume();
68 71
      restorePreferences();
69
      view.switchState(this, mCurrentState);
72
      RubikState.setState(this);
70 73
      }
71 74
    
72 75
///////////////////////////////////////////////////////////////////////////////////////////////////
......
94 97

  
95 98
        if( success )
96 99
          {
97
          view.markButton(id);
100
          RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
101
          play.markButton(this,id);
98 102
          }
99 103
        }
100 104

  
101
      if( id == RubikSurfaceView.BUTTON_ID_BACK )
105
      if( id == RubikStateAbstract.BUTTON_ID_BACK )
102 106
        {
103
        mCurrentState = mCurrentState.getBack();
104

  
105
        if( mCurrentState!=null )
106
          {
107
          RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
108
          view.switchState(this, mCurrentState);
109
          }
110
        else
111
          {
112
          mCurrentState = RubikState.MAIN;
113
          finish();
114
          }
107
        RubikState.goBack(this);
115 108
        }
116 109
      }
117 110

  
......
122 115
      SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
123 116
      SharedPreferences.Editor editor = preferences.edit();
124 117

  
125
      for (int i = 0; i< BaseEffect.Type.LENGTH; i++)
118
      for (int i=0; i<BaseEffect.Type.LENGTH; i++)
126 119
        {
127 120
        BaseEffect.Type.getType(i).savePreferences(editor);
128 121
        }
129 122

  
130
      editor.putInt("state", mCurrentState.ordinal() );
131

  
132
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
133
      view.savePreferences(editor);
123
      for (int i=0; i<RubikState.LENGTH; i++)
124
        {
125
        RubikState.getState(i).getStateClass().savePreferences(editor);
126
        }
134 127

  
128
      RubikState.savePreferences(editor);
135 129
      editor.apply();
136 130
      }
137 131

  
......
146 140
        BaseEffect.Type.getType(i).restorePreferences(preferences);
147 141
        }
148 142

  
149
      int stateOrdinal = preferences.getInt("state", RubikState.MAIN.ordinal() );
150
      mCurrentState = RubikState.getState(stateOrdinal);
143
      for (int i=0; i< RubikState.LENGTH; i++)
144
        {
145
        RubikState.getState(i).getStateClass().restorePreferences(preferences);
146
        }
151 147

  
152
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
153
      view.restorePreferences(preferences);
148
      RubikState.restorePreferences(preferences);
154 149
      }
155 150

  
156 151
///////////////////////////////////////////////////////////////////////////////////////////////////
......
159 154

  
160 155
    public void Play(View v)
161 156
      {
162
      mCurrentState = RubikState.PLAY;
163
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
164
      view.switchState(this,mCurrentState);
157
      RubikState.switchState(this,RubikState.PLAY);
165 158
      }
166 159

  
167 160
///////////////////////////////////////////////////////////////////////////////////////////////////
......
176 169

  
177 170
    public void Scores(View v)
178 171
      {
172
      RubikStatePlay play = (RubikStatePlay) RubikState.PLAY.getStateClass();
173
      int tab = play.getButton();
174

  
179 175
      Bundle bundle = new Bundle();
180
      bundle.putInt("tab", RubikSurfaceView.getRedButton());
176
      bundle.putInt("tab", tab);
181 177

  
182 178
      RubikDialogScores scores = new RubikDialogScores();
183 179
      scores.setArguments(bundle);
......
197 193
    public void Scramble(View v)
198 194
      {
199 195
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
200
      view.scramble();
196
      RubikStatePlay play = (RubikStatePlay)RubikState.PLAY.getStateClass();
197
      int scramble = play.getPicker();
198
      view.getRenderer().scrambleCube(scramble);
201 199
      }
202 200

  
203 201
///////////////////////////////////////////////////////////////////////////////////////////////////

Also available in: Unified diff