Jump to content

I have two serious problems


Recommended Posts

Hello world! I'm sorry for my bad English, but I am Russian. I haven't been helped on Russian part of forum. I have two serious problems.

The first problem

I have created a universal window to show notifications ("you have inputted the login that is busy" or "this menu is not available to you" etc). The window is a standart window centered on the screen. There are only a label and a button in the window. The label takes up most of the window. The button has one function. This function is closing the window. Because I am lazy, I do not want to find height and width the label, the window and the button. Therefore, depending on the size of a text (I find size of the text using guiLabelGetFontHeight and guiLabelGetTextExtent), I find size of the label. Then I find size of the button and size of the window. (All this is depends the size of the text). But there is a problem. I use guiLabelSetHorizontalAlign(errorW.label, "left", true) for line wrapping. But guiLabelGetTextExtent gets the size of a text without spaces, which guiLabelSetHorizontalAlign(errorW.label, "left", true) has created, when guiLabelSetHorizontalAlign(errorW.label, "left", true) made line wrapping. These spaces are reason of wrong set size of the label.

I see two ways to solve the problem:

1. Tell me, how I can find out, how many pixels add to the height of the label, that a part of the text do not loses.

2. Or tell me, how I can make line wrapping. But do not transfer all word, but transfer part of a word (transfer letters, do letter-wrap).

P.S. The size of a text I get so

local y =  guiLabelGetFontHeight(errorW.label) 
    local k = guiLabelGetTextExtent(errorW.label) 
    local s = math.ceil(math.sqrt(k * y / 2.5) / y) 
    local x = math.ceil(k / s) --  the label has width = x and height = y * s 

The second problem.

I have a problem with a browser. I created a browser. Then I created video as background of the browser. I attached children. All works good. But when I press "backspace" in a guiEdit, the browser stop. When I press "backspace" , when I am focussed on the browser, the browser stop. How I can fix it?

If you do not understand me, ask me in the comments. I am sorry for my bad English. But I am tired of trying fix these problems. Help me, please.

Link to comment

About the first problem: I suggest you try remaking the GUI (as you said it's nothing big) in the guieditor resource (https://community.multitheftauto.com/?p ... ils&id=141), it's one of the best thing made for GUIs and you'll find it really helpful. Try using that and see if you can fix your problem (I'd help you out in other ways but I got lost when you mentioned the same function 4 times in a row).

About the second problem: Can you take a screenshot of what it looks like before and after you press "backspace"? As I don't really understand your problem.

Link to comment
About the first problem: I suggest you try remaking the GUI (as you said it's nothing big) in the guieditor resource (https://community.multitheftauto.com/?p ... ils&id=141), it's one of the best thing made for GUIs and you'll find it really helpful. Try using that and see if you can fix your problem (I'd help you out in other ways but I got lost when you mentioned the same function 4 times in a row).

About the second problem: Can you take a screenshot of what it looks like before and after you press "backspace"? As I don't really understand your problem.

Probably, I incorrect tell about the first problem. Full code:

errorW = {} 

-- this is in the top of the script

       function whenServerSendWrongAfterFirstPart(x) 
        if(x == 1) 
    then 
        showErrorGui("К сожалению, такой логин уже занят. Пожалуйста, придумайте другой логин.") 
    elseif(x == 2) 
    then 
        showErrorGui("Логин может состоять только из букв английского алфавита (латиница) и цифр, а также логин должен быть не менее 6 и не более 32 символов.") 
    elseif(x == 3) 
    then 
        showErrorGui("Пароль может состоять только из букв английского алфавита (латиница) и цифр, а также пароль должен быть не менее 8 и не более 64 символов.") 
    elseif(x == 4) 
    then 
        showErrorGui("Адрес электронной почты может состоять только из букв английского алфавита (латиница), цифр и следующих символов: .@_- .Также адрес электронной почты должен быть не менее 2 и не более 64 символов.") 
    elseif(x == 5) 
    then 
        showErrorGui("Номер телефона может состоять только из цифр, знака плюс ('+') , а также номер телефона должен быть не менее 2 и не более 32 символов.") 
    end 
end 

        function showErrorGui(errorString) 
        errorW.window = guiCreateWindow(0, 0, 1.0, 1.0, "Внимание!", true) 
    guiBringToFront(errorW.window) 
    errorW.label = guiCreateLabel(0, 0, 1.0, 1.0, errorString, true, errorW.window) 
    errorW.button = guiCreateButton(0, 0, 1.0, 1.0, "Далее", true, errorW.window) 
    guiSetFont(errorW.label, fonts.Registration) 
    guiLabelSetHorizontalAlign(errorW.label, "left", true) 
    local y =  guiLabelGetFontHeight(errorW.label) 
    local k = guiLabelGetTextExtent(errorW.label) 
    local s = math.ceil(math.sqrt(k * y / 2.5) / y) 
    local x = math.ceil(k / s) 
    guiSetSize(errorW.window, x / 0.8, (y * s + (x / 0.8 * 0.6) / 3) / 0.85 + 0.01470588235 * height, false) 
    guiSetSize(errorW.label, x, y * s, false) 
    guiSetSize(errorW.button, x / 0.8 * 0.6, (x / 0.8 * 0.6) / 3, false) 
    guiSetPosition(errorW.window, (width - x / 0. / 2, (height - (y * s + (x / 0.8 * 0.6) / 3) / 0.85) / 2, false) 
    guiSetPosition(errorW.label, x / 0.8 * 0.1, (y * s + (x / 0.8 * 0.6) / 3) / 0.85 * 0.05 + 0.01470588235 * height, false) 
    guiSetPosition(errorW.button, x / 0.8 * 0.2, (y * s + (x / 0.8 * 0.6) / 3) / 0.85 * 0.95 - (x / 0.8 * 0.6) / 3 + 0.01470588235 * height, false) 
    guiWindowSetMovable(errorW.window, false) 
    guiWindowSetSizable(errorW.window, false) 
end 

Link to comment

I suggest you try putting the 'guiLabelSetHorizontalAlign(errorW.label, "left", true)' after 'guiSetPosition(errorW.label, x / 0.8 * 0.1, (y * s + (x / 0.8 * 0.6) / 3) / 0.85 * 0.05 + 0.01470588235 * height, false)'

Link to comment
Try unbinding the key until the player stops browsing? Not sure, never even knew "backspace" returns you to your previous page. Or bind the key with a new function that puts him back onto the page he was.

How can I unbind "backspace"? I've found one thing. "shift + backspace" go you forward (to next page). I can use it, but it is strange method. (and user will understand that its page will have restarted)

Link to comment
I suggest you try putting the 'guiLabelSetHorizontalAlign(errorW.label, "left", true)' after 'guiSetPosition(errorW.label, x / 0.8 * 0.1, (y * s + (x / 0.8 * 0.6) / 3) / 0.85 * 0.05 + 0.01470588235 * height, false)'

Unfortunately, your suggestion did not help me. It does not work.

Link to comment
Try unbinding the key until the player stops browsing? Not sure, never even knew "backspace" returns you to your previous page. Or bind the key with a new function that puts him back onto the page he was.

I have found a solution. I use focusBrowser(nil) . All is good. One problem less. There is only the problem with the label now.

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...