UI Tutorial discussion thread

This

Code:
<?xml version="1.0" encoding="utf-8" ?>
<Context>
  <Label Anchor="C,C" String="Hello World!"/>
</Context>

lives in the UI/Dialog.xml context and not the XML/DialogText.xml GameData update file

:blush:

O clever me.

Thanks a lot for the quick reply. That still does not fix the problems which caused me to look at this tutorial, but let us see whether I manage to improve.
 
After checking (most of) the contents of the tutorial, I have to say :goodjob:
That must have been quite a lot of work.

Anyway, what I did not find (maybe I missed it?) is an answer to my problem. How can I mod existing UI files and make the changes visible? As I said before, changing TXT Labels is no problem, but something like the following does not have any effect if I run the mod: If I comment away some elements in CityView_small.xml (as attached, the change is right at the beginning of the document), then this has no effect. And yes, I am using the small interface. It almost seems as if I have to indicate somewhere that I overwrite some existing file but all I read said that this would be done automatically. :confused:
 

Attachments

You didn't miss it as the tutorial address UI components and uses examples that add new UI popups/dialogs.

To replace an existing file you need to set "Import into VFS" to true
 
You didn't miss it as the tutorial address UI components and uses examples that add new UI popups/dialogs.

To replace an existing file you need to set "Import into VFS" to true

That's it. Thanks a lot.

:worship:

Makes me wonder though, why this is not pointed out anywhere. After some search, I realized that it is due to a change setting it by default to false. Wise Choice! :rolleyes:
 
Most files in most mods should have "VFS=false", so it is indeed the wise choice. You happen to have hit one of the exceptions ... which is indeed pointed out in numerous posts - most of them by Spatz ;)
 
Most files in most mods should have "VFS=false", so it is indeed the wise choice. You happen to have hit one of the exceptions ... which is indeed pointed out in numerous posts - most of them by Spatz ;)

Right. I guess I did not explain that very well.

True indeed, that it is pointed out. I only found it after I knew what to look for.
Ultimately my fault, but it would have been much easier if this necessary option would be more visible similar to Actions and Contents that add new content from new .xml and .lua files.
 
Hello whoward69:

First thank you for your great UI tutorial! I learned a lot from it and now considering build some UI components my self.

I have a question regarding to the Toppanel UI. To be more specific, I plan to add a function, which gives a civ +10% research points bonus per turn if the civ is at peace; and -10% if it is at war.

To fulfill the goal I can simply add a function triggers every turn to change the team's science progress on current research, based on the players' war/peace status. I can handle this part.
However the tooltip of the top panel will not show show - or to say "predict" - the change correctly. As the first try, I copied the whole toppanel.lua to my mod and changed the "str" text in the Science part, adding a factor "+10% research because your empire is at peace" at the botton of the list -- actually it works fine. But the problem is that now my mod becomes incompatible with some mods which also altered the toppanel.lua.

So my question is that, if it is possible to "update" the mouse-over tooltip text in the Science part rather than completely override the file?

Sincerely
xxhe
 
In a way that will be compatible with any mods, no.

In a way that will be compatible with some mods and/or have the least impact on other mods (so making it easier to merge mods), possibly.

You may be able to overlay your own control over the science entry in the top panel to "steal" the mouse over for the tooltip - see UI - Gold Alerts for an example

The alternative is to move the tooltip code out into it's own function that only uses the default text if it doesn't get a response from a LuaEvent. You then write your own tooltip code, in it's own file, that responds to the LuaEvent and so overrides the default
 
Looking for tech tree modding info/tutorial. Understand it's special circumstance due to the "pipes". Has there been an extensive conversation about how to go about modding the tree correctly?

I'd like to add more (x)height rows in order to have more techs per column. Thought it might be possible by reducing the y value of everything by half, updating the appropriate art to fit the new sizes, doubling the amount of rows, and modifying the grid positions to match. I'm realizing problems with this as I type, namely that resizing elements used in other portions of the game, like icons, will affect other portions of the game. Hm. Maybe I could make a new icon template (just reduce the size by half) specifically called by the tech tree? This is my first foray into this stuff and it's already getting confusing. Back to late night tutorials.
 
If you have some programming experience, fixing the tech tree pipes isn't that hard - just frustrating. The hardest part is trying to figure out what Firaxis are actually doing in their code. Rather than devise an algorithm that works for any Y1 and Y2 values, they have a huge if then elseif ... else end block, and the problem for modders occurs when you run off the end of the block becuase your abs(Y2-Y1) is greater than the value they were expecting.

There are three approaches to the solution
1) Just add more elseif blocks
2) Re-write their if then else end block into a single function that works for any Y1 and Y2 values
3) Ditch their entire tech tree code and roll-your-own

1) is the easiest, but you now have to decide on the max Y delta you want to support. Any updates to the original code should be just a case of copying over your changes

2) is the most flexible and could be used by any other mod, but you will have to redo your work everytime Firaxis update that section of the code

3) is only really recommended if you are changing the tech buttons as well (eg making them narrower but longer). If you want to take this route, see my UI - Promotion Tree mod, specifically the PipeManager and ButtonManager lua files

Edit: I should probably add that I would not consider TechTree.lua a good file to start your UI modding with!
 
Thought it might be possible by reducing the y value of everything by half, updating the appropriate art to fit the new sizes.

There are various sizes of the icons in the game. IIRC the tech tree uses the 64 variant, so you can just use the 45 or 32 variants in smaller buttons
 
Thanks for the advice and the answers man. I really appreciate the abilities of guys like you. Do you think I could ask you to point out some up to date sources I could start learning modding from? I wouldn't say I have any real programming experience but I have knowledge of the basics, and have worked in c# a decent bit. I'm just looking for the ability to add the major elements to the game. Resources, techs, units, buildings. I'd also like to know if it's possible to create new yields now that the dll has opened up. Anyway, thanks again.
 
Do you think I could ask you to point out some up to date sources I could start learning modding from?
  • Kael's guide will still give you a very good overview of what is possible (even if how to do it is now out-of-date/wrong in some areas)
  • The Tutorials and References sub-forum here has thousands of man-hours of knowledge in - use it
  • The best source for Lua documentation is the game source files, especially those in the DLC scenarios - get yourself a good multiple file search utility, eg Notepad++, AgentRansack, etc
  • Active, up-to-date, existing mods (especially small focused ones) will show you how others have done things before - they may not always be "best practice" but they should at least work
  • The wiki's - both at CFC and 2K
  • The Lua Reference site
That should get you started!

I'm just looking for the ability to add the major elements to the game. Resources, techs, units, buildings.
Start small and in XML - change some values, duplicate an existing unit, make some changes and make it a UU, do the same for a building, create your own UU/UB from scratch (use existing artwork), learn about dds (icons sheets and images) and add the artwork to you UU/UB, create a civ.
Start small in Lua - tweak some existing UI files, hook some events
Resources are the biggest thing above, as you'll need to understand the horror that is AssignStartingPlots.lua (there is a very good tutorial on adding a new resource in the sub-forum)

I'd also like to know if it's possible to create new yields now that the dll has opened up.
Yes. But it will be a massive effort as everything is intertwined with everything else in the C++ code (C++ it may be, OO it is not) You will also need to modify large chunks of the UI to get a new yield to display.
 
Help me understand a scope issue. I don't understand where ContextPtr gets defined, and it's called as an instance with a ':'. Not that it matters, as long as it works, I'm just confused and I hate feeling confused.

Code:
function OnShowDialog(sDialog)
  if (g_DialogID == sDialog) then
    ContextPtr:SetHide(false)
  else
    ContextPtr:SetHide(true)
  end
end
LuaEvents.TestDialog_Show.Add(OnShowDialog)
 
Same place as Players, Game, Map, et al - as part of the Lua wrapper of the C++ game core
 
I can't seem to get it, and I really tried. Here is the project, maybe you can point out the dumb thing I'm missing. Let me tell you what I understand and don't first.

I create an XML file that is the layout of the dialog box I want to display. It contains, among other things, elements with IDs. These IDs automatically become part of a Controls object. For example, an ID of Message becomes Controls.Message...

A second lua file is created that sets up the initialize for the dialog, and handles the close button (in this case).

In my file I call either ContextPtr (a global created for me when I created the dialog) or Controls.[some id] to do what I want.

The problem: When I try to call Controls I get an error. I've attached the code.

Edited: Left out an incude that was demostrated in a much later tutorial. Now on to other problems - nothing to see here.

Edited Edited: Lost again. No runtime errors now, but no popup either. I've replaced the old attached source with the new.
 

Attachments

That was an issue, but not the issue.... The new error message (which is really an old error message returned) is "attempt to index field 'Message'" when I call
Code:
Controls.Message:SetText(Locale.ConvertTextKey("TXT_KEY_WONDER_RACE_LOSING_TIP", wonder))
I thought all the child elements got defined when you made a luacontext for the main element
HTML:
<LuaContext FileName="WonderRaceDialog" ID="WonderRaceDialog" Hidden="True" />
	<Grid Size="400,270" Anchor="C,C" Style="Grid9DetailFive140" ConsumeMouse="1">
etc...
Of course, I'm not sure what the main element is supposed to be here. Do I need to add an ID to the grid = to "WonderRaceDialog" or something?

I just want to show a popup from lua without anyone having to click on anything. And yes, I've read the entire thread and the other tutorial you linked for another poster. /me beats head on wall

Edit: Great tutorials even if I am struggling, btw - you put a lot of work into them. Impressive!
 
Not sure what you're trying to do with that <LuaContext ...> but it's a) wrong and b) not in your posted mod

What you had in the posted mod is "more right", just with a missing InGameUIAddin (and possibly a few other errors but I didn't get past the missing addin error)
 
Back
Top Bottom