Skip to content

Commit

Permalink
Keyboard support for language menu.
Browse files Browse the repository at this point in the history
  • Loading branch information
nagolove committed Jul 2, 2020
1 parent d761428 commit 3b0bc67
Show file tree
Hide file tree
Showing 12 changed files with 77 additions and 51 deletions.
6 changes: 3 additions & 3 deletions colorconstants.lua
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ end

if not ... then
local inspect = require "libs.inspect"
print("new()", inspect(new()))
print("new():makeIndexArray()", inspect(new():makeNamesArray()))
--print("new()", inspect(new()))
--print("new():makeIndexArray()", inspect(new():makeNamesArray()))
local c = new()
print(inspect(c["brown"]))
--print(inspect(c["brown"]))
local a = c:makeNamesArray()
print(inspect(a[1]))
print(inspect(c[a[1]]))
Expand Down
2 changes: 1 addition & 1 deletion common.lua
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ end

function storeGooi()
--local g = { components = deepcopy(gooi.components) }
print("gooi.components", inspect(gooi.components))
--print("gooi.components", inspect(gooi.components))
--local g = { components = table.deepcopy(gooi.components) }
local g = { components = gooi.components }
gooi.components = {}
Expand Down
3 changes: 2 additions & 1 deletion conf.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
function love.conf(t)
--t.console = true
t.console = true
t.window.msaa = 4
t.window.fullscreen = false
--t.window.vsync = false
t.window.vsync = true
end
8 changes: 0 additions & 8 deletions generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ local clone = require "libs.lume".clone
local inspect = require "libs.inspect"

local function generate(sig_count, level, gen, cmp)
--print("generate", "sig_count", sig_count, "gen", inspect(gen), "cmp", inspect(cmp), "level", level)
--[[print(string.format("generating signal array for %d signals of %d level.", sig_count, level))]]

local ret = {} -- массив сигналов, который будет сгенерирован и возвращен
--функцией.
--Если поставить меньше 3, то может зависать генерация в бесконечном цикле.
local ratio = 5
-- что делает эта таблица, задает границы цему-то? С какой вероятностью
-- должно выпадать событие? 1/3?
local range = {1, 3}
local null = {} -- обозначает пустой элемент массива, отсутствие сигнала.

-- забиваю пустыми значениями весь массив, по всей длине.
for i = 1, ratio * sig_count do
table.insert(ret, null)
end
Expand Down
6 changes: 3 additions & 3 deletions help.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ local g = love.graphics
function help:init()
self:buildLayout()

print("gooi", inspect(gooi))
print("gooi.setStyle", inspect(gooi.setStyle))
--print("gooi", inspect(gooi))
--print("gooi.setStyle", inspect(gooi.setStyle))

gooi.setStyle({ font = fonts.help.gooi,
showBorder = true,
Expand Down Expand Up @@ -56,7 +56,7 @@ end

function help:enter()
print("help:enter()")
print("help self.gooi", inspect(self.gooi))
--print("help self.gooi", inspect(self.gooi))
restoreGooi(self.gooi)

--print("gooi.components", inspect(gooi.components))
Expand Down
2 changes: 1 addition & 1 deletion hex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ function newHexField(startcx, startcy, map,rad, color)
last.j = j
last.i = i
--table.insert(result, last)
local visible = map[i][j] ~= 0
local visible = map[j][i] ~= 0

if visible then
table.insert(horizon, last)
Expand Down
3 changes: 1 addition & 2 deletions keyconfig.lua
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,8 @@ local function checkDownKeys()
if not pressed then break end -- если хоть одна клавиша в комбинации не нажата, то сбрасываю комбинацию.
end
if pressed and v.action then
-- print("call action on shortcut", inspect(v.combo))
v.action()
end -- может какие дополнительные параметры передавать в функцию action()?
end
end
end
end
Expand Down
33 changes: 28 additions & 5 deletions languageselector.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ function LanguageSelector:new()
return self
end

function LanguageSelector:getLocale()
return self.locale
end

function LanguageSelector:prepareDraw()
local w, h = gr.getDimensions()
local menuItemHeight = self.font:getHeight() + 6
Expand Down Expand Up @@ -61,7 +57,7 @@ function LanguageSelector:prepareDraw()

gr.setCanvas()

self.canvas:newImageData():encode("png", "langlist.png")
--self.canvas:newImageData():encode("png", "langlist.png")
end

function LanguageSelector:draw()
Expand Down Expand Up @@ -100,6 +96,33 @@ end
function LanguageSelector:touchmoved(id, x, y, dx, dy)
end

function LanguageSelector:up()
if self.selected - 1 < 1 then
self.selected = #self.items
else
self.selected = self.selected - 1
end
end

function LanguageSelector:down()
if self.selected + 1 > #self.items then
self.selected = 1
else
self.selected = self.selected + 1
end
end

function LanguageSelector:keypressed(_, key)
if key == "up" or key == "k" then
self:up()
elseif key == "down" or key == "j" then
self:down()
elseif key == "space" or key == "return" then
print("select")
self.locale = self.languages[self.selected].locale
end
end

function LanguageSelector:mousepressed(x, y, btn, istouch)
print("LanguageSelector:mousepressed")
for k, v in pairs(self.items) do
Expand Down
16 changes: 10 additions & 6 deletions main.lua
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
onAndroid = love.system.getOS() == "Android" or false
onAndroid = love.system.getOS() == "Android"
useKeyboard = true
preventiveFirstRun = true
--preventiveFirstRun = false
onAndroid = true
--onAndroid = true

require "common"

Expand Down Expand Up @@ -139,8 +139,8 @@ end
function love.update(dt)
if languageSelector then
languageSelector:update(dt)
if languageSelector:getLocale() then
setupLocale(languageSelector:getLocale())
if languageSelector.locale then
setupLocale(languageSelector.locale)
subInit()
languageSelector = nil
end
Expand Down Expand Up @@ -244,8 +244,12 @@ end

function love.keypressed(_, scancode)
--if onAndroid then return end
keyconfig.checkPressedKeys(scancode)
menu:keypressed(_, scancode)
if languageSelector and languageSelector.keypressed then
languageSelector:keypressed(_, scancode)
else
keyconfig.checkPressedKeys(scancode)
menu:keypressed(_, scancode)
end
end

function love.keyreleased(key, scancode)
Expand Down
4 changes: 2 additions & 2 deletions menu.lua
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,15 @@ function menu:moveUp()
end
end

function menu:keyreleased(key, scancode)
function menu:keyreleased(_, key)
if self.active then
--пересылка обработки в активное состояние
local obj = self.items[self.active_item].obj
if obj.keyreleased then obj:keyreleased(key, scancode) end
end
end

function menu:keypressed(key, scancode)
function menu:keypressed(_, key)
if self.active then
--пересылка обработки в активное состояние
local obj = self.items[self.active_item].obj
Expand Down
38 changes: 21 additions & 17 deletions nback.lua
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,6 @@ local nbackSelf = {
function nback.new()
local self = deepcopy(nbackSelf)
--print("self.statisticRender", inspect(self.statisticRender))
local w, h = gr.getDimensions()
local rad = math.floor(math.min(w, h) / 8)

self.hexField, self.hexMesh = require "hex".newHexField(100, 100,
{
{1, 0, 1, 0, 1},
{0, 1, 1, 1, 0},
{0, 1, 0, 1, 0},
{0, 1, 1, 1, 0},
{1, 0, 1, 0, 1},
},
rad, {1, 0, 1, 1})
--self.hexField, self.hexMesh = require "hex".newHexField(100, 100, 10, 10,
--rad, {1, 0, 1, 1})

return setmetatable(self, nback)
end

Expand Down Expand Up @@ -297,7 +282,26 @@ function nback:init(save_name)
love.audio.setVolume(settings.volume)
self.save_name = save_name
self.timer = Timer()
self.signal = signal.new(self.cell_width, "alphabet")

local w, h = gr.getDimensions()
local rad = math.floor(math.min(w, h) / 8)

self.map = {
{1, 0, 1, 0, 1},
{0, 1, 1, 0, 0},
{0, 1, 0, 1, 0},
{0, 1, 1, 0, 0},
{1, 0, 1, 0, 1},
}
self.startcx, self.startcy = 100, 100
self.hexField, self.hexMesh = require "hex".newHexField(self.startcx,
self.startcy, self.map, rad, {1, 0, 1, 1})
--self.hexField, self.hexMesh = require "hex".newHexField(100, 100, 10, 10,
--rad, {1, 0, 1, 1})

self.signal = signal.new(self.startcx, self.startcy, self.map,
self.cell_width, "alphabet")

self:createSetupMenu()
self:resize(g.getDimensions())
self:initShaders()
Expand Down Expand Up @@ -611,7 +615,7 @@ function nback:draw()
gr.draw(self.hexMesh)

self:drawActiveSignal()
self.processor:update()
--self.processor:update()
--self:drawButtons()
end
else
Expand Down
7 changes: 5 additions & 2 deletions signal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@ signal.__index = signal

-- width - ширина ячейки для фигурки
-- soundPack - имя подкаталога в 'sfx' с набором звуков
function signal.new(width, soundPack)
function signal.new(startcx, startcy, map, width, soundPack)
local self = {
startcx = startcx,
startcy = startcy,
map = map,
width = width,
sounds = {},
canvas = nil,
Expand Down Expand Up @@ -109,7 +112,7 @@ end
-- сигнала диапазон возможных значений номеров сэмпла 1..samplesCount
function signal:play(index)
assert(index <= #self.sounds)
self.sounds[index]:play()
--self.sounds[index]:play()
end

function signal:quad_internal(x, y, w, h)
Expand Down

0 comments on commit 3b0bc67

Please sign in to comment.