From afb3dad22bf90c86ddb388e72f6a302376430a80 Mon Sep 17 00:00:00 2001 From: Freddo Date: Thu, 29 Oct 2020 17:36:59 +0100 Subject: [PATCH] Markers - Add timestamps (#7947) * Add timestamps to markers * Tiny tweaks * Update addons/markers/functions/fnc_canTimestamp.sqf Co-authored-by: Brett * Update addons/markers/functions/fnc_initInsertMarker.sqf Co-authored-by: Brett * Add timestamp format setting * Script cleanup, move checkbox under desc * Fix stringtable validation * Tweaks * Remove styling from stringtable * Edit timestamps instead of append Credits to @PabstMirror Co-authored-by: Brett --- addons/markers/InsertMarker.hpp | 15 ++- addons/markers/XEH_PREP.hpp | 3 + addons/markers/functions/fnc_canTimestamp.sqf | 26 ++++ .../functions/fnc_initInsertMarker.sqf | 115 +++++++++++++----- .../functions/fnc_onButtonClickConfirm.sqf | 42 +++++++ .../fnc_onCheckedChangedTimestamp.sqf | 23 ++++ .../functions/fnc_onLBSelChangedColor.sqf | 9 +- .../functions/fnc_onLBSelChangedShape.sqf | 9 +- .../functions/fnc_onSliderPosChangedAngle.sqf | 2 +- addons/markers/initSettings.sqf | 57 ++++++++- addons/markers/script_component.hpp | 22 +++- addons/markers/stringtable.xml | 42 +++++++ 12 files changed, 317 insertions(+), 48 deletions(-) create mode 100644 addons/markers/functions/fnc_canTimestamp.sqf create mode 100644 addons/markers/functions/fnc_onButtonClickConfirm.sqf create mode 100644 addons/markers/functions/fnc_onCheckedChangedTimestamp.sqf diff --git a/addons/markers/InsertMarker.hpp b/addons/markers/InsertMarker.hpp index 5d7cc987e2..ed2d562220 100644 --- a/addons/markers/InsertMarker.hpp +++ b/addons/markers/InsertMarker.hpp @@ -5,6 +5,7 @@ class RscStructuredText; class RscButtonMenuOK; class RscButtonMenuCancel; class RscButtonMenu; +class RscCheckBox; class RscEdit; class RscCombo; class RscSlider; @@ -16,17 +17,23 @@ class RscDisplayInsertMarker { movingEnable = 1; class controls { + class TimeStampText: RscStructuredText { + idc = IDC_ACE_INSERT_MARKER_TIMESTAMP_TEXT; + }; + class TimeStamp: RscCheckBox { + idc = IDC_ACE_INSERT_MARKER_TIMESTAMP; + }; class MarkerShape: RscCombo { - idc = 1210; + idc = IDC_ACE_INSERT_MARKER_SHAPE; }; class MarkerColor: RscCombo { - idc = 1211; + idc = IDC_ACE_INSERT_MARKER_COLOR; }; class MarkerAngle: RscXSliderH { - idc = 1220; + idc = IDC_ACE_INSERT_MARKER_ANGLE; }; class MarkerAngleText: RscText { - idc = 1221; + idc = IDC_ACE_INSERT_MARKER_ANGLE_TEXT; }; }; }; diff --git a/addons/markers/XEH_PREP.hpp b/addons/markers/XEH_PREP.hpp index bbac954b66..3cf9dfc600 100644 --- a/addons/markers/XEH_PREP.hpp +++ b/addons/markers/XEH_PREP.hpp @@ -14,3 +14,6 @@ PREP(canMove); PREP(onMouseButtonDown); PREP(onMouseButtonUp); PREP(movePFH); +PREP(canTimestamp); +PREP(onButtonClickConfirm); +PREP(onCheckedChangedTimestamp); diff --git a/addons/markers/functions/fnc_canTimestamp.sqf b/addons/markers/functions/fnc_canTimestamp.sqf new file mode 100644 index 0000000000..21e80c0921 --- /dev/null +++ b/addons/markers/functions/fnc_canTimestamp.sqf @@ -0,0 +1,26 @@ +#include "script_component.hpp" +/* + * Author: Freddo + * Checks whether a unit is able to timestamp. + * + * Arguments: + * 0: Unit + * + * Return Value: + * Whether unit is able to timestamp + * + * Example: + * [ACE_Player] call ace_markers_fnc_canTimestamp + * + * Public: No + */ + +params [["_unit", ACE_player]]; + +private _assignedItems = assignedItems _unit; + +private _index = _assignedItems findIf { + ([_x] call EFUNC(common,getItemType)) isEqualTo ["item", "watch"] +}; + +_index != -1 diff --git a/addons/markers/functions/fnc_initInsertMarker.sqf b/addons/markers/functions/fnc_initInsertMarker.sqf index 8a7a5f21fb..1560040bc9 100644 --- a/addons/markers/functions/fnc_initInsertMarker.sqf +++ b/addons/markers/functions/fnc_initInsertMarker.sqf @@ -1,4 +1,5 @@ #include "script_component.hpp" +#include "\A3\ui_f\hpp\defineResincl.inc" /* * Author: BIS, commy2, Timi007 * Sets up the marker placement @@ -29,26 +30,28 @@ }; //BIS Controls: - private _text = _display displayctrl 101; - private _picture = _display displayctrl 102; - private _channel = _display displayctrl 103; - private _buttonOK = _display displayctrl 1; - private _buttonCancel = _display displayctrl 2; - private _description = _display displayctrl 1100; - private _title = _display displayctrl 1001; - private _descriptionChannel = _display displayctrl 1101; + private _text = _display displayctrl IDC_INSERT_MARKER; + private _picture = _display displayctrl IDC_INSERT_MARKER_PICTURE; + private _channel = _display displayctrl IDC_INSERT_MARKER_CHANNELS; + private _buttonOK = _display displayctrl IDC_OK; + private _buttonCancel = _display displayctrl IDC_CANCEL; + private _description = _display displayctrl 1100; + private _title = _display displayctrl 1001; + private _descriptionChannel = _display displayctrl 1101; //ACE Controls: - // _sizeX = _display displayctrl 1200; - // _sizeY = _display displayctrl 1201; - private _aceShapeLB = _display displayctrl 1210; - private _aceColorLB = _display displayctrl 1211; - private _aceAngleSlider = _display displayctrl 1220; - private _aceAngleSliderText = _display displayctrl 1221; + // _sizeX = _display displayctrl 1200; + // _sizeY = _display displayctrl 1201; + private _aceTimestamp = _display displayCtrl IDC_ACE_INSERT_MARKER_TIMESTAMP; + private _aceTimestampText = _display displayCtrl IDC_ACE_INSERT_MARKER_TIMESTAMP_TEXT; + private _aceShapeLB = _display displayctrl IDC_ACE_INSERT_MARKER_SHAPE; + private _aceColorLB = _display displayctrl IDC_ACE_INSERT_MARKER_COLOR; + private _aceAngleSlider = _display displayctrl IDC_ACE_INSERT_MARKER_ANGLE; + private _aceAngleSliderText = _display displayctrl IDC_ACE_INSERT_MARKER_ANGLE_TEXT; - private _mapDisplay = displayParent _display; + private _mapDisplay = displayParent _display; if (isNull _mapDisplay) exitWith {ERROR("No Map");}; - private _mapCtrl = _mapDisplay displayCtrl 51; + private _mapCtrl = _mapDisplay displayCtrl IDC_MAP; GVAR(editingMarker) = ""; (ctrlMapMouseOver _mapCtrl) params ["_mouseOverType", "_marker"]; @@ -76,7 +79,10 @@ GVAR(currentMarkerPosition) = markerPos GVAR(editingMarker); } else { private _pos = ctrlPosition _picture; - _pos = [(_pos select 0) + (_pos select 2) / 2, (_pos select 1) + (_pos select 3) / 2]; + _pos = [ + (_pos select 0) + (_pos select 2) / 2, + (_pos select 1) + (_pos select 3) / 2 + ]; GVAR(currentMarkerPosition) = _mapCtrl ctrlMapScreenToWorld _pos; }; @@ -86,9 +92,19 @@ // prevent vanilla key input _display displayAddEventHandler ["KeyDown", {(_this select 1) in [200, 208]}]; + private _hasTimestamp = false; if !((markerText GVAR(editingMarker)) isEqualTo "") then { - //fill text input with text from marker which is being edited - _text ctrlSetText (markerText GVAR(editingMarker)); + // fill text input with text from marker which is being edited + + private _originalText = markerText GVAR(editingMarker); + private _timeIndex = _originalText find (TIMESTAMP_SPACE + "["); + if (_timeIndex > 0 ) then { + // Shave off timestamp + _hasTimestamp = true; + _originalText = _originalText select [0,_timeIndex]; + }; + + _text ctrlSetText _originalText; }; //Focus on the text input @@ -112,33 +128,70 @@ //--- Description _pos set [1, _posY - 1 * _posH]; - _pos set [3,6 * _posH + 6 * BORDER]; + if (GVAR(timestampEnabled)) then { + _pos set [3,7 * _posH + 7 * BORDER]; + } else { + _pos set [3,6 * _posH + 6 * BORDER]; + }; _description ctrlEnable false; _description ctrlSetPosition _pos; _description ctrlSetStructuredText parseText format ["%1", localize "str_lib_label_description"]; _description ctrlCommit 0; + //--- Timestamp + private _timestampOffset = 0; + if (GVAR(timestampEnabled)) then { + _timestampOffset = _posH + BORDER; + + _pos set [0, _posX]; + _pos set [1, _posY + 1 * _posH + 2 * BORDER]; + _pos set [2, _posW - _posH]; + _pos set [3, _posH]; + _aceTimestampText ctrlSetStructuredText parseText format ["%1", LLSTRING(Timestamp)]; + _aceTimestampText ctrlSetPosition _pos; + _aceTimestampText ctrlCommit 0; + + _pos set [0, _posX + _posW - _posH]; + _pos set [2, _posH]; + _pos set [3, _posH]; + _aceTimestamp ctrlSetPosition _pos; + _aceTimestamp ctrlCommit 0; + + if !([ACE_player] call FUNC(canTimestamp)) then { + _aceTimestamp ctrlEnable false; + _aceTimestamp ctrlSetTooltip LLSTRING(TimestampTooltipNoWatch); + } else { + _aceTimestamp cbSetChecked (GETUVAR(GVAR(timestampChecked),false) || _hasTimestamp); + }; + } else { + _aceTimestampText ctrlEnable false; + _aceTimestampText ctrlShow false; + _aceTimestamp ctrlEnable false; + _aceTimestamp ctrlShow false; + }; + //--- Shape - _pos set [1, _posY + 1 * _posH + 2 * BORDER]; + _pos set [0, _posX]; + _pos set [1, _posY + 1 * _posH + 2 * BORDER + _timestampOffset]; _pos set [2, _posW]; _pos set [3, _posH]; _aceShapeLB ctrlSetPosition _pos; _aceShapeLB ctrlCommit 0; //--- Color - _pos set [1, _posY + 2 * _posH + 3 * BORDER]; + _pos set [1, _posY + 2 * _posH + 3 * BORDER + _timestampOffset]; _pos set [2, _posW]; _aceColorLB ctrlSetPosition _pos; _aceColorLB ctrlCommit 0; //--- Angle - _pos set [1, _posY + 3 * _posH + 4 * BORDER]; + _pos set [1, _posY + 3 * _posH + 4 * BORDER + _timestampOffset]; _pos set [2, _posW]; _aceAngleSlider ctrlSetPosition _pos; _aceAngleSlider ctrlCommit 0; //--- Angle Text - _pos set [1, _posY + 4 * _posH + 5 * BORDER]; + _pos set [1, _posY + 4 * _posH + 5 * BORDER + _timestampOffset]; _pos set [2, _posW]; _aceAngleSliderText ctrlSetPosition _pos; _aceAngleSliderText ctrlCommit 0; @@ -146,13 +199,13 @@ private _offsetButtons = 0; if (isMultiplayer) then { - _pos set [1,_posY + 5 * _posH + 7 * BORDER]; + _pos set [1,_posY + 5 * _posH + 7 * BORDER + _timestampOffset]; _pos set [3,_posH]; _descriptionChannel ctrlSetStructuredText parseText format ["%1:", localize "str_a3_cfgvehicles_modulerespawnposition_f_arguments_marker_0"]; _descriptionChannel ctrlSetPosition _pos; _descriptionChannel ctrlCommit 0; - _pos set [1,_posY + 6 * _posH + 7 * BORDER]; + _pos set [1,_posY + 6 * _posH + 7 * BORDER + _timestampOffset]; _pos set [3,_posH]; _channel ctrlSetPosition _pos; _channel ctrlCommit 0; @@ -199,7 +252,7 @@ }; //--- ButtonOK - _pos set [1, _posY + _offsetButtons]; + _pos set [1, _posY + _offsetButtons + _timestampOffset]; _pos set [2, _posW / 2 - BORDER]; _pos set [3, _posH]; _buttonOk ctrlSetPosition _pos; @@ -207,12 +260,18 @@ //--- ButtonCancel _pos set [0, _posX + _posW / 2]; - _pos set [1, _posY + _offsetButtons]; + _pos set [1, _posY + _offsetButtons + _timestampOffset]; _pos set [2, _posW / 2]; _pos set [3, _posH]; _buttonCancel ctrlSetPosition _pos; _buttonCancel ctrlCommit 0; + //////////////////// + // init marker timestamp cb + + _buttonOK ctrlAddEventHandler ['ButtonClick', FUNC(onButtonClickConfirm)]; + _aceTimestamp ctrlAddEventHandler ['CheckedChanged', FUNC(onCheckedChangedTimestamp)]; + //////////////////// // init marker shape lb lbClear _aceShapeLB; diff --git a/addons/markers/functions/fnc_onButtonClickConfirm.sqf b/addons/markers/functions/fnc_onButtonClickConfirm.sqf new file mode 100644 index 0000000000..caa49a0e1c --- /dev/null +++ b/addons/markers/functions/fnc_onButtonClickConfirm.sqf @@ -0,0 +1,42 @@ +#include "script_component.hpp" +#include "\a3\ui_f\hpp\defineResincl.inc" +/* + * Author: Freddo + * When the confirm button is pressed. + * + * Arguments: + * 0: Confirm button + * + * Return Value: + * None + * + * Example: + * [_buttonOk] call ACE_markers_fnc_onButtonClickConfirm + * + * Public: No + */ +params ["_buttonOk"]; + +private _display = ctrlParent _buttonOk; +private _description = _display displayctrl IDC_INSERT_MARKER; +private _aceTimestamp = _display displayCtrl IDC_ACE_INSERT_MARKER_TIMESTAMP; + +// Handle timestamp +if (cbChecked _aceTimestamp && {[ACE_player] call FUNC(canTimestamp)}) then { + private _time = daytime; + private _ampm = switch (true) do { + case (GVAR(timestampHourFormat) == 24): {""}; + case (_time < 12): {" am"}; + case (_time > 12): {SUB(_time,12); " pm"}; + }; + + _description ctrlSetText format [ // Add timestamp suffix + "%1%2[%2%3]", + ctrlText _description, + TIMESTAMP_SPACE, + [_time, GVAR(timestampFormat)] call BIS_fnc_timeToString, + _ampm + ]; +}; + +nil diff --git a/addons/markers/functions/fnc_onCheckedChangedTimestamp.sqf b/addons/markers/functions/fnc_onCheckedChangedTimestamp.sqf new file mode 100644 index 0000000000..23a3b8c73d --- /dev/null +++ b/addons/markers/functions/fnc_onCheckedChangedTimestamp.sqf @@ -0,0 +1,23 @@ +#include "script_component.hpp" +#include "\a3\ui_f\hpp\defineResincl.inc" +/* + * Author: Freddo + * When the timestamp checkbox is toggled + * + * Arguments: + * 0: Checkbox + * 1: Value + * + * Return Value: + * None + * + * Example: + * [_cbTimestamp,1] call ACE_markers_fnc_onCheckedChangedTimestamp + * + * Public: No + */ +params ["_cbTimestamp", "_checked"]; + +SETUVAR(GVAR(timestampChecked),(_checked == 1)); + +nil diff --git a/addons/markers/functions/fnc_onLBSelChangedColor.sqf b/addons/markers/functions/fnc_onLBSelChangedColor.sqf index a141f7e72d..df45213b8e 100644 --- a/addons/markers/functions/fnc_onLBSelChangedColor.sqf +++ b/addons/markers/functions/fnc_onLBSelChangedColor.sqf @@ -1,4 +1,5 @@ #include "script_component.hpp" +#include "\a3\ui_f\hpp\defineResincl.inc" /* * Author: commy2 * When the color list box is changed. @@ -29,10 +30,10 @@ GVAR(currentMarkerColorConfigName) = configName _config; //Set map display to same color: private _bisColorLB = switch (false) do { - case (isNull findDisplay 12): {(findDisplay 12) displayCtrl 1090}; - case (isNull findDisplay 52): {(findDisplay 52) displayCtrl 1090}; - case (isNull findDisplay 53): {(findDisplay 53) displayCtrl 1090}; - case (isNull findDisplay 37): {(findDisplay 37) displayCtrl 1090}; + case (isNull findDisplay 12): {(findDisplay 12) displayCtrl IDC_DIARY_MARKER_COLOR}; + case (isNull findDisplay 52): {(findDisplay 52) displayCtrl IDC_DIARY_MARKER_COLOR}; + case (isNull findDisplay 53): {(findDisplay 53) displayCtrl IDC_DIARY_MARKER_COLOR}; + case (isNull findDisplay 37): {(findDisplay 37) displayCtrl IDC_DIARY_MARKER_COLOR}; default {controlNull}; }; if (_ctrl != _bisColorLB) then { //Don't set what we got a EH from diff --git a/addons/markers/functions/fnc_onLBSelChangedShape.sqf b/addons/markers/functions/fnc_onLBSelChangedShape.sqf index 52a85e5c8d..25e6b54468 100644 --- a/addons/markers/functions/fnc_onLBSelChangedShape.sqf +++ b/addons/markers/functions/fnc_onLBSelChangedShape.sqf @@ -1,4 +1,5 @@ #include "script_component.hpp" +#include "\a3\ui_f\hpp\defineResincl.inc" /* * Author: commy2 * When the shape list box is changed. @@ -29,10 +30,10 @@ GVAR(currentMarkerConfigName) = configName _config; //Set map display to same shape: private _bisShapeLB = switch (false) do { - case (isNull findDisplay 12): {(findDisplay 12) displayCtrl 1091}; - case (isNull findDisplay 52): {(findDisplay 52) displayCtrl 1091}; - case (isNull findDisplay 53): {(findDisplay 53) displayCtrl 1091}; - case (isNull findDisplay 37): {(findDisplay 37) displayCtrl 1091}; + case (isNull findDisplay 12): {(findDisplay 12) displayCtrl IDC_DIARY_MARKER_ICON}; + case (isNull findDisplay 52): {(findDisplay 52) displayCtrl IDC_DIARY_MARKER_ICON}; + case (isNull findDisplay 53): {(findDisplay 53) displayCtrl IDC_DIARY_MARKER_ICON}; + case (isNull findDisplay 37): {(findDisplay 37) displayCtrl IDC_DIARY_MARKER_ICON}; default {controlNull}; }; if (_ctrl != _bisShapeLB) then { //Don't set what we got a EH from diff --git a/addons/markers/functions/fnc_onSliderPosChangedAngle.sqf b/addons/markers/functions/fnc_onSliderPosChangedAngle.sqf index c334d0a8f0..20f63e7115 100644 --- a/addons/markers/functions/fnc_onSliderPosChangedAngle.sqf +++ b/addons/markers/functions/fnc_onSliderPosChangedAngle.sqf @@ -25,6 +25,6 @@ if (_direction < 0) then { _direction = _direction + 360; }; -((ctrlParent _ctrl) displayCtrl 1221) ctrlSetText format [localize LSTRING(MarkerDirection), _direction]; +((ctrlParent _ctrl) displayCtrl IDC_ACE_INSERT_MARKER_ANGLE_TEXT) ctrlSetText format [localize LSTRING(MarkerDirection), _direction]; GVAR(currentMarkerAngle) = _data; diff --git a/addons/markers/initSettings.sqf b/addons/markers/initSettings.sqf index e4aa16b00f..35d1cca4bb 100644 --- a/addons/markers/initSettings.sqf +++ b/addons/markers/initSettings.sqf @@ -1,7 +1,9 @@ +private _categoryName = format ["ACE %1", localize ELSTRING(map,Module_DisplayName)]; + [ QGVAR(moveRestriction), "LIST", [LSTRING(MoveRestriction), LSTRING(MoveRestriction_Description)], - [format ["ACE %1", localize ELSTRING(map,Module_DisplayName)], localize LSTRING(Module_DisplayName)], + [_categoryName, LLSTRING(Module_DisplayName)], [ [ MOVE_RESTRICTION_NOBODY, @@ -22,3 +24,56 @@ 1 ] ] call cba_settings_fnc_init; + +[ + QGVAR(timestampEnabled), "CHECKBOX", + [LSTRING(TimestampEnabled), LSTRING(TimestampEnabledDescription)], + [_categoryName, LLSTRING(Module_DisplayName)], + true +] call CBA_fnc_addSetting; + +[ + QGVAR(timestampHourFormat), "LIST", + [LSTRING(TimestampHourFormat), LSTRING(TimestampHourFormatDescription)], + [_categoryName, LLSTRING(Module_DisplayName)], + [ + [ + 24, + 12 + ], + [ + LSTRING(TimestampHourFormat24), + LSTRING(TimestampHourFormat12) + ], + 0 + ] +] call CBA_fnc_addSetting; + +private _formatDescription = [ + LLSTRING(TimestampFormatDescription0), + LLSTRING(TimestampFormatDescription1), + LLSTRING(TimestampFormatDescription2), + LLSTRING(TimestampFormatDescription3), + LLSTRING(TimestampFormatDescription4) +] joinString "\n"; + +[ + QGVAR(timestampFormat), "LIST", + [LSTRING(timestampFormat), _formatDescription], + [_categoryName, LLSTRING(Module_DisplayName)], + [ + [ + "HH", + "HH:MM", + "HH:MM:SS", + "HH:MM:SS:MM" + ], + [ + "HH", + "HH:MM", + "HH:MM:SS", + "HH:MM:SS:MM" + ], + 1 + ] +] call CBA_fnc_addSetting; diff --git a/addons/markers/script_component.hpp b/addons/markers/script_component.hpp index 8b268e2d03..a40e557135 100644 --- a/addons/markers/script_component.hpp +++ b/addons/markers/script_component.hpp @@ -24,9 +24,19 @@ localize "str_channel_vehicle" \ ] -#define MOVE_RESTRICTION_NOBODY -1 -#define MOVE_RESTRICTION_ALL 0 -#define MOVE_RESTRICTION_ADMINS 1 -#define MOVE_RESTRICTION_GROUP_LEADERS 2 -#define MOVE_RESTRICTION_GROUP_LEADERS_ADMINS 3 -#define MOVE_RESTRICTION_OWNER 4 +// 129 just looks like a space +#define TIMESTAMP_SPACE (toString [129]) + +#define MOVE_RESTRICTION_NOBODY -1 +#define MOVE_RESTRICTION_ALL 0 +#define MOVE_RESTRICTION_ADMINS 1 +#define MOVE_RESTRICTION_GROUP_LEADERS 2 +#define MOVE_RESTRICTION_GROUP_LEADERS_ADMINS 3 +#define MOVE_RESTRICTION_OWNER 4 + +#define IDC_ACE_INSERT_MARKER_TIMESTAMP 1210 +#define IDC_ACE_INSERT_MARKER_TIMESTAMP_TEXT 1211 +#define IDC_ACE_INSERT_MARKER_SHAPE 1220 +#define IDC_ACE_INSERT_MARKER_COLOR 1221 +#define IDC_ACE_INSERT_MARKER_ANGLE 1230 +#define IDC_ACE_INSERT_MARKER_ANGLE_TEXT 1231 diff --git a/addons/markers/stringtable.xml b/addons/markers/stringtable.xml index 2add6e468e..1fb27d8a1d 100644 --- a/addons/markers/stringtable.xml +++ b/addons/markers/stringtable.xml @@ -150,5 +150,47 @@ Tvůrce Yaratıcı + + Allow Timestamps + + + Whether to allow timestamps to be automatically applied to markers + + + Add Timestamp: + + + Watch Required + + + Timestamp Format + + + Changes the timestamp format + + + "HH" - Hour + + + "MM" - Minute + + + "SS" - Seconds + + + "MM" - Milliseconds + + + Timestamp Hour Format + + + 24-Hour Clock + + + 12-Hour Clock + + + Changes timestamp to use either 24-hour or 12-hour clock format +