Skip to content
This repository has been archived by the owner on Oct 10, 2024. It is now read-only.

Commit

Permalink
[WIP] Feature/visualization (#295)
Browse files Browse the repository at this point in the history
* - Added basic Replay Tab and Window (WIP)
- Added new gui helper element CustomListBoxIntMultiple for multiple selections
- Improved Console filters by excluding by event types with CustomListBoxIntMultiple now
- Minor code improvements

* - Added new custom dropdown selection for multiple players
-Added filtering by players to console events
-Some minor improvements

* Added Reset Buttons to custom list boxes selections
Removed EVENT_NONE
Minor changes

* improved console looks

* -filter event types the same as player filter
-minor changes to console looks

* - Fixed console height
- Fixed IsInGame call in gui-helper function
- Added some groundwork for replay handling
- Added proper filter elements for replay window

* - Commented out Replay window for main merge
  • Loading branch information
v0idp authored Feb 10, 2022
1 parent f1d6435 commit ed56978
Show file tree
Hide file tree
Showing 19 changed files with 396 additions and 42 deletions.
4 changes: 4 additions & 0 deletions AmongUsMenu.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,15 @@
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">NotUsing</PrecompiledHeader>
<PrecompiledHeader Condition="'$(Configuration)|$(Platform)'=='Debug_Version|Win32'">NotUsing</PrecompiledHeader>
</ClCompile>
<ClCompile Include="gui\replay.cpp" />
<ClCompile Include="gui\tabs\debug_tab.cpp" />
<ClCompile Include="gui\tabs\doors_tab.cpp" />
<ClCompile Include="gui\tabs\esp_tab.cpp" />
<ClCompile Include="gui\tabs\game_tab.cpp" />
<ClCompile Include="gui\tabs\host_tab.cpp" />
<ClCompile Include="gui\tabs\players_tab.cpp" />
<ClCompile Include="gui\tabs\radar_tab.cpp" />
<ClCompile Include="gui\tabs\replay_tab.cpp" />
<ClCompile Include="gui\tabs\sabotage_tab.cpp" />
<ClCompile Include="gui\tabs\settings_tab.cpp" />
<ClCompile Include="gui\tabs\tasks_tab.cpp" />
Expand Down Expand Up @@ -326,13 +328,15 @@
<ClInclude Include="gui\gui-helpers.hpp" />
<ClInclude Include="gui\RenderCmd.hpp" />
<ClInclude Include="gui\Renderer.hpp" />
<ClInclude Include="gui\replay.hpp" />
<ClInclude Include="gui\tabs\debug_tab.h" />
<ClInclude Include="gui\tabs\doors_tab.h" />
<ClInclude Include="gui\tabs\esp_tab.h" />
<ClInclude Include="gui\tabs\game_tab.h" />
<ClInclude Include="gui\tabs\host_tab.h" />
<ClInclude Include="gui\tabs\players_tab.h" />
<ClInclude Include="gui\tabs\radar_tab.h" />
<ClInclude Include="gui\tabs\replay_tab.h" />
<ClInclude Include="gui\tabs\sabotage_tab.h" />
<ClInclude Include="gui\tabs\settings_tab.h" />
<ClInclude Include="gui\tabs\tasks_tab.h" />
Expand Down
12 changes: 12 additions & 0 deletions AmongUsMenu.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,12 @@
<ClCompile Include="rpc\RpcSetRole.cpp">
<Filter>rpc</Filter>
</ClCompile>
<ClCompile Include="gui\replay.cpp">
<Filter>gui</Filter>
</ClCompile>
<ClCompile Include="gui\tabs\replay_tab.cpp">
<Filter>gui\tabs</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="appdata\il2cpp-api-functions.h">
Expand Down Expand Up @@ -448,6 +454,12 @@
<Filter>user</Filter>
</ClInclude>
<ClInclude Include="gitparams.h" />
<ClInclude Include="gui\replay.hpp">
<Filter>gui</Filter>
</ClInclude>
<ClInclude Include="gui\tabs\replay_tab.h">
<Filter>gui\tabs</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<Image Include="resources\mira_hq.png">
Expand Down
26 changes: 13 additions & 13 deletions events/_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@

using namespace app;

#define EVENT_TYPES_SIZE 11

enum EVENT_TYPES {
EVENT_NONE = 0,
EVENT_KILL = 1,
EVENT_VENT = 2,
EVENT_TASK = 3,
EVENT_REPORT = 4,
EVENT_MEETING = 5,
EVENT_VOTE = 6,
EVENT_CHEAT = 7,
EVENT_DISCONNECT = 8,
EVENT_SHAPESHIFT = 9,
EVENT_PROTECTPLAYER = 10,
EVENT_WALK = 11,
EVENT_TYPES_SIZE = 12
EVENT_KILL = 0,
EVENT_VENT = 1,
EVENT_TASK = 2,
EVENT_REPORT = 3,
EVENT_MEETING = 4,
EVENT_VOTE = 5,
EVENT_CHEAT = 6,
EVENT_DISCONNECT = 7,
EVENT_SHAPESHIFT = 8,
EVENT_PROTECTPLAYER = 9,
EVENT_WALK = 10
};

enum VENT_ACTION {
Expand Down
83 changes: 71 additions & 12 deletions gui/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,93 @@
#include "gui-helpers.hpp"
#include "state.hpp"

namespace ConsoleGui {
int selectedType = 0;
namespace ConsoleGui
{
// TODO: improve this by building it dynamically based on the EVENT_TYPES enum
std::vector<std::pair<const char*, bool>> event_filter =
{
{"Kill", false},
{"Vent", false},
{"Task", false},
{"Report", false},
{"Meeting", false},
{"Vote", false},
{"Cheat", false},
{"Disconnect", false},
{"Shapeshift", false},
{"Protect", false}
};

std::vector<std::pair<PlayerSelection, bool>> player_filter;

bool init = false;
void Init() {
ImGui::SetNextWindowSize(ImVec2(520, 320), ImGuiCond_Once);
ImGui::SetNextWindowBgAlpha(1.F);

if (!init)
{
// setup player_filter list based on MAX_PLAYERS definition
for (int i = 0; i < MAX_PLAYERS; i++) {
ConsoleGui::player_filter.push_back({ PlayerSelection(), false });
}
init = true;
}
}

bool init = false;

void Render() {
if (!init)
ConsoleGui::Init();
ConsoleGui::Init();

ImGui::Begin("Console", &State.ShowConsole, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoScrollbar);
ImGui::BeginChild("console#filter", ImVec2(490, 20), true);
ImGui::Text("Filter\t");
ImGui::BeginChild("console#filter", ImVec2(520, 20), true);
ImGui::Text("Event Filter: ");
ImGui::SameLine();
CustomListBoxInt("By Type", &ConsoleGui::selectedType, ConsoleGui::BY_TYPE, 100.f);
CustomListBoxIntMultiple("Event Types", &ConsoleGui::event_filter, 100.f);
if (IsInGame()) {
ImGui::SameLine(0.f, 5.f);
ImGui::Text("Player Filter: ");
ImGui::SameLine();
CustomListBoxPlayerSelectionMultiple("Players", &ConsoleGui::player_filter, 150.f);
}
ImGui::EndChild();
ImGui::Separator();
ImGui::BeginChild("console#scroll", ImVec2(490, 225), true);
ImGui::BeginChild("console#scroll", ImVec2(511, 270), true, ImGuiWindowFlags_AlwaysVerticalScrollbar);
for (int i = State.consoleEvents.size() - 1; i >= 0; i--) {
if (State.consoleEvents[i]->getType() == EVENT_WALK)
continue;

if (ConsoleGui::selectedType > 0)
if (State.consoleEvents[i]->getType() != (EVENT_TYPES)ConsoleGui::selectedType)
continue;
bool typeFound = false, anyTypeFilterSelected = false;
for (int n = 0; n < ConsoleGui::event_filter.size(); n++) {
if (ConsoleGui::event_filter[n].second
&& (EVENT_TYPES)n == State.consoleEvents[i]->getType()) {
typeFound = true;
anyTypeFilterSelected = true;
break;
}
else if (ConsoleGui::event_filter[n].second)
anyTypeFilterSelected = true;
}

if (!typeFound && anyTypeFilterSelected)
continue;

bool playerFound = false, anyPlayerFilterSelected = false;
for (auto player : ConsoleGui::player_filter) {
if (player.second
&& player.first.has_value()
&& player.first.get_PlayerId() == State.consoleEvents[i]->getSource().playerId)
{
playerFound = true;
anyPlayerFilterSelected = true;
break;
}
else if (player.second) // if no player was selected we want to make sure that any filter was set in the first place before we continue
anyPlayerFilterSelected = true;
}

if (!playerFound && anyPlayerFilterSelected)
continue;

State.consoleEvents[i]->ColoredEventOutput();
ImGui::SameLine();
Expand Down
3 changes: 0 additions & 3 deletions gui/console.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
#include <vector>

namespace ConsoleGui {
const std::vector<const char*> BY_TYPE = { "All", "Kill", "Vent", "Task", "Report", "Meeting", "Vote", "Cheat", "Disconnect", "Shapeshift", "Protect" };
extern int selectedType;

void Init();
void Render();
};
113 changes: 110 additions & 3 deletions gui/gui-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
#include "gui-helpers.hpp"
#include "keybinds.h"
#include "imgui/imgui_internal.h"
#include "state.hpp"
#include "game.h"

bool CustomListBoxInt(const char* label, int* value, const std::vector<const char*> list, float width, ImGuiComboFlags flags) {
auto comboLabel = "##" + std::string(label);
auto leftArrow = "##" + std::string(label) + "Left";
auto rightArrow = "##" + std::string(label) + "Right";

ImGuiStyle& style = ImGui::GetStyle();
float w = ImGui::CalcItemWidth();
float spacing = style.ItemInnerSpacing.x;
float button_sz = ImGui::GetFrameHeight();
ImGui::PushItemWidth(width);
const bool response = ImGui::BeginCombo(comboLabel.c_str(), list.at(*value), ImGuiComboFlags_NoArrowButton | flags);
if (response) {
Expand Down Expand Up @@ -41,12 +41,119 @@ bool CustomListBoxInt(const char* label, int* value, const std::vector<const cha
if (*value > (int)(list.size() - 1)) *value = 0;
return RightResponse;
}
ImGui::SameLine(0, style.ItemInnerSpacing.x);
ImGui::SameLine(0, spacing);
ImGui::Text(label);

return response;
}

bool CustomListBoxIntMultiple(const char* label, std::vector<std::pair<const char*, bool>>* list, float width, bool resetButton, ImGuiComboFlags flags) {
auto comboLabel = "##" + std::string(label);
auto buttonLabel = "Reset##" + std::string(label);
ImGuiStyle& style = ImGui::GetStyle();
float spacing = style.ItemInnerSpacing.x;
ImGui::PushItemWidth(width);
const bool response = ImGui::BeginCombo(comboLabel.c_str(), label, flags);
if (response) {
for (size_t i = 0; i < list->size(); i++) {
if (ImGui::Selectable(list->at(i).first, list->at(i).second))
list->at(i).second ^= 1;
if (list->at(i).second)
ImGui::SetItemDefaultFocus();
}
ImGui::EndCombo();
}

ImGui::PopItemWidth();

if (resetButton)
{
ImGui::SameLine(0, spacing);
const bool resetResponse = ImGui::Button(buttonLabel.c_str());
if (resetResponse) {
for (int i = 0; i < list->size(); i++)
list->at(i).second = false;
return resetResponse;
}
}

return response;
}

bool CustomListBoxPlayerSelectionMultiple(const char* label, std::vector<std::pair<PlayerSelection, bool>>* list, float width, bool resetButton, ImGuiComboFlags flags) {
if (!IsInGame()) return false; // works only ingame

auto comboLabel = "##" + std::string(label);
auto buttonLabel = "Reset##" + std::string(label);
ImGuiStyle& style = ImGui::GetStyle();
float spacing = style.ItemInnerSpacing.x;
ImGui::PushItemWidth(width);
const bool response = ImGui::BeginCombo(comboLabel.c_str(), label, flags);
if (response) {
auto localData = GetPlayerData(*Game::pLocalPlayer);
for (auto playerData : GetAllPlayerData()) {
if (playerData->fields.Disconnected) // maybe make that an option for replays ? (parameter based on "state.showDisconnected" related data)
continue;

std::string playerName = convert_from_string(GetPlayerOutfit(playerData)->fields._playerName);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
if (ImGui::Selectable(std::string("##" + playerName + "_ConsoleName").c_str(), list->at(playerData->fields.PlayerId).second))
{
list->at(playerData->fields.PlayerId).second ^= 1;
if (list->at(playerData->fields.PlayerId).second
&& (!list->at(playerData->fields.PlayerId).first.has_value()
|| (list->at(playerData->fields.PlayerId).first.has_value()
&& list->at(playerData->fields.PlayerId).first.is_Disconnected())))
{
list->at(playerData->fields.PlayerId).first = PlayerSelection(playerData);
}
}
if (list->at(playerData->fields.PlayerId).second)
ImGui::SetItemDefaultFocus();
ImGui::SameLine();
ImGui::ColorButton(std::string("##" + playerName + "_ConsoleColorButton").c_str(), AmongUsColorToImVec4(GetPlayerColor(GetPlayerOutfit(playerData)->fields.ColorId)), ImGuiColorEditFlags_NoBorder | ImGuiColorEditFlags_NoTooltip);
ImGui::SameLine();
ImGui::PopStyleVar(2);
ImGui::Dummy(ImVec2(0, 0));
ImGui::SameLine();

ImVec4 nameColor = AmongUsColorToImVec4(Palette__TypeInfo->static_fields->White);
if (State.RevealRoles)
{
std::string roleName = GetRoleName(playerData->fields.Role);
playerName = playerName + " (" + roleName + ")";
nameColor = AmongUsColorToImVec4(GetRoleColor(playerData->fields.Role));
}
else if (PlayerIsImpostor(localData) && PlayerIsImpostor(playerData))
nameColor = AmongUsColorToImVec4(Palette__TypeInfo->static_fields->ImpostorRed);
else if (PlayerSelection(playerData).is_LocalPlayer() || std::count(State.aumUsers.begin(), State.aumUsers.end(), playerData->fields.PlayerId))
nameColor = AmongUsColorToImVec4(Palette__TypeInfo->static_fields->Orange);

if (playerData->fields.IsDead)
nameColor = AmongUsColorToImVec4(Palette__TypeInfo->static_fields->DisabledGrey);

ImGui::TextColored(nameColor, playerName.c_str());
}
ImGui::EndCombo();
}

ImGui::PopItemWidth();

if (resetButton)
{
ImGui::SameLine(0, spacing);
const bool resetResponse = ImGui::Button(buttonLabel.c_str());
if (resetResponse) {
for (int i = 0; i < list->size(); i++)
list->at(i).second = false;
return resetResponse;
}
}

return response;
}

bool SteppedSliderFloat(const char* label, float* v, float v_min, float v_max, float v_step, const char* format = "%.3f", ImGuiSliderFlags flags = 0) {
char text_buf[64] = {};
ImFormatString(text_buf, IM_ARRAYSIZE(text_buf), format, *v);
Expand Down
3 changes: 3 additions & 0 deletions gui/gui-helpers.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#pragma once
#include <vector>
#include <imgui/imgui.h>
#include "utility.h"

bool CustomListBoxInt(const char* label, int* value, const std::vector<const char*> list, float width = 225.f, ImGuiComboFlags flags = ImGuiComboFlags_None);
bool CustomListBoxIntMultiple(const char* label, std::vector<std::pair<const char*, bool>>* list, float width, bool resetButton = true, ImGuiComboFlags flags = ImGuiComboFlags_None);
bool CustomListBoxPlayerSelectionMultiple(const char* label, std::vector<std::pair<PlayerSelection, bool>>* list, float width, bool resetButton = true, ImGuiComboFlags flags = ImGuiComboFlags_None);
bool SteppedSliderFloat(const char* label, float* v, float v_min, float v_max, float v_step, const char* format, ImGuiSliderFlags flags);
bool HotKey(uint8_t& key);
2 changes: 2 additions & 0 deletions gui/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "tabs/host_tab.h"
#include "tabs/players_tab.h"
#include "tabs/radar_tab.h"
#include "tabs/replay_tab.h"
#include "tabs/esp_tab.h"
#include "tabs/sabotage_tab.h"
#include "tabs/self_tab.h"
Expand Down Expand Up @@ -36,6 +37,7 @@ namespace Menu {
GameTab::Render();
SelfTab::Render();
RadarTab::Render();
//ReplayTab::Render();
EspTab::Render();
PlayersTab::Render();
TasksTab::Render();
Expand Down
Loading

0 comments on commit ed56978

Please sign in to comment.