Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 44 additions & 43 deletions drive/carts/settings.p8
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,47 @@ local scroll_offset = 0
local wifi_status = {ssid="", state="unknown"}
local airplane_mode = false

-- virtual keyboard
local keyboard_up_y = 78
local keyboard_down_y = 148
local keyboard = Keyboard:new(7, 0, 8, 14, keyboard_down_y, function(text)
show_keyboard = false
make_vkeyboard_tween(false)

-- no-op if empty string
if text == "" then return end

-- currently only used for connecting to networks
local ssid = wifi_menu:cur().ssid
local psk = text
serial_debug('connect to wifi request, ssid: '..ssid..', psk: '..psk)
request_loadable('wifi_connect', {ssid, psk})
end)

-- tweens for keyboard
vkeyboard_tween = {}
function make_vkeyboard_tween(show_keyboard)
local vkeyboard_target_y = 0
if show_keyboard then
vkeyboard_target_y = keyboard_up_y
else
vkeyboard_target_y = keyboard_down_y
end
vkeyboard_tween=tween_machine:add_tween({
func=outQuart,
v_start=keyboard.y,
v_end=vkeyboard_target_y,
duration=0.5
})
vkeyboard_tween:register_step_callback(function(pos)
keyboard.y = pos
end)
vkeyboard_tween:register_finished_callback(function(tween)
tween:remove()
end)
vkeyboard_tween:restart()
end

function _init()
-- TODO fetch the platform to do platform specific settings pages
-- info is pretty important to get, so retry a couple times
Expand Down Expand Up @@ -136,7 +177,6 @@ function _init()
init_title_bar(14, 2)
end


function new_wifi_menu(networks)
wifi_menu_items = {
{label="[scan]", func=function()request_loadable('wifi_list')end},
Expand All @@ -147,7 +187,10 @@ function new_wifi_menu(networks)

for i, network in ipairs(networks) do
add(wifi_menu_items, {ssid=network.ssid, name=network.name, strength=network.strength, func=function()
-- each time we show the keyboard, we can decide whether or not
-- the text field is to be redacted
show_keyboard=true
keyboard.redact_textfield = true
make_vkeyboard_tween(true)
end})
end
Expand Down Expand Up @@ -189,48 +232,6 @@ local joycon_controls = {
local control_names = {"up", "down", "left", "right", "a", "b"}
local current_control = 1

-- virtual keyboard
local keyboard_up_y = 78
local keyboard_down_y = 148
local keyboard = Keyboard:new(7, 0, 8, 14, keyboard_down_y, function(text)
show_keyboard = false
make_vkeyboard_tween(false)

-- no-op if empty string
if text == "" then return end

-- currently only used for connecting to networks
local ssid = wifi_menu:cur().ssid
local psk = text
serial_debug('connect to wifi request, ssid: '..ssid..', psk: '..psk)
request_loadable('wifi_connect', {ssid, psk})
end)

-- tweens for keyboard
vkeyboard_tween = {}
function make_vkeyboard_tween(show_keyboard)
local vkeyboard_target_y = 0
if show_keyboard then
vkeyboard_target_y = keyboard_up_y
else
vkeyboard_target_y = keyboard_down_y
end
vkeyboard_tween=tween_machine:add_tween({
func=outQuart,
v_start=keyboard.y,
v_end=vkeyboard_target_y,
duration=0.5
})
vkeyboard_tween:register_step_callback(function(pos)
keyboard.y = pos
end)
vkeyboard_tween:register_finished_callback(function(tween)
tween:remove()
end)
vkeyboard_tween:restart()
end


function _update60()
update_loadables()
if show_keyboard then
Expand Down
32 changes: 9 additions & 23 deletions drive/carts/vkeyboard.p8
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ Keyboard.__index = Keyboard
local WIDTH=100
local HEIGHT=50

function rep(c, n)
local s = ""
for i=1,n do
s = s..c
end
return s
end

function Keyboard:new(key_color, border_color, selected_color, x, y, confirm_fn)

local obj = {
Expand Down Expand Up @@ -185,7 +193,7 @@ function Keyboard:draw()
rectfill(textfield_x0, textfield_y0, textfield_x1, textfield_y1, self.textfield_color)
rect(textfield_x0, textfield_y0, textfield_x1, textfield_y1, self.textfield_border_color)
if self.redact_textfield then
-- print(string.rep("*", #self.text), textfield_x0 + 2, textfield_y0 + 2, self.border_color)
print(rep("*", #self.text), textfield_x0 + 2, textfield_y0 + 2, self.border_color)
else
print(self.text, textfield_x0 + 2, textfield_y0 + 2, self.border_color)
end
Expand Down Expand Up @@ -300,25 +308,3 @@ function Keyboard:input()
end
end
end

--local keyboard = Keyboard:new(7, 0, 8, (128-100)/2, 78, 100, 50)
--function _update()
--keyboard:input()
--end

--function _draw()
--cls()
--keyboard:draw()
--print(keyboard.text, 60,90,8)
--end

----TODO can't use gfx since we are using vkeyboard as a library
--__gfx__
--00000000777777770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000777777770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000777007770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000770000770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000700000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000700000070000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000777007770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
--00000000777007770000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
Loading