-- player_mcp - Player UI components of MCP module -- (component of MCP) -- Template attachment: none -- Created by: Patrick Ferland -- Created on: 07/11/2008 -- Revision History -- 07/11/2008 P.Ferland - New script -- 07/14/2008 P.Ferland - Module auto-configuration "makefile" section added -- and removed -- 07/30/2008 P.Ferland - Added persistent dragging -- 08/01/2008 P.Ferland - Added standard ui_tooltip and persisted expanded state -- Constants MCP_WINSTYLE = '13197:4' BUTTONS = { MCP = { BN = '13197:116', BH = '13197:115', BP = '13197:117', W = 32, H = 32 }, EXPAND_CONTRACT = { EXPAND = { BN = '13197:104', BH = '13197:103', BP = '13197:105' }, CONTRACT = { BN = '13197:86', BH = '13197:137', BP = '13197:87' }, W = 32, H = 32 }, SCROLL = { LEFT = { BN = '13197:126', BH = '13197:125', BP = '13197:138' }, RIGHT = { BN = '13197:129', BH = '13197:128', BP = '13197:130' }, W = 32, H = 32 }, } LAYOUT = { MAIN = { X = 14, Y = 0, W = 52, H = 32, MCP_X = -14, EC_X = 46, L_X = 18 }, TOOLBAR = { X = 100, Y = 0, W = 374, H = 32, SL_X = -16, SR_X = 370, } } -- Script Properties Define Properties() mcp_main_window = 0 mcp_location = { x = 0, y = 0 } mcp_tooltips = {} mcp_toolbar_window = 0 mcp_mode = 'CONTRACT' PersistProperty('mcp_mode') mcp_scroll_index = 1 mcp_visible = 0 PersistProperty('mcp_visible') -- Drag Memory mcp_drag_offset = { x = 0, y = 0 } PersistProperty('mcp_drag_offset') IncludeScript('13197:21') -- ui_library end -- Commands Define Commands() MakeCommand('mcp_size', 'Change MCP size', 'size:string') MakeCommand('mcp_scroll', 'Scroll the MCP contents', 'dir:string') MakeCommand('mcp_toggle', 'Toggle MCP visibility') MakeInput('Shift-M to toggle MCP display', 'm', 'down', 'shift', 'mcp_toggle') end Command mcp_toggle() self.mcp_visible = math.abs(self.mcp_visible -1) SendTo(self, 'mcp_draw', 0) end Command mcp_scroll(dir) local w = GetWorld() local mcp = w.singleton_tracker['mcp'] if (mcp == nil) then return end local mcp_count = 0 local command_name = '' local command_data = {} for command_name, command_data in pairs(mcp.mcp_commands) do mcp_count = mcp_count + 1 end if (dir == 'left') then self.mcp_scroll_index = self.mcp_scroll_index - 10 else self.mcp_scroll_index = self.mcp_scroll_index + 10 end if (self.mcp_scroll_index > mcp_count) then self.mcp_scroll_index = mcp_count end if (self.mcp_scroll_index < 1) then self.mcp_scroll_index = 1 end SendTo(self, 'mcp_draw', 0) end Command mcp_size(size) if (self.mcp_mode == 'CONTRACT') then self.mcp_mode = 'EXPAND' else self.mcp_mode = 'CONTRACT' end SaveToDb(self) SendTo(self, 'mcp_draw', 0) end -- Triggers Trigger attach() local w = GetWorld() local mcp = w.singleton_tracker['mcp'] if (mcp == nil) then return end self.mcp_visible = mcp.mcp_visible_on_login SendTo(self, 'mcp_draw', 0) end Trigger mcp_draw() Debug('received mcp_draw') mcp_draw(self) end function mcp_clear_tooltips(self) local tooltip_id = 0 for _, tooltip_id in ipairs(self.mcp_tooltips) do Debug('deleting tooltip ' .. tooltip_id) UiVisible(tooltip_id, 0) UiDelete(tooltip_id) end table.clear(self.mcp_tooltips) end function mcp_draw(self) if (IsSuperuser(self) ~= 1) then return end mcp_clear_tooltips(self) if (self.mcp_main_window ~= 0) then UiDelete(self.mcp_main_window) self.mcp_main_window = 0 end if (self.mcp_visible ~= 1) then return end local w = GetWorld() local mcp = w.singleton_tracker['mcp'] if (mcp == nil) then Debug("MCP: Unable to obtain world singleton!") return end self.mcp_main_window = UiWindow(0, 'mcp_main_window', LAYOUT.MAIN.X + self.mcp_drag_offset.x, LAYOUT.MAIN.Y + self.mcp_drag_offset.y, LAYOUT.MAIN.W, LAYOUT.MAIN.H, MCP_WINSTYLE) UiCapability(self.mcp_main_window, 'drag') local mcp_main_button = UiImageButton(self.mcp_main_window, 'mcp_main_button', LAYOUT.MAIN.MCP_X, LAYOUT.MAIN.Y, BUTTONS.MCP.W, BUTTONS.MCP.H, BUTTONS.MCP.BN, BUTTONS.MCP.BH, BUTTONS.MCP.BP, '/configure ' .. mcp.id) mcp_tooltip(self, 'Metaplace Control Panel (hide with Shift-M)', mcp_main_button) local mcp_label = UiLabel(self.mcp_main_window, 'mcp_label', LAYOUT.MAIN.L_X, 6, 'MCP') UiColor(mcp_label, 0, 0, 0, 1) local ec_command = 'mcp_size contract' local ec_tooltip = 'Minimize MCP' if (self.mcp_mode == 'EXPAND') then ec_command = 'mcp_size expand' ec_tooltip = 'Maximize MCP' end local ec_button = BUTTONS.EXPAND_CONTRACT[self.mcp_mode] local mcp_ec_button = UiImageButton(self.mcp_main_window, 'mcp_ec_button', LAYOUT.MAIN.EC_X, LAYOUT.MAIN.Y, BUTTONS.EXPAND_CONTRACT.W, BUTTONS.EXPAND_CONTRACT.H, ec_button.BN, ec_button.BH, ec_button.BP, ec_command) mcp_tooltip(self, ec_tooltip, mcp_ec_button) if (self.mcp_mode == 'CONTRACT') then -- Only draw toolbar if not already minimized local mcp_count = 0 local command_name = '' local command_data = {} for command_name, command_data in pairs(mcp.mcp_commands) do mcp_count = mcp_count + 1 end self.mcp_toolbar_window = UiWindow(self.mcp_main_window, 'mcp_toolbar_window', LAYOUT.TOOLBAR.X, LAYOUT.TOOLBAR.Y, LAYOUT.TOOLBAR.W, LAYOUT.TOOLBAR.H, MCP_WINSTYLE) local sl_bn = 'BN' local sl_bh = 'BH' local sl_bp = 'BP' local sl_command = 'mcp_scroll left' local sl_tooltip = 'Scroll left' if (self.mcp_scroll_index < 2) then sl_command = '' sl_tooltip = 'Cannot scroll' end local sr_bn = 'BN' local sr_bh = 'BH' local sr_bp = 'BP' local sr_command = 'mcp_scroll right' local sr_tooltip = 'Scroll right' Debug(self.mcp_scroll_index) Debug(mcp_count) if (self.mcp_scroll_index + 10 > mcp_count) then sr_command = '' sr_tooltip = 'Cannot scroll' end local mcp_sl_button = UiImageButton(self.mcp_toolbar_window, 'mcp_sl_button', LAYOUT.TOOLBAR.SL_X, LAYOUT.TOOLBAR.Y, BUTTONS.SCROLL.W, BUTTONS.SCROLL.H, BUTTONS.SCROLL.LEFT[sl_bn], BUTTONS.SCROLL.LEFT[sl_bh], BUTTONS.SCROLL.LEFT[sl_bp], sl_command) mcp_tooltip(self, sl_tooltip, mcp_sl_button) if (sl_command == '') then UiTint(mcp_sl_button, 128, 128, 190) end local mcp_sr_button = UiImageButton(self.mcp_toolbar_window, 'mcp_sr_button', LAYOUT.TOOLBAR.SR_X, LAYOUT.TOOLBAR.Y, BUTTONS.SCROLL.W, BUTTONS.SCROLL.H, BUTTONS.SCROLL.RIGHT[sr_bn], BUTTONS.SCROLL.RIGHT[sr_bh], BUTTONS.SCROLL.RIGHT[sr_bp], sr_command) mcp_tooltip(self, sr_tooltip, mcp_sr_button) if (sr_command == '') then UiTint(mcp_sr_button, 128, 128, 190) end local i = 0 local max = 10 local x = 20 for command_name, command_data in pairs(mcp.mcp_commands) do i = i + 1 if ( i >= self.mcp_scroll_index ) then Debug("Processing " .. command_name) Debug(table.tostring(command_data)) max = max - 1 local mcp_button = UiImageButton(self.mcp_toolbar_window, 'mcp_button_' .. max, x, 0, 32, 32, command_data.sprite_id, command_data.sprite_id, command_data.sprite_id, command_name) mcp_tooltip(self, command_data.tooltip, mcp_button) x = x + 35 end if (max < 1) then break end end end UiAttachUser(self, self.mcp_main_window) UiVisible(self.mcp_main_window, 1) end Trigger ui_move(win_id, destination_x, destination_y) if (win_id == self.mcp_main_window) then self.mcp_drag_offset.x = destination_x self.mcp_drag_offset.y = destination_y SaveToDb(self) end end -- Render a tooltip for a UI element function mcp_tooltip(self, text, item) local tooltip_id = ui_tooltip(item, text, 500, 'below', self) table.insert(self.mcp_tooltips, tooltip_id) return tooltip_id end