Project

General

Profile

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

magiccube / src / main / java / org / distorted / playui / PlayScreen.java @ c9f72ca3

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