Project

General

Profile

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

magiccube / src / main / java / org / distorted / tutorials / TutorialScreen.java @ d433b50e

1
///////////////////////////////////////////////////////////////////////////////////////////////////
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
package org.distorted.tutorials;
21

    
22
import android.app.Activity;
23
import android.view.View;
24
import android.widget.LinearLayout;
25

    
26
import org.distorted.helpers.MovesController;
27
import org.distorted.objectlib.main.ObjectControl;
28

    
29
import org.distorted.helpers.LockController;
30
import org.distorted.main.R;
31
import org.distorted.main.RubikActivity;
32
import org.distorted.objects.RubikObject;
33
import org.distorted.objects.RubikObjectList;
34
import org.distorted.screens.RubikScreenPlay;
35
import org.distorted.screens.ScreenList;
36
import org.distorted.helpers.TransparentImageButton;
37

    
38
///////////////////////////////////////////////////////////////////////////////////////////////////
39

    
40
public class TutorialScreen
41
{
42
  private TransparentImageButton mSolveButton, mScrambleButton, mBackButton;
43
  private final LockController mLockController;
44
  private final MovesController mMovesController;
45

    
46
///////////////////////////////////////////////////////////////////////////////////////////////////
47

    
48
  private void setupSolveButton(final TutorialActivity act)
49
    {
50
    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);
51
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
52
    mSolveButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
53

    
54
    mSolveButton.setOnClickListener( new View.OnClickListener()
55
      {
56
      @Override
57
      public void onClick(View v)
58
        {
59
        act.getControl().solveObject();
60
        mMovesController.clearMoves(act);
61
        }
62
      });
63
    }
64

    
65
///////////////////////////////////////////////////////////////////////////////////////////////////
66

    
67
  private void setupScrambleButton(final TutorialActivity act)
68
    {
69
    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);
70
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
71
    mScrambleButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
72

    
73
    mScrambleButton.setOnClickListener( new View.OnClickListener()
74
      {
75
      @Override
76
      public void onClick(View v)
77
        {
78
        RubikScreenPlay play = (RubikScreenPlay) ScreenList.PLAY.getScreenClass();
79
        int object = play.getObject();
80
        RubikObject obj = RubikObjectList.getObject(object);
81
        int numScrambles = obj==null ? 0 : obj.getNumScramble();
82
        act.getControl().scrambleObject(numScrambles);
83
        }
84
      });
85
    }
86

    
87
///////////////////////////////////////////////////////////////////////////////////////////////////
88

    
89
  private void setupBackButton(final TutorialActivity act)
90
    {
91
    int icon = RubikActivity.getDrawable(R.drawable.ui_small_smallback,R.drawable.ui_medium_smallback, R.drawable.ui_big_smallback, R.drawable.ui_huge_smallback);
92
    LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,LinearLayout.LayoutParams.MATCH_PARENT,1.0f);
93
    mBackButton = new TransparentImageButton(act, icon, TransparentImageButton.GRAVITY_MIDDLE, params);
94

    
95
    mBackButton.setOnClickListener( new View.OnClickListener()
96
      {
97
      @Override
98
      public void onClick(View v)
99
        {
100
        ObjectControl control = act.getControl();
101
        if( control!=null ) control.unblockEverything();
102
        act.finish();
103
        }
104
      });
105
    }
106

    
107
///////////////////////////////////////////////////////////////////////////////////////////////////
108

    
109
  void createRightPane(final TutorialActivity act)
110
    {
111
    LinearLayout layout = act.findViewById(R.id.tutorialRightBar);
112
    layout.removeAllViews();
113

    
114
    ObjectControl control = act.getControl();
115
    mMovesController.setupButton(act,control);
116
    mLockController.setupButton(act,control);
117
    setupSolveButton(act);
118
    setupScrambleButton(act);
119
    setupBackButton(act);
120

    
121
    layout.addView(mSolveButton);
122
    layout.addView(mScrambleButton);
123
    layout.addView(mMovesController.getButton());
124
    layout.addView(mLockController.getButton());
125
    layout.addView(mBackButton);
126
    }
127

    
128
///////////////////////////////////////////////////////////////////////////////////////////////////
129

    
130
  void addMove(Activity act, int axis, int row, int angle)
131
    {
132
    mMovesController.addMove(act, axis,row,angle);
133
    }
134

    
135
///////////////////////////////////////////////////////////////////////////////////////////////////
136
// PUBLIC API
137

    
138
  public TutorialScreen()
139
    {
140
    mLockController = new LockController();
141
    mMovesController = new MovesController();
142
    }
143

    
144
///////////////////////////////////////////////////////////////////////////////////////////////////
145

    
146
  public void reddenLock(final TutorialActivity act)
147
    {
148
    ObjectControl control = act.getControl();
149
    mLockController.reddenLock(act,control);
150
    }
151
}
(5-5/7)