Skip to content

Commit

Permalink
Add wheel action to destroy all free messages
Browse files Browse the repository at this point in the history
  • Loading branch information
timoschwarzer committed Aug 18, 2024
1 parent 54e6fa1 commit 7c78793
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 74 deletions.
20 changes: 10 additions & 10 deletions projects/Core/messages/message_controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ namespace core::messages {
} // namespace

void MessageController::update_time(const MessageData& data, const float delta_time) {
if (data.handle->state == message_handle_t::MessageState::Visible) {
if (data.handle->state == message_handle_t::QueuedMessageState::Visible) {
data.handle->active_time += delta_time;
}

Expand All @@ -74,7 +74,7 @@ namespace core::messages {
}

if (*data.handle->time_left <= 0.f) {
data.handle->state = message_handle_t::MessageState::Finished;
data.handle->state = message_handle_t::QueuedMessageState::Finished;
data.handle->time_left = std::optional<float>();
}
}
Expand All @@ -95,24 +95,24 @@ namespace core::messages {
if (!m_current->info.prioritized && !m_priority_data.empty()) {
// Switch out normal message for prioritized, pausing it.
m_current->message->hide(true);
m_current->handle->state = message_handle_t::MessageState::InterruptedByPriorityMessage;
m_current->handle->state = message_handle_t::QueuedMessageState::InterruptedByPriorityMessage;
m_normal_data.insert(m_normal_data.begin(), *m_current);
m_current = m_priority_data.front();
m_priority_data.erase(m_priority_data.begin());
}

update_time(*m_current, delta_time);
switch (m_current->handle->state) {
case message_handle_t::MessageState::InterruptedByPriorityMessage:
m_current->handle->state = message_handle_t::MessageState::Visible;
case message_handle_t::QueuedMessageState::InterruptedByPriorityMessage:
m_current->handle->state = message_handle_t::QueuedMessageState::Visible;
m_current->message->show(m_current->info.instant_fade, m_current->info.play_sound);
break;
case message_handle_t::MessageState::Queued:
case message_handle_t::QueuedMessageState::Queued:
m_current->handle->time_left = m_current->info.duration;
m_current->handle->state = message_handle_t::MessageState::Visible;
m_current->handle->state = message_handle_t::QueuedMessageState::Visible;
m_current->message->show(m_current->info.instant_fade, m_current->info.play_sound);
break;
case message_handle_t::MessageState::Finished:
case message_handle_t::QueuedMessageState::Finished:
// Clear m_current, so it gets set next time update is run.
m_current->message->hide(m_current->info.instant_fade);
m_current = std::optional<MessageData>();
Expand Down Expand Up @@ -161,7 +161,7 @@ namespace core::messages {
sync = queue.add(std::move(message), std::move(info));
} else {
sync = std::make_shared<message_handle_t>();
sync->state = message_handle_t::MessageState::Visible;
sync->state = message_handle_t::QueuedMessageState::Visible;
sync->time_left = info.duration;
sync->message = message;
message->show(info.instant_fade, info.play_sound);
Expand Down Expand Up @@ -246,7 +246,7 @@ namespace core::messages {

for (auto it = m_unqueued_messages.begin(); it != m_unqueued_messages.end();) {
update_time(*it, delta_time);
if (it->handle->state == message_handle_t::MessageState::Finished) {
if (it->handle->state == message_handle_t::QueuedMessageState::Finished) {
it = m_unqueued_messages.erase(it);
} else {
++it;
Expand Down
14 changes: 7 additions & 7 deletions projects/Core/messages/message_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ namespace core::messages {
const auto max_in_queue = m_max_in_queue.get();
if (max_in_queue.has_value() && m_messages.size() > max_in_queue.value() && !m_active_messages.empty()) {
m_active_messages.front().message->hide();
m_active_messages.front().handle->state = message_handle_t::MessageState::Finished;
m_active_messages.front().handle->state = message_handle_t::QueuedMessageState::Finished;
}

int total_lines = 0;
Expand All @@ -81,7 +81,7 @@ namespace core::messages {
if (max_line_count.has_value() && total_lines_temp >= max_line_count.value()) {
for (auto jit = it; jit != m_active_messages.end(); ++jit) {
jit->info.duration = std::max(jit->handle->active_time, 1.0f);
jit->handle->state = message_handle_t::MessageState::Finished;
jit->handle->state = message_handle_t::QueuedMessageState::Finished;
jit->handle->time_left = jit->info.duration;
jit->handle->active_time = 0;
jit->message->hide(jit->info.instant_fade);
Expand Down Expand Up @@ -152,7 +152,7 @@ namespace core::messages {

bool MessageDisplay::handle_active_message(MessageData& data, int& total_lines, app::Vector3& cursor_position, float fade_out, float delta_time) {
update_time(data, delta_time);
if (data.handle->state != message_handle_t::MessageState::Finished) {
if (data.handle->state != message_handle_t::QueuedMessageState::Finished) {
update_message_position(data, total_lines, cursor_position, delta_time);
data.message->fade_out().set(fade_out);
return true;
Expand All @@ -170,7 +170,7 @@ namespace core::messages {
}

void MessageDisplay::update_time(MessageData& data, float delta_time) {
if (data.handle->state == message_handle_t::MessageState::Visible) {
if (data.handle->state == message_handle_t::QueuedMessageState::Visible) {
data.handle->active_time += delta_time;
}

Expand All @@ -183,7 +183,7 @@ namespace core::messages {
}

if (*data.handle->time_left <= 0.f) {
data.handle->state = message_handle_t::MessageState::Finished;
data.handle->state = message_handle_t::QueuedMessageState::Finished;
data.handle->time_left = std::optional<float>();
}
}
Expand All @@ -203,7 +203,7 @@ namespace core::messages {
cursor_position.y -= data.info.padding.x * cursor_y_direction;

// Animate message box movement if the message is visible
if (data.handle->state == MessageHandle::MessageState::Visible) {
if (data.handle->state == QueuedMessageHandle::QueuedMessageState::Visible) {
// When this message is queued, stall it on the pickup position
data.message->position().set(
modloader::math::lerp(
Expand Down Expand Up @@ -261,7 +261,7 @@ namespace core::messages {
data.message->show(false, data.info.play_sound);
}

data.handle->state = message_handle_t::MessageState::Visible;
data.handle->state = message_handle_t::QueuedMessageState::Visible;
}

int MessageDisplay::get_expand_direction_y_multiplier() const {
Expand Down
8 changes: 4 additions & 4 deletions projects/Core/messages/message_handle.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,20 @@
#include <optional>

namespace core::messages {
struct MessageHandle {
enum class MessageState {
struct QueuedMessageHandle {
enum class QueuedMessageState {
Queued,
InterruptedByPriorityMessage,
Visible,
Finished
};

MessageState state = MessageState::Queued;
QueuedMessageState state = QueuedMessageState::Queued;
std::optional<float> time_left;
float active_time = 0;
std::weak_ptr<api::messages::MessageBox> message;
};
} // namespace core::messages

using message_handle_t = core::messages::MessageHandle;
using message_handle_t = core::messages::QueuedMessageHandle;
using message_handle_ptr_t = std::shared_ptr<message_handle_t>;
14 changes: 11 additions & 3 deletions projects/Randomizer/features/wheel_initialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace randomizer::features::wheel {
set_wheel_item_description(wheel, position, desc);
set_wheel_item_texture(wheel, position, texture);
set_wheel_item_color(wheel, position, 255, 255, 255, 255);
set_wheel_item_callback(wheel, position, WheelBind::Ability1, callback);
set_wheel_item_callback(wheel, position, WheelBind::All, callback);
}

void on_dev_changed() {
Expand Down Expand Up @@ -190,8 +190,16 @@ namespace randomizer::features::wheel {
});
initialize_item(9001, 9, "Force Exit", "Forcibly exit the game.", "file:assets/icons/wheel/force_exit.blue.png",
[](auto, auto, auto) { modloader::shutdown(); });
initialize_item(9001, 10, "Clear messages", "Clears the message queue.", "file:assets/icons/wheel/clear_messages.blue.png",
[](auto, auto, auto) { core::message_controller().clear_central(); });
initialize_item(9001, 10, "Clear messages", "[Ability1] Clear all\n[Ability2] Clear queue\n[Ability3] Clear free", "file:assets/icons/wheel/clear_messages.blue.png",
[](auto, auto, auto bind) {
if (bind == WheelBind::Ability1 || bind == WheelBind::Ability2) {
core::message_controller().clear_central();
}

if (bind == WheelBind::Ability1 || bind == WheelBind::Ability3) {
seed::destroy_free_message_boxes();
}
});
initialize_item(9001, 11, "Next", "Go to next page of actions", "file:assets/icons/wheel/menu.blue.png",
[](auto, auto, auto) { set_active_wheel(9000); });
on_dev_changed();
Expand Down
2 changes: 1 addition & 1 deletion projects/Randomizer/online/multiplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ namespace randomizer::online {
std::shared_ptr<core::api::messages::MessageBox> box = nullptr;
if (message->has_id()) {
auto it = m_message_boxes.find(message->id());
if (it != m_message_boxes.end() && it->second->state != message_handle_t::MessageState::Finished) {
if (it != m_message_boxes.end() && it->second->state != message_handle_t::QueuedMessageState::Finished) {
box = it->second->message.lock();
it->second->time_left = message->time();
}
Expand Down
Loading

0 comments on commit 7c78793

Please sign in to comment.