|
|
|
@ -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 <ColorText.h>
|
|
|
|
|
#include <Console.h>
|
|
|
|
|
#include <Export.h>
|
|
|
|
|
#include <MiscUtils.h>
|
|
|
|
|
#include <PluginManager.h>
|
|
|
|
|
#include <ColorText.h>
|
|
|
|
|
|
|
|
|
|
#include <modules/Screen.h>
|
|
|
|
|
#include <modules/Gui.h>
|
|
|
|
|
#include <modules/Screen.h>
|
|
|
|
|
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <list>
|
|
|
|
|
#include <set>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <utility>
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
#include "df/enabler.h"
|
|
|
|
|
#include "df/graphic.h"
|
|
|
|
|
#include "df/interface_key.h"
|
|
|
|
|
#include "df/ui.h"
|
|
|
|
|
#include "df/graphic.h"
|
|
|
|
|
#include "df/enabler.h"
|
|
|
|
|
|
|
|
|
|
using namespace DFHack;
|
|
|
|
|
using namespace df::enums;
|
|
|
|
@ -36,7 +38,9 @@ class prompt_ostream:public buffered_color_ostream
|
|
|
|
|
protected:
|
|
|
|
|
void flush_proxy();
|
|
|
|
|
public:
|
|
|
|
|
prompt_ostream(viewscreen_commandpromptst* parent):parent_(parent){}
|
|
|
|
|
prompt_ostream(viewscreen_commandpromptst* parent)
|
|
|
|
|
: parent_(parent)
|
|
|
|
|
{}
|
|
|
|
|
bool empty() { return buffer.empty(); }
|
|
|
|
|
};
|
|
|
|
|
class viewscreen_commandpromptst : public dfhack_viewscreen {
|
|
|
|
@ -57,7 +61,8 @@ public:
|
|
|
|
|
df::plant* getSelectedPlant() { return Gui::getAnyPlant(parent); }
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
gps->display_frames = 0;
|
|
|
|
@ -156,12 +161,18 @@ void viewscreen_commandpromptst::render()
|
|
|
|
|
parent->render();
|
|
|
|
|
if (is_response)
|
|
|
|
|
{
|
|
|
|
|
auto it=responses.begin();
|
|
|
|
|
for(int i=0;i<dim.y && it!=responses.end();i++,it++)
|
|
|
|
|
int y = 0;
|
|
|
|
|
for (auto &response : responses)
|
|
|
|
|
{
|
|
|
|
|
Screen::fillRect(Screen::Pen(' ', 7, 0),0,i,dim.x,i);
|
|
|
|
|
std::string cur_line=it->second;
|
|
|
|
|
Screen::paintString(Screen::Pen(' ',it->first,0),0,i,cur_line.substr(0,cur_line.size()-1));
|
|
|
|
|
std::vector<std::string> lines;
|
|
|
|
|
word_wrap(&lines, response.second, dim.x);
|
|
|
|
|
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
|
|
|
|
@ -170,7 +181,7 @@ void viewscreen_commandpromptst::render()
|
|
|
|
|
Screen::fillRect(Screen::Pen(' ', 7, 0), 0, 0, dim.x, 0);
|
|
|
|
|
Screen::paintString(Screen::Pen(' ', 7, 0), 0, 0, "[DFHack]#");
|
|
|
|
|
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);
|
|
|
|
|
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)
|
|
|
|
|
{
|
|
|
|
|
commands.push_back(PluginCommand(
|
|
|
|
|
"command-prompt","Shows a command prompt on window.",show_prompt,hotkey_allow_all,
|
|
|
|
|
"command-prompt [entry] - shows a cmd prompt in df window. Entry is used for default prefix (e.g. ':lua')"
|
|
|
|
|
"command-prompt", "Shows a command prompt on window.",
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|