Hard Light Productions Forums

Modding, Mission Design, and Coding => The Scripting Workshop => Topic started by: SeeNeYe on August 08, 2010, 10:27:32 am

Title: No stretch on UI - script
Post by: SeeNeYe on August 08, 2010, 10:27:32 am
Hi all,

I've managed to write a script for the preload picture which permit to prevent it to stretch across the screen and display it on the screen's center whatever the screen's resolution.

Code: [Select]
#Global hooks
$Splash: [
x = (gr.getScreenWidth()-800)/2
y = (gr.getScreenHeight()-600)/2
gr.drawImage("PreLoad.dds", x, y)
]
+Override: true
#End

This code allows to have a correct aspect ratio even on 16/10 and triple head displays.  :D

Now, I would like to extend this concept to the entire FS2O User Interface.

I guess that I could start from the "On Game Init" hook but for the rest i'm a bit newbie in the LUA scripting, so if anybody has some ideas on how I can manage to do it, it would be great ! :)

Thx (c)
Title: Re: No stretch on UI - script
Post by: The E on August 08, 2010, 10:48:26 am
Except that you're really doing it wrong :P

Instead of using

x = (gr.getScreenWidth()-800/2)

You should do it like this:

Code: [Select]
#Global hooks
$Splash: [
screenX = gr.getScreenWidth()
screenY = gr.getScreenHeight()
if screenX >= 1024 then
   image = gr.loadTexture("2_preload.dds")
else
   image = gr.loadTexture("preload.dds")
end

if texture:isValid() then
   x = (screenX - image:getWidth())/2
   y = (screenY - image:getHeight())/2
   gr.drawImage(image, x, y)
end

]
+Override: true
#End

EDIT: Oops, slight oversight.
Title: Re: No stretch on UI - script
Post by: SeeNeYe on August 08, 2010, 01:32:58 pm
 :)

you're completly right, as there should be a compatibility with resolutions lower than 1024 wide, as in the original game, but my script is not perfect at all ^^

Any idea to do the same thing with all the UI display ?  :P
Title: Re: No stretch on UI - script
Post by: The E on August 08, 2010, 01:39:32 pm
Yes.

However, I should warn you that it's impossible.
Title: Re: No stretch on UI - script
Post by: SeeNeYe on August 08, 2010, 01:49:33 pm
wow really impossible ?

I guessed that was not an easy task, but not this much !

thx for your answer btw
Title: Re: No stretch on UI - script
Post by: FreeSpaceFreak on August 09, 2010, 12:36:15 pm
Hmm, I would love the interface sticking to 4:3 resolution. Finally getting rid of the stretching on widescreen resolutions.
Title: Re: No stretch on UI - script
Post by: SeeNeYe on August 09, 2010, 02:51:04 pm
 :D Definitly !
Title: Re: No stretch on UI - script
Post by: The E on August 09, 2010, 05:44:07 pm
Hmm, I would love the interface sticking to 4:3 resolution. Finally getting rid of the stretching on widescreen resolutions.

Yes, but that's something that has to be fixed on the code side, really. A rewrite, similar to the HUD rewrite effort, basically.
Title: Re: No stretch on UI - script
Post by: SeeNeYe on August 09, 2010, 05:48:06 pm
hi

:( the new script is not working, i've got this error from the debugger :

Code: [Select]
LUA ERROR: [string "Splash"]:9: attempt to index global 'texture' (a nil value)

------------------------------------------------------------------
ADE Debug:
------------------------------------------------------------------
Name: (null)
Name of:
Function type: main
Defined on: 0
Upvalues: 0

Source: Splash
Short source: [string "Splash"]
Current line: 4
- Function line: 0
------------------------------------------------------------------


------------------------------------------------------------------
LUA Stack:
------------------------------------------------------------------

------------------------------------------------------------------

I've checked and re-checked everything, but it seems not working at all.

Any clue ? thx  :)

EDIT: problem resolved, i'm feeling really newbie lol

Quote
#Global hooks
$Splash: [
screenX = gr.getScreenWidth()
screenY = gr.getScreenHeight()
if screenX >= 1024 then
   image = gr.loadTexture("2_preload.dds")
else
   image = gr.loadTexture("preload.dds")
end

if texture:isValid() then            => in this line it's not the right variable name, it should be image :)
   x = (screenX - image:getWidth())/2
   y = (screenY - image:getHeight())/2
   gr.drawImage(image, x, y)
end

]   
   +Override: true
#End
Title: Re: No stretch on UI - script
Post by: The E on August 09, 2010, 07:22:27 pm
Actually, the error is mine. But good spotting nonetheless.
Title: Re: No stretch on UI - script
Post by: Reprobator on August 11, 2010, 03:01:01 am
That'ts a good start anyway, i now have a non stretched splash screen on my triplehead setup :D
Title: Re: No stretch on UI - script
Post by: Fury on August 11, 2010, 04:52:15 am
Hmm, I would love the interface sticking to 4:3 resolution. Finally getting rid of the stretching on widescreen resolutions.

Yes, but that's something that has to be fixed on the code side, really. A rewrite, similar to the HUD rewrite effort, basically.
For those who are not aware, there's already been significant progress on the new HUD code. See http://www.hard-light.net/forums/index.php?topic=69858.0
Title: Re: No stretch on UI - script
Post by: Commander Zane on August 11, 2010, 11:33:34 am
E doesn't recommend using it for now unless you know what you're doing with it, and I don't think a lot of us do.
Title: Re: No stretch on UI - script
Post by: The E on August 11, 2010, 12:27:12 pm
Once it goes into antipodes, that's when you should take another look at it.