1 强化前置条件完善
StrengthManager里实现一个Check前置的函数
bool CheckPreAllIsActive(int index),所有的前置都已经激活就返回true,否则返回false
之后在强化的时候加入条件检查:
1.所有前置技能全部激活
2.本身没有强化过
最后测试的时候修改下UI样式以便查看信息
2 实现过程
2.1 bool CheckPreAllIsActive和void SetCellIsActiveByIndex
声明:
cpp
UFUNCTION(BlueprintCallable)
bool CheckPreAllIsActive(int index);
UFUNCTION(BlueprintCallable)
void SetCellIsActiveByIndex(int index,bool isActive);
实现:
bool CheckPreAllIsActive检查所有前置是否激活
SetCellIsActiveByIndex提供一个对外接口设置IsActive
cpp
bool UStrengthenManager::CheckPreAllIsActive(int index)
{
TArray<int> AllPreIndex=StrengthenTree_1[index].PreIndex;
for(int i=0;i<AllPreIndex.Num();i++)
{
if(AllPreIndex[i]>=0&&AllPreIndex[i]<StrengthenTree_1.Num())
{
if(!StrengthenTree_1[AllPreIndex[i]].bIsActive)
{
return false;
}
}
}
return true;
}
void UStrengthenManager::SetCellIsActiveByIndex(int index,bool isActive)
{
if(index>=0&&index<StrengthenTree_1.Num())
{
StrengthenTree_1[index].bIsActive=isActive;
}
}
2.2 TryStrengthenByCellIndex的修改
修改条件判断,加入前置检查和自身是否激活检查
cpp
if(temp.NeededItems[i].CurrentOwnedCnt>OwnedCnt||!StrengthenManager->CheckPreAllIsActive(index)||temp.bIsActive)
{
bCanStrengthen=false;
}
强化具体逻辑修改:
cpp
StrengthenManager->SetCellIsActiveByIndex(index,true);
StrengthenManager->Save();
StrengthenByName(FString("BaseAttack"),10);
for(int i=0;i<temp.NeededItems.Num();i++)
{
WarehouseManager->RemoveItemFromWarehouse(temp.NeededItems[i].ItemId,temp.NeededItems[i].CurrentOwnedCnt);
}
WarehouseManager->SaveData();
UpdatePadInfo();
SaveToSlot();
return true;
2.3 UI样式的修改
加了一个根据是否激活更新外观的Update:
在开始的时候统一了按钮的样式:
3 最终效果测试
除了界面丑以外还是挺完美的()
4 补充:给物品加入图标
仓库管理类中加入了一个获取图标的函数
cpp
UTexture2D* UWarehouseManager::GetTexture2DByItemId(int32 ItemId)
{
UTexture2D* MyTexture=NewObject<UTexture2D>();
if(ItemId==1)
{
MyTexture = LoadObject<UTexture2D>(nullptr, TEXT("/Game/ItemTexture/id_1.id_1"));
}
return MyTexture;
}
UI中同步更新图标:
效果: