نشرت موضوع قبل يوم عن الفنكشنات اللي سويتها
كانت مجرد تجربه وشفتها نجحت *-* ف عدلت عليها وظفت فنكشنات أكثر
الأحداث
"onMButtonClicked" -- من تضغط على زر
"onMFrameClicked" -- من تضغط على شريط العنوان للنافذه
"onMTextBoxClicked" -- واضح من أسمه
"onKeyTyped" -- من ينكتب الحرف داخل ال textBox
"onKeyPressed" -- من تظغط على الحرف سواء تمت كتابته أو لا
Frame
--[[
createFrame(
x - أحداثي x للأطار
y - أحداثي y للأطار
w - عرض الأطار
h - أرتفاع الأطار
Title - عنوان الأطار
Color - لون الأطار
TitleBarColor - لون شريط العنوان
withX - أذا تريد يحط علامة أكس لأخفاء الاطار
)
]]
function createFrame( x, y, w, h, Title, Color, TitleBarColor, withX )
local isVisableX = true;
local isMouseInsideX = false;
local FrameTrigger = 0;
local TempComponents = {};
MFrame = {
x = 0, y = 0,
w = 400, h = 250,
Title = "Frame",
Color = tocolor( 120, 120, 120, 150 ),
Color = tocolor( 120, 120, 120, 255 ),
type = "Frame",
isX = false,
components = {
},
isMouseOnTitleBar = function ()
mouseX, mouseY = getCursorPosition();
if ( not isCursorShowing ( ) ) then
return false;
end
local Sx, Sy = guiGetScreenSize( )
mx = mouseX * Sx; my = mouseY * Sy;
--outputChatBox( y .. " : " .. h + .. ", " .. mx )
if ( mx > x and mx <= x + w + 10 and my > y and my <= y + 15 ) then
return true;
end
return false;
end,
clear = function ()
for k,v in pairs(MFrame.components) do
if ( v.getText() ~= "X" ) then
v.setVisable(false)
end
end
end,
setTitle = function ( newTitle )
Title = newTitle;
end,
setX = function ( newX )
x = newX;
end,
setY = function ( newY )
y = newY;
end,
setVisable = function ( visable )
isVisableX = visable;
end,
render = function ()
if ( isVisableX ) then
dxDrawRectangle( x, y, w, h, Color, false)
dxDrawRectangle( x, y, w, 30, TitleBarColor, false)
dxDrawText( Title, x + 5, y + 7)
for k,v in pairs(MFrame.components) do
v.setOfset(x, y)
if ( v.type ~= "TextBox" ) then
if ( v.isMouseInside() ) then
v.highlight(30);
else
v.dehighlight();
end
end
v.render();
end
end
end,
add = function ( comp )
comp.setOfset(x, y)
table.insert(MFrame.components, comp);
TempComponents = MFrame.components;
end,
click = function ( button, state )
if ( not isMouseInsideX ) then
return;
end
if ( FrameTrigger == 0 ) then
triggerEvent( "onMFrameClicked", getRootElement(), button, state )
FrameTrigger = 1;
setTimer( function ( )
FrameTrigger = 0;
end, 150, 1 )
end
end
}
function close( button, state, text )
if ( text == "X" and button == "left" and state == "down" ) then
isVisableX = false;
showCursor( false )
end
end
function createX( x, y, w, h)
if ( withX ) then
Color = TitleBarColor + 10;
TextColor = TitleBarColor - 10;
x = createButton( w - 30, 0, 30, 30, "X", Color, textColor )
MFrame.add(x);
addEventHandler( "onMButtonClicked", getRootElement( ), close )
end
end
function Cliced( button, state )
end
function updae()
isMouseInsideX = MFrame.isMouseOnTitleBar();
end
function create()
addEvent( "onMButtonClicked", true )
addEvent( "onMFrameClicked" )
MFrame.x = x; MFrame.y = y;
MFrame.w = w; MFrame.h = h;
MFrame.Title = Title;
MFrame.Color = Color; MFrame.TitleBarColor = TitleBarColor;
createX(x, y, w, h);
addEventHandler( "onClientClick", getRootElement(), MFrame.click )
addEventHandler( "onClientRender", getRootElement(), updae )
addEventHandler( "onMFrameClicked", getRootElement( ), Cliced )
return MFrame;
end
return create();
end
Button
--[[
createButton(
x - أحداثي x للزر
y - أحداثي y للزر
w - عرض الزر
h - أرتفاع الزر
text - النص اللي يضهر داخله
Color - لون مربع الزر
textColor - لون النص
)
]]
function createButton( x, y, w, h, text, Color, textColor )
local xOfset = 0;
local yOfset = 0;
local isVisableX = true;
local mouseInside = false;
local swap = Color;
local swapCheck = 0;
local test = 0;
local MButton = {
x = 0, y = 0,
w = 80, h = 20,
text = "Button",
isVisable = isVisableX,
textColor = tocolor( 236, 240, 241, 255 ),
Color = tocolor( 231, 76, 60, 150 ),
type = "Button",
render = function ()
if ( isVisableX == true ) then
dxDrawRectangle( x + xOfset, y + yOfset, w, h, Color )
dxDrawText( text, ( (x + xOfset) + (w/2) ) - (string.len(text)*3), ((y + yOfset) - 7) + (h/2) )
end
end,
isMouseInside = function ()
mouseX, mouseY = getCursorPosition();
if ( not isCursorShowing ( ) ) then
return false
end
local Sx, Sy = guiGetScreenSize( )
x2 = Sx * mouseX;
y2 = Sy * mouseY;
--outputChatBox(y + yOfset .. " : " .. h + yOfset + 40 .. ", " .. math.floor(y2))
--outputChatBox(x + xOfset .. " : " .. w + xOfset + x .. ", " .. math.floor(x2))
if ( x2 >= x + xOfset and x2 <= w + xOfset + x and y2 >= y + yOfset and y2 <= h + yOfset + y) then
return true;
end
return false;
end,
highlight = function ( value )
if ( swapCheck == 0 ) then
swap = Color;
swapCheck = 1;
Color = Color + value
end
end,
dehighlight = function ()
Color = swap;
swapCheck = 0;
end,
setVisable = function ( visable )
isVisableX = visable;
end,
getVisable = function ( )
return isVisableX;
end,
setTextColor = function ( color )
textColor = color;
end,
setTextColorRGBA = function ( r, g, b, a )
textColor = tocolor( r, g, b, a )
end,
getText = function ( )
return text;
end,
setText = function ( text2 )
text = text2;
end,
setColor = function ( Color2 )
Color = Color2;
end,
setColorRGBA = function ( r, g, b, a )
Color = tocolor( r, g, b, a )
end,
getColorRGBA = function ( )
end,
setOfset = function ( ofx, ofy )
xOfset = ofx;
yOfset = ofy;
end,
setX = function (x2) x = x2 end,
getX = function () return x; end,
setY = function (y2) y = y2 end,
getY = function () return y; end,
setW = function (w2) w = w2 end,
getW = function () return w; end,
setH = function (h2) h = h2 end,
getH = function () return h; end,
Click = function ( button, state )
if ( not mouseInside ) then
return;
end
if ( test == 0 ) then
triggerEvent( "onMButtonClicked", getRootElement(), button, state, text, x, y, w, h )
test = 1;
Color = Color + 30;
setTimer( function ()
test = 0;
Color = Color - 30;
end, 150, 1 )
end
end,
}
local update = function ()
mouseInside = MButton.isMouseInside();
end
local create = function ()
MButton.x = x; MButton.y = y;
MButton.w = w; MButton.h = h;
MButton.text = text; MButton.Color = Color;
MButton.textColor = textColor;
addEventHandler( "onClientClick", getRootElement(), MButton.Click )
addEventHandler( "onClientRender", getRootElement(), update )
return MButton;
end
return create()
end
Label
--[[
text - النص
x - أحداثي x
y - أحداثي y
Color - اللون
]]
function createLabel( text, x, y, Color)
local xOfset = 0;
local yOfset = 0;
local isVisable = true;
MLabel = {
x = 0,
y = 0,
text = "Label",
Color = tocolor( 120, 21, 0, 255 ),
type = "Label",
render = function ()
if ( isVisable ) then
dxDrawText( text, x + xOfset, y + yOfset, 0, 0, Color )
end
end,
setVisable = function( visable )
isVisable = visable;
end,
setOfset = function ( ofx, ofy )
xOfset = ofx;
yOfset = ofy;
end,
setText = function ( Text )
text = Text;
end,
getText = function ()
return text;
end,
setX = function ( newX )
x = newX;
end,
getX = function ( )
return x;
end,
setY = function ( newY )
y = newY;
end,
getY = function ( )
return y;
end,
isMouseInside = function ( )
end,
dehighlight = function ( )
end
}
function create()
MLabel.x = x; MLabel.y = y;
MLabel.text = text;
MLabel.Color = Color;
return MLabel;
end
return create();
end
راح تفهم تقريباً نص الفنكشنات من المثال
Example
local fps = false
function getCurrentFPS()
return fps
end
local function updateFPS(msSinceLastFrame)
fps = (1 / msSinceLastFrame) * 1000
end
addEventHandler("onClientPreRender", root, updateFPS)
local Frame;
local b1;
local b2;
local b3;
local l1;
function renderer ( )
Frame.render();
end
function init()
showCursor(true)
ButtonColor = tocolor( 255, 76, 60, 255 )
textColor = tocolor( 236, 240, 241, 255 )
b1 = createButton( 10, 40, 80, 40, "Button1", ButtonColor, textColor )
b2 = createButton( 200, 40, 80, 40, "Button2", ButtonColor, textColor )
b3 = createButton( 300, 200, 80, 40, "Button3", ButtonColor, textColor )
l1 = createLabel( "Hello", 20, 200, tocolor( 0, 0, 0, 255) )
FrameColor = tocolor( 231, 76, 60, 120 )
Frame = createFrame( 250, 250, 450, 250, "Frame", FrameColor, FrameColor, true );
Frame.add(b1)
Frame.add(b2)
Frame.add(b3)
Frame.add(l1)
addEventHandler ( "onClientRender", root, renderer )
setTimer( function ()
Frame.setTitle( "FPS : " .. math.floor(getCurrentFPS()))
end, 250, 0 )
bindKey ( "F5", "down",
function ( )
Frame.setVisable(true)
showCursor( true )
end
)
end
addEventHandler ( "onClientResourceStart", resourceRoot, init )
ClickedX = 0;
function Move( )
local screenx, screeny, worldx, worldy, worldz = getCursorPosition()
local x, y = guiGetScreenSize( )
x2 = screenx * x;
y2 = screeny * y;
if ( Frame.isMouseOnTitleBar() ) then
Frame.setX(x2 -10);
Frame.setY(y2 -10);
end
end
function ClickHandler( button, state, text, x, y, w, h)
if ( text == "Button3" ) then
Frame.clear();
elseif ( text == "Button1" ) then
if ( button == "left" ) then
l1.setText(text)
l1.setX( l1.getX() + 10 )
else
l1.setText(text)
l1.setX( l1.getX() - 10 )
end
end
end
addEvent( "onMButtonClicked" )
addEventHandler("onMButtonClicked", getRootElement(), ClickHandler)
Result
وهذي محاولتي ب TextBox
اللي فشلت
أذا عندك أمكانيه تصلحها صلحها : )