Skip to content

Commit

Permalink
Buy Menu Vehicle Render (#2356)
Browse files Browse the repository at this point in the history
Hovering over vehicle menu buy button renders a preview of the vehicle. For when the mod-pack (Unsung) doesn't include images.
  • Loading branch information
CalebSerafin authored May 22, 2022
1 parent 7b6ddb2 commit 29338c8
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 4 deletions.
6 changes: 6 additions & 0 deletions A3A/addons/GUI/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ class CfgFunctions {
class requestMissionDialog {};
};
};
class A3A_GUI {
class ObjectHelpers {
file = QPATHTOFOLDER(functions\ObjectHelpers);
class sizeOf {};
};
};
};
28 changes: 28 additions & 0 deletions A3A/addons/GUI/dialogues/buyVehicleDialog.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,32 @@ class A3A_BuyVehicleDialog : A3A_DefaultDialog
y = DIALOG_Y - 5 * GRID_H;
};
};

// Used for preview renders. Has to be defined inline. Class inheritance incompatible. ctrlCreate incompatible.
class Objects
{
class VehiclePreview
{
idc = A3A_IDC_BUYVEHICLEOBJECTRENDER;

type = 82;
model = "\A3\Structures_F\Items\Food\Can_V3_F.p3d";
scale = 0.00001; // Hide unless there is a mouse hover. This is overwritten by proper ctrlShow command on initialisation.

direction[] = {0, -0.35, -0.65};
up[] = {0, 0.65, -0.35};

x = 0.5;
y = 0.5;
z = 0.2;

xBack = 0.5;
yBack = 0.5;
zBack = 1.2;

inBack = 1;
enableZoom = 1;
zoomDuration = 0.001;
};
};
};
2 changes: 2 additions & 0 deletions A3A/addons/GUI/dialogues/ids.inc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ Maintainer: DoomMetal
#define A3A_IDD_BUYVEHICLEDIALOG 9300
#define A3A_IDC_BUYVEHICLEMAIN 9301
#define A3A_IDC_VEHICLESGROUP 9302
#define A3A_IDC_BUYVEHICLEOBJECTRENDER 9303
#define A3A_IDC_BUYVEHICLEPREVIEW 9304

// Load last save
#define A3A_IDC_LOADDIALOG 9400
Expand Down
76 changes: 72 additions & 4 deletions A3A/addons/GUI/functions/GUI/fn_buyVehicleDialog.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ switch (_mode) do

private _display = findDisplay A3A_IDD_BUYVEHICLEDIALOG;

// Setup Object render
private _objPreview = _display displayCtrl A3A_IDC_BUYVEHICLEOBJECTRENDER; // 9303;
_objPreview ctrlShow false;

// Add stuff to the buyable vehicles list
private _buyableVehiclesList = [];

Expand Down Expand Up @@ -86,8 +90,17 @@ switch (_mode) do
private _configClass = configFile >> "CfgVehicles" >> _className;
private _displayName = getText (_configClass >> "displayName");
private _editorPreview = getText (_configClass >> "editorPreview");

if (!fileExists _editorPreview) then {
//private _vehicleIcon= getText (_configClass >> "Icon");
private _model = getText (_configClass >> "model");

private _hasVehiclePreview = fileExists _editorPreview;
/* Turn on if you want the icons as a midway fallback
if (!_hasVehiclePreview && fileExists _vehicleIcon) then {
_editorPreview = _vehicleIcon;
_hasVehiclePreview = true;
};
*/
if (!_hasVehiclePreview) then {
_editorPreview = A3A_PlaceHolder_NoVehiclePreview;
};

Expand All @@ -102,7 +115,7 @@ switch (_mode) do
_itemControlsGroup ctrlSetFade 1;
_itemControlsGroup ctrlCommit 0;

private _previewPicture = _display ctrlCreate ["A3A_Picture", -1, _itemControlsGroup];
private _previewPicture = _display ctrlCreate ["A3A_Picture", A3A_IDC_BUYVEHICLEPREVIEW, _itemControlsGroup];
_previewPicture ctrlSetPosition [0, 0, 44 * GRID_W, 25 * GRID_H];
_previewPicture ctrlSetText _editorPreview;
_previewPicture ctrlCommit 0;
Expand All @@ -112,9 +125,64 @@ switch (_mode) do
_button ctrlSetText _displayName;
_button ctrlSetTooltip format [localize "STR_antistasi_dialogs_buy_vehicle_button_tooltip", _displayName, _price, ""];
_button setVariable ["className", _className];
_button ctrlAddEventHandler ["ButtonClick", {closeDialog 2; [(_this # 0) getVariable "className"] spawn A3A_fnc_addFIAveh}];
_button setVariable ["model", _model];
_button ctrlAddEventHandler ["ButtonClick", {
closeDialog 2; [(_this # 0) getVariable "className"] spawn A3A_fnc_addFIAveh;
}];
_button ctrlCommit 0;

// Object Render
_button ctrlAddEventHandler ["MouseEnter", {
params ["_control"];
if (true || isNil "Dev_GUI_prevInjectEnter") then {
params ["_control"];
private _UIScaleAdjustment = (0.55/getResolution#5); // I tweaked this on UI Small, so that's why the 0.55 is the base size.

private _model = _control getVariable "model";
private _className = _control getVariable "className";
private _display = findDisplay A3A_IDD_BUYVEHICLEDIALOG; // 9300;
private _objPreview = _display displayCtrl A3A_IDC_BUYVEHICLEOBJECTRENDER; // 9303;
_objPreview ctrlSetModel _model;
private _boundingDiameter = [_className] call FUNC(sizeOf);
_objPreview ctrlSetModelScale (2.25/(_boundingDiameter) * _UIScaleAdjustment);
_objPreview ctrlSetModelDirAndUp [[-0.6283,0.3601,0.6896],[-0.0125,-0.5015,0.8651]]; // x y z

private _editorPreviewPicture = ctrlParentControlsGroup _control controlsGroupCtrl A3A_IDC_BUYVEHICLEPREVIEW; // 9304;
// A3A_faction_reb set ['vehicleLightArmed',"B_T_VTOL_01_vehicle_F"]; // Big test item.
private _mouseAbsolutePos = getMousePosition;
private _mouseRelativePos = ctrlMousePosition _editorPreviewPicture;
_mouseAbsolutePos vectorDiff _mouseRelativePos params ["_objPreview_x", "_objPreview_y"];


private _yAdjustment = 0.25 * _UIScaleAdjustment;
_objPreview ctrlSetPosition [_objPreview_x + 0.5 * (22 * pixelW * pixelGridNoUIScale), 4, _objPreview_y - 0.5 * (12.5 * pixelW * pixelGridNoUIScale) + _yAdjustment];
_editorPreviewPicture ctrlShow false;
_editorPreviewPicture ctrlCommit 1;

_objPreview ctrlShow true;
_objPreview ctrlEnable false; // Prevent the user dragging it.
} else {
_control call Dev_GUI_prevInjectEnter;
};
}];
_button ctrlAddEventHandler ["MouseExit", {
params ["_control"];
if (true || isNil "Dev_GUI_prevInjectExit") then {
params ["_control"];
private _display = findDisplay A3A_IDD_BUYVEHICLEDIALOG; // 9300;
private _objPreview = _display displayCtrl A3A_IDC_BUYVEHICLEOBJECTRENDER; // 9303;

private _editorPreviewPicture = ctrlParentControlsGroup _control controlsGroupCtrl A3A_IDC_BUYVEHICLEPREVIEW; // 9304;

_editorPreviewPicture ctrlShow true;
_editorPreviewPicture ctrlCommit 1;

_objPreview ctrlShow false;
} else {
_control call Dev_GUI_prevInjectExit;
};
}];

private _priceText = _display ctrlCreate ["A3A_InfoTextRight", -1, _itemControlsGroup];
_priceText ctrlSetPosition[23 * GRID_W, 21 * GRID_H, 20 * GRID_W, 3 * GRID_H];
_priceText ctrlSetText format ["%1 €",_price];
Expand Down
52 changes: 52 additions & 0 deletions A3A/addons/GUI/functions/ObjectHelpers/fn_sizeOf.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
Maintainer: Caleb Serafin
Similar to sizeOf, but it will always return the accurate size.
The bounding-box diameters are cached after the first sizeOf call.
If sizeOf returns 0, a vehicle will be created temporally for measurement.
Arguments:
<STRING> Vehicle Classname.
Return Value:
<SCALAR> The bounding-box diameter of the vehicle.
Scope: Any, Local Effect
Environment: Any
Public: Yes
Example:
["C_Offroad_01_F"] call A3A_GUI_fnc_sizeOf; // 11.4563
["C_Heli_Light_01_civil_F"] call A3A_GUI_fnc_sizeOf; // 12.6111
// Within GUI
["C_Offroad_01_F"] call FUNC(sizeOf); // 11.4563
*/

params [
["_classname", "", [""]]
];

if (isNil "A3A_GUI_sizeOf_cache") then {
A3A_GUI_sizeOf_cache = createHashMap;
};

if (_classname in A3A_GUI_sizeOf_cache) exitWith {
A3A_GUI_sizeOf_cache get _classname; // Object is cached.
};

private _diameter = sizeOf _classname;
if (_diameter != 0) exitWith {
A3A_GUI_sizeOf_cache set [_classname, _diameter];
_diameter; // Object was not cached but did exist.
};

private _object = createVehicle [_classname, [random 1000, random 1000, 1000 + random 1000], [], 0, "CAN_COLLIDE"];

if (isNull _object) exitWith {
0; // Object does not exist.
};

_diameter = sizeOf _classname;
deleteVehicle _object;
A3A_GUI_sizeOf_cache set [_classname, _diameter];
_diameter; // Object was not cached and did not exist.

0 comments on commit 29338c8

Please sign in to comment.