fix buffer :)

Pawkette [03-01-14 - 16:46]
fix buffer :)
Filename
Console.lua
Console.xml
LogList.lua
diff --git a/Console.lua b/Console.lua
index e3cc194..85515b9 100644
--- a/Console.lua
+++ b/Console.lua
@@ -95,10 +95,16 @@ function Console:Initialize( control )

     self.control:SetHandler( 'OnUpdate', function() self:OnUpdate() end )
     self.closeBtn:SetHandler( 'OnClicked', function() self:Hide() end )
-    self.clearBtn:SetHandler( 'OnClicked', function() self.textBuffer:Clear() end )
+    self.clearBtn:SetHandler( 'OnClicked', function() self:OnClear() end )
     self.textBuffer:SetHandler( 'OnMouseWheel', function( ... ) self:OnScroll( ... ) end )
 end

+function Console:OnClear()
+    self.textBuffer:Clear()
+    self.log_lines:Clear()
+    self.last_index = self.log_lines:First()
+end
+
 function Console:IsDirty( flag )
     if ( not flag ) then return #self.dirty_flags ~= 0 end

@@ -118,14 +124,13 @@ function Console:OnUpdate()

     if ( self:IsDirty( DirtyFlags.FILTER_CHANGED ) ) then
         self.textBuffer:Clear()
-        self.last_index = 1
-        self:AddNewLines()
-        self.last_index = self.log_lines:Last()
+        self.last_index = self.log_lines:First()
+        table.insert( self.dirty_flags, DirtyFlags.NEW_LINES )
     end

     if ( self:IsDirty( DirtyFlags.NEW_LINES ) ) then
         self:AddNewLines()
-        self.last_index = self.log_lines:Last()
+        self.last_index = self.log_lines:Last() + 1
     end

     self.dirty_flags = {}
@@ -135,7 +140,7 @@ function Console:AddNewLines()
     local color = {}
     local entry = {}
     for i = self.last_index, self.log_lines:Last(), 1 do
-        entry = self.log_lines[ i ]
+        entry = self.log_lines:At( i )
         if ( self.log_level >= entry:GetTag() ) then
             color = LogLevelColors[ entry:GetTag() ]
             self.textBuffer:AddMessage( entry:GetFormatted(), color.r, color.g, color.b, nil )
@@ -186,6 +191,10 @@ function Console:Log( logLevel, fmt, ... )

     if ( self.log_lines:Size() > 500 ) then
         self.log_lines:Pop()
+
+        if ( self.last_index == 1 ) then -- we haven't iterated over this yet
+            self.last_index = self.log_level:First()
+        end
     end

     self.log_lines:Push( LogLine:New( logLevel, GetTimeString(), fmt:format( ... ) ) )
@@ -230,6 +239,7 @@ end
 -- @tparam table self
 function Pky_Console_Initialized( self )
     CONSOLE = Console:New( self )
+    CONSOLE:Hide()
     SLASH_COMMANDS['/console']  = function( ... ) CONSOLE:Show() end
     SLASH_COMMANDS['/d']        = function( ... ) CONSOLE:Show() end
 end
\ No newline at end of file
diff --git a/Console.xml b/Console.xml
index 518da42..c8e818e 100644
--- a/Console.xml
+++ b/Console.xml
@@ -37,7 +37,7 @@
                     <Anchor point="TOPLEFT" offsetX="-80" offsetY="30" />
                     <Anchor point="TOPRIGHT" offsetX="80" offsetY="30" />
                 </Texture>
-                <TextBuffer name="$(parent)_Buffer" font="ZoFontChat" maxHistoryLines="200" mouseEnabled="true">
+                <TextBuffer name="$(parent)_Buffer" font="ZoFontChat" maxHistoryLines="500" mouseEnabled="true">
                     <Anchor point="TOPLEFT" offsetX="8" offsetY="30" />
                     <Anchor point="BOTTOMRIGHT" offsetX="-8" offsetY="-35" />
                     <!--<LineFade fadeBegin="60" fadeDuration="2" />-->
diff --git a/LogList.lua b/LogList.lua
index 17a5b5e..44dcb88 100644
--- a/LogList.lua
+++ b/LogList.lua
@@ -8,8 +8,9 @@

 LogList =
 {
-    first = 0,
-    last = -1,
+    first = 1,
+    last = 0,
+    data = {}
 }

 function LogList:New( ... )
@@ -26,7 +27,7 @@ end

 function LogList:Push( value )
     self.last = self.last + 1
-    self[ self.last ] = value
+    self.data[ self.last ] = value
 end

 function LogList:Pop()
@@ -34,8 +35,8 @@ function LogList:Pop()
         return nil
     end

-    local value = self[ self.first ]
-    self[ self.first ] = nil
+    local value = self.data[ self.first ]
+    self.data[ self.first ] = nil

     self.first = self.first + 1
 end
@@ -50,4 +51,14 @@ end

 function LogList:Last()
     return self.last
+end
+
+function LogList:Clear()
+    self.data = {}
+    self.first = 1
+    self.last = 0
+end
+
+function LogList:At( index )
+    return self.data[ index ]
 end
\ No newline at end of file