[UI] in-game screeen slider with link to function

Please somebody help me with adding slider to game screen (running game) in SP campaign and maybe vs CPU to using existing function Universe_SlowDown() to lowering game speed for my purpose (HW2 campaign slowing down for better feeling). I use this function with hack mission files but it is one more time solution for whole mission.

BUT I am not a modder or programmer, more “shortcut-seeker/hacker”, so please slowly at me. I spend few hours in last days with “terrain mapping” and I suppose this can be done with editing the “newtaskbar.lua”, right or not?
Can anyone pls advise me in a few steps how to do it? Or direct me to a guide?

@Dwarfinator - I totally like slider for speed in your rainbow mod. Can you help?

Excuse pls my faulty English and Thanks.

@NoOne The first thing you have to do is to think where you want this slider to be, because it will define in which file you’ll need to incorporate it (not necessarily newtaskbar.lua)

The vertical slider is currently not an easy option, as it’s not currently existing in the game and is not really well supported by it, as previously explained to me by @BitVenom. I had to create a special function for it and I still have to clean my code a bit before being able to release it.

Would adding an horizontal slider at the top of the screen, above the Resource for example, be ok for you ?

edit :
you also need to think about the limits of the slider.
max = 1 (so standard speed)
min = 1/2 ? 1/10 ? etc…
step = 0.1 ? 0.5 ? etc…

Sorry, I forgot to write the position. Initially I had in mind place below EVENTS button, but I like more your suggestion now. So above from Resource would be great, eventually left or right, depends on slider size.

Yes, I read it in that topic. Acctualy horizontal slider is better for me.

Max: 1.0 … its normal speed
Steps: 0.1
Min: 0.0 … its stop/pause game

I like the text inside slider in your mod, but its not necessary :wink:

Thank You.

@NoOne @Mikali

I can confirm that the slow-down function works when called from the UI. I’m going to make a mini-mod for you two. Nothing too fancy, though.

1 Like

If I understand correctly what you’re talking about, the " text inside slider" is not working, it was just a question/request I made to the dev :wink:

That will be great at least to me. Unfortunately, the function is only to slow down the game, not for the acceleration. I had the not fancy idea, but its not working.

I mean https://youtu.be/10fEKw591F8?t=85

Thank You very much in advance.

I don’t know if it will ever be possible. I will explain myself :

  • the code is running at a defined speed (defined by your pc performance and the code optimization + hard-limit to prevent crazy execution speed in 10 years ^^)
  • slowing it is “easy”, just add a timer before executing the next line of code
  • to accelerate it, how can you do ? You can not only execute one line of code and not the next one, to speed-up the process.

That’s what I’ve done with the rainbow mod to speed-up the effect. Instead of increasing the color value by one, I increase it by two (for example), effectively increasing the visual speed of it, but at the cost of the smoothness in extreme case.
This kind of trick can’t be use here, so I don’t know if it’s possible to have a Universe_Accelerate() function…

Ah yes, this one works (I thougth you were talking about a text inside the button of the slider, which doesn’t ^^).
It’s a trick (my ui is full of this kind of trick, especially for the rainbow mod which was, litterally, a nightmare ^^), it’s not really into the slider. It’s a textlabel behind it and the slider background is transparent ^^

Thanks for the explanation. Unclean idea mentioned above was run HWRM with param -superTurbo and then slow it down with that function.
But unfortunately lowest working value (seems around 0.032-lower just stop/pause the game) is still faster than normal speed.
Maybe is possible write new function like you desribe:

but it is definitely out of my present skills.

In addition param turbo speeds probably also other things (e.g. screen move). Therefore by my current knowledge and like you wrote, I think that without intervention the devs is still impossible increase game speed, maybe even for them.
I try describe this in topic dedicated to and ask devs for help or their opinion. But it is not probably main area of interest, although the desire to increase the speed is here since HW2 classic.

However, possibility slow down the game with slider will be for me (and maybe someone else) really great and much appreciated.

Clever …

… and superclever :slight_smile:

Thank you for your time.

uh ? No, you misunderstood. I was only explaining the principle of it.

In our case, using Universe_SlowDown() is a totally working solution :slight_smile:

Yes, I had in mind only as a principle, maybe for devs. Sorry my writing skills in English are weak :cry:

I have one more quick question. For my another MOD/Hack is possible add slider to game option menu and its value read and write to file? Clone of existing slider for TACTICAL DOTSCALE would be absolutely perfect, maybe even with its limit and steps. I planed start new topic in a few days, but if you say that it is not possible so I will not do.


Don’t worry, your english is not as bad as you think :wink:

Definitely possible.
What do you want to do after that with the created file ?

And don’t bother making another thread, we can discuss this here :wink:

@NoOne @Mikali Done ^^


The steps to reproduce it :

  • extract resource.lua from Homeworld2.big (it’s in the \ui\newui folder)

  • in resource.lua, add the following code just before the last }

      -- Adjust universe speed
          type = "Frame",
          Layout = {
              pos_XY = { x = 0, y = 0, xr = "px", yr = "px" },    
              size_WH = { w = 1, h = 1, wr = "par", hr = "px" },                    
          backgroundColor = {20,20,20,20},
              type = "Frame",
              Layout = {                                    
                  size_WH = {w = 1, h = LISTBOXITEM_HEIGHT, wr = "par", hr = "scr_min",},
                  pad_LT = { l = 4, t = 4, lr = "px", tr = "px" },
                  pad_RB = { r = 4, b = 4, rr = "px", br = "px" },
              arrangetype = "horiz",
                  type = "TextLabel",
                  name = "lblUniverseSpeed",                    
                  style = "FESliderLabelStyle",
                  Layout = {                        
                      size_WH = {w = 30.0/800, h = 1.0, wr = "scr", hr = "par" },    
                  Text = {
                      text ="1.0",
                      font = "ButtonFont",
                      vAlign = "Middle",
                      hAlign = "Center",
                      color = {255,255,255,255},
                  helpTipTextLabel = "m_lblHelpText", 
                  helpTip = "Adjust universe speed",
                  type = "ScrollBar",
                  sliderTextLabel = "lblUniverseSpeed",
                  arrangeweight = 1,
                  Layout = {                        
                      size_WH = {    w = 1.0, h = 1.0, wr = "px", hr = "par" },    
                  displayLabelAsFloat = 1,
                  scrollBarStyle = "FESliderStyle",
                  range =  { 0.0, 1.0 },            
                  scrollPosition = 1.0,
                  stepSize = 0.1,
                  pageSize = 0.5,
                  TrackFrame = {
                      type = "Frame",
                      backgroundColor = {20,20,20,20},
                  helpTipTextLabel = "m_lblHelpText", 
                  helpTip = "Adjust universe speed",
                  onScroll =  [[Universe_SlowDown(%spos, 0);]],
                  labelSignificantDigits = 4,

Enjoy ! :slight_smile:


Quick test and it works perfectly. :stuck_out_tongue:

You are amazing, Thank you very much.

Tomorrow I will learn from your code. And i write more to the slider in options menu. Midnight here :wink:

Thank you again.

Midnight here too ^^
Have a good sleep

Still enjoying it, works great. Summer Christmas. :relaxed:
Maybe it deserves to be mod.

Thank you and good night!

To the other question respectively the slider in options menu.
I use (and describe in another topic) solution (with existing property in engine) for adjust difficulty in SP. Maybe devs consider add this to game properly. Meantime i was thinking to do a simple MOD for others player with possibility change the difficulty and also for testing with more players to confirm functionality in all missions.

My existing solution is using file “SP_Difficulty.lua” in player’s folder with:

-- Ratio and then difficulty for extra added ships and RU to CPU in Campaign Missions
-- Value 0.0 "Turn off" adding extra ship/RU. More testing or try is needed, because it can maybe control regular reinforcement during some missions.
-- Value above 0.0 to 1.0 is lowering difficulty. 1.0 is "normal" i.e default difficulty.
-- Value above 1.0 to whatever is increasing difficulty. Cap/roof is not testing, up to 3.0 seems is not problem.
-- Change "RF_ExtraRURatio" seems (to me) have small or none influence to difficulty (maybe have, but later in mission). Yet not deeply tested.

RF_ExtraShipRatio = 0.4
RF_ExtraRURatio = 0.6

and in file end “referencefleet.lua” (in each mission folder) is added this:

multiplierForExtraShips = RF_ExtraShipRatio
multiplierForExtraRU = RF_ExtraRURatio

Now i use manually editing my new file with value for difficulty.

I planned release to in this form for quick purposes and because editing that file is not frequently in normal case and later (next week when start my holidays-busy now) try find user friendly solution with slider in options.

BUT if you help me and direct me to, that would be great. All credit will be yours.

Simultaneously, if you or someone else knows a better/cleaner solution please tell me.
I try few other main lua files to add described multiplier to eliminate the need edit many “referencefleet” files, but yet not success.

Although in described above are two value (extra ships and extra RU) i think is enough have to one property for difficulty and thereby one slider, because (until now) seems that the extra RU multiplier have small influence to difficulty. Then the file “SP_Difficulty.lua” could look like:

RefFleetRatio = 0.4

Notes will be in mod description or can be in short way in slider helptip.
Limits may be 0.0 to 3.0 with step 0.1

Till this moment i have only unclear idea, but your code for slow down above clarify me a few things :wink:
But still much to do and learn to me.

Thanks for the advice and directions.

soooo, good news and bad news.

Good news is that it’s working.
Bad news is that it’s not working from the main menu Options, only ingame, because there is a bug in the declaration of one function, as I explain here

here is the modification, it goes in ot_gameplay.lua :

Add this just before FE_GAMEPLAYOPTION_TAB = { :
edit : updated max to 3.0 instead of 2.0, and text formatting to always have a decimal written in file even for integer (2.0 instead of 2 for example)

difficultycommand = [[
        write("-- Ratio and then difficulty for extra added ships and RU to CPU in Campaign Missions\n");
        write("-- Value 0.0 \"Turn off\" adding extra ship/RU. More testing or try is needed, because it can maybe control regular reinforcement during some missions.\n");
        write("-- Value above 0.0 to 1.0 is lowering difficulty. 1.0 is \"normal\" i.e default difficulty.\n");
        write("-- Value above 1.0 to whatever is increasing difficulty. Cap/roof is not testing, up to 3.0 seems is not problem.\n");
        write("RefFleetRatio = ]]..format("%.1f", %spos)..[[\n");
OPTION_GAMEPLAY_DIFFICULTY = Option_LabeledSlider("DIFFICULTY", "SINGLE PLAYER DIFFICULTY", "lblDifficulty", "SINGLE PLAYER DIFFICULTY", "m_sbarDifficulty", "ADJUST SINGLE PLAYER DIFFICULTY", 1, 1, 0.0, 3.0, difficultycommand)


And finaly, add this to the end of the file :

--overrides for the game difficulty slider (be careful with this, as it depends of the position of OPTION_GAMEPLAY_DIFFICULTY in the table above)
if RefFleetRatio == nil then
    RefFleetRatio = 0.4
FE_GAMEPLAYOPTION_TAB[1][3][2][1].Text.text = RefFleetRatio --default text in the label
FE_GAMEPLAYOPTION_TAB[1][3][2][2].scrollPosition = RefFleetRatio --default position for the scrollbar button

Wow, you are amazing. Quick test and its working great.

Aaaa, this is why my first “clone” attempts last week have been unsuccessful. I tried it only in main menu options.

I’ll do a deeper test, and then i will respond during this or next week. I’m too busy now. :rage:

Thank You VERY much for code (i learned a lot) and your time, specialy night time :wink:

You’re welcome ^^

I’ve edited my previous post with some changes (only in the first part of code) :

  • max has been changed from 2.0 to 3.0 (silly me who forgot to change it back after some test)
  • text formatting added when writing slider position in SP_Difficulty.lua, to make sure that there is always a decimal even for integers (2.0 instead of 2 for example). This is done to ensure that the value in the slider label is always in this format even after reloading the value from the file.
1 Like