Browse Source

Add option to save messages from channel

Konrad Kuśnierz 5 years ago
parent
commit
f9d183837a
1 changed files with 21 additions and 1 deletions
  1. 21
    1
      modules/game_console/console.lua

+ 21
- 1
modules/game_console/console.lua View File

@@ -679,8 +679,28 @@ function processChannelTabMenu(tab, mousePos, mouseButton)
679 679
 
680 680
   if consoleTabBar:getCurrentTab() == tab then
681 681
     menu:addOption(tr('Clear Messages'), function() clearChannel(consoleTabBar) end)
682
+    menu:addOption(tr('Save Messages'), function()
683
+      local panel = consoleTabBar:getTabPanel(tab)
684
+      local consoleBuffer = panel:getChildById('consoleBuffer')
685
+      local lines = {}
686
+      for _,label in pairs(consoleBuffer:getChildren()) do
687
+        table.insert(lines, label:getText())
688
+      end
689
+
690
+      local filename = channelName .. '.txt'
691
+      local filepath = '/' .. filename
692
+
693
+      -- extra information at the beginning
694
+      table.insert(lines, 1, os.date('\nChannel saved at %a %b %d %H:%M:%S %Y'))
695
+
696
+      if g_resources.fileExists(filepath) then
697
+        table.insert(lines, 1, signalcall(g_resources.readFileContents, filepath) or '')
698
+      end
699
+
700
+      g_resources.writeFileContents(filepath, table.concat(lines, '\n'))
701
+      modules.game_textmessage.displayStatusMessage(tr('Channel appended to %s', filename))
702
+    end)
682 703
   end
683
-  --menu:addOption(tr('Save Messages'), function() --[[TODO]] end)
684 704
 
685 705
   menu:display(mousePos)
686 706
 end

Loading…
Cancel
Save