File: MenuPanel.cpp

package info (click to toggle)
primrose 6%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd, stretch
  • size: 5,300 kB
  • ctags: 3,383
  • sloc: cpp: 27,318; php: 765; ansic: 636; objc: 272; sh: 136; makefile: 93; perl: 67
file content (269 lines) | stat: -rw-r--r-- 6,768 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
#include "MenuPanel.h"

#include "numeral.h"

#include "gameControl.h"


#include <GL/gl.h>



MenuPanel::MenuPanel( int inW, int inH )
        : Panel( inW, inH ),
          mNewButton( inW - 21 - 19, 100, "+" ),
          mTutorialButton( inW - 21 - 19, 165, "+" ),
          mHighScoreButton( inW - 21 - 19, 230, "+" ),
          mEditNameButton( inW - 21 - 19, 295, "+" ),
          mColorblindButton( inW - 21 - 19, 360, "off" ),
          mSoundButton( inW - 21 - 19, 425, " on " ),
          mHighScoreLoadingPanel( inW, inH ),
          mEditNamePanel( inW, inH ),
          mTutorialPanel( inW, inH ) {
          

    mNewButton.setVisible( false );
    mTutorialButton.setVisible( false );
    mHighScoreButton.setVisible( false );
    mEditNameButton.setVisible( false );
    mEditNameButton.setVisible( false );
    mColorblindButton.setVisible( false );
    mSoundButton.setVisible( false );
    
    if( getColorblindMode() ) {
        mColorblindButton.forceString( " on " );
        }
    if( ! getSoundOn() ) {
        mSoundButton.forceString( "off" );
        }
    
    
    
    addButton( &mNewButton );
    addButton( &mTutorialButton );
    addButton( &mHighScoreButton );
    addButton( &mEditNameButton );
    addButton( &mColorblindButton );
    addButton( &mSoundButton );
    
    mHighScoreLoadingPanel.setVisible( false );
    mEditNamePanel.setVisible( false );
    
    
    addSubPanel( &mEditNamePanel );
    // high score loading panel may need pop up on top of name editing panel
    addSubPanel( &mHighScoreLoadingPanel );

    addSubPanel( &mTutorialPanel );
    
    // display panel created by loading panel, but sits under us
    mDisplayPanel = mHighScoreLoadingPanel.getDisplayPanel();
    
    mDisplayPanel->setMenuPanel( this );
    
    addSubPanel( mDisplayPanel );
    }


    
MenuPanel::~MenuPanel() {

    }



void MenuPanel::postScore( ScoreBundle *inScore ) {
    if( getNameSet() ) {
        mHighScoreLoadingPanel.setScoreToPost( inScore );
        mHighScoreLoadingPanel.setVisible( true );
        }
    else {
        mEditNamePanel.setScoreToPost( inScore, this );
        mEditNamePanel.setVisible( true );
        }
    }



void MenuPanel::forceFadeOutScoreDisplay() {
    mDisplayPanel->forceVisible();
    
    mDisplayPanel->setVisible( false );
    }



char MenuPanel::pointerUp( int inX, int inY ) {
    
    char consumed = Panel::pointerUp( inX, inY );
    
    if( consumed ) {
        return true;
        }
    

    if( ! isSubPanelVisible() ) {
        
        if( mNewButton.isInside( inX, inY ) ) {
            restartGame();
            
            setVisible( false );
            return true;
            }
        if( mEditNameButton.isInside( inX, inY ) ) {
            
            mEditNamePanel.setVisible( true );
            
            return true;
            }
        if( mTutorialButton.isInside( inX, inY ) ) {
            
            mTutorialPanel.setVisible( true );
            
            return true;
            }
        if( mHighScoreButton.isInside( inX, inY ) ) {
            
            mHighScoreLoadingPanel.setLoadingMessage();
            mHighScoreLoadingPanel.setVisible( true );
            
            return true;
            }
        if( mColorblindButton.isInside( inX, inY ) ) {
            // flip
            char oldMode = getColorblindMode();
            char *newString;
            
            if( oldMode ) {
                newString = "off";
                }
            else {
                newString = " on ";
                }
            mColorblindButton.setString( newString );
            setColorblindMode( !oldMode );
            
            return true;
            }
        if( mSoundButton.isInside( inX, inY ) ) {
            // flip
            char oldMode = getSoundOn();
            char *newString;
            
            if( oldMode ) {
                newString = "off";
                }
            else {
                newString = " on ";
                }
            mSoundButton.setString( newString );
            setSoundOn( !oldMode );
            
            return true;
            }
        
        } 
    
    return false;
    }



Color menuItemColor( 76/255.0, 76/255.0, 255/255.0 );

        
void MenuPanel::drawBase() {
    
    Panel::drawBase();
    
    if( mFadeProgress > 0 ) {
        
        glEnable( GL_BLEND );
        glBlendFunc( GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA );

        drawStringBig( "new game", right, 
                       mNewButton.mX - 21 - 19,
                       mNewButton.mY,
                       &menuItemColor, mFadeProgress );

        drawStringBig( "instructions", right, 
                       mTutorialButton.mX - 21 - 19,
                       mTutorialButton.mY,
                       &menuItemColor, mFadeProgress );

        drawStringBig( "high scores", right, 
                       mHighScoreButton.mX - 21 - 19,
                       mHighScoreButton.mY,
                       &menuItemColor, mFadeProgress );

        drawStringBig( "edit name", right, 
                       mEditNameButton.mX - 21 - 19,
                       mEditNameButton.mY,
                       &menuItemColor, mFadeProgress );

        drawStringBig( "colorblind", right, 
                       mColorblindButton.mX - 21 - 19,
                       mColorblindButton.mY,
                       &menuItemColor, mFadeProgress );

        drawStringBig( "sound", right, 
                       mSoundButton.mX - 21 - 19,
                       mSoundButton.mY,
                       &menuItemColor, mFadeProgress );
        

        glDisable( GL_BLEND );
        
        }
    


    
    }




void MenuPanel::step() {
    Panel::step();
    
    
    // check if we should force ourself visible
    // (to pass button presses through to loading and display panel, and be
    //  there to catch it when either of their BACK buttons are pressed)
    if( !mVisible &&
        ( mHighScoreLoadingPanel.isFullyVisible() 
          || 
          mDisplayPanel->isFullyVisible()
          ||
          mEditNamePanel.isFullyVisible() ) ) {
        
        forceVisible();
        }
    if( mHighScoreLoadingPanel.isFullyVisible()
        &&
        mEditNamePanel.isVisible() ) {
        
        // loading panel has popped up fully over edit panel
        mEditNamePanel.forceInvisible();
        }
    }



void MenuPanel::closePressed() {
    // don't do this anymore
    // instead, allow them to look at their game even after score is posted

    // they can manually create a new one when ready
    
    // treat close like NEW if game over
    //if( isGameOver() ) {
    //    restartGame();
    //    }

    }