Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/FortuneMaker.activity/FortuneMaker.py
blob: 182c9e47f491e81519be201c586f8c8165e99d8e (plain)
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
from Room import Room
from Dungeon import Dungeon
from constants import THEME_NAME

from sugar.activity.activity import Activity, ActivityToolbox
from gettext import gettext as _

import gtk

MAX_GRID_WIDTH = 15
MAX_GRID_HEIGHT = 15
MIN_GRID_WIDTH = 2
MIN_GRID_HEIGHT = 2

class FortuneMaker(Activity):
    def __init__(self, handle):
        Activity.__init__(self, handle)

        self.dungeon = None
        self.active_room = None

        # INITIALIZE GUI
        ################
        self.set_title('File Share')

        # Create Toolbox
        toolbox = ActivityToolbox(self)
        self.set_toolbox(toolbox)
        toolbox.show()

        self.set_create_dungeon_settings()

    def view_change_cb(self, widget, view=None):
        if view == 'stats':
            self.view_dungeon_stats()
        elif view == 'layout':
            self.view_dungeon_grid()
        elif view == 'room':
            self.view_room()

    def set_gui_view(self,  view, buttons=False):
        if buttons:
            box = gtk.VBox()
            box.pack_start( self.get_button_bar(), False )
            box.pack_start(view)
            self.set_canvas( box )
        else:
            self.set_canvas( view )
        self.show_all()

    def get_button_bar(self):
        button_tabs = gtk.HBox()
        stats = gtk.Button( _("Dungeon Summery") )
        stats.set_alignment(0,.5)
        stats.connect( 'clicked', self.view_change_cb, 'stats')
        button_tabs.pack_start( stats, False )

        layout = gtk.Button( _("Dungeon Layout") )
        layout.set_alignment(0,.5)
        layout.connect( 'clicked', self.view_change_cb, 'layout')
        button_tabs.pack_start( layout, False )

        room = gtk.Button( _("Room Layout") )
        room.set_alignment(0,.5)
        room.connect( 'clicked', self.view_change_cb, 'room')
        button_tabs.pack_start( room, False )

        return button_tabs

    def set_create_dungeon_settings(self):
        window_container = gtk.VBox()

        ## Dungeon Properties
        ###############
        frame = gtk.Frame(_("Dungeon Properties"))

        container =  gtk.VBox()

        # Name
        row = gtk.HBox()
        label = gtk.Label(_("Name:"))
        label.set_alignment( 0, 0.5)
        row.pack_start( label )
        name = gtk.Entry()
        row.pack_end( name )
        container.pack_start( row, False )

        # Theme
        row = gtk.HBox()
        label = gtk.Label(_("Theme:"))
        label.set_alignment( 0, 0.5)
        row.pack_start( label )
        theme = gtk.combo_box_new_text()
        for option in THEME_NAME:
            theme.append_text( option )
        theme.set_active( 0 )
        row.pack_end( theme )
        container.pack_start( row, False )

        frame.add( container )
        window_container.pack_start( frame, False )

        ## Dungeon Size
        ###############
        frame = gtk.Frame(_("Dungeon Size"))

        # Width
        widthADJ = gtk.Adjustment(MIN_GRID_WIDTH, MIN_GRID_WIDTH, MAX_GRID_WIDTH, 1.0, 5.0, 0.0)
        widthspin = gtk.SpinButton(widthADJ, 0, 0)
        container = gtk.VBox()
        row = gtk.HBox()
        label = gtk.Label(_("Width:") )
        label.set_alignment( 0, 0.5)
        row.pack_start( label)
        row.pack_end( widthspin )
        container.pack_start( row, False )

        # Height
        heightADJ = gtk.Adjustment(MIN_GRID_HEIGHT, MIN_GRID_HEIGHT, MAX_GRID_HEIGHT, 1.0, 5.0, 0.0)
        heightspin = gtk.SpinButton(heightADJ, 0, 0)
        row = gtk.HBox()
        label = gtk.Label(_("Height:") )
        label.set_alignment( 0, 0.5)
        row.pack_start( label )
        row.pack_end( heightspin )
        container.pack_start( row, False )

        frame.add( container )
        window_container.pack_start( frame, False )

        ## Make Dungeon Button
        make_dungeon = gtk.Button(_("Create Dungeon"))
        make_dungeon.connect("clicked", self.create_dungeon_cb, {'name':name,'theme':theme,'width':widthspin,'height':heightspin})

        window_container.pack_start( make_dungeon, False )

        self.set_gui_view( window_container )

    def create_dungeon_cb(self, widget, data):
        name = data['name'].get_text()
        theme = data['theme'].get_active()  #.get_active_text()
        width = data['width'].get_value_as_int()
        height = data['height'].get_value_as_int()

        self.dungeon = Dungeon( name, theme, width, height )
        self.view_dungeon_stats()

    def view_dungeon_stats(self):
        dungeon_stats = gtk.HBox()
        dungeon_stats.pack_start(gtk.Label("Dungeon Statistics to be implemented"))
        self.set_gui_view( dungeon_stats, True )

    def view_dungeon_grid(self):
        room_array = self.dungeon.get_room_array()
        box = gtk.VBox()
        for row_array in room_array:
            row = gtk.HBox()
            box.pack_start( row, False )
            for room in row_array:
                room_gui = room.render_room()
                room_gui.connect('clicked', self.set_active_room, room)
                row.pack_start( room_gui, False )

        scroll = gtk.ScrolledWindow()
        scroll.add_with_viewport( box )

        self.set_gui_view( scroll, True )

    def view_room(self):
        dungeon_stats = gtk.HBox()
        dungeon_stats.pack_start(gtk.Label("room to be implemented"))
        self.set_gui_view( dungeon_stats, True )

    def set_active_room(self, widgit, room):
        self.active_room  = room
        self.view_room()

if __name__ == "__main__":

    aroom = Room()

    aroom.add_door('N', 'u')
    aroom.add_door('E', 'p')

    aroom.set_enemy(1,'2')
    aroom.set_enemy(3,'4')

    aroom.set_room_flag('P')
    #ADD SET ITEM WHEN CODED

    print aroom.room_to_string()