dfhack/library/modules/Gui.cpp

132 lines
3.2 KiB
C++

/*
www.sourceforge.net/projects/dfhack
Copyright (c) 2009 Petr Mrázek (peterix), Kenneth Ferland (Impaler[WrG]), dorf
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any
damages arising from the use of this software.
Permission is granted to anyone to use this software for any
purpose, including commercial applications, and to alter it and
redistribute it freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must
not claim that you wrote the original software. If you use this
software in a product, an acknowledgment in the product documentation
would be appreciated but is not required.
2. Altered source versions must be plainly marked as such, and
must not be misrepresented as being the original software.
3. This notice may not be removed or altered from any source
distribution.
*/
#include "Internal.h"
#include "ContextShared.h"
2010-05-26 00:42:09 -06:00
#include "dfhack/modules/Gui.h"
2010-05-25 22:48:23 -06:00
#include "dfhack/DFProcess.h"
#include "dfhack/VersionInfo.h"
2010-05-25 22:48:23 -06:00
#include "dfhack/DFTypes.h"
2010-04-04 16:48:19 -06:00
using namespace DFHack;
2010-04-04 16:48:19 -06:00
struct Gui::Private
{
2010-08-31 04:59:48 -06:00
Private()
{
Started = PauseInited = ViewScreeInited = MenuStateInited = false;
}
2010-04-04 16:48:19 -06:00
bool Started;
uint32_t pause_state_offset;
2010-08-31 04:59:48 -06:00
bool PauseInited;
2010-04-04 16:48:19 -06:00
uint32_t view_screen_offset;
2010-08-31 04:59:48 -06:00
bool ViewScreeInited;
2010-04-04 16:48:19 -06:00
uint32_t current_menu_state_offset;
2010-08-31 04:59:48 -06:00
bool MenuStateInited;
DFContextShared *d;
2010-04-18 13:30:02 -06:00
Process * owner;
2010-04-04 16:48:19 -06:00
};
Gui::Gui(DFContextShared * _d)
2010-04-04 16:48:19 -06:00
{
2010-04-04 16:48:19 -06:00
d = new Private;
d->d = _d;
2010-04-18 13:30:02 -06:00
d->owner = _d->p;
OffsetGroup * OG_Gui = d->d->offset_descriptor->getGroup("GUI");
2010-08-31 04:59:48 -06:00
try
{
d->current_menu_state_offset = OG_Gui->getAddress("current_menu_state");
d->MenuStateInited = true;
}
catch(exception &){};
try
{
d->pause_state_offset = OG_Gui->getAddress ("pause_state");
d->PauseInited = true;
}
catch(exception &){};
try
{
d->view_screen_offset = OG_Gui->getAddress ("view_screen");
d->ViewScreeInited = true;
}
catch(exception &){};
d->Started = true;
2010-04-04 16:48:19 -06:00
}
Gui::~Gui()
{
delete d;
}
bool Gui::Start()
{
return true;
}
bool Gui::Finish()
{
return true;
}
bool Gui::ReadPauseState()
{
2010-08-31 04:59:48 -06:00
if(!d->PauseInited) return false;
2010-04-18 13:30:02 -06:00
uint32_t pauseState = d->owner->readDWord (d->pause_state_offset);
return pauseState & 1;
}
void Gui::SetPauseState(bool paused)
{
if(!d->PauseInited) return;
cout << "pause set" << endl;
d->owner->writeDWord (d->pause_state_offset, paused);
}
2010-04-04 16:48:19 -06:00
uint32_t Gui::ReadMenuState()
{
2010-08-31 04:59:48 -06:00
if(d->MenuStateInited)
2010-04-18 13:30:02 -06:00
return(d->owner->readDWord(d->current_menu_state_offset));
return false;
}
2010-04-04 16:48:19 -06:00
bool Gui::ReadViewScreen (t_viewscreen &screen)
{
2010-08-31 04:59:48 -06:00
if (!d->ViewScreeInited) return false;
2010-04-18 13:30:02 -06:00
Process * p = d->owner;
2010-04-18 13:30:02 -06:00
uint32_t last = p->readDWord (d->view_screen_offset);
uint32_t screenAddr = p->readDWord (last);
uint32_t nextScreenPtr = p->readDWord (last + 4);
while (nextScreenPtr != 0)
{
last = nextScreenPtr;
2010-04-18 13:30:02 -06:00
screenAddr = p->readDWord (nextScreenPtr);
nextScreenPtr = p->readDWord (nextScreenPtr + 4);
}
2010-04-04 16:48:19 -06:00
return d->d->offset_descriptor->resolveObjectToClassID (last, screen.type);
}