优化选择强化逻辑

This commit is contained in:
2026-04-26 19:30:32 +08:00
parent 34c36306fe
commit a5747ff55c
6 changed files with 280 additions and 72 deletions
+68
View File
@@ -29,6 +29,43 @@ static bool FileExists(const std::wstring& path);
static void StopBackgroundMusic();
static void StartBackgroundMusic();
/**
* @brief 将指定滚动偏移按步长调整,并限制在非负范围内。
*/
static void AdjustScrollOffset(int& scrollOffset, int delta)
{
scrollOffset += delta;
if (scrollOffset < 0)
{
scrollOffset = 0;
}
if (scrollOffset > 2400)
{
scrollOffset = 2400;
}
}
/**
* @brief 按当前窗口缩放返回一次滚动操作的像素距离。
*/
static int GetScrollStep(HWND hWnd, int baseStep)
{
RECT clientRect;
GetClientRect(hWnd, &clientRect);
int clientWidth = clientRect.right - clientRect.left;
int clientHeight = clientRect.bottom - clientRect.top;
int scaleX = MulDiv(clientWidth, 1000, WINDOW_CLIENT_WIDTH);
int scaleY = MulDiv(clientHeight, 1000, WINDOW_CLIENT_HEIGHT);
int scale = (scaleX < scaleY) ? scaleX : scaleY;
if (scale < 500)
{
scale = 500;
}
return MulDiv(baseStep, scale, 1000);
}
struct LayoutMetrics
{
int scale;
@@ -886,6 +923,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
{
helpState.selectedIndex = i;
helpState.currentPage = i + 1;
helpScrollOffset = 0;
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
@@ -899,6 +937,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
else if (IsPointInRect(GetHelpBackHintRect(hWnd), mouseX, mouseY))
{
helpState.currentPage = 0;
helpScrollOffset = 0;
InvalidateRect(hWnd, nullptr, FALSE);
}
break;
@@ -1013,6 +1052,25 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
return DefWindowProc(hWnd, message, wParam, lParam);
}
case WM_MOUSEWHEEL:
{
int wheelDelta = GET_WHEEL_DELTA_WPARAM(wParam);
int direction = (wheelDelta > 0) ? -1 : 1;
int scrollStep = GetScrollStep(hWnd, 64);
if (currentScreen == SCREEN_RULES && helpState.currentPage != 0)
{
AdjustScrollOffset(helpScrollOffset, direction * scrollStep);
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
if (currentScreen == SCREEN_PLAYING && currentMode == MODE_ROGUE)
{
AdjustScrollOffset(upgradeListScrollOffset, direction * scrollStep);
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
break;
}
case WM_KEYDOWN:
if (currentScreen == SCREEN_MENU)
{
@@ -1103,6 +1161,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
if (helpState.currentPage == 0)
{
helpState.currentPage = helpState.selectedIndex + 1;
helpScrollOffset = 0;
InvalidateRect(hWnd, nullptr, FALSE);
}
break;
@@ -1116,6 +1175,7 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
else
{
helpState.currentPage = 0;
helpScrollOffset = 0;
}
InvalidateRect(hWnd, nullptr, FALSE);
break;
@@ -1280,6 +1340,14 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
break;
}
if (currentMode == MODE_ROGUE && (wParam == 'J' || wParam == 'K'))
{
int direction = (wParam == 'J') ? 1 : -1;
AdjustScrollOffset(upgradeListScrollOffset, direction * GetScrollStep(hWnd, 52));
InvalidateRect(hWnd, nullptr, FALSE);
break;
}
switch (wParam)
{
case VK_LEFT: