-
-
Notifications
You must be signed in to change notification settings - Fork 172
admin2: Add GUI panel for mute #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
omar-o22
wants to merge
10
commits into
multitheftauto:master
Choose a base branch
from
omar-o22:feature/add-GUI-mute
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0f0151d
Add GUI panel for mute
omar-o22 c3037bf
Fix lint warning
omar-o22 cef7f3a
Merge branch 'master' into feature/add-GUI-mute
omar-o22 f219901
Fixes
omar-o22 31e34bb
update
omar-o22 6d1c1d2
I pushed the last commit by mistake
omar-o22 524d3a0
Merge remote-tracking branch 'origin/master' into feature/add-GUI-mute
omar-o22 06c2613
Fix lint warnings
omar-o22 2aae5dd
Update ACL.xml
omar-o22 b1f5478
Merge branch 'master' into feature/add-GUI-mute
omar-o22 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,194 @@ | ||
| --[[********************************** | ||
| * | ||
| * Multi Theft Auto - Admin Panel | ||
| * | ||
| * client\widgets\admin_mute.lua | ||
| * | ||
| * Original File by omar-o22 | ||
| * | ||
| **************************************]] | ||
| aMute = { | ||
| defaultDurations = { | ||
| {"1 minute", 60}, | ||
| {"1 hour", 60 * 60}, | ||
| {"1 day", 60 * 60 * 24}, | ||
| {"1 week", 60 * 60 * 24 * 7}, | ||
| {"Permanent", 0}, -- HARDCODED AS SECOND LAST IN THIS TABLE, DO NOT MOVE | ||
| {"Custom", 0} -- HARDCODED AS LAST LAST IN THIS TABLE, DO NOT MOVE | ||
| }, | ||
| } | ||
|
|
||
| function aMute.Show(player) | ||
| if (not aMuteForm) then | ||
omar-o22 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| aMute.Create() | ||
| end | ||
|
|
||
| if (player) then | ||
| aMute.playerName = getPlayerName(player) | ||
| guiSetText(aMute.Form, "Mute player "..aMute.playerName) | ||
| end | ||
|
|
||
| addEventHandler("onClientGUIClick", aMute.Form, aMute.onClick) | ||
| addEventHandler("onClientGUIFocus", aMute.Form, aMute.onFocus) | ||
| addEventHandler("onClientGUIBlur", aMute.Form, aMute.onBlur) | ||
| end | ||
|
|
||
| function aMute.Close(destroy) | ||
| if (destroy) then | ||
| destroyElement(aMute.Form) | ||
| aMute.Form = nil | ||
| else | ||
| removeEventHandler("onClientGUIClick", aMute.Form, aMute.onClick) | ||
| guiSetVisible(aMute.Form, false) | ||
| aMute.Reset() | ||
| end | ||
| aMute.playerName = nil | ||
| end | ||
|
|
||
| function aMute.Create() | ||
| local sx, sy = guiGetScreenSize() | ||
|
|
||
| aMute.Form = guiCreateWindow((sx - 350) / 2, (sy - 270) / 2, 350, 270, "Mute player", false) | ||
| aMute.ReasonLabel = guiCreateLabel(25, 40, 300, 20, "Mute reason (required):", false, aMute.Form) | ||
| aMute.ReasonEditBox = guiCreateEdit(25, 65, 300, 30, "Enter mute reason...", false, aMute.Form) | ||
| aMute.ReasonEditBoxRecievedInput = false | ||
| aMute.DurationLabel = guiCreateLabel(25, 110, 300, 20, "Mute duration (required):", false, aMute.Form) | ||
| aMute.DurationComboBox = guiCreateComboBox(25, 140, 300, 100, "Select mute duration...", false, aMute.Form) | ||
| for i=1, #aMute.defaultDurations do | ||
| guiComboBoxAddItem(aMute.DurationComboBox, aMute.defaultDurations[i][1]) | ||
| end | ||
| aMute.DurationEditBox = guiCreateEdit(25, 175, 300, 30, "Duration (seconds)...", false, aMute.Form) | ||
| aMute.DurationEditBoxRecievedInput = false | ||
| guiSetEnabled(aMute.DurationEditBox, false) | ||
|
|
||
| aMute.SubmitButton = guiCreateButton(70, 222, 100, 30, "Submit", false, aMute.Form) | ||
| aMute.CancelButton = guiCreateButton(180, 222, 100, 30, "Cancel", false, aMute.Form) | ||
| aRegister("mute", aMute.Form, aMute.Show, aMute.Close) | ||
| end | ||
|
|
||
| function aMute.Reset() | ||
| guiSetText(aMute.Form, "Mute player") | ||
| guiSetText(aMute.ReasonEditBox, "Enter mute reason...") | ||
| aMute.ReasonEditBoxRecievedInput = false | ||
| guiComboBoxSetSelected(aMute.DurationComboBox, -1) | ||
| guiSetText(aMute.DurationEditBox, "Duration (seconds)...") | ||
| guiSetEnabled(aMute.DurationEditBox, false) | ||
| aMute.DurationEditBoxRecievedInput = false | ||
| end | ||
|
|
||
| function aMute.onClick(button, state) | ||
| if not (button == "left" and state == "up") then | ||
| return | ||
| end | ||
|
|
||
| -- Handle cancel button first | ||
| if source == aMute.CancelButton then | ||
| aMute.Close() | ||
| return | ||
| end | ||
|
|
||
| -- Autofill and enable/disable duration editbox based on choice | ||
| if source == aMute.DurationComboBox then | ||
| local selected = guiComboBoxGetSelected(aMute.DurationComboBox) | ||
| if selected == -1 then | ||
| return | ||
| elseif selected == #aMute.defaultDurations - 2 then | ||
| -- Second-last option is permanent duration - clear and disable edit box | ||
| guiSetText(aMute.DurationEditBox, "0") | ||
| guiSetEnabled(aMute.DurationEditBox, false) | ||
| elseif selected == #aMute.defaultDurations - 1 then | ||
| -- Last option (should) be custom duration - enable duration edit box | ||
| guiSetText(aMute.DurationEditBox, "Duration (seconds)...") | ||
| guiSetEnabled(aMute.DurationEditBox, true) | ||
| aMute.DurationEditBoxRecievedInput = false | ||
| else | ||
| guiSetText(aMute.DurationEditBox, aMute.defaultDurations[selected + 1][2]) | ||
| guiSetEnabled(aMute.DurationEditBox, false) | ||
| end | ||
| return | ||
| end | ||
|
|
||
| -- Handle submit button | ||
| if source == aMute.SubmitButton then | ||
| aMute.verifyForm() | ||
| return | ||
| end | ||
| end | ||
|
|
||
| function aMute.onFocus() | ||
| -- Clear reason/duration edit boxes on first click | ||
| if source == aMute.ReasonEditBox then | ||
| if not aMute.ReasonEditBoxRecievedInput then | ||
| guiSetText(aMute.ReasonEditBox, "") | ||
| aMute.ReasonEditBoxRecievedInput = true | ||
| end | ||
| elseif source == aMute.DurationEditBox then | ||
| if not aMute.DurationEditBoxRecievedInput then | ||
| guiSetText(aMute.DurationEditBox, "") | ||
| aMute.DurationEditBoxRecievedInput = true | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function aMute.onBlur() | ||
| -- Reset default text of reason/duration edit boxes if they lose focus with no input | ||
| if source == aMute.ReasonEditBox then | ||
| if guiGetText(source) == "" then | ||
| guiSetText(aMute.ReasonEditBox, "Enter mute reason...") | ||
| aMute.ReasonEditBoxRecievedInput = false | ||
| end | ||
| elseif source == aMute.DurationEditBox then | ||
| if guiGetText(source) == "" and (guiComboBoxGetSelected(aMute.DurationComboBox) == #aMute.defaultDurations - 1) then | ||
| guiSetText(aMute.DurationEditBox, "Duration (seconds)...") | ||
| aMute.DurationEditBoxRecievedInput = false | ||
| end | ||
| end | ||
| end | ||
|
|
||
| function aMute.verifyForm() | ||
| -- Verify mute reason | ||
| local muteReason = guiGetText(aMute.ReasonEditBox) | ||
| if muteReason == "" or (not aMute.ReasonEditBoxRecievedInput) then | ||
| messageBox("No mute reason provided.", MB_ERROR, MB_OK) | ||
| return | ||
| end | ||
|
|
||
| -- Verify mute duration | ||
| local muteDuration | ||
| local durationSelection = guiComboBoxGetSelected(aMute.DurationComboBox) | ||
| if durationSelection == -1 then | ||
| messageBox("No mute duration provided.", MB_ERROR, MB_OK) | ||
| return | ||
| end | ||
| durationSelection = durationSelection + 1 -- ComboBox item indices starts at 0 instead of one | ||
| if durationSelection == #aMute.defaultDurations then | ||
| muteDuration = guiGetText(aMute.DurationEditBox) | ||
| muteDuration = tonumber(muteDuration) | ||
| if not muteDuration or muteDuration <= 0 then | ||
| messageBox("Invalid mute duration provided.", MB_ERROR, MB_OK) | ||
| return | ||
| end | ||
| else | ||
| muteDuration = aMute.defaultDurations[durationSelection][2] | ||
| end | ||
|
|
||
| -- Build mute request "packet" and send to server | ||
| local actualPlayer -- Actual player may be offline | ||
| if aMute.playerName then | ||
| actualPlayer = getPlayerFromName(aMute.playerName) | ||
| end | ||
| local data = { | ||
| playerName = aMute.playerName, | ||
| reason = muteReason, | ||
| duration = muteDuration | ||
| } | ||
|
|
||
| triggerServerEvent( | ||
| "aPlayer", | ||
| localPlayer, | ||
| actualPlayer, | ||
| "mute", | ||
| data | ||
| ) | ||
| aMute.Close() | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.