Skip to content

Commit

Permalink
Add two utility functions to get a layer's name from a CUILayer or an…
Browse files Browse the repository at this point in the history
… Ident.*
  • Loading branch information
Aessi committed Nov 15, 2017
1 parent 9f76f95 commit 0714980
Showing 1 changed file with 50 additions and 24 deletions.
74 changes: 50 additions & 24 deletions Common/Scripts/ManiaApps/Nadeo/Layers.Script.txt
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
/**
* Library helping to manage UI layers
*/
#Const Version "2016-09-14"
#Const Version "2017-09-13"
#Const ScriptName "ManiaApps/Nadeo/Layers.Script.txt"

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Globales
// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
declare Ident[Text] G_LibLayers_Layers; ///< Stock the registred layers ["LayerName" => #LayerId]

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Functions
// ---------------------------------- //
// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// Public
// ---------------------------------- //
// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Return the version number of the script
*
* @return The version number of the script
Expand All @@ -24,7 +24,7 @@ Text GetScriptVersion() {
return Version;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Return the name of the script
*
* @return The name of the script
Expand All @@ -33,7 +33,7 @@ Text GetScriptName() {
return ScriptName;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Check if a layer really exists
*
* @param _LayerName The name of the layer to check
Expand All @@ -47,7 +47,7 @@ Boolean Exists(Text _LayerName) {
);
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get a layer from its name
*
* @param _LayerName The name of the layer to get
Expand All @@ -59,7 +59,7 @@ CUILayer Get(Text _LayerName) {
return UILayers[G_LibLayers_Layers[_LayerName]];
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Destroy a layer
*
* @param _LayerName The name of the layer to destroy
Expand All @@ -70,15 +70,15 @@ Void Destroy(Text _LayerName) {
declare Removed = G_LibLayers_Layers.removekey(_LayerName);
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Destroy all layers
Void DestroyAll() {
foreach (LayerName => LayerId in G_LibLayers_Layers) {
Destroy(LayerName);
}
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Create a new layer
*
* @param _LayerName The name of the layer to create
Expand All @@ -94,7 +94,7 @@ Void Create(Text _LayerName, Text _LayerManialink) {
}
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Create a new layer
* If a layer with the same name already exists,
* destroys and replaces it
Expand All @@ -105,7 +105,7 @@ Void Create(Text _LayerName) {
Create(_LayerName, "");
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Update a layer manialink
*
* @param _LayerName The name of the layer to update
Expand All @@ -117,7 +117,7 @@ Void Update(Text _LayerName, Text _LayerManialink) {
Layer.ManialinkPage = _LayerManialink;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Set the type of a layer
*
* @param _LayerName The name of the layer
Expand All @@ -129,7 +129,7 @@ Void SetType(Text _LayerName, CUILayer::EUILayerType _LayerType) {
Layer.Type = _LayerType;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Set the Animation type of a layer (IN OUT ANIMATION)
*
* @param _LayerName The name of the layer
Expand All @@ -151,7 +151,7 @@ Void SetAnimationTypeIn(Text _LayerName, CUILayer::EUILayerAnimation _LayerAnima
Layer.InAnimation = _LayerAnimation;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Set the layer visibility
*
* @param _LayerName The name of the layer to update
Expand All @@ -163,7 +163,7 @@ Void SetVisibility(Text _LayerName, Boolean _IsVisible) {
Layer.IsVisible = _IsVisible;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Show the layer
*
* @param _LayerName The name of the layer to show
Expand All @@ -172,7 +172,7 @@ Void Show(Text _LayerName) {
SetVisibility(_LayerName, True);
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Hide the layer
*
* @param _LayerName The name of the layer to hide
Expand All @@ -181,7 +181,7 @@ Void Hide(Text _LayerName) {
SetVisibility(_LayerName, False);
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Check if a layer is visible
*
* @param _LayerName The name of the layer to check
Expand All @@ -194,13 +194,39 @@ Boolean CheckVisible(Text _LayerName) {
return Layer.IsVisible;
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the name of a layer
*
* @param _Layer The layer to get
*
* @return The name of the layer if found
* An empty Text otherwise
*/
Text GetName(CUILayer _Layer) {
if (_Layer != Null && G_LibLayers_Layers.exists(_Layer.Id)) return G_LibLayers_Layers.keyof(_Layer.Id);
return "";
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/** Get the name of a layer
*
* @param _LayerId The iflayer to get
*
* @return The name of the layer if found
* An empty Text otherwise
*/
Text GetName(Ident _LayerId) {
if (G_LibLayers_Layers.exists(_LayerId)) return G_LibLayers_Layers.keyof(_LayerId);
return "";
}

// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Unload the library
Void Unload() {
DestroyAll();
}

// ---------------------------------- //
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ //
/// Load the library
Void Load() {
Unload();
Expand Down

0 comments on commit 0714980

Please sign in to comment.