forked from cafeberry/cafeberry
added some kbm stuff
This commit is contained in:
@@ -39,7 +39,12 @@
|
||||
|
||||
#include "Windows64_Minecraft.h"
|
||||
#include "Xbox/resource.h"
|
||||
#include <vector>
|
||||
#include "..\Common\UI\DirectTextEdit.h"
|
||||
#include "..\Common\UI\UIControl_TextInput.h"
|
||||
#include "..\Common\UI\UIScene.h"
|
||||
|
||||
BOOL g_bResolutionSetByCMD = FALSE;
|
||||
HINSTANCE hMyInst;
|
||||
LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam);
|
||||
char chGlobalText[256];
|
||||
@@ -76,10 +81,53 @@ DWORD dwProfileSettingsA[NUM_PROFILE_VALUES]=
|
||||
//-------------------------------------------------------------------------------------
|
||||
|
||||
BOOL g_bWidescreen = TRUE;
|
||||
BOOL g_bResolutionSetByCMD = FALSE;
|
||||
|
||||
int g_iScreenWidth = 1920;
|
||||
int g_iScreenHeight = 1080;
|
||||
int g_iScreenWidth = 1280;
|
||||
int g_iScreenHeight = 720;
|
||||
|
||||
int g_iWindowClientW = 1280;
|
||||
int g_iWindowClientH = 720;
|
||||
|
||||
static bool s_bEscapeKeyPrev = false;
|
||||
static bool s_bMenuMouseLPrev = false;
|
||||
static bool s_bMenuMouseRPrev = false;
|
||||
static int s_iWheelCarry = 0;
|
||||
|
||||
static void TickMenuNavKeys(int iPad, bool bMenuOpen)
|
||||
{
|
||||
struct NavKey { int vk; int altVk; unsigned int action; bool repeat; bool prev; };
|
||||
static NavKey s_keys[] =
|
||||
{
|
||||
{ 'W', VK_UP, ACTION_MENU_UP, true, false },
|
||||
{ 'S', VK_DOWN, ACTION_MENU_DOWN, true, false },
|
||||
{ 'A', VK_LEFT, ACTION_MENU_LEFT, true, false },
|
||||
{ 'D', VK_RIGHT, ACTION_MENU_RIGHT, true, false },
|
||||
{ 'F', VK_RETURN, ACTION_MENU_OK, false, false },
|
||||
{ 'Q', 0, ACTION_MENU_LEFT_SCROLL, false, false },
|
||||
{ 'E', 0, ACTION_MENU_RIGHT_SCROLL, false, false },
|
||||
};
|
||||
bool bActive = bMenuOpen && !DirectTextEdit::IsActive();
|
||||
for (int i = 0; i < sizeof(s_keys) / sizeof(s_keys[0]); ++i)
|
||||
{
|
||||
NavKey &k = s_keys[i];
|
||||
bool down = InputManager.IsKeyDown(k.vk) || (k.altVk != 0 && InputManager.IsKeyDown(k.altVk));
|
||||
if (bActive)
|
||||
{
|
||||
unsigned int button = InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), k.action);
|
||||
if (k.repeat)
|
||||
{
|
||||
if (down)
|
||||
InputManager.MapTouchInput(iPad, button);
|
||||
}
|
||||
else if (down && !k.prev)
|
||||
{
|
||||
InputManager.MapTouchInput(iPad, button);
|
||||
}
|
||||
}
|
||||
k.prev = down;
|
||||
}
|
||||
}
|
||||
int g_iPendingHotbarScroll = 0;
|
||||
|
||||
void DefineActions(void)
|
||||
{
|
||||
@@ -360,6 +408,94 @@ LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||
pMinecraft->soundEngine->playMusicTick();
|
||||
}
|
||||
break;
|
||||
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (!(lParam & 0x40000000))
|
||||
{
|
||||
InputManager.OnKeyDown((int)wParam);
|
||||
}
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
InputManager.OnKeyUp((int)wParam);
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_CHAR:
|
||||
InputManager.OnChar((wchar_t)wParam);
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_INPUT:
|
||||
{
|
||||
UINT dwSize = 0;
|
||||
GetRawInputData((HRAWINPUT)lParam, RID_INPUT, nullptr, &dwSize, sizeof(RAWINPUTHEADER));
|
||||
if (dwSize > 0 && dwSize <= 256)
|
||||
{
|
||||
BYTE rawBuffer[256];
|
||||
if (GetRawInputData((HRAWINPUT)lParam, RID_INPUT, rawBuffer, &dwSize, sizeof(RAWINPUTHEADER)) == dwSize)
|
||||
{
|
||||
const RAWINPUT* raw = (RAWINPUT*)rawBuffer;
|
||||
if (raw->header.dwType == RIM_TYPEMOUSE)
|
||||
{
|
||||
InputManager.OnRawMouseDelta(raw->data.mouse.lLastX, raw->data.mouse.lLastY);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_SIZE:
|
||||
g_iWindowClientW = LOWORD(lParam);
|
||||
g_iWindowClientH = HIWORD(lParam);
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_MOUSEMOVE:
|
||||
InputManager.OnMouseMove(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_LBUTTONDOWN:
|
||||
InputManager.OnLButtonDown(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_LBUTTONUP:
|
||||
InputManager.OnLButtonUp(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_RBUTTONDOWN:
|
||||
InputManager.OnRButtonDown(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_RBUTTONUP:
|
||||
InputManager.OnRButtonUp(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_MBUTTONDOWN:
|
||||
InputManager.OnMButtonDown(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_MBUTTONUP:
|
||||
InputManager.OnMButtonUp(LOWORD(lParam), HIWORD(lParam));
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_MOUSEWHEEL:
|
||||
{
|
||||
POINT pt = { (SHORT)LOWORD(lParam), (SHORT)HIWORD(lParam) };
|
||||
ScreenToClient(hWnd, &pt);
|
||||
InputManager.OnMouseWheel((short)HIWORD(wParam), pt.x, pt.y);
|
||||
}
|
||||
return DefWindowProc(hWnd, message, wParam, lParam);
|
||||
|
||||
case WM_KILLFOCUS:
|
||||
InputManager.SetWindowFocused(false);
|
||||
if (InputManager.IsMouseCaptured())
|
||||
InputManager.SetMouseCaptured(false);
|
||||
break;
|
||||
|
||||
case WM_SETFOCUS:
|
||||
InputManager.SetWindowFocused(true);
|
||||
break;
|
||||
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
break;
|
||||
@@ -432,6 +568,13 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
|
||||
ShowWindow(g_hWnd, (nCmdShow != SW_HIDE) ? SW_SHOWMAXIMIZED : nCmdShow);
|
||||
UpdateWindow(g_hWnd);
|
||||
|
||||
RECT rcClient;
|
||||
if (GetClientRect(g_hWnd, &rcClient))
|
||||
{
|
||||
g_iWindowClientW = rcClient.right - rcClient.left;
|
||||
g_iWindowClientH = rcClient.bottom - rcClient.top;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -483,6 +626,492 @@ LRESULT CALLBACK DlgProc(HWND hWndDlg, UINT Msg, WPARAM wParam, LPARAM lParam)
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
namespace DirectTextEdit
|
||||
{
|
||||
static UIControl_TextInput *s_ctrl = NULL;
|
||||
static UIControl *s_parent = NULL;
|
||||
static bool s_mousePrev = false;
|
||||
static LineNavCallback s_navCb = NULL;
|
||||
static LPVOID s_navParam = NULL;
|
||||
static CommitCallback s_callback = NULL;
|
||||
static LPVOID s_param = NULL;
|
||||
static wstring s_text;
|
||||
static wstring s_initial;
|
||||
static size_t s_caret = 0;
|
||||
static bool s_selAll = false;
|
||||
static unsigned int s_maxChars = 0;
|
||||
static int s_keyMode = 0;
|
||||
static vector<pair<wstring, size_t> > s_undo;
|
||||
static wstring s_clipboard;
|
||||
static bool s_keyPrev[256] = { false };
|
||||
static int s_repKey = 0;
|
||||
static int s_repDelay = 0;
|
||||
|
||||
static bool s_commitReady = false;
|
||||
static wstring s_commitText;
|
||||
|
||||
enum { UNDO_CAP = 64, REPEAT_DELAY_FRAMES = 24, REPEAT_RATE_FRAMES = 2 };
|
||||
|
||||
static void PushUndo()
|
||||
{
|
||||
if (s_undo.size() >= UNDO_CAP)
|
||||
s_undo.erase(s_undo.begin());
|
||||
s_undo.push_back(make_pair(s_text, s_caret));
|
||||
}
|
||||
|
||||
static bool CharAllowed(wchar_t ch)
|
||||
{
|
||||
if (ch < 0x20 || ch == 0x7F)
|
||||
return false;
|
||||
if (s_keyMode == C_4JInput::EKeyboardMode_Numeric)
|
||||
return (ch >= L'0' && ch <= L'9') || ch == L'-' || ch == L'+';
|
||||
return true;
|
||||
}
|
||||
|
||||
static void PushToFlash()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
s_ctrl->setLabel(s_text.c_str());
|
||||
s_ctrl->SyncCaret((int)s_caret, (int)s_text.length());
|
||||
}
|
||||
|
||||
static void InsertText(const wstring &ins)
|
||||
{
|
||||
if (ins.empty() || !s_ctrl)
|
||||
return;
|
||||
wstring filtered;
|
||||
for (size_t i = 0; i < ins.length(); ++i)
|
||||
if (CharAllowed(ins[i]))
|
||||
filtered += ins[i];
|
||||
if (filtered.empty())
|
||||
return;
|
||||
PushUndo();
|
||||
if (s_selAll)
|
||||
{
|
||||
s_text.clear();
|
||||
s_caret = 0;
|
||||
s_selAll = false;
|
||||
}
|
||||
if (s_text.length() + filtered.length() > s_maxChars)
|
||||
filtered.erase(s_maxChars > s_text.length() ? s_maxChars - s_text.length() : 0);
|
||||
s_text.insert(s_caret, filtered);
|
||||
s_caret += filtered.length();
|
||||
PushToFlash();
|
||||
}
|
||||
|
||||
static void ActBackspace()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
if (s_selAll)
|
||||
{
|
||||
s_selAll = false;
|
||||
if (s_text.empty())
|
||||
return;
|
||||
PushUndo();
|
||||
s_text.clear();
|
||||
s_caret = 0;
|
||||
PushToFlash();
|
||||
return;
|
||||
}
|
||||
if (s_caret == 0)
|
||||
return;
|
||||
PushUndo();
|
||||
s_text.erase(s_caret - 1, 1);
|
||||
--s_caret;
|
||||
PushToFlash();
|
||||
}
|
||||
|
||||
static void ActDelete()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
if (s_selAll)
|
||||
{
|
||||
s_selAll = false;
|
||||
if (s_text.empty())
|
||||
return;
|
||||
PushUndo();
|
||||
s_text.clear();
|
||||
s_caret = 0;
|
||||
PushToFlash();
|
||||
return;
|
||||
}
|
||||
if (s_caret >= s_text.length())
|
||||
return;
|
||||
PushUndo();
|
||||
s_text.erase(s_caret, 1);
|
||||
PushToFlash();
|
||||
}
|
||||
|
||||
static void ActLeft()
|
||||
{
|
||||
if (!s_ctrl || s_caret == 0)
|
||||
{
|
||||
s_selAll = false;
|
||||
return;
|
||||
}
|
||||
s_selAll = false;
|
||||
--s_caret;
|
||||
PushToFlash();
|
||||
}
|
||||
|
||||
static void ActRight()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
s_selAll = false;
|
||||
if (s_caret < s_text.length())
|
||||
{
|
||||
++s_caret;
|
||||
PushToFlash();
|
||||
}
|
||||
}
|
||||
|
||||
static void ActHome()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
s_selAll = false;
|
||||
if (s_caret != 0)
|
||||
{
|
||||
s_caret = 0;
|
||||
PushToFlash();
|
||||
}
|
||||
}
|
||||
|
||||
static void ActEnd()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
s_selAll = false;
|
||||
if (s_caret != s_text.length())
|
||||
{
|
||||
s_caret = s_text.length();
|
||||
PushToFlash();
|
||||
}
|
||||
}
|
||||
|
||||
static void CopyToClipboard(const wstring &s)
|
||||
{
|
||||
s_clipboard = s;
|
||||
InputManager.SetClipboardText(s.c_str());
|
||||
}
|
||||
|
||||
static bool ClipboardText(wstring &out)
|
||||
{
|
||||
wchar_t buf[512];
|
||||
int n = InputManager.GetClipboardText(buf, 512);
|
||||
if (n > 0)
|
||||
{
|
||||
out.assign(buf, n);
|
||||
return true;
|
||||
}
|
||||
if (!s_clipboard.empty())
|
||||
{
|
||||
out = s_clipboard;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool FreshPress(int vk)
|
||||
{
|
||||
return vk >= 0 && vk < 256 && InputManager.IsKeyDown(vk) && !s_keyPrev[vk];
|
||||
}
|
||||
|
||||
static void PollRepeatKey(int vk, void (*action)())
|
||||
{
|
||||
bool down = InputManager.IsKeyDown(vk);
|
||||
if (down && !s_keyPrev[vk])
|
||||
{
|
||||
action();
|
||||
s_repKey = vk;
|
||||
s_repDelay = REPEAT_DELAY_FRAMES;
|
||||
}
|
||||
else if (down && s_repKey == vk)
|
||||
{
|
||||
if (--s_repDelay <= 0)
|
||||
{
|
||||
action();
|
||||
s_repDelay = REPEAT_RATE_FRAMES;
|
||||
}
|
||||
}
|
||||
else if (!down && s_repKey == vk)
|
||||
{
|
||||
s_repKey = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static bool ClickOutsideBox()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return false;
|
||||
UIScene *scene = s_ctrl->getParentScene();
|
||||
if (!scene)
|
||||
return false;
|
||||
float movieW = (float)scene->getMovieWidth();
|
||||
float movieH = (float)scene->getMovieHeight();
|
||||
float fx = (float)InputManager.GetMouseX();
|
||||
float fy = (float)InputManager.GetMouseY();
|
||||
if (movieW > 0.0f && movieH > 0.0f && g_iWindowClientW > 0 && g_iWindowClientH > 0)
|
||||
{
|
||||
fx = fx * (movieW / (float)g_iWindowClientW);
|
||||
fy = fy * (movieH / (float)g_iWindowClientH);
|
||||
}
|
||||
float ox = 0.0f, oy = 0.0f;
|
||||
if (s_parent)
|
||||
{
|
||||
s_parent->UpdateControl();
|
||||
ox = (float)s_parent->getXPos();
|
||||
oy = (float)s_parent->getYPos();
|
||||
}
|
||||
s_ctrl->UpdateControl();
|
||||
float w = (float)s_ctrl->getWidth();
|
||||
float h = (float)s_ctrl->getHeight();
|
||||
if (w < 4.0f || h < 4.0f)
|
||||
return false;
|
||||
float x = ox + (float)s_ctrl->getXPos();
|
||||
float y = oy + (float)s_ctrl->getYPos();
|
||||
return fx < x || fx >= x + w || fy < y || fy >= y + h;
|
||||
}
|
||||
|
||||
void Begin(UIControl_TextInput *ctrl, UIControl *parent,
|
||||
const wchar_t *initialText,
|
||||
unsigned int maxChars, int keyboardMode,
|
||||
CommitCallback callback, LPVOID param)
|
||||
{
|
||||
if (!ctrl)
|
||||
return;
|
||||
if (s_ctrl == ctrl)
|
||||
return;
|
||||
if (s_ctrl)
|
||||
Finish(true);
|
||||
s_ctrl = ctrl;
|
||||
s_parent = parent;
|
||||
s_mousePrev = InputManager.IsMouseLDown();
|
||||
s_callback = callback;
|
||||
s_param = param;
|
||||
s_text = initialText ? initialText : L"";
|
||||
s_initial = s_text;
|
||||
s_caret = s_text.length();
|
||||
s_selAll = false;
|
||||
s_maxChars = maxChars;
|
||||
s_keyMode = keyboardMode;
|
||||
s_undo.clear();
|
||||
memset(s_keyPrev, 0, sizeof(s_keyPrev));
|
||||
s_repKey = 0;
|
||||
ctrl->setFocus(true);
|
||||
PushToFlash();
|
||||
}
|
||||
|
||||
bool IsActive()
|
||||
{
|
||||
return s_ctrl != NULL;
|
||||
}
|
||||
|
||||
void SetLineNav(LineNavCallback callback, LPVOID param)
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
s_navCb = callback;
|
||||
s_navParam = param;
|
||||
}
|
||||
|
||||
static void DoLineNav(int vk, int dir)
|
||||
{
|
||||
LineNavCallback cb = s_navCb;
|
||||
LPVOID p = s_navParam;
|
||||
Finish(true);
|
||||
if (cb)
|
||||
cb(p, dir);
|
||||
s_keyPrev[vk] = true;
|
||||
s_repKey = vk;
|
||||
s_repDelay = REPEAT_DELAY_FRAMES;
|
||||
}
|
||||
|
||||
static void PollNavKey(int vk, int dir)
|
||||
{
|
||||
if (!s_navCb)
|
||||
return;
|
||||
bool down = InputManager.IsKeyDown(vk);
|
||||
if (down && !s_keyPrev[vk])
|
||||
{
|
||||
DoLineNav(vk, dir);
|
||||
}
|
||||
else if (down && s_repKey == vk)
|
||||
{
|
||||
if (--s_repDelay <= 0)
|
||||
{
|
||||
DoLineNav(vk, dir);
|
||||
s_repDelay = REPEAT_RATE_FRAMES;
|
||||
}
|
||||
}
|
||||
else if (!down && s_repKey == vk)
|
||||
{
|
||||
s_repKey = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void Tick()
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
|
||||
s_ctrl->RefreshFocus();
|
||||
|
||||
{
|
||||
UIScene *pinScene = s_ctrl->getParentScene();
|
||||
if (pinScene && s_ctrl->getId() >= 0)
|
||||
pinScene->SetFocusToElement(s_ctrl->getId(), true);
|
||||
}
|
||||
|
||||
bool mouseDown = InputManager.IsMouseLDown();
|
||||
if (mouseDown && !s_mousePrev)
|
||||
{
|
||||
if (ClickOutsideBox())
|
||||
{
|
||||
Finish(true);
|
||||
s_mousePrev = mouseDown;
|
||||
for (int v = 0; v < 256; ++v)
|
||||
s_keyPrev[v] = InputManager.IsKeyDown(v);
|
||||
return;
|
||||
}
|
||||
}
|
||||
s_mousePrev = mouseDown;
|
||||
|
||||
bool ctrlDown = InputManager.IsKeyDown(VK_CONTROL) && !InputManager.IsKeyDown(VK_MENU);
|
||||
if (ctrlDown)
|
||||
{
|
||||
if (FreshPress('A'))
|
||||
{
|
||||
s_selAll = !s_text.empty();
|
||||
}
|
||||
else if (FreshPress('C'))
|
||||
{
|
||||
CopyToClipboard(s_text);
|
||||
}
|
||||
else if (FreshPress('X'))
|
||||
{
|
||||
CopyToClipboard(s_text);
|
||||
if (!s_text.empty())
|
||||
{
|
||||
PushUndo();
|
||||
s_text.clear();
|
||||
s_caret = 0;
|
||||
s_selAll = false;
|
||||
PushToFlash();
|
||||
}
|
||||
}
|
||||
else if (FreshPress('V'))
|
||||
{
|
||||
wstring pasted;
|
||||
if (ClipboardText(pasted))
|
||||
InsertText(pasted);
|
||||
}
|
||||
else if (FreshPress('Z'))
|
||||
{
|
||||
if (!s_undo.empty())
|
||||
{
|
||||
s_text = s_undo.back().first;
|
||||
s_caret = s_undo.back().second;
|
||||
if (s_caret > s_text.length())
|
||||
s_caret = s_text.length();
|
||||
s_undo.pop_back();
|
||||
s_selAll = false;
|
||||
PushToFlash();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (FreshPress(VK_RETURN))
|
||||
{
|
||||
if (s_navCb)
|
||||
{
|
||||
LineNavCallback cb = s_navCb;
|
||||
LPVOID p = s_navParam;
|
||||
Finish(true);
|
||||
cb(p, +1);
|
||||
}
|
||||
else
|
||||
{
|
||||
Finish(true);
|
||||
}
|
||||
}
|
||||
else if (FreshPress(VK_ESCAPE))
|
||||
{
|
||||
Finish(false);
|
||||
}
|
||||
else if (s_ctrl)
|
||||
{
|
||||
int n = InputManager.GetCharCount();
|
||||
if (n > 0)
|
||||
{
|
||||
wstring ins;
|
||||
for (int i = 0; i < n; ++i)
|
||||
ins += InputManager.GetChar(i);
|
||||
InsertText(ins);
|
||||
}
|
||||
PollRepeatKey(VK_BACK, ActBackspace);
|
||||
PollRepeatKey(VK_DELETE, ActDelete);
|
||||
PollRepeatKey(VK_LEFT, ActLeft);
|
||||
PollRepeatKey(VK_RIGHT, ActRight);
|
||||
PollRepeatKey(VK_HOME, ActHome);
|
||||
PollRepeatKey(VK_END, ActEnd);
|
||||
PollNavKey(VK_UP, -1);
|
||||
PollNavKey(VK_DOWN, +1);
|
||||
}
|
||||
|
||||
for (int v = 0; v < 256; ++v)
|
||||
s_keyPrev[v] = InputManager.IsKeyDown(v);
|
||||
}
|
||||
|
||||
void Finish(bool accepted)
|
||||
{
|
||||
if (!s_ctrl)
|
||||
return;
|
||||
UIControl_TextInput *ctrl = s_ctrl;
|
||||
s_ctrl = NULL;
|
||||
if (!accepted)
|
||||
{
|
||||
s_text = s_initial;
|
||||
s_caret = 0;
|
||||
ctrl->setLabel(s_text.c_str());
|
||||
}
|
||||
ctrl->setFocus(false);
|
||||
if (s_callback)
|
||||
{
|
||||
s_commitReady = true;
|
||||
s_commitText = accepted ? s_text : L"";
|
||||
CommitCallback cb = s_callback;
|
||||
LPVOID p = s_param;
|
||||
s_callback = NULL;
|
||||
s_param = NULL;
|
||||
cb(p, accepted);
|
||||
s_commitReady = false;
|
||||
}
|
||||
s_undo.clear();
|
||||
s_selAll = false;
|
||||
s_repKey = 0;
|
||||
s_navCb = NULL;
|
||||
s_navParam = NULL;
|
||||
}
|
||||
|
||||
bool TakeText(uint16_t *outText, unsigned int outCapacity)
|
||||
{
|
||||
if (!s_commitReady || !outText || outCapacity == 0)
|
||||
return false;
|
||||
unsigned int n = (unsigned int)s_commitText.length();
|
||||
if (n >= outCapacity)
|
||||
n = outCapacity - 1;
|
||||
for (unsigned int i = 0; i < n; ++i)
|
||||
outText[i] = (uint16_t)s_commitText[i];
|
||||
outText[n] = 0;
|
||||
return true;
|
||||
}
|
||||
};
|
||||
|
||||
//--------------------------------------------------------------------------------------
|
||||
// Create Direct3D device and swap chain
|
||||
//--------------------------------------------------------------------------------------
|
||||
@@ -647,6 +1276,17 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
UNREFERENCED_PARAMETER(hPrevInstance);
|
||||
UNREFERENCED_PARAMETER(lpCmdLine);
|
||||
|
||||
{
|
||||
HMODULE hShcore = LoadLibraryW(L"Shcore.dll");
|
||||
if (hShcore)
|
||||
{
|
||||
typedef HRESULT (STDAPICALLTYPE *SetProcDpiAwareFn)(int);
|
||||
SetProcDpiAwareFn pFn = (SetProcDpiAwareFn)GetProcAddress(hShcore, "SetProcessDpiAwareness");
|
||||
if (pFn) pFn(2);
|
||||
FreeLibrary(hShcore);
|
||||
}
|
||||
}
|
||||
|
||||
if(lpCmdLine)
|
||||
{
|
||||
if(lpCmdLine[0] == '1')
|
||||
@@ -975,12 +1615,13 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
MSG msg = {0};
|
||||
while( WM_QUIT != msg.message )
|
||||
{
|
||||
if( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
|
||||
while( PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ) )
|
||||
{
|
||||
if (msg.message == WM_QUIT) break;
|
||||
TranslateMessage( &msg );
|
||||
DispatchMessage( &msg );
|
||||
continue;
|
||||
}
|
||||
if (msg.message == WM_QUIT) break;
|
||||
RenderManager.StartFrame();
|
||||
#if 0
|
||||
if(pMinecraft->soundEngine->isStreamingWavebankReady() &&
|
||||
@@ -1000,6 +1641,117 @@ int APIENTRY _tWinMain(_In_ HINSTANCE hInstance,
|
||||
// }
|
||||
|
||||
app.UpdateTime();
|
||||
|
||||
if (app.GetGameStarted())
|
||||
{
|
||||
int iPad = ProfileManager.GetPrimaryPad();
|
||||
TickMenuNavKeys(iPad, ui.GetMenuDisplayed(iPad) || pMinecraft->screen != NULL);
|
||||
if (ui.GetMenuDisplayed(iPad) || pMinecraft->screen != NULL)
|
||||
{
|
||||
if (InputManager.IsKeyDown(VK_ESCAPE) && !s_bEscapeKeyPrev && !DirectTextEdit::IsActive())
|
||||
{
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_CANCEL));
|
||||
}
|
||||
|
||||
bool bMouseL = InputManager.IsMouseLDown();
|
||||
bool bMouseR = InputManager.IsMouseRDown();
|
||||
if (bMouseL && !s_bMenuMouseLPrev)
|
||||
{
|
||||
if (InputManager.IsKeyDown(VK_SHIFT))
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_Y));
|
||||
else if (!ui.IsCraftingMenuDisplayed(iPad))
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_A));
|
||||
}
|
||||
if (bMouseR && !s_bMenuMouseRPrev)
|
||||
{
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_X));
|
||||
}
|
||||
s_bMenuMouseLPrev = bMouseL;
|
||||
s_bMenuMouseRPrev = bMouseR;
|
||||
|
||||
int iWheelMenu = InputManager.GetMouseWheelDelta();
|
||||
if (iWheelMenu > 0)
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_UP));
|
||||
else if (iWheelMenu < 0)
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_DOWN));
|
||||
s_iWheelCarry = 0;
|
||||
g_iPendingHotbarScroll = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (InputManager.IsMouseLDown()) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_ACTION));
|
||||
if (InputManager.IsMouseRDown()) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_USE));
|
||||
if (!DirectTextEdit::IsActive())
|
||||
{
|
||||
if (InputManager.IsKeyDown('Q')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_DROP));
|
||||
if (InputManager.IsKeyDown(VK_SHIFT)) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_SNEAK_TOGGLE));
|
||||
if (InputManager.IsKeyDown('E')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_INVENTORY));
|
||||
if (InputManager.IsKeyDown('F')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_RENDER_THIRD_PERSON));
|
||||
if (InputManager.IsKeyDown(VK_ESCAPE)) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_PAUSEMENU));
|
||||
if (InputManager.IsKeyDown('R')) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_CRAFTING));
|
||||
if (InputManager.IsKeyDown(VK_TAB)) InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), MINECRAFT_ACTION_GAME_INFO));
|
||||
}
|
||||
s_iWheelCarry += InputManager.GetMouseWheelDelta();
|
||||
int iNewNotches = s_iWheelCarry / 120;
|
||||
if (iNewNotches != 0)
|
||||
{
|
||||
s_iWheelCarry -= iNewNotches * 120;
|
||||
g_iPendingHotbarScroll += iNewNotches;
|
||||
if (g_iPendingHotbarScroll > 12) g_iPendingHotbarScroll = 12;
|
||||
else if (g_iPendingHotbarScroll < -12) g_iPendingHotbarScroll = -12;
|
||||
}
|
||||
}
|
||||
s_bEscapeKeyPrev = InputManager.IsKeyDown(VK_ESCAPE);
|
||||
}
|
||||
else
|
||||
{
|
||||
int iPad = ProfileManager.GetPrimaryPad();
|
||||
TickMenuNavKeys(iPad, ui.GetMenuDisplayed(iPad) ? true : false);
|
||||
if (ui.GetMenuDisplayed(iPad))
|
||||
{
|
||||
if (InputManager.IsKeyDown(VK_ESCAPE) && !s_bEscapeKeyPrev && !DirectTextEdit::IsActive())
|
||||
{
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_CANCEL));
|
||||
}
|
||||
|
||||
bool bMouseL = InputManager.IsMouseLDown();
|
||||
bool bMouseR = InputManager.IsMouseRDown();
|
||||
if (bMouseL && !s_bMenuMouseLPrev)
|
||||
{
|
||||
if (!ui.IsSkinSelectMenuDisplayed(iPad))
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OK));
|
||||
}
|
||||
s_bMenuMouseLPrev = bMouseL;
|
||||
s_bMenuMouseRPrev = bMouseR;
|
||||
|
||||
int iWheelMenu = InputManager.GetMouseWheelDelta();
|
||||
if (iWheelMenu > 0)
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_UP));
|
||||
else if (iWheelMenu < 0)
|
||||
InputManager.MapTouchInput(iPad, InputManager.GetGameJoypadMaps(InputManager.GetJoypadMapVal(iPad), ACTION_MENU_OTHER_STICK_DOWN));
|
||||
}
|
||||
s_bEscapeKeyPrev = InputManager.IsKeyDown(VK_ESCAPE);
|
||||
}
|
||||
|
||||
{
|
||||
int iPad = ProfileManager.GetPrimaryPad();
|
||||
bool bPointerMenu = ui.IsContainerMenuDisplayed(iPad) && !ui.IsCraftingMenuDisplayed(iPad);
|
||||
if (bPointerMenu && !InputManager.IsMouseCaptured())
|
||||
{
|
||||
while (ShowCursor(FALSE) >= 0) {}
|
||||
}
|
||||
else if (!InputManager.IsMouseCaptured())
|
||||
{
|
||||
while (ShowCursor(TRUE) < 0) {}
|
||||
}
|
||||
}
|
||||
|
||||
DirectTextEdit::Tick();
|
||||
|
||||
PIXBeginNamedEvent(0,"Input manager tick mouse");
|
||||
InputManager.TickKBM();
|
||||
PIXEndNamedEvent();
|
||||
|
||||
PIXBeginNamedEvent(0,"Input manager tick");
|
||||
InputManager.Tick();
|
||||
PIXEndNamedEvent();
|
||||
|
||||
Reference in New Issue
Block a user