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

Arsenal Stats - Add support for multiline text #9856

Merged
merged 14 commits into from
Sep 9, 2024
2 changes: 2 additions & 0 deletions addons/arsenal/defines.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,8 @@
#define IDC_statsPreviousPage 52
#define IDC_statsNextPage 53
#define IDC_statsCurrentPage 54
#define IDC_statsBoxTitleBackground 55
#define IDC_statsBoxBackground 56
#define IDC_actionsBox 90
#define IDC_actionsBackground1 90010
#define IDC_actionsBackground2 90011
Expand Down
54 changes: 47 additions & 7 deletions addons/arsenal/functions/fnc_handleStats.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
params ["_display", "_control", "_curSel", ["_itemCfg", configNull]];

private _statsBoxCtrl = _display displayCtrl IDC_statsBox;
private _statsBoxTitleBackgroundCtrl = _display displayCtrl IDC_statsBoxTitleBackground;
private _statsBoxBackgroundCtrl = _display displayCtrl IDC_statsBoxBackground;
private _statsPreviousPageCtrl = _display displayCtrl IDC_statsPreviousPage;
private _statsNextPageCtrl = _display displayCtrl IDC_statsNextPage;
private _statsCurrentPageCtrl = _display displayCtrl IDC_statsCurrentPage;
Expand Down Expand Up @@ -111,6 +113,7 @@ private _fnc_handleStats = {
private _statsBarCtrl = controlNull;
private _statsTextCtrl = controlNull;
private _textStatementResult = "";
private _lastCtrl = _statsBoxTitleBackgroundCtrl;

{
_x params ["", "_configEntry", "_title", "_bools", "_statements"];
Expand All @@ -127,6 +130,17 @@ private _fnc_handleStats = {
_statsTitleCtrl ctrlSetText _title;
_statsTitleCtrl ctrlSetFade 0;

// Vertical Position
ctrlPosition _lastCtrl params ["", "_lastPosY", "", "_lastPosH"];
_statsTitleCtrl ctrlSetPositionY (_lastPosY + _lastPosH + GRID_H);
{
_x ctrlSetPositionY (_lastPosY + _lastPosH + GRID_H + (5 * GRID_H));
} forEach [
_statsBackgroundCtrl,
_statsBarCtrl,
_statsTextCtrl
];

// Handle bars
if (_showBar) then {
_statsBarCtrl progressSetPosition ([_configEntry, _itemCfg] call _barStatement);
Expand All @@ -140,18 +154,39 @@ private _fnc_handleStats = {
// Handle text entries
if (_showText) then {
_textStatementResult = [_configEntry, _itemCfg] call _textStatement;

if !(_textStatementResult isEqualType "") then {
_textStatementResult = str _textStatementResult;
if (_textStatementResult isEqualType []) then {
_textStatementResult = _textStatementResult joinString endl;
} else {
if !(_textStatementResult isEqualType "") then {
_textStatementResult = str _textStatementResult;
};
};

_statsTextCtrl ctrlSetText _textStatementResult;
_statsTextCtrl ctrlSetTextColor ([[1, 1, 1, 1], [0, 0, 0, 1]] select (_showBar));

//Height based on Text lines
{
_x ctrlSetPositionH (ctrlTextHeight _statsTextCtrl);
} forEach [
_statsBackgroundCtrl,
_statsBarCtrl,
_statsTextCtrl
];

_statsTextCtrl ctrlSetFade 0;
} else {
_statsTextCtrl ctrlSetFade 1;
//Ensure default height
{
_x ctrlSetPositionH (5 * GRID_H);
} forEach [
_statsBackgroundCtrl,
_statsBarCtrl,
_statsTextCtrl
];
};

{
_x ctrlCommit 0;
} forEach [
Expand All @@ -160,24 +195,29 @@ private _fnc_handleStats = {
_statsBarCtrl,
_statsTextCtrl
];

_lastCtrl = _statsTextCtrl;

} forEach _statsToDisplay;


// Resize the window
(5 - _statsCount) call _fnc_hideUnused;
private _height = 10 * _statsCount + 5;
ctrlPosition _lastCtrl params ["", "_lastPosY", "", "_lastPosH"];
_statsBoxCtrl ctrlSetPosition [
(0.5 - WIDTH_TOTAL / 2) + WIDTH_GAP,
safeZoneY + 1.8 * GRID_H,
47 * GRID_W,
_height * GRID_H
_lastPosY + _lastPosH + GRID_H
];
_statsBoxBackgroundCtrl ctrlSetPositionH (_lastPosY + _lastPosH + GRID_H);
_statsBoxBackgroundCtrl ctrlCommit 0;
_statsBoxCtrl ctrlCommit 0;

// Move the actions box
private _ctrl = _display displayCtrl IDC_actionsBox;
private _pos = ctrlPosition _ctrl;
_pos set [1, safeZoneY + (_height + 3.6) * GRID_H];
_pos set [1, safeZoneY + (_lastPosY + _lastPosH + GRID_H + (3.6 * GRID_H))];
_ctrl ctrlSetPosition _pos;
_ctrl ctrlCommit 0;

Expand Down
14 changes: 7 additions & 7 deletions addons/arsenal/ui/RscAttributes.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -283,15 +283,15 @@ class GVAR(display) {
h = QUOTE(55 * GRID_H);
class controls {
class statsStaticBackground1: ctrlStaticBackground {
idc = -1;
idc = IDC_statsBoxBackground;
x = QUOTE(0);
y = QUOTE(0);
w = QUOTE(47 * GRID_W);
h = QUOTE(55 * GRID_H);
colorBackground[] = {0.1,0.1,0.1,0.5};
};
class statsStaticBackground2: ctrlStaticBackground {
idc = -1;
idc = IDC_statsBoxTitleBackground;
x = QUOTE(0);
y = QUOTE(0);
w = QUOTE(47 * GRID_W);
Expand All @@ -316,7 +316,7 @@ class GVAR(display) {
x = QUOTE(1 * GRID_W);
y = QUOTE(10 * GRID_H);
w = QUOTE(45 * GRID_W);
h = QUOTE(4 * GRID_H);
h = QUOTE(5 * GRID_H);
colorBackground[] = {1,1,1,0.15};
};
class statsBar1: ctrlProgress {
Expand All @@ -329,9 +329,9 @@ class GVAR(display) {
x = QUOTE(1 * GRID_W);
y = QUOTE(10 * GRID_H);
w = QUOTE(45 * GRID_W);
h = QUOTE(4 * GRID_H);
h = QUOTE(5 * GRID_H);
LinkIsGrim marked this conversation as resolved.
Show resolved Hide resolved
};
class statsText1: RscText {
class statsText1: RscTextMulti {
idc = IDC_statsText1;
shadow = 0;
fade = 1;
Expand All @@ -340,7 +340,7 @@ class GVAR(display) {
x = QUOTE(0 * GRID_W);
y = QUOTE(10 * GRID_H);
w = QUOTE(45 * GRID_W);
h = QUOTE(4 * GRID_H);
h = QUOTE(5 * GRID_H);
sizeEx = QUOTE(5 * GRID_H);
text = "";
};
Expand Down Expand Up @@ -482,7 +482,7 @@ class GVAR(display) {
x = QUOTE(1 * GRID_W);
y = QUOTE(6 * GRID_H);
w = QUOTE(45 * GRID_W);
h = QUOTE(4 * GRID_H);
h = QUOTE(5 * GRID_H);
};
class actionsText2: actionsText1 {
idc = IDC_actionsText2;
Expand Down
2 changes: 1 addition & 1 deletion docs/wiki/framework/arsenal-framework.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ class ace_arsenal_stats {
showBar = 1; // 0 disabled; 1 enabled;
showText = 1; // 0 disabled; 1 enabled;
barStatement = "1"; // Statement evaluated to set the bar progress, needs to return a NUMBER.
textStatement = "test entry"; // statement evaluated to set the text entry, can return anything.
textStatement = "test entry"; // statement evaluated to set the text entry, can return anything. Arrays will have a linebreak added after each element.
condition = "true"; // Condition for the stats to be displayed, default is true if not defined, needs to return a BOOL.
tabs[] = { {0,1,2}, { } }; // Arrays of tabs, left array is left tabs, right array is right tabs.
};
Expand Down
Loading