--[[
Object Explorer v3.5
Author: Jeff the Intern
Created On: 07/23/2008
Component of: Behavior Library
Revisions
New Script: 09/03/2008
08/01/08 - J.McNab UI Updates and Scrollbar Added
08/05/08 - J.McNab List View and Input List Added
08/11/08 - J.McNab Restructure Work Flow
08/12/08 - J.McNab Added Basic/Advanced Modes
08/13 - 09/02/08 - J.McNab Too many revisions to list
09/03/09 - 09/12/08 - J.McNab
Move Thumbnail and List functions into UI_LIBRARY (13197)
Clean up of Code
Added Sliders and Color Pickers
09/16/08 - J.McNab
Script Properties now display in input window in order they were exposed
Added script meta data support
Default slider positions
Button field support for input window
09/17/08 - J.McNab
Color Picker working
Added support for custom palette
09/21/08 - J.McNab
Added Module Filtering system when adding a behavior
09/23/08 - J.McNab
Added cloe_ui_all trigger back into script
Changed 'Filter' to 'Search' in module filtering
[J.McNab] 10/22/08 - Added Save to Template functionality
-- Connected to player_use_smart_object for user commands
--]]
-- CONSTANTS
-- Display Constants
-- Window Constants
WINDOW = {WIDTH = 300,
HEIGHT = 400}
-- Default Color Palette
PALETTE ={IMAGE = '12071:441',
WIDTH = 200,
HEIGHT = 180}
-- Display Icon Constants
ICON = {EMPTY = '12071:27',
DEFAULT = '12071:58',
SCRIPT = '12071:197',
SOUND = '12071:198',
SPRITE = '12071:199',
TEMPLATE = '12071:200',
MODULE = '12071:407',
BACKGROUND = '13197:134',
HISTORY_NEXT = '12071:55',
COLOR = '13197:194',
RETURN = '12071:429',
RESET = '12071:430',
HOME = '12071:444'}
-- Button Constants
BUTTON = {ADD = {NORMAL = '12071:410',
HOVER = '12071:409',
PRESS = '12071:411',
WIDTH = 32,
HEIGHT = 17},
REMOVE = {NORMAL = '12071:413',
HOVER = '12071:412',
PRESS = '12071:408',
WIDTH = 32,
HEIGHT = 17},
ADVANCED = {NORMAL = '12071:415',
HOVER = '12071:416',
PRESS = '12071:417',
WIDTH = 42,
HEIGHT = 17},
BASIC = {NORMAL = '12071:419',
HOVER = '12071:418',
PRESS = '12071:414',
WIDTH = 42,
HEIGHT = 17},
PLAY = {NORMAL = '12071:55',
HOVER = '12071:55',
PRESS = '12071:55',
WIDTH = 8,
HEIGHT = 12},
DONE = {NORMAL = '12071:203',
HOVER = '12071:202',
PRESS = '12071:201',
WIDTH = 32,
HEIGHT = 17},
NEXT = {NORMAL = '12071:422',
HOVER = '12071:421',
PRESS = '12071:423',
WIDTH = 42,
HEIGHT = 17},
PREVIOUS = {NORMAL = '12071:425',
HOVER = '12071:424',
PRESS = '12071:420',
WIDTH = 42,
HEIGHT = 17},
LIST = {NORMAL = '12071:428',
HOVER = '12071:427',
PRESS = '12071:426',
WIDTH = 12,
HEIGHT = 12},
SAVE = {NORMAL = '12071:454',
HOVER = '12071:455',
PRESS = '12071:456',
WIDTH = 42,
HEIGHT = 17}}
-- Color Constants
COLOR = {BASE = {RED = 128,
GREEN = 128,
BLUE = 128,
ALPHA = 1},
DIM = {RED = 200,
GREEN = 200,
BLUE = 200,
ALPHA = 1},
MENU_BG = {RED = 0,
GREEN = 0,
BLUE = 0,
ALPHA = 0.3},
RESET = {RED = 255,
GREEN = 128,
BLUE = 128},
SELECTION = {RED = 247,
GREEN = 233,
BLUE = 141}}
-- Menu Constants
MENU = {WIDTH = WINDOW.WIDTH - 16,
HEIGHT = 36}
-- Scritp Constants
AVATAR_MOVEMENT_SCRIPT = '8282:17'
-- Input Constants
INPUT = {ITEMS = 4,
PADDING = 4,
HEIGHT = 16}
SCROLLBAR = {WIDTH = 16,
BG = {RED = 0,
GREEN = 0,
BLUE = 0,
ALPHA = .5},
COLOR = {RED = 160,
GREEN = 160,
BLUE = 160}}
THUMBNAIL = {ROWS = 4,
COLS = 4}
-- Properties
Define Properties()
-- UI variables
ox_window = 0
-- Add UI Library
IncludeScript('13197:21') -- ui_library
-- Custom Window function for custom configurations
ExportFunction('config_window',
'Draws a window for a behavior custom configuration')
-- Script Metadata
script_description = 'Configurable'
script_long_descritpion = 'This object can use the Object Explorer to customize its behaviors.'
end
-- Triggers
-----------------------------------------------------------------------------------------------------------------------------
-- MAIN TRIGGERS --
-----------------------------------------------------------------------------------------------------------------------------
-- Attach Script to object
Trigger attach()
-- Register 'Customize' to the radial menu
local customize_command = string.format('/event radial_configure %d',
self.id)
SendTo(self,
'radial_menu_register',
0,
self,
'Customize',
customize_command,
ui_library.config.normal, ui_library.config.hover, ui_library.config.press,
0,
1)
end
-- Detach Script from object
Trigger detach()
-- Unregister 'Customize' from the radial.menu
SendTo(self,
'radial_menu_unregister',
0,
self,
'Customize')
end
-- Radial Menu Configure
Trigger radial_configure(caller, user_id)
local user = GetObjectById(user_id)
if(IsSuperuser(user) == 0) then
return
end
local script_list = get_script_list(self, 0, 1, 1)
if(#script_list < 1) then
script_list = get_script_list(self, 0, 1)
if(#script_list < 1) then
script_list = get_script_list(self, 0)
end
end
local first_script = script_list[1]
SendTo(self,
'configure_behaviors',
0,
self.id,
user_id)
end
-- Build Window Data Triggers
Trigger configure(user, ...)
if(IsSuperuser(user) == 0) then
return
end
SendTo(self,
'configure_behaviors',
0,
self,
user.id)
end
Trigger configure_behaviors(caller, user_id, all_scripts, offset)
-- Get user object
local user = GetObjectById(user_id)
if(IsSuperuser(user) == 0) then
return
end
-- UI Data
local history = {}
local ui_data = {}
-- Flag to show all scripts
if(all_scripts == nil) then
all_scripts = 0
end
if(offset == nil) then
offset = 0
end
-- Populate the window history table
local item = {name = 'Home',
icon = ICON.HOME}
table.insert(history, item)
-- Populate the window data table
local script_list = get_script_list(self, all_scripts)
-- Iterate through the script_list and add items to the window data table
for _, script_id in pairs(script_list) do
-- Get script data
-- TODO: Replace references in get_script_meta with apporpriate metadata information
local script_data = get_script_metadata(script_id)
-- Item to place into table
local item = {name = script_data.name,
icon = script_data.icon,
command = string.format('/event configure_behavior_properties %d %d %s %d',
self.id,
user_id,
script_id,
all_scripts),
bg_color = COLOR.BASE,
description = script_data.description}
-- Dim the background if the script has no properies
if(has_exposed_properties(script_id) == 0) then
item.bg_color = COLOR.DIM
end
table.insert(ui_data, item)
end
-- Draw main window
local display_area = main_window(self,
user_id,
WINDOW.WIDTH, WINDOW.HEIGHT,
string.format("Customize this %s",
self.type))
-- Draw window history
window_history(self,
user.smart_object_window,
history)
-- Draw bottom menu
local menu_bottom = UiFindWindow(user.smart_object_window,
'ox_menu_bottom')
local add_command = string.format('/event module_filtering %d %d',
self.id,
user_id)
local add_button = UiImageButton(menu_bottom,
'add_script_btn',
MENU.WIDTH - (BUTTON.DONE.WIDTH + BUTTON.ADD.WIDTH + 12 + BUTTON.SAVE.WIDTH), (MENU.HEIGHT - BUTTON.ADD.HEIGHT)/2,
BUTTON.ADD.WIDTH, BUTTON.ADD.HEIGHT,
BUTTON.ADD.NORMAL, BUTTON.ADD.HOVER, BUTTON.ADD.PRESS,
add_command)
local add_tooltip = UiWindow(menu_bottom,
'add_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(add_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, 'Add Script')
UiHoverWindow(add_button, add_tooltip, 500, 'below')
UiVisible(add_tooltip, 0, 0)
-- [J.McNab] Added for Save to Template functionality --
local save_command = string.format('/event save_to_template %d %d %d',
self.id,
user_id,
self.id)
local save_button = UiImageButton(menu_bottom,
'save_to_template_btn',
MENU.WIDTH - (BUTTON.SAVE.WIDTH + 8 + BUTTON.DONE.WIDTH),
(MENU.HEIGHT - BUTTON.SAVE.HEIGHT)/2,
BUTTON.SAVE.WIDTH, BUTTON.SAVE.HEIGHT,
BUTTON.SAVE.NORMAL, BUTTON.SAVE.HOVER, BUTTON.SAVE.PRESS,
save_command)
local done_command = string.format('ui_library_close_window %d',
user.smart_object_window)
local done_button = UiImageButton(menu_bottom,
'done_customizing_btn',
MENU.WIDTH - (BUTTON.DONE.WIDTH + 4), (MENU.HEIGHT - BUTTON.DONE.HEIGHT)/2,
BUTTON.DONE.WIDTH, BUTTON.DONE.HEIGHT,
BUTTON.DONE.NORMAL, BUTTON.DONE.HOVER, BUTTON.DONE.PRESS,
done_command)
local done_tooltip = UiWindow(menu_bottom,
'done_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(done_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, 'Finished Customizing')
UiHoverWindow(done_button, done_tooltip, 500, 'below')
UiVisible(done_tooltip, 0, 0)
-- Draw the Show All Checkbox
local show_all = ui_checkbox(menu_bottom,
UI_LIBRARY.CHECKBOX.WIDTH/2, MENU.HEIGHT/2 - UI_LIBRARY.CHECKBOX.HEIGHT/2,
all_scripts,
string.format('/event show_all_toggle %d %d',
self.id,
user_id)
)
local show_all_label = UiMultiLabel(menu_bottom,
'show_all_label',
UI_LIBRARY.CHECKBOX.WIDTH + INPUT.PADDING, -- X Location
MENU.HEIGHT/2 - UI_LIBRARY.CHECKBOX.HEIGHT/4 - (INPUT.HEIGHT)/2, -- Y Location
100, INPUT.HEIGHT * 1.5, -- Size
UI_LIBRARY.FONT.COLOR.RED,UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE, -- Foreground Color
0, 0, 0, 0, -- Background Color
0, 0, 0)
UiText(show_all_label, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
'Show All'))
-- Grab a subset of UI Data to pass to ui_thumbnail_window
local new_ui_data = {}
local item_num = 1
-- Set max number of items
local max_num = math.floor(THUMBNAIL.ROWS * 1.5)
-- Add the scrollbar
-- Paginate Data
local current_page = math.ceil(offset/#ui_data)
local max_page = math.floor(#ui_data/max_num)
if(math.fmod(#ui_data, max_num) == 0 and #ui_data <= max_num) then
max_page = max_page -1
end
local scroll_command = string.format('/event configure_behaviors %d %d %d',
self.id,
user_id,
all_scripts)
scrollbar(self, user_id, '-1:-1', display_area, current_page, max_page, max_num, scroll_command)
local new_display_area = UiWindow(display_area.id,
'display_area_2',
0, 0, -- Position
display_area.width - SCROLLBAR.WIDTH, display_area.height) -- Size
while(item_num + offset <= #ui_data and item_num <= max_num) do
table.insert(new_ui_data, ui_data[item_num + offset])
item_num = item_num + 1
end
if(#ui_data > 0) then
-- Draw the list window
ui_list_window(new_display_area,
display_area.width - SCROLLBAR.WIDTH, display_area.height,
max_num,
new_ui_data)
else
local message_title= UiMultiLabel(display_area.id,
'ox_message_window',
0, 20,
display_area.width - SCROLLBAR.WIDTH, 30,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 2)
local message_window = UiMultiLabel(display_area.id,
'ox_message_window',
28, 52,
display_area.width - SCROLLBAR.WIDTH - 56, display_area.height - 60,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 0)
local title = 'This object has no customizable behaviors.'
UiText(message_title, title)
local message = 'You may add new behaviors using the Add button at the bottom of the screen.'
local message_text = string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
message)
UiText(message_window, message_text)
end
end
Trigger configure_behavior_properties(caller, user_id, script_id, mode, offset)
local user = GetObjectById(user_id)
if(IsSuperuser(user) == 0) then
return
end
-- Set arguments to defaults if nil
if(all_scripts == nil) then
all_scripts = 0
end
if(mode == nil) then
mode = 0
end
if(offset == nil) then
offset = 0
end
-- Call custom config if exists
if(has_custom_config(script_id) == 1 and mode == 1) then
SendTo(self,
'custom_config',
0,
self,
user_id,
script_id,
offset)
return
end
-- Get user object
local user = GetObjectById(user_id)
local script_data = get_script_metadata(script_id)
local history = {}
local ui_data = {}
-- Populate the window history table
local item = {name = 'Home',
icon = ICON.HOME,
command = string.format('/event configure_behaviors %d %d',
self.id,
user_id)}
table.insert(history, item)
local item = {name = script_data.name,
icon = script_data.icon}
table.insert(history, item)
-- Iterate through script parameters
for _, param in pairs(stylesheet.scripts[script_id].exposed) do
-- Check to see if parameter is exposed
if(stylesheet.scripts[script_id].params[param].exposed == 1) then
-- Build data item
local item = {name = param,
icon = ICON.SCRIPT,
bg_color = COLOR.BASE,
description = stylesheet.scripts[script_id].params[param].comment,
user_type = get_param_user_type(self, script_id, param),
value = self[param]}
-- Attach data item into table
table.insert(ui_data, item)
end
end
-- Add UI metadata
ui_data.script_id = script_id
ui_data.mode = mode
ui_data.user_id = user_id
-- Draw main window
local display_area = main_window(self,
user_id,
WINDOW.WIDTH, WINDOW.HEIGHT,
string.format("Customize %s for %s", script_data.name, self.type))
-- Draw window history
window_history(self,
user.smart_object_window,
history)
-- Display advanced mode UI
-- Draw bottom menu
local menu_bottom = UiFindWindow(user.smart_object_window, 'ox_menu_bottom')
-- Add Remove Button
local remove_command = string.format('/event remove_script %d %d %s',
self.id,
user_id,
script_id)
local remove_button = UiImageButton(menu_bottom,
'remove_script_btn',
MENU.WIDTH - (BUTTON.REMOVE.WIDTH + 8 + BUTTON.DONE.WIDTH), (MENU.HEIGHT - BUTTON.REMOVE.HEIGHT)/2,
BUTTON.REMOVE.WIDTH, BUTTON.REMOVE.HEIGHT,
BUTTON.REMOVE.NORMAL, BUTTON.REMOVE.HOVER, BUTTON.REMOVE.PRESS,
remove_command)
local remove_tooltip = UiWindow(menu_bottom,
'remove_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(remove_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, 'Remove This Script')
UiHoverWindow(remove_button, remove_tooltip, 500, 'below')
UiVisible(remove_tooltip, 0, 0)
-- Buttons to pass to input window
local buttons = {}
-- Add Done Button
local done_command = string.format('set_multiple_params %d %d %s \'%s\'',
self.id,
user_id,
script_id,
string.format('ui_library_close_window %d', user.smart_object_window))
local done_button = UiImageButton(menu_bottom,
'done_customizing_btn',
MENU.WIDTH - (BUTTON.DONE.WIDTH + 4), (MENU.HEIGHT - BUTTON.DONE.HEIGHT)/2,
BUTTON.DONE.WIDTH, BUTTON.DONE.HEIGHT,
BUTTON.DONE.NORMAL, BUTTON.DONE.HOVER, BUTTON.DONE.PRESS,
done_command)
buttons.done = done_button
local done_tooltip = UiWindow(menu_bottom,
'done_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(done_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, 'Finished Customizing')
UiHoverWindow(done_button, done_tooltip, 500, 'below')
UiVisible(done_tooltip, 0, 0)
-- Paginate system for scripts
-- Get script list
local script_list = get_script_list(self, 0, mode)
if(#script_list < 1) then
script_list = get_script_list(self, 0)
end
-- Find this script in the script list
local current_script_index = 1
for index, script_list_id in pairs(script_list) do
if(script_list_id == script_id) then
current_script_index = index
end
end
-- Display basic button
if(has_custom_config(script_id) == 1) then
local basic_command_tmp = string.format('/event configure_behavior_properties %d %d %s 1',
self.id,
user_id,
script_id)
local basic_command = string.format('set_multiple_params %d %d %s \'%s\'',
self.id,
user_id,
script_id,
basic_command_tmp)
local basic_btn = UiImageButton(menu_bottom,
'basic_btn',
INPUT.PADDING, MENU.HEIGHT/2 - BUTTON.BASIC.HEIGHT/2,
BUTTON.BASIC.WIDTH, BUTTON.BASIC.HEIGHT,
BUTTON.BASIC.NORMAL, BUTTON.BASIC.HOVER, BUTTON.BASIC.PRESS,
basic_command)
end
-- Draw next and previous buttons
local next_command = ''
if(current_script_index + 1 <= #script_list) then
local next_command_tmp = string.format('/event configure_behavior_properties %d %d %s %d',
self.id,
user_id,
script_list[current_script_index + 1],
mode)
next_command = string.format('set_multiple_params %d %d %s \'%s\'',
self.id,
user_id,
script_id,
next_command_tmp)
end
local next_script_btn = UiImageButton(menu_bottom,
'next_script_btn',
MENU.WIDTH - BUTTON.DONE.WIDTH - BUTTON.REMOVE.WIDTH - BUTTON.NEXT.WIDTH - INPUT.PADDING * 3,
MENU.HEIGHT/2 - BUTTON.NEXT.HEIGHT/2,
BUTTON.NEXT.WIDTH, BUTTON.NEXT.HEIGHT,
BUTTON.NEXT.NORMAL, BUTTON.NEXT.HOVER, BUTTON.NEXT.PRESS,
next_command)
buttons.next = next_script_btn
if(next_command ~= '') then
local next_tooltip = UiWindow(menu_bottom,
'next_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(next_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
local next_script_data = get_script_metadata(script_list[current_script_index + 1])
UiText(tooltip_text, next_script_data.name)
UiHoverWindow(next_script_btn, next_tooltip, 500, 'below')
UiVisible(next_tooltip, 0, 0)
end
if(next_command == '') then
UiTint(next_script_btn, 128, 128, 128)
end
local prev_command = ''
if(current_script_index - 1 > 0) then
local prev_command_tmp = string.format('/event configure_behavior_properties %d %d %s %d',
self.id,
user_id,
script_list[current_script_index - 1],
mode)
prev_command = string.format('set_multiple_params %d %d %s \'%s\'',
self.id,
user_id,
script_id,
prev_command_tmp)
end
local prev_script_btn = UiImageButton(menu_bottom,
'prev_script_btn',
MENU.WIDTH - BUTTON.DONE.WIDTH - BUTTON.REMOVE.WIDTH - BUTTON.NEXT.WIDTH - BUTTON.PREVIOUS.WIDTH - INPUT.PADDING * 4,
MENU.HEIGHT/2 - BUTTON.PREVIOUS.HEIGHT/2,
BUTTON.PREVIOUS.WIDTH, BUTTON.PREVIOUS.HEIGHT,
BUTTON.PREVIOUS.NORMAL, BUTTON.PREVIOUS.HOVER, BUTTON.PREVIOUS.PRESS,
prev_command)
buttons.prev = prev_script_btn
if(prev_command ~= '') then
local prev_tooltip = UiWindow(menu_bottom,
'prev_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(prev_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
local prev_script_data = get_script_metadata(script_list[current_script_index - 1])
UiText(tooltip_text, prev_script_data.name)
UiHoverWindow(prev_script_btn, prev_tooltip, 500, 'below')
UiVisible(prev_tooltip, 0, 0)
end
if(prev_command == '') then
UiTint(prev_script_btn, 128, 128, 128)
end
if(#ui_data > 0) then
-- Draw input window
input_window(self,
user_id,
display_area,
buttons,
ui_data,
mode,
offset)
else
local message_title= UiMultiLabel(display_area.id,
'ox_message_window',
0, 20,
display_area.width, 30,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 2)
local message_window = UiMultiLabel(display_area.id,
'ox_message_window',
28, 52,
display_area.width - 64, display_area.height - 50,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 0)
local title = 'This behavior has nothing to configure.'
UiText(message_title, title)
local message = 'You may remove the script using the Remove button at the bottom of the screen or return to the behavior list window.'
local message_text = string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
message)
UiText(message_window, message_text)
end
end
-----------------------------------------------------------------------------------------------------------------------------
-- DATA TRIGGERS --
-----------------------------------------------------------------------------------------------------------------------------
Trigger set_multiple_params(caller, user_id, script_id, window_id, param_table)
local user = GetObjectById(user_id)
DoCommand(user, 'ui_library_close_window', window_id)
end
-- Set a scripts parameter
Trigger set_script_param(caller, user_id, script_id, param, value)
-- Get user
local user = GetObjectById(user_id)
if(IsSuperuser(user) == 0) then
return
end
-- NOTE: Only super users should be able to set script parameters
if(IsSuperuser(user) == 0) then
return
end
-- Universal script parameter setting
SetScriptParam(self, script_id, param, value)
SendTo(self,
'param_changed',
0,
self.id,
user_id,
script_id,
param)
end
Trigger checkbox_set_script_param(caller, user_id, script_id, param, value)
SendTo(self,
'set_script_param',
100,
self.id,
user_id,
script_id,
param,
value)
end
Trigger save_to_template(caller, user_id, object_id, resave)
local user = GetObjectById(user_id)
clear_ui(user)
window_width = 300
window_height = 100
local window = ui_default_window(0,
'save_name_dialogue',
0, 0,
window_width, window_height)
local dialogue = UiMultiLabel(window,
'dialogue',
6, 30,
window_width - 12, 50,
0, 0, 0,
0, 0, 0, 0,
0, 0, 2)
if(resave == nil) then
UiText(dialogue, 'Please enter a name for this new template')
else
UiText(dialogue, 'Template already exists.
Please enter a name for this new template')
end
local text_command = string.format('/event save_to_template_name_check %d %d %d',
self.id,
user_id,
object_id)
local text_input = UiTextField(window,
'text_input',
8, 70,
window_width - 16, 20,
0, 0, 0,
255, 255, 255, 1,
text_command)
user.smart_object_window = window
UiAlign(window, 0, 0, 'center', 'scale_none')
UiAttachUser(user, window)
end
Trigger save_to_template_name_check(caller, user_id, object_id, name)
for _, template_id in pairs(stylesheet.templates._all_) do
local template = stylesheet.templates[template_id]
if(template.name == name) then
SendTo(self, 'save_to_template', 0, self, user_id, object_id, 1)
return
end
end
local user = GetObjectById(user_id)
DoCommand(user,
'template_from_object',
object_id,
name)
clear_ui(user)
end
Trigger slider_set_value(caller, user_id, script_id, param, window_id, value)
UiText(window_id, tostring(value))
SendTo(self,
'set_script_param',
0,
self.id,
user_id,
script_id,
param,
value)
end
-- Item selected from a selector
Trigger select_from_selector(caller, user_id, script_id, param, mode, offset, value)
if(script_id ~= 'none') then
SendTo(self,
'set_script_param',
0,
self,
user_id,
script_id,
param,
value)
SendTo(self,
'configure_behavior_properties',
0,
self,
user_id,
script_id,
mode,
offset)
else
AttachScriptById(self, value)
SendTo(self,
'configure_behavior_properties',
0,
self,
user_id,
value)
end
end
-- Remove a script from the object
Trigger remove_script(caller, user_id, script_id)
-- Get User
local user = GetObjectById(user_id)
-- Should not run if the user isn't a super user
if(IsSuperuser(user) == 0) then
return
end
DetachScriptById(self, script_id)
SendTo(self,
'configure_behaviors',
0,
self,
user_id)
end
-----------------------------------------------------------------------------------------------------------------------------
-- PICKER TRIGGERS --
-----------------------------------------------------------------------------------------------------------------------------
Trigger module_filtering(caller, user_id, offset)
-- Get User
local user = GetObjectById(user_id)
if(offset == nil) then
offset = 0
end
local history = {}
local ui_data = {}
local module_list = {}
local default_icon = ICON.SCRIPT
local base_command = string.format('/event selector %d %d \'none\' \'none\' 0 0 \'scripts\'',
self.id,
user_id)
local item = {name = 'Return',
icon = ICON.RETURN,
command = string.format('/event configure_behaviors %d %d',
self.id,
user_id)}
table.insert(ui_data, item)
-- Add 'All' item
local item = {name = 'All',
icon = default_icon,
command = string.format('%s %s',
base_command,
''),
bg_color = COLOR.BASE}
table.insert(module_list, item)
-- Add 'My Stuff' item
local item = {name = 'My Stuff',
icon = default_icon,
command = string.format('%s %s',
base_command,
'0:'),
bg_color = COLOR.BASE}
table.insert(module_list, item)
for _, module_id in pairs(stylesheet.modules._all_) do
local module = stylesheet.modules[module_id]
local labels = module.labels
local id = module.worldId
for _, tag in pairs(labels) do
if(tag == 'behavior_lib') then
local item = {name = module.name,
icon = default_icon,
command = string.format('%s %s',
base_command,
tostring(id) .. ':'),
bg_color = COLOR.BASE}
table.insert(module_list, item)
end
end
end
local item_num = 1
local rows = 8
while (item_num < rows - 1 and item_num + offset < #module_list + 1) do
table.insert(ui_data, module_list[item_num + offset])
item_num = item_num + 1
end
-- Draw main window
local display_area = main_window(self,
user_id,
WINDOW.WIDTH,
WINDOW.HEIGHT,
string.format("Select a Behavior Library", selector_name))
-- Get new display area to make room for instructions
local param_comments_height = 30
local new_display_area = UiElement(display_area.id,
'thumbnail_area',
0, param_comments_height)
local param_info = UiMultiLabel(display_area.id,
'param_comment',
0, 0,
display_area.width - SCROLLBAR.WIDTH, param_comments_height,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 2)
param_info_text = string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
'Please select a behavior library')
UiText(param_info, param_info_text)
-- Display as a list
ui_list_window(new_display_area,
display_area.width - SCROLLBAR.WIDTH, display_area.height - 36, -- Size
rows, -- Rows
ui_data) -- UI Data
-- Add a scrollbar
local max_num = rows - 2
-- Paginate Data
local current_page = math.floor(offset/max_num)
local max_page = math.floor(#module_list/max_num)
if(math.fmod(#ui_data, max_num) == 0 and #ui_data > max_num) then
max_page = max_page -1
end
local scroll_command = string.format('/event module_filtering %d %d',
self.id,
user_id)
scrollbar(self,
user_id,
script_id,
display_area,
current_page,
max_page,
max_num,
scroll_command,
1)
-- Populate the window history table
local item = {name = 'Home',
icon = ICON.HOME,
command = string.format('/event configure_behaviors %d %d',
self.id,
user_id)}
table.insert(history, item)
-- Draw window history
window_history(self, user.smart_object_window, history)
local menu_bottom = UiFindWindow(user.smart_object_window,
'ox_menu_bottom')
local done_command = string.format('ui_library_close_window %d',
user.smart_object_window)
local done_button = UiImageButton(menu_bottom,
'done_customizing_btn',
MENU.WIDTH - (BUTTON.DONE.WIDTH + 4), (MENU.HEIGHT - BUTTON.DONE.HEIGHT)/2,
BUTTON.DONE.WIDTH, BUTTON.DONE.HEIGHT,
BUTTON.DONE.NORMAL, BUTTON.DONE.HOVER, BUTTON.DONE.PRESS,
done_command)
local done_tooltip = UiWindow(menu_bottom,
'done_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(done_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT + 10,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, 'Finished Customizing')
UiHoverWindow(done_button, done_tooltip, 500, 'below')
UiVisible(done_tooltip, 0, 0)
end
Trigger selector(caller, user_id, script_id, param, mode, parent_offset, selector_type, module_filter, filter, offset)
-- Get User
local user = GetObjectById(user_id)
if(filter ~= nil) then
if(string.len(filter) > 1) then
filter = string.gsub(filter, '\'', '')
end
end
if(module_filter ~= nil) then
if(string.len(module_filter) > 1) then
module_filter = string.gsub(module_filter, '\'', '')
end
end
local selector_name = string.upper(string.sub(selector_type, 1, 1)) .. string.lower(string.sub(selector_type, 2, string.len(selector_type) - 1))
-- Set window data
local history = {}
local ui_data = {}
local script_data = get_script_metadata(script_id)
-- Set Defaults
if (filter == nil) then
filter = ''
end
if(offset == nil) then
offset = 0
end
-- Set default Icon for selector type
local default_icon = ''
if(selector_type == 'sprites') then
default_icon = ICON.SPRITE
end
if(selector_type == 'sounds') then
default_icon = ICON.SOUND
end
if(selector_type == 'templates') then
default_icon = ICON.TEMPLATE
end
if(selector_type == 'scripts') then
default_icon = ICON.SCRIPT
end
-- Populate the window history table
local item = {name = 'Home',
icon = ICON.HOME,
command = string.format('/event configure_behaviors %d %d',
self.id,
user_id)}
table.insert(history, item)
if(script_id ~= 'none') then
local item = {name = script_data.name,
icon = script_data.icon,
command = string.format('/event configure_behavior_properties %d %d %s %d %d',
self.id,
user_id,
script_id,
mode,
parent_offset)}
table.insert(history, item)
end
local item = {name = selector_name,
icon = default_icon,
command = string.format('/event selector %d %d %s %s %d %d %s',
self.id,
user_id,
script_id,
param,
mode,
parent_offset,
selector_type)}
table.insert(history, item)
-- Populate UI Data
-- Add 'Reset' option
local reset_value = ''
if(script_id ~= 'none') then
reset_value = stylesheet.scripts[script_id].params[param].value
end
local item = {name = 'Reset',
icon = ICON.RESET,
command = string.format('/event select_from_selector %d %d %s %s %d %d %s',
self.id,
user_id,
script_id,
param,
mode,
parent_offset,
reset_value)}
if(script_id == 'none') then
item.name = 'Return'
item.icon = ICON.RETURN
item.command = string.format('/event module_filtering %d %d',
self.id,
user_id)
end
table.insert(ui_data, item)
-- Iterate through the appropriate stylesheet data
local parent_data = stylesheet[selector_type]
for _, item_id in pairs(parent_data._all_) do
-- Get Name
local name = ''
local script_item_data = {}
if(selector_type == 'scripts') then
script_item_data = get_script_metadata(item_id)
name = script_item_data.name
else
name = parent_data[item_id].name
end
local module_id = ''
if(selector_type == 'scripts') then
module_id = stylesheet.scripts[item_id].id
module_id = string.gsub(module_id, ':(.+)', '') .. ':'
end
if(module_filter == nil) then
module_filter = ''
end
-- Check to see if the filter is part of the name
if(string.find(string.lower(name), string.lower(filter)) ~= nil and
string.find(module_id, module_filter) ~= nil) then
-- Add data name
local item = {name = name}
-- Add data icon
if(selector_type == 'sounds') then
item.icon = default_icon
end
if(selector_type == 'sprites') then
item.icon = item_id
end
if(selector_type == 'scripts') then
item.icon = script_item_data.icon
end
if(selector_type == 'templates') then
item.icon = parent_data[item_id].spriteId
if(item.icon == nil or string.sub(item.icon, -2) == '-1') then
item.icon = default_icon
end
end
item.value = item_id
-- Set item command
item.command = string.format('/event select_from_selector %d %d %s %s %d %d %s',
self.id,
user_id,
script_id,
param,
mode,
parent_offset,
item_id)
-- Set item background color
item.bg_color = COLOR.BASE
table.insert(ui_data, item)
end
end
-- Draw main window
local display_area = main_window(self,
user_id,
WINDOW.WIDTH,
WINDOW.HEIGHT,
string.format("Select a %s", selector_name))
-- Get new display area to make room for scrollbars
local param_comments_height = 30
local new_display_area = UiElement(display_area.id,
'thumbnail_area',
0, param_comments_height)
local param_info = UiMultiLabel(display_area.id,
'param_comment',
0, 0,
display_area.width - SCROLLBAR.WIDTH, param_comments_height,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 2)
local param_info_text = ''
if(selector_type ~= 'scripts') then
param_info_text = string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
stylesheet.scripts[script_id].params[param].comment)
else
param_info_text = string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
'Please select a script to add to this object')
end
UiText(param_info, param_info_text)
-- Draw window history
window_history(self, user.smart_object_window, history)
-- Grab a subset of UI Data to pass to ui_thumbnail_window
local new_ui_data = {}
local item_num = 1
-- Set max number of items
local max_num = 0
if(selector_type == 'sprites') then
max_num = THUMBNAIL.ROWS * THUMBNAIL.COLS
else
max_num = math.floor(THUMBNAIL.ROWS * 1.5)
end
while(item_num + offset <= #ui_data and item_num <= max_num) do
table.insert(new_ui_data, ui_data[item_num + offset])
item_num = item_num + 1
end
-- Add the scrollbar
-- Paginate Data
local current_page = math.floor(offset/max_num)
local max_page = math.floor(#ui_data/max_num)
if(math.fmod(#ui_data, max_num) == 0 and #ui_data > max_num) then
max_page = max_page -1
end
local scroll_command = string.format('/event selector %d %d %s %s %d %d %s \'%s\' \'%s\'',
self.id,
user_id,
script_id,
param,
mode,
parent_offset,
selector_type,
module_filter,
filter)
scrollbar(self,
user_id,
script_id,
display_area,
current_page,
max_page,
max_num,
scroll_command)
-- Draw a thumbnail or list window
if(selector_type == 'sprites') then
ui_thumbnail_window(new_display_area,
display_area.width - SCROLLBAR.WIDTH, display_area.height - param_comments_height, -- Size
THUMBNAIL.ROWS, THUMBNAIL.COLS, -- Cols and Rows
new_ui_data) -- UI Data
else
ui_list_window(new_display_area,
display_area.width - SCROLLBAR.WIDTH, display_area.height - param_comments_height, -- Size
max_num, -- Rows
new_ui_data) -- UI Data
end
-- Filter system
local filter_label = UiMultiLabel(display_area.id,
'filter_label',
0, display_area.height + MENU.HEIGHT/2 - 10,
60, 26,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 1)
UiText(filter_label, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
'Search:'))
local filter_command = string.format('/event filter_selector %d %d %s %s %d %d %s %s',
self.id,
user_id,
script_id,
param,
mode,
parent_offset,
selector_type,
module_filter)
local filter_system = UiTextField(filter_label,
'filter_input',
60, 3,
70, INPUT.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.INPUT.BG_COLOR.RED, UI_LIBRARY.INPUT.BG_COLOR.GREEN,
UI_LIBRARY.INPUT.BG_COLOR.BLUE, UI_LIBRARY.INPUT.BG_COLOR.ALPHA,
filter_command,
filter)
-- Play Sound Buttons
if(selector_type == 'sounds') then
local item_size = display_area.height/ max_num
local play_index = 1
for play_index = 1, #new_ui_data, 1 do
if(new_ui_data[play_index].name ~= 'Reset') then
local play_icon = UiFindWindow(new_display_area, 'list_' .. play_index)
if(play_icon ~= 0) then
local play_sound_command = string.format('/event play_sound %d %d %s',
self.id,
user_id,
new_ui_data[play_index].value)
local play_sound_bg = UiImage(play_icon,
'play_sound_bg_' .. item.name,
display_area.width - item_size, item_size/2 - item_size/4,
item_size/2, item_size/2,
ICON.BACKGROUND)
local play_sound_icon = UiImage(play_sound_bg,
'play_sound_' .. item.name .. '_icon',
item_size/4 - BUTTON.PLAY.WIDTH/2, item_size/4 - BUTTON.PLAY.HEIGHT/2,
BUTTON.PLAY.WIDTH, BUTTON.PLAY.HEIGHT,
BUTTON.PLAY.NORMAL)
local play_btn = UiImageButton(play_sound_bg,
'play_sound_' .. item.name .. '_btn',
0, 0,
item_size/2, item_size/2,
ICON.BACKGROUND, ICON.BACKGROUND, ICON.BACKGROUND,
play_sound_command)
UiColor(play_btn, 0, 0, 0, 0)
end
end
end
end
end
-- Reorder arguments and send back to Selector
Trigger filter_selector(caller, user_id, script_id, param, mode, parent_offset, selector_type, module_filter, filter)
SendTo(self,
'selector',
0,
self,
user_id,
script_id,
param,
mode,
parent_offset,
selector_type,
module_filter,
filter,
0)
end
Trigger play_sound(caller, user_id, sound_id)
local user = GetObjectById(user_id)
PlaySoundTo(user, sound_id, 100, 0)
end
-----------------------------------------------------------------------------------------------------------------------------
-- UI TRIGGERS --
-----------------------------------------------------------------------------------------------------------------------------
-- Toggle the showing/hiding of all scripts
Trigger show_all_toggle(caller, user_id, value)
SendTo(self,
'configure_behaviors',
100,
self,
user_id,
value)
end
-- Show a list window (Used for parameters with user_type of list)
Trigger show_list_window(caller, user_id, script_id, param, parent_id, parent_width, parent_height)
-- Get user
local user = GetObjectById(user_id)
-- Pack display data
local display_area = {id = parent_id,
width = parent_width,
height = parent_height}
local command = string.format('/event list_window_selection %d %d %s %s %d',
self.id,
user_id,
script_id,
param,
display_area.id)
local list = self[param .. '_list']
list.name = param
-- Call list function
list_window(self, display_area, list, command)
end
-- Make a selection from a list window
Trigger list_window_selection(caller, user_id, script_id, param, window_id, value)
local list_window = UiFindWindow(window_id, 'list_selection_' .. param)
UiDelete(list_window)
local text_field = UiFindWindow(window_id, 'list_input_item_' .. param)
UiText(text_field, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
value))
SendTo(self,
'set_script_param',
0,
self,
user_id,
script_id,
param,
value)
end
Trigger show_table_window(caller, user_id, script_id, param, parent_id, parent_width, parent_height)
-- Get User
local user = GetObjectById(user_id)
-- Pack Display data
local display_area = {id = parent_id,
width = parent_width,
height = parent_height}
-- Command attached to list
local command = string.format('/event table_window_selection %d %d %s %s %d %d %d',
self.id,
user_id,
script_id,
param,
parent_id,
parent_width,
parent_height)
-- Populate data table
local list = table.deepcopy(self[param])
list.name = param
list.add = 'Add New'
list_window(self, display_area, list, command, 1)
end
Trigger table_window_selection(caller, user_id, script_id, param, parent_window, parent_width, parent_height, index)
-- Get User
local user = GetObjectById(user_id)
-- Delete last input if one still exists
local input_window = UiFindWindow(parent_window, 'input_item_' .. param)
if(input_window ~= 0) then
UiDelete(input_window)
end
-- Draw input window
-- Position/Sizing info
local size_x = parent_width * (2/3)
local size_y = parent_height * (2/3)
local pos_x = 0
local pos_y = size_y
-- Get parent for window
local input_parent = UiFindWindow(parent_window, 'list_selection_' .. param)
local input_window = UiWindow(input_parent,
'input_item_' .. param,
pos_x, pos_y,
size_x, INPUT.HEIGHT * 2,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
-- Draw text input field
input_command = string.format('/event table_window_input %d %d %s %s %d %d %d %s',
self.id,
user_id,
script_id,
param,
parent_window,
parent_width,
parent_height,
index)
local item_input = UiTextField(input_window,
'input_item_' .. param .. '_input',
INPUT.HEIGHT/2, INPUT.HEIGHT/2,
size_x - INPUT.HEIGHT - 18, INPUT.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.INPUT.BG_COLOR.RED, UI_LIBRARY.INPUT.BG_COLOR.GREEN, UI_LIBRARY.INPUT.BG_COLOR.BLUE, UI_LIBRARY.INPUT.BG_COLOR.ALPHA,
input_command)
local remove_item_command = string.format('/event table_remove_item %d %d %s %s %d %d %d %s',
self.id,
user_id,
script_id,
param,
parent_window,
parent_width,
parent_height,
index)
local remove_item = UiImageButton(input_window,
'input_item_' .. param .. '_remove',
size_x - 14 - INPUT.HEIGHT/2, INPUT.HEIGHT - 8,
16, 16,
UI_LIBRARY.DELETE.NORMAL, UI_LIBRARY.DELETE.HOVER, UI_LIBRARY.DELETE.PRESS,
remove_item_command)
local remove_tooltip = UiWindow(input_window,
'remove_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(remove_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, 'Remove Item')
UiHoverWindow(remove_item, remove_tooltip, 500, 'below')
UiVisible(remove_tooltip, 0, 0)
-- Place value into input field
local current_value = ''
if(index ~= 'add' and self[param][index] ~= nil) then
current_value = self[param][index]
end
UiText(item_input, string.format('%s', current_value))
end
Trigger table_window_input(caller, user_id, script_id, param, parent_window, parent_width, parent_height, index, value)
-- Duplicate the current table into a new table
local new_table= table.deepcopy(self[param])
-- If not new, modify. If new, add
if(index ~= 'add') then
new_table[index] = value
else
table.insert(new_table, tostring(value))
end
-- Update displays
SendTo(self,
'set_script_param',
0,
self,
user_id,
script_id,
param,
table.tostring(new_table))
SendTo(self,
'show_table_window',
0,
self,
user_id,
script_id,
param,
parent_window,
parent_width,
parent_height)
SendTo(self,
'table_window_selection',
0,
self,
user_id,
script_id,
param,
parent_window,
parent_width,
parent_height,
index)
end
Trigger table_remove_item(caller, user_id, script_id, param, parent_window, parent_width, parent_height, index)
-- Duplicate the current table into a new table
local new_table = table.deepcopy(self[param])
-- Remove the entry if it exists
if(new_table[index] ~= nil) then
table.remove(new_table, index)
end
-- Update the displays
SendTo(self,
'set_script_param',
0,
self,
user_id,
script_id,
param,
table.tostring(new_table))
SendTo(self,
'show_table_window',
0,
self,
user_id,
script_id,
param,
parent_window,
parent_width,
parent_height)
SendTo(self,
'table_window_selection',
0,
self,
user_id,
script_id,
param,
parent_window,
parent_width,
parent_height,
index)
end
Trigger color_selector(caller, user_id, script_id, param, parent_window, parent_width, parent_height, offset)
-- Set the command sent to the color picker
local color_command = string.format('/event color_selected %d %d %s %s %d',
self.id,
user_id,
script_id,
param,
offset)
local color_selector_color = self[param]
color_selector_color.alpha = color_selector_color.alpha * 100
-- Window positioning values
local size_x = parent_width * (2/3)
local size_y = parent_height * (2/3)
local pos_x = parent_width/2 - size_x/2
local pos_y = parent_height/2 - size_y/2
local image = PALETTE.IMAGE
if(has_property(script_id, 'color_palette') == 1) then
image = stylesheet.scripts[script_id].params['color_palette'].value
end
-- Color Picker Window
local color_picker_window = ui_color_picker(parent_window,
pos_x,
pos_y,
PALETTE.WIDTH,
PALETTE.HEIGHT,
image,
color_command,
self[param])
end
Trigger color_selected(caller, user_id, script_id, param, offset, red, green, blue, alpha)
local color = {red = red,
green = green,
blue = blue,
alpha = alpha}
SendTo(self,
'set_script_param',
0,
self,
user_id,
script_id,
param,
table.tostring(color))
SendTo(self,
'configure_behavior_properties',
0,
self,
user_id,
script_id,
offset)
end
Trigger close_ui_all(self, user_id)
local user = GetObjectById(user_id)
if(user == nil) then
return
end
clear_ui(user)
end
-- Functions
-----------------------------------------------------------------------------------------------------------------------------
-- DATA RETRIEVAL FUNCTIONS --
-----------------------------------------------------------------------------------------------------------------------------
-- Returns a table of the current
-- NOTE: mode determines basic/advanced script listing. (Basic = 1, Advanced = Non-1)
function get_script_list(self, all_scripts, mode, first_loading)
-- Get script list
local scripts = GetScriptList(self)
local return_list = {}
if(all_scripts == nil) then
all_scripts = 0
end
-- Iterate through scripts
for _, script_id in pairs(scripts) do
if(has_exposed_properties(script_id) == 1 or all_scripts == 1) then
if(mode ~= 1) then
table.insert(return_list, script_id)
else
if(has_custom_config(script_id) == 1) then
if(first_loading ~= 1) then
table.insert(return_list, script_id)
else
if(has_property(script_id, 'script_load_first') == 1) then
table.insert(return_list, script_id)
end
end
end
end
end
end
table.sort(return_list,
function(a,b)
return get_script_metadata(a).name < get_script_metadata(b).name
end)
return return_list
end
function has_custom_config(script_id)
-- Get script from stylesheet
local script = stylesheet.scripts[script_id]
-- Iterate through triggers
for _, trigger in pairs(script.triggers._all_) do
-- Custom config trigger found
if(trigger == 'trg_custom_config') then
return 1
end
end
-- No custom config trigger found
return 0
end
-- Check to see if a script has exposed properties
function has_exposed_properties(script_id)
-- Get script from stylesheet
local script = stylesheet.scripts[script_id]
-- Iterate through parameters
for _, param_name in pairs(script.params._all_) do
local param = script.params[param_name]
-- At least one exposed parameter found
if(param.exposed == 1) then
return 1
end
end
-- No exposed paramters found
return 0
end
-- Returns an appropriate sprite to represent the object
function get_object_sprite(object)
if(HasScriptById(object, AVATAR_MOVEMENT_SCRIPT) == 1) then
return ICON.DEFAULT
else
return object.spriteId
end
return nil
end
-- Returns the user_type of a script parameter
function get_param_user_type(self, script_id, param)
local user_type = stylesheet.scripts[script_id].params[param].user_type
if(type(self[param]) == 'table' and user_type ~= 'color') then
return 'table'
else
return user_type
end
return nil
end
-- TODO: Replace with script metadata
function get_script_metadata(script_id)
-- Build a base return table
if(script_id == 'none') then
return
end
local return_table = {name = stylesheet.scripts[script_id].name,
description = '',
icon = ICON.SCRIPT}
-- Iterate through script parameters look for appropriate properties
for _, param in pairs(stylesheet.scripts[script_id].params._all_) do
if(param == 'script_description') then
return_table.name = stylesheet.scripts[script_id].params[param].value
end
if(param == 'script_long_description') then
return_table.description = stylesheet.scripts[script_id].params[param].value
end
if(param == 'script_icon') then
return_table.icon = stylesheet.scripts[script_id].params[param].value
end
if(param == 'script_load_first') then
return_table.first_load = 1
end
end
if(string.len(stylesheet.scripts[script_id].shortDescription) > 1) then
return_table.name = stylesheet.scripts[script_id].shortDescription
end
if(stylesheet.scripts[script_id].iconId ~= '0:0') then
return_table.icon = stylesheet.scripts[script_id].iconId
end
return return_table
end
function has_property(script_id, name)
for _, param in pairs(stylesheet.scripts[script_id].params._all_) do
if(param == name) then
return 1
end
end
return 0
end
function module_in_world(module_id)
for _, module in pairs(stylesheet.modules._all_) do
if(tostring(module_id) == tostring(module)) then
return 1
end
end
return 0
end
-----------------------------------------------------------------------------------------------------------------------------
-- UI FUNCTIONS --
-----------------------------------------------------------------------------------------------------------------------------
-- Draw the main window
function main_window(self, user_id, width, height, title, custom)
-- Get user object
local user = GetObjectById(user_id)
-- Remove last window if it exists
clear_ui(user)
-- Set Custom Flag
if(custom == nil) then
custom = 0
end
-- Draw the Main Window
local main_window = ui_default_window(0, 'ox_main_window', 0, 0, width, height)
UiCapability(main_window, 'drag')
-- Add a title to the window
local main_title = 0
if(title ~= nil) then
main_title = UiMultiLabel(main_window,
'ox_title',
2, 0,
width - 64, 24,
UI_LIBRARY.TITLE.COLOR.RED, UI_LIBRARY.TITLE.COLOR.GREEN, UI_LIBRARY.TITLE.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 0)
UiText(main_title, string.format('%s',
UI_LIBRARY.TITLE.FONT_SIZE,
UI_LIBRARY.FONT.FACE,
title))
end
-- Add the top and bottom menu areas
local menu_width = MENU.WIDTH
if(custom == 1) then
menu_width = width - (WINDOW.WIDTH - MENU.WIDTH)
end
local menu_top = UiWindow(main_window,
'ox_menu_top',
(width - menu_width)/2, 30,
menu_width, MENU.HEIGHT)
local menu_top_bg = UiRect(menu_top,
'ox_menu_top_bg',
0, 0,
menu_width, MENU.HEIGHT)
UiColor(menu_top_bg,
COLOR.MENU_BG.RED,
COLOR.MENU_BG.GREEN,
COLOR.MENU_BG.BLUE,
COLOR.MENU_BG.ALPHA)
local menu_bottom = UiWindow(main_window,
'ox_menu_bottom',
(width - menu_width)/2, height - (MENU.HEIGHT + 8),
menu_width, MENU.HEIGHT)
local menu_bottom_bg = UiRect(menu_bottom,
'ox_menu_bottom_bg',
0, 0,
menu_width, MENU.HEIGHT)
UiColor(menu_bottom_bg,
COLOR.MENU_BG.RED,
COLOR.MENU_BG.GREEN,
COLOR.MENU_BG.BLUE,
COLOR.MENU_BG.ALPHA)
-- Create inner window area (used by other UI elements)
local display_area = UiWindow(main_window,
'ox_display_area',
8, 31 + MENU.HEIGHT,
width - 16, height - (MENU.HEIGHT * 2 + 39))
user.smart_object_window = main_window
-- Position window in last location unless new user
if(user.smart_object_window_coords.x ~= -1 and user.smart_object_window_coords.y ~= -1) then
UiPosition(main_window,
user.smart_object_window_coords.x, user.smart_object_window_coords.y)
else
UiAlign(main_window, 0, 0, 'top_right', 'scale_none')
end
UiAttachUser(user, main_window)
return {id = display_area, width = width - 16, height = height - (MENU.HEIGHT * 2 + 40)}
end
function window_history(self, window_id, history_data)
-- Get Top Menu
local menu_top = UiFindWindow(window_id, 'ox_menu_top')
if(menu_top == 0) then
Debug("Could not locate top menu")
return
end
local x_location = 0
local history_num = 1
for _, history_item_data in pairs(history_data) do
local history_item = UiElement(menu_top,
'history_item_' .. history_item_data.name,
x_location, 1)
local history_icon = ui_draw_icon(history_item,
history_item_data.icon,
MENU.HEIGHT,
MENU.HEIGHT,
2)
-- Add the command button
if(history_item_data.command ~= nil) then
local history_command_btn = UiImageButton(history_item,
'history_item_' .. history_item_data.name .. '_btn',
0, 0,
MENU.HEIGHT, MENU.HEIGHT,
ICON.EMPTY, ICON.EMPTY, ICON.EMPTY,
history_item_data.command)
UiColor(history_command_btn,
0,
0,
0,
0)
end
-- Add the seperator
if(history_num < #history_data) then
local history_next_tick = UiImage(history_item,
'history_item_next',
MENU.HEIGHT + 1, MENU.HEIGHT / 2 - 4,
4, 8,
ICON.HISTORY_NEXT)
end
x_location = x_location + MENU.HEIGHT + 4
history_num = history_num + 1
end
-- Draw the ID icon
local id_icon = UiElement(menu_top,
'id_icon',
MENU.WIDTH - MENU.HEIGHT - 4, 1)
local id_icon_img = ui_draw_icon(id_icon,
self.spriteId,
MENU.HEIGHT,
MENU.HEIGHT,
2)
-- Add thumbnails
for _, history_item_data in pairs(history_data) do
local history_element = UiFindWindow(menu_top, 'history_item_' .. history_item_data.name)
local tooltip = UiWindow(menu_top,
'history_tooltip_' .. history_item_data.name,
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(tooltip_text, history_item_data.name)
UiHoverWindow(history_element, tooltip, 500, 'right')
UiVisible(tooltip, 0, 0)
end
end
function input_window(self, user_id, display_area, form_button, window_data, mode, offset)
-- Get user
local user = GetObjectById(user)
-- Set offset to default if nil
if(offset == nil) then
offset = 0
end
-- Initialize input window values
local item_num = 0
local item_size = (display_area.height - INPUT.PADDING * INPUT.ITEMS) / INPUT.ITEMS
-- NOTE: List windows need to be drawn last on the OX so that they are above other items
local list_items = {}
-- Sort window_data by name
--[[
table.sort(window_data, function(a,b)
return a.name < b.name
end)
--]]
local scroll_command = string.format('/event configure_behavior_properties %d %d %s %d',
self.id,
window_data.user_id,
window_data.script_id,
window_data.mode)
-- Paginate Data
local current_page = math.floor(offset/INPUT.ITEMS)
local max_page = math.floor(#window_data/INPUT.ITEMS)
if(math.fmod(#window_data, INPUT.ITEMS) == 0 and #window_data > INPUT.ITEMS) then
max_page = max_page - 1
end
scrollbar(self, user_id, window_data.script_id, display_area, current_page, max_page, INPUT.ITEMS, scroll_command)
while(item_num + offset <= #window_data and item_num < INPUT.ITEMS) do
-- Get window data item
local item = window_data[item_num + 1 + offset]
if(item ~= nil) then
-- Calculate window width wtih scroll bar
local window_width = display_area.width - SCROLLBAR.WIDTH
-- Calculate positioning data
local position_x = 0
local position_y = INPUT.PADDING/2 + item_num * (item_size + INPUT.PADDING)
-- Draw container element
local item_ui_element = UiElement(display_area.id,
'input_item_' .. item_num,
position_x, position_y)
if(math.fmod(item_num, 2) == 1) then
local bg = UiRect(item_ui_element,
'input_item_' .. item_num .. '_bg',
0, 0,
window_width, item_size + INPUT.PADDING/2)
UiColor(bg,
255,
255,
255,
.4)
end
-- Item description
local item_name = 0
-- Display item. If user_type is none, then display a text input line. Otherwise, display appropriate input options
if(item.user_type == 'none' or item.user_type == 'int') then
local input_command = string.format('/event set_script_param %d %d %s %s',
self.id,
user_id,
window_data.script_id,
item.name)
local item_data = stylesheet.scripts[window_data.script_id].params[item.name]
-- Place a text input option
if(item_data.range_min == item_data.range_max) then
item_name = UiMultiLabel(item_ui_element,
'input_item_' .. item_num .. '_name',
0, 0,
window_width, item_size * 2/3,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN, UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 0)
local item_input = UiTextField(item_ui_element,
item.name,
4, item_size - 2 - INPUT.HEIGHT,
window_width - 9, INPUT.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.INPUT.BG_COLOR.RED, UI_LIBRARY.INPUT.BG_COLOR.GREEN,
UI_LIBRARY.INPUT.BG_COLOR.BLUE, UI_LIBRARY.INPUT.BG_COLOR.ALPHA,
input_command,
item.value)
-- Associate item with done button
if(type(form_button) == 'table') then
UiButtonField(form_button.done, item_input)
UiButtonField(form_button.next, item_input)
UiButtonField(form_button.prev, item_input)
end
local scrollbar = UiFindWindow(display_area.id, 'scrollbar')
if(scrollbar ~= 0) then
local scroll_up = UiFindWindow(scrollbar, 'scrollbar_up_btn')
if(scroll_up ~= 0) then
UiButtonField(scroll_up, item_input)
end
local scroll_down = UiFindWindow(scrollbar, 'scrollbar_down_btn')
if(scroll_down ~= 0) then
UiButtonField(scroll_down, item_input)
end
end
else
-- Place a slider option
item_name = UiMultiLabel(item_ui_element,
'input_item_' .. item_num .. '_name',
0, 0,
window_width, item_size/3,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN, UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 0)
local item_input = UiTextField(item_ui_element,
'input_item_' .. item_num .. '_input_text',
window_width - 39, item_size - INPUT.HEIGHT - INPUT.PADDING,
30, INPUT.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.INPUT.BG_COLOR.RED, UI_LIBRARY.INPUT.BG_COLOR.GREEN,
UI_LIBRARY.INPUT.BG_COLOR.BLUE, UI_LIBRARY.INPUT.BG_COLOR.ALPHA,
input_command,
item.value)
local slider_command = string.format('/event slider_set_value %d %d %s %s %d',
self.id,
user_id,
window_data.script_id,
item.name,
item_input)
local slider_tick = (item_data.range_max - item_data.range_min)/30
if(item.user_type == 'int') then
slider_tick = math.max(math.floor(slider_tick), 1)
end
local slider_value = item_data.range_min
if(item.value ~= nil) then
slider_value = item.value
end
local item_slider = UiSlider(item_ui_element,
'input_item_' .. item_num .. '_input',
16, item_size - 2 - INPUT.HEIGHT,
window_width - 70, INPUT.HEIGHT,
item_data.range_min, item_data.range_max,
slider_tick,
10,
slider_command,
slider_value)
local item_slider_min = UiMultiLabel(item_ui_element,
'input_item_' .. item_num .. '_input_min',
10, item_size/2,
60, 25,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 0)
UiText(item_slider_min, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
item_data.range_min))
local item_slider_max = UiMultiLabel(item_ui_element,
'input_item_' .. item_num .. '_input_min',
window_width - 106, item_size/2,
60, 25,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 1)
UiText(item_slider_max, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
item_data.range_max))
end
else
-- Create base selector command
local selector_command = string.format('/event selector %d %d %s %s %d %d',
self.id,
user_id,
window_data.script_id,
item.name,
mode,
offset)
local value_name = ''
-- Set Icon and Command to appropriate user_type
if(item.user_type == 'spriteId') then
if(self[item.name] ~= stylesheet.scripts[window_data.script_id].params[item.name].value) then
item.icon = self[item.name]
item.tint = COLOR.SELECTION
value_name = stylesheet.sprites[self[item.name]].name
else
item.icon = ICON.SPRITE
end
item.command = string.format('%s %s', selector_command, 'sprites')
end
if(item.user_type == 'templateId') then
if(self[item.name] ~= stylesheet.scripts[window_data.script_id].params[item.name].value) then
item.tint = COLOR.SELECTION
end
item.icon = ICON.TEMPLATE
if(self[item.name] ~= '' and self[item.name] ~= nil and self[item.name] ~= ' ') then
value_name = stylesheet.templates[self[item.name]].name
if(string.sub(stylesheet.templates[self[item.name]].spriteId, -2) ~= '-1') then
item.icon = stylesheet.templates[self[item.name]].spriteId
end
end
item.command = string.format('%s %s', selector_command, 'templates')
end
if(item.user_type == 'soundId') then
if(self[item.name] ~= stylesheet.scripts[window_data.script_id].params[item.name].value) then
item.icon = ICON.SOUND
item.tint = COLOR.SELECTION
value_name = stylesheet.sounds[self[item.name]].name
else
item.icon = ICON.SOUND
end
item.command = string.format('%s %s', selector_command, 'sounds')
end
if(item.user_type == 'color') then
item.icon = '__SQUARE__'
item.command = string.format('/event color_selector %d %d %s %s %d %d %d %d',
self.id,
user_id,
window_data.script_id,
item.name,
display_area.id,
display_area.width,
display_area.height,
offset)
item.fg_tint = {red = item.value.red,
green = item.value.green,
blue = item.value.blue,
alpha = item.value.alpha}
end
item_name = UiMultiLabel(item_ui_element,
'input_item_' .. item_num .. '_name',
0, 0,
window_width - item_size * .75, item_size,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
UI_LIBRARY.BG_COLOR.RED, UI_LIBRARY.BG_COLOR.GREEN,
UI_LIBRARY.BG_COLOR.BLUE, UI_LIBRARY.BG_COLOR.ALPHA,
0, 0, 0)
-- Display picker box for pickers
if(item.user_type ~= 'checkbox' and item.user_type ~= 'list' and type(self[item.name]) ~= 'table' or item.user_type == 'color') then
local item_icon_bg = 0
if(item.icon ~= '__SQUARE__') then
item_icon_bg = UiImage(item_ui_element,
'input_item_' .. item_num .. '_icon',
window_width - item_size/2 - INPUT.PADDING/2, item_size/2,
item_size/2, item_size/2,
ICON.BACKGROUND)
if(item.tint ~= nil) then
UiTint(item_icon_bg,
item.tint.RED,
item.tint.GREEN,
item.tint.BLUE)
end
local item_icon = ui_draw_icon(item_icon_bg,
item.icon,
item_size/2,
item_size/2,
2)
else
item_icon_bg = UiRect(item_ui_element,
'input_item_' .. item_num .. '_icon',
window_width - item_size/2 - INPUT.PADDING/2, item_size/2,
item_size/2, item_size/2)
end
if(item.fg_tint ~= nil) then
UiColor(item_icon_bg,
item.fg_tint.red,
item.fg_tint.green,
item.fg_tint.blue,
1)
end
local item_command_btn = UiImageButton(item_icon_bg,
'input_item_' .. item_num .. '_btn',
0, 0,
item_size/2, item_size/2,
ICON.EMPTY, ICON.EMPTY, ICON.EMPTY,
item.command)
UiColor(item_command_btn,
0,
0,
0,
0)
-- Play Sound Button
if(item.user_type == 'soundId' and self[item.name] ~= '' and self[item.name] ~= nil) then
local play_sound_command = string.format('/event play_sound %d %d %s',
self.id,
user_id,
self[item.name])
local play_sound_btn = UiImageButton(item_icon_bg,
'play_sound_' .. item.name,
-4 - BUTTON.PLAY.WIDTH, item_size/4 - BUTTON.PLAY.HEIGHT/2,
BUTTON.PLAY.WIDTH, BUTTON.PLAY.HEIGHT,
BUTTON.PLAY.NORMAL, BUTTON.PLAY.HOVER, BUTTON.PLAY.PRESS,
play_sound_command)
end
if(item.user_type == 'soundId' or item.user_type == 'templateId' or item.user_type == 'spriteId') then
local picker_tooltip = UiWindow(item_ui_element,
'picker_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(picker_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
if(value_name ~= '') then
UiText(tooltip_text, value_name)
UiHoverWindow(item_icon_bg, picker_tooltip, 500, 'left')
end
UiVisible(picker_tooltip, 0, 0)
end
end
-- Display checkbox for checkboxes
if(item.user_type == 'checkbox') then
local checkbox_command = string.format('/event checkbox_set_script_param %d %d %s %s',
self.id,
user_id,
window_data.script_id,
item.name)
local checkbox = ui_checkbox(item_ui_element,
window_width - item_size/2 + (item_size/4 - UI_LIBRARY.CHECKBOX.WIDTH/2),
item_size/2 + (item_size/4 - UI_LIBRARY.CHECKBOX.HEIGHT/2),
tonumber(item.value),
checkbox_command)
end
-- Display list input for lists
if(item.user_type == 'list') then
-- Show current value
local display_bg = UiRect(item_ui_element,
'list_input_item_' .. item.name .. '_bg',
window_width - item_size - INPUT.PADDING, item_size/2 + (item_size/4 - INPUT.HEIGHT/2),
item_size, INPUT.HEIGHT)
UiColor(display_bg,
UI_LIBRARY.INPUT.BG_COLOR.RED,
UI_LIBRARY.INPUT.BG_COLOR.GREEN,
UI_LIBRARY.INPUT.BG_COLOR.BLUE,
UI_LIBRARY.INPUT.BG_COLOR.ALPHA)
local display_value = UiMultiLabel(item_ui_element,
'list_input_item_' .. item.name,
window_width - item_size - INPUT.PADDING, item_size/2 + (item_size/4 - INPUT.HEIGHT/2) - 3,
item_size, INPUT.HEIGHT + 4,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 0)
-- Test to make sure there is a valid list to pull data from
if(has_property(window_data.script_id, item.name .. '_list') == 1) then
UiText(display_value, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
item.value))
local list_command = string.format('/event show_list_window %d %d %s %s %d %d %d',
self.id,
user_id,
window_data.script_id,
item.name,
display_area.id,
display_area.width,
display_area.height)
local display_value_btn = UiImageButton(display_value,
'list_input_item_btn_' .. item_num,
-1, -2,
item_size + 2, INPUT.HEIGHT + 4,
ICON.EMPTY, ICON.EMPTY, ICON.EMPTY,
list_command)
UiColor(display_value_btn,
0,
0,
0,
0)
local list_btn = UiImageButton(display_value,
'list_input_item_icon_' .. item_num,
item_size - INPUT.HEIGHT, 2,
INPUT.HEIGHT + 2, INPUT.HEIGHT + 2,
BUTTON.LIST.NORMAL, BUTTON.LIST.HOVER, BUTTON.LIST.PRESS,
list_command)
else
UiText(display_value, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
'!invalid list!'))
end
end
-- Display Table input
if(type(self[item.name]) == 'table' and item.user_type ~= 'color') then
-- Display Text box
local display_bg = UiRect(item_ui_element,
'list_input_item_' .. item.name .. '_bg',
window_width - item_size - INPUT.PADDING, item_size/2 + (item_size/4 - INPUT.HEIGHT/2),
item_size, INPUT.HEIGHT)
UiColor(display_bg,
UI_LIBRARY.INPUT.BG_COLOR.RED,
UI_LIBRARY.INPUT.BG_COLOR.GREEN,
UI_LIBRARY.INPUT.BG_COLOR.BLUE,
UI_LIBRARY.INPUT.BG_COLOR.ALPHA)
local display_value = UiMultiLabel(item_ui_element,
'list_input_item_' .. item.name,
window_width - item_size - INPUT.PADDING, item_size/2 + (item_size/4 - INPUT.HEIGHT/2) - 3,
item_size, INPUT.HEIGHT + 4,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
UiText(display_value, string.format('%s',
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
'Table Input'))
-- Attach empty button
local display_value_btn = UiImageButton(display_value,
'list_input_item_btn_' .. item_num,
-1, -2,
item_size + 2, INPUT.HEIGHT + 4,
ICON.EMPTY, ICON.EMPTY, ICON.EMPTY,
string.format('/event show_table_window %d %d %s %s %d %d %d',
self.id,
user_id,
window_data.script_id,
item.name,
display_area.id,
display_area.width,
display_area.height))
UiColor(display_value_btn,
0,
0,
0,
0)
end
end
-- Add item description text
UiText(item_name, string.format("%s",
UI_LIBRARY.FONT.SIZE,
UI_LIBRARY.FONT.FACE,
item.description))
end
item_num = item_num + 1
end
end
function list_window(self, display_area, list_item, command, mode)
-- Positioning/Sizing Data for the list window
local size_x = display_area.width * (2/3)
local size_y = display_area.height * (2/3)
local pos_x = display_area.width/2 - (size_x/2)
local pos_y = display_area.height/2 - (size_y/2)
-- Set Default mode
if(mode == nil) then
mode = 0
end
-- Remove the previous list window if it exists
local list_window = UiFindWindow(display_area.id, 'list_selection_' .. list_item.name)
if(list_window ~= 0) then
UiDelete(list_window)
end
-- Draw the list window
local list_window = ui_default_window(display_area.id,
'list_selection_' .. list_item.name,
pos_x,
pos_y,
size_x,
size_y)
-- Add title area to list selector
local title = UiMultiLabel(list_window,
'list_selection_' .. list_item.name .. '_title',
2, 0,
size_x - 24, 24,
UI_LIBRARY.TITLE.COLOR.RED, UI_LIBRARY.TITLE.COLOR.GREEN, UI_LIBRARY.TITLE.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 0)
UiText(title, string.format('Please make a selection',
UI_LIBRARY.TITLE.FONT_SIZE,
UI_LIBRARY.FONT.FACE))
-- Draw list
local list = UiListBox(list_window,
'list_selection_' .. list_item.name .. '_list',
6, 30,
size_x - 12, size_y - 36,
command)
-- Populate list
for index, item in pairs(list_item) do
if(index ~= 'name') then
if(mode == 1) then
UiListItem(list, item, tostring(index))
else
UiListItem(list, item, tostring(item))
end
end
end
end
function scrollbar(self, user_id, script_id, display_area, current_page, max_page, change_per_page, scroll_command, set_scripts)
-- Paginate Scrollbar System
local scrollbar = UiElement(display_area.id,
'scrollbar',
display_area.width - SCROLLBAR.WIDTH, 0)
-- Add scroll background
local scrollbar_bg = UiRect(scrollbar,
'scrollbar_background',
0, 0,
SCROLLBAR.WIDTH, display_area.height)
UiColor(scrollbar_bg,
SCROLLBAR.BG.RED,
SCROLLBAR.BG.GREEN,
SCROLLBAR.BG.BLUE,
SCROLLBAR.BG.ALPHA)
-- Generic scroll command
local scroll_up = math.max(0, current_page * (change_per_page) - change_per_page)
local scroll_down = current_page * change_per_page + change_per_page
if(scroll_down > max_page * change_per_page) then
scroll_down = current_page * change_per_page
end
local scroll_up_tmp = string.format('%s %d', scroll_command, scroll_up)
local scroll_up_command = ''
local scroll_down_command = ''
if(set_scripts == nil) then
scroll_up_command = string.format('set_multiple_params %d %d %s \"%s\"',
self.id,
user_id,
script_id,
scroll_up_tmp)
scroll_down_command = string.format('set_multiple_params %d %d %s \"%s\"',
self.id,
user_id,
script_id,
string.format('%s %d', scroll_command, scroll_down))
else
scroll_up_command = string.format('%s %d', scroll_command, scroll_up)
scroll_down_command = string.format('%s %d', scroll_command, scroll_down)
end
-- Scroll buttons
local scrollbar_up = UiImageButton(scrollbar,
'scrollbar_up_btn',
0, 0,
SCROLLBAR.WIDTH + 1, SCROLLBAR.WIDTH + 1,
UI_LIBRARY.UP.NORMAL, UI_LIBRARY.UP.HOVER, UI_LIBRARY.UP.PRESS,
scroll_up_command)
local scrollbar_down = UiImageButton(scrollbar,
'scrollbar_down_btn',
0, display_area.height - SCROLLBAR.WIDTH,
SCROLLBAR.WIDTH + 1, SCROLLBAR.WIDTH + 1,
UI_LIBRARY.DOWN.NORMAL, UI_LIBRARY.DOWN.HOVER, UI_LIBRARY.DOWN.PRESS,
scroll_down_command)
if(max_page == 0) then
UiTint(scrollbar_up,
128,
128,
128)
UiTint(scrollbar_down,
128,
128,
128)
end
-- Calculate scroll bar size and location
local scrollbar_height = display_area.height - (SCROLLBAR.WIDTH * 2)
local num_scrollbar_segments = max_page + 1
local scrollbar_segment_height = scrollbar_height / num_scrollbar_segments
local current_segment = current_page
-- Draw 'click to jump' aspect of scrollbar
local segment = 0
for segment = 0, num_scrollbar_segments - 1, 1 do
local segment_command_tmp = string.format('%s %d', scroll_command, segment * change_per_page)
local segment_command = ''
if(set_scripts == nil) then
segment_command = string.format('set_multiple_params %d %d %s \"%s\"',
self.id,
user_id,
script_id,
segment_command_tmp)
else
segment_command = segment_command_tmp
end
local segment_btn = UiImageButton(scrollbar,
'scrollbar_segment_' .. segment,
0, SCROLLBAR.WIDTH + 1 + segment * scrollbar_segment_height,
SCROLLBAR.WIDTH, scrollbar_segment_height,
ICON.EMPTY, ICON.EMPTY, ICON.EMPTY,
segment_command)
UiColor(segment_btn,
0,
0,
0,
0)
-- Attach scrollbar button
if(segment == current_segment) then
local scrollbar_segment = UiRect(scrollbar,
'scrollbar_segment',
0, SCROLLBAR.WIDTH + 1 + segment * scrollbar_segment_height,
SCROLLBAR.WIDTH, scrollbar_segment_height)
UiColor(scrollbar_segment,
SCROLLBAR.COLOR.RED,
SCROLLBAR.COLOR.GREEN,
SCROLLBAR.COLOR.BLUE,
1)
end
end
end
function clear_ui(user)
if(user.smart_object_window ~= 0) then
UiDelete(user.smart_object_window)
user.smart_object_window = 0
end
end
-----------------------------------------------------------------------------------------------------------------------------
-- CUSTOM CONFIGURATION FUNCTIONS --
-----------------------------------------------------------------------------------------------------------------------------
function config_window(self, user_id, script_id, width, height)
-- Get user object
local user = GetObjectById(user_id)
local script_data = get_script_metadata(script_id)
local history = {}
local ui_data = {}
-- Maintain a minimum size for windwos
width = math.max(width, 300)
height = math.max(height, 400)
-- Populate the window history table
local item = {name = 'Home',
icon = ICON.HOME,
command = string.format('/event configure_behaviors %d %d',
self.id,
user_id)}
table.insert(history, item)
local item = {name = script_data.name,
icon = script_data.icon}
table.insert(history, item)
-- Draw main window
local display_area = main_window(self,
user_id,
width, height,
string.format("Customize this %s", self.type),
1)
-- Draw window history
window_history(self,
user.smart_object_window,
history)
-- Draw bottom menu
local menu_bottom = UiFindWindow(user.smart_object_window, 'ox_menu_bottom')
-- Add Done Button
local done_command = string.format('ui_library_close_window %d',
user.smart_object_window)
local done_button = UiImageButton(menu_bottom,
'done_customizing_btn',
display_area.width - (BUTTON.DONE.WIDTH + 4), (MENU.HEIGHT - BUTTON.DONE.HEIGHT)/2,
BUTTON.DONE.WIDTH, BUTTON.DONE.HEIGHT,
BUTTON.DONE.NORMAL, BUTTON.DONE.HOVER, BUTTON.DONE.PRESS,
done_command)
-- Paginate system for scripts
-- Get script list
local script_list = get_script_list(self, 0, 1)
-- Find this script in the script list
local current_script_index = 1
for index, script_list_id in pairs(script_list) do
if(script_list_id == script_id) then
current_script_index = index
end
end
-- Display basic button
-- Get a list of the basic scripts
local advanced_script_list = get_script_list(self, 0, 0)
-- Find this script in the basic script list
-- NOTE: If this script isn't in the basic script list, then goto the first script in the basic script list
local advanced_script_index = 1
for index, script_list_id in pairs(advanced_script_list) do
if(script_list_id == script_id) then
advanced_script_index = index
end
end
local advanced_command = string.format('/event configure_behavior_properties %d %d %s 0',
self.id,
user_id,
script_id)
local advanced_btn = UiImageButton(menu_bottom,
'advanced_btn',
INPUT.PADDING, MENU.HEIGHT/2 - BUTTON.ADVANCED.HEIGHT/2,
BUTTON.ADVANCED.WIDTH, BUTTON.ADVANCED.HEIGHT,
BUTTON.ADVANCED.NORMAL, BUTTON.ADVANCED.HOVER, BUTTON.ADVANCED.PRESS,
advanced_command)
-- Draw next and previous buttons
local next_command = ''
if(current_script_index + 1 <= #script_list) then
local next_command_tmp = string.format('/event configure_behavior_properties %d %d %s %d',
self.id,
user_id,
script_list[current_script_index + 1],
1)
next_command = string.format('set_multiple_params %d %d %s \'%s\'',
self.id,
user_id,
script_id,
next_command_tmp)
end
local next_script_btn = UiImageButton(menu_bottom,
'next_script_btn',
MENU.WIDTH - BUTTON.DONE.WIDTH - BUTTON.REMOVE.WIDTH - BUTTON.NEXT.WIDTH - INPUT.PADDING * 3,
MENU.HEIGHT/2 - BUTTON.NEXT.HEIGHT/2,
BUTTON.NEXT.WIDTH, BUTTON.NEXT.HEIGHT,
BUTTON.NEXT.NORMAL, BUTTON.NEXT.HOVER, BUTTON.NEXT.PRESS,
next_command)
if(next_command ~= '') then
local next_tooltip = UiWindow(menu_bottom,
'next_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(next_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
local next_script_data = get_script_metadata(script_list[current_script_index + 1])
UiText(tooltip_text, next_script_data.name)
UiHoverWindow(next_script_btn, next_tooltip, 500, 'below')
UiVisible(next_tooltip, 0, 0)
end
if(next_command == '') then
UiTint(next_script_btn, 128, 128, 128)
end
local prev_command = ''
if(current_script_index - 1 > 0) then
local prev_command_tmp = string.format('/event configure_behavior_properties %d %d %s %d',
self.id,
user_id,
script_list[current_script_index - 1],
1)
prev_command = string.format('set_multiple_params %d %d %s \'%s\'',
self.id,
user_id,
script_id,
prev_command_tmp)
end
local prev_script_btn = UiImageButton(menu_bottom,
'prev_script_btn',
MENU.WIDTH - BUTTON.DONE.WIDTH - BUTTON.REMOVE.WIDTH - BUTTON.NEXT.WIDTH - BUTTON.PREVIOUS.WIDTH - INPUT.PADDING * 4,
MENU.HEIGHT/2 - BUTTON.PREVIOUS.HEIGHT/2,
BUTTON.PREVIOUS.WIDTH, BUTTON.PREVIOUS.HEIGHT,
BUTTON.PREVIOUS.NORMAL, BUTTON.PREVIOUS.HOVER, BUTTON.PREVIOUS.PRESS,
prev_command)
if(prev_command ~= '') then
local prev_tooltip = UiWindow(menu_bottom,
'prev_tooltip',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.WINSTYLE_NO_TITLEBAR)
local tooltip_text = UiMultiLabel(prev_tooltip,
'text',
0, 0,
UI_LIBRARY.THUMBNAIL.TOOLTIP.WIDTH, UI_LIBRARY.THUMBNAIL.TOOLTIP.HEIGHT,
UI_LIBRARY.FONT.COLOR.RED, UI_LIBRARY.FONT.COLOR.GREEN, UI_LIBRARY.FONT.COLOR.BLUE,
0, 0, 0, 0,
0, 0, 2)
local prev_script_data = get_script_metadata(script_list[current_script_index - 1])
UiText(tooltip_text, prev_script_data.name)
UiHoverWindow(prev_script_btn, prev_tooltip, 500, 'below')
UiVisible(prev_tooltip, 0, 0)
end
if(prev_command == '') then
UiTint(prev_script_btn, 128, 128, 128)
end
return display_area
end