|
| 1 | +//$ Copyright 2015-2016, Code Respawn Technologies Pvt Ltd - All Rights Reserved $// |
| 2 | +#include "TreeArchitectEditorPrivatePCH.h" |
| 3 | +#include "TreeArchitectStyle.h" |
| 4 | +#include "IPluginManager.h" |
| 5 | + |
| 6 | +#define IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( Style.RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ ) |
| 7 | +#define BOX_BRUSH( RelativePath, ... ) FSlateBoxBrush( Style.RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ ) |
| 8 | +#define BORDER_BRUSH( RelativePath, ... ) FSlateBorderBrush( Style.RootToContentDir( RelativePath, TEXT(".png") ), __VA_ARGS__ ) |
| 9 | +#define TTF_FONT( RelativePath, ... ) FSlateFontInfo( Style.RootToContentDir( RelativePath, TEXT(".ttf") ), __VA_ARGS__ ) |
| 10 | +#define TTF_CORE_FONT( RelativePath, ... ) FSlateFontInfo( Style.RootToCoreContentDir( RelativePath, TEXT(".ttf") ), __VA_ARGS__ ) |
| 11 | +#define OTF_FONT( RelativePath, ... ) FSlateFontInfo( Style.RootToContentDir( RelativePath, TEXT(".otf") ), __VA_ARGS__ ) |
| 12 | +#define OTF_CORE_FONT( RelativePath, ... ) FSlateFontInfo( Style.RootToCoreContentDir( RelativePath, TEXT(".otf") ), __VA_ARGS__ ) |
| 13 | + |
| 14 | +#define PLUGIN_IMAGE_BRUSH( RelativePath, ... ) FSlateImageBrush( FLAStyle::InContent( RelativePath, ".png" ), __VA_ARGS__ ) |
| 15 | + |
| 16 | + |
| 17 | +TSharedPtr< FSlateStyleSet > FLAStyle::StyleInstance = nullptr; |
| 18 | + |
| 19 | +FString FLAStyle::InContent(const FString& RelativePath, const ANSICHAR* Extension) |
| 20 | +{ |
| 21 | + static FString ContentDir = IPluginManager::Get().FindPlugin(TEXT("TreeArchitect"))->GetContentDir(); |
| 22 | + return (ContentDir / RelativePath) + Extension; |
| 23 | +} |
| 24 | + |
| 25 | +void FLAStyle::Initialize() |
| 26 | +{ |
| 27 | + if (!StyleInstance.IsValid()) |
| 28 | + { |
| 29 | + StyleInstance = Create(); |
| 30 | + FSlateStyleRegistry::RegisterSlateStyle(*StyleInstance); |
| 31 | + } |
| 32 | +} |
| 33 | + |
| 34 | +void FLAStyle::Shutdown() |
| 35 | +{ |
| 36 | + FSlateStyleRegistry::UnRegisterSlateStyle(*StyleInstance); |
| 37 | + ensure(StyleInstance.IsUnique()); |
| 38 | + StyleInstance.Reset(); |
| 39 | +} |
| 40 | + |
| 41 | +FName FLAStyle::GetStyleSetName() |
| 42 | +{ |
| 43 | + static FName StyleSetName(TEXT("CityArchitectStyle")); |
| 44 | + return StyleSetName; |
| 45 | +} |
| 46 | + |
| 47 | +TSharedRef< class FSlateStyleSet > FLAStyle::Create() |
| 48 | +{ |
| 49 | + TSharedRef<FSlateStyleSet> StyleRef = MakeShareable(new FSlateStyleSet(FLAStyle::GetStyleSetName())); |
| 50 | + StyleRef->SetContentRoot(FPaths::EngineContentDir() / TEXT("Editor/Slate")); |
| 51 | + StyleRef->SetCoreContentRoot(FPaths::EngineContentDir() / TEXT("Slate")); |
| 52 | + FSlateStyleSet& Style = StyleRef.Get(); |
| 53 | + |
| 54 | + const FVector2D Icon16x16(16.0f, 16.0f); |
| 55 | + const FVector2D Icon20x20(20.0f, 20.0f); |
| 56 | + const FVector2D Icon40x40(40.0f, 40.0f); |
| 57 | + const FVector2D Icon48x48(48.0f, 48.0f); |
| 58 | + |
| 59 | + |
| 60 | + // Define some 'normal' styles, upon which other variations can be based |
| 61 | + const FSlateFontInfo NormalFont = TTF_CORE_FONT("Fonts/Roboto-Regular", 9); |
| 62 | + |
| 63 | + FTextBlockStyle NormalText = FTextBlockStyle() |
| 64 | + .SetFont(TTF_CORE_FONT("Fonts/Roboto-Regular", 10)) |
| 65 | + .SetColorAndOpacity(FSlateColor::UseForeground()) |
| 66 | + .SetShadowOffset(FVector2D::ZeroVector) |
| 67 | + .SetShadowColorAndOpacity(FLinearColor::Black) |
| 68 | + .SetHighlightColor(FLinearColor(0.02f, 0.3f, 0.0f)) |
| 69 | + .SetHighlightShape(BOX_BRUSH("Common/TextBlockHighlightShape", FMargin(3.f / 8.f))); |
| 70 | + |
| 71 | + |
| 72 | + // Generic styles |
| 73 | + { |
| 74 | + Style.Set("CityArchitect.TabIcon", new PLUGIN_IMAGE_BRUSH("Icons/icon_CityEd_40x", Icon40x40)); |
| 75 | + Style.Set("CityArchitect.TabIcon.Small", new PLUGIN_IMAGE_BRUSH("Icons/icon_CityEd_40x", Icon40x40)); |
| 76 | + |
| 77 | + Style.Set("CityEditMode.SetCategoryFlowMap", new IMAGE_BRUSH("Icons/icon_meshpaint_40x", Icon20x20)); |
| 78 | + Style.Set("CityEditMode.SetCategoryPopulation", new IMAGE_BRUSH("Icons/icon_ShowSkeletalMeshes_40x", Icon20x20)); |
| 79 | + Style.Set("CityEditMode.SetCategoryLandWater", new IMAGE_BRUSH("Icons/icon_Placement_FilterProps_40x", Icon20x20)); |
| 80 | + Style.Set("CityEditMode.SetCategoryParkForest", new IMAGE_BRUSH("Icons/icon_Mode_Foliage_40x", Icon20x20)); |
| 81 | + Style.Set("CityEditMode.SetCategoryStreetGraph", new IMAGE_BRUSH("Icons/icon_TextureEd_CheckeredBackground_40x", Icon20x20)); |
| 82 | + |
| 83 | + } |
| 84 | + |
| 85 | + Style.Set("CityEditMode.ActiveToolName.Text", FTextBlockStyle(NormalText) |
| 86 | + .SetFont(TTF_CORE_FONT("Fonts/Roboto-Bold", 11)) |
| 87 | + .SetShadowOffset(FVector2D(1, 1)) |
| 88 | + ); |
| 89 | + |
| 90 | + /* |
| 91 | + // Editor Mode Styles |
| 92 | + { |
| 93 | + Style.Set("CityArchitect.ModePaint", new IMAGE_PLUGIN_BRUSH("Icons/CityEditMode/icon_CityEdMode_Paint_40x", Icon40x40)); |
| 94 | + Style.Set("CityArchitect.ModeRectangle", new IMAGE_PLUGIN_BRUSH("Icons/CityEditMode/icon_CityEdMode_Rectangle_40x", Icon40x40)); |
| 95 | + Style.Set("CityArchitect.ModeBorder", new IMAGE_PLUGIN_BRUSH("Icons/CityEditMode/icon_CityEdMode_Border_40x", Icon40x40)); |
| 96 | + Style.Set("CityArchitect.ModeSelect", new IMAGE_PLUGIN_BRUSH("Icons/CityEditMode/icon_CityEdMode_Select_40x", Icon40x40)); |
| 97 | + } |
| 98 | + */ |
| 99 | + |
| 100 | + return StyleRef; |
| 101 | +} |
| 102 | + |
| 103 | + |
| 104 | + |
| 105 | +const ISlateStyle& FLAStyle::Get() |
| 106 | +{ |
| 107 | + return *StyleInstance; |
| 108 | +} |
| 109 | + |
0 commit comments