Exemplo n.º 1
0
 def color_picker_finish(self, the_color):
     # Reload the original parts images in the player descriptor
     for ptype in self.indexes.keys():
         thepart = self.player_descriptor.parts_list[ptype]
         thepart.load(thepart.filename)
     
     self.player_descriptor.color = the_color
     
     # Re-create the tank icon with the color
     self.tank_icon = render_tank_icon(self.player_descriptor)
Exemplo n.º 2
0
 def refresh_part(self, part_type, offset):
     # Refreshes part. Adjusts index by 'offset' and reloads new part.
     self.indexes[part_type] = roll_index(self.indexes[part_type] + offset, len(self.parts[part_type]))
     self.player_descriptor.parts_list[part_type] = parts.Part(self.parts[part_type][self.indexes[part_type]])
     
     # Re-create the tank icon with the new part
     self.tank_icon = render_tank_icon(self.player_descriptor)
     
     # Recalculate the stats
     self.player_descriptor.recalculate_stats()
     
     # Update the labels to reflect the new stats
     for stat_type, stat_label in self.labels.items():
         stat_label.text = DEF.PART_AUG_USER_STRINGS[stat_type] + " : " + str(self.player_descriptor.gather_augment_stat(stat_type) * 100) + "%"
Exemplo n.º 3
0
 def __init__(self, player_descriptor):
     self.desktop = gui.Desktop()
     
     # NOTE: this does not work as planned, both self.player_descriptor and self.original_descriptor
     # are actually "pointing" to the same class. This is evident since a) their id() is the same,
     # and b) the player_descriptor.color attribute is not getting restored when tank viewer is cancelled
     self.player_descriptor = player_descriptor
     self.original_descriptor = player_descriptor
     
     self.done = False
     self.tank_icon = render_tank_icon(player_descriptor)
     
     # Get the list of parts files
     self.parts = {}
     self.parts[DEF.PART_TYPE_TURRET] = glob.glob(DEF.PARTS_FILE_DIRECTORY + "Turret*.utp")
     self.parts[DEF.PART_TYPE_BODY]   = glob.glob(DEF.PARTS_FILE_DIRECTORY + "Body*.utp")
     self.parts[DEF.PART_TYPE_TRACKS] = glob.glob(DEF.PARTS_FILE_DIRECTORY + "Tracks*.utp")
     self.parts[DEF.PART_TYPE_CANNON] = glob.glob(DEF.PARTS_FILE_DIRECTORY + "Cannon*.utp")
     
     # Store what index is currently selected
     self.indexes = {}
     self.indexes[DEF.PART_TYPE_TURRET] = 0
     self.indexes[DEF.PART_TYPE_BODY]   = 0
     self.indexes[DEF.PART_TYPE_TRACKS] = 0
     self.indexes[DEF.PART_TYPE_CANNON] = 0
     
     # Find the actual index that we need to start with. The tank could have been non-default
     # parts to start editing from.
     for ptype in self.indexes.keys():
         thepart = self.player_descriptor.parts_list[ptype]
         self.indexes[ptype] = self.parts[ptype].index(thepart.getFilename())
     
     done_button = gui.Button((700,500),(95,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "Done")
     done_button.onClick = self.done_button
     cancel_button = gui.Button((800,500),(95,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "Cancel")
     cancel_button.onClick = self.cancel_button
     #Labels:
     self.player_descriptor.recalculate_stats()
     
     gui.Label((700,100), (100,50), self.desktop,
               style=RESRC.GUISTYLE_BIGLABEL,
               text="Stats:")
     gui.Label((50,50), (100,50), self.desktop,
               style=RESRC.GUISTYLE_BIGLABEL,
               text="Customize your tank.")
     
     # Create and save the labels displaying the overal stats
     self.labels = {}
     y = 150
     for stat_type, stat_string in DEF.PART_AUG_USER_STRINGS.items():
         self.labels[stat_type] = gui.Label((700,y), (100,50), self.desktop,
               style = RESRC.GUISTYLE_MEDLABEL,
               text = stat_string + " : " + str(self.player_descriptor.gather_augment_stat(stat_type) * 100) + "%")
         y += 25
     
     # Turret Buttons
     turret_select_left = gui.Button((100,100), (30,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "<")
     turret_select_left.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_TURRET, -1)
     turret_select_right = gui.Button((200,100), (30,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = ">")
     turret_select_right.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_TURRET, 1)
     
     # Body Buttons
     body_select_left = gui.Button((100,155), (30,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "<")
     body_select_left.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_BODY, -1)
     body_select_right = gui.Button((200,155), (30,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = ">")
     body_select_right.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_BODY, 1)
     
     # Tracks Buttons
     tracks_select_left = gui.Button((100,210), (30,50),
                             self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "<")
     tracks_select_left.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_TRACKS, -1)
     tracks_select_right = gui.Button((200,210), (30,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = ">")
     tracks_select_right.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_TRACKS, 1)
     
     # Cannon Buttons
     cannon_select_left = gui.Button((100,265), (30,50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "<")
     cannon_select_left.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_CANNON, -1)
     cannon_select_right = gui.Button((200,265),(30, 50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = ">")
     cannon_select_right.onClick = lambda button : self.refresh_part(DEF.PART_TYPE_CANNON, 1)
     
     # Color picker
     color_picker = gui.Button((100, 340), (75, 50),
                              self.desktop,
                              style=RESRC.GUISTYLE_BIGBUTTON,
                              text = "Color")
     color_picker.onClick = self.color_picker_begin