fnc_valueProgressBar.sqf 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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: representation of how complete the bar should be.
  9. * 0: Progress Complete Variable: representation of when the bar should be considered 'complete', must be larger than progressVar value.
  10. * 1: Arguments, passed to condition, fail and finish <ARRAY>
  11. * 2: On Finish: Code called or STRING raised as event. <CODE, STRING>
  12. * 3: On Failure: Code called or STRING raised as event. <CODE, STRING>
  13. * 4: (Optional) Localized Title <STRING>
  14. * 5: Code to check each frame (Optional) <CODE>
  15. * 6: Exceptions for checking EFUNC(common,canInteractWith) (Optional)<ARRAY>
  16. *
  17. * Return Value:
  18. * None
  19. *
  20. * Example:
  21. * ["rd501_medical_ccp_stitchProgress", "rd501_medical_ccp_stitchProgressComplete", [], {Hint "Finished!"}, {hint "Failure!"}, "My Title"] call rd501_fnc_valueProgressBar
  22. *
  23. * Public: Yes
  24. */
  25. params ["_progressVar","_progressCompleteVar", "_building", "_args", "_onFinish", "_onFail", ["_localizedTitle", ""], ["_condition", {true}], ["_exceptions", []]];
  26. private _player = ACE_player;
  27. //Open Dialog and set the title
  28. closeDialog 0;
  29. createDialog "ace_common_ProgressBar_Dialog";
  30. (uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlSetText _localizedTitle;
  31. //Adjust position based on user setting:
  32. private _ctrlPos = ctrlPosition (uiNamespace getVariable "ace_common_ctrlProgressBarTitle");
  33. _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))];
  34. (uiNamespace getVariable "ace_common_ctrlProgressBG") ctrlSetPosition _ctrlPos;
  35. (uiNamespace getVariable "ace_common_ctrlProgressBG") ctrlCommit 0;
  36. (uiNamespace getVariable "ace_common_ctrlProgressBar") ctrlSetPosition _ctrlPos;
  37. (uiNamespace getVariable "ace_common_ctrlProgressBar") ctrlCommit 0;
  38. (uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlSetPosition _ctrlPos;
  39. (uiNamespace getVariable "ace_common_ctrlProgressBarTitle") ctrlCommit 0;
  40. [{
  41. (_this select 0) params ["_progressVar", "_progressCompleteVar", "_args", "_onFinish", "_onFail", "_condition", "_player", "_building", "_exceptions"];
  42. private _progress = _building getVariable[_progressVar, -1];
  43. private _progressComplete = _building getVariable[_progressCompleteVar, 100];
  44. private _errorCode = -1;
  45. // 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.
  46. if (isNull (uiNamespace getVariable ["ace_common_ctrlProgressBar", controlNull])) then {
  47. _errorCode = 1;
  48. } else {
  49. if (ACE_player != _player || !alive _player) then {
  50. _errorCode = 2;
  51. } else {
  52. if !([_args, _progress, _errorCode] call _condition) then {
  53. _errorCode = 3;
  54. } else {
  55. if !([_player, objNull, _exceptions] call ace_common_fnc_canInteractWith) then {
  56. _errorCode = 4;
  57. } else {
  58. if (_progress >= _progressComplete) then {
  59. _errorCode = 0;
  60. };
  61. };
  62. };
  63. };
  64. };
  65. if (_errorCode != -1) then {
  66. //Error or Success, close dialog and remove PFEH
  67. //Only close dialog if it's the progressBar:
  68. if (!isNull (uiNamespace getVariable ["ace_common_ctrlProgressBar", controlNull])) then {
  69. closeDialog 0;
  70. };
  71. [_this select 1] call CBA_fnc_removePerFrameHandler;
  72. if (_errorCode == 0) then {
  73. if (_onFinish isEqualType "") then {
  74. [_onFinish, [_args, _errorCode]] call CBA_fnc_localEvent;
  75. } else {
  76. [_args, _errorCode] call _onFinish;
  77. };
  78. } else {
  79. if (_onFail isEqualType "") then {
  80. [_onFail, [_args, _progress, _errorCode]] call CBA_fnc_localEvent;
  81. } else {
  82. [_args, _progress, _errorCode] call _onFail;
  83. };
  84. };
  85. } else {
  86. private _progressResult = ((_progress / _progressComplete)) min 1;
  87. (uiNamespace getVariable "ace_common_ctrlProgressBar") progressSetPosition _progressResult;
  88. };
  89. }, 0, [_progressVar, _progressCompleteVar, _args, _onFinish, _onFail, _condition, _player, _building, _exceptions]] call CBA_fnc_addPerFrameHandler;