Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "Login.h"
- #include "Components/Button.h"
- #include "Components/WidgetSwitcher.h"
- #include "Components/EditableTextBox.h"
- #include "UserWidget.h"
- #include "Windows.h"
- bool ULogin::Initialize() {
- bool Sucess=Super::Initialize();
- if (!Sucess) return false;
- if (!ensure(Registerbutton != nullptr)) return false;
- Registerbutton->OnClicked;
- if (!ensure(Optionsbutton != nullptr)) return false;
- Optionsbutton->OnClicked.AddDynamic(this,&ULogin::HostServer);
- if (!ensure(Loginbutton != nullptr)) return false;
- Loginbutton->OnClicked.AddDynamic(this, &ULogin::Login);
- if (!ensure(Logout != nullptr)) return false;
- Logout->OnClicked.AddDynamic(this, &ULogin::BackLogin);
- if (!ensure(Apply != nullptr)) return false;
- Apply->OnClicked.AddDynamic(this, &ULogin::JoinServer);
- if (!ensure(QuitButton != nullptr)) return false;
- QuitButton->OnClicked.AddDynamic(this, &ULogin::QuitLogin);
- return true;
- }
- void ULogin::HostServer()
- {
- if (MenuInterface != nullptr)
- {
- MenuInterface->Host();
- }
- }
- void ULogin::JoinServer()
- {
- if (MenuInterface != nullptr) {
- if (!ensure(ip != nullptr)) return;
- const FString& Adress=ip->GetText().ToString();
- MenuInterface->Join(Adress);
- }
- }
- void ULogin::Login()
- {
- FString username = T_Username->GetText().ToString();
- FString password= T_PASSWORD->GetText().ToString();
- if (username.IsEmpty() & password.IsEmpty()) {
- MessageBoxA(NULL, "Username and Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (username.IsEmpty()) {
- MessageBoxA(NULL, "Username Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else if (password.IsEmpty()) {
- MessageBoxA(NULL, "Password Can´t be Empty", "Login", MB_OK | MB_SYSTEMMODAL);
- return;
- }
- else {
- GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
- GameSparks::Api::Requests::AuthenticationRequest authRequest(gs);
- authRequest.SetUserName(std::string(TCHAR_TO_UTF8(*username)));
- authRequest.SetPassword(std::string(TCHAR_TO_UTF8(*password)));
- //authRequest.Send(AuthenticationRequest_Response);
- authRequest.Send([this](GameSparks::Core::GS& gs, const GameSparks::Api::Responses::AuthenticationResponse& response) {
- AuthenticationRequest_Response(gs, response);
- if (!response.GetHasErrors()) {
- GameSparks::Core::GS& gs = UGameSparksModule::GetModulePtr()->GetGSInstance();
- GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, response.GetJSONString().c_str());
- GSRequestData scriptData;
- if (!ensure(MenuSwicther != nullptr)) return;
- if (!ensure(Server != nullptr)) return;
- MenuSwicther->SetActiveWidget(Server);
- //scriptData.AddString("email",std::string(TCHAR_TO_UTF8(*email)));
- //scriptData.AddString("level", "3");
- //Sucesso&;
- //GameSparks::Api::Requests::LogEventRequest forceMessage(gs);
- // forceMessage.SetEventKey("AAAAMessage");
- // forceMessage.Send();
- }
- else {
- GEngine->AddOnScreenDebugMessage(-1, 20.f, FColor::Red, TEXT("ERRO"));
- }
- });
- /* if (!ensure(MenuSwicther != nullptr)) return;
- if (!ensure(Server != nullptr)) return;
- MenuSwicther->SetActiveWidget(Server);
- */
- }
- }
- void ULogin::BackLogin()
- {
- if (!ensure(MenuSwicther != nullptr)) return;
- if (!ensure(LoginMain != nullptr)) return;
- MenuSwicther->SetActiveWidget(LoginMain);
- FText user;
- FText pass;
- T_Username->SetText(user);
- T_PASSWORD->SetText(pass);
- }
- void ULogin::QuitLogin()
- {
- UWorld* World = GetWorld();
- if (!ensure(World != nullptr)) return;
- APlayerController* PlayerController = World->GetFirstPlayerController();
- if (!ensure(PlayerController != nullptr)) return;
- PlayerController->ConsoleCommand("quit");
- }
- void ULogin::Sucesso()
- {
- if (!ensure(MenuSwicther != nullptr)) return;
- if (!ensure(Server != nullptr)) return;
- MenuSwicther->SetActiveWidget(Server);
- }
- void ULogin::AuthenticationRequest_Response(GameSparks::Core::GS&, const GameSparks::Api::Responses::AuthenticationResponse& response)
- {
- //Check is response has no errors
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement