Optimize some gameinstance codes

This commit is contained in:
martinluckyrobots 2025-04-03 10:13:55 +08:00
parent 7fa3ec0926
commit b7ed84f353
33 changed files with 118 additions and 4 deletions

Binary file not shown.

View 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;
}
}

View File

@ -2,6 +2,42 @@
#include "LuckyRobotsGameInstance.h" #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() void ULuckyRobotsGameInstance::ClearTaskList()
{ {
@ -79,4 +115,21 @@ void ULuckyRobotsGameInstance::ReSetTaskList()
TArray<FGoalsTaskData> ULuckyRobotsGameInstance::GetTaskList() TArray<FGoalsTaskData> ULuckyRobotsGameInstance::GetTaskList()
{ {
return TaskList; return TaskList;
} }
void ULuckyRobotsGameInstance::DoSetTempTaskValueChange(bool IsClear)
{
if (IsClear)
{
ClearTaskList();
}
else
{
AddTask(TempTask);
}
if (GameUserWidget)
{
GameUserWidget->DoRefreshListView();
}
}

View 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();
};

View File

@ -8,6 +8,7 @@
#include "LuckyRobotsGameInstance.generated.h" #include "LuckyRobotsGameInstance.generated.h"
class USIOJsonValue; class USIOJsonValue;
class UGameUserWidget;
/** /**
* *
*/ */
@ -39,10 +40,20 @@ public:
UPROPERTY(EditAnywhere, BlueprintReadWrite) UPROPERTY(EditAnywhere, BlueprintReadWrite)
FGoalsTaskData TempTask; FGoalsTaskData TempTask;
public: UPROPERTY(EditAnywhere, BlueprintReadWrite)
UFUNCTION(BlueprintImplementableEvent) UGameUserWidget* GameUserWidget;
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
public:
UFUNCTION(BlueprintCallable)
void DoSendMessage(FString SendValue);
UFUNCTION(BlueprintCallable)
void DoLogItemAdd(FString Topic, FString MsgText, int Type);
UFUNCTION(BlueprintCallable)
void SwitchGamePaused();
public:
UFUNCTION(BlueprintCallable) UFUNCTION(BlueprintCallable)
void ClearTaskList(); void ClearTaskList();
@ -69,4 +80,11 @@ public:
UFUNCTION(BlueprintPure) UFUNCTION(BlueprintPure)
TArray<FGoalsTaskData> GetTaskList(); TArray<FGoalsTaskData> GetTaskList();
UFUNCTION(BlueprintCallable)
void DoSetTempTaskValueChange(bool IsClear);
public:
UFUNCTION(BlueprintImplementableEvent)
void DoGetDispatch(const FString& EventName, USIOJsonValue* EventData);
}; };