More Customization Ahoy

As I relentlessly march through my code, I am taking the time to externalise anything that gets in my way, which now includes the About page and the In-Game Menu too, which can now be scripted using LUA instead of being hard coded with a few pre-fixed graphics. The script even takes care of loading the images it wants so apart from some commands to leave, pretty much everything on screen is customise friendly (as it ought to be).

SaveLoad

As you can see in the shot above, I decided to start the Load page script as it was a new item of the main menu and it makes sense to have all the menus converted and ready to go before I start the actual parsing of game state data for the actual save progress part.  And here is the LUA script that created it (so far):

– LoadGame page script

LOADGAME_BACK = 9
g_strBestResolution = “”
g_imgBackdrop = 0
g_sprBackdrop = 0
g_posBackdropAngle = 0
g_imgHeading = 0
g_sprHeading = 0
g_imgButton = {}
g_imgButtonH = {}
g_sprButton = {}
g_posButton = {}
g_imgCursor = 0
g_sprCursor = 0

function loadgame_init()
— choose ideal resolution
g_strBestResolution = “1366×768″
iSmallestDifference = 99999
for i = 1, 8, 1
do
if i == 1 then iAvailableWidth = 1280; iAvailableHeight = 720;
elseif i == 2 then iAvailableWidth = 1280; iAvailableHeight = 800;
elseif i == 3 then iAvailableWidth = 1366; iAvailableHeight = 768;
elseif i == 4 then iAvailableWidth = 1440; iAvailableHeight = 900;
elseif i == 5 then iAvailableWidth = 1600; iAvailableHeight = 900;
elseif i == 6 then iAvailableWidth = 1680; iAvailableHeight = 1050;
elseif i == 7 then iAvailableWidth = 1920; iAvailableHeight = 1080;
elseif i == 8 then iAvailableWidth = 1920; iAvailableHeight = 1200;
else iAvailableWidth = 0
end
iDifference = math.abs(GetDeviceWidth()-iAvailableWidth) + math.abs(GetDeviceHeight()-iAvailableHeight)
if iDifference < iSmallestDifference then
iSmallestDifference = iDifference
g_strBestResolution = iAvailableWidth .. “x” .. iAvailableHeight
end
end
— backdrop
g_imgBackdrop = LoadImage(“titlesbank\\default\\” .. g_strBestResolution .. “\\loading.jpg”)
g_sprBackdrop = CreateSprite ( g_imgBackdrop )
SetSpritePosition ( g_sprBackdrop, 0, 0 )
SetSpriteSize ( g_sprBackdrop, 110, 110 )
SetSpriteOffset ( g_sprBackdrop, 5, 5 )
— heading
g_imgHeading = LoadImage(“titlesbank\\default\\load-game-hover.png”)
g_sprHeading = CreateSprite ( g_imgHeading )
SetSpriteOffset ( g_sprHeading, GetImageWidth(g_imgHeading)/2, 0 )
SetSpritePosition ( g_sprHeading, 50, 8 )
— buttons
for i = 1, LOADGAME_BACK, 1
do
if i==LOADGAME_BACK then
strButtonName = “back”
g_posButton[i] = 90
else
strButtonName = “blank”
g_posButton[i] = 20+(i*7)
end
g_imgButton[i] = LoadImage(“titlesbank\\default\\” .. strButtonName .. “.png”)
g_imgButtonH[i] = LoadImage(“titlesbank\\default\\” .. strButtonName .. “-hover.png”)
g_sprButton[i] = CreateSprite ( g_imgButton[i] )
SetSpriteOffset ( g_sprButton[i], GetImageWidth(g_imgButton[i])/2, 0 )
SetSpritePosition ( g_sprButton[i], 50, g_posButton[i] )
end
— cursor
g_imgCursor = LoadImage(“titlesbank\\default\\cursor.png”)
g_sprCursor = CreateSprite ( g_imgCursor )
ActivateMouse()
end

function loadgame_main()
— control menus
SetSpritePosition ( g_sprCursor, g_MouseX, g_MouseY )
iHighlightButton = 0
if g_MouseX > 50-(GetImageWidth(g_imgButton[LOADGAME_BACK])/2) and g_MouseX <= 50+(GetImageWidth(g_imgButton[LOADGAME_BACK])/2) then
for i = 1, LOADGAME_BACK, 1
do
if g_MouseY > g_posButton[i] and g_MouseY <= g_posButton[i]+GetImageHeight(g_imgButton[i]) then
iHighlightButton = i
end
end
end
for i = 1, LOADGAME_BACK, 1
do
if i < LOADGAME_BACK then
TextCenterOnX ( 50, g_posButton[i] + 0.5 + (GetImageHeight(g_imgButton[i])/2), 3, “EMPTY PROGRESS SLOT”)
end
if iHighlightButton == i then
SetSpriteImage ( g_sprButton[i], g_imgButtonH[i] )
else
SetSpriteImage ( g_sprButton[i], g_imgButton[i] )
end
end
if g_MouseClick == 1 then
if iHighlightButton==LOADGAME_BACK then
SwitchPageBack()
end
end
— move backdrop
SetSpritePosition ( g_sprBackdrop, math.cos(g_posBackdropAngle* 0.0174533)*5, math.sin(g_posBackdropAngle*0.0174533)*5 )
g_posBackdropAngle = g_posBackdropAngle + 0.002
end

function loadgame_free()
— free resources
for i = 1, LOADGAME_BACK, 1
do
DeleteSprite ( g_sprButton[i] )
DeleteImage ( g_imgButton[i] )
DeleteImage ( g_imgButtonH[i] )
end
DeleteSprite ( g_sprBackdrop )
DeleteImage ( g_imgBackdrop )
DeleteSprite ( g_sprHeading )
DeleteImage ( g_imgHeading )
DeleteSprite ( g_sprCursor )
DeleteImage ( g_imgCursor )
DeactivateMouse()
end

You will notice I am not using any ‘screen capture’ style saving system for the first build, but I have an idea to make the capture a background wash so you can see the point you saved in full detail (just by hovering over the save slot in question).  I will code the LUA script to handle eight fixed save slots, but I will leave the underlying code capable of saving and loading a thousand slots (for you to provide your own GUI solutions).

It’s time now for me to pack a bag and set off out the office again for the last of my yearly meetings, this time in Manchester to discuss general strategy and overview of current TGC projects, and hopefully the Gammon & Egg I’ve just wolfed down will not make me tired during the 2 hour drive.  Has been real fun and rewarding to see the features so long requested starting to take shape and I hope to bring you them soon in a build near you!

  • T-Rex

    This is wonderful Lee ! :D