Author Topic: No stretch on UI - script  (Read 2795 times)

0 Members and 1 Guest are viewing this topic.

Offline SeeNeYe

  • 25
No stretch on UI - script
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)
-----------------
The Thuth is a pathless land

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: No stretch on UI - script
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.
« Last Edit: August 08, 2010, 12:42:24 pm by The E »
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline SeeNeYe

  • 25
Re: No stretch on UI - script
 :)

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
-----------------
The Thuth is a pathless land

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: No stretch on UI - script
Yes.

However, I should warn you that it's impossible.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline SeeNeYe

  • 25
Re: No stretch on UI - script
wow really impossible ?

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

thx for your answer btw
-----------------
The Thuth is a pathless land

 
Re: No stretch on UI - script
Hmm, I would love the interface sticking to 4:3 resolution. Finally getting rid of the stretching on widescreen resolutions.

 

Offline SeeNeYe

  • 25
Re: No stretch on UI - script
 :D Definitly !
-----------------
The Thuth is a pathless land

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: No stretch on UI - script
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.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline SeeNeYe

  • 25
Re: No stretch on UI - script
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
« Last Edit: August 09, 2010, 06:15:50 pm by SeeNeYe »
-----------------
The Thuth is a pathless land

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: No stretch on UI - script
Actually, the error is mine. But good spotting nonetheless.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 
Re: No stretch on UI - script
That'ts a good start anyway, i now have a non stretched splash screen on my triplehead setup :D
$Formula: ( every-time
   ( has-time-elapsed "0" )
   ( Do-Nothing
   )
   ( send-message
      "#Dalek"
      "High"
      "Pro-crasti-nate"
   )
   )
)
+Name: Procratination
+Repeat Count: 99999999999
+Interval: 1

 

Offline Fury

  • The Curmudgeon
  • 213
Re: No stretch on UI - script
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

 

Offline Commander Zane

  • 212
  • Spoot Knight of Anvils
Re: No stretch on UI - script
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.

 

Offline The E

  • He's Ebeneezer Goode
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: No stretch on UI - script
Once it goes into antipodes, that's when you should take another look at it.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns