Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialState.java @ 588ace55

1 344f290c Leszek Koltunski
///////////////////////////////////////////////////////////////////////////////////////////////////
2
// Copyright 2020 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 eaf87d1d Leszek Koltunski
package org.distorted.tutorials;
21 344f290c Leszek Koltunski
22
import android.view.View;
23
import android.widget.ImageButton;
24
import android.widget.LinearLayout;
25
26 55e6be1d Leszek Koltunski
import org.distorted.helpers.MovesAndLockController;
27 146661ec Leszek Koltunski
import org.distorted.helpers.TwistyActivity;
28 84b4fc43 Leszek Koltunski
import org.distorted.helpers.TwistyPreRender;
29 344f290c Leszek Koltunski
import org.distorted.main.R;
30
import org.distorted.main.RubikActivity;
31 588ace55 Leszek Koltunski
import org.distorted.objectlib.ObjectList;
32 fcd5b990 Leszek Koltunski
import org.distorted.screens.RubikScreenPlay;
33
import org.distorted.screens.ScreenList;
34 55e6be1d Leszek Koltunski
import org.distorted.helpers.TransparentImageButton;
35 344f290c Leszek Koltunski
36
///////////////////////////////////////////////////////////////////////////////////////////////////
37
38 55e6be1d Leszek Koltunski
public class TutorialState
39 344f290c Leszek Koltunski
{
40 55e6be1d Leszek Koltunski
  private ImageButton mSolveButton, mScrambleButton, mBackButton;
41 146661ec Leszek Koltunski
  private final MovesAndLockController mController;
42 344f290c Leszek Koltunski
43
///////////////////////////////////////////////////////////////////////////////////////////////////
44
45
  private void setupSolveButton(final TutorialActivity act, final float width)
46
    {
47
    int icon = RubikActivity.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);
48
    mSolveButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
49
50
    mSolveButton.setOnClickListener( new View.OnClickListener()
51
      {
52
      @Override
53
      public void onClick(View v)
54
        {
55
        act.getPreRender().solveObject();
56 1ae92052 Leszek Koltunski
        mController.clearMoves(act);
57 344f290c Leszek Koltunski
        }
58
      });
59
    }
60
61
///////////////////////////////////////////////////////////////////////////////////////////////////
62
63
  private void setupScrambleButton(final TutorialActivity act, final float width)
64
    {
65
    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);
66
    mScrambleButton = new TransparentImageButton(act, icon, width,LinearLayout.LayoutParams.MATCH_PARENT);
67
68
    mScrambleButton.setOnClickListener( new View.OnClickListener()
69
      {
70
      @Override
71
      public void onClick(View v)
72
        {
73 f5da732a Leszek Koltunski
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
74 13ed203c Leszek Koltunski
        int size = play.getSize();
75
        int object= play.getObject();
76
        int sizeIndex = ObjectList.getSizeIndex(object,size);
77 0a7aa15b Leszek Koltunski
        int numScrambles = ObjectList.getNumScramble(object, sizeIndex);
78 13ed203c Leszek Koltunski
79 0a7aa15b Leszek Koltunski
        act.getPreRender().scrambleObject(numScrambles);
80 344f290c Leszek Koltunski
        }
81
      });
82
    }
83
84
///////////////////////////////////////////////////////////////////////////////////////////////////
85
86
  private void setupBackButton(final TutorialActivity act, final float width)
87
    {
88 e314f6ae Leszek Koltunski
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
89 344f290c Leszek Koltunski
    mBackButton = new TransparentImageButton(act, icon, width, LinearLayout.LayoutParams.MATCH_PARENT);
90
91
    mBackButton.setOnClickListener( new View.OnClickListener()
92
      {
93
      @Override
94
      public void onClick(View v)
95
        {
96 84b4fc43 Leszek Koltunski
        TwistyPreRender pre = act.getPreRender();
97
        if( pre!=null ) pre.unblockEverything();
98 344f290c Leszek Koltunski
        act.finish();
99
        }
100
      });
101
    }
102
103
///////////////////////////////////////////////////////////////////////////////////////////////////
104
105
  void createRightPane(final TutorialActivity act, float width)
106
    {
107 2971588c Leszek Koltunski
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
108 344f290c Leszek Koltunski
    layout.removeAllViews();
109
110 55e6be1d Leszek Koltunski
    mController.setupPrevButton(act,width);
111
    mController.setupLockButton(act,width);
112 344f290c Leszek Koltunski
    setupSolveButton(act,width);
113
    setupScrambleButton(act,width);
114
    setupBackButton(act,width);
115
116
    layout.addView(mSolveButton);
117 55e6be1d Leszek Koltunski
    layout.addView(mController.getPrevButton());
118 344f290c Leszek Koltunski
    layout.addView(mScrambleButton);
119 55e6be1d Leszek Koltunski
    layout.addView(mController.getLockButton());
120 344f290c Leszek Koltunski
    layout.addView(mBackButton);
121
    }
122
123
///////////////////////////////////////////////////////////////////////////////////////////////////
124
125 146661ec Leszek Koltunski
  void addMove(TwistyActivity act, int axis, int row, int angle)
126
    {
127
    mController.addMove(act, axis,row,angle);
128
    }
129
130
///////////////////////////////////////////////////////////////////////////////////////////////////
131
// PUBLIC API
132
133
  public TutorialState()
134 344f290c Leszek Koltunski
    {
135 146661ec Leszek Koltunski
    mController = new MovesAndLockController();
136 344f290c Leszek Koltunski
    }
137 cc88f2fa Leszek Koltunski
138
///////////////////////////////////////////////////////////////////////////////////////////////////
139
140
  public void reddenLock(final TwistyActivity act)
141
    {
142
    mController.reddenLock(act);
143
    }
144 344f290c Leszek Koltunski
}