mirror of
https://github.com/IgorTimofeev/MineOS.git
synced 2026-01-07 19:52:40 +01:00
Пографонистей, да и фичи пиздатенькие
This commit is contained in:
parent
bf64f879db
commit
b982010cf2
@ -19,7 +19,7 @@ local sg = image.load("MineOS/Applications/Stargate.app/Resources/Gate.pic")
|
||||
local sgCore = image.load("MineOS/Applications/Stargate.app/Resources/GateCore.pic")
|
||||
local pathToContacts = "MineOS/System/Stargate/Contacts.cfg"
|
||||
local buttons = {}
|
||||
local contacts = {}
|
||||
local contacts = {addresses = {}}
|
||||
local chevrons = {
|
||||
{x = 5, y = 26, isActivated = false},
|
||||
{x = 1, y = 15, isActivated = false},
|
||||
@ -79,7 +79,11 @@ local function drawSG()
|
||||
local toolbarHeight = 31
|
||||
local x, y = math.floor((buffer.screen.width - toolbarWidth) / 2 - sg.width / 2), math.floor(buffer.screen.height / 2 - sg.height / 2)
|
||||
buffer.image(x, y, sg)
|
||||
|
||||
local stargateState = stargate.stargateState()
|
||||
local irisState = stargate.irisState()
|
||||
local remoteAddress = stargate.remoteAddress()
|
||||
|
||||
if stargateState == "Connected" then
|
||||
stateOfChevrons(true)
|
||||
buffer.image(x, y, sgCore)
|
||||
@ -94,7 +98,9 @@ local function drawSG()
|
||||
end
|
||||
|
||||
local lineColor = 0xFFFFFF
|
||||
local pressColor = 0x888888
|
||||
local pressColor = 0x6692FF
|
||||
local buttonDisabledColor = 0xAAAAAA
|
||||
|
||||
local pizdos = math.floor(buffer.screen.height / 2)
|
||||
x, y = x + sg.width + 5, pizdos
|
||||
local width = buffer.screen.width - x - toolbarWidth
|
||||
@ -110,39 +116,31 @@ local function drawSG()
|
||||
x = x + 3
|
||||
local buttonWidth = buffer.screen.width - x - 1
|
||||
centerText(y, lineColor, "Stargate " .. stargate.localAddress()); y = y + 1
|
||||
centerText(y, 0x888888, stargateState == "Connected" and "(подключено к " .. remoteAddress .. ")" or "(не подключено)"); y = y + 1
|
||||
|
||||
|
||||
|
||||
if stargateState == "Connected" then
|
||||
centerText(y, 0x888888, "(подключено к " .. stargate.remoteAddress() .. ")"); y = y + 1
|
||||
end
|
||||
|
||||
y = y + 1
|
||||
buttons.connectButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Прямое подключение"); y = y + 3
|
||||
|
||||
if stargate.remoteAddress() ~= "" then
|
||||
buttons.disconnectButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Отключиться"); y = y + 3
|
||||
end
|
||||
|
||||
local irisState = stargate.irisState()
|
||||
if irisState ~= "Offline" then
|
||||
buttons.closeIrisButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, irisState == "Closed" and "Открыть Iris" or "Закрыть Iris"); y = y + 3
|
||||
end
|
||||
buttons.connectButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Прямое подключение", stargateState == "Connected"); y = y + 3
|
||||
buttons.disconnectButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Отключиться", stargateState ~= "Connected"); y = y + 3
|
||||
buttons.closeIrisButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, irisState == "Closed" and "Открыть Iris" or "Закрыть Iris"); y = y + 3
|
||||
|
||||
y = y + 1
|
||||
centerText(y, lineColor, "Контакты"); y = y + 2
|
||||
local sizeOfContacts = getArraySize(contacts)
|
||||
if sizeOfContacts > 0 then buttons.connectToContactButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Соединиться"); y = y + 3 end
|
||||
local sizeOfContacts = getArraySize(contacts.addresses)
|
||||
buttons.addContactButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Добавить"); y = y + 3
|
||||
if sizeOfContacts > 0 then buttons.removeContactButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Удалить"); y = y + 3 end
|
||||
buttons.connectToContactButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Соединиться", sizeOfContacts <= 0); y = y + 3
|
||||
buttons.removeContactButton = GUI.framedButton(x, y, buttonWidth, 3, lineColor, lineColor, pressColor, pressColor, "Удалить", sizeOfContacts <= 0); y = y + 3
|
||||
|
||||
y = y + 1
|
||||
centerText(y, lineColor, "Энергия"); y = y + 2
|
||||
buffer.text(x, y, 0x000000, string.rep("━", buttonWidth))
|
||||
centerText(y, lineColor, "Затраты на активацию"); y = y + 2
|
||||
buffer.text(x, y, 0x228822, string.rep("━", buttonWidth))
|
||||
|
||||
local hyi = stargate.remoteAddress()
|
||||
if hyi ~= "" then
|
||||
local pidor = stargate.energyToDial(hyi)
|
||||
if remoteAddress ~= "" then
|
||||
local pidor = stargate.energyToDial(remoteAddress)
|
||||
local cyka = stargate.energyAvailable()
|
||||
local blyad = math.ceil(pidor * buttonWidth / cyka)
|
||||
centerText(y, lineColor, tostring(blyad) .. "%")
|
||||
buffer.text(x, y, 0x55FF55, string.rep("━", blyad))
|
||||
end
|
||||
|
||||
@ -157,8 +155,19 @@ local function drawAll(force)
|
||||
end
|
||||
|
||||
local function connectSG(address)
|
||||
local success, reason = stargate.dial(unicode.upper(address))
|
||||
if not success then
|
||||
address = unicode.upper(address)
|
||||
|
||||
if stargate.stargateState() == "Connected" then
|
||||
stateOfChevrons(false)
|
||||
stargate.disconnect()
|
||||
os.sleep(2)
|
||||
end
|
||||
|
||||
local success, reason = stargate.dial(address)
|
||||
if success then
|
||||
contacts.lastAddress = address
|
||||
saveContacts()
|
||||
else
|
||||
GUI.error(reason, {title = {color = 0xFFDB40, text = "Ошибка подключения к Вратам"}, backgroundColor = 0x262626})
|
||||
end
|
||||
end
|
||||
@ -186,11 +195,12 @@ while true do
|
||||
{"EmptyLine"},
|
||||
{"CenterText", ecs.colors.orange, "Прямое подключение"},
|
||||
{"EmptyLine"},
|
||||
{"Input", 0xFFFFFF, ecs.colors.orange, "ZFFBXP8SA"},
|
||||
{"Input", 0xFFFFFF, ecs.colors.orange, contacts.lastAddress or "Введите адрес"},
|
||||
{"EmptyLine"},
|
||||
{"Button", {ecs.colors.orange, 0xffffff, "OK"}, {0x999999, 0xffffff, "Отмена"}}
|
||||
)
|
||||
if data[2] == "OK" then
|
||||
os.sleep(2)
|
||||
connectSG(data[1])
|
||||
end
|
||||
elseif button.text == "Открыть Iris" then
|
||||
@ -202,7 +212,7 @@ while true do
|
||||
{"CenterText", ecs.colors.orange, "Добавить контакт"},
|
||||
{"EmptyLine"},
|
||||
{"Input", 0xFFFFFF, ecs.colors.orange, "Название"},
|
||||
{"Input", 0xFFFFFF, ecs.colors.orange, "Адрес Звездных Врат"},
|
||||
{"Input", 0xFFFFFF, ecs.colors.orange, contacts.lastAddress or "Адрес Звездных Врат"},
|
||||
{"EmptyLine"},
|
||||
remoteAddress ~= "" and
|
||||
{"Button", {ecs.colors.orange, 0xffffff, "OK"}, {0x999999, 0xffffff, "Добавить текущий"}, {0x777777, 0xffffff, "Отмена"}}
|
||||
@ -210,16 +220,16 @@ while true do
|
||||
{"Button", {ecs.colors.orange, 0xffffff, "OK"}, {0x777777, 0xffffff, "Отмена"}}
|
||||
)
|
||||
if data[3] == "OK" then
|
||||
contacts[data[1]] = data[2]
|
||||
contacts.addresses[data[1]] = data[2]
|
||||
saveContacts()
|
||||
elseif data[3] == "Добавить текущий" then
|
||||
contacts[data[1]] = remoteAddress
|
||||
contacts.addresses[data[1]] = remoteAddress
|
||||
saveContacts()
|
||||
end
|
||||
drawAll()
|
||||
elseif button.text == "Соединиться" or button.text == "Удалить" then
|
||||
local isConnect = (button.text == "Соединиться")
|
||||
local names = {}; for name in pairs(contacts) do table.insert(names, name) end
|
||||
local names = {}; for name in pairs(contacts.addresses) do table.insert(names, name) end
|
||||
local data = ecs.universalWindow("auto", "auto", 36, 0x262626, true,
|
||||
{"EmptyLine"},
|
||||
{"CenterText", ecs.colors.orange, isConnect and "Соединиться" or "Удалить контакт"},
|
||||
@ -230,10 +240,10 @@ while true do
|
||||
)
|
||||
if data[2] == "OK" then
|
||||
if isConnect then
|
||||
connectSG(contacts[data[1]])
|
||||
connectSG(contacts.addresses[data[1]])
|
||||
else
|
||||
for name in pairs(contacts) do
|
||||
if name == data[1] then contacts[name] = nil; break end
|
||||
for name in pairs(contacts.addresses) do
|
||||
if name == data[1] then contacts.addresses[name] = nil; break end
|
||||
end
|
||||
saveContacts()
|
||||
end
|
||||
|
||||
42
lib/GUI.lua
42
lib/GUI.lua
@ -18,12 +18,20 @@ GUI.buttonTypes = {
|
||||
framedAdaptive = 3,
|
||||
}
|
||||
|
||||
GUI.colors = {
|
||||
disabled = 0x888888,
|
||||
}
|
||||
|
||||
-- Универсальный метод для проверки клика на прямоугольный объект
|
||||
local function clickedAtObject(object, x, y)
|
||||
if x >= object.x and y >= object.y and x <= object.x + object.width - 1 and y <= object.y + object.height - 1 then return true end
|
||||
local function objectClicked(object, x, y)
|
||||
if x >= object.x and y >= object.y and x <= object.x + object.width - 1 and y <= object.y + object.height - 1 and not object.disabled then return true end
|
||||
return false
|
||||
end
|
||||
|
||||
local function objectSetDisabled(object, state)
|
||||
object.disabled = state
|
||||
end
|
||||
|
||||
--Создание базового примитива-объекта
|
||||
function GUI.object(x, y, width, height)
|
||||
return {
|
||||
@ -31,7 +39,7 @@ function GUI.object(x, y, width, height)
|
||||
y = y,
|
||||
width = width,
|
||||
height = height,
|
||||
isClicked = clickedAtObject,
|
||||
isClicked = objectClicked,
|
||||
}
|
||||
end
|
||||
|
||||
@ -44,8 +52,8 @@ local function drawButton(buttonObject, isPressed)
|
||||
|
||||
local xText = math.floor(buttonObject.x + buttonObject.width / 2 - textLength / 2)
|
||||
local yText = math.floor(buttonObject.y + buttonObject.height / 2)
|
||||
local buttonColor = isPressed and buttonObject.colors.pressed.button or buttonObject.colors.default.button
|
||||
local textColor = isPressed and buttonObject.colors.pressed.text or buttonObject.colors.default.text
|
||||
local buttonColor = buttonObject.disabled and buttonObject.colors.disabled.button or (isPressed and buttonObject.colors.pressed.button or buttonObject.colors.default.button)
|
||||
local textColor = buttonObject.disabled and buttonObject.colors.disabled.text or (isPressed and buttonObject.colors.pressed.text or buttonObject.colors.default.text)
|
||||
|
||||
if buttonObject.type == GUI.buttonTypes.default or buttonObject.type == GUI.buttonTypes.adaptive then
|
||||
buffer.square(buttonObject.x, buttonObject.y, buttonObject.width, buttonObject.height, buttonColor, textColor, " ")
|
||||
@ -66,7 +74,7 @@ local function pressButton(buttonObject, pressTime)
|
||||
end
|
||||
|
||||
-- Создание таблицы кнопки со всеми необходимыми параметрами
|
||||
local function createButtonObject(buttonType, x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
local function createButtonObject(buttonType, x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
local buttonObject = GUI.object(x, y, width, height)
|
||||
buttonObject.colors = {
|
||||
default = {
|
||||
@ -77,7 +85,13 @@ local function createButtonObject(buttonType, x, y, width, height, buttonColor,
|
||||
button = buttonPressedColor,
|
||||
text = textPressedColor
|
||||
},
|
||||
disabled = {
|
||||
button = GUI.colors.disabled,
|
||||
text = GUI.colors.disabled,
|
||||
}
|
||||
}
|
||||
buttonObject.disabled = disabledState
|
||||
buttonObject.setDisabled = objectSetDisabled
|
||||
buttonObject.type = buttonType
|
||||
buttonObject.text = text
|
||||
buttonObject.press = pressButton
|
||||
@ -86,29 +100,29 @@ local function createButtonObject(buttonType, x, y, width, height, buttonColor,
|
||||
end
|
||||
|
||||
-- Кнопка фиксированных размеров
|
||||
function GUI.button(x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.default, x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
function GUI.button(x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.default, x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
buttonObject:draw()
|
||||
return buttonObject
|
||||
end
|
||||
|
||||
-- Кнопка, подстраивающаяся под размер текста
|
||||
function GUI.adaptiveButton(x, y, xOffset, yOffset, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.adaptive, x, y, xOffset * 2 + unicode.len(text), yOffset * 2 + 1, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
function GUI.adaptiveButton(x, y, xOffset, yOffset, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.adaptive, x, y, xOffset * 2 + unicode.len(text), yOffset * 2 + 1, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
buttonObject:draw()
|
||||
return buttonObject
|
||||
end
|
||||
|
||||
-- Кнопка в рамке
|
||||
function GUI.framedButton(x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.framedDefault, x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
function GUI.framedButton(x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.framedDefault, x, y, width, height, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
buttonObject:draw()
|
||||
return buttonObject
|
||||
end
|
||||
|
||||
-- Кнопка в рамке, подстраивающаяся под размер текста
|
||||
function GUI.adaptiveFramedButton(x, y, xOffset, yOffset, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.framedAdaptive, x, y, xOffset * 2 + unicode.len(text), yOffset * 2 + 1, buttonColor, textColor, buttonPressedColor, textPressedColor, text)
|
||||
function GUI.adaptiveFramedButton(x, y, xOffset, yOffset, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
local buttonObject = createButtonObject(GUI.buttonTypes.framedAdaptive, x, y, xOffset * 2 + unicode.len(text), yOffset * 2 + 1, buttonColor, textColor, buttonPressedColor, textPressedColor, text, disabledState)
|
||||
buttonObject:draw()
|
||||
return buttonObject
|
||||
end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user