mirror of
https://github.com/OpenMW/openmw.git
synced 2025-12-24 10:53:11 +00:00
Move control switch reading/writing to relevant class
This commit is contained in:
parent
b4e52a6bc8
commit
73552f1d3c
3 changed files with 61 additions and 24 deletions
|
|
@ -1,5 +1,11 @@
|
||||||
#include "controlswitch.hpp"
|
#include "controlswitch.hpp"
|
||||||
|
|
||||||
|
#include <components/esm/esmwriter.hpp>
|
||||||
|
#include <components/esm/esmreader.hpp>
|
||||||
|
#include <components/esm/controlsstate.hpp>
|
||||||
|
|
||||||
|
#include <components/loadinglistener/loadinglistener.hpp>
|
||||||
|
|
||||||
#include "../mwbase/environment.hpp"
|
#include "../mwbase/environment.hpp"
|
||||||
#include "../mwbase/world.hpp"
|
#include "../mwbase/world.hpp"
|
||||||
|
|
||||||
|
|
@ -55,4 +61,39 @@ namespace MWInput
|
||||||
}
|
}
|
||||||
mSwitches[key] = value;
|
mSwitches[key] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ControlSwitch::write(ESM::ESMWriter& writer, Loading::Listener& /*progress*/)
|
||||||
|
{
|
||||||
|
ESM::ControlsState controls;
|
||||||
|
controls.mViewSwitchDisabled = !mSwitches["playerviewswitch"];
|
||||||
|
controls.mControlsDisabled = !mSwitches["playercontrols"];
|
||||||
|
controls.mJumpingDisabled = !mSwitches["playerjumping"];
|
||||||
|
controls.mLookingDisabled = !mSwitches["playerlooking"];
|
||||||
|
controls.mVanityModeDisabled = !mSwitches["vanitymode"];
|
||||||
|
controls.mWeaponDrawingDisabled = !mSwitches["playerfighting"];
|
||||||
|
controls.mSpellDrawingDisabled = !mSwitches["playermagic"];
|
||||||
|
|
||||||
|
writer.startRecord (ESM::REC_INPU);
|
||||||
|
controls.save(writer);
|
||||||
|
writer.endRecord (ESM::REC_INPU);
|
||||||
|
}
|
||||||
|
|
||||||
|
void ControlSwitch::readRecord(ESM::ESMReader& reader, uint32_t type)
|
||||||
|
{
|
||||||
|
ESM::ControlsState controls;
|
||||||
|
controls.load(reader);
|
||||||
|
|
||||||
|
set("playerviewswitch", !controls.mViewSwitchDisabled);
|
||||||
|
set("playercontrols", !controls.mControlsDisabled);
|
||||||
|
set("playerjumping", !controls.mJumpingDisabled);
|
||||||
|
set("playerlooking", !controls.mLookingDisabled);
|
||||||
|
set("vanitymode", !controls.mVanityModeDisabled);
|
||||||
|
set("playerfighting", !controls.mWeaponDrawingDisabled);
|
||||||
|
set("playermagic", !controls.mSpellDrawingDisabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ControlSwitch::countSavedGameRecords() const
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,18 @@
|
||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
namespace ESM
|
||||||
|
{
|
||||||
|
struct ControlsState;
|
||||||
|
class ESMReader;
|
||||||
|
class ESMWriter;
|
||||||
|
}
|
||||||
|
|
||||||
|
namespace Loading
|
||||||
|
{
|
||||||
|
class Listener;
|
||||||
|
}
|
||||||
|
|
||||||
namespace MWInput
|
namespace MWInput
|
||||||
{
|
{
|
||||||
class ControlSwitch
|
class ControlSwitch
|
||||||
|
|
@ -14,6 +26,10 @@ namespace MWInput
|
||||||
void set(const std::string& key, bool value);
|
void set(const std::string& key, bool value);
|
||||||
void clear();
|
void clear();
|
||||||
|
|
||||||
|
void write(ESM::ESMWriter& writer, Loading::Listener& progress);
|
||||||
|
void readRecord(ESM::ESMReader& reader, uint32_t type);
|
||||||
|
int countSavedGameRecords() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, bool> mSwitches;
|
std::map<std::string, bool> mSwitches;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -208,39 +208,19 @@ namespace MWInput
|
||||||
|
|
||||||
int InputManager::countSavedGameRecords() const
|
int InputManager::countSavedGameRecords() const
|
||||||
{
|
{
|
||||||
return 1;
|
return mControlSwitch->countSavedGameRecords();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::write(ESM::ESMWriter& writer, Loading::Listener& /*progress*/)
|
void InputManager::write(ESM::ESMWriter& writer, Loading::Listener& progress)
|
||||||
{
|
{
|
||||||
ESM::ControlsState controls;
|
mControlSwitch->write(writer, progress);
|
||||||
controls.mViewSwitchDisabled = !getControlSwitch("playerviewswitch");
|
|
||||||
controls.mControlsDisabled = !getControlSwitch("playercontrols");
|
|
||||||
controls.mJumpingDisabled = !getControlSwitch("playerjumping");
|
|
||||||
controls.mLookingDisabled = !getControlSwitch("playerlooking");
|
|
||||||
controls.mVanityModeDisabled = !getControlSwitch("vanitymode");
|
|
||||||
controls.mWeaponDrawingDisabled = !getControlSwitch("playerfighting");
|
|
||||||
controls.mSpellDrawingDisabled = !getControlSwitch("playermagic");
|
|
||||||
|
|
||||||
writer.startRecord (ESM::REC_INPU);
|
|
||||||
controls.save(writer);
|
|
||||||
writer.endRecord (ESM::REC_INPU);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void InputManager::readRecord(ESM::ESMReader& reader, uint32_t type)
|
void InputManager::readRecord(ESM::ESMReader& reader, uint32_t type)
|
||||||
{
|
{
|
||||||
if (type == ESM::REC_INPU)
|
if (type == ESM::REC_INPU)
|
||||||
{
|
{
|
||||||
ESM::ControlsState controls;
|
mControlSwitch->readRecord(reader, type);
|
||||||
controls.load(reader);
|
|
||||||
|
|
||||||
toggleControlSwitch("playerviewswitch", !controls.mViewSwitchDisabled);
|
|
||||||
toggleControlSwitch("playercontrols", !controls.mControlsDisabled);
|
|
||||||
toggleControlSwitch("playerjumping", !controls.mJumpingDisabled);
|
|
||||||
toggleControlSwitch("playerlooking", !controls.mLookingDisabled);
|
|
||||||
toggleControlSwitch("vanitymode", !controls.mVanityModeDisabled);
|
|
||||||
toggleControlSwitch("playerfighting", !controls.mWeaponDrawingDisabled);
|
|
||||||
toggleControlSwitch("playermagic", !controls.mSpellDrawingDisabled);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue