Project

General

Profile

« Previous | Next » 

Revision f12e4de9

Added by Leszek Koltunski about 3 years ago

Progress with Config UI.

View differences:

src/main/java/org/distorted/config/ConfigScreenPane.java
34 34

  
35 35
import java.io.InputStream;
36 36

  
37
import static android.view.View.inflate;
38

  
39 37
///////////////////////////////////////////////////////////////////////////////////////////////////
40 38

  
41 39
public class ConfigScreenPane
42 40
{
41
  public static final int MESH_NICE = 0;
42
  public static final int MESH_FAST = 1;
43

  
43 44
  private static final int[] IMAGES =
44 45
    {
45 46
    R.id.configDifficulty0,
......
56 57

  
57 58
  private JsonReader mReader;
58 59
  private int mObjectOrdinal;
60
  private boolean mProgramatic;
59 61

  
60 62
///////////////////////////////////////////////////////////////////////////////////////////////////
61 63

  
62
  private void switchMesh(ConfigActivity act, boolean simple)
64
  private void switchMeshState(ConfigActivity act, int meshState)
63 65
    {
66
    RubikObjectList.setMeshState(mObjectOrdinal,meshState);
64 67

  
68
    // TODO: rebuild the mesh
65 69
    }
66 70

  
67 71
///////////////////////////////////////////////////////////////////////////////////////////////////
......
98 102
      ImageView image = layout.findViewById(IMAGES[i]);
99 103
      image.setImageResource( i==difficulty ? R.drawable.ui_difficulty_checked : R.drawable.ui_difficulty_unchecked );
100 104
      }
105

  
106
    int meshState = object.getMeshState();
107
    int id = meshState==MESH_NICE ? R.id.meshNice : R.id.meshSimple;
108
    RadioButton button = act.findViewById(id);
109

  
110
    mProgramatic = true;
111
    button.setChecked(true);
112
    mProgramatic = false;
101 113
    }
102 114

  
103 115
///////////////////////////////////////////////////////////////////////////////////////////////////
......
159 171
      @Override
160 172
      public void onCheckedChanged(RadioGroup group, int checkedId)
161 173
        {
162
        switchMesh( act, checkedId != R.id.meshNice );
174
        if( !mProgramatic )
175
          {
176
          int meshState = checkedId == R.id.meshNice ? MESH_NICE : MESH_FAST;
177
          switchMeshState( act, meshState );
178
          }
163 179
        }
164 180
      });
165 181

  
src/main/java/org/distorted/main/RubikActivity.java
254 254
        RubikScores scores = RubikScores.getInstance();
255 255
        scores.incrementNumRuns();
256 256
        scores.setCountry(this);
257
        SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
258
        RubikObjectList.restoreMeshState(preferences);
257 259
        }
258 260

  
259 261
      int object = RubikObjectList.getCurrObject();
......
307 309
        }
308 310

  
309 311
      RubikObjectList.savePreferences(editor);
312
      RubikObjectList.saveMeshState(editor);
310 313
      ScreenList.savePreferences(editor);
311 314
      RubikSurfaceView view = findViewById(R.id.rubikSurfaceView);
312 315
      view.getObjectControl().savePreferences(editor);
src/main/java/org/distorted/objects/RubikObject.java
24 24
import org.distorted.objectlib.main.ObjectType;
25 25
import org.distorted.patterns.RubikPatternList;
26 26

  
27
import static org.distorted.config.ConfigScreenPane.MESH_NICE;
28

  
27 29
///////////////////////////////////////////////////////////////////////////////////////////////////
28 30

  
29 31
public class RubikObject
......
37 39
  private final int[] mIconID;
38 40
  private final String[][] mPatterns;
39 41

  
42
  private int mMeshState;
43

  
40 44
///////////////////////////////////////////////////////////////////////////////////////////////////
41 45

  
42 46
  RubikObject(ObjectType type)
......
52 56

  
53 57
    int patternOrdinal  = RubikPatternList.getOrdinal(mOrdinal);
54 58
    mPatterns = RubikPatternList.getPatterns(patternOrdinal);
59

  
60
    mMeshState = MESH_NICE;
61
    }
62

  
63
///////////////////////////////////////////////////////////////////////////////////////////////////
64

  
65
  public void setMeshState(int state)
66
    {
67
    mMeshState = state;
68
    }
69

  
70
///////////////////////////////////////////////////////////////////////////////////////////////////
71

  
72
  public int getMeshState()
73
    {
74
    return mMeshState;
55 75
    }
56 76

  
57 77
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/objects/RubikObjectList.java
28 28
import org.distorted.screens.ScreenList;
29 29

  
30 30
import java.util.ArrayList;
31

  
32
import static org.distorted.config.ConfigScreenPane.MESH_NICE;
31 33
import static org.distorted.objectlib.main.ObjectType.NUM_OBJECTS;
32 34

  
33 35
///////////////////////////////////////////////////////////////////////////////////////////////////
......
107 109
    return type.getNumScramble();
108 110
    }
109 111

  
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

  
114
  public static void setMeshState(int ordinal, int state)
115
    {
116
    if( ordinal>=0 && ordinal<mNumObjects ) mObjects.get(ordinal).setMeshState(state);
117
    }
118

  
119
///////////////////////////////////////////////////////////////////////////////////////////////////
120

  
121
  public static int getMeshState(int ordinal)
122
    {
123
    return (ordinal>=0 && ordinal<mNumObjects) ? mObjects.get(ordinal).getMeshState() : MESH_NICE;
124
    }
125

  
110 126
///////////////////////////////////////////////////////////////////////////////////////////////////
111 127

  
112 128
  public static void savePreferences(SharedPreferences.Editor editor)
113 129
    {
114
    RubikObject object = getObject(mObject);
130
    RubikObject obj = getObject(mObject);
131
    if( obj!=null ) editor.putString("rol_objName", obj.getName() );
132
    }
115 133

  
116
    if( object!=null )
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

  
136
  public static void saveMeshState(SharedPreferences.Editor editor)
137
    {
138
    for(int i=0; i<mNumObjects; i++)
117 139
      {
118
      editor.putString("statePlay_objName", object.getName() );
140
      RubikObject obj = getObject(i);
141

  
142
      if( obj!=null )
143
        {
144
        String name = obj.getName();
145
        editor.putInt("rol_"+name, obj.getMeshState() );
146
        }
119 147
      }
120 148
    }
121 149

  
......
125 153
    {
126 154
    RubikObject object = getObject(DEF_OBJECT);
127 155
    String defName = object==null ? "CUBE_3" : object.getName();
128
    String objName= preferences.getString("statePlay_objName",defName);
156
    String objName= preferences.getString("rol_objName",defName);
129 157
    mObject = getOrdinal(objName);
130 158

  
131 159
    if( mObject<0 || mObject>=mNumObjects ) mObject = DEF_OBJECT;
132 160
    }
133 161

  
162
///////////////////////////////////////////////////////////////////////////////////////////////////
163

  
164
  public static void restoreMeshState(SharedPreferences preferences)
165
    {
166
    for(int i=0; i<mNumObjects; i++)
167
      {
168
      RubikObject obj = getObject(i);
169

  
170
      if( obj!=null )
171
        {
172
        String name  = obj.getName();
173
        int meshState= preferences.getInt("rol_"+name,MESH_NICE);
174
        obj.setMeshState(meshState);
175
        }
176
      }
177
    }
178

  
134 179
///////////////////////////////////////////////////////////////////////////////////////////////////
135 180

  
136 181
  public static boolean setCurrObject(RubikActivity act, int ordinal)
src/main/java/org/distorted/screens/RubikScreenPlay.java
337 337
      @Override
338 338
      public void onClick(View v)
339 339
        {
340
        if( mObjectPopup!=null ) mObjectPopup.dismiss();
340 341
        int currObject = RubikObjectList.getCurrObject();
341 342
        act.switchConfig(currObject);
342 343
        }

Also available in: Unified diff