Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (File.exists("c.lua")) then File.delete("c.lua"); end
- local scrSize = Vector2(guiGetScreenSize());
- cursorPosition = Vector2();
- isCursorShown = false;
- local HISTORY_CALL_TYPE = {INCOMING = 0, INCOMING_UNANSWERED = 1, OUTGOING = 2};
- local HISOTRY_CALL_TYPE_TEXTS = {
- [HISTORY_CALL_TYPE.INCOMING] = "Bejövő",
- [HISTORY_CALL_TYPE.INCOMING_UNANSWERED] = "#D63131Nem fogadott#646464",
- [HISTORY_CALL_TYPE.OUTGOING] = "Kimenő",
- }
- local CALL_STATE = {
- CALLING = 0,
- TALKING = 1,
- CALLED_NUMBER_UNAVAILABLE = 2,
- INVALID_NUMBER = 3,
- LINE_BUSY = 4,
- ITEM_OWNER_NOT_PLAYER = 5,
- TIMEOUT = 6,
- ENDED = 7,
- CONNECTION_LOST = 8
- };
- local CALL_STATE_TEXTS = {
- [CALL_STATE.CALLING] = {"Tárcsázás..", "Bejövő hívás"},
- [CALL_STATE.TALKING] = "Beszélgetés..",
- [CALL_STATE.CALLED_NUMBER_UNAVAILABLE] = "A hívott szám nem elérhető",
- [CALL_STATE.INVALID_NUMBER] = "Helytelen szám",
- [CALL_STATE.LINE_BUSY] = "Foglalt",
- [CALL_STATE.ITEM_OWNER_NOT_PLAYER] = "Kicsörgött",
- [CALL_STATE.TIMEOUT] = "Timeout",
- [CALL_STATE.ENDED] = "Beszélgetés befejezve",
- [CALL_STATE.CONNECTION_LOST] = "Kapcsolat megszakadt"
- };
- local WEEKDAY_NAMES = {[0] = "Hétfő", "Kedd", "Szerda", "Csütörtök", "Péntek", "Szombat", "Vasárnap"};
- local MONTH_NAMES = {[0] = "Jan.", "Feb.", "Márc.", "Ápr.", "Máj.", "Jún.", "Júl.", "Aug.", "Szep.", "Okt.", "Nov.", "Dec."};
- local responsiveMultiplier = Vector2(reMap(scrSize.y, 768, 1080, 0.7, 1), reMap(scrSize.y, 768, 1080, 0.7, 1));
- fonts = {
- roboto_light = {
- [26] = DxFont("files/fonts/Roboto-Light.ttf", 26 * responsiveMultiplier.x, false, "cleartype"),
- [18] = DxFont("files/fonts/Roboto-Light.ttf", 18 * responsiveMultiplier.x, false, "cleartype"),
- [16] = DxFont("files/fonts/Roboto-Light.ttf", 16 * responsiveMultiplier.x, false, "cleartype"),
- [14] = DxFont("files/fonts/Roboto-Light.ttf", 14 * responsiveMultiplier.x, false, "cleartype"),
- [12] = DxFont("files/fonts/Roboto-Light.ttf", 12 * responsiveMultiplier.x, false, "cleartype"),
- [10] = DxFont("files/fonts/Roboto-Light.ttf", 10 * responsiveMultiplier.x, false, "cleartype")
- },
- roboto_regular = {
- [18] = DxFont("files/fonts/Roboto-Regular.ttf", 18 * responsiveMultiplier.x, false, "cleartype"),
- [16] = DxFont("files/fonts/Roboto-Regular.ttf", 16 * responsiveMultiplier.x, false, "cleartype"),
- [14] = DxFont("files/fonts/Roboto-Regular.ttf", 14 * responsiveMultiplier.x, false, "cleartype"),
- [12] = DxFont("files/fonts/Roboto-Regular.ttf", 12 * responsiveMultiplier.x, false, "cleartype"),
- [10] = DxFont("files/fonts/Roboto-Regular.ttf", 10 * responsiveMultiplier.x, false, "cleartype")
- },
- roboto_medium = {
- [24] = DxFont("files/fonts/Roboto-Medium.ttf", 24 * responsiveMultiplier.x, false, "cleartype"),
- [18] = DxFont("files/fonts/Roboto-Medium.ttf", 18 * responsiveMultiplier.x, false, "cleartype"),
- [16] = DxFont("files/fonts/Roboto-Medium.ttf", 16 * responsiveMultiplier.x, false, "cleartype"),
- [14] = DxFont("files/fonts/Roboto-Medium.ttf", 14 * responsiveMultiplier.x, false, "cleartype"),
- [12] = DxFont("files/fonts/Roboto-Medium.ttf", 12 * responsiveMultiplier.x, false, "cleartype"),
- [10] = DxFont("files/fonts/Roboto-Medium.ttf", 10 * responsiveMultiplier.x, false, "cleartype")
- }
- };
- local callInfo = {}
- local lastPanelID, currentPanelID;
- local PANEL = {
- MENU = 0,
- ADVERTISING = 1,
- CONTACTS = 2,
- BALANCE = 3,
- CAMERA = 4,
- GALLERY = 5,
- SETTINGS = 6,
- CALENDAR = 7,
- CLOCK = 8,
- COMPASS = 10,
- MESSAGES = 11,
- MUSIC = 12,
- FILES = 23,
- EDIT_CONTACT = 13,
- CALL_CHAT = 14,
- CALL_OUTGOING = 15,
- CALL_INCOMING = 16,
- CALL_HISTORY = 17,
- CALL_KEYPAD = 18,
- CONTACT_MESSENGER = 19,
- CONTACT_ADD_OR_EDIT = 20, -- add if panels[PANEL.CONTACT_ADD_OR_EDIT].edit == nil, otherwise edit
- CONTACT_FAVORITES = 21,
- WALLPAPER_CHANGE = 22
- };
- local soundElementsByPhone = setmetatable({}, CREATE_INDEX_IF_NIL_MT1D); -- key: phoneNumber, value: {ringtone = <elem>, sms = <elem>}. Desc: Contains the current ringtone / sms element of the given phone.
- local isShowing = false;
- local phoneData = {wallpaperID = 0};
- local position = Vector2(500, 200) * responsiveMultiplier;
- local screenPosition = position + Vector2(18, 18) * responsiveMultiplier; -- the positions picture are drawn at, so the border can overlap them
- -- Size must be a fixed one, otherwise things blow up.
- local size = Vector2(328, 638) * responsiveMultiplier;
- local screenSize = size - Vector2(2 * 18, 2 * 18) * responsiveMultiplier;
- local panels = {}; -- panel renderes
- local panelSetHistory = {};
- function setPhoneVisible(newState, newPhoneData)
- if (newState == isShowing) then return; end
- isShowing = newState;
- if (newState) then
- panelSetHistory = {};
- end
- if (newPhoneData) then
- phoneData = newPhoneData;
- local contacts = phoneData.contacts;
- phoneData.favoriteContacts = {};
- phoneData.contacts = {};
- for _, v in pairs(contacts) do
- if (v.favorite) then table.insert(phoneData.favoriteContacts, contact); end
- table.insert(phoneData.contacts, v);
- end
- sortContactList();
- local oldMessages = phoneData.messages;
- phoneData.messages = {};
- for number, v in pairs(oldMessages) do
- table.insert(phoneData.messages, v);
- phoneData.messages[#phoneData.messages].number = number;
- end
- sortSMSArray();
- if (not File.exists("files/textures/wallpapers/" .. phoneData.settings.wallpaper .. ".png")) then
- phoneData.settings.wallpaper = 0;
- end
- end
- setCurrentPanel(PANEL.MENU);
- local eventHandlerRemoveAdd = newState and addEventHandler or removeEventHandler;
- eventHandlerRemoveAdd("onClientRender", root, onClientRender, false, "low-100");
- eventHandlerRemoveAdd("onClientClick", root, onClientClick);
- local bindOrUnbind = newState and bindKey or unbindKey;
- bindOrUnbind("backspace", "down", goBackToPanelCameFrom);
- end
- function setCurrentPanel(panelID)
- if (not panels[panelID]) then return; end
- if (panelID == PANEL.CAMERA and localPlayer.vehicle) then exports.cr_infobox:addBox("warning", "Kocsiban nem használhatod a fényképezőt."); return; end
- lastPanelID = currentPanelID;
- currentPanelID = panelID;
- outputChatBox("switch panel from " .. tostring(lastPanelID) .. " to " .. tostring(currentPanelID));
- if (lastPanelID) then
- if (lastPanelID ~= PANEL.CALL_INCOMING and lastPanelID ~= PANEL.CALL_OUTGOING and lastPanelID ~= PANEL.CALL_CHAT) then
- table.insert(panelSetHistory, lastPanelID);
- end
- if (lastPanelID == PANEL.SETTINGS and currentPanelID ~= PANEL.WALLPAPER_CHANGE) then
- triggerServerEvent("onClientPlayerChangePhoneSettings", localPlayer, phoneData.settings);
- end
- if (panels[lastPanelID].deinit) then panels[lastPanelID].deinit(); end
- end
- if (panels[currentPanelID].init) then panels[currentPanelID].init(); end
- end
- function onClientRender()
- isCursorShown = isCursorShowing()
- if (isCursorShown) then
- cursorPosition = Vector2(getCursorPosition()) * scrSize;
- end
- dxDrawText(inspect(panelSetHistory), 650, 120)
- if (currentPanelID == PANEL.CAMERA) then
- dxDrawRectangle(scrSize / 2 - Vector2(screenSize.y, screenSize.x) / 2, screenSize.y, screenSize.x, 0xFF2c2c2c);
- else
- dxDrawRectangle(screenPosition, screenSize, 0xFF000000);
- end
- if (panels[currentPanelID].render) then panels[currentPanelID].render(); end
- if (currentPanelID == PANEL.CAMERA) then
- dxDrawImage(scrSize / 2 - Vector2(size.y, size.x) / 2, size.y, size.x, "files/textures/iphonex90.png");
- else
- dxDrawImage(position, size, "files/textures/iphonex.png");
- end
- end
- function onClientClick(button, state, x, y)
- if (not wasEventCancelled() and panels[currentPanelID].click) then
- panels[currentPanelID].click(button, state == "down", Vector2(x, y));
- end
- end
- panels[PANEL.MENU] = {
- init = function()
- end,
- render = function()
- dxDrawImage(screenPosition, screenSize, "files/textures/wallpapers/" .. phoneData.settings.wallpaper .. ".png");
- local iconMarginRight = screenSize.x * 0.06;
- local iconSize = (screenSize.x - iconMarginRight) / 4 - iconMarginRight;
- local icons = {
- "files/textures/icons/menu/balance.png",
- "files/textures/icons/menu/calendar.png",
- "files/textures/icons/menu/camera.png",
- "files/textures/icons/menu/clock.png",
- "files/textures/icons/menu/compass.png",
- "files/textures/icons/menu/files.png",
- "files/textures/icons/menu/music.png",
- "files/textures/icons/menu/settings.png",
- };
- local i = 0;
- for y = screenPosition.y + screenSize.y * 0.1, screenPosition.y + screenSize.y * 0.22, screenSize.y * 0.12 do
- for x = screenPosition.x + iconMarginRight, screenPosition.x + screenSize.x, iconSize + iconMarginRight do
- dxDrawImage(x, y, iconSize, iconSize, icons[i + 1]);
- i = i + 1;
- if (i % 4 == 0) then break; end
- end
- end
- -- 266, 68
- local dockerPadding = screenSize.x * 0.045;
- local iconMarginRight = screenSize.x * 0.0766;
- local dockerMargin = dockerPadding;
- local iconSize = (screenSize.x - 1 * dockerPadding - 2 * dockerMargin) / 4 - iconMarginRight;
- dxDrawImage(screenPosition.x + dockerMargin, screenPosition.y + screenSize.y - dockerMargin - dockerPadding - iconSize - dockerPadding,
- screenSize.x - 2 * dockerMargin, iconSize + 2 * dockerPadding, "files/textures/docker_bg.png");
- local icons = {
- "files/textures/icons/menu/messages.png",
- "files/textures/icons/menu/contacts.png",
- "files/textures/icons/menu/ad.png",
- "files/textures/icons/menu/call.png",
- };
- local i = 1;
- for x = screenPosition.x + dockerMargin + dockerPadding, screenPosition.x + screenSize.x - dockerMargin - dockerPadding, iconSize + iconMarginRight do
- dxDrawImage(x, screenPosition.y + screenSize.y - dockerMargin - dockerPadding - iconSize, iconSize, iconSize, icons[i]);
- i = i + 1;
- end
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local iconMarginRight = screenSize.x * 0.06;
- local iconSize = (screenSize.x - iconMarginRight) / 4 - iconMarginRight;
- local i = 0;
- for y = screenPosition.y + screenSize.y * 0.1, screenPosition.y + screenSize.y * 0.22, screenSize.y * 0.12 do
- for x = screenPosition.x + iconMarginRight, screenPosition.x + screenSize.x, iconSize + iconMarginRight do
- if (isCursorOnRectangle(x, y, iconSize, iconSize)) then
- setCurrentPanel(({PANEL.BALANCE, PANEL.CALENDAR, PANEL.CAMERA, PANEL.CLOCK, PANEL.COMPASS, PANEL.FILES, PANEL.MUSIC, PANEL.SETTINGS})[i + 1]);
- return;
- end
- i = i + 1;
- if (i % 4 == 0) then break; end
- end
- end
- -- 266, 68
- local dockerPadding = screenSize.x * 0.045;
- local iconMarginRight = screenSize.x * 0.0766;
- local dockerMargin = dockerPadding;
- local iconSize = (screenSize.x - 1 * dockerPadding - 2 * dockerMargin) / 4 - iconMarginRight;
- local i = 1;
- for x = screenPosition.x + dockerMargin + dockerPadding, screenPosition.x + screenSize.x - dockerMargin - dockerPadding, iconSize + iconMarginRight do
- if (isCursorOnRectangle(x, screenPosition.y + screenSize.y - dockerMargin - dockerPadding - iconSize, iconSize, iconSize)) then
- setCurrentPanel(({PANEL.MESSAGES, PANEL.CONTACTS, PANEL.ADVERTISING, PANEL.CALL_KEYPAD})[i]);
- return;
- end
- i = i + 1;
- end
- end
- }
- panels[PANEL.BALANCE] = {
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Egyenlegem", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.23, screenSize.x, 2, 0x80464646);
- local fontHeight = dxGetFontHeight(1, fonts.roboto_medium[12]);
- dxDrawText("Szolgáltató: ", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32, screenPosition.x + screenSize.x - 15, 0, tocolor(128, 128, 128), 1, fonts.roboto_regular[14], "left", "top")
- dxDrawText("Telecom", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32, screenPosition.x + screenSize.x - 15, 0, tocolor(128, 128, 128), 1, fonts.roboto_light[14], "right", "top")
- dxDrawRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32 + fontHeight + 2, screenSize.x - 30, 1, tocolor(128, 128, 128), false, false);
- dxDrawText("Telefonszámom: ", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenPosition.x + screenSize.x - 15, 0, tocolor(128, 128, 128), 1, fonts.roboto_regular[14], "left", "top")
- dxDrawText(phoneData.number, screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenPosition.x + screenSize.x - 15, 0, tocolor(128, 128, 128), 1, fonts.roboto_light[14], "right", "top")
- dxDrawRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39 + fontHeight + 2, screenSize.x - 30, 1, tocolor(128, 128, 128), false, false);
- dxDrawText("Egyenlegem: ", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.46, screenPosition.x + screenSize.x - 15, 0, tocolor(128, 128, 128), 1, fonts.roboto_regular[14], "left", "top")
- dxDrawText(phoneData.balance, screenPosition.x + 15, screenPosition.y + screenSize.y * 0.46, screenPosition.x + screenSize.x - 15, 0, tocolor(128, 128, 128), 1, fonts.roboto_light[14], "right", "top")
- dxDrawRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.46 + fontHeight + 2, screenSize.x - 30, 1, tocolor(128, 128, 128), false, false);
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then
- setCurrentPanel(PANEL.MENU);
- end
- end,
- }
- panels[PANEL.CONTACT_ADD_OR_EDIT] = {
- init = function()
- local thisPanel = panels[PANEL.CONTACT_ADD_OR_EDIT];
- thisPanel.nameEditBox = GuiEdit(-1000, -1000, 0, 0, "", false);
- thisPanel.nameEditBox.maxLength = 16;
- thisPanel.numberEditBox = GuiEdit(-1000, -1000, 0, 0, "", false);
- thisPanel.numberEditBox.maxLength = 10;
- if (thisPanel.editedContact) then
- thisPanel.nameEditBox:setText(thisPanel.editedContact.name);
- thisPanel.numberEditBox:setText(thisPanel.editedContact.number);
- thisPanel.title = "Szerkesztés";
- else
- thisPanel.title = "Hozzáadás";
- end
- end,
- deinit = function()
- local thisPanel = panels[PANEL.CONTACT_ADD_OR_EDIT];
- thisPanel.nameEditBox:destroy();
- thisPanel.numberEditBox:destroy();
- end,
- render = function()
- local thisPanel = panels[PANEL.CONTACT_ADD_OR_EDIT];
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- if (thisPanel.editedContact) then
- dxDrawImage(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12, "files/textures/icons/accept.png");
- else
- dxDrawImage(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12, "files/textures/icons/add.png");
- end
- dxDrawText(thisPanel.title, screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.23, screenSize.x, 2, 0x80464646);
- local fontHeight = dxGetFontHeight(1, fonts.roboto_medium[12]);
- dxDrawText("Név: ", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32, screenPosition.x + screenSize.x - 15, 0, 0xFF464646, 1, fonts.roboto_medium[16], "left", "top")
- dxDrawText(thisPanel.nameEditBox:getText(), screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32, screenPosition.x + screenSize.x - 15, 0, 0xFF464646, 1, fonts.roboto_light[16], "right", "top")
- dxDrawRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32 + fontHeight + 2, screenSize.x - 30, 1, 0xFF464646, false, false);
- dxDrawText("Telefonszám: ", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenPosition.x + screenSize.x - 15, 0, 0xFF464646, 1, fonts.roboto_medium[16], "left", "top")
- dxDrawText(thisPanel.numberEditBox:getText(), screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenPosition.x + screenSize.x - 15, 0, 0xFF464646, 1, fonts.roboto_light[16], "right", "top")
- dxDrawRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39 + fontHeight + 2, screenSize.x - 30, 1, 0xFF464646, false, false);
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local thisPanel = panels[PANEL.CONTACT_ADD_OR_EDIT];
- local fontHeight = dxGetFontHeight(1, fonts.roboto_medium[14]);
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then
- goBackToPanelCameFrom();
- elseif (isCursorOnRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.32, screenSize.x - 30, fontHeight)) then -- focus name field
- thisPanel.nameEditBox:bringToFront();
- thisPanel.nameEditBox:setCaretIndex(#thisPanel.nameEditBox:getText());
- elseif (isCursorOnRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenSize.x - 30, fontHeight)) then -- focus number field
- thisPanel.numberEditBox:bringToFront();
- thisPanel.numberEditBox:setCaretIndex(#thisPanel.numberEditBox:getText());
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12)) then -- add / edit
- local name, number = thisPanel.nameEditBox:getText(), tonumber(thisPanel.numberEditBox:getText());
- if (#name == 0) then exports['cr_infobox']:addBox("error", "A név legalább 1 karakter hosszú kell, hogy legyen"); return; end
- if (not checkIfNumberIsValidAndAlertIfNot(tostring(number))) then return; end
- local sameContact = getContactFromNumber(number);
- if (sameContact and sameContact ~= thisPanel.editedContact) then
- exports['cr_infobox']:addBox("error", "Ez a telefonszám már szerepel a kacspolatok között");
- return;
- end
- local sameContact = getContactFromName(name);
- if (sameContact and sameContact ~= thisPanel.editedContact) then
- exports['cr_infobox']:addBox("error", "Ez a név már szerepel a kacspolatok között");
- return;
- end
- if (thisPanel.editedContact) then -- edit
- triggerServerEvent("onPlayerEditPhoneContact", localPlayer, thisPanel.editedContact.id, name, number);
- thisPanel.editedContact.name = name;
- thisPanel.editedContact.number = number;
- thisPanel.editedContact = nil;
- goBackToPanelCameFrom();
- else -- add
- triggerServerEvent("onPlayerAddPhoneContact", localPlayer, name, number);
- goBackToPanelCameFrom();
- end
- end
- end,
- }
- --[[ panels[PANEL.MUSIC] = {
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Rádió", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.23, screenSize.x, 2, 0x80464646);
- -- todo
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then
- setCurrentPanel(PANEL.MENU);
- end
- end
- } ]]
- panels[PANEL.ADVERTISING] = {
- init = function()
- panels[PANEL.ADVERTISING].editbox:setMaxLength(120);
- bindKey("enter", "down", panels[PANEL.ADVERTISING].sendAd);
- bindKey("num_enter", "down", panels[PANEL.ADVERTISING].sendAd);
- end,
- deinit = function()
- unbindKey("enter", "down", panels[PANEL.ADVERTISING].sendAd);
- unbindKey("num_enter", "down", panels[PANEL.ADVERTISING].sendAd);
- end,
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Hirdetés feladás", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.23, screenSize.x, 2, 0x80464646);
- local boxWidth = screenSize.x * 0.84;
- local boxContectWidth = screenSize.x * 0.675;
- local charWidth = dxGetTextWidth("0123456789", 1, fonts.roboto_light[14]) / 10;
- local lineCount = (charWidth * panels[PANEL.ADVERTISING].editbox.maxLength) / boxContectWidth;
- local boxHeight = lineCount * dxGetFontHeight(1, fonts.roboto_light[14]) + 20;
- dxDrawRectangle(screenPosition + Vector2(screenSize.x * 0.088 - 2, screenSize.y - 20 - boxHeight - 2), boxWidth + 4, boxHeight + 4, 0x80464646);
- dxDrawRectangle(screenPosition + Vector2(screenSize.x * 0.088, screenSize.y - 20 - boxHeight), boxWidth, boxHeight, 0xFFFFFFFF);
- dxDrawText(panels[PANEL.ADVERTISING].editbox:getText(), screenPosition + Vector2(screenSize.x * 0.088 + 2, screenSize.y - 18 - boxHeight), screenPosition + Vector2(screenSize.x * 0.088 + boxContectWidth, screenSize.y - 34), 0xFF464646, 1, fonts.roboto_light[14], "left", "top", true, true)
- dxDrawImage(screenPosition + Vector2(screenSize.x * 0.088 + boxWidth - 30, screenSize.y - 50), 25, 25, "files/textures/icons/send.png");
- -- check box
- dxDrawRectangle(screenPosition + Vector2(screenSize.x * 0.088 - 1, screenSize.y - 20 - boxHeight - 21), 12, 12, 0x80464646); --bg
- dxDrawRectangle(screenPosition + Vector2(screenSize.x * 0.088, screenSize.y - 20 - boxHeight - 20), 10, 10, panels[PANEL.ADVERTISING].hidePhoneNumber and 0x80464646 or 0xFFFFFFFF); --bg
- dxDrawText("Telefonszám elrejtése", screenPosition + Vector2(screenSize.x * 0.088 + 14, screenSize.y - 20 - boxHeight - 21), 0, 0, 0xFF464646, 1, fonts.roboto_light[14], "left", "top");
- end,
- sendAd = function()
- local thisPanel = panels[PANEL.ADVERTISING];
- local text = thisPanel.editbox:getText();
- if (#text < 10) then exports['cr_infobox']:addBox("error", "A hírdetés leírása legalább 10 karakter hosszú kell, hogy legyen"); return; end
- triggerServerEvent("onClientPlayerSendAdvertisement", localPlayer, thisPanel.editbox:getText(), thisPanel.hidePhoneNumber);
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local thisPanel = panels[PANEL.ADVERTISING];
- local boxWidth = screenSize.x * 0.84;
- local boxContectWidth = screenSize.x * 0.675;
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- back button
- goBackToPanelCameFrom();
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.088 + boxWidth - 30, screenPosition.y + screenSize.y - 50, 25, 25)) then -- send ad
- thisPanel.sendAd();
- else
- local charWidth = dxGetTextWidth("0123456789abcdefg", 1, fonts.roboto_light[14]) / #("0123456789abcdefg");
- local lineCount = (charWidth * thisPanel.editbox.maxLength) / boxContectWidth;
- local boxHeight = lineCount * dxGetFontHeight(1, fonts.roboto_light[14]) + 20;
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.088, screenPosition.y + screenSize.y - 20 - boxHeight - 21, 12, 12)) then -- hide phone number checkbox
- thisPanel.hidePhoneNumber = not thisPanel.hidePhoneNumber;
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.088, screenPosition.y + screenSize.y - 20 - boxHeight, boxWidth, boxHeight)) then -- focus to editbox
- thisPanel.editbox:bringToFront();
- thisPanel.editbox:setCaretIndex(#thisPanel.editbox:getText());
- end
- end
- end,
- hidePhoneNumber = false,
- editbox = GuiEdit(-1000, -1000, 0, 0, "", false)
- }
- panels[PANEL.CONTACTS] = {
- init = function()
- local this = panels[PANEL.CONTACTS];
- local height = screenSize.y * 0.65;
- this.drawableContactCount = math.floor(height / (screenSize.y * 0.08));
- this.contactHeight = height / this.drawableContactCount;
- bindKey("mouse_wheel_up", "down", this.scrollHandler);
- bindKey("mouse_wheel_down", "down", this.scrollHandler);
- end,
- deinit = function()
- local this = panels[PANEL.CONTACTS];
- unbindKey("mouse_wheel_up", "down", this.scrollHandler);
- unbindKey("mouse_wheel_down", "down", this.scrollHandler);
- end,
- scrollHandler = function(key)
- if (not isCursorOnRectangle(screenPosition.x, screenPosition.y, screenSize.x, screenSize.y)) then return; end
- local this = panels[PANEL.CONTACTS];
- if (key == "mouse_wheel_down" and (this.scrollIndex + 1 + this.drawableContactCount < #phoneData.contacts)) then
- this.scrollIndex = this.scrollIndex + 1;
- elseif (key == "mouse_wheel_up" and (this.scrollIndex - 1 >= 0)) then
- this.scrollIndex = this.scrollIndex - 1;
- end
- end,
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12, "files/textures/icons/add.png");
- dxDrawText("Kapcsolatok", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- drawContactTabBar();
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = panels[PANEL.CONTACTS].contactHeight
- for i = panels[PANEL.CONTACTS].scrollIndex, panels[PANEL.CONTACTS].scrollIndex + panels[PANEL.CONTACTS].drawableContactCount do
- local v = phoneData.contacts[i + 1];
- if (not v) then break; end
- local clipX = screenPosition.x + screenSize.x * 0.925;
- if (isCursorOnRectangle(screenPosition.x, y, screenSize.x, h)) then
- local actionSize = screenSize * Vector2(0.3, 0.026);
- dxDrawImage(screenPosition.x + screenSize.x * 0.936 - actionSize.x - actionSize.x / 4, y + h / 2 - actionSize.y / 2, screenSize.x * 0.042, actionSize.y, "files/textures/icons/contact_app/favorites.png", 0, 0, 0, v.favorite and 0xFFFFD700 or 0xFFFFFFFF);
- dxDrawImage(screenPosition.x + screenSize.x * 0.936 - actionSize.x, y + h / 2 - actionSize.y / 2, actionSize, "files/textures/icons/contact_app/actions.png");
- clipX = screenPosition.x + screenSize.x * 0.936 - actionSize.x - actionSize.x / 4 - 5;
- end
- dxDrawImage(screenPosition.x + screenSize.x * 0.062, y + 3, h - 6, h - 6, "files/textures/profile_pics/" .. v.profilePictureID .. ".png");
- dxDrawText(v.name, screenPosition.x + screenSize.x * 0.062 + h - 6 + 4, y + 3, clipX, y + h - 3, 0xFF000000, 1, fonts.roboto_light[16], "left", "top", true);
- dxDrawText(v.number, screenPosition.x + screenSize.x * 0.062 + h - 6 + 4, y + 3, clipX, y + h - 3, 0xFF000000, 1, fonts.roboto_light[14], "left", "bottom", true);
- if (i > 0) then dxDrawRectangle(screenPosition.x + screenSize.x * 0.062, y, screenSize.x * 0.889, 1, 0xFF464646); end -- sep line on the bottom
- y = y + h;
- end
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12)) then -- add
- setCurrentPanel(PANEL.CONTACT_ADD_OR_EDIT);
- else
- -- tab bar
- if (handleContactTabBarClick()) then return; end
- -- contact actions
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = panels[PANEL.CONTACTS].contactHeight;
- local actionSize = screenSize * Vector2(0.3, 0.026);
- for i = panels[PANEL.CONTACTS].scrollIndex, panels[PANEL.CONTACTS].scrollIndex + panels[PANEL.CONTACTS].drawableContactCount do
- local contact = phoneData.contacts[i + 1];
- if (not contact) then break; end
- for j = 0, 4 do
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.936 - (j + 1) * (actionSize.x / 4), y + h / 2 - actionSize.y / 2, actionSize.x, actionSize.y)) then
- if (j == 4) then
- contact.favorite = not contact.favorite;
- if (contact.favorite) then addFavoriteContact(contact.id); else removeFavoriteByContactID(contact.id); end
- elseif (j == 3) then -- call
- callNumber(contact.number);
- elseif (j == 1) then -- edit
- panels[PANEL.CONTACT_ADD_OR_EDIT].editedContact = contact;
- setCurrentPanel(PANEL.CONTACT_ADD_OR_EDIT);
- elseif (j == 2) then -- msg
- panels[PANEL.CONTACT_MESSENGER].displayedNumberOrName = contact.name;
- panels[PANEL.CONTACT_MESSENGER].phoneNumber = contact.number;
- setCurrentPanel(PANEL.CONTACT_MESSENGER);
- elseif (j == 0) then -- delete
- removeContactByID(contact.id);
- end
- return;
- end
- end
- y = y + h;
- end
- end
- end,
- scrollIndex = 0
- }
- panels[PANEL.CONTACT_FAVORITES] = {
- init = function()
- local this = panels[PANEL.CONTACT_FAVORITES];
- local height = screenSize.y * 0.65;
- this.drawableContactCount = math.floor(height / (screenSize.y * 0.08));
- this.contactHeight = height / this.drawableContactCount;
- bindKey("mouse_wheel_up", "down", this.scrollHandler);
- bindKey("mouse_wheel_down", "down", this.scrollHandler);
- end,
- deinit = function()
- unbindKey("mouse_wheel_up", "down", this.scrollHandler);
- unbindKey("mouse_wheel_down", "down", this.scrollHandler);
- end,
- scrollHandler = function(key)
- if (not isCursorOnRectangle(screenPosition.x, screenPosition.y, screenSize.x, screenSize.y)) then return; end
- local this = panels[PANEL.CONTACT_FAVORITES];
- if (key == "mouse_wheel_down" and (this.scrollIndex + 1 + this.drawableContactCount < #phoneData.favoriteContacts)) then
- this.scrollIndex = this.scrollIndex + 1;
- elseif (key == "mouse_wheel_up" and (this.scrollIndex - 1 >= 0)) then
- this.scrollIndex = this.scrollIndex - 1;
- end
- end,
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Kapcsolatok", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- drawContactTabBar();
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = panels[PANEL.CONTACT_FAVORITES].contactHeight
- for i = panels[PANEL.CONTACT_FAVORITES].scrollIndex, panels[PANEL.CONTACT_FAVORITES].scrollIndex + panels[PANEL.CONTACT_FAVORITES].drawableContactCount do
- local v = phoneData.favoriteContacts[i + 1];
- if (not v) then break; end
- local clipX = screenPosition.x + screenSize.x * 0.925;
- if (isCursorOnRectangle(screenPosition.x, y, screenSize.x, h)) then
- local actionSize = screenSize * Vector2(0.3, 0.026);
- dxDrawImage(screenPosition.x + screenSize.x * 0.936 - actionSize.x - actionSize.x / 4, y + h / 2 - actionSize.y / 2, screenSize.x * 0.042, actionSize.y, "files/textures/icons/contact_app/favorites.png", 0, 0, 0, 0xFFFFD700);
- dxDrawImage(screenPosition.x + screenSize.x * 0.936 - actionSize.x, y + h / 2 - actionSize.y / 2, actionSize, "files/textures/icons/contact_app/actions.png");
- clipX = screenPosition.x + screenSize.x * 0.936 - actionSize.x - actionSize.x / 4 - 5;
- end
- dxDrawImage(screenPosition.x + screenSize.x * 0.062, y + 3, h - 6, h - 6, "files/textures/profile_pics/" .. (v.profilePictureID or 0) .. ".png");
- dxDrawText(v.name, screenPosition.x + screenSize.x * 0.062 + h - 6 + 4, y + 3, clipX, y + h - 3, 0xFF000000, 1, fonts.roboto_light[16], "left", "top", true);
- dxDrawText(v.number, screenPosition.x + screenSize.x * 0.062 + h - 6 + 4, y + 3, clipX, y + h - 3, 0xFF000000, 1, fonts.roboto_light[14], "left", "bottom", true);
- if (i > 0) then dxDrawRectangle(screenPosition.x + screenSize.x * 0.062, y, screenSize.x * 0.889, 1, 0xFF464646); end -- sep line on the bottom
- y = y + h;
- end
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- else
- -- tab bar
- if (handleContactTabBarClick()) then return; end
- -- contact actions
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = panels[PANEL.CONTACT_FAVORITES].contactHeight
- for i = panels[PANEL.CONTACT_FAVORITES].scrollIndex, panels[PANEL.CONTACT_FAVORITES].scrollIndex + panels[PANEL.CONTACT_FAVORITES].drawableContactCount do
- local v = phoneData.favoriteContacts[i + 1];
- if (not v) then break; end
- local actionSize = screenSize * Vector2(0.3, 0.026);
- for j = 0, 4 do
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.936 - (j + 1) * (actionSize.x / 4), y + h / 2 - actionSize.y / 2, actionSize.x, actionSize.y)) then
- if (j == 4) then
- removeFavoriteByContactID(v.id);
- triggerServerEvent("onPlayerChangeContactFavoriteState", localPlayer, v.id, true);
- elseif (j == 3) then -- call
- callNumber(v.number);
- elseif (j == 1) then -- edit
- panels[PANEL.CONTACT_ADD_OR_EDIT].editedContact = v;
- setCurrentPanel(PANEL.CONTACT_ADD_OR_EDIT);
- elseif (j == 2) then -- msg
- panels[PANEL.CONTACT_MESSENGER].displayedNumberOrName = v.name;
- panels[PANEL.CONTACT_MESSENGER].phoneNumber = v.number;
- setCurrentPanel(PANEL.CONTACT_MESSENGER);
- elseif (j == 0) then -- delete
- removeContactByID(v.id);
- end
- return;
- end
- end
- y = y + h;
- end
- end
- end,
- scrollIndex = 0
- }
- panels[PANEL.CALL_HISTORY] = {
- init = function()
- local thisPanel = panels[PANEL.CALL_HISTORY];
- local height = screenSize.y * 0.65;
- thisPanel.drawableContactCount = math.floor(height / (screenSize.y * 0.085));
- thisPanel.contactHeight = height / thisPanel.drawableContactCount;
- bindKey("mouse_wheel_up", "down", thisPanel.scrollHandler);
- bindKey("mouse_wheel_down", "down", thisPanel.scrollHandler);
- refreshCallHistoryContactNames();
- refreshCallHisotryDates();
- thisPanel.dateRefreshTimer = setTimer(refreshCallHisotryDates, 60000, 0);
- end,
- deinit = function()
- local thisPanel = panels[PANEL.CALL_HISTORY];
- unbindKey("mouse_wheel_up", "down", thisPanel.scrollHandler);
- unbindKey("mouse_wheel_down", "down", thisPanel.scrollHandler);
- thisPanel.dateRefreshTimer:destroy();
- end,
- scrollHandler = function(key)
- if (not isCursorOnRectangle(screenPosition.x, screenPosition.y, screenSize.x, screenSize.y)) then return; end
- local this = panels[PANEL.CALL_HISTORY];
- if (key == "mouse_wheel_down" and (this.scrollIndex + 1 + this.drawableContactCount < #phoneData.callHistory)) then
- this.scrollIndex = this.scrollIndex + 1;
- elseif (key == "mouse_wheel_up" and (this.scrollIndex - 1 >= 0)) then
- this.scrollIndex = this.scrollIndex - 1;
- end
- end,
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Előzmények", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- drawContactTabBar();
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = panels[PANEL.CALL_HISTORY].contactHeight
- for i = panels[PANEL.CALL_HISTORY].scrollIndex, panels[PANEL.CALL_HISTORY].scrollIndex + panels[PANEL.CALL_HISTORY].drawableContactCount do
- local v = phoneData.callHistory[i + 1];
- if (not v) then break; end
- local clipX = screenPosition.x + screenSize.x * 0.925;
- if (isCursorOnRectangle(screenPosition.x, y, screenSize.x, h)) then
- local actionSize = screenSize * Vector2(0.15, 0.026);
- if (not v.contact) then
- dxDrawImage(screenPosition.x + screenSize.x * 0.936 - actionSize.x - actionSize.x / 2 - 2, y + h / 2 - actionSize.y / 2, screenSize.x * 0.042, actionSize.y, "files/textures/icons/add.png");
- end
- dxDrawImage(screenPosition.x + screenSize.x * 0.936 - actionSize.x, y + h / 2 - actionSize.y / 2, actionSize, "files/textures/icons/contact_app/history_actions.png");
- clipX = screenPosition.x + screenSize.x * 0.936 - actionSize.x - actionSize.x / 2 - 5;
- end
- -- number / name
- if (not v.number) then outputChatBox(inspect(v)); end
- dxDrawText(v.contact and v.contact.name or v.number, screenPosition.x + screenSize.x * 0.08, y + 3, clipX, y + h - 3, 0xFF000000, 1, fonts.roboto_regular[16], "left", "top", true);
- -- prof. pics
- --dxDrawImage(screenPosition.x + screenSize.x * 0.062, y + 3, h - 6, h - 6, "files/textures/profile_pics/" .. (v.contact and v.contact.profilePictureID or 0) .. ".png");
- -- call type
- --local iconSize = screenSize.x * 0.05;
- --dxDrawImage(screenPosition.x + screenSize.x * 0.062, y + h - 3 - iconSize, iconSize, iconSize, "files/textures/icons/history_app/call_type/" .. v.type .. ".png", 0, 0, 0, 0xFF000000);
- -- Call date
- dxDrawText(v.text, screenPosition.x + screenSize.x * 0.08, y + h - 3, clipX, y + h - 3, 0xFF646464, 1, fonts.roboto_light[14], "left", "bottom", false, false, false, true);
- if (i > 0) then dxDrawRectangle(screenPosition.x + screenSize.x * 0.062, y, screenSize.x * 0.889, 1, 0xFF464646); end -- sep line on the bottom
- y = y + h;
- end
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- else
- -- tab bar
- if (handleContactTabBarClick()) then return; end
- -- contact actions
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = panels[PANEL.CALL_HISTORY].contactHeight
- for i = panels[PANEL.CALL_HISTORY].scrollIndex, panels[PANEL.CALL_HISTORY].scrollIndex + panels[PANEL.CALL_HISTORY].drawableContactCount do
- local v = phoneData.callHistory[i + 1];
- if (not v) then break; end
- local actionSize = screenSize * Vector2(0.15, 0.026);
- for j = 0, 2 do
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.936 - (j + 1) * (actionSize.x / 2), y + h / 2 - actionSize.y / 2, actionSize.x, actionSize.y)) then
- if (j == 2) then -- add
- if (not v.contact) then
- setCurrentPanel(PANEL.CONTACT_ADD_OR_EDIT);
- panels[PANEL.CONTACT_ADD_OR_EDIT].numberEditBox:setText(v.number);
- end
- elseif (j == 1) then -- call
- callNumber(v.number);
- elseif (j == 0) then --
- panels[PANEL.CONTACT_MESSENGER].displayedNumberOrName = v.contact and v.contact.name or v.number;
- panels[PANEL.CONTACT_MESSENGER].phoneNumber = v.number;
- setCurrentPanel(PANEL.CONTACT_MESSENGER);
- end
- return;
- end
- end
- y = y + h;
- end
- end
- end,
- scrollIndex = 0
- }
- panels[PANEL.CALL_OUTGOING] = {
- init = function()
- end,--callInfo.state
- render = function()
- dxDrawImage(screenPosition, screenSize, "files/textures/call_bg.png");
- local text = callInfo.state == CALL_STATE.CALLING and CALL_STATE_TEXTS[CALL_STATE.CALLING][callInfo.callerNumber == phoneData.number and 1 or 2] or CALL_STATE_TEXTS[callInfo.state];
- dxDrawText(text, screenPosition.x, screenPosition.y + screenSize.y * 0.08, screenPosition.x + screenSize.x, 0, 0xFFFFFFFF, 1, fonts.roboto_light[14], "center", "top");
- dxDrawText(callInfo.displayedNumberOrName or "Ismeretlen", screenPosition.x, screenPosition.y + screenSize.y * 0.12, screenPosition.x + screenSize.x, 0, 0xFFFFFFFF, 1, fonts.roboto_light[18], "center", "top");
- local iconSize = screenSize.x * 0.167;
- dxDrawImage(screenPosition + Vector2(screenSize.x / 2 - iconSize / 2, screenSize.y * 0.75), iconSize, iconSize, "files/textures/icons/call_deny.png");
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local iconSize = screenSize.x * 0.167;
- if (isCursorOnRectangle(screenPosition.x + screenSize.x / 2 - iconSize / 2, screenPosition.y + screenSize.y * 0.75, iconSize, iconSize)) then -- cancel call
- triggerServerEvent("onPlayerCancelCall", localPlayer);
- end
- end
- }
- panels[PANEL.CALL_INCOMING] = {
- init = function()
- end,
- render = function()
- dxDrawImage(screenPosition, screenSize, "files/textures/call_bg.png");
- dxDrawText("Bejövő hívás", screenPosition.x, screenPosition.y + screenSize.y * 0.08, screenPosition.x + screenSize.x, 0, 0xFFFFFFFF, 1, fonts.roboto_light[12], "center", "top");
- dxDrawText(callInfo.displayedNumberOrName or "Ismeretlen", screenPosition.x, screenPosition.y + screenSize.y * 0.12, screenPosition.x + screenSize.x, 0, 0xFFFFFFFF, 1, fonts.roboto_light[14], "center", "top");
- local iconSize = screenSize.x * 0.167;
- dxDrawImage(screenPosition.x + iconSize, screenPosition.y + screenSize.y * 0.75, iconSize, iconSize, "files/textures/icons/call_deny.png");
- dxDrawImage(screenPosition.x + screenSize.x - 2 * iconSize, screenPosition.y + screenSize.y * 0.75, iconSize, iconSize, "files/textures/icons/call_accept.png");
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local iconSize = screenSize.x * 0.167;
- if (isCursorOnRectangle(screenPosition.x + iconSize, screenPosition.y + screenSize.y * 0.75, iconSize, iconSize)) then
- triggerServerEvent("onPlayerCancelCall", localPlayer);
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x - 2 * iconSize, screenPosition.y + screenSize.y * 0.75, iconSize, iconSize)) then
- triggerServerEvent("onPlayerAcceptCall", localPlayer);
- end
- end
- }
- panels[PANEL.CALL_CHAT] = {
- init = function()
- local thisPanel = panels[PANEL.CALL_CHAT];
- local guiBrowser = GuiBrowser(screenPosition + screenSize * Vector2(0.018, 0.162), screenSize * Vector2(1 - 2 * 0.018, 1 - 0.162 - 0.03), true, false, false);
- thisPanel.guiBrowser = guiBrowser;
- thisPanel.browserDocumentReady = false;
- thisPanel.messagesToAddCache = {};
- addEventHandler("onClientBrowserCreated", guiBrowser:getBrowser(),
- function()
- source:loadURL("http://mta/local/files/html/messenger/index.html");
- addEventHandler("onClientPlayerSendMessage", source, thisPanel.messageSendHandler);
- thisPanel.browserDocumentReady = true;
- addEventHandler("onClientBrowserDocumentReady", panels[currentPanelID].guiBrowser:getBrowser(),
- function()
- for _, v in pairs(thisPanel.messagesToAddCache) do
- thisPanel.guiBrowser:getBrowser():executeJavascript(("addMessage(%q, %q, 0)"):format(unpack(v)));
- end
- end
- );
- end
- );
- end,
- deinit = function()
- panels[PANEL.CALL_CHAT].guiBrowser:destroy();
- panels[PANEL.CALL_CHAT].browserDocumentReady = false;
- end,
- messageSendHandler = function(message)
- if (callInfo.state == CALL_STATE.TALKING) then
- panels[PANEL.CALL_CHAT].addMessage("me", message);
- triggerServerEvent("onPlayerSendCallChatMessage", localPlayer, message);
- end
- end,
- addMessage = function(type, message)
- local thisPanel = panels[PANEL.CALL_CHAT];
- if (thisPanel.browserDocumentReady) then
- panels[PANEL.CALL_CHAT].guiBrowser:getBrowser():executeJavascript(("addMessage(%q, %q, 0)"):format(type, message));
- else
- table.insert(thisPanel.messagesToAddCache, {type, message});
- end
- end,
- addMessages = function(messages)
- local thisPanel = panels[PANEL.CALL_CHAT];
- if (thisPanel.browserDocumentReady) then
- for _, msg in pairs(messages) do
- thisPanel.guiBrowser:getBrowser():executeJavascript(("addMessage(%q, %q, 0)"):format(msg.sentBy == phoneData.number and "me" or "other", msg.messages));
- end
- else
- for _, msg in pairs(messages) do
- table.insert(thisPanel.messagesToAddCache, {msg.sentBy == phoneData.number and "me" or "other", msg.message});
- end
- end
- end,
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- local iconSize = screenSize.x * 0.1;
- dxDrawImage(screenPosition.x + screenSize.x * (1 - 0.07) - iconSize, screenPosition.y + screenSize.y * 0.23 / 2 - iconSize / 2, iconSize, iconSize, "files/textures/icons/call_deny.png");
- dxDrawText(callInfo.displayedNumberOrName, screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- end,
- click = function(button, state)
- if (button ~= "left" or (not state)) then return; end
- local iconSize = screenSize.x * 0.1;
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * (1 - 0.07) - iconSize, screenPosition.y + screenSize.y * 0.23 / 2 - iconSize / 2, iconSize, iconSize)) then
- triggerServerEvent("onPlayerCancelCall", localPlayer);
- end
- end
- }
- --[[ panels[PANEL.MESSAGE_ADD] = {
- init = function()
- local thisPanel = panels[PANEL.MESSAGE_ADD];
- thisPanel.numberEditBox = GuiEdit(-1000, -1000, 0, 0, "", false);
- thisPanel.numberEditBox.maxLength = 10;
- end,
- deinit = function()
- local thisPanel = panels[PANEL.MESSAGE_ADD];
- thisPanel.nameEditBox:destroy();
- thisPanel.numberEditBox:destroy();
- end,
- render = function()
- local thisPanel = panels[PANEL.MESSAGE_ADD];
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12, "files/textures/icons/add.png");
- dxDrawText("Üzenet hozzáadása", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.23, screenSize.x, 2, 0x80464646);
- local fontHeight = dxGetFontHeight(1, fonts.roboto_medium[12]);
- dxDrawText("Telefonszám: ", screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenPosition.x + screenSize.x - 15, 0, 0xFF464646, 1, fonts.roboto_medium[16], "left", "top")
- dxDrawText(thisPanel.numberEditBox:getText(), screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenPosition.x + screenSize.x - 15, 0, 0xFF464646, 1, fonts.roboto_light[16], "right", "top")
- dxDrawRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39 + fontHeight + 2, screenSize.x - 30, 1, 0xFF464646, false, false);
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local thisPanel = panels[PANEL.MESSAGE_ADD];
- local fontHeight = dxGetFontHeight(1, fonts.roboto_medium[14]);
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then
- goBackToPanelCameFrom();
- elseif (isCursorOnRectangle(screenPosition.x + 15, screenPosition.y + screenSize.y * 0.39, screenSize.x - 30, fontHeight)) then -- focus number field
- thisPanel.numberEditBox:bringToFront();
- thisPanel.numberEditBox:setCaretIndex(#thisPanel.numberEditBox:getText());
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12)) then -- add
- local number = tonumber(thisPanel.numberEditBox:getText());
- if (not checkIfNumberIsValidAndAlertIfNot(tostring(number))) then return; end
- panels[PANEL.CONTACT_MESSENGER].phoneNumber = number;
- goBackToPanelCameFrom();
- end
- end,
- }
- ]]
- panels[PANEL.MESSAGES] = {
- init = function()
- local thisPanel = panels[PANEL.MESSAGES];
- local height = screenSize.y * 0.65;
- thisPanel.drawableContactCount = math.floor(height / (screenSize.y * 0.08));
- thisPanel.contactHeight = height / thisPanel.drawableContactCount;
- bindKey("mouse_wheel_up", "down", thisPanel.scrollHandler);
- bindKey("mouse_wheel_down", "down", thisPanel.scrollHandler);
- end,
- deinit = function()
- unbindKey("mouse_wheel_up", "down", this.scrollHandler);
- unbindKey("mouse_wheel_down", "down", this.scrollHandler);
- end,
- scrollHandler = function(key)
- if (not isCursorOnRectangle(screenPosition.x, screenPosition.y, screenSize.x, screenSize.y)) then return; end
- local this = panels[PANEL.MESSAGES];
- if (key == "mouse_wheel_down" and (this.scrollIndex + 1 + this.drawableContactCount < #phoneData.contacts)) then
- this.scrollIndex = this.scrollIndex + 1;
- elseif (key == "mouse_wheel_up" and (this.scrollIndex - 1 >= 0)) then
- this.scrollIndex = this.scrollIndex - 1;
- end
- end,
- render = function()
- local thisPanel = panels[PANEL.MESSAGES];
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12, "files/textures/icons/add.png");
- dxDrawText("Üzenetek", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = thisPanel.contactHeight
- for i = thisPanel.scrollIndex, thisPanel.scrollIndex + thisPanel.drawableContactCount do
- local v = phoneData.messages[i + 1];
- if (not v) then
- --thisPanel.scrollIndex = #phoneData.messages - thisPanel.drawableContactCount;
- break;
- end
- --outputChatBox(i)
- local clipX = screenPosition.x + screenSize.x * 0.925;
- if (not v.contact and isCursorOnRectangle(screenPosition.x, y, screenSize.x, h)) then
- local iconSize = screenSize.y * 0.026;
- clipX = screenPosition.x + screenSize.x * 0.9 - iconSize - 8;
- --dxDrawImage(clipX + 8, y + h / 2 - iconSize / 2, iconSize, iconSize, "files/textures/icons/message_actions.png");
- end
- dxDrawImage(screenPosition.x + screenSize.x * 0.062, y + 3, h - 6, h - 6, "files/textures/profile_pics/0.png");
- local lastMessage = v[#v];
- local contact = getContactFromNumber(v.number);
- dxDrawText((contact and contact.name or v.number) .. ((lastMessage and not lastMessage.read) and "[új üzenet]" or ""), screenPosition.x + screenSize.x * 0.062 + h - 6 + 4, y + 3, clipX, y + h - 3, 0xFF000000, 1, fonts.roboto_light[16], "left", "top", true);
- -- draw last message
- local text = lastMessage and lastMessage.isSender and ("Én: " .. lastMessage.text) or ((contact and (contact.name .. ":") or "") .. lastMessage.text);
- local color = lastMessage and lastMessage.read and 0xFF464646 or 0xFF000000;
- dxDrawText(text, screenPosition.x + screenSize.x * 0.062 + h - 6 + 4, y + 3, clipX, y + h - 3, color, 1, fonts.roboto_light[14], "left", "bottom", true);
- if (i > 0) then dxDrawRectangle(screenPosition.x + screenSize.x * 0.062, y, screenSize.x * 0.889, 1, 0xFF464646); end -- sep line on the bottom
- y = y + h;
- end
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local thisPanel = panels[PANEL.MESSAGES];
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88, screenPosition.y + screenSize.y * 0.23 / 2 - 12 / 2, 12, 12)) then -- add
- panels[PANEL.CONTACT_MESSENGER].phoneNumber = nil; -- so the user can enter one.
- setCurrentPanel(PANEL.CONTACT_MESSENGER);
- else
- -- contact actions
- local y = screenPosition.y + screenSize.y * 0.162;
- local h = thisPanel.contactHeight;
- local actionSize = screenSize * Vector2(0.3, 0.026);
- for i = thisPanel.scrollIndex, thisPanel.scrollIndex + thisPanel.drawableContactCount do
- local v = phoneData.messages[i + 1];
- if (not v) then break; end
- if (isCursorOnRectangle(screenPosition.x, y, screenSize.x, h)) then
- -- TODO icons click test thing here
- -- open chat with the clicked preson
- local contact = getContactFromNumber(v.number);
- panels[PANEL.CONTACT_MESSENGER].displayedNumberOrName = contact and contact.name or v.number;
- panels[PANEL.CONTACT_MESSENGER].phoneNumber = v.number;
- setCurrentPanel(PANEL.CONTACT_MESSENGER);
- break;
- end
- y = y + h;
- end
- end
- end,
- scrollIndex = 0
- }
- addEventHandler("onClientResourceStop", resourceRoot,
- function()
- if (currentPanelID == PANEL.CAMERA) then
- panels[currentPanelID].deinit();
- end
- end
- );
- local salt = "~>>ˇ~^˘°˛`_BlueMTA";
- panels[PANEL.CAMERA] = {
- init = function()
- local thisPanel = panels[PANEL.CAMERA];
- thisPanel.wasHudVisible = localPlayer:getData(salt .. "hudVisible" .. salt);
- localPlayer:setData(salt .. "hudVisible" .. salt, false);
- thisPanel.scrSource = DxScreenSource(scrSize);
- thisPanel.lookAtOffset = Vector3();
- exports['cr_animation']:applyAnimation(localPlayer, "SHOP", "ROB_Loop_Threat", -1, false, true, false);
- localPlayer:setData(salt .. "forceAnimation" .. salt, {"NEIRDFELUL", "NEIRDFELUL"});
- --localPlayer:setAnimation("SHOP", "ROB_Loop_Threat", -1, false, true, false);
- end,
- deinit = function()
- local thisPanel = panels[PANEL.CAMERA];
- setCameraTarget(localPlayer, localPlayer);
- localPlayer:setData(salt .. "forceAnimation" .. salt, {"", ""})
- --exports['cr_animation']:removeAnimation(localPlayer)
- localPlayer:setData(salt .. "hudVisible" .. salt, thisPanel.wasHudVisible);
- end,
- render = function()
- local thisPanel = panels[PANEL.CAMERA];
- thisPanel.scrSource:update();
- dxDrawImage(scrSize / 2 - Vector2(screenSize.y, screenSize.x) / 2, screenSize.y, screenSize.x, thisPanel.scrSource);
- dxDrawImage(scrSize / 2 - Vector2(screenSize.y, screenSize.x) / 2 + Vector2(screenSize.y * 0.038), screenSize.y * 0.978, screenSize.x, "files/textures/camerabg.png");
- setPedLookAt(localPlayer, localPlayer:getBonePosition(25));
- setCameraMatrix(localPlayer:getBonePosition(25) + Vector3(0, 0, 0.2), localPlayer:getBonePosition(6) + thisPanel.lookAtOffset);
- dxDrawText("Visszalépni a 'backspace' gomb segítségével tudsz.", 0, scrSize.y - 200, scrSize.x, scrSize.y, 0xFFFFFFFF, 1, fonts.roboto_light[26], "center", "top", false, false, false, true);
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- local thisPanel = panels[PANEL.CAMERA];
- -- 927, 720
- -- 795, 218
- -- 132, 502
- -- 0,47, 0.84
- local pos = scrSize / 2 - Vector2(size.y, size.x) / 2 + Vector2(screenSize.y * 0.84, screenSize.x * 0.47);
- if (isCursorOnRectangle(pos.x, pos.y, 64, 64)) then
- local pixelSZ = thisPanel.scrSource:getPixels();
- if (not pixelSZ) then exports.cr_infobox:addBox("error", "Nem sikerült lementeni a képet. Lehetséges, hogy nincs engedélyezve a képernyő feltöltés az MTAn belül."); return; end
- local d = getRealTime();
- local fname = ("%i.%.2i.%.2i - %.2i-%.2i-%.2i.png"):format(d.year + 1900, d.month + 1, d.monthday, d.hour, d.minute, d.second);
- local f = File.create("photos/" .. fname);
- if (not f) then exports.cr_infobox:addBox("error", "Nem sikerült lementeni a képet - A fájl létehozása sikertelen "); return; end
- f:write(dxConvertPixels(pixelSZ, "png"));
- f:close();
- exports.cr_infobox:addBox("info", "A kép le lett mentve. Az '<MTA elérési útvonal>/mods/deathmatch/cr_phone/photos/' mappában találod '" .. fname .. "' név alatt.");
- end
- end
- }
- addEvent("onClientPlayerSendMessage");
- addEvent("onMessageScrollBarOnTop");
- panels[PANEL.CONTACT_MESSENGER] = {
- init = function()
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- if (thisPanel.phoneNumber) then
- triggerServerEvent("onPlayerRequestPhoneMessages", localPlayer, thisPanel.phoneNumber);
- else
- thisPanel.numberEditBox = GuiEdit(-1000, -1000, 0, 0, "", false);
- thisPanel.numberEditBox:setMaxLength(10);
- end
- local guiBrowser = GuiBrowser(screenPosition + screenSize * Vector2(0.018, 0.162), screenSize * Vector2(1 - 2 * 0.018, 1 - 0.162 - 0.03), true, false, false);
- thisPanel.guiBrowser = guiBrowser;
- thisPanel.browserDocumentReady = false;
- thisPanel.messageToAddCache = {};
- addEventHandler("onClientBrowserCreated", guiBrowser:getBrowser(),
- function()
- source:loadURL("http://mta/local/files/html/messenger/index.html");
- addEventHandler("onClientPlayerSendMessage", source,
- function(message)
- if (not thisPanel.phoneNumber) then
- if not (checkIfNumberIsValidAndAlertIfNot(thisPanel.numberEditBox:getText())) then return; end
- thisPanel.phoneNumber = tonumber(thisPanel.numberEditBox:getText());
- thisPanel.numberEditBox:destroy();
- triggerServerEvent("onPlayerRequestPhoneMessages", localPlayer);
- end
- triggerServerEvent("onClientPlayerSendSMS", localPlayer, thisPanel.phoneNumber, message);
- end
- );
- addEventHandler("onClientBrowserDocumentReady", source,
- function()
- thisPanel.browserDocumentReady = true;
- outputConsole("messageToAddCache\n"..inspect(thisPanel.messageToAddCache));
- for _, v in pairs(thisPanel.messageToAddCache) do
- thisPanel.guiBrowser:getBrowser():executeJavascript(("addMessage(%q, %q, %i)"):format(unpack(v)));
- end
- end
- );
- end
- );
- end,
- deinit = function()
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- thisPanel.guiBrowser:destroy();
- if (isElement(thisPanel.numberEditBox)) then thisPanel.numberEditBox:destroy(); end
- end,
- addMessage = function(type, message, state)
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- if (thisPanel.browserDocumentReady) then
- thisPanel.guiBrowser:getBrowser():executeJavascript(("addMessage(%q, %q, %i)"):format(type, message, state or 0));
- else
- table.insert(thisPanel.messageToAddCache, {type, message, state or 0});
- end
- end,
- clear = function()
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- if (thisPanel.browserDocumentReady) then
- panels[PANEL.CONTACT_MESSENGER].guiBrowser:getBrowser():executeJavascript("document.getElementById(\"messages\").innerHTML = ''");
- end
- end,
- --[[ addMessagesToTop = function(messages)
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- thisPanel.requestedMessges = false;
- if (thisPanel.browserDocumentReady) then
- for k, v in pairs(messages) do
- thisPanel.guiBrowser:getBrowser():executeJavascript(("addMessageToTop(%q, %q, %i, 1)"):format(v.isSender and "me" or "other", v.text, v.state));
- end
- else
- addEventHandler("onClientBrowserDocumentReady", panels[currentPanelID].guiBrowser:getBrowser(),
- function()
- for k, v in pairs(messages) do
- thisPanel.guiBrowser:getBrowser():executeJavascript(("addMessageToTop(%q, %q, %i, 1)"):format(v.isSender and "me" or "other", v.text, v.state));
- end
- end
- );
- end
- end, ]]
- render = function()
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- local text = not thisPanel.phoneNumber and thisPanel.numberEditBox:getText();
- local number = thisPanel.phoneNumber or tonumber(text);
- local contact = number and getContactFromNumber(number);
- dxDrawText(contact and contact.name or number or (text and (#text > 0 and text or "Írj be egy számot")) , screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- end,
- click = function(button, state)
- if (button ~= "left" or (not state)) then return; end
- local thisPanel = panels[PANEL.CONTACT_MESSENGER];
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- elseif (not thisPanel.phoneNumber and isCursorOnRectangle(screenPosition.x, screenPosition.y, screenSize.x, screenSize.y * 0.16)) then -- focus edit field
- thisPanel.numberEditBox:bringToFront();
- thisPanel.numberEditBox:setCaretIndex(#thisPanel.numberEditBox:getText());
- end
- end,
- phoneNumber = 0 -- parnter number
- }
- panels[PANEL.CALL_KEYPAD] = {
- init = function()
- addEventHandler("onClientCharacter", root, panels[PANEL.CALL_KEYPAD].onClientCharacter);
- addEventHandler("onClientKey", root, panels[PANEL.CALL_KEYPAD].onClientKey);
- end,
- deinit = function()
- removeEventHandler("onClientCharacter", root, panels[PANEL.CALL_KEYPAD].onClientCharacter);
- removeEventHandler("onClientKey", root, panels[PANEL.CALL_KEYPAD].onClientKey);
- end,
- onClientCharacter = function(key)
- local thisPanel = panels[PANEL.CALL_KEYPAD];
- if (#thisPanel.enteredNumber > 12) then return; end
- -- letter -> number conversation
- local char = string.byte(string.upper(key)) - string.byte("A"); -- A's ASCII is 65, thus if A is pressed then its 0, if Z its 25, so we have 26 letters.
- if (char >= 0 and char <= 25) then
- local number = 0;
- if (char == 25) then -- 'Z' is on 9, not 10, as the code would calculate it.
- number = 9;
- elseif (char == 18) then -- 'S' is on 7, not 8
- number = 7;
- elseif (char == 21) then -- 'V' is on 8, not 9
- number = 8;
- elseif (char >= 22) then
- number = 9;
- else
- number = tostring(2 + math.floor(char / 3));
- end
- thisPanel.enteredNumber = thisPanel.enteredNumber .. number;
- elseif (tonumber(key) or key == "#" or key == "*" or key == "+") then
- thisPanel.enteredNumber = thisPanel.enteredNumber .. key;
- end
- end,
- onClientKey = function(key, state)
- if (not state) then return; end
- local thisPanel = panels[PANEL.CALL_KEYPAD];
- if (key == "backspace") then
- if (#thisPanel.enteredNumber == 0) then return; end
- thisPanel.enteredNumber = string.sub(thisPanel.enteredNumber, 0, #thisPanel.enteredNumber - 1);
- elseif (key == "enter") then
- local number = tonumber(thisPanel.enteredNumber);
- if (number) then
- callNumber(number);
- else
- --todo: infobox invalid number
- end
- end
- end,
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Gombok", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- dxDrawText(panels[PANEL.CALL_KEYPAD].enteredNumber, screenPosition + screenSize * Vector2(0, 0.160), screenPosition + screenSize * Vector2(1, 0.3), 0xFF000000, 1, fonts.roboto_medium[24], "center", "center", true, true);
- local keypadSize = screenSize * Vector2(1, 0.6);
- local keypadPosition = screenPosition + screenSize * Vector2(0, 0.3);
- dxDrawImage(keypadPosition, keypadSize, "files/textures/icons/contact_app/keypad_bg.png");
- end,
- click = function(button, state)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- return;
- end
- local keypadPosition = screenPosition + screenSize * Vector2(0.12, 0.3); -- 0.100, 0.199
- local keySize = screenSize * Vector2(0.206, 0.115);
- for x = 0, 2 do
- for y = 0, 4 do
- local keyPos = keypadPosition + screenSize * Vector2(x * 0.280, y * 0.125);
- if (isCursorOnRectangle(keyPos.x, keyPos.y, keySize.x, keySize.y)) then
- local thisPanel = panels[PANEL.CALL_KEYPAD];
- if (#thisPanel.enteredNumber > 12) then return; end
- if (y <= 2) then -- numbers
- thisPanel.enteredNumber = thisPanel.enteredNumber .. tostring(1 + y * 3 + x);
- elseif (y == 3) then -- *, 0, #
- if (x == 0) then -- *
- thisPanel.enteredNumber = thisPanel.enteredNumber .. "*";
- elseif (x == 1) then -- 0
- thisPanel.enteredNumber = thisPanel.enteredNumber .. "0";
- else
- thisPanel.enteredNumber = thisPanel.enteredNumber .. "#";
- end
- elseif (x == 1) then -- call(only here if y == 4, so no need to check that as well.)
- local number = tonumber(thisPanel.enteredNumber);
- if (not checkIfNumberIsValidAndAlertIfNot(tostring(number))) then return; end
- if (number) then
- callNumber(number);
- else
- exports['cr_infobox']:addBox("error", "Helytelen telefonszámot írtál be");
- end
- end
- break;
- end
- end
- end
- end,
- enteredNumber = ""
- }
- panels[PANEL.SETTINGS] = {
- render = function()
- dxDrawRectangle(screenPosition, screenSize, 0xFFFFFFFF);
- -- back button
- dxDrawImage(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15, "files/textures/icons/arrow_left.png");
- dxDrawText("Beállítások", screenPosition, screenPosition + Vector2(screenSize.x, screenSize.y * 0.23), 0xFF000000, 1, fonts.roboto_medium[18], "center", "center", true, true)
- -- sep. line
- dxDrawRectangle(screenPosition.x, screenPosition.y + screenSize.y * 0.16, screenSize.x, 1, 0x80464646);
- local h = screenSize.y * 0.084;
- local iconSize = h * 0.8;
- local marginSide = screenSize.x * 0.028;
- local y = screenPosition.y + screenSize.y * 0.16 + 0 * h;
- -- wallpaper change
- dxDrawImage(screenPosition.x + marginSide, y + h * 0.1, iconSize, iconSize, "files/textures/icons/wallpaper.png");
- dxDrawText("Háttérkép", screenPosition.x + marginSide + iconSize + 3, y, screenPosition.x + screenSize.x * 0.88, y + h, 0xFF000000, 1, fonts.roboto_medium[12], "left", "center");
- dxDrawText(phoneData.settings.wallpaper, screenPosition.x + marginSide + iconSize + 3, y, screenPosition.x + screenSize.x * 0.88, y + h, 0xFF464646, 1, fonts.roboto_light [12], "right", "center");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88 + 10, y + h / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_right.png");
- dxDrawRectangle(screenPosition.x + 2 * marginSide, y + h, screenSize.x - 4 * marginSide, 1, 0x80464646); -- sep
- y = y + h;
- -- ringtone
- dxDrawImage(screenPosition.x + marginSide, y + h * 0.1, iconSize, iconSize, "files/textures/icons/menu/call.png");
- dxDrawText("Csengőhang", screenPosition.x + marginSide + iconSize + 3, y, screenPosition.x + screenSize.x * 0.88, y + h, 0xFF000000, 1, fonts.roboto_medium[12], "left", "center");
- dxDrawText(phoneData.settings.ringtone, screenPosition.x + screenSize.x * 0.88 - 8 - 10, y + h / 2 - 13 / 2, screenPosition.x + screenSize.x * 0.88 + 10 + 8, y + h / 2 + 13 / 2, 0xFF464646, 1, fonts.roboto_light [12], "center", "center");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88 - 8 - 10, y + h / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_left.png");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88 + 10, y + h / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_right.png");
- dxDrawRectangle(screenPosition.x + 2 * marginSide, y + h, screenSize.x - 4 * marginSide, 1, 0x80464646); -- sep
- y = y + h;
- -- ringtone volume
- dxDrawImage(screenPosition.x + marginSide, y + h * 0.1, iconSize, iconSize, "files/textures/icons/menu/call.png");
- dxDrawText("Csengőhang hangerje", screenPosition.x + marginSide + iconSize + 3, y, screenPosition.x + screenSize.x * 0.88, y + h, 0xFF000000, 1, fonts.roboto_medium[12], "left", "center");
- local textW = dxGetTextWidth("Csengőhang hangerje", 1, fonts.roboto_medium[12]);
- local sliderW = screenSize.x - (marginSide + iconSize + 3 + textW + 8) - 2 * marginSide - 10;
- dxDrawRectangle(screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5, y + h / 2, sliderW, 2, 0xFF464646);
- local circleX = phoneData.settings.ringtoneVolume / 100 * sliderW;
- dxDrawCircle(screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5 + circleX, y + h / 2, 6, 0, 360, 0xFF464646, 0xFF464646, 256);
- if (isCursorOnRectangle(screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5, y, sliderW, h) and getKeyState("mouse1")) then
- phoneData.settings.ringtoneVolume = (1 - ((screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5 + sliderW) - cursorPosition.x) / sliderW) * 100;
- end
- dxDrawRectangle(screenPosition.x + 2 * marginSide, y + h, screenSize.x - 4 * marginSide, 1, 0x80464646); -- sep
- -- sms
- y = y + h;
- -- ringtone
- dxDrawImage(screenPosition.x + marginSide, y + h * 0.1, iconSize, iconSize, "files/textures/icons/menu/call.png");
- dxDrawText("SMS hang", screenPosition.x + marginSide + iconSize + 3, y, screenPosition.x + screenSize.x * 0.88, y + h, 0xFF000000, 1, fonts.roboto_medium[12], "left", "center");
- dxDrawText(phoneData.settings.smsSound, screenPosition.x + screenSize.x * 0.88 - 8 - 10, y + h / 2 - 13 / 2, screenPosition.x + screenSize.x * 0.88 + 10 + 8, y + h / 2 + 13 / 2, 0xFF464646, 1, fonts.roboto_light [12], "center", "center");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88 - 8 - 10, y + h / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_left.png");
- dxDrawImage(screenPosition.x + screenSize.x * 0.88 + 10, y + h / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_right.png");
- dxDrawRectangle(screenPosition.x + 2 * marginSide, y + h, screenSize.x - 4 * marginSide, 1, 0x80464646); -- sep
- y = y + h;
- -- ringtone volume
- dxDrawImage(screenPosition.x + marginSide, y + h * 0.1, iconSize, iconSize, "files/textures/icons/menu/call.png");
- dxDrawText("SMS hangerő", screenPosition.x + marginSide + iconSize + 3, y, screenPosition.x + screenSize.x * 0.88, y + h, 0xFF000000, 1, fonts.roboto_medium[12], "left", "center");
- local textW = dxGetTextWidth("SMS hangerő", 1, fonts.roboto_medium[12]);
- local sliderW = screenSize.x - (marginSide + iconSize + 3 + textW + 8) - 2 * marginSide - 10;
- dxDrawRectangle(screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5, y + h / 2, sliderW, 2, 0xFF464646);
- local circleX = phoneData.settings.smsSoundVolume / 100 * sliderW;
- dxDrawCircle(screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5 + circleX, y + h / 2, 6, 0, 360, 0xFF464646, 0xFF464646, 256);
- if (isCursorOnRectangle(screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5, y, sliderW, h) and getKeyState("mouse1")) then
- phoneData.settings.smsSoundVolume = (1 - ((screenPosition.x + marginSide + iconSize + 3 + textW + 8 + 5 + sliderW) - cursorPosition.x) / sliderW) * 100;
- phoneData.ringtoneVolumeUpdated = true;
- end
- dxDrawRectangle(screenPosition.x + 2 * marginSide, y + h, screenSize.x - 4 * marginSide, 1, 0x80464646); -- sep
- end,
- click = function(button, state, position)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.07, screenPosition.y + screenSize.y * 0.23 / 2 - 15 / 2, 9, 15)) then -- go back
- goBackToPanelCameFrom();
- else
- local h = screenSize.y * 0.084;
- local iconSize = h * 0.8;
- local marginSide = screenSize.x * 0.028;
- local y = screenPosition.y + screenSize.y * 0.16 + 0 * h;
- if (isCursorOnRectangle(screenPosition.x, y, screenSize.x, h)) then -- wallpaper change
- setCurrentPanel(PANEL.WALLPAPER_CHANGE);
- end
- y = y + h;
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88 - 8 - 10, y + h / 2 - 13 / 2, 8, 13)) then -- ringtone -
- if (setRingtone(phoneData.settings.ringtone - 1)) then playRingtoneSound(); end
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88 + 10, y + h / 2 - 13 / 2, 8, 13)) then -- ringtone +
- if (setRingtone(phoneData.settings.ringtone + 1)) then playRingtoneSound(); end
- end
- y = y + 2 * h;
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88 - 8 - 10, y + h / 2 - 13 / 2, 8, 13)) then -- sms sound -
- if (setSMSSound(phoneData.settings.smsSound - 1)) then playSMSSound(); end
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x * 0.88 + 10, y + h / 2 - 13 / 2, 8, 13)) then -- sms sound +
- if (setSMSSound(phoneData.settings.smsSound + 1)) then playSMSSound(); end
- end
- end
- end,
- scrollIndex = 0
- }
- panels[PANEL.WALLPAPER_CHANGE] = {
- render = function()
- dxDrawImage(screenPosition, screenSize, "files/textures/wallpapers/" .. phoneData.settings.wallpaper .. ".png");
- dxDrawImage(screenPosition.x + 5, screenPosition.y + screenSize.y / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_left.png");
- dxDrawImage(screenPosition.x + screenSize.x - 5 - 8, screenPosition.y + screenSize.y / 2 - 13 / 2, 8, 13, "files/textures/icons/settings/arrow_right.png");
- local x, y = screenPosition.x + screenSize.x * (0.5 - 0.25 / 2), screenPosition.y + screenSize.y * 0.87;
- dxDrawRectangle(x, y, screenSize.x * 0.25, screenSize.y * 0.08, 0xFF3d7abc);
- dxDrawText("Mentés", x, y, x + screenSize.x * 0.25, y + screenSize.y * 0.08, 0xFF000000, 1, fonts.roboto_light[12], "center", "center", true, true);
- end,
- click = function(button, state)
- if (button ~= "left" or (not state)) then return; end
- if (isCursorOnRectangle(screenPosition.x + screenSize.x * (0.5 - 0.25 / 2), screenPosition.y + screenSize.y * 0.87, screenSize.x * 0.25, screenSize.y * 0.08)) then -- go back and save
- goBackToPanelCameFrom();
- elseif (isCursorOnRectangle(screenPosition.x + 5, screenPosition.y + screenSize.y / 2 - 13 / 2, 8, 13)) then -- go to the left
- phoneData.settings.wallpaper = math.max(0, phoneData.settings.wallpaper - 1);
- elseif (isCursorOnRectangle(screenPosition.x + screenSize.x - 5 - 8, screenPosition.y + screenSize.y / 2 - 13 / 2, 8, 13)) then
- if (File.exists("files/textures/wallpapers/" .. (phoneData.settings.wallpaper + 1) .. ".png")) then
- phoneData.settings.wallpaper = phoneData.settings.wallpaper + 1;
- end
- end
- end
- }
- function math.clamp(val, min, max)
- return (val < min and min) or (val > max and max) or val;
- end
- -- utilty
- function callNumber(number)
- local contact = getContactFromNumber(number);
- callInfo = {
- calledNumber = number,
- callerNumber = phoneData.number,
- callerPlayer = localPlayer,
- displayedNumberOrName = contact and contact.name or number,
- state = CALL_STATE.CALLING
- }
- setCurrentPanel(PANEL.CALL_OUTGOING);
- triggerServerEvent("onPlayerPhoneCall", localPlayer, number);
- end
- function setSMSSound(val)
- local prev = phoneData.settings.smsSound;
- if (File.exists("files/sounds/sms/" .. val .. ".mp3")) then phoneData.settings.smsSound = val; end
- return prev ~= phoneData.settings.smsSound;
- end
- function setRingtone(val)
- local prev = phoneData.settings.ringtone;
- if (File.exists("files/sounds/ringtone/" .. val .. ".mp3")) then phoneData.settings.ringtone = val; end
- return prev ~= phoneData.settings.ringtone;
- end
- function playRingtoneSound(phoneNumber, endAfter, loop, soundID, volume)
- local phoneNumber = phoneNumber or phoneData.number;
- if (isElement(soundElementsByPhone[phoneNumber].ringtone)) then soundElementsByPhone[phoneNumber].ringtone:destroy(); end
- local soundID = soundID or phoneData.settings.ringtone;
- local volume = volume or phoneData.settings.ringtoneVolume;
- local filePath = "files/sounds/ringtone/" .. soundID .. ".mp3"
- if (not File.exists(filePath)) then filePath = "files/sounds/ringtone/0.mp3"; end
- soundElementsByPhone[phoneNumber].ringtone = Sound(filePath, loop);
- soundElementsByPhone[phoneNumber].ringtone:setVolume(volume / 100);
- if (endAfter) then
- setTimer(
- function(n)
- if (isElement(soundElementsByPhone[n].ringtone)) then
- soundElementsByPhone[n].ringtone:destroy()
- soundElementsByPhone[n] = nil;
- end
- end,
- endAfter * 1000, 1, phoneNumber);
- end
- end
- function playSMSSound(phoneNumber, soundID, volume)
- outputConsole("call: " .. debug.traceback())
- local phoneNumber = phoneNumber or phoneData.number;
- local soundID = soundID or phoneData and phoneData.settings.smsSound;
- local volume = volume or phoneData and phoneData.settings.smsSoundVolume;
- local filePath = "files/sounds/sms/" .. soundID .. ".mp3"
- if (not File.exists(filePath)) then filePath = "files/sounds/sms/0.mp3"; end
- soundElementsByPhone[phoneNumber].sms = Sound(filePath);
- soundElementsByPhone[phoneNumber].sms:setVolume(volume / 100);
- end
- function goBackToPanelCameFrom()
- local tbllen = #panelSetHistory;
- if (tbllen > 0) then
- setCurrentPanel(table.remove(panelSetHistory, tbllen), true);
- table.remove(panelSetHistory, tbllen); -- remove the newly inserted panel(the panel we came from) so we dont get a cycle
- end
- end
- -- some drawing shit
- function drawContactTabBar()
- local tabBarWidth = screenSize.x * 0.95;
- local iconSize = tabBarWidth / 4;
- local icons = {
- {"files/textures/icons/contact_app/favorites.png", "Kedvencek", 1, currentPanelID == PANEL.CONTACT_FAVORITES and 0xFF007aff or 0xFF464646},
- {"files/textures/icons/contact_app/contacts.png", "Kapcsolatok", 1.52, currentPanelID == PANEL.CONTACTS and 0xFF007aff or 0xFF464646},
- {"files/textures/icons/contact_app/recents.png", "Előzmény", 1, currentPanelID == PANEL.CALL_HISTORY and 0xFF007aff or 0xFF464646},
- {"files/textures/icons/contact_app/keypadicon.png", "Gombok", 1, currentPanelID == PANEL.CALL_KEYPAD and 0xFF007aff or 0xFF464646},
- }
- for i = 1, 4 do
- local x = screenPosition.x + screenSize.x / 2 - tabBarWidth / 2 + (i - 1) * iconSize;
- local size = screenSize.x * 0.085;
- dxDrawImage(x + iconSize / 2 - size * icons[i][3] / 2, screenPosition.y + screenSize.y * 0.9, size * icons[i][3], size, icons[i][1], 0, 0, 0, icons[i][4]);
- dxDrawText(icons[i][2], x + iconSize / 2, screenPosition.y + screenSize.y * 0.9 + size + 2, x + iconSize / 2, 0, icons[i][4], 1, fonts.roboto_light[10], "center", "top");
- end
- end
- function handleContactTabBarClick()
- local tabBarWidth = screenSize.x * 0.95;
- local iconSize = tabBarWidth / 4;
- for i = 0, 3 do
- if (isCursorOnRectangle(screenPosition.x + screenSize.x / 2 - tabBarWidth / 2 + i * iconSize, screenPosition.y + screenSize.y * 0.9, iconSize, iconSize)) then
- setCurrentPanel(PANEL[(i == 0 and "CONTACT_FAVORITES") or (i == 1 and "CONTACTS") or (i == 2 and "CALL_HISTORY") or (i == 3 and "CALL_KEYPAD")]);
- return true;
- end
- end
- return false;
- end
- -- favorite contact handling
- function removeFavoriteByContactID(contactID)
- for k, v in pairs(phoneData.favoriteContacts) do
- if (v.id == contactID) then
- -- reset scroll index so we dont go out of list
- if (panels[PANEL.CONTACT_FAVORITES].drawableContactCount) then
- panels[PANEL.CONTACT_FAVORITES].scrollIndex = math.min(panels[PANEL.CONTACT_FAVORITES].scrollIndex, #phoneData.favoriteContacts - 1 - panels[PANEL.CONTACT_FAVORITES].drawableContactCount);
- end
- v.favorite = false;
- triggerServerEvent("onPlayerChangeContactFavoriteState", localPlayer, v.id, false);
- table.remove(phoneData.favoriteContacts, k);
- sortFavoriteList();
- return;
- end
- end
- return nil;
- end
- function addFavoriteContact(contactID)
- local contact = getContactFromID(contactID);
- if (not contact) then return; end
- contact.favorite = true;
- table.insert(phoneData.favoriteContacts, contact);
- triggerServerEvent("onPlayerChangeContactFavoriteState", localPlayer, contactID, true);
- return true;
- end
- function sortFavoriteList(list)
- table.sort(phoneData.contacts,
- function(a, b)
- return string.upper(a.name) < string.upper(b.name);
- end
- );
- end
- -- contact handling
- addEvent("onClientPlayerAddPhoneContact", true);
- addEventHandler("onClientPlayerAddPhoneContact", localPlayer,
- function(contact)
- table.insert(phoneData.contacts, contact);
- sortContactList();
- refreshCallHistoryContactNames();
- end
- );
- function removeContactByID(id)
- local contact, k = getContactFromID(id);
- if (contact.favorite) then removeFavoriteByContactID(contact.id); end
- table.remove(phoneData.contacts, k);
- refreshCallHistoryContactNames();
- triggerServerEvent("onPlayerDeletePhoneContact", localPlayer, id);
- end
- function getContactFromID(id)
- for k, v in pairs(phoneData.contacts) do
- if (v.id == id) then
- return v, k;
- end
- end
- end
- function getContactFromNumber(number)
- local number = tonumber(number);
- for k, v in pairs(phoneData.contacts) do
- if (v.number == number) then
- return v, k;
- end
- end
- end
- function getContactFromName(name)
- for k, v in pairs(phoneData.contacts) do
- if (v.name == name) then
- return v, k;
- end
- end
- return nil;
- end
- function sortContactList(list)
- table.sort(phoneData.contacts,
- function(a, b)
- return string.upper(a.name) < string.upper(b.name);
- end
- );
- end
- -- call history
- function refreshCallHistoryContactNames()
- if (currentPanelID ~= PANEL.CALL_HISTORY) then return; end
- for k, v in pairs(phoneData.callHistory) do
- v.contact = getContactFromNumber(v.number);
- end
- end
- function refreshCallHisotryDates()
- if (currentPanelID ~= PANEL.CALL_HISTORY) then return; end
- local currentDate = getRealTime();
- for _, v in pairs(phoneData.callHistory) do
- local callDate, callDateStr = getRealTime(v.timestamp), "";
- if (callDate.year == currentDate.year) then -- same year
- if (callDate.yearday == currentDate.yearday) then -- same day
- if (callDate.hour == currentDate.hour) then -- same hour
- callDateStr = ((currentDate.minute - callDate.minute)) .. " perce";
- else
- callDateStr = ((currentDate.hour - callDate.hour)) .. " órája";
- end
- -- same week
- elseif (callDate.yearday - currentDate.yearday == 1) then -- yesterday
- callDateStr = ("Tegnap, %2i:%2i"):format(callDate.hour, callDate.minute);
- elseif (callDate.yearday - currentDate.yearday == 1) then -- two days ago
- callDateStr = ("Tegnapelőtt, %2i:%2i"):format(callDate.hour, callDate.minute);
- elseif (callDate.month == currentDate.month and (callDate.monthday - callDate.weekday) == (currentDate.monthday - currentDate.weekday)) then
- callDateStr = ("%s, %2i:%2i"):format(WEEKDAY_NAMES[callDate.weekday], callDate.hour, callDate.minute);
- else
- callDateStr = ("%s %i, %2i:%2i"):format(MONTH_NAMES[callDate.month], callDate.monthday, callDate.hour, callDate.minute);
- end
- else -- not same year
- callDateStr = ("%i. %s %i, %2i:%2i"):format(1900 + callDate.year, MONTH_NAMES[callDate.month], callDate.monthday, callDate.hour, callDate.minute);
- end
- v.text = HISOTRY_CALL_TYPE_TEXTS[v.type] .. " - " .. callDateStr;
- end
- end
- function getSMSArrayFromNumber(number)
- for k, v in pairs(phoneData.messages) do
- if (v.number == number) then
- return v, k;
- end
- end
- end
- function sortSMSArray()
- table.sort(phoneData.messages,
- function(a, b)
- return a[#a].timestamp > b[#b].timestamp;
- end
- );
- end
- addEvent("onClientPlayerUpdatePhoneBalance", true);
- addEventHandler("onClientPlayerUpdatePhoneBalance", localPlayer,
- function(balance)
- phoneData.balance = balance;
- end
- );
- addEvent("onClientPlayerUsePhoneItem", true);
- addEventHandler("onClientPlayerUsePhoneItem", localPlayer,
- function(state, data)
- setPhoneVisible(state, data);
- end
- );
- -- Call related
- addEvent("onClientPlayerCallIncoming", true);
- addEventHandler("onClientPlayerCallIncoming", localPlayer,
- function(callerNumber, calledNumber, ringtone, ringtoneVolume)
- -- if ringtone / ringtoneVolume vars are missing then the current phone's settings must be used.
- playRingtoneSound(calledNumber, nil, true, ringtone, ringtoneVolume);
- -- if no other phone is showing then just show the called phone.
- if (not isShowing) then
- exports.cr_inventory:findAndUseItemByIDAndValue(15, calledNumber);
- end
- if (calledNumber == phoneData.number) then
- local contact = getContactFromNumber(callerNumber);
- callInfo = {
- callerNumber = callerNumber,
- calledNumber = phoneData.number,
- displayedNumberOrName = contact and contact.name or callerNumber,
- state = CALL_STATE.CALL_INCOMING
- };
- setCurrentPanel(PANEL.CALL_INCOMING);
- end
- end
- );
- addEvent("onClientSetInCall", true); -- used to set player in call when he put away his phone while in call.
- addEventHandler("onClientSetInCall", localPlayer,
- function(callerNumber, calledNumber, messages)
- assert(type(messages) == "table")
- local contact = getContactFromNumber(callerNumber == phoneData.number and calledNumber or callerNumber);
- callInfo = {
- callerNumber = callerNumber,
- calledNumber = calledNumber,
- displayedNumberOrName = contact and contact.name or callerNumber,
- state = CALL_STATE.TALKING
- };
- setCurrentPanel(PANEL.CALL_CHAT);
- panels[currentPanelID].addMessages(messages);
- end
- );
- addEvent("onClientPlayerCancelCall", true)
- addEventHandler("onClientPlayerCancelCall", localPlayer,
- function(calledNumber, callerNumber, state, timestamp)
- setTimer(
- function()
- goBackToPanelCameFrom();
- callInfo = {};
- end,
- 2500, 1, PANEL.MENU);
- if (callerNumber == phoneData.number) then --
- addCallToHistory(calledNumber, HISTORY_CALL_TYPE.OUTGOING, timestamp);
- elseif (calledNumber == phoneData.number) then
- local histType = calledPhoneCallHistoryType or HISTORY_CALL_TYPE[callInfo.state == CALL_STATE.TALKING and "INCOMING" or "INCOMING_UNANSWERED"];
- addCallToHistory(callerNumber, histType, timestamp);
- end
- if (isElement(soundElementsByPhone[calledNumber].ringtone)) then soundElementsByPhone[calledNumber].ringtone:destroy(); end
- callInfo.state = state or CALL_STATE[(callInfo.state == CALL_STATE.TALKING or callInfo.state == CALL_STATE.INCOMING) and "CALL_ENDED" or "LINE_BUSY"];
- end
- );
- addEvent("onClientPlayerAcceptCall", true)
- addEventHandler("onClientPlayerAcceptCall", localPlayer,
- function()
- callInfo.state = CALL_STATE.TALKING;
- setCurrentPanel(PANEL.CALL_CHAT);
- if (isElement(soundElementsByPhone[phoneData.number].ringtone)) then soundElementsByPhone[phoneData.number].ringtone:destroy(); end
- end
- );
- addEvent("onClientPlayerReceiveCallChatMessage", true);
- addEventHandler("onClientPlayerReceiveCallChatMessage", localPlayer,
- function(msg)
- panels[PANEL.CALL_CHAT].addMessage("other", msg);
- end
- );
- addEvent("onPhoneAddCallToHistory", true);
- function addCallToHistory(number, historyType, timestamp)
- table.insert(phoneData.callHistory, 1, {
- number = number,
- timestamp = getRealTime().timestamp,
- type = historyType or HISTORY_CALL_TYPE.OUTGOING
- });
- end
- addEventHandler("onPhoneAddCallToHistory", localPlayer, addCallToHistory);
- -- SMS
- -- receives all messages with a speificed partner
- addEvent("onClientServerSendPhoneMessages", true);
- addEventHandler("onClientServerSendPhoneMessages", localPlayer,
- function(number, messages)
- outputConsole("got messages\n"..inspect(messages))
- local _, k = getSMSArrayFromNumber(number);
- if (not k) then table.insert(phoneData.messages, 1, {}); k = 1; end
- if (currentPanelID == PANEL.CONTACT_MESSENGER) then
- panels[currentPanelID].clear();
- for k, v in pairs(messages) do
- assert(type(v) == "table", "v not table @ "..k)
- panels[currentPanelID].addMessage(v.isSender and "me" or "other", v.text, v.state);
- end
- end
- phoneData.messages[k] = messages;
- phoneData.messages[k].number = number;
- end
- );
- -- only called if the current phone is the phone that got the SMS
- addEvent("onClientPlayerRecieveSMS", true);
- addEventHandler("onClientPlayerRecieveSMS", localPlayer,
- function(sentBy, sentTo, messageData, smsSoundID, volume)
- playSMSSound(sentToNumber, smsSoundID, volume);
- if (phoneData.number == sentTo) then
- local smss, k = getSMSArrayFromNumber(sentBy);
- if (not k) then table.insert(phoneData.messages, 1, {number = sentBy}); k = 1; end
- table.insert(smss, messageData);
- table.move(phoneData.messages, k, 1); -- move this SMS to the first place, because this is the latest one.
- if ((currentPanelID == PANEL.CONTACT_MESSENGER) and (panels[currentPanelID].phoneNumber == sentBy)) then
- panels[PANEL.CONTACT_MESSENGER].addMessage("other", messageData.text);
- end
- end
- end
- );
- addEvent("onServerConfirmSMSSend", true);
- addEventHandler("onServerConfirmSMSSend", localPlayer,
- function(sentBy, sentTo, messageData) --senderPhone.number, message, sendToPhoneNumber, SMS_STATE.FAILED_TO_SEND_INVALID_NUMBER
- if (phoneData.number == sentBy) then
- local smss, k = getSMSArrayFromNumber(sentTo);
- table.insert(smss, 1, messageData);
- table.move(phoneData.messages, k, 1); -- move this SMS to the first place, because this is the latest one.
- if ((currentPanelID == PANEL.CONTACT_MESSENGER) and (panels[currentPanelID].phoneNumber == sentTo)) then
- panels[PANEL.CONTACT_MESSENGER].addMessage("me", messageData.text);
- end
- end
- end
- );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement