From dd64aef91098a66c76829eb1bd1ca24506cea9c1 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Sun, 6 Jun 2021 20:25:26 -0400 Subject: [PATCH] Improves request construction and improves descriptions. --- Machines/Utility/ROMCatalogue.cpp | 49 ++++++++++++++----- Machines/Utility/ROMCatalogue.hpp | 7 +-- .../Clock Signal.xcodeproj/project.pbxproj | 4 +- .../Documents/MachineDocument.swift | 4 ++ .../ROMRequester/ROMRequester.xib | 12 ++--- OSBindings/SDL/main.cpp | 2 +- 6 files changed, 53 insertions(+), 25 deletions(-) diff --git a/Machines/Utility/ROMCatalogue.cpp b/Machines/Utility/ROMCatalogue.cpp index 0982c5735..734538247 100644 --- a/Machines/Utility/ROMCatalogue.cpp +++ b/Machines/Utility/ROMCatalogue.cpp @@ -27,14 +27,28 @@ Request::Request(Name name, bool optional) { } Request Request::append(Node::Type type, const Request &rhs) { - // Start with the easiest case: this is already an ::All request, and - // so is the new thing. + // Start with the easiest case: this is already an appropriate + // request, and so is the new thing. if(node.type == type && rhs.node.type == type) { Request new_request = *this; new_request.node.children.insert(new_request.node.children.end(), rhs.node.children.begin(), rhs.node.children.end()); return new_request; } + // Possibly: left is appropriate request and rhs is just one more thing? + if(node.type == type && rhs.node.type == Node::Type::One) { + Request new_request = *this; + new_request.node.children.push_back(rhs.node); + return new_request; + } + + // Or: right is appropriate request and this is just one more thing? + if(rhs.node.type == type && node.type == Node::Type::One) { + Request new_request = rhs; + new_request.node.children.push_back(node); + return new_request; + } + // Otherwise create a new parent node. Request parent; parent.node.type = type; @@ -144,7 +158,7 @@ bool Request::Node::validate(Map &map) const { } void Request::visit( - const std::function &enter_list, + const std::function &enter_list, const std::function &exit_list, const std::function &add_item ) const { @@ -156,8 +170,8 @@ void Request::visit( ) const { int indentation_level = 0; node.visit( - [&indentation_level, &add_item] (ROM::Request::ListType type) { - add_item(LineItem::NewList, type, indentation_level, nullptr, false, -1); + [&indentation_level, &add_item] (ROM::Request::ListType type, size_t size) { + add_item(LineItem::NewList, type, indentation_level, nullptr, false, size); ++indentation_level; }, [&indentation_level] { @@ -170,13 +184,13 @@ void Request::visit( } void Request::Node::visit( - const std::function &enter_list, + const std::function &enter_list, const std::function &exit_list, const std::function &add_item ) const { switch(type) { case Type::One: - enter_list(ListType::Single); + enter_list(ListType::Single, 1); add_item(ROM::Request::ListType::Any, Description(name), is_optional, 0); exit_list(); break; @@ -184,7 +198,7 @@ void Request::Node::visit( case Type::Any: case Type::All: { const ListType list_type = type == Type::Any ? ListType::Any : ListType::All; - enter_list(list_type); + enter_list(list_type, children.size()); for(size_t index = 0; index < children.size(); index++) { auto &child = children[index]; @@ -304,10 +318,21 @@ std::wstring Request::description(int description_flags, wchar_t bullet_point) { switch(item) { case ROM::Request::LineItem::NewList: - switch(type) { - default: - case ROM::Request::ListType::All: output << "all of:"; break; - case ROM::Request::ListType::Any: output << "any of:"; break; + if(remaining > 1) { + if(!indentation_level) output << " "; + switch(type) { + default: + case ROM::Request::ListType::All: output << "all of:"; break; + case ROM::Request::ListType::Any: + if(remaining == 2) { + output << "either of:"; + } else { + output << "any of:"; + } + break; + } + } else { + output << ":"; } break; diff --git a/Machines/Utility/ROMCatalogue.hpp b/Machines/Utility/ROMCatalogue.hpp index d995e397c..3dfb2542d 100644 --- a/Machines/Utility/ROMCatalogue.hpp +++ b/Machines/Utility/ROMCatalogue.hpp @@ -201,7 +201,7 @@ struct Request { Any, All, Single }; void visit( - const std::function &enter_list, + const std::function &enter_list, const std::function &exit_list, const std::function &add_item ) const; @@ -214,7 +214,8 @@ struct Request { ) const; /// @returns a full bullet-pointed list of the requirements of this request, including - /// appropriate conjuntives. + /// appropriate conjuntives. This text is intended to be glued to the end of an opening + /// portion of a sentence, e.g. "Please supply" + request.description(0, L'*'). std::wstring description(int description_flags, wchar_t bullet_point); private: @@ -233,7 +234,7 @@ struct Request { void add_descriptions(std::vector &) const; bool validate(Map &) const; void visit( - const std::function &enter_list, + const std::function &enter_list, const std::function &exit_list, const std::function &add_item ) const; diff --git a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj index b5932eb04..bda241923 100644 --- a/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj +++ b/OSBindings/Mac/Clock Signal.xcodeproj/project.pbxproj @@ -14,6 +14,7 @@ 4B049CDD1DA3C82F00322067 /* BCDTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 4B049CDC1DA3C82F00322067 /* BCDTest.swift */; }; 4B051C912669C90B00CA44E8 /* ROMCatalogue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B051C5826670A9300CA44E8 /* ROMCatalogue.cpp */; }; 4B051C922669C90B00CA44E8 /* ROMCatalogue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B051C5826670A9300CA44E8 /* ROMCatalogue.cpp */; }; + 4B051C93266D9D6900CA44E8 /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; 4B05401E219D1618001BF69C /* ScanTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B05401D219D1618001BF69C /* ScanTarget.cpp */; }; 4B05401F219D1618001BF69C /* ScanTarget.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B05401D219D1618001BF69C /* ScanTarget.cpp */; }; 4B055A7A1FAE78A00060FFFF /* SDL2.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B055A771FAE78210060FFFF /* SDL2.framework */; }; @@ -568,7 +569,6 @@ 4B9F11CA2272433900701480 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 4B69FB451C4D950F00B5F0AA /* libz.tbd */; }; 4B9F11CC22729B3600701480 /* OPCLOGR2.BIN in Resources */ = {isa = PBXBuildFile; fileRef = 4B9F11CB22729B3500701480 /* OPCLOGR2.BIN */; }; 4BA0F68E1EEA0E8400E9489E /* ZX8081.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4BA0F68C1EEA0E8400E9489E /* ZX8081.cpp */; }; - 4BA3189422E7A4CA00D18CFA /* ROMImages in Resources */ = {isa = PBXBuildFile; fileRef = 4BC9DF441D044FCA00F44158 /* ROMImages */; }; 4BA61EB01D91515900B3C876 /* NSData+StdVector.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BA61EAF1D91515900B3C876 /* NSData+StdVector.mm */; }; 4BA91E1D216D85BA00F79557 /* MasterSystemVDPTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = 4BA91E1C216D85BA00F79557 /* MasterSystemVDPTests.mm */; }; 4BAD13441FF709C700FD114A /* MSX.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 4B0E61051FF34737002A9DBD /* MSX.cpp */; }; @@ -4768,7 +4768,7 @@ 4BB73EAC1B587A5100552FC2 /* MainMenu.xib in Resources */, 4B8FE21D1DA19D5F0090D3CE /* QuickLoadCompositeOptions.xib in Resources */, 4B49F0A923346F7A0045E6A6 /* MacintoshOptions.xib in Resources */, - 4BA3189422E7A4CA00D18CFA /* ROMImages in Resources */, + 4B051C93266D9D6900CA44E8 /* ROMImages in Resources */, 4B79E4461E3AF38600141F11 /* floppy525.png in Resources */, 4BEEE6BD20DC72EB003723BF /* CompositeOptions.xib in Resources */, 4B1497981EE4B97F00CE2596 /* ZX8081Options.xib in Resources */, diff --git a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift index 983988958..e2a0bc7c9 100644 --- a/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift +++ b/OSBindings/Mac/Clock Signal/Documents/MachineDocument.swift @@ -415,6 +415,10 @@ class MachineDocument: private var romRequestBaseText = "" private func setRomRequesterIsVisible(_ visible : Bool) { + if !visible && self.romRequesterPanel == nil { + return; + } + if self.romRequesterPanel!.isVisible == visible { return } diff --git a/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib b/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib index 82b71ef6e..44b71c68f 100644 --- a/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib +++ b/OSBindings/Mac/Clock Signal/ROMRequester/ROMRequester.xib @@ -1,8 +1,8 @@ - + - + @@ -20,18 +20,16 @@ - + - + - Clock Signal requires you to provide images of the system ROMs for this machine. They will be stored permanently; you need do this only once.

Please drag and drop the following over this text: - - + Clock Signal requires you to provide images of the system ROMs for this machine. They will be stored permanently; you need do this only once.

Please drag and drop over this text diff --git a/OSBindings/SDL/main.cpp b/OSBindings/SDL/main.cpp index e78118884..6034207aa 100644 --- a/OSBindings/SDL/main.cpp +++ b/OSBindings/SDL/main.cpp @@ -774,7 +774,7 @@ int main(int argc, char *argv[]) { default: break; case ::Machine::Error::MissingROM: { std::cerr << "Could not find system ROMs; please install to /usr/local/share/CLK/ or /usr/share/CLK/, or provide a --rompath, e.g. --rompath=~/ROMs." << std::endl; - std::cerr << "Needed — but didn't find — "; + std::cerr << "Needed — but didn't find —"; using DescriptionFlag = ROM::Description::DescriptionFlag; std::wcerr << missing_roms.description(DescriptionFlag::Filename | DescriptionFlag::CRC, L'*');