From 5fe5be4a5f172e9bfd0584988fd69e99baac088d Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Fri, 29 May 2020 11:45:17 +0200 Subject: [PATCH] Dialogue menu stuff --- .../engine/derma/lib/cl_menu_dialogueBox.lua | 97 +++++++++++++------ gamemode/engine/derma/lib/cl_menu_theme.lua | 13 +++ gamemode/engine/derma/menus/menu_dialogue.lua | 15 ++- gamemode/settings/sh_dialogues.lua | 5 + 4 files changed, 101 insertions(+), 29 deletions(-) diff --git a/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua b/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua index 31f4cb0..f4f648a 100644 --- a/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua +++ b/gamemode/engine/derma/lib/cl_menu_dialogueBox.lua @@ -56,45 +56,89 @@ 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 ) - cinematic = cinematic || true - local fw, fh = parent:GetSize() - local logtext = logdata["init"].question +local maxW, maxH = 775 * scale, 160 * scale + +function log.createOptionButton( parent, index, text, font ) + local btn = parent:Add("DButton") + btn:SetContentAlignment(4) + btn:SetText(text) + btn:SetFont(font) + btn:SetTextColor( Color( 255, 255, 255, 200 ) ) + btn.index = index + btn.w, btn.h = maxW - padding*4, 40 * scale + btn:SetSize( btn.w, btn.h ) + btn.Paint = function( self ) + theme.renderblur( self, 2, 6 ) + theme.sharpbutton( self, Color( 20, 20, 20, 220) ) + end + + function btn:UpdateSize( add ) + local font, lines = self:GetFont(), log.genTextLinebreak( self:GetText(), font, btn.w ) + self:SetText( log.appendLinesToStr(lines, " ") ) + log.setHeightToLines(self, lines, font, add) + self.w, self.h = self:GetSize() + + self:Dock(TOP) + self:DockMargin( padding_s*4, 0, padding_s*4, padding_s*2 ) + return self + end + return btn +end +function log.createContainer( parent, hide ) local box = vgui.Create( "DPanel", 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 ) + box.Paint = function( self ) + if( !hide ) then + theme.dialogueBox(self) + end + end + box.w, box.h = maxW, maxH + + function box:UpdateSize( lines, font, add ) + log.setHeightToLines(self, lines, font, add) + + self.w, self.h = self:GetSize() + if( self.h > maxH ) then + self:SetHeight(maxH) + end + self.w, self.h = self:GetSize() - -- outline - surface.SetDrawColor( 220, 220, 220, 100) - surface.DrawOutlinedRect( 0, 0, w, h ) + return self end local scroll = vgui.Create( "DScrollPanel", box ) scroll:SetSize( box:GetSize() ) scroll.Paint = function( self ) end local sb = scroll:GetVBar() - sb.Paint = function( self ) end + sb.Paint = Quantum.EmptyFunction function sb.btnGrip:Paint() - theme.button( self, Color( 0, 0, 0, 0 ) ) + theme.blurpanel(self) end + sb:SetWidth(padding) + sb.btnUp:SetSize(0,0) + sb.btnUp.Paint = function(self) end + sb.btnDown:SetSize(0,0) + sb.btnDown.Paint = function(self) end + scroll:SetSize( box:GetSize() ) scroll.w, scroll.h = scroll:GetSize() + return box, scroll +end + +function log.createQBox( logdata, parent ) + cinematic = cinematic || true + local fw, fh = parent:GetSize() + local logtext = logdata["init"].question + + local box, scroll = log.createContainer( parent ) + local text = vgui.Create( "DLabel", scroll ) text:SetFont( "q_dialogue_question" ) text.lines = log.genTextLinebreak( logtext, text:GetFont(), maxW - (padding) ) @@ -106,16 +150,13 @@ function log.createDialogueBox( logdata, parent ) text.w, text.h = text:GetSize() text:SetPos(padding, padding) - log.setHeightToLines(box, text.lines, text:GetFont(), padding*2) - - box.w, box.h = box:GetSize() - if( box.h > maxH ) then - box:SetHeight(maxH) - end - box:SetPos( fw/2 - box.w/2, fh*0.7 ) + box:UpdateSize( text.lines, text:GetFont(), padding*2 ) + box:SetPos( fw/2 - box.w/2, fh*0.65 ) - return box + return box, text end + + function log.createinfobox( logdata, parent, cinematic ) cinematic = cinematic || true local fw, fh = parent:GetSize() @@ -124,7 +165,7 @@ function log.createinfobox( logdata, parent, cinematic ) local box = vgui.Create( "DPanel", parent ) box:SetSize( 775 * scale, 200 * scale ) - box.Paint = function( self ) theme.sharpblurpanel( self ) end + box.Paint = function( self ) theme.dialogueBox( self ) end box.w, box.h = box:GetSize() box:SetPos( fw/2 - box.w/2, fh*0.8 - box.h/2 ) box.x, box.y = box:GetPos() diff --git a/gamemode/engine/derma/lib/cl_menu_theme.lua b/gamemode/engine/derma/lib/cl_menu_theme.lua index a90ae86..daa69ff 100644 --- a/gamemode/engine/derma/lib/cl_menu_theme.lua +++ b/gamemode/engine/derma/lib/cl_menu_theme.lua @@ -260,6 +260,19 @@ function theme.fadebutton( b, dir, inColor, font, txtColor ) end +function theme.dialogueBox( p ) + local w, h = p:GetSize() + -- background blur + theme.renderblur( p, 2, 7 ) + + -- background + surface.SetDrawColor( 20, 20, 20, 220 ) + surface.DrawRect( 0, 0, w, h ) + + -- outline + surface.SetDrawColor( 220, 220, 220, 60) + surface.DrawOutlinedRect( 0, 0, w, h ) +end ---- Color Manipulation ---- theme.color = {} diff --git a/gamemode/engine/derma/menus/menu_dialogue.lua b/gamemode/engine/derma/menus/menu_dialogue.lua index 725fc27..0521313 100644 --- a/gamemode/engine/derma/menus/menu_dialogue.lua +++ b/gamemode/engine/derma/menus/menu_dialogue.lua @@ -92,8 +92,21 @@ function menu.open( dt ) title.w, title.h = title:GetSize() title:SetPos(padding*2, borderHeight/2 - title.h/2) + -- Dialogue options + f.dialogue.cont, f.dialogue.contScroll = log.createContainer( f, true ) + f.dialogue.cont.options = {} + local btnFont = "q_info" + for i, option in SortedPairs(dialogue["init"].response) do + f.dialogue.cont.options[i] = log.createOptionButton( f.dialogue.contScroll, i, option.text, btnFont ) + f.dialogue.cont.options[i]:UpdateSize(padding_s) + end + + f.dialogue.cont:SetPos( f.w/2 - f.dialogue.cont.w/2, f.h - f.dialogue.cont.h - padding ) + f.dialogue.cont.x, f.dialogue.cont.y = f.dialogue.cont:GetPos() + -- Dialogue question - f.dialogue.q = log.createDialogueBox( dialogue, f ) + f.dialogue.q, f.dialogue.qtext = log.createQBox( dialogue, f ) + f.dialogue.q:SetPos( f.w/2 - f.dialogue.q.w/2, f.dialogue.cont.y - f.dialogue.q.h - padding*2 ) return f end diff --git a/gamemode/settings/sh_dialogues.lua b/gamemode/settings/sh_dialogues.lua index 9480c6b..453de02 100644 --- a/gamemode/settings/sh_dialogues.lua +++ b/gamemode/settings/sh_dialogues.lua @@ -18,6 +18,11 @@ Quantum.Dialogue.Create( "npc_generalvendor" ) print("You pressed this response!") end }, 1 ) + + Quantum.Dialogue.AddResponse( "npc_generalvendor", "init", { + text = "To take all of your money! Aaaaa aaaa a aa a a a aa aa a aa a a a aa aa a a a a aaaaaaaaaaaaaaaaa a a a a aa a a a a aa a aa a aa a a a aaaa a a aa a aa aa aa!" + + }, 2 ) Quantum.Dialogue.AddQuestion( "npc_generalvendor", "sellorbuy", "What do you have in mind?" )