Project

General

Profile

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

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

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2023 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.playui;
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.objectlib.effects.BaseEffect;
18
import org.distorted.objectlib.main.ObjectControl;
19
import org.distorted.os.OSInterface;
20
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
public class PlayScreen
28
{
29
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
30
  private final LockController mLockController;
31
  private final MovesController mMovesController;
32
  private String mKey;
33

    
34
///////////////////////////////////////////////////////////////////////////////////////////////////
35

    
36
  public PlayScreen()
37
    {
38
    mLockController = new LockController();
39
    mMovesController= new MovesController();
40
    }
41

    
42
///////////////////////////////////////////////////////////////////////////////////////////////////
43

    
44
  private void setupBackButton(final PlayActivity act)
45
    {
46
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT);
47
    mBackButton = new TransparentImageButton(act,R.drawable.ui_smallback,params);
48

    
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
  private void setupSolveButton(final PlayActivity act)
62
    {
63
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
64
    mSolveButton = new TransparentImageButton(act,R.drawable.ui_cube_solve,params);
65

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

    
78
///////////////////////////////////////////////////////////////////////////////////////////////////
79

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

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

    
99
///////////////////////////////////////////////////////////////////////////////////////////////////
100

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

    
105
    int width = act.getScreenWidthInPixels();
106

    
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
    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
    setupScrambleButton(act);
135

    
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
    layoutUpper.removeAllViews();
149
    layoutUpper.addView(layoutLeftU);
150
    layoutUpper.addView(layoutMidU);
151
    layoutUpper.addView(layoutRightU);
152
    }
153

    
154
///////////////////////////////////////////////////////////////////////////////////////////////////
155

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

    
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
  public void savePreferences(PlayActivity act, SharedPreferences.Editor editor)
172
    {
173
    mMovesController.savePreferences(mKey,editor);
174
    ObjectControl control = act.getControl();
175
    OSInterface os = (OSInterface)control.getOS();
176
    os.setEditor(editor);
177
    control.savePreferences();
178
    }
179

    
180
///////////////////////////////////////////////////////////////////////////////////////////////////
181

    
182
  public void restorePreferences(PlayActivity act, SharedPreferences preferences)
183
    {
184
    mMovesController.restorePreferences(act,mKey,preferences);
185
    ObjectControl control = act.getControl();
186
    OSInterface os = (OSInterface)control.getOS();
187
    os.setPreferences(preferences);
188
    control.restorePreferences();
189
    }
190
}
(4-4/5)