def graphics(self):
        logo = pygame.image.load(os.path.join('data', 'logo.png')).convert()
        self.ff_logo = pygame.transform.scale(logo,
                                              threades.resize_pos((1111, 250)))
        threades.screen.fill((0, 0, 0))
        threades.screen.blit(self.ff_logo, threades.resize_pos((40, 50)))

        # Font type
        myfont = pangofont.PangoFont(size=threades.resize_pt(17))

        #creating new label showing loading of level
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 1
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont
        labelStyleCopy['font-color'] = (0, 200, 0)

        if self.level_no == -1:
            text1 = _('Loading New Level...')
        else:
            text1 = _('Loading Level No:') + str(self.level_no)

        #creating the label
        label = gui.Label(position=threades.resize_pos((500, 600)),
                          size=threades.resize_pos((250, 50)),
                          parent=desktop_level,
                          style=labelStyleCopy,
                          text=text1)
Example #2
0
    def __init__(self):
        ''' Constructor
        '''
        global background_image
        self.chatWinFlag = False
        self.position = threades.resize_pos((15, 10))
        self.initial_position = threades.resize_pos((15, 10))
        self.final_position = threades.resize_pos((15, 750))
        self.update_win_pos = pygame.Rect(threades.resize_pos((150.0, 50.0)),
                                          threades.resize_pos((900, 800)))
        self.imageBox = pygame.image.load(os.path.join(
            'art', 'imageBox.png')).convert_alpha()
        self.chatBox = pygame.image.load(os.path.join(
            'art', 'chatBox.png')).convert_alpha()
        self.characterImage = {}
        self.characterImage['KAMAT'] = pygame.image.load(
            os.path.join('art', 'kamat.png')).convert_alpha()
        self.characterImage['SON'] = pygame.image.load(
            os.path.join('art', 'son.png')).convert_alpha()
        self.characterImage['AJMAL'] = pygame.image.load(
            os.path.join('art', 'ajmal.png')).convert_alpha()
        self.characterImage['SUKHDEV'] = pygame.image.load(
            os.path.join('art', 'sukhdev.png')).convert_alpha()
        self.characterImage['FARMER'] = pygame.image.load(
            os.path.join('art', 'villager.png')).convert_alpha()
        #  changes made while adding skip buttons etc
        self.size_win = threades.resize_pos((900.0, 800.0))
        #### TODO : This self.myfont is supposed to be replaced by pangofont when the storyboard will be translated, however, right now done like this
        #### as the characters doesn't appear to be coming completer otherwise, so need to solve the problem by the time we are going to localize
        #### the storyboard.
        self.myfont = pygame.font.Font("font.ttf", threades.resize_pt(16))
        #self.myfont = pangofont.PangoFont(size=threades.resize_pt(16))
        self.button_style = gui.defaultButtonStyle.copy()
        self.button_style['font'] = self.myfont

        #crating label textsurface
        #myfont = pygame.font.Font("font.ttf",10)
        #textColor = (0,0,0)
        #self.label_text='     ENTER : To show whole chat at once              ESC : To skip chat           '
        #self.label_textsurface=gui.renderText(self.label_text,myfont,True,textColor,(700,20),False,True)
        #self.label_tempSurface = pygame.transform.scale(self.chatBox,(800,30))

        self.label_text = '     ' + _(
            'ENTER : To show whole chat') + '              ' + _(
                'ESC : To skip chat') + '           '
        self.myfont2 = pangofont.PangoFont(size=threades.resize_pt(25))
        self.labelStyleCopy = gui.defaultLabelStyle.copy()
        self.labelStyleCopy['border-width'] = 1
        self.labelStyleCopy['wordwrap'] = True
        self.labelStyleCopy['autosize'] = False
        self.labelStyleCopy['font'] = self.myfont2
        self.labelStyleCopy['font-color'] = (255, 214, 150)
        self.labelStyleCopy['border-color'] = (255, 214, 150)
 def __init__(self,
              text=None,
              family=None,
              size=None,
              bold=False,
              italic=False,
              color=None,
              background=None):
     super(TextSprite, self).__init__()
     self.font = pangofont.PangoFont(family=family,
                                     size=size,
                                     bold=bold,
                                     italic=italic)
     self.set_color(color)
     self.set_background(background)
     self.set_text(text)
    def __init__(self):
        ''' Draws the Facilities panel
        '''
        self.update_flag = True
        myfont1 = pangofont.PangoFont(size=threades.resize_pt(
            25))  # For model.resources name and their value

        self.labelstyle1 = gui.defaultLabelStyle.copy()
        self.labelstyle1['border-width'] = 0
        self.labelstyle1['wordwrap'] = False
        self.labelstyle1['autosize'] = False
        self.labelstyle1['font'] = myfont1
        self.labelstyle1['font-color'] = self.font_color
        #self.labelstyle1['bg-color'] = self.font_bg_color

        self.list_titles = (_('Houses '), _('Schools '), _('Hospitals '),
                            _('Workshops '), _('Farms '), _('Wells '))
        self.list_names = (_('Number: '), _('Number: '), _('Number: '),
                           _('Number: '), _('Number: '), _('Number: '))
        self.list_values1 = (model.House.get_number(),
                             model.School.get_number(),
                             model.Hospital.get_number(),
                             model.Workshop.get_number(),
                             model.Farm.get_number(),
                             model.Fountain.get_number())
        self.list_values2 = (model.House.get_level(), model.School.get_level(),
                             model.Hospital.get_level(),
                             model.Workshop.get_level(),
                             model.Farm.get_level(),
                             model.Fountain.get_level())
        self.value_labels = []
        for i in range(6):
            label = gui.Label(position=threades.resize_pos((950, 50 + 55 * i)),
                              size=threades.resize_pos((300, 30)),
                              parent=threades.desktop,
                              text=self.list_titles[i],
                              style=self.labelstyle1)
            label = gui.Label(position=threades.resize_pos((950, 75 + 55 * i)),
                              size=threades.resize_pos((300, 30)),
                              parent=threades.desktop,
                              text=self.list_names[i] +
                              str(int(self.list_values1[i])) + _(' Level: ') +
                              str(int(self.list_values2[i])),
                              style=self.labelstyle1)
            label.surf.set_alpha(200)
            self.value_labels.append(label)
    def tradingWindow(self,
                      handle,
                      buddyName='Friend',
                      resource='Water',
                      quantity='0',
                      price='10',
                      trade='sell'):
        '''Opens the trading window at the reciever end for trading
        '''

        #self.font_color = (255,214,150) # Brown
        self.replyhandle = handle
        self.replymessage = ['TradeReply', resource, quantity, price, trade]
        color_blue = (0, 0, 250)
        myfont = pangofont.PangoFont(size=threades.resize_pt(17))
        # Custom Window Style
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont
        win_style['bg-color'] = (0, 0, 0)
        win_style['font-color'] = color_blue

        # Calculating position and size of window from the size of the desktop
        position_win = threades.resize_pos((725.0, 42.0))
        size_win = threades.resize_pos((470.0, 180.0))

        # Creating custom label style for the text to be displayed as a message
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont
        labelStyleCopy['font-color'] = color_blue
        #labelStyleCopy['font-color'] = font_color

        self.win = gui.Window(position=position_win,
                              size=size_win,
                              parent=threades.desktop,
                              text=_("Trade "),
                              style=win_style,
                              shadeable=False,
                              moveable=False)
        # Creating label
        label_text = '\n' + buddyName + _(
            ' wants to ') + trade + ' ' + quantity + _(
                ' units of ') + resource + '\n at $ ' + price
        message_label = gui.Label(position=threades.resize_pos(
            (5, 5), (470.0, 180.0), self.win.size),
                                  size=threades.resize_pos((460, 120),
                                                           (470.0, 180.0),
                                                           self.win.size),
                                  parent=self.win,
                                  text=label_text,
                                  style=labelStyleCopy)

        # Creating button style
        myfont2 = pangofont.PangoFont(size=threades.resize_pt(16))
        button_style = gui.defaultButtonStyle.copy()
        button_style['font'] = myfont2

        self.button_accept = gui.Button(position=threades.resize_pos(
            (100.0, 130.0), (470.0, 180.0), size_win),
                                        size=threades.resize_pos(
                                            (100.0, 40.0), (470.0, 180.0),
                                            size_win),
                                        parent=self.win,
                                        text=_(" Accept "),
                                        style=button_style)
        self.button_reject = gui.Button(position=threades.resize_pos(
            (300.0, 130.0), (470.0, 180.0), size_win),
                                        size=threades.resize_pos(
                                            (100.0, 40.0), (470.0, 180.0),
                                            size_win),
                                        parent=self.win,
                                        text=_(" Reject "),
                                        style=button_style)

        self.button_accept.onClick = self.checkTrade
        self.button_reject.onClick = self.closeWin

        sleep(6)
        if self.win:
            self.win.close()
    def showFailureWindow(self,text):
        
        self.brown_color = (255,214,150) 
        self.green_color = (0,250,0)
        self.black_color = (0,0,0)
        myfont1 = pangofont.PangoFont(size=threades.resize_pt(40))

        # Custom gui.Window Style
        win_style = gui.defaultWindowStyle.copy()
        win_style['font'] = myfont1
        win_style['font-color'] = self.brown_color
        win_style['bg-color'] = (0,0,0)
        win_style['border-color'] = self.brown_color
        win_style['border-width'] = 2
        
        st_desktop = gui.Desktop()
        clock = pygame.time.Clock()
        clock.tick()
        
        # Calculating position and size of window from the size of the threades.desktop
        position_win =threades.resize_pos((150.0,100.0))
        size_win =threades.resize_pos((900.0,500.0))

        # Creating window
        self.win = gui.Window(position = position_win, size = size_win, parent = st_desktop, text = _(" FoodForce2") , style = win_style, shadeable = False, closeable = False,moveable = False)
        #self.win.onClose = lambda button: self.main_menu(self.pause_flag)
        #self.win.surf.set_alpha(140) This seems to be redundant as translucency doesnt seems to work properly

        myfont2 = pangofont.PangoFont(size=threades.resize_pt(20))
        labelStyleCopy = gui.defaultLabelStyle.copy()
        labelStyleCopy['border-width'] = 0
        labelStyleCopy['wordwrap'] = True
        labelStyleCopy['autosize'] = False
        labelStyleCopy['font'] = myfont2
        labelStyleCopy['font-color'] = self.brown_color
        labelStyleCopy['border-color'] = self.black_color
        
        self.storyboardwin_run = True
        #logo =  pygame.image.load(os.path.join('data', 'logo.png')).convert()
        #ff_logo = pygame.transform.scale(logo,threades.resize_pos((1111,250)))
        
        #self.instructions_counter = 0
        label = gui.Label(position = threades.resize_pos((100.0,100.0),(900.0,500.0),self.win.size),size = threades.resize_pos((700.0,340.0),(900.0,500.0),self.win.size), parent = self.win, text = text, style = labelStyleCopy)

        gl_time = 0
        
        st_desktop.update()
        st_desktop.draw()
        pygame.display.update()
        
        while self.storyboardwin_run:
            pygame.display.set_caption('FoodForce2')
            
            for e in gui.setEvents(pygame.event.get()):
                if e.type == KEYDOWN:
                    if e.key == 27:  # For escape key
                        self.storyboardwin_run = False
                        
            gl_time += clock.tick()
            if gl_time >= 17000:
                self.storyboardwin_run = False
                
            
            
            
        event = game_events.Event(type = game_events.ACTIONCOMPLETEEVENT, facility_name = '', res_name = '' , res_quantity = 0)
        game_events.EventQueue.add(event)
    def __init__(self):
        ''' Draws the indicator panel on the surface
        '''

        self.update_flag = True

        myfont1 = pangofont.PangoFont(
            size=threades.resize_pt(30))  # For main heading

        myfont2 = pangofont.PangoFont(
            size=threades.resize_pt(25))  # For indicators name
        myfont3 = pangofont.PangoFont(size=threades.resize_pt(16), bold=True)
        # Creating a custom label style
        self.labelstyle1 = gui.defaultLabelStyle.copy()
        self.labelstyle1['border-width'] = 1
        self.labelstyle1['wordwrap'] = True
        self.labelstyle1['autosize'] = False
        self.labelstyle1['font'] = myfont1
        self.labelstyle1['font-color'] = self.font_color
        self.labelstyle1['border-color'] = self.color_grey
        # Drawing main Indicator label
        label = gui.Label(position=threades.resize_pos((900, 600)),
                          size=threades.resize_pos((300, 45)),
                          parent=threades.desktop,
                          text="      " + _("Indicators"),
                          style=self.labelstyle1)

        #print " deawing indicator panel"

        # Creating second custom label
        self.labelstyle2 = gui.defaultLabelStyle.copy()
        self.labelstyle2['border-width'] = 0
        self.labelstyle2['wordwrap'] = True
        self.labelstyle2['autosize'] = False
        self.labelstyle2['font'] = myfont2
        self.labelstyle2['font-color'] = self.font_color
        self.labelstyle2['border-color'] = self.color_grey
        # Drawing all the indicators
        ind_namelist = (_(' Housing'), _(' Nutrition'), _(' Health'),
                        _(' Education'), _(' Training'))

        # Creating second custom label
        self.labelstyle3 = gui.defaultLabelStyle.copy()
        self.labelstyle3['border-width'] = 0
        self.labelstyle3['wordwrap'] = False
        self.labelstyle3['autosize'] = True
        self.labelstyle3['font'] = myfont3
        self.labelstyle3['font-color'] = self.font_color
        self.labelstyle3['border-color'] = self.color_grey

        # Empty Dictionary for bar
        self.bar_dict = []
        name_label_size = threades.resize_pos((300, 25))
        self.value_labels = []
        for i in range(5):
            label = gui.Label(position=threades.resize_pos(
                (900, 650 + 50 * i)),
                              size=name_label_size,
                              parent=threades.desktop,
                              text=ind_namelist[i],
                              style=self.labelstyle2)
            self.bar_dict.append(bar((902, 677 + 50 * i)))
            label = gui.Label(position=threades.resize_pos(
                (1160, 677 + 50 * i)),
                              parent=threades.desktop,
                              text=str(0),
                              style=self.labelstyle3)
            self.value_labels.append(label)
    def __init__(self):
        ''' Draws the manpower panel
        '''

        self.update_flag = True
        myfont1 = pangofont.PangoFont(
            size=threades.resize_pt(30))  # For main heading
        myfont2 = pangofont.PangoFont(size=threades.resize_pt(
            25))  # For model.resources name and their value
        myfont3 = pangofont.PangoFont(size=threades.resize_pt(
            25))  # For model.resources name and their value

        # Creating a custom label style
        self.labelstyle1 = gui.defaultLabelStyle.copy()
        self.labelstyle1['border-width'] = 1
        self.labelstyle1['wordwrap'] = True
        self.labelstyle1['autosize'] = False
        self.labelstyle1['font'] = myfont1
        self.labelstyle1['font-color'] = self.font_color
        self.labelstyle1['border-color'] = self.color_grey

        # Drawing main Manpower Resources rectangle
        label = gui.Label(position=threades.resize_pos((0, 600)),
                          size=threades.resize_pos((400, 45)),
                          parent=threades.desktop,
                          text=_("  Manpower Distribution"),
                          style=self.labelstyle1)

        # Creating second label style
        self.labelstyle2 = gui.defaultLabelStyle.copy()
        self.labelstyle2['border-width'] = 0
        self.labelstyle2['wordwrap'] = True
        self.labelstyle2['autosize'] = False
        self.labelstyle2['font'] = myfont2
        self.labelstyle2['font-color'] = self.font_color
        self.labelstyle2['border-color'] = self.color_grey

        self.labelstyle3 = gui.defaultLabelStyle.copy()
        self.labelstyle3['border-width'] = 0
        self.labelstyle3['wordwrap'] = False
        self.labelstyle3['autosize'] = True
        self.labelstyle3['font'] = myfont3
        self.labelstyle3['font-color'] = self.font_color
        self.labelstyle3['border-color'] = self.color_grey

        # Drawing Manpower model.resources list
        list_names = (_(' Total Population'), _(' Sheltered People'),
                      _(' Educated People'), _(' Healthy People'),
                      _(' People Fed'), _(' People Employed'))
        list_values = (model.ppl.get_total_population(),
                       model.ppl.get_no_of_ppl_sheltered(),
                       model.ppl.get_no_of_ppl_educated(),
                       model.ppl.get_no_of_ppl_healthy(),
                       model.ppl.get_no_of_ppl_fed(),
                       model.ppl.get_total_no_of_ppl_emp())

        self.value_labels = []
        for i in range(6):
            label = gui.Label(position=threades.resize_pos((0, 645 + 35 * i)),
                              size=threades.resize_pos((350, 35)),
                              parent=threades.desktop,
                              text=list_names[i],
                              style=self.labelstyle2)
            label = gui.Label(position=threades.resize_pos(
                (355, 649 + 35 * i)),
                              parent=threades.desktop,
                              text=str(int(list_values[i])),
                              style=self.labelstyle3)
            self.value_labels.append(label)
    def __init__(self):
        ''' Draws the model.resources panel on the surface
        '''

        self.update_flag = True
        self.money_flag = True
        self.time_flag = False
        self.time_help_value = 0
        myfont1 = pangofont.PangoFont(
            size=threades.resize_pt(30))  # For main heading
        myfont2 = pangofont.PangoFont(size=threades.resize_pt(
            25))  # For model.resources name and their value
        myfont3 = pangofont.PangoFont(size=threades.resize_pt(16))
        myfont4 = pangofont.PangoFont(
            size=threades.resize_pt(18))  # For the display of model.money

        # Creating a custom label style
        self.labelstyle1 = gui.defaultLabelStyle.copy()
        self.labelstyle1['border-width'] = 1
        self.labelstyle1['wordwrap'] = True
        self.labelstyle1['autosize'] = False
        self.labelstyle1['font'] = myfont1
        self.labelstyle1['font-color'] = self.font_color
        self.labelstyle1['border-color'] = self.color_grey

        # Drawing main Resources rectangle
        label = gui.Label(position=threades.resize_pos((400, 600)),
                          size=threades.resize_pos((500, 45)),
                          parent=threades.desktop,
                          text="                    " + _("Resources"),
                          style=self.labelstyle1)

        # Creating second label style
        self.labelstyle2 = gui.defaultLabelStyle.copy()
        self.labelstyle2['border-width'] = 0
        self.labelstyle2['wordwrap'] = True
        self.labelstyle2['autosize'] = False
        self.labelstyle2['font'] = myfont2
        self.labelstyle2['font-color'] = self.font_color

        self.labelstyle3 = gui.defaultLabelStyle.copy()
        self.labelstyle3['border-width'] = 0
        self.labelstyle3['wordwrap'] = False
        self.labelstyle3['autosize'] = True
        self.labelstyle3['font'] = myfont3
        self.labelstyle3['font-color'] = self.font_color

        self.labelstyle4 = gui.defaultLabelStyle.copy()
        self.labelstyle4['border-width'] = 0
        self.labelstyle4['wordwrap'] = False
        self.labelstyle4['autosize'] = True
        self.labelstyle4['font'] = myfont4
        self.labelstyle4['font-color'] = (160, 160, 160)
        self.money_label = gui.Label(position=threades.resize_pos((850, 10)),
                                     parent=threades.desktop,
                                     text=_('Money -:') + '   ' +
                                     str(int(model.money.get_money())) +
                                     '      ',
                                     style=self.labelstyle4)
        self.time_label = gui.Label(position=threades.resize_pos((300, 10)),
                                    parent=threades.desktop,
                                    text=_('Time Elapsed -:') + '   ' +
                                    _('Level Just Started') + '      ',
                                    style=self.labelstyle4)
        self.value_labels = []
        # Drawing general model.resources list
        list_gen_res = (_(' Water'), _(' Building Materials'), _(' Tools'),
                        _(' Medicines'), _(' Books'))
        for i in range(5):
            label = gui.Label(position=threades.resize_pos(
                (400, 645 + 35 * i)),
                              size=threades.resize_pos((200, 35)),
                              parent=threades.desktop,
                              text=list_gen_res[i],
                              style=self.labelstyle2)
            label = gui.Label(
                position=threades.resize_pos((605, 649 + 35 * i)),
                parent=threades.desktop,
                text=str(int(model.resources[i].get_vquantity())),
                style=self.labelstyle3)
            self.value_labels.append(label)

        # Drawing food model.resources list
        list_food_res = (_(' Rice'), _(' Fruit & Vegatables'), _(' Beans'),
                         _(' Sugar'), _(' Salt'), _(' Oil'))
        for i in range(6):
            label = gui.Label(position=threades.resize_pos(
                (650, 645 + 35 * i)),
                              size=threades.resize_pos((200, 35)),
                              parent=threades.desktop,
                              text=list_food_res[i],
                              style=self.labelstyle2)
            label = gui.Label(position=threades.resize_pos(
                (855, 649 + 35 * i)),
                              parent=threades.desktop,
                              text=str(
                                  int(model.resources[i + 5].get_vquantity())),
                              style=self.labelstyle3)
            self.value_labels.append(label)