root/src/main.py @ 261

Revision 261, 7.3 KB (checked in by rthomas, 2 years ago)

main menu structure

Line 
1'''
2Created on Mar 24, 2012
3
4@author: TechTrek
5'''
6import window
7from globals import *
8import pygame, os, math
9from image import *
10from text import *
11from rectangle import *
12import background
13import top
14import onScreenButton
15import inGameMenu
16import sys
17import description
18import menuEntry
19import map
20import spinner
21import mainMenu
22import mainMenuButton
23from buildables import buildingLUT
24
25
26def Initialize():
27    """
28        Returns the top object with everything fully initialized.
29       
30        input type: none
31        return type: top
32    """
33    # surface
34    screenSurface = pygame.display.set_mode((SCREEN_W,SCREEN_H),RESIZABLE)
35    screenSurface.fill(BLACK)
36   
37   
38    newTop = top.Top(screenSurface)
39   
40    newBackground = background.Background((0,0),True,'background.png')
41   
42    ############################################################################################
43   
44    #menuBackground = background.Background((0,0),True,'menuBackground.jpg')
45   
46   
47    mainMenuWindow = mainMenu.MainMenu((400,100),True)
48   
49    newGameButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*0),True,'New Game')
50    newGameButton.addResponse((mainMenuWindow.toggle,)) 
51    # will also need to set new state and show opening sequence
52   
53    resumeButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*1),False,'Resume')
54    resumeButton.addResponse((mainMenuWindow.toggle,))
55   
56    loadButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*2),True,'Load')
57    # will need a response
58   
59    saveButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*3),False,'Save')
60    # will need a response
61   
62    quitButton = mainMenuButton.MainMenuButton((450,170+MAIN_SHIFT*4),True,'Quit')
63    quitButton.addResponse((pygame.quit,))
64    quitButton.addResponse((sys.exit,))
65   
66       
67   
68    mainMenuWindow.addWindow(newGameButton)
69    mainMenuWindow.addWindow(resumeButton)
70    mainMenuWindow.addWindow(loadButton)
71    mainMenuWindow.addWindow(saveButton)
72    mainMenuWindow.addWindow(quitButton)
73   
74   
75    ###########################################################################################################
76   
77       
78    buildPowerDescription = description.Description('power',
79                                                    "This is where the text would go.",
80                                                    pygame.image.load(os.path.abspath(iconDir + "power.png")))
81    buildPowerButton = menuEntry.MenuEntry((20,100+ENTRY_SHIFT*0),False,buildPowerDescription)
82   
83    buildTransportationDescription = description.Description('transportation',
84                                                    "This is where the text would go.",
85                                                    pygame.image.load(os.path.abspath(iconDir + "transportation.png")))
86    buildTransportationButton = menuEntry.MenuEntry((20,100+ENTRY_SHIFT*1),False,buildTransportationDescription)
87   
88    buildMaterialDescription = description.Description('material',
89                                                    "This is where the text would go.",
90                                                    pygame.image.load(os.path.abspath(iconDir + "material.png")))
91    buildMaterialButton = menuEntry.MenuEntry((20,100+ENTRY_SHIFT*2),False,buildMaterialDescription)
92   
93    buildMenu = inGameMenu.InGameMenu((20,20),False,'BUILD MENU','build.png')
94    buildMenu.addWindow(buildPowerButton)
95    buildMenu.addWindow(buildTransportationButton)
96    buildMenu.addWindow(buildMaterialButton)
97   
98    ###########################################################################################################
99   
100    researchPowerSpinner = spinner.Spinner((0,0),False)
101   
102    researchPowerDescription = description.Description('power',
103                                                    "This is where the text would go.",
104                                                    pygame.image.load(os.path.abspath(iconDir + "power.png")))
105    researchPowerButton = menuEntry.MenuEntry((20,100+ENTRY_SHIFT*0),False,researchPowerDescription)
106    researchPowerButton.addResponse((researchPowerSpinner.toggle,))
107    researchPowerButton.addWindow(researchPowerSpinner)
108
109   
110    researchTransportationDescription = description.Description('transportation',
111                                                    "This is where the text would go.",
112                                                    pygame.image.load(os.path.abspath(iconDir + "transportation.png")))
113    researchTransportationButton = menuEntry.MenuEntry((20,100+ENTRY_SHIFT*1),False,researchTransportationDescription)
114   
115    researchMaterialDescription = description.Description('material',
116                                                    "This is where the text would go.",
117                                                    pygame.image.load(os.path.abspath(iconDir + "material.png")))
118    researchMaterialButton = menuEntry.MenuEntry((20,100+ENTRY_SHIFT*2),False,researchMaterialDescription)
119
120    researchMenu = inGameMenu.InGameMenu((20,20),False,'RESEARCH MENU','research.png')
121    researchMenu.addWindow(researchPowerButton)
122    researchMenu.addWindow(researchTransportationButton)
123    researchMenu.addWindow(researchMaterialButton)
124   
125    ###########################################################################################################
126
127    researchButton = onScreenButton.OnScreenButton((20 + 169,720), True,'RESEARCH')
128    researchButton.addWindow(researchMenu)   
129    researchButton.addResponse((researchMenu.toggle,))
130    researchButton.addResponse((buildMenu.closeWindow,)) 
131   
132    buildButton = onScreenButton.OnScreenButton((20,720),True,'BUILD')
133    buildButton.addWindow(buildMenu)   
134    buildButton.addResponse((buildMenu.toggle,))
135    buildButton.addResponse((researchMenu.closeWindow,))
136   
137    undoButton = onScreenButton.OnScreenButton((20 + 169*2,720), True,'UNDO TURN')
138   
139    menuButton = onScreenButton.OnScreenButton((20,20),True,'MAIN MENU')
140    menuButton.addResponse((mainMenuWindow.openWindow,))
141    menuButton.addResponse((resumeButton.openWindow,))
142    menuButton.addResponse((saveButton.openWindow,))
143    menuButton.addResponse((loadButton.openWindow,))
144    menuButton.addResponse((quitButton.openWindow,))
145    menuButton.addResponse((newGameButton.openWindow,))
146
147    newMap = map.Map((600,20),True)
148   
149   
150    ############################################################################################
151    newTop.addWindow(mainMenuWindow)
152    newTop.addWindow(menuButton)
153    newTop.addWindow(buildButton)
154    newTop.addWindow(researchButton)
155    newTop.addWindow(undoButton)
156    newTop.addWindow(newMap)
157   
158    newTop.addWindow(newBackground)
159   
160    ############################################################################################
161   
162    newTop.event(pygame.event.Event(VIDEORESIZE, {'w':SCREEN_W, 'h':SCREEN_H}))
163    newTop.render(screenSurface)
164    pygame.display.update()
165    return newTop
166
167if __name__ == '__main__':
168    # initialize pygame modules
169    pygame.init()
170    if not pygame.display.get_init():
171        print "Display Error"
172        pygame.quit()
173        sys.exit()
174       
175    # initialize our game   
176    top = Initialize()
177       
178    # run our game!
179    while True:
180        for e in pygame.event.get():
181            top.event(e)
182
183
184
185   
186   
Note: See TracBrowser for help on using the browser.