You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
64 lines
1.9 KiB
64 lines
1.9 KiB
2 years ago
|
// Fill out your copyright notice in the Description page of Project Settings.
|
||
|
|
||
|
#include "Components/Button.h"
|
||
|
#include "Components/TextBlock.h"
|
||
|
#include "BattleUI.h"
|
||
|
#include "BattlePlayerController.h"
|
||
|
#include "BattlePlayerState.h"
|
||
|
|
||
|
|
||
|
void UBattleUI::NativeConstruct() {
|
||
|
Super::NativeConstruct();
|
||
|
EndTurnButton->OnClicked.AddDynamic(this, &ThisClass::OnEndTurnClicked);
|
||
|
ButtonAction_0->OnClicked.AddDynamic(this, &ThisClass::OnActionSwitched_0);
|
||
|
ButtonAction_1->OnClicked.AddDynamic(this, &ThisClass::OnActionSwitched_1);
|
||
|
ButtonAction_2->OnClicked.AddDynamic(this, &ThisClass::OnActionSwitched_2);
|
||
|
}
|
||
|
|
||
|
void UBattleUI::SetWidgetText_Implementation(const FString &Text) {
|
||
|
InformationText->SetText(FText::FromString(Text));
|
||
|
}
|
||
|
|
||
|
void UBattleUI::SetWhoseTurnText_Implementation(bool IsThisPlayerTurn) {
|
||
|
if (IsThisPlayerTurn) {
|
||
|
SetWidgetText(TEXT("Your turn!"));
|
||
|
} else {
|
||
|
SetWidgetText(TEXT("Opponent's turn"));
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void UBattleUI::OnEndTurnClicked() {
|
||
|
Cast<ABattlePlayerController>(GetWorld()->GetFirstPlayerController())->
|
||
|
EndTurn();
|
||
|
}
|
||
|
|
||
|
void UBattleUI::OnActionSwitched_0() {
|
||
|
ButtonAction_0->SetIsEnabled(false);
|
||
|
ButtonAction_1->SetIsEnabled(true);
|
||
|
ButtonAction_2->SetIsEnabled(true);
|
||
|
ActionType = 0;
|
||
|
OnActionSwitched();
|
||
|
}
|
||
|
|
||
|
void UBattleUI::OnActionSwitched_1() {
|
||
|
ButtonAction_0->SetIsEnabled(true);
|
||
|
ButtonAction_1->SetIsEnabled(false);
|
||
|
ButtonAction_2->SetIsEnabled(true);
|
||
|
ActionType = 1;
|
||
|
OnActionSwitched();
|
||
|
}
|
||
|
|
||
|
void UBattleUI::OnActionSwitched_2() {
|
||
|
ButtonAction_0->SetIsEnabled(true);
|
||
|
ButtonAction_1->SetIsEnabled(true);
|
||
|
ButtonAction_2->SetIsEnabled(false);
|
||
|
ActionType = 2;
|
||
|
OnActionSwitched();
|
||
|
}
|
||
|
|
||
|
void UBattleUI::OnActionSwitched() const {
|
||
|
Cast<ABattlePlayerController>(GetWorld()->GetFirstPlayerController())->
|
||
|
GetPlayerState<ABattlePlayerState>()->SetCurrentAction(ActionType);
|
||
|
}
|
||
|
|