Support showing announcements, as suggested by Q.

develop
Alexander Gavrilov 2012-01-15 15:19:20 +04:00
parent 54485d2551
commit 0f56611edc
3 changed files with 90 additions and 5 deletions

@ -48,24 +48,43 @@ namespace DFHack
{ {
class Core; class Core;
// Full-screen item details view
DFHACK_EXPORT bool item_details_hotkey(Core *, df::viewscreen *top); DFHACK_EXPORT bool item_details_hotkey(Core *, df::viewscreen *top);
// 'u'nits or 'j'obs full-screen view
DFHACK_EXPORT bool unitjobs_hotkey(Core *, df::viewscreen *top); DFHACK_EXPORT bool unitjobs_hotkey(Core *, df::viewscreen *top);
// A job is selected in a workshop
DFHACK_EXPORT bool workshop_job_hotkey(Core *c, df::viewscreen *top); DFHACK_EXPORT bool workshop_job_hotkey(Core *c, df::viewscreen *top);
// Building material selection mode
DFHACK_EXPORT bool build_selector_hotkey(Core *c, df::viewscreen *top); DFHACK_EXPORT bool build_selector_hotkey(Core *c, df::viewscreen *top);
// A unit is selected in the 'v' mode
DFHACK_EXPORT bool view_unit_hotkey(Core *c, df::viewscreen *top); DFHACK_EXPORT bool view_unit_hotkey(Core *c, df::viewscreen *top);
// Above + the inventory page is selected.
DFHACK_EXPORT bool unit_inventory_hotkey(Core *c, df::viewscreen *top); DFHACK_EXPORT bool unit_inventory_hotkey(Core *c, df::viewscreen *top);
DFHACK_EXPORT bool any_job_hotkey(Core *c, df::viewscreen *top); // In workshop_job_hotkey, returns the job
DFHACK_EXPORT bool any_unit_hotkey(Core *c, df::viewscreen *top);
DFHACK_EXPORT bool any_item_hotkey(Core *c, df::viewscreen *top);
DFHACK_EXPORT df::job *getSelectedWorkshopJob(Core *c, bool quiet = false); DFHACK_EXPORT df::job *getSelectedWorkshopJob(Core *c, bool quiet = false);
// A job is selected in a workshop, or unitjobs
DFHACK_EXPORT bool any_job_hotkey(Core *c, df::viewscreen *top);
DFHACK_EXPORT df::job *getSelectedJob(Core *c, bool quiet = false); DFHACK_EXPORT df::job *getSelectedJob(Core *c, bool quiet = false);
// A unit is selected via 'v', 'k', unitjobs, or
// a full-screen item view of a cage or suchlike
DFHACK_EXPORT bool any_unit_hotkey(Core *c, df::viewscreen *top);
DFHACK_EXPORT df::unit *getSelectedUnit(Core *c, bool quiet = false); DFHACK_EXPORT df::unit *getSelectedUnit(Core *c, bool quiet = false);
// An item is selected via 'v'->inventory, 'k', 't', or
// a full-screen item view of a container. Note that in the
// last case, the highlighted contained item is returned, not
// the container itself.
DFHACK_EXPORT bool any_item_hotkey(Core *c, df::viewscreen *top);
DFHACK_EXPORT df::item *getSelectedItem(Core *c, bool quiet = false); DFHACK_EXPORT df::item *getSelectedItem(Core *c, bool quiet = false);
// Show a plain announcement, or a titan-style popup message
DFHACK_EXPORT void showAnnouncement(std::string message, int color = 7, bool bright = true);
DFHACK_EXPORT void showPopupAnnouncement(std::string message, int color = 7, bool bright = true);
class DFContextShared; class DFContextShared;
/** /**
* A GUI screen * A GUI screen

@ -57,6 +57,8 @@ using namespace DFHack;
#include "df/building_furnacest.h" #include "df/building_furnacest.h"
#include "df/general_ref.h" #include "df/general_ref.h"
#include "df/unit_inventory_item.h" #include "df/unit_inventory_item.h"
#include "df/report.h"
#include "df/popup_message.h"
using namespace df::enums; using namespace df::enums;
@ -380,6 +382,70 @@ df::item *DFHack::getSelectedItem(Core *c, bool quiet)
// //
void DFHack::showAnnouncement(std::string message, int color, bool bright)
{
using df::global::world;
using df::global::cur_year;
using df::global::cur_year_tick;
int year = 0, year_time = 0;
if (cur_year && cur_year_tick)
{
year = *cur_year;
year_time = *cur_year_tick;
}
else if (!world->status.reports.empty())
{
// Fallback: copy from the last report
df::report *last = world->status.reports.back();
year = last->year;
year_time = last->time;
}
bool continued = false;
while (!message.empty())
{
df::report *new_rep = new df::report();
new_rep->color = color;
new_rep->bright = bright;
new_rep->year = year;
new_rep->time = year_time;
new_rep->flags.bits.continuation = continued;
new_rep->flags.bits.announcement = true;
int size = std::min(message.size(), 73U);
new_rep->text = message.substr(0, size);
message = message.substr(size);
continued = true;
// Add the object to the lists
new_rep->id = world->status.next_report_id++;
world->status.reports.push_back(new_rep);
world->status.announcements.push_back(new_rep);
world->status.display_timer = 2000;
}
}
void DFHack::showPopupAnnouncement(std::string message, int color, bool bright)
{
using df::global::world;
df::popup_message *popup = new df::popup_message();
popup->text = message;
popup->color = color;
popup->bright = bright;
world->status.popups.push_back(popup);
}
//
Module* DFHack::createGui() Module* DFHack::createGui()
{ {
return new Gui(); return new Gui();

@ -1 +1 @@
Subproject commit f9c6d105af74cd4e307f513a7df674e685dc9ff0 Subproject commit 30ce6e3d537ccc51e232c129680d53d5d58180fc