From 84b18d3f0699a05d8b73aa7d04fdc5179d152091 Mon Sep 17 00:00:00 2001 From: Walthzer Date: Sun, 25 Oct 2020 18:14:57 +0100 Subject: [PATCH] Slideshow - Add "SlideChanged" event (#7954) * Implement Events in slideshow framework. * Update function header * Pass correct agruments to next call of autoTransiton. * Add return of slideshow ID Return slideshow ID so it can be stored for later use with the events. * Replace repeat code with variable. _image. * Redundant comment removal * Update addons/slideshow/functions/fnc_createSlideshow.sqf Co-authored-by: jonpas Co-authored-by: jonpas --- AUTHORS.txt | 1 + .../slideshow/functions/fnc_addSlideActions.sqf | 5 +++-- addons/slideshow/functions/fnc_autoTransition.sqf | 15 ++++++++++----- .../slideshow/functions/fnc_createSlideshow.sqf | 6 ++++-- 4 files changed, 18 insertions(+), 9 deletions(-) diff --git a/AUTHORS.txt b/AUTHORS.txt index 78f4287014..e8d1b9affb 100644 --- a/AUTHORS.txt +++ b/AUTHORS.txt @@ -159,6 +159,7 @@ Tuupertunut Valentin Torikian voiper VyMajoris(W-Cephei) +Walthzer Winter xrufix Zakant diff --git a/addons/slideshow/functions/fnc_addSlideActions.sqf b/addons/slideshow/functions/fnc_addSlideActions.sqf index 6acd304d32..6416c35748 100644 --- a/addons/slideshow/functions/fnc_addSlideActions.sqf +++ b/addons/slideshow/functions/fnc_addSlideActions.sqf @@ -30,14 +30,15 @@ private _actions = []; _names select _forEachIndex, "", { - (_this select 2) params ["_objects", "_image"]; + (_this select 2) params ["_objects", "_image", "_currentSlideshow"]; { _x setObjectTextureGlobal [0, _image] } count _objects; + [QGVAR(slideChanged), [_image, _currentSlideshow]] call CBA_fnc_localEvent; }, {true}, {}, - [_objects, _x] + [_objects, _x, _currentSlideshow] ] call EFUNC(interact_menu,createAction), [], _controller diff --git a/addons/slideshow/functions/fnc_autoTransition.sqf b/addons/slideshow/functions/fnc_autoTransition.sqf index 50e8b1d13d..87fe488754 100644 --- a/addons/slideshow/functions/fnc_autoTransition.sqf +++ b/addons/slideshow/functions/fnc_autoTransition.sqf @@ -7,7 +7,8 @@ * 0: Objects * 1: Image Paths * 2: State Variable Name - * 3: Duration (0 disables automatic transitions) + * 3: Current Slideshow + * 4: Duration (0 disables automatic transitions) * * Return Value: * None @@ -18,7 +19,7 @@ * Public: No */ -params ["_objects", "_images", "_varString", "_duration"]; +params ["_objects", "_images", "_varString", "_currentSlideshow", "_duration"]; // Get current slide number of this slideshow private _currentSlide = missionNamespace getVariable [_varString, 0]; @@ -29,11 +30,15 @@ _currentSlide = (_currentSlide + 1) mod (count _images); // Save slide back into global variable (PFH's local variables do not persist through PFH run) missionNamespace setVariable [_varString, _currentSlide]; +private _image = _images select _currentSlide; + // Set slide { - _x setObjectTextureGlobal [0, _images select _currentSlide]; + _x setObjectTextureGlobal [0, _image]; } count _objects; +[QGVAR(slideChanged), [_image, _currentSlideshow]] call CBA_fnc_localEvent; + // Log current slide and execute Next slide -TRACE_4("Auto-transition",_images select _currentSlide,_currentSlide,count _images,_duration); -[FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call CBA_fnc_waitAndExecute; +TRACE_4("Auto-transition",_image,_currentSlide,count _images,_duration); +[FUNC(autoTransition), [_objects, _images, _varString, _currentSlideshow, _duration], _duration] call CBA_fnc_waitAndExecute; diff --git a/addons/slideshow/functions/fnc_createSlideshow.sqf b/addons/slideshow/functions/fnc_createSlideshow.sqf index 290fad89b4..0d84fa969b 100644 --- a/addons/slideshow/functions/fnc_createSlideshow.sqf +++ b/addons/slideshow/functions/fnc_createSlideshow.sqf @@ -12,7 +12,7 @@ * 5: Set Name (default: localized "Slides") * * Return Value: - * None + * Slideshow ID * * Example: * [[object1, object2, object3], [controller1], ["images\image1.paa", "images\image2.paa"], ["Action1", "Action2"], 5, "My Slides"] call ace_slideshow_fnc_createSlideshow @@ -100,5 +100,7 @@ if (_duration == 0) then { missionNamespace setVariable [_varString, 0]; // Automatic transitions handler - [FUNC(autoTransition), [_objects, _images, _varString, _duration], _duration] call CBA_fnc_waitAndExecute; + [FUNC(autoTransition), [_objects, _images, _varString, _currentSlideshow, _duration], _duration] call CBA_fnc_waitAndExecute; }; + +_currentSlideshow