Skip to content

An OpenMW mod that lets you play the whole Elder Scrolls III: Morrowind as a top-down isometric game — with full online co-op or MMO modes.

C++

Move prompt: asked once the inventory can be opened (fixes #11)

Claudea8d4ba508bc8
diff --git a/isowind/mod/scripts/isowind/moveprompt.lua b/isowind/mod/scripts/isowind/moveprompt.lua
index ad36656..77a98ac 100644
--- a/isowind/mod/scripts/isowind/moveprompt.lua
+++ b/isowind/mod/scripts/isowind/moveprompt.lua
@@ -4,6 +4,9 @@
-- leaves WASD, the default. The choice is the installation's, not the character's (permanent storage). Playing with a
-- controller it isn't asked (topdown.lua: the menus made for a controller, Isowind.exe's Controller tick box, or the
-- controller last used): its own controls, never click to move; it is asked once the mouse and keyboard are used.
+-- On a new game it waits until the inventory can be opened: during character creation the engine refuses the
+-- Interface mode (windowmanagerimp.cpp, pushGuiMode), which left the window up with no cursor and no keys. Should the
+-- mode still not come, it takes the window down and asks again a little later.
-- Used by topdown.lua, which calls update every frame in the top-down view.
local async = require('openmw.async')
@@ -22,9 +25,33 @@ local ownSettings = storage.playerSection('IsowindTopDown')
local prompt = nil
local keysUp = false -- 1, 2 and A have been up since it opened (one held as it opened doesn't choose)
local modeCame = false -- the Interface mode asked for has come (I.UI.getMode says so from a frame later)
+local waitedFrames = 0 -- frames since it was asked for, while it hasn't come
+local retryAt = 0 -- (real time) not asked again before this, after the mode didn't come
+
+local GIVE_UP_FRAMES = 30 -- the mode comes a frame or two after it is asked for; not by then, it won't
+local RETRY_AFTER = 5 -- seconds
local M = {}
+-- Whether the inventory screen can be opened: not during character creation until Morrowind's own scripts allow it
+local function inventoryAllowed()
+ return I.UI.getWindowsForMode('Interface').Inventory ~= nil
+end
+
+-- The Interface mode didn't come (refused, or another window opened in its place): the window goes, nothing is chosen
+-- (WASD meanwhile) and it is asked again later
+local function giveUp()
+ prompt:destroy()
+ prompt = nil
+ retryAt = core.getRealTime() + RETRY_AFTER
+ -- The windows it hid come back with whatever mode opens next (ui.lua); with none open, Interface asked for again
+ -- plainly brings them back, then no mode (as close does)
+ if I.UI.getMode() == nil then
+ I.UI.setMode('Interface')
+ I.UI.setMode()
+ end
+end
+
local function close(mode)
controls:set('MoveMode', mode)
ownSettings:set('MoveModeChosen', true)
@@ -80,7 +107,7 @@ end
local function open()
local templates = I.MWUI.templates
I.UI.setMode('Interface', { windows = {} })
- keysUp, modeCame = false, false
+ keysUp, modeCame, waitedFrames = false, false, 0
prompt = ui.create {
layer = 'Windows',
template = templates.boxTransparentThick,
@@ -114,17 +141,24 @@ local function open()
}
end
--- canAsk: the player has control of the character (it is asked then, once)
+-- canAsk: the player has control of the character (it is asked then, once the inventory can be opened)
function M.update(canAsk)
-- (the topdown view's onFrame keeps calling while it is up: the game paused under it doesn't stop that)
if not prompt then
- if canAsk and not ownSettings:get('MoveModeChosen') then open() end
+ if canAsk and not ownSettings:get('MoveModeChosen') and inventoryAllowed()
+ and core.getRealTime() >= retryAt then
+ open()
+ end
return
end
if I.UI.getMode() == 'Interface' then
modeCame = true
+ elseif modeCame then
+ close('move_wasd')
+ return
else
- if modeCame then close('move_wasd') end
+ waitedFrames = waitedFrames + 1
+ if waitedFrames >= GIVE_UP_FRAMES then giveUp() end
return
end
local one, two = input.isKeyPressed(input.KEY._1), input.isKeyPressed(input.KEY._2)