Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option to change/remove the background hud color as well #6

Open
whitecanealpha opened this issue Jul 11, 2024 · 14 comments
Open

Option to change/remove the background hud color as well #6

whitecanealpha opened this issue Jul 11, 2024 · 14 comments

Comments

@whitecanealpha
Copy link

I love the idea behind HudColor. Two things came to mind: one was the background and SteveSpuller already asked about the other.

Could an option be added to change the color and alpha of the background, i.e., alter both the color and transparency?

@whitecanealpha
Copy link
Author

whitecanealpha commented Jul 11, 2024

I should have read the entire reply series to SteveSpuller's request #3 (comment) has my answer. Sorry for the bother; closing.

@whitecanealpha
Copy link
Author

I apologize, Peppie84. I thought the above would do the trick or set me on the path but unfortunately I can't puzzle out how to do to GameInfoDisplay what you gave Flitsche for VehicleSchemaDisplay. I had a good rummage through the dataS scripts and the data table but clearly I'm missing something or staring at it without realizing it.

Would you be so kind as to show me how to set the background color/alpha for the GameInfoDisplay please?

@Peppie84
Copy link
Owner

@whitecanealpha unfortunately i can't find a color variable to change the background of the GameInfoDisplay, sry.

@whitecanealpha
Copy link
Author

I tried going through the overlay construction in the .lua for InfoDisplay and GameInfoDisplay to do a :setColor() to but I must be looking at something wrong or looking for it in the wrong place.

@Peppie84
Copy link
Owner

if you look into: Farming Simulator 22\sdk\debugger\gameSource\dataS\scripts\gui\hud\GameInfoDisplay.lua there is a method called: createBackground i guess, if you override this method, you can use the :setColor() to change the color to your needs.

@whitecanealpha
Copy link
Author

I looked at that but the overlay:setColor() is not active (:setColor() and :setUVs() are remarked) so that would be being set elsewhere.

@Peppie84
Copy link
Owner

Override the method and enable both methods and change the color for the setColor and try it - sometimes it is just trial and error 😄

@whitecanealpha
Copy link
Author

Yep. I was just hoping to avoid using the bash-head-into-code approach :D

@whitecanealpha
Copy link
Author

No joy. Overriding the GameInfoDisplay.createBackground() function with :setUVs() and :setColor() set has no effect; it's getting (re)set somewhere else as I suspected.

@Peppie84
Copy link
Owner

@whitecanealpha what do you think?
image

@Peppie84
Copy link
Owner

Sometimes is it hard to get class/functions etc... If you scroll down a bit from the createBackground function, you can find the createComponents and on the fourth line, there is

self.backgroundOverlay = self:createBackgroundOverlay()

So, this function is not on the sdk scripts. But no worry, just overwrite this function and start the debugger, with a breakpoint at local debug ...

---Overwrite GameInfoDisplay createBackgroundOverlay method
---@param overwrittenFunc function
function HudColor:createBackgroundOverlay(overwrittenFunc)
    local debug = overwrittenFunc(self)
    return debug
end

GameInfoDisplay.createBackgroundOverlay = Utils.overwrittenFunction(GameInfoDisplay.createBackgroundOverlay, HudColor.createBackgroundOverlay)

Then you can check the return of the overwritten function and this is what you get:
image

So, if you do a Find in Files for some of the variables you will find the HudElement-Class and there is one overlay in it. With the :setColor() from above, you can now change the overlay.

I'll bring it with one of the next releases.

@whitecanealpha
Copy link
Author

@whitecanealpha what do you think?

What do I think? I'm drooling and doing a happydance.

I knew about HudElement by tracing back the class inheritance (HUDDisplayElement -> HUDElement) since overlay passed back in each .new() call, and found the HUDElement:setColor() function. However, when I tried to use it, I get "Error: dataS/scripts/gui/hud/HUDElement.lua(268) : attempt to index field 'overlay' (a nil value)"

What code are you issuing? I've got to be overlooking something obvious.

@Peppie84
Copy link
Owner

Nothing more than you do.

---Overwrite GameInfoDisplay createBackgroundOverlay
---@param overwrittenFunc function
function HudColor:createBackgroundOverlay(overwrittenFunc)
    local hudElement = overwrittenFunc(self)
    hudElement:setColor(1,0,0,.30)
    return hudElement
end

Results in:
image

@whitecanealpha
Copy link
Author

Thanks. I hooked differently but it should have executed the same...well, anyway, that's a mystery for another day when I have the time and stubbornness.

Thank you very, very much, Peppie84. You saved me some headache in the code and a ton of headaches in gameplay with the background and color-change: I smile every time I look at the UI and can actually easily read it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants