[SOLVED][UI] Item to clone

Several UI files have items (usually in lists) that get cloned by the game somehow.

For instance, “unitcapinfopopup.lua” has a “Tab spacer frame to clone” item and a “Title to clone” item.

How do I create a new UI screen that also does this? I don’t see any code that does the actual cloning.

The number of cloned items and content that are spawned should be determined by my custom game rule settings, as well as the number of players.

Thanks!

[edit]

I am looking at the files in the “ui\newui\developer”, but they seem to populate the lists manually instead of automatically. For instance, the “CreateListboxItem()” function in “gamebalancescreen_aimenu.lua”.

It’s possible to create “cloned” elements, with recursive names. I’ve created a method from scratch to do this kind of thing in my rainbow mod, but I don’t know if anybody else ever did it before.

I will explain how to do so in the ui tutorial I will make, but I don’t know if it will be soon enough for you :confused:

Are the number of cloned elements based on game rule stuff?

I bolded the relevant part in my first post.

the number of cloned elements could be written in an external file by the gamerule code, and a doFilePath can be used by the ui file to read this value (that’s currently what I do to create the badge elements in my rainbow mod, which are dependent of what exists in the badge folder)

You are sure that the game rule code gets executed before the UI code?

[edit]

Because I cannot count on there being a file to read from before the match starts.

It’s not a problem, the gamerule will be able to reload the specific UI screen at any time with UI_ReloadScreen, so just after the file has been written for example :wink:
(that’s already what I use for my mod, reloading the badge list and sliders positions on the go with this function)

Okay, that makes sense. Thanks!

One more question:

In files like “eventsscreen.lua”, there are items that are listed as being cloned. But where do they get cloned to? Which is the parent of the cloned element?

I mean, where should I put my new list items so they show up in the menu?

Thanks.

the parent of those is the listbox called listEvents, just above it.
But you won’t be able to populate this specific listbox with your own elements if that was your question.
The HWRm code (hardcode I mean) is using the listBoxItems listItem and listObjectiveItem as a base for each elements populating this listBox, adding to this base the needed hardcoded values (text associated with it, etc…)

Edit : you could use the function UI_AddToEventScreen if you wanted to write someting in this list (look in the KarosGraveyard wiki for help on this function, as it works in a very specific way)

I created a copy of “eventsscreen.lua” and named the copy “bountiesscreen.lua”. Can I use the new copy as a template?

Also, I have listed the new file in the “GameScreens” section of “uisettings.lua”. But I still get these errors:

"Error, LoadScreen failed to screen of type BountiesScreen when loading section BountiesScreen from file DATA:\UI\NewUI\BountiesScreen.lua"

"Warning, screen with name BountiesScreen does not exist"

What do I need to change?

you must not set a type for the UI screen you create. Those “type” things are used by HWRm for hardcoded screens to know what type of screen it is and what type of hardcoded info to send to it.

I managed to get the screen to appear when the button is pressed. So I’ve got that part taken care of. THANKS!!!

But I’m having a few problems with the screen itself. Here’s the code:

-- Displays detailed information about unit caps when the user mouses over the units menu
dofilepath("data:ui/newui/Styles/HWRM_Style/HWRMDefines.lua")

--UnitCapInfoPopupWidth = 225
UnitCapInfoPopupWidth = 235
MAXHEIGHT = 325

function StuffToClone(MyInteger, MyTextLeft, MyTextRight)
	return
	{
		type = "Frame",
		name = "frmName",
		autosize = 1,
		arrangetype = "horiz",
		;
		-- Title to clone
		{
			type = "TextLabel",
			name = "lblBountyLeft" .. MyInteger,

			autosize = 1,
			ignored = 1,
			Layout = {
				--pos_XY = { x = 0.0, y = 0.0, xr = "par", yr = "par" },
				size_WH = { w = 1, h = STD_LABEL_HEIGHT, wr = "px", hr = "scr" },				
			},
			Text = {
				textStyle = "IGHeading2",
				hAlign = "Left",
				text = MyTextLeft,
			},
			giveParentMouseInput = 1,
			dropShadow = 1,
			visible = 1,
		},
		{
			type = "TextLabel",
			name = "lblBountyRight" .. MyInteger,
			autosize = 1,
			ignored = 1,
			Layout = {
				min_WH = { w = 85, wr = "px" },
				pad_LT  = { l = 8, t = 1, lr = "px", tr = "px" },				
			},
			Text = {
				textStyle = "IGHeading2",
				hAlign = "Right",
				text = MyTextRight,
			},
			giveParentMouseInput = 1,
			dropShadow = 1,
			visible = 1,
		},
	}
end

BountiesScreen = {

	maxColor = {255,0,0,255}, -- color for max pop reached
	availColor = {0,255,0,255},	-- color for pop available

	--size = {32, 71, 100, 200},
	autosize = 1,
	RootElementSettings = {

		autosize = 1,
		--backgroundColor          = {255,128,0,255},

		Layout = {	
			pad_LT  = { l = 8, t = 0, lr = "px", tr = "px" },
		},	
		Anchor_Binds = {
			pivotX = "Taskbar_LeftButtonsTopRight",
			pivotY = "Taskbar_LeftButtonsTopRight",
		},
	},

	soundOnShow = "SFX_RecallMenuONOFF",
	soundOnHide = "SFX_RecallMenuONOFF",

	onShow = "UI_SetButtonPressed('NewTaskbar', 'btnBounties', 1); UI_HideScreen('BuildQueueMenu'); UI_HideScreen('EventsScreen'); UI_HideScreen('UnitCapInfoPopup')",
	onHide = "UI_SetButtonPressed('NewTaskbar', 'btnBounties', 0)",

	stylesheet = "HW2StyleSheet",

	-- Flags
	pixelUVCoords = 1, -- Enter pixel coords for texture coords
	arrangetype = "vert",
	clickThrough = 1,
	;
	-- Unit cap item to clone
	{
		type = "Frame",
		name = "frmItemToClone",
		autosize = 1,		
		giveParentMouseInput = 1,
		visible = 1,
		arrangetype = "vert",
		Layout = {
			size_WH = { w = 1, h = 1, wr = "1", hr = "px" },								
		},
		;
		StuffToClone(0, "PLAYER", "BOUNTY"),
		StuffToClone(1, "Player " .. 1, 0),
		StuffToClone(2, "Player " .. 2, 0),
		StuffToClone(3, "Player " .. 3, 0),
		StuffToClone(4, "Player " .. 4, 0),
		StuffToClone(5, "Player " .. 5, 0),
		StuffToClone(6, "Player " .. 6, 0),
		StuffToClone(7, "Player " .. 7, 0),
		StuffToClone(8, "Player " .. 8, 0),
	},
}

It is based off of “unitcapinfopopup.lua”.

The problems I’m having are:

  1. I don’t know how to set the dimensions of the widget elements.
  2. I don’t know how to change the color of some of the text.
  3. The screen is too narrow. I need more space for the Player names, but don’t know how to do that.

Here’s my latest screenshot. You can see the new panel on the left, and the old panel on the right.

BTW, thanks for the great help! I am putting your name in the mod credits. :slight_smile:

1 Like
  1. could you be more precise about what you call “widget elements” ?

  2. just add a “color = {255,0,0,255},” into

Text = {
textStyle = “IGHeading2”,
hAlign = “Left”,
text = MyTextLeft,
color = {255,0,0,255}, – R,G,B,Alpha, so this is red with full visibility (no transparency effect)
},

  1. EDITED, see following posts

Thanks, very kind of you ^^ :slight_smile:

1 Like
  1. By widget elements I mean frames, textlabels, and other GUI primitives.

  2. Can I set the color from within a game rule? I don’t see any functions in the wiki to do this. http://hw2wiki.net/wiki.hw2.info/ScopeGameType.html

  3. “UnitCapInfoPopupWidth” has no effect. It is not referenced anywhere within the script.

  1. those explanations are far and wide, and will come in details later, because there is A LOT of things to explain to understand UI settings, especially with the new (since HWRm) layout system, which is very powerful but also very complex (lots of things to understand). Furthermore, it seems that there were some changes since pre 2.0 patch, so I will have to make some new tests not to say too much bullsh*t ^^

  2. you could try to trick it by incorporating a color switch into the text you send with the function UI_SetTextLabelText
    example :
    “hello” will use default color
    IN THE NEXT TWO LINES, REPLACE [ by < and ] by > (I couldn’t write it correctly because of the forum formatting)
    "[c FF0000]hello[/c]" will use red color (it’s a hexadecimal code : FF=255 so here you have 255,0,0 which is red
    "[c “…myHexaColor…”]hello[/c]" will use the color you defined in the myHexaColor string value

  3. yeah, I saw that, sorry for the confusion. It seems the layout system has evolved since pre 2.0 and this file along it. I will need to investigate more, but from what I see the “player name” text is set to autosize, so its parent should automatically increase its width if the text become longer

EDIT : forum formatting problem with < and > character

EDIT : my gawd, I didn’t see the clock… it’s 5:30am here ! Sleepy time for me ^^

@BitVenom
I was lurking in the exe, and it seems there is A LOT of new UI_ functions in there !
Should I let my excitement go over 9000 or not ? (please let it be real, please let it be real :grinning:)

And at the same time, I’m a little bit afraid, because I also saw a message “MainUI_ScarEvent is SP ONLY”… (or perhaps SP means singleplayer+skirmish, at least I really hope so :’( )

  1. I look forward to your tutorial, though I think I got things looking good enough (except the icons).

  2. That worked!! Thanks!

  3. It’s because I deleted most of the code in that file, probably.

There’s a list of functions here:

Nothing about changing colors, though.

[edit]

Here’s the latest screenshot:

The colored backgrounds are just there to make sure everything is lined up correctly.

Nope, don’t worry, my answer was after comparing the pre 2.0 and 2.1 versions of the UnitCapInfoPopup file :wink:
Is the autoresize I talked about working by the way ? In your screenshot, it seems there is a maximum width over which it doesn’t go, it’s strange. What was the full text for the 4th one ? “PalyerNameIsSuperDupe…?” I have an idea of what could happen, but I know this first to confirm it

Thanks, this one seems a lot more complete than the KarosGraveyard one !

This is intentional. I turned autoresize off. So now the text is clipped if it goes too long.

[quote=“Dwarfinator, post:15, topic:1510813, full:true”](I couldn’t write it correctly because of the forum formatting)
[/quote]

You can escape forum formatting with the code tag

<c FF0000>hello</c> -- Red <c "..myHexaColor..">hello</c> -- Color defined by myHexaColor string