91 lines
2.1 KiB
C++
91 lines
2.1 KiB
C++
// 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));
|
|
}
|