Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- I'll be working on a dx based resource editor ingame.
- If you have questions about what I am doing, ask them in the message box to the right of the screen.
- Or type them in the message box below my code.
- Besides that do not write anyhting in the code, to let me continue my work.
- ]]
- local screenx,screeny=guiGetScreenSize()
- local fontSize=1
- local fontOverlay=1
- local currentResource=nil
- local currentFile=nil
- local toOpenFile=nil
- local font=--[["arial"]]dxCreateFont("font.ttf",12)
- local overLayFont=dxCreateFont("font.ttf",40)
- local buttons={}
- local scrollBars={}
- local lists={}
- local memos={}
- local edits={}
- local case=false
- local ctrl=false
- local command="script"
- local postGui=true
- local pasteMemo=guiCreateMemo(-0.4,0.4,0.2,0.2,"",true)
- guiSetVisible(pasteMemo,false)
- local syntaxHighlightings={
- ["function"]={"#5555ff",true},
- ["if"]={"#5555ff",true},
- ["else"]={"#5555ff",true},
- ["elseif"]={"#5555ff",true},
- ["then"]={"#5555ff",true},
- ["end"]={"#5555ff",true},
- ["do"]={"#5555ff",true},
- ["and"]={"#5555ff",true},
- ["or"]={"#5555ff",true},
- ["for"]={"#5555ff",true},
- ["return"]={"#5555ff",true},
- ["repeat"]={"#5555ff",true},
- ["until"]={"#5555ff",true},
- ["local"]={"#5555ff",true},
- ["true"]={"#5555ff",true},
- ["false"]={"#5555ff",true},
- --["[^'][0-9]*[^']"]={"#888800",false},
- ["'.*'"]={"#555555",false},
- ['".*"']={"#555555",false},
- ["%-%-.*"]={"#009900",false},
- ["string%."]={"#990044",false},
- ["math%."]={"#00aaff",false},
- ["ipairs"]={"#00aaff",true},
- ["pairs"]={"#00aaff",true},
- --["string"]={"#00aaff",true},
- ["math"]={"#00aaff",true},
- ["tostring"]={"#00aaff",true},
- ["tonumber"]={"#00aaff",true},
- ["_G"]={"#00aaff",true},
- }
- function dxSetVisible(dxData,bool)
- dxData.visible=bool
- for id,data in pairs(dxData) do
- if type(data)=="table" and data.visible~=nil then
- data.visible=bool
- end
- end
- end
- function hightLightSyntax(fullString)
- for text,data in pairs(syntaxHighlightings) do
- local start,stop=string.find(fullString,text)
- if start~=nil then
- if data[2]==true then
- if stop==string.len(fullString) and start==1 then
- fullString=string.gsub(fullString,text,data[1]..string.sub(fullString,start,stop))
- elseif stop==string.len(fullString) then
- fullString=string.gsub(fullString," "..text," "..data[1]..string.sub(fullString,start,stop).."#000000 ")
- fullString=string.gsub(fullString,"%)"..text,"%)"..data[1]..string.sub(fullString,start,stop).."#000000 ")
- fullString=string.gsub(fullString,"%("..text,"%("..data[1]..string.sub(fullString,start,stop).."#000000 ")
- fullString=string.gsub(fullString,"%."..text,"%."..data[1]..string.sub(fullString,start,stop).."#000000 ")
- fullString=string.gsub(fullString,"\n"..text,"\n"..data[1]..string.sub(fullString,start,stop).."#000000 ")
- fullString=string.gsub(fullString,"t"..text,"\t"..data[1]..string.sub(fullString,start,stop).."#000000 ")
- else
- fullString=string.gsub(fullString,text.." ",data[1]..string.sub(fullString,start,stop).."#000000 ")
- fullString=string.gsub(fullString,text.."%(",data[1]..string.sub(fullString,start,stop).."#000000(")
- fullString=string.gsub(fullString,text.."%)",data[1]..string.sub(fullString,start,stop).."#000000)")
- fullString=string.gsub(fullString,text.."%.",data[1]..string.sub(fullString,start,stop).."#000000.")
- fullString=string.gsub(fullString,text.."\n",data[1]..string.sub(fullString,start,stop).."#000000")
- fullString=string.gsub(fullString,text.."\t",data[1]..string.sub(fullString,start,stop).."#000000")
- end
- else
- if stop==string.len(fullString) then
- fullString=string.gsub(fullString,text,data[1]..string.sub(fullString,start,stop).."#000000")
- else
- fullString=string.gsub(fullString,text,data[1]..string.sub(fullString,start,stop).."#000000")
- end
- end
- if text=="--" then
- break
- end
- end
- end
- return fullString
- end
- local drawFunctions={
- ["button"]=
- function(button)
- if button.visible==false then return end
- if fileExists(button.image)==true then
- dxDrawImage(button.x,button.y,button.width,button.height,button.image,0,0,0,tocolor(255,255,255,255),postGui)
- else
- dxDrawRectangle(button.x,button.y,button.width,button.height,button.color,postGui)
- end
- if isCursorShowing()==false then return end
- local cursorx,cursory=getCursorPosition()
- local cursorx,cursory=cursorx*screenx,cursory*screeny
- 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
- local fontOverlay=fontOverlay
- if button.fontOverlay~=nil then
- fontOverlay=button.fontOverlay
- end
- dxDrawText(button.text,cursorx,cursory,cursorx,cursory,tocolor(100,100,200,255),fontOverlay,overLayFont,"center","center",false,false,postGui)
- end
- end,
- ["list"]=
- function(list)
- if list.visible==false then return end
- if list.border~=nil then --background
- dxDrawRectangle(list.x-list.border,list.y-list.border,list.width+list.border*2,list.height+list.border*2,list.borderColor,postGui)
- end
- dxDrawRectangle(list.x,list.y,list.width,list.height,list.color,postGui)
- dxDrawRectangle(list.x+list.width*0.88,list.y,list.width*0.12,list.height,list.borderColor,postGui) --scrollbar
- dxDrawRectangle(list.x+list.width*0.91,list.y+list.height*0.02,list.width*0.08,list.height*0.96,list.color,postGui)
- 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)
- local fontHeight=dxGetFontHeight(fontSize,font)
- for id,entry in ipairs(list.entries) do
- if list.selected==id then
- if id-1+list.scrollPosition>=0 then
- 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)
- end
- else
- if id-1+list.scrollPosition>=0 then
- 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)
- end
- end
- end
- end,
- ["memo"]=
- function(memo)
- if memo.visible==false then return end
- if memo.border~=nil then --background
- dxDrawRectangle(memo.x-memo.border,memo.y-memo.border,memo.width+memo.border*2,memo.height+memo.border*2,memo.borderColor,postGui)
- end
- dxDrawRectangle(memo.x,memo.y,memo.width,memo.height,memo.color,postGui)
- dxDrawRectangle(memo.x+memo.width*0.92,memo.y,memo.width*0.08,memo.height,memo.borderColor,postGui) --scrollbar
- dxDrawRectangle(memo.x+memo.width*0.93,memo.y+memo.height*0.02,memo.width*0.06,memo.height*0.96,memo.color,postGui)
- 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)
- local memoHeight=memo.height
- if memo.hScrollBar~=nil then
- dxDrawRectangle(memo.x,memo.y+memo.height*0.95,memo.width*0.93,memo.height*0.05,memo.borderColor,postGui) --scrollbar
- dxDrawRectangle(memo.x+memo.width*0.01,memo.y+memo.height*0.96,memo.width*0.91,memo.height*0.03,memo.color,postGui)
- 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)
- memoHeight=memoHeight*0.95
- end
- local fontHeight=dxGetFontHeight(fontSize,font)
- local ammountOfLines=memoHeight/fontHeight
- local letterWidth=dxGetTextWidth("I",1,font)
- local ammountOfLetters=memo.width/letterWidth*0.87
- local horizontalScrollPosition=0
- if memo.hScrollPosition~=nil then
- horizontalScrollPosition=-memo.hScrollPosition
- end
- for id,entry in ipairs(memo.lines) do
- if id-1+memo.scrollPosition>=0 and id+memo.scrollPosition<ammountOfLines then
- local entry=entry
- --if string.len(entry)>ammountOfLetters then
- entry=string.sub(entry,1+horizontalScrollPosition,ammountOfLetters+horizontalScrollPosition)
- --end
- if memo.syntax=="lua" then
- entry=hightLightSyntax(entry)
- end
- if memo.selectedLine==id then
- local cursorEntry=string.gsub(entry,"#%x%x%x%x%x%x","")
- local cursorEntry=string.sub(cursorEntry,0,memo.selectedCollumn)
- local width=dxGetTextWidth(cursorEntry,fontSize,font)
- local charWidth=dxGetTextWidth("I",fontSize,font)
- 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)
- 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)
- 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)
- else
- 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)
- 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)
- end
- end
- end
- --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)
- end,
- ["label"]=
- function(label)
- if label.visible==false then return end
- 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)
- end,
- ["edit"]=
- function(edit)
- dxDrawRectangle(edit.x,edit.y,edit.width,edit.height,edit.color,true)
- 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)
- local width=dxGetTextWidth(string.sub(edit.text,0,edit.selectedCollumn),fontSize,font)
- if edit.selected==true then
- 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)
- end
- end,
- }
- local DXs={}
- DXs["editor"]={
- ["type"]="window",
- ["x"]=screenx*0.1,
- ["y"]=screeny*0.1,
- ["width"]=screenx*0.8,
- ["height"]=screeny*0.8,
- ["color"]=tocolor(200,200,200,255),
- ["border"]=15,
- ["borderColor"]=tocolor(50,50,50,255),
- ["visible"]=false,
- }
- DXs["editor"]["editField"]={
- ["type"]="memo",
- ["x"]=screenx*0.35,
- ["y"]=screeny*0.25,
- ["width"]=screenx*0.5,
- ["height"]=screeny*0.6,
- ["color"]=tocolor(255,255,255,255),
- ["border"]=5,
- ["borderColor"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["lines"]={""},
- ["scrollPosition"]=0,
- ["scrollBar"]=0,
- ["selectedLine"]=1,
- ["selectedCollumn"]=1,
- ["hScrollPosition"]=0,
- ["hScrollBar"]=0,
- ["selected"]=true,
- ["syntax"]="lua",
- }
- DXs["editor"]["save"]={
- ["type"]="button",
- ["x"]=screenx*0.35,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- local fullFile=""
- for id,text in ipairs(DXs.editor.editField.lines) do
- if string.find(text,"\n")==nil then
- fullFile=fullFile..text.."\n"
- else
- fullFile=fullFile..text
- end
- end
- triggerServerEvent("onFileSave",getRootElement(),currentFile,fullFile)
- end,
- ["image"]="images/save.png",
- ["text"]="Save",
- }
- DXs["editor"]["resourceFiles"]={
- ["type"]="list",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.7,
- ["color"]=tocolor(255,255,255,255),
- ["border"]=5,
- ["borderColor"]=tocolor(50,50,50,255),
- ["entries"]={},
- ["selected"]=nil,
- ["visible"]=false,
- ["scrollPosition"]=0,
- ["scrollBar"]=0,
- ["func"]=
- function(double)
- if double==true then
- local selected=DXs.editor.resourceFiles.entries[DXs.editor.resourceFiles.selected]
- if selected~=nil then
- toOpenFile=":"..currentResource.."/"..selected
- currentFile=toOpenFile
- triggerServerEvent("onClientFileRequest",getRootElement(),toOpenFile)
- DXs.editor.editField.scrollBar=0
- DXs.editor.editField.scrollPosition=0
- DXs.editor.editField.selectedCollumn=1
- DXs.editor.editField.selectedLine=1
- end
- end
- end,
- }
- DXs["editor"]["browse"]={
- ["type"]="button",
- ["x"]=screenx*0.45,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- dxSetVisible(DXs.editor,false)
- dxSetVisible(DXs.browser,true)
- triggerServerEvent("onResourceListRequest",getRootElement())
- end,
- ["image"]="images/search.png",
- ["text"]="Browse",
- }
- DXs["editor"]["create"]={
- ["type"]="button",
- ["x"]=screenx*0.55,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- dxSetVisible(DXs.new,true)
- dxSetVisible(DXs.editor,false)
- end,
- ["image"]="images/newResource.png",
- ["text"]="New Resource",
- }
- DXs["editor"]["run"]={
- ["type"]="button",
- ["x"]=screenx*0.65,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- triggerServerEvent("onResourceRun",getRootElement(),currentResource)
- end,
- ["image"]="images/run.png",
- ["text"]="Run",
- }
- DXs["editor"]["close"]={
- ["type"]="button",
- ["x"]=screenx*0.75,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- dxSetVisible(DXs.editor,false)
- showCursor(false)
- end,
- ["image"]="images/cancel.png",
- ["text"]="Cancel",
- }
- DXs["browser"]={
- ["type"]="window",
- ["x"]=screenx*0.1,
- ["y"]=screeny*0.1,
- ["width"]=screenx*0.4,
- ["height"]=screeny*0.8,
- ["color"]=tocolor(200,200,200,255),
- ["border"]=15,
- ["borderColor"]=tocolor(50,50,50,255),
- ["visible"]=false,
- }
- DXs["browser"]["resourceList"]={
- ["type"]="list",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.35,
- ["width"]=screenx*0.3,
- ["height"]=screeny*0.45,
- ["color"]=tocolor(255,255,255,255),
- ["border"]=5,
- ["borderColor"]=tocolor(50,50,50,255),
- ["entries"]={},
- ["selected"]=nil,
- ["visible"]=false,
- ["scrollPosition"]=0,
- ["scrollBar"]=0,
- }
- DXs["browser"]["open"]={
- ["type"]="button",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- if DXs.browser.resourceList.selected~=nil and DXs.browser.resourceList.selected>0 then
- currentResource=DXs.browser.resourceList.entries[DXs.browser.resourceList.selected]
- triggerServerEvent("onResourceFilesRequest",getRootElement(),DXs.browser.resourceList.entries[DXs.browser.resourceList.selected])
- dxSetVisible(DXs.editor,true)
- dxSetVisible(DXs.browser,false)
- DXs.editor.editField.lines={}
- DXs.editor.editField.scrollBar=0
- DXs.editor.editField.scrollPosition=0
- DXs.editor.editField.selectedCollumn=1
- DXs.editor.editField.selectedLine=1
- DXs.editor.editField.hScrollBar=0
- DXs.editor.editField.hScrollPosition=0
- end
- end,
- ["image"]="images/open.png",
- ["text"]="Open",
- }
- DXs["browser"]["cancel"]={
- ["type"]="button",
- ["x"]=screenx*0.25,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- dxSetVisible(DXs.editor,true)
- dxSetVisible(DXs.browser,false)
- end,
- ["image"]="images/cancel.png",
- ["text"]="Cancel",
- }
- DXs["new"]={
- ["type"]="window",
- ["x"]=screenx*0.1,
- ["y"]=screeny*0.1,
- ["width"]=screenx*0.4,
- ["height"]=screeny*0.8,
- ["color"]=tocolor(200,200,200,255),
- ["border"]=15,
- ["borderColor"]=tocolor(50,50,50,255),
- ["visible"]=false,
- }
- DXs["new"]["create"]={
- ["type"]="button",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- dxSetVisible(DXs.editor,true)
- dxSetVisible(DXs.new,false)
- if DXs.new.resource.text=="" or DXs.new.author.text=="" or DXs.new.scriptType.text=="" then return end
- DXs.new.resource.text=string.gsub(DXs.new.resource.text," ","-")
- local filesTable={}
- local linesTable=DXs.new.files.lines
- for id,line in ipairs(linesTable) do
- filesTable[#filesTable+1]={["text"]=line}
- if string.find(line,"%.lua")~=nil and DXs.new["typeButton "..id]~=nil then
- local concerningButton=DXs.new["typeButton "..id]
- filesTable[#filesTable]["type"]=concerningButton.text
- end
- end
- triggerServerEvent("onResourceCreate",getRootElement(),DXs.new.resource.text,DXs.new.author.text,DXs.new.scriptType.text,filesTable)
- end,
- ["image"]="images/newResource.png",
- ["text"]="Create",
- }
- DXs["new"]["cancel"]={
- ["type"]="button",
- ["x"]=screenx*0.25,
- ["y"]=screeny*0.15,
- ["width"]=screenx*0.08,
- ["height"]=screeny*0.08,
- ["color"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["func"]=
- function()
- dxSetVisible(DXs.editor,true)
- dxSetVisible(DXs.new,false)
- end,
- ["image"]="images/cancel.png",
- ["text"]="Cancel",
- }
- DXs["new"]["resource"]={
- ["type"]="edit",
- ["x"]=screenx*0.25,
- ["y"]=screeny*0.25,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="",
- ["selectedCollumn"]=1,
- ["selected"]=false,
- }
- DXs["new"]["resourcelabel"]={
- ["type"]="label",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.25,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="Resource Name",
- ["selectedCollumn"]=1,
- }
- DXs["new"]["author"]={
- ["type"]="edit",
- ["x"]=screenx*0.25,
- ["y"]=screeny*0.31,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="",
- ["selectedCollumn"]=1,
- ["selected"]=false,
- }
- DXs["new"]["authorLabel"]={
- ["type"]="label",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.31,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="Author",
- ["selectedCollumn"]=1,
- }
- DXs["new"]["scriptType"]={
- ["type"]="edit",
- ["x"]=screenx*0.25,
- ["y"]=screeny*0.37,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="",
- ["selectedCollumn"]=1,
- ["selected"]=false,
- }
- DXs["new"]["scriptTypeLabel"]={
- ["type"]="label",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.37,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="type",
- ["selectedCollumn"]=1,
- }
- DXs["new"]["files"]={
- ["type"]="memo",
- ["x"]=screenx*0.25,
- ["y"]=screeny*0.43,
- ["width"]=screenx*0.2,
- ["height"]=screeny*0.3,
- ["color"]=tocolor(255,255,255,255),
- ["border"]=0,
- ["borderColor"]=tocolor(50,50,50,255),
- ["visible"]=false,
- ["lines"]={""},
- ["scrollPosition"]=0,
- ["scrollBar"]=0,
- ["selectedLine"]=1,
- ["selectedCollumn"]=1,
- ["selected"]=true,
- ["func"]=
- function(memo)
- local lineID=memo.selectedLine
- local currentLine=memo.lines[lineID]
- if string.find(currentLine,"%.lua")==nil and DXs.new["typeButton "..lineID]~=nil then
- local thisButton=DXs.new["typeButton "..lineID]
- --[[local index=#buttons
- for i=index+1,0,-1 do
- local buttonData=buttons[i]
- if buttonData==thisButton then
- break
- else
- end]]
- local buttonFound=false
- for id,button in ipairs(buttons) do
- if button==thisButton then
- buttons[id]=nil
- buttonFound=true
- elseif buttonFound==true then
- buttons[id-1]=buttons[id]
- buttons[id]=nil
- end
- end
- DXs.new["typeButton "..lineID]=nil
- elseif string.find(currentLine,"%.lua")~=nil and DXs.new["typeButton "..lineID]==nil then
- local buttonHeight=dxGetFontHeight(fontSize,font)
- local buttonY=memo.y+buttonHeight*(lineID-1)
- DXs.new["typeButton "..lineID]={
- ["type"]="button",
- ["x"]=memo.x-buttonHeight*1.5,
- ["y"]=buttonY,
- ["width"]=buttonHeight*0.9,
- ["height"]=buttonHeight*0.9,
- ["color"]=tocolor(200,100,100,255),
- ["visible"]=true,
- ["fontOverlay"]=fontOverlay/2,
- ["func"]=
- function(button)
- if button.text=="Client" then
- button.text="Server"
- button.color=tocolor(100,200,100,255)
- elseif button.text=="Server" then
- button.text="Shared"
- button.color=tocolor(100,100,200,255)
- else
- button.text="Client"
- button.color=tocolor(200,100,100,255)
- end
- end,
- ["image"]="images/cancel.png",
- ["text"]="Client",
- }
- buttons[#buttons+1]=DXs.new["typeButton "..lineID]
- end
- end,
- }
- DXs["new"]["filesLabel"]={
- ["type"]="label",
- ["x"]=screenx*0.15,
- ["y"]=screeny*0.43,
- ["width"]=screenx*0.15,
- ["height"]=screeny*0.05,
- ["color"]=tocolor(255,255,255,255),
- ["visible"]=false,
- ["text"]="Files",
- ["selectedCollumn"]=1,
- }
- function listResources(resources)
- for id,resource in ipairs(resources) do
- DXs["browser"]["resourceList"]["entries"][id]=resource.name
- end
- table.sort(DXs["browser"]["resourceList"]["entries"])
- end
- addEvent("onResourceList",true)
- addEventHandler("onResourceList",getRootElement(),listResources)
- function listFiles(files)
- DXs.editor.resourceFiles.entries={}
- local entriesTable=DXs.editor.resourceFiles.entries
- for id,file in ipairs(files) do
- entriesTable[id]=file
- end
- end
- addEvent("onResourceFiles",true)
- addEventHandler("onResourceFiles",getRootElement(),listFiles)
- function openFile(fullFile)
- DXs.editor.editField.lines={}
- local linesTable=DXs.editor.editField.lines
- local fullFile=fullFile
- repeat
- local start,stop=string.find(fullFile,"\n")
- if start==nil then
- linesTable[#linesTable+1]=string.gsub(string.sub(fullFile,0,string.len(fullFile)),"\t"," ")
- else
- linesTable[#linesTable+1]=string.gsub(string.sub(fullFile,0,start),"\t"," ")
- fullFile=string.gsub(string.sub(fullFile,stop+1,string.len(fullFile)),"\t"," ")
- end
- until start==nil
- if #linesTable==0 then
- linesTable[1]="-- this file was empty!"
- end
- end
- addEvent("onClientFile",true)
- addEventHandler("onClientFile",getRootElement(),openFile)
- function setup()
- buttons={}
- for id,window in pairs(DXs) do
- for id,data in pairs(window) do
- if type(data)=="table" then
- if data.type=="button" then
- buttons[#buttons+1]=data -- makes a reference in the buttons table to the button in the DXs table
- elseif data.type=="list" then
- lists[#lists+1]=data
- scrollBars[#scrollBars+1]=data
- elseif data.type=="memo" then
- scrollBars[#scrollBars+1]=data
- memos[#memos+1]=data
- elseif data.type=="edit" then
- edits[#edits+1]=data
- end
- end
- end
- end
- triggerServerEvent("getServerFunctions",getRootElement())
- end
- setup()
- function setupSyntax(serverFunctions)
- for id,data in pairs(_G) do
- if type(data)=="function" then
- if syntaxHighlightings[id]==nil then
- if serverFunctions[id]~=nil then
- syntaxHighlightings[id]={"#990000",true}
- else
- syntaxHighlightings[id]={"#dd0000",true}
- end
- end
- end
- end
- for id,data in pairs(serverFunctions) do
- if syntaxHighlightings[id]==nil then
- syntaxHighlightings[id]={"#ff6600",true}
- end
- end
- for id,data in pairs(string) do
- if type(data)=="function" then
- syntaxHighlightings[id]={"#990044",true}
- end
- end
- for id,data in pairs(math) do
- if type(data)=="function" then
- syntaxHighlightings[id]={"#00aaff",true}
- end
- end
- end
- addEvent("onClientFunctionList",true)
- addEventHandler("onClientFunctionList",getRootElement(),setupSyntax)
- function drawAll() -- function to draw all objects
- for id,data in pairs(DXs) do
- if data.type=="window" then
- drawWindow(data)
- end
- end
- end
- addEventHandler("onClientRender",getRootElement(),drawAll)
- function drawWindow(window)
- if window.visible==false then return end
- if window.visible==true then
- if window.border~=nil then
- dxDrawRectangle(window.x-window.border,window.y-window.border,window.width+window.border*2,window.height+window.border*2,window.borderColor,postGui)
- end
- dxDrawRectangle(window.x,window.y,window.width,window.height,window.color,postGui)
- end
- for id,data in pairs(window) do
- if type(data)=="table" then
- drawFunctions[data.type](data)
- end
- end
- end
- function playerClicked(button,state,cursorx,cursory)
- if state=="up" or button=="right" or button=="middle" then return end
- for id,button in ipairs(buttons) do
- 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
- if button.func~=nil then
- button.func(button)
- end
- break
- end
- end
- for id,list in ipairs(lists) do
- 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
- local fontHeight=dxGetFontHeight(fontSize,font)
- local ammountOfLines=list.height/fontHeight
- local cursory=cursory-list.y
- local lineClicked=math.floor(cursory/list.height*ammountOfLines+0.5)
- local toSelect=lineClicked-list.scrollPosition
- list.selected=toSelect
- if list.func~=nil then
- list.func(list)
- end
- break
- end
- end
- for id,memo in ipairs(memos) do
- 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
- local fontHeight=dxGetFontHeight(fontSize,font)
- local ammountOfLines=memo.height/fontHeight
- local cursory=cursory-memo.y
- local lineClicked=math.floor(cursory/memo.height*ammountOfLines+0.5)
- local toSelect=math.floor(lineClicked-memo.scrollPosition+0.5)
- if toSelect>#memo.lines then break end
- memo.selectedLine=toSelect
- local letterWidth=dxGetTextWidth("I",1,font)
- local ammountOfLetters=memo.width/letterWidth
- local cursorx=cursorx-memo.x
- local collumnClicked=math.floor(cursorx/memo.width*0.91*ammountOfLetters+0.5)
- local scrollPosition=0
- if memo.hScrollPosition~=nil then
- scrollPosition=memo.hScrollPosition
- end
- local toSelectCollumn=math.floor(collumnClicked-scrollPosition+0.5)
- if toSelect>string.len(memo.lines[memo.selectedLine]) then
- toSelect=string.len(memo.lines[memo.selectedLine])
- end
- memo.selectedCollumn=toSelectCollumn
- break
- 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
- for id,othermemo in ipairs(memos) do
- if othermemo~=memo then
- othermemo.selected=false
- end
- end
- for id,otherEdit in ipairs(edits) do
- if otherEdit~=edit then
- otherEdit.selected=false
- end
- end
- memo.selected=true
- end
- end
- for id,list in ipairs(scrollBars) do
- 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
- local scrollBarHeight=list.height*0.96
- local cursory=cursory-list.y
- list.scrollBar=cursory/scrollBarHeight
- if list.entries==nil then
- list.scrollPosition=-1*#list.lines*list.scrollBar
- else
- list.scrollPosition=-1*#list.entries*list.scrollBar
- end
- if list.scrollBar<0 then
- list.scrollBar=0
- elseif list.scrollBar>1 then
- list.scrollBar=1
- end
- break
- 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
- local scrollBarWidth=list.width*0.92
- local cursorx=cursorx-list.x
- list.hScrollBar=cursorx/scrollBarWidth
- list.hScrollPosition=-1*string.len(list.lines[list.selectedLine])*list.hScrollBar
- if list.hScrollBar<0 then
- list.hScrollBar=0
- elseif list.hScrollBar>1 then
- list.hScrollBar=1
- end
- break
- end
- end
- for id,edit in ipairs(edits) do
- 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
- for id,otherEdit in ipairs(edits) do
- if otherEdit~=edit then
- otherEdit.selected=false
- end
- end
- for id,othermemo in ipairs(memos) do
- if othermemo~=memo then
- othermemo.selected=false
- end
- end
- edit.selected=true
- end
- end
- end
- addEventHandler("onClientClick",getRootElement(),playerClicked)
- function playerDoubleClicked(button,cursorx,cursory)
- for id,list in ipairs(lists) do
- 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
- local fontHeight=dxGetFontHeight(fontSize,font)
- local ammountOfLines=list.height/fontHeight
- local cursory=cursory-list.y
- local lineClicked=math.floor(cursory/list.height*ammountOfLines+0.5)
- local toSelect=lineClicked-list.scrollPosition
- list.selected=toSelect
- if list.func~=nil then
- list.func(true)
- end
- break
- end
- end
- end
- addEventHandler("onClientDoubleClick",getRootElement(),playerDoubleClicked)
- local keys={["space"]=" ",["tab"]=" ",["#"]="'",["test"]="test",["mouse_wheel_up"]="",["mouse_wheel_down"]=""}
- local upperCase={["1"]="!",["2"]="@",["3"]="#",["4"]="$",["5"]="%",["6"]="^",["7"]="&",["8"]="*",["9"]="(",["0"]=")",["`"]="~",["-"]="_",["="]="+",["\\"]="|",["["]="{",["]"]="}",[";"]=":",["'"]='"',[","]="<",["."]=">",["/"]="?",}
- function playerKey(button,state)
- if button=="lshift" then
- case=not case
- elseif button=="capslock" and state==true then
- case=not case
- elseif button=="lctrl" then
- ctrl=state
- end
- for id,memo in ipairs(memos) do
- if memo.selected==true and memo.visible==true then
- cancelEvent()
- if button=="v" and ctrl==true then
- if state==false then
- postGui=true
- local paste=guiGetText(pasteMemo)
- local pasteLines={}
- repeat
- local start,stop=string.find(paste,"\n")
- if start~=nil then
- pasteLines[#pasteLines+1]=string.gsub(string.gsub(string.sub(paste,0,start),"\n",""),"\t"," ")
- paste=string.sub(paste,stop+1,string.len(paste))
- end
- until start==nil
- local lineCount=#memo.lines
- local pasteCount=#pasteLines
- for i=lineCount+pasteCount,memo.selectedLine,-1 do
- memo.lines[i]=memo.lines[i-pasteCount]
- end
- for i=memo.selectedLine-1,memo.selectedLine+pasteCount do
- if pasteLines[i-memo.selectedLine]~=nil then
- memo.lines[i]=pasteLines[i-memo.selectedLine]
- end
- end
- if memo.lines[memo.selectedLine]==nil then
- memo.lines[memo.selectedLine]=" "
- end
- break
- else
- postGui=false
- guiSetText(pasteMemo,"")
- guiSetVisible(pasteMemo,true)
- guiBringToFront(pasteMemo)
- guiMemoSetCaretIndex(pasteMemo,0)
- break
- end
- end
- if state==false then return end
- if button=="enter" then
- local nextLine=string.sub(memo.lines[memo.selectedLine],memo.selectedCollumn,string.len(memo.lines[memo.selectedLine]))
- memo.lines[memo.selectedLine]=string.sub(memo.lines[memo.selectedLine],0,memo.selectedCollumn-1)
- memo.selectedLine=memo.selectedLine+1
- local index=#memo.lines
- for i=index+1,memo.selectedLine,-1 do
- if i==memo.selectedLine then
- memo.lines[i]=nextLine
- else
- memo.lines[i]=memo.lines[i-1]
- end
- end
- memo.selectedCollumn=1
- elseif button=="arrow_u" then
- memo.selectedLine=memo.selectedLine-1
- if string.len(memo.selectedLine)>memo.selectedCollumn then
- memo.selectedCollumn=string.len(memo.selectedLine)
- end
- elseif button=="arrow_d" then
- memo.selectedLine=memo.selectedLine+1
- if string.len(memo.selectedLine)>memo.selectedCollumn then
- memo.selectedCollumn=string.len(memo.selectedLine)
- end
- --memo.selectedCollumn=1
- elseif button=="arrow_l" then
- if memo.selectedCollumn>1 then
- memo.selectedCollumn=memo.selectedCollumn-1
- elseif memo.selectedLine>1 then
- memo.selectedLine=memo.selectedLine-1
- memo.selectedCollumn=string.len(memo.lines[memo.selectedLine])+1
- end
- elseif button=="arrow_r" then
- if string.len(memo.lines[memo.selectedLine])<memo.selectedCollumn then
- if memo.lines[memo.selectedLine+1]~=nil then
- memo.selectedLine=memo.selectedLine+1
- memo.selectedCollumn=1
- end
- else
- memo.selectedCollumn=memo.selectedCollumn+1
- end
- elseif button=="backspace" then
- 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]))
- if memo.selectedCollumn>1 then
- memo.selectedCollumn=memo.selectedCollumn-1
- elseif memo.selectedLine<=1 then
- memo.selectedLine=memo.selectedLine-1
- memo.selectedCollumn=string.len(memo.lines[memo.selectedLine])
- end
- elseif button=="delete" then
- 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]))
- else
- local button=button
- if keys[button]==nil and string.len(button)>1 then return end
- if keys[button]~=nil then
- button=keys[button]
- end
- if case==true and upperCase[button]~=nil then
- button=upperCase[button]
- elseif case==true then
- button=string.upper(button)
- end
- if memo.lines[memo.selectedLine]==nil then
- memo.lines[memo.selectedLine]=""
- end
- 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]))
- memo.selectedCollumn=memo.selectedCollumn+string.len(button)
- end
- if memo.lines[memo.selectedLine]==nil then
- memo.lines[memo.selectedLine]=""
- end
- if memo.func~=nil then
- memo.func(memo)
- end
- end
- end
- if state==false then return end
- for id,edit in ipairs(edits) do
- if edit.selected==true and edit.visible==true then
- cancelEvent()
- if button=="arrow_l" then
- if edit.selectedCollumn>1 then
- edit.selectedCollumn=edit.selectedCollumn-1
- end
- elseif button=="arrow_r" then
- edit.selectedCollumn=edit.selectedCollumn+1
- elseif button=="backspace" then
- edit.text=string.sub(edit.text,0,edit.selectedCollumn-2)..string.sub(edit.text,edit.selectedCollumn+0,string.len(edit.text))
- if edit.selectedCollumn>0 then
- edit.selectedCollumn=edit.selectedCollumn-1
- end
- elseif button=="delete" then
- edit.text=string.sub(edit.text,0,edit.selectedCollumn-1)..string.sub(edit.text,edit.selectedCollumn+1,string.len(edit.text))
- else
- if case==true and upperCase[button]~=nil then
- button=upperCase[button]
- elseif case==true then
- button=string.upper(button)
- end
- local button=button
- if keys[button]==nil and string.len(button)>1 then return end
- if keys[button]~=nil then
- button=keys[button]
- end
- edit.text=string.sub(edit.text,0,edit.selectedCollumn-1)..button..string.sub(edit.text,edit.selectedCollumn,string.len(edit.text))
- edit.selectedCollumn=edit.selectedCollumn+string.len(button)
- end
- end
- end
- if button~="mouse_wheel_up" and button~="mouse_wheel_down" or isCursorShowing()==false then return end
- local cursorx,cursory=getCursorPosition()
- local cursorx,cursory=cursorx*screenx,cursory*screeny
- for id,list in ipairs(scrollBars) do
- 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
- if list.type=="list" then
- if button=="mouse_wheel_up" then
- list.scrollBar=list.scrollBar-0.025
- list.scrollPosition=list.scrollPosition+6
- elseif button=="mouse_wheel_down" then
- list.scrollBar=list.scrollBar+0.025
- list.scrollPosition=list.scrollPosition-6
- end
- if list.scrollBar<0 then
- list.scrollBar=0
- elseif list.scrollBar>1 then
- list.scrollBar=1
- end
- if list.scrollPosition>0 then
- list.scrollPosition=0
- end
- cancelEvent()
- elseif list.type=="memo" then
- if button=="mouse_wheel_up" then
- list.scrollBar=list.scrollBar-0.01
- list.scrollPosition=list.scrollPosition+#list.lines/100
- elseif button=="mouse_wheel_down" then
- list.scrollBar=list.scrollBar+0.01
- list.scrollPosition=list.scrollPosition-#list.lines/100
- end
- if list.scrollBar<0 then
- list.scrollBar=0
- elseif list.scrollBar>1 then
- list.scrollBar=1
- end
- if list.scrollPosition>0 then
- list.scrollPosition=0
- end
- cancelEvent()
- end
- break
- 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
- if list.hScrollBar~=nil then
- if button=="mouse_wheel_up" then
- list.hScrollBar=list.hScrollBar-0.05
- list.hScrollPosition=list.hScrollPosition+string.len(list.lines[list.selectedLine])/20
- elseif button=="mouse_wheel_down" then
- list.hScrollBar=list.hScrollBar+0.05
- list.hScrollPosition=list.hScrollPosition-string.len(list.lines[list.selectedLine])/20
- end
- if list.hScrollBar<0 then
- list.hScrollBar=0
- elseif list.hScrollBar>1 then
- list.hScrollBar=1
- end
- if list.hScrollPosition>0 then
- list.hScrollPosition=0
- end
- end
- end
- end
- end
- addEventHandler("onClientKey",getRootElement(),playerKey)
- function toggleEditor()
- dxSetVisible(DXs.editor,not DXs.editor.visible)
- showCursor(DXs.editor.visible)
- end
- addCommandHandler(command,toggleEditor)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement