Skip to content

Commit

Permalink
-fixed generic WndProc for modules
Browse files Browse the repository at this point in the history
-implemented automatic away/online status
  • Loading branch information
HasKha committed May 2, 2017
1 parent 620c090 commit 0aad62b
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 12 deletions.
18 changes: 12 additions & 6 deletions GWToolbox/GWToolbox/GWToolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@

#include <Windows\Minimap\Minimap.h>

#include "Panels\HotkeyPanel.h"

#include "GuiUtils.h"

namespace {
Expand Down Expand Up @@ -180,7 +178,9 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
switch (Message) {
// Send button up mouse events to both gw and imgui, to avoid gw being stuck on mouse-down
case WM_LBUTTONUP:
Minimap::Instance().WndProc(Message, wParam, lParam);
for (ToolboxModule* m : tb.GetModules()) {
m->WndProc(Message, wParam, lParam);
}
break;

// Send other mouse events to imgui first and consume them if used
Expand All @@ -190,7 +190,11 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
case WM_MOUSEWHEEL:
if (!right_mouse_down) {
if (io.WantCaptureMouse) return true;
if (Minimap::Instance().WndProc(Message, wParam, lParam)) return true;
bool captured = false;
for (ToolboxModule* m : tb.GetModules()) {
if (m->WndProc(Message, wParam, lParam)) captured = true;
}
if (captured) return true;
}
break;

Expand All @@ -217,8 +221,10 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT Message, WPARAM wParam, LPARAM lParam)
return true;
}

// send input to toolbox to trigger hotkeys
HotkeyPanel::Instance().WndProc(Message, wParam, lParam);
// send to toolbox modules
for (ToolboxModule* m : tb.GetModules()) {
m->WndProc(Message, wParam, lParam);
}

// block alt-enter if in borderless to avoid graphic glitches (no reason to go fullscreen anyway)
if (GameSettings::Instance().borderless_window
Expand Down
49 changes: 44 additions & 5 deletions GWToolbox/GWToolbox/OtherModules/GameSettings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <GWCA\Managers\PartyMgr.h>
#include <GWCA\Managers\AgentMgr.h>
#include <GWCA\Managers\StoCMgr.h>
#include <GWCA\Managers\FriendListMgr.h>

#include <logger.h>
#include "GuiUtils.h"
Expand Down Expand Up @@ -117,7 +118,6 @@ void GameSettings::Initialize() {

GW::StoC::AddCallback<GW::Packet::StoC::P444>(
[](GW::Packet::StoC::P444*) -> bool {
printf("Received P444\n");
if (GameSettings::Instance().flash_window_on_party_invite) FlashWindow();
return false;
});
Expand All @@ -129,10 +129,6 @@ void GameSettings::Initialize() {
});
}

void GameSettings::Terminate() {
ToolboxModule::Terminate();
}

void GameSettings::LoadSettings(CSimpleIni* ini) {
ToolboxModule::LoadSettings(ini);
borderless_window = ini->GetBoolValue(Name(), "borderlesswindow", false);
Expand All @@ -143,6 +139,9 @@ void GameSettings::LoadSettings(CSimpleIni* ini) {
flash_window_on_pm = ini->GetBoolValue(Name(), "flash_window_on_pm", true);
flash_window_on_party_invite = ini->GetBoolValue(Name(), "flash_window_on_party_invite", true);
flash_window_on_zoning = ini->GetBoolValue(Name(), "flash_window_on_zoning", true);
auto_set_away = ini->GetBoolValue(Name(), "auto_set_away", false);
auto_set_away_delay = ini->GetLongValue(Name(), "auto_set_away_delay", 10);
auto_set_online = ini->GetBoolValue(Name(), "auto_set_online", false);

ApplyBorderless(borderless_window);
if (open_template_links) GW::Chat::SetOpenLinks(open_template_links);
Expand All @@ -162,6 +161,9 @@ void GameSettings::SaveSettings(CSimpleIni* ini) {
ini->SetBoolValue(Name(), "flash_window_on_pm", flash_window_on_pm);
ini->SetBoolValue(Name(), "flash_window_on_party_invite", flash_window_on_party_invite);
ini->SetBoolValue(Name(), "flash_window_on_zoning", flash_window_on_zoning);
ini->SetBoolValue(Name(), "auto_set_away", auto_set_away);
ini->SetLongValue(Name(), "auto_set_away_delay", auto_set_away_delay);
ini->SetBoolValue(Name(), "auto_set_online", auto_set_online);
}

void GameSettings::DrawSettingInternal() {
Expand Down Expand Up @@ -192,12 +194,26 @@ void GameSettings::DrawSettingInternal() {
ImGui::ShowHelp("Double clicking on the author of a message in chat will target the author");

ImGui::Text("Flash Guild Wars taskbar icon when:");
ImGui::Indent();
ImGui::ShowHelp("Only triggers when Guild Wars is not the active window");
if (ImGui::Checkbox("Receiving a private message", &flash_window_on_pm)) {
GW::Chat::SetWhisperCallback(&WhisperCallback);
}
ImGui::Checkbox("Receiving a party invite", &flash_window_on_party_invite);
ImGui::Checkbox("Zoning in a new map", &flash_window_on_zoning);
ImGui::Unindent();

ImGui::Checkbox("Automatically set 'Away' after ", &auto_set_away);
ImGui::SameLine();
ImGui::PushItemWidth(50);
ImGui::InputInt("##awaydelay", &auto_set_away_delay, 0);
ImGui::PopItemWidth();
ImGui::SameLine();
ImGui::Text("minutes of inactivity");
ImGui::ShowHelp("Only if you were 'Online'");

ImGui::Checkbox("Automatically set 'Online' after an input to Guild Wars", &auto_set_online);
ImGui::ShowHelp("Only if you were 'Away'");
}

void GameSettings::DrawBorderlessSetting() {
Expand Down Expand Up @@ -241,3 +257,26 @@ void GameSettings::ApplyBorderless(bool value) {
}
}
}

void GameSettings::Update() {
if (auto_set_away
&& TIMER_DIFF(activity_timer) > auto_set_away_delay * 60000
&& GW::FriendListMgr::GetMyStatus() == (DWORD)GW::Constants::OnlineStatus::ONLINE) {
GW::FriendListMgr::SetFriendListStatus(GW::Constants::OnlineStatus::AWAY);
activity_timer = TIMER_INIT(); // refresh the timer to avoid spamming in case the set status call fails
}
}

bool GameSettings::WndProc(UINT Message, WPARAM wParam, LPARAM lParam) {

activity_timer = TIMER_INIT();
static clock_t set_online_timer = TIMER_INIT();
if (auto_set_online
&& TIMER_DIFF(set_online_timer) > 5000 // to avoid spamming in case of failure
&& GW::FriendListMgr::GetMyStatus() == (DWORD)GW::Constants::OnlineStatus::AWAY) {
GW::FriendListMgr::SetFriendListStatus(GW::Constants::OnlineStatus::ONLINE);
set_online_timer = TIMER_INIT();
}

return false;
}
12 changes: 11 additions & 1 deletion GWToolbox/GWToolbox/OtherModules/GameSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <GWCA\Managers\ChatMgr.h>

#include "ToolboxModule.h"
#include <Timer.h>

class GameSettings : public ToolboxModule {
GameSettings() {};
Expand All @@ -19,11 +20,14 @@ class GameSettings : public ToolboxModule {
const char* Name() const override { return "Game Settings"; }

void Initialize() override;
void Terminate() override;
void LoadSettings(CSimpleIni* ini) override;
void SaveSettings(CSimpleIni* ini) override;
void DrawSettingInternal() override;

void Update() override;
bool WndProc(UINT Message, WPARAM wParam, LPARAM lParam);


void DrawBorderlessSetting();

// some settings that are either referenced from multiple places
Expand All @@ -33,10 +37,16 @@ class GameSettings : public ToolboxModule {
bool auto_transform_url;
bool tick_is_toggle = false;
bool select_with_chat_doubleclick = false;

bool flash_window_on_pm = false;
bool flash_window_on_party_invite = false;
bool flash_window_on_zoning = false;

bool auto_set_away = false;
int auto_set_away_delay = 10;
bool auto_set_online = false;
clock_t activity_timer = 0;

void ApplyBorderless(bool value);

private:
Expand Down

0 comments on commit 0aad62b

Please sign in to comment.