Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 789769bd

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 21a1bb5d Leszek Koltunski
import org.distorted.os.OSInterface;
24 9530f6b0 Leszek Koltunski
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26
27
public class BandagedPlayScreen
28
{
29 bb3bc6a9 Leszek Koltunski
  private static final int NUM_SCRAMBLES = 300;
30 b72b71a1 Leszek Koltunski
31 ca280c3f Leszek Koltunski
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
32 9530f6b0 Leszek Koltunski
  private final LockController mLockController;
33 b72b71a1 Leszek Koltunski
  private final MovesController mMovesController;
34 972f9eae Leszek Koltunski
  private String mKey;
35 9530f6b0 Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38
  public BandagedPlayScreen()
39
    {
40
    mLockController = new LockController();
41
    mMovesController= new MovesController();
42
    }
43
44
///////////////////////////////////////////////////////////////////////////////////////////////////
45
46
  private void setupBackButton(final BandagedPlayActivity act)
47
    {
48 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);
49 9530f6b0 Leszek Koltunski
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
50
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
51
52
    mBackButton.setOnClickListener( new View.OnClickListener()
53
      {
54
      @Override
55
      public void onClick(View v)
56
        {
57
        act.finish();
58
        }
59
      });
60
    }
61
62
///////////////////////////////////////////////////////////////////////////////////////////////////
63
64 f3563327 Leszek Koltunski
  private void setupSolveButton(final BandagedPlayActivity act)
65 9530f6b0 Leszek Koltunski
    {
66 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);
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 b72b71a1 Leszek Koltunski
        ObjectControl control = act.getControl();
76 ca280c3f Leszek Koltunski
        control.solveObject();
77 f3563327 Leszek Koltunski
        mMovesController.clearMoves(act);
78
        }
79
      });
80
    }
81
82
///////////////////////////////////////////////////////////////////////////////////////////////////
83 9530f6b0 Leszek Koltunski
84 f3563327 Leszek Koltunski
  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 4844152a Leszek Koltunski
        ObjectControl control = act.getControl();
96 b1629e16 Leszek Koltunski
        int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
97
        control.fastScrambleObject(duration,NUM_SCRAMBLES);
98 ca280c3f Leszek Koltunski
        mMovesController.clearMoves(act);
99 f3563327 Leszek Koltunski
        }
100
      });
101
    }
102
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
105 972f9eae Leszek Koltunski
  void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
106 f3563327 Leszek Koltunski
    {
107 972f9eae Leszek Koltunski
    mKey = "moveController_"+objectName;
108
109 f3563327 Leszek Koltunski
    int width = act.getScreenWidthInPixels();
110 9530f6b0 Leszek Koltunski
111
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
112
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
113
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
114
115
    LinearLayout layoutLeft = new LinearLayout(act);
116
    layoutLeft.setLayoutParams(paramsL);
117
    LinearLayout layoutMid  = new LinearLayout(act);
118
    layoutMid.setLayoutParams(paramsM);
119
    LinearLayout layoutRight= new LinearLayout(act);
120
    layoutRight.setLayoutParams(paramsR);
121
122
    setupBackButton(act);
123
    ObjectControl control = act.getControl();
124
    mMovesController.setupButton(act,control);
125
    layoutLeft.addView(mMovesController.getButton());
126
    mLockController.setupButton(act,control);
127
    layoutMid.addView(mLockController.getButton());
128
129
    layoutRight.addView(mBackButton);
130
131 f3563327 Leszek Koltunski
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
132
    layoutLower.removeAllViews();
133
    layoutLower.addView(layoutLeft);
134
    layoutLower.addView(layoutMid);
135
    layoutLower.addView(layoutRight);
136
137
    setupSolveButton(act);
138 1db19441 Leszek Koltunski
    setupScrambleButton(act);
139 f3563327 Leszek Koltunski
140
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
141
142
    LinearLayout layoutLeftU = new LinearLayout(act);
143
    layoutLeftU.setLayoutParams(paramsL);
144
    LinearLayout layoutMidU  = new LinearLayout(act);
145
    layoutMidU.setLayoutParams(paramsM);
146
    LinearLayout layoutRightU= new LinearLayout(act);
147
    layoutRightU.setLayoutParams(paramsR);
148
149
    layoutLeftU.addView(mSolveButton);
150
    layoutRightU.addView(mScrambleButton);
151
152 775d5361 Leszek Koltunski
    layoutUpper.removeAllViews();
153 f3563327 Leszek Koltunski
    layoutUpper.addView(layoutLeftU);
154
    layoutUpper.addView(layoutMidU);
155
    layoutUpper.addView(layoutRightU);
156 9530f6b0 Leszek Koltunski
    }
157
158
///////////////////////////////////////////////////////////////////////////////////////////////////
159
160 88b94310 Leszek Koltunski
  public void reddenLock(final BandagedPlayActivity act)
161 9530f6b0 Leszek Koltunski
    {
162
    ObjectControl control = act.getControl();
163
    mLockController.reddenLock(act,control);
164
    }
165 88b94310 Leszek Koltunski
166
///////////////////////////////////////////////////////////////////////////////////////////////////
167
168
  public void addMove(Activity act, int axis, int row, int angle)
169
    {
170
    mMovesController.addMove(act,axis,row,angle);
171
    }
172
173
///////////////////////////////////////////////////////////////////////////////////////////////////
174
175 972f9eae Leszek Koltunski
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
176 88b94310 Leszek Koltunski
    {
177 972f9eae Leszek Koltunski
    mMovesController.savePreferences(mKey,editor);
178
    ObjectControl control = act.getControl();
179 21a1bb5d Leszek Koltunski
    OSInterface os = (OSInterface)control.getOS();
180
    os.setEditor(editor);
181
    control.savePreferences();
182 88b94310 Leszek Koltunski
    }
183
184
///////////////////////////////////////////////////////////////////////////////////////////////////
185
186 972f9eae Leszek Koltunski
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
187 88b94310 Leszek Koltunski
    {
188 972f9eae Leszek Koltunski
    mMovesController.restorePreferences(act,mKey,preferences);
189
    ObjectControl control = act.getControl();
190 21a1bb5d Leszek Koltunski
    OSInterface os = (OSInterface)control.getOS();
191
    os.setPreferences(preferences);
192
    control.restorePreferences();
193 b72b71a1 Leszek Koltunski
    }
194 9530f6b0 Leszek Koltunski
}