Strip out old offsets from Gui module and use df::global vars where available

develop
Quietust 2012-01-24 22:18:21 -06:00
parent 9a683ffda4
commit 902e0c4d90
3 changed files with 34 additions and 197 deletions

@ -629,7 +629,7 @@ bool Core::Init()
// init the console. // init the console.
Gui * g = getGui(); Gui * g = getGui();
bool is_text_mode = false; bool is_text_mode = false;
if(g->init && g->init->graphics.flags.is_set(GRAPHICS_TEXT)) if(df::global::init && df::global::init->display.flag.is_set(df::enums::init_display_flags::TEXT))
{ {
is_text_mode = true; is_text_mode = true;
} }
@ -843,19 +843,18 @@ bool Core::ncurses_wgetch(int in, int & out)
int idx = in - KEY_F(1); int idx = in - KEY_F(1);
// FIXME: copypasta, push into a method! // FIXME: copypasta, push into a method!
Gui * g = getGui(); Gui * g = getGui();
if(g->hotkeys && g->df_interface && g->df_menu_state) if(df::global::ui && df::global::gview && g->df_menu_state)
{ {
t_viewscreen * ws = g->GetCurrentScreen(); df::viewscreen * ws = g->GetCurrentScreen();
// FIXME: put hardcoded values into memory.xml // FIXME: put hardcoded values into memory.xml
if(ws->getClassName() == "viewscreen_dwarfmodest" && *g->df_menu_state == 0x23) if(((t_virtual *)ws)->getClassName() == "viewscreen_dwarfmodest" && *g->df_menu_state == 0x23)
{ {
out = in; out = in;
return true; return true;
} }
else else
{ {
t_hotkey & hotkey = (*g->hotkeys)[idx]; setHotkeyCmd(df::global::ui->main.hotkeys[idx].name);
setHotkeyCmd(hotkey.name);
return false; return false;
} }
} }

@ -32,6 +32,10 @@ distribution.
#include "BitArray.h" #include "BitArray.h"
#include <string> #include <string>
#include "DataDefs.h"
#include "df/init.h"
#include "df/ui.h"
namespace df { namespace df {
struct viewscreen; struct viewscreen;
struct job; struct job;
@ -86,88 +90,6 @@ namespace DFHack
DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true); DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true);
class DFContextShared; class DFContextShared;
/**
* A GUI screen
* \ingroup grp_gui
*/
struct t_viewscreen : public t_virtual
{
t_viewscreen * child;
t_viewscreen * parent;
char unk1; // varies
char unk2; // state?
};
/**
* Interface - wrapper for the GUI
* \ingroup grp_gui
*/
struct t_interface
{
int fps;
t_viewscreen view;
unsigned int flags; // ?
// more crud this way ...
};
enum graphics_flag
{
GRAPHICS_ENABLED = 0,
GRAPHICS_BLACKSPACE = 1,
GRAPHICS_PARTIAL_PRINT = 2,
GRAPHICS_TEXT = 11,
GRAPHICS_FIXED_SIZE = 13
};
enum media_flag
{
MEDIA_NO_SOUND,
MEDIA_NO_INTRO,
MEDIA_COMPRESS_WORLDS,
};
/**
* The init structure - basically DF settings
* \ingroup grp_gui
*/
struct t_init
{
struct
{
BitArray <graphics_flag> flags;
enum
{
WINDOWED_YES,
WINDOWED_NO,
WINDOWED_PROMPT
} windowed;
// screen size in tiles
int grid_x;
int grid_y;
// in pixels ?
int fullscreen_x;
int fullscreen_y;
int window_x;
int window_y;
char partial_print;
} graphics;
struct
{
BitArray <media_flag> flags;
int32_t volume;
} media;
// much more stuff follows
};
#define NUM_HOTKEYS 16
/**
* The hotkey structure
* \ingroup grp_gui
*/
struct t_hotkey
{
std::string name;
int16_t mode;
int32_t x;
int32_t y;
int32_t z;
};
typedef t_hotkey hotkey_array[NUM_HOTKEYS];
/** /**
* One tile of the screen. Possibly outdated. * One tile of the screen. Possibly outdated.
@ -212,23 +134,11 @@ namespace DFHack
/* /*
* Gui screens * Gui screens
*/ */
/// handle to the interface object
t_interface * df_interface;
/// Get the current top-level view-screen /// Get the current top-level view-screen
t_viewscreen * GetCurrentScreen(); df::viewscreen * GetCurrentScreen();
/// The DF menu state (designation menu ect) /// The DF menu state (designation menu ect)
uint32_t * df_menu_state; uint32_t * df_menu_state;
/*
* Hotkeys (DF's zoom locations)
*/
hotkey_array * hotkeys;
/*
* Game settings
*/
t_init * init;
/* /*
* Window size in tiles * Window size in tiles
*/ */

@ -47,7 +47,6 @@ using namespace DFHack;
#include "df/viewscreen_dwarfmodest.h" #include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_unitjobsst.h" #include "df/viewscreen_unitjobsst.h"
#include "df/viewscreen_itemst.h" #include "df/viewscreen_itemst.h"
#include "df/ui.h"
#include "df/ui_unit_view_mode.h" #include "df/ui_unit_view_mode.h"
#include "df/ui_sidebar_menus.h" #include "df/ui_sidebar_menus.h"
#include "df/ui_look_list.h" #include "df/ui_look_list.h"
@ -59,8 +58,14 @@ using namespace DFHack;
#include "df/unit_inventory_item.h" #include "df/unit_inventory_item.h"
#include "df/report.h" #include "df/report.h"
#include "df/popup_message.h" #include "df/popup_message.h"
#include "df/interface.h"
#include "df/graphic.h"
#include "df/selection_rect.h"
using namespace df::enums; using namespace df::enums;
using df::global::gview;
using df::global::init;
using df::global::gps;
// Predefined common guard functions // Predefined common guard functions
@ -457,25 +462,12 @@ struct Gui::Private
{ {
Started = false; Started = false;
StartedScreen = false; StartedScreen = false;
mouse_xy_offset = 0;
designation_xyz_offset = 0;
} }
bool Started; bool Started;
int32_t * window_x_offset; int32_t * window_x_offset;
int32_t * window_y_offset; int32_t * window_y_offset;
int32_t * window_z_offset; int32_t * window_z_offset;
struct xyz
{
int32_t x;
int32_t y;
int32_t z;
} * cursor_xyz_offset, * designation_xyz_offset;
struct xy
{
int32_t x;
int32_t y;
} * mouse_xy_offset, * window_dims_offset;
bool StartedScreen; bool StartedScreen;
void * screen_tiles_ptr_offset; void * screen_tiles_ptr_offset;
@ -491,26 +483,6 @@ Gui::Gui()
VersionInfo * mem = c.vinfo; VersionInfo * mem = c.vinfo;
OffsetGroup * OG_Gui = mem->getGroup("GUI"); OffsetGroup * OG_Gui = mem->getGroup("GUI");
// Setting up hotkeys
try
{
hotkeys = (hotkey_array *) OG_Gui->getAddress("hotkeys");
}
catch(Error::All &)
{
hotkeys = 0;
};
// Setting up init
try
{
init = (t_init *) OG_Gui->getAddress("init");
}
catch(Error::All &)
{
init = 0;
};
// Setting up menu state // Setting up menu state
try try
{ {
@ -521,16 +493,6 @@ Gui::Gui()
df_menu_state = 0; df_menu_state = 0;
}; };
// Setting up the view screen stuff
try
{
df_interface = (t_interface *) OG_Gui->getAddress ("interface");
}
catch(exception &)
{
df_interface = 0;
};
OffsetGroup * OG_Position; OffsetGroup * OG_Position;
try try
{ {
@ -538,28 +500,10 @@ Gui::Gui()
d->window_x_offset = (int32_t *) OG_Position->getAddress ("window_x"); d->window_x_offset = (int32_t *) OG_Position->getAddress ("window_x");
d->window_y_offset = (int32_t *) OG_Position->getAddress ("window_y"); d->window_y_offset = (int32_t *) OG_Position->getAddress ("window_y");
d->window_z_offset = (int32_t *) OG_Position->getAddress ("window_z"); d->window_z_offset = (int32_t *) OG_Position->getAddress ("window_z");
d->cursor_xyz_offset = (Private::xyz *) OG_Position->getAddress ("cursor_xyz");
d->window_dims_offset = (Private::xy *) OG_Position->getAddress ("window_dims");
d->Started = true; d->Started = true;
} }
catch(Error::All &){}; catch(Error::All &){};
try try
{
d->mouse_xy_offset = (Private::xy *) OG_Position->getAddress ("mouse_xy");
}
catch(Error::All &)
{
d->mouse_xy_offset = 0;
};
try
{
d->designation_xyz_offset = (Private::xyz *) OG_Position->getAddress ("designation_xyz");
}
catch(Error::All &)
{
d->designation_xyz_offset = 0;
};
try
{ {
d->screen_tiles_ptr_offset = (void *) OG_Position->getAddress ("screen_tiles_pointer"); d->screen_tiles_ptr_offset = (void *) OG_Position->getAddress ("screen_tiles_pointer");
d->StartedScreen = true; d->StartedScreen = true;
@ -582,11 +526,9 @@ bool Gui::Finish()
return true; return true;
} }
t_viewscreen * Gui::GetCurrentScreen() df::viewscreen * Gui::GetCurrentScreen()
{ {
if(!df_interface) df::viewscreen * ws = &gview->view;
return 0;
t_viewscreen * ws = &df_interface->view;
while(ws) while(ws)
{ {
if(ws->child) if(ws->child)
@ -625,12 +567,9 @@ bool Gui::setViewCoords (const int32_t x, const int32_t y, const int32_t z)
bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z) bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
if(!d->Started) return false; x = df::global::cursor->x;
int32_t coords[3]; y = df::global::cursor->y;
d->owner->read (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); z = df::global::cursor->z;
x = coords[0];
y = coords[1];
z = coords[2];
if (x == -30000) return false; if (x == -30000) return false;
return true; return true;
} }
@ -638,55 +577,44 @@ bool Gui::getCursorCoords (int32_t &x, int32_t &y, int32_t &z)
//FIXME: confine writing of coords to map bounds? //FIXME: confine writing of coords to map bounds?
bool Gui::setCursorCoords (const int32_t x, const int32_t y, const int32_t z) bool Gui::setCursorCoords (const int32_t x, const int32_t y, const int32_t z)
{ {
if (!d->Started) return false; df::global::cursor->x = x;
int32_t coords[3] = {x, y, z}; df::global::cursor->y = y;
d->owner->write (d->cursor_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); df::global::cursor->z = z;
return true; return true;
} }
bool Gui::getDesignationCoords (int32_t &x, int32_t &y, int32_t &z) bool Gui::getDesignationCoords (int32_t &x, int32_t &y, int32_t &z)
{ {
if(!d->designation_xyz_offset) return false; x = df::global::selection_rect->start_x;
int32_t coords[3]; y = df::global::selection_rect->start_y;
d->owner->read (d->designation_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); z = df::global::selection_rect->start_z;
x = coords[0];
y = coords[1];
z = coords[2];
if (x == -30000) return false; if (x == -30000) return false;
return true; return true;
} }
bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t z) bool Gui::setDesignationCoords (const int32_t x, const int32_t y, const int32_t z)
{ {
if(!d->designation_xyz_offset) return false; df::global::selection_rect->start_x = x;
int32_t coords[3] = {x, y, z}; df::global::selection_rect->start_y = y;
d->owner->write (d->designation_xyz_offset, 3*sizeof (int32_t), (uint8_t *) coords); df::global::selection_rect->start_z = z;
return true; return true;
} }
bool Gui::getMousePos (int32_t & x, int32_t & y) bool Gui::getMousePos (int32_t & x, int32_t & y)
{ {
if(!d->mouse_xy_offset) return false; x = gps->mouse_x;
int32_t coords[2]; y = gps->mouse_y;
d->owner->read (d->mouse_xy_offset, 2*sizeof (int32_t), (uint8_t *) coords);
x = coords[0];
y = coords[1];
if(x == -1) return false; if(x == -1) return false;
return true; return true;
} }
bool Gui::getWindowSize (int32_t &width, int32_t &height) bool Gui::getWindowSize (int32_t &width, int32_t &height)
{ {
if(!d->Started) return false; width = gps->dimx;
height = gps->dimy;
int32_t coords[2];
d->owner->read (d->window_dims_offset, 2*sizeof (int32_t), (uint8_t *) coords);
width = coords[0];
height = coords[1];
return true; return true;
} }
bool Gui::getScreenTiles (int32_t width, int32_t height, t_screen screen[]) bool Gui::getScreenTiles (int32_t width, int32_t height, t_screen screen[])
{ {
if(!d->StartedScreen) return false; if(!d->StartedScreen) return false;