I smell....progress.
scripting.tbl:
#Conditional Hooks
$Application: Freespace 2
$On Game Init: [[Global_onInit.LUA]]
$State: GS_STATE_MAIN_MENU
$On State Start: [[mainhall_onStart.LUA]]
+Override: true
$On State End: [[mainhall_onEnd.lua]]
+Override: true
$On Frame: [[mainhall_onFrame.LUA]]
+Override: true
#End
Global_onInit:
--Function to handle a section every frame. These are used to create the entries in the Mainhall menu
--This function is useful for drawing a row or line of buttons
--name: (string) The text associated with the control
--num: (int) Multiplier that is used to generate the position
--hidden: (boolean) Whether or not there will be visual feedback for moving the mouse over the "button"
--xdivsize: (int) These control the positioning of the buttons. The actual coordinates for the buttons are dependant on the current screen resolution
--ydivsize: (int) (i.e. the horizontal coordinates can be determined by dividing the screen width by xdivsize)
--xadd: (int) These control the size of the buttons. If they are set to 10, for example, the result will be a box 10 pixels wide and long.
--yadd: (int)
--mode: (int) 1: Controls will be arranged horizontally (num will be applied to the x axis) 2: Vertical arrangement
--
--returns: (boolean) True when this button has received a left click
mh_section = function(name, num, hidden, xdivsize, ydivsize, xadd, yadd, mode)
--MENU COLOR
local xmargin = gr.getScreenWidth()/xdivsize
local ymargin = gr.getScreenHeight()/ydivsize
--Get corner coordinates for this box
--if (mode == 1) then
local x1 = xmargin*num
local y1 = ymargin
--elseif (mode == 2) then --Why does this not work?
-- local x1 = xmargin
-- local y1 = ymargin*num
--end
local x2 = x1+xadd
local y2 = y1+yadd
--When the mouse is OVER this section...
if io.getMouseX() > x1 and io.getMouseX() < x2 and io.getMouseY() > y1 and io.getMouseY() < y2 then
if hidden == false then
--Draw the inside box
gr.setColor(0, 255, 0)
gr.drawRectangle(x1+5, y1+5, x2-5, y2-5, false, false)
--Draw the little target lines now
local x = x1+(x2-x1)/2
local y = y1-20
--Top target line
--gr.drawLine(x, y, x, y+15)
--Bottom target line
--y = y2+10
--gr.drawLine(x, y, x, y+15)
--Left target line
--x = x1-20
--y = y1+17
--gr.drawLine(x, y, x+15, y)
--Right target line
--x = x2+5
--gr.drawLine(x, y, x+15, y)
end
--Handle the button click
if io.isMouseButtonDown(MOUSE_LEFT_BUTTON) then
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, (y2-((y2-y1)/2))-4 )
gr.drawRectangle(x1, y1, x2, y2, false, false)
return true
end
end
--Draw the outline
gr.setColor(255, 255, 255)
gr.drawRectangle(x1, y1, x2, y2, false, false)
if hidden == false then
--Draw the name
gr.drawString(name, x1 + ( (x2-x1) - gr.getStringWidth(name) ) / 2, (y2-((y2-y1)/2))-4 )
end
return false
end
mainhall_onStart:
logolist = {"43_logo","1610_logo"} --This is a list of logos. Basically the same Logo, only adapted for 4:3 aspect ratio displays and 16:10 ones
shiplist = {"EA Thunderbolt","EA Aurora","EA Badger","EA Tiger","PSI Command Ship","EA Hyperion","EA Omega","EA Warlock","EA Omega-X","Babylon 5 (S1)","MF Sharlin","NR G'Quan","CR Primus"} --Put your ship classes in quotes here
missionlist = {"Mainhall.fs2"} --List of missions to be used
backgroundlist43 = {"43_mainhall", "43_B5", "43_Omega"} --List of 4:3 backgrounds.
backgroundlist1610 = {"1610_mainhall", "1610_ea_warlock", "1610_warlock_b5"} --List of 16:10 backgrounds
splashscreen = "2_PreLoad" --Splashscreen displayed while the mission loads
usemission = false --If false, the single- and multiplayer UI will use the same layout. If true, one of the missions defined in the missionlist will play in the background of the single player UI
rotConst = 7 --Modify this to make the ship turn faster to slower
logoXFactor = 1 --Scaling Factor for the Logo. 1 means the Logo will fill the entire screen width.
screenWidth = gr.getScreenWidth()
screenHeight = gr.getScreenHeight()
aspectRatio = screenWidth/screenHeight
if aspectRatio == 1.6 then
logo = logolist[2]
bg_num = table.getn(backgroundlist1610)
background = backgroundlist1610[math.random(1, bg_num)]
logoYFactor = 0.06 -- This is similar to logoXFactor. Since the 16:10 logo in this example has the same height as the 4:3 one, I need to set this factor according to the aspect ratio as well
else
logo = logolist[1]
bg_num = table.getn(backgroundlist43)
background = backgroundlist43[math.random(1, bg_num)]
logoYFactor = 0.08
end
renderX1 = 0 --
renderX2 = screenWidth -- These determine the amount of screen real estate the rotating model will take up.
renderY1 = 0 --
renderY2 = screenHeight --
rendermidX = (renderX1+renderX2)/2
logoX = 0 --
logoY = screenHeight-(screenHeight*logoYFactor) --These control the positioning and size of the logo
logoX2 = screenWidth --
logoY2 = screenHeight --
if ts.isCurrentPlayerMulti()==true or usemission==false then
numChoices = table.getn(shiplist)
randomShip = tb.ShipClasses[shiplist[math.random(1,numChoices)]]
shipName = randomShip.Name
init = 42
end
mainhall_onFrame:
if ts.isCurrentPlayerMulti()==true or usemission==false then
--Draw background image
local tex = gr.loadTexture(background)
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end
if rotate_pct then
rotate_pct = rotate_pct + rotConst*ba.getFrametime()
if rotate_pct > 100 then
rotate_pct = rotate_pct - 100
end
else
rotate_pct = 40
end
randomShip:renderTechModel(renderX1, renderY1, renderX2, renderY2, rotate_pct)
gr.setColor(255,255,255)
gr.drawString(shipName,rendermidX-gr.getStringWidth(shipName)/2,renderY2)
else
if not g_splashScreen then
--Don't need cursor
io.setCursorHidden(true)
--Draw splash image
local tex = gr.loadTexture(splashscreen)
if tex:isValid() then
gr.drawImage(tex, 0, 0, gr.getScreenWidth(), gr.getScreenHeight())
end
--Draw "Loading..."
gr.setColor(255, 255, 255)
gr.CurrentFont = gr.Fonts['font02']
local loadString = "Loading..."
local x = (gr.getScreenWidth()-gr.getStringWidth(loadString))/2
local y = (gr.getScreenHeight()-gr.CurrentFont.Height)/2
gr.drawString(loadString, x, y)
--Done with splash
gr.CurrentFont = gr.Fonts['font01']
g_splashScreen = true
elseif not g_missionLoaded then
if init2 == nil then
missionName = missionlist[math.random(1,table.getn(missionlist))]
init2 = 42
end
mn.loadMission(missionName)
io.setCursorHidden(false)
g_missionLoaded = true
end
end
if g_missionLoaded then
mn.simulateFrame()
mn.renderFrame()
end
if g_missionLoaded or ts.isCurrentPlayerMulti()==true or usemission==false then
if ts.isCurrentPlayerMulti()==true then
if ts.isPXOEnabled()==true then
b1 = mh_section("Multiplayer", 1, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
else
b1 = mh_section("Multiplayer", 1, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
end
else
b1 = mh_section("Ready Room", 1, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
end
b2 = mh_section("Campaign Room", 2, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
b3 = mh_section("Tech Room", 3, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
b4 = mh_section("Barracks", 4, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
b5 = mh_section("Options", 5, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
b6 = mh_section("Exit", 6, false, 8, 256, gr.getScreenWidth()/9, gr.getScreenHeight()/25, 1)
b7 = mh_section("F3", 1, true, 256, 256, 10, 10, 1)
end
gr.drawImage(logo, logoX, logoY, logoX2, logoY2)
--gr.drawRectangle(x1, y1, x2, y2, false, false)
if b1 then
if ts.isCurrentPlayerMulti()==true then
if ts.isPXOEnabled()==true then
event = "GS_EVENT_PXO"
else
event = "GS_EVENT_MULTI_JOIN_GAME"
end
else
event = "GS_EVENT_NEW_CAMPAIGN"
end
elseif b2 then
event = "GS_EVENT_CAMPAIGN_ROOM"
elseif b3 then
event = "GS_EVENT_TECH_MENU"
elseif b4 then
event = "GS_EVENT_BARRACKS_MENU"
elseif b5 then
event = "GS_EVENT_OPTIONS_MENU"
elseif b6 then
event = "GS_EVENT_QUIT_GAME"
elseif b7 then
event = "GS_EVENT_LAB"
else
event = NIL
end
if g_missionloaded and (event == "GS_EVENT_NEW_CAMPAIGN" or event == "GS_EVENT_OPTIONS_MENU") then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
if not (event == NIL) then
ba.postGameEvent(ba.GameEvents[event])
end
mainhall_onEnd:
if g_missionLoaded then
mn.unloadMission()
g_missionLoaded = nil
g_splashScreen = nil
end
Comments?