Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ fa93ffc2

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.effects.BaseEffect;
22
import org.distorted.objectlib.main.ObjectControl;
23
import org.distorted.os.OSInterface;
24

    
25
///////////////////////////////////////////////////////////////////////////////////////////////////
26

    
27
public class BandagedPlayScreen
28
{
29
  private static final int NUM_SCRAMBLES = 300;
30

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

    
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
    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
    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
  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
        int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
97
        //control.fastScrambleObject(duration,NUM_SCRAMBLES);
98
        control.scrambleObject(10);
99
        mMovesController.clearMoves(act);
100
        }
101
      });
102
    }
103

    
104
///////////////////////////////////////////////////////////////////////////////////////////////////
105

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

    
110
    int width = act.getScreenWidthInPixels();
111

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

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

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

    
130
    layoutRight.addView(mBackButton);
131

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

    
138
    setupSolveButton(act);
139
    setupScrambleButton(act);
140

    
141
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
142

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

    
150
    layoutLeftU.addView(mSolveButton);
151
    layoutRightU.addView(mScrambleButton);
152

    
153
    layoutUpper.removeAllViews();
154
    layoutUpper.addView(layoutLeftU);
155
    layoutUpper.addView(layoutMidU);
156
    layoutUpper.addView(layoutRightU);
157
    }
158

    
159
///////////////////////////////////////////////////////////////////////////////////////////////////
160

    
161
  public void reddenLock(final BandagedPlayActivity act)
162
    {
163
    ObjectControl control = act.getControl();
164
    mLockController.reddenLock(act,control);
165
    }
166

    
167
///////////////////////////////////////////////////////////////////////////////////////////////////
168

    
169
  public void addMove(Activity act, int axis, int row, int angle)
170
    {
171
    mMovesController.addMove(act,axis,row,angle);
172
    }
173

    
174
///////////////////////////////////////////////////////////////////////////////////////////////////
175

    
176
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
177
    {
178
    mMovesController.savePreferences(mKey,editor);
179
    ObjectControl control = act.getControl();
180
    OSInterface os = (OSInterface)control.getOS();
181
    os.setEditor(editor);
182
    control.savePreferences();
183
    }
184

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

    
187
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
188
    {
189
    mMovesController.restorePreferences(act,mKey,preferences);
190
    ObjectControl control = act.getControl();
191
    OSInterface os = (OSInterface)control.getOS();
192
    os.setPreferences(preferences);
193
    control.restorePreferences();
194
    }
195
}
(11-11/12)