added text input

This commit is contained in:
LIghty 2018-03-24 11:32:30 +01:00
parent 44d51f917f
commit 36229efea5
2 changed files with 57 additions and 13 deletions

View File

@ -23,6 +23,7 @@ public:
ItemVariable(CatVar &variable);
void Change(float amount);
void PutChar(char ch);
virtual void Update() override;
virtual bool ConsumesKey(ButtonCode_t key) override;

View File

@ -66,7 +66,9 @@ bool ItemVariable::ConsumesKey(ButtonCode_t key)
if (capturing)
return true;
if (key == ButtonCode_t::MOUSE_WHEEL_DOWN ||
key == ButtonCode_t::MOUSE_WHEEL_UP || key == ButtonCode_t::MOUSE_FIRST)
key == ButtonCode_t::MOUSE_WHEEL_UP ||
key == ButtonCode_t::KEY_LSHIFT || key == ButtonCode_t::KEY_LCONTROL ||
key >= ButtonCode_t::KEY_FIRST && key <= ButtonCode_t::KEY_BACKSPACE)
return true;
return false;
}
@ -84,11 +86,16 @@ void ItemVariable::OnFocusLose()
capturing = false;
}
void ItemVariable::PutChar(char ch)
{
catvar.SetValue(catvar.GetString() + std::string(1, ch));
}
void ItemVariable::OnKeyPress(ButtonCode_t key, bool repeat)
{
if (capturing)
{
if (key == 70)
if (key == ButtonCode_t::KEY_ESCAPE)
key = (ButtonCode_t) 0;
catvar = (int) key;
capturing = false;
@ -101,32 +108,68 @@ void ItemVariable::OnKeyPress(ButtonCode_t key, bool repeat)
{
case CV_ENUM:
case CV_SWITCH:
change = 1.0f;
break;
case CV_STRING:
{
if (key == ButtonCode_t::KEY_BACKSPACE)
{
std::string val = catvar.GetString();
if (val.length() > 0)
catvar.SetValue(val.substr(0, val.length() - 1));
return;
}
else if (key == ButtonCode_t::KEY_SPACE)
{
PutChar(' ');
return;
}
else
{
char ch = 0;
if (g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LSHIFT) ||
g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_RSHIFT))
ch = GetUpperChar(key);
else
ch = GetChar(key);
if (ch)
PutChar(ch);
}
}
case CV_INT:
case CV_FLOAT:
{
if (catvar.restricted)
{
change = float(catvar.max - catvar.min) / 50.0f;
}
else
{
change = 1.0f;
}
}
if (catvar.type == CV_STRING)
{
}
if (change < 1.0f && catvar.type == CV_INT)
change = 1.0f;
if ((catvar.type == CV_SWITCH && key == ButtonCode_t::MOUSE_FIRST) ||
key == ButtonCode_t::MOUSE_WHEEL_UP)
if (key == ButtonCode_t::MOUSE_WHEEL_UP)
{
if (catvar.type == CV_FLOAT &&
g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LSHIFT))
Change(change * 2);
else if (catvar.type == CV_FLOAT &&
g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LCONTROL))
Change(change / 4);
else
Change(change);
}
else if (key == ButtonCode_t::MOUSE_WHEEL_DOWN)
{
if (catvar.type == CV_FLOAT &&
g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LSHIFT))
Change(-change * 2);
else if (catvar.type == CV_FLOAT &&
g_IInputSystem->IsButtonDown(ButtonCode_t::KEY_LCONTROL))
Change(-change / 4);
else
Change(-change);
}
}