handleInput in CvMainInterface.py

12monkeys said:
you may reduce the load by splitting it :
option 1 : doing a scan on each button each 2nd or 3rd update
option 2 : doing a scan on half of the button one update and the second half next update.

Of course, this makes only sense, if the logic to split the load is not to complex.
I've just run a few tests.

It would appear update triggers about 7 times every second (~ every 0.14 seconds), rather than 4 times as mentioned earlier, though it's not quite fixed - mousing over the end turn button pops it up to 0.3 seconds for example. I think it's based on how quick you computer is, and when playing it's probably even faster (I have loads of background apps open at the moment).

The method I'm using takes about 0.015 seconds when it runs fully through, but almost always it's cut a bit early - it only runs fully through if the mouse moves onto the button.

Not really worth the effort then, IMO.
 
The Great Apple said:
I've just run a few tests.

It would appear update triggers about 7 times every second (~ every 0.14 seconds), rather than 4 times as mentioned earlier, though it's not quite fixed - mousing over the end turn button pops it up to 0.3 seconds for example. I think it's based on how quick you computer is, and when playing it's probably even faster (I have loads of background apps open at the moment).

The method I'm using takes about 0.015 seconds when it runs fully through, but almost always it's cut a bit early - it only runs fully through if the mouse moves onto the button.

Not really worth the effort then, IMO.

You're right. No need to do somthing here.

BTW: if you're still looking for the dropshadow, I found a way to get it. Just display the text in black color with one pixel shift on x and y-axis before you set the text.
The result looks the same as the one in game, which makes me think they doing it exactly this way in the game core.
 
Code damnit, I need code :D
 
Here is some code:

PHP:
# text to display
szText = "Hello!\nThis code example is dedicated to TheLopez\nHave Fun!"

# create shadow text
szTextBlack = localText.changeTextColor(szText, gc.getInfoTypeForString("COLOR_BLACK"))

# display shadow text at position x+1, y+1
screen.addMultilineText( "TEXT_SHADOW", szTextBlack, X+1, Y+1, 100, 100, \
		WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)

# display text at position x, y
screen.addMultilineText( "TEXT", szText, X, Y, 100, 100, \
		WidgetTypes.WIDGET_GENERAL, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)


In case you have some color information within the text to display, you have to remove it in the shadow text before you make it black. You can use that function here :
PHP:
def removeColor(szText):
	# replace color start sequence
	while szText.find("<color=") != -1:
		iStartPos = szText.find("<color=")
		iEndPos = szText.find(">", iStartPos)
		szText = szText[:iStartPos]+szText[iEndPos+1:]			
	# replace color end sequence
	szText = szText.replace("</color>", "")		
	return szText
 
@TGA : you said you're using the CyInterface().getMousePos() function for reading the x,y coords of the mouse cursor. How do you managed to split the resulting tuple into x and y positions. When I do this, I always get the python error "object not indexable" or something like that. Example :

PHP:
tMousePos = CyInterface().getMousePos()
x = tMousePos[0]
y = tMousePos[1]

The second line produces the error. Can you or anybody else give me a hint, please?
 
TheLopez said:
12monkeys, I was looking for TGA code, I know how to set color for text already, I do it in the merc mod.


Here from http://sthurlow.com/cvDocs/cvDoc/CyInterface.htm:

getMousePos(...) - POINT getMousePos() - returns the mouse coords

from the POINT def:
http://sthurlow.com/cvDocs/cvDoc/POINT.htm

Here's how to unpack it.

Code:
(x,y) = CyInterface().getMousePos().x,CyInterface().getMousePos().y

I don't speak about the text color, I speak about a drop shadow of displayed text. The text color is only a method to get the drop shadow.

I know sturlows and I know that definition. But, to be honest, I don't understand that stuff, because I don't know the syntax. What I was in need of, was syntax example. Thank you for that!
 
TheLopez said:
12monkeys, I was looking for TGA code, I know how to set color for text already, I do it in the merc mod.
Okies - just finished ironing out a glitch where the text would be the wrong size.

It's rather long, and I shamelessly stole some stuff from 12monkeys domestic advisor, as well as this thread.

Also, as I warned before, alot of it won't be relavent - all the calculations for finding where the button would be would be alot easier with standard selection button positioning, and quite a bit of it would be completely different... so I'm not sure how useful posting this will be to you.
Spoiler code :
Code:
def update(self, fDelta):
	screen = CyGInterfaceScreen( "MainInterface", CvScreenEnums.MAIN_INTERFACE )

	pHeadSelectedUnit = CyInterface().getHeadSelectedUnit()
	bComplete = False

	global g_ActionInfoIsUp
			
	# This code is for mouseover info on the custom buttons
	if (pHeadSelectedUnit and not CyEngine().isGlobeviewUp() and CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_HIDE_ALL and CyInterface().getShowInterface() != InterfaceVisibility.INTERFACE_MINIMAP_ONLY):
		global g_ActionListOverflow
	
		# Find out our resolution
		xResolution = screen.getXResolution()
		yResolution = screen.getYResolution()
		
		mouseX = CyInterface().getMousePos().x
		mouseY = CyInterface().getMousePos().y
	
		# This is the area the big box the selection boxes can be in is
		if ((yResolution - 160 - (57 * g_ActionListOverflow)) < mouseY < yResolution) and (296 < mouseX < (xResolution - 296)):
			# Don't check the default buttons
			numDefaults = len(CyInterface().getActionsToShow())

			defaultPositions = []
			bContinue = True
			
			if numDefaults > 18:
				return
			while bContinue:
				for Y in range(2):
					for X in range (9):
						if len(defaultPositions) < numDefaults:
							defaultPositions.append((X, Y))
						else:
							bContinue = False
							
			# Getting the button spacing/sizing
			### THIS SIZING IS SPECIFIC TO MY INTERFACE ###
			realWidth = xResolution - 592 - ((xResolution - 592)/11.5)
			buttonSpacing = int(realWidth/8.7)
			buttonSize = int(realWidth/9) - 4			

			notDefaults = []
			addedButtons = ActionButtons.getButtons(pHeadSelectedUnit)
			numAddedButtons = len(addedButtons)
			iCount = 0
							
			for iY in range(3):
				for iX in range (9):
					if (iCount < numAddedButtons) and ((iX, iY) not in defaultPositions):
					
						buttonXmin = (296 + (xResolution - 592)/33 + (iX * buttonSpacing))
				
						if  (buttonXmin) <= mouseX <= (buttonXmin + buttonSize):
							buttonYmin = yResolution - 107 + (57 * (iY - g_ActionListOverflow - 1)) + (48 - buttonSize)/2 # Dunno why there it is g_ActionListOverflow - 1. Too tired to work it out. It works though
							
							if (buttonYmin) <= mouseY <= (buttonYmin + buttonSize):						
								
								if g_ActionInfoIsUp == iCount:
									return
									
								bComplete = True
								
								szHelpText = "<font=2>" 
								szHelpText += "<color=100,225,255>"
								szHelpText += u"%s" %addedButtons[iCount].getType()
								szHelpText += "</color>"
								szHelpText += u"\n"
								szHelpText += u"%s" %addedButtons[iCount].getText()
								szHelpText += "</font>"
										
								# calculate panel heigth by examining the to be dispalyed text
								# seperate the text into the chapters : everything between the line feeds
								lChapters = szHelpText.split("\n")
	
								nLines = 0
								
								for iLoop in range(len(lChapters)):							
									# one line for each "\n"
									nLines += 1
									# another line for each n characters per chapter
									nLines += int(CyInterface().determineWidth( lChapters[iLoop] )/259)
																			
								# transform the lines into pixels
								yOffset = int(nLines*18)

								szTextBlack = szHelpText
								
								while szTextBlack.find("<color=") != -1:
									iStartPos = szTextBlack.find("<color=")
									iEndPos = szTextBlack.find(">", iStartPos)
									szTextBlack = szTextBlack[:iStartPos]+szTextBlack[iEndPos+1:]            
								# replace color end sequence
								szTextBlack = szTextBlack.replace("</color>", "")   						
														
								szTextBlack = localText.changeTextColor(szTextBlack, gc.getInfoTypeForString("COLOR_BLACK")) 									
								
								screen.addPanel( "MouseoverTextPanel", u"", u"", True, False, \
												7, yResolution - 182 - yOffset, 269, yOffset + 10, \
												PanelStyles.PANEL_STYLE_HUD_HELP )
														
								screen.addMultilineText( "MouseoverTextShadow", szTextBlack, \
														7 + 1 + 1, yResolution - 178 + 1 - yOffset, \
														269 - 10, yOffset + 4, \
														WidgetTypes.WIDGET_HELP_SELECTED, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)
								
								screen.addMultilineText( "MouseoverText", szHelpText, \
														7 + 1, yResolution - 178 - yOffset, \
														269 - 10, yOffset +4, \
														WidgetTypes.WIDGET_HELP_SELECTED, -1, -1, CvUtil.FONT_LEFT_JUSTIFY)	
														
						
																							
								screen.show( "MouseoverTextPanel" )
								screen.show( "MouseoverTextShadow" )
								screen.show( "MouseoverText" )
																	
								g_ActionInfoIsUp = iCount								
								
								#CyInterface().addImmediateMessage("Mouse is over custom button", "")									
						iCount += 1
								
	if not (bComplete):
		screen.hide("MouseoverTextPanel")
		screen.hide( "MouseoverTextShadow" )
		screen.hide("MouseoverText")
		g_ActionInfoIsUp = -1
		#CyInterface().addImmediateMessage("Mouse is NOT over custom button", "")						

						
	return
Basically, it first checks to see if there is a selection box, then if the mouse is over it, and then if the mouse is over a custom button. Finally, it adds the message if the message for that button isn't already up.

Probably should have had a few sub-functions. I think it would be better to define the panel in def interfaceScreen along with all the others as well, and only resize it in this code.

EDIT: g_ActionListOverflow just in case you are wondering is a variable calculated when the selection buttons are updated to dynamically change the positioning/size of the bottom bar.

EDIT 2: I forgot to mention that you'll also have to fiddle with the action buttons class so as to include a description.

EDIT 3: The third and final... I hope. There is also a small bug which means that sometimes default info is displayed from the terrain beneath as well as the button for a small amount of time. Looks a bit daft, but only occurs for an instant. Perhaps could be fixed by fiddling with the panel's widget.

EDIT 4: This has to be a record. I've just realised the way I've done the default button removal may be far from optimal. Too late to fix and test now - need sleep.
 

Attachments

  • Image1.jpg
    Image1.jpg
    61.6 KB · Views: 80
Wow, great work TGA.
 
Good work! Now action button can have on screen mouse over help or mosuse over handler..
And for (X,y) syntax is ....
TGA said:
tMousePos = CyInterface().getMousePos()
x = tMousePos[0]
y = tMousePos[1]

(x, y) = (tMousePos.x, tMousePos.y)
 
TGA : great job. :goodjob:

Thx for the mouse pos syntax, I really could use it.

I also like the CyInterface().determineWidth() function. It's a real improvement in this case. :goodjob:
 
Back
Top Bottom