ESO Lua File v100010

ingame/alerttext/alerttext.lua

[◄ back to folders ]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
local g_alerts
local g_recentMessages
--add customization for message categories here
-- Previous colors: error = INTERFACE_GENERAL_COLOR_ERROR, alert = INTERFACE_GENERAL_COLOR_ALERT, colorType = INTERFACE_COLOR_TYPE_GENERAL
local AlertParams =
{
     [UI_ALERT_CATEGORY_ERROR] =
     {
          color = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_SELECTED)),
     },
     [UI_ALERT_CATEGORY_ALERT] =
     {
          color = ZO_ColorDef:New(GetInterfaceColor(INTERFACE_COLOR_TYPE_TEXT_COLORS, INTERFACE_TEXT_COLOR_SELECTED)),
     },
}
local function InternalPerformAlert(category, soundId, message)
     local color = AlertParams[UI_ALERT_CATEGORY_ALERT].color
     local params = AlertParams[category]
     if(params) then
          color = params.color or color
     end
          
     g_alerts:AddMessage("ZO_AlertLine", category, message, color, soundId)
end
function ZO_Alert(category, soundId, message, ...)
     if(not message) then return end
     message = zo_strformat(message, ...)
     if(message == "") then return end
     if(g_recentMessages:ShouldDisplayMessage(message)) then
          InternalPerformAlert(category, soundId, message)
    else
        ZO_SoundAlert(category, soundId)
    end
end
function ZO_AlertNoSuppression(category, soundId, message, ...)
     if(not message) then return end
     message = zo_strformat(message, ...)
     if(message == "") then return end
     InternalPerformAlert(category, soundId, message)
end
function ZO_SoundAlert(category, soundId)
     if(soundId and soundId ~= "" and g_recentMessages:ShouldDisplayMessage(soundId)) then
          PlaySound(soundId)
        g_recentMessages:AddRecent(soundId)
     end
end
local function OnAlertEvent(eventCode, ...)
     local alertHandlers = ZO_AlertText_GetHandlers()
     if alertHandlers[eventCode] then
          local category, message, soundId, noSuppression = alertHandlers[eventCode](...)
          if category then
               if message and message ~= "" then
                    if noSuppression then
                         ZO_AlertNoSuppression(category, soundId, message)
                    else
                         ZO_Alert(category, soundId, message)
                    end
               else
                    ZO_SoundAlert(category, soundId)
               end
          end
     end
end
function ZO_AlertEvent(eventId, ...)
     OnAlertEvent(eventId, ...)
end
local function OnScriptAccessViolation(eventCode, functionName)
     ZO_Dialogs_ShowDialog("SCRIPT_ACCESS_VIOLATION", nil, {mainTextParams = {functionName}})
end
     self:RegisterForEvent(EVENT_SCRIPT_ACCESS_VIOLATION, OnScriptAccessViolation)
     local alertHandlers = ZO_AlertText_GetHandlers()
     for event in pairs(alertHandlers) do
          self:RegisterForEvent(event, OnAlertEvent)
     end
     g_alerts = ZO_FadingControlBuffer:New(self, 3, "AlertFade", "AlertTranslate", TOPRIGHT)
     g_recentMessages = ZO_RecentMessages:New()
     local function SetupFunction(control, category, message, color, soundId)
          control:SetWidth(GuiRoot:GetRight() - ZO_Compass:GetRight() - 40)
          control:SetText(message)
          control:SetColor(color:UnpackRGBA())
        ZO_SoundAlert(category, soundId)
     end
     g_alerts:AddTemplate("ZO_AlertLine", SetupFunction)
end