Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
muit committed Mar 24, 2024
2 parents 2050949 + 4c77585 commit 4105d44
Show file tree
Hide file tree
Showing 38 changed files with 757 additions and 862 deletions.
39 changes: 17 additions & 22 deletions Source/Editor/Private/Customizations/FactionCustomization.cpp
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
// Copyright 2015-2020 Piperift. All Rights Reserved.
// Copyright 2015-2023 Piperift. All Rights Reserved.

#include "Customizations/FactionCustomization.h"

#include "Customizations/SFaction.h"
#include "Faction.h"
#include "FactionsModule.h"
#include "FactionsSubsystem.h"
#include "Customizations/SFaction.h"

#include <DetailWidgetRow.h>



#define LOCTEXT_NAMESPACE "FFactionCustomization"


void FFactionCustomization::CustomizeHeader(TSharedRef<class IPropertyHandle> StructPropertyHandle,
class FDetailWidgetRow& HeaderRow,
IPropertyTypeCustomizationUtils& StructCustomizationUtils)
class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
StructHandle = StructPropertyHandle;
if (!StructHandle->IsValidHandle())
Expand All @@ -25,24 +25,19 @@ void FFactionCustomization::CustomizeHeader(TSharedRef<class IPropertyHandle> St

auto IdHandle = StructHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFaction, Id));

HeaderRow.NameContent()
[
StructHandle->CreatePropertyNameWidget()
]
.ValueContent()
.MinDesiredWidth(150.0f)
.MaxDesiredWidth(250.0f)
[
SNew(SFaction)
.Faction_Lambda([IdHandle]() {
FName Id;
IdHandle->GetValue(Id);
return FFaction{Id};
})
.OnFactionSelected_Lambda([IdHandle](FFaction Faction, ESelectInfo::Type) {
IdHandle->SetValue(Faction.GetId());
})
];
HeaderRow.NameContent()[StructHandle->CreatePropertyNameWidget()]
.ValueContent()
.MinDesiredWidth(150.0f)
.MaxDesiredWidth(
250.0f)[SNew(SFaction)
.Faction_Lambda([IdHandle]() {
FName Id;
IdHandle->GetValue(Id);
return FFaction{Id};
})
.OnFactionSelected_Lambda([IdHandle](FFaction Faction, ESelectInfo::Type) {
IdHandle->SetValue(Faction.GetId());
})];
}

#undef LOCTEXT_NAMESPACE
36 changes: 16 additions & 20 deletions Source/Editor/Private/Customizations/FactionPin.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
// Copyright 2015-2020 Piperift. All Rights Reserved.
// Copyright 2015-2023 Piperift. All Rights Reserved.

#include "Customizations/FactionPin.h"

#include "Kismet2/KismetEditorUtilities.h"
#include "EdGraph/EdGraphPin.h"
#include "EdGraph/EdGraphSchema.h"

#include "Faction.h"
#include "FactionsModule.h"
#include "FactionsSubsystem.h"
#include "Kismet2/KismetEditorUtilities.h"



void SFactionPin::Construct(const FArguments& InArgs, UEdGraphPin* InGraphPinObj)
Expand All @@ -20,33 +20,29 @@ TSharedRef<SWidget> SFactionPin::GetDefaultValueWidget()
{
ParseDefaultValue();

return SNew(SBox)
.MaxDesiredHeight(20.f)
.Visibility( this, &SGraphPin::GetDefaultValueVisibility )
[
SNew(SFaction)
.ContentPadding(0.f)
.Faction_Lambda([this]() {
return FFaction{FactionDefaultNameValue};
})
.OnFactionSelected_Lambda([this](FFaction Faction, ESelectInfo::Type)
{
FactionDefaultNameValue = Faction.GetId();
ApplyDefaultValue();
})
];
return SNew(SBox).MaxDesiredHeight(20.f).Visibility(
this, &SGraphPin::GetDefaultValueVisibility)[SNew(SFaction)
.ContentPadding(0.f)
.Faction_Lambda([this]() {
return FFaction{FactionDefaultNameValue};
})
.OnFactionSelected_Lambda(
[this](FFaction Faction, ESelectInfo::Type) {
FactionDefaultNameValue = Faction.GetId();
ApplyDefaultValue();
})];
}

void SFactionPin::ParseDefaultValue()
{
FString NameString = GraphPinObj->GetDefaultAsString();
if (NameString.StartsWith(TEXT("(")) && NameString.EndsWith(TEXT(")")))
{
//Remove ( and )
// Remove ( and )
NameString = NameString.LeftChop(1);
NameString = NameString.RightChop(1);

//Get parameter string value
// Get parameter string value
NameString.Split("=", nullptr, &NameString);
if (NameString.StartsWith(TEXT("\"")) && NameString.EndsWith(TEXT("\"")))
{
Expand Down
7 changes: 3 additions & 4 deletions Source/Editor/Private/Customizations/FactionPinFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2015-2020 Piperift. All Rights Reserved.
// Copyright 2015-2023 Piperift. All Rights Reserved.

#include "Customizations/FactionPinFactory.h"

Expand All @@ -8,10 +8,9 @@ TSharedPtr<class SGraphPin> FFactionPinFactory::CreatePin(class UEdGraphPin* InP
const UEdGraphSchema_K2* K2Schema = GetDefault<UEdGraphSchema_K2>();

if (InPin->PinType.PinCategory == K2Schema->PC_Struct &&
InPin->PinType.PinSubCategoryObject == FFaction::StaticStruct() &&
!InPin->PinType.bIsReference)
InPin->PinType.PinSubCategoryObject == FFaction::StaticStruct() && !InPin->PinType.bIsReference)
{
return SNew(SFactionPin, InPin); //and return our customized pin widget ;).
return SNew(SFactionPin, InPin); // and return our customized pin widget ;).
}
return nullptr;
}
106 changes: 46 additions & 60 deletions Source/Editor/Private/Customizations/FactionRelationCustomization.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// Copyright 2015-2020 Piperift. All Rights Reserved.
// Copyright 2015-2023 Piperift. All Rights Reserved.

#include "Customizations/FactionRelationCustomization.h"

#include "Customizations/SFaction.h"
#include "DetailWidgetRow.h"
#include "IDetailPropertyRow.h"
#include "FactionsEditorStyle.h"
#include "FactionsSubsystem.h"
#include "IDetailChildrenBuilder.h"
#include "IDetailPropertyRow.h"
#include "Widgets/Views/SListView.h"

#include "FactionsSubsystem.h"
#include "Customizations/SFaction.h"
#include "FactionsEditorStyle.h"

#define LOCTEXT_NAMESPACE "FFactionRelationCustomization"

Expand All @@ -18,72 +18,58 @@ TSharedRef<IPropertyTypeCustomization> FFactionRelationCustomization::MakeInstan
return MakeShareable(new FFactionRelationCustomization);
}

void FFactionRelationCustomization::CustomizeHeader(TSharedRef<IPropertyHandle> StructPropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
void FFactionRelationCustomization::CustomizeHeader(TSharedRef<IPropertyHandle> StructPropertyHandle,
FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
TSharedPtr<IPropertyHandle> SourceHandle = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, Source));
TSharedPtr<IPropertyHandle> TargetHandle = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, Target));
TSharedPtr<IPropertyHandle> AttitudeHandle = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, Attitude));
TSharedPtr<IPropertyHandle> BidirectionalHandle = StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, bBidirectional));
TSharedPtr<IPropertyHandle> SourceHandle =
StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, Source));
TSharedPtr<IPropertyHandle> TargetHandle =
StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, Target));
TSharedPtr<IPropertyHandle> AttitudeHandle =
StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, Attitude));
TSharedPtr<IPropertyHandle> BidirectionalHandle =
StructPropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFactionRelation, bBidirectional));

HeaderRow
.NameContent()
.HAlign(HAlign_Fill)
[
StructPropertyHandle->CreatePropertyNameWidget()
]
.ValueContent()
.HAlign(HAlign_Fill)
[
SNew(SHorizontalBox)
+SHorizontalBox::Slot()
.HAlign(HAlign_Fill)
[
CreateFactionWidget(SourceHandle.ToSharedRef())
]
+ SHorizontalBox::Slot()
.AutoWidth()
[
SNew(SCheckBox)
.Style(FFactionsEditorStyle::Get(), "Relation.DirectionalCheckBox")
.IsChecked_Lambda([=](){
bool bValue = false;
BidirectionalHandle->GetValue(bValue);
return bValue ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
})
.OnCheckStateChanged_Lambda([=](const ECheckBoxState NewState){
BidirectionalHandle->SetValue(NewState == ECheckBoxState::Checked);
})
.ToolTipText(BidirectionalHandle->GetToolTipText())
]
+ SHorizontalBox::Slot()
.HAlign(HAlign_Fill)
[
CreateFactionWidget(TargetHandle.ToSharedRef())
]
+ SHorizontalBox::Slot()
HeaderRow.NameContent()
.HAlign(HAlign_Fill)[StructPropertyHandle->CreatePropertyNameWidget()]
.ValueContent()
.HAlign(HAlign_Fill)
[
AttitudeHandle->CreatePropertyValueWidget()
]
];
[SNew(SHorizontalBox) +
SHorizontalBox::Slot().HAlign(HAlign_Fill)[CreateFactionWidget(SourceHandle.ToSharedRef())] +
SHorizontalBox::Slot()
.AutoWidth()[SNew(SCheckBox)
.Style(FFactionsEditorStyle::Get(), "Relation.DirectionalCheckBox")
.IsChecked_Lambda([=]() {
bool bValue = false;
BidirectionalHandle->GetValue(bValue);
return bValue ? ECheckBoxState::Checked : ECheckBoxState::Unchecked;
})
.OnCheckStateChanged_Lambda([=](const ECheckBoxState NewState) {
BidirectionalHandle->SetValue(NewState == ECheckBoxState::Checked);
})
.ToolTipText(BidirectionalHandle->GetToolTipText())] +
SHorizontalBox::Slot().HAlign(HAlign_Fill)[CreateFactionWidget(TargetHandle.ToSharedRef())] +
SHorizontalBox::Slot().HAlign(HAlign_Fill)[AttitudeHandle->CreatePropertyValueWidget()]];
}

void FFactionRelationCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle, IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
void FFactionRelationCustomization::CustomizeChildren(TSharedRef<IPropertyHandle> StructPropertyHandle,
IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{}

TSharedRef<SWidget> FFactionRelationCustomization::CreateFactionWidget(TSharedRef<IPropertyHandle> PropertyHandle)
TSharedRef<SWidget> FFactionRelationCustomization::CreateFactionWidget(
TSharedRef<IPropertyHandle> PropertyHandle)
{
auto IdHandle = PropertyHandle->GetChildHandle(GET_MEMBER_NAME_CHECKED(FFaction, Id));

return SNew(SFaction)
.Faction_Lambda([IdHandle]() {
FName Id;
IdHandle->GetValue(Id);
return FFaction{Id};
})
.OnFactionSelected_Lambda([IdHandle](FFaction Faction, ESelectInfo::Type) {
IdHandle->SetValue(Faction.GetId());
});
.Faction_Lambda([IdHandle]() {
FName Id;
IdHandle->GetValue(Id);
return FFaction{Id};
})
.OnFactionSelected_Lambda([IdHandle](FFaction Faction, ESelectInfo::Type) {
IdHandle->SetValue(Faction.GetId());
});
}

#undef LOCTEXT_NAMESPACE
Loading

0 comments on commit 4105d44

Please sign in to comment.