Project

General

Profile

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

magiccube / src / main / java / org / distorted / playui / ScreenList.java @ 7bb30586

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is proprietary software licensed under an EULA which you should have received      //
7
// along with the code. If not, check https://distorted.org/magic/License-Magic-Cube.html        //
8
///////////////////////////////////////////////////////////////////////////////////////////////////
9

    
10
package org.distorted.playui;
11

    
12
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
13
import static org.distorted.objectlib.main.ObjectControl.MODE_NOTHING;
14
import static org.distorted.objectlib.main.ObjectControl.MODE_ROTATE;
15

    
16
import android.content.SharedPreferences;
17

    
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
public enum ScreenList
21
  {
22
  FREE ( null , MODE_ROTATE , new ScreenFree()       ),
23
  SCRA ( null , MODE_NOTHING, new ScreenScrambling() ),
24
  READ ( null , MODE_ROTATE , new ScreenReady()      ),
25
  SOLV ( null , MODE_ROTATE , new ScreenSolving()    ),
26
  DONE ( null , MODE_DRAG   , new ScreenDone()       ),
27
  ;
28

    
29
  public static final int LENGTH = values().length;
30
  private static final ScreenList[] screens;
31
  private final ScreenList mBack;
32
  private final int mMode;
33
  private final ScreenAbstract mClass;
34

    
35
  private static ScreenList mCurrScreen;
36

    
37
  static
38
    {
39
    int i = 0;
40
    screens = new ScreenList[LENGTH];
41
    for(ScreenList state: ScreenList.values()) screens[i++] = state;
42
    }
43

    
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45

    
46
  public static ScreenList getScreen(int ordinal)
47
    {
48
    return ordinal>=0 && ordinal<LENGTH ?  screens[ordinal] : SCRA;
49
    }
50

    
51
///////////////////////////////////////////////////////////////////////////////////////////////////
52

    
53
  public static ScreenList getScreenFromName(String name)
54
    {
55
    for(int i=0; i<LENGTH; i++)
56
      {
57
      if( name.equals(screens[i].name()) )
58
        {
59
        return screens[i];
60
        }
61
      }
62

    
63
    return SCRA;
64
    }
65

    
66
///////////////////////////////////////////////////////////////////////////////////////////////////
67

    
68
  public static ScreenList getCurrentScreen()
69
    {
70
    return mCurrScreen;
71
    }
72

    
73
///////////////////////////////////////////////////////////////////////////////////////////////////
74

    
75
  public static int getMode()
76
    {
77
    return mCurrScreen.mMode;
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  public static void savePreferences(SharedPreferences.Editor editor)
83
    {
84
    android.util.Log.e("D", "saving current state: "+mCurrScreen.name() );
85

    
86
    editor.putString("curr_state_name", mCurrScreen.name() );
87
    }
88

    
89
///////////////////////////////////////////////////////////////////////////////////////////////////
90

    
91
  public static void restorePreferences(SharedPreferences preferences)
92
    {
93
    String currScreenName = preferences.getString("curr_state_name", ScreenList.SCRA.name() );
94
    mCurrScreen = getScreenFromName(currScreenName);
95

    
96
    android.util.Log.e("D", "restoring current state: "+currScreenName );
97
    }
98

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

    
101
  public static void goBack(PlayActivity act)
102
    {
103
    switchScreen(act, mCurrScreen.mBack );
104
    }
105

    
106
///////////////////////////////////////////////////////////////////////////////////////////////////
107

    
108
  public static void setScreen(PlayActivity act)
109
    {
110
    mCurrScreen.enterScreen(act);
111
    }
112

    
113
///////////////////////////////////////////////////////////////////////////////////////////////////
114

    
115
  public static void switchScreen(PlayActivity act, ScreenList next)
116
    {
117
    if( next!=null )
118
      {
119
      if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
120
      next.enterScreen(act);
121
      mCurrScreen = next;
122
      }
123
    else
124
      {
125
      act.finish();
126
      }
127
    }
128

    
129
///////////////////////////////////////////////////////////////////////////////////////////////////
130

    
131
  ScreenList(ScreenList back, int mode, ScreenAbstract clazz)
132
    {
133
    mBack = back;
134
    mMode = mode;
135
    mClass= clazz;
136
    }
137

    
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139

    
140
  public ScreenAbstract getScreenClass()
141
    {
142
    return mClass;
143
    }
144

    
145
///////////////////////////////////////////////////////////////////////////////////////////////////
146

    
147
  public void leaveScreen(PlayActivity act)
148
    {
149
    mClass.leaveScreen(act);
150
    }
151

    
152
///////////////////////////////////////////////////////////////////////////////////////////////////
153

    
154
  public void enterScreen(PlayActivity act)
155
    {
156
    mClass.enterScreen(act);
157
    }
158
  }
(9-9/12)