def loadImages(self, urls): nodepaths=[] # z is the vertical axis in the 3D world sx,sz = getattr(self.config,'f_scale',[1.0,1.0]) horGap = getattr(self.config,'f_horgap',0.1) vertGap = getattr(self.config,'f_vertgap',0.1) # for horizontal distribution # incX: distance between centers # inc = vertGap + 2.0*sx # startX is the first position (all the space / 2) incX = vertGap + 2.0*sx startX = - (len(urls)-1)*incX/2.0 # load each texture # the screen x coord in 2D goes from -1.6 to 1.6 (left to right horizontally) # the screen z coord in 2D goes from -1 to 1 (top-down vertically) try: for i in urls: # no need to reparent to render or aspect or anything!!!! nodepath = OnscreenImage( image = i , scale = Vec3(sx,1.0,sz)) nodepath.setTransparency(TransparencyAttrib.MAlpha) nodepath.setX(startX) startX += incX nodepaths.append(nodepath) except: print "Fatal error, could not load texture file or model in models/plane" print "Check the file path" sys.quit() return nodepaths
class Pointer(): def __init__(self): #----------------------------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------ #----------------------------------------------------------------------------------------------------------------------------------------------- self.bitmap = OnscreenImage(image="./tex/sun_cursor.png", pos=(0, 0, 0), hpr=None, scale=0.05, color=None, parent=None, sort=200) self.bitmap.setTransparency(TransparencyAttrib.MAlpha) #end __init__ #----------------------------------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------FUNCTIONS---------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------------------------------- # It sets the x position given def setPosX(self, x): self.posX = x * 1.3 self.bitmap.setX(self.posX) #end setPosX # It sets the y position given def setPosY(self, y): self.posY = y self.bitmap.setZ(self.posY)
class Pointer(): def __init__(self): #----------------------------------------------------------------------------------------------------------------------------------------------- #---------------------------------------------------VARIABLE DECLARATION------------------------------------------------------------------------ #----------------------------------------------------------------------------------------------------------------------------------------------- self.bitmap = OnscreenImage(image="./tex/sun_cursor.png", pos = (0, 0, 0),hpr=None, scale=0.05, color=None, parent=None, sort=200) self.bitmap.setTransparency(TransparencyAttrib.MAlpha) #end __init__ #----------------------------------------------------------------------------------------------------------------------------------------------- #----------------------------------------------------------------FUNCTIONS---------------------------------------------------------------------- #----------------------------------------------------------------------------------------------------------------------------------------------- # It sets the x position given def setPosX(self, x): self.posX = x*1.3 self.bitmap.setX(self.posX) #end setPosX # It sets the y position given def setPosY(self, y): self.posY = y self.bitmap.setZ(self.posY) #end setPosY
class SideBySideImage(Element): """ Class to display a two images side by side Will get some configuration from the corresponding JSON node. """ def __init__(self, **kwargs): """ world is a reference to the main class text: is the name of the node in the XML config """ # build basic element # self.sceneNP and self.hudNP are defined here super(SideBySideImage, self).__init__(**kwargs) urlA = getattr(self, 's_urlA', None) urlB = getattr(self, 's_urlB', None) if (urlA is None or urlB is None): print "Missing references of images to compare" sys.quit() sx, sz = getattr(self, 'f_scale', [1.0, 1.0]) # load textures try: self.imageNodeA = OnscreenImage(image=urlA, scale=Vec3(sx, 1.0, sz)) self.imageNodeA.setTransparency(TransparencyAttrib.MAlpha) self.imageNodeA.setX(-0.5) self.imageNodeB = OnscreenImage(image=urlB, scale=Vec3(sx, 1.0, sz)) self.imageNodeB.setTransparency(TransparencyAttrib.MAlpha) self.imageNodeB.setX(0.5) #planeNP = loader.loadModel("models/plane") #planeNP.setName(name) #planeNP.setTexture(t) #planeNP.setTransparency(1) #planeNP.setScale(1.0, 1.0, 1.0) #planeNP.reparentTo(self.hudNP) except: print "Fatal error, could not load texture file or model in models/plane" print "Check the file path" self.hideElement() def showElement(self): self.imageNodeA.show() self.imageNodeB.show() def hideElement(self): self.imageNodeA.hide() self.imageNodeB.hide() def enterState(self): print "entering FullScreenImage" # super class enterState Element.enterState(self) # self.registerKeys() def exitState(self): print "leaving state FullScreenImage" Element.exitState(self) self.unregisterKeys() self.imageNodeA.destroy() self.imageNodeB.destroy()
class SMGUICounter(): def __init__(self, icon, maxValue): self.value = 0 self.life = 0.0 self.basePos = Vec2(0.7, POS_TOP) self.maxValue = maxValue # Must be 1 or higher to activate. self.iconImg = OnscreenImage(image = ("../res/icons/gui_" + str(icon) + ".png"), pos = (self.basePos.getX(), 0, self.basePos.getY()), scale = 0.1) self.iconImg.setTransparency(TransparencyAttrib.MAlpha) strValue = str(self.value) if(self.maxValue > 0): strValue += ("/" + str(self.maxValue)) self.textObj = OnscreenText(text = strValue, style = 1, fg = (0,0,0,1), pos = (self.basePos.getX() + COUNT_OFFSET_X, self.basePos.getY() + COUNT_OFFSET_Y), align = TextNode.ARight, scale = .2) self.state = ST_IDLE #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Returns the GUI element type. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def getGUIType(self): return 1 #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Summons a 100-foot tall unicorn with chainsaws strapped to its back. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def updateGUI(self): dt = globalClock.getDt() state = self.state # State-based control if(state == ST_PEEK_IN): y = self.getYPos() if(y <= MIN_PEEK_HEIGHT): self.setState(ST_PEEK_WAIT) else: self.setYPos(y - PEEK_RATE * dt) elif(state == ST_PEEK_OUT): y = self.getYPos() if(y >= MAX_PEEK_HEIGHT): self.setState(ST_IDLE) self.life = 0.0 else: self.setYPos(y + PEEK_RATE * dt) elif(state == ST_PEEK_WAIT): if(self.getLife() > PEEK_TIME): self.setState(ST_PEEK_OUT) else: self.addLife() self.updateText() self.updatePos() def updatePos(self): x = self.basePos.getX() y = self.basePos.getY() self.iconImg.setX(x) self.iconImg.setZ(y) self.textObj.setX(x + COUNT_OFFSET_X) self.textObj.setY(y + COUNT_OFFSET_Y) def updateText(self): txt = str(self.value) if(self.maxValue > 0): txt += ("/" + str(self.maxValue)) self.textObj.setText(txt) #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Returns the peek state as an integer. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def getState(self): return self.state #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Sets the peek state. # setState(int a {0 - 3}) #------------------------------------------------------------------------------------------------------------------------------------------------------------ def setState(self, state): self.state = state; def setMaxValue(self, value): self.maxValue = value #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Adds 1 to the peek life counter. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def addLife(self): self.life += globalClock.getDt() #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Resets the peek life counter to 0. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def resetLife(self): self.life = 0.0 #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Makes this class get a freaking life and stop sitting on its lazy a- Wait, what? Oh, returns the current peek life. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def getLife(self): return self.life #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Gets the value of the tracked variable. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def getValue(self): return self.value #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Changes the variable behind the scenes with no peeking. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def setValue(self, value): self.value = value #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Adds a value to the tracked variable and peeks the counter out. Use negatives to subtract. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def increment(self): self.setState(ST_PEEK_IN) self.value += 1 #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Returns the OnScreenText object. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def getTextObj(self): return self.textObj #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Gets the vertical position of the text. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def getYPos(self): return self.basePos.getY() #------------------------------------------------------------------------------------------------------------------------------------------------------------ # Sets the Y position of both the label and value. #------------------------------------------------------------------------------------------------------------------------------------------------------------ def setYPos(self, ypos): self.basePos = Vec2(self.basePos.getX(), ypos)
class RightMenu: """ Add comment. """ def __init__(self): self.visible_x_np = None self.visible_y_np = None self.visible_z_np = None self.filter_label_np = None self.dims_parent_np = None # Dictionary for the tagset/dims self.dimensionCards = {} # Member variable for dimension/filter context menu. self.selected_tagset_id = None self.selected_hierarchy_id = None self.selected_filter_id = None # Create nodepath for the menu. self.right_menu_node_path = camera.attachNewNode( 'right_menu_node_path') self.right_menu_node_path.setY(3) # Flag for right menu visability. self.is_visable = True # Create background for the menu. self.bg = OnscreenImage(image='static/images/box.tif') self.bg.setTransparency(TransparencyAttrib.MAlpha) self.bg.setAlphaScale(0.24) self.bg.setScale(1, 2, 2) # start the placement task for menu placement. base.taskMgr.add(self.__placement, 'menuplacement_left_panel') # Collections of cards. Used for card highlighting. self.cards = dict() # How many dimensions should we show in the dimension list? self.max_dimension_visable_in_menu = 10 # Member variable for the dimensions scrollbar if needed. self.dimension_scrollbar = None # Create all the objects for this menu. self.__initalize_objects() self.__createTagsetAndHierarchyLabels() self.__register_view_menu_messages() # Create instance of filter menu. self.filter_menu = FilterMenu(np=self.right_menu_node_path, begin_pos=self.last_dim_pos) # Events that we are interested in. base.accept(CUBE_MENU_RELOAD_FILTERS, self.reload_filter2) base.accept(TAGSET_BTN_CLICK, self.btn_dimensions) base.accept(HIERARCHY_BTN_CLICK, self.btn_hierarchy) base.accept(SEARCH_BTN_CLICK, self.btn_search) base.accept(FILTER_BTN_CLICK, self.btn_filters) base.accept(CUBE_MENU_OVERVIEW_X_BUTTON_CLICK, self.btn_x_view) base.accept(CUBE_MENU_OVERVIEW_Y_BUTTON_CLICK, self.btn_y_view) base.accept(CUBE_MENU_OVERVIEW_Z_BUTTON_CLICK, self.btn_z_view) base.accept(CUBE_MENU_RELOAD_DIMENSIONS, self.reloadDimensionLabels) def reloadDimensionLabels(self): """ Function for reloading the tagset/hir list. This function is called when tagset/hir is changed or new are added. """ self.__createTagsetAndHierarchyLabels() #self.reload() def __createTagsetAndHierarchyLabels(self): if self.dims_parent_np is not None: self.dims_parent_np.remove() if self.dimension_scrollbar is not None: self.dimension_scrollbar.remove() # Create labels for each tagset and hirs. card_pos = -1.1 index = 0 # List that contains the dimension cards. Used for scrolling the cards. self.dimension_list = [] #self.cards = dict() self.dims_parent_np = self.right_menu_node_path.attachNewNode( 'parent_dim_np') for tagset in photocube.objectcube.objectCubeService.getAllTagsets(): if (tagset.typeId == 1 or tagset.typeId == 5) and ( tagset.name[:5] != 'Rank:' and tagset.name[:5] != 'Dist:' ): #FOR MASTER PRESENTATION, NOT SHOWING SEARCH DIMENSION #print 'tagset.name: ' + tagset.name + 'tagset.typeId: ' + str(tagset.typeId) dim_np = self.dims_parent_np.attachNewNode('dim;tagset;' + str(tagset.id)) # Create a card to make the dimension clickable card_np = dim_np.attachNewNode('card-tagset-' + tagset.name) card_np = card_np.attachNewNode('card-x-label-np') card_np.setPos(1, 1.5, 1.5) cm = CardMaker('card') card = card_np.attachNewNode(cm.generate()) card.setScale(0.50, 1, 0.050) card.setPos(-2.045, -1.3, card_pos) card.setTwoSided(True) card.setColor(0, 0, 0) # Make the tagset cards clickable. base.accept( photocube.devices.mouse_handler.makeNPPickableRight( dim_np), self.on_tagset_right_click) base.accept( photocube.devices.mouse_handler.makeNPPickableLeft(dim_np), self.on_tagset_right_click) # Create a new node for the text label. t_node = card.attachNewNode('card-label' + tagset.name) t_node.setY(-0.001) t_node.setZ(1.35) t_node.setX(0.03) t = OnscreenText(text=tagset.name[0:43] + ' (tagset)', fg=(1, 1, 1, 1), parent=t_node, pos=(0, -1, -4), scale=(0.075, 0.73), align=TextNode.ALeft) # Make the dim button mouse over enabled. if dim_np.__str__() not in self.cards.keys(): self.cards[dim_np.__str__()] = card self.dimension_list.append(dim_np) messageHover, messageLeave = photocube.devices.mouse_handler.makeNPMouseHoverable( dim_np) # When created, the menu is hided. dim_np.hide() # Accept the hover messages. base.accept(messageLeave, self.mouse_leave) base.accept(messageHover, self.mouse_over) """ dim_np = self.dims_parent_np.attachNewNode('dim;tagset;' + str(tagset.id)) # Create a card to make the dimension clickable card_np = dim_np.attachNewNode('card-tagset-'+ tagset.name) card_np = card_np.attachNewNode('card-x-label-np') card_np.setPos(1,1.5,1.5) cm = CardMaker('card') card = card_np.attachNewNode(cm.generate()) card.setScale(0.50, 1, 0.050) card.setPos(-2.045, -1.3, card_pos) card.setTwoSided(True) card.setColor(0,0,0) # Make the tagset cards clickable. base.accept(photocube.devices.mouse_handler.makeNPPickableRight(dim_np), self.on_tagset_right_click) base.accept(photocube.devices.mouse_handler.makeNPPickableLeft(dim_np), self.on_tagset_right_click) # Create a new node for the text label. t_node = card.attachNewNode( 'card-label' + tagset.name ) t_node.setY(-0.001) t_node.setZ(1.35) t_node.setX(0.03) t = OnscreenText(text=tagset.name[0:43] + ' (tagset)', fg=(1,1,1,1), parent=t_node, pos=(0, -1, -4), scale=(0.075, 0.73), align=TextNode.ALeft) # Make the dim button mouse over enabled. if dim_np.__str__() not in self.cards.keys(): self.cards[ dim_np.__str__() ] = card self.dimension_list.append( dim_np ) messageHover,messageLeave = photocube.devices.mouse_handler.makeNPMouseHoverable( dim_np ) # When created, the menu is hided. dim_np.hide() # Accept the hover messages. base.accept(messageLeave, self.mouse_leave) base.accept(messageHover, self.mouse_over) """ # show the hir if tagset.name[:5] != 'Rank:' and tagset.name[:5] != 'Dist:': #FOR MASTER PRESENTATION, NOT SHOWING SEARCH DIMENSION for hir in tagset.getPersistentDimensions(): hir_np = self.dims_parent_np.attachNewNode('dim;hir;' + tagset.name + ';' + str(hir.id) + ';' + str(tagset.id)) # Create a card to make the dimension clickable card_np = hir_np.attachNewNode('card-tagset-' + tagset.name) card_np = card_np.attachNewNode('card-x-label-np') card_np.setPos(1, 1.5, 1.5) cm = CardMaker('card-hir') card = card_np.attachNewNode(cm.generate()) card.setScale(0.50, 1, 0.050) card.setPos(-2.045, -1.3, card_pos) card.setTwoSided(True) card.setColor(0, 0, 0) # Make the hierachy card clickable. base.accept( photocube.devices.mouse_handler.makeNPPickableRight( hir_np), self.on_hierarchy_right_click) base.accept( photocube.devices.mouse_handler.makeNPPickableLeft( hir_np), self.on_hierarchy_right_click) # Make the hierachy card hoverable. messageHover, messageLeave = photocube.devices.mouse_handler.makeNPMouseHoverable( hir_np) base.accept(messageHover, self.mouse_over) base.accept(messageLeave, self.mouse_leave) # Create a new node for the text label. t_node = card.attachNewNode('card-label' + tagset.name) t_node.setY(-0.001) t_node.setZ(1.35) t_node.setX(0.03) t = OnscreenText(text=hir.getRoot().name + ' (hierarchy)', fg=(1, 1, 1, 1), parent=t_node, pos=(0, -1, -4), scale=(0.075, 0.73), align=TextNode.ALeft) # Make the dim button mouse over enabled. if hir_np.__str__() not in self.cards.keys(): self.cards[hir_np.__str__()] = card self.dimension_list.append(hir_np) photocube.devices.mouse_handler.makeNPMouseHoverable( hir_np) # Create label for filters if len(self.dimension_list) < self.max_dimension_visable_in_menu: self.last_dim_pos = -0.025 * len(self.dimension_list) else: self.last_dim_pos = -0.25 self.dimension_scrollbar = DirectScrollBar( range=(0, math.ceil(len(self.dimension_list))), orientation=DGG.VERTICAL, command=self.on_dimension_scroll_change, scrollSize=5, pageSize=len(self.dimension_list) / 5, value=0) self.dimension_scrollbar.setScale(0.5, 1, 0.69) self.dimension_scrollbar['frameColor'] = (0.6, 0.6, 0.6, 0.8) # disable the click sound for the scrollbar. self.dimension_scrollbar[ 'incButton_clickSound'] = button_mouseclick_sound self.dimension_scrollbar['incButton_rolloverSound'] = None self.dimension_scrollbar[ 'decButton_clickSound'] = button_mouseclick_sound self.dimension_scrollbar['decButton_rolloverSound'] = None self.dimension_scrollbar['thumb_clickSound'] = None self.dimension_scrollbar['thumb_rolloverSound'] = None self.dimension_scrollbar['incButton_relief'] = None self.dimension_scrollbar['decButton_relief'] = None self.dimension_scrollbar['decButton_text'] = '-' self.dimension_scrollbar['decButton_text_scale'] = 0.07 self.dimension_scrollbar['incButton_text'] = '+' self.dimension_scrollbar['incButton_text_scale'] = (0.07, 0.05) self.dimension_scrollbar['incButton_text_pos'] = (-0.005, -0.02) self.dimension_scrollbar['decButton_text_pos'] = (-0.005, -0.02) self.dimension_scrollbar['thumb_frameColor'] = (0, 0, 0, 0.2) self.dimenion_scroll_value = self.dimension_scrollbar['value'] self.text_dims = OnscreenText(mayChange=True, text='Filters:', fg=(1, 1, 1, 1), parent=self.right_menu_node_path, pos=(-1.10, self.last_dim_pos, -10), scale=(0.040), align=TextNode.ALeft) # create nodepath for the filter labels self.filter_label_np = self.right_menu_node_path.attachNewNode( 'filter-label-np') self.current_dimension_index_left = 0 self.current_dimension_index_right = self.max_dimension_visable_in_menu - 1 self.show_dimension_tabs() def __initalize_objects(self): # refactored from the function for dims labels reload self.text_dims = OnscreenText(text='Dimensions:', fg=(1, 1, 1, 1), parent=self.right_menu_node_path, pos=(-1.10, 0.45, -10), scale=0.040, align=TextNode.ALeft) # Create a label for the menu. self.text_dims = OnscreenText(mayChange=True, text='Visible:', fg=(1, 1, 1, 1), parent=self.right_menu_node_path, pos=(-1.10, 0.74, -10), scale=(0.040), align=TextNode.ALeft) self.visible_x_np = self.right_menu_node_path.attachNewNode( 'np_visiable_x') self.visible_x_np.setPos(-0.50, 0, 0.85) self.visible_x_np.setScale(0.6) self.text_x = OnscreenText(mayChange=True, text=EMPTY_ON_FRONT, fg=(1, 1, 1, 1), parent=self.visible_x_np, align=TextNode.ALeft, pos=(-0.95, -0.29, -0.21), scale=0.075) # Create clicable card for x. card_np = self.visible_x_np.attachNewNode( 'card-x-label-np').attachNewNode('card-x-label-np') card_np.setPos(1, 1.5, 1.5) cm = CardMaker('card-x') card = card_np.attachNewNode(cm.generate()) card.setScale(0.8, 1, 0.1) card.setPos(-1.93, -1.3, -1.78) card.setTwoSided(True) card.setColor(0, 0, 0) # Make the x view nodepath clickable. self.curXDimRightClickMessage = mouse_handler.makeNPPickableRight( self.visible_x_np) self.curXDimLeftClickMessage = mouse_handler.makeNPPickableLeft( self.visible_x_np) # Make the x view nodepath mouseoverable and save the nodepath for making it glow. self.cards[self.visible_x_np.__str__()] = card leavemessage, hoverMessage = photocube.devices.mouse_handler.makeNPMouseHoverable( self.visible_x_np) base.accept(hoverMessage, self.mouse_leave) base.accept(leavemessage, self.mouse_over) # Create notepath for y self.visible_y_np = self.right_menu_node_path.attachNewNode( 'np_visiable_y') self.visible_y_np.setPos(-0.50, 0, 0.78) self.visible_y_np.setScale(0.6) self.text_y = OnscreenText(mayChange=True, text=EMPTY_ON_IN, fg=(1, 1, 1, 1), parent=self.visible_y_np, align=TextNode.ALeft, pos=(-0.95, -0.29, 0.21), scale=0.075) # Create clicable card for y. card_np = self.visible_y_np.attachNewNode( 'card-y-label-np').attachNewNode('card-y-label-np') card_np.setPos(1, 1.5, 1.5) cm = CardMaker('card-y') card = card_np.attachNewNode(cm.generate()) card.setScale(0.8, 1, 0.1) card.setPos(-1.93, -1.3, -1.78) card.setTwoSided(True) card.setColor(0, 0, 0) card.setTransparency(TransparencyAttrib.MAlpha) self.curYDimRightClickMessage = mouse_handler.makeNPPickableRight( self.visible_y_np) self.curYDimLeftClickMessage = mouse_handler.makeNPPickableLeft( self.visible_y_np) # Make the y view nodepath mouseoverable. self.cards[self.visible_y_np.__str__()] = card #TODO: Here is a good place to refactor. photocube.devices.mouse_handler.makeNPMouseHoverable(self.visible_y_np) base.accept('zoomout_render/camera/right_menu_node_path/np_visiable_y', self.mouse_leave) base.accept('zoomin_render/camera/right_menu_node_path/np_visiable_y', self.mouse_over) # Create notepath for z self.visible_z_np = self.right_menu_node_path.attachNewNode( 'np_visiable_z') self.visible_z_np.setPos(-0.50, 0, 0.71) self.visible_z_np.setScale(0.6) self.text_z = OnscreenText(mayChange=True, text=EMPTY_ON_UP, fg=(1, 1, 1, 1), parent=self.visible_z_np, align=TextNode.ALeft, pos=(-0.95, -0.28, 0.21), scale=0.075) # Create clicable card for y. card_np = self.visible_z_np.attachNewNode( 'card-z-label-np').attachNewNode('card-z-label-np') card_np.setPos(1, 1.5, 1.5) cm = CardMaker('card-z') card = card_np.attachNewNode(cm.generate()) card.setScale(0.8, 1, 0.1) card.setPos(-1.93, -1.3, -1.78) card.setTwoSided(True) card.setColor(0, 0, 0) card.setTransparency(TransparencyAttrib.MAlpha) self.curZDimRightClickMessage = mouse_handler.makeNPPickableRight( self.visible_z_np) self.curZDimLeftClickMessage = mouse_handler.makeNPPickableLeft( self.visible_z_np) # Make the z view nodepath mouseoverable. self.cards[self.visible_z_np.__str__()] = card photocube.devices.mouse_handler.makeNPMouseHoverable(self.visible_z_np) base.accept('zoomout_render/camera/right_menu_node_path/np_visiable_z', self.mouse_leave) base.accept('zoomin_render/camera/right_menu_node_path/np_visiable_z', self.mouse_over) def on_dimension_scroll_change(self): val = int(self.dimension_scrollbar['value']) #print 'val', val if val == self.dimenion_scroll_value: return elif val < self.dimenion_scroll_value: for n in range(self.dimenion_scroll_value - val): self.dim_menu_move_up() else: for n in range(val - self.dimenion_scroll_value): self.dim_menu_move_down() #self.dimenion_scroll_value = self.dimension_scrollbar['value'] self.dimenion_scroll_value = val def show_dimension_tabs(self): card_pos = 0 i = 0 for card in self.dimension_list: card.hide() card.setX(100) for r in range(self.current_dimension_index_left, len(self.dimension_list)): self.dimension_list[r].show() self.dimension_list[r].setZ(card_pos) self.dimension_list[r].setX(0) card_pos -= 0.06 i += 1 if i is self.max_dimension_visable_in_menu: break def dim_menu_move_down(self): r = len(self.dimension_list) - self.current_dimension_index_right if r > 1: self.current_dimension_index_left += 1 self.current_dimension_index_right += 1 self.show_dimension_tabs() def dim_menu_move_up(self): if self.current_dimension_index_left > 0: self.current_dimension_index_left -= 1 self.current_dimension_index_right -= 1 self.show_dimension_tabs() def btn_filters(self, index): self.filter_menu.btn_filters(index) def mouse_over(self, p): if not photocube.ui.coremenu.context_menu_handler.has_open_context(): #print 'here', p c = self.cards[p.__str__()] #print c self.current_glowing_card = c c.setColor(0.15, 0.15, 0.15) def mouse_leave(self, p): if not photocube.ui.coremenu.context_menu_handler.has_open_context(): c = self.cards[p.__str__()] c.setColor(0, 0, 0) self.current_glowing_card = None def clear_glow(self, f=None): if not photocube.ui.coremenu.context_menu_handler.has_open_context(): #print 'clear' self.clear_all_glowings() def clear_all_glowings(self): for key in self.cards.keys(): card = self.cards[key] card.setColor(0, 0, 0) self.current_glowing_card = None def btn_x_view(self, index): self.clear_glow() if index == 'view up': x = photocube.cube.cubeService.coordinate.get_x() if x is not None: messenger.send('dim_move_to_axis', [X_AXIS, Z_AXIS]) action = ActionAxis(ACTION_MOVE, X_AXIS, Z_AXIS) actionManager.addAction(action) if index == 'view in': x = photocube.cube.cubeService.coordinate.get_x() if x is not None: messenger.send('dim_move_to_axis', [X_AXIS, Y_AXIS]) action = ActionAxis(ACTION_MOVE, X_AXIS, Y_AXIS) actionManager.addAction(action) if index == "swap with up": messenger.send('x_dim_action_swap', [Z_AXIS]) # create action for the swap. action = ActionAxis(ACTION_SWAP, X_AXIS, Z_AXIS) actionManager.addAction(action) if index == "swap with in": messenger.send('x_dim_action_swap', [Y_AXIS]) # create action for the swap. action = ActionAxis(ACTION_SWAP, X_AXIS, Y_AXIS) actionManager.addAction(action) if index is 'clear': messenger.send('dim_action_clear', [X_AXIS]) action = ActionAxis(ACTION_CLEAR, X_AXIS) actionManager.addAction(action) def btn_y_view(self, index): """ This function is called when we select buttons in the view y context menu. """ self.clear_glow() if index == 'clear': messenger.send('dim_action_clear', [Y_AXIS]) action = ActionAxis(ACTION_CLEAR, Y_AXIS) actionManager.addAction(action) if index == 'view front': y = photocube.cube.cubeService.coordinate.get_y() if y is not None: messenger.send('dim_move_to_axis', [Y_AXIS, X_AXIS]) action = ActionAxis(ACTION_MOVE, Y_AXIS, X_AXIS) actionManager.addAction(action) if index == 'view up': y = photocube.cube.cubeService.coordinate.get_y() if y is not None: messenger.send('dim_move_to_axis', [Y_AXIS, Z_AXIS]) action = ActionAxis(ACTION_MOVE, Y_AXIS, Z_AXIS) actionManager.addAction(action) if index == "swap with front": messenger.send('y_dim_action_swap', [X_AXIS]) action = ActionAxis(ACTION_SWAP, Y_AXIS, X_AXIS) actionManager.addAction(action) if index == "swap with up": messenger.send('y_dim_action_swap', [Z_AXIS]) action = ActionAxis(ACTION_SWAP, Y_AXIS, Z_AXIS) actionManager.addAction(action) def btn_z_view(self, index): self.clear_glow() if index == 'clear': messenger.send('dim_action_clear', [Z_AXIS]) action = ActionAxis(ACTION_CLEAR, Z_AXIS) actionManager.addAction(action) if index == 'view front': z = photocube.cube.cubeService.coordinate.get_z() if z is not None: messenger.send('dim_move_to_axis', [Z_AXIS, X_AXIS]) action = ActionAxis(ACTION_MOVE, Z_AXIS, X_AXIS) actionManager.addAction(action) if index == 'view in': z = photocube.cube.cubeService.coordinate.get_z() if z is not None: messenger.send('dim_move_to_axis', [Z_AXIS, Y_AXIS]) action = ActionAxis(ACTION_MOVE, Z_AXIS, Y_AXIS) actionManager.addAction(action) if index == "swap with front": messenger.send('z_dim_action_swap', [X_AXIS]) action = ActionAxis(ACTION_SWAP, Z_AXIS, X_AXIS) actionManager.addAction(action) if index == "swap with in": messenger.send('z_dim_action_swap', [Y_AXIS]) action = ActionAxis(ACTION_SWAP, Z_AXIS, Y_AXIS) actionManager.addAction(action) def btn_dimensions(self, index): self.clear_glow() tagset = photocube.objectcube.objectCubeService.get_tagset_by_id( self.selected_tagset_id) if index == 'view front': action = ActionTagset(ACTION_SET, tagset.id, X_AXIS) actionManager.addAction(action) messenger.send('dim_view_tagset', [X_AXIS, tagset]) if index == 'view in': action = ActionTagset(ACTION_SET, tagset.id, Y_AXIS) actionManager.addAction(action) messenger.send('dim_view_tagset', [Y_AXIS, tagset]) if index == 'view up': action = ActionTagset(ACTION_SET, tagset.id, Z_AXIS) actionManager.addAction(action) messenger.send('dim_view_tagset', [Z_AXIS, tagset]) if index == 'add dimension filter': dim_filter = ObjectCubePython.DimensionFilter( tagset.getDefaultDimension().getRoot(), tagset.id) filterManager.add_filter(dim_filter, True) # add action action = ActionFilter(ACTION_DIMENSIONFILTER, ACTION_ADD, tagsetId=tagset.id) actionManager.addAction(action) # reload filters menu. self.reload_filter2() if index == 'add tag filter': photocube.dialogs.dialogService.open_add_tagfilter(tagset) if index == 'add range filter': if tagset.typeId == 3: photocube.dialogs.dialogService.open_add_date_range(tagset) elif tagset.typeId == 4: photocube.dialogs.dialogService.open_add_time_range(tagset) else: photocube.dialogs.dialogService.open_add_numerical_range( tagset) if index == 'edit': photocube.dialogs.dialogService.openCreateNewTagsetDialog(tagset) def btn_hierarchy(self, index): # Get the tagset that the hir belongs to. tagset = photocube.objectcube.objectCubeService.get_tagset_by_id( self.selected_tagset_id) print 'selected_hierarchy_id: ' + str(self.selected_hierarchy_id) # Get the hirarchy from the tagset. dim = tagset.getDimension(int(self.selected_hierarchy_id)) print 'Dimension click' if index == 'view front': print 'DimId: ' + str(dim.id) print 'TagSetId: ' + str(tagset.id) print index + ': Begin' print 'ACTION_SET' print ACTION_SET print 'X_AXIS' print X_AXIS action = ActionHierachy(ACTION_SET, tagset.id, dim.id, X_AXIS) actionManager.addAction(action) print 'action' print action messenger.send('dim_view_hierarchy', [X_AXIS, dim]) print index + ': End' elif index == 'view in': action = ActionHierachy(ACTION_SET, tagset.id, dim.id, Y_AXIS) actionManager.addAction(action) messenger.send('dim_view_hierarchy', [Y_AXIS, dim]) elif index == 'view up': action = ActionHierachy(ACTION_SET, tagset.id, dim.id, Z_AXIS) actionManager.addAction(action) messenger.send('dim_view_hierarchy', [Z_AXIS, dim]) elif index == 'add dimension filter': dim_filter = ObjectCubePython.DimensionFilter( dim.getRoot(), tagset.id) filterManager.add_filter(dim_filter, True) # add action action = ActionFilter(ACTION_DIMENSIONFILTER, ACTION_ADD, tagsetId=tagset.id, hirarchyId=int(self.selected_hierarchy_id)) actionManager.addAction(action) self.reload_filter2() else: raise Exception('btn_hierarchy: unknown index: ' + index) def btn_search(self, index): tagset = photocube.objectcube.objectCubeService.get_tagset_by_id( self.selected_tagset_id) if index == 'search': print 'Vuubidu' photocube.dialogs.dialogService.openSearchDialogWithTagSet(tagset) def reload_filter2(self): self.filter_menu.reload() def on_x_view_right_click(self, f): photocube.ui.coremenu.context_menu_handler.open_x_view_context() def open_context_view_y(self, f): photocube.ui.coremenu.context_menu_handler.open_y_view_context() def open_context_view_z(self, f): photocube.ui.coremenu.context_menu_handler.open_z_view_context() def on_hierarchy_right_click(self, f): split_list = f.__str__().split(';') self.selected_hierarchy_id = int(split_list[3]) self.selected_tagset_id = int(split_list[4]) photocube.ui.coremenu.context_menu_handler.open_context_hierarchy() def on_tagset_right_click(self, f): """ Function for opening dimension context. """ split_list = f.__str__().split(';') self.selected_tagset_id = int(split_list[len(split_list) - 1]) t_id = photocube.objectcube.objectCubeService.get_tagset_by_id( self.selected_tagset_id).typeId print 't_id' + str(t_id) if t_id == photocube.objectcube.framework.TagSet.TYPE.ALPHANUMERICAL: print 'ALPHANUMERICAL' photocube.ui.coremenu.context_menu_handler.open_context_tagset_search_alphanumerical( ) elif t_id == photocube.objectcube.framework.TagSet.TYPE.RGB: print 'RGB' photocube.ui.coremenu.context_menu_handler.open_context_tagset_search_rgb( ) ''' if t_id == photocube.objectcube.framework.TagSet.TYPE.ALPHANUMERICAL: photocube.ui.coremenu.context_menu_handler.open_context_tagset_alphanumerical() else: photocube.ui.coremenu.context_menu_handler.open_context_tagset_numerical() ''' def hide(self): #self.right_menu_node_path.hide() if self.dimension_scrollbar is not None: self.dimension_scrollbar.hide() self.filter_menu.hide() # hide the background image self.bg.hide() self.is_visable = False def show(self): #self.right_menu_node_path.show() if self.dimension_scrollbar is not None: self.dimension_scrollbar.show() #self.filter_menu.show() # hide the background image #self.bg.show() self.is_visable = True def setXViewText(self, text): self.text_x.setText('front: ' + text) def setYViewText(self, text): self.text_y.setText('in: ' + text) def setZViewText(self, text): self.text_z.setText('up: ' + text) def __register_view_menu_messages(self): # Click messages for dimensions. base.accept(self.curXDimRightClickMessage, self.on_x_view_right_click) base.accept(self.curXDimLeftClickMessage, self.on_x_view_right_click) base.accept(self.curYDimRightClickMessage, self.open_context_view_y) base.accept(self.curYDimLeftClickMessage, self.open_context_view_y) base.accept(self.curZDimRightClickMessage, self.open_context_view_z) base.accept(self.curZDimLeftClickMessage, self.open_context_view_z) base.accept('clear_glow', self.clear_glow) base.accept('zoomout_none', self.clear_glow) def __placement(self, task): """ Called to fix the size, location of object when the aspect changes. """ if self.is_visable: base.camLens.setAspectRatio(base.getAspectRatio()) wp = base.win.getProperties() base.camLens.setAspectRatio( (wp.getXSize() + 0.0) / (wp.getYSize() + 0.0)) self.right_menu_node_path.show() self.right_menu_node_path.setX( (base.getAspectRatio() + (0.40 / base.getAspectRatio()))) # Fix the position of the menu background image. self.bg.setX(0.32 + base.getAspectRatio()) if self.dimension_scrollbar is not None: self.dimension_scrollbar.setX(base.getAspectRatio() - 0.04) self.dimension_scrollbar.setZ(0.18) else: # set the position for the dimensino buttons base.camLens.setAspectRatio(base.getAspectRatio()) wp = base.win.getProperties() base.camLens.setAspectRatio( (wp.getXSize() + 0.0) / (wp.getYSize() + 0.0)) #self.right_menu_node_path.setX( (base.getAspectRatio()+(0.3/base.getAspectRatio())) ) self.right_menu_node_path.hide() self.right_menu_node_path.setX(500) #THIS IS NOT ALLOWD, CLOSES CLUSTER MENUS AS WELL! #messenger.send('CLOSE_ALL_CONTEXT') # Fix the position of the menu background image. self.bg.setX(0.95 + base.getAspectRatio()) self.bg.show() return task.cont
class World(DirectObject): def __init__(self): self.start = False self.mainScreen = OnscreenImage(image = 'mainScreen.png') #self.mainScreen.setScale(1.25) self.accept("mouse1", self.begin) def begin(self): if self.start == False: self.start = True self.mainScreen.destroy() self.__init__1() def __init__1(self): #load physics base.enableParticles() #create a traverser base.cTrav = CollisionTraverser() self.cevent = CollisionHandlerEvent() self.cevent.addInPattern('into-%in') self.cevent.addOutPattern('outof-%in') #load all the models self.w_terrain = Terrain() self.p_bike = PlayerBike(base.cTrav) #disable mouse base.disableMouse() self.dead = False self.deadCount = 0 taskMgr.add(self.gameOverDead, 'deadTask') self.win = False self.winCount = 0 taskMgr.add(self.gameOverWin, 'winTask') #load and play background sound backgroundSound = base.loader.loadSfx('Modern_Battlefield.mp3') backgroundSound.setLoop(True) backgroundSound.play() #parent the camera to the player bike and offset the initial location base.camera.reparentTo(self.p_bike.bike) base.camera.setZ(6) base.camera.setP(-8) base.camera.setY(-32) #set up accept tasks #close the game self.accept("escape", sys.exit) #handle movement self.accept("arrow_up", self.p_bike.setDirection, ["forward", 1]) self.accept("arrow_right", self.p_bike.setDirection, ["right", 1]) self.accept("arrow_left", self.p_bike.setDirection, ["left", 1]) self.accept("arrow_up-up", self.p_bike.setDirection, ["forward", 0]) self.accept("arrow_right-up", self.p_bike.setDirection, ["right", 0]) self.accept("arrow_left-up", self.p_bike.setDirection, ["left", 0]) #handle shooting #self.accept("space", self.p_bike.setShoot, [1]) #self.accept("space-up", self.p_bike.setShoot, [0]) self.accept("z", self.p_bike.setShoot, [1]) self.accept("z-up", self.p_bike.setShoot, [0]) #powerup collisions self.accept("p_bike-powerup1", self.powerupCollision) self.accept("p_bike-powerup2", self.powerupCollision) self.accept("p_bike-powerup3", self.powerupCollision) self.accept("p_bike-powerup4", self.powerupCollision) self.accept("p_bike-powerup5", self.powerupCollision) #bullet collision with player self.accept("p_bike-bullet", self.bulletCollision) self.accept("e_bike-bullet", self.bulletCollision) #setup basic environment lighting self.ambientLight = AmbientLight("ambientLight") self.ambientLight.setColor((.25, .25, .25, 1)) self.ambientLightNP = render.attachNewNode(self.ambientLight) render.setLight(self.ambientLightNP) render.setShaderAuto() self.playerHealth = OnscreenImage(image = 'PlayerHealthBar.png') self.playerHealth.setX(-1) self.playerHealth.setZ(-1.95) #enemy health self.enemyHealth = OnscreenImage(image = 'EnemyHealthBar.png') self.enemyHealth.setX(1) self.enemyHealth.setZ(-1.95) self.initAI() self.e_bikes = [self.addEnemy()] base.cTrav.addCollider(self.p_bike.cNodePath1, self.e_bikes[0].cevent) def gameOverDead(self, task): if self.dead == True: self.deadCount += 1 if self.deadCount > 200: self.gameOver = OnscreenImage(image = 'gameOver.png') self.gameOver.setScale(1.35) return Task.cont def gameOverWin(self, task): if self.win == True: self.winCount += 1 if self.winCount > 200: self.gameOverWin = OnscreenImage(image = 'win.png') self.gameOverWin.setScale(1.35) return Task.cont def powerupCollision(self, cEntry): #check powerup1 if cEntry.getIntoNodePath() == self.w_terrain.cPowerNode1Path: self.w_terrain.powerUp1 = False self.p_bike.invin = True #print('I WIN') #check powerup2 elif cEntry.getIntoNodePath() == self.w_terrain.cPowerNode2Path: self.w_terrain.powerUp2 = False self.p_bike.shotgun = True self.p_bike.p_up_timer = 0 #check powerup3 elif cEntry.getIntoNodePath() == self.w_terrain.cPowerNode3Path: self.w_terrain.powerUp3 = False self.p_bike.shotgun = True self.p_bike.p_up_timer = 0 #check power4 elif cEntry.getIntoNodePath() == self.w_terrain.cPowerNode4Path: self.w_terrain.powerUp4 = False self.p_bike.health_up = True #check powerup5 elif cEntry.getIntoNodePath() == self.w_terrain.cPowerNode5Path: self.w_terrain.powerUp5 = False self.p_bike.health_up = True cEntry.getIntoNodePath().remove() def bulletCollision(self, cEntry): #check which bike is being hit if self.p_bike.invin == False and (cEntry.getFromNodePath() == self.p_bike.cNodePath1 or cEntry.getFromNodePath() == self.p_bike.cNodePath1 or cEntry.getFromNodePath() == self.p_bike.cNodePath3): #print('player bike!') self.p_bike.hp -= 1 self.playerHealth.setX(self.playerHealth.getX() - .1) #print('player hp:', self.p_bike.hp) if self.p_bike.hp <= 0: #kill player bike and reset camera taskMgr.remove("moveTask") taskMgr.remove("bulletTask") taskMgr.remove("shootTask") taskMgr.remove("powerupTask") x = base.camera.getX() + self.p_bike.bike.getX() y = base.camera.getY() + self.p_bike.bike.getY() h = self.p_bike.bike.getH() angle = deg2Rad(self.p_bike.bike.getH()) dy = -math.cos(angle) dx = math.sin(angle) dx = -dx * 32 dy = -dy * 32 base.camera.reparentTo(render) base.camera.setPos(0,0,0) base.camera.setPosHpr( self.p_bike.bike.getX() - dx, self.p_bike.bike.getY() - dy, 7, self.p_bike.bike.getH(), -8, 0) x = self.p_bike.bike.getX() y = self.p_bike.bike.getY() z = self.p_bike.bike.getZ() h = self.p_bike.bike.getH() self.p_bike.bike.delete() self.death_player = Actor("moto2_deadActor.egg", {"death":"moto2_deadAnim.egg"}) self.death_player.reparentTo(render) self.death_player.setPos(x,y,z) self.death_player.setH(h) self.animcontrol = self.death_player.getAnimControl('death') self.death_player.play("death") self.dead = True #UNCOMMENT WHEN ENEMY BIKES ARE FIXED else: for enemy in self.e_bikes: #print('in enemy list') #print(cEntry.getFromNodePath()) #print(cEntry.getFromNodePath().getParent()) #print(cEntry.getFromNodePath().getParent()) #print(enemy.cNodePath) #print(cEntry.getIntoNodePath()) #print(cEntry.getIntoNodePath().getParent()) if cEntry.getFromNodePath() == enemy.cNodePath1 or cEntry.getFromNodePath() == enemy.cNodePath2 or cEntry.getFromNodePath() == enemy.cNodePath3: #print('enemy hit') enemy.hp -= 1 self.enemyHealth.setX(self.enemyHealth.getX() + .1) #print('enemy hp:', enemy.hp) if enemy.hp <= 0: #print('Game Over. You Win!') #kill enemy bike x = enemy.cNodePath.getParent().getX() y = enemy.cNodePath.getParent().getY() z = enemy.cNodePath.getParent().getZ() h = enemy.cNodePath.getParent().getH() #print(x,y,z,h) enemy.cNodePath.getParent().remove() self.death_enemy = Actor("moto1_deadActor.egg", {"death":"moto1_deadAnim.egg"}) self.death_enemy.reparentTo(render) self.death_enemy.setPos(x,y,z) self.death_enemy.setH(h) self.death_enemy.play("death") self.win = True break #destroy the bullet for i in range(len(self.p_bike.bullet.bulletList)): if cEntry.getIntoNodePath().getParent() == self.p_bike.bullet.bulletList[i]: #print('erased') self.p_bike.bullet.bulletTime.remove(self.p_bike.bullet.bulletTime[i]) self.p_bike.bullet.bulletList.remove(self.p_bike.bullet.bulletList[i]) cEntry.getIntoNodePath().getParent().remove() break #UNCOMMENT WHEN ENEMY BIKES ARE FIXED #cycle through the enemy bullets for enemy in self.e_bikes: for i in range(len(enemy.bullet.bulletList)): if cEntry.getIntoNodePath().getParent() == enemy.bullet.bulletList[i]: #print('erased') enemy.bullet.bulletTime.remove(enemy.bullet.bulletTime[i]) enemy.bullet.bulletList.remove(enemy.bullet.bulletList[i]) cEntry.getIntoNodePath().getParent().remove() break def initAI(self): self.AIworld = AIWorld(render) #self.AIworld.addObstacle(self.w_terrain.wall_terrain) #self.AIworld.addObstacle(self.w_terrain.cNodePathWall1) #self.AIworld.addObstacle(self.w_terrain.cNodePathWall2) #self.AIworld.addObstacle(self.w_terrain.cNodePathWall3) #self.AIworld.addObstacle(self.w_terrain.cNodePathWall4) #self.AIworld.addObstacle(self.w_terrain.bounds) #AI World update taskMgr.add(self.AIUpdate,"AIUpdate") def AIUpdate(self, task): self.AIworld.update() for i in self.e_bikes: i.update() i.bike.setHpr(i.bike.getH(), 0, i.bike.getR()) #i.bike.setZ(max(0.0, i.bike.getZ())) #i.bike.setZ(0.0) #print i.bike.getHpr() return Task.cont def addEnemy(self): enemy = EnemyBike(base.cTrav, self.cevent) enemy.target = self.p_bike enemy.setMode('scan') self.AIworld.addAiChar(enemy.AIchar) base.cTrav.addCollider(self.p_bike.cNodePath1, enemy.cevent) return enemy
class Minimap: def __init__(self, path='/models', scale = 0.0, posX = -0.9, posZ = -0.65, mapimageName = None): taskMgr.add(self.step,"MinimapTask") self.path = path self.posX = posX self.posZ = posZ b = 500 pos = Vec3(self.posX,0,self.posZ)#Aspect2D coordinates for the location of the center of the minimap. if mapimageName is None: mapimageName = '%s/battlemap.png' % self.path#mapimage is the image to place in the minimap self.scale = scale #this value is the number of pixels wide the map will be. ratio = b/self.scale self.dotScale = (ratio) * b self.dotSize = 0.005 / ratio self.map = aspect2d.attachNewNode('Map') mapimage = self.getMapImage(mapimageName) props = base.win.getProperties( ) self.Height = float(props.getYSize()) self.Hscale = (1/self.Height) self.map.setScale(self.Hscale) #Sets scale to the screen resolution. self.map.setPos(pos) #this is the location on aspect2d for the minimap. self.dots = [] self.dots.append([]) self.targets = [] self.targets.append([]) self.teamImage = [] #a list of paths to the image that each team will use. self.setNumTeams(9) self.mapimage = OnscreenImage(image = mapimage, scale = self.scale, parent = self.map) self.mousePosition = OnscreenImage(image = self.path + 'select3.png', scale = self.dotSize*10, pos = (0,0,0), parent = aspect2d) self.totaltargets = 0 def destroy(self): """Remove Minimap from game""" for team in range(len(self.dots)): #will cycle through each team for i in range(len(self.dots[team])): #will cycle through each member of the team dot = self.dots[team][i] dot.removeNode() self.mousePosition.removeNode() self.mapimage.removeNode() self.map.removeNode() def getMapImage(self, mapimageName): texImage=PNMImage() texImage.read(Filename(mapimageName)) tex=Texture() tex.load(texImage) return tex def setTargets(self, targets, team): for i in range(len(targets)): self.targets[team].append(targets[i]) for i in range(len(self.targets[team])): self.dots[team].append(OnscreenImage(image = self.teamImage[team], scale = self.dotSize, pos = (0,0,0), parent = aspect2d)) def setBezel(self, image = None, scale = None): if image is None: image = '%s/bezel.png' % self.path if scale is None: scale = 1 self.bezel = OnscreenImage(image = image, scale = self.scale * scale, parent = self.map) self.bezel.setTransparency(TransparencyAttrib.MAlpha) def setScale(self, scale): self.scale = scale def setPos(self,num): #must be a Vec3 self.pos = num def appendTarget(self, target = None, team = None): #target must be a nodepath, team must be an integer if target is not None: self.targets[team].append(target) x = len(self.targets[team]) self.dots[team].append(OnscreenImage(image = self.teamImage[team], scale = self.dotSize, pos = (0,0,0), parent = aspect2d)) def setNumTeams(self, num): #Num must be an integer. Sets the number of different groups for the map to track. Each group may be tracked using a different graphic newTargets = [] for x in range(num): newTargets.append([]) self.dots.append([]) self.teamImage.append('%s/dot%d.png' % (self.path, x)) self.targets = newTargets def removeTarget(self, target = None, team = None): for i in range(len(self.targets[team])): if self.targets[team][i] == target: #This means the object in question is the object to be removed self.dots[team][i].stash() def step(self, task): try: for team in range(len(self.targets)): #will cycle through each team for i in range(len(self.targets[team])): #will cycle through each member of the team target = self.targets[team][i] if target.isEmpty() == False: x = (target.getX()/self.dotScale) + self.posX z = (target.getZ()/self.dotScale) + self.posZ self.dots[team][i].setX(x) self.dots[team][i].setZ(z) self.mousePosition.setX((camera.getX()/self.dotScale + self.posX)) self.mousePosition.setZ((camera.getZ()/self.dotScale + self.posZ)) return Task.cont except: pass