#include "ui/ui_extensions.lua" local menuContentWidth = 0 local menuContentHeight = 0 local function drawLabel() UiPush() UiTranslate(UiCenter(), 1020) UiAlign("center middle") UiFont("regular.ttf", 48) UiColor(1.0, 1.0, 1.0) UiTextShadow(0, 0, 0, 1, 3.0, 1.0) UiTextOutline(0, 0, 0, 1, 0.8) UiText("loc@UI_SHOWCASE") UiPop() end local function drawBackground() UiPush() UiColor(0.5, 0.75, 0.85, 1.0) UiRect(UiWidth(), UiHeight()) UiPop() end local function drawGamepadConnectionAlert() UiPush() UiTranslate(UiCenter(), 130) UiAlign("center middle") UiFont("regular.ttf", 35) UiWordWrap(700) UiTextAlignment("center") UiColor(1.0, 1.0, 1.0) UiImageBox("MOD/img/menu-bg.png", 800, 110, 25, 25) UiText("loc@UI_SHOWCASE_PLEASE_PRESS") UiPop() end local function drawDescription() UiPush() local text = GetTranslatedStringByKey("UI_SHOWCASE_DESCRIPTION") UiTranslate(UiCenter() / 2 - 200, UiHeight() * 0.225) UiAlign("center middle") UiFont("regular.ttf", 22) UiColor(1.0, 1.0, 1.0) UiTextAlignment("left") UiWordWrap(450) UiTextLineSpacing(10) local w,h = UiGetTextSize(text) UiImageBox("MOD/img/menu-bg.png", w + 50, h + 50, 50, 50) UiText(text) UiPop() end local function drawMenuBackground() UiImageBox("MOD/img/menu-bg.png", menuContentWidth + 50, menuContentHeight + 30, 75, 75) end -- If the player has an interactive mode enabled via UiMakeInteractive -- and he also has a gamepad connected, then navigation between UI elements (buttons, sliders etc.) occurs with the d-pad. local function drawButtons() UiAlign("center") UiFont("regular.ttf", 40) UiColor(1.0, 1.0, 1.0) UiButtonHoverColor(0.5, 1.0, 0.5) UiButtonImageBox("MOD/img/box-solid-6.png", 6, 6, 0.4,0.4,0.4,0.5) UiTranslate(0, 20) for i = 1, 2, 1 do UiTranslate(0, i * 50) if UiTextButton(GetTranslatedStringByKey("UI_SHOWCASE_BUTTON") .. " " .. i, 200, 40) then DebugPrint(GetTranslatedStringByKey("UI_SHOWCASE_BUTTON") .. " " .. i) end end UiTranslate(-25, 100) UiButtonImageBox("MOD/img/box-solid-6.png", 6, 6, 0.4,0.4,0.4,0.5) UiAlign("center") for i = 1, 2, 1 do UiTranslate((i - 1) * 50, 0) if UiTextButton(tostring(i + 2), 30, 40) then DebugPrint(GetTranslatedStringByKey("UI_SHOWCASE_BUTTON") .. " " .. (i + 2)) end end end --You can draw special controls icons with strings like: -- [[player:gamepad_dpad_updown;iconsize=40,40]] -- [[gamepad_left_stick;iconsize=40,40]] -- [[player:usetool]] -- [[player:grab]] -- [[menu:interact]] -- [[gamepad_left_stick_right]] -- For menus and gameplay, the style of the buttons is slightly different. -- So you can use the prefixes "player" and "menu" to specify which style to draw the icons in. -- To specify the size of the icon, use the "iconsize" parameter separated by a semicolon. local function drawHints() UiTranslate(-30, 60) -- To simplify the icons rendering you can use UiDrawHintsCentered from "ui/ui_extensions.lua". -- At the same time, no one forbids you to use regular UiText function. UiDrawHintsCentered({ { ico = "[[menu_cancel]]", txt = "loc@UI_BUTTON_CLOSE", txtColor=0xAA5555 }, { ico = "[[menu:menu_accept;iconsize=42,42]]", txt = "loc@UI_BUTTON_SELECT", txtColor=0x55AA55 } },20) UiTranslate(0, 60) UiDrawHintsCentered({ {ico="[[player:gamepad_dpad_up;iconsize=42,42]] [[player:gamepad_dpad_down;iconsize=42,42]] ", txt="loc@UI_SHOWCASE_UP_DOWN", txtColor=0xCCAA55} },20) UiTranslate(0, 60) UiDrawHintsCentered({ {ico="[[player:gamepad_dpad_left;iconsize=42,42]] [[player:gamepad_dpad_right;iconsize=42,42]] ", txt="loc@UI_SHOWCASE_LEFT_RIGHT", txtColor=0xCCAA55} },20) UiTranslate(0, 60) UiDrawHintsCentered({ {ico="[[gamepad_left_stick;iconsize=50,50]]", txt="loc@UI_SHOWCASE_MOVE", txtColor=0x5555AA} },20) UiTranslate(0, 60) UiDrawHintsCentered({ {ico="[[gamepad_right_stick;iconsize=50,50]]", txt="loc@UI_SHOWCASE_CAMERA", txtColor=0x5555AA} },20) UiTranslate(-75, 60) UiDrawHintsCentered({ {ico="[[player:grab;iconsize=35,35]]", txt="loc@UI_SHOWCASE_AIM", txtColor=0xAAAA55} },20) UiTranslate(150, 0) UiDrawHintsCentered({ {ico="[[player:usetool;iconsize=35,35]]", txt="loc@UI_SHOWCASE_SHOOT", txtColor=0xAAAA55} },20) UiTranslate(-75, 50) UiFont("regular.ttf", 24) UiText("loc@UI_SHOWCASE_MORE_EXAMPLES") UiFont("regular.ttf", 40) UiTranslate(-75, 50) -- More icons examples rendered with UiText local icons = { { "[[gamepad_left_stick_up]]", "[[gamepad_button_l1]]", "[[gamepad_button_l2]]", "[[gamepad_button_r1]]", "[[gamepad_button_r2]]" }, { "[[gamepad_right_stick_down]]", "[[player:flashlight]]", "[[map]]", "[[pause]]", "[[gamepad_button_l3]]" } } for i = 1, #icons, 1 do UiPush() for j = 1, #icons[i], 1 do UiText(icons[i][j]) UiTranslate(40, 0) end UiPop() UiTranslate(0, 40) end end function draw() UiMakeInteractive() drawBackground() drawLabel() drawDescription() -- You can check that the user is using a gamepad via the LastInputDevice function. local isUsingGamepad = LastInputDevice() == UI_DEVICE_GAMEPAD -- If the user is using a gamepad, we call the UiSetCursorState function. -- It hides the cursor and automatically activates gamepad UI navigation using the d-pad. if isUsingGamepad then UiSetCursorState(UI_CURSOR_HIDE_AND_LOCK) UiPush() UiTranslate(UiWidth()/2, UiHeight()/6) UiAlign("center top") drawMenuBackground() UiBeginFrame() drawButtons() drawHints() menuContentWidth, menuContentHeight = UiEndFrame() UiPop() else drawGamepadConnectionAlert() end end