• small HUD problem...
    14 replies, posted
So I have the following code: -snip- I'm completely lost because when I add a law, the size of the surface.DrawRect or surface.DrawOutlinedRect doesn't change. I'm lost due to the fact that the code is in a HUDPaint hook, so it updates every frame. I also thought of adding this into the addLaw hook from DarkRP, but I'd have to create a new function within the function WITHIN the HUDPaint hook and have this reside inside the new function and the DrawRect's won't initiate when the HUD is drawn! How would I go about fixing this issue? Thanks for any help you guys can give :)
[QUOTE=Wavie;52084890]So I have the following code: [code] ... for k, v in pairs(DarkRP.getLaws()) do local msgwidth, msgheight = surface.GetTextSize(k .. ". " .. v) surface.SetDrawColor(35, 35, 35) surface.DrawRect(ScrW() - 350, 19, 350, 61 + msgheight) surface.SetDrawColor(175, 175, 175) surface.DrawOutlinedRect(ScrW() - 350, 19, 350, 61 + msgheight) end ... [/code] I'm completely lost because when I add a law, the size of the surface.DrawRect or surface.DrawOutlinedRect doesn't change. I'm lost due to the fact that the code is in a HUDPaint hook, so it updates every frame. I also thought of adding this into the addLaw hook from DarkRP, but I'd have to create a new function within the function WITHIN the HUDPaint hook and have this reside inside the new function and the DrawRect's won't initiate when the HUD is drawn! How would I go about fixing this issue? Thanks for any help you guys can give :)[/QUOTE] You forgot to set the font you are using with [URL="http://wiki.garrysmod.com/page/surface/SetFont"]this surface function[/URL]. [editline]10th April 2017[/editline] The reason the height isn't changing is because you are checking the height of one line at a time, which will always be the same. If you want the height to increase use a counter in your loop. Example, this will draw a black box every 20 pixels for every law in the law table. [CODE]local counter = 0 for k,v in pairs(DarkRP.getLaws()) do surface.SetDrawColor(0, 0, 0) surface.DrawRect(0, counter, 10, 10) counter = counter + 20 end[/CODE]
[QUOTE=MrRalgoman;52084945]You forgot to set the font you are using with [URL="http://wiki.garrysmod.com/page/surface/SetFont"]this surface function[/URL]. [editline]10th April 2017[/editline] Also, because you are in a loop and you haven't made a counter or anything the boxes are going to draw on top of eachother.[/QUOTE] So I have the following code now: -snip- Everything works, however, at a certain amount of laws this starts to happen: [t]https://i.gyazo.com/50a62f9cacc224c0498ba07c6249d3b9.png[/t]
[QUOTE=Wavie;52084969]I've set the font, it's just not shown in this snippet. Also, how would I get them to not do so whilst still getting the keys and values of DarkRP.getLaws(). So I have the following code now: [code] local counter = 0 local msgwidth, msgheight for k, v in pairs(DarkRP.getLaws()) do counter = k msgwidth, msgheight = surface.GetTextSize(k .. ". " .. v) end surface.SetDrawColor(35, 35, 35) surface.DrawRect(ScrW() - 350, 19, 350, 36 + msgheight * counter) surface.SetDrawColor(175, 175, 175) surface.DrawOutlinedRect(ScrW() - 350, 19, 350, 36 + msgheight * counter) ... [/code] Everything works, however, at a certain amount of laws this starts to happen: [t]https://i.gyazo.com/50a62f9cacc224c0498ba07c6249d3b9.png[/t][/QUOTE] Is that all that you have in that code? From what I can see it should work, there might be a mistake in some code you have decided to leave out. You can add me and send me the code if you don't want to post it on here.
[QUOTE=MrRalgoman;52085017]Is that all that you have in that code? From what I can see it should work, there might be a mistake in some code you have decided to leave out. You can add me and send me the code if you don't want to post it on here.[/QUOTE] -snip- I don't really care honestly. I'll probably snip it after I've got my problem solved, though.
I got this working on my local server, [CODE]hook.Add("HUDPaint", "DrawLaws_BH", function() surface.SetFont("armoryFont_15") -- Base local counter = 0 local msgwidth, msgheight for k, v in pairs(DarkRP.getLaws()) do msgwidth, msgheight = surface.GetTextSize(k .. ". " .. v) counter = counter + msgheight end surface.SetDrawColor(35, 35, 35) surface.DrawRect(ScrW() - 350, 19, 350, 36 + counter) surface.SetDrawColor(175, 175, 175) surface.DrawOutlinedRect(ScrW() - 350, 19, 350, 36 + counter) -- Title surface.DrawLine(ScrW() - 349, 39, ScrW() - 1, 39) draw.DrawText(DarkRP.getPhrase("laws_of_the_land"), "armoryFont_15", ScrW() - 175, 23, Color(255, 255, 255), TEXT_ALIGN_CENTER) -- Laws for k, v in pairs(DarkRP.getLaws()) do draw.DrawText(k .. ". " .. v, "armoryFont_15", ScrW() - 345, 29 + k * 15, Color(255, 255, 255), TEXT_ALIGN_LEFT) end end)[/CODE] Just need to change your fonts back around. Your code worked fine for me though... I don't understand why it cut off for you. [editline]10th April 2017[/editline] [IMG]https://i.gyazo.com/376666e2f3baf069a6704167e64c267d.png[/IMG]
[QUOTE=MrRalgoman;52085101]I got this working on my local server, [CODE]hook.Add("HUDPaint", "DrawLaws_BH", function() surface.SetFont("armoryFont_15") -- Base local counter = 0 local msgwidth, msgheight for k, v in pairs(DarkRP.getLaws()) do msgwidth, msgheight = surface.GetTextSize(k .. ". " .. v) counter = counter + msgheight end surface.SetDrawColor(35, 35, 35) surface.DrawRect(ScrW() - 350, 19, 350, 36 + counter) surface.SetDrawColor(175, 175, 175) surface.DrawOutlinedRect(ScrW() - 350, 19, 350, 36 + counter) -- Title surface.DrawLine(ScrW() - 349, 39, ScrW() - 1, 39) draw.DrawText(DarkRP.getPhrase("laws_of_the_land"), "armoryFont_15", ScrW() - 175, 23, Color(255, 255, 255), TEXT_ALIGN_CENTER) -- Laws for k, v in pairs(DarkRP.getLaws()) do draw.DrawText(k .. ". " .. v, "armoryFont_15", ScrW() - 345, 29 + k * 15, Color(255, 255, 255), TEXT_ALIGN_LEFT) end end)[/CODE] Just need to change your fonts back around. Your code worked fine for me though... I don't understand why it cut off for you. [editline]10th April 2017[/editline] [IMG]https://i.gyazo.com/376666e2f3baf069a6704167e64c267d.png[/IMG][/QUOTE] Strange... I also have this code in a separate file: -snip- Try that out, and see if it does it after you use that code as well? EDIT: Just tried with cutting that file out of the folder. I was unsuccessful. I'm so confused right now.
[QUOTE=Wavie;52085152]Strange... I also have this code in a separate file: -snip- Try that out, and see if it does it after you use that code as well? EDIT: Just tried with cutting that file out of the folder. I was unsuccessful. I'm so confused right now.[/QUOTE] Perhaps it's your font choice. Try a different font.
[QUOTE=MrRalgoman;52085321]Perhaps it's your font choice. Try a different font.[/QUOTE] There's a font I found that works, but I dislike the font. Well this sucks.
Check out the different fonts on the wiki, there are a lot of preset ones. I used roboto in my screenshot.
[QUOTE=Wavie;52085035][code] hook.Add("HUDPaint", "DrawLaws_BH", function() surface.SetFont("BarHUDFont") -- Base local counter = 0 local msgwidth, msgheight for k, v in pairs(DarkRP.getLaws()) do counter = k msgwidth, msgheight = surface.GetTextSize(k .. ". " .. v) end surface.SetDrawColor(35, 35, 35) surface.DrawRect(ScrW() - 350, 19, 350, 36 + counter * msgheight) surface.SetDrawColor(175, 175, 175) surface.DrawOutlinedRect(ScrW() - 350, 19, 350, 36 + counter * msgheight) -- Title surface.DrawLine(ScrW() - 349, 39, ScrW() - 1, 39) draw.DrawText(DarkRP.getPhrase("laws_of_the_land"), "BarHUDFont", ScrW() - 175, 23, Color(255, 255, 255), TEXT_ALIGN_CENTER) -- Laws for k, v in pairs(DarkRP.getLaws()) do draw.DrawText(k .. ". " .. v, "BarHUDFont", ScrW() - 345, 29 + k * 15, Color(255, 255, 255), TEXT_ALIGN_LEFT) end end) [/code] I don't really care honestly. I'll probably snip it after I've got my problem solved, though.[/QUOTE] You should find another place to do that loop. It's not constantly updating, so just update the board when the laws are changed. Loops in paint hooks are really resource heavy. * Localize your colors outside of the paint hook too.
[t]https://i.gyazo.com/f93965838c184ae78f027ea0800c6cb0.png[/t] I used roboto.. lol If you change your font's size to 13, you'll see the same thing I'm seeing. [editline]10th April 2017[/editline] [QUOTE=tgandrew2468;52085606]You should find another place to do that loop. It's not constantly updating, so just update the board when the laws are changed. Loops in paint hooks are really resource heavy. * Localize your colors outside of the paint hook too.[/QUOTE] I'll probably do this when the bug at hand is fixed. My priority is fixing the issue I'm having with sizing. After which, I will optimize the code.
just gonna snip this so i don't look like a smart arse fuck, 3late
[QUOTE=tgandrew2468;52085676]just gonna snip this so i don't look like a smart arse fuck, 3late[/QUOTE] lol it's fine, dude [editline]10th April 2017[/editline] [QUOTE=tgandrew2468;52085606]You should find another place to do that loop. It's not constantly updating, so just update the board when the laws are changed. Loops in paint hooks are really resource heavy. * Localize your colors outside of the paint hook too.[/QUOTE] I guess since no one can help me, I might as well do this. So should I keep the for loop in for the drawing of the laws' text?
Just redid the whole code but with the optimization suggestions tgandrew2468 made. I'm having the same problems as before. -snip- [t]https://i.gyazo.com/a5ac0252d7835d1302c9c9fbdcdcb72d.png[/t] [editline]10th April 2017[/editline] I finally fixed this bug. It was due to me not compensating for the " + k * 15" in each law's positioning.
Sorry, you need to Log In to post a reply to this thread.