Project

General

Profile

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

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

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
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
49
    mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,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
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
66
    mSolveButton = new TransparentImageButton(act,R.drawable.ui_cube_solve,params);
67

    
68
    mSolveButton.setOnClickListener( new View.OnClickListener()
69
      {
70
      @Override
71
      public void onClick(View v)
72
        {
73
        ObjectControl control = act.getControl();
74
        control.solveObject();
75
        mMovesController.clearMoves(act);
76
        }
77
      });
78
    }
79

    
80
///////////////////////////////////////////////////////////////////////////////////////////////////
81

    
82
  private void setupScrambleButton(final BandagedPlayActivity act)
83
    {
84
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
85
    mScrambleButton = new TransparentImageButton(act,R.drawable.ui_cube_scramble,params);
86

    
87
    mScrambleButton.setOnClickListener( new View.OnClickListener()
88
      {
89
      @Override
90
      public void onClick(View v)
91
        {
92
        ObjectControl control = act.getControl();
93
        int duration = BaseEffect.Type.FAST_SCRAMBLE.getDuration();
94
        control.fastScrambleObject(duration,NUM_SCRAMBLES);
95
        mMovesController.clearMoves(act);
96
        }
97
      });
98
    }
99

    
100
///////////////////////////////////////////////////////////////////////////////////////////////////
101

    
102
  void onAttachedToWindow(final BandagedPlayActivity act, String objectName)
103
    {
104
    mKey = "moveController_"+objectName;
105

    
106
    int width = act.getScreenWidthInPixels();
107

    
108
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
109
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
110
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
111

    
112
    LinearLayout layoutLeft = new LinearLayout(act);
113
    layoutLeft.setLayoutParams(paramsL);
114
    LinearLayout layoutMid  = new LinearLayout(act);
115
    layoutMid.setLayoutParams(paramsM);
116
    LinearLayout layoutRight= new LinearLayout(act);
117
    layoutRight.setLayoutParams(paramsR);
118

    
119
    setupBackButton(act);
120
    ObjectControl control = act.getControl();
121
    mMovesController.setupButton(act,control);
122
    layoutLeft.addView(mMovesController.getButton());
123
    mLockController.setupButton(act,control);
124
    layoutMid.addView(mLockController.getButton());
125

    
126
    layoutRight.addView(mBackButton);
127

    
128
    LinearLayout layoutLower = act.findViewById(R.id.lowerBar);
129
    layoutLower.removeAllViews();
130
    layoutLower.addView(layoutLeft);
131
    layoutLower.addView(layoutMid);
132
    layoutLower.addView(layoutRight);
133

    
134
    setupSolveButton(act);
135
    setupScrambleButton(act);
136

    
137
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
138

    
139
    LinearLayout layoutLeftU = new LinearLayout(act);
140
    layoutLeftU.setLayoutParams(paramsL);
141
    LinearLayout layoutMidU  = new LinearLayout(act);
142
    layoutMidU.setLayoutParams(paramsM);
143
    LinearLayout layoutRightU= new LinearLayout(act);
144
    layoutRightU.setLayoutParams(paramsR);
145

    
146
    layoutLeftU.addView(mSolveButton);
147
    layoutRightU.addView(mScrambleButton);
148

    
149
    layoutUpper.removeAllViews();
150
    layoutUpper.addView(layoutLeftU);
151
    layoutUpper.addView(layoutMidU);
152
    layoutUpper.addView(layoutRightU);
153
    }
154

    
155
///////////////////////////////////////////////////////////////////////////////////////////////////
156

    
157
  public void reddenLock(final BandagedPlayActivity act)
158
    {
159
    ObjectControl control = act.getControl();
160
    mLockController.reddenLock(act,control);
161
    }
162

    
163
///////////////////////////////////////////////////////////////////////////////////////////////////
164

    
165
  public void addMove(Activity act, int axis, int row, int angle)
166
    {
167
    mMovesController.addMove(act,axis,row,angle);
168
    }
169

    
170
///////////////////////////////////////////////////////////////////////////////////////////////////
171

    
172
  public void savePreferences(BandagedPlayActivity act, SharedPreferences.Editor editor)
173
    {
174
    mMovesController.savePreferences(mKey,editor);
175
    ObjectControl control = act.getControl();
176
    OSInterface os = (OSInterface)control.getOS();
177
    os.setEditor(editor);
178
    control.savePreferences();
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
    OSInterface os = (OSInterface)control.getOS();
188
    os.setPreferences(preferences);
189
    control.restorePreferences();
190
    }
191
}
(11-11/12)