Jump to content

GUI dynamic size problems


Recommended Posts

Hi all, could you tell me how to make a dynamic installation of interface sizes depending on the size of the user's screen?

Code:

function guiCreateMainMenu()
local sWidth,sHeight = guiGetScreenSize()
local localPlayerName = getPlayerName(getLocalPlayer())
mainMenuSound()

menu = guiCreateStaticImage( 0, 0, sWidth, sHeight, "img/screen_shadow.png", false )
userImg = guiCreateStaticImage( sWidth/2.8, 0, sWidth/1.5, sHeight/1.5, "img/user.png", false, menu )
menuBg = guiCreateStaticImage( sWidth/7, sHeight/8.07692, sWidth/1.4, sHeight/17, "img/bg.png", false, menu )
menuFg = guiCreateStaticImage( sWidth/7, sHeight/8.07692, sWidth/1.4, sHeight/17, "img/fg.png", false, menu )


usernameLabel = guiCreateLabel( sWidth/2434.78260, sHeight/14000, 1, 1, localPlayerName, true, userImg) --24 символа макс.
userNameFont = guiCreateFont( "fonts/calibri.ttf", 16 )
guiSetFont ( usernameLabel, userNameFont )

menuMainLabel = guiCreateLabel( sWidth/8400, sHeight/11666.66666, 1, 1, "*Главное меню*", true, menu)
mainMenuFont = guiCreateFont( "fonts/carbon.ttf", 32 )
guiSetFont ( menuMainLabel, mainMenuFont )

carrierBtn = guiCreateLabel( (0.12/1680)*sWidth, 0.341, 1, 1, "КАРЬЕРА", true, menuFg)
carrierBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( carrierBtn, carrierBtnFont )
carrierButton = guiCreateStaticImage( 385, 154, 80, 13, "img/btn.png", false, menu )

statBtn = guiCreateLabel( 0.2, 0.341, 1, 1, "СТАТИСТИКА", true, menuFg)
statBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( statBtn, statBtnFont )
statButton = guiCreateStaticImage( 481, 154, 111, 13, "img/btn.png", false, menu )

achBtn = guiCreateLabel( 0.313, 0.341, 1, 1, "ДОСТИЖЕНИЯ", true, menuFg)
achBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( achBtn, achBtnFont )
achButton = guiCreateStaticImage( 615, 154, 121, 13, "img/btn.png", false, menu )

bestBtn = guiCreateLabel( 0.432, 0.341, 1, 1, "ТОП ЛУЧШИХ ИГРОКОВ", true, menuFg)
bestBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( bestBtn, bestBtnFont )
bestButton = guiCreateStaticImage( 758, 154, 198, 13, "img/btn.png", false, menu )

settingsBtn = guiCreateLabel( 0.616, 0.341, 1, 1, "НАСТРОЙКИ", true, menuFg)
settingsBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( settingsBtn, settingsBtnFont )
settingsButton = guiCreateStaticImage( 980, 154, 101, 13, "img/btn.png", false, menu )

newsBtn = guiCreateLabel( 0.720, 0.341, 1, 1, "НОВОСТИ", true, menuFg)
newsBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( newsBtn, newsBtnFont )
newsButton = guiCreateStaticImage( 1106, 154, 78, 13, "img/btn.png", false, menu )

aboutBtn = guiCreateLabel( 0.810, 0.341, 1, 1, "О СЕРВЕРЕ", true, menuFg)
aboutBtnFont = guiCreateFont( "fonts/calibri.ttf", 15 )
guiSetFont ( aboutBtn, aboutBtnFont )
aboutButton = guiCreateStaticImage( 1213, 154, 87, 13, "img/btn.png", false, menu )


showCursor(true)
showChat(false)
setPlayerHudComponentVisible("all", false)
end

 

Link to comment
  • Discord Moderators

Hello!

First of all, consider reading about code redundancy.

Use some loops, to make your code look better.

But to answer you question:

local fResp = guiGetScreenSize()/[[INSERT YOU CURRENT SCREEN WIDTH HERE]]
function respc(num)
    return num*fResp
end

use the respc function to 'resize' the number.

Ex.:

dxDrawImage(0, 0, respc(20), respc(20), "testimg.png")

 

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...