Advertisement
MagmaLP

Fontania-Regel_Tafeln Blau (startup)

Sep 18th, 2020 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 12.86 KB | None | 0 0
  1. local monitor = peripheral.wrap("back")
  2. local main_text_scale = 1
  3. local main_back_color = colors.black
  4. local main_text_color = colors.lightGray
  5. local w, h = monitor.getSize()
  6. monitor.clear()
  7. local button = {}
  8. local language = 1
  9. local page = 1
  10. local languages_amount = 2
  11. local pages_amount = 5
  12.  
  13. function setupScreen()
  14.     monitor.setTextScale(main_text_scale)
  15.     monitor.setBackgroundColor(main_back_color)
  16.     monitor.setTextColor(main_text_color)
  17. end
  18.  
  19. --button-api start
  20.  
  21. function convertColor(color)
  22.     if color == "white" then
  23.         return 1
  24.     end
  25.     if color == "lightgray" then
  26.         return 256
  27.     end
  28.     if color == "gray" then
  29.         return 128
  30.     end
  31.     if color == "black" then
  32.         return 32768
  33.     end
  34.     if color == "brown" then
  35.         return 4096
  36.     end
  37.     if color == "red" then
  38.         return 16384
  39.     end
  40.     if color == "orange" then
  41.         return 2
  42.     end
  43.     if color == "yellow" then
  44.         return 16
  45.     end
  46.     if color == "lime" then
  47.         return 32
  48.     end
  49.     if color == "green" then
  50.         return 8192
  51.     end
  52.     if color == "blue" then
  53.         return 2048
  54.     end
  55.     if color == "cyan" then
  56.         return 512
  57.     end
  58.     if color == "lightblue" then
  59.         return 8
  60.     end
  61.     if color == "purple" then
  62.         return 1024
  63.     end
  64.     if color == "magenta" then
  65.         return 4
  66.     end
  67.     if color == "pink" then
  68.         return 64
  69.     end
  70. end
  71.  
  72. function setButton(name, caption, func, xpos, ypos, width, height, backColor, textColor)
  73.     button[name] = {}
  74.     button[name]["func"] = func
  75.     button[name]["caption"] = caption
  76.     button[name]["x"] = xpos
  77.     button[name]["y"] = ypos
  78.     button[name]["width"] = width
  79.     button[name]["height"] = height
  80.     button[name]["backColor"] = backColor
  81.     button[name]["textColor"] = textColor
  82.     button[name]["visible"] = false
  83. end
  84.  
  85. function drawButton(title)
  86.     for name, data in pairs(button) do
  87.         if name == title then
  88.             data["visible"] = true
  89.             monitor.setBackgroundColor(convertColor(data["backColor"]))
  90.             monitor.setTextColor(convertColor(data["textColor"]))
  91.             local xspot = data["x"] + math.floor((data["width"] - string.len(data["caption"])) / 2 ) + 1
  92.             local yspot = data["y"] + math.floor(data["height"] / 2) + 1
  93.             for i = 1, data["height"] do
  94.                 for j = 1, data["width"] do
  95.                     monitor.setCursorPos(data["x"] + j, data["y"] + i)
  96.                     monitor.write(" ")
  97.                 end
  98.             end
  99.             monitor.setCursorPos(xspot, yspot)
  100.             monitor.write(data["caption"])
  101.         end
  102.     end
  103. end
  104.  
  105. function buttonHit(x, y)
  106.     for name, data in pairs(button) do
  107.         if data["visible"] == true then
  108.             if math.floor(y) >= data["y"] + 1 and  y <= data["y"] + data["height"] then
  109.                 if math.floor(x) >= data["x"] + 1 and x <= data["x"] + data["width"] then
  110.                     data["func"]()
  111.                     screen()
  112.                     return true
  113.                 end
  114.             end
  115.         end
  116.     end
  117. end
  118.  
  119.  
  120. --button-api ende
  121.  
  122.  
  123. --alle button-fkt start
  124.  
  125. function assignButtons()
  126.     local caption = language_button_caption[language]
  127.     setButton("Language", caption, nextLanguage, 0, (h-3), 12, 3, "lightblue", "black")
  128.     setButton("PageUp", "-->", pageUp, (w-7), (h-3), 7, 3, "lightblue", "black")
  129.     setButton("PageDown", "<--", pageDown, (w-15), (h-3), 7, 3, "lightblue", "black")
  130. end
  131.  
  132. function nextLanguage()
  133.     language = language + 1
  134.     if language == (languages_amount + 1) then
  135.         language = 1
  136.     end
  137. end
  138.  
  139. function pageUp()
  140.     page = page + 1
  141.     if page == (pages_amount + 1) then
  142.         page = 1
  143.     end
  144. end
  145.  
  146. function pageDown()
  147.     page = page - 1
  148.     if page == 0 then
  149.         page = pages_amount
  150.     end
  151. end
  152.  
  153. function zeilenAnzahl()
  154.     local b = 1
  155.     while text[language][page][b] ~= nil do
  156.         b = b + 1
  157.     end
  158.     return b-1
  159. end
  160.  
  161. --alle Button-Fkt ende
  162.  
  163.  
  164. --alle Screen-Fkt start
  165.  
  166. function drawButtons()
  167.     assignButtons()
  168.     drawButton("Language")
  169.     drawButton("PageUp")
  170.     drawButton("PageDown")
  171. end
  172.  
  173. function drawHeading()
  174.     local heading = heading_string[language][page]
  175.     local string_length = string.len(heading)
  176.     setupScreen()
  177.     monitor.setTextColor(colors.lightBlue)
  178.     monitor.setCursorPos((w - string_length) / 2 + 1, 2)
  179.     monitor.write(heading)
  180. end
  181.  
  182. function drawLines()
  183.     setupScreen()
  184.     for c = 1, zeilenAnzahl() do       
  185.         monitor.setCursorPos(3 , c + 3)
  186.         monitor.write(text[language][page][c])
  187.     end
  188. end
  189.  
  190. function drawHighlights()
  191.     for name, data in pairs(highlight) do
  192.         if data["lang"] == language then
  193.             if data["page"] == page then
  194.                 monitor.setBackgroundColor(convertColor(data["backColor"]))
  195.                 monitor.setTextColor(convertColor(data["textColor"]))
  196.                 local xspot = data["x"]
  197.                 local yspot = data["y"]
  198.            
  199.                 monitor.setCursorPos(xspot, yspot)
  200.                 monitor.write(data["text"])
  201.             end
  202.         end
  203.     end
  204. end
  205.  
  206. function drawPageNumber()
  207.     setupScreen()
  208.     monitor.setCursorPos(w-2,1)
  209.     monitor.write(string.gsub(page, ".0", ""))
  210.     monitor.write("/")
  211.     monitor.write(string.gsub(pages_amount, ".0", ""))
  212. end
  213.  
  214. function screen()
  215.     setupScreen()
  216.     monitor.clear()
  217.    
  218.     drawButtons()
  219.    
  220.     drawHeading()
  221.    
  222.     drawLines()
  223.    
  224.     drawHighlights()
  225.    
  226.     drawPageNumber()
  227. end
  228.  
  229. --alle Screen-Fkt ende
  230.  
  231. function main()
  232.     local event, button, x, y = os.pullEvent( "monitor_touch" )
  233.     --if event == "mouse_click" then
  234.         buttonHit(x, y)
  235.     --end
  236. end
  237.  
  238. function textZuweisen()
  239.     --Change Language - Button
  240.         language_button_caption = {}
  241.         language_button_caption[1] = "English"
  242.         language_button_caption[2] = "Deutsch"
  243.    
  244.     --Headings
  245.         heading_string = {}
  246.         for a = 1, languages_amount do
  247.             heading_string[a] = {}
  248.         end
  249.             --Deutsch
  250.             heading_string[1][1] = "Wichtige Befehle"       --heading_string[language][page]
  251.             heading_string[1][2] = " "
  252.             heading_string[1][3] = " "
  253.             heading_string[1][4] = " "
  254.             heading_string[1][5] = " "
  255.            
  256.             --English
  257.             heading_string[2][1] = "Important Commands"     --heading_string[language][page]
  258.             heading_string[2][2] = " "
  259.             heading_string[2][3] = " "
  260.             heading_string[2][4] = " "
  261.             heading_string[2][5] = " "
  262.    
  263.    
  264.     --Lines
  265.         text = {}
  266.         for d = 1, languages_amount do
  267.         text[d] = {}
  268.             for e = 1, pages_amount do
  269.                 text[d][e] = {}
  270.             end
  271.         end
  272.             --Deutsch
  273.             text[1][1][1] = "Hier findest Du allerlei nützliche und essentielle"
  274.             text[1][1][2] = "Befehle welche Du als Stadtbewohner benötigen wirst."
  275.            
  276.             text[1][2][1] = "/t join Fontania - Hiermit trittst Du der Stadt bei."
  277.             text[1][2][2] = "                   Ausserdem sind alle anderen Befehle"
  278.             text[1][2][3] = "                   erst hiernach möglich"
  279.             text[1][2][4] = " "
  280.             text[1][2][5] = "/t leave - Verlasse die Stadt (Bitte Hinweise dazu bei"
  281.             text[1][2][6] = "           'Grundstücke' berücksichtigen!)"
  282.             text[1][2][7] = " "
  283.             text[1][2][8] = "/tc - Wechselt in den TownChat. Funktioniert identisch"
  284.             text[1][2][9] = "      zu /l oder /g"
  285.            
  286.             text[1][3][1] = "/t spawn - Teleportiere Dich zum Stadtspawn!"
  287.             text[1][3][2] = " "
  288.             text[1][3][3] = "/t outpost - Teleportiere Dich zum Spawn des Stadtteils"
  289.             text[1][3][4] = "             Ocean!"
  290.             text[1][3][5] = " "
  291.             text[1][3][6] = "/t [stadt] - Zeigt Dir Informationen zur Stadt"
  292.             text[1][3][7] = " "
  293.             text[1][3][8] = "/t deposit [betrag] - Spende der Stadt einen bestimmten"
  294.             text[1][3][9] = "                      Betrag"
  295.            
  296.             text[1][4][1] = "/plot claim - Hiermit kauft man genau einen Chunk eines"
  297.             text[1][4][2] = "              Grundstücks, sofern dieses 'For Sale'"
  298.             text[1][4][3] = "              ist."
  299.             text[1][4][4] = " "
  300.             text[1][4][5] = "/resident friend add [name]    - Gebe einem anderen Spieler"
  301.             text[1][4][6] = "                                 Rechte auf deinem GS"
  302.             text[1][4][7] = " "
  303.             text[1][4][8] = "/resident friend remove [name] - Entziehe einem Spieler"
  304.             text[1][4][9] = "                                 Rechte auf deinem GS"
  305.             text[1][4][10] = " "
  306.             text[1][4][11] = "/plot toggle mob - Erlaubt das Spawnen von Mobs (für"
  307.             text[1][4][12] = "                   Mob-Farm erforderlich)"
  308.            
  309.             text[1][5][1] = "/seen [name] - Wie lange ist jemand schon offline?"
  310.             text[1][5][2] = " "
  311.             text[1][5][3] = "/t online - Wer ist derzeit aus der Stadt noch online?"
  312.             text[1][5][4] = " "
  313.             text[1][5][5] = "/t ranklist - Wer besitzt welchen Stadt-Rang?"
  314.             text[1][5][6] = " "
  315.             text[1][5][7] = "Liste aller Befehle: https://goo.gl/tEHZe7"
  316.             text[1][5][8] = "(Die meisten davon erfordern Permissions)"
  317.            
  318.            
  319.             --English
  320.             text[2][1][1] = "Here you will find a lot of useful and essential"
  321.             text[2][1][2] = "commands to interact in a city."
  322.            
  323.             text[2][2][1] = "/t join Fontania - Joins the city of Fontania and"
  324.             text[2][2][2] = "                   enables all other commands you"
  325.             text[2][2][3] = "                   find on this screen."
  326.             text[2][2][4] = " "
  327.             text[2][2][5] = "/t leave - Leaves the city (Please read the 'Property/"
  328.             text[2][2][6] = "           Estate'-Screen for more information)"
  329.             text[2][2][7] = " "
  330.             text[2][2][8] = "/tc - Switches to the TownChat. Works the same as /l"
  331.             text[2][2][9] = "      or /g"
  332.            
  333.             text[2][3][1] = "/t spawn - Warp to the spawn of Fontania"
  334.             text[2][3][2] = " "
  335.             text[2][3][3] = "/t outpost - Warp to the spawn of Ocean, which is our"
  336.             text[2][3][4] = "             outpost"
  337.             text[2][3][5] = " "
  338.             text[2][3][6] = "/t [city] - Lists information about a city"
  339.             text[2][3][7] = " "
  340.             text[2][3][8] = "/t deposit [amount] - Donate a certain amount of money"
  341.             text[2][3][9] = "                      to the city"
  342.        
  343.             text[2][4][1] = "/plot claim - Buys one chunk of a property, if it is"
  344.             text[2][4][2] = "              marked as 'For Sale'. Always buy all chunks"
  345.             text[2][4][3] = "              of a property!"
  346.             text[2][4][4] = " "
  347.             text[2][4][5] = "/resident friend add [name]    - Enables a player to"
  348.             text[2][4][6] = "                                 interact on your plots"
  349.             text[2][4][7] = " "
  350.             text[2][4][8] = "/resident friend remove [name] - Disables a player to"
  351.             text[2][4][9] = "                                 interact on your plots"
  352.             text[2][4][10] = " "
  353.             text[2][4][11] = "/plot toggle mob - Enables mobs to spawn in this chunk"
  354.             text[2][4][12] = "                   (necessary for mob farms to work)"
  355.            
  356.             text[2][5][1] = "/seen [name] - How long has somebody been not online?"
  357.             text[2][5][2] = " "
  358.             text[2][5][3] = "/t online - Who else is online in Fontania atm?"
  359.             text[2][5][4] = " "
  360.             text[2][5][5] = "/t ranklist - Who is what in the city?"
  361.             text[2][5][6] = " "
  362.             text[2][5][7] = "List of all commands: https://goo.gl/tEHZe7"
  363.             text[2][5][8] = "(Most of which require extra permissions)"
  364.  
  365.            
  366.    
  367.     --Highlights
  368.         highlight = {}
  369.         --setHighlight(id, sprache, seite, "text", xpos, ypos, "backcolor", "textcolor")
  370.         --Deutsch
  371.         setHighlight(1, 1, 2, "/t join Fontania", 3, 4, "black", "lightblue")
  372.         setHighlight(2, 1, 2, "/t leave", 3, 8, "black", "lightblue")
  373.         setHighlight(3, 1, 2, "/tc", 3, 11, "black", "lightblue")
  374.        
  375.         setHighlight(4, 1, 3, "/t spawn", 3, 4, "black", "lightblue")
  376.         setHighlight(5, 1, 3, "/t outpost", 3, 6, "black", "lightblue")
  377.         setHighlight(6, 1, 3, "/t [stadt]", 3, 9, "black", "lightblue")
  378.         setHighlight(7, 1, 3, "/t deposit [betrag]", 3, 11, "black", "lightblue")
  379.        
  380.         setHighlight(8, 1, 4, "/plot claim", 3, 4, "black", "lightblue")
  381.         setHighlight(9, 1, 4, "/resident friend add [name]", 3, 8, "black", "lightblue")
  382.         setHighlight(10, 1, 4, "/resident friend remove [name]", 3, 11, "black", "lightblue")
  383.         setHighlight(11, 1, 4, "/plot toggle mob", 3, 14, "black", "lightblue")
  384.        
  385.         setHighlight(12, 1, 5, "/seen [name]", 3, 4, "black", "lightblue")
  386.         setHighlight(13, 1, 5, "/t online", 3, 6, "black", "lightblue")
  387.         setHighlight(14, 1, 5, "/t ranklist", 3, 8, "black", "lightblue")
  388.        
  389.         --English
  390.         setHighlight(15, 2, 2, "/t join Fontania", 3, 4, "black", "lightblue")
  391.         setHighlight(16, 2, 2, "/t leave", 3, 8, "black", "lightblue")
  392.         setHighlight(17, 2, 2, "/tc", 3, 11, "black", "lightblue")
  393.        
  394.         setHighlight(18, 2, 3, "/t spawn", 3, 4, "black", "lightblue")
  395.         setHighlight(19, 2, 3, "/t outpost", 3, 6, "black", "lightblue")
  396.         setHighlight(20, 2, 3, "/t [city]", 3, 9, "black", "lightblue")
  397.         setHighlight(21, 2, 3, "/t deposit [amount]", 3, 11, "black", "lightblue")
  398.        
  399.         setHighlight(22, 2, 4, "/plot claim", 3, 4, "black", "lightblue")
  400.         setHighlight(23, 2, 4, "/resident friend add [name]", 3, 8, "black", "lightblue")
  401.         setHighlight(24, 2, 4, "/resident friend remove [name]", 3, 11, "black", "lightblue")
  402.         setHighlight(25, 2, 4, "/plot toggle mob", 3, 14, "black", "lightblue")
  403.        
  404.         setHighlight(26, 2, 5, "/seen [name]", 3, 4, "black", "lightblue")
  405.         setHighlight(27, 2, 5, "/t online", 3, 6, "black", "lightblue")
  406.         setHighlight(28, 2, 5, "/t ranklist", 3, 8, "black", "lightblue")
  407.        
  408. end
  409.  
  410. function setHighlight(id, sprache, seite, text, xpos, ypos, backColor, textColor)
  411.     highlight[id] = {}
  412.     highlight[id]["lang"] = sprache
  413.     highlight[id]["page"] = seite
  414.     highlight[id]["text"] = text
  415.     highlight[id]["x"] = xpos
  416.     highlight[id]["y"] = ypos
  417.     highlight[id]["backColor"] = backColor
  418.     highlight[id]["textColor"] = textColor
  419. end
  420.  
  421. textZuweisen()
  422. screen()
  423. while true do
  424.     main()
  425. end
  426.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement