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
|
editor.putString("curr_state_name", mCurrScreen.name() );
|
85
|
}
|
86
|
|
87
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
88
|
|
89
|
public static void restorePreferences(SharedPreferences preferences)
|
90
|
{
|
91
|
String currScreenName = preferences.getString("curr_state_name", ScreenList.SCRA.name() );
|
92
|
mCurrScreen = getScreenFromName(currScreenName);
|
93
|
}
|
94
|
|
95
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
96
|
|
97
|
public static void goBack(PlayActivity act)
|
98
|
{
|
99
|
switchScreen(act, mCurrScreen.mBack );
|
100
|
}
|
101
|
|
102
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
103
|
|
104
|
public static void setScreen(PlayActivity act)
|
105
|
{
|
106
|
mCurrScreen.enterScreen(act);
|
107
|
}
|
108
|
|
109
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
110
|
|
111
|
public static void switchScreen(PlayActivity act, ScreenList next)
|
112
|
{
|
113
|
if( next!=null )
|
114
|
{
|
115
|
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
|
116
|
next.enterScreen(act);
|
117
|
mCurrScreen = next;
|
118
|
}
|
119
|
else
|
120
|
{
|
121
|
act.finish();
|
122
|
}
|
123
|
}
|
124
|
|
125
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
126
|
|
127
|
ScreenList(ScreenList back, int mode, ScreenAbstract clazz)
|
128
|
{
|
129
|
mBack = back;
|
130
|
mMode = mode;
|
131
|
mClass= clazz;
|
132
|
}
|
133
|
|
134
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
135
|
|
136
|
public ScreenAbstract getScreenClass()
|
137
|
{
|
138
|
return mClass;
|
139
|
}
|
140
|
|
141
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
142
|
|
143
|
public void leaveScreen(PlayActivity act)
|
144
|
{
|
145
|
mClass.leaveScreen(act);
|
146
|
}
|
147
|
|
148
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
149
|
|
150
|
public void enterScreen(PlayActivity act)
|
151
|
{
|
152
|
mClass.enterScreen(act);
|
153
|
}
|
154
|
}
|