Фикс перемещения иконок

This commit is contained in:
Igor Timofeev 2017-09-17 23:41:28 +03:00
parent ab98638515
commit 3df6599347
3 changed files with 63 additions and 40 deletions

View File

@ -5,7 +5,7 @@
about="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/MineOS/About/",
type="Script",
forceDownload=true,
version=3.80,
version=3.81,
},
{
path="/MineOS/Pictures/MoonTouch.pic",
@ -223,7 +223,7 @@
path="/lib/MineOSCore.lua",
url="https://raw.githubusercontent.com/IgorTimofeev/OpenComputers/master/lib/MineOSCore.lua",
type="Library",
version=1.80,
version=1.81,
},
{
path="/lib/advancedLua.lua",

View File

@ -336,8 +336,6 @@ local function createOSWindow()
icon.selected = false
MineOSCore.OSDraw()
elseif eventData[1] == "double_touch" then
icon.onDoubleClick(icon, eventData)
end
end
@ -361,10 +359,6 @@ local function createOSWindow()
end
end
icon.onDoubleClick = function(icon, eventData)
MineOSCore.iconDoubleClick(icon, eventData)
end
icon.onRightClick = function(icon, eventData)
local indexOf = icon:indexOf()

View File

@ -394,6 +394,27 @@ end
-----------------------------------------------------------------------------------------------------------------------------------
local function getCykaIconPosition(iconField)
local y = iconField.yOffset
for i = 1, #iconField.iconsContainer.children do
y = math.max(y, iconField.iconsContainer.children[i].localPosition.y)
end
local x = iconField.xOffset
for i = 1, #iconField.iconsContainer.children do
if iconField.iconsContainer.children[i].localPosition.y == y then
x = math.max(x, iconField.iconsContainer.children[i].localPosition.x)
end
end
x = x + MineOSCore.iconWidth + iconField.spaceBetweenIcons.horizontal
if x + MineOSCore.iconWidth + iconField.spaceBetweenIcons.horizontal > iconField.iconsContainer.width then
x, y = iconField.xOffset, y + MineOSCore.iconHeight + iconField.spaceBetweenIcons.vertical
end
return x, y
end
local function iconFieldUpdateFileList(iconField)
iconField.fileList = fs.sortedList(iconField.workpath, iconField.sortingMethod, MineOSCore.OSSettings.showHiddenFiles)
iconField:update()
@ -403,49 +424,57 @@ local function iconFieldUpdateFileList(iconField)
iconField:loadIconConfig()
end
-- Заполнение дочернего контейнера
iconField.iconsContainer:deleteChildren()
local xPos, yPos, horizontalIconCounter = iconField.xOffset, iconField.yOffset, 1
local configList, notConfigList = {}, {}
for i = iconField.fromFile, iconField.fromFile + iconField.iconCount.total - 1 do
if iconField.fileList[i] then
if not iconField.filenameMatcher or string.unicodeFind(unicode.lower(iconField.fileList[i]), unicode.lower(iconField.filenameMatcher)) then
-- Выставление позиций иконок на основании конфига
local xIcon, yIcon, filename = xPos, yPos, fs.name(iconField.fileList[i])
if iconField.iconConfig[filename] then
xIcon, yIcon = iconField.iconConfig[filename].x, iconField.iconConfig[filename].y
if iconField.iconConfigEnabled and iconField.iconConfig[iconField.fileList[i]] then
table.insert(configList, iconField.fileList[i])
else
xPos, horizontalIconCounter = xPos + MineOSCore.iconWidth + iconField.spaceBetweenIcons.horizontal, horizontalIconCounter + 1
if horizontalIconCounter > iconField.iconCount.horizontal then
xPos, horizontalIconCounter = iconField.xOffset, 1
yPos = yPos + MineOSCore.iconHeight + iconField.spaceBetweenIcons.vertical
end
if iconField.iconConfigEnabled then
iconField.iconConfig[filename] = {
x = xIcon,
y = yIcon
}
end
table.insert(notConfigList, iconField.fileList[i])
end
local icon = iconField.iconsContainer:addChild(
MineOSCore.icon(
xIcon, yIcon,
iconField.workpath .. iconField.fileList[i],
iconField.colors.text,
iconField.colors.selection
)
)
icon.eventHandler = iconEventHandler
icon.launchers = iconField.launchers
icon:analyseExtension()
end
else
break
end
end
-- Заполнение дочернего контейнера
iconField.iconsContainer:deleteChildren()
for i = 1, #configList do
local icon = iconField.iconsContainer:addChild(MineOSCore.icon(
iconField.iconConfig[configList[i]].x,
iconField.iconConfig[configList[i]].y,
iconField.workpath .. configList[i],
iconField.colors.text,
iconField.colors.selection
))
icon.eventHandler = iconEventHandler
icon.launchers = iconField.launchers
icon:analyseExtension()
end
local x, y
if #configList > 0 then
x, y = getCykaIconPosition(iconField, configList)
else
x, y = iconField.xOffset, iconField.yOffset
end
for i = 1, #notConfigList do
local icon = iconField.iconsContainer:addChild(MineOSCore.icon(x, y, iconField.workpath .. notConfigList[i], iconField.colors.text, iconField.colors.selection))
iconField.iconConfig[notConfigList[i]] = {x = x, y = y}
icon.eventHandler = iconEventHandler
icon.launchers = iconField.launchers
icon:analyseExtension()
x = x + MineOSCore.iconWidth + iconField.spaceBetweenIcons.horizontal
if x + MineOSCore.iconWidth + iconField.spaceBetweenIcons.horizontal - 1 > iconField.iconsContainer.width then
x, y = iconField.xOffset, y + MineOSCore.iconHeight + iconField.spaceBetweenIcons.vertical
end
end
if iconField.iconConfigEnabled then
iconField:saveIconConfig()
end