Project

General

Profile

« Previous | Next » 

Revision ca280c3f

Added by Leszek Koltunski over 2 years ago

Make the BandagedPlay use FastScramble. (static 500 times)

View differences:

src/main/java/org/distorted/bandaged/BandagedCreatorScreen.java
40 40
import org.distorted.main.R;
41 41
import org.distorted.main.RubikActivity;
42 42

  
43
import static org.distorted.objectlib.scrambling.ScrambleStateBandagedCuboid.MAX_SUPPORTED_SIZE;
44

  
43 45
///////////////////////////////////////////////////////////////////////////////////////////////////
44 46

  
45 47
public class BandagedCreatorScreen implements AdapterView.OnItemSelectedListener
46 48
{
47
  public static final int MAX_SUPPORTED_SIZE = 5;
48

  
49 49
  private WeakReference<BandagedCreatorActivity> mAct;
50 50
  private TransparentImageButton mBackButton, mResetButton, mDoneButton;
51 51
  private LinearLayout mObjectView;
src/main/java/org/distorted/bandaged/BandagedPlayScreen.java
19 19

  
20 20
package org.distorted.bandaged;
21 21

  
22
import java.util.Random;
23

  
24 22
import android.app.Activity;
25 23
import android.content.SharedPreferences;
26
import android.os.Bundle;
27 24
import android.view.View;
28 25
import android.widget.LinearLayout;
29 26

  
30
import org.distorted.dialogs.RubikDialogBandagedSettings;
31 27
import org.distorted.helpers.LockController;
32 28
import org.distorted.helpers.MovesController;
33 29
import org.distorted.helpers.TransparentImageButton;
34 30
import org.distorted.main.R;
35 31
import org.distorted.objectlib.main.ObjectControl;
36
import org.distorted.objectlib.main.TwistyObject;
37 32

  
38 33
///////////////////////////////////////////////////////////////////////////////////////////////////
39 34

  
40 35
public class BandagedPlayScreen
41 36
{
42
  public static final int[] DEPTHS = new int[] {20,50,100,200,500,1000};
43
  public static final int ANIMATION_ON  = 0;
44
  public static final int ANIMATION_OFF = 1;
37
  private static final int NUM_SCRAMBLES = 500;
45 38

  
46
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton, mSettingsButton;
39
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
47 40
  private final LockController mLockController;
48 41
  private final MovesController mMovesController;
49 42
  private String mKey;
50
  private int[][] mMoves;
51
  private Random mRnd;
52

  
53
  private int mAnimationMode;
54
  private int mScrambleDepth;
55 43

  
56 44
///////////////////////////////////////////////////////////////////////////////////////////////////
57 45

  
......
81 69
      });
82 70
    }
83 71

  
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85

  
86
  private void setupSettingsButton(final BandagedPlayActivity act)
87
    {
88
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_settings,R.drawable.ui_medium_settings, R.drawable.ui_big_settings, R.drawable.ui_huge_settings);
89
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
90
    mSettingsButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
91

  
92
    mSettingsButton.setOnClickListener( new View.OnClickListener()
93
      {
94
      @Override
95
      public void onClick(View v)
96
        {
97
        Bundle bundle = new Bundle();
98
        bundle.putInt("scraPos", mScrambleDepth );
99
        bundle.putInt("animPos", mAnimationMode );
100

  
101
        RubikDialogBandagedSettings setDiag = new RubikDialogBandagedSettings();
102
        setDiag.setArguments(bundle);
103
        setDiag.show(act.getSupportFragmentManager(), null);
104
        }
105
      });
106
    }
107

  
108 72
///////////////////////////////////////////////////////////////////////////////////////////////////
109 73

  
110 74
  private void setupSolveButton(final BandagedPlayActivity act)
......
119 83
      public void onClick(View v)
120 84
        {
121 85
        ObjectControl control = act.getControl();
122
        if( mAnimationMode==ANIMATION_OFF ) control.solveOnly();
123
        if( mAnimationMode==ANIMATION_ON  ) control.solveObject();
86
        control.solveObject();
124 87
        mMovesController.clearMoves(act);
125 88
        }
126 89
      });
......
140 103
      public void onClick(View v)
141 104
        {
142 105
        ObjectControl control = act.getControl();
143
        TwistyObject object = control.getObject();
144

  
145
        int depth = DEPTHS[mScrambleDepth];
146

  
147
        if( mAnimationMode==ANIMATION_OFF )
148
          {
149
          if( mMoves==null || mMoves.length<depth ) mMoves = new int[depth][3];
150
          if( mRnd==null ) mRnd = new Random();
151

  
152
          for(int move=0; move<depth; move++)
153
            {
154
            object.randomizeNewScramble(mMoves, mRnd, move, depth);
155
            }
156
          for(int move=0; move<depth; move++)
157
            {
158
            int row = mMoves[move][1];
159
            mMoves[move][1] = (1<<row);
160
            }
161

  
162
          control.initializeObject(mMoves);
163
          }
164

  
165
        if( mAnimationMode==ANIMATION_ON )
166
          {
167
          control.scrambleObject(depth);
168
          }
106
        control.fastScrambleObject(NUM_SCRAMBLES);
107
        mMovesController.clearMoves(act);
169 108
        }
170 109
      });
171 110
    }
......
205 144
    layoutLower.addView(layoutRight);
206 145

  
207 146
    setupSolveButton(act);
208
    setupSettingsButton(act);
209 147
    setupScrambleButton(act);
210 148

  
211 149
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
......
218 156
    layoutRightU.setLayoutParams(paramsR);
219 157

  
220 158
    layoutLeftU.addView(mSolveButton);
221
    layoutMidU.addView(mSettingsButton);
222 159
    layoutRightU.addView(mScrambleButton);
223 160

  
224 161
    layoutUpper.removeAllViews();
......
257 194
    mMovesController.savePreferences(mKey,editor);
258 195
    ObjectControl control = act.getControl();
259 196
    control.savePreferences(editor);
260

  
261
    editor.putInt("playScreen_scramble" , mScrambleDepth);
262
    editor.putInt("playScreen_animation", mAnimationMode);
263 197
    }
264 198

  
265 199
///////////////////////////////////////////////////////////////////////////////////////////////////
......
269 203
    mMovesController.restorePreferences(act,mKey,preferences);
270 204
    ObjectControl control = act.getControl();
271 205
    control.restorePreferences(preferences);
272

  
273
    mScrambleDepth = preferences.getInt("playScreen_scramble" ,3);
274
    mAnimationMode = preferences.getInt("playScreen_animation",ANIMATION_OFF);
275
    }
276

  
277
///////////////////////////////////////////////////////////////////////////////////////////////////
278

  
279
  public void setAnimationMode(int mode)
280
    {
281
    mAnimationMode = mode;
282
    }
283

  
284
///////////////////////////////////////////////////////////////////////////////////////////////////
285

  
286
  public void setScrambleDepth(int depth)
287
    {
288
    mScrambleDepth = depth;
289 206
    }
290 207
}
src/main/java/org/distorted/dialogs/RubikDialogBandagedSettings.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.bandaged.BandagedPlayActivity;
42
import org.distorted.bandaged.BandagedPlayScreen;
43
import org.distorted.main.R;
44
import org.distorted.main.RubikActivity;
45

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

  
48
public class RubikDialogBandagedSettings 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 = BandagedPlayScreen.DEPTHS.length;
58
    String[] ret = new String[len];
59

  
60
    for(int i=0; i<len; i++)
61
      {
62
      ret[i] = String.valueOf(BandagedPlayScreen.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
    final BandagedPlayActivity bact = (BandagedPlayActivity)getContext();
163

  
164
    builder.setCancelable(true);
165
    builder.setPositiveButton( R.string.ok, new DialogInterface.OnClickListener()
166
      {
167
      @Override
168
      public void onClick(DialogInterface dialog, int which)
169
        {
170
        BandagedPlayScreen screen = bact!=null ? bact.getScreen() : null;
171

  
172
        if( screen!=null )
173
          {
174
          screen.setScrambleDepth(mScraPos);
175
          screen.setAnimationMode(mAnimPos);
176
          }
177
        }
178
      });
179

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

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

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

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

  
203
    return dialog;
204
    }
205
  }
src/main/java/org/distorted/screens/RubikScreenPlay.java
366 366
        {
367 367
        int currObject = RubikObjectList.getCurrObject();
368 368
        RubikObject object = RubikObjectList.getObject(currObject);
369
        int numScrambles = object==null ? 0 : object.getNumScramble();
369
        int numScrambles = object==null ? 0 : 2*object.getNumScramble();
370 370
        mShouldReactToEndOfScrambling = false;
371 371
        act.getControl().fastScrambleObject(numScrambles);
372 372
        }
src/main/java/org/distorted/tutorials/TutorialScreen.java
75 75
        {
76 76
        int object = RubikObjectList.getCurrObject();
77 77
        RubikObject obj = RubikObjectList.getObject(object);
78
        int numScrambles = obj==null ? 0 : obj.getNumScramble();
78
        int numScrambles = obj==null ? 0 : 2*obj.getNumScramble();
79 79
        act.getControl().fastScrambleObject(numScrambles);
80 80
        }
81 81
      });

Also available in: Unified diff