summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorouwou <26526779+ouwou@users.noreply.github.com>2021-03-08 02:14:17 -0500
committerouwou <26526779+ouwou@users.noreply.github.com>2021-03-08 02:14:17 -0500
commit40726a7cd6d958718e4853dd51be77b66992fb44 (patch)
tree6b705f3d2d73fadc9aa0119a8840e6f08be33330
parent447e3f8d387017da65a008e9bc060d29b413cc3b (diff)
downloadabaddon-portaudio-40726a7cd6d958718e4853dd51be77b66992fb44.tar.gz
abaddon-portaudio-40726a7cd6d958718e4853dd51be77b66992fb44.zip
modify role color
-rw-r--r--css/main.css4
-rw-r--r--discord/discord.cpp16
-rw-r--r--discord/discord.hpp3
-rw-r--r--discord/objects.hpp2
-rw-r--r--windows/guildsettings/rolespane.cpp46
-rw-r--r--windows/guildsettings/rolespane.hpp2
6 files changed, 69 insertions, 4 deletions
diff --git a/css/main.css b/css/main.css
index 45a711b..5d450a9 100644
--- a/css/main.css
+++ b/css/main.css
@@ -315,3 +315,7 @@ radio:checked {
box-shadow: 0 1px rgba(0, 0, 0, 0);
color: #dddddd;
}
+
+colorswatch {
+ box-shadow: 0 1px rgba(0, 0, 0, 0);
+}
diff --git a/discord/discord.cpp b/discord/discord.cpp
index 481a0f6..ff4b8bf 100644
--- a/discord/discord.cpp
+++ b/discord/discord.cpp
@@ -555,6 +555,22 @@ void DiscordClient::ModifyRoleName(Snowflake guild_id, Snowflake role_id, const
});
}
+void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, sigc::slot<void(bool success)> callback) {
+ ModifyGuildRoleObject obj;
+ obj.Color = color;
+ m_http.MakePATCH("/guilds/" + std::to_string(guild_id) + "/roles/" + std::to_string(role_id), nlohmann::json(obj).dump(), [this, callback](const http::response_type &response) {
+ callback(CheckCode(response));
+ });
+}
+
+void DiscordClient::ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::RGBA color, sigc::slot<void(bool success)> callback) {
+ uint32_t int_color = 0;
+ int_color |= static_cast<uint32_t>(color.get_blue() * 255.0) << 0;
+ int_color |= static_cast<uint32_t>(color.get_green() * 255.0) << 8;
+ int_color |= static_cast<uint32_t>(color.get_red() * 255.0) << 16;
+ ModifyRoleColor(guild_id, role_id, int_color, callback);
+}
+
std::vector<BanData> DiscordClient::GetBansInGuild(Snowflake guild_id) {
return m_store.GetBans(guild_id);
}
diff --git a/discord/discord.hpp b/discord/discord.hpp
index da59853..0ee70c7 100644
--- a/discord/discord.hpp
+++ b/discord/discord.hpp
@@ -125,6 +125,9 @@ public:
void RemoveGroupDMRecipient(Snowflake channel_id, Snowflake user_id);
void ModifyRolePermissions(Snowflake guild_id, Snowflake role_id, Permission permissions, sigc::slot<void(bool success)> callback);
void ModifyRoleName(Snowflake guild_id, Snowflake role_id, const Glib::ustring &name, sigc::slot<void(bool success)> callback);
+ void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, uint32_t color, sigc::slot<void(bool success)> callback);
+ void ModifyRoleColor(Snowflake guild_id, Snowflake role_id, Gdk::RGBA color, sigc::slot<void(bool success)> callback);
+
// real client doesn't seem to use the single role endpoints so neither do we
template<typename Iter>
diff --git a/discord/objects.hpp b/discord/objects.hpp
index ea5d888..5efd94c 100644
--- a/discord/objects.hpp
+++ b/discord/objects.hpp
@@ -518,7 +518,7 @@ struct ModifyGuildMemberObject {
struct ModifyGuildRoleObject {
std::optional<std::string> Name;
std::optional<Permission> Permissions;
- std::optional<int> Color;
+ std::optional<uint32_t> Color;
std::optional<bool> IsHoisted;
std::optional<bool> Mentionable;
diff --git a/windows/guildsettings/rolespane.cpp b/windows/guildsettings/rolespane.cpp
index d92dc14..311e775 100644
--- a/windows/guildsettings/rolespane.cpp
+++ b/windows/guildsettings/rolespane.cpp
@@ -170,11 +170,13 @@ void GuildSettingsRolesPaneRolesListItem::UpdateItem(const RoleData &role) {
GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id)
: GuildID(guild_id)
- , m_layout(Gtk::ORIENTATION_VERTICAL) {
+ , m_layout(Gtk::ORIENTATION_VERTICAL)
+ , m_meta(Gtk::ORIENTATION_HORIZONTAL) {
set_propagate_natural_height(true);
set_propagate_natural_width(true);
- Abaddon::Get().GetDiscordClient().signal_role_update().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneInfo::OnRoleUpdate));
+ auto &discord = Abaddon::Get().GetDiscordClient();
+ discord.signal_role_update().connect(sigc::mem_fun(*this, &GuildSettingsRolesPaneInfo::OnRoleUpdate));
const auto cb = [this](GdkEventKey *e) -> bool {
if (e->keyval == GDK_KEY_Return)
@@ -192,6 +194,23 @@ GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id)
m_role_name.set_margin_start(5);
m_role_name.set_margin_end(5);
+ m_color_button.set_margin_top(5);
+ m_color_button.set_margin_bottom(5);
+ m_color_button.set_margin_start(5);
+ m_color_button.set_margin_end(5);
+
+ m_color_button.signal_color_set().connect([this, &discord]() {
+ const auto color = m_color_button.get_rgba();
+ const auto cb = [this, &discord](bool success) {
+ if (!success) {
+ m_color_button.set_rgba(IntToRGBA(discord.GetRole(RoleID)->Color));
+ Gtk::MessageDialog dlg("Failed to set role color", false, Gtk::MESSAGE_ERROR, Gtk::BUTTONS_OK, true);
+ dlg.run();
+ }
+ };
+ discord.ModifyRoleColor(GuildID, RoleID, color, cb);
+ });
+
int left_ypos = 0;
int right_ypos = 0;
@@ -257,9 +276,13 @@ GuildSettingsRolesPaneInfo::GuildSettingsRolesPaneInfo(Snowflake guild_id)
// clang-format on
- m_layout.add(m_role_name);
+ m_meta.add(m_role_name);
+ m_meta.add(m_color_button);
+ m_layout.add(m_meta);
m_layout.add(m_grid);
add(m_layout);
+ m_meta.show();
+ m_color_button.show();
m_role_name.show();
m_layout.show();
m_grid.show();
@@ -271,6 +294,14 @@ void GuildSettingsRolesPaneInfo::SetRole(const RoleData &role) {
it = m_update_connections.erase(it);
}
+ if (role.Color != 0) {
+ m_color_button.set_rgba(IntToRGBA(role.Color));
+ } else {
+ static Gdk::RGBA trans;
+ trans.set_alpha(0.0);
+ m_color_button.set_rgba(trans);
+ }
+
m_role_name.set_text(role.Name);
RoleID = role.ID;
@@ -285,6 +316,15 @@ void GuildSettingsRolesPaneInfo::OnRoleUpdate(Snowflake guild_id, Snowflake role
if (guild_id != GuildID || role_id != RoleID) return;
const auto role = *Abaddon::Get().GetDiscordClient().GetRole(RoleID);
m_role_name.set_text(role.Name);
+
+ if (role.Color != 0) {
+ m_color_button.set_rgba(IntToRGBA(role.Color));
+ } else {
+ static Gdk::RGBA trans;
+ trans.set_alpha(0.0);
+ m_color_button.set_rgba(trans);
+ }
+
m_perms = role.Permissions;
for (const auto [perm, btn] : m_perm_items)
btn->set_active((role.Permissions & perm) == perm);
diff --git a/windows/guildsettings/rolespane.hpp b/windows/guildsettings/rolespane.hpp
index 15f16cc..f2ff988 100644
--- a/windows/guildsettings/rolespane.hpp
+++ b/windows/guildsettings/rolespane.hpp
@@ -77,7 +77,9 @@ private:
std::vector<sigc::connection> m_update_connections;
Gtk::Box m_layout;
+ Gtk::Box m_meta;
Gtk::Entry m_role_name;
+ Gtk::ColorButton m_color_button;
Gtk::Grid m_grid;
std::unordered_map<Permission, GuildSettingsRolesPanePermItem *> m_perm_items;