Advertisement
Guest User

CPP

a guest
Apr 25th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.80 KB | None | 0 0
  1. // Fill out your copyright notice in the Description page of Project Settings.
  2.  
  3. #include "GSTut.h"
  4. #include "Runtime/UMG/Public/UMG.h"
  5. #include "Blueprint/UserWidget.h"
  6. #include "GameSparksStatics.h"
  7. #include "StateManager.h"
  8.  
  9. void UStateManager::Init()
  10. {
  11.     Super::Init();
  12.  
  13.     currentState = EGameState::ENone;
  14.  
  15.     currentWidget = nullptr;
  16. }
  17.  
  18. void UStateManager::ChangeState(EGameState newState)
  19. {
  20.     //if the desired state is not the current state
  21.     if (newState != currentState) {
  22.         LeaveState(currentState);
  23.         EnterState(newState);
  24.     }
  25. }
  26.  
  27. EGameState UStateManager::GetGameState()
  28. {
  29.     return currentState;
  30. }
  31.  
  32. void UStateManager::Login(FString username, FString password)
  33. {
  34.     //make sure our username and password aren't empty
  35.     if (username.IsEmpty() || password.IsEmpty()) {
  36.         return;
  37.     }
  38.  
  39.     //get instance of gamesparks
  40.     GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  41.  
  42.     //build our login request
  43.     GameSparks::Api::Requests::AuthenticationRequest req(gs);
  44.  
  45.     //set the username and password on our request
  46.     req.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
  47.     req.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
  48.  
  49.     //send the request
  50.     req.Send(UGameSparksStatics::LoginRequest_Response);
  51. }
  52.  
  53. void UStateManager::Register(FString username, FString password)
  54. {
  55.     //make sure our username and password aren't empty
  56.     if (username.IsEmpty() || password.IsEmpty()) {
  57.         return;
  58.     }
  59.  
  60.     //get instance of gamesparks
  61.     GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  62.  
  63.     //build our registration request
  64.     GameSparks::Api::Requests::RegistrationRequest req(gs);
  65.  
  66.     //set username, password and display name
  67.     req.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
  68.     req.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
  69.     req.SetDisplayName(std::string(TCHAR_TO_UTF8(*username)));
  70.  
  71.     //send the request
  72.     req.Send(UGameSparksStatics::RegistrationRequest_Response);
  73. }
  74.  
  75. void UStateManager::EnterState(EGameState newState)
  76. {
  77.     //set new state
  78.     currentState = newState;
  79.  
  80.     switch (currentState) {
  81.     case EGameState::EStartup: {
  82.         break;
  83.     }
  84.     case EGameState::ELoginScreen: {
  85.         currentWidget = CreateWidget<UUserWidget>(GetWorld()->GetFirstPlayerController(), cLoginMenu);
  86.         currentWidget->AddToViewport();
  87.  
  88.         //Change input mode to UI only and show mouse cursor
  89.         FInputModeUIOnly mode;
  90.         GetWorld()->GetFirstPlayerController()->SetInputMode(mode);
  91.         GetWorld()->GetFirstPlayerController()->bShowMouseCursor = true;
  92.  
  93.         break;
  94.     }
  95.     case EGameState::ENone: {
  96.         break;
  97.     }
  98.     }
  99. }
  100.  
  101. void UStateManager::LeaveState(EGameState oldState)
  102. {
  103.     switch (currentState) {
  104.     case EGameState::EStartup: {
  105.         break;
  106.     }
  107.     case EGameState::ELoginScreen: {
  108.         break;
  109.     }
  110.     case EGameState::ENone: {
  111.         break;
  112.     }
  113.     }
  114.  
  115.     EnterState(EGameState::ENone);
  116. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement