talchas
Prince
- Joined
- Jan 3, 2006
- Messages
- 428
Edit:
This is now (sort of) obseleted by a new version that uses the SDK. Look in my sig for the link.
This set of utilities allows you to add buttons to the list of actions in the bottom center of the main interface. However, you cannot add any sort of tooltip to your button. AFAIK it is hardcoded with the relevant linkups in Units/CIV4MissionInfos.xml and the text in one of the Text/* xml files. It works like this:
All of this code would have to be in the same file, and should be at a place that is run at the beginning of the game. This would include any file imported by one of the EntryPonts/Cv*Interface classes.
Make your handlers - what python code you want to execute when a button is pushed:
Make your buttons:
Make a function that returns a list of buttons you want to appear for a given unit. Use setEnabled(false) to make the button appear greyed-out. If you do, you will have to call setEnabled(true) when you want it to be enabled again.
This would let you heal units up to 80%, and hurt units that have first strikes. The heal ability would always appear and just change being enabled/disabled, but the hurt one would only appear if that unit had first strikes.
Then tell this mod's code about it:
The mod using this would also have to have all the python files in its Assets/Python folder. If you need to edit CvScreensInterface, edit mine instead or change yours to import and use CvActionButtonsMainInterface instead of CvMainInterface. The only other thing is CvGameInterface, which you could do anything you want with as long as you copy into your CvGameUtils subclass my cannotHandleAction function and the "import ActionButtons" statement. If you need to edit CvMainInterface, mine has markers everywhere I changed the original (v. 1.52).
The zip file contains a Python folder with all the .py files.
This stuff is just the modularized version of what I was using in my Magic/Square Selection demo.
Edit:
1.01: Updated version that repaints the ui.
1.02: Only repaints the necessary parts of the ui. Also put in a possible workaround for the occasional MemoryError/Unidentified C++ Exception thing.
This is now (sort of) obseleted by a new version that uses the SDK. Look in my sig for the link.
This set of utilities allows you to add buttons to the list of actions in the bottom center of the main interface. However, you cannot add any sort of tooltip to your button. AFAIK it is hardcoded with the relevant linkups in Units/CIV4MissionInfos.xml and the text in one of the Text/* xml files. It works like this:
All of this code would have to be in the same file, and should be at a place that is run at the beginning of the game. This would include any file imported by one of the EntryPonts/Cv*Interface classes.
Make your handlers - what python code you want to execute when a button is pushed:
Code:
import ActionButtons
gc = CyGlobalContext()
...
def hurtUnit(unit):
unit.changeDamage(10,gc.getGame().getActivePlayer())
def healUnit(unit):
unit.changeDamage(-10,gc.getGame().getActivePlayer())
Make your buttons:
Code:
...
hurt = ActionButtons.ActionButton("Art/Interface/Buttons/Actions/SplitUnitGroup.dds",hurtUnit)
heal = ActionButtons.ActionButton("Art/Interface/Buttons/Actions/CreateUnitGroup.dds",healUnit)
Make a function that returns a list of buttons you want to appear for a given unit. Use setEnabled(false) to make the button appear greyed-out. If you do, you will have to call setEnabled(true) when you want it to be enabled again.
Code:
...
def buttons(unit):
heal.setEnabled(unit.getDamage()>20) # you can only heal up to 80%
if(unit.firstStrikes()>0):
return [heal,hurt]
return [heal]
Then tell this mod's code about it:
Code:
ActionButtons.setButtonsFunction(buttons)
The mod using this would also have to have all the python files in its Assets/Python folder. If you need to edit CvScreensInterface, edit mine instead or change yours to import and use CvActionButtonsMainInterface instead of CvMainInterface. The only other thing is CvGameInterface, which you could do anything you want with as long as you copy into your CvGameUtils subclass my cannotHandleAction function and the "import ActionButtons" statement. If you need to edit CvMainInterface, mine has markers everywhere I changed the original (v. 1.52).
The zip file contains a Python folder with all the .py files.
This stuff is just the modularized version of what I was using in my Magic/Square Selection demo.
Edit:
1.01: Updated version that repaints the ui.
1.02: Only repaints the necessary parts of the ui. Also put in a possible workaround for the occasional MemoryError/Unidentified C++ Exception thing.