Script Canvas, replace the text replacement system to a JSON file based one (#5228)
It is now possible to right click on nodes on the node palette to navigate to the file that holds the text data for any given node, this way it is easy to update and improve the naming of titles, subtitles, categories, tool tips and slots.
This commit is contained in:
@@ -10,8 +10,10 @@
|
||||
|
||||
#include "TranslationAsset.h"
|
||||
|
||||
#include <AzCore/std/string/conversions.h>
|
||||
#include <AzCore/StringFunc/StringFunc.h>
|
||||
|
||||
|
||||
namespace GraphCanvas
|
||||
{
|
||||
namespace Translation
|
||||
@@ -88,10 +90,16 @@ namespace GraphCanvas
|
||||
static AZStd::string Sanitize(const AZStd::string& text)
|
||||
{
|
||||
AZStd::string result = text;
|
||||
AZ::StringFunc::Replace(result, "*", "x");
|
||||
AZ::StringFunc::Replace(result, "(", "_");
|
||||
AZ::StringFunc::Replace(result, ")", "_");
|
||||
AZ::StringFunc::Replace(result, "{", "_");
|
||||
AZ::StringFunc::Replace(result, "}", "_");
|
||||
AZ::StringFunc::Replace(result, ":", "_");
|
||||
AZ::StringFunc::Replace(result, "<", "_");
|
||||
AZ::StringFunc::Replace(result, ",", "_");
|
||||
AZ::StringFunc::Replace(result, ">", " ");
|
||||
AZ::StringFunc::Replace(result, "/", "");
|
||||
AZ::StringFunc::Strip(result, " ");
|
||||
AZ::StringFunc::Path::Normalize(result);
|
||||
return result;
|
||||
@@ -117,32 +125,32 @@ namespace GraphCanvas
|
||||
virtual bool HasKey(const AZStd::string& /*key*/) { return false; }
|
||||
|
||||
//! Returns the text value for a given key
|
||||
virtual const char* Get(const AZStd::string& /*key*/) { return nullptr; }
|
||||
virtual bool Get(const AZStd::string& /*key*/, AZStd::string& /*value*/) { return false; }
|
||||
|
||||
struct Details
|
||||
{
|
||||
AZStd::string Name;
|
||||
AZStd::string Tooltip;
|
||||
AZStd::string Category;
|
||||
AZStd::string Subtitle;
|
||||
AZStd::string m_name;
|
||||
AZStd::string m_tooltip;
|
||||
AZStd::string m_category;
|
||||
AZStd::string m_subtitle;
|
||||
|
||||
bool Valid = false;
|
||||
bool m_valid = false;
|
||||
|
||||
Details() = default;
|
||||
|
||||
Details(const Details& rhs)
|
||||
{
|
||||
Name = rhs.Name;
|
||||
Tooltip = rhs.Tooltip;
|
||||
Subtitle = rhs.Subtitle;
|
||||
Category = rhs.Category;
|
||||
Valid = rhs.Valid;
|
||||
m_name = rhs.m_name;
|
||||
m_tooltip = rhs.m_tooltip;
|
||||
m_category = rhs.m_category;
|
||||
m_subtitle = rhs.m_subtitle;
|
||||
m_valid = rhs.m_valid;
|
||||
}
|
||||
|
||||
Details(const char* name, const char* tooltip, const char* subtitle, const char* category)
|
||||
: Name(name), Tooltip(tooltip), Subtitle(subtitle), Category(category)
|
||||
: m_name(name), m_tooltip(tooltip), m_subtitle(subtitle), m_category(category)
|
||||
{
|
||||
Valid = !Name.empty();
|
||||
m_valid = !m_name.empty();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -150,7 +158,7 @@ namespace GraphCanvas
|
||||
virtual bool Add(const TranslationFormat& /*translationFormat*/) { return false; }
|
||||
|
||||
//! Get the details associated with a given key (assumes they are within a "details" object)
|
||||
virtual Details GetDetails(const AZStd::string& /*key*/) { return Details(); }
|
||||
virtual Details GetDetails(const AZStd::string& /*key*/, const Details& /*fallbackDetails*/) { return Details(); }
|
||||
|
||||
//! Generates the source JSON assets for all reflected elements
|
||||
virtual void GenerateSourceAssets() {}
|
||||
|
||||
@@ -104,35 +104,49 @@ namespace GraphCanvas
|
||||
return m_database.find(key) != m_database.end();
|
||||
}
|
||||
|
||||
GraphCanvas::TranslationRequests::Details TranslationDatabase::GetDetails(const AZStd::string& key)
|
||||
GraphCanvas::TranslationRequests::Details TranslationDatabase::GetDetails(const AZStd::string& key, const Details& fallbackDetails)
|
||||
{
|
||||
const char* name = Get(key + ".name");
|
||||
const char* tooltip = Get(key + ".tooltip");
|
||||
const char* subtitle = Get(key + ".subtitle");
|
||||
const char* category = Get(key + ".category");
|
||||
|
||||
static bool s_traceMissingItems = true;
|
||||
if (s_traceMissingItems)
|
||||
Details details;
|
||||
if (!Get(key + ".name", details.m_name))
|
||||
{
|
||||
AZ_TracePrintf("GraphCanvas", AZStd::string::format("Value (name) not found for key: %s", key.c_str()).c_str());
|
||||
AZ_TracePrintf("GraphCanvas", AZStd::string::format("Value (tooltip) not found for key: %s", key.c_str()).c_str());
|
||||
AZ_TracePrintf("GraphCanvas", AZStd::string::format("Value (subtitle) not found for key: %s", key.c_str()).c_str());
|
||||
AZ_TracePrintf("GraphCanvas", AZStd::string::format("Value (category) not found for key: %s", key.c_str()).c_str());
|
||||
details.m_name = fallbackDetails.m_name;
|
||||
}
|
||||
|
||||
return Details(name ? name : "", tooltip ? tooltip : "", subtitle ? subtitle : "", category ? category : "");
|
||||
if (!Get(key + ".tooltip", details.m_tooltip))
|
||||
{
|
||||
details.m_tooltip = fallbackDetails.m_tooltip;
|
||||
}
|
||||
|
||||
if (!Get(key + ".subtitle", details.m_subtitle))
|
||||
{
|
||||
details.m_subtitle = fallbackDetails.m_subtitle;
|
||||
}
|
||||
|
||||
if (!Get(key + ".category", details.m_category))
|
||||
{
|
||||
details.m_category = fallbackDetails.m_category;
|
||||
}
|
||||
|
||||
return details;
|
||||
}
|
||||
|
||||
const char* TranslationDatabase::Get(const AZStd::string& key)
|
||||
bool TranslationDatabase::Get(const AZStd::string& key, AZStd::string& value)
|
||||
{
|
||||
AZStd::lock_guard<AZStd::recursive_mutex> lock(m_mutex);
|
||||
|
||||
if (m_database.find(key) != m_database.end())
|
||||
{
|
||||
return m_database[key].c_str();
|
||||
value = m_database[key];
|
||||
return true;
|
||||
}
|
||||
|
||||
return "";
|
||||
static bool s_traceMissingItems = false;
|
||||
if (s_traceMissingItems)
|
||||
{
|
||||
AZ_TracePrintf("GraphCanvas", AZStd::string::format("Value not found for key: %s", key.c_str()).c_str());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TranslationDatabase::Add(const TranslationFormat& format)
|
||||
|
||||
@@ -43,9 +43,9 @@ namespace GraphCanvas
|
||||
|
||||
bool HasKey(const AZStd::string& key) override;
|
||||
|
||||
TranslationRequests::Details GetDetails(const AZStd::string& key) override;
|
||||
TranslationRequests::Details GetDetails(const AZStd::string& key, const Details& value) override;
|
||||
|
||||
const char* Get(const AZStd::string& key) override;
|
||||
bool Get(const AZStd::string& key, AZStd::string& value) override;
|
||||
|
||||
bool Add(const TranslationFormat& format) override;
|
||||
|
||||
|
||||
@@ -35,8 +35,10 @@ namespace GraphCanvas
|
||||
}
|
||||
else
|
||||
{
|
||||
AZStd::string existingValue = translationFormat->m_database[finalKey.c_str()];
|
||||
|
||||
// There is a name collision
|
||||
AZStd::string error = AZStd::string::format("Unable to store key: %s with value: %s because that key already exists", finalKey.c_str(), it.GetString());
|
||||
AZStd::string error = AZStd::string::format("Unable to store key: %s with value: %s because that key already exists with value: %s (proposed: %s)", finalKey.c_str(), it.GetString(), existingValue.c_str(), it.GetString());
|
||||
AZ_Error("TranslationSerializer", false, error.c_str());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user