ACE3/addons/slideshow/functions/fnc_createSlideshow.sqf

83 lines
2.8 KiB
Plaintext
Raw Normal View History

2015-06-27 02:11:57 +00:00
/*
* Author: Jonpas, DaC
* Prepares necessary variables and default image.
*
* Arguments:
* 0: Objects <ARRAY>
* 1: Controller Objects <ARRAY>
* 2: Image Paths <ARRAY>
* 3: Action Names <ARRAY>
* 4: Slide Duration <NUMBER> (0 disables automatic transitions)
2015-06-27 02:11:57 +00:00
*
* Return Value:
* Parsed List <ARRAY>
*
* Example:
* [[object1, object2, object3], [controller1], ["images\image1.paa", "images\image2.paa"], ["Action1", "Action2"], 5] call ace_slideshow_fnc_createSlideshow
2015-06-27 02:11:57 +00:00
*
* Public: Yes
*/
#include "script_component.hpp"
2015-08-07 10:11:34 +00:00
private ["_currentSlideshow", "_actionsObject", "_actionsClass", "_mainAction", "_slidesAction", "_varString"];
params ["_objects", "_controllers", "_images", "_names", "_duration"];
2015-06-27 02:11:57 +00:00
// Verify data
if (count _images != count _names || {count _images == 0} || {count _names == 0}) exitWith {
diag_log "[ACE] ERROR: Slideshow Images or Names fields can NOT be empty and must have equal number of items!"
};
2015-06-27 02:11:57 +00:00
// Objects synced to the module
{
2015-07-13 20:07:21 +00:00
_objects pushBack _x;
2015-08-07 10:11:34 +00:00
nil
} count (synchronizedObjects _logic);
2015-06-27 02:11:57 +00:00
// If no controllers use objects as controllers
if (count _controllers == 0) then {
_controllers = _objects;
};
TRACE_4("Information",_objects,_controllers,_images,_names);
if (isServer) then {
// Default images on whiteboards (first image)
{
_x setObjectTextureGlobal [0, _images select 0];
} count _objects;
// Number of slideshows (multiple modules support)
GVAR(slideshows) = GVAR(slideshows) + 1;
};
2015-06-27 02:11:57 +00:00
2015-07-13 20:07:21 +00:00
_currentSlideshow = GVAR(slideshows); // Local variable in case GVAR gets changed during execution of below code
2015-06-29 19:54:40 +00:00
// If interaction menu module is not present, set default duration value
if !(["ace_interact_menu"] call EFUNC(common,isModLoaded)) then {
_duration = 5;
diag_log text format ["[ACE]: Slideshow: Interaction Menu module not present, defaulting duration value to %1", _duration];
};
2015-07-13 20:07:21 +00:00
// Add interactions if automatic transitions are disabled, else setup automatic transitions
if (_duration == 0) then {
{
// Add Slides sub-action and populate with images
_slidesAction = [QGVAR(Slides), localize LSTRING(Interaction), "", {}, {true}, {(_this select 2) call FUNC(addSlideActions)}, [_objects,_images,_names,_x,_currentSlideshow], [0,0,0], 2] call EFUNC(interact_menu,createAction);
[_x, 0, ["ACE_MainActions"], _slidesAction] call EFUNC(interact_menu,addActionToObject);
2015-08-07 10:11:34 +00:00
nil
} count _controllers;
2015-07-13 20:07:21 +00:00
} else {
if !(isServer) exitWith {};
2015-07-13 20:07:21 +00:00
// Formatted GVAR string (multiple modules support)
_varString = format [QGVAR(slideshow%1), _currentSlideshow];
TRACE_1("Current Slide",_varString);
2015-07-13 20:07:21 +00:00
// Set formatted GVAR to first slide
missionNamespace setVariable [_varString, 0];
2015-07-13 20:07:21 +00:00
// Automatic transitions handler
[FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call EFUNC(common,waitAndExecute);
};