Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Multiple Issues With Timestamps #8034

Merged
merged 3 commits into from
Feb 26, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions addons/markers/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ PREP(movePFH);
PREP(canTimestamp);
PREP(onButtonClickConfirm);
PREP(onCheckedChangedTimestamp);
PREP(removeTimestamp);
96 changes: 43 additions & 53 deletions addons/markers/functions/fnc_initInsertMarker.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\A3\ui_f\hpp\defineResincl.inc"
/*
* Author: BIS, commy2, Timi007
* Sets up the marker placement
Expand All @@ -26,30 +25,28 @@

//Can't place markers when can't interact
if !([ACE_player, objNull, ["notOnMap", "isNotInside", "isNotSitting"]] call EFUNC(common,canInteractWith)) exitWith {
_display closeDisplay 2; //emulate "Cancel" button
_display closeDisplay 2; //emulate "Cancel" button
};

//BIS Controls:
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;
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 _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 _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;
private _aceAngleSliderText = _display displayctrl IDC_ACE_INSERT_MARKER_ANGLE_TEXT;

private _mapDisplay = displayParent _display;
if (isNull _mapDisplay) exitWith {ERROR("No Map");};
private _mapCtrl = _mapDisplay displayCtrl IDC_MAP;

Expand Down Expand Up @@ -93,17 +90,9 @@
_display displayAddEventHandler ["KeyDown", {(_this select 1) in [200, 208]}];

private _hasTimestamp = false;
if !((markerText GVAR(editingMarker)) isEqualTo "") then {
if !(markerText GVAR(editingMarker) isEqualTo "") then {
jonpas marked this conversation as resolved.
Show resolved Hide resolved
// 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];
};

private _originalText = markerText GVAR(editingMarker) call FUNC(removeTimestamp);
jonpas marked this conversation as resolved.
Show resolved Hide resolved
_text ctrlSetText _originalText;
};

Expand All @@ -114,7 +103,7 @@
private _pos = ctrlposition _text;
_pos params ["_posX", "_posY", "_posW", "_posH"];
_posX = _posX + 0.01;
_posY = _posY min ((safeZoneH + safeZoneY) - (8 * _posH + 8 * BORDER)); //prevent buttons being placed below bottom edge of screen
_posY = _posY min ((safeZoneH + safeZoneY) - (8 * _posH + 8 * BORDER)); //prevent buttons being placed below bottom edge of screen
_pos set [0, _posX];
_pos set [1, _posY];
_text ctrlSetPosition _pos;
Expand Down Expand Up @@ -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 (GETUVAR(GVAR(timestampChecked),false) || _hasTimestamp);
};
} 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
Expand Down Expand Up @@ -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
Expand Down
37 changes: 24 additions & 13 deletions addons/markers/functions/fnc_onButtonClickConfirm.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: Freddo
* When the confirm button is pressed.
Expand All @@ -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";
};

if (floor _time == 12) exitWith {
_periodPostfix = " pm";
};

if (_time < 12) then {
_periodPostfix = " am";
} else {
_time = _time - 12;
_periodPostfix = " pm";
};
};

_description ctrlSetText format [ // Add timestamp suffix
"%1%2[%2%3]",
_description ctrlSetText format [
"%1 [%2%3]",
ctrlText _description,
TIMESTAMP_SPACE,
[_time, GVAR(timestampFormat)] call BIS_fnc_timeToString,
_ampm
_periodPostfix
];
};

nil
13 changes: 5 additions & 8 deletions addons/markers/functions/fnc_onCheckedChangedTimestamp.sqf
Original file line number Diff line number Diff line change
@@ -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>
Expand All @@ -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]
1 change: 0 additions & 1 deletion addons/markers/functions/fnc_onLBSelChangedColor.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: commy2
* When the color list box is changed.
Expand Down
1 change: 0 additions & 1 deletion addons/markers/functions/fnc_onLBSelChangedShape.sqf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "script_component.hpp"
#include "\a3\ui_f\hpp\defineResincl.inc"
/*
* Author: commy2
* When the shape list box is changed.
Expand Down
46 changes: 46 additions & 0 deletions addons/markers/functions/fnc_removeTimestamp.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#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]"
*
* Public: No
*/
#define DIGITS "0123456789"

params ["_original"];

// @todo, 2.02 reverse command will support STRING types
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reverse does not like unicode
image
copies as "�ссѵЀѿ� �добовС�"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

: (

Copy link
Contributor

@dedmen dedmen Feb 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With forceUnicode? Can you please also make a FT ticket for that example if its really broken?

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};

if !(_string select [1, 1] in DIGITS) exitWith {_original};
if !(_string select [2, 1] in DIGITS) exitWith {_original};
if (_string select [3, 1] != ":") exitWith {_original};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fails if using "HH" format

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we just need to drop this and the next few lines to support time codes like [12]
or just drop HH format
(I'm also not sure I understand why we have "HH:MM:SS:MM" but that's unrelated)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@commy2 - I commited a fix to this PR, let me know if it looks ok

if !(_string select [4, 1] in DIGITS) exitWith {_original};
if !(_string select [5, 1] in DIGITS) exitWith {_original};

[_original select [0, count _original - _timestampLength], " "] call CBA_fnc_rightTrim // return
26 changes: 5 additions & 21 deletions addons/markers/initSettings.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
30 changes: 14 additions & 16 deletions addons/markers/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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", \
Expand All @@ -24,19 +25,16 @@
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
#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
#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
4 changes: 2 additions & 2 deletions addons/markers/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down