You've already forked LuckyWorld
Optimize some gameinstance codes
This commit is contained in:
17
Source/Luckyrobots/Private/GameUserWidget.cpp
Normal file
17
Source/Luckyrobots/Private/GameUserWidget.cpp
Normal file
@ -0,0 +1,17 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "GameUserWidget.h"
|
||||
#include "LuckyRobotsFunctionLibrary.h"
|
||||
#include "LuckyRobotsGameInstance.h"
|
||||
|
||||
void UGameUserWidget::NativeConstruct()
|
||||
{
|
||||
Super::NativeConstruct();
|
||||
|
||||
ULuckyRobotsGameInstance* LuckyRobotsGameInstance = ULuckyRobotsFunctionLibrary::GetLuckyRobotsGameInstance(this);
|
||||
if (LuckyRobotsGameInstance)
|
||||
{
|
||||
LuckyRobotsGameInstance->GameUserWidget = this;
|
||||
}
|
||||
}
|
@ -2,6 +2,42 @@
|
||||
|
||||
|
||||
#include "LuckyRobotsGameInstance.h"
|
||||
#include "LuckyRobotsGameState.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "GameUserWidget.h"
|
||||
|
||||
void ULuckyRobotsGameInstance::DoSendMessage(FString SendValue)
|
||||
{
|
||||
ALuckyRobotsGameState* LuckyRobotsGameState = Cast<ALuckyRobotsGameState>(UGameplayStatics::GetGameState(this));
|
||||
if (LuckyRobotsGameState)
|
||||
{
|
||||
LuckyRobotsGameState->DoSendMessage(SendValue);
|
||||
}
|
||||
|
||||
DoLogItemAdd("Receive", SendValue, 0);
|
||||
}
|
||||
|
||||
void ULuckyRobotsGameInstance::DoLogItemAdd(FString Topic, FString MsgText, int Type)
|
||||
{
|
||||
if (GameUserWidget)
|
||||
{
|
||||
GameUserWidget->DoLogItemAdd(Topic, MsgText, Type);
|
||||
}
|
||||
}
|
||||
|
||||
void ULuckyRobotsGameInstance::SwitchGamePaused()
|
||||
{
|
||||
UGameplayStatics::SetGamePaused(this, !UGameplayStatics::IsGamePaused(this));
|
||||
|
||||
if (UGameplayStatics::IsGamePaused(this))
|
||||
{
|
||||
UKismetSystemLibrary::ExecuteConsoleCommand(this, "r.SceneRendering 0");
|
||||
}
|
||||
else
|
||||
{
|
||||
UKismetSystemLibrary::ExecuteConsoleCommand(this, "r.SceneRendering 1");
|
||||
}
|
||||
}
|
||||
|
||||
void ULuckyRobotsGameInstance::ClearTaskList()
|
||||
{
|
||||
@ -79,4 +115,21 @@ void ULuckyRobotsGameInstance::ReSetTaskList()
|
||||
TArray<FGoalsTaskData> ULuckyRobotsGameInstance::GetTaskList()
|
||||
{
|
||||
return TaskList;
|
||||
}
|
||||
}
|
||||
|
||||
void ULuckyRobotsGameInstance::DoSetTempTaskValueChange(bool IsClear)
|
||||
{
|
||||
if (IsClear)
|
||||
{
|
||||
ClearTaskList();
|
||||
}
|
||||
else
|
||||
{
|
||||
AddTask(TempTask);
|
||||
}
|
||||
|
||||
if (GameUserWidget)
|
||||
{
|
||||
GameUserWidget->DoRefreshListView();
|
||||
}
|
||||
}
|
||||
|
26
Source/Luckyrobots/Public/GameUserWidget.h
Normal file
26
Source/Luckyrobots/Public/GameUserWidget.h
Normal file
@ -0,0 +1,26 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "GameUserWidget.generated.h"
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
UCLASS()
|
||||
class LUCKYROBOTS_API UGameUserWidget : public UUserWidget
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
protected:
|
||||
virtual void NativeConstruct();
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void DoLogItemAdd(const FString& Topic, const FString& MsgText,int Type);
|
||||
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void DoRefreshListView();
|
||||
};
|
@ -8,6 +8,7 @@
|
||||
#include "LuckyRobotsGameInstance.generated.h"
|
||||
|
||||
class USIOJsonValue;
|
||||
class UGameUserWidget;
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@ -39,10 +40,20 @@ public:
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
FGoalsTaskData TempTask;
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
|
||||
UPROPERTY(EditAnywhere, BlueprintReadWrite)
|
||||
UGameUserWidget* GameUserWidget;
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void DoSendMessage(FString SendValue);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void DoLogItemAdd(FString Topic, FString MsgText, int Type);
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void SwitchGamePaused();
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void ClearTaskList();
|
||||
|
||||
@ -69,4 +80,11 @@ public:
|
||||
|
||||
UFUNCTION(BlueprintPure)
|
||||
TArray<FGoalsTaskData> GetTaskList();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
void DoSetTempTaskValueChange(bool IsClear);
|
||||
|
||||
public:
|
||||
UFUNCTION(BlueprintImplementableEvent)
|
||||
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
|
||||
};
|
||||
|
Reference in New Issue
Block a user