fnc_valueProgressBar.sqf 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. /*
  2. * Author: commy2, Glowbal, PabstMirror
  3. * Modified by: Mirror
  4. * Draw progress bar and execute given function if succesful.
  5. * Finish/Failure/Conditional are all passed [_args, _elapsedTime, _totalTime, _errorCode]
  6. *
  7. * Arguments:
  8. * 0: Progress Variable Func: 0-100 representation of how complete the bar should be.
  9. * 1: Arguments, passed to condition, fail and finish <ARRAY>
  10. * 2: On Finish: Code called or STRING raised as event. <CODE, STRING>
  11. * 3: On Failure: Code called or STRING raised as event. <CODE, STRING>
  12. * 4: (Optional) Localized Title <STRING>
  13. * 5: Code to check each frame (Optional) <CODE>
  14. * 6: Exceptions for checking EFUNC(common,canInteractWith) (Optional)<ARRAY>
  15. *
  16. * Return Value:
  17. * None
  18. *
  19. * Example:
  20. * ["rd501_medical_ccp_stitchProgress", [], {Hint "Finished!"}, {hint "Failure!"}, "My Title"] call rd501_fnc_valueProgressBar
  21. *
  22. * Public: Yes
  23. */
  24. params ["_progressVar","_progressCompleteVar", "_building", "_args", "_onFinish", "_onFail", ["_localizedTitle", ""], ["_condition", {true}], ["_exceptions", []]];
  25. private _player = ACE_player;
  26. //Open Dialog and set the title
  27. closeDialog 0;
  28. createDialog "ace_common_ProgressBar_Dialog";
  29. (uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlSetText _localizedTitle;
  30. //Adjust position based on user setting:
  31. private _ctrlPos = ctrlPosition (uiNamespace getVariable "ace_common_ctrlProgressBarTitle");
  32. _ctrlPos set [1, ((0 + 29 * ace_common_settingProgressBarLocation) * ((((safezoneW / safezoneH) min 1.2) / 1.2) / 25) + (safezoneY + (safezoneH - (((safezoneW / safezoneH) min 1.2) / 1.2))/2))];
  33. (uiNamespace getVariable "ace_common_ctrlProgressBG") ctrlSetPosition _ctrlPos;
  34. (uiNamespace getVariable "ace_common_ctrlProgressBG") ctrlCommit 0;
  35. (uiNamespace getVariable "ace_common_ctrlProgressBar") ctrlSetPosition _ctrlPos;
  36. (uiNamespace getVariable "ace_common_ctrlProgressBar") ctrlCommit 0;
  37. (uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlSetPosition _ctrlPos;
  38. (uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlCommit 0;
  39. [{
  40. (_this select 0) params ["_progressVar", "_progressCompleteVar", "_args", "_onFinish", "_onFail", "_condition", "_player", "_building", "_exceptions"];
  41. private _progress = _building getVariable[_progressVar, -1];
  42. private _errorCode = -1;
  43. // this does not check: target fell unconscious, target died, target moved inside vehicle / left vehicle, target moved outside of players range, target moves at all.
  44. if (isNull (uiNamespace getVariable ["ace_common_ctrlProgressBar", controlNull])) then {
  45. _errorCode = 1;
  46. } else {
  47. if (ACE_player != _player || !alive _player) then {
  48. _errorCode = 2;
  49. } else {
  50. if !([_args, _progress, _errorCode] call _condition) then {
  51. _errorCode = 3;
  52. } else {
  53. if !([_player, objNull, _exceptions] call ace_common_fnc_canInteractWith) then {
  54. _errorCode = 4;
  55. } else {
  56. if (_progress >= 100) then {
  57. _errorCode = 0;
  58. };
  59. };
  60. };
  61. };
  62. };
  63. if (_errorCode != -1) then {
  64. //Error or Success, close dialog and remove PFEH
  65. //Only close dialog if it's the progressBar:
  66. if (!isNull (uiNamespace getVariable ["ace_common_ctrlProgressBar", controlNull])) then {
  67. closeDialog 0;
  68. };
  69. [_this select 1] call CBA_fnc_removePerFrameHandler;
  70. if (_errorCode == 0) then {
  71. if (_onFinish isEqualType "") then {
  72. [_onFinish, [_args, _errorCode]] call CBA_fnc_localEvent;
  73. } else {
  74. [_args, _errorCode] call _onFinish;
  75. };
  76. } else {
  77. if (_onFail isEqualType "") then {
  78. [_onFail, [_args, _progress, _errorCode]] call CBA_fnc_localEvent;
  79. } else {
  80. [_args, _progress, _errorCode] call _onFail;
  81. };
  82. };
  83. } else {
  84. (uiNamespace getVariable "ace_common_ctrlProgressBar") progressSetPosition _progress / 100;
  85. };
  86. }, 0, [_progressVar, _args, _onFinish, _onFail, _condition, _player, _building, _exceptions]] call CBA_fnc_addPerFrameHandler;