Project

General

Profile

« Previous | Next » 

Revision 4f3e2d90

Added by Leszek Koltunski over 2 years ago

Progress with central menu popup.

View differences:

src/main/java/org/distorted/dialogs/RubikDialogFreePlaySettings.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2019 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.dialogs;
21

  
22
import android.app.Dialog;
23
import android.content.DialogInterface;
24
import android.os.Bundle;
25
import android.util.DisplayMetrics;
26
import android.util.TypedValue;
27
import android.view.LayoutInflater;
28
import android.view.View;
29
import android.view.Window;
30
import android.widget.AdapterView;
31
import android.widget.ArrayAdapter;
32
import android.widget.Button;
33
import android.widget.Spinner;
34
import android.widget.TextView;
35

  
36
import androidx.annotation.NonNull;
37
import androidx.appcompat.app.AlertDialog;
38
import androidx.appcompat.app.AppCompatDialogFragment;
39
import androidx.fragment.app.FragmentActivity;
40

  
41
import org.distorted.main.RubikActivity;
42
import org.distorted.screens.RubikScreenFreePlay;
43
import org.distorted.main.R;
44
import org.distorted.screens.ScreenList;
45

  
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

  
48
public class RubikDialogFreePlaySettings extends AppCompatDialogFragment implements AdapterView.OnItemSelectedListener
49
  {
50
  private int mAnimPos, mScraPos;
51
  private float mTextSize;
52

  
53
///////////////////////////////////////////////////////////////////////////////////////////////////
54

  
55
  private String[] createScrambleModes()
56
    {
57
    int len = RubikScreenFreePlay.DEPTHS.length;
58
    String[] ret = new String[len];
59

  
60
    for(int i=0; i<len; i++)
61
      {
62
      ret[i] = String.valueOf(RubikScreenFreePlay.DEPTHS[i]);
63
      }
64

  
65
    return ret;
66
    }
67

  
68
///////////////////////////////////////////////////////////////////////////////////////////////////
69

  
70
  private void configureView(FragmentActivity act, View view, float textSize, int scraPos, int animPos)
71
    {
72
    TextView text1 = view.findViewById(R.id.bandaged_text_depth);
73
    text1.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
74
    TextView text2 = view.findViewById(R.id.bandaged_text_animation);
75
    text2.setTextSize(TypedValue.COMPLEX_UNIT_PX, textSize);
76

  
77
    mScraPos = scraPos;
78
    mAnimPos = animPos;
79

  
80
    Spinner scramble = view.findViewById(R.id.bandaged_spinner_scramble);
81
    scramble.setOnItemSelectedListener(this);
82
    String[] scrambleModes = createScrambleModes();
83

  
84
    ArrayAdapter<String> scrambleAdapter = new ArrayAdapter<>(act, R.layout.spinner_item, scrambleModes );
85
    scrambleAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
86
    scramble.setAdapter(scrambleAdapter);
87
    scramble.setSelection(mScraPos,true);
88
    View v1 = scramble.getSelectedView();
89
    ((TextView)v1).setTextSize(TypedValue.COMPLEX_UNIT_PX,mTextSize);
90

  
91
    Spinner animation = view.findViewById(R.id.bandaged_spinner_animation);
92
    animation.setOnItemSelectedListener(this);
93
    String[] animationModes = { "ON" , "OFF" };
94

  
95
    ArrayAdapter<String> animationAdapter = new ArrayAdapter<>(act, R.layout.spinner_item, animationModes );
96
    animationAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
97
    animation.setAdapter(animationAdapter);
98
    animation.setSelection(mAnimPos,true);
99
    View v2 = animation.getSelectedView();
100
    ((TextView)v2).setTextSize(TypedValue.COMPLEX_UNIT_PX,mTextSize);
101
    }
102

  
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104

  
105
  @Override
106
  public void onItemSelected(AdapterView<?> parent, View view, int pos, long id)
107
    {
108
    int spinnerID = parent.getId();
109

  
110
    ((TextView) view).setTextSize(TypedValue.COMPLEX_UNIT_PX,mTextSize);
111

  
112
    if( spinnerID == R.id.bandaged_spinner_scramble )
113
      {
114
      mScraPos = pos;
115
      }
116
    else if( spinnerID == R.id.bandaged_spinner_animation )
117
      {
118
      mAnimPos = pos;
119
      }
120
    }
121

  
122
///////////////////////////////////////////////////////////////////////////////////////////////////
123

  
124
  @Override
125
  public void onNothingSelected(AdapterView<?> parent) { }
126

  
127
///////////////////////////////////////////////////////////////////////////////////////////////////
128

  
129
  @NonNull
130
  @Override
131
  public Dialog onCreateDialog(Bundle savedInstanceState)
132
    {
133
    FragmentActivity act = getActivity();
134
    LayoutInflater inflater = act.getLayoutInflater();
135
    AlertDialog.Builder builder = new AlertDialog.Builder(act);
136

  
137
    DisplayMetrics displaymetrics = new DisplayMetrics();
138
    act.getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
139
    final float titleSize= displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
140
    final float okSize   = displaymetrics.widthPixels * RubikActivity.DIALOG_BUTTON_SIZE;
141
    mTextSize = displaymetrics.widthPixels * RubikActivity.MENU_BIG_TEXT_SIZE;
142

  
143
    TextView tv = (TextView) inflater.inflate(R.layout.dialog_title, null);
144
    tv.setTextSize(TypedValue.COMPLEX_UNIT_PX, titleSize);
145
    tv.setText(R.string.settings);
146
    builder.setCustomTitle(tv);
147

  
148
    Bundle args = getArguments();
149
    int scraPos, animPos;
150

  
151
    try
152
      {
153
      scraPos = args.getInt("scraPos");
154
      animPos = args.getInt("animPos");
155
      }
156
    catch(Exception e)
157
      {
158
      scraPos = 0;
159
      animPos = 0;
160
      }
161

  
162
    builder.setCancelable(true);
163
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
164
      {
165
      @Override
166
      public void onClick(DialogInterface dialog, int which)
167
        {
168
        RubikScreenFreePlay free = (RubikScreenFreePlay) ScreenList.FREE.getScreenClass();
169

  
170
        if( free!=null )
171
          {
172
          free.setScrambleDepth(mScraPos);
173
          free.setAnimationMode(mAnimPos);
174
          }
175
        }
176
      });
177

  
178
    final View view = inflater.inflate(R.layout.dialog_settings, null);
179
    configureView(act,view,mTextSize,scraPos,animPos);
180
    builder.setView(view);
181

  
182
    Dialog dialog = builder.create();
183
    dialog.setCanceledOnTouchOutside(false);
184
    Window window = dialog.getWindow();
185

  
186
    if( window!=null )
187
      {
188
      window.getDecorView().setSystemUiVisibility(RubikActivity.FLAGS);
189
      }
190

  
191
    dialog.setOnShowListener(new DialogInterface.OnShowListener()
192
      {
193
      @Override
194
      public void onShow(DialogInterface dialog)
195
        {
196
        Button btnPositive = ((AlertDialog)dialog).getButton(Dialog.BUTTON_POSITIVE);
197
        btnPositive.setTextSize(TypedValue.COMPLEX_UNIT_PX, okSize);
198
        }
199
      });
200

  
201
    return dialog;
202
    }
203
  }
src/main/java/org/distorted/main/RubikActivity.java
56 56
import org.distorted.external.RubikNetwork;
57 57
import org.distorted.objects.RubikObject;
58 58
import org.distorted.objects.RubikObjectList;
59
import org.distorted.screens.RubikScreenFreePlay;
60 59
import org.distorted.screens.RubikScreenSolving;
61 60
import org.distorted.screens.ScreenList;
62 61
import org.distorted.screens.RubikScreenPlay;
......
103 102

  
104 103
    private static final String KEY_PLAY = "movesController_play";
105 104
    private static final String KEY_SOLV = "movesController_solv";
106
    public  static final String KEY_FREE = "movesController_free";
107 105

  
108 106
    private boolean mJustStarted;
109 107
    private FirebaseAnalytics mFirebaseAnalytics;
......
334 332
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
335 333
        solv.saveMovePreferences(KEY_SOLV,editor);
336 334
        }
337
      if( curr==ScreenList.FREE )
338
        {
339
        RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass();
340
        free.saveMovePreferences(KEY_FREE,editor);
341
        }
342 335

  
343 336
      editor.apply();
344 337
      }
......
407 400
        RubikScreenSolving solv = (RubikScreenSolving)ScreenList.SOLV.getScreenClass();
408 401
        solv.restoreMovePreferences(this,KEY_SOLV,preferences);
409 402
        }
410
      if( curr==ScreenList.FREE )
411
        {
412
        RubikScreenFreePlay free = (RubikScreenFreePlay)ScreenList.FREE.getScreenClass();
413
        free.restoreMovePreferences(this,KEY_FREE,preferences);
414
        }
415 403
      }
416 404

  
417 405
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/main/RubikObjectLibInterface.java
45 45
import org.distorted.external.RubikScores;
46 46
import org.distorted.objects.RubikObject;
47 47
import org.distorted.objects.RubikObjectList;
48
import org.distorted.screens.RubikScreenFreePlay;
49 48
import org.distorted.screens.RubikScreenPlay;
50 49
import org.distorted.screens.RubikScreenReady;
51 50
import org.distorted.screens.RubikScreenSolver;
......
265 264
      RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
266 265
      play.addMove(mAct.get(), axis, row, angle);
267 266
      }
268
    if( ScreenList.getCurrentScreen()== ScreenList.FREE )
269
      {
270
      RubikScreenFreePlay free = (RubikScreenFreePlay) ScreenList.FREE.getScreenClass();
271
      free.addMove(mAct.get(), axis, row, angle);
272
      }
273 267
    }
274 268

  
275 269
///////////////////////////////////////////////////////////////////////////////////////////////////
......
314 308
      RubikScreenSolving solv = (RubikScreenSolving) ScreenList.SOLV.getScreenClass();
315 309
      solv.reddenLock(mAct.get());
316 310
      }
317
    else if( curr==ScreenList.FREE )
318
      {
319
      RubikScreenFreePlay free = (RubikScreenFreePlay) ScreenList.FREE.getScreenClass();
320
      free.reddenLock(mAct.get());
321
      }
322 311
    }
323 312

  
324 313
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/screens/RubikScreenFreePlay.java
1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

  
20
package org.distorted.screens;
21

  
22
import java.util.Random;
23

  
24
import android.content.SharedPreferences;
25
import android.os.Bundle;
26
import android.view.View;
27
import android.widget.LinearLayout;
28

  
29
import org.distorted.dialogs.RubikDialogFreePlaySettings;
30
import org.distorted.helpers.TransparentImageButton;
31
import org.distorted.main.R;
32
import org.distorted.main.RubikActivity;
33
import org.distorted.objectlib.main.ObjectControl;
34
import org.distorted.objectlib.main.TwistyObject;
35

  
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37

  
38
public class RubikScreenFreePlay extends RubikScreenBase
39
{
40
  public static final int[] DEPTHS = new int[] {20,50,100};
41
  public static final int ANIMATION_ON  = 0;
42
  public static final int ANIMATION_OFF = 1;
43

  
44
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton;
45
  private int[][] mMoves;
46
  private Random mRnd;
47
  private int mAnimationMode;
48
  private int mScrambleDepth;
49

  
50
///////////////////////////////////////////////////////////////////////////////////////////////////
51

  
52
  void leaveScreen(final RubikActivity act)
53
    {
54

  
55
    }
56

  
57
///////////////////////////////////////////////////////////////////////////////////////////////////
58

  
59
  void enterScreen(final RubikActivity act)
60
    {
61
    int width = act.getScreenWidthInPixels();
62

  
63
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
64
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
65
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
66

  
67
    // UPPER PANE /////////////
68

  
69
    setupSolveButton(act);
70
    setupSettingsButton(act);
71
    setupScrambleButton(act);
72

  
73
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
74

  
75
    LinearLayout layoutLeftU = new LinearLayout(act);
76
    layoutLeftU.setLayoutParams(paramsL);
77
    LinearLayout layoutMidU  = new LinearLayout(act);
78
    layoutMidU.setLayoutParams(paramsM);
79
    LinearLayout layoutRightU= new LinearLayout(act);
80
    layoutRightU.setLayoutParams(paramsR);
81

  
82
    layoutLeftU.addView(mSolveButton);
83
    layoutMidU.addView(mSettingsButton);
84
    layoutRightU.addView(mScrambleButton);
85

  
86
    layoutUpper.removeAllViews();
87
    layoutUpper.addView(layoutLeftU);
88
    layoutUpper.addView(layoutMidU);
89
    layoutUpper.addView(layoutRightU);
90

  
91
    // LOWER PANE /////////////
92

  
93
    setupBackButton(act);
94
    createBottomPane(act,mBackButton,null);
95
    }
96

  
97
///////////////////////////////////////////////////////////////////////////////////////////////////
98

  
99
  private void setupBackButton(final RubikActivity act)
100
    {
101
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
102
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
103
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
104

  
105
    mBackButton.setOnClickListener( new View.OnClickListener()
106
      {
107
      @Override
108
      public void onClick(View v)
109
        {
110
        if(act.getControl().isUINotBlocked()) ScreenList.goBack(act);
111
        }
112
      });
113
    }
114

  
115
///////////////////////////////////////////////////////////////////////////////////////////////////
116

  
117
  private void setupSettingsButton(final RubikActivity act)
118
    {
119
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_settings,R.drawable.ui_medium_settings, R.drawable.ui_big_settings, R.drawable.ui_huge_settings);
120
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
121
    mSettingsButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
122

  
123
    mSettingsButton.setOnClickListener( new View.OnClickListener()
124
      {
125
      @Override
126
      public void onClick(View v)
127
        {
128
        if(act.getControl().isUINotBlocked())
129
          {
130
          Bundle bundle = new Bundle();
131
          bundle.putInt("scraPos", mScrambleDepth );
132
          bundle.putInt("animPos", mAnimationMode );
133

  
134
          RubikDialogFreePlaySettings setDiag = new RubikDialogFreePlaySettings();
135
          setDiag.setArguments(bundle);
136
          setDiag.show(act.getSupportFragmentManager(), null);
137
          }
138
        }
139
      });
140
    }
141

  
142
///////////////////////////////////////////////////////////////////////////////////////////////////
143

  
144
  private void setupSolveButton(final RubikActivity act)
145
    {
146
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_solve,R.drawable.ui_medium_cube_solve, R.drawable.ui_big_cube_solve, R.drawable.ui_huge_cube_solve);
147
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
148
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
149

  
150
    mSolveButton.setOnClickListener( new View.OnClickListener()
151
      {
152
      @Override
153
      public void onClick(View v)
154
        {
155
        ObjectControl control = act.getControl();
156
        if( mAnimationMode==ANIMATION_OFF ) control.solveOnly();
157
        if( mAnimationMode==ANIMATION_ON  ) control.solveObject();
158
        mMovesController.clearMoves(act);
159
        }
160
      });
161
    }
162

  
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

  
165
  private void setupScrambleButton(final RubikActivity act)
166
    {
167
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_cube_scramble,R.drawable.ui_medium_cube_scramble, R.drawable.ui_big_cube_scramble, R.drawable.ui_huge_cube_scramble);
168
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
169
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
170

  
171
    mScrambleButton.setOnClickListener( new View.OnClickListener()
172
      {
173
      @Override
174
      public void onClick(View v)
175
        {
176
        ObjectControl control = act.getControl();
177
        TwistyObject object = control.getObject();
178

  
179
        int depth = DEPTHS[mScrambleDepth];
180

  
181
        if( mAnimationMode==ANIMATION_OFF )
182
          {
183
          if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
184
          if( mRnd==null ) mRnd = new Random();
185

  
186
          for(int move=0; move<depth; move++)
187
            {
188
            object.randomizeNewScramble(mMoves, mRnd, move, depth);
189
            }
190
          for(int move=0; move<depth; move++)
191
            {
192
            int row = mMoves[move][1];
193
            mMoves[move][1] = (1<<row);
194
            }
195

  
196
          control.initializeObject(mMoves);
197
          }
198

  
199
        if( mAnimationMode==ANIMATION_ON )
200
          {
201
          control.scrambleObject(depth);
202
          }
203
        }
204
      });
205
    }
206

  
207
///////////////////////////////////////////////////////////////////////////////////////////////////
208

  
209
  public void savePreferences(SharedPreferences.Editor editor)
210
    {
211
    editor.putInt("freePlayScreen_scramble" , mScrambleDepth);
212
    editor.putInt("freePlayScreen_animation", mAnimationMode);
213
    }
214

  
215
///////////////////////////////////////////////////////////////////////////////////////////////////
216

  
217
  public void restorePreferences(SharedPreferences preferences)
218
    {
219
    mScrambleDepth = preferences.getInt("freePlayScreen_scramble" ,1);
220
    mAnimationMode = preferences.getInt("freePlayScreen_animation",ANIMATION_OFF);
221
    }
222

  
223
///////////////////////////////////////////////////////////////////////////////////////////////////
224

  
225
  public void setAnimationMode(int mode)
226
    {
227
    mAnimationMode = mode;
228
    }
229

  
230
///////////////////////////////////////////////////////////////////////////////////////////////////
231

  
232
  public void setScrambleDepth(int depth)
233
    {
234
    mScrambleDepth = depth;
235
    }
236
}
src/main/java/org/distorted/screens/RubikScreenPlay.java
49 49
import org.distorted.dialogs.RubikDialogScores;
50 50
import org.distorted.dialogs.RubikDialogTutorial;
51 51
import org.distorted.helpers.TransparentImageButton;
52
import org.distorted.objectlib.main.ObjectControl;
52 53
import org.distorted.objects.MainEntry;
53 54
import org.distorted.objects.MainEntryList;
54 55
import org.distorted.objects.RubikObject;
......
63 64
  public static final int NUM_COLUMNS  = 5;
64 65
  public static final int LEVELS_SHOWN = 8;
65 66
  private static final int NUM_BUTTONS = 5;
66

  
67 67
  private static final int[] mLocation = new int[2];
68 68

  
69 69
  private TransparentImageButton mObjButton, mMenuButton, mSolveButton, mScrambleButton;
70
  private PopupWindow mObjectPopup, mMenuPopup, mPlayPopup;
71

  
70
  private PopupWindow mObjectPopup, mMenuPopup;
71
  private WeakReference<RubikActivity> mWeakAct;
72 72
  private TextView mBubbleUpdates;
73 73
  private int mObjectSize, mMenuLayoutWidth, mMenuLayoutHeight, mMenuButtonHeight;
74 74
  private int mLevelValue;
......
76 76
  private int mUpperBarHeight;
77 77
  private boolean mShouldReactToEndOfScrambling;
78 78
  private float mScreenWidth;
79
  private WeakReference<RubikActivity> mWeakAct;
80
  private String mObjectsPlayed;
81 79

  
82 80
///////////////////////////////////////////////////////////////////////////////////////////////////
83 81

  
......
380 378
    mMenuPopup = new PopupWindow(act);
381 379
    mMenuPopup.setContentView(layout);
382 380
    mMenuPopup.setFocusable(true);
383
    int margin  = (int)(width*RubikActivity.SMALL_MARGIN);
384 381
    int padding = (int)(width*RubikActivity.MEDIUM_MARGIN);
385 382

  
386 383
    mMenuLayoutWidth = (int)(width*0.6f);
387
    mMenuLayoutHeight= (int)(2*padding + NUM_BUTTONS*(mMenuButtonHeight+margin));
384
    mMenuLayoutHeight= (int)( padding + NUM_BUTTONS*(mMenuButtonHeight+padding) + 4*mMenuButtonHeight+5*padding);
388 385

  
389 386
    layout.setPadding(padding,0,padding,0);
390 387

  
......
451 448
          aDiag.show(act.getSupportFragmentManager(), null);
452 449
          }
453 450
        });
451

  
452
    setupLevelButtons(act,layout,padding);
453
    }
454

  
455
///////////////////////////////////////////////////////////////////////////////////////////////////
456

  
457
  private void setupLevelButtons(RubikActivity act, View layout, int padding)
458
    {
459
    int sizeW = (mMenuLayoutWidth-4*padding)/3;
460
    int sizeH = (int)(sizeW*0.85f);
461
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(sizeW,sizeH);
462
    params.setMargins(padding/2,0,padding/2,0);
463

  
464
    Button level1 = layout.findViewById(R.id.level1);
465
    level1.setLayoutParams(params);
466
    setupLevelButton(act,level1,1);
467
    Button level2 = layout.findViewById(R.id.level2);
468
    level2.setLayoutParams(params);
469
    setupLevelButton(act,level2,2);
470
    Button level3 = layout.findViewById(R.id.level3);
471
    level3.setLayoutParams(params);
472
    setupLevelButton(act,level3,3);
473
    Button level4 = layout.findViewById(R.id.level4);
474
    level4.setLayoutParams(params);
475
    setupLevelButton(act,level4,4);
476
    Button level5 = layout.findViewById(R.id.level5);
477
    level5.setLayoutParams(params);
478
    setupLevelButton(act,level5,5);
479
    Button level6 = layout.findViewById(R.id.level6);
480
    level6.setLayoutParams(params);
481
    setupLevelButton(act,level6,6);
482
    Button level7 = layout.findViewById(R.id.level7);
483
    level7.setLayoutParams(params);
484
    setupLevelButton(act,level7,7);
485
    Button level8 = layout.findViewById(R.id.level8);
486
    level8.setLayoutParams(params);
487
    setupLevelButton(act,level8,8);
488
    Button levelM = layout.findViewById(R.id.levelM);
489
    levelM.setLayoutParams(params);
490
    setupLevelButton(act,levelM,9);
491
    }
492

  
493
///////////////////////////////////////////////////////////////////////////////////////////////////
494

  
495
  private void setupLevelButton(RubikActivity act, Button button, int level)
496
    {
497
    button.setOnClickListener( new View.OnClickListener()
498
        {
499
        @Override
500
        public void onClick(View v)
501
          {
502
          ObjectControl control = act.getControl();
503

  
504
          if(control.isUINotBlocked())
505
            {
506
            if( mMenuPopup!=null ) mMenuPopup.dismiss();
507

  
508
            int currObject = RubikObjectList.getCurrObject();
509
            RubikObject object = RubikObjectList.getObject(currObject);
510
            final int scrambles = level<=LEVELS_SHOWN ? level : (object==null ? 0 : object.getNumScramble());
511

  
512
            mLevelValue = level;
513
            mShouldReactToEndOfScrambling = true;
514
            control.scrambleObject(scrambles);
515
            }
516
          }
517
        });
454 518
    }
455 519

  
456 520
///////////////////////////////////////////////////////////////////////////////////////////////////
......
462 526
  public void savePreferences(SharedPreferences.Editor editor)
463 527
    {
464 528
    editor.putInt("play_LevelValue", mLevelValue );
465
    editor.putString("play_objectsPlayed", mObjectsPlayed );
466 529

  
467 530
    if( mObjectPopup!=null )
468 531
      {
......
475 538
      mMenuPopup.dismiss();
476 539
      mMenuPopup = null;
477 540
      }
478

  
479
    if( mPlayPopup!=null )
480
      {
481
      mPlayPopup.dismiss();
482
      mPlayPopup = null;
483
      }
484
    }
485

  
486
///////////////////////////////////////////////////////////////////////////////////////////////////
487

  
488
  private void addToPlayedObjects()
489
    {
490
    String name = RubikObjectList.getCurrentName();
491
    if( !mObjectsPlayed.contains(name) ) mObjectsPlayed += (" "+name);
492
    }
493

  
494
///////////////////////////////////////////////////////////////////////////////////////////////////
495

  
496
  private boolean hasBeenPlayed()
497
    {
498
    String name = RubikObjectList.getCurrentName();
499
    return mObjectsPlayed.contains(name);
500 541
    }
501 542

  
502 543
///////////////////////////////////////////////////////////////////////////////////////////////////
......
504 545
  public void restorePreferences(SharedPreferences preferences)
505 546
    {
506 547
    mLevelValue    = preferences.getInt("play_LevelValue", 0);
507
    mObjectsPlayed = preferences.getString("play_objectsPlayed", "");
508 548
    }
509 549

  
510 550
///////////////////////////////////////////////////////////////////////////////////////////////////
src/main/java/org/distorted/screens/ScreenList.java
38 38
  SOLU ( SVER , MODE_DRAG   , new RubikScreenSolution() ),
39 39
  READ ( PLAY , MODE_ROTATE , new RubikScreenReady()    ),
40 40
  DONE ( PLAY , MODE_DRAG   , new RubikScreenDone()     ),
41
  FREE ( PLAY , MODE_ROTATE , new RubikScreenFreePlay() ),
42 41
  ;
43 42

  
44 43
  public static final int LENGTH = values().length;
src/main/res/layout/popup_menu.xml
65 65
      android:singleLine="true"
66 66
      android:backgroundTint="@color/dark_grey"
67 67
      android:gravity="center"/>
68

  
69
   <TextView
70
       android:layout_width="match_parent"
71
       android:text="@string/levels"
72
       android:layout_height="0dp"
73
       android:layout_weight="0.7"
74
       android:gravity="center"/>
75

  
76
   <LinearLayout
77
        android:layout_width="match_parent"
78
        android:layout_height="0dp"
79
        android:layout_weight="1.0"
80
        android:gravity="center"
81
        android:orientation="horizontal">
82

  
83
        <Button
84
           android:id="@+id/level1"
85
           android:text="1"
86
           android:layout_width="30dp"
87
           android:layout_height="30dp"
88
           android:paddingRight="10dp"
89
           android:paddingLeft="10dp"
90
           android:backgroundTint="@color/dark_grey"/>
91
        <Button
92
           android:id="@+id/level2"
93
           android:text="2"
94
           android:layout_width="30dp"
95
           android:layout_height="30dp"
96
           android:paddingRight="10dp"
97
           android:paddingLeft="10dp"
98
           android:backgroundTint="@color/dark_grey"/>
99
        <Button
100
           android:id="@+id/level3"
101
           android:text="3"
102
           android:layout_width="30dp"
103
           android:layout_height="30dp"
104
           android:paddingRight="10dp"
105
           android:paddingLeft="10dp"
106
           android:backgroundTint="@color/dark_grey"/>
107
   </LinearLayout>
108

  
109
   <LinearLayout
110
        android:layout_width="match_parent"
111
        android:layout_height="0dp"
112
        android:layout_weight="1.0"
113
        android:gravity="center"
114
        android:orientation="horizontal">
115

  
116
        <Button
117
           android:id="@+id/level4"
118
           android:text="4"
119
           android:layout_width="30dp"
120
           android:layout_height="30dp"
121
           android:paddingRight="10dp"
122
           android:paddingLeft="10dp"
123
           android:backgroundTint="@color/dark_grey"/>
124
        <Button
125
           android:id="@+id/level5"
126
           android:text="5"
127
           android:layout_width="30dp"
128
           android:layout_height="30dp"
129
           android:paddingRight="10dp"
130
           android:paddingLeft="10dp"
131
           android:backgroundTint="@color/dark_grey"/>
132
        <Button
133
           android:id="@+id/level6"
134
           android:text="6"
135
           android:layout_width="30dp"
136
           android:layout_height="30dp"
137
           android:paddingRight="10dp"
138
           android:paddingLeft="10dp"
139
           android:backgroundTint="@color/dark_grey"/>
140
   </LinearLayout>
141

  
142
   <LinearLayout
143
        android:layout_width="match_parent"
144
        android:layout_height="0dp"
145
        android:layout_weight="1.0"
146
        android:gravity="center"
147
        android:orientation="horizontal">
148

  
149
        <Button
150
           android:id="@+id/level7"
151
           android:text="7"
152
           android:layout_width="30dp"
153
           android:layout_height="30dp"
154
           android:paddingRight="10dp"
155
           android:paddingLeft="10dp"
156
           android:backgroundTint="@color/dark_grey"/>
157
        <Button
158
           android:id="@+id/level8"
159
           android:text="8"
160
           android:layout_width="30dp"
161
           android:layout_height="30dp"
162
           android:paddingRight="10dp"
163
           android:paddingLeft="10dp"
164
           android:backgroundTint="@color/dark_grey"/>
165
        <Button
166
           android:id="@+id/levelM"
167
           android:text="MAX"
168
           android:layout_width="30dp"
169
           android:layout_height="30dp"
170
           android:paddingRight="10dp"
171
           android:paddingLeft="10dp"
172
           android:backgroundTint="@color/dark_grey"/>
173
   </LinearLayout>
68 174
</LinearLayout>
src/main/res/values-de/strings.xml
37 37
    <string name="view">Sehen</string>
38 38
    <string name="free_play">Freies Spiel</string>
39 39
    <string name="level_full">Volles Scramble</string>
40
    <string name="levels">Ebenen</string>
40 41
    <string name="save_object">Speichern</string>
41 42
    <string name="save_object_really">Möchten Sie diesen Cube speichern?</string>
42 43
    <string name="delete_object">Löschen</string>
src/main/res/values-es/strings.xml
37 37
    <string name="view">Ver</string>
38 38
    <string name="free_play">Juego libre</string>
39 39
    <string name="level_full">Revuelto Completo</string>
40
    <string name="levels">Niveles</string>
40 41
    <string name="save_object">Guardar</string>
41 42
    <string name="save_object_really">¿Quieres guardar este Cubo?</string>
42 43
    <string name="delete_object">Borrar</string>
src/main/res/values-fr/strings.xml
37 37
    <string name="view">Regarder</string>
38 38
    <string name="free_play">Jeu libre</string>
39 39
    <string name="level_full">Brouillage Complet</string>
40
    <string name="levels">Niveaux</string>
40 41
    <string name="save_object">Enregistrer</string>
41 42
    <string name="save_object_really">Voulez-vous enregistrer ce Cube?</string>
42 43
    <string name="delete_object">Supprimer</string>
src/main/res/values-ja/strings.xml
37 37
    <string name="view">見る</string>
38 38
    <string name="free_play">無料プレイ</string>
39 39
    <string name="level_full">フルスクランブル</string>
40
    <string name="levels">レベル</string>
40 41
    <string name="save_object">保存</string>
41 42
    <string name="save_object_really">このキューブを保存しますか?</string>
42 43
    <string name="delete_object">消す</string>
src/main/res/values-ko/strings.xml
37 37
    <string name="view">보다</string>
38 38
    <string name="free_play">게임</string>
39 39
    <string name="level_full">풀 스크램블</string>
40
    <string name="levels">레벨</string>
40 41
    <string name="save_object">저장</string>
41 42
    <string name="save_object_really">이 큐브를 저장하시겠습니까?</string>
42 43
    <string name="delete_object">삭제</string>
src/main/res/values-pl/strings.xml
37 37
    <string name="view">Zobacz</string>
38 38
    <string name="free_play">Zabawa z Kostką</string>
39 39
    <string name="level_full">Pełne Pomieszanie</string>
40
    <string name="levels">Poziomy</string>
40 41
    <string name="save_object">Zapisz</string>
41 42
    <string name="save_object_really">Chcesz zapisać tą kostkę?</string>
42 43
    <string name="delete_object">Usuń</string>
src/main/res/values-ru/strings.xml
37 37
    <string name="view">Смотри</string>
38 38
    <string name="free_play">Игра с кубом</string>
39 39
    <string name="level_full">Полная Схватка</string>
40
    <string name="levels">Уровни</string>
40 41
    <string name="save_object">Сохранять</string>
41 42
    <string name="save_object_really">Вы хотите сохранить этот куб?</string>
42 43
    <string name="delete_object">Удалить</string>
src/main/res/values-zh-rCN/strings.xml
37 37
    <string name="view">看</string>
38 38
    <string name="free_play">玩立方体</string>
39 39
    <string name="level_full">级满</string>
40
    <string name="levels">级别</string>
40 41
    <string name="save_object">保存</string>
41 42
    <string name="save_object_really">你想保存这个多维数据集吗?</string>
42 43
    <string name="delete_object">删除</string>
src/main/res/values-zh-rTW/strings.xml
37 37
    <string name="view">看</string>
38 38
    <string name="free_play">玩立方體</string>
39 39
    <string name="level_full">級滿</string>
40
    <string name="levels">級別</string>
40 41
    <string name="save_object">保存</string>
41 42
    <string name="save_object_really">你想保存這個多維數據集嗎?</string>
42 43
    <string name="delete_object">刪除</string>
src/main/res/values/strings.xml
39 39
    <string name="view">View</string>
40 40
    <string name="free_play">Free Play</string>
41 41
    <string name="level_full">Full Scramble</string>
42
    <string name="levels">Levels</string>
42 43
    <string name="save_object">Save</string>
43 44
    <string name="save_object_really">Do you want to save this Cube?</string>
44 45
    <string name="delete_object">Delete</string>

Also available in: Unified diff