More text wrapping stuff

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

@ -9,7 +9,7 @@
---- CREATE DIALOGUE INSTANCES UNDER THIS LINE ---- ---- CREATE DIALOGUE INSTANCES UNDER THIS LINE ----
Quantum.Dialogue.Create( "npc_generalvendor" ) 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", { Quantum.Dialogue.AddResponse( "npc_generalvendor", "init", {
text = "To do business.", text = "To do business.",

Loading…
Cancel
Save