| 1 |
e9245b7b
|
leszek
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 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 |
7e9d918b
|
leszek
|
package org.distorted.patterns;
|
| 11 |
e9245b7b
|
leszek
|
|
| 12 |
|
|
import static org.distorted.objectlib.main.ObjectControl.MODE_DRAG;
|
| 13 |
|
|
|
| 14 |
|
|
import android.content.SharedPreferences;
|
| 15 |
|
|
|
| 16 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 17 |
|
|
|
| 18 |
|
|
public enum ScreenList
|
| 19 |
|
|
{
|
| 20 |
|
|
PATT ( null, MODE_DRAG, new ScreenPattern() ),
|
| 21 |
|
|
;
|
| 22 |
|
|
|
| 23 |
|
|
public static final int LENGTH = values().length;
|
| 24 |
|
|
private static final ScreenList[] screens;
|
| 25 |
|
|
private final ScreenList mBack;
|
| 26 |
|
|
private final int mMode;
|
| 27 |
|
|
private final ScreenAbstract mClass;
|
| 28 |
|
|
|
| 29 |
|
|
private static ScreenList mCurrScreen;
|
| 30 |
|
|
|
| 31 |
|
|
static
|
| 32 |
|
|
{
|
| 33 |
|
|
int i = 0;
|
| 34 |
|
|
screens = new ScreenList[LENGTH];
|
| 35 |
|
|
for(ScreenList state: ScreenList.values()) screens[i++] = state;
|
| 36 |
|
|
}
|
| 37 |
|
|
|
| 38 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 39 |
|
|
|
| 40 |
|
|
public static ScreenList getScreen(int ordinal)
|
| 41 |
|
|
{
|
| 42 |
|
|
return ordinal>=0 && ordinal<LENGTH ? screens[ordinal] : PATT;
|
| 43 |
|
|
}
|
| 44 |
|
|
|
| 45 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 46 |
|
|
|
| 47 |
|
|
public static ScreenList getScreenFromName(String name)
|
| 48 |
|
|
{
|
| 49 |
|
|
for(int i=0; i<LENGTH; i++)
|
| 50 |
|
|
{
|
| 51 |
|
|
if( name.equals(screens[i].name()) )
|
| 52 |
|
|
{
|
| 53 |
|
|
return screens[i];
|
| 54 |
|
|
}
|
| 55 |
|
|
}
|
| 56 |
|
|
|
| 57 |
|
|
return PATT;
|
| 58 |
|
|
}
|
| 59 |
|
|
|
| 60 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 61 |
|
|
|
| 62 |
|
|
public static ScreenList getCurrentScreen()
|
| 63 |
|
|
{
|
| 64 |
|
|
return mCurrScreen;
|
| 65 |
|
|
}
|
| 66 |
|
|
|
| 67 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 68 |
|
|
|
| 69 |
|
|
public static int getMode()
|
| 70 |
|
|
{
|
| 71 |
|
|
return mCurrScreen.mMode;
|
| 72 |
|
|
}
|
| 73 |
|
|
|
| 74 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 75 |
|
|
|
| 76 |
|
|
public static void savePreferences(SharedPreferences.Editor editor)
|
| 77 |
|
|
{
|
| 78 |
|
|
editor.putString("curr_state_name", mCurrScreen.name() );
|
| 79 |
|
|
}
|
| 80 |
|
|
|
| 81 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 82 |
|
|
|
| 83 |
|
|
public static void restorePreferences(SharedPreferences preferences)
|
| 84 |
|
|
{
|
| 85 |
|
|
String currScreenName = preferences.getString("curr_state_name", ScreenList.PATT.name() );
|
| 86 |
|
|
mCurrScreen = getScreenFromName(currScreenName);
|
| 87 |
|
|
}
|
| 88 |
|
|
|
| 89 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 90 |
|
|
|
| 91 |
|
|
public static void goBack(PatternActivity act)
|
| 92 |
|
|
{
|
| 93 |
|
|
switchScreen(act, mCurrScreen.mBack );
|
| 94 |
|
|
}
|
| 95 |
|
|
|
| 96 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 97 |
|
|
|
| 98 |
|
|
public static void setScreen(PatternActivity act)
|
| 99 |
|
|
{
|
| 100 |
|
|
mCurrScreen.enterScreen(act);
|
| 101 |
|
|
}
|
| 102 |
|
|
|
| 103 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 104 |
|
|
|
| 105 |
|
|
public static void switchScreen(PatternActivity act, ScreenList next)
|
| 106 |
|
|
{
|
| 107 |
|
|
if( next!=null )
|
| 108 |
|
|
{
|
| 109 |
|
|
if( mCurrScreen !=null ) mCurrScreen.leaveScreen(act);
|
| 110 |
|
|
next.enterScreen(act);
|
| 111 |
|
|
mCurrScreen = next;
|
| 112 |
|
|
}
|
| 113 |
|
|
else
|
| 114 |
|
|
{
|
| 115 |
|
|
act.finish();
|
| 116 |
|
|
}
|
| 117 |
|
|
}
|
| 118 |
|
|
|
| 119 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 120 |
|
|
|
| 121 |
|
|
ScreenList(ScreenList back, int mode, ScreenAbstract clazz)
|
| 122 |
|
|
{
|
| 123 |
|
|
mBack = back;
|
| 124 |
|
|
mMode = mode;
|
| 125 |
|
|
mClass= clazz;
|
| 126 |
|
|
}
|
| 127 |
|
|
|
| 128 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 129 |
|
|
|
| 130 |
|
|
public ScreenAbstract getScreenClass()
|
| 131 |
|
|
{
|
| 132 |
|
|
return mClass;
|
| 133 |
|
|
}
|
| 134 |
|
|
|
| 135 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 136 |
|
|
|
| 137 |
|
|
public void leaveScreen(PatternActivity act)
|
| 138 |
|
|
{
|
| 139 |
|
|
mClass.leaveScreen(act);
|
| 140 |
|
|
}
|
| 141 |
|
|
|
| 142 |
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
| 143 |
|
|
|
| 144 |
|
|
public void enterScreen(PatternActivity act)
|
| 145 |
|
|
{
|
| 146 |
|
|
mClass.enterScreen(act);
|
| 147 |
|
|
}
|
| 148 |
|
|
}
|