#pragma region CPL License /* Nuclex Unreal Module Copyright (C) 2014-2021 Nuclex Development Labs This library is free software; you can redistribute it and/or modify it under the terms of the IBM Common Public License as published by the IBM Corporation; either version 1.0 of the License, or (at your option) any later version. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the IBM Common Public License for more details. You should have received a copy of the IBM Common Public License along with this library */ #pragma endregion // CPL License #include "VisualNovel/VisualNovelPlayerController.h" #include "InterfaceCast.h" // --------------------------------------------------------------------------------------------- // AVisualNovelPlayerController::AVisualNovelPlayerController() : defaultDialogInputActionsBound(false), dialogForWhichParagraphWasChecked(nullptr) {} // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::InjectAcceptChoice(int choiceIndex) { if(this->EnableDialogInput) { UObject *dialogPointer = this->ActiveDialog.GetObject(); if(dialogPointer != nullptr) { if(this->dialogForWhichParagraphWasChecked != dialogPointer) { this->activeParagraph = interface_cast(this->ActiveDialog); this->dialogForWhichParagraphWasChecked = dialogPointer; } if(this->activeParagraph.GetObject() != nullptr) { IButtonControllableParagraph::Execute_AcceptChoice( this->activeParagraph.GetObject(), choiceIndex ); } } } } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::InjectSkip() { if(this->EnableDialogInput) { UObject *dialogPointer = this->ActiveDialog.GetObject(); if(dialogPointer != nullptr) { if(this->dialogForWhichParagraphWasChecked != dialogPointer) { this->activeParagraph = interface_cast(this->ActiveDialog); this->dialogForWhichParagraphWasChecked = dialogPointer; } if(this->activeParagraph.GetObject() != nullptr) { IButtonControllableParagraph::Execute_Skip(this->activeParagraph.GetObject()); } } } } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::BindToDefaultInputActions_Implementation() { Super::BindToDefaultInputActions_Implementation(); if(!this->defaultDialogInputActionsBound) { UInputComponent &inputComponent = *this->InputComponent; // Tell Unreal's "input component" to notify us when certain input actions are activated inputComponent.BindAction( TEXT("Choice1"), IE_Pressed, this, &AVisualNovelPlayerController::firstChoiceAccepted ); inputComponent.BindAction( TEXT("Choice2"), IE_Pressed, this, &AVisualNovelPlayerController::secondChoiceAccepted ); inputComponent.BindAction( TEXT("Choice3"), IE_Pressed, this, &AVisualNovelPlayerController::thirdChoiceAccepted ); inputComponent.BindAction( TEXT("Choice4"), IE_Pressed, this, &AVisualNovelPlayerController::fourthChoiceAccepted ); inputComponent.BindAction( TEXT("Choice5"), IE_Pressed, this, &AVisualNovelPlayerController::fifthChoiceAccepted ); inputComponent.BindAction( TEXT("Skip"), IE_Pressed, this, &AVisualNovelPlayerController::InjectSkip ); this->defaultDialogInputActionsBound = true; } } // --------------------------------------------------------------------------------------------- // const TScriptInterface< IButtonControllableParagraph > AVisualNovelPlayerController::GetActiveParagraph_Implementation() { UObject *dialogPointer = this->ActiveDialog.GetObject(); if(dialogPointer != nullptr) { if(this->dialogForWhichParagraphWasChecked != dialogPointer) { this->activeParagraph = interface_cast(this->ActiveDialog); this->dialogForWhichParagraphWasChecked = dialogPointer; } return this->activeParagraph; } else { return TScriptInterface(); } } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::BeginParagraphInput_Implementation( const TScriptInterface &targetParagraph ) { this->activeParagraph = targetParagraph; this->dialogForWhichParagraphWasChecked = this->ActiveDialog.GetObject(); Super::BeginDialogInput_Implementation( interface_cast(targetParagraph) ); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::EndParagraphInput_Implementation() { this->activeParagraph = nullptr; this->dialogForWhichParagraphWasChecked = nullptr; Super::EndDialogInput_Implementation(); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::BeginDialogInput_Implementation( const TScriptInterface &targetDialog ) { UObject *dialogPointer = targetDialog.GetObject(); if(dialogPointer != nullptr) { if(this->dialogForWhichParagraphWasChecked != dialogPointer) { this->activeParagraph = interface_cast(targetDialog); this->dialogForWhichParagraphWasChecked = dialogPointer; } } Super::BeginDialogInput_Implementation(targetDialog); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::EndDialogInput_Implementation() { this->activeParagraph = nullptr; this->dialogForWhichParagraphWasChecked = nullptr; Super::EndDialogInput_Implementation(); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::firstChoiceAccepted() { InjectAcceptChoice(0); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::secondChoiceAccepted() { InjectAcceptChoice(1); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::thirdChoiceAccepted() { InjectAcceptChoice(2); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::fourthChoiceAccepted() { InjectAcceptChoice(3); } // --------------------------------------------------------------------------------------------- // void AVisualNovelPlayerController::fifthChoiceAccepted() { InjectAcceptChoice(4); } // --------------------------------------------------------------------------------------------- //