-- simInput.lua

local roboto2 = loadFont(getXPlanePath().."Resources/fonts/Roboto-Bold.ttf")
local noto2 = loadFont(getXPlanePath().."Resources/fonts/NotoSansCJK-SC-Regular.otf")

-- setting mouse action  ------------------------------------------------
function onMouseDown(component , x , y , button , parentX , parentY)
	if button == MB_LEFT then
		if x > 5 and x <= 92 then
			if y > 2 and y < 30 then
				if get(simStage) == 0 then        -- "Liftoff" pressed
					set(startIsOn, 1)
					set(resetIsOn, 0)
					sasl.commandOnce( viewSet )
					print("Liftoff pressed") 
				elseif get(simStage)==1 then -- "Reset" pressed
					set(simStage, 0)
					set(startIsOn, 0)
					set(resetIsOn, 1)
					sasl.commandOnce( viewSet )
					sasl.stopTimer( animTime )
					set(mapIsOn, 1)
					print("Reset pressed")
				end
			end
		end
		
		if x > 200 and x <= 300 then
			if y > 5 and y < 15 then
				if get(simStage) == 0 then            -- Input area clicked
					set(isKeyReady, 1 - get(isKeyReady))
				end
				if get(isKeyReady) == 1 then
					set(portId, "" )
				end
			end
		end
	end
    return true
end

function onKeyDown( component , char , key , shDown , ctrlDown , altOptDown )
	if get(isKeyReady) == 1 then
		if char == SASL_KEY_RETURN then
			set(isKeyReady, 0)                   -- Fix portId and start mapping
		else
			newChr = string.char ( char )
			set(portId, get(portId)..string.upper( newChr ) )
		end
	end
	return true
end