Project

General

Profile

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

magiccube / src / main / java / org / distorted / screens / RubikScreenFreePlay.java @ 85038b84

1
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2022 Leszek Koltunski                                                               //
3
//                                                                                               //
4
// This file is part of Magic Cube.                                                              //
5
//                                                                                               //
6
// Magic Cube is free software: you can redistribute it and/or modify                            //
7
// it under the terms of the GNU General Public License as published by                          //
8
// the Free Software Foundation, either version 2 of the License, or                             //
9
// (at your option) any later version.                                                           //
10
//                                                                                               //
11
// Magic Cube is distributed in the hope that it will be useful,                                 //
12
// but WITHOUT ANY WARRANTY; without even the implied warranty of                                //
13
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the                                 //
14
// GNU General Public License for more details.                                                  //
15
//                                                                                               //
16
// You should have received a copy of the GNU General Public License                             //
17
// along with Magic Cube.  If not, see <http://www.gnu.org/licenses/>.                           //
18
///////////////////////////////////////////////////////////////////////////////////////////////////
19

    
20
package org.distorted.screens;
21

    
22
import android.content.SharedPreferences;
23
import android.view.View;
24
import android.widget.LinearLayout;
25

    
26
import org.distorted.bandaged.BandagedPlayActivity;
27
import org.distorted.dialogs.RubikDialogAbandon;
28
import org.distorted.helpers.TransparentImageButton;
29
import org.distorted.main.R;
30
import org.distorted.main.RubikActivity;
31
import org.distorted.objectlib.main.ObjectControl;
32
import org.distorted.objects.RubikObject;
33
import org.distorted.objects.RubikObjectList;
34

    
35
///////////////////////////////////////////////////////////////////////////////////////////////////
36

    
37
public class RubikScreenFreePlay extends RubikScreenBase
38
  {
39
  private static final int MOVES_THRESHHOLD = 10;
40
  private TransparentImageButton mBackButton, mScrambleButton, mSolveButton;
41

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

    
44
  RubikScreenFreePlay()
45
    {
46

    
47
    }
48

    
49
///////////////////////////////////////////////////////////////////////////////////////////////////
50

    
51
  void leaveScreen(RubikActivity act)
52
    {
53

    
54
    }
55

    
56
///////////////////////////////////////////////////////////////////////////////////////////////////
57

    
58
  void enterScreen(final RubikActivity act)
59
    {
60
    int width = act.getScreenWidthInPixels();
61

    
62
    LinearLayout.LayoutParams paramsL = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
63
    LinearLayout.LayoutParams paramsM = new LinearLayout.LayoutParams(width/2, LinearLayout.LayoutParams.MATCH_PARENT);
64
    LinearLayout.LayoutParams paramsR = new LinearLayout.LayoutParams(width/4, LinearLayout.LayoutParams.MATCH_PARENT);
65

    
66
    // TOP ////////////////////////////
67
    setupSolveButton(act);
68
    setupScrambleButton(act);
69

    
70
    LinearLayout layoutUpper = act.findViewById(R.id.upperBar);
71

    
72
    LinearLayout layoutLeftU = new LinearLayout(act);
73
    layoutLeftU.setLayoutParams(paramsL);
74
    LinearLayout layoutMidU = new LinearLayout(act);
75
    layoutMidU.setLayoutParams(paramsM);
76
    LinearLayout layoutRightU= new LinearLayout(act);
77
    layoutRightU.setLayoutParams(paramsR);
78

    
79
    layoutLeftU.addView(mSolveButton);
80
    layoutRightU.addView(mScrambleButton);
81

    
82
    layoutUpper.removeAllViews();
83
    layoutUpper.addView(layoutLeftU);
84
    layoutUpper.addView(layoutMidU);
85
    layoutUpper.addView(layoutRightU);
86

    
87
    // BOTTOM //////////////////////////
88
    setupBackButton(act);
89
    createBottomPane(act,mBackButton,null);
90
    }
91

    
92
///////////////////////////////////////////////////////////////////////////////////////////////////
93

    
94
  private void setupSolveButton(final RubikActivity act)
95
    {
96
    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);
97
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
98
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE,params);
99

    
100
    mSolveButton.setOnClickListener( new View.OnClickListener()
101
      {
102
      @Override
103
      public void onClick(View v)
104
        {
105
        ObjectControl control = act.getControl();
106
        control.solveObject();
107
        mMovesController.clearMoves(act);
108
        }
109
      });
110
    }
111

    
112
///////////////////////////////////////////////////////////////////////////////////////////////////
113

    
114
  private void setupScrambleButton(final RubikActivity act)
115
    {
116
    int icon = RubikActivity.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);
117
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
118
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
119

    
120
    mScrambleButton.setOnClickListener( new View.OnClickListener()
121
      {
122
      @Override
123
      public void onClick(View v)
124
        {
125
        int currObject = RubikObjectList.getCurrObject();
126
        RubikObject object = RubikObjectList.getObject(currObject);
127
        int numScrambles = object==null ? 0 : object.getNumScramble();
128
        //mShouldReactToEndOfScrambling = false;
129
        act.getControl().scrambleObject(numScrambles);
130
        }
131
      });
132
    }
133

    
134
///////////////////////////////////////////////////////////////////////////////////////////////////
135

    
136
  private void setupBackButton(final RubikActivity act)
137
    {
138
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_back,R.drawable.ui_medium_back, R.drawable.ui_big_back, R.drawable.ui_huge_back);
139
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
140
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
141

    
142
    mBackButton.setOnClickListener( new View.OnClickListener()
143
      {
144
      @Override
145
      public void onClick(View v)
146
        {
147
        if( mMovesController.getNumMoves() > MOVES_THRESHHOLD )
148
          {
149
          RubikDialogAbandon abaDiag = new RubikDialogAbandon();
150
          abaDiag.show(act.getSupportFragmentManager(), null);
151
          }
152
        else
153
          {
154
          ScreenList.goBack(act);
155
          }
156
        }
157
      });
158
    }
159

    
160
///////////////////////////////////////////////////////////////////////////////////////////////////
161

    
162
  public void savePreferences(SharedPreferences.Editor editor)
163
    {
164

    
165
    }
166

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

    
169
  public void restorePreferences(SharedPreferences preferences)
170
    {
171

    
172
    }
173
  }
(5-5/12)