完善背包配置UI
This commit is contained in:
parent
19ca9f7212
commit
a66065abae
@ -8,6 +8,7 @@
|
|||||||
#include "ProjectFish/DataAsset/BagShapeAsset.h"
|
#include "ProjectFish/DataAsset/BagShapeAsset.h"
|
||||||
#include "Widgets/BagConfigGridWidget.h"
|
#include "Widgets/BagConfigGridWidget.h"
|
||||||
#include "Widgets/BagShapeGridWidget.h"
|
#include "Widgets/BagShapeGridWidget.h"
|
||||||
|
#include "Widgets/SkillListWidget.h"
|
||||||
#include "Widgets/Notifications/SNotificationList.h"
|
#include "Widgets/Notifications/SNotificationList.h"
|
||||||
|
|
||||||
|
|
||||||
@ -194,30 +195,30 @@ void SBagConfigEditorWidget::Construct(const FArguments& InArgs)
|
|||||||
]
|
]
|
||||||
]
|
]
|
||||||
|
|
||||||
// // 右侧:技能列表
|
// 右侧:技能列表
|
||||||
// + SSplitter::Slot()
|
+ SSplitter::Slot()
|
||||||
// .Value(0.3f)
|
.Value(0.3f)
|
||||||
// [
|
[
|
||||||
// SNew(SVerticalBox)
|
SNew(SVerticalBox)
|
||||||
//
|
|
||||||
// + SVerticalBox::Slot()
|
+ SVerticalBox::Slot()
|
||||||
// .AutoHeight()
|
.AutoHeight()
|
||||||
// .Padding(5.0f)
|
.Padding(5.0f)
|
||||||
// [
|
[
|
||||||
// SNew(STextBlock)
|
SNew(STextBlock)
|
||||||
// .Text(FText::FromString(TEXT("Placed Skills:")))
|
.Text(FText::FromString(TEXT("已添加技能:")))
|
||||||
// .Font(FCoreStyle::GetDefaultFontStyle("Bold", 12))
|
.Font(FCoreStyle::GetDefaultFontStyle("Bold", 12))
|
||||||
// ]
|
]
|
||||||
//
|
|
||||||
// + SVerticalBox::Slot()
|
+ SVerticalBox::Slot()
|
||||||
// .FillHeight(1.0f)
|
.FillHeight(1.0f)
|
||||||
// .Padding(5.0f)
|
.Padding(5.0f)
|
||||||
// [
|
[
|
||||||
// SAssignNew(SkillListWidget, SSkillListWidget)
|
SAssignNew(SkillListWidget, SSkillListWidget)
|
||||||
// .BagClass(BagClass.Get())
|
.BagConfig(BagConfig.Get())
|
||||||
// .OnSkillSelected(this, &SBagClassEditor::OnSkillSelected)
|
.OnSkillSelected(this, &SBagConfigEditorWidget::OnSkillSelected)
|
||||||
// ]
|
]
|
||||||
// ]
|
]
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
@ -320,6 +321,11 @@ void SBagConfigEditorWidget::OnSkillAssetChanged(const FAssetData& AssetData)
|
|||||||
SelectedSkillAsset = Cast<USkillAsset>(AssetData.GetAsset());
|
SelectedSkillAsset = Cast<USkillAsset>(AssetData.GetAsset());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SBagConfigEditorWidget::OnSkillSelected(int32 SkillIndex)
|
||||||
|
{
|
||||||
|
SelectedSkillIndex = SkillIndex;
|
||||||
|
}
|
||||||
|
|
||||||
void SBagConfigEditorWidget::OnGridCellClicked(int32 X, int32 Y)
|
void SBagConfigEditorWidget::OnGridCellClicked(int32 X, int32 Y)
|
||||||
{
|
{
|
||||||
if (!BagConfig.IsValid())
|
if (!BagConfig.IsValid())
|
||||||
@ -372,10 +378,10 @@ void SBagConfigEditorWidget::RefreshUI()
|
|||||||
BagGridWidget->RefreshGrid();
|
BagGridWidget->RefreshGrid();
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (SkillListWidget.IsValid())
|
if (SkillListWidget.IsValid())
|
||||||
// {
|
{
|
||||||
// SkillListWidget->RefreshSkillList();
|
SkillListWidget->RefreshSkillList();
|
||||||
// }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SBagConfigEditorWidget::ShowWarningMessage(const FString& Message)
|
void SBagConfigEditorWidget::ShowWarningMessage(const FString& Message)
|
||||||
|
|||||||
@ -0,0 +1,90 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
|
||||||
|
#include "Widgets/SkillListWidget.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void SSkillListWidget::Construct(const FArguments& InArgs)
|
||||||
|
{
|
||||||
|
BagConfig = InArgs._BagConfig;
|
||||||
|
OnSkillSelected = InArgs._OnSkillSelected;
|
||||||
|
SelectedSkillIndex = -1;
|
||||||
|
|
||||||
|
ChildSlot
|
||||||
|
[
|
||||||
|
SNew(SBox)
|
||||||
|
.MinDesiredWidth(200.0f)
|
||||||
|
.MinDesiredHeight(300.0f)
|
||||||
|
[
|
||||||
|
SAssignNew(SkillListView, SListView<TSharedPtr<int32>>)
|
||||||
|
.ItemHeight(24.0f)
|
||||||
|
.ListItemsSource(&SkillIndices)
|
||||||
|
.OnGenerateRow(this, &SSkillListWidget::OnGenerateSkillRow)
|
||||||
|
.OnSelectionChanged(this, &SSkillListWidget::OnSkillSelectionChanged)
|
||||||
|
]
|
||||||
|
];
|
||||||
|
|
||||||
|
RefreshSkillList();
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSkillListWidget::RefreshSkillList()
|
||||||
|
{
|
||||||
|
SkillIndices.Empty();
|
||||||
|
|
||||||
|
if (BagConfig.IsValid())
|
||||||
|
{
|
||||||
|
for (int32 i = 0; i < BagConfig->PlacedSkills.Num(); i++)
|
||||||
|
{
|
||||||
|
SkillIndices.Add(MakeShareable(new int32(i)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SkillListView.IsValid())
|
||||||
|
{
|
||||||
|
SkillListView->RequestListRefresh();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
TSharedRef<ITableRow> SSkillListWidget::OnGenerateSkillRow(TSharedPtr<int32> SkillIndex,
|
||||||
|
const TSharedRef<STableViewBase>& OwnerTable)
|
||||||
|
{
|
||||||
|
return SNew(STableRow<TSharedPtr<int32>>, OwnerTable)
|
||||||
|
[
|
||||||
|
SNew(STextBlock)
|
||||||
|
.Text(this, &SSkillListWidget::GetSkillDisplayText, *SkillIndex)
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
void SSkillListWidget::OnSkillSelectionChanged(TSharedPtr<int32> SelectedItem, ESelectInfo::Type SelectInfo)
|
||||||
|
{
|
||||||
|
if (SelectedItem.IsValid())
|
||||||
|
{
|
||||||
|
SelectedSkillIndex = *SelectedItem;
|
||||||
|
OnSkillSelected.ExecuteIfBound(SelectedSkillIndex);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
SelectedSkillIndex = -1;
|
||||||
|
OnSkillSelected.ExecuteIfBound(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FText SSkillListWidget::GetSkillDisplayText(int32 SkillIndex) const
|
||||||
|
{
|
||||||
|
if (!BagConfig.IsValid() || SkillIndex < 0 || SkillIndex >= BagConfig->PlacedSkills.Num())
|
||||||
|
{
|
||||||
|
return FText::FromString(TEXT("Invalid Skill"));
|
||||||
|
}
|
||||||
|
|
||||||
|
const FPlacedSkillInfo& PlacedSkill = BagConfig->PlacedSkills[SkillIndex];
|
||||||
|
if (!PlacedSkill.SkillAsset)
|
||||||
|
{
|
||||||
|
return FText::FromString(TEXT("Invalid Skill"));
|
||||||
|
}
|
||||||
|
|
||||||
|
return FText::FromString(FString::Printf(TEXT("%s at (%d,%d)"),
|
||||||
|
*PlacedSkill.SkillAsset->SkillName.ToString(),
|
||||||
|
PlacedSkill.PositionX,
|
||||||
|
PlacedSkill.PositionY));
|
||||||
|
}
|
||||||
@ -35,7 +35,7 @@ private:
|
|||||||
|
|
||||||
// UI组件
|
// UI组件
|
||||||
TSharedPtr<class SBagConfigGridWidget> BagGridWidget;
|
TSharedPtr<class SBagConfigGridWidget> BagGridWidget;
|
||||||
//TSharedPtr<class SSkillListWidget> SkillListWidget;
|
TSharedPtr<class SSkillListWidget> SkillListWidget;
|
||||||
|
|
||||||
// 回调函数
|
// 回调函数
|
||||||
FReply OnAddSkillClicked();
|
FReply OnAddSkillClicked();
|
||||||
@ -48,9 +48,9 @@ private:
|
|||||||
// 技能选择回调
|
// 技能选择回调
|
||||||
void OnSkillAssetChanged(const FAssetData& AssetData);
|
void OnSkillAssetChanged(const FAssetData& AssetData);
|
||||||
|
|
||||||
// // 技能选择回调
|
// 技能选择回调
|
||||||
// void OnSkillSelected(int32 SkillIndex);
|
void OnSkillSelected(int32 SkillIndex);
|
||||||
//
|
|
||||||
// 格子点击回调
|
// 格子点击回调
|
||||||
void OnGridCellClicked(int32 X, int32 Y);
|
void OnGridCellClicked(int32 X, int32 Y);
|
||||||
|
|
||||||
@ -66,3 +66,5 @@ private:
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -61,7 +61,7 @@ private:
|
|||||||
FVector2D GetGridCellFromPosition(const FVector2D& Position) const;
|
FVector2D GetGridCellFromPosition(const FVector2D& Position) const;
|
||||||
bool IsValidGridPosition(int32 X, int32 Y) const;
|
bool IsValidGridPosition(int32 X, int32 Y) const;
|
||||||
FLinearColor GetCellColor(int32 X, int32 Y) const;
|
FLinearColor GetCellColor(int32 X, int32 Y) const;
|
||||||
// int32 GetSkillAtPosition(int32 X, int32 Y) const;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
inline FVector2D SBagConfigGridWidget::GetCellPosition(int32 X, int32 Y) const
|
inline FVector2D SBagConfigGridWidget::GetCellPosition(int32 X, int32 Y) const
|
||||||
|
|||||||
@ -0,0 +1,57 @@
|
|||||||
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "ProjectFish/DataAsset/BagConfigAsset.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
DECLARE_DELEGATE_OneParam(FOnSkillSelected, int32);
|
||||||
|
|
||||||
|
class SSkillListWidget : public SCompoundWidget
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SLATE_BEGIN_ARGS(SSkillListWidget) {}
|
||||||
|
SLATE_ARGUMENT(UBagConfigAsset*, BagConfig)
|
||||||
|
SLATE_EVENT(FOnSkillSelected, OnSkillSelected)
|
||||||
|
SLATE_END_ARGS()
|
||||||
|
|
||||||
|
void Construct(const FArguments& InArgs);
|
||||||
|
|
||||||
|
// // 设置背包类
|
||||||
|
// void SetBagClass(UBagConfigAsset* InBagClass);
|
||||||
|
|
||||||
|
// 刷新技能列表
|
||||||
|
void RefreshSkillList();
|
||||||
|
//
|
||||||
|
// // 获取选中的技能索引
|
||||||
|
// int32 GetSelectedSkillIndex() const { return SelectedSkillIndex; }
|
||||||
|
//
|
||||||
|
// // 设置选中的技能
|
||||||
|
// void SetSelectedSkill(int32 SkillIndex);
|
||||||
|
|
||||||
|
private:
|
||||||
|
// 背包类引用
|
||||||
|
TWeakObjectPtr<UBagConfigAsset> BagConfig;
|
||||||
|
|
||||||
|
// 回调委托
|
||||||
|
FOnSkillSelected OnSkillSelected;
|
||||||
|
|
||||||
|
// 选中的技能索引
|
||||||
|
int32 SelectedSkillIndex;
|
||||||
|
|
||||||
|
// UI组件
|
||||||
|
TSharedPtr<class SListView<TSharedPtr<int32>>> SkillListView;
|
||||||
|
TArray<TSharedPtr<int32>> SkillIndices;
|
||||||
|
|
||||||
|
// 列表项生成函数
|
||||||
|
TSharedRef<ITableRow> OnGenerateSkillRow(TSharedPtr<int32> SkillIndex, const TSharedRef<STableViewBase>& OwnerTable);
|
||||||
|
|
||||||
|
// 选择改变回调
|
||||||
|
void OnSkillSelectionChanged(TSharedPtr<int32> SelectedItem, ESelectInfo::Type SelectInfo);
|
||||||
|
|
||||||
|
// 创建技能显示文本
|
||||||
|
FText GetSkillDisplayText(int32 SkillIndex) const;
|
||||||
|
};
|
||||||
Loading…
x
Reference in New Issue
Block a user