|
|
@ -1,23 +1,25 @@
|
|
|
|
//command-prompt a one line command entry at the top of the screen for quick commands
|
|
|
|
// command-prompt: A one-line command entry at the top of the screen for quick commands
|
|
|
|
|
|
|
|
|
|
|
|
#include "Core.h"
|
|
|
|
#include "Core.h"
|
|
|
|
|
|
|
|
#include <ColorText.h>
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Console.h>
|
|
|
|
#include <Export.h>
|
|
|
|
#include <Export.h>
|
|
|
|
|
|
|
|
#include <MiscUtils.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <PluginManager.h>
|
|
|
|
#include <ColorText.h>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <modules/Screen.h>
|
|
|
|
|
|
|
|
#include <modules/Gui.h>
|
|
|
|
#include <modules/Gui.h>
|
|
|
|
|
|
|
|
#include <modules/Screen.h>
|
|
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <list>
|
|
|
|
#include <list>
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <utility>
|
|
|
|
#include <utility>
|
|
|
|
#include <vector>
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "df/enabler.h"
|
|
|
|
|
|
|
|
#include "df/graphic.h"
|
|
|
|
#include "df/interface_key.h"
|
|
|
|
#include "df/interface_key.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/ui.h"
|
|
|
|
#include "df/graphic.h"
|
|
|
|
|
|
|
|
#include "df/enabler.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace DFHack;
|
|
|
|
using namespace df::enums;
|
|
|
|
using namespace df::enums;
|
|
|
@ -36,7 +38,9 @@ class prompt_ostream:public buffered_color_ostream
|
|
|
|
protected:
|
|
|
|
protected:
|
|
|
|
void flush_proxy();
|
|
|
|
void flush_proxy();
|
|
|
|
public:
|
|
|
|
public:
|
|
|
|
prompt_ostream(viewscreen_commandpromptst* parent):parent_(parent){}
|
|
|
|
prompt_ostream(viewscreen_commandpromptst* parent)
|
|
|
|
|
|
|
|
: parent_(parent)
|
|
|
|
|
|
|
|
{}
|
|
|
|
bool empty() { return buffer.empty(); }
|
|
|
|
bool empty() { return buffer.empty(); }
|
|
|
|
};
|
|
|
|
};
|
|
|
|
class viewscreen_commandpromptst : public dfhack_viewscreen {
|
|
|
|
class viewscreen_commandpromptst : public dfhack_viewscreen {
|
|
|
@ -57,7 +61,8 @@ public:
|
|
|
|
df::plant* getSelectedPlant() { return Gui::getAnyPlant(parent); }
|
|
|
|
df::plant* getSelectedPlant() { return Gui::getAnyPlant(parent); }
|
|
|
|
|
|
|
|
|
|
|
|
std::string getFocusString() { return "commandprompt"; }
|
|
|
|
std::string getFocusString() { return "commandprompt"; }
|
|
|
|
viewscreen_commandpromptst(std::string entry):submitted(false), is_response(false)
|
|
|
|
viewscreen_commandpromptst(std::string entry)
|
|
|
|
|
|
|
|
: submitted(false), is_response(false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
show_fps = gps->display_frames;
|
|
|
|
show_fps = gps->display_frames;
|
|
|
|
gps->display_frames = 0;
|
|
|
|
gps->display_frames = 0;
|
|
|
@ -156,12 +161,18 @@ void viewscreen_commandpromptst::render()
|
|
|
|
parent->render();
|
|
|
|
parent->render();
|
|
|
|
if (is_response)
|
|
|
|
if (is_response)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
auto it=responses.begin();
|
|
|
|
int y = 0;
|
|
|
|
for(int i=0;i<dim.y && it!=responses.end();i++,it++)
|
|
|
|
for (auto &response : responses)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Screen::fillRect(Screen::Pen(' ', 7, 0),0,i,dim.x,i);
|
|
|
|
std::vector<std::string> lines;
|
|
|
|
std::string cur_line=it->second;
|
|
|
|
word_wrap(&lines, response.second, dim.x);
|
|
|
|
Screen::paintString(Screen::Pen(' ',it->first,0),0,i,cur_line.substr(0,cur_line.size()-1));
|
|
|
|
for (auto &line : lines)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
Screen::fillRect(Screen::Pen(' ', 7, 0), 0, y, dim.x, y);
|
|
|
|
|
|
|
|
Screen::paintString(Screen::Pen(' ', response.first, 0), 0, y, line);
|
|
|
|
|
|
|
|
if (++y >= dim.y)
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -170,7 +181,7 @@ void viewscreen_commandpromptst::render()
|
|
|
|
Screen::fillRect(Screen::Pen(' ', 7, 0), 0, 0, dim.x, 0);
|
|
|
|
Screen::fillRect(Screen::Pen(' ', 7, 0), 0, 0, dim.x, 0);
|
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), 0, 0, "[DFHack]#");
|
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), 0, 0, "[DFHack]#");
|
|
|
|
std::string cursor = (frame < enabler->gfps / 2) ? "_" : " ";
|
|
|
|
std::string cursor = (frame < enabler->gfps / 2) ? "_" : " ";
|
|
|
|
if(cursor_pos < (dim.x - 10))
|
|
|
|
if (cursor_pos < dim.x - 10)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), 10, 0, entry);
|
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), 10, 0, entry);
|
|
|
|
if (int16_t(entry.size()) > dim.x - 10)
|
|
|
|
if (int16_t(entry.size()) > dim.x - 10)
|
|
|
@ -333,8 +344,10 @@ bool hotkey_allow_all(df::viewscreen *top)
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
DFhackCExport command_result plugin_init(color_ostream &out, std::vector <PluginCommand> &commands)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
"command-prompt","Shows a command prompt on window.",show_prompt,hotkey_allow_all,
|
|
|
|
"command-prompt", "Shows a command prompt on window.",
|
|
|
|
"command-prompt [entry] - shows a cmd prompt in df window. Entry is used for default prefix (e.g. ':lua')"
|
|
|
|
show_prompt, hotkey_allow_all,
|
|
|
|
|
|
|
|
"command-prompt [entry] - shows a cmd prompt in df window."
|
|
|
|
|
|
|
|
" Entry is used for default prefix (e.g. ':lua')"
|
|
|
|
));
|
|
|
|
));
|
|
|
|
return CR_OK;
|
|
|
|
return CR_OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|