Interface: Religion icon added to tech button

phungus420

Deity
Joined
Mar 1, 2003
Messages
6,296
I've gotten a limited religions component working and fully functional for RevDCM. Had to completely abandon the way others have tried doing it, as things are completely different in the SDK then Python and I've never been satisfied with the functionality of other modcomps that implemented this feature; so it was quite a bit of work. Good experience though, lots of interweaving functions I had to track down using the debugger, but in a fairly straightforward not banging your head against the wall way.

Only problem left with this feature is that the religion icons on the tech list -top center of the screen in the main interface, that pops up when you need to pick a tech- still appear on religions that can't be founded. In the SDK I've only found the a reference in CvDLLButtonPopup that looked good, but adding logic there didn't fix it (though I'm fairly certain based on the code there that this will fix the same issue with icons on recommended techs, just haven't checked yet). I browsed through CvMainInterface, and did a cursory search looking for references of FoundReligion, but nothing immediately stood out. I'm hoping one of you interface gurus on the BUG team can point me toward the right location, as I really don't want to have to scour all the python files related to the interface with a fine tooth comb; but will if I must. So please let me know if you have an idea where this is handled.
 
This appears to be handled in updateResearchButtons(). The religion icons are separate buttons that appear on top of the tech buttons. There's a call to check if the religion's slot is taken, and if not it shows the button.

The strange part is that I cannot see where it moves the religion icon over the tech button. It calls setResearchButtonPosition() to move the tech button, but it has no analog for the religion button. :hmm: Oddly, i do see that this function has a bug in it, though. The second moveItem() call should probably be under the else.
 
OK, thanks for letting me know. What file is this function in, or is it all over the place and I should just "search in files", and if so is this python or SDK?
 
Edit: Got it working, typo messed things up. My question is though, why didn't the typo throw an exception, or at the very least return false? How did it allow the control statement to continue? Code below, my question relates to the fact I forgot the parentheses on the player function canFoundReligion(), yet the function continued into the loop, because it definitely added the religion buttons, and adding the parentheses fixed it.

Spoiler :
It does not seem to be working. Here is the code I've added:
Code:
#RevolutionDCM limited religions
			pPlayer = gc.getActivePlayer()
			for i in range( gc.getNumTechInfos() ):
				if (pPlayer.canResearch(i, False)):
					if (iCount < 20):
						szName = "ResearchButton" + str(i)

						[B]if(pPlayer.canFoundReligion and gc.getGame().isTechCanFoundReligion(i))[/B]:
							for j in range( gc.getNumReligionInfos() ):
								if (gc.getReligionInfo(j).getTechPrereq() == i):
									if( not gc.getGame().isReligionSlotTaken(j) ):
										szName = "ReligionButton" + str(j)
										break
#RevolutionDCM end

Obviously those are two functions I have added. Their SDK equivalents are working fine, and no exceptions are being thrown, so I can't see how they are being messed up (it's not like it's hard to expose a function to python). How can I print or log a value for python? If this were the SDK I'd put in a breakpoint and create a new variable and check the stack to make sure these functions are returning the correct values, but I'm not sure how to go about this in python. Also I'm pretty sure that that it's not a coding problem, as this is pretty simple, and if I'd screwed up exposing those two functions to python I'd expect a python exception to be thrown.
 
"pPlayer.canFoundReligion" evaluates to the canFoundReligion function which is itself an object in Python, an instance of the internal function class. Since the function class does not define a __bool__() function to convert itself into a boolean value which is checked for by the if <boolean> context, the default "None is False, everything else is True" algorithm is applied to the function. Since the function isn't None (it's an object reference which has a value), the result is True.

Placing parentheses with optional arguments inside after any variable/attribute in Python just calls that object's special __call__() function if it has one. Thus you can turn any object into a function (doesn't work with plain values like numbers or strings even though they are objects too):

Code:
class Callable:
    pass

def hello():
    print "Hello, world!"

foo = Callable()
foo.__call__ = hello
foo()
[I]> Hello, world![/I]
 
Top Bottom