mirror of
https://github.com/edubart/otclient.git
synced 2025-10-15 12:04:55 +02:00
add chat panel, send text messages, guard forbidden functions with an ifdef
This commit is contained in:
@@ -33,6 +33,7 @@ UILineEdit::UILineEdit()
|
||||
m_startRenderPos = 0;
|
||||
m_textHorizontalMargin = 0;
|
||||
m_textHidden = false;
|
||||
m_alwaysFocused = false;
|
||||
blinkCursor();
|
||||
}
|
||||
|
||||
@@ -50,7 +51,7 @@ void UILineEdit::render()
|
||||
g_graphics.drawTexturedRect(m_glyphsCoords[i], texture, m_glyphsTexCoords[i]);
|
||||
|
||||
// render cursor
|
||||
if(isExplicitlyEnabled() && isActive() && m_cursorPos >= 0) {
|
||||
if(isExplicitlyEnabled() && (isActive() || m_alwaysFocused) && m_cursorPos >= 0) {
|
||||
assert(m_cursorPos <= textLength);
|
||||
// draw every 333ms
|
||||
const int delay = 333;
|
||||
@@ -384,6 +385,8 @@ void UILineEdit::onStyleApply(const OTMLNodePtr& styleNode)
|
||||
setTextHidden(node->value<bool>());
|
||||
} else if(node->tag() == "text margin") {
|
||||
m_textHorizontalMargin = node->value<int>();
|
||||
} else if(node->tag() == "always focused") {
|
||||
m_alwaysFocused = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -395,7 +398,7 @@ void UILineEdit::onGeometryUpdate(const Rect& oldRect, const Rect& newRect)
|
||||
|
||||
void UILineEdit::onFocusChange(bool focused, Fw::FocusReason reason)
|
||||
{
|
||||
if(focused) {
|
||||
if(focused && !m_alwaysFocused) {
|
||||
if(reason == Fw::TabFocusReason)
|
||||
setCursorPos(m_text.length());
|
||||
else
|
||||
@@ -420,8 +423,10 @@ bool UILineEdit::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
|
||||
else if(keyCode == Fw::KeyV && keyboardModifiers == Fw::KeyboardCtrlModifier)
|
||||
appendText(g_platform.getClipboardText());
|
||||
else if(keyCode == Fw::KeyTab) {
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->focusNextChild(Fw::TabFocusReason);
|
||||
if(!m_alwaysFocused) {
|
||||
if(UIWidgetPtr parent = getParent())
|
||||
parent->focusNextChild(Fw::TabFocusReason);
|
||||
}
|
||||
} else if(keyChar != 0)
|
||||
appendCharacter(keyChar);
|
||||
else
|
||||
|
@@ -71,6 +71,7 @@ private:
|
||||
int m_cursorTicks;
|
||||
int m_textHorizontalMargin;
|
||||
bool m_textHidden;
|
||||
bool m_alwaysFocused;
|
||||
|
||||
std::vector<Rect> m_glyphsCoords;
|
||||
std::vector<Rect> m_glyphsTexCoords;
|
||||
|
@@ -63,9 +63,13 @@ void OTClient::registerLuaFunctions()
|
||||
g_lua.bindClassStaticFunction<Game>("logout", std::bind(&Game::logout, &g_game, _1));
|
||||
g_lua.bindClassStaticFunction<Game>("cancelLogin", std::bind(&Game::cancelLogin, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
|
||||
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
|
||||
g_lua.bindClassStaticFunction<Game>("isOnline", std::bind(&Game::isOnline, &g_game));
|
||||
|
||||
g_lua.registerClass<UIMap, UIWidget>();
|
||||
g_lua.bindClassStaticFunction<UIMap>("create", &UIWidget::create<UIMap>);
|
||||
|
||||
#ifdef FORBIDDEN_FUNCTIONS
|
||||
g_lua.bindClassStaticFunction<Game>("talkChannel", std::bind(&Game::talkChannel, &g_game, _1, _2, _3));
|
||||
g_lua.bindClassStaticFunction<Game>("talkPrivate", std::bind(&Game::talkPrivate, &g_game, _1, _2, _3));
|
||||
#endif
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@
|
||||
#include <otclient/core/game.h>
|
||||
#include <framework/otml/otml.h>
|
||||
#include <framework/graphics/graphics.h>
|
||||
#include <framework/ui/uilineedit.h>
|
||||
|
||||
void UIMap::setup()
|
||||
{
|
||||
@@ -46,6 +47,8 @@ void UIMap::render()
|
||||
|
||||
bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
|
||||
{
|
||||
UILineEditPtr chatLineEdit = std::dynamic_pointer_cast<UILineEdit>(getParent()->recursiveGetChildById("chatLineEdit"));
|
||||
|
||||
if(keyboardModifiers == Fw::KeyboardNoModifier) {
|
||||
if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {
|
||||
g_game.walk(Otc::North);
|
||||
@@ -71,6 +74,28 @@ bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
|
||||
} else if(keyCode == Fw::KeyNumpad7) {
|
||||
g_game.walk(Otc::NorthWest);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyReturn || keyCode == Fw::KeyEnter) {
|
||||
g_game.talkChannel(1, 0, chatLineEdit->getText());
|
||||
chatLineEdit->clearText();
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyDelete) {
|
||||
chatLineEdit->removeCharacter(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyBackspace) {
|
||||
chatLineEdit->removeCharacter(false);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyRight) {
|
||||
chatLineEdit->moveCursor(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft) {
|
||||
chatLineEdit->moveCursor(false);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyHome) {
|
||||
chatLineEdit->setCursorPos(0);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyEnd) {
|
||||
chatLineEdit->setCursorPos(chatLineEdit->getText().length());
|
||||
return true;
|
||||
}
|
||||
} else if(keyboardModifiers == Fw::KeyboardCtrlModifier) {
|
||||
if(keyCode == Fw::KeyUp || keyCode == Fw::KeyNumpad8) {
|
||||
@@ -86,7 +111,21 @@ bool UIMap::onKeyPress(uchar keyCode, char keyChar, int keyboardModifiers)
|
||||
g_game.turn(Otc::West);
|
||||
return true;
|
||||
}
|
||||
} else if(keyboardModifiers == Fw::KeyboardShiftModifier) {
|
||||
if(keyCode == Fw::KeyRight || keyCode == Fw::KeyNumpad6) {
|
||||
chatLineEdit->moveCursor(true);
|
||||
return true;
|
||||
} else if(keyCode == Fw::KeyLeft || keyCode == Fw::KeyNumpad4) {
|
||||
chatLineEdit->moveCursor(false);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if(keyChar != 0) {
|
||||
chatLineEdit->appendText(std::string(1, keyChar));
|
||||
return true;
|
||||
}
|
||||
|
||||
return UIWidget::onKeyPress(keyCode, keyChar, keyboardModifiers);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user