User Tools

Site Tools


arma2:missions:user-interface-dialog-resource

ArmA 2 User Interface Dialog Resource

ArmA 2 Forum, ArmA 2 Home, ArmA 2 Config, ArmA 2 File Formats, ArmA 2 Missions, ArmA 2 3D Modeling, ArmA 2 Scripting, ArmA 2 Terrain, ArmA 2 Texturing, ArmA 2 Tools

ArmA 2 User Interface Dialog Resource guide

Dialogs steal focus, if you don't want that, you need to create a resource. In most aspects, they are identical to dialogs with the following differences:

They are displayed using cutRsc instead of createDialog.

You cannot control interactive controls (buttons, text fields, etc.), obviously

They are defined a bit differently. I'll use your dialog to demonstrate.

class RscTitles //All resources reside in this class
{
    class TAG_RscWhatever
    {
        idd = -1; //IDD is irrelevant, we can't access the resource by it anyway
        duration = 1e+1000; //Time in seconds the resource will stay visible for. 1e+1000 = 1 * 10^1000 = never disappear
        fadeIn = 0; //Length of the fade-in effect (smooth transition from transparent to opaque upon creation) in seconds. 0 = no fade-in, display immediately.
        fadeOut = 0; //Length of the fade-out effect (smooth transition from opaque to transparent once duration elapses) in seconds. 0 = no fade-out, just hide immediately.
        name = ""; //Name of the resource. This is irrelevant for resources defined in the mission.
        onLoad = "uiNamespace setVariable ['TAG_RscWhatever_display', _this select 0];"; //A command executed upon the resource's creation. In this case we store this resource's "display" in a variable for later use via a script (such as to change the text of a RscText or read the value from RscEdit, etc.), but more on that later. If you don't plan on doing that, you can leave out this line.
 
        //movingEnabled has been removed. Since we cannot interact with the resource it has no effect. You can define it but it will be ignored.
 
        class Controls //From now on everything is identical to 
        {
            class HUD_THIRST : RscText
            {
                text = "Thirst";
                idc = 1000;
                x = 1.25134;
                y = 0.655357;
                w = 0.1;
                h = 0.1;
            };
        };
    };
};

They are a bit more difficult to access via scripts. Unlike with dialogs, you cannot access their controls directly via IDC. You have to access them via a Control type, unlike dialogs, which you may (but don't have to) access using this method. In the previous point I mentioned we saved the resource's display and that's exactly what we'll need. Displays are the individual resources and we can use displayCtrl to get the pesky Control. At this point I've probably succeeded in confusing everybody so allow me to rectify that using an example.

disableSerialization; //We need this to be able to store UI info in normal variables. There are implications to using this (as well as resources in general) when it comes to game saves. But I won't go into it unless specifically asked. For now, let's just say it stops an error message from appearing.
 
cutRsc ["TAG_RscWhatever", "PLAIN"]; //Display our resource
 
_display = uiNamespace getVariable "TAG_RscWhatever_display"; //Get its display
_ctrl = _display displayCtrl 1000; //Get the control of HUD_THIRST (1000 is its IDC)
 
while {!isNull _display} do //Loop as long as the resource is shown
{
 
    _ctrl ctrlSetText format["Thirst: %1", TAG_thirstLevel]; //Display the thirst value
 
    //Now for something fancy, let's change the text color based on how high our thirst is.
    _color = if (TAG_thirstLevel > 90) then {
        [1,0,0,1] //Red
    } else {
        [1,1,1,1] //White
    }; //We got the color...
 
    _ctrl ctrlSetForegroundColor _color; //And now we've applied it.
 
    sleep 5; //No need to loop that often.
};
arma2/missions/user-interface-dialog-resource.txt · Last modified: 2024/08/01 21:32 by snakeman

Except where otherwise noted, content on this wiki is licensed under the following license: CC Attribution-Share Alike 4.0 International
CC Attribution-Share Alike 4.0 International Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki

All PMC web site download services are temporarily suspended until web site yearly fees have been recovered, want to download addons/mods? Then Support PMC.

If you are grateful for all the work PMC has done in the past 25 years, use Support PMC page.