Command prompt plugin with docs and readme patch.

develop
Warmist 2014-02-13 23:55:13 +02:00
parent 36b09c950d
commit 904808b168
5 changed files with 140 additions and 1 deletions

@ -6,6 +6,7 @@ DFHack future
New commands:
- move the 'grow', 'extirpate' and 'immolate' commands as 'plant' subcommands
- 'plant create' - spawn a new shrub under the cursor
- command-prompt: a dfhack command prompt in df.
Misc improvements:
- digfort: improved csv parsing, add start() comment handling

@ -329,6 +329,11 @@ Options:
The building must be one of stockpile, workshop, furnace, trap,
siege engine or an activity zone.
command-prompt
--------------
A one line command prompt in df. Same as entering command into dfhack console. Best
used as a keybinding.
Adventure mode
==============

@ -31,6 +31,9 @@ keybinding add Ctrl-Alt-S@dwarfmode/Default quicksave
keybinding add Ctrl-Shift-N gui/rename
keybinding add Ctrl-Shift-T "gui/rename unit-profession"
# a dfhack prompt in df. Sublime text like.
keybinding add Ctrl-Shift-P command-prompt
##############################
# Generic adv mode bindings #
##############################

@ -163,7 +163,7 @@ if (BUILD_SUPPORTED)
DFHACK_PLUGIN(cleanconst cleanconst.cpp)
DFHACK_PLUGIN(3dveins 3dveins.cpp)
DFHACK_PLUGIN(strangemood strangemood.cpp)
endif()
DFHACK_PLUGIN(command-prompt command-prompt.cpp)endif()
# this is the skeleton plugin. If you want to make your own, make a copy and then change it
OPTION(BUILD_SKELETON "Build the skeleton plugin." OFF)

@ -0,0 +1,130 @@
//command-prompt a one line command entry at the top of the screen for quick commands
#include "Core.h"
#include <Console.h>
#include <Export.h>
#include <PluginManager.h>
#include <modules/Screen.h>
#include <set>
#include "df/interface_key.h"
#include "df/ui.h"
#include "df/graphic.h"
#include "df/enabler.h"
using namespace DFHack;
using namespace df::enums;
using df::global::ui;
using df::global::gps;
using df::global::enabler;
class viewscreen_commandpromptst : public dfhack_viewscreen {
public:
void feed(std::set<df::interface_key> *events);
void logic() {
dfhack_viewscreen::logic();
}
void render();
void help() { }
std::string getFocusString() { return "commandprompt"; }
viewscreen_commandpromptst()
{
show_fps=df::global::gps->display_frames;
df::global::gps->display_frames=0;
}
~viewscreen_commandpromptst()
{
df::global::gps->display_frames=show_fps;
}
protected:
bool show_fps;
void submit();
std::string entry;
};
void viewscreen_commandpromptst::render()
{
if (Screen::isDismissed(this))
return;
dfhack_viewscreen::render();
auto dim = Screen::getWindowSize();
parent->render();
Screen::fillRect(Screen::Pen(' ', 7, 0),0,0,dim.x,0);
Screen::paintString(Screen::Pen(' ', 7, 0), 0, 0,"[DFHack]#");
if(entry.size()<dim.x)
Screen::paintString(Screen::Pen(' ', 7, 0), 10,0 , entry);
else
{
Screen::paintTile(Screen::Pen('>', 7, 0), 9, 0);
Screen::paintString(Screen::Pen(' ', 7, 0), 10, 0, entry.substr(entry.size()-dim.x));
}
}
void viewscreen_commandpromptst::submit()
{
CoreSuspendClaimer suspend;
color_ostream_proxy out(Core::getInstance().getConsole());
Core::getInstance().runCommand(out, entry);
Screen::dismiss(this);
}
void viewscreen_commandpromptst::feed(std::set<df::interface_key> *events)
{
bool leave_all = events->count(interface_key::LEAVESCREEN_ALL);
if (leave_all || events->count(interface_key::LEAVESCREEN))
{
events->clear();
Screen::dismiss(this);
if (leave_all)
{
events->insert(interface_key::LEAVESCREEN);
parent->feed(events);
events->clear();
}
return;
}
if(events->count(interface_key::SELECT))
{
submit();
return;
}
for (auto it = events->begin(); it != events->end(); ++it)
{
auto key = *it;
if (key==interface_key::STRING_A000) //delete?
{
if(entry.size())
entry.pop_back();
continue;
}
if (key >= interface_key::STRING_A000 &&
key <= interface_key::STRING_A255)
{
entry.push_back(char(key - interface_key::STRING_A000));
}
}
}
DFHACK_PLUGIN("command-prompt");
command_result show_prompt(color_ostream &out, std::vector <std::string> & parameters)
{
Screen::show(new viewscreen_commandpromptst);
return CR_OK;
}
DFhackCExport command_result plugin_init ( color_ostream &out, std::vector <PluginCommand> &commands)
{
commands.push_back(PluginCommand(
"command-prompt","Shows a command prompt on window.",show_prompt
));
return CR_OK;
}
DFhackCExport command_result plugin_shutdown ( color_ostream &out )
{
return CR_OK;
}