Merge branch 'master' of git://github.com/peterix/dfhack
commit
a25c0b81de
@ -0,0 +1,91 @@
|
||||
/*
|
||||
https://github.com/peterix/dfhack
|
||||
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
||||
|
||||
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.
|
||||
*/
|
||||
|
||||
/*******************************************************************************
|
||||
GRAPHIC
|
||||
Changing tile cache
|
||||
*******************************************************************************/
|
||||
#pragma once
|
||||
#ifndef CL_MOD_GRAPHIC
|
||||
#define CL_MOD_GRAPHIC
|
||||
|
||||
#include <stdint.h>
|
||||
#include "dfhack/Export.h"
|
||||
#include "dfhack/Module.h"
|
||||
|
||||
namespace DFHack
|
||||
{
|
||||
// SDL stuff
|
||||
typedef signed short SINT16;
|
||||
typedef struct
|
||||
{
|
||||
int16_t x, y;
|
||||
uint16_t w, h;
|
||||
} DFSDL_Rect;
|
||||
typedef struct
|
||||
{
|
||||
uint32_t flags;
|
||||
void* format; // PixelFormat*
|
||||
int w, h;
|
||||
int pitch;
|
||||
void* pixels;
|
||||
void* userdata; // as far as i could see DF doesnt use this
|
||||
int locked;
|
||||
void* lock_data;
|
||||
DFSDL_Rect clip_rect;
|
||||
void* map;
|
||||
int refcount;
|
||||
} DFSDL_Surface;
|
||||
|
||||
// =========
|
||||
struct DFTileSurface
|
||||
{
|
||||
bool paintOver; // draw over original tile?
|
||||
DFSDL_Surface* surface; // from where it should be drawn
|
||||
DFSDL_Rect* rect; // from which coords (NULL to draw whole surface)
|
||||
DFSDL_Rect* dstResize; // if not NULL dst rect will be resized (x/y/w/h will be added to original dst)
|
||||
};
|
||||
|
||||
|
||||
class DFHACK_EXPORT Graphic : public Module
|
||||
{
|
||||
public:
|
||||
Graphic();
|
||||
~Graphic();
|
||||
bool Finish()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
bool Register(DFTileSurface* (*func)(int,int));
|
||||
bool Unregister(DFTileSurface* (*func)(int,int));
|
||||
DFTileSurface* Call(int x, int y);
|
||||
|
||||
private:
|
||||
struct Private;
|
||||
Private *d;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
@ -0,0 +1,112 @@
|
||||
/*
|
||||
https://github.com/peterix/dfhack
|
||||
Copyright (c) 2009-2011 Petr Mrázek (peterix@gmail.com)
|
||||
|
||||
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 <string>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <cassert>
|
||||
#include <cstdlib>
|
||||
using namespace std;
|
||||
|
||||
#include "dfhack/modules/Graphic.h"
|
||||
#include "dfhack/Error.h"
|
||||
#include "dfhack/VersionInfo.h"
|
||||
#include "dfhack/Process.h"
|
||||
#include "dfhack/Vector.h"
|
||||
#include "ModuleFactory.h"
|
||||
#include <dfhack/Core.h>
|
||||
|
||||
using namespace DFHack;
|
||||
|
||||
Module* DFHack::createGraphic()
|
||||
{
|
||||
return new Graphic();
|
||||
}
|
||||
|
||||
struct Graphic::Private
|
||||
{
|
||||
bool Started;
|
||||
vector<DFTileSurface* (*)(int,int)> funcs;
|
||||
};
|
||||
|
||||
Graphic::Graphic()
|
||||
{
|
||||
d = new Private;
|
||||
|
||||
d->Started = true;
|
||||
}
|
||||
|
||||
Graphic::~Graphic()
|
||||
{
|
||||
delete d;
|
||||
}
|
||||
|
||||
bool Graphic::Register(DFTileSurface* (*func)(int,int))
|
||||
{
|
||||
d->funcs.push_back(func);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Graphic::Unregister(DFTileSurface* (*func)(int,int))
|
||||
{
|
||||
if ( d->funcs.empty() ) return false;
|
||||
|
||||
vector<DFTileSurface* (*)(int,int)>::iterator it = d->funcs.begin();
|
||||
while ( it != d->funcs.end() )
|
||||
{
|
||||
if ( *it == func )
|
||||
{
|
||||
d->funcs.erase(it);
|
||||
return true;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// This will return first DFTileSurface it can get (or NULL if theres none)
|
||||
DFTileSurface* Graphic::Call(int x, int y)
|
||||
{
|
||||
if ( d->funcs.empty() ) return NULL;
|
||||
|
||||
DFTileSurface* temp = NULL;
|
||||
|
||||
vector<DFTileSurface* (*)(int,int)>::iterator it = d->funcs.begin();
|
||||
while ( it != d->funcs.end() )
|
||||
{
|
||||
temp = (*it)(x,y);
|
||||
if ( temp != NULL )
|
||||
{
|
||||
return temp;
|
||||
}
|
||||
it++;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
@ -1 +1 @@
|
||||
Subproject commit 71d28909ec397d0a772e6135a822cc1c4a5fd3a7
|
||||
Subproject commit dbfeaf935df92644b72746842166baf700450e15
|
@ -0,0 +1,148 @@
|
||||
// This tool display dfhack version on df screen
|
||||
|
||||
#include <Windows.h>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <map>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
using namespace std;
|
||||
#include <dfhack/Core.h>
|
||||
#include <dfhack/Console.h>
|
||||
#include <dfhack/Export.h>
|
||||
#include <dfhack/PluginManager.h>
|
||||
#include <dfhack/modules/Graphic.h>
|
||||
#include <dfhack/modules/Gui.h>
|
||||
using namespace DFHack;
|
||||
|
||||
DFhackCExport command_result df_versionosd (Core * c, vector <string> & parameters);
|
||||
static DFSDL_Surface* (*_IMG_LoadPNG_RW)(void* src) = 0;
|
||||
static vPtr (*_SDL_RWFromFile)(const char* file, const char *mode) = 0;
|
||||
static int (*_SDL_SetAlpha)(vPtr surface, uint32_t flag, uint8_t alpha) = 0;
|
||||
static int (*_SDL_SetColorKey)(vPtr surface, uint32_t flag, uint32_t key) = 0;
|
||||
static uint32_t (*_SDL_MapRGB)(vPtr pixelformat, uint8_t r, uint8_t g, uint8_t b) = 0;
|
||||
DFTileSurface* gettile(int x, int y);
|
||||
|
||||
bool On = true;
|
||||
DFSDL_Surface* surface;
|
||||
DFTileSurface* tiles[10];
|
||||
char* file = "Cooz_curses_square_16x16.png";
|
||||
Gui* gui;
|
||||
|
||||
DFhackCExport const char * plugin_name ( void )
|
||||
{
|
||||
return "versionosd";
|
||||
}
|
||||
|
||||
DFTileSurface* createTile(int x, int y)
|
||||
{
|
||||
DFTileSurface* tile = new DFTileSurface;
|
||||
tile->paintOver = true;
|
||||
tile->rect = new DFSDL_Rect;
|
||||
tile->rect->x = x*16;
|
||||
tile->rect->y = y*16;
|
||||
tile->rect->w = 16;
|
||||
tile->rect->h = 16;
|
||||
tile->surface = surface;
|
||||
tile->dstResize = NULL;
|
||||
return tile;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_init ( Core * c, std::vector <PluginCommand> &commands)
|
||||
{
|
||||
commands.clear();
|
||||
commands.push_back(PluginCommand("versionosd",
|
||||
"Toggles displaying version in DF window",
|
||||
df_versionosd));
|
||||
|
||||
HMODULE SDLImageLib = LoadLibrary("SDL_image.dll");
|
||||
_IMG_LoadPNG_RW = (DFHack::DFSDL_Surface* (*)(void*))GetProcAddress(SDLImageLib, "IMG_LoadPNG_RW");
|
||||
|
||||
HMODULE realSDLlib = LoadLibrary("SDLreal.dll");
|
||||
_SDL_RWFromFile = (void*(*)(const char*, const char*))GetProcAddress(realSDLlib,"SDL_RWFromFile");
|
||||
_SDL_SetAlpha = (int (*)(void*, uint32_t, uint8_t))GetProcAddress(realSDLlib,"SDL_SetAlpha");
|
||||
_SDL_SetColorKey = (int (*)(void*, uint32_t, uint32_t))GetProcAddress(realSDLlib,"SDL_SetColorKey");
|
||||
_SDL_MapRGB = (uint32_t (*)(void*, uint8_t, uint8_t, uint8_t))GetProcAddress(realSDLlib,"SDL_MapRGB");
|
||||
|
||||
void* RWop = _SDL_RWFromFile(file, "rb");
|
||||
surface = _IMG_LoadPNG_RW(RWop);
|
||||
|
||||
if ( !surface )
|
||||
{
|
||||
c->con.print("Couldnt load image from file %s", file);
|
||||
return CR_FAILURE;
|
||||
}
|
||||
|
||||
UINT32 pink = _SDL_MapRGB(vPtr(surface->format), 0xff, 0x00, 0xff);
|
||||
|
||||
_SDL_SetColorKey((vPtr)surface, 4096, pink);
|
||||
_SDL_SetAlpha((vPtr)surface, 65536, 255);
|
||||
|
||||
|
||||
// setup tiles
|
||||
tiles[0] = createTile(4, 4); // D
|
||||
tiles[1] = createTile(6, 4); // F
|
||||
tiles[2] = createTile(8, 4); // H
|
||||
tiles[3] = createTile(1, 6); // a
|
||||
tiles[4] = createTile(3, 6); // c
|
||||
tiles[5] = createTile(11, 6); // k
|
||||
tiles[6] = createTile(0, 0); // " "
|
||||
// FIXME: it should get REAL version not hardcoded one
|
||||
tiles[7] = createTile(2, 7); // r
|
||||
tiles[8] = createTile(8, 3); // 8
|
||||
|
||||
tiles[9] = createTile(9, 0); // o
|
||||
|
||||
gui = c->getGui();
|
||||
|
||||
|
||||
Graphic* g = c->getGraphic();
|
||||
g->Register(gettile);
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result plugin_shutdown ( Core * c )
|
||||
{
|
||||
Graphic* g = c->getGraphic();
|
||||
g->Unregister(gettile);
|
||||
delete surface;
|
||||
|
||||
for (int i=0; i<10; i++)
|
||||
{
|
||||
delete tiles[i];
|
||||
}
|
||||
delete [] tiles;
|
||||
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFhackCExport command_result df_versionosd (Core * c, vector <string> & parameters)
|
||||
{
|
||||
On = !On;
|
||||
c->Suspend();
|
||||
c->con.print("Version OSD is %s\n", On ? "On" : "Off");
|
||||
c->Resume();
|
||||
return CR_OK;
|
||||
}
|
||||
|
||||
DFTileSurface* gettile (int x, int y)
|
||||
{
|
||||
if ( !On ) return NULL;
|
||||
|
||||
if ( x == 0 && y-4 >= 0 && y-4 < 9 )
|
||||
{
|
||||
return tiles[y-4];
|
||||
}
|
||||
|
||||
int32_t cx, cy, cz;
|
||||
int32_t vx, vy, vz;
|
||||
if ( !gui->getViewCoords(vx, vy, vz) ) return NULL;
|
||||
if ( !gui->getCursorCoords(cx, cy, cz) ) return NULL;
|
||||
if ( cx-vx+1 == x && cy-vy+1 == y )
|
||||
{
|
||||
return tiles[9];
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
Loading…
Reference in New Issue