mirror of
https://github.com/OpenMW/openmw.git
synced 2025-02-28 17:09:41 +00:00
Add a showInDialogue parameter to ui.showMessage and use it for level up messages
This commit is contained in:
parent
daada262d7
commit
91bcd0a556
5 changed files with 34 additions and 7 deletions
|
@ -266,8 +266,8 @@ namespace MWLua
|
|||
playerScripts->onFrame(frameDuration);
|
||||
mProcessingInputEvents = false;
|
||||
|
||||
for (const std::string& message : mUIMessages)
|
||||
windowManager->messageBox(message);
|
||||
for (const auto& [message, mode] : mUIMessages)
|
||||
windowManager->messageBox(message, mode);
|
||||
mUIMessages.clear();
|
||||
for (auto& [msg, color] : mInGameConsoleMessages)
|
||||
windowManager->printToConsole(msg, "#" + color.toHex());
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
#include <components/misc/color.hpp>
|
||||
|
||||
#include "../mwbase/luamanager.hpp"
|
||||
#include "../mwbase/windowmanager.hpp"
|
||||
|
||||
#include "engineevents.hpp"
|
||||
#include "globalscripts.hpp"
|
||||
|
@ -106,7 +107,11 @@ namespace MWLua
|
|||
|
||||
// Used only in Lua bindings
|
||||
void addCustomLocalScript(const MWWorld::Ptr&, int scriptId, std::string_view initData);
|
||||
void addUIMessage(std::string_view message) { mUIMessages.emplace_back(message); }
|
||||
void addUIMessage(
|
||||
std::string_view message, MWGui::ShowInDialogueMode mode = MWGui::ShowInDialogueMode_IfPossible)
|
||||
{
|
||||
mUIMessages.emplace_back(message, mode);
|
||||
}
|
||||
void addInGameConsoleMessage(const std::string& msg, const Misc::Color& color)
|
||||
{
|
||||
mInGameConsoleMessages.push_back({ msg, color });
|
||||
|
@ -218,7 +223,7 @@ namespace MWLua
|
|||
};
|
||||
std::vector<DelayedAction> mActionQueue;
|
||||
std::optional<DelayedAction> mTeleportPlayerAction;
|
||||
std::vector<std::string> mUIMessages;
|
||||
std::vector<std::pair<std::string, MWGui::ShowInDialogueMode>> mUIMessages;
|
||||
std::vector<std::pair<std::string, Misc::Color>> mInGameConsoleMessages;
|
||||
std::optional<ObjectId> mDelayedUiModeChangedArg;
|
||||
|
||||
|
|
|
@ -90,7 +90,21 @@ namespace MWLua
|
|||
};
|
||||
api["_isHudVisible"] = []() -> bool { return MWBase::Environment::get().getWindowManager()->isHudVisible(); };
|
||||
api["showMessage"]
|
||||
= [luaManager = context.mLuaManager](std::string_view message) { luaManager->addUIMessage(message); };
|
||||
= [luaManager = context.mLuaManager](std::string_view message, const sol::optional<sol::table>& options) {
|
||||
MWGui::ShowInDialogueMode mode = MWGui::ShowInDialogueMode_IfPossible;
|
||||
if (options.has_value())
|
||||
{
|
||||
auto showInDialogue = options->get<sol::optional<bool>>("showInDialogue");
|
||||
if (showInDialogue.has_value())
|
||||
{
|
||||
if (*showInDialogue)
|
||||
mode = MWGui::ShowInDialogueMode_Only;
|
||||
else
|
||||
mode = MWGui::ShowInDialogueMode_Never;
|
||||
}
|
||||
}
|
||||
luaManager->addUIMessage(message, mode);
|
||||
};
|
||||
api["CONSOLE_COLOR"] = LuaUtil::makeStrictReadOnly(context.mLua->tableFromPairs<std::string, Misc::Color>({
|
||||
{ "Default", Misc::Color::fromHex(MWBase::WindowManager::sConsoleColor_Default.substr(1)) },
|
||||
{ "Error", Misc::Color::fromHex(MWBase::WindowManager::sConsoleColor_Error.substr(1)) },
|
||||
|
|
|
@ -74,10 +74,10 @@ local function skillLevelUpHandler(skillid, source, params)
|
|||
message = '#{sBookSkillMessage}\n'..message
|
||||
end
|
||||
|
||||
ui.showMessage(message)
|
||||
ui.showMessage(message, { showInDialogue = false })
|
||||
|
||||
if levelStat.progress >= core.getGMST('iLevelUpTotal') then
|
||||
ui.showMessage('#{sLevelUpMsg}')
|
||||
ui.showMessage('#{sLevelUpMsg}', { showInDialogue = false })
|
||||
end
|
||||
|
||||
if not source or source == I.SkillProgression.SKILL_INCREASE_SOURCES.Usage then skillStat.progress = 0 end
|
||||
|
|
|
@ -39,6 +39,14 @@
|
|||
-- Shows given message at the bottom of the screen.
|
||||
-- @function [parent=#ui] showMessage
|
||||
-- @param #string msg
|
||||
-- @param #table options An optional table with additional optional arguments. Can contain:
|
||||
--
|
||||
-- * `showInDialogue` - If true, this message will only be shown in the dialogue window. If false, it will always be shown in a message box.
|
||||
-- When omitted, the message will be displayed in the dialogue window if it is open and will be shown at the bottom of the screen otherwise.
|
||||
-- @usage local params = {
|
||||
-- showInDialogue=false
|
||||
-- };
|
||||
-- ui.showMessage("Hello world", params)
|
||||
|
||||
---
|
||||
-- Predefined colors for console output
|
||||
|
|
Loading…
Reference in a new issue