mirror of https://github.com/ENSL/NS.git
SDL ChatPanel
This commit is contained in:
parent
ac85878fa9
commit
32506d863b
Binary file not shown.
|
@ -2384,11 +2384,11 @@ bool TeamFortressViewport::SlotInput( int iSlot )
|
||||||
// Direct Key Input
|
// Direct Key Input
|
||||||
int TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrentBinding )
|
int TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrentBinding )
|
||||||
{
|
{
|
||||||
/*@linux remove chat
|
|
||||||
if (m_chatPanel->isVisible())
|
if (m_chatPanel->isVisible())
|
||||||
{
|
{
|
||||||
// Don't let the game handle the input while the user is typing in the
|
// Don't let the game handle the input while the user is typing in the chat window.
|
||||||
// chat window.
|
m_chatPanel->KeyEvent();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2405,7 +2405,7 @@ int TeamFortressViewport::KeyInput( int down, int keynum, const char *pszCurrent
|
||||||
m_chatPanel->requestFocus();
|
m_chatPanel->requestFocus();
|
||||||
m_chatPanel->SetChatMode(ChatPanel::chatModeTeam);
|
m_chatPanel->SetChatMode(ChatPanel::chatModeTeam);
|
||||||
return 0;
|
return 0;
|
||||||
}*/
|
}
|
||||||
|
|
||||||
// Open Text Window?
|
// Open Text Window?
|
||||||
if (m_pCurrentMenu && gEngfuncs.Con_IsVisible() == false)
|
if (m_pCurrentMenu && gEngfuncs.Con_IsVisible() == false)
|
||||||
|
|
|
@ -193,3 +193,75 @@ bool ChatPanel::WasKeyPushed(int virtualKey) const
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string ChatPanel::UTF8toASCII(unsigned char* multibyte)
|
||||||
|
{
|
||||||
|
string ASCIIValue;
|
||||||
|
if (multibyte[0] <= 127)// let ascii pass
|
||||||
|
ASCIIValue = multibyte[0];
|
||||||
|
|
||||||
|
if (multibyte[0] == 0xC3)// is it a UTF8 multibyte?
|
||||||
|
{
|
||||||
|
ASCIIValue = multibyte[1] + 64;
|
||||||
|
}
|
||||||
|
|
||||||
|
return ASCIIValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ChatPanel::KeyEvent()
|
||||||
|
{
|
||||||
|
const Uint8 *state = SDL_GetKeyboardState(NULL);
|
||||||
|
|
||||||
|
if (SDL_PollEvent(&event)) {
|
||||||
|
|
||||||
|
if (event.type == SDL_TEXTINPUT)
|
||||||
|
{
|
||||||
|
unsigned char* buffer;
|
||||||
|
buffer = (unsigned char*)event.text.text;
|
||||||
|
|
||||||
|
mText += UTF8toASCII(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state[SDL_SCANCODE_ESCAPE])
|
||||||
|
{
|
||||||
|
CancelChat();
|
||||||
|
}
|
||||||
|
if (state[SDL_SCANCODE_BACKSPACE])
|
||||||
|
{
|
||||||
|
if (mText.length() > 0)
|
||||||
|
{
|
||||||
|
mText.erase(mText.length() - 1, mText.length());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (state[SDL_SCANCODE_RETURN])
|
||||||
|
{
|
||||||
|
std::string theCommand;
|
||||||
|
|
||||||
|
theCommand += mChatMode;
|
||||||
|
|
||||||
|
theCommand += " \"";
|
||||||
|
|
||||||
|
// Replace all ';' characters with ':' characters since we can't have
|
||||||
|
// ';' characters on a console message.
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < mText.length(); ++i)
|
||||||
|
{
|
||||||
|
if (mText[i] == ';')
|
||||||
|
{
|
||||||
|
mText[i] = ':';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
theCommand += mText;
|
||||||
|
|
||||||
|
theCommand += "\"";
|
||||||
|
|
||||||
|
//say_x "the message here" instead of
|
||||||
|
//say_x the message here (ever word was treated as another argument)
|
||||||
|
gEngfuncs.pfnClientCmd((char*)theCommand.c_str());
|
||||||
|
|
||||||
|
CancelChat();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -11,9 +11,9 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
//@2014
|
//@2014
|
||||||
|
|
||||||
//#define VK_ESCAPE 0x1B
|
#include <SDL2\SDL_events.h> //#define VK_ESCAPE 0x1B
|
||||||
//#define VK_RETURN 0x0D
|
#include <SDL2\SDL_keyboard.h> //#define VK_RETURN 0x0D
|
||||||
//#define VK_CAPITAL 0x14
|
#include <SDL2\SDL_keycode.h> //#define VK_CAPITAL 0x14
|
||||||
//#define VK_LCONTROL 0xA2
|
//#define VK_LCONTROL 0xA2
|
||||||
//#define VK_RCONTROL 0xA3
|
//#define VK_RCONTROL 0xA3
|
||||||
|
|
||||||
|
@ -25,7 +25,7 @@ public:
|
||||||
|
|
||||||
void CancelChat();
|
void CancelChat();
|
||||||
void SetChatMode(std::string sChatMode);
|
void SetChatMode(std::string sChatMode);
|
||||||
|
void KeyEvent();
|
||||||
void KeyDown(int virtualKey, int scanCode);
|
void KeyDown(int virtualKey, int scanCode);
|
||||||
|
|
||||||
// Checks if a key was pushed since the chat window was opened.
|
// Checks if a key was pushed since the chat window was opened.
|
||||||
|
@ -40,9 +40,9 @@ public:
|
||||||
private:
|
private:
|
||||||
std::string mText;
|
std::string mText;
|
||||||
std::string mChatMode;
|
std::string mChatMode;
|
||||||
|
std::string UTF8toASCII(unsigned char* multibyte);
|
||||||
bool mKeyPushed[256];
|
bool mKeyPushed[256];
|
||||||
|
SDL_Event event;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue