Skip to content

Commit

Permalink
Add CJK font support (#356)
Browse files Browse the repository at this point in the history
* added CJK support

* get index of font within TTC

* fix some warnings
  • Loading branch information
cddjr committed Apr 25, 2022
1 parent c0ef502 commit 828c088
Show file tree
Hide file tree
Showing 28 changed files with 210 additions and 144 deletions.
2 changes: 1 addition & 1 deletion events/CastVoteEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

CastVoteEvent::CastVoteEvent(EVENT_PLAYER source, std::optional<EVENT_PLAYER> target) : EventInterface(source, EVENT_VOTE) {
CastVoteEvent::CastVoteEvent(EVENT_PLAYER source, std::optional<EVENT_PLAYER> target) : EventInterface(source, EVENT_TYPES::EVENT_VOTE) {
this->target = target;
}

Expand Down
4 changes: 2 additions & 2 deletions events/CheatDetectedEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

CheatDetectedEvent::CheatDetectedEvent(EVENT_PLAYER source, CHEAT_ACTIONS action) : EventInterface(source, EVENT_CHEAT) {
CheatDetectedEvent::CheatDetectedEvent(EVENT_PLAYER source, CHEAT_ACTIONS action) : EventInterface(source, EVENT_TYPES::EVENT_CHEAT) {
this->action = action;
}

Expand All @@ -11,7 +11,7 @@ void CheatDetectedEvent::Output() {
ImGui::SameLine();
ImGui::Text(">");
ImGui::SameLine();
ImGui::Text("Cheat detected: %s", CHEAT_ACTION_NAMES[this->action]);
ImGui::Text("Cheat detected: %s", CHEAT_ACTION_NAMES[(int)this->action]);
ImGui::SameLine();
ImGui::Text("[%s ago]", std::format("{:%OM:%OS}", (std::chrono::system_clock::now() - this->timestamp)).c_str());
}
Expand Down
2 changes: 1 addition & 1 deletion events/DisconnectEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

DisconnectEvent::DisconnectEvent(EVENT_PLAYER source) : EventInterface(source, EVENT_DISCONNECT) { }
DisconnectEvent::DisconnectEvent(EVENT_PLAYER source) : EventInterface(source, EVENT_TYPES::EVENT_DISCONNECT) { }

void DisconnectEvent::Output() {
ImGui::TextColored(AmongUsColorToImVec4(GetPlayerColor(source.colorId)), source.playerName.c_str());
Expand Down
2 changes: 1 addition & 1 deletion events/KillEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

KillEvent::KillEvent(EVENT_PLAYER source, EVENT_PLAYER target, Vector2 position, Vector2 targetPosition) : EventInterface(source, EVENT_KILL) {
KillEvent::KillEvent(EVENT_PLAYER source, EVENT_PLAYER target, Vector2 position, Vector2 targetPosition) : EventInterface(source, EVENT_TYPES::EVENT_KILL) {
this->target = target;
this->targetPosition = targetPosition;
this->position = position;
Expand Down
2 changes: 1 addition & 1 deletion events/ProtectPlayerEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

ProtectPlayerEvent::ProtectPlayerEvent(EVENT_PLAYER source, EVENT_PLAYER target) : EventInterface(source, EVENT_PROTECTPLAYER) {
ProtectPlayerEvent::ProtectPlayerEvent(EVENT_PLAYER source, EVENT_PLAYER target) : EventInterface(source, EVENT_TYPES::EVENT_PROTECTPLAYER) {
this->target = target;
}

Expand Down
2 changes: 1 addition & 1 deletion events/ReportDeadBodyEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "utility.h"

ReportDeadBodyEvent::ReportDeadBodyEvent(EVENT_PLAYER source, std::optional<EVENT_PLAYER> target, Vector2 position, std::optional<Vector2> targetPosition)
: EventInterface(source, (target.has_value() ? EVENT_REPORT : EVENT_MEETING)) {
: EventInterface(source, (target.has_value() ? EVENT_TYPES::EVENT_REPORT : EVENT_TYPES::EVENT_MEETING)) {
this->target = target;
this->position = position;
this->targetPosition = targetPosition;
Expand Down
2 changes: 1 addition & 1 deletion events/ShapeShiftEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

ShapeShiftEvent::ShapeShiftEvent(EVENT_PLAYER source, EVENT_PLAYER target) : EventInterface(source, EVENT_SHAPESHIFT) {
ShapeShiftEvent::ShapeShiftEvent(EVENT_PLAYER source, EVENT_PLAYER target) : EventInterface(source, EVENT_TYPES::EVENT_SHAPESHIFT) {
this->target = target;
}

Expand Down
2 changes: 1 addition & 1 deletion events/TaskCompletedEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

TaskCompletedEvent::TaskCompletedEvent(EVENT_PLAYER source, std::optional<TaskTypes__Enum> taskType, Vector2 position) : EventInterface(source, EVENT_TASK) {
TaskCompletedEvent::TaskCompletedEvent(EVENT_PLAYER source, std::optional<TaskTypes__Enum> taskType, Vector2 position) : EventInterface(source, EVENT_TYPES::EVENT_TASK) {
this->taskType = taskType;
this->position = position;
this->systemType = GetSystemTypes(position);
Expand Down
6 changes: 3 additions & 3 deletions events/VentEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

VentEvent::VentEvent(EVENT_PLAYER source, Vector2 position, VENT_ACTIONS action) : EventInterface(source, EVENT_VENT)
VentEvent::VentEvent(EVENT_PLAYER source, Vector2 position, VENT_ACTIONS action) : EventInterface(source, EVENT_TYPES::EVENT_VENT)
{
this->position = position;
this->systemType = GetSystemTypes(position);
Expand All @@ -24,9 +24,9 @@ void VentEvent::ColoredEventOutput()
ImGui::SameLine();

ImVec4 color;
((action == VENT_ENTER) ? color = ImVec4(0.f, 1.f, 0.f, 1.f) : color = ImVec4(1.f, 0.f, 0.f, 1.f));
((action == VENT_ACTIONS::VENT_ENTER) ? color = ImVec4(0.f, 1.f, 0.f, 1.f) : color = ImVec4(1.f, 0.f, 0.f, 1.f));

ImGui::TextColored(color, ((action == VENT_ENTER) ? "IN" : "OUT"));
ImGui::TextColored(color, ((action == VENT_ACTIONS::VENT_ENTER) ? "IN" : "OUT"));
ImGui::SameLine();
ImGui::Text("]");
}
2 changes: 1 addition & 1 deletion events/WalkEvent.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "_events.h"
#include "utility.h"

WalkEvent::WalkEvent(EVENT_PLAYER source, Vector2 position) : EventInterface(source, EVENT_WALK) {
WalkEvent::WalkEvent(EVENT_PLAYER source, Vector2 position) : EventInterface(source, EVENT_TYPES::EVENT_WALK) {
this->position = position;
}

Expand Down
6 changes: 3 additions & 3 deletions events/_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ using namespace app;

#define EVENT_TYPES_SIZE 11

enum EVENT_TYPES {
enum class EVENT_TYPES {
EVENT_KILL,
EVENT_VENT,
EVENT_TASK,
Expand All @@ -22,12 +22,12 @@ enum EVENT_TYPES {
EVENT_WALK
};

enum VENT_ACTIONS {
enum class VENT_ACTIONS {
VENT_ENTER,
VENT_EXIT
};

enum CHEAT_ACTIONS {
enum class CHEAT_ACTIONS {
CHEAT_TELEPORT,
CHEAT_KILL_IMPOSTOR
};
Expand Down
2 changes: 1 addition & 1 deletion gui/console.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ namespace ConsoleGui
STREAM_ERROR("State.liveReplayEvents[" << i << "] was NULL (liveReplayEvents.size(): " << State.liveReplayEvents.size() << ")");
continue;
}
if (evt->getType() == EVENT_WALK)
if (evt->getType() == EVENT_TYPES::EVENT_WALK)
continue;

if (isUsingEventFilter && ConsoleGui::event_filter.at((size_t)evt->getType()).second == false)
Expand Down
64 changes: 26 additions & 38 deletions gui/gui-helpers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ bool CustomListBoxInt(const char* label, int* value, const std::vector<const cha
for (size_t i = 0; i < list.size(); i++) {
bool is_selected = (*value == i);
if (Selectable(list.at(i), is_selected)) {
*value = i;
*value = (int)i;
response = true;
}
if (is_selected)
Expand All @@ -38,7 +38,7 @@ bool CustomListBoxInt(const char* label, int* value, const std::vector<const cha
const bool LeftResponse = ArrowButton(leftArrow.c_str(), ImGuiDir_Left);
if (LeftResponse) {
*value -= 1;
if (*value < 0) *value = (list.size() - 1);
if (*value < 0) *value = int(list.size() - 1);
return LeftResponse;
}
SameLine(0, spacing);
Expand Down Expand Up @@ -343,15 +343,12 @@ void drawPlayerDot(PlayerControl* player, ImVec2 winPos, ImU32 color, ImU32 stat

Vector2 playerPos = app::PlayerControl_GetTruePosition(player, NULL);

float xOffset = maps[State.mapType].x_offset;
float yOffset = maps[State.mapType].y_offset;
const auto& map = maps[(size_t)State.mapType];
float xOffset = getMapXOffsetSkeld(map.x_offset);
float yOffset = map.y_offset;

if (State.mapType == Settings::MapType::Ship && State.FlipSkeld) {
xOffset -= 50;
}

float radX = xOffset + (playerPos.x * maps[State.mapType].scale);
float radY = yOffset - (playerPos.y * maps[State.mapType].scale);
float radX = xOffset + (playerPos.x * map.scale);
float radY = yOffset - (playerPos.y * map.scale);
const ImVec2& center = ImVec2(radX, radY) * State.dpiScale + winPos;

drawList->AddCircleFilled(center, 4.5F * State.dpiScale, color);
Expand All @@ -364,18 +361,15 @@ void drawPlayerIcon(PlayerControl* player, ImVec2 winPos, ImU32 color)

Vector2 playerPos = app::PlayerControl_GetTruePosition(player, NULL);

float xOffset = maps[State.mapType].x_offset;
float yOffset = maps[State.mapType].y_offset;

if (State.mapType == Settings::MapType::Ship && State.FlipSkeld) {
xOffset -= 50;
}
const auto& map = maps[(size_t)State.mapType];
float xOffset = getMapXOffsetSkeld(map.x_offset);
float yOffset = map.y_offset;

IconTexture icon = icons.at(ICON_TYPES::PLAYER);
float radX = xOffset + (playerPos.x - (icon.iconImage.imageWidth * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radY = yOffset - (playerPos.y - (icon.iconImage.imageHeight * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radXMax = xOffset + (playerPos.x + (icon.iconImage.imageWidth * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radYMax = yOffset - (playerPos.y + (icon.iconImage.imageHeight * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radX = xOffset + (playerPos.x - (icon.iconImage.imageWidth * icon.scale * 0.5f)) * map.scale;
float radY = yOffset - (playerPos.y - (icon.iconImage.imageHeight * icon.scale * 0.5f)) * map.scale;
float radXMax = xOffset + (playerPos.x + (icon.iconImage.imageWidth * icon.scale * 0.5f)) * map.scale;
float radYMax = yOffset - (playerPos.y + (icon.iconImage.imageHeight * icon.scale * 0.5f)) * map.scale;

const ImVec2& p_min = ImVec2(radX, radY) * State.dpiScale + winPos;
const ImVec2& p_max = ImVec2(radXMax, radYMax) * State.dpiScale + winPos;
Expand All @@ -398,15 +392,12 @@ void drawDeadPlayerDot(DeadBody* deadBody, ImVec2 winPos, ImU32 color)

Vector2 bodyPos = app::DeadBody_get_TruePosition(deadBody, NULL);

float xOffset = maps[State.mapType].x_offset;
float yOffset = maps[State.mapType].y_offset;
const auto& map = maps[(size_t)State.mapType];
float xOffset = getMapXOffsetSkeld(map.x_offset);
float yOffset = map.y_offset;

if (State.mapType == Settings::MapType::Ship && State.FlipSkeld) {
xOffset -= 50;
}

float radX = xOffset + (bodyPos.x * maps[State.mapType].scale);
float radY = yOffset - (bodyPos.y * maps[State.mapType].scale);
float radX = xOffset + (bodyPos.x * map.scale);
float radY = yOffset - (bodyPos.y * map.scale);

drawList->AddText(GetFont(), 16 * State.dpiScale,
ImVec2(radX - 5.F, radY - 6.75F) * State.dpiScale + winPos, color, "X");
Expand All @@ -418,18 +409,15 @@ void drawDeadPlayerIcon(DeadBody* deadBody, ImVec2 winPos, ImU32 color)

Vector2 bodyPos = app::DeadBody_get_TruePosition(deadBody, NULL);

float xOffset = maps[State.mapType].x_offset;
float yOffset = maps[State.mapType].y_offset;

if (State.mapType == Settings::MapType::Ship && State.FlipSkeld) {
xOffset -= 50;
}
const auto& map = maps[(size_t)State.mapType];
float xOffset = getMapXOffsetSkeld(map.x_offset);
float yOffset = map.y_offset;

IconTexture icon = icons.at(ICON_TYPES::DEAD);
float radX = xOffset + (bodyPos.x - (icon.iconImage.imageWidth * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radY = yOffset - (bodyPos.y - (icon.iconImage.imageHeight * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radXMax = xOffset + (bodyPos.x + (icon.iconImage.imageWidth * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radYMax = yOffset - (bodyPos.y + (icon.iconImage.imageHeight * icon.scale * 0.5f)) * maps[State.mapType].scale;
float radX = xOffset + (bodyPos.x - (icon.iconImage.imageWidth * icon.scale * 0.5f)) * map.scale;
float radY = yOffset - (bodyPos.y - (icon.iconImage.imageHeight * icon.scale * 0.5f)) * map.scale;
float radXMax = xOffset + (bodyPos.x + (icon.iconImage.imageWidth * icon.scale * 0.5f)) * map.scale;
float radYMax = yOffset - (bodyPos.y + (icon.iconImage.imageHeight * icon.scale * 0.5f)) * map.scale;

drawList->AddImage((void*)icon.iconImage.shaderResourceView,
ImVec2(radX, radY) * State.dpiScale + winPos,
Expand Down
22 changes: 11 additions & 11 deletions gui/radar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,20 +34,20 @@ namespace Radar {
ImVec2 mouse = ImGui::GetMousePos();
ImVec2 winpos = ImGui::GetWindowPos();
ImVec2 winsize = ImGui::GetWindowSize();
int MapType = State.mapType;

if (mouse.x < winpos.x
|| mouse.x > winpos.x + winsize.x
|| mouse.y < winpos.y
|| mouse.y > winpos.y + winsize.y)
return;

float xOffset = getMapXOffsetSkeld(maps[MapType].x_offset);
float yOffset = maps[MapType].y_offset;
const auto& map = maps[(size_t)State.mapType];
float xOffset = getMapXOffsetSkeld(map.x_offset);
float yOffset = map.y_offset;

Vector2 target = {
((mouse.x - winpos.x) / State.dpiScale - xOffset) / maps[MapType].scale,
(((mouse.y - winpos.y) / State.dpiScale - yOffset) * -1.F) / maps[MapType].scale
((mouse.x - winpos.x) / State.dpiScale - xOffset) / map.scale,
(((mouse.y - winpos.y) / State.dpiScale - yOffset) * -1.F) / map.scale
};

State.rpcQueue.push(new RpcSnapTo(target));
Expand All @@ -64,8 +64,8 @@ namespace Radar {
if (!init)
Radar::Init();

Settings::MapType MapType = State.mapType;
ImGui::SetNextWindowSize(ImVec2((float)maps[MapType].mapImage.imageWidth * 0.5f + 10.f, (float)maps[MapType].mapImage.imageHeight * 0.5f + 10.f) * State.dpiScale, ImGuiCond_None);
const auto& map = maps[(size_t)State.mapType];
ImGui::SetNextWindowSize(ImVec2((float)map.mapImage.imageWidth * 0.5f + 10.f, (float)map.mapImage.imageHeight * 0.5f + 10.f) * State.dpiScale, ImGuiCond_None);

if(State.LockRadar)
ImGui::Begin("Radar", &State.ShowRadar, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove);
Expand All @@ -74,11 +74,11 @@ namespace Radar {

ImVec2 winpos = ImGui::GetWindowPos();

ImGui::Image((void*)maps[MapType].mapImage.shaderResourceView,
ImVec2((float)maps[MapType].mapImage.imageWidth * 0.5F, (float)maps[MapType].mapImage.imageHeight * 0.5F) * State.dpiScale,
ImGui::Image((void*)map.mapImage.shaderResourceView,
ImVec2((float)map.mapImage.imageWidth * 0.5F, (float)map.mapImage.imageHeight * 0.5F) * State.dpiScale,
ImVec2(0.0f, 0.0f),
(State.FlipSkeld && MapType == 0) ? ImVec2(1.0f, 0.0f) : ImVec2(0.0f, 0.0f),
(State.FlipSkeld && MapType == 0) ? ImVec2(0.0f, 1.0f) : ImVec2(1.0f, 1.0f),
(State.FlipSkeld && State.mapType == Settings::MapType::Ship) ? ImVec2(1.0f, 0.0f) : ImVec2(0.0f, 0.0f),
(State.FlipSkeld && State.mapType == Settings::MapType::Ship) ? ImVec2(0.0f, 1.0f) : ImVec2(1.0f, 1.0f),
State.SelectedColor);

for (auto player : GetAllPlayerControl()) {
Expand Down

0 comments on commit 828c088

Please sign in to comment.