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

Tasks - Add default stringtable reference for title and description #186

Merged
merged 9 commits into from
Dec 5, 2021
Merged
82 changes: 79 additions & 3 deletions addons/tasks/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,19 @@

Tasks framework. Automatic tasks creation from mission config. All scripts, conditions and events are run on server only.

## Table of Contents

- [Tasks](#tasks)
- [Table of Contents](#table-of-contents)
- [How to use](#how-to-use)
- [Example config](#example-config)
- [Using stringtable](#using-stringtable)
- [Autogenerated stringtable references](#autogenerated-stringtable-references)
- [Autogenerated stringtable references with TAG](#autogenerated-stringtable-references-with-tag)
- [Example custom event handling](#example-custom-event-handling)
- [Framework events](#framework-events)
- [Authors](#authors)

## How to use

Just create `CfgTasks` in your mission's `description.ext` and fill it with tasks! Yes, and that's it, no more linking modules and triggers into spaghetti, works out of the box.
Expand All @@ -12,9 +25,17 @@ If you don't want to use some property it is best to remove it at all, don't lea

```hpp
class CfgTasks {
/* Optional tag specification. Used for automatic title/description stringtable references.
For e.g., "MyMission", the autogenerated stringtable refrences will be "STR_MyMission_Task_TASKNAME_Title" and "STR_MyMission_Task_TASKNAME_Description".
When omitted or empty, the references will be "STR_Task_TASKNAME_Title" and "STR_Task_TASKNAME_Description".
For more details please look at "Using Stringtable" section in README.
*/
tag = "";

class Soapy_Mission_XD {
title = "Soapy Mission XD - Horse Knocked"; // Regular task title
description = "Great mission of beating horse."; // Regular description. Cannot use linebreaks (enters), if needed use stringtable.
tag = ""; // Optional CfgTasks.tag override for task. When omitted, fallback to global tag will be performed. If defined as empty, global tag will be ignored.
/* Task icon location on the map
First checks for marker with given name, and if doesn't exists, checks for object in mission namespace.
Alternatively {x, y, z} can be used for supplying position coordinates.
Expand Down Expand Up @@ -97,9 +118,64 @@ title = $STR_TAG_TaskOneTitle;
title = "STR_TAG_TaskOneTitle";
```

If using CBA macros use `LSTRING()` instead of `CSTRING()`.
If using CBA macros use `LSTRING()` instead of `CSTRING()`. Otherwise localization will be performed on the server, before tasks configuration is read.

### Autogenerated stringtable references

You may choose to omit title/description definition and use autogenerated stringtable keys:

```hpp
class CfgTasks {
class TASKCLASSNAME {
icon = "attack";
};
};
```

Framework will look for the keys below:

- `STR_Task_TASKCLASSNAME_Title`
- `STR_Task_TASKCLASSNAME_Description`

Effectively, this will behave the same as (with one exception):

```hpp
class CfgTasks {
class TASKCLASSNAME {
title = "STR_Task_TASKCLASSNAME_Title";
description = "STR_Task_TASKCLASSNAME_Description";
icon = "attack";
};
};
```

The one exception being class inheritance. If you want to inherit title or description, you must specify it manually (so nothing really changes here). In case you don't want to inherit it (like me in 90% cases), you have a lot less code to write.

### Autogenerated stringtable references with TAG

You may also want to include TAG in your stringtable reference. It can be defined on `CfgTasks` level or at the task level (in case you need to override global tag).

```hpp
class CfgTasks {
tag = "MySuperMission";

class TASKCLASSNAME {
icon = "attack";
};

class OTHERTAGTASKCLASSNAME {
tag = "MyOtherMission";
icon = "defend";
};
};
```

This will result in the following keys expected:

Otherwise localization will be performed on the server, before tasks configuration is read.
- `STR_MySuperMission_Task_TASKCLASSNAME_Title`
- `STR_MySuperMission_Task_TASKCLASSNAME_Description`
- `STR_MyOtherMission_Task_OTHERTAGTASKCLASSNAME_Title`
- `STR_MyOtherMission_Task_OTHERTAGTASKCLASSNAME_Description`

## Example custom event handling

Expand Down Expand Up @@ -135,6 +211,6 @@ Event "afm_tasks_taskStateChanged"
- 1: New task state <STRING>
```

### Authors
## Authors

- [3Mydlo3](http://github.com/3Mydlo3)
1 change: 1 addition & 0 deletions addons/tasks/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ PREP(handleShow);

PREP(readDestination);
PREP(readOwners);
PREP(readTitleAndDescription);
6 changes: 5 additions & 1 deletion addons/tasks/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,19 @@ if (isServer) then {
GVAR(tasks) = createHashMap;
GVAR(tasksArray) = [];

private _cfgTasks = missionConfigFile >> "CfgTasks";
private _tag = getTextRaw (_cfgTasks >> "tag");

// Load tasks from config
{
private _taskConfigName = configName _x;
private _taskNamespace = [_x] call EFUNC(common,readConfigToNamespace);
_taskNamespace setVariable ["taskConfigName", _taskConfigName];
_taskNamespace setVariable ["taskGlobalTag", _tag];

GVAR(tasks) set [_taskConfigName, _taskNamespace];
GVAR(tasksArray) pushBack _taskNamespace;
} forEach ("true" configClasses (missionConfigFile >> "CfgTasks"));
} forEach ("true" configClasses _cfgTasks);
};

ADDON = true;
6 changes: 3 additions & 3 deletions addons/tasks/functions/fnc_createTask.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* Function creates task from given task namespace.
*
* Arguments:
* 0: Task namespace <CBA_NAMESPACE>
* 0: Task config name <STRING>
* 1: Task namespace <CBA_NAMESPACE>
*
* Return Value:
* None
Expand All @@ -19,8 +20,7 @@ params ["_taskConfigName", "_taskNamespace"];

INFO_1("Creating '%1'",_taskConfigName);

private _title = _taskNamespace getVariable ["title", ""];
private _description = _taskNamespace getVariable ["description", ""];
[_taskConfigName, _taskNamespace] call FUNC(readTitleAndDescription) params ["_title", "_description"];
private _marker = _taskNamespace getVariable ["marker", ""];
private _object = _taskNamespace getVariable ["object", ""];
private _position = _taskNamespace getVariable ["position", []];
Expand Down
38 changes: 38 additions & 0 deletions addons/tasks/functions/fnc_readTitleAndDescription.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Reads title and description from given task namespace.
*
* Arguments:
* 0: Task config name <STRING>
* 1: Task namespace <CBA_NAMESPACE>
*
* Return Value:
* 0: Mission Title <STRING>
* 1: Mission Description <STRING>
*
* Example:
* None
*
* Public: No
*/

params ["_taskConfigName", "_taskNamespace"];

private _taskTag = _taskNamespace getVariable [
"tag",
// Get global CfgTasks tag as fallback
_taskNamespace getVariable ["taskGlobalTag", ""]
];

if (_taskTag isNotEqualTo "") then {
[
_taskNamespace getVariable ["title", format [DEFAULT_TITLE_FORMAT_WITH_COMPONENT, _taskTag, _taskConfigName]],
_taskNamespace getVariable ["description", format [DEFAULT_DESCRIPTION_FORMAT_WITH_COMPONENT, _taskTag, _taskConfigName]]
]
} else {
[
_taskNamespace getVariable ["title", format [DEFAULT_TITLE_FORMAT, _taskConfigName]],
_taskNamespace getVariable ["description", format [DEFAULT_DESCRIPTION_FORMAT, _taskConfigName]]
]
};
5 changes: 5 additions & 0 deletions addons/tasks/script_component.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,9 @@

#include "\z\afm\addons\main\script_macros.hpp"

#define DEFAULT_TITLE_FORMAT "STR_Task_%1_Title"
#define DEFAULT_TITLE_FORMAT_WITH_COMPONENT "STR_%1_Task_%2_Title"
#define DEFAULT_DESCRIPTION_FORMAT "STR_Task_%1_Description"
#define DEFAULT_DESCRIPTION_FORMAT_WITH_COMPONENT "STR_%1_Task_%2_Description"

#define FINISHED_TASK_STATES ["SUCCEEDED", "FAILED", "CANCELED"]