Skip to content

Commit

Permalink
GameMode: Added more game mode options. Includes automatic process de…
Browse files Browse the repository at this point in the history
…tection and full screen D3D exclusive mode detection. Also, includes options to load layout(s) if wanted.
  • Loading branch information
brianferguson committed Apr 8, 2021
1 parent db41743 commit 43d517c
Show file tree
Hide file tree
Showing 13 changed files with 1,064 additions and 59 deletions.
13 changes: 12 additions & 1 deletion Language/Resource.rc
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,17 @@ STRINGTABLE
ID_STR_BUILTINPLUGINS, STR_BUILTINPLUGINS
ID_STR_LANGUAGEOBSOLETE, STR_LANGUAGEOBSOLETE
ID_STR_HARDWAREACCELERATED, "Use hardware acceleration (Requires restart)"
ID_STR_GAMEMODE, "Game mode"
ID_STR_MEASURE, "Measure"
ID_STR_GAMEMODE, "Game mode"
ID_STR_GAMEMODE_START, "Start game mode"
ID_STR_GAMEMODE_STOP, "Stop game mode"
ID_STR_GAMEMODE_FULLSCREEN, "Full-screen mode"
ID_STR_GAMEMODE_PROCESSLIST, "Additional process list"
ID_STR_GAMEMODE_PROCESSLISTSC, "Additional process list:"
ID_STR_GAMEMODE_SETTINGS_DESC, "You can also manually start/stop game mode by using the tray icon context menu. Manually starting/stopping game mode will uncheck both the ""Full-screen mode"" and ""Process list"" checkbox. You must re-enable those items for Rainmeter to start monitoring them again.\n\nClick the ""Help"" button for more information."
ID_STR_GAMEMODE_ACTIONS_ONSTART, "On start"
ID_STR_GAMEMODE_ACTIONS_ONSTOP, "On stop"
ID_STR_GAMEMODE_ACTIONS_DESC, "Select the action to perform when starting/stopping game mode. ""On start"" can unload all skins or load a layout. ""On stop"" can reload the current layout or another layout."
ID_STR_GAMEMODE_ACTIONS_UNLOADALL, "Unload all skins"
ID_STR_GAMEMODE_ACTIONS_CURRENT, "Load current layout"
}
162 changes: 155 additions & 7 deletions Library/ContextMenu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "../Common/MenuTemplate.h"
#include "../Common/Gfx/Canvas.h"
#include "ContextMenu.h"
#include "GameMode.h"
#include "Meter.h"
#include "Rainmeter.h"
#include "Util.h"
Expand Down Expand Up @@ -55,14 +56,14 @@ void ContextMenu::ShowMenu(POINT pos, Skin* skin)
MENU_ITEM(IDM_DELETELOGFILE, ID_STR_DELETELOGFILE),
MENU_ITEM(IDM_DEBUGLOG, ID_STR_DEBUGMODE)),
MENU_SEPARATOR(),
MENU_ITEM(IDM_TOGGLE_GAMEMODE, ID_STR_GAMEMODE),
MENU_ITEM_GRAYED(0, ID_STR_GAMEMODE),
MENU_SEPARATOR(),
MENU_ITEM(IDM_QUIT, ID_STR_EXIT)
};

static const MenuTemplate s_GameModeMenu[] =
{
MENU_ITEM(IDM_TOGGLE_GAMEMODE, ID_STR_GAMEMODE),
MENU_ITEM_GRAYED(0, ID_STR_GAMEMODE),
MENU_SEPARATOR(),
MENU_ITEM(IDM_QUIT, ID_STR_EXIT)
};
Expand All @@ -72,9 +73,10 @@ void ContextMenu::ShowMenu(POINT pos, Skin* skin)
Rainmeter& rainmeter = GetRainmeter();

// Show context menu, if no actions were executed
HMENU menu = rainmeter.IsInGameMode() ?
MenuTemplate::CreateMenu(s_GameModeMenu, _countof(s_GameModeMenu), GetString) :
MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
HMENU menu = !GetGameMode().IsEnabled() ?
MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString) :
MenuTemplate::CreateMenu(s_GameModeMenu, _countof(s_GameModeMenu), GetString);

if (!menu) return;

m_MenuActive = true;
Expand All @@ -98,9 +100,16 @@ void ContextMenu::ShowMenu(POINT pos, Skin* skin)
m_MenuActive = false;
};

if (rainmeter.IsInGameMode())
int gamePos = GetMenuItemCount(menu) - 3;
HMENU gameMenu = CreateGameModeMenu();
if (gameMenu)
{
DeleteMenu(menu, gamePos, MF_BYPOSITION);
InsertMenu(menu, gamePos, MF_BYPOSITION | MF_POPUP, (UINT_PTR)gameMenu, GetString(ID_STR_GAMEMODE));
}

if (GetGameMode().IsEnabled())
{
CheckMenuItem(menu, IDM_TOGGLE_GAMEMODE, MF_BYCOMMAND | MF_CHECKED);
displayMenu();
return;
}
Expand Down Expand Up @@ -763,3 +772,142 @@ void ContextMenu::ChangeSkinIndex(HMENU menu, int index)
}
}
}

HMENU ContextMenu::CreateGameModeOnStartMenu()
{
static const MenuTemplate s_Menu[] =
{
MENU_ITEM(ID_GAMEMODE_ONSTART_FIRST, ID_STR_GAMEMODE_ACTIONS_UNLOADALL)
};

HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
if (!menu) return nullptr;

std::wstring& action = GetGameMode().GetOnStartAction();
bool checked = false;

const auto& layouts = GetRainmeter().m_Layouts;
if (layouts.size() > 0)
{
InsertMenu(menu, 1, MF_BYPOSITION, MF_SEPARATOR, nullptr);

for (size_t i = 0, isize = layouts.size(); i < isize; ++i)
{
LPCWSTR item = layouts[i].c_str();
UINT pos = (UINT)(i + 2);
InsertMenu(menu, pos, MF_BYPOSITION, ID_GAMEMODE_ONSTART_FIRST + i + 1, item);
if (_wcsicmp(item, action.c_str()) == 0)
{
CheckMenuRadioItem(menu, pos, pos, pos, MF_BYPOSITION);
checked = true;
}
}
}

if (!checked)
{
CheckMenuRadioItem(menu, 0, 0, 0, MF_BYPOSITION);
}

return menu;
}

HMENU ContextMenu::CreateGameModeOnStopMenu()
{
static const MenuTemplate s_Menu[] =
{
MENU_ITEM(ID_GAMEMODE_ONSTOP_FIRST, ID_STR_GAMEMODE_ACTIONS_CURRENT)
};

HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
if (!menu) return nullptr;

std::wstring& action = GetGameMode().GetOnStopAction();
bool checked = false;

const auto& layouts = GetRainmeter().m_Layouts;
if (layouts.size() > 0)
{
InsertMenu(menu, 1, MF_BYPOSITION, MF_SEPARATOR, nullptr);

for (size_t i = 0, isize = layouts.size(); i < isize; ++i)
{
LPCWSTR item = layouts[i].c_str();
UINT pos = (UINT)(i + 2);
InsertMenu(menu, pos, MF_BYPOSITION, ID_GAMEMODE_ONSTOP_FIRST + i + 1, item);
if (_wcsicmp(item, action.c_str()) == 0)
{
CheckMenuRadioItem(menu, pos, pos, pos, MF_BYPOSITION);
checked = true;
}
}
}

if (!checked)
{
CheckMenuRadioItem(menu, 0, 0, 0, MF_BYPOSITION);
}

return menu;
}

HMENU ContextMenu::CreateGameModeMenu()
{
static const MenuTemplate s_Menu[] =
{
MENU_ITEM(IDM_GAMEMODE_START, ID_STR_GAMEMODE_START),
MENU_SEPARATOR(),
MENU_ITEM_GRAYED(IDM_GAMEMODE_FULLSCREEN, ID_STR_GAMEMODE_FULLSCREEN),
MENU_ITEM_GRAYED(IDM_GAMEMODE_PROCESSLIST, ID_STR_GAMEMODE_PROCESSLIST),
MENU_SEPARATOR(),
MENU_ITEM_GRAYED(0, ID_STR_GAMEMODE_ACTIONS_ONSTART),
MENU_ITEM_GRAYED(0, ID_STR_GAMEMODE_ACTIONS_ONSTOP)
};

HMENU menu = MenuTemplate::CreateMenu(s_Menu, _countof(s_Menu), GetString);
if (!menu) return nullptr;

GameMode& game = GetGameMode();
bool enabled = game.IsEnabled();

// If game is enabled (or in layout mode), change item 0 to "Disable"
if (!game.IsDisabled())
{
DeleteMenu(menu, 0, MF_BYPOSITION);
InsertMenu(menu, 0, MF_BYPOSITION, IDM_GAMEMODE_STOP, GetString(ID_STR_GAMEMODE_STOP));
}

// Tick the settings
if (game.GetFullScreenMode())
{
CheckMenuItem(menu, IDM_GAMEMODE_FULLSCREEN, MF_BYCOMMAND | MF_CHECKED);
}

if (game.GetProcessListMode())
{
CheckMenuItem(menu, IDM_GAMEMODE_PROCESSLIST, MF_BYCOMMAND | MF_CHECKED);
}

// Only allow changing of settings if not enabled (layout enabled or disabled is okay)
if (!game.IsEnabled())
{
EnableMenuItem(menu, IDM_GAMEMODE_FULLSCREEN, MF_ENABLED);
EnableMenuItem(menu, IDM_GAMEMODE_PROCESSLIST, MF_ENABLED);

HMENU activateMenu = CreateGameModeOnStartMenu();
if (activateMenu)
{
DeleteMenu(menu, 5, MF_BYPOSITION);
InsertMenu(menu, 5, MF_BYPOSITION | MF_POPUP, (UINT_PTR)activateMenu, GetString(ID_STR_GAMEMODE_ACTIONS_ONSTART));
}

HMENU deactivateMenu = CreateGameModeOnStopMenu();
if (deactivateMenu)
{
DeleteMenu(menu, 6, MF_BYPOSITION);
InsertMenu(menu, 6, MF_BYPOSITION | MF_POPUP, (UINT_PTR)deactivateMenu, GetString(ID_STR_GAMEMODE_ACTIONS_ONSTOP));
}
}

return menu;
}
5 changes: 5 additions & 0 deletions Library/ContextMenu.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ class ContextMenu

static void CreateMonitorMenu(HMENU monitorMenu, Skin* skin);

static HMENU CreateGameModeOnStartMenu();
static HMENU CreateGameModeOnStopMenu();

private:
static void DisplayMenu(POINT pos, HMENU menu, HWND parentWindow);

Expand All @@ -43,6 +46,8 @@ class ContextMenu

static void CreateFavoritesMenu(HMENU favoriteMenu) { CreateSkinsMenuRecursive(favoriteMenu, 0, true); }

static HMENU CreateGameModeMenu();

bool m_MenuActive;
};

Expand Down
Loading

0 comments on commit 43d517c

Please sign in to comment.