Advertisement
Guest User

Untitled

a guest
Dec 5th, 2017
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. #include "Login.h"
  2. #include "Components/Button.h"
  3. #include "Components/WidgetSwitcher.h"
  4. #include "Components/EditableTextBox.h"
  5. #include "UserWidget.h"
  6. #include "Windows.h"
  7.  
  8.  
  9.  
  10.  
  11. bool ULogin::Initialize() {
  12.  
  13. bool Sucess=Super::Initialize();
  14. if (!Sucess) return false;
  15. if (!ensure(Registerbutton != nullptr)) return false;
  16. Registerbutton->OnClicked;
  17. if (!ensure(Optionsbutton != nullptr)) return false;
  18. Optionsbutton->OnClicked.AddDynamic(this,&ULogin::HostServer);
  19. if (!ensure(Loginbutton != nullptr)) return false;
  20. Loginbutton->OnClicked.AddDynamic(this, &ULogin::Login);
  21. if (!ensure(Logout != nullptr)) return false;
  22. Logout->OnClicked.AddDynamic(this, &ULogin::BackLogin);
  23. if (!ensure(Apply != nullptr)) return false;
  24. Apply->OnClicked.AddDynamic(this, &ULogin::JoinServer);
  25. if (!ensure(QuitButton != nullptr)) return false;
  26. QuitButton->OnClicked.AddDynamic(this, &ULogin::QuitLogin);
  27.  
  28. return true;
  29. }
  30.  
  31. void ULogin::HostServer()
  32. {
  33. if (MenuInterface != nullptr)
  34. {
  35.  
  36. MenuInterface->Host();
  37.  
  38. }
  39. }
  40.  
  41. void ULogin::JoinServer()
  42. {
  43. if (MenuInterface != nullptr) {
  44. if (!ensure(ip != nullptr)) return;
  45. const FString& Adress=ip->GetText().ToString();
  46. MenuInterface->Join(Adress);
  47. }
  48. }
  49.  
  50.  
  51.  
  52. void ULogin::Login()
  53. {
  54.  
  55. FString username = T_Username->GetText().ToString();
  56. FString password= T_PASSWORD->GetText().ToString();
  57.  
  58. if (username.IsEmpty() & password.IsEmpty()) {
  59. MessageBoxA(NULL, "Username and Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  60. return;
  61. }
  62. else if (username.IsEmpty()) {
  63. MessageBoxA(NULL, "Username Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  64. return;
  65. }
  66. else if (password.IsEmpty()) {
  67. MessageBoxA(NULL, "Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
  68. return;
  69. }
  70. else {
  71. GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  72. GameSparks::Api::Requests::AuthenticationRequest authRequest(gs);
  73. authRequest.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
  74. authRequest.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
  75. //authRequest.Send(AuthenticationRequest_Response);
  76. authRequest.Send([this](GameSparks::Core::GS& gs, const GameSparks::Api::Responses::AuthenticationResponse& response) {
  77. AuthenticationRequest_Response(gs, response);
  78. if (!response.GetHasErrors()) {
  79. GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
  80. GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, response.GetJSONString().c_str());
  81.  
  82.  
  83. GSRequestData scriptData;
  84.  
  85. if (!ensure(MenuSwicther != nullptr)) return;
  86. if (!ensure(Server != nullptr)) return;
  87. MenuSwicther->SetActiveWidget(Server);
  88.  
  89. //scriptData.AddString("email",std::string(TCHAR_TO_UTF8(*email)));
  90. //scriptData.AddString("level", "3");
  91. //Sucesso&;
  92. //GameSparks::Api::Requests::LogEventRequest forceMessage(gs);
  93.  
  94. // forceMessage.SetEventKey("AAAAMessage");
  95. // forceMessage.Send();
  96. }
  97. else {
  98. GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, TEXT("ERRO"));
  99. }
  100. });
  101. /* if (!ensure(MenuSwicther != nullptr)) return;
  102. if (!ensure(Server != nullptr)) return;
  103. MenuSwicther->SetActiveWidget(Server);
  104. */
  105.  
  106.  
  107. }
  108.  
  109.  
  110. }
  111.  
  112. void ULogin::BackLogin()
  113. {
  114. if (!ensure(MenuSwicther != nullptr)) return;
  115. if (!ensure(LoginMain != nullptr)) return;
  116. MenuSwicther->SetActiveWidget(LoginMain);
  117. FText user;
  118. FText pass;
  119. T_Username->SetText(user);
  120. T_PASSWORD->SetText(pass);
  121. }
  122.  
  123. void ULogin::QuitLogin()
  124. {
  125. UWorld* World = GetWorld();
  126. if (!ensure(World != nullptr)) return;
  127. APlayerController* PlayerController = World->GetFirstPlayerController();
  128. if (!ensure(PlayerController != nullptr)) return;
  129. PlayerController->ConsoleCommand("quit");
  130. }
  131.  
  132. void ULogin::Sucesso()
  133. {
  134. if (!ensure(MenuSwicther != nullptr)) return;
  135. if (!ensure(Server != nullptr)) return;
  136. MenuSwicther->SetActiveWidget(Server);
  137. }
  138.  
  139. void ULogin::AuthenticationRequest_Response(GameSparks::Core::GS&, const GameSparks::Api::Responses::AuthenticationResponse& response)
  140. {
  141.  
  142. //Check is response has no errors
  143.  
  144.  
  145. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement