--[[ Some common APK_S2D actions for interacting with the Scaleform Studio plugin. More custom actions should be implemented as needed or within custom level code. ]]-- require 'core/appkit/lua/class' require 'core/appkit/lua/util' Appkit.Scaleform = Appkit.Scaleform or {} local APK_S2D = Appkit.Scaleform function APK_S2D.send_mouse_input() local cursor = stingray.Mouse.axis(stingray.Mouse.axis_id("cursor"), stingray.Mouse.RAW, 3) local wheel = stingray.Mouse.axis(stingray.Mouse.axis_id("wheel"), stingray.Mouse.RAW, 3) scaleform.Stingray.send_message("mouse_move" , cursor.x, cursor.y) scaleform.Stingray.send_message("mouse_wheel", cursor.x, cursor.y, wheel.y) if(stingray.Mouse.pressed(stingray.Mouse.button_id("left"))) then scaleform.Stingray.send_message("mouse_down", cursor.x, cursor.y, 0) elseif(stingray.Mouse.released(stingray.Mouse.button_id("left"))) then scaleform.Stingray.send_message("mouse_up", cursor.x, cursor.y, 0) end if(stingray.Mouse.pressed(stingray.Mouse.button_id("right"))) then scaleform.Stingray.send_message("mouse_down", cursor.x, cursor.y, 1) elseif(stingray.Mouse.released(stingray.Mouse.button_id("right"))) then scaleform.Stingray.send_message("mouse_up", cursor.x, cursor.y, 1) end if(stingray.Mouse.pressed(stingray.Mouse.button_id("middle"))) then scaleform.Stingray.send_message("mouse_down", cursor.x, cursor.y, 2) elseif(stingray.Mouse.released(stingray.Mouse.button_id("middle"))) then scaleform.Stingray.send_message("mouse_up", cursor.x, cursor.y, 2) end end local touch_down = false function APK_S2D.send_touch_input() --Turn touch into left mouse messages for scaleform.Stingray --Todo: Short term work around. local touch = Appkit.Util.touch_interface() -- Handle new touches local contacts = {touch.contacts()} for _,id in ipairs(contacts) do local pos = Appkit.Util.location(touch, id) scaleform.Stingray.send_message("mouse_move" ,pos.x, pos.y, id) if(touch.is_touch_down(id)) then scaleform.Stingray.send_message("mouse_down", pos.x,pos.y, 0, id) end if(touch.is_touch_up(id)) then scaleform.Stingray.send_message("mouse_up", pos.x, pos.y, 0, id) end end --local tap_location = touch.gesture_tap(); -- if tap_location then -- scaleform.Stingray.send_message("mouse_down", tap_location.x, tap_location.y, 0, 0) -- scaleform.Stingray.send_message("mouse_up", tap_location.x, tap_location.y, 0, 0) -- end -- local touch = Appkit.Util.touch_interface() -- -- Handle new touches -- local contacts = {touch.contacts()} -- for _,id in ipairs(contacts) do -- local pos = Appkit.Util.location(touch, id) -- if touch.is_touch_down(id) and touch_down == false then -- touch_down = true -- scaleform.Stingray.send_message("touch_begin", id, pos.x, pos.y, 1, 1, .5) -- end -- if touch.is_touch_down(id) then -- scaleform.Stingray.send_message("touch_tap", id, pos.x, pos.y, 1, 1, .5) -- end -- if touch.is_touch_up(id) then1 -- scaleform.Stingray.send_message("touch_end", id, pos.x, pos.y, 1, 1, .5) -- end -- end end function APK_S2D.send_keyboard_input() --Check if a key has been pressed or released and forward to Scaleform Studio local last_button_id = stingray.Keyboard.num_buttons() - 1 for i = 0,last_button_id do if stingray.Keyboard.button_name(i) ~= "" then if stingray.Keyboard.pressed(i) then scaleform.Stingray.send_message("key_down", i, 0) elseif stingray.Keyboard.released(i) then scaleform.Stingray.send_message("key_up", i, 0) end end end strokes = stingray.Keyboard.keystrokes() for k,v in pairs(strokes) do if(type(v) == "string") then scaleform.Stingray.send_message("char_message", v) end end end return APK_S2D