Advertisement
NanoBob

dx script editor

May 16th, 2015
289
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 38.05 KB | None | 0 0
  1. --[[
  2. I'll be working on a dx based resource editor ingame.
  3. If you have questions about what I am doing, ask them in the message box to the right of the screen.
  4. Or type them in the message box below my code.
  5. Besides that do not write anyhting in the code, to let me continue my work.
  6. ]]
  7.  
  8.  
  9. local screenx,screeny=guiGetScreenSize()
  10. local fontSize=1
  11. local fontOverlay=1
  12. local currentResource=nil
  13. local currentFile=nil
  14. local toOpenFile=nil
  15. local font=--[["arial"]]dxCreateFont("font.ttf",12)
  16. local overLayFont=dxCreateFont("font.ttf",40)
  17.  
  18. local buttons={}
  19. local scrollBars={}
  20. local lists={}
  21. local memos={}
  22. local edits={}
  23. local case=false
  24. local ctrl=false
  25. local command="script"
  26. local postGui=true
  27. local pasteMemo=guiCreateMemo(-0.4,0.4,0.2,0.2,"",true)
  28. guiSetVisible(pasteMemo,false)
  29.  
  30. local syntaxHighlightings={
  31.     ["function"]={"#5555ff",true},
  32.     ["if"]={"#5555ff",true},
  33.     ["else"]={"#5555ff",true},
  34.     ["elseif"]={"#5555ff",true},
  35.     ["then"]={"#5555ff",true},
  36.     ["end"]={"#5555ff",true},
  37.     ["do"]={"#5555ff",true},
  38.     ["and"]={"#5555ff",true},
  39.     ["or"]={"#5555ff",true},
  40.     ["for"]={"#5555ff",true},
  41.     ["return"]={"#5555ff",true},
  42.     ["repeat"]={"#5555ff",true},
  43.     ["until"]={"#5555ff",true},
  44.     ["local"]={"#5555ff",true},
  45.     ["true"]={"#5555ff",true},
  46.     ["false"]={"#5555ff",true},
  47.     --["[^'][0-9]*[^']"]={"#888800",false},
  48.     ["'.*'"]={"#555555",false},
  49.     ['".*"']={"#555555",false},
  50.    
  51.     ["%-%-.*"]={"#009900",false},
  52.    
  53.     ["string%."]={"#990044",false},
  54.    
  55.     ["math%."]={"#00aaff",false},
  56.     ["ipairs"]={"#00aaff",true},
  57.     ["pairs"]={"#00aaff",true},
  58.     --["string"]={"#00aaff",true},
  59.     ["math"]={"#00aaff",true},
  60.     ["tostring"]={"#00aaff",true},
  61.     ["tonumber"]={"#00aaff",true},
  62.     ["_G"]={"#00aaff",true},
  63. }
  64.  
  65. function dxSetVisible(dxData,bool)
  66.     dxData.visible=bool
  67.     for id,data in pairs(dxData) do
  68.         if type(data)=="table" and data.visible~=nil then
  69.             data.visible=bool  
  70.         end
  71.     end
  72. end
  73.  
  74. function hightLightSyntax(fullString)
  75.     for text,data in pairs(syntaxHighlightings) do
  76.         local start,stop=string.find(fullString,text)
  77.         if start~=nil then
  78.             if data[2]==true then
  79.                 if stop==string.len(fullString) and start==1 then
  80.                     fullString=string.gsub(fullString,text,data[1]..string.sub(fullString,start,stop))
  81.                 elseif stop==string.len(fullString) then
  82.                     fullString=string.gsub(fullString," "..text," "..data[1]..string.sub(fullString,start,stop).."#000000 ")
  83.                     fullString=string.gsub(fullString,"%)"..text,"%)"..data[1]..string.sub(fullString,start,stop).."#000000 ")
  84.                     fullString=string.gsub(fullString,"%("..text,"%("..data[1]..string.sub(fullString,start,stop).."#000000 ")
  85.                     fullString=string.gsub(fullString,"%."..text,"%."..data[1]..string.sub(fullString,start,stop).."#000000 ")
  86.                     fullString=string.gsub(fullString,"\n"..text,"\n"..data[1]..string.sub(fullString,start,stop).."#000000 ")
  87.                     fullString=string.gsub(fullString,"t"..text,"\t"..data[1]..string.sub(fullString,start,stop).."#000000 ")
  88.                 else
  89.                     fullString=string.gsub(fullString,text.." ",data[1]..string.sub(fullString,start,stop).."#000000 ")
  90.                     fullString=string.gsub(fullString,text.."%(",data[1]..string.sub(fullString,start,stop).."#000000(")
  91.                     fullString=string.gsub(fullString,text.."%)",data[1]..string.sub(fullString,start,stop).."#000000)")
  92.                     fullString=string.gsub(fullString,text.."%.",data[1]..string.sub(fullString,start,stop).."#000000.")
  93.                     fullString=string.gsub(fullString,text.."\n",data[1]..string.sub(fullString,start,stop).."#000000")
  94.                     fullString=string.gsub(fullString,text.."\t",data[1]..string.sub(fullString,start,stop).."#000000")
  95.                 end
  96.             else
  97.                 if stop==string.len(fullString) then
  98.                     fullString=string.gsub(fullString,text,data[1]..string.sub(fullString,start,stop).."#000000")
  99.                 else
  100.                     fullString=string.gsub(fullString,text,data[1]..string.sub(fullString,start,stop).."#000000")
  101.                 end
  102.             end
  103.             if text=="--" then
  104.                 break
  105.             end
  106.         end
  107.     end
  108.     return fullString
  109. end
  110.  
  111. local drawFunctions={
  112.     ["button"]=
  113.         function(button)
  114.             if button.visible==false then return end
  115.            
  116.             if fileExists(button.image)==true then
  117.                 dxDrawImage(button.x,button.y,button.width,button.height,button.image,0,0,0,tocolor(255,255,255,255),postGui)
  118.             else
  119.                 dxDrawRectangle(button.x,button.y,button.width,button.height,button.color,postGui)
  120.             end
  121.            
  122.             if isCursorShowing()==false then return end
  123.            
  124.             local cursorx,cursory=getCursorPosition()
  125.             local cursorx,cursory=cursorx*screenx,cursory*screeny
  126.            
  127.             if cursorx>button.x and cursorx<button.x+button.width and cursory>button.y and cursory<button.y+button.height and button.visible==true then
  128.                 local fontOverlay=fontOverlay
  129.                 if button.fontOverlay~=nil then
  130.                     fontOverlay=button.fontOverlay
  131.                 end
  132.                 dxDrawText(button.text,cursorx,cursory,cursorx,cursory,tocolor(100,100,200,255),fontOverlay,overLayFont,"center","center",false,false,postGui)
  133.             end
  134.         end,
  135.     ["list"]=
  136.         function(list)
  137.             if list.visible==false then return end
  138.            
  139.             if list.border~=nil then --background
  140.                 dxDrawRectangle(list.x-list.border,list.y-list.border,list.width+list.border*2,list.height+list.border*2,list.borderColor,postGui)
  141.             end
  142.             dxDrawRectangle(list.x,list.y,list.width,list.height,list.color,postGui)
  143.            
  144.             dxDrawRectangle(list.x+list.width*0.88,list.y,list.width*0.12,list.height,list.borderColor,postGui) --scrollbar
  145.             dxDrawRectangle(list.x+list.width*0.91,list.y+list.height*0.02,list.width*0.08,list.height*0.96,list.color,postGui)
  146.            
  147.             dxDrawRectangle(list.x+list.width*0.91,list.y+list.height*0.96*list.scrollBar,list.width*0.08,list.height*0.02,tocolor(100,100,200),postGui)
  148.            
  149.             local fontHeight=dxGetFontHeight(fontSize,font)
  150.            
  151.             for id,entry in ipairs(list.entries) do
  152.                 if list.selected==id then
  153.                     if id-1+list.scrollPosition>=0 then
  154.                         dxDrawText(entry,list.x+list.width*0.05,list.y+fontHeight*(id-1+list.scrollPosition),list.x+list.width,list.y+list.height,tocolor(100,100,200,255),fontSize,font,"left","top",true,false,postGui)
  155.                     end
  156.                 else
  157.                     if id-1+list.scrollPosition>=0 then
  158.                         dxDrawText(entry,list.x+list.width*0.05,list.y+fontHeight*(id-1+list.scrollPosition),list.x+list.width,list.y+list.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui)
  159.                     end
  160.                 end
  161.             end
  162.         end,
  163.     ["memo"]=
  164.         function(memo)
  165.             if memo.visible==false then return end
  166.            
  167.             if memo.border~=nil then --background
  168.                 dxDrawRectangle(memo.x-memo.border,memo.y-memo.border,memo.width+memo.border*2,memo.height+memo.border*2,memo.borderColor,postGui)
  169.             end
  170.             dxDrawRectangle(memo.x,memo.y,memo.width,memo.height,memo.color,postGui)
  171.            
  172.            
  173.             dxDrawRectangle(memo.x+memo.width*0.92,memo.y,memo.width*0.08,memo.height,memo.borderColor,postGui) --scrollbar
  174.             dxDrawRectangle(memo.x+memo.width*0.93,memo.y+memo.height*0.02,memo.width*0.06,memo.height*0.96,memo.color,postGui)
  175.            
  176.             dxDrawRectangle(memo.x+memo.width*0.93,memo.y+memo.height*0.96*memo.scrollBar,memo.width*0.06,memo.height*0.02,tocolor(100,100,200),postGui)
  177.             local memoHeight=memo.height
  178.             if memo.hScrollBar~=nil then
  179.                 dxDrawRectangle(memo.x,memo.y+memo.height*0.95,memo.width*0.93,memo.height*0.05,memo.borderColor,postGui) --scrollbar
  180.                 dxDrawRectangle(memo.x+memo.width*0.01,memo.y+memo.height*0.96,memo.width*0.91,memo.height*0.03,memo.color,postGui)
  181.            
  182.                 dxDrawRectangle(memo.x+memo.width*0.93*memo.hScrollBar,memo.y+memo.height*0.96,memo.width*0.01,memo.height*0.03,tocolor(100,100,200),postGui)
  183.                 memoHeight=memoHeight*0.95
  184.             end
  185.            
  186.             local fontHeight=dxGetFontHeight(fontSize,font)
  187.             local ammountOfLines=memoHeight/fontHeight
  188.             local letterWidth=dxGetTextWidth("I",1,font)
  189.             local ammountOfLetters=memo.width/letterWidth*0.87
  190.             local horizontalScrollPosition=0
  191.             if memo.hScrollPosition~=nil then
  192.                 horizontalScrollPosition=-memo.hScrollPosition     
  193.             end
  194.             for id,entry in ipairs(memo.lines) do
  195.                 if id-1+memo.scrollPosition>=0 and id+memo.scrollPosition<ammountOfLines then
  196.                     local entry=entry
  197.                     --if string.len(entry)>ammountOfLetters then
  198.                         entry=string.sub(entry,1+horizontalScrollPosition,ammountOfLetters+horizontalScrollPosition)
  199.                     --end
  200.                     if memo.syntax=="lua" then
  201.                         entry=hightLightSyntax(entry)
  202.                     end
  203.                     if memo.selectedLine==id then
  204.                         local cursorEntry=string.gsub(entry,"#%x%x%x%x%x%x","")
  205.                         local cursorEntry=string.sub(cursorEntry,0,memo.selectedCollumn)
  206.                         local width=dxGetTextWidth(cursorEntry,fontSize,font)
  207.                         local charWidth=dxGetTextWidth("I",fontSize,font)
  208.                         dxDrawText("#559955|",memo.x+memo.width*0.05+width-charWidth*0.5,memo.y+fontHeight*(id-1+memo.scrollPosition),memo.x+memo.width,memo.y+memo.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui,true)
  209.                         dxDrawText(entry,memo.x+memo.width*0.05,memo.y+fontHeight*(id-1+memo.scrollPosition),memo.x+memo.width,memo.y+memo.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui,true)
  210.                         dxDrawText(id.."]",memo.x+memo.width*0.0,memo.y+fontHeight*(id-1+memo.scrollPosition),memo.x+memo.width,memo.y+memo.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui,true)
  211.                     else                   
  212.                         dxDrawText(entry,memo.x+memo.width*0.05,memo.y+fontHeight*(id-1+memo.scrollPosition),memo.x+memo.width,memo.y+memo.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui,true)
  213.                         dxDrawText(id.."]",memo.x+memo.width*0.0,memo.y+fontHeight*(id-1+memo.scrollPosition),memo.x+memo.width,memo.y+memo.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui,true)                      
  214.                     end
  215.                 end
  216.             end
  217.             --dxDrawText(memo.text,memo.x,memo.y,memo.x+memo.width,memo.y+memo.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,true,true)
  218.         end,
  219.     ["label"]=
  220.         function(label)
  221.             if label.visible==false then return end
  222.             dxDrawText(label.text,label.x+label.width*0.05,label.y,label.x+label.width,label.y+label.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui)
  223.         end,
  224.     ["edit"]=
  225.         function(edit)
  226.             dxDrawRectangle(edit.x,edit.y,edit.width,edit.height,edit.color,true)
  227.             dxDrawText(edit.text,edit.x+edit.width*0.05,edit.y,edit.x+edit.width,edit.y+edit.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui)
  228.             local width=dxGetTextWidth(string.sub(edit.text,0,edit.selectedCollumn),fontSize,font)
  229.             if edit.selected==true then
  230.                 dxDrawText("#559955|",edit.x+edit.width*0.05+width,edit.y,edit.x+edit.width,edit.y+edit.height,tocolor(0,0,0,255),fontSize,font,"left","top",true,false,postGui,true)
  231.             end
  232.         end,
  233. }
  234.  
  235. local DXs={}
  236.  
  237.  
  238. DXs["editor"]={
  239.     ["type"]="window",
  240.     ["x"]=screenx*0.1,
  241.     ["y"]=screeny*0.1,
  242.     ["width"]=screenx*0.8,
  243.     ["height"]=screeny*0.8,
  244.     ["color"]=tocolor(200,200,200,255),
  245.     ["border"]=15,
  246.     ["borderColor"]=tocolor(50,50,50,255),
  247.     ["visible"]=false,
  248. }
  249.    
  250. DXs["editor"]["editField"]={
  251.     ["type"]="memo",
  252.     ["x"]=screenx*0.35,
  253.     ["y"]=screeny*0.25,
  254.     ["width"]=screenx*0.5,
  255.     ["height"]=screeny*0.6,
  256.     ["color"]=tocolor(255,255,255,255),
  257.     ["border"]=5,
  258.     ["borderColor"]=tocolor(50,50,50,255),
  259.     ["visible"]=false,
  260.     ["lines"]={""},
  261.     ["scrollPosition"]=0,
  262.     ["scrollBar"]=0,
  263.     ["selectedLine"]=1,
  264.     ["selectedCollumn"]=1,
  265.     ["hScrollPosition"]=0,
  266.     ["hScrollBar"]=0,
  267.     ["selected"]=true,
  268.     ["syntax"]="lua",
  269. }
  270.    
  271. DXs["editor"]["save"]={
  272.     ["type"]="button",
  273.     ["x"]=screenx*0.35,
  274.     ["y"]=screeny*0.15,
  275.     ["width"]=screenx*0.08,
  276.     ["height"]=screeny*0.08,
  277.     ["color"]=tocolor(50,50,50,255),
  278.     ["visible"]=false,
  279.     ["func"]=
  280.         function()
  281.             local fullFile=""
  282.             for id,text in ipairs(DXs.editor.editField.lines) do
  283.                 if string.find(text,"\n")==nil then
  284.                     fullFile=fullFile..text.."\n"
  285.                 else
  286.                     fullFile=fullFile..text                
  287.                 end
  288.             end
  289.             triggerServerEvent("onFileSave",getRootElement(),currentFile,fullFile)
  290.         end,
  291.     ["image"]="images/save.png",
  292.     ["text"]="Save",
  293. }
  294.  
  295. DXs["editor"]["resourceFiles"]={
  296.     ["type"]="list",
  297.     ["x"]=screenx*0.15,
  298.     ["y"]=screeny*0.15,
  299.     ["width"]=screenx*0.15,
  300.     ["height"]=screeny*0.7,
  301.     ["color"]=tocolor(255,255,255,255),
  302.     ["border"]=5,
  303.     ["borderColor"]=tocolor(50,50,50,255),
  304.     ["entries"]={},
  305.     ["selected"]=nil,
  306.     ["visible"]=false,
  307.     ["scrollPosition"]=0,
  308.     ["scrollBar"]=0,
  309.     ["func"]=
  310.         function(double)
  311.             if double==true then
  312.                 local selected=DXs.editor.resourceFiles.entries[DXs.editor.resourceFiles.selected]
  313.                 if selected~=nil then
  314.                     toOpenFile=":"..currentResource.."/"..selected
  315.                     currentFile=toOpenFile
  316.                     triggerServerEvent("onClientFileRequest",getRootElement(),toOpenFile)
  317.                     DXs.editor.editField.scrollBar=0
  318.                     DXs.editor.editField.scrollPosition=0
  319.                     DXs.editor.editField.selectedCollumn=1
  320.                     DXs.editor.editField.selectedLine=1
  321.                 end
  322.             end
  323.         end,
  324. }
  325.    
  326. DXs["editor"]["browse"]={
  327.     ["type"]="button",
  328.     ["x"]=screenx*0.45,
  329.     ["y"]=screeny*0.15,
  330.     ["width"]=screenx*0.08,
  331.     ["height"]=screeny*0.08,
  332.     ["color"]=tocolor(50,50,50,255),
  333.     ["visible"]=false,
  334.     ["func"]=
  335.         function()
  336.             dxSetVisible(DXs.editor,false)
  337.             dxSetVisible(DXs.browser,true)
  338.             triggerServerEvent("onResourceListRequest",getRootElement())
  339.         end,
  340.     ["image"]="images/search.png",
  341.     ["text"]="Browse",
  342. }
  343.    
  344. DXs["editor"]["create"]={
  345.     ["type"]="button",
  346.     ["x"]=screenx*0.55,
  347.     ["y"]=screeny*0.15,
  348.     ["width"]=screenx*0.08,
  349.     ["height"]=screeny*0.08,
  350.     ["color"]=tocolor(50,50,50,255),
  351.     ["visible"]=false,
  352.     ["func"]=
  353.         function()
  354.             dxSetVisible(DXs.new,true)
  355.             dxSetVisible(DXs.editor,false)
  356.         end,
  357.     ["image"]="images/newResource.png",
  358.     ["text"]="New Resource",
  359. }
  360.    
  361. DXs["editor"]["run"]={
  362.     ["type"]="button",
  363.     ["x"]=screenx*0.65,
  364.     ["y"]=screeny*0.15,
  365.     ["width"]=screenx*0.08,
  366.     ["height"]=screeny*0.08,
  367.     ["color"]=tocolor(50,50,50,255),
  368.     ["visible"]=false,
  369.     ["func"]=
  370.         function()
  371.             triggerServerEvent("onResourceRun",getRootElement(),currentResource)           
  372.         end,
  373.     ["image"]="images/run.png",
  374.     ["text"]="Run",
  375. }
  376.    
  377. DXs["editor"]["close"]={
  378.     ["type"]="button",
  379.     ["x"]=screenx*0.75,
  380.     ["y"]=screeny*0.15,
  381.     ["width"]=screenx*0.08,
  382.     ["height"]=screeny*0.08,
  383.     ["color"]=tocolor(50,50,50,255),
  384.     ["visible"]=false,
  385.     ["func"]=
  386.         function()
  387.             dxSetVisible(DXs.editor,false)
  388.             showCursor(false)
  389.         end,
  390.     ["image"]="images/cancel.png",
  391.     ["text"]="Cancel",
  392. }
  393.  
  394.  
  395.  
  396. DXs["browser"]={
  397.     ["type"]="window",
  398.     ["x"]=screenx*0.1,
  399.     ["y"]=screeny*0.1,
  400.     ["width"]=screenx*0.4,
  401.     ["height"]=screeny*0.8,
  402.     ["color"]=tocolor(200,200,200,255),
  403.     ["border"]=15,
  404.     ["borderColor"]=tocolor(50,50,50,255),
  405.     ["visible"]=false,
  406.  
  407. }
  408.  
  409. DXs["browser"]["resourceList"]={
  410.     ["type"]="list",
  411.     ["x"]=screenx*0.15,
  412.     ["y"]=screeny*0.35,
  413.     ["width"]=screenx*0.3,
  414.     ["height"]=screeny*0.45,
  415.     ["color"]=tocolor(255,255,255,255),
  416.     ["border"]=5,
  417.     ["borderColor"]=tocolor(50,50,50,255),
  418.     ["entries"]={},
  419.     ["selected"]=nil,
  420.     ["visible"]=false,
  421.     ["scrollPosition"]=0,
  422.     ["scrollBar"]=0,
  423. }
  424.    
  425. DXs["browser"]["open"]={
  426.     ["type"]="button",
  427.     ["x"]=screenx*0.15,
  428.     ["y"]=screeny*0.15,
  429.     ["width"]=screenx*0.08,
  430.     ["height"]=screeny*0.08,
  431.     ["color"]=tocolor(50,50,50,255),
  432.     ["visible"]=false,
  433.     ["func"]=
  434.         function()
  435.             if DXs.browser.resourceList.selected~=nil and DXs.browser.resourceList.selected>0 then
  436.                 currentResource=DXs.browser.resourceList.entries[DXs.browser.resourceList.selected]
  437.                 triggerServerEvent("onResourceFilesRequest",getRootElement(),DXs.browser.resourceList.entries[DXs.browser.resourceList.selected])
  438.                 dxSetVisible(DXs.editor,true)
  439.                 dxSetVisible(DXs.browser,false)
  440.                 DXs.editor.editField.lines={}
  441.                 DXs.editor.editField.scrollBar=0
  442.                 DXs.editor.editField.scrollPosition=0
  443.                 DXs.editor.editField.selectedCollumn=1
  444.                 DXs.editor.editField.selectedLine=1
  445.                 DXs.editor.editField.hScrollBar=0
  446.                 DXs.editor.editField.hScrollPosition=0
  447.             end
  448.         end,
  449.     ["image"]="images/open.png",
  450.     ["text"]="Open",
  451. }
  452.    
  453. DXs["browser"]["cancel"]={
  454.     ["type"]="button",
  455.     ["x"]=screenx*0.25,
  456.     ["y"]=screeny*0.15,
  457.     ["width"]=screenx*0.08,
  458.     ["height"]=screeny*0.08,
  459.     ["color"]=tocolor(50,50,50,255),
  460.     ["visible"]=false,
  461.     ["func"]=
  462.         function()
  463.             dxSetVisible(DXs.editor,true)
  464.             dxSetVisible(DXs.browser,false)
  465.         end,
  466.     ["image"]="images/cancel.png",
  467.     ["text"]="Cancel",
  468. }
  469.  
  470. DXs["new"]={
  471.     ["type"]="window",
  472.     ["x"]=screenx*0.1,
  473.     ["y"]=screeny*0.1,
  474.     ["width"]=screenx*0.4,
  475.     ["height"]=screeny*0.8,
  476.     ["color"]=tocolor(200,200,200,255),
  477.     ["border"]=15,
  478.     ["borderColor"]=tocolor(50,50,50,255),
  479.     ["visible"]=false,
  480. }
  481.    
  482. DXs["new"]["create"]={
  483.     ["type"]="button",
  484.     ["x"]=screenx*0.15,
  485.     ["y"]=screeny*0.15,
  486.     ["width"]=screenx*0.08,
  487.     ["height"]=screeny*0.08,
  488.     ["color"]=tocolor(50,50,50,255),
  489.     ["visible"]=false,
  490.     ["func"]=
  491.         function()
  492.             dxSetVisible(DXs.editor,true)
  493.             dxSetVisible(DXs.new,false)
  494.             if DXs.new.resource.text=="" or DXs.new.author.text=="" or DXs.new.scriptType.text=="" then return end
  495.             DXs.new.resource.text=string.gsub(DXs.new.resource.text," ","-")
  496.             local filesTable={}
  497.             local linesTable=DXs.new.files.lines
  498.             for id,line in ipairs(linesTable) do
  499.                 filesTable[#filesTable+1]={["text"]=line}
  500.                 if string.find(line,"%.lua")~=nil and DXs.new["typeButton "..id]~=nil then
  501.                     local concerningButton=DXs.new["typeButton "..id]
  502.                     filesTable[#filesTable]["type"]=concerningButton.text
  503.                 end
  504.             end
  505.             triggerServerEvent("onResourceCreate",getRootElement(),DXs.new.resource.text,DXs.new.author.text,DXs.new.scriptType.text,filesTable)
  506.            
  507.         end,
  508.        
  509.     ["image"]="images/newResource.png",
  510.     ["text"]="Create",
  511. }
  512.    
  513. DXs["new"]["cancel"]={
  514.     ["type"]="button",
  515.     ["x"]=screenx*0.25,
  516.     ["y"]=screeny*0.15,
  517.     ["width"]=screenx*0.08,
  518.     ["height"]=screeny*0.08,
  519.     ["color"]=tocolor(50,50,50,255),
  520.     ["visible"]=false,
  521.     ["func"]=
  522.         function()
  523.             dxSetVisible(DXs.editor,true)
  524.             dxSetVisible(DXs.new,false)
  525.         end,
  526.     ["image"]="images/cancel.png",
  527.     ["text"]="Cancel",
  528. }
  529.  
  530. DXs["new"]["resource"]={
  531.     ["type"]="edit",
  532.     ["x"]=screenx*0.25,
  533.     ["y"]=screeny*0.25,
  534.     ["width"]=screenx*0.15,
  535.     ["height"]=screeny*0.05,
  536.     ["color"]=tocolor(255,255,255,255),
  537.     ["visible"]=false,
  538.     ["text"]="",
  539.     ["selectedCollumn"]=1,
  540.     ["selected"]=false,
  541. }
  542.  
  543. DXs["new"]["resourcelabel"]={
  544.     ["type"]="label",
  545.     ["x"]=screenx*0.15,
  546.     ["y"]=screeny*0.25,
  547.     ["width"]=screenx*0.15,
  548.     ["height"]=screeny*0.05,
  549.     ["color"]=tocolor(255,255,255,255),
  550.     ["visible"]=false,
  551.     ["text"]="Resource Name",
  552.     ["selectedCollumn"]=1,
  553. }
  554.  
  555. DXs["new"]["author"]={
  556.     ["type"]="edit",
  557.     ["x"]=screenx*0.25,
  558.     ["y"]=screeny*0.31,
  559.     ["width"]=screenx*0.15,
  560.     ["height"]=screeny*0.05,
  561.     ["color"]=tocolor(255,255,255,255),
  562.     ["visible"]=false,
  563.     ["text"]="",
  564.     ["selectedCollumn"]=1,
  565.     ["selected"]=false,
  566. }
  567.  
  568. DXs["new"]["authorLabel"]={
  569.     ["type"]="label",
  570.     ["x"]=screenx*0.15,
  571.     ["y"]=screeny*0.31,
  572.     ["width"]=screenx*0.15,
  573.     ["height"]=screeny*0.05,
  574.     ["color"]=tocolor(255,255,255,255),
  575.     ["visible"]=false,
  576.     ["text"]="Author",
  577.     ["selectedCollumn"]=1,
  578. }
  579.  
  580. DXs["new"]["scriptType"]={
  581.     ["type"]="edit",
  582.     ["x"]=screenx*0.25,
  583.     ["y"]=screeny*0.37,
  584.     ["width"]=screenx*0.15,
  585.     ["height"]=screeny*0.05,
  586.     ["color"]=tocolor(255,255,255,255),
  587.     ["visible"]=false,
  588.     ["text"]="",
  589.     ["selectedCollumn"]=1,
  590.     ["selected"]=false,
  591. }
  592.  
  593. DXs["new"]["scriptTypeLabel"]={
  594.     ["type"]="label",
  595.     ["x"]=screenx*0.15,
  596.     ["y"]=screeny*0.37,
  597.     ["width"]=screenx*0.15,
  598.     ["height"]=screeny*0.05,
  599.     ["color"]=tocolor(255,255,255,255),
  600.     ["visible"]=false,
  601.     ["text"]="type",
  602.     ["selectedCollumn"]=1,
  603. }
  604.    
  605. DXs["new"]["files"]={
  606.     ["type"]="memo",
  607.     ["x"]=screenx*0.25,
  608.     ["y"]=screeny*0.43,
  609.     ["width"]=screenx*0.2,
  610.     ["height"]=screeny*0.3,
  611.     ["color"]=tocolor(255,255,255,255),
  612.     ["border"]=0,
  613.     ["borderColor"]=tocolor(50,50,50,255),
  614.     ["visible"]=false,
  615.     ["lines"]={""},
  616.     ["scrollPosition"]=0,
  617.     ["scrollBar"]=0,
  618.     ["selectedLine"]=1,
  619.     ["selectedCollumn"]=1,
  620.     ["selected"]=true,
  621.     ["func"]=
  622.         function(memo)
  623.             local lineID=memo.selectedLine
  624.             local currentLine=memo.lines[lineID]
  625.             if string.find(currentLine,"%.lua")==nil and DXs.new["typeButton "..lineID]~=nil then  
  626.                 local thisButton=DXs.new["typeButton "..lineID]
  627.                 --[[local index=#buttons
  628.                 for i=index+1,0,-1 do
  629.                     local buttonData=buttons[i]
  630.                     if buttonData==thisButton then
  631.                        
  632.                         break
  633.                     else
  634.                    
  635.                     end]]
  636.                     local buttonFound=false
  637.                     for id,button in ipairs(buttons) do
  638.                         if button==thisButton then
  639.                             buttons[id]=nil
  640.                             buttonFound=true
  641.                         elseif buttonFound==true then
  642.                             buttons[id-1]=buttons[id]
  643.                             buttons[id]=nil
  644.                         end
  645.                     end
  646.                 DXs.new["typeButton "..lineID]=nil
  647.             elseif string.find(currentLine,"%.lua")~=nil and DXs.new["typeButton "..lineID]==nil then
  648.                 local buttonHeight=dxGetFontHeight(fontSize,font)
  649.                 local buttonY=memo.y+buttonHeight*(lineID-1)
  650.                 DXs.new["typeButton "..lineID]={
  651.                     ["type"]="button",
  652.                     ["x"]=memo.x-buttonHeight*1.5,
  653.                     ["y"]=buttonY,
  654.                     ["width"]=buttonHeight*0.9,
  655.                     ["height"]=buttonHeight*0.9,
  656.                     ["color"]=tocolor(200,100,100,255),
  657.                     ["visible"]=true,
  658.                     ["fontOverlay"]=fontOverlay/2,
  659.                     ["func"]=
  660.                         function(button)
  661.                             if button.text=="Client" then
  662.                                 button.text="Server"
  663.                                 button.color=tocolor(100,200,100,255)
  664.                             elseif button.text=="Server" then
  665.                                 button.text="Shared"
  666.                                 button.color=tocolor(100,100,200,255)
  667.                             else
  668.                                 button.text="Client"
  669.                                 button.color=tocolor(200,100,100,255)
  670.                             end
  671.                         end,
  672.                     ["image"]="images/cancel.png",
  673.                     ["text"]="Client",
  674.                 }  
  675.                 buttons[#buttons+1]=DXs.new["typeButton "..lineID]
  676.                
  677.             end
  678.         end,
  679. }
  680.  
  681. DXs["new"]["filesLabel"]={
  682.     ["type"]="label",
  683.     ["x"]=screenx*0.15,
  684.     ["y"]=screeny*0.43,
  685.     ["width"]=screenx*0.15,
  686.     ["height"]=screeny*0.05,
  687.     ["color"]=tocolor(255,255,255,255),
  688.     ["visible"]=false,
  689.     ["text"]="Files",
  690.     ["selectedCollumn"]=1,
  691. }
  692.  
  693. function listResources(resources)
  694.     for id,resource in ipairs(resources) do
  695.         DXs["browser"]["resourceList"]["entries"][id]=resource.name
  696.     end
  697.     table.sort(DXs["browser"]["resourceList"]["entries"])
  698. end
  699. addEvent("onResourceList",true)
  700. addEventHandler("onResourceList",getRootElement(),listResources)
  701.  
  702. function listFiles(files)
  703.     DXs.editor.resourceFiles.entries={}
  704.     local entriesTable=DXs.editor.resourceFiles.entries
  705.     for id,file in ipairs(files) do
  706.         entriesTable[id]=file
  707.     end
  708. end
  709. addEvent("onResourceFiles",true)
  710. addEventHandler("onResourceFiles",getRootElement(),listFiles)
  711.  
  712. function openFile(fullFile)
  713.     DXs.editor.editField.lines={}
  714.     local linesTable=DXs.editor.editField.lines
  715.     local fullFile=fullFile
  716.     repeat
  717.         local start,stop=string.find(fullFile,"\n")
  718.         if start==nil then
  719.             linesTable[#linesTable+1]=string.gsub(string.sub(fullFile,0,string.len(fullFile)),"\t","    ")
  720.         else
  721.             linesTable[#linesTable+1]=string.gsub(string.sub(fullFile,0,start),"\t","    ")
  722.             fullFile=string.gsub(string.sub(fullFile,stop+1,string.len(fullFile)),"\t","    ") 
  723.         end
  724.     until start==nil
  725.     if #linesTable==0 then
  726.         linesTable[1]="-- this file was empty!"
  727.     end
  728. end
  729. addEvent("onClientFile",true)
  730. addEventHandler("onClientFile",getRootElement(),openFile)
  731.  
  732.  
  733. function setup()
  734.     buttons={}
  735.     for id,window in pairs(DXs) do
  736.         for id,data in pairs(window) do
  737.             if type(data)=="table" then
  738.                 if data.type=="button" then
  739.                     buttons[#buttons+1]=data    -- makes a reference in the buttons table to the button in the DXs table   
  740.                 elseif data.type=="list" then
  741.                     lists[#lists+1]=data                   
  742.                     scrollBars[#scrollBars+1]=data
  743.                 elseif data.type=="memo" then
  744.                     scrollBars[#scrollBars+1]=data
  745.                     memos[#memos+1]=data
  746.                 elseif data.type=="edit" then
  747.                     edits[#edits+1]=data
  748.                 end
  749.             end
  750.         end
  751.     end
  752.    
  753.     triggerServerEvent("getServerFunctions",getRootElement())
  754. end
  755. setup()
  756.  
  757. function setupSyntax(serverFunctions)
  758.     for id,data in pairs(_G) do
  759.         if type(data)=="function" then
  760.             if syntaxHighlightings[id]==nil then
  761.                 if serverFunctions[id]~=nil then
  762.                     syntaxHighlightings[id]={"#990000",true}
  763.                 else
  764.                     syntaxHighlightings[id]={"#dd0000",true}
  765.                 end
  766.                
  767.             end
  768.         end
  769.     end
  770.     for id,data in pairs(serverFunctions) do
  771.         if syntaxHighlightings[id]==nil then
  772.             syntaxHighlightings[id]={"#ff6600",true}
  773.         end
  774.     end
  775.     for id,data in pairs(string) do
  776.         if type(data)=="function" then
  777.             syntaxHighlightings[id]={"#990044",true}
  778.         end
  779.     end
  780.     for id,data in pairs(math) do
  781.         if type(data)=="function" then
  782.             syntaxHighlightings[id]={"#00aaff",true}
  783.         end
  784.     end
  785. end
  786. addEvent("onClientFunctionList",true)
  787. addEventHandler("onClientFunctionList",getRootElement(),setupSyntax)
  788.  
  789. function drawAll() -- function to draw all objects
  790.     for id,data in pairs(DXs) do
  791.         if data.type=="window" then
  792.             drawWindow(data)
  793.         end
  794.     end
  795. end
  796. addEventHandler("onClientRender",getRootElement(),drawAll)
  797.  
  798. function drawWindow(window)
  799.     if window.visible==false then return end
  800.    
  801.     if window.visible==true then
  802.         if window.border~=nil then
  803.             dxDrawRectangle(window.x-window.border,window.y-window.border,window.width+window.border*2,window.height+window.border*2,window.borderColor,postGui)
  804.         end
  805.         dxDrawRectangle(window.x,window.y,window.width,window.height,window.color,postGui)
  806.     end
  807.     for id,data in pairs(window) do
  808.         if type(data)=="table" then
  809.             drawFunctions[data.type](data)
  810.         end
  811.     end
  812. end
  813.  
  814. function playerClicked(button,state,cursorx,cursory)
  815.     if  state=="up" or button=="right" or button=="middle" then return end
  816.    
  817.     for id,button in ipairs(buttons) do
  818.         if cursorx>button.x and cursorx<button.x+button.width and cursory>button.y and cursory<button.y+button.height and button.visible==true then
  819.             if button.func~=nil then
  820.                 button.func(button)
  821.             end
  822.             break  
  823.         end
  824.     end
  825.     for id,list in ipairs(lists) do
  826.         if cursorx>list.x and cursorx<list.x+list.width and cursory>list.y and cursory<list.y+list.height and list.visible==true then
  827.             local fontHeight=dxGetFontHeight(fontSize,font)
  828.             local ammountOfLines=list.height/fontHeight
  829.             local cursory=cursory-list.y
  830.             local lineClicked=math.floor(cursory/list.height*ammountOfLines+0.5)
  831.             local toSelect=lineClicked-list.scrollPosition
  832.             list.selected=toSelect
  833.             if list.func~=nil then
  834.                 list.func(list)
  835.             end
  836.             break
  837.         end
  838.     end
  839.     for id,memo in ipairs(memos) do
  840.         if cursorx>memo.x and cursorx<memo.x+memo.width and cursory>memo.y and cursory<memo.y+memo.height and memo.visible==true and memo.selected==true then
  841.             local fontHeight=dxGetFontHeight(fontSize,font)
  842.             local ammountOfLines=memo.height/fontHeight
  843.             local cursory=cursory-memo.y
  844.             local lineClicked=math.floor(cursory/memo.height*ammountOfLines+0.5)
  845.             local toSelect=math.floor(lineClicked-memo.scrollPosition+0.5)
  846.             if toSelect>#memo.lines then break end
  847.             memo.selectedLine=toSelect
  848.            
  849.             local letterWidth=dxGetTextWidth("I",1,font)
  850.             local ammountOfLetters=memo.width/letterWidth
  851.             local cursorx=cursorx-memo.x
  852.             local collumnClicked=math.floor(cursorx/memo.width*0.91*ammountOfLetters+0.5)
  853.             local scrollPosition=0
  854.             if memo.hScrollPosition~=nil then
  855.                 scrollPosition=memo.hScrollPosition
  856.             end
  857.             local toSelectCollumn=math.floor(collumnClicked-scrollPosition+0.5)
  858.             if toSelect>string.len(memo.lines[memo.selectedLine]) then
  859.                 toSelect=string.len(memo.lines[memo.selectedLine])
  860.             end
  861.             memo.selectedCollumn=toSelectCollumn
  862.             break
  863.         elseif cursorx>memo.x and cursorx<memo.x+memo.width and cursory>memo.y and cursory<memo.y+memo.height and memo.visible==true then
  864.             for id,othermemo in ipairs(memos) do
  865.                 if othermemo~=memo then
  866.                     othermemo.selected=false
  867.                 end
  868.             end
  869.             for id,otherEdit in ipairs(edits) do
  870.                 if otherEdit~=edit then
  871.                     otherEdit.selected=false
  872.                 end
  873.             end
  874.             memo.selected=true
  875.         end
  876.     end
  877.     for id,list in ipairs(scrollBars) do
  878.         if cursorx>list.x+list.width*0.9 and cursorx<list.x+list.width and cursory>list.y and cursory<list.y+list.height and list.visible==true then
  879.             local scrollBarHeight=list.height*0.96
  880.             local cursory=cursory-list.y
  881.             list.scrollBar=cursory/scrollBarHeight
  882.             if list.entries==nil then
  883.                 list.scrollPosition=-1*#list.lines*list.scrollBar
  884.             else
  885.                 list.scrollPosition=-1*#list.entries*list.scrollBar
  886.             end
  887.             if list.scrollBar<0 then
  888.                 list.scrollBar=0
  889.             elseif list.scrollBar>1 then
  890.                 list.scrollBar=1
  891.             end
  892.             break  
  893.         elseif cursorx>list.x and cursorx<list.x+list.width*0.92 and cursory>list.y+list.height*0.95 and cursory<list.y+list.height and list.visible==true and list.hScrollBar~=nil then
  894.             local scrollBarWidth=list.width*0.92
  895.             local cursorx=cursorx-list.x
  896.             list.hScrollBar=cursorx/scrollBarWidth
  897.             list.hScrollPosition=-1*string.len(list.lines[list.selectedLine])*list.hScrollBar
  898.             if list.hScrollBar<0 then
  899.                 list.hScrollBar=0
  900.             elseif list.hScrollBar>1 then
  901.                 list.hScrollBar=1
  902.             end
  903.             break
  904.         end
  905.     end
  906.     for id,edit in ipairs(edits) do
  907.         if cursorx>edit.x and cursorx<edit.x+edit.width and cursory>edit.y and cursory<edit.y+edit.height and edit.visible==true then
  908.             for id,otherEdit in ipairs(edits) do
  909.                 if otherEdit~=edit then
  910.                     otherEdit.selected=false
  911.                 end
  912.             end
  913.             for id,othermemo in ipairs(memos) do
  914.                 if othermemo~=memo then
  915.                     othermemo.selected=false
  916.                 end
  917.             end
  918.             edit.selected=true
  919.         end
  920.     end
  921. end
  922. addEventHandler("onClientClick",getRootElement(),playerClicked)
  923.  
  924. function playerDoubleClicked(button,cursorx,cursory)
  925.     for id,list in ipairs(lists) do
  926.         if cursorx>list.x and cursorx<list.x+list.width and cursory>list.y and cursory<list.y+list.height and list.visible==true and list.selected>0 then
  927.             local fontHeight=dxGetFontHeight(fontSize,font)
  928.             local ammountOfLines=list.height/fontHeight
  929.             local cursory=cursory-list.y
  930.             local lineClicked=math.floor(cursory/list.height*ammountOfLines+0.5)
  931.             local toSelect=lineClicked-list.scrollPosition
  932.             list.selected=toSelect
  933.             if list.func~=nil then
  934.                 list.func(true)
  935.             end
  936.             break
  937.         end
  938.     end
  939. end
  940. addEventHandler("onClientDoubleClick",getRootElement(),playerDoubleClicked)
  941.  
  942. local keys={["space"]=" ",["tab"]="    ",["#"]="'",["test"]="test",["mouse_wheel_up"]="",["mouse_wheel_down"]=""}
  943.  
  944. local upperCase={["1"]="!",["2"]="@",["3"]="#",["4"]="$",["5"]="%",["6"]="^",["7"]="&",["8"]="*",["9"]="(",["0"]=")",["`"]="~",["-"]="_",["="]="+",["\\"]="|",["["]="{",["]"]="}",[";"]=":",["'"]='"',[","]="<",["."]=">",["/"]="?",}
  945.  
  946. function playerKey(button,state)
  947.     if button=="lshift" then
  948.         case=not case
  949.     elseif button=="capslock" and state==true then
  950.         case=not case
  951.     elseif button=="lctrl" then
  952.         ctrl=state
  953.     end
  954.     for id,memo in ipairs(memos) do
  955.         if memo.selected==true and memo.visible==true then
  956.             cancelEvent()
  957.             if button=="v" and ctrl==true then
  958.                 if state==false then
  959.                     postGui=true
  960.                     local paste=guiGetText(pasteMemo)
  961.                     local pasteLines={}
  962.                     repeat
  963.                         local start,stop=string.find(paste,"\n")
  964.                         if start~=nil then
  965.                             pasteLines[#pasteLines+1]=string.gsub(string.gsub(string.sub(paste,0,start),"\n",""),"\t","    ")
  966.                             paste=string.sub(paste,stop+1,string.len(paste))
  967.                         end
  968.                     until start==nil
  969.                    
  970.                     local lineCount=#memo.lines
  971.                     local pasteCount=#pasteLines
  972.                     for i=lineCount+pasteCount,memo.selectedLine,-1 do
  973.                         memo.lines[i]=memo.lines[i-pasteCount]
  974.                     end
  975.                     for i=memo.selectedLine-1,memo.selectedLine+pasteCount do
  976.                         if pasteLines[i-memo.selectedLine]~=nil then
  977.                             memo.lines[i]=pasteLines[i-memo.selectedLine]
  978.                         end
  979.                     end
  980.                     if memo.lines[memo.selectedLine]==nil then
  981.                         memo.lines[memo.selectedLine]=" "
  982.                     end
  983.                    
  984.                     break
  985.                 else
  986.                     postGui=false
  987.                     guiSetText(pasteMemo,"")
  988.                     guiSetVisible(pasteMemo,true)
  989.                     guiBringToFront(pasteMemo)
  990.                     guiMemoSetCaretIndex(pasteMemo,0)
  991.                     break
  992.                 end
  993.             end
  994.             if state==false then return end
  995.             if button=="enter" then
  996.                 local nextLine=string.sub(memo.lines[memo.selectedLine],memo.selectedCollumn,string.len(memo.lines[memo.selectedLine]))
  997.                 memo.lines[memo.selectedLine]=string.sub(memo.lines[memo.selectedLine],0,memo.selectedCollumn-1)
  998.                 memo.selectedLine=memo.selectedLine+1
  999.                 local index=#memo.lines
  1000.                 for i=index+1,memo.selectedLine,-1 do
  1001.                     if i==memo.selectedLine then
  1002.                         memo.lines[i]=nextLine
  1003.                     else
  1004.                         memo.lines[i]=memo.lines[i-1]
  1005.                     end
  1006.                 end
  1007.                 memo.selectedCollumn=1
  1008.             elseif button=="arrow_u" then
  1009.                 memo.selectedLine=memo.selectedLine-1
  1010.                 if string.len(memo.selectedLine)>memo.selectedCollumn then
  1011.                     memo.selectedCollumn=string.len(memo.selectedLine)
  1012.                 end
  1013.             elseif button=="arrow_d" then
  1014.                 memo.selectedLine=memo.selectedLine+1
  1015.                 if string.len(memo.selectedLine)>memo.selectedCollumn then
  1016.                     memo.selectedCollumn=string.len(memo.selectedLine)
  1017.                 end
  1018.                 --memo.selectedCollumn=1
  1019.             elseif button=="arrow_l" then
  1020.                 if memo.selectedCollumn>1 then
  1021.                     memo.selectedCollumn=memo.selectedCollumn-1
  1022.                 elseif memo.selectedLine>1 then
  1023.                     memo.selectedLine=memo.selectedLine-1
  1024.                     memo.selectedCollumn=string.len(memo.lines[memo.selectedLine])+1
  1025.                 end
  1026.             elseif button=="arrow_r" then
  1027.                 if string.len(memo.lines[memo.selectedLine])<memo.selectedCollumn then
  1028.                     if memo.lines[memo.selectedLine+1]~=nil then
  1029.                         memo.selectedLine=memo.selectedLine+1
  1030.                         memo.selectedCollumn=1
  1031.                     end
  1032.                 else
  1033.                     memo.selectedCollumn=memo.selectedCollumn+1
  1034.                 end
  1035.             elseif button=="backspace" then
  1036.                 memo.lines[memo.selectedLine]=string.sub(memo.lines[memo.selectedLine],0,memo.selectedCollumn-2)..string.sub(memo.lines[memo.selectedLine],memo.selectedCollumn+0,string.len(memo.lines[memo.selectedLine]))
  1037.                 if memo.selectedCollumn>1 then
  1038.                     memo.selectedCollumn=memo.selectedCollumn-1
  1039.                 elseif memo.selectedLine<=1 then
  1040.                     memo.selectedLine=memo.selectedLine-1
  1041.                     memo.selectedCollumn=string.len(memo.lines[memo.selectedLine])
  1042.                 end
  1043.             elseif button=="delete" then
  1044.                 memo.lines[memo.selectedLine]=string.sub(memo.lines[memo.selectedLine],0,memo.selectedCollumn-1)..string.sub(memo.lines[memo.selectedLine],memo.selectedCollumn+1,string.len(memo.lines[memo.selectedLine]))
  1045.             else
  1046.                 local button=button
  1047.                 if keys[button]==nil and string.len(button)>1 then return end
  1048.                 if keys[button]~=nil then
  1049.                     button=keys[button]
  1050.                 end
  1051.                 if case==true and upperCase[button]~=nil then
  1052.                     button=upperCase[button]
  1053.                 elseif case==true then
  1054.                     button=string.upper(button)
  1055.                 end
  1056.                 if memo.lines[memo.selectedLine]==nil then
  1057.                     memo.lines[memo.selectedLine]=""
  1058.                 end
  1059.                 memo.lines[memo.selectedLine]=string.sub(memo.lines[memo.selectedLine],0,memo.selectedCollumn-1)..button..string.sub(memo.lines[memo.selectedLine],memo.selectedCollumn,string.len(memo.lines[memo.selectedLine]))
  1060.                 memo.selectedCollumn=memo.selectedCollumn+string.len(button)
  1061.             end
  1062.             if memo.lines[memo.selectedLine]==nil then
  1063.                 memo.lines[memo.selectedLine]=""
  1064.             end
  1065.             if memo.func~=nil then
  1066.                 memo.func(memo)
  1067.             end
  1068.         end
  1069.     end
  1070.     if state==false then return end
  1071.     for id,edit in ipairs(edits) do
  1072.         if edit.selected==true and edit.visible==true then
  1073.             cancelEvent()
  1074.             if button=="arrow_l" then
  1075.                 if edit.selectedCollumn>1 then
  1076.                     edit.selectedCollumn=edit.selectedCollumn-1
  1077.                 end
  1078.             elseif button=="arrow_r" then
  1079.                 edit.selectedCollumn=edit.selectedCollumn+1
  1080.             elseif button=="backspace" then
  1081.                 edit.text=string.sub(edit.text,0,edit.selectedCollumn-2)..string.sub(edit.text,edit.selectedCollumn+0,string.len(edit.text))
  1082.                 if edit.selectedCollumn>0 then
  1083.                     edit.selectedCollumn=edit.selectedCollumn-1
  1084.                 end
  1085.             elseif button=="delete" then
  1086.                 edit.text=string.sub(edit.text,0,edit.selectedCollumn-1)..string.sub(edit.text,edit.selectedCollumn+1,string.len(edit.text))
  1087.             else
  1088.                 if case==true and upperCase[button]~=nil then
  1089.                     button=upperCase[button]
  1090.                 elseif case==true then
  1091.                     button=string.upper(button)
  1092.                 end
  1093.                 local button=button
  1094.                 if keys[button]==nil and string.len(button)>1 then return end
  1095.                 if keys[button]~=nil then
  1096.                     button=keys[button]
  1097.                 end
  1098.                 edit.text=string.sub(edit.text,0,edit.selectedCollumn-1)..button..string.sub(edit.text,edit.selectedCollumn,string.len(edit.text))
  1099.                 edit.selectedCollumn=edit.selectedCollumn+string.len(button)
  1100.             end
  1101.         end
  1102.     end
  1103.  
  1104.     if button~="mouse_wheel_up" and button~="mouse_wheel_down" or isCursorShowing()==false then return end
  1105.     local cursorx,cursory=getCursorPosition()
  1106.     local cursorx,cursory=cursorx*screenx,cursory*screeny  
  1107.     for id,list in ipairs(scrollBars) do
  1108.         if cursorx>list.x and cursorx<list.x+list.width and cursory>list.y and cursory<list.y+list.height*0.95 and list.visible==true then
  1109.             if list.type=="list" then
  1110.                 if button=="mouse_wheel_up" then
  1111.                     list.scrollBar=list.scrollBar-0.025
  1112.                     list.scrollPosition=list.scrollPosition+6
  1113.                 elseif button=="mouse_wheel_down" then
  1114.                     list.scrollBar=list.scrollBar+0.025
  1115.                     list.scrollPosition=list.scrollPosition-6
  1116.                 end
  1117.                 if list.scrollBar<0 then
  1118.                     list.scrollBar=0
  1119.                 elseif list.scrollBar>1 then
  1120.                     list.scrollBar=1
  1121.                 end
  1122.                 if list.scrollPosition>0 then
  1123.                     list.scrollPosition=0
  1124.                 end
  1125.                 cancelEvent()
  1126.             elseif list.type=="memo" then
  1127.                 if button=="mouse_wheel_up" then
  1128.                     list.scrollBar=list.scrollBar-0.01
  1129.                     list.scrollPosition=list.scrollPosition+#list.lines/100
  1130.                 elseif button=="mouse_wheel_down" then
  1131.                     list.scrollBar=list.scrollBar+0.01
  1132.                     list.scrollPosition=list.scrollPosition-#list.lines/100
  1133.                 end
  1134.                 if list.scrollBar<0 then
  1135.                     list.scrollBar=0
  1136.                 elseif list.scrollBar>1 then
  1137.                     list.scrollBar=1
  1138.                 end
  1139.                 if list.scrollPosition>0 then
  1140.                     list.scrollPosition=0
  1141.                 end
  1142.                 cancelEvent()
  1143.             end
  1144.             break  
  1145.         elseif cursorx>list.x and cursorx<list.x+list.width and cursory<list.y+list.height and cursory>list.y+list.height*0.95 and list.visible==true then
  1146.             if list.hScrollBar~=nil then
  1147.                 if button=="mouse_wheel_up" then
  1148.                     list.hScrollBar=list.hScrollBar-0.05
  1149.                     list.hScrollPosition=list.hScrollPosition+string.len(list.lines[list.selectedLine])/20
  1150.                 elseif button=="mouse_wheel_down" then
  1151.                     list.hScrollBar=list.hScrollBar+0.05
  1152.                     list.hScrollPosition=list.hScrollPosition-string.len(list.lines[list.selectedLine])/20
  1153.                 end
  1154.                 if list.hScrollBar<0 then
  1155.                     list.hScrollBar=0
  1156.                 elseif list.hScrollBar>1 then
  1157.                     list.hScrollBar=1
  1158.                 end
  1159.                 if list.hScrollPosition>0 then
  1160.                     list.hScrollPosition=0
  1161.                 end
  1162.             end
  1163.         end
  1164.     end
  1165. end
  1166. addEventHandler("onClientKey",getRootElement(),playerKey)
  1167.  
  1168. function toggleEditor()
  1169.     dxSetVisible(DXs.editor,not DXs.editor.visible)
  1170.     showCursor(DXs.editor.visible)
  1171. end
  1172. addCommandHandler(command,toggleEditor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement