Merge branch 'fixes' into main/rendor-staging
[ryzomcore.git] / ryzom / client / mods / syui_v3 / interaction.lua
blob5c7cf60f99ecf14a9ae682d98ac8248451218b70
1 -- In this file we define functions that serves for interaction windows
4 ------------------------------------------------------------------------------------------------------------
5 -- create the game namespace without reseting if already created in an other file.
6 if (game==nil) then
7 game= {};
8 end
10 ------------------------------------------------------------------------------------------------------------
11 -- called when server send an invitaion we receive a text id containing the string to display (invitor name)
12 function game:onTeamInvation(textID)
14 local ui = getUI('ui:interface:join_team_proposal');
15 ui.content.inside.invitor_name.textid = textID;
16 ui.active = true;
17 setTopWindow(ui);
18 ui:center();
19 ui:blink(2);
20 end
22 ------------------------------------------------------------------------------------------------------------
23 --
24 function game:teamInvitationAccept()
26 local ui = getUI('ui:interface:join_team_proposal');
27 ui.active = false;
28 sendMsgToServer('TEAM:JOIN');
29 end
31 ------------------------------------------------------------------------------------------------------------
32 --
33 function game:teamInvitationRefuse()
35 local ui = getUI('ui:interface:join_team_proposal');
36 ui.active = false;
37 sendMsgToServer('TEAM:JOIN_PROPOSAL_DECLINE');
38 end
40 ------------------------------------------------------------------------------------------------------------
41 --
42 function game:switchChatTab(dbEntry)
43 local db= 'UI:SAVE:ISENABLED:' .. dbEntry;
44 local val= getDbProp(db);
45 -- switch value
46 if(val==0) then
47 setDbProp(db, 1);
48 else
49 setDbProp(db, 0);
50 end
51 end
53 ------------------------------------------------------------------------------------------------------------
54 --
55 function game:updateEmoteMenu(prop, tooltip, tooltip_pushed, name, param)
56 for i=0,9 do
57 -- Get key shortcut
58 local text = i18n.get('uiTalkMemMsg0' .. i);
59 local key = runExpr( "getKey('talk_message','0" .. i .. "',1)" );
61 if (key ~= nil and key ~= '') then
62 key = ' @{T25}@{2F2F}(' .. key .. ')';
63 text = concatUCString(text, key);
64 end
66 -- if we don't do the full getUI, it doesn't work (don't understand why)
67 local uiQC= getUI("ui:interface:user_chat_emote_menu:quick_chat:" .. "qc" .. i);
68 uiQC.uc_hardtext_format= text;
69 end
71 end
73 ------------------------------------------------------------------------------------------------------------
74 --
75 if (ui_free_chat_h == nil) then
76 ui_free_chat_h = {}
77 end
79 if (ui_free_chat_w == nil) then
80 ui_free_chat_w = {}
81 end
83 ------------------------------------------------------------------------------------------------------------
84 --
85 function game:closeTellHeader(uiID)
86 local ui = getUI('ui:interface:' .. uiID);
88 -- save size
89 ui_free_chat_h[uiID] = ui.h;
90 ui_free_chat_w[uiID] = ui.w;
92 -- reduce window size
93 ui.pop_min_h = 32;
94 ui.h = 0;
95 ui.w = 216;
96 end
98 ------------------------------------------------------------------------------------------------------------
99 --
100 function game:openTellHeader(uiID)
101 local ui = getUI('ui:interface:' .. uiID);
102 ui.pop_min_h = 96;
104 -- set size from saved values
105 if (ui_free_chat_h[uiID] ~= nil) then
106 ui.h = ui_free_chat_h[uiID];
109 if (ui_free_chat_w[uiID] ~= nil) then
110 ui.w = ui_free_chat_w[uiID];
113 -- set Header Color to normal values (when a tell is closed and the telled player say someone, header change to "UI:SAVE:WIN:COLORS:INFOS")
114 ui:setHeaderColor('UI:SAVE:WIN:COLORS:COM');
118 --/////////////////////////
119 --// TARGET WINDOW SETUP //
120 --/////////////////////////
122 -- local functions for tests
123 local function levelToForceRegion(level)
124 if level < 20 then
125 return 1
126 elseif level >= 250 then
127 return 6
128 else
129 return math.floor(level / 50) + 2
130 end
131 end
133 local function levelToLevelForce(level)
134 return math.floor(math.fmod(level, 50) * 5 / 50) + 1
135 end
139 -- tmp var for tests in local mode
140 local twPlayerLevel = 10
141 local twTargetLevel = 19
142 local twTargetForceRegion = levelToForceRegion(twTargetLevel)
143 local twTargetLevelForce = levelToLevelForce(twTargetLevel)
144 local twTargetPlayer = false
145 local twPlayerInPVPMode = false
146 local twTargetInPVPMode = false
149 -----------------------------------
150 local function twGetPlayerLevel()
151 if config.Local == 1 then
152 return twPlayerLevel
153 else
154 return getPlayerLevel()
158 -----------------------------------
159 local function twGetTargetLevel()
160 if config.Local == 1 then
161 return twTargetLevel
162 else
163 return getTargetLevel()
167 -----------------------------------
168 local function twGetTargetForceRegion()
169 if config.Local == 1 then
170 return twTargetForceRegion
171 else
172 return getTargetForceRegion()
176 -----------------------------------
177 local function twGetTargetLevelForce()
178 if config.Local == 1 then
179 return twTargetLevelForce
180 else
181 return getTargetLevelForce()
185 -----------------------------------
186 local function twIsTargetPlayer()
187 if config.Local == 1 then
188 return twTargetPlayer
189 else
190 return isTargetPlayer()
194 -----------------------------------
195 local function twIsPlayerInPVPMode()
196 if config.Local == 1 then
197 return twPlayerInPVPMode
198 else
199 return isPlayerInPVPMode()
203 -----------------------------------
204 local function twIsTargetInPVPMode()
205 if config.Local == 1 then
206 return twTargetInPVPMode
207 else
208 return isTargetInPVPMode()
212 ----------------------
213 -- MISC local tests function
214 -- no selection
215 function twTest0()
216 twTargetLevel = -1
217 twTargetPlayer = false
218 game:updateTargetConsiderUI()
220 -- selection, not impossible
221 function twTest1()
222 twTargetPlayer = false
223 twPlayerLevel = 10
224 twTargetLevel = 15
225 twTargetForceRegion = levelToForceRegion(twTargetLevel)
226 twTargetLevelForce = levelToLevelForce(twTargetLevel)
227 game:updateTargetConsiderUI()
229 -- selection, not impossible (limit)
230 function twTest2()
231 twTargetPlayer = false
232 twPlayerLevel = 10
233 twTargetLevel = 20
234 twTargetForceRegion = levelToForceRegion(twTargetLevel)
235 twTargetLevelForce = levelToLevelForce(twTargetLevel)
236 game:updateTargetConsiderUI()
238 -- selection, impossible
239 function twTest3()
240 twTargetPlayer = false
241 twPlayerLevel = 10
242 twTargetLevel = 21
243 twTargetForceRegion = levelToForceRegion(twTargetLevel)
244 twTargetLevelForce = levelToLevelForce(twTargetLevel)
245 game:updateTargetConsiderUI()
247 ------ NAMED
248 ------
249 -- selection, not impossible, named
250 function twTest4()
251 twTargetPlayer = false
252 twPlayerLevel = 10
253 twTargetLevel = 15
254 twTargetForceRegion = levelToForceRegion(twTargetLevel)
255 twTargetLevelForce = 6
256 game:updateTargetConsiderUI()
258 -- selection, not impossible (limit), named
259 function twTest5()
260 twTargetPlayer = false
261 twPlayerLevel = 10
262 twTargetLevel = 20
263 twTargetForceRegion = levelToForceRegion(twTargetLevel)
264 twTargetLevelForce = 6
265 game:updateTargetConsiderUI()
267 -- selection, impossible, named
268 function twTest6()
269 twTargetPlayer = false
270 twPlayerLevel = 10
271 twTargetLevel = 21
272 twTargetForceRegion = levelToForceRegion(twTargetLevel)
273 twTargetLevelForce = 6
274 game:updateTargetConsiderUI()
276 ------ BOSS
277 ------
278 -- selection, not impossible, boss
279 function twTest7()
280 twTargetPlayer = false
281 twPlayerLevel = 10
282 twTargetLevel = 15
283 twTargetForceRegion = levelToForceRegion(twTargetLevel)
284 twTargetLevelForce = 7
285 game:updateTargetConsiderUI()
287 -- selection, not impossible (limit), boss
288 function twTest8()
289 twTargetPlayer = false
290 twPlayerLevel = 10
291 twTargetLevel = 20
292 twTargetForceRegion = levelToForceRegion(twTargetLevel)
293 twTargetLevelForce = 7
294 game:updateTargetConsiderUI()
296 -- selection, impossible, boss
297 function twTest9()
298 twTargetPlayer = false
299 twPlayerLevel = 10
300 twTargetLevel = 21
301 twTargetForceRegion = levelToForceRegion(twTargetLevel)
302 twTargetLevelForce = 7
303 game:updateTargetConsiderUI()
305 ------ MINI-BOSS
306 ------
307 -- selection, not impossible, boss
308 function twTest10()
309 twTargetPlayer = false
310 twPlayerLevel = 10
311 twTargetLevel = 15
312 twTargetForceRegion = levelToForceRegion(twTargetLevel)
313 twTargetLevelForce = 8
314 game:updateTargetConsiderUI()
316 -- selection, not impossible (limit), boss
317 function twTest11()
318 twTargetPlayer = false
319 twPlayerLevel = 10
320 twTargetLevel = 20
321 twTargetForceRegion = levelToForceRegion(twTargetLevel)
322 twTargetLevelForce = 8
323 game:updateTargetConsiderUI()
325 -- selection, impossible, boss
326 function twTest12()
327 twTargetPlayer = false
328 twPlayerLevel = 10
329 twTargetLevel = 21
330 twTargetForceRegion = levelToForceRegion(twTargetLevel)
331 twTargetLevelForce = 8
332 game:updateTargetConsiderUI()
335 ------ PLAYER SELECTION
336 ------ 2 players, no pvp
337 function twTest13()
338 twTargetPlayer = true
339 twPlayerInPVPMode = false
340 twTargetInPVPMode = false
342 twPlayerLevel = 10
343 twTargetLevel = 15
344 twTargetForceRegion = levelToForceRegion(twTargetLevel)
345 twTargetLevelForce = levelToLevelForce(twTargetLevel)
346 game:updateTargetConsiderUI()
349 function twTest14()
350 twTargetPlayer = true
351 twPlayerInPVPMode = true
352 twTargetInPVPMode = true
354 twPlayerLevel = 10
355 twTargetLevel = 15
356 twTargetForceRegion = levelToForceRegion(twTargetLevel)
357 twTargetLevelForce = levelToLevelForce(twTargetLevel)
358 game:updateTargetConsiderUI()
362 ------ 2 players, pvp
364 -- groups
365 function twGroup(groupSize)
366 for gm = 0, 7 do
367 if gm < groupSize then
368 setDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT", 1)
369 else
370 setDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT", 0)
372 end
375 ------------------------------------------------------------------------------------------------------------
377 function game:closeWebIGBrowserHeader()
378 local ui = getUI('ui:interface:webig');
380 -- save size
381 ui_webig_browser_h = ui.h;
382 ui_webig_browser_w = ui.w;
384 -- reduce window size
385 ui.pop_min_h = 32;
386 ui.h = 0;
387 ui.w = 150;
390 ------------------------------------------------------------------------------------------------------------
392 function game:openWebIGBrowserHeader()
393 local ui = getUI('ui:interface:webig');
394 ui.pop_min_h = 96;
396 -- set size from saved values
397 if (ui_webig_browser_h ~= nil) then
398 ui.h = ui_webig_browser_h;
401 if (ui_webig_browser_w ~= nil) then
402 ui.w = ui_webig_browser_w;
405 ------------------------------------------------------------------------------------------------------------
407 ------------------------------------------------------------------------------------------------------------
408 --#############################
409 --###### Syphox's modlib ######
410 --#############################
411 if (package_path_native == nil) then
412 package_path_native = package.path;
414 package.path = package.path .. ';./user/syui/?.lua';
417 function isModuleAvailable(name)
418 if(package.loaded[name])then
419 return true
420 else
421 for _, searcher in ipairs(package.searchers or package.loaders) do
422 local loader = searcher(name)
423 if(type(loader) == 'function')then
424 package.preload[name] = loader
425 return true
428 return false
432 if(isModuleAvailable("syui"))then
433 sy_ui = require("syui")
436 function game:showTargetPercent()
437 if(not sy_ui.exist())then return end
438 sy_ui.UpdateJauge()
439 sy_ui.showTargetPercent()
442 function game:newConsider()
443 if(not sy_ui.exist())then return end
444 sy_ui.newConsider()
447 function game:updateFPS()
448 if(not sy_ui.exist())then return end
449 sy_ui.updateFPS()
452 function game:sysinfo(txt, mtd)
453 if(not sy_ui.exist())then return end
454 sy_ui.sysinfo(txt, mtd)
457 function game:updateMemberCount()
458 if(not sy_ui.exist())then return end
459 sy_ui.updateMemberCount()
462 function game:updateGLinvB()
463 if(not sy_ui.exist())then return end
464 sy_ui.updateGLinvB()
467 function game:teamInviteFromGuild(uiID)
468 if(not sy_ui.exist())then return end
469 sy_ui.teamInviteFromGuild(uiID)
472 function game:invToGuild(ply)
473 if(not sy_ui.exist())then return end
474 sy_ui.invToGuild(ply)
477 function game:updateFLinvB(uiID)
478 if(not sy_ui.exist())then return end
479 sy_ui.updateFLinvB(uiID)
482 function game:teamInvite(uiID)
483 if(not sy_ui.exist())then return end
484 sy_ui.teamInvite(uiID)
487 --#############################
488 --######## modlib end #########
489 --#############################
491 ------------------------------------------------------------------------------------------------------------
492 -- This function is called when a new target is selected, it should update the 'consider' widget
493 -- Level of the creature
494 -- Is its level known (not too high ...)
495 -- Boss/Mini-bosses/Names colored ring
496 function game:updateTargetConsiderUI()
497 --debugInfo("Updating consider widget")
500 local targetWindow = getUI("ui:interface:target")
502 local wgTargetSlotForce = targetWindow:find("slot_force")
503 local wgTargetLevel = targetWindow:find("target_level")
504 local wgImpossible = targetWindow:find("impossible")
505 local wgSlotRing = targetWindow:find("slot_ring")
506 local wgToolTip = targetWindow:find("target_tooltip")
507 local wgPvPTag = targetWindow:find("pvp_tags")
508 local wgHeader = targetWindow:find("header_opened")
510 wgTargetSlotForce.active = true
511 wgImpossible.active = true
513 -- no selection ?
514 if twGetTargetLevel() == -1 then
515 wgTargetSlotForce.active = false
516 wgTargetLevel.active = false
517 wgImpossible.active = false
518 wgSlotRing.active = false
519 if (isTargetUser() and twIsPlayerInPVPMode()) then
520 wgToolTip.tooltip = ""
521 wgPvPTag.active = true
522 wgHeader.h = 56;
523 else
524 wgPvPTag.active = false
525 wgHeader.h = 34;
526 wgToolTip.tooltip = i18n.get("uittConsiderTargetNoSelection")
528 return
531 local pvpMode = false
532 wgPvPTag.active = false
533 wgHeader.h = 34;
535 -- if the selection is a player, then both the local & targeted player must be in PVP mode for the level to be displayed
536 if (twIsTargetPlayer()) then
537 -- don't display anything ...
538 wgTargetSlotForce.active = false
539 wgTargetLevel.active = false
540 wgImpossible.active = false
541 wgSlotRing.active = false
542 wgToolTip.tooltip = ""
543 if twIsTargetInPVPMode() then
544 debugInfo("target in pvp")
545 wgPvPTag.active = true
546 wgHeader.h = 34; -- 56
548 return
551 -- load default code if syphox.lua is not available
552 if(not sy_ui.exist())then
553 -- depending on the number of people in the group, set the max diff for visibility between player level
554 -- & creature level (x 10 per member)
555 local maxDiffLevel = 10
556 if not pvpMode then
557 -- exception there : when "pvping", don't relate the levelof the target to the level of the group, but to thelocal
558 -- player only
559 for gm = 0, 7 do
560 if getDbProp("SERVER:GROUP:" .. tostring(gm) .. ":PRESENT") ~= 0 then
561 maxDiffLevel = maxDiffLevel + 10
566 debugInfo("Max diff level= " .. tostring(maxDiffLevel))
568 local impossible = (twGetTargetLevel() - twGetPlayerLevel() > maxDiffLevel)
570 wgSlotRing.active = false
572 if impossible then
573 -- targeted object is too hard too beat, display a skull
574 wgTargetLevel.active = false
575 wgTargetLevelText.active = wgTargetLevel.active
576 wgTargetLevelText.hardtext = ""
577 wgImpossible.y = -5
578 wgImpossible.color = "255 50 50 255"
579 else
580 -- player can see the level of the targeted creature
581 wgTargetLevel.active = true
582 wgTargetLevelText.active = wgTargetLevel.active
583 wgImpossible.y = 6
584 wgTargetLevel.hardtext = tostring(twGetTargetLevel())
585 wgImpossible.color = "255 255 255 255"
586 wgTargetLevel.color = getDefine("region_force_" .. tostring(levelToForceRegion(twGetTargetLevel())))
587 wgTargetLevelText.color = wgTargetLevel.color
588 wgTargetLevelText.hardtext = "LVL"
591 -- based on the 'level force', set a colored ring around the level
592 local levelForce = twGetTargetLevelForce()
593 wgTargetSlotForce.color = getDefine("region_force_" .. tostring(levelToForceRegion(twGetTargetLevel())))
595 wgImpossible.texture = getDefine("force_level_" .. tostring(levelForce))
596 wgImpossible.active = true
597 if levelForce < 6 then
598 wgToolTip.tooltip = i18n.get("uittConsiderTargetLevel")
599 elseif levelForce == 6 then
600 -- Named creature
601 wgImpossible.color = "117 132 126 255"
602 wgSlotRing.color = "117 132 126 255"
603 wgTargetSlotForce.color = "117 132 126 255"
604 wgSlotRing.texture = "consider_ring.tga"
605 wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss")
606 elseif levelForce == 7 then
607 -- Boss
608 wgImpossible.color = "156 98 65 255"
609 wgSlotRing.color = "156 98 65 255"
610 wgTargetSlotForce.color = "156 98 65 255"
611 wgSlotRing.texture = "consider_ring.tga"
612 wgToolTip.tooltip = i18n.get("uittConsiderNamedOrMiniBoss")
613 elseif levelForce == 8 then
614 -- Mini-Boss
615 wgImpossible.color = "213 212 9 255"
616 wgSlotRing.texture = "consider_ring.tga"
617 wgSlotRing.color = "213 212 9 255"
618 if isTargetNPC() then
619 wgTargetSlotForce.color = "255 255 255 255"
620 wgToolTip.tooltip = i18n.get("uittConsiderBossNpc")
621 else
622 wgTargetSlotForce.color = "213 212 9 255"
623 wgToolTip.tooltip = i18n.get("uittConsiderBoss")
627 if impossible then
628 wgToolTip.tooltip = concatUCString(wgToolTip.tooltip, ucstring("\n"), i18n.get("uittConsiderUnknownLevel"))
630 else
631 game:newConsider()