// Copyright 1998-2015 Epic Games, Inc. All Rights Reserved. #pragma once #include "IDataTableEditor.h" #include "Toolkits/AssetEditorToolkit.h" #include "EditorUndoClient.h" #include "Kismet2/StructureEditorUtils.h" #include "DataTableEditorUtils.h" class UDataTable; class FJsonObject; DECLARE_DELEGATE_OneParam(FOnRowHighlighted, FName /*Row name*/); /** Viewer/editor for a DataTable */ class FDataTableEditor : public IDataTableEditor , public FEditorUndoClient , public FStructureEditorUtils::INotifyOnStructChanged , public FDataTableEditorUtils::INotifyOnDataTableChanged { friend class SDataTableListViewRow; public: virtual void RegisterTabSpawners(const TSharedRef& TabManager) override; virtual void UnregisterTabSpawners(const TSharedRef& TabManager) override; /** * Edits the specified table * * @param Mode Asset editing mode for this editor (standalone or world-centric) * @param InitToolkitHost When Mode is WorldCentric, this is the level editor instance to spawn this editor within * @param Table The table to edit */ void InitDataTableEditor( const EToolkitMode::Type Mode, const TSharedPtr< class IToolkitHost >& InitToolkitHost, UDataTable* Table ); /** Constructor */ FDataTableEditor(); /** Destructor */ virtual ~FDataTableEditor(); /** IToolkit interface */ virtual FName GetToolkitFName() const override; virtual FText GetBaseToolkitName() const override; virtual FString GetWorldCentricTabPrefix() const override; virtual FLinearColor GetWorldCentricTabColorScale() const override; // FEditorUndoClient virtual void PostUndo(bool bSuccess) override; virtual void PostRedo(bool bSuccess) override; void HandleUndoRedo(); // INotifyOnStructChanged virtual void PreChange(const class UUserDefinedStruct* Struct, FStructureEditorUtils::EStructureEditorChangeInfo Info) override; virtual void PostChange(const class UUserDefinedStruct* Struct, FStructureEditorUtils::EStructureEditorChangeInfo Info) override; // INotifyOnDataTableChanged virtual void PreChange(const UDataTable* Changed, FDataTableEditorUtils::EDataTableChangeInfo Info) override; virtual void PostChange(const UDataTable* Changed, FDataTableEditorUtils::EDataTableChangeInfo Info) override; /** Get the data table being edited */ const UDataTable* GetDataTable() const; void HandlePostChange(); void SetHighlightedRow(FName Name); private: void RefreshCachedDataTable(); void UpdateVisibleRows(); void RestoreCachedSelection(const FName InCachedSelection, const bool bUpdateEvenIfValid = false); FText GetFilterText() const; void OnFilterTextChanged(const FText& InFilterText); FSlateColor GetRowTextColor(FName RowName) const; TSharedRef CreateContentBox(); TSharedRef CreateRowEditorBox(); /** Spawns the tab with the data table inside */ TSharedRef SpawnTab_DataTable( const FSpawnTabArgs& Args ); /** Spawns the tab with the Row Editor inside */ TSharedRef SpawnTab_RowEditor(const FSpawnTabArgs& Args); FOptionalSize GetRowNameColumnWidth() const; float GetColumnWidth(const int32 ColumnIndex) const; void OnColumnResized(const float NewWidth, const int32 ColumnIndex); void LoadLayoutData(); void SaveLayoutData(); /** Make the widget for a row name entry in the data table row list view */ TSharedRef MakeRowNameWidget(FDataTableEditorRowListViewDataPtr InRowDataPtr, const TSharedRef& OwnerTable); /** Make the widget for a row entry in the data table row list view */ TSharedRef MakeRowWidget(FDataTableEditorRowListViewDataPtr InRowDataPtr, const TSharedRef& OwnerTable); /** Make the widget for a cell entry in the data table row list view */ TSharedRef MakeCellWidget(FDataTableEditorRowListViewDataPtr InRowDataPtr, const int32 InRowIndex, const FName& InColumnId); void OnRowNamesListViewScrolled(double InScrollOffset); void OnCellsListViewScrolled(double InScrollOffset); void OnRowSelectionChanged(FDataTableEditorRowListViewDataPtr InNewSelection, ESelectInfo::Type InSelectInfo); private: /** Struct holding information about the current column widths */ struct FColumnWidth { FColumnWidth() : bIsAutoSized(true) , CurrentWidth(0.0f) { } /** True if this column is being auto-sized rather than sized by the user */ bool bIsAutoSized; /** The width of the column, either sized by the user, or auto-sized */ float CurrentWidth; }; /** Array of the columns that are available for editing */ TArray AvailableColumns; /** Array of the rows that are available for editing */ TArray AvailableRows; /** Array of the rows that match the active filter(s) */ TArray VisibleRows; /** Header row containing entries for each column in AvailableColumns */ TSharedPtr ColumnNamesHeaderRow; /** List view responsible for showing the row names column */ TSharedPtr> RowNamesListView; /** List view responsible for showing the rows in VisibleRows for each entry in AvailableColumns */ TSharedPtr> CellsListView; /** Width of the row name column */ float RowNameColumnWidth; /** Widths of data table cell columns */ TArray ColumnWidths; /** The layout data for the currently loaded data table */ TSharedPtr LayoutData; /** The name of the currently selected row */ FName HighlightedRowName; /** The current filter text applied to the data table */ FText ActiveFilterText; FOnRowHighlighted CallbackOnRowHighlighted; FSimpleDelegate CallbackOnDataTableUndoRedo; /** The tab id for the data table tab */ static const FName DataTableTabId; /** The tab id for the row editor tab */ static const FName RowEditorTabId; /** The column id for the row name list view column */ static const FName RowNameColumnId; };