def onEvent(self, e): if e.eventType == "research_begin": #dayum. work! r = savage.ResearchItem(e.objtype, e.sourceId, savage.getGameTime(), 0); #do we have this exact thing already? remove it first (just purchased) for item in self.items: if item.item.objtype == e.objtype: if item.action == None: item.item.builder = e.sourceId; elif item.action.item == r: #who is naming this stuff? :P item.action = None; return; item = ResearchManagerItem(r); self.itemsContainer.add(item); self.items.append(item); elif e.eventType == "research_complete" or e.eventType == "research_cancel": for item in self.items: if item.item.objtype == e.objtype and item.item.builder == e.sourceId: self.items.remove(item); self.itemsContainer.remove(item); item.erase(); elif e.eventType == "research_queued": for item in self.items: if item.item.objtype == e.objtype and item.item.builder == e.sourceId: item.action = None; elif e.eventType == "team_reset": for item in self.items: self.itemsContainer.remove(item); item.erase(); del self.items[:];
def onEvent(self, e): if e.eventType == "research_begin" and self.object: if e.sourceId == self.object.objectId: ri = savage.ResearchItem(e.objtype, e.sourceId, savage.getGameTime(), 0); self.newResearch(ri); elif e.eventType == "research_complete": self.buildContext(self.context);
def update(self): player = savage.getLocalPlayer(); self.unitViewer.setModel( player.getType().getValue("model") ); self.unitViewer.fitCameraToModel(40); for b in self.techButtons: b.update(); for b in self.inventory: b.update(); for b in self.units: b.update(); if player.getRespawnTime() > savage.getGameTime(): self.spawn.setCaption(str(int(math.ceil((player.getRespawnTime() - savage.getGameTime())/1000.0)))); self.spawn.setClickAction(""); else: self.spawn.setCaption("PLAY"); self.spawn.setClickAction("CL_RequestSpawn(-1)");
def onMouseClick(self, e): #cm = commhud.contextmenu; x = e.x y = e.y if e.button == MOUSE_RIGHTBUTTON: #cm.coords = x,y; #remember where we clicked! #cm.close(); #if Input_IsKeyDown(KEY_CTRL): if CL_CommanderMode() in (CMDR_PLACING_OBJECT, CMDR_PLACING_LINK, CMDR_PICKING_LOCATION, CMDR_PICKING_UNIT): CL_CommanderExitMode(); else: commhud.defaultAction(x,y); #else: # obj = savage.getObjectUnder(x,y); # ctx = self.determineContext(obj); # ctx.object = obj; # cm.buildContext( ctx ); # if x < cm.RADIUS: # x = cm.RADIUS; # elif x > screenWidth - cm.RADIUS: # x = screenWidth - cm.RADIUS; # if y < cm.RADIUS: # y = cm.RADIUS; # elif y > screenHeight - cm.RADIUS: # y = screenHeight - cm.RADIUS; # # cm.setPosition( x-cm.RADIUS , y-cm.RADIUS ); # actions = cm.context.getContextActions(); # if len(actions) > 0: # cm.setAlpha(0); # cm.open(); elif e.button == MOUSE_LEFTBUTTON: #cm.close(); if commhud.selectionRect.getWidth() > 0: #sel = savage.getObjectsWithin(commhud.selectionRect.getX(), commhud.selectionRect.getY(), commhud.selectionRect.getWidth(), commhud.selectionRect.getHeight()); #for o in sel: # commhud.selectObject(o, True); commhud.selectionRect.setSize(0, 0); elif savage.getGameTime() - self.lastClickTime < 500: try: obj = savage.getObjectsWithin(x-1,y-1,3,3)[0]; if obj == None: CL_CommanderLeftClick(); self.selection.selectObjectAndRadius(obj, 500); commhud.selection.updateSelection(self.selection); except IndexError: pass; else: try: if CL_CommanderMode() in (CMDR_PLACING_OBJECT, CMDR_PLACING_LINK, CMDR_PICKING_LOCATION, CMDR_PICKING_UNIT): CL_CommanderLeftClick(); else: obj = savage.getObjectsWithin(x-1,y-1,3,3)[0] self.selection.selectObject(obj, False); commhud.selection.updateSelection(self.selection); except IndexError: pass self.lastClickTime = savage.getGameTime(); else: #cm.close(); pass;