Advertisement
Altaric

Untitled

Jun 12th, 2017
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 8.45 KB | None | 0 0
  1.  -- ******************************************************
  2.  -- ***                     GUI                        ***
  3.  -- ******************************************************
  4.  
  5. script.on_event(defines.events.on_player_joined_game,function(n)
  6.     local player=game.players[n.player_index]
  7.     if player.gui.center.README~=nil     then player.gui.center.README.destroy()    end
  8.     if player.gui.left.PlayerList~=nil   then player.gui.left.PlayerList.destroy()    end
  9.     if player.gui.top.PlayerList~=nil    then player.gui.top.PlayerList.destroy()    end
  10.     drawToolbar()
  11.     drawPlayerList()
  12.     -- local v=encode(game.players,"players",{"name","admin","online_time","connected","index"})
  13.     -- game.write_file("players.json",v,false)
  14.     if (player.admin == false) and (ticktominutes(player.online_time)<1)     then ReadmeGui(player,"Welcome")    end
  15. end)
  16.  
  17. script.on_event(defines.events.on_player_left_game,function(n)
  18.     -- local m=game.players[n.player_index]
  19.     drawPlayerList()
  20. end)
  21.  
  22. function clearElement(s)
  23.     if s~=nil then
  24.         for t,u in pairs(s.children_names) do
  25.             s[u].destroy()
  26.         end
  27.     end
  28. end
  29.  
  30. function drawToolbar()
  31.     for t,I in pairs(game.players) do
  32.         local z=I.gui.top
  33.         clearElement(z)
  34.         -- z.add{name="btn_toolbar_rocket_score",type="button",caption="Score",tooltip="Show the satellites launched."}
  35.         z.add{name="btn_toolbar_score",type="button",caption="Score",tooltip="Shows how well you are performing."}
  36.         z.add{name="btn_toolbar_playerList",type="button",caption="Playerlist",tooltip="Lists player connected."}
  37.         z.add{name="btn_readme",type="button",caption="Readme",tooltip="Rules, Server info."}
  38.         if I.name == "Altaric" then z.add{name="btn_toolbar_spectate",type="button",caption="Spectate",tooltip="Turn into a ghost."} end
  39.         if I.name == "Altaric" then z.add{name="btn_toolbar_test",type="button",caption="Test",tooltip="For science !"} end
  40.  
  41.         I.gui.left.direction = "vertical"
  42.         if (I.gui.left.score == nil) then
  43.             local frame = I.gui.left.add{name = "score", type = "frame", direction = "vertical"}
  44.             if I.admin then frame.add{name="debug", type = "label", caption="-- Debug --"} end
  45.             frame.add{name="difficulty", type = "label", caption="Difficulty = "}
  46.             if (GAME_SETTING == "Comet Catcher") then
  47.                 frame.add{name="", type = "label", caption="Kill alien structures to raise your morale."}
  48.                 frame.add{name="label", type = "label", caption="Alien homes burned recently: 0"}
  49.             end
  50.         end
  51.     end
  52. end
  53.  
  54. function scoreGuiSwitch(J)
  55.     if J.gui.left.score~=nil     then
  56.         J.gui.left.score.style.visible = not J.gui.left.score.style.visible
  57.     end
  58. end
  59.  
  60. function satelliteGuiSwitch(J)
  61.     if J.gui.left.rocket_score~=nil     then
  62.         J.gui.left.rocket_score.style.visible = not J.gui.left.rocket_score.style.visible
  63.     end
  64. end
  65.  
  66. function playerListGuiSwitch(J)
  67.     if J.gui.left.PlayerList~=nil then
  68.         J.gui.left.PlayerList.style.visible = not J.gui.left.PlayerList.style.visible
  69.     end
  70. end
  71.  
  72. function spectate(m)
  73.     if m.character~=nil then
  74.         spectating[m.index]=m.character
  75.         m.character=nil
  76.         m.print("You are spectating.")
  77.     else
  78.         m.character=spectating[m.index]
  79.         spectating[m.index]=nil
  80.         m.print("You are no longer spectating.")
  81.     end
  82. end
  83.  
  84. function drawPlayerList()
  85.     for _,I in pairs(game.players) do
  86.         if I.gui.left.PlayerList==nil then I.gui.left.add{name="PlayerList",type="frame",direction="vertical"} end
  87.         clearElement(I.gui.left.PlayerList)
  88.         for t,m in pairs(game.connected_players) do
  89.             if m.admin==true then
  90.                 I.gui.left.PlayerList.add{type="label",name=m.name,style="caption_label_style",caption={"",ticktominutes(m.online_time)," mn - ",m.name," [Admin]"}}
  91.                 I.gui.left.PlayerList[m.name].style.font_color={r=233,g=63,b=233}
  92.                 m.tag="*"
  93.             else
  94.                 -- if ticktominutes(m.online_time)>=timeforRegular then
  95.                     I.gui.left.PlayerList.add{type="label",name=m.name,style="caption_label_style",caption={"",ticktominutes(m.online_time)," mn - ",m.name}}
  96.                     I.gui.left.PlayerList[m.name].style.font_color={r=24,g=172,b=188}
  97.                     m.tag=""
  98.                 -- else
  99.                     -- I.gui.left.PlayerList.add{type="label",name=m.name,style="caption_label_style",caption={"",ticktominutes(m.online_time)," mn - ",t}}
  100.                     -- I.gui.left.PlayerList[m.name].style.font_color={r=255,g=159,b=27}m.tag="[Guest]"
  101.                 -- end
  102.             end
  103.         end
  104.     end
  105. end
  106.  
  107. function ReadmeGui(player,page)
  108.     if player.gui.center.README~=nil     then player.gui.center.README.destroy()    end
  109.     local gui=player.gui.center.add{name="README",type="frame",direction="vertical"}
  110.  
  111.     gui.add{type="scroll-pane",name="flowContent",direction="vertical",vertical_scroll_policy="always",horizontal_scroll_policy="never"}
  112.     gui.add{type="flow",name="flowNavigation",direction="horizontal"}
  113.     gui.flowNavigation.add{name="btn_readme_welcome",type="button",caption="Welcome !",tooltip="Welcome message and rules."}
  114.     gui.flowNavigation.add{name="btn_readme_scenario_info",type="button",caption="Scenario info",tooltip="Scenario information."}
  115.     gui.flowNavigation.add{name="btn_readme_close",type="button",caption="Close",tooltip="Close the readme."}
  116.     gui.flowContent.style.maximal_height=450
  117.     gui.flowContent.style.minimal_height=450
  118.     gui.flowContent.style.maximal_width=500
  119.     gui.flowContent.style.minimal_width=500
  120.     gui.flowNavigation.style.maximal_width=500
  121.     gui.flowNavigation.style.minimal_width=500
  122.     if page == "Welcome" then
  123.         gui.caption="Welcome fellow pilgrim !"
  124.         gui.flowContent.add{type="label",caption=[===[
  125. We hope that you will enjoy you stay here !
  126.  
  127. Coding and hosting by Altaric.
  128.  
  129. We have a few rules you will have to respect :
  130. - No griefing.
  131. - No offending language.
  132. We will kick/ban/rollback as necessary.
  133.  
  134. Discord channel available at : ]===], single_line = false}
  135.         gui.flowContent.add{type="textfield",text="https://discord.gg/kf8KKyY"}.style.minimal_width=200
  136.         gui.flowContent.add{type="label",caption=[===[
  137.  
  138. We value your feedback on :
  139. - Difficulty of the game,
  140. - How do you like our custom events,
  141. - Your ideas on things to implement,
  142. - Anything you like :)
  143.  
  144. Visit us on the forums at : ]===], single_line = false}
  145.         gui.flowContent.add{type="textfield",text="https://forums.factorio.com/viewtopic.php?f=53&t=42966"}.style.minimal_width=400
  146.  
  147.     end
  148.  
  149.     if (page == "Scenario") then fill_Readme(gui) end
  150. end
  151.  
  152. script.on_event(defines.events.on_gui_click,function(n)
  153.     local player=game.players[n.player_index]
  154.     if n.element.name=="btn_readme"                        then ReadmeGui(player,"Welcome")         else
  155.     if n.element.name=="btn_readme_welcome"                then ReadmeGui(player,"Welcome")         else
  156.     if n.element.name=="btn_readme_scenario_info"          then ReadmeGui(player,"Scenario")        else
  157.     if n.element.name=="btn_readme_close"                  then player.gui.center.README.destroy()  else
  158.     if n.element.name=="btn_toolbar_spectate"              then spectate(player)                    else
  159.     if n.element.name=="btn_toolbar_test"                  then test()                              else
  160.     if n.element.name=="btn_toolbar_playerList"            then playerListGuiSwitch(player)         else
  161.     if n.element.name=="btn_toolbar_score"                 then scoreGuiSwitch(player)              else
  162.     -- if n.element.name=="btn_toolbar_rocket_score"          then satelliteGuiSwitch(player)
  163.     end end end end end end end end
  164. end)
  165.  
  166.  
  167. function fill_Readme(gui)
  168.     if GAME_SETTING == "Archipellago" then
  169.         gui.caption="Now playing : Archipellago"
  170.         gui.flowContent.add{type="label",caption=[===[
  171.  
  172. After the recent exploration missions, our resources are getting low.
  173. We have selected this planet to set up a new excavation.
  174. You are to pump as much resources into orbit as possible, so we can
  175. fuel more missions!
  176.  
  177. Scenario details:
  178.  - Biter bowels spit aliens every now and then
  179.  - No evolution over time
  180.  - Evolution from pollution: x2.5
  181.  - Evolution from killing nest: x1
  182.  - Pollution diffusion: x4
  183.  - Trees: 10 times less
  184.  
  185. This is a builder game.]===], single_line = false}
  186.     end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement