Elevate Engine 1
Loading...
Searching...
No Matches
WwiseBrowserWidget.h
Go to the documentation of this file.
1#pragma once
2#ifdef EE_EDITOR_BUILD
3
8
9#include <set>
10#include <glm/vec4.hpp>
11#include "imgui.h"
12
13namespace Elevate::Editor
14{
15 // Todo move this somewhere else, can be very usefull for UI messages
16 struct EditorMessage
17 {
18 enum Type : uint8_t
19 {
20 Error,
21 Warning,
22 Message,
23 Success,
24 Information
25 };
26
27 std::string message;
28 Type type;
29
30 EditorMessage(std::string message, Type type)
31 : message(message), type(type) { }
32
33 inline glm::vec4 GetColor()
34 {
35 // todo remove the hardcoded colors from here
36 switch (type)
37 {
38 case Error:
39 return { 166, 25, 46, 255 };
40 case Warning:
41 return { 255, 153, 0, 255 };
42 case Message:
43 return { 255, 255, 255, 255 };
44 case Success:
45 return { 4, 179, 9, 255 };
46 case Information:
47 return { 0, 87, 184, 255 };
48 }
49 return { 0, 87, 184, 255 };
50 }
51 };
52
53#ifdef EE_USES_WWISE
54 class WwiseBrowserWidget : public EditorWidget
55 {
56 private:
57 char m_searchBuffer[128];
58 std::set<WwiseItemPtr> m_selectedItems;
59
60 public:
61 WwiseBrowserWidget() = default;
62 virtual ~WwiseBrowserWidget() = default;
63
64 virtual void OnImGuiRender() override
65 {
66 // todo : prevent from being fetched each frame and only update when there is a refresh.
67 WwiseSoundEngine* wwiseEngine = WwiseSoundEngine::Get();
68 if (!wwiseEngine) // Protection in case the SoundEngine is misssconfigured
69 {
70 return;
71 }
72
73 ImGui::Begin("Wwise Browser");
74
75 ImGui::BeginGroup();
76 ImGui::Text(WAAPIClient::IsConnected() ? "Conntected to WAAPI." : "Not Connected to WAAPI");
77 ImGui::EndGroup();
78
79 ImGui::BeginGroup();
80 if (ImGui::Button("Expand All"))
81 {
82 }
83 ImGui::SameLine();
84 if (ImGui::Button("Collapse All"))
85 {
86 }
87 ImGui::SameLine();
88 ImGui::InputText("##", m_searchBuffer, sizeof(m_searchBuffer) / sizeof(char));
89 ImGui::SameLine();
90 if (ImGui::Button("Refresh"))
91 {
92 wwiseEngine->GetDataSource()->RefreshSource();
93 // todo add a notifier here
94 }
95 ImGui::SameLine();
96 ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
97 if (ImGui::Button("Generate SoundBanks"))
98 {
99 }
100 ImGui::EndGroup();
101 ImGui::Separator();
102 if (ImGui::BeginTable("WwiseBrowserTreeView", 3, ImGuiTableFlags_Resizable))
103 {
104 ImGui::TableSetupColumn("Wwise Item");
105 ImGui::TableSetupColumn("State on Disk");
106 ImGui::TableSetupColumn("State in SoundBanks");
107 ImGui::TableHeadersRow();
108
109 DrawTreeView(wwiseEngine->GetDataSource()->GetItems().lock());
110
111 ImGui::EndTable();
112 }
113
114 ImGui::End();
115 }
116
117 protected:
118 void DrawTreeView(WwiseItemPtr root)
119 {
120 for (const auto& child : root->Children)
121 {
122 DrawItemsRecursive(child);
123 }
124 }
125
126 void DrawItemsRecursive(WwiseItemPtr item)
127 {
128 ImGui::TableNextRow();
129 ImGui::TableSetColumnIndex(0);
130
131 ImGuiTreeNodeFlags nodeFlags = ImGuiTreeNodeFlags_FramePadding | ImGuiTreeNodeFlags_SpanAvailWidth | ImGuiTreeNodeFlags_OpenOnArrow;
132 if (!item->HasChildren())
133 {
134 nodeFlags |= ImGuiTreeNodeFlags_Leaf;
135 }
136
137 if (m_selectedItems.contains(item))
138 {
139 nodeFlags |= ImGuiTreeNodeFlags_Selected;
140 }
141
142 bool open = false;
143 // todo impl.
144 //ImGui::Image((ImTextureID)m_objectTexture->GetNativeHandle(), ImVec2(16, 16));
145 //ImGui::SameLine();
146 open = ImGui::TreeNodeEx((item->Name + "##" + item->GUID).c_str(), nodeFlags);
147
148 if (ImGui::BeginPopupContextItem())
149 {
150 ImGui::SeparatorText("Playback");
151 ImGui::BeginDisabled(item->ShortID == 0 || !item->IsEvent());
152 if (ImGui::MenuItem("Play Event"))
153 {
154 SoundEngine::PostEvent(item->ShortID);
155 }
156 ImGui::EndDisabled();
157 ImGui::EndPopup();
158 }
159
160 if (ImGui::IsItemClicked() && !ImGui::IsItemToggledOpen())
161 {
162 if (!ImGui::IsKeyDown(ImGuiKey::ImGuiKey_LeftCtrl))
163 {
164 m_selectedItems.clear();
165 }
166 m_selectedItems.insert(item);
167 }
168
169 if (open)
170 {
171 for (const auto& child : item->Children)
172 {
173 DrawItemsRecursive(child);
174 }
175 ImGui::TreePop();
176 }
177
178 // We do not draw in the other columns if the item is a parent
179 if (!item->IsDirectory())
180 {
181 ImGui::TableSetColumnIndex(1);
182 EditorMessage msg = GetDiskStatusText(item);
183 glm::vec4 color = msg.GetColor();
184 ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(color.r, color.g, color.b, color.a));
185 ImGui::Text("%s", msg.message.c_str());
186 ImGui::PopStyleColor();
187
188 ImGui::TableSetColumnIndex(2);
189 msg = GetSoundBanksStatusText(item);
190 color = msg.GetColor();
191 ImGui::PushStyleColor(ImGuiCol_Text, IM_COL32(color.r, color.g, color.b, color.a));
192 ImGui::Text("%s", msg.message.c_str());
193 ImGui::PopStyleColor();
194 }
195 }
196
197 EditorMessage GetDiskStatusText(WwiseItemPtr item)
198 {
199 if (item->IsOnDisk)
200 {
201 return EditorMessage("On Disk", EditorMessage::Type::Message);
202 }
203 else
204 {
205 return EditorMessage("Not on Disk", EditorMessage::Type::Warning);
206 }
207 }
208
209 EditorMessage GetSoundBanksStatusText(WwiseItemPtr item)
210 {
211 if (item->IsInBank)
212 {
213 return EditorMessage("SoundBank up to date", EditorMessage::Type::Message);
214 }
215 else
216 {
217 return EditorMessage("Missing in SoundBank", EditorMessage::Type::Warning);
218 }
219 }
220 };
221#endif // #ifdef EE_USES_WWISE
222}
223
224#endif // EE_EDITOR_BUILD