Advertisement
MjnMixael

Untitled

Mar 1st, 2015
278
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.69 KB | None | 0 0
  1. #Conditional Hooks
  2. $Application: FS2_Open
  3.  
  4. $On Game Init:
  5. [
  6.  
  7. Journal = {}
  8.  
  9. --INITIALIZE
  10. function Journal:Init()
  11.  
  12. ba.print("*****Initializing Journal System...\n")
  13.  
  14. if self.Ingame then
  15. AXUI.InGame = false
  16. AXUI:ScreenInit()
  17. self.Time = mn.getMissionTime
  18. else
  19. self.Time = ba.getFrametimeOverall
  20. end
  21.  
  22. self.FullScreen = {w = gr.getScreenWidth(), h = gr.getScreenHeight()}
  23. self.LastClicked = nil
  24.  
  25. AXUI:SetFocus(0)
  26.  
  27. self:SetRead()
  28.  
  29. self.Player = ba.getCurrentPlayer()
  30. self.PlayerName = self:GetPlayerName()
  31. self.Fonts = {}
  32.  
  33. --All the config data we need is here
  34. self.JournalConfig = axemParse:ToTable("journal_" .. self.Player:getCampaignFilename() .. "_config.cfg", true)
  35. if self.JournalConfig then
  36. if self.JournalConfig[99] then
  37. self.Fonts = self.JournalConfig[99]
  38.  
  39. if self.Fonts.SmallFont then
  40. AXUI.Fonts.Small = gr.Fonts[self.Fonts.SmallFont]
  41. end
  42.  
  43. if self.Fonts.LargeFont then
  44. AXUI.Fonts.Medium = gr.Fonts[self.Fonts.LargeFont]
  45. end
  46.  
  47. end
  48.  
  49. for i = 1, 3 do
  50. if self.JournalConfig[i].Name == "!Special" then
  51. local database = axemParse:Open(self.JournalConfig[i].File)
  52. self.JournalConfig[i].Name = database[math.random(#database)]
  53. --local key = os.date("%W")
  54. --self.JournalConfig[i].Name = database[math.floor(key / 2) + key % 2]
  55. self.JournalConfig[i].AuthorizedContent = true
  56. end
  57. end
  58.  
  59. end
  60.  
  61. --Let's make some buttans!
  62. self.Buttons = {}
  63.  
  64. ba.print("About to make...\n")
  65. ba.print("Exit button\n")
  66. self.Buttons.Exit = AXUI:CreateButton("Exit", 920, 694, 0, -30, "white", "ui_light_pink", "ui_pink", nil, 0, 0, "2_CAB_050001", "2_CAB_050002", true, 0, self.Fonts.ButtonFont)
  67.  
  68. ba.print("Text up down buttons\n")
  69. self.Buttons.TextUp = AXUI:CreateButton(nil, 3, 181, nil, nil, nil, nil, nil, nil, 0, 0, "2_CAB_000001", "2_CAB_000002", true, 0, self.Fonts.ButtonFont)
  70. self.Buttons.TextDown = AXUI:CreateButton(nil, 3, 255, nil, nil, nil, nil, nil, nil, 0, 0, "2_CAB_010001", "2_CAB_010002", true, 0, self.Fonts.ButtonFont)
  71.  
  72. ba.print("List up down buttons\n")
  73. self.Buttons.ListUp = AXUI:CreateButton(nil, 3, 590, nil, nil, nil, nil, nil, nil, 0, 0, "2_CAB_020001", "2_CAB_020002", true, 0, self.Fonts.ButtonFont)
  74. self.Buttons.ListDown = AXUI:CreateButton(nil, 3, 664, nil, nil, nil, nil, nil, nil, 0, 0, "2_CAB_030001", "2_CAB_030002", true, 0, self.Fonts.ButtonFont)
  75.  
  76. --We might be loading without a valid config, so lets not setup tabs then
  77. if self.JournalConfig then
  78. ba.print("Tab buttons\n")
  79. self.TabGroup = AXUI:CreateRadioGroup()
  80. if self.JournalConfig[1] then
  81. self.Buttons.Tab1 = AXUI:CreateButton(self.JournalConfig[1].Name, 12, 5, 48, 10, "grey", "ui_light_green", "ui_green", nil, 0, 0, "2_TSB_000001", "2_TSB_000002", true, 0, self.Fonts.ButtonFont)
  82. self.TabGroup:AddToGroup(self.Buttons.Tab1)
  83. end
  84.  
  85. if self.JournalConfig[2] then
  86. self.Buttons.Tab2 = AXUI:CreateButton(self.JournalConfig[2].Name, 12, 31, 48, 10, "grey", "ui_light_green", "ui_green", nil, 0, 0, "2_TSB_010001", "2_TSB_010002", true, 0, self.Fonts.ButtonFont)
  87. self.TabGroup:AddToGroup(self.Buttons.Tab2)
  88. end
  89.  
  90. if self.JournalConfig[3] then
  91. self.Buttons.Tab3 = AXUI:CreateButton(self.JournalConfig[3].Name, 12, 56, 48, 10, "grey", "ui_light_green", "ui_green", nil, 0, 0, "2_TSB_020001", "2_TSB_020002", true, 0, self.Fonts.ButtonFont)
  92. self.TabGroup:AddToGroup(self.Buttons.Tab3)
  93. end
  94.  
  95. end
  96.  
  97. ba.print("ListBox\n")
  98. self.ListBox = AXUI:CreateListBox(nil, 80, 575, 745, 200, "grey", "blue", "bright_blue", true, 0, self.ListFont)
  99.  
  100. if self.Buttons.Tab1 then
  101. self.TabGroup:SwitchTo(1)
  102. self:LoadTab(1)
  103. end
  104.  
  105. end
  106.  
  107. --So Freespace doesn't like 32 or more character filenames, so we'll just truncate the player name so we keep it under the required limit
  108. function Journal:GetPlayerName()
  109.  
  110. local player = ba.getCurrentPlayer()
  111. local campaignfilename = player:getCampaignFilename()
  112. local maxnamelength = 32 - ("..1.sav."):len() - campaignfilename:len()
  113. local name = player:getName()
  114. --ba.print("MAX NAME LENGTH: " .. maxnamelength .. "\n")
  115. return string.sub(name, 1, maxnamelength)
  116.  
  117. end
  118.  
  119. --Load a tab, setup elements, etc
  120. function Journal:LoadTab(tab)
  121.  
  122. self.CurrentTab = self.JournalConfig[tab]
  123. self.CurrentTab.SaveFilename = self.Player:getCampaignFilename() .. "." .. self.PlayerName .. "." .. tab .. ".sav"
  124.  
  125. if Journal.SSLKey == "" or false or not not not not self.CurrentTab.AuthorizedContent ~= true then
  126.  
  127. --SetupTable will load the table and only return entries that will be visible to the player
  128. self.TabEntry = self:SetupTable(axemParse:ToTable(self.CurrentTab.File), self.CurrentTab.RevSort)
  129.  
  130. --Populate the list box
  131. local titleList = {}
  132.  
  133. for i = 1, #self.TabEntry do
  134. titleList[i] = self.TabEntry[i].Title
  135. end
  136.  
  137. self.ListBox:ChangeList(titleList)
  138. self.ListBox.Group:SwitchTo(1)
  139.  
  140. end
  141.  
  142. local style = string.lower(self.CurrentTab.Style)
  143.  
  144. --Create the interface items we need and nil the rest
  145.  
  146. if style == "fulltext" then
  147. self.TextBox = AXUI:CreateTextBox(nil, 75, 160, 850, 320, "white", true, self.CurrentTab.Font)
  148. self.ImageBox = nil
  149. self.Thumbnails = nil
  150. self.FullImage = nil
  151. self.Buttons.CloseImage = nil
  152. self.Buttons.NextImage = nil
  153. self.Buttons.PrevImage = nil
  154. self.httpstream = nil
  155. self:ShowContent(1)
  156.  
  157. elseif style == "imagetext" then
  158. self.TextBox = AXUI:CreateTextBox(nil, 310, 160, 635, 320, "white", true, self.CurrentTab.Font)
  159. self.ImageBox = AXUI:CreateImageBox(nil, 60, 175, nil, "white", 245, 320, true, false, true, self.CurrentTab.CaptionFont)
  160. self.Thumbnails = nil
  161. self.FullImage = nil
  162. self.Buttons.CloseImage = nil
  163. self.Buttons.NextImage = nil
  164. self.Buttons.PrevImage = nil
  165. self.httpstream = nil
  166. self:ShowContent(1)
  167.  
  168. elseif style == "thumbnails" then
  169. self.TextBox = nil
  170. self.ImageBox = nil
  171. self.FullImage = nil
  172. self.Thumbnails = AXUI:CreateThumbnails(nil, 75, 175, 900, 375, 200, 120, 25, 60, true, 0, self.CurrentTab.Font)
  173. self.ListBox:ChangeList(nil)
  174. self.Buttons.CloseImage = nil
  175. self.Buttons.NextImage = nil
  176. self.Buttons.PrevImage = nil
  177. self.httpstream = nil
  178. self.Thumbnails:ChangeThumbnailList(self.TabEntry)
  179. elseif style == "httpstream" then
  180. self.TextBox = nil
  181. self.ImageBox = nil
  182. self.FullImage = nil
  183. self.Thumbnails = nil
  184. self.ListBox:ChangeList(nil)
  185. self.Buttons.CloseImage = nil
  186. self.Buttons.NextImage = nil
  187. self.Buttons.PrevImage = nil
  188. self.httpstream = ba.getFrametimeOverall()
  189. end
  190.  
  191. end
  192.  
  193. --Checks for saved data, since we can't depend on the index (since it can change) we check the title for a match. String comparisons may suck but we're not dealing with too many and its just once a tab change.
  194. function Journal:ApplySaveData(t, data)
  195.  
  196. --t should be the tab file
  197. --data should be the ***loaded*** save data (parseToTable should already have been called)
  198.  
  199. for i = 1, #t do
  200. for j = 1 , #data do
  201. if t[i].Title == data[j].Title then
  202.  
  203. t[i].Visible = data[j].Visible
  204. t[i].Read = data[j].Read
  205.  
  206. end
  207. end
  208. end
  209.  
  210. end
  211.  
  212. --Take t and apply them appropriately and sort if needed
  213. function Journal:SetupTable(t, sorting)
  214.  
  215. local finalT = {}
  216. local savedData = {}
  217. local startAt = 1
  218. local endAt = #t
  219. local step = 1
  220. local index = 1
  221. local fileName = self.CurrentTab.SaveFilename
  222.  
  223. for i = 1, #t do
  224. if t[i].File then
  225. local thisFile = cf.openFile(t[i].File,"rb","data/fiction")
  226. local text = thisFile:read("*a")
  227. t[i].Text = text
  228. end
  229. end
  230.  
  231. if cf.fileExists(fileName, "data/config", true) then
  232. savedData = axemParse:ToTable(fileName) --Loads the saved data
  233. else
  234. savedData = self:SaveData(t, fileName) --If no saved data exists, we create it here.
  235. end
  236.  
  237. self:ApplySaveData(t, savedData)
  238.  
  239. --Reverse sort action
  240. if sorting then
  241. startAt = #t
  242. endAt = 1
  243. step = -1
  244. end
  245.  
  246. for i = startAt, endAt, step do
  247. if t[i].Visible then
  248. finalT[index] = t[i]
  249. index = index + 1
  250. end
  251. end
  252.  
  253. return finalT
  254.  
  255. end
  256.  
  257. --Save required t fields to fileName
  258. function Journal:SaveData(t, fileName)
  259.  
  260. --We only need to save the Title, Visiblity and Read status.
  261.  
  262. local data = {}
  263.  
  264. for i = 1, #t do
  265. data[i] = {}
  266. data[i].Title = t[i].Title
  267. data[i].Visible = t[i].Visible
  268. data[i].Read = t[i].Read
  269. end
  270.  
  271. axemParse:Write(data, fileName, "data/config") --axemParse is in parsecfg-sct.tbm
  272.  
  273. return data
  274.  
  275. end
  276.  
  277. function Journal:ConnectHTTP(server)
  278.  
  279. --TODO: Later
  280.  
  281. return false
  282.  
  283. end
  284.  
  285. --Show requested content
  286. function Journal:ShowContent(index)
  287.  
  288. self.ContentIndex = index
  289.  
  290. --If we've viewed an entry, mark is read and save the data
  291. if self.TabEntry[index].Read ~= true then
  292. self.TabEntry[index].Read = true
  293. self:SaveData(self.TabEntry, self.CurrentTab.SaveFilename)
  294. end
  295.  
  296. --If there's a text box around, display its text
  297. if self.TextBox then
  298. self.TextBox:ChangeText(self.TabEntry[index].Text)
  299. end
  300.  
  301. --If there's an image box, toss up the image and the caption
  302. if self.ImageBox then
  303. if self.TabEntry[index].Caption then
  304. self.ImageBox:ChangeText(self.TabEntry[index].Caption)
  305. else
  306. self.ImageBox:ChangeText(nil)
  307. end
  308.  
  309. if self.TabEntry[index].Image then
  310. self.ImageBox:ChangeImage(self.TabEntry[index].Image)
  311. else
  312. self.ImageBox:ChangeImage(nil)
  313. end
  314.  
  315. --If there's an available FullImage, generate a zoom button
  316. if self.TabEntry[index].FullImage then
  317. self.Buttons.Zoom = AXUI:CreateButton(nil, 0, 0, nil, nil, nil, nil, nil, "axui_zoomin", 0, 0, "axui_zoomin_h", "axui_zoomin_c", false, 0)
  318. self.Buttons.Zoom.BitmapX = self.ImageBox.BitmapX + self.ImageBox.BitmapWidth - gr.getImageWidth("axui_zoomin")
  319. self.Buttons.Zoom.BitmapY = self.ImageBox.BitmapY
  320. self.Buttons.Zoom:CalculateRegion()
  321. else
  322. self.Buttons.Zoom = nil
  323. end
  324.  
  325. end
  326.  
  327. --If there's thumbnails...
  328. if self.Thumbnails then
  329.  
  330. self.Thumbnails.Index = index
  331.  
  332. local thisItem = self.Thumbnails.Items[index]
  333.  
  334. --Thumbnail images need a slightly different way of saving their info
  335. if thisItem.Read ~= true then
  336. thisItem.Read = true
  337. self:SaveData(self.Thumbnails.Items, self.CurrentTab.SaveFilename)
  338. end
  339.  
  340. Journal:DisplayFullImage(thisItem.Image) --This will also create a close button
  341.  
  342. local halfHeight = (gr.getScreenHeight() / 2) - (gr.getImageHeight("axui_right") / 2) --This is cheating, but I make the rules here
  343.  
  344. --Making the next and prev buttons
  345. self.Buttons.NextImage = AXUI:CreateButton(nil, AXUI.Screen.w - gr.getImageWidth("axui_right"), halfHeight, nil, nil, nil, nil, nil, "axui_right", 0, 0, "axui_right_h", "axui_right_c", false, 1)
  346.  
  347. self.Buttons.PrevImage = AXUI:CreateButton(nil, 0, halfHeight, nil, nil, nil, nil, nil, "axui_left", 0, 0, "axui_left_h", "axui_left_c", false, 1)
  348.  
  349. end
  350.  
  351. end
  352.  
  353. --Display a large image, across the entire screen and centered
  354. function Journal:DisplayFullImage(imagefilename)
  355.  
  356. self.FullImage = AXUI:CreateImageBox(imagefilename, 0, 0, nil, nil, AXUI.Screen.w, AXUI.Screen.h, true, true, false)
  357.  
  358. --Generate the close button
  359. self.Buttons.CloseImage = AXUI:CreateButton(nil, 0, 0, nil, nil, nil, nil, nil, "axui_close", 0, 0, "axui_close_h", "axui_close_c", false, 1)
  360.  
  361. --If the close button would be off screen, we should move it so its visible, if not, move it to the top right corner
  362. if (self.Buttons.CloseImage.BitmapX + self.Buttons.CloseImage.BitmapWidth) > AXUI.Screen.w then
  363. self.Buttons.CloseImage.BitmapX = AXUI.Screen.w - self.Buttons.CloseImage.BitmapWidth
  364. else
  365. self.Buttons.CloseImage.BitmapX = self.FullImage.BitmapX + self.FullImage.BitmapWidth - gr.getImageWidth("axui_close")
  366. end
  367.  
  368. if self.Buttons.CloseImage.BitmapY < 0 then
  369. self.Buttons.CloseImage.BitmapY = 0
  370. else
  371. self.Buttons.CloseImage.BitmapY = self.FullImage.BitmapY
  372. end
  373.  
  374. self.Buttons.CloseImage:CalculateRegion()
  375.  
  376. end
  377.  
  378. --DRAW THINGS
  379. function Journal:Draw()
  380.  
  381. gr.setColor(0,0,0,255)
  382. gr.drawRectangle(0,0,self.FullScreen.w, self.FullScreen.h)
  383.  
  384. --The background
  385. gr.drawImage("2_Journal",AXUI.Screen.x,AXUI.Screen.y,AXUI.Screen.x + AXUI.Screen.w,AXUI.Screen.y + AXUI.Screen.h)
  386.  
  387. --These buttons are always visible
  388. self.Buttons.Exit:Draw()
  389. self.Buttons.TextUp:Draw()
  390. self.Buttons.TextDown:Draw()
  391. self.Buttons.ListUp:Draw()
  392. self.Buttons.ListDown:Draw()
  393.  
  394. --These might not be, so only draw if they're not nil
  395. if self.Buttons.Tab1 then
  396. self.Buttons.Tab1:Draw()
  397. end
  398.  
  399. if self.Buttons.Tab2 then
  400. self.Buttons.Tab2:Draw()
  401. end
  402.  
  403. if self.Buttons.Tab3 then
  404. self.Buttons.Tab3:Draw()
  405. end
  406.  
  407. if self.TextBox then
  408. self.TextBox:Draw()
  409. end
  410.  
  411. if self.ImageBox then
  412. self.ImageBox:Draw()
  413.  
  414. if self.Buttons.Zoom then
  415. self.Buttons.Zoom:Draw()
  416. end
  417.  
  418. end
  419.  
  420. if self.ListBox then
  421. if self.ListBox.List then
  422. self.ListBox:DrawList()
  423.  
  424. --Displaying read notification (in red!)
  425. for i = 1, self.ListBox.ItemLines do
  426. if self.TabEntry[i + self.ListBox.ItemOffset].Read ~= true then
  427. AXUI:SetColor("red")
  428. gr.drawString("new", self.ListBox.Item[i].TextX - gr.getStringWidth("new") - 5, self.ListBox.Item[i].TextY)
  429. end
  430. end
  431. end
  432. end
  433.  
  434. if self.httpstream then
  435.  
  436. if not self:ConnectHTTP() then
  437. local ctime = ba.getFrametimeOverall() -- measure timeout
  438. local status, status2
  439.  
  440. if ctime < (self.httpstream + 10) then
  441. status = "Connecting to JADPlay server"
  442. status2 = status .. string.rep(".",(math.floor(ba.getFrametimeOverall() - self.httpstream) % 3)+1)
  443. AXUI:SetColor("bright_white")
  444. else
  445. status = "Cannot connect to server\n Try Again Later"
  446. status2 = status
  447. AXUI:SetColor("bright_red")
  448. end
  449.  
  450. gr.CurrentFont = gr.Fonts[2]
  451.  
  452. local x, y = AXUI.Screen.x + (AXUI.Screen.w / 2) - (gr.getStringWidth(status)/2), AXUI.Screen.y + (AXUI.Screen.h / 3)
  453. gr.drawString(status2, x, y)
  454.  
  455. gr.CurrentFont = gr.Fonts[1]
  456. else
  457. self:RenderWebpage(self.httpstream)
  458. end
  459.  
  460. end
  461.  
  462. if self.Thumbnails then
  463. self.Thumbnails:DrawThumbnails()
  464.  
  465. --Displaying read notification (in red!)
  466. for i = 1, #self.Thumbnails.Buttons do
  467. if self.Thumbnails.Items[i+self.Thumbnails.Offset].Read ~= true then
  468. AXUI:SetColor("red")
  469. gr.drawString("New!", self.Thumbnails.Buttons[i].BitmapX, self.Thumbnails.Buttons[i].BitmapY-11)
  470. end
  471. end
  472. end
  473.  
  474. if self.FullImage then
  475. gr.setColor(0,0,0,128) --Slightly dimming the background like the cool kids do
  476. gr.drawRectangle(0,0,gr.getScreenWidth(),gr.getScreenHeight(),true)
  477. self.FullImage:Draw()
  478. self.Buttons.CloseImage:Draw()
  479.  
  480. if self.Buttons.NextImage then
  481. self.Buttons.NextImage:Draw()
  482. self.Buttons.PrevImage:Draw()
  483. end
  484. end
  485.  
  486. end
  487.  
  488. --Anytime a mouse button goes up, we check to see if something was clicked, and if it was, we take an action. Anything that scrolls will return true or false, depending if the operation succeeded.
  489. function Journal:MonitorActions(pressed)
  490.  
  491. if pressed and self.MouseDown and self.MouseTimestamp and (Journal.MouseTimestamp < self.Time()) then
  492.  
  493. self.MouseTimestamp = self.Time() + 0.1
  494.  
  495. --Sigh, ScrollText uses positive numbers to go up and negative numbers to scroll thumbnails up. I'm sorry. :(
  496. if self.Buttons.TextUp:Clicked() then
  497. if self.TextBox then
  498. if self.TextBox:ScrollText(10) then
  499. ad.playInterfaceSound(0) --0 is the normal FreeSpace click sound
  500. else
  501. ad.playInterfaceSound(10) --10 is a fail sound
  502. end
  503. elseif self.Thumbnails then
  504. if self.Thumbnails:ScrollThumbnails(-1) then
  505. ad.playInterfaceSound(0)
  506. else
  507. ad.playInterfaceSound(10)
  508. end
  509. else
  510. ad.playInterfaceSound(10)
  511. end
  512. end
  513.  
  514. if self.Buttons.TextDown:Clicked() then
  515. if self.TextBox then
  516. if self.TextBox:ScrollText(-10) then
  517. ad.playInterfaceSound(0)
  518. else
  519. ad.playInterfaceSound(10)
  520. end
  521. elseif self.Thumbnails then
  522. if self.Thumbnails:ScrollThumbnails(1) then
  523. ad.playInterfaceSound(0)
  524. else
  525. ad.playInterfaceSound(10)
  526. end
  527. else
  528. ad.playInterfaceSound(10)
  529. end
  530. end
  531.  
  532. if self.Buttons.ListUp:Clicked() then
  533. if self.ListBox.List then
  534. if self.ListBox:ScrollList(-1) then
  535. ad.playInterfaceSound(0)
  536. else
  537. ad.playInterfaceSound(10)
  538. end
  539. else
  540. ad.playInterfaceSound(10)
  541. end
  542. end
  543.  
  544. if self.Buttons.ListDown:Clicked() then
  545. if self.ListBox.List then
  546. if self.ListBox:ScrollList(1) then
  547. ad.playInterfaceSound(0)
  548. else
  549. ad.playInterfaceSound(10)
  550. end
  551. else
  552. ad.playInterfaceSound(10)
  553. end
  554. end
  555.  
  556. elseif not pressed then
  557.  
  558. if self.Buttons.Exit:Clicked() then
  559.  
  560. ad.playInterfaceSound(7)
  561.  
  562. if self.Ingame then
  563.  
  564. if mn.SEXPVariables["music"]:isValid() and mn.SEXPVariables["oldMusic"]:isValid() then
  565.  
  566. local music = mn.SEXPVariables["music"]
  567. local oldMusic = mn.SEXPVariables["oldMusic"]
  568.  
  569. music.Value = oldMusic.Value
  570. oldMusic.Value = "NULL"
  571.  
  572. end
  573.  
  574. self.Ingame = nil
  575. self:CheckNew()
  576. self:Exit()
  577. AXUI.InGame = true
  578. AXUI:ScreenInit()
  579.  
  580. if CMap and CMap.Suspended then
  581. CMap.Enabled = true
  582. CMap.Suspended = nil
  583. end
  584.  
  585. return
  586.  
  587. else
  588.  
  589. Monitor:GoToState(Monitor.LastState) --Monitor is from imonitor-sct.tbm
  590.  
  591. end
  592. end
  593.  
  594. if self.Buttons.Tab1 then
  595. if self.Buttons.Tab1:Clicked() then
  596. ad.playInterfaceSound(0)
  597. self.TabGroup:SwitchTo(1)
  598. if not self.Thumbnails then
  599. self.ListBox.SelectedItem = 1
  600. end
  601. self:LoadTab(1)
  602. end
  603. end
  604.  
  605. if self.Buttons.Tab2 then
  606. if self.Buttons.Tab2:Clicked() then
  607. ad.playInterfaceSound(0)
  608. self.TabGroup:SwitchTo(2)
  609. if not self.Thumbnails then
  610. self.ListBox.SelectedItem = 1
  611. end
  612. self:LoadTab(2)
  613. end
  614. end
  615.  
  616. if self.Buttons.Tab3 then
  617. if self.Buttons.Tab3:Clicked() then
  618. ad.playInterfaceSound(0)
  619. self.TabGroup:SwitchTo(3)
  620. if not self.Thumbnails then
  621. self.ListBox.SelectedItem = 1
  622. end
  623. self:LoadTab(3)
  624. end
  625. end
  626.  
  627. if self.ListBox and self.ListBox.ItemLines then
  628. for i = 1, self.ListBox.ItemLines do
  629. if self.ListBox.Item[i]:Clicked() then
  630. ad.playInterfaceSound(0)
  631. self.ListBox.Group:SwitchTo(i)
  632. self.ListBox.SelectedItem = i + self.ListBox.ItemOffset
  633. self:ShowContent(i+self.ListBox.ItemOffset)
  634. end
  635. end
  636. end
  637.  
  638. if self.Thumbnails then
  639. for i = 1, #self.Thumbnails.Buttons do
  640. if self.Thumbnails.Buttons[i]:Clicked() then
  641. ad.playInterfaceSound(0)
  642. AXUI:SetFocus(1) --Focus is normally 0, but while in image mode, it should be 1 so only the full image buttons can be clicked
  643. self:ShowContent(i+self.Thumbnails.Offset)
  644. end
  645. end
  646. end
  647.  
  648. if self.Buttons.CloseImage then
  649. if self.Buttons.CloseImage:Clicked() then
  650. ad.playInterfaceSound(0)
  651. self.FullImage = nil
  652. self.Buttons.CloseImage = nil
  653. AXUI:SetFocus(0)
  654. end
  655. end
  656.  
  657. if self.Buttons.NextImage then
  658. if self.Buttons.NextImage:Clicked() then
  659. if (self.Thumbnails.Index + 1) > #self.Thumbnails.Items then
  660. self:ShowContent(1)
  661. else
  662. self:ShowContent(self.Thumbnails.Index + 1)
  663. end
  664. ad.playInterfaceSound(0)
  665. end
  666. end
  667.  
  668. if self.Buttons.PrevImage then
  669. if self.Buttons.PrevImage:Clicked() then
  670. if (self.Thumbnails.Index - 1) <= 0 then
  671. self:ShowContent(#self.Thumbnails.Items)
  672. else
  673. self:ShowContent(self.Thumbnails.Index - 1)
  674. end
  675. ad.playInterfaceSound(0)
  676. end
  677. end
  678.  
  679. if self.Buttons.Zoom then
  680. if self.Buttons.Zoom:Clicked() then
  681. ad.playInterfaceSound(0)
  682. AXUI:SetFocus(1) --Focus is normally 0, but while in image mode, it should be 1 so only the full image buttons can be clicked
  683. self:DisplayFullImage(self.TabEntry[self.ContentIndex].FullImage)
  684. end
  685. end
  686. end
  687. end
  688.  
  689. --When we exit we should make these things nil
  690. function Journal:Exit()
  691.  
  692. self.JournalConfig = nil
  693. self.TextBox = nil
  694. self.ImageBox = nil
  695. self.Thumbnails = nil
  696. self.FullImage = nil
  697. self.Buttons.CloseImage = nil
  698. self.Buttons.NextImage = nil
  699. self.Buttons.PrevImage = nil
  700.  
  701. self.Buttons = nil
  702. self.TabGroup = nil
  703. self.ListBox = nil
  704.  
  705. end
  706.  
  707. --This is what you use in FRED to make a non-visible item visible. Single quotes!
  708. function jsv(tab, title)
  709.  
  710. if mn.isInCampaign() then
  711.  
  712. local journalConfig = axemParse:ToTable("journal_" .. ba.getCurrentPlayer():getCampaignFilename() .. "_config.cfg", true)
  713. local tabEntry
  714. local fileName
  715.  
  716. if type(tab) == "number" then
  717. tabEntry = axemParse:ToTable(journalConfig[tab].File, true)
  718. fileName = ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. "." .. tab .. ".sav"
  719. else
  720. for i = 1, #journalConfig do
  721. if string.lower(tab) == string.lower(journalConfig[i].Name) then
  722. tabEntry = axemParse:ToTable(journalConfig[i].File, true)
  723. fileName = ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. "." .. i .. ".sav"
  724. break
  725. end
  726. end
  727. end
  728.  
  729. if cf.fileExists(fileName, "data/config", true) then
  730. local saveData = axemParse:ToTable(fileName, true)
  731. Journal:ApplySaveData(tabEntry, saveData)
  732. end
  733.  
  734. for j = 1, #tabEntry do
  735. if (tabEntry[j].ShortTitle and (string.lower(title) == string.lower(tabEntry[j].ShortTitle))) or (tabEntry[j].Title and (string.lower(title) == string.lower(tabEntry[j].Title))) then
  736. if tabEntry[j].Visible == false then
  737. tabEntry[j].Visible = true
  738. Journal:SaveData(tabEntry, fileName)
  739. Journal:SetNew()
  740. end
  741. end
  742. end
  743.  
  744. end
  745.  
  746. end
  747.  
  748. --And here we make entries invisible
  749. function jsi(tab, title)
  750.  
  751. if mn.isInCampaign() then
  752.  
  753. local journalConfig = axemParse:ToTable("journal_" .. ba.getCurrentPlayer():getCampaignFilename() .. "_config.cfg", true)
  754. local tabEntry
  755.  
  756. if not cf.fileExists(journalConfig[tab].File, "data/config", true) then
  757.  
  758. end
  759.  
  760. if type(tab) == number then
  761. tabEntry = axemParse:ToTable(journalConfig[tab].File, true)
  762. else
  763. for i = 1, #journalConfig do
  764. if string.lower(tab) == string.lower(journalConfig[i].Name) then
  765. tabEntry = axemParse:ToTable(journalConfig[i].File, true)
  766. break
  767. end
  768. end
  769. end
  770.  
  771. local fileName = ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. "." .. i .. ".sav"
  772.  
  773. if cf.fileExists(fileName, "data/config", true) then
  774. local saveData = axemParse:ToTable(fileName, true)
  775. Journal:ApplySaveData(tabEntry, saveData)
  776. end
  777.  
  778. for j = 1, #tabEntry do
  779. if (tabEntry[j].ShortTitle and (string.lower(title) == string.lower(tabEntry[j].ShortTitle))) or (tabEntry[j].Title and (string.lower(title) == string.lower(tabEntry[j].Title))) then
  780. tabEntry[j].Visible = false
  781. Journal:SaveData(tabEntry, fileName)
  782. --Journal:SetNew()
  783. end
  784. end
  785.  
  786. end
  787.  
  788. end
  789.  
  790. --And this is how we reset progress... by deleting the save files... Clumsy but it works!
  791. function Journal:ResetProgress()
  792.  
  793. if mn.isInCampaign() then
  794.  
  795. local journalConfig = axemParse:ToTable("journal_" .. ba.getCurrentPlayer():getCampaignFilename() .. "_config.cfg", true)
  796. local fileName = nil
  797.  
  798. for i = 1, #journalConfig do
  799. fileName = ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. "." .. i .. ".sav"
  800. cf.deleteFile(fileName, "data/config")
  801. end
  802.  
  803. end
  804.  
  805. end
  806.  
  807. --When we jsv we set a notify file to tell us is something is new
  808. function Journal:SetNew()
  809.  
  810. local file = cf.openFile(ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. ".n.sav", "w+", "data/config")
  811.  
  812. file:write("1")
  813. file:close()
  814.  
  815. end
  816.  
  817. --And we'll just make it an empty file when its been read
  818. function Journal:SetRead()
  819.  
  820. local file = cf.openFile(ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. ".n.sav", "w+", "data/config")
  821.  
  822. file:write("")
  823. file:close()
  824.  
  825. end
  826.  
  827. --Let's check for new entries!
  828. function Journal:CheckNew()
  829.  
  830. if cf.fileExists(ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. ".n.sav", "data/config", true) then
  831. self.NewEntries = axemParse:Open(ba.getCurrentPlayer():getCampaignFilename() .. "." .. Journal:GetPlayerName() .. ".n.sav")[1]
  832. else
  833. self:SetNew()
  834. self.NewEntries = 1
  835. end
  836.  
  837. end
  838.  
  839. --And draw something if there is
  840. function Journal:DrawNew()
  841.  
  842. AXUI:SetColor("red")
  843. gr.drawString("New!", Monitor.Buttons.Journal.BitmapX - gr.getStringWidth("New!") - 20, Monitor.Buttons.Journal.TextY)
  844.  
  845. end
  846.  
  847. function Journal:DrawNew2()
  848.  
  849. AXUI:SetColor("red")
  850. gr.drawString("New!", CMap.Buttons.Journal.BitmapX - gr.getStringWidth("New!") - 20, CMap.Buttons.Journal.TextY)
  851.  
  852. end
  853.  
  854. ]
  855.  
  856. $State: GS_STATE_SCRIPTING
  857. $On State Start:
  858. [
  859. if Monitor.Substate == "Journal" then
  860. Journal:Init()
  861. end
  862. ]
  863.  
  864. $On State End:
  865. [
  866. if Monitor.Substate == "Journal" then
  867. Journal:Exit()
  868. end
  869. ]
  870.  
  871. $On Frame:
  872. [
  873. if Monitor.Substate == "Journal" then
  874. Journal:Draw()
  875. Journal:MonitorActions(true)
  876. end
  877. ]
  878.  
  879. $On Mouse Pressed:
  880. [
  881. if Monitor.Substate == "Journal" then
  882. if bit.checkBit(hv.MouseButton, 0) then
  883. Journal.MouseDown = true
  884. Journal.MouseTimestamp = Journal.Time()
  885. end
  886. end
  887. ]
  888.  
  889. $On Mouse Released:
  890. [
  891. if Monitor.Substate == "Journal" then
  892. if bit.checkBit(hv.MouseButton, 0) then
  893. Journal.MouseDown = nil
  894. Journal.MouseTimestamp = nil
  895. Journal:MonitorActions()
  896. end
  897. end
  898. ]
  899.  
  900. $State: GS_STATE_GAME_PLAY
  901. $On State End:
  902. [
  903. if Journal.Ingame then
  904. Journal:Exit()
  905. end
  906. ]
  907.  
  908. $On Frame:
  909. [
  910. if Journal.Ingame then
  911. io.setCursorHidden(false)
  912. Journal:Draw()
  913. Journal:MonitorActions(true)
  914. end
  915. ]
  916.  
  917. $On Mouse Pressed:
  918. [
  919. if Journal.Ingame then
  920. if bit.checkBit(hv.MouseButton, 0) then
  921. Journal.MouseDown = true
  922. Journal.MouseTimestamp = Journal.Time()
  923. end
  924. end
  925. ]
  926.  
  927. $On Mouse Released:
  928. [
  929. if Journal.Ingame then
  930. if bit.checkBit(hv.MouseButton, 0) then
  931. Journal.MouseDown = nil
  932. Journal.MouseTimestamp = nil
  933. Journal:MonitorActions()
  934. end
  935. end
  936. ]
  937.  
  938. $State: GS_STATE_CMD_BRIEF
  939. $On State Start:
  940. [
  941. if Monitor and Monitor.Enabled and cf.fileExists(Monitor.ConfigFilename, "data/config", true) then
  942. if Monitor.Config.CmdBrief.Journal then
  943. Journal:CheckNew()
  944. end
  945. end
  946. ]
  947.  
  948. $On Frame:
  949. [
  950. if Monitor and Monitor.Enabled and Journal.NewEntries and Monitor.Buttons.Journal then
  951. Journal:DrawNew()
  952. end
  953. ]
  954.  
  955. #End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement