BindMenu = {}
function BindMenu:new()
local public = {}
public.x, public.y = 0, 0
public.currentPageLink = 1
public.currentPageLine = 1
public.currentLink = -1
public.countLine = 1
public.countLink = 1
public.openOptions = false
public.btnClose = tweaks.button:new(4, "x", bmClose ,fonted)
public.btnAddLink = tweaks.button:new(4, "Add", addLink ,fonted)
public.btnRemoveLink = tweaks.button:new(4, "Remove", delLink ,fonted)
public.btnAdd = tweaks.button:new(4, "Add to end", addline ,fonted)
public.btnAddAL = tweaks.button:new(4, "Add after line", addLineAL ,fonted)
public.btnRemove = tweaks.button:new(4, "Remove", delLine,fonted)
public.btnOptions = tweaks.button:new(4, "Options", openOptions ,fonted,true)
public.btnList = tweaks.button:new(4, "List", openOptions ,fonted,false)
public.EditBox = {}
public.ebxOptions = {}
for i = 1,6 do
public.ebxOptions[i] = EditBox:new(36+i, "" ,fonted)
end
public.ebxKey = EditBox:new(100, "" ,fonted)
public.ebxType = EditBox:new(80, "" ,fonted)
public.ebxName = EditBox:new(81, "" ,fonted)
public.ebxEvent = EditBox:new(82, "" ,fonted)
public.ebxWeapID = EditBox:new(83, "" ,fonted)
public.ebxWeapIDPrev = EditBox:new(84, "" ,fonted)
public.cbxEnter = {}
public.ebxPause = {}
for i = 1,18 do
public.EditBox[i] = EditBox:new(i,"",fonted)
public.ebxPause[i] = EditBox:new(18+i,"",fonted)
public.cbxEnter[i] = CheckBox:new(i,true,changeCheckBox)
end
public.btnPage = {}
public.btnLink = {}
for i = 1, 15*8 do
if (ini2["Options_"..i] ~= nil) then
public.btnLink[i] = tweaks.button:new(20+i, ini2["Options_"..i].Name, openLink,fonted,{i,1})
else
public.countLink = i-1
break
end
end
for i = 1, 8 do
public.btnPage[i] = tweaks.button:new(10+i, i, pageSwitch , fonted,i)
end
public.btnPageLink = {}
for i = 1, 10 do
public.btnPageLink[i] = tweaks.button:new(10+i, i, openLink , fonted,{1,i})
end
public.toolTip = tweaks.toolTip:new(330)
public.windowTitle = "BinderManager v " .. thisScript().version
function public:drawWindowTitle(text)
local x = self.x - (renderGetFontDrawTextLength(fonted, text) / 2) + self.w / 2
local y = self.y - 17
renderDrawBox(self.x, y, self.w, 20, 0xFF141414)
renderFontDrawText(fonted, text, x, y, 0xDCDCFFFF)
end
function public:drawWindow(w,h)
repeat
until fonted
sampToggleCursor(true)
self.x, self.y = getScreenResolution()
self.w, self.h = w,h
self.x, self.y = self.x / 2 - self.w / 2, self.y / 2 - self.h / 2
self:drawWindowTitle(self.windowTitle)
renderDrawBoxWithBorder(self.x, self.y, self.w, self.h, 0xD0101010, 2, 0xFF141414)
self.btnClose:draw(self.x + self.w - 15, self.y - 17, 15, 20)
self:drawList()
renderDrawBox(self.x + 200, self.y + 40, self.w - 205 , self.h - 50 , 0x42FFFFFF)
self.btnOptions:draw(self.x + self.w - 105,self.y + 8,100,30,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f)
self.btnList:draw(self.x + self.w - 207,self.y + 8,100,30,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f)
if not self.openOptions then
self:drawEditWindow()
else
self:drawOptions()
end
end
function public:drawOptions()
---------------------------------------------------------------------------------------------------------------------------------
renderDrawBox(self.x + 205, self.y + 45, 315 , 40 , 0x42FFFFFF)
self.ebxOptions[2]:draw(self.x + 330, self.y + 52, 185 , 26 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
renderFontDrawText(fonted, "Name", self.x + 268 - (renderGetFontDrawTextLength(fonted, "Name") / 2), self.y + 57, 0xFFa8cc7f)
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
renderDrawBox(self.x + 525, self.y + 45, 315 , 40 , 0x42FFFFFF)
self.ebxOptions[3]:draw(self.x + 650, self.y + 52, 185 , 26 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
renderFontDrawText(fonted, "Type Bind", self.x + 587 - (renderGetFontDrawTextLength(fonted, "Type Bind") / 2), self.y + 57, 0xFFa8cc7f)
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
renderDrawBox(self.x + 205, self.y + 90, 315 , 40 , 0x42FFFFFF)
self.ebxOptions[1]:draw(self.x + 330, self.y + 97, 185 , 26 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
renderFontDrawText(fonted, "Key", self.x + 268 - (renderGetFontDrawTextLength(fonted, "Key") / 2), self.y + 99, 0xFFa8cc7f)
---------------------------------------------------------------------------------------------------------------------------------
---------------------------------------------------------------------------------------------------------------------------------
renderDrawBox(self.x + 525, self.y + 90, 315 , 40 , 0x42FFFFFF)
self.ebxOptions[4]:draw(self.x + 650, self.y + 97, 185 , 26 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
renderFontDrawText(fonted, "Event ID", self.x + 587 - (renderGetFontDrawTextLength(fonted, "Event ID") / 2), self.y + 99, 0xFFa8cc7f)
---------------------------------------------------------------------------------------------------------------------------------]]
---------------------------------------------------------------------------------------------------------------------------------
renderDrawBox(self.x + 205, self.y + 135, 315 , 40 , 0x42FFFFFF)
self.ebxOptions[5]:draw(self.x + 330, self.y + 142, 185 , 26 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
renderFontDrawText(fonted, "Weapon IDs", self.x + 268 - (renderGetFontDrawTextLength(fonted, "Weapon IDs") / 2), self.y + 144, 0xFFa8cc7f)
---------------------------------------------------------------------------------------------------------------------------------]]
---------------------------------------------------------------------------------------------------------------------------------
renderDrawBox(self.x + 525, self.y + 135, 315 , 40 , 0x42FFFFFF)
self.ebxOptions[6]:draw(self.x + 650, self.y + 142, 185 , 26 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
renderFontDrawText(fonted, "Weapon Prev IDs", self.x + 587 - (renderGetFontDrawTextLength(fonted, "Weapon Prev IDs") / 2), self.y + 144, 0xFFa8cc7f)
---------------------------------------------------------------------------------------------------------------------------------]]
end
function public:drawEditWindow()
self.btnAdd:draw(self.x + 200,self.y + 8,130,14,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f)
local ccl = false
if EditBoxActive == -1 then
ccl = not ccl
end
self.btnAddAL:draw(self.x + 200,self.y + 24,130,14,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f,ccl)
self.btnRemove:draw(self.x + 333,self.y + 8,60,30,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f,ccl)
renderDrawBox(self.x + 202, self.y + 40+2, 35 , 25 , 0x42FFFFFF)
renderDrawBox(self.x + 240, self.y + 40+2, 453 , 25 , 0x42FFFFFF)
renderDrawBox(self.x + 696, self.y + 40+2, 50 , 25 , 0x42FFFFFF)
renderDrawBox(self.x + 749, self.y + 40+2, 94, 25 , 0x42FFFFFF)
renderFontDrawText(fonted, "№", self.x + 219 - (renderGetFontDrawTextLength(fonted, "№") / 2), self.y + 46, 0xFFa8cc7f)
renderFontDrawText(fonted, "Text", self.x + 466 - (renderGetFontDrawTextLength(fonted, "Text") / 2), self.y + 46, 0xFFa8cc7f)
renderFontDrawText(fonted, "Enter", self.x + 721 - (renderGetFontDrawTextLength(fonted, "Enter") / 2), self.y + 46, 0xFFa8cc7f)
renderFontDrawText(fonted, "Pause(ms)", self.x + 749 + 94/2 - (renderGetFontDrawTextLength(fonted, "Pause(ms)") / 2), self.y + 46, 0xFFa8cc7f)
local lPage = self.countLine - 18*(self.currentPageLine-1)
if lPage > 18 then lPage = 18 end
if self.countLine ~= 0 then
for i = 1,lPage do
renderDrawBox(self.x + 202, self.y + 42+27*i, 35 , 25 , 0x42FFFFFF)
renderFontDrawText(fonted, i+18*(self.currentPageLine-1), self.x + 219 - (renderGetFontDrawTextLength(fonted, i+18*(self.currentPageLine-1)) / 2), self.y + 46+27*i, 0xFFa8cc7f)
self.EditBox[i]:draw(self.x + 240, self.y + 42+27*i, 453 , 25 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
self.cbxEnter[i]:draw(self.x + 696, self.y + 42+27*i, 50 , 25 , 0x42FFFFFF, 0x42FFFFFF)
self.ebxPause[i]:draw(self.x + 749, self.y + 42+27*i, 94 , 25 , 0x42FFFFFF, 0xFFa8cc7f,0x7AC5C5C5)
end
end
for i = 1, 10 do
if self.countLine - 18*(i-1) <= 0 then
closed = true
else
closed = false
end
self.btnPageLink[i].param = {public.currentLink,i}
if i == self.currentPageLine then
self.btnPageLink[i]:draw(self.x + 400 + 23*(i-1), self.y + 560, 20 , 20,0x92FFFFFF,0x92FFFFFF,0x92FFFFFF,0xFFa8cc7f)
else
self.btnPageLink[i]:draw(self.x + 400 + 23*(i-1), self.y + 560, 20 , 20,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f,closed)
end
end
end
function public:drawList()
local closed;
renderDrawBox(self.x + 5, self.y + 8, 190 , 62 + (33*15), 0x30FFFFFF)
renderFontDrawText(fonted, "Tag", self.x + 100 - (renderGetFontDrawTextLength(fonted, "Tag") / 2), self.y + 17, 0xFFc34545)
self.btnAddLink:draw(self.x + 10, self.y + 12,65,25, 0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f)
self.btnRemoveLink:draw(self.x + 125, self.y + 12,65,25, 0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f)
local lPage = self.countLink - 15*(self.currentPageLink-1)
if lPage > 15 then lPage = 15 end
if self.countLink ~= 0 then
for i = 1, lPage do
self.btnLink[i+15*(self.currentPageLink-1)]:draw(self.x + 5, self.y + 42 + 33*(i-1), 190 , 30, 0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f)
end
end
for i = 1, 8 do
if self.countLink - 15*(i-1) <= 0 then
closed = true
else
closed = false
end
if i == self.currentPageLink then
self.btnPage[i]:draw(self.x + 10 + 23*(i-1), self.y + 77 + (33*14), 20 , 20,0x92FFFFFF,0x92FFFFFF,0x92FFFFFF,0xFFa8cc7f)
else
self.btnPage[i]:draw(self.x + 10 + 23*(i-1), self.y + 77 + (33*14), 20 , 20,0x42FFFFFF,0x7AC5C5C5,0x7Aa9a9a9,0xFFa8cc7f,closed)
end
end
end
setmetatable(public, self)
self.__index = self
openLink({1,1,public})
return public
end
EditBox = {}
EditBoxActive = -1
EditBox.last = 0
function EditBox:new(id,text,font)
local public = {}
public.id = id
public.text = tostring(text)
public.font = font
public.time = 0
public.currentChar = 0
public.currentChar2 = 0
public.offsetLeft = 0
public.offsetRight = 0
public.first = true
function public:draw(x,y,w,h,color,colorText,colorActive)
self.x = x
self.y = y
self.w = w
self.h = h
self.text = tostring(self.text)
self.ty = self.y+self.h/2-renderGetFontDrawHeight(self.font)/2
if self.first then self:setStartOffset() self.first = false self.currentChar = 0 self.currentChar2 = 0 end
renderFontDrawText(self.font, string.sub(self.text,1+self.offsetLeft-self.offsetRight,self.text:len()-self.offsetRight), self.x + 5, self.ty, colorText)
local flags,xp,yp = mh:isKeyPressed(VK_LBUTTON, self.x, self.y, self.w, self.h)
if flags.isWnd then
if flags.isPressedWnd then
if EditBoxActive ~= self.id then
onEditBoxActiveChange(EditBoxActive,self.id)
EditBoxActive = self.id
end
self.currentChar = self:getChar(xp,yp)
elseif flags.isDownWnd then
self.currentChar2 = self:getChar(xp,yp)
end
end
if EditBoxActive == self.id then
renderDrawBox(self.x,self.y,self.w,self.h,colorActive)
if self.time >= 25 and self.time < 50 then
renderDrawBox(self.x+5+ renderGetFontDrawTextLength(self.font, self.text:sub(1+self.offsetLeft-self.offsetRight,self.currentChar)), self.ty, 2,renderGetFontDrawHeight(self.font),0x8F0000FF)
elseif self.time == 50 then self.time = 0 end
self.time = self.time+1
if self.currentChar2 ~= self.currentChar then
if self.currentChar2 > self.currentChar then
renderDrawBox(self.x+5+ renderGetFontDrawTextLength(self.font, self.text:sub(1+self.offsetLeft-self.offsetRight,self.currentChar)), self.ty, renderGetFontDrawTextLength(self.font, self.text:sub(self.currentChar+1,self.currentChar2)),renderGetFontDrawHeight(self.font),0x8F0000FF)
else
renderDrawBox(self.x+5+ renderGetFontDrawTextLength(self.font, self.text:sub(1+self.offsetLeft-self.offsetRight,self.currentChar2)), self.ty, renderGetFontDrawTextLength(self.font, self.text:sub(self.currentChar2+1,self.currentChar)),renderGetFontDrawHeight(self.font),0x8F0000FF)
end
end
else
renderDrawBox(self.x,self.y,self.w,self.h,color)
end
end
function public:getChar(x,y)
cx = x - (self.x+5)
self.text = tostring(self.text)
if self.text:len() == nil then return 0 end
for i = 1, self.text:len() do
if cx < (renderGetFontDrawTextLength(self.font, self.text:sub(1,i)) - renderGetFontDrawTextLength(self.font, self.text:sub(i,i))/2) then return i-1+self.offsetLeft-self.offsetRight end
end
return self.text:len()
end
function public:setStartOffset(onlyleft)
self.offsetRight = 0
self.offsetLeft = 0
self.text = tostring(self.text)
for i=1,self.text:len() do
if (renderGetFontDrawTextLength(self.font, self.text:sub(1,i)) > self.w - 10 ) then
self.offsetLeft = self.text:len() - i
if not onlyleft then self.offsetRight = self.offsetLeft end
sampfuncsLog(self.offsetLeft)
break
end
end
end
function public:SendChar(id)
if lock then lock = not lock return false end
local pvtext,pvcr1,pvcr2 = self.text,self.currentChar,self.currentChar2
if id == 8 then
if self.currentChar2 == self.currentChar then
if self.currentChar ~= 0 then
self.text,self.currentChar = ReplaceText(self.text,self.currentChar-1,self.currentChar,"")
self.currentChar2 = self.currentChar
if (self.offsetLeft >= 1) then
self.offsetLeft = self.offsetLeft - 1
self.offsetRight = self.offsetRight -1
end
if (self.offsetRight < 0) then self.offsetRight = 0 end
end
else
local minus = 0
self.text,self.currentChar,minus = ReplaceText(self.text,self.currentChar,self.currentChar2,"")
self.offsetLeft = self.offsetLeft - minus
self.offsetRight = self.offsetRight - minus
if self.offsetLeft < 0 then self.offsetLeft = 0 end
if self.offsetRight < 0 then self.offsetRight = 0 end
self.currentChar2 = self.currentChar
end
elseif id == 37 then
sampfuncsLog(self.currentChar.."|"..self.offsetRight.."|"..self.offsetLeft )
if self.currentChar ~= 0 then
if self.currentChar == self.offsetLeft - self.offsetRight and self.offsetLeft ~= 0 then self.offsetRight = self.offsetRight + 1 end
self.currentChar = self.currentChar - 1
self.currentChar2 = self.currentChar
end
elseif id == 39 then
sampfuncsLog(self.currentChar.."|"..self.offsetRight.."|"..self.offsetLeft )
if self.currentChar ~= self.text:len() then
if self.currentChar == self.text:len() - self.offsetRight and self.offsetRight ~= 0 then self.offsetRight = self.offsetRight - 1 end
self.currentChar = self.currentChar + 1
self.currentChar2 = self.currentChar
end
else
if not isKeyDown(0x11) then
local char = string.char(id)
if self.currentChar2 == self.currentChar then
self.text,self.currentChar = ReplaceText(self.text,self.currentChar,self.currentChar2,char)
self.currentChar2 = self.currentChar
if (self.x + 5+ renderGetFontDrawTextLength(self.font, string.format("%s%s",self.text,char)) > self.x + self.w - 5 ) then
self.offsetLeft = self.offsetLeft + 1
end
else
local minus = 0
self.text,self.currentChar,minus = ReplaceText(self.text,self.currentChar,self.currentChar2,char)
self.offsetLeft = self.offsetLeft - minus
self.offsetRight = self.offsetRight - minus
if self.offsetLeft < 0 then self.offsetLeft = 0 end
if self.offsetRight < 0 then self.offsetRight = 0 end
self.currentChar2 = self.currentChar
end
else
if isKeyJustPressed(0x43) then
if self.currentChar2 ~= self.currentChar then
if self.currentChar > self.currentChar2 then
local temp = self.currentChar
self.currentChar = self.currentChar2
self.currentChar2 = temp
end
setClipboardText(self.text:sub(self.currentChar,self.currentChar2+1))
end
elseif isKeyJustPressed(0x56) then
copytext = getClipboardText()
local minus;
self.text,self.currentChar,minus = ReplaceText(self.text,self.currentChar,self.currentChar2,copytext)
self:setStartOffset(true)
self.currentChar2 = self.currentChar
end
end
end
if onTextEdit(self.id,self.text) then self.text,self.currentChar,self.currentChar2 =pvtext,pvcr1,pvcr2 end
end
setmetatable(public, self)
self.__index = self
table.insert(EditBox,public)
return EditBox[#EditBox]
end