Project

General

Profile

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

magiccube / src / main / java / org / distorted / bandaged / BandagedPlayScreen.java @ 9234018b

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

    
24
///////////////////////////////////////////////////////////////////////////////////////////////////
25

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

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

    
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
    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
    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
  private void setupSolveButton(final BandagedPlayActivity act)
64
    {
65
    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
        ObjectControl control = act.getControl();
75
        control.solveObject();
76
        mMovesController.clearMoves(act);
77
        }
78
      });
79
    }
80

    
81
///////////////////////////////////////////////////////////////////////////////////////////////////
82

    
83
  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
        ObjectControl control = act.getControl();
95
        int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
96
        control.fastScrambleObject(duration,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 reddenLock(final BandagedPlayActivity act)
160
    {
161
    ObjectControl control = act.getControl();
162
    mLockController.reddenLock(act,control);
163
    }
164

    
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
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
175
    {
176
    mMovesController.savePreferences(mKey,editor);
177
    ObjectControl control = act.getControl();
178
    control.savePreferences(editor);
179
    }
180

    
181
///////////////////////////////////////////////////////////////////////////////////////////////////
182

    
183
  public void restorePreferences(BandagedPlayActivity act, SharedPreferences preferences)
184
    {
185
    mMovesController.restorePreferences(act,mKey,preferences);
186
    ObjectControl control = act.getControl();
187
    control.restorePreferences(preferences);
188
    }
189
}
(12-12/13)