Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class FContentBrush;
- class FButton;
- class FMenu;
- class FMenuState;
- struct FIntRect
- {
- uint32 X;
- uint32 Y;
- uint32 SizeX;
- uint32 SizeY;
- };
- class FContentBrush
- {
- public:
- FTexture2D *Sprite;
- FColor32 OutlineColor;
- FColor32 ColorAndOpacity;
- public:
- FContentBrush(const FColor32 &ColorAndOpacity);
- FContentBrush(const FColor32 &ColorAndOpacity, const FColor32 &OutlineColor);
- FContentBrush(const FColor32 &ColorAndOpacity, const FColor32 &OutlineColor, const FTexture2D *InSprite);
- FContentBrush(const FColor32 &ColorAndOpacity, const FTexture2D *InSprite);
- };
- class FButton
- {
- public:
- FMenu *OwnerMenu;
- FIntRect Position;
- FContentBrush DisabledBrush;
- FContentBrush EnabledBrush;
- FContentBrush HoveredBrush;
- FContentBrush ClickedBrush;
- public:
- virtual void OnInitialize();
- virtual void OnRelease();
- virtual void OnUpdate();
- virtual void OnHover();
- virtual void OnClick();
- virtual void OnRelease();
- virtual void Draw(); // Render Self.
- };
- class FMenu
- {
- public:
- FMenuState *OwnerMenuState;
- TArray<FButton *> MenuButtons;
- public:
- void AddButton(FButton *InButton)
- {
- MenuButtons.Add(InButton);
- InButton->OwnerMenu = this;
- }
- void RemoveButton(FButton *InButton)
- {
- MenuButtons.Remove(InButton);
- InButton->OwnerMenu = 0;
- }
- void Update()
- {
- for (uint32 Index = 0; Index < MenuButtons.GetCount(); ++Index)
- {
- FButton *Button = MenuButtons[Index];
- Button->OnUpdate();
- }
- }
- void Render()
- {
- for (uint32 Index = 0; Index < MenuButtons.GetCount(); ++Index)
- {
- FButton *Button = MenuButtons[Index];
- Button->Draw();
- }
- }
- };
- class FMenuState
- {
- public:
- uint32 CurrentMenuIndex;
- TArray<FMenu *> MenuCache;
- public:
- void AddMenu(FMenu *InMenu)
- {
- MenuCache.Add(InMenu);
- InMenu->OwnerMenuState = this;
- }
- void RemoveMenu(FMenu *InMenu)
- {
- MenuCache.Remove(InMenu);
- InMenu->OwnerMenuState = 0;
- }
- void UpdateAndRender()
- {
- FMenu *CurrentMenu = MenuCache[CurrentMenuIndex];
- CurrentMenu->Update();
- CurrentMenu->Render();
- }
- };
- class FLoginButton : public FButton
- {
- public:
- virtual void OnRelease() override
- {
- bIsPressed = true;
- }
- virtual void OnUpdate() override
- {
- if (bIsPressed)
- {
- OwnerMenu->OwnerMenuState->CurrentMenuIndex++;
- }
- }
- private:
- bool bIsPressed;
- };
- class FLoginMenu : public FMenu
- {
- public:
- FLoginMenu()
- {
- FButton *LoginButton;
- FMenu::AddButton(LoginButton);
- FButton *ExitButton;
- FMenu::AddButton(ExitButton);
- }
- };
- void Main()
- {
- FLoginButton *LoginButton;
- // ->SetColor and stuff
- FButton *ExitButton;
- // ->SetColor and stuff
- FButton *AccountNameButton;
- // ->SetColor and stuff
- FButton *AccountPasswordButton;
- // ->SetColor and stuff
- FMenu *MenuA;
- MenuA->AddButton(LoginButton);
- MenuA->AddButton(ExitButton);
- FMenu *MenuB;
- MenuB->AddButton(AccountNameButton);
- MenuB->AddButton(AccountPasswordButton);
- FMenuState *MenuState;
- MenuState->AddMenu(MenuA);
- MenuState->AddMenu(MenuB);
- while (bGameIsRunning)
- {
- MenuState->UpdateAndRender();
- }
- }
- /* - MenuA
- ->Login
- ->Exit
- */
- /* - MenuB
- ->AccountName
- ->AccountPassword
- */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement