Ejemplo n.º 1
0
	def handleInput (self, inputClass):
		screen = self.getScreen()
		if not screen.isActive():
			return
		HandleInputUtil.debugInput(inputClass)
		bAlt, bCtrl, bShift = self.InputData.getModifierKeys()
		iCode	= inputClass.eNotifyCode
		iData	= inputClass.iData
		ID		= inputClass.iItemID
		NAME	= inputClass.szFunctionName
		iBtn	= inputClass.iButtonType
		iData1	= inputClass.iData1
		iData2	= inputClass.iData2
		szFlag	= HandleInputUtil.MOUSE_FLAGS.get(inputClass.uiFlags, "UNKNOWN")

		szSplit = NAME.split("|")
		BASE = szSplit[0]
		if szSplit[1:]:
			TYPE = szSplit[1]
		else:
			TYPE = ""
		if szSplit[2:]:
			CASE = szSplit[2:]
		else:
			CASE = [0]
		# Remove potential Help Text
		self.bTooltip = False
		screen.hide("Tooltip")

		if iCode == NotifyCode.NOTIFY_CURSOR_MOVE_ON:

			if BASE == "WID":
				if TYPE == "RELATION":
					aMap = [
						"<color=255,0,0>",
						"<color=0,255,255>",
						"",
						"<color=0,255,0>",
						"<color=255,255,0>"
					]
					iPlayerY, iPlayerX = self.aRelationList[ID]
					iSum, szTxt = self.sumAttitude(iPlayerY, iPlayerX)
					szTxt += "\n---> " + aMap[GC.getPlayer(iPlayerY).AI_getAttitude(iPlayerX)] + str(iSum)
					self.updateTooltip(screen, szTxt)

				elif TYPE == "LEADER":
					CyPlayer = GC.getPlayer(ID)
					szLeader = GC.getLeaderHeadInfo(CyPlayer.getLeaderType()).getDescription()

					if CyPlayer.isHuman():
						szTxt = CyPlayer.getName()
						if szTxt == szLeader:
							szTxt = TRNSLTR.getText("TXT_KEY_PITBOSS_HUMAN", ())
					else:
						szTxt = TRNSLTR.getText("TXT_KEY_MAIN_MENU_AI", ())

					szTxt += "\n%s %s\n" %(CyPlayer.getCivilizationAdjective(0), szLeader)
					szTxt += "%s - %s" %(CyPlayer.getCivilizationShortDescription(0), CyPlayer.getCivilizationDescription(0))
					self.updateTooltip(screen, szTxt)

				elif TYPE == "BONUS":
					if CASE[0] == "DEAL":
						iBonus, CyDeal = self.aDealMap[ID]
						szTxt = GTM.getDealString(CyDeal, self.iPlayer) + "\n"
						if CyDeal.isCancelable(self.iPlayer, False):
							szTxt += TRNSLTR.getText("TXT_KEY_MISC_CLICK_TO_CANCEL", ()) + "\n"
						szTxt += "\n"
					else:
						szTxt = ""
						iBonus = ID
					szTxt += GTM.getBonusHelp(iBonus, False)
					self.updateTooltip(screen, szTxt)
				elif TYPE == "CIVIC":
					self.updateTooltip(screen, GTM.parseCivicInfo(ID, False, True, False))
				elif TYPE == "RELIGION":
					self.updateTooltip(screen, GTM.parseReligionInfo(ID, False))
				elif TYPE == "TECH":
					self.updateTooltip(screen, GTM.getTechHelp(ID, False, True, False, True, -1))

			elif BASE == "GPT":
				szTxt = ""
				if TYPE == "WILL":
					szTxt = TRNSLTR.getText("TXT_KEY_FOREIGN_ADVISOR_GOLD_PER_TURN_FOR_TRADE", (ID,))
				elif TYPE == "POS":
					szTxt = "<color=27,255,71>" + TRNSLTR.getText("TXT_KEY_FINANCIAL_ADVISOR_NET_INCOME", (ID,)) + " " + self.charGold
				elif TYPE == "NEG":
					szTxt = "<color=255,27,27>" + TRNSLTR.getText("TXT_KEY_FINANCIAL_ADVISOR_NET_INCOME", (-ID,)) + " " + self.charGold
				if szTxt:
					self.updateTooltip(screen, szTxt)
			elif BASE == "GOLD":
				if TYPE == "ALL":
					CyPlayerX = GC.getPlayer(ID)
					iGold = CyPlayerX.getGold()
					iGrGold = CyPlayerX.getGreaterGold()
					szTxt = ""
					if iGrGold:
						szTxt += str(iGrGold)
					szTxt += str(iGold) + self.charGold
					self.updateTooltip(screen, szTxt)
				elif TYPE == "WILL":
					iGold = GC.getPlayer(ID).AI_maxGoldTrade(self.iPlayer)
					iGrGold = iGold / 1000000
					szTxt = ""
					if iGrGold:
						iGold - iGrGold*1000000
						szTxt += str(iGrGold)
					szTxt += str(iGold) + self.charGold
					self.updateTooltip(screen, szTxt)

		elif iCode == NotifyCode.NOTIFY_CLICKED:

			if BASE == "FA_Tab":
				if CASE[0] != "Col":
					screen.hide("FA_Tab|Col" + str(self.iTab))
					screen.show("FA_Tab" + str(self.iTab))
					self.iTab = ID
					self.drawContents(screen)

			elif NAME == "BonusList":
				self.iBonusList = ID
				self.drawContents(screen)

			elif BASE == "KD":
				screen.deleteWidget("KD|Pnl")
				screen.deleteWidget("KD|Nay0")
				screen.deleteWidget("KD|Nay1")
				screen.deleteWidget("KD|Yay1")
				if TYPE == "Yay":
					CyMessageControl().sendModNetMessage(666, self.iPlayer, iData1, 0, 0)
					GAME.getDeal(iData1).kill()
					self.drawContents(screen)

			elif szFlag == "MOUSE_RBUTTONUP":

				if iBtn == WidgetTypes.WIDGET_LEADERHEAD and self.iTab == 0:
					if bShift:
						UP.pediaJumpToLeader([GC.getPlayer(iData1).getLeaderType()])
					elif iData1 != self.iPlayer:
						screen.hideScreen()

				elif iBtn == WidgetTypes.WIDGET_LEADERHEAD:
					if iData1 != self.iPlayer:
						screen.hideScreen()

				elif BASE == "WID":
					if TYPE == "LEADER":
						UP.pediaJumpToLeader([GC.getPlayer(ID).getLeaderType()])
					elif TYPE == "BONUS":
						if CASE[0] == "DEAL":
							iBonus = self.aDealMap[ID][0]
						else:
							iBonus = ID
						UP.pediaJumpToBonus([iBonus])
					elif TYPE == "CIVIC":
						UP.pediaJumpToCivic([ID])
					elif TYPE == "RELIGION":
						UP.pediaJumpToReligion([ID])
					elif TYPE == "TECH":
						UP.pediaJumpToTech([ID])
			else:
				if iBtn == WidgetTypes.WIDGET_LEADERHEAD and self.iTab == 0:
					aList = self.selectedLeaders
					if bShift:
						if iData1 in aList:
							aList.remove(iData1)
						else:
							aList.append(iData1)
					else:
						if aList and len(aList) == 1 and iData1 == aList[0]:
							aList = []
						else:
							aList = [iData1]
					self.selectedLeaders = aList
					self.drawContents(screen)

				elif BASE == "WID":
					if TYPE == "LEADER":
						if ID != self.iPlayer:
							self.CyPlayer.contact(ID)
							screen.hideScreen()
					elif TYPE == "BONUS":
						if CASE[0] == "DEAL":
							iBonus, CyDeal = self.aDealMap[ID]
							if CyDeal.isCancelable(self.iPlayer, False):
								eWidGen = WidgetTypes.WIDGET_GENERAL
								ePnlMain = PanelStyles.PANEL_STYLE_MAIN
								eBtnStd = ButtonStyles.BUTTON_STYLE_STANDARD
								xRes = self.xRes
								yRes = self.yRes
								xMid = xRes/2
								yMid = yRes/2
								screen.setImageButton("KD|Nay0", "", 0, 0, xRes, yRes, eWidGen, 1, 1)
								screen.addPanel("KD|Pnl", "", "", True, True, xMid-180, yMid-60, 360, 120, ePnlMain)
								szTxt = "<font=3b>" + TRNSLTR.getText("TXT_KEY_ANNUL", ())
								screen.setLabelAt("", "KD|Pnl", szTxt, 1<<2, 180, 20, 0, FontTypes.GAME_FONT, eWidGen, 1, 1)
								szTxt = TRNSLTR.getText("TXT_KEY_POPUP_NO", ())
								screen.setButtonGFC("KD|Nay1", szTxt, "", xMid - 160, yMid, 150, 40, eWidGen, 1, 1, eBtnStd)
								szTxt = TRNSLTR.getText("TXT_KEY_POPUP_YES", ())
								screen.setButtonGFC("KD|Yay1", szTxt, "", xMid + 10, yMid, 150, 40, eWidGen, CyDeal.getID(), 1, eBtnStd)

		elif iCode == NotifyCode.NOTIFY_LISTBOX_ITEM_SELECTED:
			if NAME == "FA_DebugDD":
				iIndex = screen.getSelectedPullDownID(NAME)
				self.iPlayer = iPlayer = screen.getPullDownData(NAME, iIndex)
				self.CyPlayer = CyPlayer = GC.getPlayer(iPlayer)
				self.iTeam = iTeam = CyPlayer.getTeam()
				self.CyTeam = GC.getTeam(iTeam)
				self.calcPlayerRelative()
				self.drawContents(screen)
Ejemplo n.º 2
0
	def handleInput(self, inputClass):
		if not self.created:
			print "CvTechChooser.handleInput - aborted due to screen not being created"
			return 0

		print "CvTechChooser.handleInput"

		screen = self.screen()
		bAlt, bCtrl, bShift = self.InputData.getModifierKeys()
		iCode	= inputClass.eNotifyCode
		iData	= inputClass.iData
		iData2	= inputClass.iData2
		ID		= inputClass.iItemID
		NAME	= inputClass.szFunctionName
		szFlag	= HandleInputUtil.MOUSE_FLAGS.get(inputClass.uiFlags, "UNKNOWN")

		szSplit = NAME.split("|")
		BASE = szSplit[0]
		if szSplit[1:]:
			TYPE = szSplit[1]
		else:
			TYPE = ""
		if szSplit[2:]:
			CASE = szSplit[2:]
		else:
			CASE = [""]

		iType = ID

		if iCode == NotifyCode.NOTIFY_CHARACTER: # Character
			if iData in (45, 49, 56): # Ctrl, Shift, Alt
				if self.bUnitTT:
					self.tooltip.handle(screen, CyGameTextMgr().getUnitHelp(self.iUnitTT, False, True, True, None))
					self.bUnitTT = None
			return 1
		elif iCode == 17: # Key Up
			if iData == InputTypes.KB_A:
				self.scrollTo(self.scrollOffs - self.xCellDist)
			elif iData == InputTypes.KB_D:
				self.scrollTo(self.scrollOffs + self.xCellDist)
			if iData == InputTypes.KB_Q:
				self.demoMode = not self.demoMode
				self.demoOffs = 0
			elif iData in (InputTypes.KB_ESCAPE, InputTypes.KB_F6):
				# Stop F6 and ESC handlers from triggering on load
				if self.skipNextExitKey:
					self.skipNextExitKey = False
				else:
					screen.hideScreen()
				return 1
			if self.bUnitTT is None:
				self.bUnitTT = True
			return 1

		# Remove potential Help Text
		self.tooltip.reset(screen)
		self.iUnitTT = None
		self.bUnitTT = False

		if iCode == NotifyCode.NOTIFY_CURSOR_MOVE_ON: # Mouse Enter
			if BASE == "WID":
				if TYPE == "TECH":
					if CASE[0] == "CURRENT":
						szTxt = "Researching: " + CyGameTextMgr().getTechHelp(self.CyPlayer.getCurrentResearch(), False, True, True, True, -1)
					elif CASE[0] == "REQ":
						szTxt = TRNSLTR.getText("TXT_KEY_MISC_TECH_REQUIRES_KNOWLEDGE_OF", (GC.getTechInfo(ID).getTextKey(),))
					else:
						szTxt = CyGameTextMgr().getTechHelp(ID, False, True, True, True, -1)
					self.tooltip.handle(screen, szTxt)
				elif TYPE == "UNIT":
					self.tooltip.handle(screen, CyGameTextMgr().getUnitHelp(ID, False, True, True, None))
					self.iUnitTT = ID
					self.bUnitTT = True
				elif TYPE == "BUILDING":
					if CASE[0] == "OBS":
						CvBuildingInfo = GC.getBuildingInfo(ID)
						szTxt = TRNSLTR.getText("TXT_KEY_TECHHELP_OBSOLETES", (CvBuildingInfo.getType(), CvBuildingInfo.getTextKey()))
					else: szTxt = CyGameTextMgr().getBuildingHelp(ID, False, None, False, False, True)
					self.tooltip.handle(screen, szTxt)
		elif iCode == NotifyCode.NOTIFY_CLICKED: # click
			if BASE == "WID":
				if szFlag == "MOUSE_RBUTTONUP":
					if TYPE == "UNIT":
						UP.pediaJumpToUnit([ID])
					elif TYPE == "BUILDING":
						UP.pediaJumpToBuilding([ID])
					elif TYPE == "PROJECT":
						UP.pediaJumpToProject([ID])
					elif TYPE == "PROMO":
						UP.pediaJumpToPromotion([ID])
					elif TYPE == "TECH":
						if CASE[0] == "CURRENT":
							UP.pediaJumpToTech([self.CyPlayer.getCurrentResearch()])
						else: UP.pediaJumpToTech([iType])
				elif szFlag == "MOUSE_LBUTTONUP":
					if TYPE == "TECH":
						if self.CyPlayer.getAdvancedStartPoints() > -1:
							if CASE[0] == "CHOICE":
								self.updateSelectedTech(screen, ID)
						elif GC.getGame().getActivePlayer() == self.iPlayer:
							if CASE[0] == "CURRENT":
								CyMessageControl().sendResearch(-1, bShift)
								self.updateTechRecords(False)
							elif CASE[0] == "CHOICE" and (self.currentTechState[iType] == CIV_TECH_AVAILABLE or not bShift and (self.currentTechState[iType] == CIV_IS_RESEARCHING or self.currentTechState[iType] == CIV_IS_QUEUED)):
								CyMessageControl().sendResearch(iType, bShift)
								self.updateTechRecords(False)
					elif TYPE == "ERAIM" or TYPE == "ERATEXT":
						self.scrollTo(self.minEraXPos[ID] - self.minX)
			elif NAME == "AddTechButton":
				CyMessageControl().sendAdvancedStartAction(AdvancedStartActionTypes.ADVANCEDSTARTACTION_TECH, self.iPlayer, -1, -1, self.iSelectedTech, True)	#Action, Player, X, Y, Data, bAdd
				self.updateSelectedTech(screen, -1)
		elif NAME == HSLIDER_ID:
			if iCode == 20:
				self.scrollOffs = iData
			self.scroll()
		elif iCode == 11: # List Select
			if NAME == "TC_DebugDD":
				self.initForPlayer(screen.getPullDownData(NAME, screen.getSelectedPullDownID(NAME)))