Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 306aa049

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 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
package org.distorted.bandaged;
11

    
12
import android.app.Activity;
13
import android.content.SharedPreferences;
14
import android.view.View;
15
import android.widget.LinearLayout;
16

    
17
import org.distorted.helpers.LockController;
18
import org.distorted.helpers.MovesController;
19
import org.distorted.helpers.TransparentImageButton;
20
import org.distorted.main.R;
21
import org.distorted.objectlib.main.ObjectControl;
22

    
23
///////////////////////////////////////////////////////////////////////////////////////////////////
24

    
25
public class BandagedPlayScreen
26
{
27
  private static final int NUM_SCRAMBLES = 300;
28

    
29
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
30
  private final LockController mLockController;
31
  private final MovesController mMovesController;
32
  private String mKey;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  public BandagedPlayScreen()
37
    {
38
    mLockController = new LockController();
39
    mMovesController= new MovesController();
40
    }
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
  private void setupBackButton(final BandagedPlayActivity act)
45
    {
46
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
47
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
48
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
49

    
50
    mBackButton.setOnClickListener( new View.OnClickListener()
51
      {
52
      @Override
53
      public void onClick(View v)
54
        {
55
        ObjectControl control = act.getControl();
56
        if( control!=null ) control.unblockEverything();
57
        act.finish();
58
        }
59
      });
60
    }
61

    
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63

    
64
  private void setupSolveButton(final BandagedPlayActivity act)
65
    {
66
    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);
67
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
68
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
69

    
70
    mSolveButton.setOnClickListener( new View.OnClickListener()
71
      {
72
      @Override
73
      public void onClick(View v)
74
        {
75
        ObjectControl control = act.getControl();
76
        control.solveObject();
77
        mMovesController.clearMoves(act);
78
        }
79
      });
80
    }
81

    
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83

    
84
  private void setupScrambleButton(final BandagedPlayActivity act)
85
    {
86
    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);
87
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
88
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
89

    
90
    mScrambleButton.setOnClickListener( new View.OnClickListener()
91
      {
92
      @Override
93
      public void onClick(View v)
94
        {
95
        ObjectControl control = act.getControl();
96
        control.fastScrambleObject(NUM_SCRAMBLES);
97
        mMovesController.clearMoves(act);
98
        }
99
      });
100
    }
101

    
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103

    
104
  void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
105
    {
106
    mKey = "moveController_"+objectName;
107

    
108
    int width = act.getScreenWidthInPixels();
109

    
110
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
111
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
112
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
113

    
114
    LinearLayout layoutLeft = new LinearLayout(act);
115
    layoutLeft.setLayoutParams(paramsL);
116
    LinearLayout layoutMid  = new LinearLayout(act);
117
    layoutMid.setLayoutParams(paramsM);
118
    LinearLayout layoutRight= new LinearLayout(act);
119
    layoutRight.setLayoutParams(paramsR);
120

    
121
    setupBackButton(act);
122
    ObjectControl control = act.getControl();
123
    mMovesController.setupButton(act,control);
124
    layoutLeft.addView(mMovesController.getButton());
125
    mLockController.setupButton(act,control);
126
    layoutMid.addView(mLockController.getButton());
127

    
128
    layoutRight.addView(mBackButton);
129

    
130
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
131
    layoutLower.removeAllViews();
132
    layoutLower.addView(layoutLeft);
133
    layoutLower.addView(layoutMid);
134
    layoutLower.addView(layoutRight);
135

    
136
    setupSolveButton(act);
137
    setupScrambleButton(act);
138

    
139
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
140

    
141
    LinearLayout layoutLeftU = new LinearLayout(act);
142
    layoutLeftU.setLayoutParams(paramsL);
143
    LinearLayout layoutMidU  = new LinearLayout(act);
144
    layoutMidU.setLayoutParams(paramsM);
145
    LinearLayout layoutRightU= new LinearLayout(act);
146
    layoutRightU.setLayoutParams(paramsR);
147

    
148
    layoutLeftU.addView(mSolveButton);
149
    layoutRightU.addView(mScrambleButton);
150

    
151
    layoutUpper.removeAllViews();
152
    layoutUpper.addView(layoutLeftU);
153
    layoutUpper.addView(layoutMidU);
154
    layoutUpper.addView(layoutRightU);
155
    }
156

    
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158

    
159
  public void setLockState(final BandagedPlayActivity act)
160
    {
161
    boolean locked = act.getControl().retLocked();
162
    mLockController.setState(act,locked);
163
    }
164

    
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166

    
167
  public void reddenLock(final BandagedPlayActivity act)
168
    {
169
    ObjectControl control = act.getControl();
170
    mLockController.reddenLock(act,control);
171
    }
172

    
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174

    
175
  public void addMove(Activity act, int axis, int row, int angle)
176
    {
177
    mMovesController.addMove(act,axis,row,angle);
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
183
    {
184
    mMovesController.savePreferences(mKey,editor);
185
    ObjectControl control = act.getControl();
186
    control.savePreferences(editor);
187
    }
188

    
189
///////////////////////////////////////////////////////////////////////////////////////////////////
190

    
191
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
192
    {
193
    mMovesController.restorePreferences(act,mKey,preferences);
194
    ObjectControl control = act.getControl();
195
    control.restorePreferences(preferences);
196
    }
197
}
(12-12/13)