Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Fill out your copyright notice in the Description page of Project Settings.
- #include "GSTut.h"
- #include "Runtime/UMG/Public/UMG.h"
- #include "Blueprint/UserWidget.h"
- #include "GameSparksStatics.h"
- #include "StateManager.h"
- void UStateManager::Init()
- {
- Super::Init();
- currentState = EGameState::ENone;
- currentWidget = nullptr;
- }
- void UStateManager::ChangeState(EGameState newState)
- {
- //if the desired state is not the current state
- if (newState != currentState) {
- LeaveState(currentState);
- EnterState(newState);
- }
- }
- EGameState UStateManager::GetGameState()
- {
- return currentState;
- }
- void UStateManager::Login(FString username, FString password)
- {
- //make sure our username and password aren't empty
- if (username.IsEmpty() || password.IsEmpty()) {
- return;
- }
- //get instance of gamesparks
- GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
- //build our login request
- GameSparks::Api::Requests::AuthenticationRequest req(gs);
- //set the username and password on our request
- req.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
- req.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
- //send the request
- req.Send(UGameSparksStatics::LoginRequest_Response);
- }
- void UStateManager::Register(FString username, FString password)
- {
- //make sure our username and password aren't empty
- if (username.IsEmpty() || password.IsEmpty()) {
- return;
- }
- //get instance of gamesparks
- GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
- //build our registration request
- GameSparks::Api::Requests::RegistrationRequest req(gs);
- //set username, password and display name
- req.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
- req.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
- req.SetDisplayName(std::string(TCHAR_TO_UTF8(*username)));
- //send the request
- req.Send(UGameSparksStatics::RegistrationRequest_Response);
- }
- void UStateManager::EnterState(EGameState newState)
- {
- //set new state
- currentState = newState;
- switch (currentState) {
- case EGameState::EStartup: {
- break;
- }
- case EGameState::ELoginScreen: {
- currentWidget = CreateWidget<UUserWidget>(GetWorld()->GetFirstPlayerController(), cLoginMenu);
- currentWidget->AddToViewport();
- //Change input mode to UI only and show mouse cursor
- FInputModeUIOnly mode;
- GetWorld()->GetFirstPlayerController()->SetInputMode(mode);
- GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
- break;
- }
- case EGameState::ENone: {
- break;
- }
- }
- }
- void UStateManager::LeaveState(EGameState oldState)
- {
- switch (currentState) {
- case EGameState::EStartup: {
- break;
- }
- case EGameState::ELoginScreen: {
- break;
- }
- case EGameState::ENone: {
- break;
- }
- }
- EnterState(EGameState::ENone);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement