More text wrapping stuff

master
E. Almqvist 5 years ago
parent b08cdecbc6
commit d3770ef811
  1. 37
      gamemode/engine/derma/lib/cl_menu_dialogueBox.lua
  2. 2
      gamemode/settings/sh_dialogues.lua

@ -12,6 +12,16 @@ local padding_s = 4 * scale
local theme = Quantum.Client.Menu.GetAPI( "theme" )
function log.appendLinesToStr(tbl)
local out = ""
for _, l in SortedPairs(tbl) do
if(l != nil) then
out = out .. l
end
end
return out
end
function log.genTextLinebreak( txt, font, maxW )
local wordlist = string.Split( txt, " " ) -- all words are seperated by spaces
local lines = {}
@ -33,17 +43,22 @@ function log.genTextLinebreak( txt, font, maxW )
for _, wordI in pairs(wordsUsed) do
wordlist[wordI] = nil
end
else
-- append the last sentence
table.insert(lines, log.appendLinesToStr(wordlist))
end
end
return lines
end
function log.appendLinesToStr(tbl)
local out = ""
for _, l in SortedPairs(tbl) do
out = out .. l
end
return out
function log.setHeightToLines( p, lines, font, add )
add = add || 0
surface.SetFont(font)
local _, h = surface.GetTextSize("Quantum")
print(#lines)
PrintTable(lines)
p:SetHeight((#lines * h) + (#lines * padding_s) + add)
end
function log.createDialogueBox( logdata, parent )
@ -55,8 +70,16 @@ function log.createDialogueBox( logdata, parent )
local maxW, maxH = 775 * scale, 160 * scale
box:SetSize( maxW, maxH )
box.Paint = function( self, w, h )
-- background blur
theme.renderblur( self, 2, 7 )
-- background
surface.SetDrawColor( 20, 20, 20, 220 )
surface.DrawRect( 0, 0, w, h )
-- outline
surface.SetDrawColor( 220, 220, 220, 100)
surface.DrawOutlinedRect( 0, 0, w, h )
end
local scroll = vgui.Create( "DScrollPanel", box )
@ -83,7 +106,7 @@ function log.createDialogueBox( logdata, parent )
text.w, text.h = text:GetSize()
text:SetPos(padding, padding)
box:SizeToChildren( false, true )
log.setHeightToLines(box, text.lines, text:GetFont(), padding*2)
box.w, box.h = box:GetSize()
if( box.h > maxH ) then

@ -9,7 +9,7 @@
---- CREATE DIALOGUE INSTANCES UNDER THIS LINE ----
Quantum.Dialogue.Create( "npc_generalvendor" )
Quantum.Dialogue.AddQuestion( "npc_generalvendor", "init", "What do you want? I don't have time for any shenanigans right now! Go away! REEEEEEEEEEEEEE! Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mi leo, blandit in ullamcorper sit amet, tristique in purus. Morbi vehicula suscipit faucibus. Quisque ultricies nisl magna, quis facilisis sem aliquam id. Integer non est sagittis, laoreet ipsum et, euismod odio. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. In sollicitudin turpis eget libero maximus commodo." )
Quantum.Dialogue.AddQuestion( "npc_generalvendor", "init", "What do you want? I don't have time for any shenanigans right now!" )
Quantum.Dialogue.AddResponse( "npc_generalvendor", "init", {
text = "To do business.",

Loading…
Cancel
Save