Ejemplo n.º 1
0
class GuiUnitInfo:
    def __init__(self, offset, parent, unit_type, default_hp, hp, default_ap, ap):
            
        self.offset = offset
        self.frame = DirectFrame(   relief = DGG.FLAT
                                  , scale = 1
                                  , frameSize = (-0.5, 0.5, 0, -0.5)
                                  , parent = parent )
        self.frame.setBillboardPointEye()
        self.frame.setLightOff()
        self.frame.setBin("fixed", 40)
        self.frame.setDepthTest(False)
        self.frame.setDepthWrite(False)
        
        fixedWidthFont = loader.loadFont(GUI_FONT)#@UndefinedVariable        
        #fixedWidthFont.setPixelsPerUnit(60)
        #fixedWidthFont.setRenderMode(fontt.RMSolid)
        if not fixedWidthFont.isValid():
            print "pandaInteractiveConsole.py :: could not load the defined font %s" % str(self.font)
            fixedWidthFont = DGG.getDefaultFont()
        
        self.label = OnscreenText( parent = self.frame
                              , text = ""
                              , pos = (offset.getX(),offset.getZ()+0.1)
                              , align=TextNode.ACenter
                              , mayChange=True
                              , scale=0.1
                              , fg = (1,0,0,1)
                              #, shadow = (0, 0, 0, 1)
                              #, frame = (200,0,0,1) 
                              )
        self.label.setFont( fixedWidthFont )
        #self.label.setLightOff()

        self.all_icons = {}
        self.visible_icons = {}
        self.addIcon("overwatch")
        self.addIcon("set_up")
        
        self.ap_bar = DirectWaitBar(parent = self.frame
                                  , text = ""
                                  , range = default_ap
                                  , value = ap
                                  , pos = (offset.getX()+0.08,0,offset.getZ()-0.27)
                                  , barColor = (0,0,1,1)
                                  , frameColor = (0,0,0.5,0.2)
                                  , scale = (0.3,0.5,0.3))
        
        self.hp_bar = DirectWaitBar(parent = self.frame
                                  , text = ""
                                  , range = default_hp
                                  , value = hp
                                  , pos = (offset.getX()+0.08,0,offset.getZ()-0.2)
                                  , barColor = (0,1,0,1)
                                  , frameColor = (1,0,0,0.9)
                                  , scale = (0.3,0.5,0.3))
        
        self.insignia = OnscreenImage(parent = self.frame
                                            ,image = "unit_" + unit_type + "_big_transparent_32.png"
                                            #,pos = (offset.getX(),0,offset.getZ()+0.14)
                                            , pos = (offset.getX() - 0.31,0,offset.getZ()-0.23)
                                            ,scale = 0.09)
        self.insignia.setTransparency(TransparencyAttrib.MAlpha)

    def addIcon(self, name):
        self.all_icons[name] = OnscreenImage(parent = self.frame
                                            ,image = name + "_icon.png"
                                           #,pos = offset + (0,0,-0.1)
                                            ,scale = 0.08)
        
        self.all_icons[name].setTransparency(TransparencyAttrib.MAlpha)
        self.all_icons[name].hide()
        
    def write(self, text):
        text = ""
        self.label.setText(text)
        
    def redraw(self):
        return

    def remove(self):
        self.frame.remove()
        
    def reparentTo(self, parent):
        self.frame.reparentTo(parent)
        
    def hide(self):
        self.label.hide()
        
    def show(self):
        self.label.show()
    
    def refreshBars(self, hp, ap):
        self.ap_bar['value'] = ap
        self.hp_bar['value'] = hp
        self.ap_bar.setValue()
        self.hp_bar.setValue()
        
    def refreshIcons(self):
        count = len(self.visible_icons)
        start_pos =  (1 - count) * 0.25 / 2
        for icon in self.all_icons:
            if icon in self.visible_icons:
                self.visible_icons[icon].setPos(self.offset + (start_pos, 0, -0.08))
                self.visible_icons[icon].show()
                start_pos += 0.21
            else:
                self.all_icons[icon].hide()
            
    def hideOverwatch(self):
        if "overwatch" in self.visible_icons:
            self.visible_icons.pop("overwatch")
        self.refreshIcons()

    def showOverwatch(self):
        self.visible_icons["overwatch"] = self.all_icons["overwatch"]
        self.refreshIcons()
    
    def hideSetUp(self):
        if "set_up" in self.visible_icons:
            self.visible_icons.pop("set_up")
        self.refreshIcons()

    def showSetUp(self):
        self.visible_icons["set_up"] = self.all_icons["set_up"]
        self.refreshIcons()