Page 1 of 2

How to display image via Lua?

Posted: Wed Mar 30, 2016 6:23 am
by Anakin
Hi,

if there is a list set up like that:

Code: Select all

listname = {
  {variable = "what ever", anOtherVar = 5, andAnBool = true, },
  {variable = "what ever2", anOtherVar = 3, andAnBool = true, },
  {variable = "what ever3", anOtherVar = 3, andAnBool = false, },
}
how would i insert my own entry without replacing the old list??

Code: Select all

{variable = "custom1", anOtherVar = 3, andAnBool = true, },

Re: lua list how to insert entry

Posted: Wed Mar 30, 2016 5:36 pm
by jedimoose32

Code: Select all

listname[table.getn(listname)] = {variable = "custom1", anOtherVar = 3, andAnBool = true, }
This will append your custom line at the end of the table. If you need to put the new entry in the middle of the list somewhere then you might want to use:

Code: Select all

table.insert(listname, <key #>, value)
You can actually use table.insert() with only two arguments and achieve the same result as my first example, if you prefer. I'm pretty sure both operations take roughly the same amount of system resources to complete. For example:

Code: Select all

table.insert(listname, value)
This will do exactly the same thing as my first code example.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 10:10 am
by Anakin
Alright i'll test it. Thank you.

==Edit==
got this message: (none):0: attempt to call field `getn' (a nil value)

==EDIT2==

tried the other method from you and got that:
(none):0: attempt to call field `insert' (a nil value)

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 10:31 am
by jedimoose32
Hm, can you try the other method I suggested? (The third code example). I remember now that table.getn() is not really good practice for tables and is actually meant for arrays. Try using table.insert() instead. I've never had trouble with that one.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 10:38 am
by Anakin
have you seen my edit 2?? same problem.

(none):0: attempt to call field `insert' (a nil value)

Here the the whole code:

Code: Select all

--This is a test output for CustomLVL
print("custom_gc_1: BF3 GC Entered")

---------------------------------------------------------------
-- Adding BF3 legal screen on startup
---------------------------------------------------------------

-- waiting for AddIFScreen calls
if AddIFScreen then
	print("custom_gc_1: Taking control of AddIFScreen()...")
	
	-- backup variables in use??
	if gc1_AddIFScreen then
		print("custom_gc_1: Warning: Someone else is using our gc1_AddIFScreen variable!")
		print("custom_gc_1: Exited")
		return
	end

	-- backup old function
	gc1_AddIFScreen = AddIFScreen
	
	-- define new function
	AddIFScreen = function(table, name,...)
	
		-- let the original function happen
		retValue = gc1_AddIFScreen(table, name, unpack(arg))
		
		-- do changes only for ifs_legal
		if name == "ifs_legal" then
			print("custom_gc_1: AddIFScreen(ifs_legal): Entered")
			print("custom_gc_1: adding bf3 legacy logo")
			
			-- add rcm_legal screen
			print("i did something cool")
			MyCoolValue = { texture = "bf3_legal", time = 3, bSkippable = 1, }
			table.insert(gLegalScreenList, MyCoolValue)
--			gLegalScreenList[table.getn(gLegalScreenList) + 1] = { texture = "bf3_legal", time = 3, bSkippable = 1, }

	    print("custom_gc_1: AddIFScreen(ifs_legal): Exited")
		end

		
	    return retValue
	end
	
	print("custom_gc_1: Have control of AddIFScreen()")
else
	print("custom_gc_1: Warning: No AddIFScreen() to take over")
	print("custom_gc_1: Exited")
	return
end

print("custom_gc_1: Exited")
before i used this one for RCM and it works fine. But is not compatible.

Code: Select all

-- waiting for AddIFScreen calls
if AddIFScreen then
	print("custom_gc_1: Taking control of AddIFScreen()...")
	
	-- backup variables in use??
	if gc1_AddIFScreen then
		print("custom_gc_1: Warning: Someone else is using our gc1_AddIFScreen variable!")
		print("custom_gc_1: Exited")
		return
	end

	-- backup old function
	gc1_AddIFScreen = AddIFScreen
	
	-- define new function
	AddIFScreen = function(table, name,...)
	
		-- do changes only for ifs_legal
		if name == "ifs_legal" then
			print("custom_gc_1: AddIFScreen(ifs_legal): Entered")
			print("custom_gc_1: adding rcm logo")
			
			-- add rcm_legal screen
			gLegalScreenList =	{
									{ texture = "bootlegal", time = 5, },
									{ texture = "lucasarts_logo", time = 3, bSkippable = 1, },
									{ texture = "pandemic_logo", time = 3, bSkippable = 1, },
									{ texture = "rcm_legal", time = 3, bSkippable = 1, },
									{ texture = "dolby_logo", time = 3, bSkippable = 1, },
								}

	    print("custom_gc_1: AddIFScreen(ifs_legal): Exited")
		end

		-- let the original function happen
	    return gc1_AddIFScreen(table, name, unpack(arg))
	end
	
	print("custom_gc_1: Have control of AddIFScreen()")
else
	print("custom_gc_1: Warning: No AddIFScreen() to take over")
	print("custom_gc_1: Exited")
	return
end

print("custom_gc_1: Exited")

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 10:51 am
by jedimoose32
You never defined gLegalScreenList before you tried to insert MyCoolValue into it. You at least need to define it beforehand. Right at the beginning of the script you can put gLegalScreenList = {} and then fill it in later.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 10:54 am
by Anakin
gLegalScreenList is defined in the ifs_legal file.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 11:03 am
by jedimoose32
Oh yeah, right. It's a global variable so I'm not sure why your script won't read it. Are you munging ifs_legal in your custom shell at the same time? If not, try adding that into your req.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 11:16 am
by Anakin
no i didn't munge the custom shell, but i don't have a custom shell. It's a custom_gc script.

==EDIT==
i added the ifs_legal script to the custom_gc lvl but still the same problem.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 11:22 am
by jedimoose32
I don't have any experience with custom GC. I do know that when it comes to anything shell related, it needs to be munged together. Try loading ifs_legal with your custom script (same req). Or use ScriptCB_DoFile at the top of your script.

Edit: Saw your edit. Try the DoFile suggestion.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 11:24 am
by Anakin
jep did that. i munged ifs_legal in my cusomt gc script, but same problem. next i added ScriptCD_DoFile at the top, but then the AddIfScreen wrapper never come to ifs_legal

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 11:25 am
by jedimoose32
What if you try doing all of this as a custom ifs file instead of a custom GC? Then you can munge it all together with no broken dependencies.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 2:10 pm
by Anakin
but that way I replace the stock ifs_legal and won't be able to make it compatible with others.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 2:24 pm
by jedimoose32
You don't have to replace it, just make a brand new one for your GC. Edit: again, I'm not a GC expert, but I do have experience modding the interface. The bottom line here though, is that you need that table, otherwise table.insert() is always going to fail. Make your own table if you want to.

Re: lua list how to insert entry

Posted: Thu Mar 31, 2016 5:29 pm
by Anakin
I understand. The GC is not a big thing. It's just a way to insert custom code and to change some functions with a wrapper.

About the custom ifs_legal. I just want to display one picture with the possibility to skip it. You say you know about interface programming. Is there a way to shorten the ifs screen code??

Re: lua list how to insert entry

Posted: Fri Apr 01, 2016 12:59 am
by jedimoose32
EDIT: Sorry, I misread your question. Typing the correct response right now.... (/edit)
EDIT 2: I just realized how late it is here... I will finish my response in the morning. :P (/edit 2)

Do you mean shorten it as in make it take less time to go through the images? That's fairly simple.

Code: Select all

gLegalScreenList = {
-- 	{ texture = "bootESRB", time = 4, bNoPAL = 1, },
	{ texture = "bootlegal", time = 5, },
	{ texture = "lucasarts_logo", time = 3, bSkippable = 1, },
	{ texture = "pandemic_logo", time = 3, bSkippable = 1, },
--	{ texture = "nvidia_logo", time = 3, bSkippable = 1, bNoPS2 = 1, bNoXBox = 1, },

	-- play the movie unless you hit x to skip, the show the texture.  else skip the texture.
--	{ movie = "pandemic_logo", texture = "pandemic_logo", time = 3, bSkippable = 1, },

--	{ texture = "logodolby", time = 3, bSkippable = 1, },
	{ texture = "dolby_logo", time = 3, bSkippable = 1, },
}
Change all the time values to something lower like 0.6 (which happens to be the length of each screen if you "skip" by clicking through the logos).

Re: lua list how to insert entry

Posted: Fri Apr 01, 2016 4:25 am
by Anakin
I want to add my own ifs screen after ifs_legal. But my custom ifs won't display a list of textures, i want only one image be displayed. That way i think i don't need to copy the whole ifs_legal script since i don't need a function ifs_legal_GotoNext(this,bWasSkip) since there is no next image.

I don't understand much of that, so what are the important parts that display the image, start the countdown, can be aboard by klick and go ahead with the next ifs screen??
Hidden/Spoiler:
[code]--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--


-- Screens to show, with time per screen
gLegalScreenList = {
-- { texture = "bootESRB", time = 4, bNoPAL = 1, },
{ texture = "bootlegal", time = 5, },
{ texture = "lucasarts_logo", time = 3, bSkippable = 1, },
{ texture = "pandemic_logo", time = 3, bSkippable = 1, },
-- { texture = "nvidia_logo", time = 3, bSkippable = 1, bNoPS2 = 1, bNoXBox = 1, },

-- play the movie unless you hit x to skip, the show the texture. else skip the texture.
-- { movie = "pandemic_logo", texture = "pandemic_logo", time = 3, bSkippable = 1, },

-- { texture = "logodolby", time = 3, bSkippable = 1, },
{ texture = "dolby_logo", time = 3, bSkippable = 1, },
}

function ifs_legal_GotoNext(this,bWasSkip)

-- reset this
this.SkippedMovie = nil
local iLastPage = this.iLastPage

local bGotNext = nil
local iNumScreens = table.getn(gLegalScreenList)

-- Advance to next screen
repeat
this.iOnPage = this.iOnPage + 1
if(this.iOnPage > iNumScreens) then
ScriptCB_SetIFScreen("ifs_start")
return
end

bGotNext = 1 -- assume so until proven otherwise
-- Skip
if ((gPlatformStr == "PS2") and (gLegalScreenList[this.iOnPage].bNoPS2)) then
bGotNext = nil
elseif ((gPlatformStr == "XBox") and (gLegalScreenList[this.iOnPage].bNoXBox)) then
bGotNext = nil
elseif ((gPlatformStr == "PC") and (gLegalScreenList[this.iOnPage].bNoPC)) then
bGotNext = nil
end

-- Also check some demo-only screens
if ((gE3Demo) and (gLegalScreenList[this.iOnPage].bNoE3Demo)) then
bGotNext = nil
end

if ((gPALBuild) and (gLegalScreenList[this.iOnPage].bNoPAL)) then
bGotNext = nil
end
until bGotNext

-- what was the previous screen?
local prev = "none"
if((this.iOnPage > 1) and (iLastPage) and (iLastPage > 0)) then
if(gLegalScreenList[iLastPage].movie) then
prev = "movie"
else
prev = "texture"
end
end

-- what is the next screen
local next = "none"
if(gLegalScreenList[this.iOnPage].movie) then
next = "movie"
else
next = "texture"
end

-- set the texture that will fade out (this.ShowTexture)
print("prev = ", prev, " iLastPage = ", iLastPage)
if(prev == "texture") then
IFImage_fnSetTexture(this.ShowTexture, gLegalScreenList[iLastPage].texture)

AnimationMgr_AddAnimation(this.ShowTexture , { fTotalTime = 0.25, fStartAlpha = 1, fEndAlpha = 0,})
IFObj_fnSetVis(this.ShowTexture, 1)
elseif (prev == "movie") then
ifelem_shellscreen_fnStopMovie()
elseif (prev == "none") then
IFObj_fnSetVis(this.ShowTexture, nil)
end

-- set the texture that will fade in (this.ShowTexture2)
if(next == "texture") then
IFImage_fnSetTexture(this.ShowTexture2, gLegalScreenList[this.iOnPage].texture)
AnimationMgr_AddAnimation(this.ShowTexture2, { fTotalTime = 0.4, fStartAlpha = 0, fEndAlpha = 1,})
if(this.bEverSkipped) then
this.Timer = 0.4 -- fast-forward thru rest of screens
else
this.Timer = gLegalScreenList[this.iOnPage].time
end
IFObj_fnSetVis(this.ShowTexture2, 1)
elseif (next == "movie") then
AnimationMgr_AddAnimation(this.ShowTexture2 , { fTotalTime = 0.1, fStartAlpha = 0, fEndAlpha = 0,})
ifelem_shellscreen_fnStartMovie(gLegalScreenList[this.iOnPage].movie, 0, nil, 1)
end

-- Store page # we're on
this.iLastPage = this.iOnPage
end

-- Input_Start = function(this)
-- if((this.iOnPage > 0) and (this.iOnPage < table.getn(gLegalScreenList))) then
-- if(gLegalScreenList[this.iOnPage].bSkippable) then
-- this.Timer = 0
-- this.iOnPage = table.getn(gLegalScreenList)
-- end -- current page is skippable
-- end -- page is sane
-- end,

function ifs_legal_fnTryToSkip(this)
if(this.iOnPage>0 and gLegalScreenList[this.iOnPage].bSkippable) then
this.bEverSkipped = 1

if(gLegalScreenList[this.iOnPage].movie) then
if(not this.SkippedMovie) then
this.SkippedMovie = 1

-- switch to the backup texture for this screen
ifelem_shellscreen_fnStopMovie()
IFImage_fnSetTexture(this.ShowTexture2, gLegalScreenList[this.iOnPage].texture)
AnimationMgr_AddAnimation(this.ShowTexture2, { fTotalTime = 0.4, fStartAlpha = 0, fEndAlpha = 1,})
this.Timer = 0.6
end
else -- current screen is a texture
this.Timer = 0 -- skip out of current screen, fast-forward thru next.
end
end -- could skip
end

ifs_legal = NewIFShellScreen {
-- # of seconds before we go into demomode. XBox TCR C1-6 says
-- this must be no larger than 120 seconds
Timer = 0, -- how long the current page has before it's advanced
iLastPage = nil,
iOnPage = 0, -- start before first page
nologo = 1,
bNohelptext = 1,
bNohelptext_backPC = 1,
movieIntro = nil,
movieBackground = nil,
enterSound = "",
exitSound = "",

ShowTexture = NewIFImage {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.5,
UseSafezone = 0,

texture = "opaque_black",
-- Size, UVs aren't fully specified here, but in NewIFShellScreen()
},

ShowTexture2 = NewIFImage {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.5,
UseSafezone = 0,

ZPos = 120, -- a bit in front of the other texture

texture = "opaque_black",
-- Size, UVs aren't fully specified here, but in NewIFShellScreen()
},

ClearTextures = function(this)
-- done with textures
for _, item in ipairs(gLegalScreenList) do
if item.texture then
ScriptCB_RemoveTexture(item.texture)
end
end
end,

Enter = function(this, bFwd)
gIFShellScreenTemplate_fnEnter(this, bFwd)
-- print("ifs_legal.Enter")

--
-- Start thread that looks for patch
if(ScriptCB_CheckForPatch) then
ScriptCB_CheckForPatch(1)
end

-- If player has already logged in, and the shell is just legaling
-- up, jump forward to main menu
if(bFwd and ((not ScriptCB_ShouldShowLegal()) or ScriptCB_SkipToNTGUI()) ) then
this.bNoUnbind = 1
ScriptCB_SetIFScreen("ifs_start")
return
else
-- Ignore controllers that go missing during this screen
ScriptCB_SetIgnoreControllerRemoval(1)
end

if((gPlatformStr ~= "PS2") and (ScriptCB_GetLanguage() ~= "english") and (this.iOnPage == 0)) then
this.iOnPage = 1 -- skip ESRB/PEGI logo.
end

-- allow all controllers
ScriptCB_SetAutoAcquireControllers(1)
ScriptCB_ReadAllControllers(1)

if(not ScriptCB_IsErrorBoxOpen()) then
-- print(" legal.Enter has no Errorbox open")
ScriptCB_EnableCursor(0)
end
IFObj_fnSetVis(this.ShowTexture, nil)
IFObj_fnSetVis(this.ShowTexture2, nil)
end,

Exit = function(this, bFwd)
print("ifs_legal.Exit")

ScriptCB_EnableCursor(1)

-- make sure we got this
ifelem_shellscreen_fnStopMovie()

-- detatch all controllers
ScriptCB_SetAutoAcquireControllers(nil)
ScriptCB_ReadAllControllers(nil)
if(not this.bNoUnbind) then
ScriptCB_UnbindController(-1) -- all controllers
end

-- done with textures
this:ClearTextures()
end,

Update = function(this, fDt)
-- Call base class functionality
gIFShellScreenTemplate_fnUpdate(this, fDt)

-- XBox Demo stuff nonsense (timer doesn't accumulate during legal screens)
if(ScriptCB_PauseDemoTimer) then
ScriptCB_PauseDemoTimer()
end

if(this.iOnPage and this.iOnPage<=table.getn(gLegalScreenList)) then
-- are we showing a texture or a movie?
if(this.iOnPage~=0 and gLegalScreenList[this.iOnPage].movie and not this.SkippedMovie) then
-- movie
if(not ScriptCB_IsMoviePlaying()) then
ifs_legal_GotoNext(this)
end
else
-- texture
this.Timer = this.Timer - fDt
if(this.Timer < 0) then
ifs_legal_GotoNext(this)
end
end
end
end,

-- Start actually works on this screen
Input_Start = function(this)
ifs_legal_fnTryToSkip(this)
end,

Input_Accept = function(this)
ifs_legal_fnTryToSkip(this)
end,

-- Overrides for most input handlers, as we want to do nothing
-- when this happens on this screen.
Input_Back = function(this)
end,
Input_GeneralLeft = function(this)
end,
Input_GeneralRight = function(this)
end,
Input_GeneralUp = function(this)
end,
Input_GeneralDown = function(this)
end,
}

function ifs_legal_fnBuildScreen(this)
-- Ask game for screen size, fill in values
local w, h, v, widescreen
w,h,v,widescreen=ScriptCB_GetScreenInfo()
this.ShowTexture.localpos_l =-w*0.5
this.ShowTexture.localpos_t =-h*0.5
this.ShowTexture.localpos_r = w*0.5
this.ShowTexture.localpos_b = h*0.5
this.ShowTexture.uvs_b = v
this.ShowTexture2.localpos_l =-w*0.5
this.ShowTexture2.localpos_t =-h*0.5
this.ShowTexture2.localpos_r = w*0.5
this.ShowTexture2.localpos_b = h*0.5
this.ShowTexture2.uvs_b = v
end

ifs_legal_fnBuildScreen(ifs_legal) -- programatic chunks
ifs_legal_fnBuildScreen = nil
AddIFScreen(ifs_legal,"ifs_legal")
[/code]

Re: lua list how to insert entry

Posted: Fri Apr 01, 2016 1:22 pm
by jedimoose32
My interface tutorial is up, though I admit that it feels kind of jumbled together. I'll add a few things to make it clearer later. Check it out here.

I don't talk specifically about this topic (legal screens) but I cover some similar topics so you might still find it helpful. I'll try and have a look at your example and see what I can do.

Re: [LUA] How to display image

Posted: Sat Apr 02, 2016 8:09 am
by Anakin
OK i made it to hack myself into the legal screen and to display my own ifscreen right after ifs_legal. Now you need to tell me why nothing is shown:


For me it looks identical to the ifs legal screen, with just renamed functions. But for some reason it does not work
Hidden/Spoiler:
[code]--
-- Copyright (c) 2005 Pandemic Studios, LLC. All rights reserved.
--

print("spalsh")
-- Screens to show, with time per screen
gBf3ScreenList = {
{ texture = "bf3_legal", time = 3, bSkippable = 1, },
}

function ifs_bf3_GotoNext(this,bWasSkip)

-- reset this
this.SkippedMovie = nil
local iLastPage = this.iLastPage

local bGotNext = nil
local iNumScreens = table.getn(gBf3ScreenList)

-- Advance to next screen
repeat
this.iOnPage = this.iOnPage + 1
if(this.iOnPage > iNumScreens) then
ScriptCB_SetIFScreen("ifs_start")
return
end

bGotNext = 1 -- assume so until proven otherwise
-- Skip
if ((gPlatformStr == "PS2") and (gBf3ScreenList[this.iOnPage].bNoPS2)) then
bGotNext = nil
elseif ((gPlatformStr == "XBox") and (gBf3ScreenList[this.iOnPage].bNoXBox)) then
bGotNext = nil
elseif ((gPlatformStr == "PC") and (gBf3ScreenList[this.iOnPage].bNoPC)) then
bGotNext = nil
end

-- Also check some demo-only screens
if ((gE3Demo) and (gBf3ScreenList[this.iOnPage].bNoE3Demo)) then
bGotNext = nil
end

if ((gPALBuild) and (gBf3ScreenList[this.iOnPage].bNoPAL)) then
bGotNext = nil
end
until bGotNext

-- what was the previous screen?
local prev = "none"
if((this.iOnPage > 1) and (iLastPage) and (iLastPage > 0)) then
if(gBf3ScreenList[iLastPage].movie) then
prev = "movie"
else
prev = "texture"
end
end

-- what is the next screen
local next = "none"
if(gBf3ScreenList[this.iOnPage].movie) then
next = "movie"
else
next = "texture"
end

-- set the texture that will fade out (this.ShowTexture)
print("prev = ", prev, " iLastPage = ", iLastPage)
if(prev == "texture") then
IFImage_fnSetTexture(this.ShowTexture, gBf3ScreenList[iLastPage].texture)

AnimationMgr_AddAnimation(this.ShowTexture , { fTotalTime = 0.25, fStartAlpha = 1, fEndAlpha = 0,})
IFObj_fnSetVis(this.ShowTexture, 1)
elseif (prev == "movie") then
ifelem_shellscreen_fnStopMovie()
elseif (prev == "none") then
IFObj_fnSetVis(this.ShowTexture, nil)
end

-- set the texture that will fade in (this.ShowTexture2)
if(next == "texture") then
IFImage_fnSetTexture(this.ShowTexture2, gBf3ScreenList[this.iOnPage].texture)
AnimationMgr_AddAnimation(this.ShowTexture2, { fTotalTime = 0.4, fStartAlpha = 0, fEndAlpha = 1,})
if(this.bEverSkipped) then
this.Timer = 0.4 -- fast-forward thru rest of screens
else
this.Timer = gBf3ScreenList[this.iOnPage].time
end
IFObj_fnSetVis(this.ShowTexture2, 1)
elseif (next == "movie") then
AnimationMgr_AddAnimation(this.ShowTexture2 , { fTotalTime = 0.1, fStartAlpha = 0, fEndAlpha = 0,})
ifelem_shellscreen_fnStartMovie(gBf3ScreenList[this.iOnPage].movie, 0, nil, 1)
end

-- Store page # we're on
this.iLastPage = this.iOnPage
end

-- Input_Start = function(this)
-- if((this.iOnPage > 0) and (this.iOnPage < table.getn(gBf3ScreenList))) then
-- if(gBf3ScreenList[this.iOnPage].bSkippable) then
-- this.Timer = 0
-- this.iOnPage = table.getn(gBf3ScreenList)
-- end -- current page is skippable
-- end -- page is sane
-- end,

function ifs_bf3_fnTryToSkip(this)
if(this.iOnPage>0 and gBf3ScreenList[this.iOnPage].bSkippable) then
this.bEverSkipped = 1

if(gBf3ScreenList[this.iOnPage].movie) then
if(not this.SkippedMovie) then
this.SkippedMovie = 1

-- switch to the backup texture for this screen
ifelem_shellscreen_fnStopMovie()
IFImage_fnSetTexture(this.ShowTexture2, gBf3ScreenList[this.iOnPage].texture)
AnimationMgr_AddAnimation(this.ShowTexture2, { fTotalTime = 0.4, fStartAlpha = 0, fEndAlpha = 1,})
this.Timer = 0.6
end
else -- current screen is a texture
this.Timer = 0 -- skip out of current screen, fast-forward thru next.
end
end -- could skip
end

ifs_bf3legal = NewIFShellScreen {
-- # of seconds before we go into demomode. XBox TCR C1-6 says
-- this must be no larger than 120 seconds
Timer = 0, -- how long the current page has before it's advanced
iLastPage = nil,
iOnPage = 0, -- start before first page
nologo = 1,
bNohelptext = 1,
bNohelptext_backPC = 1,
movieIntro = nil,
movieBackground = nil,
enterSound = "",
exitSound = "",

ShowTexture = NewIFImage {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.5,
UseSafezone = 0,

texture = "opaque_black",
-- Size, UVs aren't fully specified here, but in NewIFShellScreen()
},

ShowTexture2 = NewIFImage {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.5,
UseSafezone = 0,

ZPos = 120, -- a bit in front of the other texture

texture = "opaque_black",
-- Size, UVs aren't fully specified here, but in NewIFShellScreen()
},

ClearTextures = function(this)
-- done with textures
for _, item in ipairs(gBf3ScreenList) do
if item.texture then
ScriptCB_RemoveTexture(item.texture)
end
end
end,

Enter = function(this, bFwd)
gIFShellScreenTemplate_fnEnter(this, bFwd)
-- print("ifs_bf3legal.Enter")

--
-- Start thread that looks for patch
if(ScriptCB_CheckForPatch) then
ScriptCB_CheckForPatch(1)
end

-- If player has already logged in, and the shell is just legaling
-- up, jump forward to main menu
if(bFwd and ((not ScriptCB_ShouldShowLegal()) or ScriptCB_SkipToNTGUI()) ) then
this.bNoUnbind = 1
ScriptCB_SetIFScreen("ifs_start")
return
else
-- Ignore controllers that go missing during this screen
ScriptCB_SetIgnoreControllerRemoval(1)
end

if((gPlatformStr ~= "PS2") and (ScriptCB_GetLanguage() ~= "english") and (this.iOnPage == 0)) then
this.iOnPage = 1 -- skip ESRB/PEGI logo.
end

-- allow all controllers
ScriptCB_SetAutoAcquireControllers(1)
ScriptCB_ReadAllControllers(1)

if(not ScriptCB_IsErrorBoxOpen()) then
-- print(" legal.Enter has no Errorbox open")
ScriptCB_EnableCursor(0)
end
IFObj_fnSetVis(this.ShowTexture, nil)
IFObj_fnSetVis(this.ShowTexture2, nil)
end,

Exit = function(this, bFwd)
print("ifs_bf3legal.Exit")

ScriptCB_EnableCursor(1)

-- make sure we got this
ifelem_shellscreen_fnStopMovie()

-- detatch all controllers
ScriptCB_SetAutoAcquireControllers(nil)
ScriptCB_ReadAllControllers(nil)
if(not this.bNoUnbind) then
ScriptCB_UnbindController(-1) -- all controllers
end

-- done with textures
this:ClearTextures()
end,

Update = function(this, fDt)
-- Call base class functionality
gIFShellScreenTemplate_fnUpdate(this, fDt)

-- XBox Demo stuff nonsense (timer doesn't accumulate during legal screens)
if(ScriptCB_PauseDemoTimer) then
ScriptCB_PauseDemoTimer()
end

if(this.iOnPage and this.iOnPage<=table.getn(gBf3ScreenList)) then
-- are we showing a texture or a movie?
if(this.iOnPage~=0 and gBf3ScreenList[this.iOnPage].movie and not this.SkippedMovie) then
-- movie
if(not ScriptCB_IsMoviePlaying()) then
ifs_bf3_GotoNext(this)
end
else
-- texture
this.Timer = this.Timer - fDt
if(this.Timer < 0) then
ifs_bf3_GotoNext(this)
end
end
end
end,

-- Start actually works on this screen
Input_Start = function(this)
ifs_bf3_fnTryToSkip(this)
end,

Input_Accept = function(this)
ifs_bf3_fnTryToSkip(this)
end,

-- Overrides for most input handlers, as we want to do nothing
-- when this happens on this screen.
Input_Back = function(this)
end,
Input_GeneralLeft = function(this)
end,
Input_GeneralRight = function(this)
end,
Input_GeneralUp = function(this)
end,
Input_GeneralDown = function(this)
end,
}

function ifs_bf3legal_fnBuildScreen(this)
-- Ask game for screen size, fill in values
local w, h, v, widescreen
w,h,v,widescreen=ScriptCB_GetScreenInfo()
this.ShowTexture.localpos_l =-w*0.5
this.ShowTexture.localpos_t =-h*0.5
this.ShowTexture.localpos_r = w*0.5
this.ShowTexture.localpos_b = h*0.5
this.ShowTexture.uvs_b = v
this.ShowTexture2.localpos_l =-w*0.5
this.ShowTexture2.localpos_t =-h*0.5
this.ShowTexture2.localpos_r = w*0.5
this.ShowTexture2.localpos_b = h*0.5
this.ShowTexture2.uvs_b = v
end

ifs_bf3legal_fnBuildScreen(ifs_bf3legal) -- programatic chunks
ifs_bf3legal_fnBuildScreen = nil
AddIFScreen(ifs_bf3legal,"ifs_bf3legal")
[/code]

Re: [LUA] How to display image

Posted: Sat Apr 02, 2016 11:54 am
by jedimoose32
This looks nice and everything, but the stock ifs_legal file is really way too cluttered for what you need. I would recommend building a new screen from scratch, because currently you've got all this leftover controller initialization stuff, and a bunch of garbage related to the XBox DVD demo version, etc which is all unnecessary and could actually be causing problems since it's already run once before in the ifs_legal screen. I'll try and write a shorter version this morning and you can tweak that to your liking.