|
|
|
@@ -69,20 +69,19 @@ constexpr int resident_list_id = 1060;
|
|
|
|
|
constexpr int first_role_id = 1070;
|
|
|
|
|
constexpr int first_dock_section_id = 1080;
|
|
|
|
|
constexpr int work_list_button_id = 1083;
|
|
|
|
|
constexpr int build_blueprint_id = 1084;
|
|
|
|
|
constexpr int clear_blueprint_id = 1085;
|
|
|
|
|
constexpr int exit_menu_id = 1121;
|
|
|
|
|
constexpr int interface_scale_id = 1122;
|
|
|
|
|
constexpr int first_scale_id = 1130;
|
|
|
|
|
constexpr std::array interface_scales{100, 125, 150};
|
|
|
|
|
constexpr int default_interface_scale = 125;
|
|
|
|
|
constexpr int timer_id = 1;
|
|
|
|
|
constexpr int map_size = settlement::first_colony_map_size;
|
|
|
|
|
constexpr int tile_width = 24;
|
|
|
|
|
constexpr int tile_height = 14;
|
|
|
|
|
constexpr int map_origin_y = 86;
|
|
|
|
|
constexpr int map_top = 76;
|
|
|
|
|
constexpr int map_footer = 166;
|
|
|
|
|
constexpr int dock_sections_offset = 40;
|
|
|
|
|
constexpr int dock_actions_offset = 110;
|
|
|
|
|
constexpr int dock_materials_offset = 77;
|
|
|
|
|
constexpr int bed_choice_width = 78;
|
|
|
|
|
constexpr int bed_choice_height = 28;
|
|
|
|
|
constexpr int work_button_gap = 8;
|
|
|
|
|
constexpr settlement::GridPosition sawmill{15, 14};
|
|
|
|
|
constexpr settlement::GridPosition stonecutter{17, 14};
|
|
|
|
|
|
|
|
|
@@ -93,6 +92,16 @@ HWND stone_bed_button = nullptr;
|
|
|
|
|
HWND priority_button = nullptr;
|
|
|
|
|
HWND work_list_button = nullptr;
|
|
|
|
|
HWND residents_button = nullptr;
|
|
|
|
|
HWND build_blueprint_button = nullptr;
|
|
|
|
|
HWND clear_blueprint_button = nullptr;
|
|
|
|
|
HFONT dock_font = nullptr;
|
|
|
|
|
int interface_scale = default_interface_scale;
|
|
|
|
|
struct DockLayout {
|
|
|
|
|
int height = 0;
|
|
|
|
|
int hint_top = 0;
|
|
|
|
|
int line_height = 0;
|
|
|
|
|
};
|
|
|
|
|
DockLayout dock_layout;
|
|
|
|
|
std::array<HWND, 3> dock_section_buttons{};
|
|
|
|
|
std::unique_ptr<settlement::World> world;
|
|
|
|
|
namespace title = settlement::viewer;
|
|
|
|
@@ -113,7 +122,7 @@ enum class PlacementMode { None, Building, Foraging, BerryField, FlaxField, Tree
|
|
|
|
|
PlacementMode placement_mode = PlacementMode::None;
|
|
|
|
|
enum class WorkPanel { Farmer, Woodcutter, Miner, Builder, Gathering, Zones, Construction, None };
|
|
|
|
|
WorkPanel work_panel = WorkPanel::None;
|
|
|
|
|
enum class WorkIcon { Berries, Field, Flax, Tree, Pickaxe, Hammer, Loom, Resident, Bed, Wood, Stone, Crate, Pantry, Move, Demolish };
|
|
|
|
|
enum class WorkIcon { Berries, Field, Flax, Tree, Pickaxe, Hammer, Loom, Resident, Bed, Wood, Stone, Crate, Pantry, Move, Demolish, Priority };
|
|
|
|
|
struct WorkChoice {
|
|
|
|
|
int command;
|
|
|
|
|
const wchar_t* title;
|
|
|
|
@@ -186,6 +195,7 @@ struct ResidentRoster {
|
|
|
|
|
};
|
|
|
|
|
ResidentRoster roster;
|
|
|
|
|
std::optional<settlement::BedBase> selected_bed_base;
|
|
|
|
|
std::vector<settlement::viewer::BlueprintPart> blueprint;
|
|
|
|
|
std::optional<settlement::GridPosition> move_source;
|
|
|
|
|
settlement::viewer::MapCamera camera;
|
|
|
|
|
struct CameraDrag {
|
|
|
|
@@ -199,6 +209,10 @@ std::optional<settlement::GridPosition> hover_cell;
|
|
|
|
|
std::optional<settlement::AgentId> selected_resident;
|
|
|
|
|
std::wstring placement_message;
|
|
|
|
|
|
|
|
|
|
int dock_pixels(int pixels) {
|
|
|
|
|
return MulDiv(pixels, interface_scale, 100);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
COLORREF color(int red, int green, int blue) {
|
|
|
|
|
return RGB(red, green, blue);
|
|
|
|
|
}
|
|
|
|
@@ -228,7 +242,7 @@ void fill_ellipse(HDC dc, int left, int top, int right, int bottom,
|
|
|
|
|
DeleteObject(pen);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw_work_icon(HDC dc, WorkIcon icon, int x, int y) {
|
|
|
|
|
void draw_work_icon(HDC dc, WorkIcon icon, int x, int y, int extent = 17) {
|
|
|
|
|
const auto ink = color(54, 61, 58);
|
|
|
|
|
const auto wood = color(158, 101, 52);
|
|
|
|
|
const auto leaf = color(76, 137, 74);
|
|
|
|
@@ -237,7 +251,11 @@ void draw_work_icon(HDC dc, WorkIcon icon, int x, int y) {
|
|
|
|
|
const auto blue = color(91, 136, 184);
|
|
|
|
|
const int state = SaveDC(dc);
|
|
|
|
|
if (state == 0) return;
|
|
|
|
|
OffsetViewportOrgEx(dc, x, y, nullptr);
|
|
|
|
|
const float scale = static_cast<float>(extent) / 17.f;
|
|
|
|
|
const XFORM transform{scale, 0.f, 0.f, scale, static_cast<float>(x), static_cast<float>(y)};
|
|
|
|
|
if (extent == 17 || !SetGraphicsMode(dc, GM_ADVANCED) || !SetWorldTransform(dc, &transform)) {
|
|
|
|
|
OffsetViewportOrgEx(dc, x, y, nullptr);
|
|
|
|
|
}
|
|
|
|
|
const auto shape = [&](std::initializer_list<POINT> points, COLORREF fill) {
|
|
|
|
|
fill_polygon(dc, points.begin(), static_cast<int>(points.size()), fill, ink);
|
|
|
|
|
};
|
|
|
|
@@ -314,6 +332,11 @@ void draw_work_icon(HDC dc, WorkIcon icon, int x, int y) {
|
|
|
|
|
box(6, 2, 11, 5, metal);
|
|
|
|
|
box(2, 5, 15, 7, metal);
|
|
|
|
|
break;
|
|
|
|
|
case WorkIcon::Priority:
|
|
|
|
|
box(2, 3, 16, 6, metal);
|
|
|
|
|
box(2, 8, 12, 11, metal);
|
|
|
|
|
box(2, 13, 8, 16, metal);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
RestoreDC(dc, state);
|
|
|
|
|
}
|
|
|
|
@@ -327,9 +350,17 @@ bool shows_bed_choices() {
|
|
|
|
|
return world && world->staged_beds() && placement_mode == PlacementMode::Building;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_blueprint_tool() {
|
|
|
|
|
return placement_mode == PlacementMode::Building || placement_mode == PlacementMode::Loom;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool shows_blueprint_actions() {
|
|
|
|
|
return !showing_title && (is_blueprint_tool() || !blueprint.empty());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool is_map_point(const RECT& client, POINT point) {
|
|
|
|
|
return !showing_title && graphics.ready() && point.x >= 0 && point.x < client.right &&
|
|
|
|
|
point.y >= map_top && point.y < client.bottom - map_footer;
|
|
|
|
|
point.y >= map_top && point.y < client.bottom - dock_layout.height;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
POINT client_point(LPARAM coordinates) {
|
|
|
|
@@ -355,7 +386,7 @@ void layout_scene(HWND window) {
|
|
|
|
|
RECT client{};
|
|
|
|
|
GetClientRect(window, &client);
|
|
|
|
|
SetWindowPos(scene_window, HWND_BOTTOM, 0, map_top, client.right,
|
|
|
|
|
std::max(0, static_cast<int>(client.bottom) - map_top - map_footer), SWP_NOACTIVATE | SWP_SHOWWINDOW);
|
|
|
|
|
std::max(0, static_cast<int>(client.bottom) - map_top - dock_layout.height), SWP_NOACTIVATE | SWP_SHOWWINDOW);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update_camera_drag(POINT point) {
|
|
|
|
@@ -438,37 +469,125 @@ std::span<const WorkChoice> work_choices() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void layout_command_dock(HWND window) {
|
|
|
|
|
const auto choices = work_choices();
|
|
|
|
|
RECT client{};
|
|
|
|
|
GetClientRect(window, &client);
|
|
|
|
|
const auto width = static_cast<int>(client.right);
|
|
|
|
|
const auto height = static_cast<int>(client.bottom);
|
|
|
|
|
constexpr int section_widths[] = {112, 112, 112, 160};
|
|
|
|
|
constexpr int sections_width = 112 * 3 + 160 + 3 * work_button_gap;
|
|
|
|
|
int section_x = std::max(16, (width - sections_width) / 2);
|
|
|
|
|
SetWindowPos(status_label, nullptr, 16, 14, std::max(0, width - 32), 24, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
|
|
SetWindowPos(production_label, nullptr, 16, 44, std::max(0, width - 32), 24, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
|
|
const bool compact = height < map_top + dock_pixels(390);
|
|
|
|
|
const int margin = dock_pixels(compact ? 8 : 12);
|
|
|
|
|
const int gap = dock_pixels(compact ? 5 : 7);
|
|
|
|
|
const int available = std::max(1, width - margin * 2);
|
|
|
|
|
int bottom = height - margin;
|
|
|
|
|
struct DockItem {
|
|
|
|
|
HWND control;
|
|
|
|
|
int width;
|
|
|
|
|
bool materials = false;
|
|
|
|
|
};
|
|
|
|
|
const auto place = [](HWND button, int x, int y, int w, int h) {
|
|
|
|
|
SetWindowPos(button, nullptr, x, y, w, h, SWP_NOZORDER | SWP_NOACTIVATE);
|
|
|
|
|
};
|
|
|
|
|
place(residents_button, section_x, height - dock_sections_offset, section_widths[0], 31);
|
|
|
|
|
section_x += section_widths[0] + work_button_gap;
|
|
|
|
|
for (std::size_t index = 0; index < dock_section_buttons.size(); ++index) {
|
|
|
|
|
const int button_width = section_widths[index + 1];
|
|
|
|
|
place(dock_section_buttons[index], section_x, height - dock_sections_offset, button_width, 31);
|
|
|
|
|
section_x += button_width + work_button_gap;
|
|
|
|
|
}
|
|
|
|
|
int row_width = choices.empty() ? 0 : -work_button_gap;
|
|
|
|
|
for (const auto& choice : choices) row_width += choice.width + work_button_gap;
|
|
|
|
|
int x = std::max(16, (width - row_width) / 2);
|
|
|
|
|
const auto layout_rows = [&](std::span<const DockItem> items, int button_height) {
|
|
|
|
|
// Pack from the end so rows near the bottom stay fixed as the window grows.
|
|
|
|
|
while (!items.empty()) {
|
|
|
|
|
int row_width = 0;
|
|
|
|
|
bool materials = false;
|
|
|
|
|
auto start = items.size();
|
|
|
|
|
do {
|
|
|
|
|
const auto& item = items[start - 1];
|
|
|
|
|
const int required = std::min(available, dock_pixels(item.width)) + (row_width ? gap : 0);
|
|
|
|
|
if (row_width + required > available) break;
|
|
|
|
|
row_width += required;
|
|
|
|
|
materials |= item.materials;
|
|
|
|
|
--start;
|
|
|
|
|
} while (start != 0);
|
|
|
|
|
const int material_height = materials ? dock_pixels(compact ? 28 : 34) + gap : 0;
|
|
|
|
|
int x = std::max(margin, (width - row_width) / 2);
|
|
|
|
|
const int y = bottom - material_height - button_height;
|
|
|
|
|
for (const auto& item : items.subspan(start)) {
|
|
|
|
|
const int w = std::min(available, dock_pixels(item.width));
|
|
|
|
|
place(item.control, x, y, w, button_height);
|
|
|
|
|
if (item.materials) {
|
|
|
|
|
const int half = (w - gap) / 2;
|
|
|
|
|
const int material_y = y + button_height + gap;
|
|
|
|
|
place(wood_bed_button, x, material_y, half, material_height - gap);
|
|
|
|
|
place(stone_bed_button, x + half + gap, material_y, w - half - gap, material_height - gap);
|
|
|
|
|
}
|
|
|
|
|
x += w + gap;
|
|
|
|
|
}
|
|
|
|
|
bottom = y - gap;
|
|
|
|
|
items = items.first(start);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
const DockItem sections[] = {
|
|
|
|
|
{residents_button, 101}, {dock_section_buttons[0], 104}, {dock_section_buttons[1], 104},
|
|
|
|
|
{dock_section_buttons[2], 163}, {work_list_button, 101}, {priority_button, 172},
|
|
|
|
|
};
|
|
|
|
|
layout_rows(sections, dock_pixels(compact ? 34 : 40));
|
|
|
|
|
const auto choices = work_choices();
|
|
|
|
|
std::array<DockItem, builder_choices.size()> tools{};
|
|
|
|
|
for (std::size_t index = 0; index < choices.size(); ++index) {
|
|
|
|
|
const auto& choice = choices[index];
|
|
|
|
|
place(work_choice_buttons[index], x, height - dock_actions_offset, choice.width, 28);
|
|
|
|
|
if (choice.command == cabin_button_id) {
|
|
|
|
|
place(wood_bed_button, x, height - dock_materials_offset, bed_choice_width, bed_choice_height);
|
|
|
|
|
place(stone_bed_button, x + bed_choice_width + 4, height - dock_materials_offset,
|
|
|
|
|
bed_choice_width, bed_choice_height);
|
|
|
|
|
}
|
|
|
|
|
x += choice.width + work_button_gap;
|
|
|
|
|
const bool bed = choice.command == cabin_button_id;
|
|
|
|
|
tools[index] = {work_choice_buttons[index], choice.width + (bed ? 32 : 14), bed && shows_bed_choices()};
|
|
|
|
|
}
|
|
|
|
|
const int tool_height = dock_pixels(compact ? 30 : 36);
|
|
|
|
|
if (choices.empty()) bottom -= tool_height + gap;
|
|
|
|
|
else layout_rows(std::span(tools).first(choices.size()), tool_height);
|
|
|
|
|
|
|
|
|
|
if (shows_blueprint_actions()) {
|
|
|
|
|
const DockItem actions[] = {{build_blueprint_button, 182}, {clear_blueprint_button, 188}};
|
|
|
|
|
layout_rows(actions, dock_pixels(compact ? 31 : 37));
|
|
|
|
|
}
|
|
|
|
|
const int line_height = dock_pixels(compact ? 20 : 23);
|
|
|
|
|
const int hint_top = bottom - 2 * line_height;
|
|
|
|
|
const int new_height = height - hint_top + dock_pixels(8);
|
|
|
|
|
if (new_height != dock_layout.height && !showing_title) {
|
|
|
|
|
RECT dirty{0, height - std::max(new_height, dock_layout.height), width, height};
|
|
|
|
|
InvalidateRect(window, &dirty, FALSE);
|
|
|
|
|
}
|
|
|
|
|
dock_layout = {new_height, hint_top, line_height};
|
|
|
|
|
layout_scene(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::filesystem::path interface_settings_file() {
|
|
|
|
|
const auto saves = title::saves_directory();
|
|
|
|
|
return saves.empty() ? std::filesystem::path{} : saves.parent_path() / L"settings.ini";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void apply_interface_scale(HWND window, int scale) {
|
|
|
|
|
interface_scale = scale;
|
|
|
|
|
const auto font = CreateFontW(-dock_pixels(15), 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE, DEFAULT_CHARSET,
|
|
|
|
|
OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, CLEARTYPE_QUALITY, DEFAULT_PITCH | FF_SWISS, L"Segoe UI");
|
|
|
|
|
const auto face = reinterpret_cast<WPARAM>(font ? font : GetStockObject(DEFAULT_GUI_FONT));
|
|
|
|
|
const auto set_font = [&](HWND button) { SendMessageW(button, WM_SETFONT, face, TRUE); };
|
|
|
|
|
for (const auto button : {priority_button, work_list_button, residents_button, wood_bed_button,
|
|
|
|
|
stone_bed_button, build_blueprint_button, clear_blueprint_button}) set_font(button);
|
|
|
|
|
for (const auto button : dock_section_buttons) set_font(button);
|
|
|
|
|
for (const auto button : work_choice_buttons) set_font(button);
|
|
|
|
|
if (dock_font) DeleteObject(dock_font);
|
|
|
|
|
dock_font = font;
|
|
|
|
|
layout_command_dock(window);
|
|
|
|
|
InvalidateRect(window, nullptr, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool save_interface_scale(int scale) {
|
|
|
|
|
const auto file = interface_settings_file();
|
|
|
|
|
if (file.empty()) return false;
|
|
|
|
|
std::error_code error;
|
|
|
|
|
std::filesystem::create_directories(file.parent_path(), error);
|
|
|
|
|
if (error) return false;
|
|
|
|
|
const auto value = std::to_wstring(scale);
|
|
|
|
|
return WritePrivateProfileStringW(L"Interface", L"Scale", value.c_str(), file.c_str()) != FALSE;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int read_interface_scale() {
|
|
|
|
|
const auto file = interface_settings_file();
|
|
|
|
|
if (file.empty()) return default_interface_scale;
|
|
|
|
|
const auto scale = static_cast<int>(GetPrivateProfileIntW(L"Interface", L"Scale", default_interface_scale, file.c_str()));
|
|
|
|
|
return std::find(interface_scales.begin(), interface_scales.end(), scale) != interface_scales.end()
|
|
|
|
|
? scale : default_interface_scale;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void invalidate_work_choices() {
|
|
|
|
@@ -498,11 +617,11 @@ void set_work_panel(HWND window, WorkPanel panel) {
|
|
|
|
|
invalidate_work_choices();
|
|
|
|
|
RECT row{};
|
|
|
|
|
GetClientRect(window, &row);
|
|
|
|
|
row.top = row.bottom - map_footer;
|
|
|
|
|
row.top = row.bottom - dock_layout.height;
|
|
|
|
|
InvalidateRect(window, &row, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw_icon_button(const DRAWITEMSTRUCT& item, WorkIcon icon, bool active, bool dock = false) {
|
|
|
|
|
void draw_icon_button(const DRAWITEMSTRUCT& item, WorkIcon icon, bool active, bool dock = false, int icon_width = 17) {
|
|
|
|
|
const bool disabled = (item.itemState & ODS_DISABLED) != 0;
|
|
|
|
|
const bool pressed = (item.itemState & ODS_SELECTED) != 0;
|
|
|
|
|
const auto dc = item.hDC;
|
|
|
|
@@ -531,11 +650,10 @@ void draw_icon_button(const DRAWITEMSTRUCT& item, WorkIcon icon, bool active, bo
|
|
|
|
|
const auto previous_font = SelectObject(dc, font ? font : GetStockObject(DEFAULT_GUI_FONT));
|
|
|
|
|
SIZE caption{};
|
|
|
|
|
GetTextExtentPoint32W(dc, title, length, &caption);
|
|
|
|
|
constexpr int icon_width = 17;
|
|
|
|
|
constexpr int gap = 5;
|
|
|
|
|
const int left = std::max(box.left + 2, (box.left + box.right - icon_width - gap - caption.cx) / 2);
|
|
|
|
|
const int offset = pressed ? 1 : 0;
|
|
|
|
|
draw_work_icon(dc, icon, left + offset, (box.top + box.bottom - icon_width) / 2 + offset);
|
|
|
|
|
draw_work_icon(dc, icon, left + offset, (box.top + box.bottom - icon_width) / 2 + offset, icon_width);
|
|
|
|
|
|
|
|
|
|
RECT caption_box{left + icon_width + gap + offset, box.top + offset, box.right - 1, box.bottom + offset};
|
|
|
|
|
const auto previous_mode = SetBkMode(dc, TRANSPARENT);
|
|
|
|
@@ -550,22 +668,27 @@ void draw_icon_button(const DRAWITEMSTRUCT& item, WorkIcon icon, bool active, bo
|
|
|
|
|
|
|
|
|
|
bool draw_toolbar_button(const DRAWITEMSTRUCT& item) {
|
|
|
|
|
const auto id = static_cast<int>(item.CtlID);
|
|
|
|
|
const auto draw = [&](WorkIcon icon, bool active = false) {
|
|
|
|
|
draw_icon_button(item, icon, active, true, dock_pixels(17));
|
|
|
|
|
return true;
|
|
|
|
|
};
|
|
|
|
|
switch (id) {
|
|
|
|
|
case wood_bed_button_id: draw_icon_button(item, WorkIcon::Wood, selected_bed_base == settlement::BedBase::Wood, true); return true;
|
|
|
|
|
case stone_bed_button_id: draw_icon_button(item, WorkIcon::Stone, selected_bed_base == settlement::BedBase::Stone, true); return true;
|
|
|
|
|
case residents_button_id: draw_icon_button(item, WorkIcon::Resident, roster.window != nullptr, true); return true;
|
|
|
|
|
case work_list_button_id: draw_icon_button(item, WorkIcon::Hammer, false); return true;
|
|
|
|
|
case wood_bed_button_id: return draw(WorkIcon::Wood, selected_bed_base == settlement::BedBase::Wood);
|
|
|
|
|
case stone_bed_button_id: return draw(WorkIcon::Stone, selected_bed_base == settlement::BedBase::Stone);
|
|
|
|
|
case residents_button_id: return draw(WorkIcon::Resident, roster.window != nullptr);
|
|
|
|
|
case work_list_button_id: return draw(WorkIcon::Hammer);
|
|
|
|
|
case priority_button_id: return draw(WorkIcon::Priority);
|
|
|
|
|
case build_blueprint_id: return draw(WorkIcon::Hammer, !blueprint.empty());
|
|
|
|
|
case clear_blueprint_id: return draw(WorkIcon::Demolish);
|
|
|
|
|
}
|
|
|
|
|
if (id >= first_dock_section_id && static_cast<std::size_t>(id - first_dock_section_id) < dock_sections.size()) {
|
|
|
|
|
const auto& section = dock_sections[static_cast<std::size_t>(id - first_dock_section_id)];
|
|
|
|
|
draw_icon_button(item, section.icon, work_panel == section.panel, true);
|
|
|
|
|
return true;
|
|
|
|
|
return draw(section.icon, work_panel == section.panel);
|
|
|
|
|
}
|
|
|
|
|
const auto choices = work_choices();
|
|
|
|
|
if (id < first_work_choice_id || static_cast<std::size_t>(id - first_work_choice_id) >= choices.size()) return false;
|
|
|
|
|
const auto& choice = choices[static_cast<std::size_t>(id - first_work_choice_id)];
|
|
|
|
|
draw_icon_button(item, choice.icon, placement_mode == choice.mode, true);
|
|
|
|
|
return true;
|
|
|
|
|
return draw(choice.icon, placement_mode == choice.mode);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool can_give_orders() {
|
|
|
|
@@ -667,6 +790,7 @@ void update_status() {
|
|
|
|
|
for (const HWND button : dock_section_buttons) EnableWindow(button, can_play);
|
|
|
|
|
EnableWindow(priority_button, scenario && can_play);
|
|
|
|
|
EnableWindow(work_list_button, can_play);
|
|
|
|
|
EnableWindow(build_blueprint_button, !blueprint.empty() && can_play);
|
|
|
|
|
const wchar_t* priority = L"Равный приоритет";
|
|
|
|
|
if (world->work_priority() == settlement::WorkPriority::FoodFirst) priority = L"Сначала еда";
|
|
|
|
|
else if (world->work_priority() == settlement::WorkPriority::BuildingFirst) priority = L"Сначала стройка";
|
|
|
|
@@ -708,13 +832,22 @@ void update_status() {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update_bed_choices() {
|
|
|
|
|
const int visibility = shows_bed_choices() ? SW_SHOW : SW_HIDE;
|
|
|
|
|
const int visibility = !showing_title && shows_bed_choices() ? SW_SHOWNA : SW_HIDE;
|
|
|
|
|
ShowWindow(wood_bed_button, visibility);
|
|
|
|
|
ShowWindow(stone_bed_button, visibility);
|
|
|
|
|
InvalidateRect(wood_bed_button, nullptr, FALSE);
|
|
|
|
|
InvalidateRect(stone_bed_button, nullptr, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void update_blueprint_controls(HWND window) {
|
|
|
|
|
const int visibility = shows_blueprint_actions() ? SW_SHOWNA : SW_HIDE;
|
|
|
|
|
ShowWindow(build_blueprint_button, visibility);
|
|
|
|
|
ShowWindow(clear_blueprint_button, visibility);
|
|
|
|
|
EnableWindow(build_blueprint_button, !blueprint.empty() && can_give_orders());
|
|
|
|
|
EnableWindow(clear_blueprint_button, !blueprint.empty());
|
|
|
|
|
layout_command_dock(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_placement_mode(HWND window, PlacementMode mode, const wchar_t* message = L"") {
|
|
|
|
|
placement_mode = mode;
|
|
|
|
|
selected_bed_base.reset();
|
|
|
|
@@ -722,6 +855,7 @@ void set_placement_mode(HWND window, PlacementMode mode, const wchar_t* message
|
|
|
|
|
hover_cell.reset();
|
|
|
|
|
placement_message = message;
|
|
|
|
|
update_bed_choices();
|
|
|
|
|
update_blueprint_controls(window);
|
|
|
|
|
invalidate_work_choices();
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
}
|
|
|
|
@@ -765,14 +899,14 @@ void show_title_screen(HWND window, bool visible) {
|
|
|
|
|
RECT client{};
|
|
|
|
|
GetClientRect(window, &client);
|
|
|
|
|
title_screen.layout(client.right, client.bottom);
|
|
|
|
|
layout_command_dock(window);
|
|
|
|
|
layout_scene(window);
|
|
|
|
|
update_blueprint_controls(window);
|
|
|
|
|
SetFocus(window);
|
|
|
|
|
InvalidateRect(window, nullptr, FALSE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reset_world(HWND window) {
|
|
|
|
|
world = settlement::make_first_colony(local_worker_count);
|
|
|
|
|
blueprint.clear();
|
|
|
|
|
camera = {};
|
|
|
|
|
selected_resident.reset();
|
|
|
|
|
sync_resident_roster(true);
|
|
|
|
@@ -853,6 +987,7 @@ void handle_save_menu(HWND window, bool saving, std::optional<std::filesystem::p
|
|
|
|
|
throw std::runtime_error("This viewer opens saves with a 32 by 32 map.");
|
|
|
|
|
}
|
|
|
|
|
world = std::move(loaded);
|
|
|
|
|
blueprint.clear();
|
|
|
|
|
camera = {};
|
|
|
|
|
selected_resident.reset();
|
|
|
|
|
sync_resident_roster(true);
|
|
|
|
@@ -1009,6 +1144,7 @@ void handle_lan_menu(HWND window, int command) {
|
|
|
|
|
lan.host();
|
|
|
|
|
if (colony) {
|
|
|
|
|
world = std::move(colony);
|
|
|
|
|
blueprint.clear();
|
|
|
|
|
camera = {};
|
|
|
|
|
selected_resident.reset();
|
|
|
|
|
}
|
|
|
|
@@ -1023,6 +1159,7 @@ void handle_lan_menu(HWND window, int command) {
|
|
|
|
|
if (!request) return;
|
|
|
|
|
if (!world) world = settlement::make_first_colony(local_worker_count);
|
|
|
|
|
lan.join(narrow_lan_input(request->address.data()), narrow_lan_input(request->code.data()));
|
|
|
|
|
blueprint.clear();
|
|
|
|
|
enter_game_on_snapshot = true;
|
|
|
|
|
selected_resident.reset();
|
|
|
|
|
sync_resident_roster(true);
|
|
|
|
@@ -1132,6 +1269,71 @@ bool valid_edit_cell(settlement::GridPosition cell) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::optional<settlement::viewer::BlueprintPart> preview_blueprint(settlement::GridPosition cell) {
|
|
|
|
|
using settlement::RecipeId;
|
|
|
|
|
if (placement_mode == PlacementMode::Loom) {
|
|
|
|
|
return settlement::viewer::BlueprintPart{cell, RecipeId::WeaveCloth};
|
|
|
|
|
}
|
|
|
|
|
if (placement_mode != PlacementMode::Building || (shows_bed_choices() && !selected_bed_base)) {
|
|
|
|
|
return std::nullopt;
|
|
|
|
|
}
|
|
|
|
|
return settlement::viewer::BlueprintPart{cell,
|
|
|
|
|
world->scenario_active() ? RecipeId::BuildBed : RecipeId::BuildCabin,
|
|
|
|
|
selected_bed_base.value_or(settlement::BedBase::Wood)};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void edit_blueprint(HWND window, settlement::GridPosition cell) {
|
|
|
|
|
if (!can_give_orders()) return;
|
|
|
|
|
if (std::erase_if(blueprint, [cell](const auto& part) { return part.cell == cell; }) != 0) {
|
|
|
|
|
placement_message = L"Объект убран из чертежа.";
|
|
|
|
|
} else if (const auto part = preview_blueprint(cell); part && valid_edit_cell(cell)) {
|
|
|
|
|
blueprint.push_back(*part);
|
|
|
|
|
placement_message.clear();
|
|
|
|
|
} else {
|
|
|
|
|
placement_message = shows_bed_choices() && !selected_bed_base
|
|
|
|
|
? L"Выберите основу под кнопкой «Спальное место»."
|
|
|
|
|
: L"Эта клетка занята или недоступна для чертежа.";
|
|
|
|
|
}
|
|
|
|
|
update_blueprint_controls(window);
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void submit_blueprint(HWND window) {
|
|
|
|
|
if (!world || blueprint.empty() || !can_give_orders()) return;
|
|
|
|
|
using settlement::CommandKind;
|
|
|
|
|
using settlement::RecipeId;
|
|
|
|
|
const auto sent = std::erase_if(blueprint, [](const auto& part) {
|
|
|
|
|
switch (part.recipe) {
|
|
|
|
|
case RecipeId::BuildBed:
|
|
|
|
|
return world->can_place_bed(part.cell) &&
|
|
|
|
|
send_command(CommandKind::PlaceBed, part.cell, static_cast<std::uint8_t>(part.base));
|
|
|
|
|
case RecipeId::WeaveCloth:
|
|
|
|
|
return world->can_place_storage(part.cell) && send_command(CommandKind::PlaceLoom, part.cell);
|
|
|
|
|
case RecipeId::BuildCabin:
|
|
|
|
|
try {
|
|
|
|
|
world->queue_cabin(part.cell, sawmill, stonecutter);
|
|
|
|
|
return true;
|
|
|
|
|
} catch (const std::invalid_argument&) {
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
default:
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
const std::wstring count = std::to_wstring(sent);
|
|
|
|
|
if (!blueprint.empty()) {
|
|
|
|
|
placement_message = L"Принято мест: " + count + L". Осталось в чертеже: " +
|
|
|
|
|
std::to_wstring(blueprint.size()) +
|
|
|
|
|
(lan.is_guest() ? L". Проверьте карту и отправьте оставшиеся места снова." :
|
|
|
|
|
L". Проверьте, свободны ли клетки и есть ли к ним проход.");
|
|
|
|
|
} else {
|
|
|
|
|
placement_message = (lan.is_guest() ? L"Передано хозяину мест: " : L"Утверждено мест: ") + count + L".";
|
|
|
|
|
}
|
|
|
|
|
update_blueprint_controls(window);
|
|
|
|
|
update_status();
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void edit_at_cell(HWND window, settlement::GridPosition cell) {
|
|
|
|
|
using settlement::CommandKind;
|
|
|
|
|
using settlement::CommandStatus;
|
|
|
|
@@ -1173,8 +1375,6 @@ void edit_at_cell(HWND window, settlement::GridPosition cell) {
|
|
|
|
|
command = CommandKind::PlaceTreePlot;
|
|
|
|
|
} else if (placement_mode == PlacementMode::Mine) {
|
|
|
|
|
command = CommandKind::PlaceMine;
|
|
|
|
|
} else if (placement_mode == PlacementMode::Loom) {
|
|
|
|
|
command = CommandKind::PlaceLoom;
|
|
|
|
|
} else {
|
|
|
|
|
command = CommandKind::PlaceStorage;
|
|
|
|
|
value = static_cast<std::uint8_t>(placement_mode == PlacementMode::Pantry ? StorageKind::Pantry :
|
|
|
|
@@ -1446,6 +1646,28 @@ std::wstring resident_details() {
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::wstring blueprint_details() {
|
|
|
|
|
using settlement::ItemType;
|
|
|
|
|
struct Material {
|
|
|
|
|
ItemType type;
|
|
|
|
|
const wchar_t* name;
|
|
|
|
|
};
|
|
|
|
|
constexpr Material materials[] = {{ItemType::Wood, L"дерево"}, {ItemType::Stone, L"камень"},
|
|
|
|
|
{ItemType::Cloth, L"ткань"}, {ItemType::Plank, L"доски"}, {ItemType::StoneBlock, L"каменные блоки"}};
|
|
|
|
|
std::array<unsigned, settlement::item_type_count + 1> totals{};
|
|
|
|
|
for (const auto& part : blueprint) {
|
|
|
|
|
for (const auto& material : world->construction_materials(part.recipe, part.base)) {
|
|
|
|
|
totals[static_cast<std::size_t>(material.type)] += material.count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
std::wstring text = L"Чертёж · объектов " + std::to_wstring(blueprint.size());
|
|
|
|
|
for (const auto& material : materials) {
|
|
|
|
|
const auto count = totals[static_cast<std::size_t>(material.type)];
|
|
|
|
|
if (count != 0) text += std::wstring(L" ") + material.name + L" " + std::to_wstring(count);
|
|
|
|
|
}
|
|
|
|
|
return text;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void draw_world(HDC dc, int width, int height) {
|
|
|
|
|
RECT bounds{0, 0, width, height};
|
|
|
|
|
HBRUSH background = CreateSolidBrush(color(239, 235, 222));
|
|
|
|
@@ -1453,15 +1675,15 @@ void draw_world(HDC dc, int width, int height) {
|
|
|
|
|
DeleteObject(background);
|
|
|
|
|
if (!world) return;
|
|
|
|
|
|
|
|
|
|
if (!graphics.ready() && height > map_top + map_footer) {
|
|
|
|
|
RECT scene{16, map_top + 24, width - 16, height - map_footer};
|
|
|
|
|
if (!graphics.ready() && height > map_top + dock_layout.height) {
|
|
|
|
|
RECT scene{16, map_top + 24, width - 16, height - dock_layout.height};
|
|
|
|
|
SetBkMode(dc, TRANSPARENT);
|
|
|
|
|
SetTextColor(dc, color(55, 68, 59));
|
|
|
|
|
DrawTextW(dc, L"Не удалось запустить Direct3D 11. Откройте главное меню и войдите в колонию снова.",
|
|
|
|
|
-1, &scene, DT_CENTER | DT_WORDBREAK);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const RECT dock{0, height - map_footer, width, height};
|
|
|
|
|
const RECT dock{0, height - dock_layout.height, width, height};
|
|
|
|
|
const auto dock_brush = CreateSolidBrush(color(34, 46, 40));
|
|
|
|
|
FillRect(dc, &dock, dock_brush);
|
|
|
|
|
DeleteObject(dock_brush);
|
|
|
|
@@ -1485,8 +1707,6 @@ void draw_world(HDC dc, int width, int height) {
|
|
|
|
|
hint = L"Посадка деревьев. Выберите свободную клетку. Лесоруб высадит деревья.";
|
|
|
|
|
} else if (placement_mode == PlacementMode::Mine) {
|
|
|
|
|
hint = L"Шахта. Щёлкните по скале, к которой ведёт свободный проход.";
|
|
|
|
|
} else if (placement_mode == PlacementMode::Loom) {
|
|
|
|
|
hint = L"Ткацкий станок. Выберите свободную клетку. Строитель будет делать ткань из льна.";
|
|
|
|
|
} else if (placement_mode == PlacementMode::Storage || placement_mode == PlacementMode::Pantry) {
|
|
|
|
|
hint = L"Выберите свободную клетку для склада или кладовой.";
|
|
|
|
|
} else if (placement_mode == PlacementMode::Move) {
|
|
|
|
@@ -1494,33 +1714,34 @@ void draw_world(HDC dc, int width, int height) {
|
|
|
|
|
L"Выберите кровать, склад, станок или посаженный участок.";
|
|
|
|
|
} else if (placement_mode == PlacementMode::Demolish) {
|
|
|
|
|
hint = L"Щёлкните по объекту, чтобы снести его. Правая кнопка — отмена.";
|
|
|
|
|
} else if (placement_mode == PlacementMode::Building) {
|
|
|
|
|
if (world->staged_beds()) {
|
|
|
|
|
hint = selected_bed_base
|
|
|
|
|
? L"Щёлкайте по свободным клеткам. Основу можно сменить под кнопкой «Спальное место»."
|
|
|
|
|
: L"Выберите «Дерево» или «Камень» под кнопкой «Спальное место».";
|
|
|
|
|
} else if (world->scenario_active()) {
|
|
|
|
|
hint = L"Щёлкайте по свободным клеткам. Одно место требует доску. Правая кнопка — отмена.";
|
|
|
|
|
} else {
|
|
|
|
|
hint = L"Выберите свободную клетку. Домик стоит три доски и два блока. Правая кнопка — отмена.";
|
|
|
|
|
}
|
|
|
|
|
} else if (is_blueprint_tool()) {
|
|
|
|
|
hint = shows_bed_choices() && !selected_bed_base
|
|
|
|
|
? L"Выберите «Дерево» или «Камень» под кнопкой «Спальное место»."
|
|
|
|
|
: L"Щёлкните по клетке, чтобы добавить объект или убрать его из чертежа.";
|
|
|
|
|
}
|
|
|
|
|
RECT legend{24, height - 159, width - 24, height - 136};
|
|
|
|
|
const auto previous_font = dock_font ? SelectObject(dc, dock_font) : nullptr;
|
|
|
|
|
const int margin = dock_pixels(12);
|
|
|
|
|
RECT legend{margin, dock_layout.hint_top, width - margin, dock_layout.hint_top + dock_layout.line_height};
|
|
|
|
|
DrawTextW(dc, hint, -1, &legend, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
|
|
|
|
|
const auto details = resident_details();
|
|
|
|
|
const auto details = blueprint.empty() ? resident_details() : blueprint_details();
|
|
|
|
|
SetTextColor(dc, color(190, 201, 178));
|
|
|
|
|
RECT inspector{24, height - 135, width - 24, height - 113};
|
|
|
|
|
RECT inspector{margin, legend.bottom, width - margin, legend.bottom + dock_layout.line_height};
|
|
|
|
|
DrawTextW(dc, details.c_str(), -1, &inspector, DT_LEFT | DT_VCENTER | DT_SINGLELINE | DT_END_ELLIPSIS);
|
|
|
|
|
if (previous_font) SelectObject(dc, previous_font);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settlement::viewer::SceneView scene_view(int width, int height) {
|
|
|
|
|
const auto pan = camera.offset();
|
|
|
|
|
const auto scale = camera.scale();
|
|
|
|
|
const auto cursor = !shows_bed_choices() || selected_bed_base ? hover_cell : std::nullopt;
|
|
|
|
|
const bool valid_cursor = cursor && valid_edit_cell(*cursor);
|
|
|
|
|
const auto preview = valid_cursor && is_blueprint_tool() &&
|
|
|
|
|
std::none_of(blueprint.begin(), blueprint.end(), [&](const auto& part) { return part.cell == *cursor; })
|
|
|
|
|
? preview_blueprint(*cursor) : std::nullopt;
|
|
|
|
|
return {width, height, static_cast<float>(width / 2 * scale + pan.x),
|
|
|
|
|
static_cast<float>(map_origin_y * scale + pan.y - map_top),
|
|
|
|
|
static_cast<float>(scale), tile_width / 2.f, tile_height / 2.f,
|
|
|
|
|
cursor, cursor && valid_edit_cell(*cursor), move_source, selected_resident};
|
|
|
|
|
cursor, valid_cursor, move_source, selected_resident, blueprint, preview};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LRESULT CALLBACK scene_window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lparam) {
|
|
|
|
@@ -1621,15 +1842,37 @@ int choose_menu_action(HWND window, const wchar_t* title, std::span<const MenuAc
|
|
|
|
|
return static_cast<int>(action);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void choose_interface_scale(HWND window) {
|
|
|
|
|
std::array<std::wstring, interface_scales.size()> captions;
|
|
|
|
|
std::array<MenuAction, interface_scales.size()> actions{};
|
|
|
|
|
for (std::size_t index = 0; index < interface_scales.size(); ++index) {
|
|
|
|
|
const auto scale = interface_scales[index];
|
|
|
|
|
captions[index] = std::to_wstring(scale) + L"%";
|
|
|
|
|
if (scale == interface_scale) captions[index] += L" · текущий";
|
|
|
|
|
actions[index] = {first_scale_id + static_cast<int>(index), captions[index].c_str()};
|
|
|
|
|
}
|
|
|
|
|
const int action = choose_menu_action(window, L"Масштаб нижней панели", actions);
|
|
|
|
|
if (action < first_scale_id || action >= first_scale_id + static_cast<int>(interface_scales.size())) return;
|
|
|
|
|
const int scale = interface_scales[static_cast<std::size_t>(action - first_scale_id)];
|
|
|
|
|
if (scale == interface_scale) return;
|
|
|
|
|
const bool saved = save_interface_scale(scale);
|
|
|
|
|
const auto caption = std::to_wstring(scale) + L"%";
|
|
|
|
|
placement_message = L"Масштаб нижней панели · " + caption +
|
|
|
|
|
(saved ? L"" : L". Настройку не удалось сохранить на диск.");
|
|
|
|
|
apply_interface_scale(window, scale);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void open_pause_menu(HWND window) {
|
|
|
|
|
if (!world || showing_title || pause_menu_open) return;
|
|
|
|
|
camera_drag.reset();
|
|
|
|
|
if (GetCapture() == window) ReleaseCapture();
|
|
|
|
|
const bool offline = lan.state() == LanState::Offline;
|
|
|
|
|
const auto interface_caption = L"Масштаб панели · " + std::to_wstring(interface_scale) + L"%…";
|
|
|
|
|
const MenuAction actions[] = {
|
|
|
|
|
{IDOK, L"Продолжить"},
|
|
|
|
|
{save_menu_id, L"Сохранить поселение…", !lan.is_guest()},
|
|
|
|
|
{load_menu_id, L"Загрузить поселение…", offline},
|
|
|
|
|
{interface_scale_id, interface_caption.c_str()},
|
|
|
|
|
{title_menu_id, L"Главное меню"},
|
|
|
|
|
{exit_menu_id, L"Выйти из игры"},
|
|
|
|
|
};
|
|
|
|
@@ -1645,6 +1888,9 @@ void open_pause_menu(HWND window) {
|
|
|
|
|
case load_menu_id:
|
|
|
|
|
handle_save_menu(window, action == save_menu_id);
|
|
|
|
|
break;
|
|
|
|
|
case interface_scale_id:
|
|
|
|
|
choose_interface_scale(window);
|
|
|
|
|
break;
|
|
|
|
|
case title_menu_id:
|
|
|
|
|
show_title_screen(window, true);
|
|
|
|
|
refresh_lan_controls(window);
|
|
|
|
@@ -1702,7 +1948,7 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
case WM_GETMINMAXINFO: {
|
|
|
|
|
auto& size = *reinterpret_cast<MINMAXINFO*>(lparam);
|
|
|
|
|
size.ptMinTrackSize.x = 775;
|
|
|
|
|
size.ptMinTrackSize.y = 490;
|
|
|
|
|
size.ptMinTrackSize.y = 640;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
case WM_CREATE: {
|
|
|
|
@@ -1729,21 +1975,24 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
reinterpret_cast<HMENU>(static_cast<INT_PTR>(id)),
|
|
|
|
|
GetModuleHandleW(nullptr), nullptr);
|
|
|
|
|
};
|
|
|
|
|
priority_button = button(priority_button_id, 18, 142, L"Равный приоритет");
|
|
|
|
|
work_list_button = button(work_list_button_id, 168, 108, L"Работы", BS_OWNERDRAW);
|
|
|
|
|
priority_button = button(priority_button_id, 0, 142, L"Равный приоритет", BS_OWNERDRAW, 0);
|
|
|
|
|
work_list_button = button(work_list_button_id, 0, 108, L"Работы", BS_OWNERDRAW, 0);
|
|
|
|
|
residents_button = button(residents_button_id, 0, 112, L"Жители", BS_OWNERDRAW, 0);
|
|
|
|
|
for (std::size_t index = 0; index < dock_sections.size(); ++index) {
|
|
|
|
|
dock_section_buttons[index] = button(first_dock_section_id + static_cast<int>(index), 0, 112,
|
|
|
|
|
dock_sections[index].title, BS_OWNERDRAW, 0);
|
|
|
|
|
}
|
|
|
|
|
wood_bed_button = button(wood_bed_button_id, 0, bed_choice_width, L"Дерево", BS_OWNERDRAW, 0);
|
|
|
|
|
stone_bed_button = button(stone_bed_button_id, 0, bed_choice_width, L"Камень", BS_OWNERDRAW, 0);
|
|
|
|
|
wood_bed_button = button(wood_bed_button_id, 0, 90, L"Дерево", BS_OWNERDRAW, 0);
|
|
|
|
|
stone_bed_button = button(stone_bed_button_id, 0, 90, L"Камень", BS_OWNERDRAW, 0);
|
|
|
|
|
build_blueprint_button = button(build_blueprint_id, 0, 180, L"Начать стройку", BS_OWNERDRAW, 0);
|
|
|
|
|
clear_blueprint_button = button(clear_blueprint_id, 0, 180, L"Очистить чертёж", BS_OWNERDRAW, 0);
|
|
|
|
|
for (std::size_t index = 0; index < work_choice_buttons.size(); ++index) {
|
|
|
|
|
work_choice_buttons[index] = button(first_work_choice_id + static_cast<int>(index),
|
|
|
|
|
0, 100, L"", BS_OWNERDRAW, 0);
|
|
|
|
|
ShowWindow(work_choice_buttons[index], SW_HIDE);
|
|
|
|
|
}
|
|
|
|
|
title_screen.create(window);
|
|
|
|
|
apply_interface_scale(window, read_interface_scale());
|
|
|
|
|
show_title_screen(window, true);
|
|
|
|
|
refresh_lan_controls(window);
|
|
|
|
|
SetTimer(window, timer_id, 60, nullptr);
|
|
|
|
@@ -1770,8 +2019,8 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
if (const auto menu = create_work_menu()) {
|
|
|
|
|
RECT bounds{};
|
|
|
|
|
GetWindowRect(work_list_button, &bounds);
|
|
|
|
|
TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_TOPALIGN | TPM_RIGHTBUTTON,
|
|
|
|
|
bounds.left, bounds.bottom, 0, window, nullptr);
|
|
|
|
|
TrackPopupMenu(menu, TPM_LEFTALIGN | TPM_BOTTOMALIGN | TPM_RIGHTBUTTON,
|
|
|
|
|
bounds.left, bounds.top, 0, window, nullptr);
|
|
|
|
|
DestroyMenu(menu);
|
|
|
|
|
}
|
|
|
|
|
SetFocus(window);
|
|
|
|
@@ -1781,6 +2030,19 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
if (world) show_resident_roster(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (HIWORD(wparam) == BN_CLICKED && LOWORD(wparam) == build_blueprint_id) {
|
|
|
|
|
submit_blueprint(window);
|
|
|
|
|
SetFocus(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (HIWORD(wparam) == BN_CLICKED && LOWORD(wparam) == clear_blueprint_id && !blueprint.empty()) {
|
|
|
|
|
blueprint.clear();
|
|
|
|
|
placement_message = L"Чертёж очищен.";
|
|
|
|
|
update_blueprint_controls(window);
|
|
|
|
|
SetFocus(window);
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (LOWORD(wparam) >= farmer_menu_id && LOWORD(wparam) <= builder_menu_id && HIWORD(wparam) == BN_CLICKED) {
|
|
|
|
|
const auto panel = static_cast<WorkPanel>(LOWORD(wparam) - farmer_menu_id);
|
|
|
|
|
toggle_work_panel(window, panel);
|
|
|
|
@@ -1936,46 +2198,8 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (placement_mode == PlacementMode::Building && world) {
|
|
|
|
|
const auto cell = map_cell(client, point);
|
|
|
|
|
if (world->scenario_active()) {
|
|
|
|
|
if (!cell || !world->can_place_bed(*cell)) {
|
|
|
|
|
placement_message = L"Для спального места нужна свободная клетка.";
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (shows_bed_choices() && !selected_bed_base) {
|
|
|
|
|
placement_message = L"Сначала выберите основу под кнопкой «Спальное место».";
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
const auto base = selected_bed_base.value_or(settlement::BedBase::Wood);
|
|
|
|
|
if (send_command(settlement::CommandKind::PlaceBed, *cell, static_cast<std::uint8_t>(base))) {
|
|
|
|
|
hover_cell = cell;
|
|
|
|
|
placement_message = lan.is_guest()
|
|
|
|
|
? L"Запрос на спальное место отправлен. Можно выбрать следующую клетку."
|
|
|
|
|
: L"Спальное место заказано. Выберите следующую клетку или нажмите Esc.";
|
|
|
|
|
update_status();
|
|
|
|
|
} else {
|
|
|
|
|
placement_message = L"Для спального места нужна свободная клетка с проходом к мастерской.";
|
|
|
|
|
}
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (!cell || !world->can_place_cabin(*cell)) {
|
|
|
|
|
placement_message = L"Здесь нельзя поставить домик. Выберите свободную клетку.";
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
world->queue_cabin(*cell, sawmill, stonecutter);
|
|
|
|
|
} catch (const std::invalid_argument&) {
|
|
|
|
|
placement_message = L"К участку нет прохода от мастерских. Выберите другую клетку.";
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
set_placement_mode(window, PlacementMode::None, L"Чертёж поставлен. Материалы заказаны в мастерских.");
|
|
|
|
|
update_status();
|
|
|
|
|
if (world && is_blueprint_tool()) {
|
|
|
|
|
if (const auto cell = map_cell(client, point)) edit_blueprint(window, *cell);
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
if (world && placement_mode >= PlacementMode::BerryField) {
|
|
|
|
@@ -2036,9 +2260,22 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
sync_resident_roster();
|
|
|
|
|
if (lan.state() != displayed_lan_state) refresh_lan_controls(window);
|
|
|
|
|
if (const auto rejection = lan.take_rejection()) {
|
|
|
|
|
placement_message = *rejection == settlement::CommandStatus::Busy
|
|
|
|
|
? L"Объект занят. Дождитесь окончания работы или сна."
|
|
|
|
|
: L"Хозяин отклонил команду. Проверьте выбранную клетку.";
|
|
|
|
|
using settlement::CommandKind;
|
|
|
|
|
using settlement::RecipeId;
|
|
|
|
|
const bool bed = rejection->kind == CommandKind::PlaceBed;
|
|
|
|
|
if (bed || rejection->kind == CommandKind::PlaceLoom) {
|
|
|
|
|
if (std::none_of(blueprint.begin(), blueprint.end(),
|
|
|
|
|
[&](const auto& part) { return part.cell == rejection->cell; })) {
|
|
|
|
|
blueprint.push_back({rejection->cell, bed ? RecipeId::BuildBed : RecipeId::WeaveCloth,
|
|
|
|
|
static_cast<settlement::BedBase>(rejection->value)});
|
|
|
|
|
update_blueprint_controls(window);
|
|
|
|
|
}
|
|
|
|
|
placement_message = L"Клетка отклонена хозяином и оставлена в чертеже.";
|
|
|
|
|
} else {
|
|
|
|
|
placement_message = rejection->status == settlement::CommandStatus::Busy
|
|
|
|
|
? L"Объект занят. Дождитесь окончания работы или сна."
|
|
|
|
|
: L"Хозяин отклонил команду. Проверьте выбранную клетку.";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
update_status();
|
|
|
|
|
invalidate_scene(window);
|
|
|
|
@@ -2054,7 +2291,6 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
title_screen.layout(client.right, client.bottom);
|
|
|
|
|
} else {
|
|
|
|
|
layout_command_dock(window);
|
|
|
|
|
layout_scene(window);
|
|
|
|
|
}
|
|
|
|
|
InvalidateRect(window, nullptr, FALSE);
|
|
|
|
|
break;
|
|
|
|
@@ -2083,6 +2319,7 @@ LRESULT CALLBACK window_proc(HWND window, UINT message, WPARAM wparam, LPARAM lp
|
|
|
|
|
KillTimer(window, timer_id);
|
|
|
|
|
lan.leave();
|
|
|
|
|
graphics.reset();
|
|
|
|
|
if (dock_font) DeleteObject(std::exchange(dock_font, nullptr));
|
|
|
|
|
scene_window = nullptr;
|
|
|
|
|
PostQuitMessage(0);
|
|
|
|
|
return 0;
|
|
|
|
|