Fix
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / bg_downloader.lua
blob161012d9e5c3de3007dc0112ee3498818be6bb99
1 ------------------------------------------------------------------------------------------------------------
2 -------------------
3 -- BG DOWNLOADER --
4 -------------------
7 bgdownloader =
9 ChangePriorityLock = false
12 ------------------------------------------------------------------------------------------------------------
13 function bgdownloader:getProgressGroup()
14 if isInGame() then
15 local grp = getUI("ui:interface:bg_downloader")
16 return grp
17 else
18 local grp = getUI("ui:outgame:charsel:bgd_progress")
19 return grp
20 end
21 end
23 ------------------------------------------------------------------------------------------------------------
24 function bgdownloader:getPrioCB()
25 return self:getProgressGroup():find("prio")
26 end
28 ------------------------------------------------------------------------------------------------------------
29 function bgdownloader:getProgressBar()
30 return self:getProgressGroup():find("progress")
31 end
33 ------------------------------------------------------------------------------------------------------------
34 function bgdownloader:setIcon(icon)
35 local bm = self:getProgressGroup():find("bm")
36 if icon == "" then
37 bm.active = false
38 else
39 bm.active = true
40 bm.texture = icon
41 end
42 end
44 local pausedText = i18n.get("uiBGD_Paused")
46 ------------------------------------------------------------------------------------------------------------
47 function bgdownloader:setProgressText(ucstr, color, progress, ellipsis)
48 local text = self:getProgressGroup():find("text")
49 local ellipsisTxt = self:getProgressGroup():find("ellipsis")
50 text.color = color
51 text.uc_hardtext = ucstr
52 if ellipsis then
53 ellipsisTxt.hardtext = ellipsis
54 else
55 ellipsisTxt.hardtext = ""
56 end
57 ellipsisTxt.color = color
58 if getBGDownloaderPriority() == 0 then -- paused ?
59 -- don't update progress when in pause (it may change because the pause actually wait
60 -- any current download to finish, otherwise connection may be lost)
61 self:setIcon("bgd_pause.tga")
62 ellipsisTxt.hardtext = ""
63 text.uc_hardtext = pausedText
64 else
65 self:setIcon("")
66 local progressCtrl = self:getProgressBar()
67 progressCtrl.range = 100
68 progressCtrl.value = progress * 100
69 progressCtrl.active = true
70 end
71 self:displayPriority()
72 end
75 local progress progressSymbol = { ".", "..", "..." }
78 ------------------------------------------------------------------------------------------------------------
79 -- set patching progression (from 0 to 1)
80 function bgdownloader:setPatchProgress(progress)
81 if not isInGame() then
82 self:getProgressGroup().active = true
83 end
85 self:getPrioCB().active = true
86 local progressPercentText = string.format("%d%%", 100 * progress)
87 local progressPostfix = math.fmod(os.time(), 3)
88 local progressDate = nltime.getLocalTime() / 500
89 local colValue = math.floor(230 + 24 * math.sin(progressDate))
90 local color = string.format("%d %d %d %d", colValue, colValue, colValue, 255)
91 self:setProgressText(concatUCString(i18n.get("uiBGD_Progress"), ucstring(progressPercentText)), color, progress, progressSymbol[progressPostfix + 1])
92 end
94 ------------------------------------------------------------------------------------------------------------
95 function bgdownloader:setPatchSuccess()
96 if not isInGame() then
97 self:getProgressGroup().active = true
98 end
99 self:setProgressText(i18n.get("uiBGD_PatchUpToDate"), "0 255 0 255", 1)
100 self:setIcon("W_answer_16_valid.tga")
101 --if isInGame() then
102 self:getPrioCB().active = false
103 --end
107 ------------------------------------------------------------------------------------------------------------
108 function bgdownloader:setPatchError()
109 if not isInGame() then
110 self:getProgressGroup().active = true
112 local errMsg = getPatchLastErrorMessage()
113 if errMsg == ucstring() then
114 self:setProgressText(i18n.get("uiBGD_PatchError"), "255 0 0 255", 0)
115 else
116 self:setProgressText(errMsg, "255 0 0 255", 0)
118 self:setIcon("W_answer_16_cancel.tga")
119 --if isInGame() then
120 self:getPrioCB().active = false
121 --end
124 ------------------------------------------------------------------------------------------------------------
125 function bgdownloader:setNoDownloader()
126 if isInGame() then
127 self:setProgressText(i18n.get("uiBGD_NotUsed"), "255 255 255 255", 0)
128 else
129 self:getProgressGroup().active = false
131 self:setIcon("")
132 --if isInGame() then
133 self:getPrioCB().active = false
134 --end
135 self:getProgressBar().active = false
138 ------------------------------------------------------------------------------------------------------------
139 function bgdownloader:setNoNecessaryPatch()
140 if isInGame() then
141 self:setProgressText(i18n.get("uiBGD_PatchUpToDate"), "255 255 255 255", 0)
143 else
144 self:getProgressGroup().active = false
146 self:setIcon("")
147 --if isInGame() then
148 self:getPrioCB().active = false
149 --end
150 self:getProgressBar().active = false
153 ------------------------------------------------------------------------------------------------------------
154 -- the priority was changed by the user
155 function bgdownloader:onChangePriority()
156 if not self.ChangePriorityLock then
157 requestBGDownloaderPriority(self:getPrioCB().selection)
158 self:displayPriority()
162 ------------------------------------------------------------------------------------------------------------
163 -- the priority has been changed externally, display it
164 function bgdownloader:displayPriority()
165 --if not isInGame() then return end
166 self.ChangePriorityLock = true
167 self:getPrioCB().selection = getBGDownloaderPriority()
168 self.ChangePriorityLock = false
169 self:getPrioCB().active = (getBGDownloaderPriority() ~= -1)
172 ------------------------------------------------------------------------------------------------------------
173 -- display a warning telling that the user need a fully patched client to go further
174 function bgdownloader:inGamePatchUncompleteWarning()
175 local pg = self:getProgressGroup()
176 pg.active = true
177 setTopWindow(pg)
178 pg:blink(2)
179 messageBoxWithHelp(i18n.get("uiBGD_InGamePatchIncomplete"), "ui:interface", tonumber(getDefine("case_normal")))
180 displaySystemInfo(i18n.get("uiBGD_InGamePatchIncompleteBC"), "BC")