Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --------------------------------------------------------------------------------
- -- shop_final.lua
- -- Итоговый интерфейс:
- -- 1) Левая панель "Действия": только кнопки «Внести деньги», «Внести железо».
- -- 2) Ниже (в той же левой рамке) — "Забрать" c двумя кнопками "Забрать деньги"
- -- / "Забрать железо" и двумя полями ввода числовых значений.
- -- 3) Справа: сверху список товаров, под списком — панель "Покупка", под ней —
- -- поле "Поиск:".
- -- 4) При клике на товар строка подсвечивается (highlight).
- -- 5) Исправлен поиск и прокрутка, добавлено больше товаров.
- --------------------------------------------------------------------------------
- local component = require("component")
- local event = require("event")
- local term = require("term")
- local unicode = require("unicode")
- local gpu = component.gpu
- --------------------------------------------------------------------------------
- -- 1) Проверка PIM
- --------------------------------------------------------------------------------
- if not component.isAvailable("pim") then
- error("Ошибка: PIM не найден! Подключите PIM к компьютеру.")
- end
- local pim = component.pim
- --------------------------------------------------------------------------------
- -- ПАРАМЕТРЫ ЭКРАНА / ЦВЕТА
- --------------------------------------------------------------------------------
- local screenWidth, screenHeight = gpu.maxResolution()
- gpu.setResolution(screenWidth, screenHeight)
- local colors = {
- background = 0x000000,
- text = 0xFFFFFF,
- frame = 0xAAAAAA,
- titleBar = 0x002244,
- inputField = 0x333333, -- поля ввода
- button = 0x444444,
- buttonText = 0xFFFFFF,
- buttonInactive = 0x555555,
- warn = 0xFF0000,
- success = 0x00FF00,
- highlight = 0x4444FF, -- подсветка выбранной строки
- }
- local headerHeight = 3
- local footerHeight = 3
- --------------------------------------------------------------------------------
- -- 2) "БД" игроков: name -> { balanceEmerald, balanceIron }
- --------------------------------------------------------------------------------
- local userData = {}
- local function getUserData(name)
- if not userData[name] then
- userData[name] = { balanceEmerald=0, balanceIron=0 }
- end
- return userData[name]
- end
- --------------------------------------------------------------------------------
- -- 3) Текущий авторизованный игрок
- --------------------------------------------------------------------------------
- local currentPlayerName = nil
- local playerOnPIM = false
- --------------------------------------------------------------------------------
- -- 4) Список товаров (много)
- --------------------------------------------------------------------------------
- local allItems = {
- { name="minecraft:stone", display="Камень", quantity=50, priceEmerald=2, priceIron=1 },
- { name="minecraft:diamond", display="Алмаз", quantity=5, priceEmerald=50, priceIron=10},
- { name="minecraft:dirt", display="Земля", quantity=20, priceEmerald=1, priceIron=1 },
- { name="minecraft:iron_ingot", display="Железо", quantity=30, priceEmerald=5, priceIron=2 },
- }
- -- Добавим побольше
- for i=1,60 do
- table.insert(allItems, {
- name = "minecraft:extra"..i,
- display = "ТоварExtra"..i,
- quantity = math.random(1,99),
- priceEmerald= math.random(1,50),
- priceIron = math.random(0,20),
- })
- end
- --------------------------------------------------------------------------------
- -- Данные для интерфейса
- --------------------------------------------------------------------------------
- local filteredItems = {} -- после поиска
- local scrollOffset = 0 -- для прокрутки
- local searchText = "" -- поле поиска
- local searchFocus = false -- есть ли фокус?
- local searchCursorVisible= true
- local lastCursorBlink= 0
- local cursorBlinkInterval= 0.5
- -- Buy panel
- local buySelectedIndex= nil -- какой товар выбран (idx в filteredItems)
- local buyQuantity = ""
- local payWithEmerald = true
- local buyMessage = ""
- -- ПОЛЯ ввода "Забрать деньги" / "Забрать железо" (в левой панели)
- local withdrawMoneyInput = "" -- только цифры
- local withdrawIronInput = ""
- --------------------------------------------------------------------------------
- -- РАЗМЕТКА
- --------------------------------------------------------------------------------
- local actionsX, actionsY = 2, headerHeight+1
- local actionsW = 22
- local actionsH = screenHeight- headerHeight- footerHeight -1
- local itemsX= actionsX+ actionsW+1
- local itemsY= headerHeight+1
- local itemsW= screenWidth- (actionsW+3)
- local itemsH= screenHeight- headerHeight- footerHeight -1
- -- Высота "Buy panel" пусть будет 4 строк.
- local buyPanelHeight= 4
- -- Высота "поиск" пусть 2 строки
- local searchBarHeight= 2
- -- Итого на список остаётся (itemsH - buyPanelHeight - searchBarHeight).
- -- Колонки
- local colNameW, colQtyW, colEmerW, colIronW= 0,0,0,0
- --------------------------------------------------------------------------------
- -- 5) ВСПОМОГАТЕЛЬНЫЕ ФУНКЦИИ (шапка/подвал)
- --------------------------------------------------------------------------------
- local function clearScreen()
- gpu.setBackground(colors.background)
- gpu.setForeground(colors.text)
- term.clear()
- end
- local function drawHeader()
- gpu.setBackground(colors.titleBar)
- gpu.setForeground(colors.text)
- for y=1, headerHeight do
- gpu.fill(1, y, screenWidth, 1, " ")
- end
- local title= "[ PIM SHOP ]"
- local tx= math.floor((screenWidth- unicode.len(title))/2)
- gpu.set(tx,2, title)
- if playerOnPIM and currentPlayerName then
- local ud= getUserData(currentPlayerName)
- local info= string.format("Игрок: %s | Баланс: %d Эм / %d Жел",
- currentPlayerName, ud.balanceEmerald, ud.balanceIron)
- gpu.set(2,2, info)
- else
- gpu.set(2,2, "Не авторизовано (Встаньте на PIM)!")
- end
- end
- local function drawFooter()
- gpu.setBackground(colors.titleBar)
- gpu.setForeground(colors.text)
- for y= screenHeight- footerHeight+1, screenHeight do
- gpu.fill(1, y, screenWidth,1," ")
- end
- local footText= "[ OpenOS - PIM Shop ]"
- local fx= math.floor((screenWidth- unicode.len(footText))/2)
- gpu.set(fx, screenHeight, footText)
- end
- local function drawFrame(x,y,w,h, title)
- gpu.setForeground(colors.frame)
- gpu.setBackground(colors.background)
- gpu.set(x,y,"┌")
- gpu.set(x+w-1,y,"┐")
- gpu.set(x,y+h-1,"└")
- gpu.set(x+w-1,y+h-1,"┘")
- for i=x+1, x+w-2 do
- gpu.set(i,y,"─")
- gpu.set(i,y+h-1,"─")
- end
- for j=y+1, y+h-2 do
- gpu.set(x,j,"│")
- gpu.set(x+w-1,j,"│")
- end
- if title then
- local tx= x+ math.floor((w- unicode.len(title))/2)
- gpu.set(tx,y, title)
- end
- end
- --------------------------------------------------------------------------------
- -- 6) ЛЕВАЯ ПАНЕЛЬ "ДЕЙСТВИЯ"
- --------------------------------------------------------------------------------
- local function drawLeftPanel()
- drawFrame(actionsX, actionsY, actionsW, actionsH, " Действия ")
- -- Верхний блок: "Внести деньги" / "Внести железо"
- local marginX= actionsX+2
- local marginY= actionsY+1
- gpu.setBackground(colors.background)
- gpu.setForeground(colors.warn)
- gpu.set(marginX, marginY, "Для пополнения:")
- gpu.set(marginX, marginY+1, "Нажмите кнопку!")
- gpu.set(marginX, marginY+2, "Будут забраны")
- gpu.set(marginX, marginY+3, "все деньги/железо")
- -- Кнопка "Внести деньги"
- local btnW= actionsW-4
- local btnH= 3
- local btnY1= marginY+5
- gpu.setBackground(colors.button)
- for ry=0, btnH-1 do
- gpu.fill(marginX, btnY1+ ry, btnW,1," ")
- end
- local label1= "Внести деньги"
- local cx1= marginX+ math.floor((btnW- unicode.len(label1))/2)
- local cy1= btnY1+ math.floor(btnH/2)
- gpu.setForeground(colors.buttonText)
- gpu.set(cx1, cy1, label1)
- -- Кнопка "Внести железо"
- local btnY2= btnY1+ btnH+1
- gpu.setBackground(colors.button)
- for ry=0, btnH-1 do
- gpu.fill(marginX, btnY2+ ry, btnW,1," ")
- end
- local label2= "Внести железо"
- local cx2= marginX+ math.floor((btnW- unicode.len(label2))/2)
- local cy2= btnY2+ math.floor(btnH/2)
- gpu.setForeground(colors.buttonText)
- gpu.set(cx2, cy2, label2)
- -- Нижний блок: "Забрать" (2 кнопки + 2 поля ввода)
- local boxY= btnY2+ btnH+1
- local boxH= 10
- drawFrame(marginX, boxY, btnW, boxH, " Забрать ")
- local inX= marginX+1
- local inY= boxY+1
- local inW= btnW-2
- local lineDist=3
- gpu.setBackground(colors.background)
- gpu.setForeground(colors.text)
- -- 1) "Забрать деньги" (кнопка)
- gpu.setBackground(colors.button)
- gpu.fill(inX, inY, inW,1, " ")
- local lblZ1= "Забрать деньги"
- local cz1= inX+ math.floor((inW- unicode.len(lblZ1))/2)
- gpu.setForeground(colors.buttonText)
- gpu.set(cz1, inY, lblZ1)
- -- Под этой кнопкой: поле ввода withdrawMoneyInput
- local inputY1= inY+1
- gpu.setBackground(colors.inputField)
- gpu.fill(inX, inputY1, inW,1," ")
- gpu.setForeground(colors.text)
- local showWD= withdrawMoneyInput
- if unicode.len(showWD)> inW then
- showWD= unicode.sub(showWD, unicode.len(showWD)- inW+1)
- end
- gpu.set(inX, inputY1, showWD)
- -- 2) "Забрать железо" (кнопка)
- local yz2= inputY1+2
- gpu.setBackground(colors.button)
- gpu.fill(inX, yz2, inW,1, " ")
- local lblZ2= "Забрать железо"
- local cz2= inX+ math.floor((inW- unicode.len(lblZ2))/2)
- gpu.setForeground(colors.buttonText)
- gpu.set(cz2, yz2, lblZ2)
- -- Под кнопкой: поле ввода withdrawIronInput
- local inputY2= yz2+1
- gpu.setBackground(colors.inputField)
- gpu.fill(inX, inputY2, inW,1," ")
- gpu.setForeground(colors.text)
- local showWI= withdrawIronInput
- if unicode.len(showWI)> inW then
- showWI= unicode.sub(showWI, unicode.len(showWI)- inW+1)
- end
- gpu.set(inX, inputY2, showWI)
- end
- --------------------------------------------------------------------------------
- -- 7) СПИСОК ТОВАРОВ (Верхняя часть справа)
- --------------------------------------------------------------------------------
- local function calcColumns(availableWidth)
- local nameW= math.floor(availableWidth*0.4)
- local qtyW = math.floor(availableWidth*0.15)
- local emeW = math.floor(availableWidth*0.15)
- local iroW = availableWidth- nameW- qtyW- emeW
- if nameW<8 then nameW=8 end
- if qtyW<6 then qtyW=6 end
- if emeW<5 then emeW=5 end
- if iroW<5 then iroW=5 end
- return nameW, qtyW, emeW, iroW
- end
- local function cutPad(str,wid)
- local n= unicode.len(str)
- if n>wid then
- return unicode.sub(str,1,wid)
- else
- return str.. string.rep(" ", wid-n)
- end
- end
- local function formatRow(nm,qt,em,ir)
- local s1= cutPad(nm, colNameW)
- local s2= cutPad(qt, colQtyW)
- local s3= cutPad(em, colEmerW)
- local s4= cutPad(ir, colIronW)
- return s1.. s2.. s3.. s4
- end
- local function drawItemList()
- -- Сверху
- local listH= itemsH- (buyPanelHeight+ searchBarHeight)
- drawFrame(itemsX, itemsY, itemsW, listH, " Список товаров ")
- local inX= itemsX+1
- local inY= itemsY+1
- local inW= itemsW-2
- local inH= listH-2
- gpu.setBackground(colors.background)
- gpu.setForeground(colors.text)
- -- Заголовок
- local hdr= formatRow("Товар", "Кол-во", "Эм", "Жел")
- gpu.set(inX, inY, hdr)
- inY= inY+1
- local sep= string.rep("-", inW)
- gpu.set(inX, inY, sep)
- inY= inY+1
- local maxIdx= #filteredItems
- local linesAvailable= inH-2
- local visible= math.min(linesAvailable, maxIdx- scrollOffset)
- local lineY= inY
- for i=1, visible do
- local idx= scrollOffset+ i
- local it= filteredItems[idx]
- -- Формируем строку
- local row= formatRow(
- it.display,
- tostring(it.quantity).."шт",
- tostring(it.priceEmerald).."Эм",
- tostring(it.priceIron).."Ж"
- )
- if unicode.len(row)> inW then
- row= unicode.sub(row,1,inW)
- end
- -- Подсветка, если выбран
- if (buySelectedIndex== idx) then
- gpu.setBackground(colors.highlight)
- gpu.fill(inX, lineY, inW,1," ")
- gpu.setForeground(colors.text)
- gpu.set(inX, lineY, row)
- -- Вернём фон
- gpu.setBackground(colors.background)
- else
- gpu.setBackground(colors.background)
- gpu.setForeground(colors.text)
- gpu.set(inX, lineY, row)
- end
- lineY= lineY+1
- if lineY> (itemsY+ listH-1) then
- break
- end
- end
- end
- --------------------------------------------------------------------------------
- -- 8) ПАНЕЛЬ ПОКУПКИ (между списком и поиском)
- --------------------------------------------------------------------------------
- local function drawBuyPanel()
- if not playerOnPIM then return end
- local panelH= buyPanelHeight
- local panelW= itemsW
- local panelX= itemsX
- local panelY= itemsY+ (itemsH- searchBarHeight)- panelH
- drawFrame(panelX, panelY, panelW, panelH, " Покупка ")
- local inX= panelX+1
- local inY= panelY+1
- local inW= panelW-2
- if not buySelectedIndex then
- gpu.setForeground(colors.text)
- gpu.setBackground(colors.background)
- gpu.set(inX, inY, "Выберите товар (клик по списку)")
- return
- end
- local it= filteredItems[buySelectedIndex]
- if not it then
- gpu.set(inX, inY, "Товар не найден")
- return
- end
- local line= string.format("%s (ост. %dшт)", it.display, it.quantity)
- gpu.setBackground(colors.background)
- gpu.setForeground(colors.text)
- gpu.set(inX, inY, line)
- local textQty= "Кол-во: ".. buyQuantity
- gpu.set(inX+30, inY, textQty)
- local payLbl= payWithEmerald and "[Эм]/Жел" or "Эм/[Жел]"
- gpu.set(inX+50, inY, payLbl)
- -- Кнопка "Купить"
- local btnW= 8
- local btnX= (panelX+ panelW)- btnW
- local btnY= inY
- local canBuy= false
- local ud= getUserData(currentPlayerName)
- local q= tonumber(buyQuantity) or 0
- if q>0 and it.quantity>=q then
- local cost= (payWithEmerald and it.priceEmerald or it.priceIron)* q
- if payWithEmerald and ud.balanceEmerald>= cost then
- canBuy= true
- elseif (not payWithEmerald) and ud.balanceIron>= cost then
- canBuy= true
- end
- end
- local colBtn= canBuy and colors.success or colors.buttonInactive
- gpu.setBackground(colBtn)
- gpu.fill(btnX, btnY, btnW,1, " ")
- gpu.setForeground(colors.text)
- local lbl= "Купить"
- local cx= btnX+ math.floor((btnW- unicode.len(lbl))/2)
- gpu.set(cx, btnY, lbl)
- if buyMessage~="" then
- gpu.setForeground(colors.warn)
- gpu.set(inX, inY+1, buyMessage)
- end
- end
- --------------------------------------------------------------------------------
- -- 9) ПОЛЕ ПОИСК (ВНИЗУ)
- --------------------------------------------------------------------------------
- local function drawSearchBar()
- if not playerOnPIM then return end
- local sbH= searchBarHeight
- local sbW= itemsW
- local sbX= itemsX
- local sbY= itemsY+ itemsH- sbH +1
- drawFrame(sbX, sbY, sbW, sbH, nil)
- local inX= sbX+1
- local inY= sbY+1
- local inW= sbW-2
- gpu.setBackground(colors.inputField)
- gpu.fill(inX, inY, inW,1, " ")
- gpu.setForeground(colors.text)
- local prefix= "Поиск: "
- local text= prefix.. searchText
- if unicode.len(text)> inW then
- text= unicode.sub(text, unicode.len(text)- inW+1)
- end
- gpu.set(inX, inY, text)
- if searchFocus then
- local cx= inX+ unicode.len(text)
- if cx<(inX+ inW) then
- if searchCursorVisible then
- gpu.set(cx, inY, "_")
- end
- end
- end
- end
- --------------------------------------------------------------------------------
- -- ПОЛНАЯ ПЕРЕРИСОВКА
- --------------------------------------------------------------------------------
- local function redrawScreen()
- clearScreen()
- drawHeader()
- if not playerOnPIM then
- local msg= "Встаньте на PIM для авторизации..."
- local x= math.floor((screenWidth- unicode.len(msg))/2)
- local y= math.floor(screenHeight/2)
- gpu.set(x,y, msg)
- else
- drawLeftPanel()
- drawItemList()
- drawBuyPanel()
- drawSearchBar()
- end
- drawFooter()
- end
- --------------------------------------------------------------------------------
- -- 10) ОБНОВЛЕНИЕ СПИСКА (ПОИСК)
- --------------------------------------------------------------------------------
- local function updateFilteredItems()
- filteredItems= {}
- local q= unicode.lower(searchText)
- for _, it in ipairs(allItems) do
- local disp= unicode.lower(it.display)
- if q=="" or unicode.find(disp,q,1,true) then
- table.insert(filteredItems, it)
- end
- end
- end
- -- Подготовка колонок
- local function prepareColumns()
- local listH= itemsH- (buyPanelHeight+ searchBarHeight)
- local listW= itemsW- 2
- colNameW, colQtyW, colEmerW, colIronW= calcColumns(listW)
- end
- local function initAll()
- prepareColumns()
- updateFilteredItems()
- redrawScreen()
- end
- --------------------------------------------------------------------------------
- -- 11) Проверка PIM (таймер)
- --------------------------------------------------------------------------------
- local lastName= nil
- local function checkPIM()
- local nm= pim.getInventoryName()
- if nm and nm~="" and nm~="pim" then
- if not playerOnPIM or (nm~= lastName) then
- playerOnPIM= true
- currentPlayerName= nm
- lastName= nm
- getUserData(nm)
- redrawScreen()
- end
- else
- if playerOnPIM then
- playerOnPIM= false
- currentPlayerName= nil
- lastName= nil
- redrawScreen()
- end
- end
- end
- --------------------------------------------------------------------------------
- -- 12) ФУНКЦИИ ДЕЙСТВИЙ: Внести / Забрать / Купить
- --------------------------------------------------------------------------------
- local function depositMoney()
- print("Кнопка: «Внести деньги» (реализуйте логику, если нужно).")
- end
- local function depositIron()
- print("Кнопка: «Внести железо» (реализуйте логику, если нужно).")
- end
- local function withdrawMoney()
- if #withdrawMoneyInput>0 then
- local amt= tonumber(withdrawMoneyInput) or 0
- print("Кнопка «Забрать деньги»: "..amt)
- withdrawMoneyInput= ""
- redrawScreen()
- end
- end
- local function withdrawIron()
- if #withdrawIronInput>0 then
- local amt= tonumber(withdrawIronInput) or 0
- print("Кнопка «Забрать железо»: "..amt)
- withdrawIronInput= ""
- redrawScreen()
- end
- end
- local function tryBuyItem()
- buyMessage= ""
- if not buySelectedIndex then return end
- local it= filteredItems[buySelectedIndex]
- if not it then return end
- local q= tonumber(buyQuantity) or 0
- if q<=0 then
- buyMessage= "Количество=0"
- return
- end
- if it.quantity< q then
- buyMessage= "В магазине осталось ".. it.quantity
- return
- end
- local ud= getUserData(currentPlayerName)
- local cost= (payWithEmerald and it.priceEmerald or it.priceIron)* q
- if payWithEmerald and ud.balanceEmerald< cost then
- buyMessage= "Недостаточно Эм!"
- return
- elseif (not payWithEmerald) and ud.balanceIron< cost then
- buyMessage= "Недостаточно Жел!"
- return
- end
- -- Снимаем деньги, уменьшаем остаток товара:
- if payWithEmerald then
- ud.balanceEmerald= ud.balanceEmerald- cost
- else
- ud.balanceIron= ud.balanceIron- cost
- end
- it.quantity= it.quantity- q
- print("Куплено "..q.." шт '"..it.display.."' за ".. cost.. (payWithEmerald and " Эм" or " Жел"))
- buyQuantity= ""
- end
- --------------------------------------------------------------------------------
- -- 13) Определить, где кликнули в списке
- --------------------------------------------------------------------------------
- local function getItemIndexFromCoords(cx,cy)
- local listH= itemsH- (buyPanelHeight+ searchBarHeight)
- local inX= itemsX+1
- local inY= itemsY+3
- local inW= itemsW-2
- local inH= listH-2
- if cx< inX or cx>= (inX+inW) then return nil end
- if cy< inY or cy>= (inY+inH) then return nil end
- local line= cy- inY+1
- local idx= scrollOffset+ line
- if idx<1 or idx>#filteredItems then return nil end
- return idx
- end
- --------------------------------------------------------------------------------
- -- 14) СОБЫТИЯ
- --------------------------------------------------------------------------------
- initAll()
- event.timer(1, function() checkPIM() end, math.huge)
- while true do
- local evt, p1, p2, p3= event.pull(0.05)
- -- Мигание курсора (поиск)
- if searchFocus then
- local t= os.clock()
- if (t- lastCursorBlink)> cursorBlinkInterval then
- searchCursorVisible= not searchCursorVisible
- lastCursorBlink= t
- drawSearchBar()
- end
- end
- if evt=="scroll" then
- if playerOnPIM then
- local dir= p3
- local maxCount= #filteredItems
- local listH= itemsH- (buyPanelHeight+ searchBarHeight)
- local lines= listH-4
- if dir==-1 and scrollOffset>0 then
- scrollOffset= scrollOffset-1
- drawItemList()
- drawBuyPanel()
- elseif dir==1 and scrollOffset< (maxCount- lines) then
- scrollOffset= scrollOffset+1
- drawItemList()
- drawBuyPanel()
- end
- end
- elseif evt=="touch" then
- local cx, cy= p2, p3
- if playerOnPIM then
- -- Левая панель
- local marginX= actionsX+2
- local marginY= actionsY+1
- local btnW= actionsW-4
- local btnH=3
- local btnY1= marginY+5 -- "Внести деньги"
- local btnY2= btnY1+ btnH+1 -- "Внести железо"
- -- Кнопка1
- if cx>= marginX and cx<(marginX+btnW) and cy>= btnY1 and cy<(btnY1+ btnH) then
- depositMoney()
- -- Кнопка2
- elseif cx>= marginX and cx<(marginX+btnW) and cy>= btnY2 and cy<(btnY2+ btnH) then
- depositIron()
- else
- -- "Забрать" зона
- local boxY= btnY2+ btnH+1
- local boxH= 10
- local inX= marginX+1
- local inY= boxY+1
- local inW= btnW-2
- -- 1) "Забрать деньги"
- if cy== inY then
- -- Клик по кнопке "Забрать деньги"
- withdrawMoney()
- elseif cy== inY+1 then
- -- поле ввода withdrawMoneyInput
- withdrawMoneyInput= ""
- -- 2) "Забрать железо"
- elseif cy== inY+2 then
- -- кнопка
- withdrawIron()
- elseif cy== inY+3 then
- -- поле ввода
- withdrawIronInput= ""
- else
- -- Проверим клик по списку
- local idx= getItemIndexFromCoords(cx,cy)
- if idx then
- buySelectedIndex= idx
- buyMessage= ""
- redrawScreen()
- else
- -- Проверка поиска
- local sbY= itemsY+ itemsH- searchBarHeight +1
- if cy== sbY+1 then
- -- строка поиска
- searchFocus= true
- else
- searchFocus= false
- end
- -- Панель "покупка"
- local buyY= itemsY+ (itemsH- searchBarHeight)- buyPanelHeight
- if cy>= buyY and cy< buyY+ buyPanelHeight then
- -- Возможно клик на переключатель [Эм]/[Жел], кнопку "Купить" etc.
- local lineBuy= cy- buyY
- if lineBuy==1 then
- -- payLabel? if cx>= ??? ...
- if cx>= (itemsX+50) and cx<(itemsX+54) then
- payWithEmerald= not payWithEmerald
- redrawScreen()
- end
- -- Кнопка "Купить"
- local btnX= (itemsX+ itemsW)- 8
- if cx>= btnX and cx< btnX+8 then
- tryBuyItem()
- drawBuyPanel()
- drawItemList()
- end
- end
- end
- end
- end
- end
- end
- elseif evt=="key_down" then
- local ch= p3
- -- Если в фокусе поиск
- if searchFocus then
- if ch==8 then
- if unicode.len(searchText)>0 then
- searchText= unicode.sub(searchText,1, unicode.len(searchText)-1)
- scrollOffset=0
- updateFilteredItems()
- drawItemList()
- drawBuyPanel()
- drawSearchBar()
- end
- elseif ch==13 then
- -- Enter
- else
- -- Печатный символ?
- if (ch>=48 and ch<=57) or (ch>=65 and ch<=90) or (ch>=97 and ch<=122) or
- (ch>=1040 and ch<=1103) or (ch>=32 and ch<=47) or (ch>=58 and ch<=64) then
- local c= unicode.char(ch)
- searchText= searchText.. c
- scrollOffset=0
- updateFilteredItems()
- drawItemList()
- drawBuyPanel()
- drawSearchBar()
- end
- end
- else
- -- Смотрим, вводим ли buyQuantity
- if buySelectedIndex then
- if ch>=48 and ch<=57 then
- buyQuantity= buyQuantity.. string.char(ch)
- drawBuyPanel()
- elseif ch==8 then
- if #buyQuantity>0 then
- buyQuantity= buyQuantity:sub(1,#buyQuantity-1)
- drawBuyPanel()
- end
- elseif ch==13 then
- tryBuyItem()
- drawBuyPanel()
- drawItemList()
- end
- end
- -- Проверим поля "withdrawMoneyInput"/"withdrawIronInput"
- -- Если пользователь «выбрал» (кликнул на) withdrawMoneyInput
- -- мы должны хранить фокус, напр. focus="withdrawMoney".
- -- Ниже — упрощённо (без переменных фокуса, но иллюстрирует идею):
- -- Допустим, если user "включил" withdrawMoneyInput (очистили строку):
- -- можно проверить, if ch>=48 and ch<=57 then...
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment