More detail in build menu

develop
JapaMala 2018-07-01 14:00:05 +05:30
parent 44f461711c
commit 9c2e052d4d
3 changed files with 102 additions and 32 deletions

@ -24,13 +24,21 @@ enum MenuAction
MenuNone = 0; MenuNone = 0;
MenuSelect = 1; MenuSelect = 1;
MenuCancel = 2; MenuCancel = 2;
MenuSelectAll = 3;
}
enum BuildSelectorStage
{
StageNoMat = 0;
StagePlace = 1;
StageItemSelect = 2;
} }
message SidebarState message SidebarState
{ {
optional proto.enums.ui_sidebar_mode.ui_sidebar_mode mode = 1; optional proto.enums.ui_sidebar_mode.ui_sidebar_mode mode = 1;
repeated MenuItem menu_items = 2; repeated MenuItem menu_items = 2;
optional BuildSelector buildSelector = 3; optional BuildSelector build_selector = 3;
} }
message MenuItem message MenuItem
@ -47,7 +55,29 @@ message SidebarCommand
optional MenuAction action = 3; optional MenuAction action = 3;
} }
message BuiildReqChoice
{
optional int32 distance = 1;
optional string name = 2;
optional int32 num_candidates = 3;
optional int32 used_count = 4;
}
message BuildItemReq
{
//Put filter here = 1
optional int32 count_required = 2;
optional int32 count_max = 3;
optional int32 count_provided = 4;
}
message BuildSelector message BuildSelector
{ {
optional RemoteFortressReader.BuildingType building_type = 1; optional RemoteFortressReader.BuildingType building_type = 1;
optional BuildSelectorStage stage = 2;
repeated BuiildReqChoice choices = 3;
optional int32 sel_index = 4;
repeated BuildItemReq requirements = 5;
optional int32 req_index = 6;
repeated string errors = 7;
} }

@ -78,7 +78,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(-1); bld->mutable_building_type()->set_building_subtype(-1);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt)); bld->set_id(ENUM_KEY_STR(building_type, bt));
bld->set_name(ENUM_ATTR_STR(building_type, name, bt));
switch (bt) switch (bt)
{ {
case df::enums::building_type::NONE: case df::enums::building_type::NONE:
@ -101,6 +101,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(furnace_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(furnace_type, st));
bld->set_name(ENUM_ATTR_STR(furnace_type, name, st));
if (st == furnace_type::Custom) if (st == furnace_type::Custom)
{ {
@ -128,7 +129,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(shop_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(shop_type, st));
bld->set_name(ENUM_KEY_STR(shop_type, st));
} }
break; break;
case df::enums::building_type::Door: case df::enums::building_type::Door:
@ -149,6 +150,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(workshop_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(workshop_type, st));
bld->set_name(ENUM_ATTR_STR(workshop_type, name, st));
if (st == workshop_type::Custom) if (st == workshop_type::Custom)
{ {
@ -190,7 +192,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(siegeengine_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(siegeengine_type, st));
bld->set_name(ENUM_KEY_STR(siegeengine_type, st));
} }
break; break;
case df::enums::building_type::Trap: case df::enums::building_type::Trap:
@ -201,7 +203,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(trap_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(trap_type, st));
bld->set_name(ENUM_KEY_STR(trap_type, st));
} }
break; break;
case df::enums::building_type::AnimalTrap: case df::enums::building_type::AnimalTrap:
@ -224,7 +226,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(civzone_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(civzone_type, st));
bld->set_name(ENUM_KEY_STR(civzone_type, st));
} }
break; break;
case df::enums::building_type::Weapon: case df::enums::building_type::Weapon:
@ -241,7 +243,7 @@ DFHack::command_result GetBuildingDefList(DFHack::color_ostream &stream, const D
bld->mutable_building_type()->set_building_subtype(st); bld->mutable_building_type()->set_building_subtype(st);
bld->mutable_building_type()->set_building_custom(-1); bld->mutable_building_type()->set_building_custom(-1);
bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(construction_type, st)); bld->set_id(ENUM_KEY_STR(building_type, bt) + "/" + ENUM_KEY_STR(construction_type, st));
bld->set_name(ENUM_KEY_STR(construction_type, st));
} }
break; break;
case df::enums::building_type::Hatch: case df::enums::building_type::Hatch:

@ -2,11 +2,15 @@
#include "DataDefs.h" #include "DataDefs.h"
#include "df_version_int.h" #include "df_version_int.h"
#include "df/build_req_choice_genst.h"
#include "df/build_req_choice_specst.h"
#include "df/build_req_choicest.h"
#include "df/job.h" #include "df/job.h"
#include "df/job_list_link.h" #include "df/job_list_link.h"
#include "df/interface_button_construction_building_selectorst.h" #include "df/interface_button_construction_building_selectorst.h"
#include "df/interface_button_construction_category_selectorst.h" #include "df/interface_button_construction_category_selectorst.h"
#include "df/ui.h" #include "df/ui.h"
#include "df/ui_build_selector.h"
#include "df/ui_sidebar_menus.h" #include "df/ui_sidebar_menus.h"
#include "df/viewscreen.h" #include "df/viewscreen.h"
#include "df/world.h" #include "df/world.h"
@ -112,6 +116,57 @@ command_result SetPauseState(color_ostream &stream, const SingleBool *in)
return CR_OK; return CR_OK;
} }
void CopyBuildMenu(DwarfControl::SidebarState * out)
{
auto menus = df::global::ui_sidebar_menus;
auto build_selector = df::global::ui_build_selector;
if (build_selector->building_type == -1)
for (int i = 0; i < menus->building.choices_visible.size(); i++)
{
auto menu_item = menus->building.choices_visible[i];
auto send_item = out->add_menu_items();
STRICT_VIRTUAL_CAST_VAR(building, df::interface_button_construction_building_selectorst, menu_item);
if (building)
{
auto send_bld = send_item->mutable_building_type();
send_bld->set_building_type(building->building_type);
send_bld->set_building_subtype(building->building_subtype);
send_bld->set_building_custom(building->custom_type);
send_item->set_existing_count(building->existing_count);
}
STRICT_VIRTUAL_CAST_VAR(sub_category, df::interface_button_construction_category_selectorst, menu_item);
if (sub_category)
{
send_item->set_build_category((DwarfControl::BuildCategory)sub_category->category_id);
}
}
else
{
auto send_selector = out->mutable_build_selector();
auto send_bld = send_selector->mutable_building_type();
send_bld->set_building_type(build_selector->building_type);
send_bld->set_building_subtype(build_selector->building_subtype);
send_bld->set_building_custom(build_selector->custom_type);
send_selector->set_stage((DwarfControl::BuildSelectorStage)build_selector->stage);
for (int i = 0; i < build_selector->errors.size(); i++)
{
if (build_selector->errors[i])
send_selector->add_errors(*build_selector->errors[i]);
}
for (int i = 0; i < build_selector->choices.size(); i++)
{
auto choice = build_selector->choices[i];
auto send_choice = send_selector->add_choices();
send_choice->set_distance(choice->distance);
std::string name;
choice->getName(&name);
send_choice->set_name(name);
send_choice->set_num_candidates(choice->getNumCandidates());
send_choice->set_used_count(choice->getUsedCount());
}
}
}
command_result GetSideMenu(DFHack::color_ostream &stream, const dfproto::EmptyMessage *in, DwarfControl::SidebarState *out) command_result GetSideMenu(DFHack::color_ostream &stream, const dfproto::EmptyMessage *in, DwarfControl::SidebarState *out)
{ {
auto ui = df::global::ui; auto ui = df::global::ui;
@ -152,28 +207,7 @@ command_result GetSideMenu(DFHack::color_ostream &stream, const dfproto::EmptyMe
case ui_sidebar_mode::Stockpiles: case ui_sidebar_mode::Stockpiles:
break; break;
case ui_sidebar_mode::Build: case ui_sidebar_mode::Build:
{ CopyBuildMenu(out);
auto menus = df::global::ui_sidebar_menus;
for (int i = 0; i < menus->building.choices_visible.size(); i++)
{
auto menu_item = menus->building.choices_visible[i];
auto send_item = out->add_menu_items();
STRICT_VIRTUAL_CAST_VAR(building, df::interface_button_construction_building_selectorst, menu_item);
if (building)
{
auto send_bld = send_item->mutable_building_type();
send_bld->set_building_type(building->building_type);
send_bld->set_building_subtype(building->building_subtype);
send_bld->set_building_custom(building->custom_type);
send_item->set_existing_count(building->existing_count);
}
STRICT_VIRTUAL_CAST_VAR(sub_category, df::interface_button_construction_category_selectorst, menu_item);
if (sub_category)
{
send_item->set_build_category((DwarfControl::BuildCategory)sub_category->category_id);
}
}
}
break; break;
case ui_sidebar_mode::QueryBuilding: case ui_sidebar_mode::QueryBuilding:
break; break;
@ -270,6 +304,7 @@ command_result SetSideMenu(DFHack::color_ostream &stream, const DwarfControl::Si
{ {
case ui_sidebar_mode::Build: case ui_sidebar_mode::Build:
keyQueue.push(interface_key::D_BUILDING); keyQueue.push(interface_key::D_BUILDING);
break;
default: default:
ui->main.mode = set_mode; ui->main.mode = set_mode;
break; break;
@ -279,11 +314,14 @@ command_result SetSideMenu(DFHack::color_ostream &stream, const DwarfControl::Si
switch (ui->main.mode) switch (ui->main.mode)
{ {
case ui_sidebar_mode::Build: case ui_sidebar_mode::Build:
if (in->has_menu_index()) if (in->has_action())
{ {
df::global::ui_sidebar_menus->building.cursor = in->menu_index(); if (in->has_menu_index())
df::global::ui_sidebar_menus->building.cursor = in->menu_index();
else
df::global::ui_sidebar_menus->building.cursor = 0;
break;
} }
break;
default: default:
break; break;
} }