Script Canvas node translation system and naming consistency

Signed-off-by: lsemp3d <58790905+lsemp3d@users.noreply.github.com>
This commit is contained in:
lsemp3d
2021-12-07 15:40:04 -08:00
parent 8d096ebf61
commit 72bfd8bdf8
1515 changed files with 235974 additions and 2095 deletions
@@ -15,7 +15,6 @@
#include <GraphCanvas/Editor/EditorTypes.h>
#include <GraphCanvas/Types/EntitySaveData.h>
#include <GraphCanvas/Types/GraphCanvasGraphSerialization.h>
#include <GraphCanvas/Types/TranslationTypes.h>
#include <GraphCanvas/Components/Slots/SlotBus.h>
@@ -40,9 +39,6 @@ namespace GraphCanvas
//! Set the tooltip for the node, which will display when the mouse is over the node but not a child item.
virtual void SetTooltip(const AZStd::string&) = 0;
//! Set the translation keyed tooltip for the node, which will display when the mouse is over the node but not a child item.
virtual void SetTranslationKeyedTooltip(const TranslationKeyedString&) = 0;
//! Get the tooltip that is currently set for the node.
virtual const AZStd::string GetTooltip() const = 0;
@@ -11,7 +11,6 @@
#include <AzCore/EBus/EBus.h>
#include <AzCore/std/string/string.h>
#include <GraphCanvas/Types/TranslationTypes.h>
#include <GraphCanvas/Components/StyleBus.h>
#include <GraphCanvas/Types/SceneMemberComponentSaveData.h>
@@ -38,19 +37,18 @@ namespace GraphCanvas
virtual QGraphicsWidget* GetGraphicsWidget() = 0;
//! Set the node's details, title, subtitle, tooltip
virtual void SetDetails(const AZStd::string& title, const AZStd::string& subtitle) = 0;
//! Set the Node's title.
virtual void SetTitle(const AZStd::string& value) = 0;
virtual void SetTranslationKeyedTitle(const TranslationKeyedString& value) = 0;
//! Get the Node's title.
virtual AZStd::string GetTitle() const = 0;
//! Set the Node's sub-title.
virtual void SetSubTitle(const AZStd::string& value) = 0;
virtual void SetTranslationKeyedSubTitle(const TranslationKeyedString& value) = 0;
//! Get the Node's sub-title.
virtual AZStd::string GetSubTitle() const = 0;
@@ -16,7 +16,6 @@
#include <GraphCanvas/Types/Endpoint.h>
#include <GraphCanvas/Types/Types.h>
#include <GraphCanvas/Types/TranslationTypes.h>
class QGraphicsLayoutItem;
@@ -89,8 +88,9 @@ namespace GraphCanvas
ConnectionType m_connectionType = ConnectionType::CT_Invalid;
TranslationKeyedString m_tooltip = TranslationKeyedString();
TranslationKeyedString m_name = TranslationKeyedString();
AZStd::string m_tooltip;
AZStd::string m_name;
SlotGroup m_slotGroup = SlotGroups::Invalid;
AZStd::string m_textDecoration;
@@ -209,22 +209,19 @@ namespace GraphCanvas
//! Get the name, or label, of the slot.
//! These generally appear as a label against \ref Input or \ref Output slots.
virtual const AZStd::string GetName() const = 0;
//! Set the slot's name.
virtual void SetName(const AZStd::string&) = 0;
//! Get and set the keys used for slot name translation.
virtual TranslationKeyedString GetTranslationKeyedName() const = 0;
virtual void SetTranslationKeyedName(const TranslationKeyedString&) = 0;
//! Set the slot's name & tooltip.
virtual void SetDetails(const AZStd::string& name, const AZStd::string& tooltip) = 0;
//! Get the tooltip for the slot.
virtual const AZStd::string GetTooltip() const = 0;
//! Set the tooltip this slot should display.
virtual void SetTooltip(const AZStd::string&) = 0;
//! Get and set the keys used for slot tooltip translation.
virtual TranslationKeyedString GetTranslationKeyedTooltip() const = 0;
virtual void SetTranslationKeyedTooltip(const TranslationKeyedString&) = 0;
//! Get the group of the slot
virtual SlotGroup GetSlotGroup() const = 0;
@@ -370,9 +367,10 @@ namespace GraphCanvas
using BusIdType = SlotId;
//! When the name of the slot changes, the new name is signaled.
virtual void OnNameChanged(const TranslationKeyedString&) {}
virtual void OnNameChanged(const AZStd::string&) {}
//! When the tooltip of the slot changes, the new tooltip value is emitted.
virtual void OnTooltipChanged(const TranslationKeyedString&) {}
virtual void OnTooltipChanged(const AZStd::string&) {}
virtual void OnRegisteredToNode(const AZ::EntityId&) {}
@@ -10,7 +10,7 @@
#include <AzCore/Debug/Profiler.h>
#define GRAPH_CANVAS_PROFILE_FUNCTION() AZ_PROFILE_FUNCTION(AzToolsFramework);
#define GRAPH_CANVAS_PROFILE_SCOPE(message) AZ_PROFILE_SCOPE(AzToolsFramework, message);
#define GRAPH_CANVAS_PROFILE_SCOPE(budget, message) AZ_PROFILE_SCOPE(budget, message);
#if GRAPH_CANVAS_ENABLE_DETAILED_PROFILING
#define GRAPH_CANVAS_DETAILED_PROFILE_FUNCTION() AZ_PROFILE_FUNCTION(AzToolsFramework);
@@ -6,6 +6,7 @@
*
*/
#include <AzCore/PlatformDef.h>
#include <AzCore/Debug/Profiler.h>
AZ_PUSH_DISABLE_WARNING(4251 4800 4244, "-Wunknown-warning-option")
#include <QBitmap>
@@ -141,6 +142,8 @@ namespace
namespace GraphCanvas
{
AZ_DEFINE_BUDGET(StyleManager);
////////////////////////
// StyleSheetComponent
////////////////////////
@@ -271,6 +274,8 @@ namespace GraphCanvas
: m_editorId(editorId)
, m_assetPath(assetPath)
{
GRAPH_CANVAS_PROFILE_SCOPE(StyleManager, "StyleManager::StyleManager");
StyleManagerRequestBus::Handler::BusConnect(m_editorId);
AZ::Data::AssetInfo assetInfo;
@@ -315,8 +320,11 @@ namespace GraphCanvas
}
}
void StyleManager::LoadStyleSheet()
{
GRAPH_CANVAS_PROFILE_SCOPE(StyleManager, "LoadStyleSheet");
AZStd::string file = AZStd::string::format("@products@/%s", m_assetPath.c_str());
AZ::IO::FileIOBase* fileBase = AZ::IO::FileIOBase::GetInstance();
@@ -393,7 +401,7 @@ namespace GraphCanvas
AZ::EntityId StyleManager::ResolveStyles(const AZ::EntityId& object) const
{
GRAPH_CANVAS_DETAILED_PROFILE_FUNCTION();
GRAPH_CANVAS_PROFILE_SCOPE(StyleManager, "ResolveStyles");
Styling::SelectorVector selectors;
StyledEntityRequestBus::EventResult(selectors, object, &StyledEntityRequests::GetStyleSelectors);
@@ -401,7 +409,7 @@ namespace GraphCanvas
QVector<StyleMatch> matches;
for (const auto& style : m_styles)
{
GRAPH_CANVAS_DETAILED_PROFILE_SCOPE("StyleManager::ResolveStyles::StyleMatching");
GRAPH_CANVAS_PROFILE_SCOPE(StyleManager, "StyleManager::ResolveStyles::StyleMatching");
int complexity = style->Matches(object);
if (complexity != 0)
{
@@ -410,7 +418,7 @@ namespace GraphCanvas
}
{
GRAPH_CANVAS_DETAILED_PROFILE_SCOPE("StyleManager::ResolveStyles::Sorting");
GRAPH_CANVAS_PROFILE_SCOPE(StyleManager, "StyleManager::ResolveStyles::Sorting");
std::stable_sort(matches.begin(), matches.end());
}
Styling::StyleVector result;
@@ -418,7 +426,7 @@ namespace GraphCanvas
const auto& constMatches = matches;
for (auto& match : constMatches)
{
GRAPH_CANVAS_DETAILED_PROFILE_SCOPE("StyleManager::ResolveStyles::ResultConstruction");
GRAPH_CANVAS_PROFILE_SCOPE(StyleManager, "StyleManager::ResolveStyles::ResultConstruction");
result.push_back(match.style);
}
@@ -1,116 +0,0 @@
/*
* Copyright (c) Contributors to the Open 3D Engine Project.
* For complete copyright and license terms please see the LICENSE at the root of this distribution.
*
* SPDX-License-Identifier: Apache-2.0 OR MIT
*
*/
#pragma once
#include <QCoreApplication>
#include <AzCore/Serialization/SerializeContext.h>
namespace GraphCanvas
{
struct TranslationKeyedString
{
public:
AZ_TYPE_INFO(TranslationKeyedString, "{B796685C-0335-4E74-9EF8-A1933E8B2142}");
AZ_CLASS_ALLOCATOR(TranslationKeyedString, AZ::SystemAllocator, 0);
static void Reflect(AZ::ReflectContext* context)
{
AZ::SerializeContext* serializeContext = azrtti_cast<AZ::SerializeContext*>(context);
if (!serializeContext)
{
return;
}
serializeContext->Class<TranslationKeyedString>()
->Version(1)
->Field("Fallback", &TranslationKeyedString::m_fallback)
->Field("Context", &TranslationKeyedString::m_context)
->Field("Key", &TranslationKeyedString::m_key)
;
}
TranslationKeyedString()
: m_dirtyText(true)
{
}
~TranslationKeyedString() = default;
TranslationKeyedString(const AZStd::string& fallback, const AZStd::string& context = AZStd::string(), const AZStd::string& key = AZStd::string())
: m_fallback(fallback)
, m_context(context)
, m_key(key)
, m_dirtyText(true)
{
}
const AZStd::string GetDisplayString() const
{
if (m_dirtyText)
{
const_cast<TranslationKeyedString*>(this)->TranslateString();
}
return m_display;
}
void TranslateString()
{
m_display = m_fallback;
if (!m_context.empty() && !m_key.empty())
{
AZStd::string translatedText = QCoreApplication::translate(m_context.c_str(), m_key.c_str()).toUtf8().data();
if (translatedText != m_key)
{
m_display = translatedText;
}
}
m_dirtyText = false;
}
bool empty() const
{
return m_fallback.empty() && (m_context.empty() || m_key.empty());
}
bool operator==(const TranslationKeyedString& other) const
{
return m_fallback == other.m_fallback
&& m_context == other.m_context
&& m_key == other.m_key
;
}
void Clear()
{
m_key.clear();
m_context.clear();
m_fallback.clear();
}
void SetFallback(const AZStd::string& fallback)
{
m_fallback = fallback;
m_dirtyText = true;
}
AZStd::string m_context;
AZStd::string m_key;
AZStd::string m_display;
private:
AZStd::string m_fallback;
bool m_dirtyText;
};
}
@@ -119,6 +119,11 @@ namespace GraphCanvas
m_nodePalette->setProperty("HasNoWindowDecorations", true);
m_nodePalette->SetupNodePalette(config);
if (m_userNodePaletteWidth > 0)
{
m_nodePalette->setFixedWidth(m_userNodePaletteWidth);
}
QWidgetAction* actionWidget = new QWidgetAction(this);
actionWidget->setDefaultWidget(m_nodePalette);
@@ -63,34 +63,34 @@ namespace GraphCanvas
void ResetSourceSlotFilter();
void FilterForSourceSlot(const GraphId& graphId, const AZ::EntityId& sourceSlotId);
protected slots:
protected Q_SLOTS:
virtual void SetupDisplay();
virtual void HandleContextMenuSelection();
protected:
virtual void OnRefreshActions(const GraphId& graphId, const AZ::EntityId& targetMemberId);
void keyPressEvent(QKeyEvent* keyEvent) override;
NodePaletteWidget* m_nodePalette = nullptr;
private:
void ConstructMenu();
void AddUnprocessedActions(AZStd::vector<QAction*>& actions);
bool m_finalized;
bool m_isToolBarMenu;
NodePaletteWidget* m_nodePalette = nullptr;
bool m_finalized;
bool m_isToolBarMenu;
AZ::u32 m_userNodePaletteWidth = 300;
EditorId m_editorId;
AZStd::vector< ActionGroupId > m_actionGroupOrdering;
AZStd::unordered_set< ActionGroupId > m_actionGroups;
AZStd::vector<ActionGroupId> m_actionGroupOrdering;
AZStd::unordered_set<ActionGroupId> m_actionGroups;
AZStd::vector<QAction*> m_unprocessedFrontActions;
AZStd::vector<QAction*> m_unprocessedActions;
AZStd::vector<QAction*> m_unprocessedBackActions;
AZStd::unordered_map< AZStd::string, QMenu* > m_subMenuMap;
AZStd::unordered_map<AZStd::string, QMenu*> m_subMenuMap;
};
}
@@ -15,6 +15,7 @@
#include <GraphCanvas/Widgets/GraphCanvasTreeItem.h>
#include <GraphCanvas/Editor/EditorTypes.h>
#include <AzCore/IO/Path/Path.h>
namespace GraphCanvas
{
@@ -82,6 +83,9 @@ namespace GraphCanvas
void SetError(const AZStd::string& errorString);
virtual AZ::IO::Path GetTranslationDataPath() const { return AZ::IO::Path(); }
virtual void GenerateTranslationData() {}
protected:
void PreOnChildAdded(GraphCanvasTreeItem* item) override;