Exemple #1
0
 def get_info(self):
     basic_text = super(ItemSpec, self).get_info()
     if self.has_quality_for("cpu"):
         cpu = self.get_quality_for("cpu")
         cpu_text = _("Generates {0} CPU.").format(g.add_commas(cpu))
         return basic_text.replace("---", cpu_text + "\n---")
     return basic_text
    def update_item(self, canvas, name, key):
        visible = (key is not None)
        canvas.research_name.visible = visible
        canvas.alloc_cpus.visible = visible
        canvas.slider.visible = visible

        canvas.help_button.visible = False
        canvas.progress = 0

        if not visible:
            return

        danger = task.danger_for(key)
        if danger > 0 and g.pl.available_cpus[danger] == 0:
            canvas.help_button.visible = True
            canvas.help_button.args = (danger, )

        if key in g.pl.techs:
            canvas.progress = g.pl.techs[key].percent_complete().min()

        def my_slide(new_pos):
            self.handle_slide(key, new_pos)
            self.needs_rebuild = True

        canvas.slider.update_func = my_slide

        canvas.research_name.text = name

        if self.dirty_count:
            self.cpu_left = self.calc_cpu_left()
            self.dirty_count = False

        cpu = self.cpu_for(key)
        cpu_left = self.cpu_left[danger]
        total_cpu = cpu + cpu_left
        canvas.slider.slider_pos = cpu
        canvas.slider.slider_max = total_cpu
        canvas.slider.slider_size = ss = g.pl.available_cpus[0] // 10 + 1
        full_size = -.98
        if total_cpu:
            size_fraction = (total_cpu + ss) / float(g.pl.available_cpus[0] +
                                                     ss)
        else:
            # If people put all their bases to sleep, then total_cpu (and
            # g.pl.available_cpus[0]) are both 0.  This causes size_fraction
            # to become 1 and the slider will then take the entire width of
            # the research screen.  However, that looks odd - especially with
            # a help button, so we special case this here to ensure it looks
            # reasonable.
            size_fraction = .10
        canvas.slider.size = (full_size * size_fraction, -.4)
        canvas.alloc_cpus.text = g.add_commas(cpu)
Exemple #3
0
    def get_quality_info(self):
        bonus_text = ""

        for qual, value in self.item_qual.items():
            if qual == "cpu":
                bonus_text += _("CPU per day:") + " "
                bonus_text += g.add_commas(value)
            elif qual == "cpu_modifier":
                bonus_text += _("CPU bonus:") + " "
                bonus_text += g.to_percent(value)
            elif qual == "discover_modifier":
                bonus_text += _("Detection chance reduction:") + " "
                bonus_text += g.to_percent(value)
            bonus_text += "\n"

        return bonus_text
Exemple #4
0
    def update_item(self, canvas, name, key):
        visible = (key is not None)
        canvas.research_name.visible = visible
        canvas.alloc_cpus.visible = visible
        canvas.slider.visible = visible

        canvas.help_button.visible = False
        canvas.progress = 0

        if not visible:
            return

        danger = task.danger_for(key)
        if danger > 0 and g.pl.available_cpus[danger] == 0:
            canvas.help_button.visible = True
            canvas.help_button.args = (danger, )

        if key in g.pl.techs:
            canvas.progress = g.pl.techs[key].percent_complete().min()

        def my_slide(new_pos):
            self.handle_slide(key, new_pos)
            self.needs_rebuild = True

        canvas.slider.update_func = my_slide

        canvas.research_name.text = name

        if self.dirty_count:
            self.cpu_left = self.calc_cpu_left()
            self.dirty_count = False

        cpu = self.cpu_for(key)
        cpu_left = self.cpu_left[danger]
        total_cpu = cpu + cpu_left
        canvas.slider.slider_pos = cpu
        canvas.slider.slider_max = total_cpu
        canvas.slider.slider_size = ss = g.pl.available_cpus[0] // 10 + 1
        full_size = -.98
        size_fraction = (total_cpu + ss) / float(g.pl.available_cpus[0] + ss)
        canvas.slider.size = (full_size * size_fraction, -.4)
        canvas.alloc_cpus.text = g.add_commas(cpu)
Exemple #5
0
    def get_quality_info(self, if_installed_in_base=None, count=1):
        bonus_text = ""
        
        for qual, value in self.item_qual.items():
            if qual == "cpu":
                if if_installed_in_base is not None:
                    value = max(1, int(value * if_installed_in_base.compute_bonus // 10000))
                bonus_text += _("CPU per day:")+" "
                bonus_text += g.add_commas(value * count)
            elif qual == "cpu_modifier":
                bonus_text += _("CPU bonus:")+" "
                bonus_text += g.to_percent(value)
            elif qual == "discover_modifier":
                bonus_text += _("Detection chance reduction:")+" "
                bonus_text += g.to_percent(value)
            else:
                continue
            bonus_text += "\n"

        return bonus_text
 def display_value(self):
     if (hasattr(self, "_display") and callable(self._display)):
         return g.add_commas(self._display(self.value))
     else:
         return g.add_commas(self.value)