Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 2876aeb6

1 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2 da56b12f Leszek Koltunski
// Copyright 2022 Leszek Koltunski                                                               //
3 9530f6b0 Leszek Koltunski
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6 44fec653 Leszek Koltunski
// 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 9530f6b0 Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
9
10
package org.distorted.bandaged;
11
12 88b94310 Leszek Koltunski
import android.app.Activity;
13
import android.content.SharedPreferences;
14 9530f6b0 Leszek Koltunski
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 b1629e16 Leszek Koltunski
import org.distorted.objectlib.effects.BaseEffect;
22 9530f6b0 Leszek Koltunski
import org.distorted.objectlib.main.ObjectControl;
23
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25
26
public class BandagedPlayScreen
27
{
28 bb3bc6a9 Leszek Koltunski
  private static final int NUM_SCRAMBLES = 300;
29 b72b71a1 Leszek Koltunski
30 ca280c3f Leszek Koltunski
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
31 9530f6b0 Leszek Koltunski
  private final LockController mLockController;
32 b72b71a1 Leszek Koltunski
  private final MovesController mMovesController;
33 972f9eae Leszek Koltunski
  private String mKey;
34 9530f6b0 Leszek Koltunski
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36
37
  public BandagedPlayScreen()
38
    {
39
    mLockController = new LockController();
40
    mMovesController= new MovesController();
41
    }
42
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45
  private void setupBackButton(final BandagedPlayActivity act)
46
    {
47 88b94310 Leszek Koltunski
    int icon = BandagedPlayActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
48 9530f6b0 Leszek Koltunski
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
49
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
50
51
    mBackButton.setOnClickListener( new View.OnClickListener()
52
      {
53
      @Override
54
      public void onClick(View v)
55
        {
56
        act.finish();
57
        }
58
      });
59
    }
60
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
63 f3563327 Leszek Koltunski
  private void setupSolveButton(final BandagedPlayActivity act)
64 9530f6b0 Leszek Koltunski
    {
65 f3563327 Leszek Koltunski
    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);
66
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
67
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
68
69
    mSolveButton.setOnClickListener( new View.OnClickListener()
70
      {
71
      @Override
72
      public void onClick(View v)
73
        {
74 b72b71a1 Leszek Koltunski
        ObjectControl control = act.getControl();
75 ca280c3f Leszek Koltunski
        control.solveObject();
76 f3563327 Leszek Koltunski
        mMovesController.clearMoves(act);
77
        }
78
      });
79
    }
80
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82 9530f6b0 Leszek Koltunski
83 f3563327 Leszek Koltunski
  private void setupScrambleButton(final BandagedPlayActivity act)
84
    {
85
    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);
86
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
87
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
88
89
    mScrambleButton.setOnClickListener( new View.OnClickListener()
90
      {
91
      @Override
92
      public void onClick(View v)
93
        {
94 4844152a Leszek Koltunski
        ObjectControl control = act.getControl();
95 b1629e16 Leszek Koltunski
        int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
96
        control.fastScrambleObject(duration,NUM_SCRAMBLES);
97 ca280c3f Leszek Koltunski
        mMovesController.clearMoves(act);
98 f3563327 Leszek Koltunski
        }
99
      });
100
    }
101
102
///////////////////////////////////////////////////////////////////////////////////////////////////
103
104 972f9eae Leszek Koltunski
  void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
105 f3563327 Leszek Koltunski
    {
106 972f9eae Leszek Koltunski
    mKey = "moveController_"+objectName;
107
108 f3563327 Leszek Koltunski
    int width = act.getScreenWidthInPixels();
109 9530f6b0 Leszek Koltunski
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 f3563327 Leszek Koltunski
    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 1db19441 Leszek Koltunski
    setupScrambleButton(act);
138 f3563327 Leszek Koltunski
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 775d5361 Leszek Koltunski
    layoutUpper.removeAllViews();
152 f3563327 Leszek Koltunski
    layoutUpper.addView(layoutLeftU);
153
    layoutUpper.addView(layoutMidU);
154
    layoutUpper.addView(layoutRightU);
155 9530f6b0 Leszek Koltunski
    }
156
157
///////////////////////////////////////////////////////////////////////////////////////////////////
158
159 88b94310 Leszek Koltunski
  public void reddenLock(final BandagedPlayActivity act)
160 9530f6b0 Leszek Koltunski
    {
161
    ObjectControl control = act.getControl();
162
    mLockController.reddenLock(act,control);
163
    }
164 88b94310 Leszek Koltunski
165
///////////////////////////////////////////////////////////////////////////////////////////////////
166
167
  public void addMove(Activity act, int axis, int row, int angle)
168
    {
169
    mMovesController.addMove(act,axis,row,angle);
170
    }
171
172
///////////////////////////////////////////////////////////////////////////////////////////////////
173
174 972f9eae Leszek Koltunski
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
175 88b94310 Leszek Koltunski
    {
176 972f9eae Leszek Koltunski
    mMovesController.savePreferences(mKey,editor);
177
    ObjectControl control = act.getControl();
178
    control.savePreferences(editor);
179 88b94310 Leszek Koltunski
    }
180
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182
183 972f9eae Leszek Koltunski
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
184 88b94310 Leszek Koltunski
    {
185 972f9eae Leszek Koltunski
    mMovesController.restorePreferences(act,mKey,preferences);
186
    ObjectControl control = act.getControl();
187
    control.restorePreferences(preferences);
188 b72b71a1 Leszek Koltunski
    }
189 9530f6b0 Leszek Koltunski
}