summaryrefslogtreecommitdiff
path: root/src/port/ui/Menu.h
blob: 67bdae8ecb6cd3f08fb7553be4e8e9e70d8e94ff (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#ifndef MENU_H
#define MENU_H

#include <libultraship/libultraship.h>
#include "UIWidgets.h"
#include "MenuTypes.h"
#include "src/port/Game.h"
#include "src/port/audio/HMAS.h"
#include "engine/TrackBrowser.h"

extern "C" {
#include "defines.h"
#include "main.h"
#include "menus.h"
#include "code_800029B0.h"
#include "audio/external.h"
}

namespace Ship {
uint32_t GetVectorIndexOf(std::vector<std::string>& vector, std::string value);
class Menu : public GuiWindow {
  public:
    using GuiWindow::GuiWindow;

    Menu(const std::string& cVar, const std::string& name, uint8_t searchSidebarIndex_ = 0,
         UIWidgets::Colors menuThemeIndex_ = UIWidgets::Colors::LightBlue);
    virtual ~Menu() {}

    void InitElement() override;
    void DrawElement() override;
    void UpdateElement() override;
    void Draw() override;
    void InsertSidebarSearch();
    void RemoveSidebarSearch();
    void UpdateWindowBackendObjects();

    void MenuDrawItem(WidgetInfo& widget, uint32_t width, UIWidgets::Colors menuThemeIndex);
    void AddMenuEntry(std::string entryName, const char* entryCvar);
    std::unordered_map<uint32_t, disabledInfo>& GetDisabledMap();

  protected:
    ImVec2 mOriginalSize;
    std::string mName;
    uint32_t mWindowFlags;
    std::unordered_map<std::string, MainMenuEntry> menuEntries;
    std::vector<std::string> menuOrder;
    uint32_t DrawSearchResults(std::string& menuSearchText);
    ImGuiTextFilter menuSearch;
    uint8_t searchSidebarIndex;
    UIWidgets::Colors defaultThemeIndex;
    std::shared_ptr<std::vector<int32_t>> availableWindowBackends;
    std::unordered_map<int32_t, const char*> availableWindowBackendsMap;
    int32_t configWindowBackend;

    std::unordered_map<uint32_t, disabledInfo> disabledMap;
    std::vector<disabledInfo> disabledVector;
    const SidebarEntry searchSidebarEntry = {
        .columnCount = 1,
        .columnWidgets = { { { .name = "Sidebar Search",
                               .type = WIDGET_SEARCH,
                               .options = std::make_shared<UIWidgets::WidgetOptions>(UIWidgets::WidgetOptions{}.Tooltip(
                                   "Searches all menus for the given text, including tooltips.")) } } }
    };
    virtual void ProcessReset() {
      // Only request the reset: it is applied at the top of the next game
      // frame (ApplyPendingReset in Game.cpp), where it cannot race the menu
      // state machine mid-fade or be swallowed as a repeated gamestate write.
      CM_RequestReset();
    }

  private:
    bool allowPopout = true; // PortNote: should be set to false on small screen ports
    bool popped;
    ImVec2 poppedSize;
    ImVec2 poppedPos;
    float uiScale = 1.0f;
    float windowHeight;
    float windowWidth;
};
} // namespace Ship

#endif // MENU_H