Project

General

Profile

Download (8.96 KB) Statistics
| Branch: | Tag: | Revision:

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 972f9eae

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.bandaged;
21

    
22
import android.app.Activity;
23
import android.content.SharedPreferences;
24
import android.view.View;
25
import android.widget.LinearLayout;
26

    
27
import org.distorted.helpers.LockController;
28
import org.distorted.helpers.MovesController;
29
import org.distorted.helpers.TransparentImageButton;
30
import org.distorted.main.R;
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objectlib.main.TwistyObject;
33
import org.distorted.objectlib.scrambling.ObjectScrambler;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class BandagedPlayScreen
38
{
39
  private static final int NUM_SCRAMBLES = 24;
40

    
41
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
42
  private final LockController mLockController;
43
  private MovesController mMovesController;
44
  private String mKey;
45

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

    
48
  public BandagedPlayScreen()
49
    {
50
    mLockController = new LockController();
51
    mMovesController= new MovesController();
52
    }
53

    
54
///////////////////////////////////////////////////////////////////////////////////////////////////
55

    
56
  private void setupBackButton(final BandagedPlayActivity act)
57
    {
58
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
59
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
60
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
61

    
62
    mBackButton.setOnClickListener( new View.OnClickListener()
63
      {
64
      @Override
65
      public void onClick(View v)
66
        {
67
        ObjectControl control = act.getControl();
68
        if( control!=null ) control.unblockEverything();
69
        act.finish();
70
        }
71
      });
72
    }
73

    
74
///////////////////////////////////////////////////////////////////////////////////////////////////
75

    
76
  private void setupSolveButton(final BandagedPlayActivity act)
77
    {
78
    int icon = BandagedPlayActivity.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);
79
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
80
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
81

    
82
    mSolveButton.setOnClickListener( new View.OnClickListener()
83
      {
84
      @Override
85
      public void onClick(View v)
86
        {
87
        act.getControl().solveObject();
88
        mMovesController.clearMoves(act);
89
        }
90
      });
91
    }
92

    
93
///////////////////////////////////////////////////////////////////////////////////////////////////
94

    
95
  private void setupScrambleButton(final BandagedPlayActivity act)
96
    {
97
    int icon = BandagedPlayActivity.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);
98
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
99
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
100

    
101
    mScrambleButton.setOnClickListener( new View.OnClickListener()
102
      {
103
      @Override
104
      public void onClick(View v)
105
        {
106
        ObjectControl control = act.getControl();
107
        TwistyObject object = control.getObject();
108
        ObjectScrambler.setSignature(object.getSignature());
109
        control.scrambleObject(NUM_SCRAMBLES);
110
        }
111
      });
112
    }
113

    
114
///////////////////////////////////////////////////////////////////////////////////////////////////
115

    
116
  void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
117
    {
118
    mKey = "moveController_"+objectName;
119

    
120
    int width = act.getScreenWidthInPixels();
121

    
122
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
123
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
124
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
125

    
126
    LinearLayout layoutLeft = new LinearLayout(act);
127
    layoutLeft.setLayoutParams(paramsL);
128
    LinearLayout layoutMid  = new LinearLayout(act);
129
    layoutMid.setLayoutParams(paramsM);
130
    LinearLayout layoutRight= new LinearLayout(act);
131
    layoutRight.setLayoutParams(paramsR);
132

    
133
    setupBackButton(act);
134
    ObjectControl control = act.getControl();
135
    mMovesController.setupButton(act,control);
136
    layoutLeft.addView(mMovesController.getButton());
137
    mLockController.setupButton(act,control);
138
    layoutMid.addView(mLockController.getButton());
139

    
140
    layoutRight.addView(mBackButton);
141

    
142
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
143
    layoutLower.removeAllViews();
144
    layoutLower.addView(layoutLeft);
145
    layoutLower.addView(layoutMid);
146
    layoutLower.addView(layoutRight);
147

    
148
    setupScrambleButton(act);
149
    setupSolveButton(act);
150

    
151
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
152

    
153
    LinearLayout layoutLeftU = new LinearLayout(act);
154
    layoutLeftU.setLayoutParams(paramsL);
155
    LinearLayout layoutMidU  = new LinearLayout(act);
156
    layoutMidU.setLayoutParams(paramsM);
157
    LinearLayout layoutRightU= new LinearLayout(act);
158
    layoutRightU.setLayoutParams(paramsR);
159

    
160
    layoutLeftU.addView(mSolveButton);
161
    layoutRightU.addView(mScrambleButton);
162

    
163
    layoutUpper.removeAllViews();
164
    layoutUpper.addView(layoutLeftU);
165
    layoutUpper.addView(layoutMidU);
166
    layoutUpper.addView(layoutRightU);
167
    }
168

    
169
///////////////////////////////////////////////////////////////////////////////////////////////////
170

    
171
  public void setLockState(final BandagedPlayActivity act)
172
    {
173
    boolean locked = act.getControl().retLocked();
174
    mLockController.setState(act,locked);
175
    }
176

    
177
///////////////////////////////////////////////////////////////////////////////////////////////////
178

    
179
  public void reddenLock(final BandagedPlayActivity act)
180
    {
181
    ObjectControl control = act.getControl();
182
    mLockController.reddenLock(act,control);
183
    }
184

    
185
///////////////////////////////////////////////////////////////////////////////////////////////////
186

    
187
  public void addMove(Activity act, int axis, int row, int angle)
188
    {
189
    mMovesController.addMove(act,axis,row,angle);
190
    }
191

    
192
///////////////////////////////////////////////////////////////////////////////////////////////////
193

    
194
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
195
    {
196
    mMovesController.savePreferences(mKey,editor);
197
    ObjectControl control = act.getControl();
198
    control.savePreferences(editor);
199
    }
200

    
201
///////////////////////////////////////////////////////////////////////////////////////////////////
202

    
203
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
204
    {
205
    mMovesController.restorePreferences(act,mKey,preferences);
206
    ObjectControl control = act.getControl();
207
    control.restorePreferences(preferences);
208
    }
209
}
(12-12/13)