textbooks module complete
This commit is contained in:
parent
00740b56f3
commit
f290d821f1
|
@ -3,7 +3,7 @@ TextBooks = {}
|
||||||
local function onGameEditText(id, itemId, maxLength, text, writter, time)
|
local function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||||
local textWindow = createWidget('TextWindow', rootWidget)
|
local textWindow = createWidget('TextWindow', rootWidget)
|
||||||
|
|
||||||
local writeable = maxLength ~= #text
|
local writeable = (maxLength ~= #text) and maxLength > 0
|
||||||
local textItem = textWindow:getChildById('textItem')
|
local textItem = textWindow:getChildById('textItem')
|
||||||
local description = textWindow:getChildById('description')
|
local description = textWindow:getChildById('description')
|
||||||
local textEdit = textWindow:getChildById('text')
|
local textEdit = textWindow:getChildById('text')
|
||||||
|
@ -33,13 +33,40 @@ local function onGameEditText(id, itemId, maxLength, text, writter, time)
|
||||||
end
|
end
|
||||||
|
|
||||||
description:setText(desc)
|
description:setText(desc)
|
||||||
|
|
||||||
|
if not writeable then
|
||||||
|
textWindow:setText(tr('Show Text'))
|
||||||
|
cancelButton:hide()
|
||||||
|
else
|
||||||
|
textWindow:setText(tr('Edit Text'))
|
||||||
|
end
|
||||||
|
|
||||||
okButton.onClick = function()
|
okButton.onClick = function()
|
||||||
|
if writeable then
|
||||||
g_game.editText(id, textEdit:getText())
|
g_game.editText(id, textEdit:getText())
|
||||||
|
end
|
||||||
textWindow:destroy()
|
textWindow:destroy()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function onGameEditList(listId, id, text)
|
local function onGameEditList(id, doorId, text)
|
||||||
|
local textWindow = createWidget('TextWindow', rootWidget)
|
||||||
|
|
||||||
|
local textEdit = textWindow:getChildById('text')
|
||||||
|
local description = textWindow:getChildById('description')
|
||||||
|
local okButton = textWindow:getChildById('okButton')
|
||||||
|
local cancelButton = textWindow:getChildById('cancelButton')
|
||||||
|
|
||||||
|
textEdit:setMaxLength(8192)
|
||||||
|
textEdit:setText(text)
|
||||||
|
textEdit:setEnabled(true)
|
||||||
|
description:setText(tr('Enter one text per line.'))
|
||||||
|
textWindow:setText(tr('Edit List'))
|
||||||
|
|
||||||
|
okButton.onClick = function()
|
||||||
|
g_game.editList(id, doorId, textEdit:getText())
|
||||||
|
textWindow:destroy()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function TextBooks.init()
|
function TextBooks.init()
|
||||||
|
|
|
@ -1,13 +1,12 @@
|
||||||
TextWindow < MainWindow
|
TextWindow < MainWindow
|
||||||
id: textWindow
|
id: textWindow
|
||||||
!text: tr('Edit Text')
|
|
||||||
size: 280 280
|
size: 280 280
|
||||||
@onEscape: self:destroy()
|
@onEscape: self:destroy()
|
||||||
|
|
||||||
UIItem
|
UIItem
|
||||||
id: textItem
|
id: textItem
|
||||||
virtual: true
|
virtual: true
|
||||||
item-id: 2816
|
item-id: 173
|
||||||
size: 32 32
|
size: 32 32
|
||||||
anchors.top: parent.top
|
anchors.top: parent.top
|
||||||
anchors.left: parent.left
|
anchors.left: parent.left
|
||||||
|
|
|
@ -394,14 +394,14 @@ void Game::processCloseTrade()
|
||||||
g_lua.callGlobalField("g_game", "onCloseTrade");
|
g_lua.callGlobalField("g_game", "onCloseTrade");
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::processEditText(int id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date)
|
void Game::processEditText(uint id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date)
|
||||||
{
|
{
|
||||||
g_lua.callGlobalField("g_game", "onEditText", id, itemId, maxLength, text, writter, date);
|
g_lua.callGlobalField("g_game", "onEditText", id, itemId, maxLength, text, writter, date);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::processEditList(int listId, int id, const std::string& text)
|
void Game::processEditList(uint id, int doorId, const std::string& text)
|
||||||
{
|
{
|
||||||
g_lua.callGlobalField("g_game", "onEditList", listId, id, text);
|
g_lua.callGlobalField("g_game", "onEditList", id, doorId, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList)
|
void Game::processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList)
|
||||||
|
@ -973,11 +973,11 @@ void Game::editText(uint id, const std::string& text)
|
||||||
m_protocolGame->sendEditText(id, text);
|
m_protocolGame->sendEditText(id, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::editList(int listId, uint id, const std::string& text)
|
void Game::editList(uint id, int doorId, const std::string& text)
|
||||||
{
|
{
|
||||||
if(!canPerformGameAction())
|
if(!canPerformGameAction())
|
||||||
return;
|
return;
|
||||||
m_protocolGame->sendEditList(listId, id, text);
|
m_protocolGame->sendEditList(id, doorId, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::reportBug(const std::string& comment)
|
void Game::reportBug(const std::string& comment)
|
||||||
|
|
|
@ -114,8 +114,8 @@ protected:
|
||||||
void processCloseTrade();
|
void processCloseTrade();
|
||||||
|
|
||||||
// edit text/list
|
// edit text/list
|
||||||
void processEditText(int id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date);
|
void processEditText(uint id, int itemId, int maxLength, const std::string& text, const std::string& writter, const std::string& date);
|
||||||
void processEditList(int listId, int id, const std::string& text);
|
void processEditList(uint id, int doorId, const std::string& text);
|
||||||
|
|
||||||
// questlog
|
// questlog
|
||||||
void processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList);
|
void processQuestLog(const std::vector<std::tuple<int, std::string, bool>>& questList);
|
||||||
|
@ -218,7 +218,7 @@ public:
|
||||||
|
|
||||||
// house window and editable items related
|
// house window and editable items related
|
||||||
void editText(uint id, const std::string& text);
|
void editText(uint id, const std::string& text);
|
||||||
void editList(int listId, uint id, const std::string& text);
|
void editList(uint id, int doorId, const std::string& text);
|
||||||
|
|
||||||
// reports
|
// reports
|
||||||
void reportBug(const std::string& comment);
|
void reportBug(const std::string& comment);
|
||||||
|
|
|
@ -72,7 +72,7 @@ public:
|
||||||
void sendCloseContainer(int containerId);
|
void sendCloseContainer(int containerId);
|
||||||
void sendUpContainer(int containerId);
|
void sendUpContainer(int containerId);
|
||||||
void sendEditText(uint id, const std::string& text);
|
void sendEditText(uint id, const std::string& text);
|
||||||
void sendEditList(int listId, uint id, const std::string& text);
|
void sendEditList(uint id, int doorId, const std::string& text);
|
||||||
void sendLook(const Position& position, int thingId, int stackpos);
|
void sendLook(const Position& position, int thingId, int stackpos);
|
||||||
void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message);
|
void sendTalk(Otc::SpeakType speakType, int channelId, const std::string& receiver, const std::string& message);
|
||||||
void sendRequestChannels();
|
void sendRequestChannels();
|
||||||
|
|
|
@ -718,7 +718,7 @@ void ProtocolGame::parseCreatureTurn(InputMessage& msg)
|
||||||
|
|
||||||
void ProtocolGame::parseEditText(InputMessage& msg)
|
void ProtocolGame::parseEditText(InputMessage& msg)
|
||||||
{
|
{
|
||||||
int id = msg.getU32();
|
uint id = msg.getU32();
|
||||||
int itemId = msg.getU16();
|
int itemId = msg.getU16();
|
||||||
int maxLength = msg.getU16();
|
int maxLength = msg.getU16();
|
||||||
std::string text = msg.getString();
|
std::string text = msg.getString();
|
||||||
|
@ -730,11 +730,11 @@ void ProtocolGame::parseEditText(InputMessage& msg)
|
||||||
|
|
||||||
void ProtocolGame::parseEditList(InputMessage& msg)
|
void ProtocolGame::parseEditList(InputMessage& msg)
|
||||||
{
|
{
|
||||||
int listId = msg.getU8();
|
int doorId = msg.getU8();
|
||||||
int id = msg.getU32();
|
uint id = msg.getU32();
|
||||||
const std::string& text = msg.getString();
|
const std::string& text = msg.getString();
|
||||||
|
|
||||||
g_game.processEditList(listId, id, text);
|
g_game.processEditList(id, doorId, text);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::parsePlayerStats(InputMessage& msg)
|
void ProtocolGame::parsePlayerStats(InputMessage& msg)
|
||||||
|
|
|
@ -366,11 +366,11 @@ void ProtocolGame::sendEditText(uint id, const std::string& text)
|
||||||
send(msg);
|
send(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ProtocolGame::sendEditList(int listId, uint id, const std::string& text)
|
void ProtocolGame::sendEditList(uint id, int doorId, const std::string& text)
|
||||||
{
|
{
|
||||||
OutputMessage msg;
|
OutputMessage msg;
|
||||||
msg.addU8(Proto::ClientEditList);
|
msg.addU8(Proto::ClientEditList);
|
||||||
msg.addU8(listId);
|
msg.addU8(doorId);
|
||||||
msg.addU32(id);
|
msg.addU32(id);
|
||||||
msg.addString(text);
|
msg.addString(text);
|
||||||
send(msg);
|
send(msg);
|
||||||
|
|
Loading…
Reference in New Issue