Skip to content

Commit

Permalink
Merge pull request CleverRaven#10 from atomicdryad/readline_ish_and_more
Browse files Browse the repository at this point in the history
string_input_popup: line editing via arrows, optional persistent history backbuffer * new arguments (str title, int width, str default, str description, str history_id, int maxwid * if unset, max_width = width, or 1024 if width is unset / 0 * ^U clears li
  • Loading branch information
CIB committed Aug 10, 2013
2 parents f9073b9 + e4b061b commit e33574b
Show file tree
Hide file tree
Showing 9 changed files with 541 additions and 113 deletions.
47 changes: 43 additions & 4 deletions game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,32 @@ bool game::load_master()
return true;
}

void game::load_uistate() {
const std::string savedir="save";
std::stringstream savefile;
savefile << savedir << "/uistate.json";

std::ifstream fin;
fin.open(savefile.str().c_str());
if(!fin.good()) {
fin.close();
return;
}
picojson::value wrapped_data;
fin >> wrapped_data;
fin.close();
std::string jsonerr=picojson::get_last_error();
if ( ! jsonerr.empty() ) {
dbg(D_ERROR) << "load_uistate: " << jsonerr.c_str();
return;
}
bool success=uistate.load(wrapped_data);
if ( ! success ) {
dbg(D_ERROR) << "load_uistate: " << uistate.errdump;
}
uistate.errdump="";
}

void game::load_artifacts()
{
std::ifstream file_test("save/artifacts.gsav");
Expand Down Expand Up @@ -2669,6 +2695,7 @@ void game::load(std::string name)
u.inv.add_stack(tmpinv);
fin.close();
load_auto_pickup(true); // Load character auto pickup rules
load_uistate();
// Now load up the master game data; factions (and more?)
load_master();
update_map(u.posx, u.posy);
Expand Down Expand Up @@ -2722,6 +2749,17 @@ void game::save_maps()
MAPBUFFER.save();
}

void game::save_uistate() {
const std::string savedir="save";
std::stringstream savefile;
savefile << savedir << "/uistate.json";
std::ofstream fout;
fout.open(savefile.str().c_str());
fout << uistate.save();
fout.close();
uistate.errdump="";
}

std::string game::save_weather() const
{
std::stringstream weather_string;
Expand Down Expand Up @@ -2776,6 +2814,7 @@ void game::save()
fout.close();
//factions, missions, and npcs, maps and artifact data is saved in cleanup_at_end()
save_auto_pickup(true); // Save character auto pickup rules
save_uistate();
}

void game::delete_save()
Expand Down Expand Up @@ -7970,7 +8009,7 @@ std::string game::ask_item_filter(WINDOW* window, int rows)
mvwprintz(window, 8, 2, c_white, "%s", _("To exclude items, place - in front"));
mvwprintz(window, 9, 2, c_white, "%s", _("Example: -pipe,chunk,steel"));
wrefresh(window);
return string_input_popup(_("Filter:"), 55, sFilter);
return string_input_popup(_("Filter:"), 55, sFilter, _("UP: history, CTRL-U clear line, ESC: abort, ENTER: save"), "item_filter", 256);
}


Expand Down Expand Up @@ -8178,14 +8217,14 @@ void game::list_items()
}
else if(ch == '+')
{
std::string temp = string_input_popup(_("High Priority:"), width, list_item_upvote);
std::string temp = string_input_popup(_("High Priority:"), width, list_item_upvote, _("UP: history, CTRL-U clear line, ESC: abort, ENTER: save"), "list_item_priority", 256);
list_item_upvote = temp;
refilter = true;
reset = true;
}
else if(ch == '-')
{
std::string temp = string_input_popup(_("Low Priority:"), width, list_item_downvote);
std::string temp = string_input_popup(_("Low Priority:"), width, list_item_downvote, _("UP: history, CTRL-U clear line, ESC: abort, ENTER: save"), "list_item_downvote", 256);
list_item_downvote = temp;
refilter = true;
reset = true;
Expand Down Expand Up @@ -11633,7 +11672,7 @@ void game::quicksave(){
save_factions_missions_npcs();
save_artifacts();
save_maps();

save_uistate();
//Now reset counters for autosaving, so we don't immediately autosave after a quicksave or autosave.
moves_since_last_save = 0;
item_exchanges_since_save = 0;
Expand Down
3 changes: 2 additions & 1 deletion game.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,8 @@ void load_artifacts(); // Load artifact data
void save_artifacts();
void save_maps();
std::string save_weather() const;

void save_uistate();
void load_uistate();
// Data Initialization
void init_npctalk();
void init_materials();
Expand Down
14 changes: 12 additions & 2 deletions item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -731,10 +731,20 @@ std::string item::info(bool showtext, std::vector<iteminfo> *dump, game *g, bool
dump->push_back(iteminfo("DESCRIPTION", "\n\n"));
dump->push_back(iteminfo("DESCRIPTION", "This tool has double the normal maximum charges."));
}
std::map<std::string, std::string>::iterator item_note = item_vars.find("item_note");
std::map<std::string, std::string>::const_iterator item_note = item_vars.find("item_note");
std::map<std::string, std::string>::const_iterator item_note_type = item_vars.find("item_note_type");

if ( item_note != item_vars.end() ) {
dump->push_back(iteminfo("DESCRIPTION", "\n" ));
dump->push_back(iteminfo("DESCRIPTION", item_note->second ));
std::string ntext = "";
if ( item_note_type != item_vars.end() ) {
ntext += string_format(_("%1$s on this %2$s is a note saying: "),
item_note_type->second.c_str(), type->name.c_str()
);
} else {
ntext += "Note: ";
}
dump->push_back(iteminfo("DESCRIPTION", ntext + item_note->second ));
}
if (contents.size() > 0) {
if (is_gun()) {
Expand Down
29 changes: 22 additions & 7 deletions iuse.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,12 +94,27 @@ static bool inscribe_item( game *g, player *p, std::string verb, std::string ger
return false;
}

std::map<std::string, std::string>::iterator ent = cut->item_vars.find("item_note");
std::string message = string_format(_("%1$s on this %2$s is a note saying: "), gerund.c_str(), cut->type->name.c_str());
message = string_input_popup(string_format(_("%s what?"), verb.c_str()), 64, (ent != cut->item_vars.end() ?
cut->item_vars["item_note"] : message ));

if( message.size() > 0 ) { cut->item_vars["item_note"] = message; }
std::map<std::string, std::string>::const_iterator ent = cut->item_vars.find("item_note");
std::map<std::string, std::string>::const_iterator entprefix = cut->item_vars.find("item_note_type");
bool hasnote = (ent != cut->item_vars.end());
std::string message = "";
std::string messageprefix = string_format( hasnote ? _("(To delete, input one '.')\n") : "" ) +
string_format(_("%1$s on this %2$s is a note saying: "), gerund.c_str(), cut->type->name.c_str() );
message = string_input_popup(string_format(_("%s what?"), verb.c_str()), 64,
(hasnote ? cut->item_vars["item_note"] : message ),
messageprefix, "inscribe_item", 128
);

if( message.size() > 0 ) {
if ( hasnote && message == "." ) {
cut->item_vars.erase("item_note");
cut->item_vars.erase("item_note_type");
cut->item_vars.erase("item_note_typez");
} else {
cut->item_vars["item_note"] = message;
cut->item_vars["item_note_type"] = gerund;
}
}
return true;
}

Expand Down Expand Up @@ -4495,7 +4510,7 @@ void iuse::spray_can(game *g, player *p, item *it, bool t)

bool ismarker = (it->type->id=="permanent_marker");

std::string message = string_input_popup(ismarker?_("Write what?"):_("Spray what?"));
std::string message = string_input_popup(ismarker?_("Write what?"):_("Spray what?"),0,"","","graffiti");

if(message.empty())
{
Expand Down
Loading

0 comments on commit e33574b

Please sign in to comment.