Resolve "Toggle Free Look with Hotkey"
[ryzomcore.git] / ryzom / common / data_common / r2 / r2_ui_tools.lua
blob8b2c751431e6603f7f62881baa98261d0352d45c
1 ----------
2 -- TOOL --
3 ----------
4 -- Manage display of current selected tool into the ui
5 ------------------------------------------------------------------------------------------------------------
8 -- base Name for the tool bar in the ui
9 local toolBarPath = "ui:interface:r2ed_toolbar:"
10 local geoToolPath = "ui:interface:r2ed_palette:content:sbtree_geo:geo_features:enclosing:geo_feature_list:"
11 local featuresToolPath = "ui:interface:r2ed_palette:content:sbtree_features:features:enclosing:feature_list:"
14 r2.ToolUI =
16 -- ref to current hightlighted tool in the ui
17 ActiveToolUI = nil,
19 -- For named tools, map the name to the ui path
20 ToolNameToUIPath =
22 selectMove = toolBarPath .. "r2ed_tool_select",
23 selectRotate = toolBarPath .. "r2ed_tool_rotate",
24 teleport = toolBarPath .. "r2ed_tool_teleport",
25 drawRoad = geoToolPath .. "r2ed_tool_draw_road:tool",
26 drawRegion = geoToolPath .. "r2ed_tool_draw_region:tool",
27 createFeatureBanditCamp = featuresToolPath .. "r2ed_create_feature_bandit_camp:tool",
28 createFeatureTimer = featuresToolPath .. "r2ed_create_feature_timer:tool",
29 createFeatureTimeTrigger = featuresToolPath .. "r2ed_create_feature_time_trigger:tool",
30 createFeatureFauna = featuresToolPath .. "r2ed_create_feature_fauna:tool",
31 createFeatureBossSpawner = featuresToolPath .. "r2ed_create_feature_boss_spawner:tool",
32 createFeatureZoneTrigger = featuresToolPath .. "r2ed_create_feature_zone_trigger:tool",
33 createFeatureUserTrigger = featuresToolPath .. "r2ed_create_user_trigger:tool",
34 createFeatureEasterEgg = featuresToolPath .."r2ed_create_easter:tool",
35 createFeatureLootSpawner = featuresToolPath .."r2ed_create_feature_loot_spawner:tool",
36 createDialog = featuresToolPath .."r2ed_create_dialog:tool",
37 createFeatureGiveItem = featuresToolPath .."r2ed_create_feature_give_item:tool",
38 createFeatureRequestItem = featuresToolPath .."r2ed_create_feature_request_item:tool",
39 createFeatureTalkTo = featuresToolPath .."r2ed_create_feature_talk_to:tool",
40 createFeatureAmbush = featuresToolPath.."r2ed_create_feature_ambush:tool",
41 createFeatureTimedSpawner = featuresToolPath.."r2ed_create_feature_timed_spawner:tool",
42 createFeatureManHunt = featuresToolPath.."r2ed_create_feature_man_hunt:tool",
48 ------------------------------------------------------------------------------------------------------------
49 -- PRIVATE : hightlight a tool button by a ref on the tool ui
50 function r2.ToolUI:highlightToolUI(tool, hightlighted)
51 if not tool then return end
52 tool:find("selected").active = hightlighted
53 tool:find("unselected").active = not hightlighted
54 end
56 ------------------------------------------------------------------------------------------------------------
57 -- Get reference to a tool in the ui by its name (for named tools)
58 function r2.ToolUI:getToolUIByName(toolName)
59 if toolName == "" then return nil end
60 -- get Name of the ui button from the tool Name
61 local uiPath = self.ToolNameToUIPath[toolName]
62 if uiPath == nil then
63 debugWarning("Can't find ui for tool : " .. tostring(toolName))
64 return nil
65 end
66 return getUI(uiPath)
67 end
69 ------------------------------------------------------------------------------------------------------------
70 -- Get the current highlighted tool
71 function r2.ToolUI:getActiveToolUI()
72 if self.CurrentToolUI and not self.CurrentToolUI.isNil then
73 return self.CurrentToolUI
74 else
75 return nil
76 end
77 end
80 ------------------------------------------------------------------------------------------------------------
81 -- Set the current highlighted tool
82 function r2.ToolUI:setActiveToolUI(tool)
83 if self:getActiveToolUI() then
84 self:highlightToolUI(self:getActiveToolUI(), false)
85 end
86 self.CurrentToolUI = tool
87 self:highlightToolUI(tool, true)
88 end
91 ------------------------------------------------------------------------------------------------------------
92 -- This function will be called by the framework when it wants to highlight a tool in the
93 -- ui. It doesn't change the actual tool in the editor, just the ui
94 function r2.ToolUI:setActiveToolUIByName(toolName)
95 self:setActiveToolUI(self:getToolUIByName(toolName))
96 end
98 ------------------------------------------------------------------------------------------------------------
99 function r2.ToolUI:updateTooltip(onClickL, paramsL)
100 onClickL = defaulting(onClickL, getUICaller().onclick_l)
101 paramsL = defaulting(paramsL, getUICaller().params_l)
102 local expr = string.format("getKey('%s', '%s')", onClickL, paramsL)
103 local keyName = ucstring(runExpr(expr))
104 if keyName == i18n.get("uiNotAssigned") then
105 -- no associated key
106 setContextHelpText(getUICaller().tooltip)
107 else
108 setContextHelpText(concatUCString(getUICaller().tooltip, "@{6F6F} (", keyName, ")"))
112 ----------------------------------------------------------------------------
113 -- Update the undo / redo buttons grayed states
114 function r2.ToolUI:updateUndoRedo()
115 local toolbar = getUI("ui:interface:r2ed_toolbar")
116 toolbar:find("r2ed_tool_undo").unselected.active = r2:canUndo()
117 toolbar:find("r2ed_tool_undo").disabled.active = not r2:canUndo()
118 toolbar:find("r2ed_tool_redo").unselected.active = r2:canRedo()
119 toolbar:find("r2ed_tool_redo").disabled.active = not r2:canRedo()
123 ----------------------------------------------------------------------------
124 -- Update the toggle windows buttons
125 function r2.ToolUI:updateToggleWindowButtons()
126 local windowsBar = getUI("ui:interface:r2ed_windows_bar")
127 local active = (r2.Mode == "Edit")
128 windowsBar.active = active
129 if active then
130 windowsBar:find("r2ed_tool_map_window").selected.active = getUI("ui:interface:map").active
131 windowsBar:find("r2ed_tool_map_window").unselected.active = not getUI("ui:interface:map").active
132 windowsBar:find("r2ed_tool_scenario_window").selected.active = getUI("ui:interface:r2ed_scenario").active
133 windowsBar:find("r2ed_tool_scenario_window").unselected.active = not getUI("ui:interface:r2ed_scenario").active
134 windowsBar:find("r2ed_tool_palette_window").selected.active = getUI("ui:interface:r2ed_palette").active
135 windowsBar:find("r2ed_tool_palette_window").unselected.active = not getUI("ui:interface:r2ed_palette").active
139 ----------------------------------------------------------------------------
140 -- Update the toggle windows buttons
141 function r2.ToolUI:updateToggleWindowDMButtons()
142 local windowsDMBar = getUI("ui:interface:r2ed_windows_dm_bar")
143 windowsDMBar:find("r2ed_live").selected.active = getUI("ui:interface:r2ed_scenario_control").active
144 windowsDMBar:find("r2ed_live").unselected.active = not getUI("ui:interface:r2ed_scenario_control").active
145 windowsDMBar:find("player_control").selected.active = getUI("ui:interface:ring_chars_tracking").active
146 windowsDMBar:find("player_control").unselected.active = not getUI("ui:interface:ring_chars_tracking").active