DaHoM Posted July 12, 2019 Share Posted July 12, 2019 السلام عليكم ورحمة الله وبركاتة كيف حال الشباب عساكم طيبين الجواب من اصحاب الخبرة والاحتراف ( القصة مو سهلة على ما اعتقد )ا اليوم كنت اشتغل على برمجة بالدي اكس @t3wz وصادفت انو لازمني 2 جريد ليست وانا بستخدم جريد ليست حقت وانا مشغل نظام الكوائن بملف الميتا <oop>true</oop> بس المصيبة كانت انو ما اقدر اختار غير من جريد ليست واحده فقط وهي اخر واحده انا سويتها اكواد الجريد ليست dxGrid = { items = {} }; local cursorOn; local NATIVE_RESOLUTION = { nil } -- put your screen resolution here to fit the gridlists to all resolutions (ex: { 1366, 768 } ) if ( table.maxn ( NATIVE_RESOLUTION ) == 2 ) then FIT_MODE = true RES = { guiGetScreenSize() }; X,Y = RES[1] / NATIVE_RESOLUTION[1], RES[2] / NATIVE_RESOLUTION[2]; SCALE = ( 1 / NATIVE_RESOLUTION[1] ) * RES[1]; end --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Core - functions function dxGrid:Create ( x, y, width, height, postGUI ) -- table dxGrid:Create ( int x, int y, int width, int height[, bool postGUI ] ) if __checkParams ( "Create", "nnnn", x, y, width, height ) then local data = { x = FIT_MODE and ( x * X ) or x; -- X position y = FIT_MODE and ( y * Y ) or y; -- Y position w = FIT_MODE and ( width * X ) or width; -- Width h = FIT_MODE and ( height * Y ) or height; -- Height pg = postGUI or false; -- PostGUI i = {}; -- Items mi = __calcMaxItems ( FIT_MODE and ( height * Y ) or height ); -- Max items s = 1; -- Scroll Level r = -1; -- Row count se = -1; -- Selected item mo = nil; -- Mouse-on item vis = true -- Visible }; setmetatable ( data, { __index = dxGrid } ); table.insert ( dxGrid.items, data ); return data; end end function dxGrid:Destroy () -- bool dxGrid:Destroy () for k, v in pairs ( dxGrid.items ) do if v == self then dxGrid.items[k] = nil; return true; end end return false; end function dxGrid:SetVisible ( visible ) -- bool Gridlist:SetVisible ( bool state ) if __checkParams ( "SetVisible", "b", visible ) then self.vis = visible return true else return false end end function dxGrid:IsVisible ( ) -- bool Gridlist:IsVisible() return self.vis end function dxGrid:AddColumn ( title, width ) -- int Gridlist:AddColumn ( string title, int width ) if __checkParams ( "AddColumn", "sn", title, width ) then local data = { info = { title = title, width = FIT_MODE and ( width * X ) or width } }; table.insert ( self.i, data ); return #self.i; end end function dxGrid:RemoveColumn ( columnIndex ) -- bool Gridlist:RemoveColumn ( int columnIndex ) if __checkParams ( "RemoveColumn", "n", columnIndex ) then self.i[columnIndex] = nil; -- Recalculate the highest item count local highest = -1; for _, v in ipairs ( self.i ) do if #v > highest then highest = ( #v - 1 ); end end self.r = highest; -- Recalculate the scroll level (if necessary) if ( ( ( self.s + self.mi ) - 2 ) == self.r ) then self.s = ( self.r - self.mi ) + 1; end return true end return false end function dxGrid:GetColumnCount () -- int Gridlist:GetColumnCount() return #self.i end function dxGrid:AddItem ( columnIndex, text, data, r, g, b ) -- int Gridlist:AddItem ( int columnIndex, string title[, mixed data, int r, int g, int b ] ) if __checkParams ( "AddItem", "ns", columnIndex, text ) then if self.i[columnIndex] then local tColor = __checkRGB ( r, g, b ) and { r, g, b } or { 255, 255, 255 }; table.insert ( self.i[columnIndex], { id = #self.i[columnIndex] + 1, text = tostring( text ), data = data, color = tColor } ); if #self.i[columnIndex] > self.r then self.r = #self.i[columnIndex]; end return #self.i[columnIndex]; end return false; end end function dxGrid:RemoveItem ( column, itemID ) -- bool Gridlist:RemoveItem ( int columnIndex, int itemIndex ) if __checkParams ( "RemoveItem", "nn", column, itemID ) then if self.i[column] and self.i[column][itemID] then -- Recalculate the highest item count if self.r == #self.i[column] then local highest = -1; for _, v in ipairs ( self.i ) do if #v > highest then highest = ( #v - 1 ); end end self.r = highest; end -- Recalculate the scroll level (if necessary) if ( ( ( self.s + self.mi ) - 2 ) == self.r ) then self.s = ( self.r - self.mi ) + 1; end -- Reset the selected item if necessary² if itemID == self.se then local newItem = self.se - 1 if newItem <= self.r then self.se = math.max ( 0, newItem ); else self.se = -1 end end table.remove ( self.i[column], itemID ); return true; end return false end end function dxGrid:GetItemCount ( columnID ) -- int Gridlist:GetItemCount ( int columnIndex ) if __checkParams ( "GetItemCount", "n", columnID ) then if self.i[columnID] then return #self.i[columnID] end return false end end function dxGrid:Clear () -- bool Gridlist:Clear() for k, v in ipairs ( self.i ) do self.i[k] = { info = v.info } end self.r = -1 self.se = nil -- Recalculate the scroll level self.s = 1; return true end function dxGrid:GetSelectedItem ( ) -- int Gridlist:GetSelectedItem () return self.se; end function dxGrid:SetSelectedItem ( itemID ) -- bool Gridlist:SetSelectedItem ( int itemIndex ) if __checkParams ( "SetSelectedItem", "n", itemID ) then if itemID <= self.r then self.se = itemID; return self.se == itemID; end return false; end end function dxGrid:GetItemDetails ( column, itemID ) -- string, mixed Gridlist:GetItemDetails ( int columnIndex, int itemIndex ) if __checkParams ( "GetItemDetails", "nn", columnID, itemID ) then if self.i[column] then if self.i[column][itemID] then return self.i[column][itemID].text, self.i[column][itemID].data end end return false end end --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Core - render/move addEventHandler ( "onClientRender", root, function ( ) -- Is there any gridlist to render? if #dxGrid.items > 0 then -- Loop through all grid lists for index, data in ipairs ( dxGrid.items ) do -- Is the gridlist visible? if data.vis then -- Draw the 'gridlist' itself dxDrawRectangle ( data.x, data.y, data.w, data.h, tocolor ( 0, 0, 0, 200 ), data.pg ); -- Draw the column bar dxDrawRectangle ( data.x, data.y, data.w, 30 % data.h, tocolor ( 0, 0, 0, 220 ), data.pg ); -- Set cursorOn variable to the current gridlist, if it's selected cursorOn = nil if __isMouseInPosition ( data.x, data.y, data.w, data.h ) then cursorOn = index; end -- Check if there's any selected item local seeFrom = data.s; local seeTo = ( data.s + data.mi ) - 1; if data.se and data.se <= data.r and data.se >= seeFrom and data.se <= seeTo then local index = data.se - ( data.s - 1 ); local y2 = data.y + ( ( index - 1 ) * 25 ); -- Draw a rectangle to make it looks like selected dxDrawRectangle ( data.x, ( 30 % data.h ) + y2, data.w, 20, tocolor ( 100, 100, 100, 100 ), data.pg ); end -- Is there any column? if #data.i > 0 then local cWidth = 0 -- Loop through all columns for cIndex, cData in ipairs ( data.i ) do -- we'll go beyond the gridlist width with this column ? if ( ( cWidth + cData.info.width ) <= data.w ) then local x = data.x + cWidth; -- Draw the column title dxDrawText ( cData.info.title, x, data.y, cData.info.width + x, ( 30 % data.h ) + data.y, tocolor ( 255, 255, 255 ), FIT_MODE and ( 1 * SCALE ) or 1, "default-bold", "center", "center", true, true, data.pg, false, true ); -- Reset the selected item cData.info.selected = -1; -- Is there any item ? if #cData > 0 then local seeFrom = data.s; local seeTo = ( data.s + data.mi ) - 1; -- Loop the items for iIndex = seeFrom, seeTo do -- There's a row with this index in the current column? if cData[iIndex] then local index = iIndex - ( data.s - 1 ); local y = data.y + ( index * 25 ); local y2 = data.y + ( ( index - 1 ) * 25 ); -- Check if cursor is on item position if __isMouseInPosition ( data.x, ( 30 % data.h ) + y2, data.w, 20 ) then -- Define the mouse-on variable data.mo = iIndex; end -- Draw the item text dxDrawText ( cData[iIndex]["text"], x, y, cData.info.width + x, ( 30 % data.h ) + y, tocolor ( unpack ( cData[iIndex]["color"] ) ), FIT_MODE and ( 1 * SCALE ) or 1, "default-bold", "center", "center", true, true, data.pg, false, true ); end end end -- Increase cWidth variable (to draw the columns correctly) cWidth = cWidth + cData.info.width; end end end end end end end , true, "low-5") -- addEventHandler ( "onClientKey", root, function ( button, press ) -- Is cursor showing? if isCursorShowing () then -- Is there any gridlist? if #dxGrid.items > 0 then -- Is there any selected gridlist? if cursorOn then -- We pressed the scroll? if press and #button > 6 then -- Does the gridlist requires scroll? if dxGrid.items[cursorOn].r > dxGrid.items[cursorOn].mi then -- Define some variables local index = cursorOn; local currentValue = dxGrid.items[index].s; local newValue = math.max ( 1, button == "mouse_wheel_down" and currentValue + 2 or currentValue -1 ); -- Check if we have spent the row's limit with the new value if ( ( newValue + dxGrid.items[index].mi ) > dxGrid.items[index].r ) then newValue = ( dxGrid.items[index].r - dxGrid.items[index].mi ) + 1; end -- Set the new scroll level dxGrid.items[index].s = newValue; end elseif press and button == "mouse1" and dxGrid.items[cursorOn].mo then dxGrid.items[cursorOn].se = dxGrid.items[cursorOn].mo; end end end end end ) --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Useful function __calcMaxItems ( height ) for i = 0, 9999 do if ( ( ( i + 1 ) * 25 ) >= math.floor ( height ) ) then return ( ( ( i + 1 ) * 25 ) > math.floor ( height ) and ( i - 1 ) or i ); end end return false; end function __checkParams ( methodName, pattern, ... ) local cTable = { ["string"] = "s"; ["number"] = "n"; ["boolean"] = "b"; ["s"] = "string"; ["n"] = "number"; ["b"] = "boolean" }; if #pattern > table.maxn ( { ... } ) then local index = table.maxn ( { ... } ) == 0 and 1 or table.maxn ( { ... } ) + 1 return false, error ( "Bad Argument @ '"..methodName.."' [Expected "..cTable[ pattern:sub ( index, index ) ].." at argument "..index..", got none]" ) end for k, v in pairs ( { ... } ) do if cTable[ type ( v ) ] ~= pattern:sub ( k, k ) then return false, error ( "Bad Argument @ '"..methodName.."' [Expected "..cTable[ pattern:sub ( k, k ) ].." at argument "..k..", got "..( type ( v ) or "none" ).."]" ) end end return true; end function __checkRGB ( r, g, b ) -- Check if all parameters were passed if ( not r ) or ( not g ) or ( not b ) then return false; end for _, v in ipairs ( { r, g, b } ) do if ( type ( v ) ~= "number" ) or ( v < 0 ) or ( v > 255 ) then return false; end end return true; end function __isMouseInPosition ( x, y, w, h ) if not isCursorShowing() then return false end local res = { guiGetScreenSize() }; local cpos = { getCursorPosition() }; local fpos = { res[1] * cpos[1], res[2] * cpos[2] }; return ( fpos[1] >= x and fpos[1] <= x + w ) and ( fpos[2] >= y and fpos[2] <= y + h ) end وبارك الله في الي يقدر يساعد وجمعة مباركة تنعاد علينا وعليكم بصحة والسلامة Link to comment
nxFairlywell Posted July 12, 2019 Share Posted July 12, 2019 طبيعي جداً يا غالي , انت حاط 2 قريد ليست في كود مبرمج على دي اكس واحده يعني طبيعة الكود كذا هو مصمم على هذا الشيء , كله متغيرات والمتغير ياخذ آخر قيمه في ذا الكود هي القريد لست الأخيره اللي انت مسويها dxGrid وآخر قيمه لمتغيرات جرب تغير اسم القريد لست Lua سوي سكربت جديد , بعدين حط الكود ذا بملف بعدين جرب تسوي GridList1 = { items = {} }; function GridList1:Create(...... ...يعني عدل ع الفنكشنز اللي تسوي القريد لست واللي تجيب الاختيار من القريد لست واللي تحط عمود ووو الخ عدل إسم الفنكشنز مثل فوق في كل الملف بإسم المتغير اللي تبغاه للقريد لست الثانيه dxGrid أو انسخ الكود حق الدي اكس و انقله بملف ثاني و عن طريق النوت باد استبدل كلمة بالتوفيق 1 1 Link to comment
SycroX Posted July 12, 2019 Share Posted July 12, 2019 19 minutes ago, NX_CI said: طبيعي جداً يا غالي , انت حاط 2 قريد ليست في كود مبرمج على دي اكس واحده يعني طبيعة الكود كذا هو مصمم على هذا الشيء , كله متغيرات والمتغير ياخذ آخر قيمه في ذا الكود هي القريد لست الأخيره اللي انت مسويها dxGrid وآخر قيمه لمتغيرات جرب تغير اسم القريد لست Lua سوي سكربت جديد , بعدين حط الكود ذا بملف بعدين جرب تسوي GridList1 = { items = {} };function GridList1:Create(...... ...يعني عدل ع الفنكشنز اللي تسوي القريد لست واللي تجيب الاختيار من القريد لست واللي تحط عمود ووو الخ عدل إسم الفنكشنز مثل فوق في كل الملف بإسم المتغير اللي تبغاه للقريد لست الثانيه dxGrid أو انسخ الكود حق الدي اكس و انقله بملف ثاني و عن طريق النوت باد استبدل كلمة بالتوفيق Or لاحظت بالكود ان متغير اختيار الجدول محطوط في اللوب يعني دايما يكنسل الاختيار و يخليه لواحد فقط فممكن مع شويه تحققات و استعمل للجداول نظبط وضعنا dxGrid = { items = {} }; CursorOn = { } local NATIVE_RESOLUTION = { nil } -- put your screen resolution here to fit the gridlists to all resolutions (ex: { 1366, 768 } ) if ( table.maxn ( NATIVE_RESOLUTION ) == 2 ) then FIT_MODE = true RES = { guiGetScreenSize() }; X,Y = RES[1] / NATIVE_RESOLUTION[1], RES[2] / NATIVE_RESOLUTION[2]; SCALE = ( 1 / NATIVE_RESOLUTION[1] ) * RES[1]; end --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Core - functions function dxGrid:Create ( x, y, width, height, postGUI ) -- table dxGrid:Create ( int x, int y, int width, int height[, bool postGUI ] ) if __checkParams ( "Create", "nnnn", x, y, width, height ) then local data = { x = FIT_MODE and ( x * X ) or x; -- X position y = FIT_MODE and ( y * Y ) or y; -- Y position w = FIT_MODE and ( width * X ) or width; -- Width h = FIT_MODE and ( height * Y ) or height; -- Height pg = postGUI or false; -- PostGUI i = {}; -- Items mi = __calcMaxItems ( FIT_MODE and ( height * Y ) or height ); -- Max items s = 1; -- Scroll Level r = -1; -- Row count se = -1; -- Selected item mo = nil; -- Mouse-on item vis = true -- Visible }; setmetatable ( data, { __index = dxGrid } ); table.insert ( dxGrid.items, data ); return data; end end function dxGrid:Destroy () -- bool dxGrid:Destroy () for k, v in pairs ( dxGrid.items ) do if v == self then dxGrid.items[k] = nil; return true; end end return false; end function dxGrid:SetVisible ( visible ) -- bool Gridlist:SetVisible ( bool state ) if __checkParams ( "SetVisible", "b", visible ) then self.vis = visible return true else return false end end function dxGrid:IsVisible ( ) -- bool Gridlist:IsVisible() return self.vis end function dxGrid:AddColumn ( title, width ) -- int Gridlist:AddColumn ( string title, int width ) if __checkParams ( "AddColumn", "sn", title, width ) then local data = { info = { title = title, width = FIT_MODE and ( width * X ) or width } }; table.insert ( self.i, data ); return #self.i; end end function dxGrid:RemoveColumn ( columnIndex ) -- bool Gridlist:RemoveColumn ( int columnIndex ) if __checkParams ( "RemoveColumn", "n", columnIndex ) then self.i[columnIndex] = nil; -- Recalculate the highest item count local highest = -1; for _, v in ipairs ( self.i ) do if #v > highest then highest = ( #v - 1 ); end end self.r = highest; -- Recalculate the scroll level (if necessary) if ( ( ( self.s + self.mi ) - 2 ) == self.r ) then self.s = ( self.r - self.mi ) + 1; end return true end return false end function dxGrid:GetColumnCount () -- int Gridlist:GetColumnCount() return #self.i end function dxGrid:AddItem ( columnIndex, text, data, r, g, b ) -- int Gridlist:AddItem ( int columnIndex, string title[, mixed data, int r, int g, int b ] ) if __checkParams ( "AddItem", "ns", columnIndex, text ) then if self.i[columnIndex] then local tColor = __checkRGB ( r, g, b ) and { r, g, b } or { 255, 255, 255 }; table.insert ( self.i[columnIndex], { id = #self.i[columnIndex] + 1, text = tostring( text ), data = data, color = tColor } ); if #self.i[columnIndex] > self.r then self.r = #self.i[columnIndex]; end return #self.i[columnIndex]; end return false; end end function dxGrid:RemoveItem ( column, itemID ) -- bool Gridlist:RemoveItem ( int columnIndex, int itemIndex ) if __checkParams ( "RemoveItem", "nn", column, itemID ) then if self.i[column] and self.i[column][itemID] then -- Recalculate the highest item count if self.r == #self.i[column] then local highest = -1; for _, v in ipairs ( self.i ) do if #v > highest then highest = ( #v - 1 ); end end self.r = highest; end -- Recalculate the scroll level (if necessary) if ( ( ( self.s + self.mi ) - 2 ) == self.r ) then self.s = ( self.r - self.mi ) + 1; end -- Reset the selected item if necessary² if itemID == self.se then local newItem = self.se - 1 if newItem <= self.r then self.se = math.max ( 0, newItem ); else self.se = -1 end end table.remove ( self.i[column], itemID ); return true; end return false end end function dxGrid:GetItemCount ( columnID ) -- int Gridlist:GetItemCount ( int columnIndex ) if __checkParams ( "GetItemCount", "n", columnID ) then if self.i[columnID] then return #self.i[columnID] end return false end end function dxGrid:Clear () -- bool Gridlist:Clear() for k, v in ipairs ( self.i ) do self.i[k] = { info = v.info } end self.r = -1 self.se = nil -- Recalculate the scroll level self.s = 1; return true end function dxGrid:GetSelectedItem ( ) -- int Gridlist:GetSelectedItem () return self.se; end function dxGrid:SetSelectedItem ( itemID ) -- bool Gridlist:SetSelectedItem ( int itemIndex ) if __checkParams ( "SetSelectedItem", "n", itemID ) then if itemID <= self.r then self.se = itemID; return self.se == itemID; end return false; end end function dxGrid:GetItemDetails ( column, itemID ) -- string, mixed Gridlist:GetItemDetails ( int columnIndex, int itemIndex ) if __checkParams ( "GetItemDetails", "nn", columnID, itemID ) then if self.i[column] then if self.i[column][itemID] then return self.i[column][itemID].text, self.i[column][itemID].data end end return false end end --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Core - render/move addEventHandler ( "onClientRender", root, function ( ) -- Is there any gridlist to render? if #dxGrid.items > 0 then -- Loop through all grid lists for index, data in ipairs ( dxGrid.items ) do -- Is the gridlist visible? if data.vis then -- Draw the 'gridlist' itself dxDrawRectangle ( data.x, data.y, data.w, data.h, tocolor ( 0, 0, 0, 200 ), data.pg ); -- Draw the column bar dxDrawRectangle ( data.x, data.y, data.w, 30 % data.h, tocolor ( 0, 0, 0, 220 ), data.pg ); -- Set cursorOn variable to the current gridlist, if it's selected if __isMouseInPosition ( data.x, data.y, data.w, data.h ) then CursorOn = { true , index } else if CursorOn[1] and CursorOn[2] == gridlist then CursorOn = {} end end -- Check if there's any selected item local seeFrom = data.s; local seeTo = ( data.s + data.mi ) - 1; if data.se and data.se <= data.r and data.se >= seeFrom and data.se <= seeTo then local index = data.se - ( data.s - 1 ); local y2 = data.y + ( ( index - 1 ) * 25 ); -- Draw a rectangle to make it looks like selected dxDrawRectangle ( data.x, ( 30 % data.h ) + y2, data.w, 20, tocolor ( 100, 100, 100, 100 ), data.pg ); end -- Is there any column? if #data.i > 0 then local cWidth = 0 -- Loop through all columns for cIndex, cData in ipairs ( data.i ) do -- we'll go beyond the gridlist width with this column ? if ( ( cWidth + cData.info.width ) <= data.w ) then local x = data.x + cWidth; -- Draw the column title dxDrawText ( cData.info.title, x, data.y, cData.info.width + x, ( 30 % data.h ) + data.y, tocolor ( 255, 255, 255 ), FIT_MODE and ( 1 * SCALE ) or 1, "default-bold", "center", "center", true, true, data.pg, false, true ); -- Reset the selected item cData.info.selected = -1; -- Is there any item ? if #cData > 0 then local seeFrom = data.s; local seeTo = ( data.s + data.mi ) - 1; -- Loop the items for iIndex = seeFrom, seeTo do -- There's a row with this index in the current column? if cData[iIndex] then local index = iIndex - ( data.s - 1 ); local y = data.y + ( index * 25 ); local y2 = data.y + ( ( index - 1 ) * 25 ); -- Check if cursor is on item position if __isMouseInPosition ( data.x, ( 30 % data.h ) + y2, data.w, 20 ) then -- Define the mouse-on variable data.mo = iIndex; end -- Draw the item text dxDrawText ( cData[iIndex]["text"], x, y, cData.info.width + x, ( 30 % data.h ) + y, tocolor ( unpack ( cData[iIndex]["color"] ) ), FIT_MODE and ( 1 * SCALE ) or 1, "default-bold", "center", "center", true, true, data.pg, false, true ); end end end -- Increase cWidth variable (to draw the columns correctly) cWidth = cWidth + cData.info.width; end end end end end end end , true, "low-5") -- addEventHandler ( "onClientKey", root, function ( button, press ) -- Is cursor showing? if isCursorShowing () then -- Is there any gridlist? if #dxGrid.items > 0 then -- Is there any selected gridlist? if CursorOn and CursorOn [ 1 ] then -- We pressed the scroll? local cursorOn = CursorOn [ 2 ] if press and #button > 6 then -- Does the gridlist requires scroll? if dxGrid.items[cursorOn].r > dxGrid.items[cursorOn].mi then -- Define some variables local index = cursorOn; local currentValue = dxGrid.items[index].s; local newValue = math.max ( 1, button == "mouse_wheel_down" and currentValue + 2 or currentValue -1 ); -- Check if we have spent the row's limit with the new value if ( ( newValue + dxGrid.items[index].mi ) > dxGrid.items[index].r ) then newValue = ( dxGrid.items[index].r - dxGrid.items[index].mi ) + 1; end -- Set the new scroll level dxGrid.items[index].s = newValue; end elseif press and button == "mouse1" and dxGrid.items[cursorOn].mo then dxGrid.items[cursorOn].se = dxGrid.items[cursorOn].mo; end end end end end ) --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Useful function __calcMaxItems ( height ) for i = 0, 9999 do if ( ( ( i + 1 ) * 25 ) >= math.floor ( height ) ) then return ( ( ( i + 1 ) * 25 ) > math.floor ( height ) and ( i - 1 ) or i ); end end return false; end function __checkParams ( methodName, pattern, ... ) local cTable = { ["string"] = "s"; ["number"] = "n"; ["boolean"] = "b"; ["s"] = "string"; ["n"] = "number"; ["b"] = "boolean" }; if #pattern > table.maxn ( { ... } ) then local index = table.maxn ( { ... } ) == 0 and 1 or table.maxn ( { ... } ) + 1 return false, error ( "Bad Argument @ '"..methodName.."' [Expected "..cTable[ pattern:sub ( index, index ) ].." at argument "..index..", got none]" ) end for k, v in pairs ( { ... } ) do if cTable[ type ( v ) ] ~= pattern:sub ( k, k ) then return false, error ( "Bad Argument @ '"..methodName.."' [Expected "..cTable[ pattern:sub ( k, k ) ].." at argument "..k..", got "..( type ( v ) or "none" ).."]" ) end end return true; end function __checkRGB ( r, g, b ) -- Check if all parameters were passed if ( not r ) or ( not g ) or ( not b ) then return false; end for _, v in ipairs ( { r, g, b } ) do if ( type ( v ) ~= "number" ) or ( v < 0 ) or ( v > 255 ) then return false; end end return true; end function __isMouseInPosition ( x, y, w, h ) if not isCursorShowing() then return false end local res = { guiGetScreenSize() }; local cpos = { getCursorPosition() }; local fpos = { res[1] * cpos[1], res[2] * cpos[2] }; return ( fpos[1] >= x and fpos[1] <= x + w ) and ( fpos[2] >= y and fpos[2] <= y + h ) end جرب و قلي 1 Link to comment
DaHoM Posted July 12, 2019 Author Share Posted July 12, 2019 3 hours ago, #x1AhMeD-09 said: جرب و قلي بـارك الله فيك مبدع اخوي , يعطيك العافية ما قصرت Link to comment
DaHoM Posted July 12, 2019 Author Share Posted July 12, 2019 5 hours ago, #x1AhMeD-09 said: exports أخوي بسألك كيف اسوي للفنكشن حقت الجريد ليست مو راضي يزبطط معي ( ':' ) يضربني الديبق يقول ما ينفع تستخدم مرتين مثل exports.dx:GridList:Create(...) Link to comment
SycroX Posted July 13, 2019 Share Posted July 13, 2019 ما تقدر بسبب طريقه برمجه المود , لازم تعيد البرمجه 1 Link to comment
SycroX Posted July 13, 2019 Share Posted July 13, 2019 6 hours ago, #x1AhMeD-09 said: ما تقدر بسبب طريقه برمجه المود , لازم تعيد البرمجه او تضيف فانكشنات خاصه للاكسبورت مثال function dxCreateGridList ( ... ) gridlist = dxGrid:Create ( ... ) return gridlist end 1 Link to comment
DaHoM Posted July 13, 2019 Author Share Posted July 13, 2019 (edited) 1 hour ago, #x1AhMeD-09 said: او تضيف فانكشنات خاصه للاكسبورت مثال function dxCreateGridList ( ... ) gridlist = dxGrid:Create ( ... ) return gridlistend انا بلشت شغل عليها وحولتها Method بس بدو ازبط ال __index على كونو الديبق يقلي table index is nil يقصد سطر 6 في طريقة ثانية يعني ما يحتاج اسوي __index هذا المسار local gridlist = {} local CursorOn = {} function dxCreateGridList ( nameGridList , x, y, width, height ) if __checkParams ( "Create", "nnnn", x, y, width, height ) then gridlist [nameGridList] = { x , y , w = ( width ) , h = ( height ) , pg = ( false ) , i = {} , mi = ( __calcMaxItems ( height ) ) , s = 1 , r = -1 , se = -1 , mo = nil , vis = true } return gridlist [ nameGridList ] ; end end function dxDestroyGridList ( nameGridList ) for k, v in pairs ( gridlist ) do if ( v == nameGridList ) then gridlist [ k ] = nil; return true; end end return false; end function dxSetGridListVisible ( nameGridList , visible ) if __checkParams ( "SetVisible", "b", visible ) then gridlist [nameGridList] [vis] = visible return true else return false end end function dxIsGridListVisible ( nameGridList ) return gridlist [nameGridList] [vis] end function dxAddGridListColumn ( nameGridList , title , width ) if __checkParams ( "AddColumn", "sn", title, width ) then local data = { info = { gridlist = nameGridList , title = title, width } }; table.insert ( gridlist [nameGridList] [i] , data ); return #gridlist [nameGridList] [i] ; end end function dxRemoveGridListColumn ( nameGridList , columnIndex ) if __checkParams ( "RemoveColumn", "n", columnIndex ) then gridlist [nameGridList] [i] [ columnIndex ] = nil; -- Recalculate the highest item count local highest = -1; for _, v in ipairs ( gridlist [nameGridList] [i] ) do if #v > highest then highest = ( #v - 1 ); end end gridlist [nameGridList] [r] = highest; -- Recalculate the scroll level (if necessary) if ( ( ( gridlist [nameGridList] [s] + gridlist [nameGridList][mi] ) - 2 ) == gridlist [nameGridList] [r] ) then gridlist [nameGridList] [s] = ( gridlist [nameGridList] [r] - gridlist [nameGridList] [mi] ) + 1; end return true end return false end function dxGetGridListColumnCount ( nameGridList ) return #gridlist [nameGridList] [i] end function dxAddGridListItem ( nameGridList , columnIndex, text, data, r, g, b ) if __checkParams ( "AddItem" , "ns" , columnIndex , text ) then if gridlist [nameGridList] [i] [ columnIndex ] then local tColor = __checkRGB ( r, g, b ) and { r, g, b } or { 255, 255, 255 }; table.insert ( gridlist [nameGridList] [i] [ columnIndex ] , { id = #gridlist [nameGridList] [i] [ columnIndex ] + 1, text = tostring( text ), data = data, color = tColor } ); if #gridlist [nameGridList] [i] [ columnIndex ] > gridlist [nameGridList] [r] then gridlist [nameGridList] [r] = #gridlist [nameGridList] [i][columnIndex]; end return #gridlist [nameGridList] [i][columnIndex]; end return false; end end function dxRemoveGridListItem ( nameGridList , column, itemID ) if __checkParams ( "RemoveItem", "nn", column, itemID ) then if gridlist [nameGridList] [i] [ column ] and gridlist [nameGridList] [i] [ column ] [ itemID ] then -- Recalculate the highest item count if gridlist [nameGridList] [r] == #gridlist [nameGridList] [i] [ column ] then local highest = -1; for _, v in ipairs ( gridlist [nameGridList] [i] ) do if #v > highest then highest = ( #v - 1 ); end end gridlist [nameGridList] [r] = highest; end -- Recalculate the scroll level (if necessary) if ( ( ( gridlist [nameGridList] [s] + gridlist [nameGridList] [mi] ) - 2 ) == gridlist [nameGridList] [r] ) then gridlist [nameGridList] [s] = ( gridlist [nameGridList] [r] - gridlist [nameGridList] [mi] ) + 1; end -- Reset the selected item if necessary² if itemID == gridlist [nameGridList] [se] then local newItem = gridlist [nameGridList] [se] - 1 if newItem <= gridlist [nameGridList] [r] then gridlist [nameGridList] [se] = math.max ( 0, newItem ); else gridlist [nameGridList] [se] = -1 end end table.remove ( gridlist [nameGridList] [i] [ column ] , itemID ); return true; end return false end end function dxGetGridListItemCount ( nameGridList , columnID ) if __checkParams ( "GetItemCount", "n", columnID ) then if gridlist [nameGridList] [i][columnID] then return #gridlist [nameGridList] [i][columnID] end return false end end function dxClearGridList ( nameGridList ) for k, v in ipairs ( gridlist [nameGridList] [i] ) do gridlist [nameGridList] [i][k] = { info = v.info } end gridlist [nameGridList] [r] = -1 gridlist [nameGridList] [se] = nil -- Recalculate the scroll level gridlist [nameGridList] [s] = 1; return true end function dxGetGridListSelectedItem ( nameGridList ) return gridlist [nameGridList] [se]; end function dxSetGridListSelectedItem ( nameGridList , itemID ) if __checkParams ( "SetSelectedItem", "n", itemID ) then if itemID <= gridlist [nameGridList] [r] then gridlist [nameGridList] [se] = itemID; return gridlist [nameGridList] [se] == itemID; end return false; end end function dxGetGridListItemDetails ( nameGridList , column , itemID ) if __checkParams ( "GetItemDetails", "nn", columnID, itemID ) then if gridlist [nameGridList] [i][column] then if gridlist [nameGridList] [i][column][itemID] then return ( gridlist [nameGridList] [i] [ column ] [ itemID ] [text] ) , ( gridlist [nameGridList] [i] [ column ] [ itemID ] [data] ) end end return false end end --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Core - render/move addEventHandler ( "onClientRender", root, function ( ) -- Is there any gridlist to render? if #gridlist > 0 then -- Loop through all grid lists for index, v in ipairs ( gridlist ) do -- Is the gridlist visible? if v.vis then -- Draw the 'gridlist' itself dxDrawRectangle ( v.x, v.y, v.w, v.h, tocolor ( 0, 0, 0, 200 ), v.pg ); -- Draw the column bar dxDrawRectangle ( v.x, v.y, v.w, 30 % v.h, tocolor ( 20, 20, 20, 220 ), v.pg ); -- Set cursorOn variable to the current gridlist, if it's selected if __isMouseInPosition ( v.x, v.y, v.w, v.h ) then CursorOn = { true , index } else if CursorOn[1] and CursorOn[2] == gridlist then CursorOn = {} end end -- Check if there's any selected item local seeFrom = v.s; local seeTo = ( v.s + data.mi ) - 1; if v.se and v.se <= v.r and v.se >= seeFrom and v.se <= seeTo then -- Draw a rectangle to make it looks like selected local index = v.se - ( data.s - 1 ); local y2 = v.y + ( ( index - 1 ) * 25 ); dxDrawRectangle ( v.x, ( 30 % v.h ) + y2, v.w, 24, tocolor ( 180, 180, 180, 180 ), v.pg ); end -- Is there any column? if #v.i > 0 then local cWidth = 0 -- Loop through all columns for cIndex, cData in ipairs ( v.i ) do -- we'll go beyond the gridlist width with this column ? if ( ( cWidth + cData.info.width ) <= v.w ) then local x = v.x + cWidth; -- Draw the column title dxDrawText ( cData.info.title, x, v.y, cData.info.width + x, ( 30 % data.h ) + v.y, tocolor ( 255, 255, 255 ), 1.0 , dxFont, "center", "center", true, true, v.pg, false, true ); -- Reset the selected item cData.info.selected = -1; -- Is there any item ? if #cData > 0 then local seeFrom = v.s; local seeTo = ( v.s + v.mi ) - 1; -- Loop the items for iIndex = seeFrom, seeTo do -- There's a row with this index in the current column? if cData[iIndex] then local index = iIndex - ( v.s - 1 ); local y = v.y + ( index * 25 ); local y2 = v.y + ( ( index - 1 ) * 25 ); -- Check if cursor is on item position if __isMouseInPosition ( v.x, ( 30 % v.h ) + y2, v.w, 20 ) then -- Define the mouse-on variable v.mo = iIndex; end -- Draw the item text dxDrawText ( cData[iIndex]["text"], x, y, cData.info.width + x, ( 30 % v.h ) + y, tocolor ( unpack ( cData[iIndex]["color"] ) ), 1.0 , dxFont, "center", "center", true, true, data.pg, false, true ); end end end -- Increase cWidth variable (to draw the columns correctly) cWidth = cWidth + cData.info.width; end end end end end end end , true, "low-5") -- addEventHandler ( "onClientKey", root, function ( button, press ) -- Is cursor showing? if isCursorShowing () then -- Is there any gridlist? if #gridlist > 0 then -- Is there any selected gridlist? if CursorOn and CursorOn [ 1 ] then -- We pressed the scroll? local cursorOn = CursorOn [ 2 ] if press and #button > 6 then -- Does the gridlist requires scroll? if gridlist.data[cursorOn].r > gridlist.data[cursorOn].mi then -- Define some variables local index = cursorOn; local currentValue = gridlist.data[index].s; local newValue = math.max ( 1, button == "mouse_wheel_down" and currentValue + 2 or currentValue -1 ); -- Check if we have spent the row's limit with the new value if ( ( newValue + gridlist.data[index].mi ) > gridlist.data[index].r ) then newValue = ( gridlist.data[index].r - gridlist.data[index].mi ) + 1; end -- Set the new scroll level gridlist.data[index].s = newValue; end elseif press and button == "mouse1" and gridlist.data[cursorOn].mo then gridlist.data[cursorOn].se = gridlist.data[cursorOn].mo; end end end end end ) --=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=- Useful function __calcMaxItems ( height ) for i = 0, 9999 do if ( ( ( i + 1 ) * 25 ) >= math.floor ( height ) ) then return ( ( ( i + 1 ) * 25 ) > math.floor ( height ) and ( i - 1 ) or i ); end end return false; end function __checkParams ( methodnameGridList, pattern, ... ) local cTable = { ["string"] = "s"; ["number"] = "n"; ["boolean"] = "b"; ["s"] = "string"; ["n"] = "number"; ["b"] = "boolean" }; if #pattern > table.maxn ( { ... } ) then local index = table.maxn ( { ... } ) == 0 and 1 or table.maxn ( { ... } ) + 1 return false, error ( "Bad Argument @ '"..methodnameGridList.."' [Expected "..cTable[ pattern:sub ( index, index ) ].." at argument "..index..", got none]" ) end for k, v in pairs ( { ... } ) do if cTable[ type ( v ) ] ~= pattern:sub ( k, k ) then return false, error ( "Bad Argument @ '"..methodnameGridList.."' [Expected "..cTable[ pattern:sub ( k, k ) ].." at argument "..k..", got "..( type ( v ) or "none" ).."]" ) end end return true; end function __checkRGB ( r, g, b ) -- Check if all parameters were passed if ( not r ) or ( not g ) or ( not b ) then return false; end for _, v in ipairs ( { r, g, b } ) do if ( type ( v ) ~= "number" ) or ( v < 0 ) or ( v > 255 ) then return false; end end return true; end function __isMouseInPosition ( x, y, w, h ) if not isCursorShowing() then return false end local res = { guiGetScreenSize() }; local cpos = { getCursorPosition() }; local fpos = { res[1] * cpos[1], res[2] * cpos[2] }; return ( fpos[1] >= x and fpos[1] <= x + w ) and ( fpos[2] >= y and fpos[2] <= y + h ) end Edited July 13, 2019 by DaHoM Link to comment
DaHoM Posted July 13, 2019 Author Share Posted July 13, 2019 تم خلاص حليت المشكلة الشكرر للمساعدين Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now