Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .h
- #include "CoreMinimal.h"
- #include "Blueprint/UserWidget.h"
- #include "UW_SwitcherPanel.generated.h"
- class UCanvasPanel;
- class UWidgetSwitcher;
- class UVerticalBox;
- class UHorizontalBox;
- class UButton;
- class UW_NavigationPanel;
- class UW_SwitcherPanel;
- /**
- *
- */
- UCLASS()
- class SPORT_API UUW_SwitcherPanel : public UUserWidget
- {
- GENERATED_BODY()
- public:
- /* Constructor */
- protected:
- virtual void NativeConstruct() override;
- /* Design Layout of the right hand menu panel (in game) for users to interact with */
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UCanvasPanel> Switcher_CanvasPanel;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UWidgetSwitcher> Switcher_WidgetSwitcher;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UVerticalBox> Switcher_VerticalBox;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UHorizontalBox> Switcher_HorizontalBox1;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UHorizontalBox> Switcher_HorizontalBox2;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UButton> BtnNavigation;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UButton> BtnCrew;
- UPROPERTY(meta = (BindWidget))
- TObjectPtr<UButton> BtnShipDetails;
- private:
- int32 SwitcherIndex = 0;
- /* Button Navigation */
- UFUNCTION()
- void BtnNavigationPressed();
- /* Button Crew */
- UFUNCTION()
- void BtnCrewPressed();
- /* Button Ship Details */
- UFUNCTION()
- void BtnShipDetailsPressed();
- /* Update the switcher panel */
- void UpdateSwitcherPanel(int32 Index);
- };
- ----------------------------------------------------------------------------------------------------
- .cpp
- #include "UI/UW_SwitcherPanel.h"
- #include "Components/CanvasPanel.h"
- #include "Components/WidgetSwitcher.h"
- #include "Components/VerticalBox.h"
- #include "Components/HorizontalBox.h"
- #include "Components/Button.h"
- #include "UI/UW_NavigationPanel.h"
- //Native Constructor
- void UUW_SwitcherPanel::NativeConstruct()
- {
- BtnNavigation->OnClicked.AddDynamic(this, &UUW_SwitcherPanel::BtnNavigationPressed);
- BtnCrew->OnClicked.AddDynamic(this, &UUW_SwitcherPanel::BtnCrewPressed);
- BtnShipDetails->OnClicked.AddDynamic(this, &UUW_SwitcherPanel::BtnShipDetailsPressed);
- }
- //Navigation Button
- void UUW_SwitcherPanel::BtnNavigationPressed()
- {
- //check isCurrentWidget?
- SwitcherIndex = 0;
- UpdateSwitcherPanel(SwitcherIndex);
- }
- //Crew Button
- void UUW_SwitcherPanel::BtnCrewPressed()
- {
- SwitcherIndex = 1;
- UpdateSwitcherPanel(SwitcherIndex);
- }
- //Ship Details
- void UUW_SwitcherPanel::BtnShipDetailsPressed()
- {
- SwitcherIndex = 2;
- UpdateSwitcherPanel(SwitcherIndex);
- }
- //Update Switcher Panel
- void UUW_SwitcherPanel::UpdateSwitcherPanel(int32 Index)
- {
- UE_LOG(LogTemp, Warning, TEXT("UpdateSwitcherPanel Index %d"), Index);
- if (Switcher_WidgetSwitcher != nullptr)
- {
- int32 CurrentIndexPoint;
- CurrentIndexPoint = Switcher_WidgetSwitcher->GetActiveWidgetIndex();
- if (CurrentIndexPoint != Index)
- {
- Switcher_WidgetSwitcher->SetActiveWidgetIndex(Index);
- }
- }
- else
- {
- UE_LOG(LogTemp, Warning, TEXT("Not instantiated"));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement