Fix Multiple Issues With Timestamps (#8034)

* Fix Multiple Issues With Timestamps

* simplify

* improve parsing of timestamps

Co-authored-by: PabstMirror <pabstmirror@gmail.com>
This commit is contained in:
commy2 2021-02-27 00:17:00 +01:00 committed by GitHub
parent bac47bb292
commit 50578a2463
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 164 additions and 115 deletions

View File

@ -17,3 +17,4 @@ PREP(movePFH);
PREP(canTimestamp);
PREP(onButtonClickConfirm);
PREP(onCheckedChangedTimestamp);
PREP(removeTimestamp);

View File

@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\A3\ui_f\hpp\defineResincl.inc"
/*
* Author: BIS, commy2, Timi007
* Sets up the marker placement
@ -40,10 +39,8 @@
private _descriptionChannel = _display displayctrl 1101;
//ACE Controls:
// _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 _ctrlTimestamp = _display displayCtrl IDC_ACE_INSERT_MARKER_TIMESTAMP;
private _ctrlTimestampText = _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;
@ -92,19 +89,11 @@
// prevent vanilla key input
_display displayAddEventHandler ["KeyDown", {(_this select 1) in [200, 208]}];
private _hasTimestamp = false;
if !((markerText GVAR(editingMarker)) isEqualTo "") then {
private _markerText = markerText GVAR(editingMarker);
if (_markerText != "") then {
// 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;
_markerText = _markerText call FUNC(removeTimestamp);
_text ctrlSetText _markerText;
};
//Focus on the text input
@ -143,31 +132,33 @@
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 ["<t size='0.8'>%1</t>", LLSTRING(Timestamp)];
_aceTimestampText ctrlSetPosition _pos;
_aceTimestampText ctrlCommit 0;
private _left = _posX;
private _top = _posY + 1 * _posH + 2 * BORDER;
private _width = _posH * safeZoneH / safeZoneW;
private _height = _posH;
_pos set [0, _posX + _posW - _posH];
_pos set [2, _posH];
_pos set [3, _posH];
_aceTimestamp ctrlSetPosition _pos;
_aceTimestamp ctrlCommit 0;
_ctrlTimestamp ctrlSetPosition [_left, _top, _width, _height];
_ctrlTimestamp ctrlCommit 0;
_ctrlTimestampText ctrlSetStructuredText parseText format ["<t size='0.8'>%1</t>", LLSTRING(Timestamp)];
_left = _left + _width;
_width = _posW - _width;
_top = _top + 0.1 * _height;
_ctrlTimestampText ctrlSetPosition [_left, _top, _width, _height];
_ctrlTimestampText ctrlCommit 0;
if !([ACE_player] call FUNC(canTimestamp)) then {
_aceTimestamp ctrlEnable false;
_aceTimestamp ctrlSetTooltip LLSTRING(TimestampTooltipNoWatch);
_ctrlTimestamp ctrlEnable false;
_ctrlTimestamp ctrlSetTooltip LLSTRING(TimestampTooltipNoWatch);
} else {
_aceTimestamp cbSetChecked (GETUVAR(GVAR(timestampChecked),false) || _hasTimestamp);
_ctrlTimestamp cbSetChecked (uiNamespace getVariable [QGVAR(timestampChecked), false]);
};
} else {
_aceTimestampText ctrlEnable false;
_aceTimestampText ctrlShow false;
_aceTimestamp ctrlEnable false;
_aceTimestamp ctrlShow false;
_ctrlTimestampText ctrlEnable false;
_ctrlTimestampText ctrlShow false;
_ctrlTimestamp ctrlEnable false;
_ctrlTimestamp ctrlShow false;
};
//--- Shape
@ -268,9 +259,8 @@
////////////////////
// init marker timestamp cb
_buttonOK ctrlAddEventHandler ['ButtonClick', FUNC(onButtonClickConfirm)];
_aceTimestamp ctrlAddEventHandler ['CheckedChanged', FUNC(onCheckedChangedTimestamp)];
_buttonOK ctrlAddEventHandler ["ButtonClick", FUNC(onButtonClickConfirm)];
_ctrlTimestamp ctrlAddEventHandler ["CheckedChanged", FUNC(onCheckedChangedTimestamp)];
////////////////////
// init marker shape lb

View File

@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: Freddo
* When the confirm button is pressed.
@ -21,22 +20,34 @@ 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 {
// 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"};
// add timestamp suffix
private _periodPostfix = "";
if (GVAR(timestampHourFormat) == 12) then {
if (floor _time == 0) exitWith {
_time = _time + 12;
_periodPostfix = " am";
};
_description ctrlSetText format [ // Add timestamp suffix
"%1%2[%2%3]",
if (floor _time == 12) exitWith {
_periodPostfix = " pm";
};
if (_time < 12) then {
_periodPostfix = " am";
} else {
_time = _time - 12;
_periodPostfix = " pm";
};
};
_description ctrlSetText format [
"%1 [%2%3]",
ctrlText _description,
TIMESTAMP_SPACE,
[_time, GVAR(timestampFormat)] call BIS_fnc_timeToString,
_ampm
_periodPostfix
];
};
nil

View File

@ -1,8 +1,7 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: Freddo
* When the timestamp checkbox is toggled
* Author: Freddo, commy2
* When the timestamp checkbox is toggled.
*
* Arguments:
* 0: Checkbox <CONTROL>
@ -12,12 +11,10 @@
* None
*
* Example:
* [_cbTimestamp,1] call ACE_markers_fnc_onCheckedChangedTimestamp
* [controlNull, 1] call ACE_markers_fnc_onCheckedChangedTimestamp;
*
* Public: No
*/
params ["_cbTimestamp", "_checked"];
params ["", "_checked"];
SETUVAR(GVAR(timestampChecked),(_checked == 1));
nil
uiNamespace setVariable [QGVAR(timestampChecked), _checked == 1]

View File

@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: commy2
* When the color list box is changed.

View File

@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: commy2
* When the shape list box is changed.

View File

@ -0,0 +1,70 @@
#include "script_component.hpp"
/*
* Author: commy2
* Removes timestamp from end of a string.
*
* Arguments:
* 0: Marker text string <STRING>
*
* Return Value:
* Input with timestamp removed <STRING>
*
* Example:
* "abc [12:00 am]" call ace_markers_fnc_removeTimestamp // "abc"
* "[13:37]" call ace_markers_fnc_removeTimestamp // ""
* "xyz [123]" call ace_markers_fnc_removeTimestamp // "xyz [123]"
* "xyz [12]" call ace_markers_fnc_removeTimestamp // "xyz"
* "xyz [12 pm]" call ace_markers_fnc_removeTimestamp // "xyz"
*
* Public: No
*/
#define DIGITS "0123456789"
params ["_original"];
// @todo, 2.02 reverse command will support STRING types
private _string = toArray _original;
reverse _string;
_string = toString _string;
if (_string select [0, 1] != "]") exitWith {_original};
private _timestampLength = (_string find "[") + 1;
_string = _string select [0, _timestampLength];
// @todo
_string = toArray _string;
reverse _string;
_string = toString _string;
if (_string select [0, 1] != "[") exitWith {_original};
private _index = 1;
private _keepCheckingDigits = true;
private _validTimestamp = true;
while {_keepCheckingDigits} do {
if (!(_string select [_index, 1] in DIGITS)) exitWith { _validTimestamp = false; };
if (!(_string select [_index+1, 1] in DIGITS)) exitWith { _validTimestamp = false; };
switch (_string select [_index+2, 1]) do {
case (":"): {
_index = _index + 3;
};
case ("]"): {
_keepCheckingDigits = false;
};
case (" "): {
_keepCheckingDigits = false;
if (!(_string select [_index+3, 3] in ["am]", "pm]"])) then {_validTimestamp = false; };
};
default {
_keepCheckingDigits = false;
_validTimestamp = false;
};
};
};
if (_validTimestamp) then {
[_original select [0, count _original - _timestampLength], " "] call CBA_fnc_rightTrim // return
} else {
_original // return
}

View File

@ -37,14 +37,8 @@ private _categoryName = format ["ACE %1", localize ELSTRING(map,Module_DisplayNa
[LSTRING(TimestampHourFormat), LSTRING(TimestampHourFormatDescription)],
[_categoryName, LLSTRING(Module_DisplayName)],
[
[
24,
12
],
[
LSTRING(TimestampHourFormat24),
LSTRING(TimestampHourFormat12)
],
[24, 12],
[LSTRING(TimestampHourFormat24), LSTRING(TimestampHourFormat12)],
0
]
] call CBA_fnc_addSetting;
@ -55,25 +49,15 @@ private _formatDescription = [
LLSTRING(TimestampFormatDescription2),
LLSTRING(TimestampFormatDescription3),
LLSTRING(TimestampFormatDescription4)
] joinString "\n";
] joinString endl;
[
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"
],
["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;

View File

@ -15,6 +15,7 @@
#endif
#include "\z\ace\addons\main\script_macros.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
#define CHANNEL_NAMES [ \
localize "str_channel_global", \
@ -24,9 +25,6 @@
localize "str_channel_vehicle" \
]
// 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

View File

@ -159,8 +159,8 @@
<French>Active une interface permettant d'apposer un horodatage sur les marqueurs.</French>
</Key>
<Key ID="STR_ACE_Markers_Timestamp">
<English>Add Timestamp:</English>
<French>Ajouter l'horodatage</French>
<English>Timestamp</English>
<French>Horodatage</French>
</Key>
<Key ID="STR_ACE_Markers_TimestampTooltipNoWatch">
<English>Watch Required</English>