added journal to game, still needs fonts and navigation

This commit is contained in:
Djalim Simaila 2023-11-19 19:40:33 +01:00
parent d6aca1c30f
commit 8d0f52bccb
26 changed files with 610 additions and 6 deletions

0
.editorconfig Normal file
View File

13
.vsconfig Normal file
View File

@ -0,0 +1,13 @@
{
"version": "1.0",
"components": [
"Microsoft.Net.Component.4.6.2.TargetingPack",
"Microsoft.VisualStudio.Component.VC.14.36.17.6.x86.x64",
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
"Microsoft.VisualStudio.Component.Windows10SDK.22000",
"Microsoft.VisualStudio.Workload.CoreEditor",
"Microsoft.VisualStudio.Workload.ManagedDesktop",
"Microsoft.VisualStudio.Workload.NativeDesktop",
"Microsoft.VisualStudio.Workload.NativeGame"
]
}

Binary file not shown.

BIN
Content/ToggleJournal.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/part1--5/BP_JournalWidget.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/part1--5/JournalWidget_BPP.uasset (Stored with Git LFS) Normal file

Binary file not shown.

Binary file not shown.

BIN
Content/part1/partie1.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -3,6 +3,17 @@
"EngineAssociation": "5.3", "EngineAssociation": "5.3",
"Category": "", "Category": "",
"Description": "", "Description": "",
"Modules": [
{
"Name": "SURREALISM",
"Type": "Runtime",
"LoadingPhase": "Default",
"AdditionalDependencies": [
"Engine",
"UMG"
]
}
],
"Plugins": [ "Plugins": [
{ {
"Name": "ModelingToolsEditorMode", "Name": "ModelingToolsEditorMode",

View File

@ -0,0 +1,16 @@
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.Collections.Generic;
public class SURREALISMTarget : TargetRules
{
public SURREALISMTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Game;
DefaultBuildSettings = BuildSettingsVersion.V4;
IncludeOrderVersion = EngineIncludeOrderVersion.Latest;
ExtraModuleNames.AddRange( new string[] { "SURREALISM" } );
}
}

View File

@ -0,0 +1,53 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "Item.h"
#include "JournalWidget.h"
#include "Kismet/GameplayStatics.h"
// Sets default values
AItem::AItem()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = false;
}
// Called when the game starts or when spawned
void AItem::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AItem::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}
FString AItem::get_item_name(){
return item_name;
}
FString AItem::get_item_description(){
return item_description;
}
void AItem::set_item_name(FString new_name){
item_name = new_name;
}
void AItem::set_item_description(FString new_description){
item_description = new_description;
}
void AItem::send_item_to_journal(){
TArray<AActor*> FoundActors;
UGameplayStatics::GetAllActorsOfClass(GetWorld(), UJournalWidget::StaticClass(), FoundActors);
if (FoundActors.Num() > 0){
UJournalWidget* journal_widget = Cast<UJournalWidget>(FoundActors[0]);
journal_widget->add_to_journal(item_name, item_description);
}
}

47
Source/SURREALISM/Item.h Normal file
View File

@ -0,0 +1,47 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "Item.generated.h"
UCLASS(Blueprintable)
class SURREALISM_API AItem : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AItem();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "Item")
FString item_name = "Item name";
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Item")
FString item_description = "Item description";
UFUNCTION(BlueprintCallable,CallInEditor , Category = "Item")
FString get_item_name();
UFUNCTION(BlueprintCallable,CallInEditor, Category = "Item")
FString get_item_description();
UFUNCTION(BlueprintCallable,CallInEditor, Category = "Item")
void set_item_name(FString new_name);
UFUNCTION(BlueprintCallable,CallInEditor, Category = "Item")
void set_item_description(FString new_description);
UFUNCTION(BlueprintCallable,CallInEditor, Category = "Item")
void send_item_to_journal();
};

View File

@ -0,0 +1,75 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "JournalPage.h"
#include "utils_functions.h"
UJournalPage::UJournalPage()
{
max_page_entries = 10;
page_entries = TArray<FJournalEntry>();
}
void UJournalPage::add_entry(FString entry_name, FString entry_description)
{
if (page_entries.Num() < max_page_entries)
{
FJournalEntry entry;
entry.entry_name = entry_name;
entry.entry_description = entry_description;
page_entries.Add(entry);
}
return;
}
void UJournalPage::remove_entry(FString entry_name)
{
for (int i = 0; i < page_entries.Num(); i++)
{
if (page_entries[i].entry_name == entry_name)
{
page_entries.RemoveAt(i);
return;
}
}
return;
}
TArray<FString> UJournalPage::get_all_entries_names()
{
TArray<FString> entries_names;
for (const auto& entry : page_entries)
{
entries_names.Add(entry.entry_name);
}
return entries_names;
}
TArray<FString> UJournalPage::get_all_entries_descriptions()
{
TArray<FString> entries_descriptions;
for (const auto& entry : page_entries)
{
entries_descriptions.Add(entry.entry_description);
}
return entries_descriptions;
}
FString UJournalPage::get_entry_description(FString entry_name)
{
for (const auto& entry : page_entries)
{
if (entry.entry_name == entry_name)
{
return entry.entry_description;
}
}
return FString("No description found");
}
int UJournalPage::get_number_of_entries()
{
return page_entries.Num();
}

View File

@ -0,0 +1,45 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "JournalPage.generated.h"
USTRUCT(BlueprintType)
struct FJournalEntry
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
FString entry_name;
FString entry_description;
};
/**
*
*/
UCLASS()
class SURREALISM_API UJournalPage : public UObject
{
GENERATED_BODY()
public:
UJournalPage();
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
TArray<FJournalEntry> page_entries;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
int32 max_page_entries;
void add_entry(FString entry_name, FString entry_description);
void remove_entry(FString entry_name);
TArray<FString> get_all_entries_names();
TArray<FString> get_all_entries_descriptions();
int32 get_number_of_entries();
FString get_entry_description(FString entry_name);
};

View File

@ -0,0 +1,118 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "JournalWidget.h"
#include "JournalPage.h"
#include "utils_functions.h"
void UJournalWidget::NativeConstruct()
{
Super::NativeConstruct();
//UJournalPage* page = NewObject<UJournalPage>();
//journal_pages.Add(page);
//current_number_of_pages = journal_pages.Num();
//current_page_number = 0;
}
void UJournalWidget::next_page()
{
if (current_page_number + 1 < max_pages)
{
current_page_number++;
}
}
void UJournalWidget::previous_page()
{
if (current_page_number - 1 >= 0)
{
current_page_number--;
}
}
void UJournalWidget::go_to_page(int page_number)
{
current_page_number = page_number;
}
void UJournalWidget::remove_page(int page_number)
{
if (page_number < current_number_of_pages)
{
journal_pages.RemoveAt(page_number);
current_number_of_pages = journal_pages.Num();
}
}
TArray<FString> UJournalWidget::get_current_page_entries_names()
{
if (current_page_number < current_number_of_pages)
{
return journal_pages[current_page_number]->get_all_entries_names();
}
return TArray<FString>();
}
FString UJournalWidget::get_entry_description(FString entry_name)
{
if (current_page_number < current_number_of_pages)
{
return journal_pages[current_page_number]->get_entry_description(entry_name);
}
return FString();
}
void UJournalWidget::clear_journal()
{
journal_pages.Empty();
UJournalPage page = UJournalPage();
journal_pages.Add(&page);
current_number_of_pages = journal_pages.Num();
}
void UJournalWidget::add_to_journal(FString item_name, FString item_description)
{
for (int i = 0; i < current_number_of_pages; i++)
{
if (journal_pages[i]->get_number_of_entries() < journal_pages[i]->max_page_entries)
{
//utils_functions::debug_print("added item to page");
journal_pages[i]->add_entry(item_name, item_description);
return;
}
}
UJournalPage* page = NewObject<UJournalPage>();
page->add_entry(item_name, item_description);
journal_pages.Add(page);
current_number_of_pages = journal_pages.Num();
return;
}
void UJournalWidget::print_current_page()
{
if (current_page_number < current_number_of_pages)
{
for (FString entry_name : journal_pages[current_page_number]->get_all_entries_names())
{
utils_functions::debug_print(TCHAR_TO_ANSI(*entry_name));
FString entry_description = journal_pages[current_page_number]->get_entry_description(entry_name);
utils_functions::debug_print(TCHAR_TO_ANSI(*entry_description));
}
}
return;
}
int UJournalWidget::add_page()
{
UJournalPage* page = NewObject<UJournalPage>();
journal_pages.Add(page);
current_number_of_pages = journal_pages.Num();
return current_number_of_pages;
}
int UJournalWidget::get_current_page_number()
{
return current_page_number;
}

View File

@ -0,0 +1,68 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "JournalPage.h"
#include "JournalWidget.generated.h"
/**
*
*/
UCLASS(Blueprintable)
class SURREALISM_API UJournalWidget : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
TArray<UJournalPage*> journal_pages;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
int max_pages = 10;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
int current_number_of_pages = 0;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "Journal")
int current_page_number = 0;
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void next_page();
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void previous_page();
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void go_to_page(int page_number);
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void remove_page(int page_number);
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
TArray<FString> get_current_page_entries_names();
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
FString get_entry_description(FString entry_name);
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
int add_page();
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void add_to_journal(FString item_name, FString item_description);
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void clear_journal();
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
void print_current_page();
UFUNCTION(BlueprintCallable, CallInEditor, Category = "Journal")
int get_current_page_number();
virtual void NativeConstruct() override;
};

View File

@ -0,0 +1,27 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyActor.h"
// Sets default values
AMyActor::AMyActor()
{
// Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.
PrimaryActorTick.bCanEverTick = true;
}
// Called when the game starts or when spawned
void AMyActor::BeginPlay()
{
Super::BeginPlay();
}
// Called every frame
void AMyActor::Tick(float DeltaTime)
{
Super::Tick(DeltaTime);
}

View File

@ -0,0 +1,26 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "MyActor.generated.h"
UCLASS()
class SURREALISM_API AMyActor : public AActor
{
GENERATED_BODY()
public:
// Sets default values for this actor's properties
AMyActor();
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
public:
// Called every frame
virtual void Tick(float DeltaTime) override;
};

View File

@ -0,0 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "MyUserWidget.h"

View File

@ -0,0 +1,17 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "MyUserWidget.generated.h"
/**
*
*/
UCLASS()
class SURREALISM_API UMyUserWidget : public UUserWidget
{
GENERATED_BODY()
};

View File

@ -0,0 +1,23 @@
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
public class SURREALISM : ModuleRules
{
public SURREALISM(ReadOnlyTargetRules Target) : base(Target)
{
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore" });
PrivateDependencyModuleNames.AddRange(new string[] { });
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
}
}

View File

@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "SURREALISM.h"
#include "Modules/ModuleManager.h"
IMPLEMENT_PRIMARY_GAME_MODULE( FDefaultGameModuleImpl, SURREALISM, "SURREALISM" );

View File

@ -0,0 +1,6 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"

View File

@ -0,0 +1,9 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "utils_functions.h"
void utils_functions::debug_print(const char* str, float duration)
{
if (GEngine)GEngine->AddOnScreenDebugMessage(-1, duration, FColor::Red, FString(str));
}

View File

@ -0,0 +1,15 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
/**
*
*/
class SURREALISM_API utils_functions
{
public:
static void debug_print(const char*, float duration = 5.f);
};

View File

@ -0,0 +1,15 @@
// Fill out your copyright notice in the Description page of Project Settings.
using UnrealBuildTool;
using System.Collections.Generic;
public class SURREALISMEditorTarget : TargetRules
{
public SURREALISMEditorTarget(TargetInfo Target) : base(Target)
{
Type = TargetType.Editor;
DefaultBuildSettings = BuildSettingsVersion.V4;
ExtraModuleNames.AddRange( new string[] { "SURREALISM" } );
}
}