1
0
mirror of https://gitlab.com/OpenMW/openmw.git synced 2025-02-04 03:40:14 +00:00

Dehardcode input.ACTION.Inventory, input.ACTION.Journal, input.ACTION.QuickKeysMenu

This commit is contained in:
Petr Mikheev 2023-07-16 19:10:49 +02:00
parent 87eacf774a
commit f1bcf64afb
8 changed files with 77 additions and 84 deletions

View File

@ -226,10 +226,6 @@ namespace
void onOpen() override
{
if (!MWBase::Environment::get().getWindowManager()->getJournalAllowed())
{
MWBase::Environment::get().getWindowManager()->popGuiMode();
}
mModel->load();
setBookMode();

View File

@ -71,9 +71,6 @@ namespace MWInput
case A_Screenshot:
screenshot();
break;
case A_Inventory:
toggleInventory();
break;
case A_Console:
toggleConsole();
break;
@ -87,9 +84,6 @@ namespace MWInput
case A_MoveBackward:
handleGuiArrowKey(action);
break;
case A_Journal:
toggleJournal();
break;
case A_Rest:
rest();
break;
@ -123,9 +117,6 @@ namespace MWInput
case A_QuickKey10:
quickKey(10);
break;
case A_QuickKeysMenu:
showQuickKeysMenu();
break;
case A_ToggleHUD:
windowManager->toggleHud();
break;
@ -157,6 +148,11 @@ namespace MWInput
if (checkAllowedToUseItems() && windowManager->isAllowed(MWGui::GW_Inventory))
MWBase::Environment::get().getWindowManager()->cycleWeapon(true);
break;
case A_Inventory:
case A_Journal:
case A_QuickKeysMenu:
// Handled in Lua
break;
}
}
@ -248,30 +244,6 @@ namespace MWInput
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Rest); // Open rest GUI
}
void ActionManager::toggleInventory()
{
if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols"))
return;
if (MyGUI::InputManager::getInstance().isModalAny())
return;
if (MWBase::Environment::get().getWindowManager()->isConsoleMode())
return;
// Toggle between game mode and inventory mode
if (!MWBase::Environment::get().getWindowManager()->isGuiMode())
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_Inventory);
else
{
MWGui::GuiMode mode = MWBase::Environment::get().getWindowManager()->getMode();
if (mode == MWGui::GM_Inventory || mode == MWGui::GM_Container)
MWBase::Environment::get().getWindowManager()->popGuiMode();
}
// .. but don't touch any other mode, except container.
}
void ActionManager::toggleConsole()
{
if (MyGUI::InputManager::getInstance().isModalAny())
@ -280,25 +252,6 @@ namespace MWInput
MWBase::Environment::get().getWindowManager()->toggleConsole();
}
void ActionManager::toggleJournal()
{
if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols"))
return;
if (MyGUI::InputManager::getInstance().isModalAny())
return;
MWBase::WindowManager* windowManager = MWBase::Environment::get().getWindowManager();
if (windowManager->getMode() != MWGui::GM_Journal && windowManager->getMode() != MWGui::GM_MainMenu
&& windowManager->getMode() != MWGui::GM_Settings && windowManager->getJournalAllowed())
{
windowManager->pushGuiMode(MWGui::GM_Journal);
}
else if (windowManager->containsMode(MWGui::GM_Journal))
{
windowManager->removeGuiMode(MWGui::GM_Journal);
}
}
void ActionManager::quickKey(int index)
{
if (!MWBase::Environment::get().getInputManager()->getControlSwitch("playercontrols")
@ -315,23 +268,6 @@ namespace MWInput
MWBase::Environment::get().getWindowManager()->activateQuickKey(index);
}
void ActionManager::showQuickKeysMenu()
{
if (MWBase::Environment::get().getWindowManager()->getMode() == MWGui::GM_QuickKeysMenu)
{
MWBase::Environment::get().getWindowManager()->exitCurrentGuiMode();
return;
}
if (MWBase::Environment::get().getWorld()->getGlobalFloat(MWWorld::Globals::sCharGenState) != -1)
return;
if (!checkAllowedToUseItems())
return;
MWBase::Environment::get().getWindowManager()->pushGuiMode(MWGui::GM_QuickKeysMenu);
}
void ActionManager::activate()
{
if (MWBase::Environment::get().getWindowManager()->isGuiMode())

View File

@ -28,17 +28,14 @@ namespace MWInput
bool checkAllowedToUseItems() const;
void toggleMainMenu();
void toggleInventory();
void toggleConsole();
void screenshot();
void toggleJournal();
void activate();
void rest();
void quickLoad();
void quickSave();
void quickKey(int index);
void showQuickKeysMenu();
void resetIdleTime();
float getIdleTime() const { return mTimeIdle; }

View File

@ -2,6 +2,7 @@
#include <filesystem>
#include <MyGUI_InputManager.h>
#include <osg/Stats>
#include "sol/state_view.hpp"
@ -352,6 +353,15 @@ namespace MWLua
}
}
void LuaManager::inputEvent(const InputEvent& event)
{
if (!MyGUI::InputManager::getInstance().isModalAny()
&& !MWBase::Environment::get().getWindowManager()->isConsoleMode())
{
mInputEvents.push_back(event);
}
}
MWBase::LuaManager::ActorControls* LuaManager::getActorControls(const MWWorld::Ptr& ptr) const
{
LocalScripts* localScripts = ptr.getRefData().getLuaScripts();

View File

@ -68,7 +68,7 @@ namespace MWLua
void gameLoaded() override;
void objectAddedToScene(const MWWorld::Ptr& ptr) override;
void objectRemovedFromScene(const MWWorld::Ptr& ptr) override;
void inputEvent(const InputEvent& event) override { mInputEvents.push_back(event); }
void inputEvent(const InputEvent& event) override;
void itemConsumed(const MWWorld::Ptr& consumable, const MWWorld::Ptr& actor) override
{
mEngineEvents.addToQueue(EngineEvents::OnConsume{ getId(actor), getId(consumable) });

View File

@ -5,6 +5,7 @@
#include <apps/openmw/mwbase/world.hpp>
#include <apps/openmw/mwmechanics/npcstats.hpp>
#include <apps/openmw/mwworld/class.hpp>
#include <apps/openmw/mwworld/globals.hpp>
namespace MWLua
{
@ -126,6 +127,9 @@ namespace MWLua
const MWWorld::Class& cls = o.ptr().getClass();
return cls.getNpcStats(o.ptr()).getBounty();
};
player["isCharGenFinished"] = [](const Object&) -> bool {
return MWBase::Environment::get().getWorld()->getGlobalFloat(MWWorld::Globals::sCharGenState) == -1;
};
addPlayerQuestBindings(player, context);
}
}

View File

@ -47,6 +47,7 @@ local startAttack = false
local autoMove = false
local movementControlsOverridden = false
local combatControlsOverridden = false
local uiControlsOverridden = false
local function processMovement()
local controllerMovement = -input.getAxisValue(input.CONTROLLER_AXIS.MoveForwardBackward)
@ -123,8 +124,48 @@ local function onFrame(dt)
startAttack = false
end
local function checkNotWerewolf()
if Player.isWerewolf(self) then
ui.showMessage(core.getGMST('sWerewolfRefusal'))
return false
else
return true
end
end
local function isJournalAllowed()
-- During chargen journal is not allowed until magic window is allowed
return I.UI.getWindowsForMode(I.UI.MODE.Interface)[I.UI.WINDOW.Magic]
end
local function onInputAction(action)
if core.isWorldPaused() or not input.getControlSwitch(input.CONTROL_SWITCH.Controls) then
if not input.getControlSwitch(input.CONTROL_SWITCH.Controls) then
return
end
if not uiControlsOverridden then
if action == input.ACTION.Inventory then
if I.UI.getMode() == nil then
I.UI.setMode(I.UI.MODE.Interface)
elseif I.UI.getMode() == I.UI.MODE.Interface or I.UI.getMode() == I.UI.MODE.Container then
I.UI.removeMode(I.UI.getMode())
end
elseif action == input.ACTION.Journal then
if I.UI.getMode() == I.UI.MODE.Journal then
I.UI.removeMode(I.UI.MODE.Journal)
elseif isJournalAllowed() then
I.UI.addMode(I.UI.MODE.Journal)
end
elseif action == input.ACTION.QuickKeysMenu then
if I.UI.getMode() == I.UI.MODE.QuickKeysMenu then
I.UI.removeMode(I.UI.MODE.QuickKeysMenu)
elseif checkNotWerewolf() and Player.isCharGenFinished(self) then
I.UI.addMode(I.UI.MODE.QuickKeysMenu)
end
end
end
if core.isWorldPaused() then
return
end
@ -144,9 +185,7 @@ local function onInputAction(action)
if Actor.stance(self) == Actor.STANCE.Spell then
Actor.setStance(self, Actor.STANCE.Nothing)
elseif input.getControlSwitch(input.CONTROL_SWITCH.Magic) then
if Player.isWerewolf(self) then
ui.showMessage(core.getGMST('sWerewolfRefusal'))
else
if checkNotWerewolf() then
Actor.setStance(self, Actor.STANCE.Spell)
end
end
@ -171,19 +210,24 @@ return {
interface = {
--- Interface version
-- @field [parent=#Controls] #number version
version = 0,
version = 1,
--- When set to true then the movement controls including jump and sneak are not processed and can be handled by another script.
-- If movement should be dissallowed completely, consider to use `input.setControlSwitch` instead.
-- If movement should be disallowed completely, consider to use `input.setControlSwitch` instead.
-- @function [parent=#Controls] overrideMovementControls
-- @param #boolean value
overrideMovementControls = function(v) movementControlsOverridden = v end,
--- When set to true then the controls "attack", "toggle spell", "toggle weapon" are not processed and can be handled by another script.
-- If combat should be dissallowed completely, consider to use `input.setControlSwitch` instead.
-- If combat should be disallowed completely, consider to use `input.setControlSwitch` instead.
-- @function [parent=#Controls] overrideCombatControls
-- @param #boolean value
overrideCombatControls = function(v) combatControlsOverridden = v end,
--- When set to true then the controls "open inventory", "open journal" and so on are not processed and can be handled by another script.
-- @function [parent=#Controls] overrideUiControls
-- @param #boolean value
overrideUiControls = function(v) uiControlsOverridden = v end,
}
}

View File

@ -751,6 +751,12 @@
-- @param openmw.core#GameObject player
-- @return #number
---
-- Whether the character generation for this player is finished.
-- @function [parent=#Player] isCharGenFinished
-- @param openmw.core#GameObject player
-- @return #boolean
---
-- Returns a list containing quests @{#PlayerQuest} for the specified player, indexed by quest ID.
-- @function [parent=#Player] quests