Example #1
0
void AAvatar::ToggleInventory()
{
	APlayerController* PController = GetWorld()->GetFirstPlayerController();
	AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() );
	
	// If inventory is displayed, undisplay it.
	if( inventoryShowing )
	{
		hud->clearWidgets();
		inventoryShowing = false;
		PController->bShowMouseCursor = false;
		return;
	}

	// Otherwise, display the player's inventory
	inventoryShowing = true;
	PController->bShowMouseCursor = true;
	for( TMap<FString,int>::TIterator it = Backpack.CreateIterator(); it; ++it )
	{
		// Combine string name of the item, with qty eg Cow x 5
		FString fs = it->Key + FString::Printf( TEXT(" x %d"), it->Value );
		UTexture2D* tex = NULL;
		if( Icons.Find( it->Key ) )
		{
			tex = Icons[it->Key];
			Widget w( Icon( fs, tex ), Classes[it->Key] );
			w.bpSpell = Spells[it->Key];
			hud->addWidget( w );
		}
	}
}
Example #2
0
void APickUpItem::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32
	OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	// if the overlapped actor is NOT the player,
	// you simply should return
	if (Cast<AActor>(OtherActor) == nullptr)
	{
		return;
	}
	// Get a reference to the player avatar, to give him
	// the item
	AAvatar *avatar = Cast<AAvatar>(UGameplayStatics::GetPlayerPawn(
		GetWorld(), 0));
	// Let the player pick up item
	// Notice use of keyword this!
	// That is how _this_ Pickup can refer to itself.
	avatar->Pickup(this);
	
	if (CoinSound != NULL)
	{
		UGameplayStatics::PlaySoundAtLocation(this, CoinSound, GetActorLocation());
	}
	// Get a reference to the controller
	APlayerController* PController = GetWorld() ->GetFirstPlayerController();
	// Get a reference to the HUD from the controller
	AMyHUD* hud = Cast<AMyHUD>(PController->GetHUD());
	hud->addMessage(Message(Icon, FString("Picked up ") + FString(" ") + Name + FString(" ")+FString::FromInt(Quantity), 2.0f, FColor::Black, FColor::Black));
	Destroy();

	
}
void FBehaviorTreeDebugger::FindLockedDebugActor(UWorld* World)
{
	APlayerController* LocalPC = GEngine->GetFirstLocalPlayerController(World);
	if (LocalPC && LocalPC->GetHUD() && LocalPC->GetPawnOrSpectator())
	{
		AGameplayDebuggingReplicator* DebuggingReplicator = NULL;
		for (TActorIterator<AGameplayDebuggingReplicator> It(World); It; ++It)
		{
			AGameplayDebuggingReplicator* A = *It;
			if (!A->IsPendingKill())
			{
				DebuggingReplicator = A;
				break;
			}
		}

		const APawn* LockedPawn = DebuggingReplicator != NULL ? Cast<APawn>(DebuggingReplicator->GetSelectedActorToDebug()) : NULL;
		UBehaviorTreeComponent* TestInstance = FindInstanceInActor((APawn*)LockedPawn);
		if (TestInstance)
		{
			TreeInstance = TestInstance;

#if USE_BEHAVIORTREE_DEBUGGER
			ActiveStepIndex = TestInstance->DebuggerSteps.Num() - 1;
#endif
		}
	}
}
Example #4
0
void AAvatar::MouseRightClicked()
{
	if( inventoryShowing )
	{
		APlayerController* PController = GetWorld()->GetFirstPlayerController();
		AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() );
		hud->MouseRightClicked();
	}
}
Example #5
0
void ALearningCPPNPC::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComponent, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
	if (Cast<ALearningCPPCharacter>(OtherActor) == nullptr) return;

	APlayerController* PlayerController = GetWorld()->GetFirstPlayerController();
	if (PlayerController)
	{
		ALearningCPPHUD* Hud = Cast<ALearningCPPHUD>(PlayerController->GetHUD());
		Hud->AddMessage(FMessage(NpcName + ": " + NpcMessage, 3.0f, FColor::White, Texture));
	}
}
Example #6
0
void APawnWithCamera::LMB_Out()
{
	APlayerController* MyController = GetWorld()->GetFirstPlayerController();
	AMyHUD *Hudref = Cast<AMyHUD>(MyController->GetHUD());
	FVector WorldMousePos = Hudref->GetMOuseWorldPosition();

	FVector Start = GetActorLocation();

	DistanceWithToPoints = FVector::Dist(Start, WorldMousePos);

	//DrawDebugSphere(GetWorld(), WorldMousePos, 16.f, 8, FColor(83, 155, 83, 255), false, 0.15f);
	DrawDebugLine(GetWorld(), Start, WorldMousePos, FColor(255, 0, 0), true, 0.5f, 0, 5.0f);
}
Example #7
0
void ANPCDialogue::Prox_Implementation(AActor* otherActor, UPrimitiveComponent* 
	otherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
	if (Cast<AFPSHorrorCharacter>(otherActor) == nullptr)
	{
		return;
	}
	APlayerController* PController = GetWorld()->GetFirstPlayerController();
	if (PController)
	{
		AMyHUD* hud = Cast<AMyHUD>(PController->GetHUD());
		hud->addMessage(FMessage(NPCmessage, 5.0f, FColor::White));
	}
}
Example #8
0
void AAvatar::Pitch( float amount )
{
	//y
	if( inventoryShowing )
	{
		// if the button is down click drag
		APlayerController* PController = GetWorld()->GetFirstPlayerController();
		AMyHUD* hud = Cast<AMyHUD>( PController->GetHUD() );
		hud->MouseMoved();
	}
	//else
	{
		AddControllerPitchInput(200.f*amount * GetWorld()->GetDeltaSeconds());
	}
}
Example #9
0
void ANPC::Prox_Implementation(AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
  if (Cast<AAvatar>(OtherActor) == nullptr) { return; }
  
  APlayerController* PController = GetWorld()->GetFirstPlayerController();
  
  if (PController)
  {
    ANPC_HUD* hud = Cast<ANPC_HUD>(PController->GetHUD());
    FString NameAndMessage = FString::Printf(TEXT("%s: %s"), *Name, *NPCMessage);
    hud->AddMessage(Message(NameAndMessage, 5.f, FColor::White, Face));
    hp->is_visible = true;
    hud->AddHpBar(hp);
  }
}
Example #10
0
// Called every frame
void UHealthBar::TickComponent(float DeltaTime, ELevelTick TickType, FActorComponentTickFunction* ThisTickFunction) {
	Super::TickComponent(DeltaTime, TickType, ThisTickFunction);

	if (health == -1) {
		APlayerController* PC = UGameplayStatics::GetPlayerController(this, 0);
		if (PC) {
			ACCHUD* hud = Cast<ACCHUD>(PC->GetHUD());
			if (hud) {
				hud->RegisterHealthbar(this);
				health = maxHealth;
			}
		}
	} else {
		//health -= 0.01;
	}
}
void ANotePickup::OnDrop_Implementation()
{
	Super::OnDrop_Implementation();
	APlayerController* c = GetWorld()->GetFirstPlayerController();
	if (c)
	{
		ACharacterHUD* h = Cast<ACharacterHUD>(c->GetHUD());
		if (h)
		{
			h->DrawNoteString = false;
			h->DrawNoteImage = false;
			h->NoteString = "";
			Fade = -1.0;
		}
	}
}
void ANotePickup::Tick(float DeltaTime)
{
	if (Fade != 0)
	{
		APlayerController* c = GetWorld()->GetFirstPlayerController();
		if (c)
		{
			ACharacterHUD* h = Cast<ACharacterHUD>(c->GetHUD());
			if (h)
			{
				h->BlackBackgroundAlpha = FMath::Clamp(h->BlackBackgroundAlpha + (200 * DeltaTime * Fade), 0.0f, 150.0f);

				if (h->BlackBackgroundAlpha == 0.0f || h->BlackBackgroundAlpha == 150)
					Fade = 0;
			}
		}
	}
}
void ASCharacter::ConsumeFood(float AmountRestored)
{
	// Reduce Hunger, ensure we do not go outside of our bounds
	Hunger = FMath::Clamp(Hunger - AmountRestored, 0.0f, GetMaxHunger());

	// Restore Hitpoints
	Health = FMath::Clamp(Health + AmountRestored, 0.0f, GetMaxHealth());

	APlayerController* PC = Cast<APlayerController>(Controller);
	if (PC)
	{
		ASHUD* MyHUD = Cast<ASHUD>(PC->GetHUD());
		if (MyHUD)
		{
			MyHUD->MessageReceived("Food consumed!");
		}
	}
}
void ANotePickup::Read()
{
	APlayerController* c = GetWorld()->GetFirstPlayerController();
	if (c)
	{
		ACharacterHUD* h = Cast<ACharacterHUD>(c->GetHUD());
		if (h)
		{
			h->DrawNoteString = !h->DrawNoteString;
			h->DrawSafeString = false;
			h->NoteString = Notes[NoteIndex];
			h->NoteImage = NoteImage;
			h->DrawNoteImage = !h->DrawNoteImage;

			if (h->DrawNoteString)
				Fade = 1.0;
			else
				Fade = -1.0;
		}
	}
}
Example #15
0
PyObject *py_ue_get_player_hud(ue_PyUObject *self, PyObject * args)
{

	ue_py_check(self);

	int controller_id = 0;
	if (!PyArg_ParseTuple(args, "|i:get_player_hud", &controller_id))
	{
		return NULL;
	}

	UWorld *world = ue_get_uworld(self);
	if (!world)
		return PyErr_Format(PyExc_Exception, "unable to retrieve UWorld from uobject");

	APlayerController *controller = UGameplayStatics::GetPlayerController(world, controller_id);
	if (!controller)
		return PyErr_Format(PyExc_Exception, "unable to retrieve controller %d", controller_id);

	Py_RETURN_UOBJECT(controller->GetHUD());
}
void ASafeInteract::Tick(float DeltaTime)
{
	APlayerController* c = GetWorld()->GetFirstPlayerController();
	if (!c) return;

	ACharacterHUD* h = Cast<ACharacterHUD>(c->GetHUD());
	if (!h) return;

	if (EnteringCombination)
	{
		if ((this->GetActorLocation() - CharacterReference->GetActorLocation()).Size() > 400.0f)
		{
			EnteringCombination = false;
			Fade = -1.0;
		}

		h->DrawSafeString = true;
		FString string = TestCombination;

		if (CombinationLength < COMBINATION_LENGTH)
		{
			string += "_";
			for (int i = 0; i < (COMBINATION_LENGTH - CombinationLength) - 1; i++)
			{
				string += " ";
			}
		}
		h->SafeString = string;

		if (CheckInput())
		{
			UAudioComponent* SpeakerAudio = SafeSpeaker->GetAudioComponent();
			UAudioComponent* SpeakerAudio2 = SafeUnlockSpeaker->GetAudioComponent();

			if (EnterCombination())
			{
				EnteringCombination = false;
				h->DrawSafeString = false;
				h->SafeString = "";

				SpeakerAudio2->Play();
				IsLocked = false;
				UnlockSafe();
				Fade = -1.0;
			}
			else
			{
				if (!SpeakerAudio->IsPlaying())
					SpeakerAudio->Play();
			}
		}
	}
	else
	{
		h->DrawSafeString = false;
		h->SafeString = "";
	}

	if (Fade != 0)
	{
		h->BlackBackgroundAlpha = FMath::Clamp(h->BlackBackgroundAlpha + (200 * DeltaTime * Fade), 0.0f, 150.0f);

		if (h->BlackBackgroundAlpha == 0.0f || h->BlackBackgroundAlpha == 150)
			Fade = 0;
	}
}