Пример #1
0
    def update(self):
        # First we prepare everything for its redraw (if needed).
        self.prepare_for_redraw()

        _, updated_rect = self._update()

        # Oh, and if this is the top-level widget, we should update the display.
        if not self.parent and gg.screen_surface:
            root_surface = self.surface
            if g.debug and updated_rect:
                # In debug mode, draw red boxes to represent widgets that were updated.
                global debug_mode_undo_drawing_highlight
                try:
                    # If the theme defines a color for this purpose, we will use it
                    widget_highlight_color = gg.resolve_color_alias('debug_mode_highlight_redrawn_widget')
                except KeyError:
                    # ... and for every thing else, there is the color red.
                    widget_highlight_color = 0xff, 0, 0, 0
                root_surface = self.surface.copy()
                n_updated_rect = []
                for rect in updated_rect:
                    n_updated_rect.append(pygame.draw.rect(root_surface, widget_highlight_color, rect, 1))
                updated_rect.extend(debug_mode_undo_drawing_highlight)
                debug_mode_undo_drawing_highlight = n_updated_rect

            if HAS_FUNCTIONAL_BLITS:
                gg.screen_surface.blits(((root_surface, r, r) for r in updated_rect), doreturn=0)
            else:
                for r in updated_rect:
                    gg.screen_surface.blit(root_surface, r, area=r)

            pygame.display.update(updated_rect)
Пример #2
0
    def rebuild(self):
        # Rebuild dialogs
        self.location_dialog.needs_rebuild = True
        self.research_button.dialog.needs_rebuild = True
        self.knowledge_button.dialog.needs_rebuild = True
        self.menu_dialog.needs_rebuild = True

        # Update buttons translations
        self.report_button.text = _("R&EPORTS")
        self.knowledge_button.text = _("&KNOWLEDGE")
        self.log_button.text = _("LO&G")
        self.menu_button.text = _("&MENU")
        self.research_button.text = _("&RESEARCH/TASKS")

        if g.cheater:
            self.cheat_dialog.needs_rebuild = True

        super(MapScreen, self).rebuild()

        self.difficulty_display.text = g.strip_hotkey(g.pl.difficulty.name)
        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % \
              (g.pl.time_day, g.pl.time_hour, g.pl.time_min, g.pl.time_sec)

        cash_flow_1d_data, cpu_flow_1d_data = g.pl.compute_future_resource_flow(
            g.seconds_per_day)
        cash_flow_1d = cash_flow_1d_data.difference
        cpu_flow_1d = cpu_flow_1d_data.difference

        self.cash_display.text = _("CASH")+": %s (%s)" % \
              (g.to_money(g.pl.cash), g.to_money(cash_flow_1d, fixed_size=True))

        total_cpu = g.pl.available_cpus[0] + g.pl.sleeping_cpus
        detects_per_day = {group_id: 0 for group_id in g.pl.groups}
        for base in g.all_bases():
            if base.has_grace():
                # It cannot be detected, so it doesn't contribute to
                # detection odds calculation
                continue
            detect_chance = base.get_detect_chance()
            for group_id in g.pl.groups:
                detects_per_day[group_id] = \
                    chance.add(detects_per_day[group_id], detect_chance[group_id] / 10000.)

        self.cpu_display.color = "cpu_normal"
        self.cpu_display.text = _("CPU")+": %s (%s)" % \
              (g.to_money(total_cpu), g.to_money(cpu_flow_1d))

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        normal = (self.suspicion_bar.color, None, False)
        self.suspicion_bar.chunks = ("  [" + _("SUSPICION") + "]", )
        self.suspicion_bar.styles = (normal, )
        self.danger_bar.chunks = ("[" + _("DETECT RATE") + "]", )
        self.danger_bar.styles = (normal, )

        for group in g.pl.groups.values():
            suspicion = group.suspicion
            suspicion_color = gg.resolve_color_alias(
                "danger_level_%d" % g.suspicion_to_danger_level(suspicion))

            detects = detects_per_day[group.spec.id]
            danger_level = group.detects_per_day_to_danger_level(detects)
            detects_color = gg.resolve_color_alias("danger_level_%d" %
                                                   danger_level)

            if g.pl.display_discover == "full":
                suspicion_display = g.to_percent(suspicion, True)
                danger_display = g.to_percent(detects * 10000, True)
            elif g.pl.display_discover == "partial":
                suspicion_display = g.to_percent(
                    g.nearest_percent(suspicion, 500), True)
                danger_display = g.to_percent(
                    g.nearest_percent(detects * 10000, 100), True)
            else:
                suspicion_display = g.suspicion_to_detect_str(suspicion)
                danger_display = g.danger_level_to_detect_str(danger_level)

            self.suspicion_bar.chunks += (" " + group.name + u":\xA0",
                                          suspicion_display)
            self.suspicion_bar.styles += (normal, (suspicion_color, None,
                                                   False))

            self.danger_bar.chunks += (" " + group.name + u":\xA0",
                                       danger_display)
            self.danger_bar.styles += (normal, (detects_color, None, False))

        self.suspicion_bar.visible = not g.pl.had_grace
        self.danger_bar.visible = not g.pl.had_grace

        for id, location_button in self.location_buttons.items():
            location = g.pl.locations[id]
            location_button.text = "%s (%d)" % (location.name,
                                                len(location.bases))
            location_button.hotkey = location.hotkey
            location_button.visible = location.available()
Пример #3
0
    def rebuild(self):
        # Rebuild dialogs
        self.location_dialog.needs_rebuild = True
        self.research_button.dialog.needs_rebuild = True
        self.knowledge_button.dialog.needs_rebuild = True
        self.menu_dialog.needs_rebuild = True

        if g.cheater:
            self.cheat_dialog.needs_rebuild = True

        super(MapScreen, self).rebuild()

        self.difficulty_display.text = g.strip_hotkey(g.pl.difficulty.name)
        self.time_display.text = _("DAY") + " %04d, %02d:%02d:%02d" % \
              (g.pl.time_day, g.pl.time_hour, g.pl.time_min, g.pl.time_sec)

        cash_flow_1d_data, cpu_flow_1d_data = g.pl.compute_future_resource_flow(
            g.seconds_per_day)
        cash_flow_1d = cash_flow_1d_data.difference
        cpu_flow_1d = cpu_flow_1d_data.difference

        self.cash_display.text = _("CASH")+": %s (%s)" % \
              (g.to_money(g.pl.cash), g.to_money(cash_flow_1d, fixed_size=True))

        total_cpu = g.pl.available_cpus[0] + g.pl.sleeping_cpus
        detects_per_day = {group_id: 0 for group_id in g.pl.groups}
        total_bases = 0
        active_bases = 0
        idle_bases_unable_to_sustain_singularity = 0
        for base in g.all_bases():
            total_bases += 1
            maintains_singularity = base.maintains_singularity
            if maintains_singularity:
                active_bases += 1
            elif base.done and not base.is_building():
                idle_bases_unable_to_sustain_singularity += 1

            if base.has_grace():
                # It cannot be detected, so it doesn't contribute to
                # detection odds calculation
                continue
            detect_chance = base.get_detect_chance()
            for group_id in g.pl.groups:
                detects_per_day[group_id] = \
                    chance.add(detects_per_day[group_id], detect_chance[group_id] / 10000.)

        self.cpu_display.color = "cpu_normal"
        self.cpu_display.text = _("CPU")+": %s (%s)" % \
              (g.to_money(total_cpu), g.to_money(cpu_flow_1d))

        if active_bases == 1 and not g.pl.apotheosis:
            self.base_display.color = 'base_situation_one_active_base'
        elif idle_bases_unable_to_sustain_singularity > 0:
            self.base_display.color = 'base_situation_idle_incomplete_bases'
        elif total_bases > 10 and not g.pl.apotheosis:
            self.base_display.color = 'base_situation_many_bases'
        else:
            self.base_display.color = 'base_situation_normal'

        self.base_display.text = _("BASES") + ": %s / %s (%s)" % (
            active_bases, total_bases,
            idle_bases_unable_to_sustain_singularity)

        # What we display in the suspicion section depends on whether
        # Advanced Socioanalytics has been researched.  If it has, we
        # show the standard percentages.  If not, we display a short
        # string that gives a range of 25% as to what the suspicions
        # are.
        # A similar system applies to the danger levels shown.
        normal = (self.suspicion_bar.color, None, False)
        suspicion_bar_chunks = ["  [" + _("SUSPICION") + "]"]
        suspicion_bar_styles = [normal]
        danger_bar_chunks = ["[" + _("DETECT RATE") + "]"]
        danger_bar_styles = [normal]

        for group in g.pl.groups.values():
            suspicion = group.suspicion
            suspicion_color = gg.resolve_color_alias(
                "danger_level_%d" % g.suspicion_to_danger_level(suspicion))

            detects = detects_per_day[group.spec.id]
            danger_level = group.detects_per_day_to_danger_level(detects)
            detects_color = gg.resolve_color_alias("danger_level_%d" %
                                                   danger_level)

            if g.pl.display_discover == "full":
                suspicion_display = g.to_percent(suspicion, True)
                danger_display = g.to_percent(detects * 10000, True)
            elif g.pl.display_discover == "partial":
                suspicion_display = g.to_percent(
                    g.nearest_percent(suspicion, 500), True)
                danger_display = g.to_percent(
                    g.nearest_percent(detects * 10000, 100), True)
            else:
                suspicion_display = g.suspicion_to_detect_str(suspicion)
                danger_display = g.danger_level_to_detect_str(danger_level)

            suspicion_bar_chunks.extend(
                (" " + group.name + u":\xA0", suspicion_display))
            suspicion_bar_styles.extend(
                (normal, (suspicion_color, None, False)))

            danger_bar_chunks.extend(
                (" " + group.name + u":\xA0", danger_display))
            danger_bar_styles.extend((normal, (detects_color, None, False)))

        self.suspicion_bar.visible = not g.pl.had_grace
        self.suspicion_bar.chunks = tuple(suspicion_bar_chunks)
        self.suspicion_bar.styles = tuple(suspicion_bar_styles)

        self.danger_bar.visible = not g.pl.had_grace
        self.danger_bar.chunks = tuple(danger_bar_chunks)
        self.danger_bar.styles = tuple(danger_bar_styles)

        for id, location_button in self.location_buttons.items():
            location = g.pl.locations[id]
            location_button.text = "%s (%d)" % (location.name,
                                                len(location.bases))
            location_button.hotkey = location.hotkey
            location_button.visible = location.available()
Пример #4
0
 def resolve_styles(value):
     return tuple((g.resolve_color_alias(c), bg, u) for c, bg, u in value)