~brzeti/patat/trunk

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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
from os import system
import java.awt
import java.awt.Button
import javax.swing
import javax.swing.JFrame
import javax.swing.JButton as JButton
import javax.swing as swing
import javax.swing as s
import java.awt as awt
import java.awt.event as event
import com.brackeen.javagamebook.state.MainGameState as MainGameState
import com.brackeen.javagamebook.tilegame.GameManager as GameManager
import pl.cba.adb.util.Options as Options

def rmm():
    r()
    mm.reinit()

class MainMenu(event.MouseListener,event.ItemListener):

    def __init__(self):

        self.imagex = 0
        self.imagey = 0
        self.bDrawImage = False
        freadme = open('help.txt')
        self.readme_text = freadme.read()
        print self.readme_text
        frame = gameManager.screen.getFullScreenWindow()
        self.frame = frame
        #frame = JFrame("KeyTest")
        #frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE)
        #frame.setDefaultCloseOperation(EXIT_ON_CLOSE)
        #frame.setSize(300,150)

        self.contentPane = frame.getContentPane()
        self.cp = self.contentPane
        self.clear()
        self.contentPane.setOpaque(False)
        self.initBasicButtons()
        self.showMain()

    def initBasicButtons(self):
        self.bback = s.JButton('Back')
        self.bback.addActionListener(inputManager)
        self.bback.setActionCommand("back")
        
    def itemStateChanged(self,e):
        print 'itemStateChanged()'
        source = e.getItemSelectable()
        if(source == self.sound_enable):
            if (e.getStateChange() == event.ItemEvent.DESELECTED):
                print 'sound_enable off'
                Options.sound_enable = False
            else:
                print 'sound_enable on'
                Options.sound_enable = True
        elif(source == self.music_enable):
            if (e.getStateChange() == event.ItemEvent.DESELECTED):
                print 'music_enable off'
                midiPlayer.setPlaying(False)
                Options.music_enable = False
            else:
                print 'music_enable on'
                midiPlayer.setPlaying(True)
                Options.music_enable = True

    def showMain(self):
        self.clear()
        self.contentPane.setLayout(awt.FlowLayout(awt.FlowLayout.CENTER))
        self.b1 = JButton("Start New Game")
        self.b1.setFocusable(False)
        self.b1.setActionCommand("start")
        self.b1.addMouseListener(self)

        self.b2 = JButton('Continue Previous Game')
        self.b2.setFocusable(False)
        self.b2.setActionCommand("continue")
        self.b2.addMouseListener(self)

        self.b3 = JButton('Settings..')
        self.b3.setFocusable(False)
        self.b3.setActionCommand("settings")
        self.b3.addMouseListener(self)

        #self.b4 = JButton('Hall of Fame')
        #self.b4.setFocusable(False)

        self.bhelp = JButton('Help')
        self.bhelp.setFocusable(False)
        self.bhelp.setActionCommand("help")
        self.bhelp.addMouseListener(self)

        self.bexit = JButton('Exit')
        self.bexit.setFocusable(False)
        self.bexit.setActionCommand("exit")
        self.bexit.addMouseListener(self)

        self.contentPane.add(self.b1)
        self.contentPane.add(self.b2)
        self.contentPane.add(self.b3)
        self.contentPane.add(self.bhelp)
        self.contentPane.add(self.bexit)

        self.b1.addActionListener(inputManager)
        self.b2.addActionListener(inputManager)
        self.b3.addActionListener(inputManager)
        self.bhelp.addActionListener(inputManager)
        self.bexit.addActionListener(inputManager)



    def showHelp(self):
        self.clear()
        cp = self.cp
        c = awt.GridBagConstraints()
        layout = awt.GridBagLayout()
        cp.setLayout(layout)
        c.fill = awt.GridBagConstraints.VERTICAL
        self.ta = swing.JTextArea("Patricia Attack Help")


        bback = self.bback
        ta = self.ta

        areaScrollPane = swing.JScrollPane(ta)
        layout.setConstraints(bback,c)
        layout.setConstraints(ta,c)

        ta.setFocusable(False)
        ta.setText(self.readme_text)
        cp.add(bback)
        cp.add(ta)


    def showSettings(self):
        self.clear()
        cp = self.cp
        layout = awt.FlowLayout()
        cp.setLayout(layout)
        
        self.sound_enable = s.JCheckBox('Sound On/Off')
        self.music_enable = s.JCheckBox('Music On/Off')
        self.sound_enable.setSelected(Options.sound_enable)
        self.music_enable.setSelected(Options.music_enable)
        self.sound_enable.addItemListener(self)
        self.music_enable.addItemListener(self)
        cp.add(self.bback)
        cp.add(self.sound_enable)
        cp.add(self.music_enable)

    def showSaves(self):
        pass

    def reinit(self):
        self.clear()
        self.__init__()

    def activate(self):
        menuGameState.activate()
    def deactivate(self):
        menuGameState.deactivate()
    def clear(self):
        self.contentPane.removeAll()
    def showAcceptExit(self):
        self.clear()
        cp = self.cp
        cp.setLayout(awt.FlowLayout(awt.FlowLayout.CENTER))
        label = swing.JLabel("<HTML><FONT COLOR='blue'><B>Do you really want to suicide?</B></FONT></HTML>")
        buttonyes = swing.JButton("Yes, I do.")
        buttonno = swing.JButton("No way!")
        buttonyes.setFocusable(False)
        buttonno.setFocusable(False)
        buttonyes.addActionListener(inputManager)
        buttonno.addActionListener(inputManager)
        buttonyes.setActionCommand("exitbuttonyes")
        buttonno.setActionCommand("exitbuttonno")
        cp.add(label)
        cp.add(buttonyes)
        cp.add(buttonno)
        self.exitbuttonyes = buttonyes
        self.exitbuttonno = buttonno
    def showAcceptNewGame(self):
        self.clear()
        cp = self.cp
        cp.setLayout(awt.FlowLayout(awt.FlowLayout.CENTER))
        label = swing.JLabel("<HTML><FONT COLOR='blue'><B>Do you really want to start a new game?</B> <I>If you proceed the current game state will be lost.</I></FONT></HTML>")
        buttonyes = swing.JButton("Yes")
        buttonno = swing.JButton("No")
        buttonyes.setFocusable(False)
        buttonno.setFocusable(False)
        buttonyes.addActionListener(inputManager)
        buttonno.addActionListener(inputManager)
        buttonyes.setActionCommand("newgamebuttonyes")
        buttonno.setActionCommand("newgamebuttonno")
        cp.add(label)
        cp.add(buttonyes)
        cp.add(buttonno)
        self.newgamebuttonyes = buttonyes
        self.newgamebuttonno = buttonno
    def showSubmitScore(self):#the placeholder for submit score
        pass
    def showHighscores(self):#the placeholder for score showing routine
        pass
    def swingActionPerformed(self):
        print 'actionPerformed(e)'
        e = swingEvent
        command = e.getActionCommand()
        if("start"==command):
            print 'starting..'
            if(resourceManager.getCurrentMap()==1):
                MainGameState.map = resourceManager.loadMap(1)
                self.showMain()
                self.deactivate()
            else:
                self.showAcceptNewGame()
        elif("continue"==command):
            print 'continue'
            self.deactivate()
        elif("back"==command):
            print 'returning to main menu'
            self.showMain()
        elif("help"==command):
            print 'help menu'
            self.showHelp()
        elif("settings"==command):
            print 'settings menu'
            self.showSettings()
        elif("exit"==command):
            print 'exiting..'
            self.showAcceptExit()
            #MainGameState.endGame()
            #self.deactivate()
        elif("exitbuttonyes"==command):
            MainGameState.endGame()
            self.deactivate()
        elif("exitbuttonno"==command):
            self.showMain()
        elif("newgamebuttonyes"==command):
            MainGameState.map = resourceManager.loadMap(1)
            self.showMain()
            self.deactivate()
        elif("newgamebuttonno"==command):
            self.showMain()

    def updateCoordinates(self):
        self.imagex = GameManager.window.getWidth()/2 - menuGameState.imageCurrent.getWidth()/2
        self.imagey = 100
    def draw(self):
        g = graphics
        if(self.bDrawImage):
            g.drawImage(menuGameState.imageCurrent,self.imagex,self.imagey,None)
    def mouseEntered(self,mouseEvent):
         print 'swingMouseEntered()'
         e = mouseEvent
         #print e.getComponent()
         if(menuGameState.compareJavaObj(e.getSource(),self.b1)):
             print 'you are over start button!'
             self.bDrawImage = True
             menuGameState.imageCurrent = menuGameState.image1
             self.updateCoordinates()
         elif(menuGameState.compareJavaObj(e.getSource(),self.b2)):
             print 'you are over continue button!'
             self.bDrawImage = True
             menuGameState.imageCurrent = menuGameState.image2
             self.updateCoordinates()
         elif(menuGameState.compareJavaObj(e.getSource(),self.b3)):
             print 'you are over settings button!'
             self.bDrawImage = True
             menuGameState.imageCurrent = menuGameState.image3
             self.updateCoordinates()
         elif(menuGameState.compareJavaObj(e.getSource(),self.bhelp)):
             print 'you are over help button!'
             self.bDrawImage = True
             menuGameState.imageCurrent = menuGameState.image4
             self.updateCoordinates()
         elif(menuGameState.compareJavaObj(e.getSource(),self.bexit)):
             print 'you are over exit button!'
             self.bDrawImage = True
             menuGameState.imageCurrent = menuGameState.image5
             self.updateCoordinates()
    def mouseExited(self,mouseEvent):
        self.bDrawImage = False
    def mousePressed(self,mouseEvent):
        pass
    def mouseReleased(self,mouseEvent):
        pass
    def mouseClicked(self,mouseEvent):
        pass