Adding Status and Last server response handled but not tested
This commit is contained in:
367
Source/DTFluxAPIStatus/Private/DTFluxStatusWidget.cpp
Normal file
367
Source/DTFluxAPIStatus/Private/DTFluxStatusWidget.cpp
Normal file
@ -0,0 +1,367 @@
|
||||
// Fill out your copyright notice in the Description page of Project Settings.
|
||||
|
||||
|
||||
#include "widgets/DTFluxStatusWidget.h"
|
||||
|
||||
#include "SlateOptMacros.h"
|
||||
#include "DTFluxAPIStatusModule.h"
|
||||
#include "EditorStyleSet.h"
|
||||
#include "ISettingsCategory.h"
|
||||
#include "ISettingsContainer.h"
|
||||
#include "ISettingsModule.h"
|
||||
#include "ISettingsSection.h"
|
||||
#include "Styling/SlateIconFinder.h"
|
||||
#include "Types/Enum/DTFluxCoreEnum.h"
|
||||
#include "Subsystems/DTFluxNetworkSubsystem.h"
|
||||
#include "Framework/MultiBox/MultiBoxBuilder.h"
|
||||
|
||||
|
||||
BEGIN_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
||||
|
||||
void SDTFluxStatusWidget::OnOpenSettingsClicked()
|
||||
{
|
||||
UE_LOG(logDTFluxStatus, Warning, TEXT("Settings Clicked !!!!"));
|
||||
ISettingsModule& SettingsModule = FModuleManager::LoadModuleChecked<ISettingsModule>("Settings");
|
||||
SettingsModule.ShowViewer("Project", "DTFluxProjectSettings", "DTFluxNetworkSettings");
|
||||
}
|
||||
|
||||
FReply SDTFluxStatusWidget::OnRaceDatasClicked()
|
||||
{
|
||||
DTFlux->SendRequest(EDTFluxRequestType::RaceData);
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
FReply SDTFluxStatusWidget::OnTeamListClicked()
|
||||
{
|
||||
DTFlux->SendRequest(EDTFluxRequestType::TeamList);
|
||||
return FReply::Handled();
|
||||
}
|
||||
|
||||
void SDTFluxStatusWidget::Construct(const FArguments& InArgs)
|
||||
{
|
||||
|
||||
DTFlux =
|
||||
GEngine->GetEngineSubsystem<UDTFluxNetworkSubsystem>();
|
||||
ConnectionActionButtonText.Set(
|
||||
DTFlux->WsStatus != EDTFluxConnectionStatus::Connected ?
|
||||
FText::FromString("Connect") :
|
||||
FText::FromString("Disconnect")
|
||||
);
|
||||
|
||||
bCanSupportFocus = true;
|
||||
|
||||
|
||||
|
||||
|
||||
FSlimHorizontalToolBarBuilder ToolBarBuilder(
|
||||
nullptr,
|
||||
FMultiBoxCustomization::None,
|
||||
nullptr,
|
||||
false
|
||||
);
|
||||
|
||||
ToolBarBuilder.BeginSection("Settings");
|
||||
{
|
||||
ToolBarBuilder.AddToolBarButton(
|
||||
FUIAction(FExecuteAction::CreateSP(this, &SDTFluxStatusWidget::OnOpenSettingsClicked)),
|
||||
NAME_None,
|
||||
INVTEXT("DTFlux Settings"),
|
||||
INVTEXT("Ouvrir les paramètres DTFlux"),
|
||||
FSlateIcon(FAppStyle::GetAppStyleSetName(), "Icons.Settings")
|
||||
);
|
||||
}
|
||||
ToolBarBuilder.EndSection();
|
||||
|
||||
|
||||
|
||||
FSlateFontInfo TitleTextFont = FCoreStyle::Get().GetFontStyle(FName("EmbossedText"));
|
||||
TitleTextFont.Size = 15;
|
||||
ChildSlot
|
||||
[
|
||||
#pragma region ToolBarSection
|
||||
SNew(SVerticalBox)
|
||||
+SVerticalBox::Slot()
|
||||
.AutoHeight()
|
||||
|
||||
[
|
||||
SNew(SBox)
|
||||
[
|
||||
SNew(SHorizontalBox)
|
||||
+SHorizontalBox::Slot()
|
||||
.FillWidth(2.0)
|
||||
[
|
||||
SNew(SSpacer)
|
||||
]
|
||||
+SHorizontalBox::Slot()
|
||||
.AutoWidth()
|
||||
.FillWidth(1.0)
|
||||
.VAlign(VAlign_Center)
|
||||
.HAlign(HAlign_Right)
|
||||
[
|
||||
ToolBarBuilder.MakeWidget()
|
||||
]
|
||||
]
|
||||
]
|
||||
#pragma endregion
|
||||
#pragma region WebsocketStatusSection
|
||||
// Main VerticalBox
|
||||
+SVerticalBox::Slot()
|
||||
.AutoHeight()
|
||||
[
|
||||
SNew(SBorder)
|
||||
.Padding(6.0f)
|
||||
[
|
||||
SNew(SHorizontalBox)
|
||||
+SHorizontalBox::Slot()
|
||||
.VAlign(VAlign_Center)
|
||||
.HAlign(HAlign_Center)
|
||||
.MaxWidth(175.0)
|
||||
.MinWidth(150.0)
|
||||
[
|
||||
SNew(STextBlock )
|
||||
.Text(FText::FromString(TEXT("Websocket connection :")))
|
||||
.Justification(ETextJustify::Left)
|
||||
]
|
||||
+SHorizontalBox::Slot()
|
||||
.VAlign(VAlign_Center)
|
||||
.MinWidth(50.0)
|
||||
.MaxWidth(100.0)
|
||||
[
|
||||
SAssignNew( WsStatusText, STextBlock)
|
||||
.Text(this, &SDTFluxStatusWidget::GetWebSocketStatusText)
|
||||
.Justification(ETextJustify::Left)
|
||||
.ColorAndOpacity(this, &SDTFluxStatusWidget::GetWebSocketStatusColor)
|
||||
]
|
||||
+SHorizontalBox::Slot()
|
||||
.MaxWidth(100.0)
|
||||
.MinWidth(30.0)
|
||||
[
|
||||
SAssignNew(ConnectionActionButton, SButton)
|
||||
.Text(this, &SDTFluxStatusWidget::GetWebConnectActionButtonText)
|
||||
.ForegroundColor_Raw(this, &SDTFluxStatusWidget::GetWebConnectActionButtonColor)
|
||||
.OnClicked(this,&SDTFluxStatusWidget::OnConnectionActionButtonClicked)
|
||||
.VAlign(VAlign_Center)
|
||||
.HAlign(HAlign_Center)
|
||||
.ContentPadding(1.5f)
|
||||
]
|
||||
]
|
||||
]
|
||||
#pragma endregion
|
||||
#pragma region DataModelControlSection
|
||||
+SVerticalBox::Slot()
|
||||
.VAlign(VAlign_Fill)
|
||||
.HAlign(HAlign_Fill)
|
||||
.AutoHeight()
|
||||
[
|
||||
SNew(SBox)
|
||||
[
|
||||
SNew(SHorizontalBox)
|
||||
+SHorizontalBox::Slot()
|
||||
[
|
||||
SNew(SButton)
|
||||
.Text(FText::FromString("Get RaceDatas"))
|
||||
.OnClicked(this, &SDTFluxStatusWidget::OnRaceDatasClicked)
|
||||
]
|
||||
+SHorizontalBox::Slot()
|
||||
[
|
||||
SNew(SButton)
|
||||
.Text(FText::FromString("Get TeamList"))
|
||||
.OnClicked(this, &SDTFluxStatusWidget::OnTeamListClicked)
|
||||
]
|
||||
]
|
||||
]
|
||||
#pragma endregion
|
||||
#pragma region HTTPStatusSection
|
||||
// +SVerticalBox::Slot()
|
||||
// .AutoHeight()
|
||||
// [
|
||||
// SNew(SHorizontalBox)
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(STextBlock)
|
||||
// .Text(FText::FromString(TEXT("HTTP connection :")))
|
||||
// .Justification(ETextJustify::Left)
|
||||
// ]
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(STextBlock)
|
||||
// .Text(FText::FromString(TEXT("invalid")))
|
||||
// .Justification(ETextJustify::Center)
|
||||
// .ColorAndOpacity(FColor::Red)
|
||||
// ]
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(SButton)
|
||||
// .Text(FText::FromString(TEXT("Connection test")))
|
||||
// ]
|
||||
// ]
|
||||
#pragma endregion
|
||||
#pragma region ContestsDataSection
|
||||
// +SVerticalBox::Slot()
|
||||
// .AutoHeight()
|
||||
// .VAlign(VAlign_Fill)
|
||||
// .HAlign(HAlign_Fill)
|
||||
// [
|
||||
// SNew(SBorder)
|
||||
// .Padding(1.5f)
|
||||
// .VAlign(VAlign_Fill)
|
||||
// .HAlign(HAlign_Fill)
|
||||
// [
|
||||
// SNew(STextBlock)
|
||||
// .Justification(ETextJustify::Left)
|
||||
// .Text(FText::FromString("Contest :"))
|
||||
// .ColorAndOpacity(FColor::White)
|
||||
// ]
|
||||
// ]
|
||||
// +SVerticalBox::Slot()
|
||||
// .AutoHeight()
|
||||
// .VAlign(VAlign_Center)
|
||||
// .HAlign(HAlign_Fill)
|
||||
// [
|
||||
// SNew(SBorder)
|
||||
// .Padding(1.0f)
|
||||
// .VAlign(VAlign_Center)
|
||||
// .HAlign(HAlign_Fill)
|
||||
// [
|
||||
// SNew(SDatastorageView, DTFlux)
|
||||
// ]
|
||||
// ]
|
||||
#pragma endregion
|
||||
#pragma region ParticipantsDataSection
|
||||
// +SVerticalBox::Slot()
|
||||
// .AutoHeight()
|
||||
// [
|
||||
// SNew(SHorizontalBox)
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(STextBlock)
|
||||
// .Text(FText::FromString(TEXT("Participants")))
|
||||
// .Justification(ETextJustify::Left)
|
||||
// ]
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(SButton)
|
||||
// .Text(FText::FromString(TEXT("Show")))
|
||||
// ]
|
||||
// ]
|
||||
#pragma endregion
|
||||
#pragma region EventsSection
|
||||
// +SVerticalBox::Slot()
|
||||
// .AutoHeight()
|
||||
// [
|
||||
// SNew(SHorizontalBox)
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(STextBlock)
|
||||
// .Text(FText::FromString(TEXT("Future Events")))
|
||||
// .Justification(ETextJustify::Left)
|
||||
// ]
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(SButton)
|
||||
// .Text(FText::FromString(TEXT("Show")))
|
||||
// ]
|
||||
// ]
|
||||
#pragma endregion
|
||||
#pragma region SequencesSection
|
||||
// +SVerticalBox::Slot()
|
||||
// .AutoHeight()
|
||||
// [
|
||||
// SNew(SHorizontalBox)
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(STextBlock)
|
||||
// .Text(FText::FromString(TEXT("Sequence On Air")))
|
||||
// .Justification(ETextJustify::Left)
|
||||
// ]
|
||||
// +SHorizontalBox::Slot()
|
||||
// [
|
||||
// SNew(SButton)
|
||||
// .Text(FText::FromString(TEXT("Show")))
|
||||
// ]
|
||||
// ]
|
||||
#pragma endregion
|
||||
|
||||
|
||||
];
|
||||
}
|
||||
|
||||
FText SDTFluxStatusWidget::GetWebSocketStatusText() const
|
||||
{
|
||||
|
||||
FString Status =
|
||||
UEnum::GetDisplayValueAsText(DTFlux->WsStatus).ToString();
|
||||
return
|
||||
FText::FromString(Status);
|
||||
// FText::FromString("Unknown");
|
||||
|
||||
}
|
||||
|
||||
FText SDTFluxStatusWidget::GetWebConnectActionButtonText() const
|
||||
{
|
||||
switch (DTFlux->WsStatus)
|
||||
{
|
||||
case EDTFluxConnectionStatus::Connected:
|
||||
return FText::FromString("Disconnect");
|
||||
default:
|
||||
return FText::FromString("Connect");
|
||||
}
|
||||
}
|
||||
|
||||
FReply SDTFluxStatusWidget::OnConnectionActionButtonClicked()
|
||||
{
|
||||
if(DTFlux)
|
||||
{
|
||||
switch (DTFlux->WsStatus)
|
||||
{
|
||||
case EDTFluxConnectionStatus::Connected:
|
||||
DTFlux->Reconnect();
|
||||
break;
|
||||
default:
|
||||
DTFlux->Connect();
|
||||
break;
|
||||
}
|
||||
}
|
||||
return FReply::Handled();
|
||||
}
|
||||
FSlateColor SDTFluxStatusWidget::GetWebSocketStatusColor() const
|
||||
{
|
||||
FColor Color;
|
||||
switch (DTFlux->WsStatus)
|
||||
{
|
||||
case EDTFluxConnectionStatus::Unset:
|
||||
Color = FColor::Orange;
|
||||
break;
|
||||
case EDTFluxConnectionStatus::Connected:
|
||||
Color = FColor::Green;
|
||||
break;
|
||||
case EDTFluxConnectionStatus::NotConnected:
|
||||
Color = FColor::Orange;
|
||||
break;
|
||||
case EDTFluxConnectionStatus::Closed:
|
||||
Color = FColor::Magenta;
|
||||
break;
|
||||
default:
|
||||
Color = FColor::Red;
|
||||
break;
|
||||
}
|
||||
return FSlateColor(Color);
|
||||
}
|
||||
|
||||
FSlateColor SDTFluxStatusWidget::GetWebConnectActionButtonColor() const
|
||||
{
|
||||
FColor Color= FColor::Green;
|
||||
switch (DTFlux->WsStatus)
|
||||
{
|
||||
case EDTFluxConnectionStatus::Connected:
|
||||
Color = FColor::Red;
|
||||
break;
|
||||
default:
|
||||
Color = FColor::Green;
|
||||
break;
|
||||
}
|
||||
return FSlateColor(Color);
|
||||
}
|
||||
|
||||
|
||||
END_SLATE_FUNCTION_BUILD_OPTIMIZATION
|
||||
Reference in New Issue
Block a user