spidey-decomp/PCShell.cpp

313 lines
5.8 KiB
C++
Raw Permalink Normal View History

2024-08-04 15:01:59 +00:00
#include "PCShell.h"
2024-08-25 11:03:40 +00:00
#include "dcshellutils.h"
#include "PCInput.h"
#include "SpideyDX.h"
2024-08-25 16:37:27 +00:00
#include "front.h"
#include "DXsound.h"
2024-08-25 17:16:16 +00:00
#include "pshell.h"
#include "PCGfx.h"
#include "shell.h"
#include <cstring>
2024-08-25 11:03:40 +00:00
2024-08-25 16:02:10 +00:00
#include "validate.h"
2024-08-25 11:03:40 +00:00
EXPORT Sprite2* gCursorSprite;
EXPORT i32 gShellMouseX;
EXPORT i32 gShellMouseY;
2024-08-04 15:01:59 +00:00
2024-08-25 11:24:16 +00:00
EXPORT i32 gShellMouseOffsetX;
EXPORT i32 gShellMouseOffsetY;
const i32 MOUSE_TRIGGER_COUNT = 18;
EXPORT u8 gMouseTriggerRelated[MOUSE_TRIGGER_COUNT];
2024-08-25 16:37:27 +00:00
const i32 ACTION_MAP_COUNT = 11;
EXPORT SActionMap gActionMaps[ACTION_MAP_COUNT];
EXPORT char gKeyNames[ACTION_MAP_COUNT][32];
EXPORT CMenu* gControllerMenu;
EXPORT CMenu* gControllerMenuTwo;
EXPORT i32 gActionMapRelated;
2024-08-25 17:16:16 +00:00
char* STR_KB_CONFIG = "keyboard configuration";
char* STR_JOY_CONFIG = "joystick configuration";
EXPORT i32 gShellTitleBarRelated;
2024-08-04 15:01:59 +00:00
// @MEDIUMTODO
void PCSHELL_CheckTriggers(u32,i32,i32)
{
printf("PCSHELL_CheckTriggers(uint,i32,i32)");
}
2024-08-25 20:03:16 +00:00
// @Ok
INLINE void PCSHELL_CoordsDCtoPC(i32* pX, i32* pY)
2024-08-04 15:01:59 +00:00
{
2024-08-25 20:03:16 +00:00
*pX = (double)*pX / 512.0 * (double)gDxResolutionX;
*pY = (double)*pY / 240.0 * (double)gDxResolutionY;
2024-08-04 15:01:59 +00:00
}
2024-08-25 20:09:12 +00:00
// @Ok
// @Matching
INLINE void PCSHELL_CoordsPCtoDC(i32* pX, i32* pY)
2024-08-04 15:01:59 +00:00
{
2024-08-25 20:09:12 +00:00
*pX = (float)(*pX * 512) / (float)gDxResolutionX;
*pY = (float)(*pY * 240) / (float)gDxResolutionY;
2024-08-04 15:01:59 +00:00
}
// @SMALLTODO
void PCSHELL_DoControllerConfig(bool)
{
printf("PCSHELL_DoControllerConfig(bool)");
}
// @MEDIUMTODO
void PCSHELL_DoDisplayOptions(void)
{
printf("PCSHELL_DoDisplayOptions(void)");
}
2024-08-25 11:10:41 +00:00
// @Ok
2024-08-04 15:01:59 +00:00
void PCSHELL_DrawMouseCursor(void)
{
2024-08-25 11:10:41 +00:00
if (!(gRenderTest & 0x10) && gCursorSprite)
{
gCursorSprite->draw(gShellMouseX, gShellMouseY, 0, 0);
}
2024-08-04 15:01:59 +00:00
}
2024-08-25 11:03:40 +00:00
// @Ok
2024-08-04 15:01:59 +00:00
void PCSHELL_Initialize(void)
{
2024-08-25 11:03:40 +00:00
if (!gCursorSprite)
{
gCursorSprite = new Sprite2("lti\\cursor.bmp", 0, 0, 0, 33);
PCINPUT_SetMouseHotspot(15, 15);
PCINPUT_SetMouseBounds(0, 0, gDxResolutionX - 32, gDxResolutionY - 32);
PCINPUT_SetMousePosition((gDxResolutionX - 32) >> 1, (gDxResolutionY - 32) >> 1);
}
PCINPUT_GetMousePosition(&gShellMouseX, &gShellMouseY);
PCSHELL_CoordsPCtoDC(&gShellMouseX, &gShellMouseY);
2024-08-04 15:01:59 +00:00
}
2024-08-25 19:55:52 +00:00
// @Ok
u8 PCSHELL_IsMouseOver(
i32 a1,
i32 a2,
i32 a3,
i32 a4)
2024-08-04 15:01:59 +00:00
{
2024-08-25 19:55:52 +00:00
i32 s1 = a1;
i32 s2 = a2;
i32 s3 = a3;
i32 s4 = a4;
if (gRenderTest & 0x10)
return 0;
PCSHELL_CoordsDCtoPC(&s1, &s2);
PCSHELL_CoordsDCtoPC(&s3, &s4);
return PCINPUT_IsMouseOver(s1, s2, s3, s4);
2024-08-04 15:01:59 +00:00
}
// @SMALLTODO
void PCSHELL_IsMouseOverText(char const *,i32,i32,i32)
{
printf("PCSHELL_IsMouseOverText(char const *,i32,i32,i32)");
}
2024-08-25 13:53:11 +00:00
// @Ok
// @Matching
i32 PCSHELL_MouseMoved(void)
2024-08-04 15:01:59 +00:00
{
2024-08-25 13:53:11 +00:00
return gShellMouseOffsetX || gShellMouseOffsetY;
2024-08-04 15:01:59 +00:00
}
2024-08-25 13:51:48 +00:00
// @Ok
// @Matching
2024-08-04 15:01:59 +00:00
void PCSHELL_Relax(void)
{
2024-08-25 13:51:48 +00:00
WinYield();
Sleep(10);
2024-08-04 15:01:59 +00:00
}
2024-08-25 11:25:52 +00:00
// @Ok
// @Matching
2024-08-04 15:01:59 +00:00
void PCSHELL_Shutdown(void)
{
2024-08-25 11:25:52 +00:00
if (gCursorSprite)
{
delete gCursorSprite;
gCursorSprite = 0;
}
2024-08-04 15:01:59 +00:00
}
2024-08-25 11:24:16 +00:00
// @Ok
u8 PCSHELL_UpdateMouse(void)
2024-08-04 15:01:59 +00:00
{
2024-08-25 11:24:16 +00:00
for (i32 i = 0;
i < MOUSE_TRIGGER_COUNT;
i++)
{
gMouseTriggerRelated[i] = 0;
}
if (!(gRenderTest & 0x10))
{
if (PCINPUT_UpdateMouse())
{
i32 oldMouseX = gShellMouseX;
i32 oldMouseY = gShellMouseY;
PCINPUT_GetMousePosition(&gShellMouseX, &gShellMouseY);
PCSHELL_CoordsPCtoDC(&gShellMouseX, &gShellMouseY);
gShellMouseOffsetX = gShellMouseX - oldMouseX;
gShellMouseOffsetY = gShellMouseY - oldMouseY;
return 1;
}
else
{
gShellMouseOffsetX = 0;
gShellMouseOffsetY = 0;
}
}
return 0;
2024-08-04 15:01:59 +00:00
}
2024-08-25 17:16:16 +00:00
// @IGNORE
void shell_optimized_func(i32, i32, i32)
{
printf("void shell_optimized_func(i32, i32, i32)");
}
// @Ok
2024-08-04 15:01:59 +00:00
void displayControllerScreen(void)
{
2024-08-25 17:16:16 +00:00
if (!gSceneRelated)
PCGfx_BeginScene(1, -1);
PShell_NormalFont();
gControllerMenu->Display();
gControllerMenuTwo->Display();
shell_optimized_func(384, 222, 0);
char *configName = STR_KB_CONFIG;
if (gActionMapRelated)
configName = STR_JOY_CONFIG;
Shell_DrawTitleBar(gShellTitleBarRelated, 25, configName, 1, 0, 150, -21, 29);
Shell_DrawBackground();
PCSHELL_DrawMouseCursor();
if (gSceneRelated)
PCGfx_EndScene(1);
2024-08-04 15:01:59 +00:00
}
2024-08-25 16:37:27 +00:00
// @NotOk
// missing last addentry
2024-08-04 15:01:59 +00:00
void initActionMaps(void)
{
2024-08-25 16:37:27 +00:00
for (
i32 i = 0;
i < ACTION_MAP_COUNT;
i++)
{
SActionMap *pMap = &gActionMaps[i];
PCINPUT_GetKeyboardMappingForAction(pMap->field_0, &pMap->field_14);
PCINPUT_GetControllerMappingForAction(pMap->field_0, &pMap->field_18);
gControllerMenu->AddEntry(pMap->field_4);
if (!gActionMapRelated)
{
if (pMap->field_14 == 0x4000)
{
gControllerMenuTwo->SetNormalColor(i, 90, 20, 6);
strcpy(gKeyNames[i], "none");
}
else
{
DXINPUT_GetKeyName(pMap->field_14, gKeyNames[i]);
}
}
else
{
if (i < 4)
{
gControllerMenu->EntryEnable(i, 0);
gControllerMenuTwo->EntryEnable(i, 0);
strcpy(gKeyNames[i], pMap->field_4);
}
else
{
if (pMap->field_18 == 0x4000)
{
gControllerMenuTwo->SetNormalColor(i, 90, 20, 6);
strcpy(gKeyNames[i], "none");
}
else
{
sprintf(gKeyNames[i], "button %i", pMap->field_18);
}
}
}
gControllerMenuTwo->AddEntry(gKeyNames[i]);
}
gControllerMenu->AddEntry("restore default settings");
//@FIXME: figure out the string
//gControllerMenuTwo->AddEntry("");
2024-08-04 15:01:59 +00:00
}
// @MEDIUMTODO
void processControllerScreen(void)
{
printf("processControllerScreen(void)");
}
2024-08-25 16:46:17 +00:00
// @Ok
// @Matching
void resetActionMaps(bool a1)
2024-08-04 15:01:59 +00:00
{
2024-08-25 16:46:17 +00:00
delete gControllerMenu;
delete gControllerMenuTwo;
gControllerMenu = new CMenu(30, 60, 1u, 256, 256, 15);
gControllerMenuTwo = new CMenu(332, 60, 1u, 256, 256, 15);
initActionMaps();
gControllerMenuTwo->scrollbar_zero = 0;
gControllerMenu->scrollbar_zero = 0;
gControllerMenu->Zoom(0);
gControllerMenuTwo->Zoom(0);
gControllerMenuTwo->mLine = a1 != 0 ? 0 : 4;
gControllerMenu->mLine = gControllerMenuTwo->mLine;
2024-08-04 15:01:59 +00:00
}
2024-08-25 16:02:10 +00:00
void validate_SActionMap(void)
{
VALIDATE_SIZE(SActionMap, 0x1C);
VALIDATE(SActionMap, field_0, 0x0);
VALIDATE(SActionMap, field_4, 0x4);
VALIDATE(SActionMap, field_14, 0x14);
2024-08-25 16:37:27 +00:00
VALIDATE(SActionMap, field_18, 0x18);
2024-08-25 16:02:10 +00:00
}