Add "edit box" and get it's value stored somewhere

NotSoGood

Emperor
Joined
Jan 25, 2009
Messages
1,077
Location
Finland
I'm still making the hire unit screen for my mod, but even after few tries I haven't managed to add the "add unit experience" edit box. The screenshot shows what I mean. Even with Python API's help it's hard to find the right function. Also I would need to get the number you type there stored somewhere, so the edit box doesn't have to do anything but show you how much experience the unit'll get. Is this even possible? All help is appreciated.
 
All of World Builder is done in python. See file Python/Screens/CvWorldBuilderScreen.py. I was able to locate the python code which builds the dialog in your screenshot (search for UnitEditExperienceCB). So I guess if you copy the right parts of that existing code, you should be all set.
 
Code:
		self.m_tabCtrlEdit.addSectionLabel(localText.getText("TXT_KEY_WB_EXPERIENCE",()),  0)
		strExperience = str("UnitEditExperienceCB")
		self.m_tabCtrlEdit.addSectionSpinner(
			strExperience, 
			"CvScreensInterface", 
			"WorldBuilderHandleUnitEditExperienceCB", 
			"UnitEditExperience", 
			0,
			0.0,
			1000.0,
			1.0,
			self.m_pActivePlot.getUnit(self.m_iCurrentUnit).getExperience(),
			0,
			0)
To me this seems to do it. But where does that m_tabCtrlEdit refer? The only place I can see it defined is in the begining where it's defined as 0. Every function seems to be called with that. So the mystery is where it calls those addSectionLabel and addSectionSpinner.

EDIT: No, it seems it's been defined with this:
Code:
self.m_tabCtrlEdit = getWBToolEditTabCtrl()
Is that from SDK, because I can't find it anywhere in the python folder except there?
 
This is a part of the code I haven't worked with at all. I agree that the ...TabCtrl items don't seem to be defined anywhere in python. Also if you global search in the CvGameCoreDLL directory for all of the sdk files, it is not defined there either. So I missed it, or it is in the executable itself. However, this seems to be used to build *tabbed* dialog boxes. So if you don't want a tabbed dialog, maybe it doesn't matter. The advisor screens may also be a good place to look for ideas on how to make this all work.

EDIT: depending on how far along you are, these guides may be useful, or maybe you already know all that.

How To: Display a Blank Civ4 Screen
How To: Add New Screens to Civ4
 
My guess after looking at this a year or two ago is that those dialogs are defined in the EXE (yay!!) but are simply the same type of dialog BUG and BTS use for their options screen. They are special dialog controls with their own UI controls and APIs. AFAIK you cannot place those items on a normal window nor draw normal graphics/text on them. They are apples and oranges.

What you can do is create a spinner control yourself (text field and two +/- buttons) or use a dropdown control. You can find code for the latter in most every advisor: the player selection debug dropdown. This would only satisfy if the maximum XP you could buy was limited and low, say 10 or so, otherwise I'd use a spinner.

A third option is to have a button "buy XP" which when clicked creates a popup asking the user for the number. Check out BUG's ReminderEventManager for working code that does this and uses a spinner and a free text field with OK/Cancel buttons.

I think a dropdown would be my preference as a user. It's easy to use and requires the fewest number of clicks. The graphics UI in BTS isn't really designed to support traditional UI elements like the dialog UI is.
 
What you can do is create a spinner control yourself (text field and two +/- buttons)

I decided to go with that. It seems to be the easiest way to do it and I can do all I want (I get the value stored somewhere). But, how do I remove text from the screen? I update the unit cost when you change the amount of experience but I can't change the previous text so I reprint it, but the previous still stays there and makes it blurry.
 
Are you using the same widget name when you change the text? If not then the new text is created in a new widget and displayed on top of the old one.
 
Yeah. One of the first things I do when designing a new screen is to figure out which widgets need to be "refreshed" and then set up the code appropriately. In fact I eventually just created a class that takes care of the dirty work.
 
The difficulty will depend on what you need to scroll.

The GUI contains a generic scroll pane used by the Tech Chooser. It supports basic graphical objects, lines, etc I think.

There is another scroll panel used by the INFO and ACTIVE tabs of the Foreign Advisor. This allows a very limited set of "panel" objects that can contain a few types of graphics on them. This is quite limited.

Finally there's the Table object which is a multi-column list.

If you need anything at all complex, you'll have to do it yourself a la the TECHS and RESOURCES tabs of the Foreign Advisor. The author created an IconGrid control that does scrolling by redrawing when you click the up/down buttons. I added page up/down and top/bottom buttons for BUG's version, but it may give you some ideas on how to do it. This way involves the most work.
 
Back
Top Bottom