Add infos into target window
[ryzomcore.git] / ryzom / client / data / gamedev / interfaces_v3 / ark_lessons.lua
bloba222e416f0983e75def09479c9c4f7adc6cfd559
1 if game == nil then
2 game= {}
3 end
5 if ArkLessons == nil then
6 ArkLessons = {}
8 ArkLessons.Callbacks = {}
9 ArkLessons.Callbacks["accept"] = {}
10 ArkLessons.Callbacks["reward"] = {}
11 ArkLessons.Callbacks["step"] = {}
12 end
14 if ArkLessons.CurrentStep == nil then ArkLessons.CurrentStep = {} end
15 if ArkLessons.UsedWindow == nil then ArkLessons.UsedWindow = {} end
16 if ArkLessons.RevealStep == nil then ArkLessons.RevealStep = {} end
17 if ArkLessons.OnDraw == nil then ArkLessons.OnDraw = {} end
19 if ArkLessons.RevealMoves == nil then
20 ArkLessons.RevealMoves = {}
21 ArkLessons.RevealTooltips = {}
22 end
24 function ArkLessons:Callback(event, id, args)
26 if ArkLessons.Callbacks and ArkLessons.Callbacks[event] and ArkLessons.Callbacks[event][id] then
27 ArkLessons.Callbacks[event][id](args)
28 end
29 end
31 game.ArkLessonUsedWindowUrl = "https://app.ryzom.com/app_arcc/index.php?action=mLesson_Run&script="
33 webig.urls_to_check = {}
36 function ArkOpenLesson(id, require_rpitem)
37 debug(require_rpitem)
38 if id ~= 0 and id ~= nil then
39 local win = getUI("ui:interface:web_transaction_lessons")
40 if win then
41 win:find("html"):browse(game.ArkLessonUsedWindowUrl..id)
42 else
43 getUI("ui:interface:web_transactions"):find("html"):browse(game.ArkLessonUsedWindowUrl..id)
44 end
45 end
46 end
48 function ArkRevealLesson(id, i, total)
49 if i == game.ArkLessonRevealStep[id] then
50 game.ArkLessonRevealStep[id] = game.ArkLessonRevealStep[id] + 1
51 game:ArkLessonCallback("step", id, i)
52 game:ArkRevealLessonInfos(id, i, total)
53 if i == total then
54 game:ArkAcceptLesson()
55 end
56 end
57 end
59 function game:ArkRevealLessonInfos(id, i, total)
60 local ui = getUI("ui:interface:ArkLessonWin"..tostring(id))
61 if ui ~= nil then
62 local html = ui:find("html")
63 html:showDiv("enabled_"..tostring(i), false)
64 html:showDiv("disabled_"..tostring(i), false)
65 html:showDiv("current_"..tostring(i), true)
66 if i > 1 then
67 if i ~= total+1 then
68 html:showDiv("current_"..tostring(i-1), false)
69 html:showDiv("enabled_"..tostring(i-1), true)
70 end
71 end
72 if game.ArkLessonRevealCaps and game.ArkLessonRevealCaps[id] then
73 if total > i then
74 setCap(game.ArkLessonRevealCaps[id], "p", math.floor((100*i)/total), tostring(i).." / "..tostring(total))
75 else
76 setCap(game.ArkLessonRevealCaps[id], "p", 100, "")
77 end
78 end
79 end
80 end
83 function ArkLessonUpdateHtml(win, scriptid, title, progression, started, finished, requirement, reward)
84 win = getUI(win)
85 win = win:find("div_lesson_"..scriptid..":html")
86 local top = ""
87 if requirement ~= [[]] then
88 requirement = [[<tr><td height="20px" style="font-size: 11px; color: pink">]]..ArkLessons.NeedRequirement..[[</td>]]
89 else
90 requirement = ""
91 top = [[<tr><td height="5px"></td></tr>]]
92 end
94 local progressionHtml = "<td><table><tr><td><table style=\'background-color: black;\'><tr><td></td></tr></table></td></tr></table></td>"
95 local height = "50"
96 if progression then
97 if requirement ~= "" then
98 height = "12"
99 else
100 height = "25"
102 pogressionHtml = "<tr><td height=\'12px\' align=\'left\' >"..progression.."</td></tr>"
105 local color = "AAA"
106 if started then
107 if finished then
108 color = "FFFFFF"
109 else
110 color = "FFDD4AFF"
114 win:renderHtml([[
115 <td height="60px">
116 <table cellspacing="0" cellpadding="0">
117 <tr>
118 <td width="2px"></td>
119 <td width="407px" align="left" valign="top">
120 <table width="407px" cellspacing="0" cellpadding="0">
121 ]]..top..[[
122 <tr>
123 <td height="]]..height..[[px" valign="top"><strong style="color: #]]..color..[[">]]..title..[[</strong></td>
124 </tr>
125 ]]..requirement..pogressionHtml..[[
126 </table>
127 </td>
128 <td width="6px"></td>
129 <td align="left" valign="top" height="80px" width="46px">]]..reward..[[</td>
130 </tr>
131 </table>
132 </td>
136 function ArkLessons:Show(id, w, h, content, scriptid)
137 local ui = getUI("ui:interface:"..id)
138 -- deleteUI(framewin)
139 -- local framewin = getUI("ui:interface:"..id)
140 local center = false
141 if ui == nil then
142 createRootGroupInstance("webig_browser_no_header", id, {h=h, w=1024, global_color="false", bg_color="0 0 0 255", movable="0"})
143 WebBrowser:addWindow(id, "", getUI("ui:interface:"..id))
144 ui = getUI("ui:interface:"..id)
145 center = true
148 ui.opened = true
149 ui.openable = false
150 ui.active = true
151 ui.w = w
152 ui.h = h
153 ui.pop_min_w = w
154 ui.pop_max_w = w
155 ui.pop_min_h = h
156 ui.pop_max_h = h
158 local html = ui:find("html")
159 html:renderHtml(content)
161 if center then
162 ui.x = math.floor((getUI("ui:interface").w - ui.w) / 2)
163 ui.y = math.floor((getUI("ui:interface").h + ui.h) / 2)
166 setOnDraw(ui, "ArkLessons:onDraw("..tostring(scriptid)..")")
169 function ArkLessons:Minimize(id, h, w)
170 local ui = getUI("ui:interface:ArkLessonWin"..tostring(id))
171 if ui then
172 ui.w = w
173 ui.h = h
174 ui.pop_min_w = w
175 ui.pop_max_w = w
176 ui.pop_min_h = h
177 ui.pop_max_h = h
178 webig:displayWait("ui:interface:ArkLessonWin"..tostring(id))
180 webig:checkUrl(ArkLessons.NextStepUrl[id]["mini"])
184 function ArkLessons:MiniShowSteps(id, i)
185 getUI("ui:interface:web_transactions_lessons"):find("html"):browse(ArkLessons.NextStepUrl[id]["url"].."&mini_step="..tostring(i))
189 function ArkRevealLesson(id, i, total)
190 if i == ArkLessons.CurrentStep[id] then
191 ArkLessons.RevealStep[id] = ArkLessons.RevealStep[id] + 1
192 ArkLessons:Callback("step", id, i)
193 ArkLessons:ArkRevealLessonInfos(id, i, total)
194 WebQueue:push(ArkLessons.NextStepUrl[id][i])
198 function ArkLessons:ArkRevealLessonInfos(scriptid, i, total)
200 local ui = getUI("ui:interface:ArkLessonWin"..tostring(scriptid))
201 if ui ~= nil then
202 local html = ui:find("html")
204 html:showDiv("disabled_"..tostring(i), false)
205 html:showDiv("current2_"..tostring(i), false)
206 html:showDiv("enabled_"..tostring(i), false)
207 html:showDiv("current_"..tostring(i), true)
209 if ArkLessons.OnDraw[scriptid] == nil then ArkLessons.OnDraw[scriptid] = {} end
210 if ArkLessons.OnDraw[scriptid][i] == nil or ArkLessons.OnDraw[scriptid][i][4] == nil or ArkLessons.OnDraw[scriptid][i][4] < 1 then
211 ArkLessons.OnDraw[scriptid][i] = {"blink", nltime.getLocalTime(), 1, 4}
213 if i > 1 and i ~= total+1 then
214 html:showDiv("current_"..tostring(i-1), false)
215 html:showDiv("enabled_"..tostring(i-1), true)
216 ArkLessons.OnDraw[scriptid][i-1] = nil
219 if ArkLessons.RevealCaps and ArkLessons.RevealCaps[scriptid] then
220 if total > i then
221 setCap(ArkLessons.RevealCaps[scriptid], "p", math.floor((100*i)/total), tostring(i).." / "..tostring(total))
222 else
223 setCap(ArkLessons.RevealCaps[scriptid], "p", 100, "")
229 function openArkLessonScript(i, script_id, url)
230 if i == ArkLessons.RevealStep[script_id] then
231 getUI("ui:interface:ArkLessonWin"..tostring(script_id)).active = false
232 WebQueue:push(url)
236 function readArkLesson(i, script_id, url)
237 if ArkLessons.LockedArkReadlesson then
238 return
241 if i == ArkLessons.RevealStep[script_id] then
242 ArkLessons.LockedArkReadlesson = true
243 ArkLessons:ArkRevealLessonInfos(script_id, i, 8)
244 WebQueue:push(url)
248 function ArkLessons:onDraw(scriptid)
249 if ArkLessons.OnDraw[scriptid] ~= nil then
250 for id, command in pairs(ArkLessons.OnDraw[scriptid]) do
251 if command == "rotate" then
252 doRotateLessonQuestion(scriptid, id)
253 elseif command[1] == "blink" then
254 if command[4] > 0 and (nltime.getLocalTime() - command[2]) > 300 then
255 ui = getUI("ui:interface:ArkLessonWin"..tostring(scriptid))
256 local html = ui:find("html")
257 if command[3] == 1 then
258 ArkLessons.OnDraw[scriptid][id][3] = 2
259 html:showDiv("current_"..tostring(id), false)
260 html:showDiv("current2_"..tostring(id), true)
261 else
262 ArkLessons.OnDraw[scriptid][id][3] = 1
263 html:showDiv("current_"..tostring(id), true)
264 html:showDiv("current2_"..tostring(id), false)
266 ArkLessons.OnDraw[scriptid][id][2] = nltime.getLocalTime()
267 ArkLessons.OnDraw[scriptid][id][4] = ArkLessons.OnDraw[scriptid][id][4] - 1
268 if ArkLessons.OnDraw[scriptid][id][4] <= 0 then
269 ArkLessons.LockedArkReadlesson = nil
278 function ArkLessons:openLessonBox(continent, name, text)
279 if game.spawnShapesByZone == nil then return end
281 local box = game.spawnShapesByZone[continent]
282 if box then
283 box = box[name]
284 if box then
285 if box[9] then
286 deleteShape(box[9])
288 if box[8] and box[8]["action"] then
289 box[8]["action"]= text
290 game.spawnShapesByZone[continent][name][9] = SceneEditor:spawnShape(box[12]..".shape", box[2], box[3], box[4], box[5], box[6], box[7], box[8])
296 function ArkLessons:finishLessonBox(continent, name, text)
297 print_r(game.spawnShapesByZone)
299 if game.spawnShapesByZone == nil then return end
301 local box = game.spawnShapesByZone[continent]
302 if box then
303 box = box[name]
304 if box then
305 if box[9] then
306 deleteShape(box[9])
308 if box[10] then
309 deleteShape(box[10])
312 if box[8] and box[8]["action"] then
313 box[8]["action"] = text
314 game.spawnShapesByZone[continent][name][9] = SceneEditor:spawnShape(box[12]..".shape", box[2], box[3], box[4], box[5], box[6], box[7], box[8])
315 game.spawnShapesByZone[continent][name][10] = nil
321 function ArkLessons:init()
322 if webig.check_started == nil then
323 webig.urls_to_check = {}
324 webig.check_started = true
325 addOnDbChange(getUI("ui:interface:web_transactions_lessons"), "@UI:VARIABLES:CURRENT_SERVER_TICK", "webig:checkUrlLoop()")
330 function rotateLessonQuestion(scriptid, id)
331 local framewin = getUI("ui:interface:ArkLessonWin"..scriptid)
332 local empty = framewin:find("empty_"..id)
333 if not empty then return end
334 local sel = empty:find("selection")
335 local scene = empty:find("scene")
337 if ArkLessons.RevealStep[scriptid] == id then
338 local moves={-1, 0.5, 0, 0.5, 1}
339 local moves2={-1, 1}
340 if ArkLessons.RevealMoves[scriptid] == nil then
341 ArkLessons.RevealMoves[scriptid] = {}
343 ArkLessons.RevealMoves[scriptid][id] = {moves[math.random(#moves)], moves[math.random(#moves)], moves2[math.random(#moves2)]}
344 if ArkLessons.OnDraw[scriptid] == nil then ArkLessons.OnDraw[scriptid] = {} end
345 ArkLessons.OnDraw[scriptid][id] = "rotate"
346 sel.tooltip = getUCtf8(ArkLessons.RevealTooltips[scriptid][id])
347 scene:getElement("camera#0").posy = 24.5
348 else
349 sel.col_over = "0 0 0 0"
350 sel.col_pushed = "0 0 0 0"
351 sel.tooltip = ""
352 scene:getElement("camera#0").posy = 23.5
357 function doRotateLessonQuestion(scriptid, id)
358 local framewin = getUI("ui:interface:ArkLessonWin"..scriptid)
359 local empty = framewin:find("empty_"..id)
360 if not empty then return end
361 local x,y = getMousePos()
362 empty:find("selection").col_normal = "200 200 255 50"
363 if empty ~= nil and x > empty.x_real and x < empty.x_real + empty.w and y > empty.y_real and y < empty.y_real + empty.h then
364 local scene = empty:find("scene")
365 empty:find("selection").col_over = "255 200 255 50"
366 scene:getElement("shape#0").rotx = scene:getElement("shape#0").rotx + ArkLessons.RevealMoves[scriptid][id][1]
367 scene:getElement("shape#0").roty = scene:getElement("shape#0").roty + ArkLessons.RevealMoves[scriptid][id][2]
368 scene:getElement("shape#0").rotz = scene:getElement("shape#0").rotz + ArkLessons.RevealMoves[scriptid][id][3]
372 function webig:checkUrlLoop()
373 if webig.urls_to_check[1] ~= nil then
374 if webig.urls_to_check[1][2] == "done" then
375 table.remove(self.urls_to_check, 1)
376 return
379 if webig.urls_to_check[1][2] == "wait" then
380 local url = webig.urls_to_check[1][1]
381 webig.urls_to_check[1][2] = "run"
382 getUI("ui:interface:web_transactions_lessons"):find("html"):browse(url)
388 function webig:checkUrl(url)
389 table.insert(webig.urls_to_check, {url, "wait"})
392 function webig:luaWebLoaded()
393 if webig.urls_to_check[1] then
394 webig.urls_to_check[1][2] = "done"
398 function webig:displayWait(ui_name)
399 local ui = getUI(ui_name)
400 if ui then
401 ui.active = true
402 ui:find("html"):renderHtml([[
403 <style>
404 * { color: white; background-color: #000000F0 }
405 </style>
406 <table><tr>
407 <td>
408 <div class="ryzom-ui-grouptemplate" id="ark_lesson_please_wait" style="template:webig_inv_item_shape;id:ark_lesson_please_wait;w:]]..tostring(ui.w)..[[;h:]]..tostring(ui.h)..[[;shape:ge_mission_chrono.ps;shape_pos:0 0 -1;rotz:0;roty:0;dist:0;fontsize:16;text:uiPleaseWait;text_y:]]..tostring(-(ui.h/5.7))..[[;text_color:255 200 150 255;color_over:0 165 255 0;fx:env_aqua2.ps;"></div>
409 </td>
410 </tr></table>
411 <body>]])
415 function webig:openWin(ui_name)
416 local ui = getUI(ui_name)
417 if ui then
418 ui.active = true
423 -- VERSION --
424 RYZOM_ARK_LESSONS_VERSION = 324