Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.52 KB | None | 0 0
  1. rvreasons = {}
  2. rvreasons[1] = tr("1a) Invalid Name Format")
  3. rvreasons[2] = tr("1b) Unsuitable Name")
  4. rvreasons[3] = tr("1c) Name Inciting Rule Violatio")
  5. rvreasons[4] = tr("1d) Offensive Statement")
  6. rvreasons[5] = tr("2a) Spamming")
  7. rvreasons[6] = tr("2b) Illegal Advertising")
  8. rvreasons[7] = tr("2c) Off-Topic Public Statement")
  9. rvreasons[8] = tr("2d) Non-English Public Statement")
  10. rvreasons[9] = tr("2e) Inciting Rule Violation")
  11. rvreasons[10] = tr("2f) Bug Abuse")
  12. rvreasons[11] = tr("3a) Game Weakness Abuse")
  13. rvreasons[12] = tr("3b) Using Unofficial Software to Play")
  14. rvreasons[13] = tr("3c) Hacking")
  15. rvreasons[14] = tr("3d) Multi-Clienting")
  16. rvreasons[15] = tr("3e) Account Trading or Sharing")
  17. rvreasons[16] = tr("3f) Threatening Gamemaster")
  18. rvreasons[17] = tr("4a) Pretending to Have Influence on Rule Enforcement")
  19. rvreasons[18] = tr("4b) False Report to Gamemaster")
  20. rvreasons[19] = tr("4c) Destructive Behaviour")
  21. rvreasons[20] = tr("Excessive Unjustified Player Killing")
  22.  
  23. rvactions = {}
  24. rvactions[0] = tr("Notation")
  25. rvactions[1] = tr("Name Report")
  26. rvactions[2] = tr("Banishment")
  27. rvactions[3] = tr("Name Report + Banishment")
  28. rvactions[4] = tr("Banishment + Final Warning")
  29. rvactions[5] = tr("Name Report + Banishment + Final Warning")
  30. rvactions[6] = tr("Statement Report")
  31. rvactions[7] = tr("Deletion")
  32.  
  33. ruleViolationWindow = nil
  34. reasonsTextList = nil
  35. actionsTextList = nil
  36.  
  37. function init()
  38.   connect(g_game, { onGMActions = loadReasons })
  39.  
  40.   ruleViolationWindow = g_ui.displayUI('ruleviolation')
  41.   ruleViolationWindow:setVisible(false)
  42.  
  43.   reasonsTextList = ruleViolationWindow:getChildById('reasonList')
  44.   actionsTextList = ruleViolationWindow:getChildById('actionList')
  45.  
  46.   g_keyboard.bindKeyDown('Ctrl+Y', show)
  47.  
  48.   if g_game.isOnline() then
  49.     loadReasons()
  50.   end
  51. end
  52.  
  53. function terminate()
  54.   disconnect(g_game, { onGMActions = loadReasons })
  55.   g_keyboard.unbindKeyDown('Ctrl+Y')
  56.  
  57.   ruleViolationWindow:destroy()
  58. end
  59.  
  60. function hasWindowAccess()
  61.   return reasonsTextList:getChildCount() > 0
  62. end
  63.  
  64. function loadReasons()
  65.   reasonsTextList:destroyChildren()
  66.  
  67.   local actions = g_game.getGMActions()
  68.   for reason, actionFlags in pairs(actions) do
  69.     local label = g_ui.createWidget('RVListLabel', reasonsTextList)
  70.     label.onFocusChange = onSelectReason
  71.     label:setText(rvreasons[reason])
  72.     label.reasonId = reason
  73.     label.actionFlags = actionFlags
  74.   end
  75.  
  76.   if not hasWindowAccess() and ruleViolationWindow:isVisible() then hide() end
  77. end
  78.  
  79. function show(target, statement)
  80.   if g_game.isOnline() and hasWindowAccess() then
  81.     if target then
  82.       ruleViolationWindow:getChildById('nameText'):setText(target)
  83.     end
  84.  
  85.     if statement then
  86.       ruleViolationWindow:getChildById('statementText'):setText(statement)
  87.     end
  88.  
  89.     ruleViolationWindow:show()
  90.     ruleViolationWindow:raise()
  91.   end
  92. end
  93.  
  94. function hide()
  95.   ruleViolationWindow:hide()
  96.   clearForm()
  97. end
  98.  
  99. function onSelectReason(reasonLabel, focused)
  100.   if reasonLabel.actionFlags and focused then
  101.     actionsTextList:destroyChildren()
  102.     for actionBaseFlag = 0, #rvactions do
  103.       actionFlagString = rvactions[actionBaseFlag]
  104.       if bit32.band(reasonLabel.actionFlags, math.pow(2, actionBaseFlag)) > 0 then
  105.         local label = g_ui.createWidget('RVListLabel', actionsTextList)
  106.         label:setText(actionFlagString)
  107.         label.actionId = actionBaseFlag
  108.       end
  109.     end
  110.   end
  111. end
  112.  
  113. function report()
  114.   local target = ruleViolationWindow:getChildById('nameText'):getText()
  115.   local reason = reasonsTextList:getFocusedChild().reasonId
  116.   local action = actionsTextList:getFocusedChild().actionId
  117.   local comment = ruleViolationWindow:getChildById('commentText'):getText()
  118.   local statement = ruleViolationWindow:getChildById('statementText'):getText()
  119.   local statementId = 0 -- TODO: message unique id ?
  120.   local ipBanishment = ruleViolationWindow:getChildById('ipBanCheckBox'):isChecked()
  121.   if action == 6 and statement == "" then
  122.     displayErrorBox(tr("Error"), tr("No statement has been selected."))
  123.   elseif comment == "" then
  124.     displayErrorBox(tr("Error"), tr("You must enter a comment."))
  125.   else
  126.     g_game.reportRuleViolation(target, reason, action, comment, statement, statementId, ipBanishment)
  127.     hide()
  128.   end
  129. end
  130.  
  131. function clearForm()
  132.   ruleViolationWindow:getChildById('nameText'):clearText()
  133.   ruleViolationWindow:getChildById('commentText'):clearText()
  134.   ruleViolationWindow:getChildById('statementText'):clearText()
  135.   ruleViolationWindow:getChildById('ipBanCheckBox'):setChecked(false)
  136. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement