Move zoom-related commands to a separate dev plugin

develop
lethosor 2015-04-01 17:24:52 -04:00
parent 7913517b2c
commit 82d72007fc
3 changed files with 82 additions and 19 deletions

@ -19,6 +19,7 @@ DFHACK_PLUGIN(stockcheck stockcheck.cpp)
DFHACK_PLUGIN(stripcaged stripcaged.cpp)
DFHACK_PLUGIN(tilesieve tilesieve.cpp)
DFHACK_PLUGIN(vshook vshook.cpp)
DFHACK_PLUGIN(zoom zoom.cpp)
IF(UNIX)
DFHACK_PLUGIN(ref-index ref-index.cpp)

@ -36,7 +36,6 @@ command_result trackmenu (color_ostream &out, vector <string> & parameters);
command_result trackpos (color_ostream &out, vector <string> & parameters);
command_result trackstate (color_ostream &out, vector <string> & parameters);
command_result colormods (color_ostream &out, vector <string> & parameters);
command_result zoom (color_ostream &out, vector <string> & parameters);
DFHACK_PLUGIN("kittens");
@ -48,7 +47,6 @@ DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <Plug
commands.push_back(PluginCommand("trackpos","Track mouse and designation coords (toggle).",trackpos));
commands.push_back(PluginCommand("trackstate","Track world and map state (toggle).",trackstate));
commands.push_back(PluginCommand("colormods","Dump colormod vectors.",colormods));
commands.push_back(PluginCommand("zoom","Zoom to x y z.",zoom));
return CR_OK;
}
@ -185,23 +183,6 @@ command_result colormods (color_ostream &out, vector <string> & parameters)
return CR_OK;
}
// FIXME: move cursor properly relative to view position
command_result zoom (color_ostream &out, vector <string> & parameters)
{
if(parameters.size() < 3)
return CR_FAILURE;
int x = atoi( parameters[0].c_str());
int y = atoi( parameters[1].c_str());
int z = atoi( parameters[2].c_str());
int xi, yi, zi;
CoreSuspender cs;
if(Gui::getCursorCoords(xi, yi, zi))
{
Gui::setCursorCoords(x,y,z);
}
Gui::setViewCoords(x,y,z);
}
command_result ktimer (color_ostream &out, vector <string> & parameters)
{
if(timering)

@ -0,0 +1,81 @@
#include "Console.h"
#include "Core.h"
#include "DataDefs.h"
#include "Export.h"
#include "PluginManager.h"
#include <csignal>
#include <map>
#include <vector>
#include "modules/Gui.h"
#include "modules/World.h"
#include "df/enabler.h"
using namespace DFHack;
DFHACK_PLUGIN("zoom");
REQUIRE_GLOBAL(enabler);
command_result df_zoom (color_ostream &out, std::vector <std::string> & parameters);
command_result df_gzoom (color_ostream &out, std::vector <std::string> & parameters);
std::map<std::string, df::zoom_commands> zcmap;
DFhackCExport command_result plugin_init (color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand("zoom", "adjust screen zoom", df_zoom, false, "zoom [command]"));
commands.push_back(PluginCommand("gzoom", "zoom to grid location", df_gzoom, false, "gzoom x y z"));
zcmap["in"] = df::zoom_commands::zoom_in;
zcmap["out"] = df::zoom_commands::zoom_out;
zcmap["fullscreen"] = df::zoom_commands::zoom_fullscreen;
zcmap["reset"] = df::zoom_commands::zoom_reset;
zcmap["resetgrid"] = df::zoom_commands::zoom_resetgrid;
return CR_OK;
}
DFhackCExport command_result plugin_shutdown (color_ostream &out)
{
return CR_OK;
}
command_result df_zoom (color_ostream &out, std::vector <std::string> & parameters)
{
if (parameters.size() < 1)
return CR_WRONG_USAGE;
if (zcmap.find(parameters[0]) == zcmap.end())
{
out.printerr("Unrecognized zoom command: %s\n", parameters[0].c_str());
out.print("Valid commands:");
for (auto it = zcmap.begin(); it != zcmap.end(); ++it)
{
out << " " << it->first;
}
out.print("\n");
return CR_FAILURE;
}
df::zoom_commands cmd = zcmap[parameters[0]];
enabler->zoom_display(cmd);
if (cmd == df::zoom_commands::zoom_fullscreen)
enabler->fullscreen = !enabler->fullscreen;
return CR_OK;
}
command_result df_gzoom (color_ostream &out, std::vector<std::string> & parameters)
{
if(parameters.size() < 3)
return CR_WRONG_USAGE;
if (!World::isFortressMode())
{
out.printerr("Not fortress mode\n");
return CR_FAILURE;
}
int x = atoi( parameters[0].c_str());
int y = atoi( parameters[1].c_str());
int z = atoi( parameters[2].c_str());
int xi, yi, zi;
CoreSuspender cs;
if(Gui::getCursorCoords(xi, yi, zi))
{
Gui::setCursorCoords(x,y,z);
}
Gui::setViewCoords(x,y,z);
}