#Conditional Hooks
$Application: FS2_Open
$On Game Init:
[

MarkBox = {}

function MarkBox:Init()

	self.Enabled = false
	self.List = {}

end

function MarkBox:AddSubsys(ship, text, ...)

	if ship and mn.Ships[ship]:isValid() and (#arg > 0) then
	
		if not self.Enabled then self.Enabled = true end

		local thisShip = mn.Ships[ship]
		
		for i,subsys in ipairs(arg) do
			if thisShip[subsys]:isValid() then
				local t = {}
		
				t.Sig = thisShip:getSignature()
				t.Text = text
				t.Type = 1
				t.Target = subsys

				self.List[#self.List+1] = t

			end
		end
	end
		
end

function MarkBox:ClearList()

	MarkBox:Init()

end

function MarkBox:Draw()

	if #self.List > 0 then

		local player = hv.Player
		
		if player.Target and player.Target:isValid() then
		
			for i=1, #self.List do
		
			local thisEntry = self.List[i]
			
			if thisEntry and player.Target:getSignature() == thisEntry.Sig then
				if thisEntry.Type == 1 then
				
					local targetSS = mn.getObjectFromSignature(thisEntry.Sig)[thisEntry.Target]
					
					if targetSS:isValid() and targetSS.HitpointsLeft > 0 then
					
					
						--[[gr.setColor(200, 200, 200 , 200)
						gr.CurrentFont = gr.Fonts[1]
						gr.drawString("Target Data:",100*i,100)
						gr.drawString("Ship: " .. player.Target.Name)
						gr.drawString("Actual: " .. player.TargetSubsystem:getModelName())
						gr.drawString("Entry: " .. thisEntry.Target)]]--
						
						local focus
						
						if thisEntry.Target == player.TargetSubsystem:getModelName() then
							local r,g,b = player.Target.Team:getColor()
							gr.setColor(r,g,b,192)
							focus = true
						else
							gr.setColor(200, 200, 200 , 200)
						end
				
						local x1,y1,x2,y2 = gr.drawSubsystemTargetingBrackets(targetSS, false)
						
						if x1 and y1 and x2 and y2 then
							
								local oldsize = math.max(x2-x1,y2-y1)
								local newsize = oldsize * 0.5
								local hsize = newsize/8
								
								if focus then hsize = newsize/4 end
								
								local lineLength = math.max(hsize/5,3)
							
								local midX = (x1+x2) / 2
								local midY = (y1+y2) / 2
								
								local nx1 = midX - hsize
								local nx2 = midX + hsize
								local ny1 = midY - hsize
								local ny2 = midY + hsize
								
								gr.setLineWidth(2)
								
								gr.drawLine(nx1+1, ny1+1, nx1+lineLength, ny1)
								gr.drawLine(nx1+1, ny1+1, nx1, ny1+lineLength)
								
								gr.drawLine(nx1+1, ny2-1, nx1+lineLength, ny2)
								gr.drawLine(nx1+1, ny2-1, nx1, ny2-lineLength)

								gr.drawLine(nx2-1, ny1+1, nx2-lineLength, ny1)
								gr.drawLine(nx2-1, ny1+1, nx2, ny1+lineLength)
								
								gr.drawLine(nx2-1, ny2-1, nx2-lineLength, ny2)
								gr.drawLine(nx2-1, ny2-1, nx2, ny2-lineLength)

								gr.CurrentFont = gr.Fonts[3]
								
								local hpPct = targetSS.HitpointsLeft / targetSS.HitpointsMax
								local hpWidth = 100

								if focus then
									gr.drawLine(x1, y1, nx1, ny1)
									gr.drawLine(x1, y2, nx1, ny2)
									
									gr.drawLine(x2, y1, nx2, ny1)
									gr.drawLine(x2, y2, nx2, ny2)
									
									--gr.drawString(thisEntry.Text,x2+5,y2-20)
									--gr.drawRectangle(x2+5,y2-5,x2+5+(hpWidth*hpPct), y2+0)
								else
									
								end
								
								gr.drawString(thisEntry.Text,nx2+5,ny2-20)
								gr.drawRectangle(nx2+5,ny2-5,nx2+5+(hpWidth*hpPct), ny2+0)
								gr.setLineWidth(1)

						end
						
						if not x1 then gr.drawSubsystemTargetingBrackets(targetSS) end
						
					else
						table.remove(self.List,i)
					end
				end
			end
		
		end
			
		end
	
	end
	
end

]

$State: GS_STATE_GAME_PLAY
$On Gameplay Start:
[
	MarkBox:Init()
]

$On State End:
[
	MarkBox.Enabled = false
]

$On Frame:
[
	if MarkBox.Enabled and hu.HUDDrawn and not hu.HUDDisabledExceptMessages and (gr.hasViewmode(VM_INTERNAL) or gr.hasViewmode(VM_CHASE)) then
		if mn.getMissionTime() > 1 then
			MarkBox:Draw()
		end
	end
]

#End