Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
peterix committed May 21, 2012
2 parents 7866ab2 + 8102245 commit 1e09d67
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 2 deletions.
33 changes: 32 additions & 1 deletion library/modules/Gui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ using namespace std;
#include "MiscUtils.h"
using namespace DFHack;

#include "modules/Job.h"

#include "DataDefs.h"
#include "df/world.h"
#include "df/global_objects.h"
Expand All @@ -58,6 +60,7 @@ using namespace DFHack;
#include "df/viewscreen_layer_militaryst.h"
#include "df/viewscreen_petst.h"
#include "df/viewscreen_tradegoodsst.h"
#include "df/viewscreen_storesst.h"
#include "df/ui_unit_view_mode.h"
#include "df/ui_sidebar_menus.h"
#include "df/ui_look_list.h"
Expand Down Expand Up @@ -353,6 +356,9 @@ DEFINE_GET_FOCUS_STRING_HANDLER(pet)
if (vector_get(screen->trainer_unit, screen->trainer_cursor))
focus += "/Unit";
break;

default:
break;
}
}

Expand Down Expand Up @@ -391,6 +397,17 @@ DEFINE_GET_FOCUS_STRING_HANDLER(layer_assigntrade)
focus += "/Items";
}

DEFINE_GET_FOCUS_STRING_HANDLER(stores)
{
if (!screen->in_right_list)
focus += "/Categories";
else if (screen->in_group_mode)
focus += "/Groups";
else
focus += "/Items";
}


std::string Gui::getFocusString(df::viewscreen *top)
{
if (!top)
Expand Down Expand Up @@ -625,7 +642,13 @@ static df::unit *getAnyUnit(df::viewscreen *top)
using df::global::ui_selected_unit;

if (VIRTUAL_CAST_VAR(screen, df::viewscreen_joblistst, top))
return vector_get(screen->units, screen->cursor_pos);
{
if (auto unit = vector_get(screen->units, screen->cursor_pos))
return unit;
if (auto job = vector_get(screen->jobs, screen->cursor_pos))
return Job::getWorker(job);
return NULL;
}

if (VIRTUAL_CAST_VAR(screen, df::viewscreen_unitlistst, top))
return vector_get(screen->units[screen->page], screen->cursor_pos[screen->page]);
Expand Down Expand Up @@ -781,6 +804,14 @@ static df::item *getAnyItem(df::viewscreen *top)
return vector_get(screen->trader_items, screen->trader_cursor);
}

if (VIRTUAL_CAST_VAR(screen, df::viewscreen_storesst, top))
{
if (screen->in_right_list && !screen->in_group_mode)
return vector_get(screen->items, screen->item_cursor);

return NULL;
}

if (!Gui::dwarfmode_hotkey(top))
return NULL;

Expand Down
24 changes: 23 additions & 1 deletion plugins/sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include "modules/Gui.h"
#include "modules/Translation.h"
#include "modules/Units.h"
#include "modules/Job.h"

#include "LuaTools.h"

Expand All @@ -22,6 +23,7 @@
#include "df/viewscreen_tradegoodsst.h"
#include "df/viewscreen_dwarfmodest.h"
#include "df/viewscreen_petst.h"
#include "df/viewscreen_storesst.h"
#include "df/layer_object_listst.h"
#include "df/assign_trade_status.h"

Expand Down Expand Up @@ -273,7 +275,16 @@ DEFINE_SORT_HANDLER(unit_sorters, joblist, "", jobs)
{
PARSE_SPEC("units", parameters);

if (compute_order(*pout, L, top, &order, jobs->units))
std::vector<df::unit*> units;
for (size_t i = 0; i < jobs->units.size(); i++)
{
auto unit = jobs->units[i];
if (!unit && jobs->jobs[i])
unit = Job::getWorker(jobs->jobs[i]);
units.push_back(unit);
}

if (compute_order(*pout, L, top, &order, units))
{
reorder_cursor(&jobs->cursor_pos, order);
reorder_vector(&jobs->units, order);
Expand Down Expand Up @@ -526,6 +537,17 @@ DEFINE_SORT_HANDLER(item_sorters, layer_assigntrade, "/Items", bring)
}
}

DEFINE_SORT_HANDLER(item_sorters, stores, "/Items", stocks)
{
PARSE_SPEC("items", parameters);

if (compute_order(*pout, L, top, &order, stocks->items))
{
reorder_cursor(&stocks->item_cursor, order);
reorder_vector(&stocks->items, order);
}
}

static bool item_list_hotkey(df::viewscreen *screen)
{
auto focus = Gui::getFocusString(screen);
Expand Down

0 comments on commit 1e09d67

Please sign in to comment.