Page 2 of 2

Re: [LUA] How to display image

Posted: Sat Apr 02, 2016 12:51 pm
by Anakin
Thank you :D
already played around but couldn't get it working

Re: [LUA] How to display image

Posted: Sat Apr 02, 2016 1:05 pm
by jedimoose32
Try this:
Hidden/Spoiler:
[code]
--
-- Anakin's BF3 splash (jedimoose32's basic attempt at helping)
--

print("splash")

function ifs_bf3_fnAdvance(this)
ScriptCB_SetIFScreen("ifs_start")
end

ifs_bf3legal = NewIFShellScreen {
Timer = 3, -- how long the current page has before it's advanced
nologo = 1,
bNohelptext = 1,
bNohelptext_backPC = 1,
movieIntro = nil,
movieBackground = nil,
enterSound = "",
exitSound = "",

BGTexture = NewIFImage {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.5,
UseSafezone = 0,
alpha = 1.0,

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

BF3Texture = NewIFImage {
ScreenRelativeX = 0.5,
ScreenRelativeY = 0.5,
UseSafezone = 0,
alpha = 0.0,

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

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


Enter = function(this, bFwd)
gIFShellScreenTemplate_fnEnter(this, bFwd)

AnimationMgr_AddAnimation(this.BF3Texture, {fTotalTime = 0.4, fStartAlpha = 0.0, fEndAlpha = 1.0,})

end,

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

ScriptCB_EnableCursor(1)

end,

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

this.Timer = this.Timer - fDt
if(this.Timer <= 0) then
ifs_bf3_fnAdvance(this)
end

end,

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

Input_Accept = function(this)
ifs_bf3_fnAdvance(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.BGTexture.localpos_l =-w*0.5
this.BGTexture.localpos_t =-h*0.5
this.BGTexture.localpos_r = w*0.5
this.BGTexture.localpos_b = h*0.5
this.BGTexture.uvs_b = v
this.BF3Texture.localpos_l =-w*0.5
this.BF3Texture.localpos_t =-h*0.5
this.BF3Texture.localpos_r = w*0.5
this.BF3Texture.localpos_b = h*0.5
this.BF3Texture.uvs_b = v
end

ifs_bf3legal_fnBuildScreen(ifs_bf3legal) -- programatic chunks
ifs_bf3legal_fnBuildScreen = nil
AddIFScreen(ifs_bf3legal,"ifs_bf3legal")
[/code]
I haven't tested it but let me know how it works and I can make tweaks.

Re: How to display image via Lua?

Posted: Sun Apr 03, 2016 6:47 am
by Anakin
It still does not work.

I added some print lines and found out. that only the start and exit functions were entered. btw using ScriptDB_PushScreen() will not work. The enter and exit functions are never executed. So i need to use the movie push screen.

Now i modified the Enter function to this:

Code: Select all

Enter = function(this, bFwd)
	print("Enter BF3splash")
	gIFShellScreenTemplate_fnEnter(this, bFwd)
      
	AnimationMgr_AddAnimation(this.BF3Texture, {fTotalTime = 0.4, fStartAlpha = 0.0, fEndAlpha = 1.0,})
	this.Update(this, bFwd)
--	ifs_bf3_fnAdvance(this)
    
end,
And the update function is called. But not ifs_bf3_fnAdvance (you remember that the update function should call it. later on i deleted the -- and called the ifs_bf3_fnAdvance directly in the enter function. But nothing is shown. Only result when i push to my custom screen before legal screen is shown, it jumps direct to login.


==EDIT==

Ok maybe it's on the time to show you how i inserted my code. Here is my custom gc script it is comment, so i'm sure you understand what i'm doing:

Code: Select all

---------------------------------------------------------------------
-- custom_gc_1 script to add ifscreen before ifs_legal by Anakin
---------------------------------------------------------------------
print("custom_gc_1: BF3 GC Entered")

-- create the custom ifscreen
ScriptCB_DoFile("ifs_bf3Splash")

-- make sure that the function we are going to manipulate exist
if ScriptCB_DoFile then
	print("custom_gc_1: Taking control of ScriptCB_DoFile()...")
	
	-- make sure our backup variable is not used by someone else.
	if gc1_ScriptCB_DoFile then
		print("custom_gc_1: Warning: Someone else is using our gc1_ScriptCB_DoFile variable!")
		print("custom_gc_1: Exited")
		return
	end
	
	-- backup original function
	gc1_ScriptCB_DoFile = ScriptCB_DoFile
	
	-- redefine function
	ScriptCB_DoFile = function(name,...)

		-- execute original function, but do not leave
		retValue = gc1_ScriptCB_DoFile(name, unpack(arg))
		
		-- if we just executed ifs_movietrans
		-- that means that ifs_movietrans_PushScreen has just been defined,
		-- so we needn't check if that function exist
		-- (ok maybe someone else will redefine ifs_movietrans and remove ifs_movietrans_PushScreen but that's not my problem now)
		if name == "ifs_movietrans" then

			-- make sure our backup variable is not used by someone else.
			if gc1_ifs_movietrans_PushScreen then
				print("custom_gc_1: Warning: Someone else is using our gc1_ifs_movietrans_PushScreen variable!")
				print("custom_gc_1: Exited")
				return
			end
			
			-- backup original function
			gc1_ifs_movietrans_PushScreen = ifs_movietrans_PushScreen
			
			-- redefine function
			ifs_movietrans_PushScreen = function (table,...)
				
				-- if we push to ifs_legal
				if table == ifs_legal then
					-- push to ifs_bf3legal first
					ifs_movietrans_PushScreen(ifs_bf3legal)
				end
				
				-- execute original function
				return gc1_ifs_movietrans_PushScreen(table,unpack(arg))
			end
		end
		
		-- now we can leave
		return retValue
	end
else
	print("custom_gc_1: No ScriptCB_DoFile to take over...")
	print("custom_gc_1: Exited")
end


print("custom_gc_1: Exited")

I jump directly to the login screen. But the exit function from ifs legal and ifs bf3 legal are both executed. But for some reason nothing else.



===UPDATE===

Ok i found a way to display my image. But to be honest i'm still interested in new ifscreens and why this one did not work.
Your first code to insert a list entry worked just fine. I was so stupid. Take a look at my custom gc script. It's implemented the way the custom gc are made. But Zerted used table as variable name. Not a good idea in Lua. In c++ it's not allowed to use key words as variable and i didn't remember that lua will simply redefine the keyword. So you see that table.getn() was always something like ifs_legal.getn() and that was not defined :faint:

But nonetheless i want to understand why inserting a new ifscreen will directly go to the login.

Re: How to display image via Lua?

Posted: Sun Apr 03, 2016 4:42 pm
by jedimoose32
It goes directly to login afterward because I thought you were putting the BF3 logo *after* the ifs_legal screen, so I made it exit to ifs_start instead of exiting to ifs_legal. Just change that part and it should work for you.

Edit: I got your PM, maybe you can send me all these files and I can try and get it working properly.