comparison gamelib/gamescreen.py @ 93:350ce4ebe122

Detail view without any functionality.
author Jeremy Thurgood <firxen@gmail.com>
date Tue, 24 Aug 2010 00:43:32 +0200
parents c76f2fad2af5
children 60770ca02c1a
comparison
equal deleted inserted replaced
92:642d84501fe3 93:350ce4ebe122
3 # Main menu for the game 3 # Main menu for the game
4 4
5 import textwrap 5 import textwrap
6 6
7 from albow.controls import Button, Label, Widget 7 from albow.controls import Button, Label, Widget
8 from albow.layout import Column 8 from albow.layout import Row
9 from albow.palette_view import PaletteView 9 from albow.palette_view import PaletteView
10 from albow.screen import Screen 10 from albow.screen import Screen
11 from pygame import Rect, mouse 11 from pygame import Rect, mouse
12 from pygame.color import Color 12 from pygame.color import Color
13 from pygame.locals import BLEND_ADD 13 from pygame.locals import BLEND_ADD
14 14
15 from constants import BUTTON_SIZE 15 from constants import SCREEN, BUTTON_SIZE, SCENE_SIZE
16 from cursor import CursorWidget 16 from cursor import CursorWidget
17 from hand import HandButton 17 from hand import HandButton
18 from popupmenu import PopupMenu, PopupMenuButton 18 from popupmenu import PopupMenu, PopupMenuButton
19 from state import initial_state, Item 19 from state import initial_state, Item
20 from widgets import BoomLabel 20 from widgets import BoomLabel
65 65
66 66
67 class StateWidget(CursorWidget): 67 class StateWidget(CursorWidget):
68 68
69 def __init__(self, state): 69 def __init__(self, state):
70 CursorWidget.__init__(self, Rect(0, 0, 800, 600 - BUTTON_SIZE)) 70 CursorWidget.__init__(self, Rect(0, 0, SCENE_SIZE[0], SCENE_SIZE[1]))
71 self.state = state 71 self.state = state
72 72
73 def draw(self, surface): 73 def draw(self, surface):
74 self.state.draw(surface) 74 self.state.draw(surface)
75 CursorWidget.draw(self, surface) 75 CursorWidget.draw(self, surface)
81 MessageDialog(result.message, 60).present() 81 MessageDialog(result.message, 60).present()
82 # queue a redraw to show updated state 82 # queue a redraw to show updated state
83 self.invalidate() 83 self.invalidate()
84 84
85 def mouse_move(self, event): 85 def mouse_move(self, event):
86 self.state.mouse_move(event.pos) 86 if not self.subwidgets:
87 self.state.mouse_move(event.pos)
87 CursorWidget.mouse_move(self, event) 88 CursorWidget.mouse_move(self, event)
88 89
89 90
90 class DetailWindow(Widget): 91 class DetailWindow(CursorWidget):
91 def mouse_down(self, e): 92 def __init__(self, state):
92 if e not in self: 93 Widget.__init__(self, Rect(0, 0, SCENE_SIZE[0], SCENE_SIZE[1]))
93 self.dismiss() 94 self.state = state
95 self.draw_area = Rect(0, 0, 300, 300)
96 self.draw_area.center = self.center
94 97
95 def draw(self, surface): 98 def draw(self, surface):
96 surface.fill(Color('green')) 99 surface.fill(Color('green'), self.draw_area)
100
101 def mouse_down(self, event):
102 if self.draw_area.collidepoint(event.pos):
103 # TODO: Interact with detail view
104 pass
105 else:
106 self.parent.remove(self)
107
108 def mouse_move(self, event):
109 if self.draw_area.collidepoint(event.pos):
110 # TODO: mouse_move stuff
111 pass
112 CursorWidget.mouse_move(self, event)
113
114
115 class ToolBar(Row, CursorWidget):
116 def __init__(self, items):
117 CursorWidget.__init__(self)
118 Row.__init__(self, items, spacing=0, width=SCREEN[0])
97 119
98 120
99 class GameScreen(Screen): 121 class GameScreen(Screen):
100 def __init__(self, shell): 122 def __init__(self, shell):
101 Screen.__init__(self, shell) 123 Screen.__init__(self, shell)
106 self.add(self.state_widget) 128 self.add(self.state_widget)
107 129
108 self.popup_menu = PopupMenu(shell) 130 self.popup_menu = PopupMenu(shell)
109 self.menubutton = PopupMenuButton('Menu', 131 self.menubutton = PopupMenuButton('Menu',
110 action=self.popup_menu.show_menu) 132 action=self.popup_menu.show_menu)
111 self.menubutton.bottomleft = self.bottomleft
112 self.add(self.menubutton)
113
114 self.detail = DetailWindow()
115 self.detail.rect = Rect(0, 0, 200, 200)
116
117 self.testbutton = Button('Test', action=self.detail.present)
118 self.testbutton.bottomright = self.bottomright
119 self.add(self.testbutton)
120 133
121 self.handbutton = HandButton(action=self.hand_pressed) 134 self.handbutton = HandButton(action=self.hand_pressed)
122 self.handbutton.bottomleft = self.bottomleft
123 self.handbutton.get_rect().move_ip(BUTTON_SIZE, 0)
124 self.add(self.handbutton)
125 135
126 self.inventory = InventoryView(self.state, self.handbutton) 136 self.inventory = InventoryView(self.state, self.handbutton)
127 self.inventory.bottomleft = self.bottomleft 137
128 self.inventory.get_rect().move_ip(2 * BUTTON_SIZE, 0) 138 self.testbutton = Button('Test', action=self.show_detail)
129 self.add(self.inventory) 139
140 self.toolbar = ToolBar([
141 self.menubutton,
142 self.handbutton,
143 self.inventory,
144 self.testbutton,
145 ])
146 self.toolbar.bottomleft = self.bottomleft
147 self.add(self.toolbar)
148
149 self.detail = DetailWindow(self.state)
130 150
131 # Test items 151 # Test items
132 self.state.add_inventory_item('triangle') 152 self.state.add_inventory_item('triangle')
133 153
154 def show_detail(self):
155 self.state_widget.add_centered(self.detail)
134 156
135 # Albow uses magic method names (command + '_cmd'). Yay. 157 # Albow uses magic method names (command + '_cmd'). Yay.
136 # Albow's search order means they need to be defined here, not in 158 # Albow's search order means they need to be defined here, not in
137 # PopMenu, which is annoying. 159 # PopMenu, which is annoying.
138 def hide_cmd(self): 160 def hide_cmd(self):