#include "ui/platform.lua" #include "helpers/table.lua" #include "helpers/math.lua" #include "helpers/input.lua" #include "helpers/positioning.lua" UI_NAVLIST_VERTICAL = 0 UI_NAVLIST_HORIZONTAL = 1 UI_NAVLIST_SELECT_ITEM= "UiNavListSelectItem" UI_NAVLIST_ACTIVATE_SELECTED = "UiNavListActivateSelected" UI_EVENT_LANGUAGE_CHANGED = "LanguageChanged" UI_DEVICE_NONE = 0 UI_DEVICE_MOUSE = 1 UI_DEVICE_GAMEPAD = 2 UI_CURSOR_SHOW = 0 UI_CURSOR_HIDE = 1 UI_CURSOR_HIDE_AND_LOCK = 2 function rgb(r,g,b,a) return r / 256,g / 256,b / 256, (a or 256) / 256 end ToListItems = function(items, calculator, drawer) local values = {} for idx = 1, #items do local value = items[idx] local iw,ih = calculator(value) table.insert(values, {data = value, w = iw, h = ih, draw = function(value) drawer(value, idx) end}) end return values end --[[ The DebugQuad function can be used for visual debugging. It draws a rectangle of a given width and height, splitting it into quarters with lines. ]] function DebugQuad(rectWidth, rectHeight) local lineWidth = 2 UiColorFilter(1,1,1,0.5) UiPush() UiColor(1,1,1,1) UiPush() UiRect(lineWidth,rectHeight) UiTranslate(rectWidth - lineWidth,0) UiRect(lineWidth,rectHeight) UiPop() UiPush() UiPush() UiTranslate(rectWidth / 2,0) UiRect(lineWidth,rectHeight) UiPop() UiTranslate(0,rectHeight / 2) UiRect(rectWidth,lineWidth) UiPop() UiColor(1,0,0,1) UiRect(rectWidth,rectHeight) UiPop() end function hexrgb(hex) local r, g, b, a -- Check for the presence of an alpha channel if hex > 16777215 then a = hex % 256 r = math.floor(hex / 16777216) % 256 g = math.floor(hex / 65536) % 256 b = math.floor(hex / 256) % 256 else a = 255 r = math.floor(hex / 65536) % 256 g = math.floor(hex / 256) % 256 b = hex % 256 end return r / 255, g / 255, b / 255, a / 255 end function drawLocalUserTag(option) if not IsRunningOnPC() and not IsRunningOnApple() then UiPush() UiTranslateToPositionOnScreen(UiWidth() - 103, 87) UiAlign("middle right") UiFont("arial.ttf", 27) local userTag = GetUserNickname() local wTag, _ = UiGetTextSize(userTag) local wIcon, hIcon = UiGetImageSize("ui/menu/user_icon.png") if option and option.withBackground then local padding = 10 UiPush() UiColor(0,0,0,0.55) UiTranslate(padding, 0) UiImageBox("ui/common/box-solid-10.png", wTag + wIcon / 2 + 2 * padding + 4, hIcon / 2 + 2 * padding, 6, 6) UiPop() end UiPush() UiScale(0.5) UiImage("ui/menu/user_icon.png") UiPop() UiTranslate(-wIcon/2-4, 1) UiColor(1,1,1) UiText(userTag) UiPop() end end function randomFloat(lower, greater) return lower + math.random() * (greater - lower); end function randomColor() local r = randomFloat(0,1) local g = randomFloat(0,1) local b = randomFloat(0,1) local a = 1 return r,g,b,a end function filter(collection, predicate) local index = 0 local count = #collection return function () index = index + 1 while index <= count and (not predicate(collection[index], index)) do index = index + 1 end if index <= count and predicate(collection[index], index) then return collection[index], index end return nil end end