#Conditional Hooks
$Application: FS2_Open

$On Game Init:
[

BranchScreen = {}

function BranchScreen:Load(message, leftbitmap, rightbitmap)

	ba.print("Branching mission script running!\n")

	self.Enabled = true

	AXUI.InGame = false
	AXUI:ScreenInit()
	AXUI:SetFocus(0)
	
	if gr.getImageWidth("2_LoopBriefX") > 0 then
		self.BG = "2_LoopBriefX"
	end
	
	self.FullScreen = {}
	self.FullScreen.w = gr.getScreenWidth()
	self.FullScreen.h = gr.getScreenHeight()
		
	--Bitmaps should be 330x200
	self.LeftButton = AXUI:CreateButton(nil, 41, 484, 0, 0, nil, nil, nil, leftbitmap, 0, 0, leftbitmap .. "_h", leftbitmap .. "_c", true, 0, 1)
	self.RightButton = AXUI:CreateButton(nil, 416, 484, 0, 0, nil, nil, nil, rightbitmap, 0, 0, rightbitmap .. "_h", rightbitmap .. "_c", true, 0, 1)
		
	if mn.Messages[message]:isValid() then
		self.Text = mn.Messages[message].Message
		self.TextBox = AXUI:CreateTextBox(self.Text, 50, 190, 930, 195, "grey", true, 3)
	end
	
	if mn.SEXPVariables["choice"]:isValid() then
		self.Choice = mn.SEXPVariables["choice"]
	end

end

function BranchScreen:Draw()
	
	gr.setColor(0,0,0,255)
	gr.drawRectangle(0,0,self.FullScreen.w, self.FullScreen.h)
	
	if self.BG then
		gr.drawImage(self.BG,AXUI.Screen.x,AXUI.Screen.y,AXUI.Screen.x + AXUI.Screen.w,AXUI.Screen.y + AXUI.Screen.h)
	end
	
	if self.LeftButton then
		self.LeftButton:Draw()
	end
	
	if self.RightButton then
		self.RightButton:Draw()
	end
	
	if self.TextBox then
		self.TextBox:Draw()
	end

end

function BranchScreen:MonitorActions()

	if self.Choice then
		if self.LeftButton:Clicked() then
			self.Choice.Value = 1
		elseif self.RightButton:Clicked() then
			self.Choice.Value = 2
		end
	end

end

function BranchScreen:Exit()

	self.Enabled = nil
	self.LeftButton = nil
	self.RightButton = nil
	self.Text = nil
	self.TextBox = nil
	self.Choice = nil
	self.FullScreen = nil

end

]

$State: GS_STATE_GAME_PLAY
$On State End:
[
	if BranchScreen.Enabled then
		BranchScreen:Exit()
	end
]

$State: GS_STATE_GAME_PLAY
$On Frame:
[
	if BranchScreen.Enabled then
		io.setCursorHidden(false)
		BranchScreen:Draw()
	end
]

$State: GS_STATE_GAME_PLAY
$On Mouse Released:
[
	if BranchScreen.Enabled then
		BranchScreen:MonitorActions()
	end
]

#End