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 all commits
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);
100 changes: 45 additions & 55 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 @@ -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
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 (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
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
70 changes: 70 additions & 0 deletions addons/markers/functions/fnc_removeTimestamp.sqf
Original file line number Diff line number Diff line change
@@ -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
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};

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