From 016eb87f7d279e56c3a5333236801e9109e1dba3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sat, 18 Feb 2023 11:17:23 +0530 Subject: [PATCH 01/61] Added licenses of tolk and nvda --- LICENSE-NVDA | 504 +++++++++++++++++++++++++++++++++++++++++++++++++++ LICENSE-TOLK | 165 +++++++++++++++++ 2 files changed, 669 insertions(+) create mode 100644 LICENSE-NVDA create mode 100644 LICENSE-TOLK diff --git a/LICENSE-NVDA b/LICENSE-NVDA new file mode 100644 index 0000000..602bfc9 --- /dev/null +++ b/LICENSE-NVDA @@ -0,0 +1,504 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 2.1, February 1999 + + Copyright (C) 1991, 1999 Free Software Foundation, Inc. + 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + +[This is the first released version of the Lesser GPL. It also counts + as the successor of the GNU Library Public License, version 2, hence + the version number 2.1.] + + Preamble + + The licenses for most software are designed to take away your +freedom to share and change it. By contrast, the GNU General Public +Licenses are intended to guarantee your freedom to share and change +free software--to make sure the software is free for all its users. + + This license, the Lesser General Public License, applies to some +specially designated software packages--typically libraries--of the +Free Software Foundation and other authors who decide to use it. You +can use it too, but we suggest you first think carefully about whether +this license or the ordinary General Public License is the better +strategy to use in any particular case, based on the explanations below. + + When we speak of free software, we are referring to freedom of use, +not price. Our General Public Licenses are designed to make sure that +you have the freedom to distribute copies of free software (and charge +for this service if you wish); that you receive source code or can get +it if you want it; that you can change the software and use pieces of +it in new free programs; and that you are informed that you can do +these things. + + To protect your rights, we need to make restrictions that forbid +distributors to deny you these rights or to ask you to surrender these +rights. These restrictions translate to certain responsibilities for +you if you distribute copies of the library or if you modify it. + + For example, if you distribute copies of the library, whether gratis +or for a fee, you must give the recipients all the rights that we gave +you. You must make sure that they, too, receive or can get the source +code. If you link other code with the library, you must provide +complete object files to the recipients, so that they can relink them +with the library after making changes to the library and recompiling +it. And you must show them these terms so they know their rights. + + We protect your rights with a two-step method: (1) we copyright the +library, and (2) we offer you this license, which gives you legal +permission to copy, distribute and/or modify the library. + + To protect each distributor, we want to make it very clear that +there is no warranty for the free library. Also, if the library is +modified by someone else and passed on, the recipients should know +that what they have is not the original version, so that the original +author's reputation will not be affected by problems that might be +introduced by others. + + Finally, software patents pose a constant threat to the existence of +any free program. We wish to make sure that a company cannot +effectively restrict the users of a free program by obtaining a +restrictive license from a patent holder. Therefore, we insist that +any patent license obtained for a version of the library must be +consistent with the full freedom of use specified in this license. + + Most GNU software, including some libraries, is covered by the +ordinary GNU General Public License. This license, the GNU Lesser +General Public License, applies to certain designated libraries, and +is quite different from the ordinary General Public License. We use +this license for certain libraries in order to permit linking those +libraries into non-free programs. + + When a program is linked with a library, whether statically or using +a shared library, the combination of the two is legally speaking a +combined work, a derivative of the original library. The ordinary +General Public License therefore permits such linking only if the +entire combination fits its criteria of freedom. The Lesser General +Public License permits more lax criteria for linking other code with +the library. + + We call this license the "Lesser" General Public License because it +does Less to protect the user's freedom than the ordinary General +Public License. It also provides other free software developers Less +of an advantage over competing non-free programs. These disadvantages +are the reason we use the ordinary General Public License for many +libraries. However, the Lesser license provides advantages in certain +special circumstances. + + For example, on rare occasions, there may be a special need to +encourage the widest possible use of a certain library, so that it becomes +a de-facto standard. To achieve this, non-free programs must be +allowed to use the library. A more frequent case is that a free +library does the same job as widely used non-free libraries. In this +case, there is little to gain by limiting the free library to free +software only, so we use the Lesser General Public License. + + In other cases, permission to use a particular library in non-free +programs enables a greater number of people to use a large body of +free software. For example, permission to use the GNU C Library in +non-free programs enables many more people to use the whole GNU +operating system, as well as its variant, the GNU/Linux operating +system. + + Although the Lesser General Public License is Less protective of the +users' freedom, it does ensure that the user of a program that is +linked with the Library has the freedom and the wherewithal to run +that program using a modified version of the Library. + + The precise terms and conditions for copying, distribution and +modification follow. Pay close attention to the difference between a +"work based on the library" and a "work that uses the library". The +former contains code derived from the library, whereas the latter must +be combined with the library in order to run. + + GNU LESSER GENERAL PUBLIC LICENSE + TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION + + 0. This License Agreement applies to any software library or other +program which contains a notice placed by the copyright holder or +other authorized party saying it may be distributed under the terms of +this Lesser General Public License (also called "this License"). +Each licensee is addressed as "you". + + A "library" means a collection of software functions and/or data +prepared so as to be conveniently linked with application programs +(which use some of those functions and data) to form executables. + + The "Library", below, refers to any such software library or work +which has been distributed under these terms. A "work based on the +Library" means either the Library or any derivative work under +copyright law: that is to say, a work containing the Library or a +portion of it, either verbatim or with modifications and/or translated +straightforwardly into another language. (Hereinafter, translation is +included without limitation in the term "modification".) + + "Source code" for a work means the preferred form of the work for +making modifications to it. For a library, complete source code means +all the source code for all modules it contains, plus any associated +interface definition files, plus the scripts used to control compilation +and installation of the library. + + Activities other than copying, distribution and modification are not +covered by this License; they are outside its scope. The act of +running a program using the Library is not restricted, and output from +such a program is covered only if its contents constitute a work based +on the Library (independent of the use of the Library in a tool for +writing it). Whether that is true depends on what the Library does +and what the program that uses the Library does. + + 1. You may copy and distribute verbatim copies of the Library's +complete source code as you receive it, in any medium, provided that +you conspicuously and appropriately publish on each copy an +appropriate copyright notice and disclaimer of warranty; keep intact +all the notices that refer to this License and to the absence of any +warranty; and distribute a copy of this License along with the +Library. + + You may charge a fee for the physical act of transferring a copy, +and you may at your option offer warranty protection in exchange for a +fee. + + 2. You may modify your copy or copies of the Library or any portion +of it, thus forming a work based on the Library, and copy and +distribute such modifications or work under the terms of Section 1 +above, provided that you also meet all of these conditions: + + a) The modified work must itself be a software library. + + b) You must cause the files modified to carry prominent notices + stating that you changed the files and the date of any change. + + c) You must cause the whole of the work to be licensed at no + charge to all third parties under the terms of this License. + + d) If a facility in the modified Library refers to a function or a + table of data to be supplied by an application program that uses + the facility, other than as an argument passed when the facility + is invoked, then you must make a good faith effort to ensure that, + in the event an application does not supply such function or + table, the facility still operates, and performs whatever part of + its purpose remains meaningful. + + (For example, a function in a library to compute square roots has + a purpose that is entirely well-defined independent of the + application. Therefore, Subsection 2d requires that any + application-supplied function or table used by this function must + be optional: if the application does not supply it, the square + root function must still compute square roots.) + +These requirements apply to the modified work as a whole. If +identifiable sections of that work are not derived from the Library, +and can be reasonably considered independent and separate works in +themselves, then this License, and its terms, do not apply to those +sections when you distribute them as separate works. But when you +distribute the same sections as part of a whole which is a work based +on the Library, the distribution of the whole must be on the terms of +this License, whose permissions for other licensees extend to the +entire whole, and thus to each and every part regardless of who wrote +it. + +Thus, it is not the intent of this section to claim rights or contest +your rights to work written entirely by you; rather, the intent is to +exercise the right to control the distribution of derivative or +collective works based on the Library. + +In addition, mere aggregation of another work not based on the Library +with the Library (or with a work based on the Library) on a volume of +a storage or distribution medium does not bring the other work under +the scope of this License. + + 3. You may opt to apply the terms of the ordinary GNU General Public +License instead of this License to a given copy of the Library. To do +this, you must alter all the notices that refer to this License, so +that they refer to the ordinary GNU General Public License, version 2, +instead of to this License. (If a newer version than version 2 of the +ordinary GNU General Public License has appeared, then you can specify +that version instead if you wish.) Do not make any other change in +these notices. + + Once this change is made in a given copy, it is irreversible for +that copy, so the ordinary GNU General Public License applies to all +subsequent copies and derivative works made from that copy. + + This option is useful when you wish to copy part of the code of +the Library into a program that is not a library. + + 4. You may copy and distribute the Library (or a portion or +derivative of it, under Section 2) in object code or executable form +under the terms of Sections 1 and 2 above provided that you accompany +it with the complete corresponding machine-readable source code, which +must be distributed under the terms of Sections 1 and 2 above on a +medium customarily used for software interchange. + + If distribution of object code is made by offering access to copy +from a designated place, then offering equivalent access to copy the +source code from the same place satisfies the requirement to +distribute the source code, even though third parties are not +compelled to copy the source along with the object code. + + 5. A program that contains no derivative of any portion of the +Library, but is designed to work with the Library by being compiled or +linked with it, is called a "work that uses the Library". Such a +work, in isolation, is not a derivative work of the Library, and +therefore falls outside the scope of this License. + + However, linking a "work that uses the Library" with the Library +creates an executable that is a derivative of the Library (because it +contains portions of the Library), rather than a "work that uses the +library". The executable is therefore covered by this License. +Section 6 states terms for distribution of such executables. + + When a "work that uses the Library" uses material from a header file +that is part of the Library, the object code for the work may be a +derivative work of the Library even though the source code is not. +Whether this is true is especially significant if the work can be +linked without the Library, or if the work is itself a library. The +threshold for this to be true is not precisely defined by law. + + If such an object file uses only numerical parameters, data +structure layouts and accessors, and small macros and small inline +functions (ten lines or less in length), then the use of the object +file is unrestricted, regardless of whether it is legally a derivative +work. (Executables containing this object code plus portions of the +Library will still fall under Section 6.) + + Otherwise, if the work is a derivative of the Library, you may +distribute the object code for the work under the terms of Section 6. +Any executables containing that work also fall under Section 6, +whether or not they are linked directly with the Library itself. + + 6. As an exception to the Sections above, you may also combine or +link a "work that uses the Library" with the Library to produce a +work containing portions of the Library, and distribute that work +under terms of your choice, provided that the terms permit +modification of the work for the customer's own use and reverse +engineering for debugging such modifications. + + You must give prominent notice with each copy of the work that the +Library is used in it and that the Library and its use are covered by +this License. You must supply a copy of this License. If the work +during execution displays copyright notices, you must include the +copyright notice for the Library among them, as well as a reference +directing the user to the copy of this License. Also, you must do one +of these things: + + a) Accompany the work with the complete corresponding + machine-readable source code for the Library including whatever + changes were used in the work (which must be distributed under + Sections 1 and 2 above); and, if the work is an executable linked + with the Library, with the complete machine-readable "work that + uses the Library", as object code and/or source code, so that the + user can modify the Library and then relink to produce a modified + executable containing the modified Library. (It is understood + that the user who changes the contents of definitions files in the + Library will not necessarily be able to recompile the application + to use the modified definitions.) + + b) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (1) uses at run time a + copy of the library already present on the user's computer system, + rather than copying library functions into the executable, and (2) + will operate properly with a modified version of the library, if + the user installs one, as long as the modified version is + interface-compatible with the version that the work was made with. + + c) Accompany the work with a written offer, valid for at + least three years, to give the same user the materials + specified in Subsection 6a, above, for a charge no more + than the cost of performing this distribution. + + d) If distribution of the work is made by offering access to copy + from a designated place, offer equivalent access to copy the above + specified materials from the same place. + + e) Verify that the user has already received a copy of these + materials or that you have already sent this user a copy. + + For an executable, the required form of the "work that uses the +Library" must include any data and utility programs needed for +reproducing the executable from it. However, as a special exception, +the materials to be distributed need not include anything that is +normally distributed (in either source or binary form) with the major +components (compiler, kernel, and so on) of the operating system on +which the executable runs, unless that component itself accompanies +the executable. + + It may happen that this requirement contradicts the license +restrictions of other proprietary libraries that do not normally +accompany the operating system. Such a contradiction means you cannot +use both them and the Library together in an executable that you +distribute. + + 7. You may place library facilities that are a work based on the +Library side-by-side in a single library together with other library +facilities not covered by this License, and distribute such a combined +library, provided that the separate distribution of the work based on +the Library and of the other library facilities is otherwise +permitted, and provided that you do these two things: + + a) Accompany the combined library with a copy of the same work + based on the Library, uncombined with any other library + facilities. This must be distributed under the terms of the + Sections above. + + b) Give prominent notice with the combined library of the fact + that part of it is a work based on the Library, and explaining + where to find the accompanying uncombined form of the same work. + + 8. You may not copy, modify, sublicense, link with, or distribute +the Library except as expressly provided under this License. Any +attempt otherwise to copy, modify, sublicense, link with, or +distribute the Library is void, and will automatically terminate your +rights under this License. However, parties who have received copies, +or rights, from you under this License will not have their licenses +terminated so long as such parties remain in full compliance. + + 9. You are not required to accept this License, since you have not +signed it. However, nothing else grants you permission to modify or +distribute the Library or its derivative works. These actions are +prohibited by law if you do not accept this License. Therefore, by +modifying or distributing the Library (or any work based on the +Library), you indicate your acceptance of this License to do so, and +all its terms and conditions for copying, distributing or modifying +the Library or works based on it. + + 10. Each time you redistribute the Library (or any work based on the +Library), the recipient automatically receives a license from the +original licensor to copy, distribute, link with or modify the Library +subject to these terms and conditions. You may not impose any further +restrictions on the recipients' exercise of the rights granted herein. +You are not responsible for enforcing compliance by third parties with +this License. + + 11. If, as a consequence of a court judgment or allegation of patent +infringement or for any other reason (not limited to patent issues), +conditions are imposed on you (whether by court order, agreement or +otherwise) that contradict the conditions of this License, they do not +excuse you from the conditions of this License. If you cannot +distribute so as to satisfy simultaneously your obligations under this +License and any other pertinent obligations, then as a consequence you +may not distribute the Library at all. For example, if a patent +license would not permit royalty-free redistribution of the Library by +all those who receive copies directly or indirectly through you, then +the only way you could satisfy both it and this License would be to +refrain entirely from distribution of the Library. + +If any portion of this section is held invalid or unenforceable under any +particular circumstance, the balance of the section is intended to apply, +and the section as a whole is intended to apply in other circumstances. + +It is not the purpose of this section to induce you to infringe any +patents or other property right claims or to contest validity of any +such claims; this section has the sole purpose of protecting the +integrity of the free software distribution system which is +implemented by public license practices. Many people have made +generous contributions to the wide range of software distributed +through that system in reliance on consistent application of that +system; it is up to the author/donor to decide if he or she is willing +to distribute software through any other system and a licensee cannot +impose that choice. + +This section is intended to make thoroughly clear what is believed to +be a consequence of the rest of this License. + + 12. If the distribution and/or use of the Library is restricted in +certain countries either by patents or by copyrighted interfaces, the +original copyright holder who places the Library under this License may add +an explicit geographical distribution limitation excluding those countries, +so that distribution is permitted only in or among countries not thus +excluded. In such case, this License incorporates the limitation as if +written in the body of this License. + + 13. The Free Software Foundation may publish revised and/or new +versions of the Lesser General Public License from time to time. +Such new versions will be similar in spirit to the present version, +but may differ in detail to address new problems or concerns. + +Each version is given a distinguishing version number. If the Library +specifies a version number of this License which applies to it and +"any later version", you have the option of following the terms and +conditions either of that version or of any later version published by +the Free Software Foundation. If the Library does not specify a +license version number, you may choose any version ever published by +the Free Software Foundation. + + 14. If you wish to incorporate parts of the Library into other free +programs whose distribution conditions are incompatible with these, +write to the author to ask for permission. For software which is +copyrighted by the Free Software Foundation, write to the Free +Software Foundation; we sometimes make exceptions for this. Our +decision will be guided by the two goals of preserving the free status +of all derivatives of our free software and of promoting the sharing +and reuse of software generally. + + NO WARRANTY + + 15. BECAUSE THE LIBRARY IS LICENSED FREE OF CHARGE, THERE IS NO +WARRANTY FOR THE LIBRARY, TO THE EXTENT PERMITTED BY APPLICABLE LAW. +EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR +OTHER PARTIES PROVIDE THE LIBRARY "AS IS" WITHOUT WARRANTY OF ANY +KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE +IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR +PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE +LIBRARY IS WITH YOU. SHOULD THE LIBRARY PROVE DEFECTIVE, YOU ASSUME +THE COST OF ALL NECESSARY SERVICING, REPAIR OR CORRECTION. + + 16. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN +WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY +AND/OR REDISTRIBUTE THE LIBRARY AS PERMITTED ABOVE, BE LIABLE TO YOU +FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR +CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE +LIBRARY (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING +RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A +FAILURE OF THE LIBRARY TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF +SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH +DAMAGES. + + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Libraries + + If you develop a new library, and you want it to be of the greatest +possible use to the public, we recommend making it free software that +everyone can redistribute and change. You can do so by permitting +redistribution under these terms (or, alternatively, under the terms of the +ordinary General Public License). + + To apply these terms, attach the following notices to the library. It is +safest to attach them to the start of each source file to most effectively +convey the exclusion of warranty; and each file should have at least the +"copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + +Also add information on how to contact you by electronic and paper mail. + +You should also get your employer (if you work as a programmer) or your +school, if any, to sign a "copyright disclaimer" for the library, if +necessary. Here is a sample; alter the names: + + Yoyodyne, Inc., hereby disclaims all copyright interest in the + library `Frob' (a library for tweaking knobs) written by James Random Hacker. + + , 1 April 1990 + Ty Coon, President of Vice + +That's all there is to it! + + diff --git a/LICENSE-TOLK b/LICENSE-TOLK new file mode 100644 index 0000000..3a3b445 --- /dev/null +++ b/LICENSE-TOLK @@ -0,0 +1,165 @@ + GNU LESSER GENERAL PUBLIC LICENSE + Version 3, 29 June 2007 + + Copyright (C) 2007 Free Software Foundation, Inc. [http://fsf.org/] + Everyone is permitted to copy and distribute verbatim copies + of this license document, but changing it is not allowed. + + + This version of the GNU Lesser General Public License incorporates +the terms and conditions of version 3 of the GNU General Public +License, supplemented by the additional permissions listed below. + + 0. Additional Definitions. + + As used herein, "this License" refers to version 3 of the GNU Lesser +General Public License, and the "GNU GPL" refers to version 3 of the GNU +General Public License. + + "The Library" refers to a covered work governed by this License, +other than an Application or a Combined Work as defined below. + + An "Application" is any work that makes use of an interface provided +by the Library, but which is not otherwise based on the Library. +Defining a subclass of a class defined by the Library is deemed a mode +of using an interface provided by the Library. + + A "Combined Work" is a work produced by combining or linking an +Application with the Library. The particular version of the Library +with which the Combined Work was made is also called the "Linked +Version". + + The "Minimal Corresponding Source" for a Combined Work means the +Corresponding Source for the Combined Work, excluding any source code +for portions of the Combined Work that, considered in isolation, are +based on the Application, and not on the Linked Version. + + The "Corresponding Application Code" for a Combined Work means the +object code and/or source code for the Application, including any data +and utility programs needed for reproducing the Combined Work from the +Application, but excluding the System Libraries of the Combined Work. + + 1. Exception to Section 3 of the GNU GPL. + + You may convey a covered work under sections 3 and 4 of this License +without being bound by section 3 of the GNU GPL. + + 2. Conveying Modified Versions. + + If you modify a copy of the Library, and, in your modifications, a +facility refers to a function or data to be supplied by an Application +that uses the facility (other than as an argument passed when the +facility is invoked), then you may convey a copy of the modified +version: + + a) under this License, provided that you make a good faith effort to + ensure that, in the event an Application does not supply the + function or data, the facility still operates, and performs + whatever part of its purpose remains meaningful, or + + b) under the GNU GPL, with none of the additional permissions of + this License applicable to that copy. + + 3. Object Code Incorporating Material from Library Header Files. + + The object code form of an Application may incorporate material from +a header file that is part of the Library. You may convey such object +code under terms of your choice, provided that, if the incorporated +material is not limited to numerical parameters, data structure +layouts and accessors, or small macros, inline functions and templates +(ten or fewer lines in length), you do both of the following: + + a) Give prominent notice with each copy of the object code that the + Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the object code with a copy of the GNU GPL and this license + document. + + 4. Combined Works. + + You may convey a Combined Work under terms of your choice that, +taken together, effectively do not restrict modification of the +portions of the Library contained in the Combined Work and reverse +engineering for debugging such modifications, if you also do each of +the following: + + a) Give prominent notice with each copy of the Combined Work that + the Library is used in it and that the Library and its use are + covered by this License. + + b) Accompany the Combined Work with a copy of the GNU GPL and this license + document. + + c) For a Combined Work that displays copyright notices during + execution, include the copyright notice for the Library among + these notices, as well as a reference directing the user to the + copies of the GNU GPL and this license document. + + d) Do one of the following: + + 0) Convey the Minimal Corresponding Source under the terms of this + License, and the Corresponding Application Code in a form + suitable for, and under terms that permit, the user to + recombine or relink the Application with a modified version of + the Linked Version to produce a modified Combined Work, in the + manner specified by section 6 of the GNU GPL for conveying + Corresponding Source. + + 1) Use a suitable shared library mechanism for linking with the + Library. A suitable mechanism is one that (a) uses at run time + a copy of the Library already present on the user's computer + system, and (b) will operate properly with a modified version + of the Library that is interface-compatible with the Linked + Version. + + e) Provide Installation Information, but only if you would otherwise + be required to provide such information under section 6 of the + GNU GPL, and only to the extent that such information is + necessary to install and execute a modified version of the + Combined Work produced by recombining or relinking the + Application with a modified version of the Linked Version. (If + you use option 4d0, the Installation Information must accompany + the Minimal Corresponding Source and Corresponding Application + Code. If you use option 4d1, you must provide the Installation + Information in the manner specified by section 6 of the GNU GPL + for conveying Corresponding Source.) + + 5. Combined Libraries. + + You may place library facilities that are a work based on the +Library side by side in a single library together with other library +facilities that are not Applications and are not covered by this +License, and convey such a combined library under terms of your +choice, if you do both of the following: + + a) Accompany the combined library with a copy of the same work based + on the Library, uncombined with any other library facilities, + conveyed under the terms of this License. + + b) Give prominent notice with the combined library that part of it + is a work based on the Library, and explaining where to find the + accompanying uncombined form of the same work. + + 6. Revised Versions of the GNU Lesser General Public License. + + The Free Software Foundation may publish revised and/or new versions +of the GNU Lesser General Public License from time to time. Such new +versions will be similar in spirit to the present version, but may +differ in detail to address new problems or concerns. + + Each version is given a distinguishing version number. If the +Library as you received it specifies that a certain numbered version +of the GNU Lesser General Public License "or any later version" +applies to it, you have the option of following the terms and +conditions either of that published version or of any later version +published by the Free Software Foundation. If the Library as you +received it does not specify a version number of the GNU Lesser +General Public License, you may choose any version of the GNU Lesser +General Public License ever published by the Free Software Foundation. + + If the Library as you received it specifies that a proxy can decide +whether future versions of the GNU Lesser General Public License shall +apply, that proxy's public statement of acceptance of any version is +permanent authorization for you to choose that version for the +Library. \ No newline at end of file From 434921a6680a739405d8b04d76c9c67e5f5e082b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sat, 18 Feb 2023 12:36:39 +0530 Subject: [PATCH 02/61] Added ability to add entries specific to a certain farm type. The entries with 'farm' name will be applied to all farm types and if we want to add an entry specific to a farm type, like to beach farm layout, we can use 'farm_beach' name for this. --- stardew-access/Features/StaticTiles.cs | 134 ++++++++++++++----------- 1 file changed, 78 insertions(+), 56 deletions(-) diff --git a/stardew-access/Features/StaticTiles.cs b/stardew-access/Features/StaticTiles.cs index 87fa154..0c058e7 100644 --- a/stardew-access/Features/StaticTiles.cs +++ b/stardew-access/Features/StaticTiles.cs @@ -77,18 +77,17 @@ namespace stardew_access.Features return getStaticTileInfoAtWithCategory(x, y).name; } - public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y) - { + public (string? name, CATEGORY category) getStaticTileInfoAtWithCategory(int x, int y) { List allData = new List(); if (customTilesData != null) allData.Add(customTilesData); if (staticTilesData != null) allData.Add(staticTilesData); - foreach (JObject data in allData) - { + foreach (JObject data in allData) { foreach (KeyValuePair location in data) { - if (location.Key.Contains("||") && MainClass.ModHelper != null) + string locationName = location.Key; + if (locationName.Contains("||") && MainClass.ModHelper != null) { // Mod Specific Tiles // We can add tiles that only get detected when the specified mod is loaded. @@ -109,69 +108,92 @@ namespace stardew_access.Features // . // . // } - string uniqueModID = location.Key.Substring(location.Key.LastIndexOf("||") + 2); - string locationName = location.Key.Remove(location.Key.LastIndexOf("||")); + string uniqueModID = locationName.Substring(locationName.LastIndexOf("||") + 2); + locationName = locationName.Remove(locationName.LastIndexOf("||")); bool isLoaded = MainClass.ModHelper.ModRegistry.IsLoaded(uniqueModID); if (!isLoaded) continue; // Skip if the specified mod is not loaded - if (!Game1.currentLocation.Name.ToLower().Equals(locationName.ToLower())) continue; } - else if (!Game1.currentLocation.Name.ToLower().Equals(location.Key.ToLower())) continue; - if (location.Value != null) - foreach (var tile in ((JObject)location.Value)) + if (locationName.Contains("_") && locationName.ToLower().StartsWith("farm_")) + { + string farmType = locationName.Substring(locationName.LastIndexOf("_") + 1); + int farmTypeIndex = getFarmTypeIndex(farmType); + locationName = locationName.Remove(locationName.LastIndexOf("_")); + + if (farmTypeIndex != Game1.whichFarm) continue; // Skip if current farm type does not matches + } + + if (!Game1.currentLocation.Name.ToLower().Equals(locationName.ToLower())) continue; + if (location.Value == null) continue; + + foreach (var tile in ((JObject)location.Value)) + { + if (tile.Value == null) continue; + + JToken? tileXArray = tile.Value["x"]; + JToken? tileYArray = tile.Value["y"]; + JToken? tileType = tile.Value["type"]; + + if (tileXArray == null || tileYArray == null || tileType == null) + continue; + + bool isXPresent = false; + bool isYPresent = false; + + foreach (var item in tileXArray) { - if (tile.Value == null) + if (short.Parse(item.ToString()) != x) continue; - JToken? tileXArray = tile.Value["x"]; - JToken? tileYArray = tile.Value["y"]; - JToken? tileType = tile.Value["type"]; - - if (tileXArray == null || tileYArray == null || tileType == null) - continue; - - bool isXPresent = false; - bool isYPresent = false; - - foreach (var item in tileXArray) - { - if (short.Parse(item.ToString()) == x) - { - isXPresent = true; - break; - } - } - - foreach (var item in tileYArray) - { - if (short.Parse(item.ToString()) == y) - { - isYPresent = true; - break; - } - } - - if (isXPresent && isYPresent) - { - string key = tile.Key; - if (key.Contains('[') && key.Contains(']')) - { - int i1 = key.IndexOf('['); - int i2 = key.LastIndexOf(']'); - - if (i1 < i2) - { - key = key.Remove(i1, ++i2 - i1); - } - } - - return (key.Trim(), CATEGORY.FromString(tileType.ToString().ToLower())); - } + isXPresent = true; + break; } + + foreach (var item in tileYArray) + { + if (short.Parse(item.ToString()) != y) + continue; + + isYPresent = true; + break; + } + + if (isXPresent && isYPresent) + { + string key = tile.Key; + if (key.Contains('[') && key.Contains(']')) + { + int i1 = key.IndexOf('['); + int i2 = key.LastIndexOf(']'); + + if (i1 < i2) + { + key = key.Remove(i1, ++i2 - i1); + } + } + + return (key.Trim(), CATEGORY.FromString(tileType.ToString().ToLower())); + } + } } } return (null, CATEGORY.Others); } + + private int getFarmTypeIndex(string farmType) + { + return farmType.ToLower() switch + { + "default" => 0, + "riverlands" => 1, + "forest" => 2, + "mountains" => 3, + "combat" => 4, + "fourcorners" => 5, + "beach" => 6, + _ => 0, + }; + } } } From feff266d7c0ef079c74abb8846d75c27155d37c1 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sun, 19 Feb 2023 17:36:57 +0530 Subject: [PATCH 03/61] Possibly also added mod loaded farm layout support to it. (not tested) --- stardew-access/Features/StaticTiles.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/stardew-access/Features/StaticTiles.cs b/stardew-access/Features/StaticTiles.cs index 0c058e7..a7c6333 100644 --- a/stardew-access/Features/StaticTiles.cs +++ b/stardew-access/Features/StaticTiles.cs @@ -122,6 +122,8 @@ namespace stardew_access.Features locationName = locationName.Remove(locationName.LastIndexOf("_")); if (farmTypeIndex != Game1.whichFarm) continue; // Skip if current farm type does not matches + // if (Game1.whichModFarm != null) MainClass.DebugLog($"{farmType} {Game1.whichModFarm.MapName}"); + if (farmTypeIndex != 7 || Game1.whichModFarm == null || !farmType.ToLower().Equals(Game1.whichModFarm.MapName.ToLower())) continue; // Not checked but should work } if (!Game1.currentLocation.Name.ToLower().Equals(locationName.ToLower())) continue; @@ -192,7 +194,7 @@ namespace stardew_access.Features "combat" => 4, "fourcorners" => 5, "beach" => 6, - _ => 0, + _ => 7, }; } } From b6b8ad8c8abf905a6f6147f8d92ea628c2f8d0ed Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sun, 19 Feb 2023 21:50:57 +0530 Subject: [PATCH 04/61] Entries for town map can be distinguished for joja run use 'town_joja' as location name in static-tiles.json or custom-tiles.json --- stardew-access/Features/StaticTiles.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/stardew-access/Features/StaticTiles.cs b/stardew-access/Features/StaticTiles.cs index a7c6333..9b36631 100644 --- a/stardew-access/Features/StaticTiles.cs +++ b/stardew-access/Features/StaticTiles.cs @@ -123,7 +123,12 @@ namespace stardew_access.Features if (farmTypeIndex != Game1.whichFarm) continue; // Skip if current farm type does not matches // if (Game1.whichModFarm != null) MainClass.DebugLog($"{farmType} {Game1.whichModFarm.MapName}"); - if (farmTypeIndex != 7 || Game1.whichModFarm == null || !farmType.ToLower().Equals(Game1.whichModFarm.MapName.ToLower())) continue; // Not checked but should work + if (farmTypeIndex != 7 || Game1.whichModFarm == null || !farmType.ToLower().Equals(Game1.whichModFarm.MapName.ToLower())) continue; // Not tested but should work + } + + if (locationName.ToLower().Equals("town_joja") && Game1.MasterPlayer.mailReceived.Contains("JojaMember")) + { + locationName = "town"; } if (!Game1.currentLocation.Name.ToLower().Equals(locationName.ToLower())) continue; From 9af30890bc211a610d9990d64be945b4f0eef1e5 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sun, 19 Feb 2023 22:26:10 +0530 Subject: [PATCH 05/61] Added dynamic detection of sink in farm house Replace the name of kitchen with stove --- stardew-access/Features/TileInfo.cs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/stardew-access/Features/TileInfo.cs b/stardew-access/Features/TileInfo.cs index 53dff70..f21884f 100644 --- a/stardew-access/Features/TileInfo.cs +++ b/stardew-access/Features/TileInfo.cs @@ -455,15 +455,19 @@ namespace stardew_access.Features else if (Game1.currentLocation is FarmHouse farmHouse) { if (farmHouse.upgradeLevel >= 1) - if (farmHouse.getKitchenStandingSpot().X == x && (farmHouse.getKitchenStandingSpot().Y - 1) == y) // Standing spot is where the player will stand - return (CATEGORY.Interactables, "Kitchen"); + if (farmHouse.getKitchenStandingSpot().X == x && (farmHouse.getKitchenStandingSpot().Y - 1) == y) + return (CATEGORY.Interactables, "Stove"); + else if ((farmHouse.getKitchenStandingSpot().X + 1) == x && (farmHouse.getKitchenStandingSpot().Y - 1) == y) + return (CATEGORY.Others, "Sink"); else if (farmHouse.fridgePosition.X == x && farmHouse.fridgePosition.Y == y) return (CATEGORY.Interactables, "Fridge"); } else if (Game1.currentLocation is IslandFarmHouse islandFarmHouse) { - if ((islandFarmHouse.fridgePosition.X - 1) == x && islandFarmHouse.fridgePosition.Y == y) - return (CATEGORY.Interactables, "Kitchen"); + if ((islandFarmHouse.fridgePosition.X - 2) == x && islandFarmHouse.fridgePosition.Y == y) + return (CATEGORY.Interactables, "Stove"); + else if ((islandFarmHouse.fridgePosition.X - 1) == x && islandFarmHouse.fridgePosition.Y == y) + return (CATEGORY.Others, "Sink"); else if (islandFarmHouse.fridgePosition.X == x && islandFarmHouse.fridgePosition.Y == y) return (CATEGORY.Interactables, "Fridge"); } From 34d773204c5fc895ff1b64bb6a2fff0c480e02fb Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Sun, 19 Feb 2023 22:35:57 +0530 Subject: [PATCH 06/61] Expanded the detection of shipping bin in island --- stardew-access/Features/TileInfo.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/stardew-access/Features/TileInfo.cs b/stardew-access/Features/TileInfo.cs index f21884f..74adb00 100644 --- a/stardew-access/Features/TileInfo.cs +++ b/stardew-access/Features/TileInfo.cs @@ -524,7 +524,7 @@ namespace stardew_access.Features } else if (Game1.currentLocation is IslandWest islandWest) { - if (islandWest.shippingBinPosition.X == x && islandWest.shippingBinPosition.Y == y) + if ((islandWest.shippingBinPosition.X == x || (islandWest.shippingBinPosition.X + 1) == x) && islandWest.shippingBinPosition.Y == y) return (CATEGORY.Interactables, "Shipping Bin"); } else if (Game1.currentLocation is IslandNorth islandNorth) From d2c34451b3335af60ccf46cda9d86d639c194aa3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 11:48:24 +0530 Subject: [PATCH 07/61] Added sound cue when the slot item is not usable --- invalid-selection-license.txt | 32 ++++++++++++++++++ stardew-access/CustomSoundEffects.cs | 1 + stardew-access/Patches/GameMenuPatches.cs | 8 ++++- stardew-access/Patches/MenuPatches.cs | 15 ++++++++ .../assets/sounds/invalid-selection.wav | Bin 0 -> 30836 bytes 5 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 invalid-selection-license.txt create mode 100644 stardew-access/assets/sounds/invalid-selection.wav diff --git a/invalid-selection-license.txt b/invalid-selection-license.txt new file mode 100644 index 0000000..f1b27d8 --- /dev/null +++ b/invalid-selection-license.txt @@ -0,0 +1,32 @@ +PIXABAY LICENSE CERTIFICATE +============================================== + +This document confirms the download of an audio file pursuant to the Pixabay License as defined in the Pixabay Terms of Service available at https://https://pixabay.com/service/terms/ + +Licensor's Username: +https://pixabay.com/users/pixabay-1/ + +Licensee: +TheOneWhoKnocks + +Audio File Title: +Invalid Selection + +Audio File URL: +https://pixabay.com/sound-effects/invalid-selection-39351/ + +Audio File ID: +39351 + +Date of download: +2023-02-20 05:52:26 UTC + +Pixabay GmbH c/o Lacore Rechtsanwälte LLP +Berliner Freiheit 2, 10785 Berlin, Germany + +Pixabay is a user-contributed stock content website. The above-named Licensor is responsible for this audio file. Pixabay monitors uploaded audio files only to a reasonable extent. Pixabay cannot be held responsible for the acts or omissions of its users and does not represent or warrant that any required third-party consents or licenses have been obtained. + +For any queries related to this document please contact Pixabay via info@pixabay.com. + + +==== THIS IS NOT A TAX RECEIPT OR INVOICE ==== \ No newline at end of file diff --git a/stardew-access/CustomSoundEffects.cs b/stardew-access/CustomSoundEffects.cs index b5610e4..f4c6d43 100644 --- a/stardew-access/CustomSoundEffects.cs +++ b/stardew-access/CustomSoundEffects.cs @@ -22,6 +22,7 @@ namespace stardew_access soundEffects.Add("drop_item", TYPE.Sound); soundEffects.Add("colliding", TYPE.Sound); + soundEffects.Add("invalid-selection", TYPE.Sound); soundEffects.Add("npc_top", TYPE.Footstep); soundEffects.Add("npc_right", TYPE.Footstep); diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index e1c2d46..ead5f39 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -1,5 +1,4 @@ using StardewValley; -using StardewValley.Locations; using StardewValley.Menus; using StardewValley.Objects; @@ -21,6 +20,7 @@ namespace stardew_access.Patches internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; + internal static int prevSlotIndex = -999; internal static void CollectionsPagePatch(CollectionsPage __instance) { @@ -1295,6 +1295,12 @@ namespace stardew_access.Patches if (!inventoryMenu.highlightMethod(actualInventory[i])) { name = $"{name} not usable here"; + + if (prevSlotIndex != i) + { + prevSlotIndex = i; + Game1.playSound("invalid-selection"); + } } if (giveExtraDetails) diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 993d580..ca05742 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -16,6 +16,7 @@ namespace stardew_access.Patches internal static string pondQueryMenuQuery = " "; internal static string forgeMenuQuery = " "; internal static string itemListMenuQuery = " "; + internal static int prevSlotIndex = -999; public static Vector2? prevTile = null; internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) @@ -143,6 +144,13 @@ namespace stardew_access.Patches { toSpeak = $"{toSpeak} not usable here"; } + + if (prevSlotIndex != i) + { + prevSlotIndex = i; + MainClass.DebugLog("here"); + Game1.playSound("invalid-selection"); + } } if (forgeMenuQuery != $"{toSpeak}:{i}") @@ -310,6 +318,13 @@ namespace stardew_access.Patches { toSpeak = $"{toSpeak} not usable here"; } + + if (prevSlotIndex != i) + { + prevSlotIndex = i; + MainClass.DebugLog("here"); + Game1.playSound("invalid-selection"); + } } if (tailoringMenuQuery != $"{toSpeak}:{i}") diff --git a/stardew-access/assets/sounds/invalid-selection.wav b/stardew-access/assets/sounds/invalid-selection.wav new file mode 100644 index 0000000000000000000000000000000000000000..83e63bada354ac5edf4711b63e399d63de3a49e5 GIT binary patch literal 30836 zcmZ9V2mFoY8~>kihE4X~GbL4-q4j}+E}fvDpqx?sny7;WL37>GrC(>S`)1|t?wCQ?9q0SWT|As zbj|eVshO!BsmoFiCm&1BNz6_3N?eiH?(TM9c3*J2#G{+L*V*pe>D=d7PR@SIe$Sp{ zziB^UkFl%TS#@5 zS$^b2wv~xaM#ZgjtTK%Ap^QGOYE`g~MW;D)OZ0O%FPxkEG539Dc4lPuj;x;zvd`w8 z%~kX&dhd8|dt1D%-XMRFf5<=RcMGlvCIsVyFM`j5Ob`Yw!=~Xa;T_@3XnOPzbeZSO zb<%DDH*!Pwp5(pB*2$L1Nr}mcYKba|C)~%~aqa}S2;V>Fyy&!G{A+Kr*V+HrTkXyE zYJ08yApEIr*RYG&MeQZlZ`OC#Pu33WKWn}<&-&c@(t6ms&+2VmZM9{zWHn`2M@=|> zq1BF8<*g1@N4R~3RnMvqJ&IU0z{1s5f9p2*beDBMXlM-{dcn8btx?tptDki}R7+ZC zpwzVJ^C*a-==Y2PUIW6^7s!6Irs!ytaYC&>dGLcLshbD$4JU8pU2vSPA zCES;tSDm|^yPRRp&EO=oU$w{CH`zDZmoZjYe_1Q6Kdqj2AG?HI$i9#n-pOp9v7WbH zwO(Ld3$4M{Kx>$F3x5Y$!>yaGS&YZ5M|gJwt7^skN?1FiZP9QtK+_U)U;c zoom&Jk7>&>4Xq}u=ytArE1%YeGA&tsL8PPrD{hW7H04#AD;2j&S>>$N(TZpa>-{@g z7wzS`eZbq#V5JJy_hj$MexCg_`*Chs z?pAMzchd72r@bnE4gW{~d%s7}D|j883=4(_s~OjXSBFEw8^aI7_rrDJ#xN0CQPrqM zbZ>NbG%0#N>JfF1u3{EIDm)nO508hZ!Uf>6Q;h$+qHB?eo1($dhGcKA`9a>s#wb>sN5}1vru{IH->< zR#(t+IcTX57W#3<{m4dbYg@D)DLN7L0xd7Xr&?BB>yKzrv@-fDniu^Njpn!s*6Y?5 za62RUb#g)K*Hl-=t*P5n6O-eU6_b^d?Go)0gWW-H(kbX%9rg;Bc+0$_-a%+o%YVmz z-9PG|@*4!Tf(wHV!BfFw!GFQ7piS5+d^mhG92-6r&Vd4B!zaRz!YQEzy}CpfN3TV1 zL_?z?(Jj&KaBCL2;lZeOR3#b|4P$OgqYtA`qNk%LqBo;=qDP~LpkDWALNqQ~%-9lb zkB-9EHb_A$=<+Q{9}_(s-N+aQb?-yZd>4HK4(77<15sD77DX<|ya{~X3XU#-@-3lH z6{`>kYz*r9TLY|a&~S$Jl~oLMZRajlm=GP2r2G0f02d9FQ0fHCQ4;zF7!vQf)MufM9Tf*&OGIFERj1EyJUWH++ z=%T1$REHT4hYRx~-FI^0qr|_d4XG?rvPW-Q?^%W2w7WXBF4ZpG zI(-egCSWyxd+|L+-~jy=NINUz`4Zf;*4=dJ5`*T&a2F_mwk`qX!5(g3YIn44yMSHGu590CkK}g+dm*~=2gYZNSFKm#xeS0eP2tjI@aIA6A?rqK z2%4iWI^_cERFsQ4qbonKK7_wFqZ8}9!qFj=UL5SeUQMDSQq^heTlvs8@Apas&%S;xp6xvp3JCF+t zE-SFIz~c16^s3Z9sm7^#sTY#tlC_gnlJgUb5(nK~ZgclSx3HUZtGTt@mCiD!IX3l> zeZU@q{i$MCvX@!Qu_oVPL${!<-T~Q9V~ti@8?ANL7;H>??2+urAnf2(jKTc96b$^$ z`U--H+GxK2SX~Pwzb~U2(!U={Xf5lbjZuB{VpYZ>-mgYC{)OLh8h@jK)gZP*@;i=3 zhof_>(!45$&v7EEh^3Zn-Gv37XuSqj@8{~xvBr0zfv?7ItIB;Ua^;5HYj;#Js2u#B zU6egHTNjHnHTw#>q?A|2>*8JFy})P-PRa&lg5Ukce&3*PFx{K#Ej_dH%=KpmoN1N0 zF!N*P2kh0T?4!BIa(%qM-gn+Cud-j&f6sr{uN+hjdSk2P(|inyzYb;uK1S%$uv7ST z_$}5b8=ek5bkU};d{i+y79I|FhP%U%Z+c^~a`+9)qCcX^=-pSq%V4zgH_=y7W!5kd z`IDcb*V2o>ql24+w&&0=&B5FzY}o|RSQo@z%=n3M1cZH!FZDgBdM|oA*6){MrCzmP zu@5^(oN?}}?j7z3_shi0L<>o|rKyX-_Y ze9z*%ngAaMbHyIf)!5qyID1{}vlrw$$;w1D#gow^Q9pd_V%b93>bdHHO<6P`?h{tH>At&iL&Q;i=)##OHz;SuIG@k9%c1y-l>#()c+J`SN z6x&tb^VS_PHlckV{p z9zdUNV9bhUpi$prb)#dQdoTBp|1r?I4%;>it9HJ182LHHIEEy7QHXx3!=0b8u1#E% zcr^WZ`rLH=^joR7Qe{)+Qj?P(BxfeRO#to7K9XR#Wmy;I&dnOT{x*>2hL zxzgyVa^6mFyVu_z=s)W}gdrXXwD=ytQg}s>wX{K{RgPiKe~o< zZi{9@vv>J)D&GDCkoG?Gn~8?{2haa?e96fS#gFCCw?UM}7oQ9kAB&#BT5iXt?O^i4HzM-Wp*`CSWOg zCVC`xrFN!fq-Lcir6#7HO1_j_lK3T2Cvk4#C-+BppnIL`;%DW+?kCPvXQ#c*e$IZu ze$sx*u4C7<@3$WYsXfp-x7zpGciCTpRN1@XjA3|nWuZZD_}Rv~2)Z_oz1?HTrw3g+ zSQp23vM3T=9gVKo*+mD;N7C9vt(fb>yqXWKwntTnL%V|SvP4>nLj!QQJo*zFSHKs$ zlyA#hS+1)1Jd4-Rm%Gj*5*+J1@BHnqa_6}V+%Mdzu9dJ8$y6fsCU|`|`Ao7bqkE!f zqKH$#smLt)FxSR-cqf_5yYTV}c=jfK$7_r|(f+6cGdO}Id=2+xrzA_&vF9g{k=5Au zos8XZzbWHK;{V$+w`E#nFUXG1zM8!(*Dd!~Zh7uW?-{SYU)R6ezXxmiHu1{2Sjms^ z#Zuw*cyEYMwjDjRf+b6yTbZWBO;G(@bYRRmD`!&sW^6e1U)x|SWfZF zcyy&?W)VZNh3w>5-v7oZg8r1Ruz={G5nOD*70N*GRUES&EGLNiDlrtR+>J~<7CnVeI0d=*FnSdWo@JCJ zK9=wIDBmh>D$n~%;M^qa(?j@7mocwqjCw@iP59Xz?Ze(zjANsF;;h15)->x=vQ2ZW zS?G-4lS`8w((SO9pQom!rl!^<*Cp2^)+V;OTis%AaddKNG6^rEpU-jc#71ZB41WF% z_63Yv7%yQfN7?t-y&3;m+sI4=RtLVDXDzZOz ziB&FR)(>*z2V_Bp@UCmDg{NAd5G{O(4!wqBFGOdLV0{mRs77eifoRia#JqpTy0;SR z6J3Pk&+(yeW3-18gRqq!p*6OFrPXNdr$FIkc%y)BALuF%t?#$)C2DM8%|L6+g4$d0 zh|7?jQEa)9t1EBy4P3i{tI1!VgJ-@T->3{Wbs+OS43@WZt?fux9q_P?yRAT?28M&e z0lDjP^|SS}cjMnp$$pl-7r&s6cP^3kBJW)PJb#uy!#_!!ePeJ_a9?n5Fgf@rxHxQ& zZv8A=f(P&{V_Z0am~&wGeE1^Pe}7mcDgt(UM0cQZ-)D?No*o0Y3{kc8B?r&er zxWevEmMcyEu9&^g+KXPB8?SsOx^{*&(|U;rjHP%E8^FkBexHkGJj3TYzXI5; zhkSHn)IlHYdYBOByX@c|i#I|o6c-4Kk32d0iQgPjS`U#IFg-`-#-))N846si%`qB^xK3BpW9hCBAdNbAPaYw%Ylv z{dL}YZyUMQj(!J!DRJ%|f2ZFoxGK0ixGPwMZ*Vd=5nK^oNe<}Q@a^!e@JD=t)8xf! zL^Y!eu{qZvFQY)|7-a4(usIXydWG=`V+ms&V+}I71P!?Yxm|^Xo?&F83|J@vM%Ex{ zKNF$Ojdf`ms9b>0%b_u)BTK-O(r`wvBO>LZ#Dh)1Vp%?|$Vig=$Z#$But$*q#l{Vx zv^bW)>JEn~}HKU{DslH1v^uIT>q(EUVkW_uGhk zkD}Xz)Hz&jE_9#I-`OB)11ol*Zs9oBR2z&6 zNHeN4l>e^-4TW{dj(p%VP%q6l!l`n2tnpZ-vHZOfjnIg3E}E?t zGFXN6w?IEAFHnOanbjx_HjhCCtu=#A+s|k6d$XW0!|#KvQ8kSf@S_sgEd@Oe!?S;p z;UO@5^6RDo3dwzaU#ln2Pn23Kh;{+Mb#pFXzX0n;*vrlFBW)G7OeIb|d(%xQ1U%$7% z-QVrEClfr5tofl}A6c^lLG7?ccz1XY+22p`uhxO_GjSeRe)r{3FD&l>{NpKD<0-L? zdY^Z)r}F7%pbdTlVe|OefF9V&I7m$N3!f;@AiFk`v4@dk1jMkXS?_9&o{gQZ0)3k! z?N!ievfUL~x9m_ucvKR(Ry@3iio`nZDBmgt#fn2g<%>EoDl_DB%6F;)nuX^IyeiAt z%9#e7zXho<`JnQgdkz#VKn%SbzLf(7x>I8?T@#vDgagIU3sKaBPh}^rh<%!;tl7?Y z&NLzdKXryI+K^O~^r$$srk*z&?>TZm$CK_wMr4<>o6K)Nr@T{+3|UL(lzjrvY$kb+ zm#|#d+QsdXcGfy&Eu&uZCb7n|pmHP`s_~4ci63vkVqZ(FDL+;7>c;(Lr%r>u!>mHS zbSjp-6f>{KIu)BW2G0$VunX}RyRpJzvAt7WMM&ENcK0!qQvod)4AwJMJ6BPSt{o$+BATs*OS$pM!n}wMi;W+RmpJbpKB-a zHwxH)Tbr!k(KYwr#g69pqv(}UjQ(&=x<&cR^Poq2JYs#{9118#Q@*A(dAb&StDNJ- za7^{J3h0`;a8Nd@C_}ol6W(?!s8^FAc`wB0vSmH-%GP2NUczepK<4n_+>^Ntnbn!$ z)KfQR*JMA-eVM!5>*_W0oB3b(U;0Dw{aTZE=+5xmoI8e5->v5^c9uF%;#<{p>Nu;Y zXYFS^Za;x%)e(f2vQMH}k6Opkrd!DN|A?Re5jypQI4*gcoP_-L!HhomR~5n4`K&iX z{8X~?kf*1WKoV`!{j>^ z1;O$I6rV{Z72}@dY6-BE0fWj($R{oXD)+)e`B^&VFLZ@+W+gdy3!f?u&T?JpA>pR`14(amt8)XS*CzX(@l|6ga!VoYOv%8*wm3056$3-(?9l-_%+KVr2fScmj# zU8uPQT`B!=oKF{kdga%bGIoJ(`DSzZ>sIVi3*YdXb$~4M&+RAO~mbe@y|vw9wG-i8hL*J@AWHe(3gzq#DxpdY^tlQVt!u` z^KZjWD~|aUtEIoP0m=pb1_hNfP#t0;8GzNSs8qb3T~P2Cl-|brO5rtBifMQVt}Fw2 z=YYE+NVa0FQoL@AWD8rxcrBePnx>)TF|KEyq1(h7z9p_ARx;tH+%1#YuGx60pa*yZPP3_j?MLt(i*TJt|JxgBa8 zhgb6Pm2;8*p#BU8y|bI^NH!eKE5qbwb5v|tAH7n7?-g@2=C$;2HD+dW zv}XD%IQX6zVWYprFP$x!-J02)xhs2rwpFf4ZcA=g?g458+q@m*uj&zB{plAD3I*2% z{e!W=3qdY89W)KkC-175U^cPU_uzIDdC9-Rz2Tm)TvQ&kUPG+hALI_iqxyiTN>cwZ zc1j%*lgO)m1ugzYGB+c?^J3km{E>#_QubVuDF0n{{e zoN5N1 zx4;*FEz2GE@%{w)t>T`@Pl!pz3*RJ@uRc>1)$=+D+e* zx+OI`IXhV)Sw8tx;^{;xkw}cC3np}O&Pr!By5I$;n{x%V^+QzFe~v+@ zvou2MU*hARhyx~*pZb}<6G5+f3zUOW{rpbG$p8EMIzGJ{*{R29hs~`KBeXKF+q3R{ zta?8PSPX^tfW;!z5caSFMFBbD1a*nISdEtPI@hB6B**F-lTIwe@4d+RG0v8@j^ILZ z=pqbC4^-i91vtMTG_C9^WKtlOMkv)*CfI43ZUxOYdmH7rW)r)*S$oIuB@0nzML#0R~|UyWhBL{{@N zF#8!ARdIqe=LRsl34AIW=dfDEqQmh=KA<}H17kGfO8auWjdJ!e>yVX!bLwJJ|J*o6 zKlq|LZEwb#bT_=tXSd-i%eRoekc?i67u5oubwRf@g9|nJbP#^Yg}heGR0NEcLL(@r zK%zUww+Cg*fm?O0)x*-s2b3QmSt`eM7a%W+Up5EZg6p!^Wann)XL@COWsByD<(B4_ zATR=N`PtuZUk? zqZWA+KGsF7xvagIyy{HG4C`xa4Y|9?#H`O!MS2bYN_f2=Z%h8$#SG;}q}$}{*G6ah zU{8Hoipv|I!7f0LT?`Fm7cK&~`b_{>?`=|}| zATFI;oM#+mlZq?~}*}-r(Hij1OK39`&B`PEdC( zNZs{IaJrND^@dsAkzF z+25&C-%m|tG8D?tW6%z|D0b_N-A@wiEyBNg5si8;^?()3>~wHE_=KGGBXo!D!9p!! zltb$KlLHt`O!W>H=~c4RvbV}BDdRVZcoB~l<*6yJ_PV-lKR{W8MQ!Z3Gw;{fUdsbep&enIBPW1ViLqB4}&YEb;DKYwpV{)h5T zv0@E$RZFy-a#$UBuUb((q-OyQ&(tsCEiWDE?6lwhSp%?%)s@moK%A^A%^x3pl|lEoi9x_HtxdIz&3-C`U^c z)UzbdUfNx@e>FN~9XM1BP%P$AS$sQXua3vK-N<*!)hb3-?nU>l2=|iETREe;Q29KD za+!(^dN7VNP?d?1>5=KRskNyQ4E0Qh;P%eM$i!ZH(I>iZ(vwiZ-9jJw&GgXNp!O&G zCw!|3WL@8)vuC(n-L6Z0y9QZT%RT^d*W+bPjPq8{Vx8Y6ll2Uq)o8LGy|`;1VuMSW zQ5z&wRgwDOKy}iF%sN4wvp=S1kr-t~_`U(h)j@8BFdyoeOuzE5m7$J$-p)V+bzP_r zYBxjndK>(aUQiBPvDH54A?&4*1o2I=o%D=!uxiliLzW+X6pG4*O77)1OYbU&)&ct@ zS}IPE4cNsl%$bMQ!R;7m36Q!DoP ztD$97NpR4VjX_$~*#4Y@uB^xz;{HYGC;24eoqT`Q#+7ps9@HbEJlrUMls`T5MJAOk zkbOD(QuhAb135qEAcNo z$T&fd?HKX}&Fv<3Gx~!n;!k>(Z|wr38$szu)So9Y?xg;3FJ9ICto|-uJx%v}7f^Z? z8nroIq_8^--?2G5OBvx~*a&4mj=}jfm{d=UJfRavuymk_de4jXa0fKq`ADF0q}msv zjI46AInGcWsv;Ud^(w{shq$8jv^;tJRrX)`0r_U?UX&!%;2QGHq)X(-sRkiW;|OS$ zU$6-bOEW7UlSLODlf)R;t$X4GE zypXF(Oi?>F!QMmfi*1Gx0o zcc&+5DMNipoyqytpx1L0(r^#*{U~0O>Vvn@lQa>3N?Cw~P(t+j9mgJp#&2t>yE7`H^3yJqPl^g-_XWp|)f!gQenHfcz}kxGhjp^_5B-FH5AH{cqey z`Na#tvTETKI8VNU`eRl9lJBKlsrqs2pw|^)sb8ZRcPqj8hq*}Ws&9V}=O|Am9?NqU ze-%&2A5mPQTDJ0S>J{pQz6h<9-5^;rd0qPY^m1}ox1?@Py-4p>v1HNY!-+=|Rf)2m zbf2U1%5ir)d!0wgUtjKAM!)AVGT2M$512+@>7{XvWg$M*Jbq?a(}^43qwLvQ?SKb8sBReTA zEBh73)b_CU|H37Cv>wubFonLq3-Lbouzo-K#FH7*u&I0~$Lo2b4ZpL!sDeI=dZPK#8_RPXdv>5o$%r7mQ2N_J*H+PmZgPPjk0 zv)#UKZ+D}!Ij*@Vwr%UQan`U8?IUs_H&f59ZdW6FRf+uT`Suz7wZG`(nMT)?cEr34 zav#T5Jz+hCkM%4u!p+$0VPJPK5kO~rmP@c$EkLPi#8tu3dAx6p^sA;_8%a#FiV8$9 zeOSwBxUn+Ek-RD8@>GkHKP#D39c(jrQ{HAj@+w=UJZlg6d&4 zvRD1648BKZ;4{#_kiA|f!q#|K=MopF-&(!bS2LbuJjM8i_+Nd3Q^4;O@>t4$F2uu< z4VMq2n6Woq$W!f4=s~!fU7By$UG1KB27dj@j-HRnHGWJ_^3P<+-=g2(H8hWU5aeUM z3J6s$);0=3W#zz0teDdo%MEJ;Ik|@63+OKAd|nSHr9274ZxEFEC_h zR=a<@0}}n%HCZdM+FeFBeUmtTU4nmg6B(>BRI-n-&*N=YJC1JpJE)0vv^&ssRovc; z|NjcBd?fapZfE`%#j&dTXtmcxafo`ME@y~-Z5Wp^6kkejc0m_61-Gi*Y2ToHDq&cC zSgPEaeuxv$KcMGHmc1&73P9{`)>)sU%aNzq$WUj@Hc%*UN?EEDXP1a=ehGB0>VxVY zD$AYfGPjQS`04|bOjP44>cTSiUs>29=#xDhe~Mn*PGH%Bw%Wsb2s>E~scK=>Bo4YF zd0BE`dPsU%YH8|f#&^jdlBJX9B=@@q+?UvW+7}<#_6zu1sSF-q=fF_^M*6W2`_(N0ugqZ>7CwEu(f|v^PJ4u>8;PGY-#a2H2dA zXY~X=!aL~MPm#g(SoC=yb!jY>b9lX+*NT}Gvq-mU-<9&nir|Gi)nesOs{dWOQ+W~T zW$94m{*>pEkD(YzIX>k_Wz!U2iptW%%Inue!xWCGR*3qIx_$qFa!0vF8am4MsprUw zb<~a6TJ_p=hc?H!W+~2>wUhtgFdwaJTE|*c%MfN%3*3gT+la=}9<5r~XJz1(y*kcO zyZBZ){v#YWm!X~**%;NH6l=O5vOThK4ycr$s+@`XkMv&rQC4+JtZ(II?ZMV8<6KkI zR^N7pcR8-8I)QvLReCC+L5^@w^<{`|YoN6DMJYF_JmXTXp*Z0?@|xOHHIlK+US>B+ zHA)Rm4^GcX%}KfReD_cGOCC)er$eB1B29!fknZ-w?CF_J9dU$ntFwcBJ3rVn?BD3W zdcuB)c(N_BU(7B;273#8U)2@x9QcxAZD1E(gfH{!Emh8sTXA(N%3~0(#WP)EVof9J_FI9_yD~P__9y zup?XDf@9S4q@g{Cs%czHT%jH|Nwqm;okLxS^Sna(T!d|c_V`cYc_S2)?DO)>NE4L!IGItj>u1f5w8Rg&Qf6G4m zLe#V;2k*ywZ%dIEXirbeB<$8|YA&n7fB3zGoIo*htv8d|Q9bY#@~!=_SQFXd@H8^= z33Fb-43_ZwPtdZF6`zW||0}Tw!buzG{jU8^oN=5%UF{Ka6snc^mTk`>g4;xHOS$qH zWU&^|fAtoc=QBJm#dX)9W3J`5cG;`nyKJhOZKr4}TJm({FrqjJ?-U@G( zmqx!XXS5C41l@z4!~n0bEyM{O{DwMVefADL7`{$l`zCN2(ve*p@36pmmk=d6PX)Z<tvr)9~SiWUl#(rc?zNYG%$`%v{MOEC$Zxu%iU*bhmC?suC7d@e_<02f>6P~q0%g7&4Wq>3cJzRCUT7ur8-B440t;RO= zwGG$Q2jg?y)!a7`$0O3Qsw}EQ{Bmfgr<5qlmERy=SiXz$5vms`FE^I1l`r4GiR==0%SP7jX ze5)Y(Zm`DxfCvw(5;z=)I9@Fvf6j!M}BpW*) z4F7_Ut)5EdueO6K_3sP6ioYY)q@2nMhF&Yb*CO^2n#6ok|9)-OE856Lp97bYa6o(1 z)MKSS3;7AcxonQ|PqN`@XsR9-=}^U{ifDy><;9d|k=9WzwkTJu1D9&Ttu&u&*FhsF zKb-oGo?oQMyf#<}(GEkfm_J}gZ%PbF3`-BE^U6)%Np0|pG-)O!|<-IXJ1AgdIq!LcAs_7%CdX#Q^rr$Y{t*@ zNIydMV+gitB>h(pkOk-hTDmiXYq317KwUL{n@++ytUx`FdM?g>s3}ZV01N+N&D3|H zNL4lY63|HftMX|TzbdAez1Ckztn{Axf7OGbyn^IJzOnR22rp&ZgmKlNmHSpNwkj!# zy%fvopXwC*I8r^Yig}g0()qi&-xhu}XP@_~fytNFl?!rB?V)K$yxHID=e?F0PfXA_ zJB#sXZcJ`p?jZYJANTtC*V5B6-A@K~&@5=pj*ORrmDIEggf?;Puy7Pl3iz0~w*-Dw zTXz4Bp|@iQeHaOPUbS~wJ%f67fcD)kWc<^RSf4pO=CT+EuR{p`J7GJF}ACCvBn}s`kvPuc9;gOL<$W)y(JYr^&@# zORe-6Ilq?~ekRPU$}WrZex1FGygL55e#@YFaF}Nf3{G56?y72{DSO_=(S6m!y~3U0 zd`*Agl}>f10?(z`LXP!ao-pwwoma!ChBhO1EywPm`b4m$i33(y>lv@%W8F@La0nT? z7x5=QA+G(9=yn`y@5cPvkTq%*N0u#E@pbr^Lu1>mm`XWkVMhIY$`uJ`ZTMEtJJH`k z&`Y`Jqpa}|M|L0rz5;V^xEAjDY+p~LSEiPyKH=FK zwNo`xHzbE8AE(AL!=3K7a9TMp1kVOjyf3^)euH>C;6K2w?6>{q(0w8!WcZABVH>=G z8F&LLdG<~zcDp&a)i!l4?ZFrbMupM=@$5mp{Seu{EadR|w1JhpCNTRCm*R6NK$&oB$=)!ocY zeueTY8m*!Wc!EOx=r26dn=&_N3T0Dd0JdhoVPEj;Ja@q-v)2SSKj2AR>J)yH&Ne-lp$9d^yODD}S3%DbT7s0n0WS2cFnNdH z690eAkNhq53u_;N`WIJX)qi4!dP2}!*tQAeDU>si52KzZ_3iuw_Jm9It*g@VGv{d! z@_URA@zLckY1g5;QuItfQ1O8*rk*|^J12Xt z_v_%XsS6(Fx;tacD;m-MW94nM*Ik}L4R|H~T@H_?68UUrf8Y4TYl(j80qGxjF2f_K z$5JbjE64*>NsddrjFl>s*x;__$yPn-4OkTSwDohYakjHRdK`V1_pz_N4c^sxWB_Vn zsSa3sh_8;21K34G^(}FvcBoII!|N4(o{i;1&kwnY(HNVl9M%n3(QaTzJ<;-G)Ptp+ z!9BrB5r61pXIx$zfHMW`A+JC*$ORX-}P(&#Q~}}im%!iDmq5cQME(GxzbaL z`{WBKhj=M+(3By2+LfB~KyQFIi`ro4>?J%$?Zxb^Jlm$WSJiu&-r-7qIi4an(a-vx zUpuHCJj7G7rc)nm5jLlq-8a0RXNpYYSt5(6vTS5*=gCFo&;<^0fk%(PAmV~g!H9ai zhS7^PCf@b>2p-qtVE0?lcnVyur)S`OP^7%;NwBda&b_MUWbAJaeQ+d}`vV~8WQ?uT ziO0reoLCUg{Cue~7c*@(9%FsT{WaVAb2Se_qdQxew(1OfUQU=?{3e z*78)_)WxZR$*XxT!-m8_>MrZ(dmrTXcQf?1Kj}PyF1VE1U_0kmI@=Y84W?i4BA$(O z5j}&x<-~ngUy=WKgWA$G#z*8ow1;0-0Q@ z3UDaHw+Hw}T3T_D`V3Vs*L7W}uiA?C4Xc-C5%bXVU}XRHafJ4N3HzdbX}GHVgzAQ> zK<4AD)UUc2H9 z!S)z)qL=o?spCRbhW&8#1V^bqKzc(vVO1wrj$OF}$&a$H>M2zpmvZsi{h_{3?K6=7 zr+qvxk;ktS)C(GB>t$DG)@APFi6VQ*9)8EOd@t~tdu!Q8*v;?a|L*_c*9~e1cQQU> zPsVn7;m%_pQD1gtJkGN^-=}K0h?;f|>^5ir+eO3&o!A98kZPfx$MiN9U;D0A%h0a3 zU%-f-;VYTifDW6252l>Go+G5r3*|{vGhD-Wr@-rR)~X%~?Zpx`m8VnAL~^X7m3vlg zPjwUN0AWtOn%b`_e@azc#cAr1QEpKAM)d(G=PRE@c>&ogRbRA!PW>!9VlPj+K>l=& zyQ*trZ=7#YjZu7;j+JiE^N1pP{1R@8j_YULYZ(owUf1Laz^jsLlkX(oNVZFMNdBEz zgJ)1A@h1B+YPq%DQ_gX!g)@2fWgq$mb5ypb#d+rIc(Onbo+?t;ZV+R2CC^a#lbZf~ zGR+^OWnU)_7)kVc6H)BtSasvuD=O$nM&_D0m)8nyD*37oR#i7tZ<+E&ifWZ#tqyIp zhgCID=}Yyb>lpP!iPDNZr62V)3~3S7cvN8#U1bN=FO`2*!*aBbI>AD4E9q8ENBdt< zh|ujMbS;Q(-3PT#a@N84I6ePHey%X7o*>1H&9LEv`~m(W{$u_&e=EX|na7@y)rDknUJp}iQ3!Qy__uNYhV z|FzdwIV?RFR?j-s-ss9uTe~S$_fvm_bZ9NmR1@kdH=<`H=~-Lqv=Gj;A6Wm?7pVQj zirJMV5JpwwQ%+TOPJQgMlgb;2e|o2$8qrN!)btwr@JjYl*&AiaOjccfp?YKW+!I|- zxdM})^w2{^zDIKHdK`76m+2|YTdHt16(_S)FDpa4)y<`uSr&Le9 zB0_zx@0E?#IwgNV16fM($~@Ob`N|yh(!MeIPxANWS1MyFdoEvy#CePr^IQ*APPJn7 zU1^TT(0%Hy(7piWM^DH0Pd$EmEo@2GnNC&d${fe5`mZODnGQD1TsdsndeKIC7R4jN zsd6iN!iF%M)8siuxpC#b<#B7zta94Qv*=UxE@~&8{0a4Z2JtxoYnHUg2Qf5|g)7R8YEAO&G*d+=s#utR!iI9ms-5d7^H*1vUn9?3+}1y>Om~(g7M1m0)fH8-^*n4< z*_0(!#X~dFy!9kE%5B_P^vc(z<FG?aZR$S0zh?x?G(BTKjxhcy$O;c#tfQ)%v8On2cy&ztl3Q4LY?n&NZq4V7+E zd@Npx($YJck93#exW~QZ9R}FFqFi6OUBw(is_DoVZ6qIBm-4>Cv}UdEwPt;){x4Bp z>lT${uf+{{J<4?ICx5=KApIzO=)91l@^=#@l*3ovPgsy-i!OREis(4aM(0by#7A*S zR}+r)x%ek4>OQLQ=o2F)l3H?PSQg1p7p8bt(huDRMe;Y2{+pJEIf%1s#Iw= zjzNs_(2^kO8vQm@c4FJ4D`=*9q!@(j{yN{#OMCycCUH%YqujJ&f9>4TnNDo64eqrb z;hf2FyfjfVo|ot=sT3U~k-D#BMDL|V)B&SwtFEE%CCkdj%Kz0KE$L&;GaF-6yA}1x z3H}()+n9Ur2J#K%0=Bnygu#Ak6tJQZ!_my2Ttb&^ekXW_u;Bdt<%lvWhg%+MM{AMO8D z?Lich6llg;oB6HGwkl|%p6DvcHo8sHYOreKGfR$5y-SFce$ut{ndm1?WHglSVx&{L zz|g>GEX_@42%F~0LWd}z8Hwtmt@tlG>gu9e9--p8P%3I@r@rtljc;_8kZbgouBq=O z#iF@rXEcKLR7*0X=Y&LkBmHgYExHN8MrQS$t|U2>{!$%KF_VrLbwpcTUvg!xFWza^ zy06x&f10s$wWz4I>8jFdLXLa`t=&kbuBJ~V%f_n7@<{5WFEkfn#;izkVlb)SqMNy= z;x$uEaILxt~-d9hQeCE zLA>s7q(CbbH8p45Su@hy&CtwrO}*1AVNS0^>pX|W1!)K)31+7Hou8l9DctLh!h<{$ zV+D--7(N<#(b^2pwKiQv{4?~*`!?c==BfA67&=B4QFOFoxzft=GuBbYL(%NzFBqEZ zs*+df9&uXoElLOhqMGQfPt2#fo+v5pp}8A<&P!&i>x<8lE>+xgUA^OkSPl)s49X05 zv>vTm@AS%85ZyPAcjFxy>Prsu`b76OI5N)&GBRe+qU(uQdZ#NH+8LY+ONM{OF6cYW zK%WZDdM^a(Y^__z3M0anR&4wS;}hsJePXnosHxQpx#F?Wlj4ri9)>Q4B3y{8>W-R~ z=BX=5yX(rb1$lf3PsV=excuxzQT@{@H3L~0V{LS0ty_#Fv+gKw zQxTI;YH+DF2nl&9(@aD|%}iG{dPL~aQRY+L@Jefw1`_Y33q*U(O+3_Hbrr4CtlRuG zdP7$;-|0H~Oz+NW5%W$QF__HXUDpuqg-Xd`p4XbAt|$s=mZE`Zn&3!}zv8d>W7cM* z*-%B@5~7AYa3M@Q6+Vp5B?L;N39E+7c^jWchxGjc9X zBkW6?7;o5MOV`obMQgn_oR-!x+QY0}_s;7J(N}jiXfc$`^UvHbFV#j0^7Pj`&0M_F zUvt0w3JiCRHqpJA3dc*Y3*UyqMpxv2=c%qa8+r&i=DPn&8G{Ed!#~3(bB4ine&+hC zIhebOtKyxZqgi>LHf9wDucG-`{Au>`M8$bykwg!JI?YzAil-6(GE~%^G%x+lV^Dv! zBF(|f$k4;+0fTY#$ywgzuVz+Zt}1kzBQy`gN#V_WEA$#IY_y7@is)|6G14Sl=^MS% zY=m;H*x<(8A-^hJPoEn^8w}+oQcKo#%@KJV7~LaE8@ppxn5VGlV)&u^n0tvznv-aA z7K2)~p`ke^j~CrBPmBDkvwSe~(d=~>-CL^@^>tsPQw$$;JtJX8KNytdWhH-Stp=c%asYu^8Ru9>-3Eq+J`nwjOLE_!o5MV^p32ZDk;X|8=YY&t>g4c)WyX@`d7HQX247lN9x-_>BJRlo zn>+k3UC!b}N96UbB-dO+SIe(of6cW;Efe$04$3mh_Gks7l5D2dY;bD)0ntKNH*%Zj zhM8Y}P5LXo>mIthaAW)s{pBtHL@8ODJk>Q%BWJ?V|LS>zk-XN?nP;zS^pruLUK=iI z{+gfW@V~s*tn+9##~6;A>xrW}{{Nj}{=WJyk2P~to=Uo_p@;dzpv6$wtlnHx=WFF> z=WOnG7R%<<*%=!u>b>Wi(VZ!)o$`dOZkZ+U6xAE5U9Lt}nzq+z$AYVn% zx2_>y#8@A5SIygKLgC8Tg0u3Jryp{L0My%{)X+%|(8eBFVhW84QWe`Pf9<(XnQJ1{LOhI@`#Pp?)6I`kVjU zoSR3A=y4W*c`a|KVYp-HWVBdb7wVh*3N>F@ZDHkqd6?I>`M;uDUPkrmEU%1oN-EEC z!(30)5(hO$;~5yeAPQ?m%A}eY#H?KN&;K*)6x|Ge%pJ9|{E9UL&DlgU#y%L1=JBC- znn6Au$a^MQhvu8t=cfNTFXe`|qF7!Uj0DKDF|*Me&1wz(jkYmVH+0c@bwu837#%EJ zNS-A{d8s$36A$yaGxyaD^RM)c-kbU8KDw`&y=;akWIhw(&svGR*3_rEpOIdpjZJi9 zycDy3;{_RH{IA|o{@ft(tTYNe;#MA)Mp}(sHX2&|Iy>vLYssG_-Yc$E=1sayH5=(E yLnEW-4c-hA^7j%AL<@01>(&fRd}HLm=m4!)D=}9vv^5CQ`Q{j5!&s_>^?v|noNJi? literal 0 HcmV?d00001 From 042afa4d901106dede37920ae31975e32a684df2 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 12:43:25 +0530 Subject: [PATCH 08/61] Organized code --- stardew-access/Patches/GameMenuPatches.cs | 285 +++++++++++----------- 1 file changed, 148 insertions(+), 137 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index ead5f39..655d51b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -1196,150 +1196,161 @@ namespace stardew_access.Patches internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) { - #region Narrate hovered item for (int i = 0; i < inventory.Count; i++) { - if (inventory[i].containsPoint(x, y)) + if (!inventory[i].containsPoint(x, y)) continue; + + if ((i + 1) > actualInventory.Count || actualInventory[i] == null) { - string toSpeak = ""; - if ((i + 1) <= actualInventory.Count) - { - if (actualInventory[i] != null) - { - string name = actualInventory[i].DisplayName; - int stack = actualInventory[i].Stack; - string quality = ""; - string healthNStamine = ""; - string buffs = ""; - string description = ""; - string price = ""; - string requirements = ""; - - #region Add quality of item - if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Quality > 0) - { - int qualityIndex = ((StardewValley.Object)actualInventory[i]).Quality; - if (qualityIndex == 1) - { - quality = "Silver quality"; - } - else if (qualityIndex == 2 || qualityIndex == 3) - { - quality = "Gold quality"; - } - else if (qualityIndex >= 4) - { - quality = "Iridium quality"; - } - } - #endregion - - if (giveExtraDetails) - { - description = actualInventory[i].getDescription(); - #region Add health & stamina provided by the item - if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Edibility != -300) - { - int stamina_recovery = ((StardewValley.Object)actualInventory[i]).staminaRecoveredOnConsumption(); - healthNStamine += $"{stamina_recovery} Energy"; - if (stamina_recovery >= 0) - { - int health_recovery = ((StardewValley.Object)actualInventory[i]).healthRecoveredOnConsumption(); - healthNStamine += $"\n\t{health_recovery} Health"; - } - } - #endregion - - #region Add buff items (effects like +1 walking speed) - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = actualInventory[i] != null && actualInventory[i] is StardewValley.Object && (int)((StardewValley.Object)actualInventory[i]).Edibility != -300; - string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)actualInventory[i]).ParentSheetIndex].Split('/').Length > 7) ? actualInventory[i].ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)actualInventory[i]).ParentSheetIndex].Split('/')[7].Split(' ')) : null; - if (buffIconsToDisplay != null) - { - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - buffs += $"{buffName}\n"; - } - catch (Exception) { } - } - } - #endregion - } - - #region Narrate hovered required ingredients - if (extraItemToShowIndex != -1) - { - string itemName = Game1.objectInformation[extraItemToShowIndex].Split('/')[0]; - - if (extraItemToShowAmount != -1) - requirements = $"Required: {extraItemToShowAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - if (hoverPrice != -1) - { - price = $"Sell Price: {hoverPrice} g"; - } - - if (!inventoryMenu.highlightMethod(actualInventory[i])) - { - name = $"{name} not usable here"; - - if (prevSlotIndex != i) - { - prevSlotIndex = i; - Game1.playSound("invalid-selection"); - } - } - - if (giveExtraDetails) - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - } - else - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; - } - } - else - { - // For empty slot - toSpeak = "Empty Slot"; - } - } - else - { - // For empty slot - toSpeak = "Empty Slot"; - } - - if (hoveredItemQueryKey != $"{toSpeak}:{i}") - { - hoveredItemQueryKey = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } + // For empty slot + checkAndSpeak("Empty Slot", i); + prevSlotIndex = i; return true; } + + string toSpeak = ""; + string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; + int stack = actualInventory[i].Stack; + string quality = getQualityFromItem(actualInventory[i]); + string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); + string buffs = getBuffsFromItem(actualInventory[i]); + string description = actualInventory[i].getDescription(); + string price = getPrice(hoverPrice); + string requirements = getExtraItemInfo(extraItemToShowIndex, extraItemToShowAmount); + + if (giveExtraDetails) + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + } + else + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; + } + + + checkAndSpeak(toSpeak, i); + prevSlotIndex = i; + return true; } - #endregion + + // If no slot is hovered return false; } + + private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) + { + if (hoveredItemQueryKey == $"{toSpeak}:{hoveredInventoryIndex}") return; + + hoveredItemQueryKey = $"{toSpeak}:{hoveredInventoryIndex}"; + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static String getQualityFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Quality <= 0) + return ""; + + int qualityIndex = ((StardewValley.Object)item).Quality; + if (qualityIndex == 1) + { + return "Silver quality"; + } + else if (qualityIndex == 2 || qualityIndex == 3) + { + return "Gold quality"; + } + else if (qualityIndex >= 4) + { + return "Iridium quality"; + } + + return ""; + } + + private static String getHealthNStaminaFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Edibility == -300) + return ""; + + String toReturn = ""; + int stamina_recovery = ((StardewValley.Object)item).staminaRecoveredOnConsumption(); + toReturn += $"{stamina_recovery} Energy"; + + if (stamina_recovery < 0) return toReturn; + + int health_recovery = ((StardewValley.Object)item).healthRecoveredOnConsumption(); + toReturn += $"\n\t{health_recovery} Health"; + + return toReturn; + } + + private static String getBuffsFromItem(Item item) + { + if (item == null) return ""; + if (item is not StardewValley.Object) return ""; + if (((StardewValley.Object)item) == null) return ""; + + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = (int)((StardewValley.Object)item).Edibility != -300; + string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/').Length > 7) + ? item.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay == null) + return ""; + + String toReturn = ""; + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + toReturn += $"{buffName}\n"; + } + catch (Exception) { } + } + return toReturn; + } + + private static String getExtraItemInfo(int itemIndex, int itemAmount) + { + if (itemIndex == -1) return ""; + + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + return $"Required: {itemAmount} {itemName}"; + else + return $"Required: {itemName}"; + } + + private static String getPrice(int price) + { + if (price == -1) return ""; + + return $"Sell Price: {price} g"; + } + + private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) + { + if (isHighlighted) return ""; + + if (prevSlotIndex != hoveredInventoryIndex) + Game1.playSound("invalid-selection"); + + return " not usable here"; + } } } From 80637af4711f6e13604062b538ec9746b63e8138 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 12:59:55 +0530 Subject: [PATCH 09/61] Moved narrateHoveredItemInInventory to separate class --- stardew-access/Patches/DonationMenuPatches.cs | 52 +++--- stardew-access/Patches/GameMenuPatches.cs | 172 +----------------- stardew-access/Patches/InventoryUtils.cs | 171 +++++++++++++++++ stardew-access/Patches/MenuPatches.cs | 5 +- 4 files changed, 206 insertions(+), 194 deletions(-) create mode 100644 stardew-access/Patches/InventoryUtils.cs diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs index f4969ca..a49be83 100644 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ b/stardew-access/Patches/DonationMenuPatches.cs @@ -303,31 +303,33 @@ namespace stardew_access.Patches } else { - for (int i = 0; i < __instance.inventory.inventory.Count; i++) - { - if (!__instance.inventory.inventory[i].containsPoint(x, y)) - continue; - - if (__instance.inventory.actualInventory[i] == null) - toSpeak = "Empty slot"; - else - { - toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; - - if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) - { - toSpeak = $"{toSpeak} not usable here"; - } - } - - if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") - { - fieldOfficeMenuQuery = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) return; - } + // for (int i = 0; i < __instance.inventory.inventory.Count; i++) + // { + // if (!__instance.inventory.inventory[i].containsPoint(x, y)) + // continue; + // + // if (__instance.inventory.actualInventory[i] == null) + // toSpeak = "Empty slot"; + // else + // { + // toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; + // + // if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) + // { + // toSpeak = $"{toSpeak} not usable here"; + // } + // } + // + // if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") + // { + // fieldOfficeMenuQuery = $"{toSpeak}:{i}"; + // MainClass.ScreenReader.Say(toSpeak, true); + // } + // + // return; + // } for (int i = 0; i < __instance.pieceHolders.Count; i++) { @@ -414,4 +416,4 @@ namespace stardew_access.Patches #endregion } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 655d51b..a3018a8 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -20,7 +20,6 @@ namespace stardew_access.Patches internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; - internal static int prevSlotIndex = -999; internal static void CollectionsPagePatch(CollectionsPage __instance) { @@ -241,7 +240,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) { shopMenuQueryKey = ""; return; @@ -396,7 +395,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) geodeMenuQueryKey = ""; #endregion } @@ -573,14 +572,14 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { gameMenuQueryKey = ""; itemGrabMenuQueryKey = ""; return; } - if (narrateHoveredItemInInventory(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) { gameMenuQueryKey = ""; itemGrabMenuQueryKey = ""; @@ -855,7 +854,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) { gameMenuQueryKey = ""; craftingPageQueryKey = ""; @@ -1066,7 +1065,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { gameMenuQueryKey = ""; inventoryPageQueryKey = ""; @@ -1193,164 +1192,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) - { - for (int i = 0; i < inventory.Count; i++) - { - if (!inventory[i].containsPoint(x, y)) continue; - - if ((i + 1) > actualInventory.Count || actualInventory[i] == null) - { - // For empty slot - checkAndSpeak("Empty Slot", i); - prevSlotIndex = i; - return true; - } - - string toSpeak = ""; - string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; - int stack = actualInventory[i].Stack; - string quality = getQualityFromItem(actualInventory[i]); - string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); - string buffs = getBuffsFromItem(actualInventory[i]); - string description = actualInventory[i].getDescription(); - string price = getPrice(hoverPrice); - string requirements = getExtraItemInfo(extraItemToShowIndex, extraItemToShowAmount); - - if (giveExtraDetails) - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; - } - else - { - if (stack > 1) - toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; - else - toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; - } - - - checkAndSpeak(toSpeak, i); - prevSlotIndex = i; - return true; - } - - // If no slot is hovered - return false; - } - - private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) - { - if (hoveredItemQueryKey == $"{toSpeak}:{hoveredInventoryIndex}") return; - - hoveredItemQueryKey = $"{toSpeak}:{hoveredInventoryIndex}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - - private static String getQualityFromItem(Item item) - { - if (item is not StardewValley.Object || ((StardewValley.Object)item).Quality <= 0) - return ""; - - int qualityIndex = ((StardewValley.Object)item).Quality; - if (qualityIndex == 1) - { - return "Silver quality"; - } - else if (qualityIndex == 2 || qualityIndex == 3) - { - return "Gold quality"; - } - else if (qualityIndex >= 4) - { - return "Iridium quality"; - } - - return ""; - } - - private static String getHealthNStaminaFromItem(Item item) - { - if (item is not StardewValley.Object || ((StardewValley.Object)item).Edibility == -300) - return ""; - - String toReturn = ""; - int stamina_recovery = ((StardewValley.Object)item).staminaRecoveredOnConsumption(); - toReturn += $"{stamina_recovery} Energy"; - - if (stamina_recovery < 0) return toReturn; - - int health_recovery = ((StardewValley.Object)item).healthRecoveredOnConsumption(); - toReturn += $"\n\t{health_recovery} Health"; - - return toReturn; - } - - private static String getBuffsFromItem(Item item) - { - if (item == null) return ""; - if (item is not StardewValley.Object) return ""; - if (((StardewValley.Object)item) == null) return ""; - - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = (int)((StardewValley.Object)item).Edibility != -300; - string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/').Length > 7) - ? item.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/')[7].Split(' ')) - : null; - - if (buffIconsToDisplay == null) - return ""; - - String toReturn = ""; - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - toReturn += $"{buffName}\n"; - } - catch (Exception) { } - } - return toReturn; - } - - private static String getExtraItemInfo(int itemIndex, int itemAmount) - { - if (itemIndex == -1) return ""; - - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - return $"Required: {itemAmount} {itemName}"; - else - return $"Required: {itemName}"; - } - - private static String getPrice(int price) - { - if (price == -1) return ""; - - return $"Sell Price: {price} g"; - } - - private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) - { - if (isHighlighted) return ""; - - if (prevSlotIndex != hoveredInventoryIndex) - Game1.playSound("invalid-selection"); - - return " not usable here"; - } } } diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs new file mode 100644 index 0000000..3362e4c --- /dev/null +++ b/stardew-access/Patches/InventoryUtils.cs @@ -0,0 +1,171 @@ + +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class InventoryUtils + { + internal static string hoveredItemQueryKey = ""; + internal static int prevSlotIndex = -999; + + internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) + { + for (int i = 0; i < inventory.Count; i++) + { + if (!inventory[i].containsPoint(x, y)) continue; + + if ((i + 1) > actualInventory.Count || actualInventory[i] == null) + { + // For empty slot + checkAndSpeak("Empty Slot", i); + prevSlotIndex = i; + return true; + } + + string toSpeak = ""; + string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; + int stack = actualInventory[i].Stack; + string quality = getQualityFromItem(actualInventory[i]); + string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); + string buffs = getBuffsFromItem(actualInventory[i]); + string description = actualInventory[i].getDescription(); + string price = getPrice(hoverPrice); + string requirements = getExtraItemInfo(extraItemToShowIndex, extraItemToShowAmount); + + if (giveExtraDetails) + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}, \n{description}, \n{healthNStamine}, \n{buffs}"; + } + else + { + if (stack > 1) + toSpeak = $"{stack} {name} {quality}, \n{requirements}, \n{price}"; + else + toSpeak = $"{name} {quality}, \n{requirements}, \n{price}"; + } + + + checkAndSpeak(toSpeak, i); + prevSlotIndex = i; + return true; + } + + // If no slot is hovered + return false; + } + + private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) + { + if (hoveredItemQueryKey == $"{toSpeak}:{hoveredInventoryIndex}") return; + + hoveredItemQueryKey = $"{toSpeak}:{hoveredInventoryIndex}"; + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static String getQualityFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Quality <= 0) + return ""; + + int qualityIndex = ((StardewValley.Object)item).Quality; + if (qualityIndex == 1) + { + return "Silver quality"; + } + else if (qualityIndex == 2 || qualityIndex == 3) + { + return "Gold quality"; + } + else if (qualityIndex >= 4) + { + return "Iridium quality"; + } + + return ""; + } + + private static String getHealthNStaminaFromItem(Item item) + { + if (item is not StardewValley.Object || ((StardewValley.Object)item).Edibility == -300) + return ""; + + String toReturn = ""; + int stamina_recovery = ((StardewValley.Object)item).staminaRecoveredOnConsumption(); + toReturn += $"{stamina_recovery} Energy"; + + if (stamina_recovery < 0) return toReturn; + + int health_recovery = ((StardewValley.Object)item).healthRecoveredOnConsumption(); + toReturn += $"\n\t{health_recovery} Health"; + + return toReturn; + } + + private static String getBuffsFromItem(Item item) + { + if (item == null) return ""; + if (item is not StardewValley.Object) return ""; + if (((StardewValley.Object)item) == null) return ""; + + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = (int)((StardewValley.Object)item).Edibility != -300; + string[]? buffIconsToDisplay = (edibleItem && Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/').Length > 7) + ? item.ModifyItemBuffs(Game1.objectInformation[((StardewValley.Object)item).ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay == null) + return ""; + + String toReturn = ""; + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + toReturn += $"{buffName}\n"; + } + catch (Exception) { } + } + return toReturn; + } + + private static String getExtraItemInfo(int itemIndex, int itemAmount) + { + if (itemIndex == -1) return ""; + + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + return $"Required: {itemAmount} {itemName}"; + else + return $"Required: {itemName}"; + } + + private static String getPrice(int price) + { + if (price == -1) return ""; + + return $"Sell Price: {price} g"; + } + + private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) + { + if (isHighlighted) return ""; + + if (prevSlotIndex != hoveredInventoryIndex) + Game1.playSound("invalid-selection"); + + return " not usable here"; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index ca05742..739f83e 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -148,7 +148,6 @@ namespace stardew_access.Patches if (prevSlotIndex != i) { prevSlotIndex = i; - MainClass.DebugLog("here"); Game1.playSound("invalid-selection"); } } @@ -322,7 +321,6 @@ namespace stardew_access.Patches if (prevSlotIndex != i) { prevSlotIndex = i; - MainClass.DebugLog("here"); Game1.playSound("invalid-selection"); } } @@ -803,7 +801,8 @@ namespace stardew_access.Patches pondQueryMenuQuery = " "; } - GameMenuPatches.hoveredItemQueryKey = ""; + InventoryUtils.hoveredItemQueryKey = ""; + InventoryUtils.prevSlotIndex = -999; } #endregion From 2d061e220b0f52ea85803efadef13bd729661358 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 13:34:03 +0530 Subject: [PATCH 10/61] Organized code --- stardew-access/Patches/DonationMenuPatches.cs | 99 +------------------ stardew-access/Patches/GameMenuPatches.cs | 12 +-- stardew-access/Patches/InventoryUtils.cs | 41 +++++++- stardew-access/Patches/MenuPatches.cs | 98 +++++++----------- 4 files changed, 81 insertions(+), 169 deletions(-) diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs index a49be83..fd83808 100644 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ b/stardew-access/Patches/DonationMenuPatches.cs @@ -79,7 +79,8 @@ namespace stardew_access.Patches else { // Player Inventory - int i = narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y); + int i = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, + handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); if (i != -9999) { bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For donating hovered item @@ -148,74 +149,7 @@ namespace stardew_access.Patches } } - // Returns the index of the hovered item or -9999 - internal static int narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y) - { - #region Narrate hovered item - for (int i = 0; i < inventory.Count; i++) - { - if (inventory[i].containsPoint(x, y)) - { - string toSpeak = ""; - if ((i + 1) <= actualInventory.Count) - { - if (actualInventory[i] != null) - { - string name = actualInventory[i].DisplayName; - int stack = actualInventory[i].Stack; - string quality = ""; - - #region Add quality of item - if (actualInventory[i] is StardewValley.Object && ((StardewValley.Object)actualInventory[i]).Quality > 0) - { - int qualityIndex = ((StardewValley.Object)actualInventory[i]).Quality; - if (qualityIndex == 1) - { - quality = "Silver quality"; - } - else if (qualityIndex == 2 || qualityIndex == 3) - { - quality = "Gold quality"; - } - else if (qualityIndex >= 4) - { - quality = "Iridium quality"; - } - } - #endregion - - if (inventoryMenu.highlightMethod(inventoryMenu.actualInventory[i])) - name = $"Donatable {name}"; - - if (stack > 1) - toSpeak = $"{stack} {name} {quality}"; - else - toSpeak = $"{name} {quality}"; - } - else - { - // For empty slot - toSpeak = "Empty Slot"; - } - } - else - { - // For empty slot - toSpeak = "Empty Slot"; - } - - if (museumQueryKey != $"{toSpeak}:{i}") - { - museumQueryKey = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - return i; - } - } - #endregion - return -9999; - } - + #region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395 internal static void globalChatInfoMessage(string messageKey, params string[] args) { @@ -303,33 +237,8 @@ namespace stardew_access.Patches } else { - if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) return; - // for (int i = 0; i < __instance.inventory.inventory.Count; i++) - // { - // if (!__instance.inventory.inventory[i].containsPoint(x, y)) - // continue; - // - // if (__instance.inventory.actualInventory[i] == null) - // toSpeak = "Empty slot"; - // else - // { - // toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; - // - // if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) - // { - // toSpeak = $"{toSpeak} not usable here"; - // } - // } - // - // if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") - // { - // fieldOfficeMenuQuery = $"{toSpeak}:{i}"; - // MainClass.ScreenReader.Say(toSpeak, true); - // } - // - // return; - // } for (int i = 0; i < __instance.pieceHolders.Count; i++) { diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index a3018a8..f5d0ea2 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -240,7 +240,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) { shopMenuQueryKey = ""; return; @@ -395,7 +395,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) geodeMenuQueryKey = ""; #endregion } @@ -572,14 +572,14 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { gameMenuQueryKey = ""; itemGrabMenuQueryKey = ""; return; } - if (InventoryUtils.narrateHoveredItemInInventory(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) { gameMenuQueryKey = ""; itemGrabMenuQueryKey = ""; @@ -854,7 +854,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) { gameMenuQueryKey = ""; craftingPageQueryKey = ""; @@ -1065,7 +1065,7 @@ namespace stardew_access.Patches #endregion #region Narrate hovered item - if (InventoryUtils.narrateHoveredItemInInventory(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { gameMenuQueryKey = ""; inventoryPageQueryKey = ""; diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs index 3362e4c..e4d0089 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Patches/InventoryUtils.cs @@ -9,7 +9,20 @@ namespace stardew_access.Patches internal static string hoveredItemQueryKey = ""; internal static int prevSlotIndex = -999; - internal static bool narrateHoveredItemInInventory(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1) + internal static bool narrateHoveredSlot(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, + bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, + bool handleHighlightedItem = false, String highlightedItemPrefix = "", String highlightedItemSuffix = "") + { + if (narrateHoveredSlotAndReturnIndex(inventoryMenu, inventory, actualInventory, x, y, + giveExtraDetails = false, hoverPrice = -1, extraItemToShowIndex = -1, extraItemToShowAmount = -1, + handleHighlightedItem = false, highlightedItemPrefix = "", highlightedItemSuffix = "") == -999) + return false; + + return true; + } + internal static int narrateHoveredSlotAndReturnIndex(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, + bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, + bool handleHighlightedItem = false, String highlightedItemPrefix = "", String highlightedItemSuffix = "") { for (int i = 0; i < inventory.Count; i++) { @@ -20,11 +33,15 @@ namespace stardew_access.Patches // For empty slot checkAndSpeak("Empty Slot", i); prevSlotIndex = i; - return true; + return i; } string toSpeak = ""; - string name = $"{actualInventory[i].DisplayName}{handleUnHighlightedItem(inventoryMenu.highlightMethod(actualInventory[i]), i)}"; + bool isHighlighted = inventoryMenu.highlightMethod(actualInventory[i]); + + string namePrefix = handleHighlightedItemPrefix(isHighlighted, highlightedItemPrefix); + string nameSuffix = $"{handleHighlightedItemSuffix(isHighlighted, highlightedItemSuffix)}{handleUnHighlightedItem(isHighlighted, i)}"; + string name = $"{namePrefix}{actualInventory[i].DisplayName}{nameSuffix}"; int stack = actualInventory[i].Stack; string quality = getQualityFromItem(actualInventory[i]); string healthNStamine = getHealthNStaminaFromItem(actualInventory[i]); @@ -51,11 +68,11 @@ namespace stardew_access.Patches checkAndSpeak(toSpeak, i); prevSlotIndex = i; - return true; + return i; } // If no slot is hovered - return false; + return -999; } private static void checkAndSpeak(String toSpeak, int hoveredInventoryIndex) @@ -158,6 +175,20 @@ namespace stardew_access.Patches return $"Sell Price: {price} g"; } + private static String handleHighlightedItemPrefix(bool isHighlighted, String prefix) + { + if (!isHighlighted) return ""; + + return prefix; + } + + private static String handleHighlightedItemSuffix(bool isHighlighted, String suffix) + { + if (!isHighlighted) return ""; + + return suffix; + } + private static String handleUnHighlightedItem(bool isHighlighted, int hoveredInventoryIndex) { if (isHighlighted) return ""; diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 739f83e..ff1535d 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -129,37 +129,40 @@ namespace stardew_access.Patches } else { - for (int i = 0; i < __instance.inventory.inventory.Count; i++) - { - if (!__instance.inventory.inventory[i].containsPoint(x, y)) - continue; - - if (__instance.inventory.actualInventory[i] == null) - toSpeak = "Empty slot"; - else - { - toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; - - if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) - { - toSpeak = $"{toSpeak} not usable here"; - } - - if (prevSlotIndex != i) - { - prevSlotIndex = i; - Game1.playSound("invalid-selection"); - } - } - - if (forgeMenuQuery != $"{toSpeak}:{i}") - { - forgeMenuQuery = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) return; - } + + // for (int i = 0; i < __instance.inventory.inventory.Count; i++) + // { + // if (!__instance.inventory.inventory[i].containsPoint(x, y)) + // continue; + // + // if (__instance.inventory.actualInventory[i] == null) + // toSpeak = "Empty slot"; + // else + // { + // toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; + // + // if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) + // { + // toSpeak = $"{toSpeak} not usable here"; + // } + // + // if (prevSlotIndex != i) + // { + // prevSlotIndex = i; + // Game1.playSound("invalid-selection"); + // } + // } + // + // if (forgeMenuQuery != $"{toSpeak}:{i}") + // { + // forgeMenuQuery = $"{toSpeak}:{i}"; + // MainClass.ScreenReader.Say(toSpeak, true); + // } + // + // return; + // } } @@ -300,40 +303,9 @@ namespace stardew_access.Patches if (Game1.player.pantsItem.Value != null) toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; } - else - { - for (int i = 0; i < __instance.inventory.inventory.Count; i++) - { - if (!__instance.inventory.inventory[i].containsPoint(x, y)) - continue; - if (__instance.inventory.actualInventory[i] == null) - toSpeak = "Empty slot"; - else - { - toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; - - if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) - { - toSpeak = $"{toSpeak} not usable here"; - } - - if (prevSlotIndex != i) - { - prevSlotIndex = i; - Game1.playSound("invalid-selection"); - } - } - - if (tailoringMenuQuery != $"{toSpeak}:{i}") - { - tailoringMenuQuery = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - - return; - } - } + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; if (tailoringMenuQuery != toSpeak) From b8f77384b22671811eba990e19541feecd46bfe3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 13:46:06 +0530 Subject: [PATCH 11/61] Added config to disable inventory verbosity If set to true, disables speaking of 'not usable here' and 'donatable' in inventories --- stardew-access/ModConfig.cs | 3 ++- stardew-access/Patches/DonationMenuPatches.cs | 2 +- stardew-access/Patches/InventoryUtils.cs | 4 ++++ 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/stardew-access/ModConfig.cs b/stardew-access/ModConfig.cs index d8530fd..3516999 100644 --- a/stardew-access/ModConfig.cs +++ b/stardew-access/ModConfig.cs @@ -85,9 +85,10 @@ namespace stardew_access public Boolean Warning { get; set; } = true; // Toggles the warnings feature public Boolean TTS { get; set; } = true; // Toggles the screen reader/tts. public Boolean TrackDroppedItems {get; set;} = true; // Toggles detecting the dropped items. + public Boolean DisableInventoryVerbosity {get; set;} = false; // If enabled, does not speaks 'not usable here' and 'donatable' in inventories #endregion // TODO Add the exclusion and focus list too // public String ExclusionList { get; set; } = "test"; } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs index fd83808..ffffa2f 100644 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ b/stardew-access/Patches/DonationMenuPatches.cs @@ -264,7 +264,7 @@ namespace stardew_access.Patches else toSpeak = $"Slot {i + 1} finished: {__instance.pieceHolders[i].item.DisplayName}"; - if (__instance.heldItem != null && __instance.pieceHolders[i].item == null) + if (!MainClass.Config.DisableInventoryVerbosity && __instance.heldItem != null && __instance.pieceHolders[i].item == null) { int highlight = getPieceIndexForDonationItem(__instance.heldItem.ParentSheetIndex); if (highlight != -1 && highlight == i) diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs index e4d0089..5903f92 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Patches/InventoryUtils.cs @@ -20,6 +20,7 @@ namespace stardew_access.Patches return true; } + internal static int narrateHoveredSlotAndReturnIndex(InventoryMenu inventoryMenu, List inventory, IList actualInventory, int x, int y, bool giveExtraDetails = false, int hoverPrice = -1, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, bool handleHighlightedItem = false, String highlightedItemPrefix = "", String highlightedItemSuffix = "") @@ -177,6 +178,7 @@ namespace stardew_access.Patches private static String handleHighlightedItemPrefix(bool isHighlighted, String prefix) { + if (MainClass.Config.DisableInventoryVerbosity) return ""; if (!isHighlighted) return ""; return prefix; @@ -184,6 +186,7 @@ namespace stardew_access.Patches private static String handleHighlightedItemSuffix(bool isHighlighted, String suffix) { + if (MainClass.Config.DisableInventoryVerbosity) return ""; if (!isHighlighted) return ""; return suffix; @@ -196,6 +199,7 @@ namespace stardew_access.Patches if (prevSlotIndex != hoveredInventoryIndex) Game1.playSound("invalid-selection"); + if (MainClass.Config.DisableInventoryVerbosity) return ""; return " not usable here"; } } From 0a244649ee640d58840e2ccc8a8d5c343de26068 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Mon, 20 Feb 2023 13:54:39 +0530 Subject: [PATCH 12/61] Removed unnecessary comment --- stardew-access/Patches/MenuPatches.cs | 39 ++------------------------- 1 file changed, 2 insertions(+), 37 deletions(-) diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index ff1535d..e33a237 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -127,44 +127,9 @@ namespace stardew_access.Patches if (Game1.player.rightRing.Value != null) toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; } - else - { - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - // for (int i = 0; i < __instance.inventory.inventory.Count; i++) - // { - // if (!__instance.inventory.inventory[i].containsPoint(x, y)) - // continue; - // - // if (__instance.inventory.actualInventory[i] == null) - // toSpeak = "Empty slot"; - // else - // { - // toSpeak = $"{__instance.inventory.actualInventory[i].Stack} {__instance.inventory.actualInventory[i].DisplayName}"; - // - // if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[i])) - // { - // toSpeak = $"{toSpeak} not usable here"; - // } - // - // if (prevSlotIndex != i) - // { - // prevSlotIndex = i; - // Game1.playSound("invalid-selection"); - // } - // } - // - // if (forgeMenuQuery != $"{toSpeak}:{i}") - // { - // forgeMenuQuery = $"{toSpeak}:{i}"; - // MainClass.ScreenReader.Say(toSpeak, true); - // } - // - // return; - // } - } + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; if (forgeMenuQuery != toSpeak) { From 5296c4cabe0f813ae605f485a3755d454e1f4f39 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 21 Feb 2023 21:28:38 +0530 Subject: [PATCH 13/61] Added patch to disable left mouse sim key when a tex box is active Also speak the content of the text box when active --- stardew-access/HarmonyPatches.cs | 5 ++ stardew-access/ModEntry.cs | 6 +- .../Patches/BuildingNAnimalMenuPatches.cs | 77 ++++++++----------- stardew-access/Patches/TextBoxPatch.cs | 40 ++++++++++ 4 files changed, 82 insertions(+), 46 deletions(-) create mode 100644 stardew-access/Patches/TextBoxPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index dcdc7bd..692ce38 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -285,6 +285,11 @@ namespace stardew_access original: AccessTools.Method(typeof(InstanceGame), nameof(InstanceGame.Exit)), prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ExitEventPatch)) ); + + harmony.Patch( + original: AccessTools.Method(typeof(TextBox), nameof(TextBox.Draw)), + prefix: new HarmonyMethod(typeof(TextBoxPatch), nameof(TextBoxPatch.DrawPatch)) + ); } } } diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 7049d76..3233e58 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -29,6 +29,8 @@ namespace stardew_access internal static ModConfig Config { get => config; set => config = value; } public static IModHelper? ModHelper { get => modHelper; } + public static bool isAnyTextBoxActive = false; + public static StaticTiles STiles { get @@ -226,7 +228,7 @@ namespace stardew_access } // Alternate Keybinds - if (!isCustomizingCharacter && Game1.activeClickableMenu is not AnimalQueryMenu && Config.LeftClickAlternateKey.JustPressed()) // Excluding the character creation menu + if (!isCustomizingCharacter && !isAnyTextBoxActive && Config.LeftClickAlternateKey.JustPressed()) // Excluding the character creation menu { Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } @@ -377,4 +379,4 @@ namespace stardew_access monitor.Log(message, LogLevel.Debug); } } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs index 910e45b..d52e981 100644 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -27,65 +27,54 @@ namespace stardew_access.Patches { try { + if (MainClass.isAnyTextBoxActive) return; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details - bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box string toSpeak = " ", details = " "; isOnFarm = ___movingAnimal; animalQueryMenu = __instance; animalBeingPurchasedOrMoved = ___animal; - if (___textBox.Selected) + if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) { - toSpeak = ___textBox.Text; - - if (isEscPressed) + string name = ___animal.displayName; + string type = ___animal.displayType; + int age = (___animal.GetDaysOwned() + 1) / 28 + 1; + string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); + string parent = ""; + if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) { - ___textBox.Selected = false; + ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); } - } - else - { - if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) + if (___parentName != null) { - string name = ___animal.displayName; - string type = ___animal.displayType; - int age = (___animal.GetDaysOwned() + 1) / 28 + 1; - string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); - string parent = ""; - if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) - { - ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); - } - if (___parentName != null) - { - parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); - } - - details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; - animalQueryMenuQuery = " "; - - isNarratingAnimalInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); + parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); } - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "OK button"; - else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) - toSpeak = $"Sell for {___animal.getSellPrice()}g button"; - else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm selling animal"; - else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel selling animal"; - else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) - toSpeak = "Change home building button"; - else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) - toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = "Animal name text box"; + details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; + animalQueryMenuQuery = " "; + + isNarratingAnimalInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); } + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "OK button"; + else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) + toSpeak = $"Sell for {___animal.getSellPrice()}g button"; + else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm selling animal"; + else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel selling animal"; + else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) + toSpeak = "Change home building button"; + else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) + toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = "Animal name text box"; + if (animalQueryMenuQuery != toSpeak) { animalQueryMenuQuery = toSpeak; @@ -711,4 +700,4 @@ namespace stardew_access.Patches return; } } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/TextBoxPatch.cs b/stardew-access/Patches/TextBoxPatch.cs new file mode 100644 index 0000000..f940193 --- /dev/null +++ b/stardew-access/Patches/TextBoxPatch.cs @@ -0,0 +1,40 @@ +namespace stardew_access.Patches +{ + internal class TextBoxPatch + { + internal static string textBoxQuery = " "; + + internal static void DrawPatch(StardewValley.Menus.TextBox __instance) + { + try + { + bool isEscPressed = StardewValley.Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box + string toSpeak = " "; + if (__instance.Selected) + { + MainClass.isAnyTextBoxActive = true; + toSpeak = __instance.Text; + + if (isEscPressed) + { + __instance.Selected = false; + } + } + else + { + MainClass.isAnyTextBoxActive = false; + } + + if (textBoxQuery != toSpeak) + { + textBoxQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in DrawPatch() in TextBoxPatch:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From e595a03be61b36cf64676c223777a81b8bc47187 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 21 Feb 2023 21:41:45 +0530 Subject: [PATCH 14/61] Fixed bug for more than 1 text boxes in a menu In this bug, if there were amore than 1 text boxes, then the textBoxQuery was resets to ' ' even if a text box is selected because of the other unselected text boxes --- stardew-access/Patches/TextBoxPatch.cs | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) diff --git a/stardew-access/Patches/TextBoxPatch.cs b/stardew-access/Patches/TextBoxPatch.cs index f940193..eddc5e4 100644 --- a/stardew-access/Patches/TextBoxPatch.cs +++ b/stardew-access/Patches/TextBoxPatch.cs @@ -8,21 +8,20 @@ namespace stardew_access.Patches { try { - bool isEscPressed = StardewValley.Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box - string toSpeak = " "; - if (__instance.Selected) - { - MainClass.isAnyTextBoxActive = true; - toSpeak = __instance.Text; - - if (isEscPressed) - { - __instance.Selected = false; - } - } - else + if (!__instance.Selected) { MainClass.isAnyTextBoxActive = false; + return; + } + + MainClass.isAnyTextBoxActive = true; + + bool isEscPressed = StardewValley.Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); + string toSpeak = __instance.Text; + + if (isEscPressed) + { + __instance.Selected = false; } if (textBoxQuery != toSpeak) From c9c62d4fa9c2ff8c458edda1aa762b0201ebb1fc Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 21 Feb 2023 21:49:22 +0530 Subject: [PATCH 15/61] Removed previous text box code from other places --- stardew-access/ModEntry.cs | 8 ++--- .../Patches/BuildingNAnimalMenuPatches.cs | 8 +++-- .../CharacterCustomizationMenuPatches.cs | 31 ++--------------- stardew-access/Patches/ChatMenuPatches.cs | 3 +- stardew-access/Patches/MenuPatches.cs | 33 +++++++------------ 5 files changed, 24 insertions(+), 59 deletions(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 3233e58..03364ed 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -218,21 +218,21 @@ namespace stardew_access #region Mouse Click Simulation // Main Keybinds - if (Config.LeftClickMainKey.JustPressed()) + if (!isAnyTextBoxActive && Config.LeftClickMainKey.JustPressed()) { Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } - if (Config.RightClickMainKey.JustPressed()) + if (!isAnyTextBoxActive && Config.RightClickMainKey.JustPressed()) { Game1.activeClickableMenu.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); } // Alternate Keybinds - if (!isCustomizingCharacter && !isAnyTextBoxActive && Config.LeftClickAlternateKey.JustPressed()) // Excluding the character creation menu + if (!isAnyTextBoxActive && Config.LeftClickAlternateKey.JustPressed()) // Excluding the character creation menu { Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } - if (!isCustomizingCharacter && Game1.activeClickableMenu is not AnimalQueryMenu && Config.RightClickAlternateKey.JustPressed()) // Excluding the character creation menu + if (!isAnyTextBoxActive && Config.RightClickAlternateKey.JustPressed()) // Excluding the character creation menu { Game1.activeClickableMenu.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); } diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs index d52e981..174f6f3 100644 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -91,6 +91,8 @@ namespace stardew_access.Patches { try { + if (MainClass.isAnyTextBoxActive) return; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position purchaseAnimalsMenu = __instance; isOnFarm = ___onFarm; @@ -114,9 +116,9 @@ namespace stardew_access.Patches else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) { toSpeak = "Name Text Box"; - string? value = ___textBox.Text; - if (value != "" && value != null && value != "null") - toSpeak = $"{toSpeak}, Value: {value}"; + // string? value = ___textBox.Text; + // if (value != "" && value != null && value != "null") + // toSpeak = $"{toSpeak}, Value: {value}"; } if (purchaseAnimalMenuQuery != toSpeak) diff --git a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs b/stardew-access/Patches/CharacterCustomizationMenuPatches.cs index 52c4323..fa2cc04 100644 --- a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs +++ b/stardew-access/Patches/CharacterCustomizationMenuPatches.cs @@ -34,6 +34,8 @@ namespace stardew_access.Patches { { try { + if (MainClass.isAnyTextBoxActive) return; + bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box string toSpeak = ""; if (characterDesignToggleShouldSpeak) @@ -44,34 +46,7 @@ namespace stardew_access.Patches { string itemsToSpeak = ""; string changesToSpeak = ""; - if (___nameBox.Selected) - { - toSpeak = ___nameBox.Text; - - if (isEscPressed) - { - ___nameBox.Selected = false; - } - } - else if (___farmnameBox.Selected) - { - toSpeak = ___farmnameBox.Text; - - if (isEscPressed) - { - ___farmnameBox.Selected = false; - } - } - else if (___favThingBox.Selected) - { - toSpeak = ___favThingBox.Text; - - if (isEscPressed) - { - ___favThingBox.Selected = false; - } - } - else if (MainClass.Config.CharacterCreationMenuNextKey.JustPressed() && !isRunning) + if (MainClass.Config.CharacterCreationMenuNextKey.JustPressed() && !isRunning) { isRunning = true; itemsToSpeak =CycleThroughItems(true, __instance, ___skipIntro, ___startingCabinsLabel, ___difficultyModifierLabel, ___nameBox, ___farmnameBox, ___favThingBox); diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs index 6155a70..9d3272d 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -1,5 +1,4 @@ -using StardewValley; -using StardewValley.Menus; +using StardewValley.Menus; namespace stardew_access.Patches { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index e33a237..6e70087 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -420,35 +420,24 @@ namespace stardew_access.Patches { try { - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box - if (firstTimeInNamingMenu) { firstTimeInNamingMenu = false; ___textBox.Selected = false; } - if (___textBox.Selected) - { - ___textBox.Update(); - toSpeak = ___textBox.Text; + if (MainClass.isAnyTextBoxActive) return; - if (isEscPressed) - { - ___textBox.Selected = false; - } - } - else - { - if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = $"{___title} text box"; - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - toSpeak = $"Done naming button"; - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - toSpeak = $"Random button"; - } + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box + + if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = $"{___title} text box"; + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + toSpeak = $"Done naming button"; + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + toSpeak = $"Random button"; if (toSpeak != "") MainClass.ScreenReader.SayWithChecker(toSpeak, true); From ecb256ad575f1ba235699f109d9664c8f5b14a32 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 21 Feb 2023 21:51:55 +0530 Subject: [PATCH 16/61] Removed unnecessary code --- stardew-access/Patches/TitleMenuPatches.cs | 822 --------------------- 1 file changed, 822 deletions(-) diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs index c93e2b6..0a17870 100644 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches.cs @@ -1,37 +1,13 @@ using StardewValley; using StardewValley.Menus; -using static StardewValley.Menus.CharacterCustomization; using static StardewValley.Menus.LoadGameMenu; namespace stardew_access.Patches { internal class TitleMenuPatches { - private static int saveGameIndex = -1; private static bool isRunning = false; - public static string characterCreationMenuQueryKey = " "; public static string advancedGameOptionsQueryKey = " "; - public static string prevPants = " "; - public static string prevShirt = " "; - public static string prevHair = " "; - public static string prevAccessory = " "; - public static string prevSkin = " "; - public static string prevEyeColor = " "; - public static string prevEyeColorHue = " "; - public static string prevEyeColorSaturation = " "; - public static string prevEyeColorValue = " "; - public static string prevHairColor = " "; - public static string prevHairColorHue = " "; - public static string prevHairColorSaturation = " "; - public static string prevHairColorValue = " "; - public static string prevPantsColor = " "; - public static string prevPantsColorHue = " "; - public static string prevPantsColorSaturation = " "; - public static string prevPantsColorValue = " "; - public static string prevPetName = " "; - public static bool characterDesignToggle = false; - public static bool characterDesignToggleShouldSpeak = true; - public static ClickableComponent? currentComponent = null; internal static void AdvancedGameOptionsPatch(AdvancedGameOptions __instance) { @@ -259,803 +235,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - internal static void CharacterCustomizationMenuPatch(CharacterCustomization __instance, bool ___skipIntro, - ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox, - TextBox ___farmnameBox, TextBox ___favThingBox) - { - try - { - bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box - string toSpeak = ""; - if (characterDesignToggleShouldSpeak) - { - toSpeak = "Press left control + space to toggle character appearance controls"; - characterDesignToggleShouldSpeak = false; - } - string itemsToSpeak = ""; - string changesToSpeak = ""; - - if (___nameBox.Selected) - { - toSpeak = ___nameBox.Text; - - if (isEscPressed) - { - ___nameBox.Selected = false; - } - } - else if (___farmnameBox.Selected) - { - toSpeak = ___farmnameBox.Text; - - if (isEscPressed) - { - ___farmnameBox.Selected = false; - } - } - else if (___favThingBox.Selected) - { - toSpeak = ___favThingBox.Text; - - if (isEscPressed) - { - ___favThingBox.Selected = false; - } - } - else if (MainClass.Config.CharacterCreationMenuNextKey.JustPressed() && !isRunning) - { - isRunning = true; - itemsToSpeak =CycleThroughItems(true, __instance, ___skipIntro, ___startingCabinsLabel, ___difficultyModifierLabel, ___nameBox, ___farmnameBox, ___favThingBox); - if (itemsToSpeak != "") - toSpeak = $"{itemsToSpeak} \n {toSpeak}"; - Task.Delay(200).ContinueWith(_ => { isRunning = false; }); - } - else if (MainClass.Config.CharacterCreationMenuPreviousKey.JustPressed() && !isRunning) - { - isRunning = true; - toSpeak = CycleThroughItems(false, __instance, ___skipIntro, ___startingCabinsLabel, ___difficultyModifierLabel, ___nameBox, ___farmnameBox, ___favThingBox); - Task.Delay(200).ContinueWith(_ => { isRunning = false; }); - } - - else if (characterDesignToggle && MainClass.Config.CharacterCreationMenuSliderIncreaseKey.JustPressed() && !isRunning) - { - isRunning = true; - AdjustCurrentSlider(true, __instance); - Task.Delay(200).ContinueWith(_ => { isRunning = false; }); - } - - else if (characterDesignToggle && MainClass.Config.CharacterCreationMenuSliderLargeIncreaseKey.JustPressed() && !isRunning) - { - isRunning = true; - AdjustCurrentSlider(true, __instance, 10); - Task.Delay(200).ContinueWith(_ => { isRunning = false; }); - } - - else if (characterDesignToggle && MainClass.Config.CharacterCreationMenuSliderDecreaseKey.JustPressed() && !isRunning) - { - isRunning = true; - AdjustCurrentSlider(false, __instance); - Task.Delay(200).ContinueWith(_ => { isRunning = false; }); - } - - else if (characterDesignToggle && MainClass.Config.CharacterCreationMenuSliderLargeDecreaseKey.JustPressed() && !isRunning) - { - isRunning = true; - AdjustCurrentSlider(false, __instance, 10); - Task.Delay(200).ContinueWith(_ => { isRunning = false; }); - } - - else if (Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftControl) && MainClass.Config.CharacterCreationMenuDesignToggleKey.JustPressed() && !isRunning) - { - string displayState = ""; - characterDesignToggle = !characterDesignToggle; - saveGameIndex = Math.Min(saveGameIndex, 5); // move to random skin button if focus was beyond that point - if (characterDesignToggle) - { - displayState = "shown"; - } else { - displayState = "hidden"; - } - toSpeak = $"Character design controls {displayState}. \n {toSpeak}"; - } - - changesToSpeak = getChangesToSpeak(__instance); - if (changesToSpeak != "") - toSpeak = $"{toSpeak} \n {changesToSpeak}"; - - if (characterCreationMenuQueryKey != toSpeak && toSpeak.Trim() != "") - { - characterCreationMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static string getChangesToSpeak(CharacterCustomization __instance) - { - string toSpeak = ""; - string currentPetName = getCurrentPetName(); - string currentSkin = getCurrentSkin(); - string currentHair = getCurrentHair(); - string currentShirt = getCurrentShirt(); - string currentPants = getCurrentPants(); - string currentAccessory = getCurrentAccessory(); - string currentEyeColor = getCurrentEyeColor(); - string currentEyeColorHue = getCurrentEyeColorHue(__instance); - string currentEyeColorSaturation = getCurrentEyeColorSaturation(__instance); - string currentEyeColorValue = getCurrentEyeColorValue(__instance); - string currentHairColor = getCurrentHairColor(); - string currentHairColorHue = getCurrentHairColorHue(__instance); - string currentHairColorSaturation = getCurrentHairColorSaturation(__instance); - string currentHairColorValue = getCurrentHairColorValue(__instance); - string currentPantsColor = getCurrentPantsColor(); - string currentPantsColorHue = getCurrentPantsColorHue(__instance); - string currentPantsColorSaturation = getCurrentPantsColorSaturation(__instance); - string currentPantsColorValue = getCurrentPantsColorValue(__instance); - - if (characterDesignToggle) - { - if (prevSkin != currentSkin) - { - prevSkin = currentSkin; - if (currentSkin != "") - toSpeak = $"{toSpeak} \n {currentSkin}"; - } - - if (prevHair != currentHair) - { - prevHair = currentHair; - if (currentHair != "") - toSpeak = $"{toSpeak} \n {currentHair}"; - } - - if (prevShirt != currentShirt) - { - prevShirt = currentShirt; - if (currentShirt != "") - toSpeak = $"{toSpeak} \n {currentShirt}"; - } - - if (prevPants != currentPants) - { - prevPants = currentPants; - if (currentPants != "") - toSpeak = $"{toSpeak} \n {currentPants}"; - } - - if (prevAccessory != currentAccessory) - { - prevAccessory = currentAccessory; - if (currentAccessory != "") - toSpeak = $"{toSpeak} \n {currentAccessory}"; - } - - if (prevEyeColorHue != currentEyeColorHue) - { - if (currentComponent != null && currentComponent.myID == 522) - { - prevEyeColorHue = currentEyeColorHue; - if (currentEyeColorHue != "") - toSpeak = $"{toSpeak} \n Hue: {currentEyeColorHue}"; - } else { - prevEyeColorHue = ""; - } - } - - if (prevEyeColorSaturation != currentEyeColorSaturation) - { - if (currentComponent != null && currentComponent.myID == 523) - { - prevEyeColorSaturation = currentEyeColorSaturation; - if (currentEyeColorSaturation != "") - toSpeak = $"{toSpeak} \n Saturation: {currentEyeColorSaturation}"; - } else { - prevEyeColorSaturation = ""; - } - } - - if (prevEyeColorValue != currentEyeColorValue) - { - if (currentComponent != null && currentComponent.myID == 524) - { - prevEyeColorValue = currentEyeColorValue; - if (currentEyeColorValue != "") - toSpeak = $"{toSpeak} \n Value: {currentEyeColorValue}"; - } else { - prevEyeColorValue = ""; - } - } - - if (prevEyeColor != currentEyeColor) - { - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 522 || currentComponent.myID <= 524))) - { - prevEyeColor = currentEyeColor; - if (currentEyeColor != "") - toSpeak = $"{toSpeak} \n {currentEyeColor}"; - } - } - - if (prevHairColorHue != currentHairColorHue) - { - if (currentComponent != null && currentComponent.myID == 525) - { - prevHairColorHue = currentHairColorHue; - if (currentHairColorHue != "") - toSpeak = $"{toSpeak} \n Hue: {currentHairColorHue}"; - } else { - prevHairColorHue = ""; - } - } - - if (prevHairColorSaturation != currentHairColorSaturation) - { - if (currentComponent != null && currentComponent.myID == 526) - { - prevHairColorSaturation = currentHairColorSaturation; - if (currentHairColorSaturation != "") - toSpeak = $"{toSpeak} \n Saturation: {currentHairColorSaturation}"; - } else { - prevHairColorSaturation = ""; - } - } - - if (prevHairColorValue != currentHairColorValue) - { - if (currentComponent != null && currentComponent.myID == 527) - { - prevHairColorValue = currentHairColorValue; - if (currentHairColorValue != "") - toSpeak = $"{toSpeak} \n Value: {currentHairColorValue}"; - } else { - prevHairColorValue = ""; - } - } - - if (prevHairColor != currentHairColor) - { - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 525 || currentComponent.myID <= 527))) - { - prevHairColor = currentHairColor; - if (currentHairColor != "") - toSpeak = $"{toSpeak} \n {currentHairColor}"; - } - } - - if (prevPantsColorHue != currentPantsColorHue) - { - if (currentComponent != null && currentComponent.myID == 528) - { - prevPantsColorHue = currentPantsColorHue; - if (currentPantsColorHue != "") - toSpeak = $"{toSpeak} \n Hue: {currentPantsColorHue}"; - } else { - prevPantsColorHue = ""; - } - } - - if (prevPantsColorSaturation != currentPantsColorSaturation) - { - if (currentComponent != null && currentComponent.myID == 529) - { - prevPantsColorSaturation = currentPantsColorSaturation; - if (currentPantsColorSaturation != "") - toSpeak = $"{toSpeak} \n Saturation: {currentPantsColorSaturation}"; - } else { - prevPantsColorSaturation = ""; - } - } - - if (prevPantsColorValue != currentPantsColorValue) - { - if (currentComponent != null && currentComponent.myID == 530) - { - prevPantsColorValue = currentPantsColorValue; - if (currentPantsColorValue != "") - toSpeak = $"{toSpeak} \n Value: {currentPantsColorValue}"; - } else { - prevPantsColorValue = ""; - } - } - - if (prevPantsColor != currentPantsColor) - { - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 528 || currentComponent.myID <= 530))) - { - prevPantsColor = currentPantsColor; - if (currentPantsColor != "") - toSpeak = $"{toSpeak} \n {currentPantsColor}"; - } - } - } - - if (prevPetName != currentPetName) - { - prevPetName = currentPetName; - if (currentPetName != "") - toSpeak = $"{toSpeak} \n Current Pet: {currentPetName}"; - } - return toSpeak.Trim(); - } - - - private static string CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro, - ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox, - TextBox ___farmnameBox, TextBox ___favThingBox) - { - string toSpeak = " "; - int DesignControlsIndex = 0; - Dictionary buttons = new(); - - #region Add buttons with their names IF they are available - - #region Character related - string postText = ""; - if (__instance.nameBoxCC != null && __instance.nameBoxCC.visible) - { - if (___nameBox.Text != "") - { - postText = $": {___nameBox.Text}"; - } else { - postText = " Text Box"; - } - buttons.Add(__instance.nameBoxCC, $"Farmer's Name{postText}"); - } - - if (__instance.farmnameBoxCC != null && __instance.farmnameBoxCC.visible) - { - if (___farmnameBox.Text != "") - { - postText = $": {___farmnameBox.Text}"; - } else { - postText = " Text Box"; - } - buttons.Add(__instance.farmnameBoxCC, $"Farm's Name{postText}"); - } - - if (__instance.favThingBoxCC != null && __instance.favThingBoxCC.visible) - { - if (___favThingBox.Text != "") - { - postText = $": {___favThingBox.Text}"; - } else { - postText = " Text Box"; - } - buttons.Add(__instance.favThingBoxCC, $"Favourite Thing{postText}"); - } - - if (__instance.petPortraitBox.HasValue) // Cannot get petButtons like with others - { - ClickableComponent petPrev = __instance.getComponentWithID(511); - buttons.Add(petPrev, "Previous pet button"); - - ClickableComponent petNext = __instance.getComponentWithID(510); - buttons.Add(petNext, "Next pet button"); - } - - if (__instance.randomButton != null && __instance.randomButton.visible) - buttons.Add(__instance.randomButton, "Random Skin Button"); - - // Controls to rotate the farmer (Potentially useful for low vision players) are first if they're available. - // They also appear above the gender buttons, so we handle them separately here. - if (characterDesignToggle && new[] {__instance.leftSelectionButtons.Count, __instance.rightSelectionButtons.Count }.All(c => c >= 0)) // both have Count > 0 - { - if (new[] {__instance.leftSelectionButtons[DesignControlsIndex].visible, __instance.rightSelectionButtons[DesignControlsIndex].visible }.All(v => v == true) // both visible - && new[] {__instance.leftSelectionButtons[DesignControlsIndex].name, __instance.rightSelectionButtons[DesignControlsIndex].name }.All(n => n == "Direction")) // both named "Direction" - { - buttons.Add(__instance.leftSelectionButtons[DesignControlsIndex], "Rotate Left Button"); - buttons.Add(__instance.rightSelectionButtons[DesignControlsIndex], "Rotate Right Button"); - ++DesignControlsIndex; - } - } - - if (__instance.genderButtons.Count > 0) - { - buttons.Add(__instance.genderButtons[0], ((Game1.player.IsMale) ? "Selected " : "") + "Gender: Male Button"); - buttons.Add(__instance.genderButtons[1], ((!Game1.player.IsMale) ? "Selected " : "") + "Gender: Female Button"); - } - - if (characterDesignToggle&& new[] {__instance.leftSelectionButtons.Count, __instance.rightSelectionButtons.Count }.All(c => c >= DesignControlsIndex) && new[] {__instance.leftSelectionButtons[DesignControlsIndex].visible, __instance.rightSelectionButtons[DesignControlsIndex].visible }.All(v => v == true)) - { - while(DesignControlsIndex < __instance.leftSelectionButtons.Count) - { - ClickableComponent left = __instance.leftSelectionButtons[DesignControlsIndex]; - ClickableComponent right = __instance.rightSelectionButtons[DesignControlsIndex]; - string name = left.name; - // minor cleanup on names to be slightly more descriptive - switch (name) - { - case "Skin": - name += " Tone"; - break; - case "Hair": - name += " Style"; - break; - case "Acc": - name = "Accessory"; - break; - default: - break; - } - if (!buttons.ContainsKey(left) || !buttons.ContainsKey(right)) - { - buttons.Add(left, $"Previous {name} button"); - buttons.Add(right, $"Next {name} button"); - } - //MainClass.ScreenReader.Say($"Left {DesignControlsIndex}: {__instance.leftSelectionButtons[DesignControlsIndex]} {__instance.leftSelectionButtons[DesignControlsIndex].name}\n", true); - //MainClass.ScreenReader.Say($"Right {DesignControlsIndex}: {__instance.rightSelectionButtons[DesignControlsIndex]} {__instance.rightSelectionButtons[DesignControlsIndex].name}\n", true); - ++DesignControlsIndex; - } - - ClickableComponent eyeColorHue = __instance.getComponentWithID(522); - if (eyeColorHue != null && eyeColorHue.visible) - buttons.Add(eyeColorHue, "eye color hue slider"); - - ClickableComponent eyeColorSaturation = __instance.getComponentWithID(523); - if (eyeColorSaturation != null && eyeColorSaturation.visible) - buttons.Add(eyeColorSaturation, "eye color saturation slider"); - - ClickableComponent eyeColorValue = __instance.getComponentWithID(524); - if (eyeColorValue != null && eyeColorValue.visible) - buttons.Add(eyeColorValue, "eye color Value slider"); - - ClickableComponent hairColorHue = __instance.getComponentWithID(525); - if (hairColorHue != null && hairColorHue.visible) - buttons.Add(hairColorHue, "hair color hue slider"); - - ClickableComponent hairColorSaturation = __instance.getComponentWithID(526); - if (hairColorSaturation != null && hairColorSaturation.visible) - buttons.Add(hairColorSaturation, "hair color saturation slider"); - - ClickableComponent hairColorValue = __instance.getComponentWithID(527); - if (hairColorValue != null && hairColorValue.visible) - buttons.Add(hairColorValue, "hair color Value slider"); - - ClickableComponent pantsColorHue = __instance.getComponentWithID(528); - if (pantsColorHue != null && pantsColorHue.visible) - buttons.Add(pantsColorHue, "pants color hue slider"); - - ClickableComponent pantsColorSaturation = __instance.getComponentWithID(529); - if (pantsColorSaturation != null && pantsColorSaturation.visible) - buttons.Add(pantsColorSaturation, "pants color saturation slider"); - - ClickableComponent pantsColorValue = __instance.getComponentWithID(530); - if (pantsColorValue != null && pantsColorValue.visible) - buttons.Add(pantsColorValue, "pants color Value slider"); - } - - #endregion - - #region Farm layout related - if (__instance.farmTypeButtons.Count > 0) - { - for (int i = 0; i < __instance.farmTypeButtons.Count; i++) - { - buttons.Add(__instance.farmTypeButtons[i], ((i == Game1.whichFarm) ? "Selected " : "") + getFarmHoverText(__instance.farmTypeButtons[i])); - } - } - - if (__instance.farmTypeNextPageButton != null && __instance.farmTypeNextPageButton.visible) - buttons.Add(__instance.farmTypeNextPageButton, "Next Farm Type Page Button"); - - if (__instance.farmTypePreviousPageButton != null && __instance.farmTypePreviousPageButton.visible) - buttons.Add(__instance.farmTypePreviousPageButton, "Previous Farm Type Page Button"); - #endregion - - #region Co-op related - if (__instance.source == Source.HostNewFarm) - { - ClickableComponent cabinLeft = __instance.getComponentWithID(621); - if (Game1.startingCabins > 0) - buttons.Add(cabinLeft, "Decrease starting cabins button"); - - buttons.Add(___startingCabinsLabel, $"Starting cabins: {Game1.startingCabins}"); - - ClickableComponent cabinRight = __instance.getComponentWithID(622); - if (Game1.startingCabins < 3) - buttons.Add(cabinRight, "Increase starting cabins button"); - - if (Game1.startingCabins > 0) - { - buttons.Add(__instance.cabinLayoutButtons[0], "Cabin layout to nearby Button"); - buttons.Add(__instance.cabinLayoutButtons[1], "Cabin layout to separate Button"); - } - - ClickableComponent difficultyLeft = __instance.getComponentWithID(627); - buttons.Add(difficultyLeft, "Increase profit margin button"); - buttons.Add(___difficultyModifierLabel, "Profit Margin: " + (((Game1.player.difficultyModifier * 100) == 100f) ? "normal" : Game1.player.difficultyModifier.ToString())); - ClickableComponent difficultyRight = __instance.getComponentWithID(628); - buttons.Add(difficultyRight, "Decrease profit margin button"); - - ClickableComponent walletLeft = __instance.getComponentWithID(631); - buttons.Add(walletLeft, "Money style to " + ((!Game1.player.team.useSeparateWallets.Value) ? "separate wallets" : "shared wallets") + " button"); - } - #endregion - - if (__instance.skipIntroButton != null && __instance.skipIntroButton.visible) - buttons.Add(__instance.skipIntroButton, (___skipIntro ? "Enabled" : "Disabled") + " Skip Intro Button"); - - if (__instance.advancedOptionsButton != null && __instance.advancedOptionsButton.visible) - buttons.Add(__instance.advancedOptionsButton, "Advanced Options Button"); - - if (__instance.okButton != null && __instance.okButton.visible) - buttons.Add(__instance.okButton, "OK Button"); - - if (__instance.backButton != null && __instance.backButton.visible) - buttons.Add(__instance.backButton, "Back Button"); - #endregion - - int size = buttons.Count - 1; - - if (increase) - { - saveGameIndex++; - if (saveGameIndex > size) - saveGameIndex = 0; - } - else - { - saveGameIndex--; - if (saveGameIndex < 0) - saveGameIndex = size; - } - - currentComponent = buttons.ElementAt(saveGameIndex).Key; - currentComponent!.snapMouseCursor(); - __instance.setCurrentlySnappedComponentTo(currentComponent!.myID); - - toSpeak = buttons.ElementAt(saveGameIndex).Value; - - return toSpeak.Trim(); - } - - private static SliderBar? getCurrentSliderBar(int id, CharacterCustomization __instance) - { - if (id >= 522 && id <= 530) - { - // Three ColorPickers with 3 SliderBars each. - // First group ids by ColorPicker. - // Maps 522-524 -> 0, 525-527 -> 1, 528-530 -> 2 - int whichColorPicker = (int)Math.Floor(((float)id - 522f) / 3f); - // Next group ids by slider type. - // Maps [522,525,528] -> 0, [523,526,529] -> 1, [524,527,530] -> 2 - int whichSliderBar = (int)Math.Floor((float)id % 3f); - ColorPicker cp; - switch (whichColorPicker) - { - default: - case 0: - // 522-524 == eye color - cp = __instance.eyeColorPicker; - break; - case 1: - // 525-527 == hair color - cp = __instance.hairColorPicker; - break; - case 2: - // 528-530 == pants color - cp = __instance.pantsColorPicker; - break; - } - SliderBar sb; - switch (whichSliderBar) - { - default: - case 0: - // 522, 525, 528 == hue slider - sb = cp.hueBar; - break; - case 1: - // 523, 526, 529 == saturation slider - sb = cp.saturationBar; - break; - case 2: - // 524, 527, 530 == value slider - sb = cp.valueBar; - break; - } - return sb; - } else { - return null; - } - } - - private static void AdjustCurrentSlider(bool increase, CharacterCustomization __instance, int amount=1) - { - if (currentComponent != null && currentComponent.myID >= 522 && currentComponent.myID <= 530) - { - SliderBar sb = getCurrentSliderBar(currentComponent.myID, __instance) !; - if (sb != null) - { - double step = ((double)sb.bounds.Width / 100d); // size of 1% change in slider value - double value = (double)sb.value; - double x = 0d; - int y = currentComponent.bounds.Center.Y; - if (increase) - { - value = Math.Min(value + amount, 99d); - x = Math.Min(Math.Ceiling((value * step)), (double)sb.bounds.Width); - } else { - value = Math.Max(value - amount, 0d); - x = Math.Max(Math.Ceiling((value * step)), 0d); - } - x += (double)currentComponent.bounds.Left; - Game1.setMousePosition((int)x, y); - Game1.activeClickableMenu.receiveLeftClick((int)x, y); - } - } - } - - // Most values (exception noted below) are 0 indexed internally but visually start from 1. Thus we increment before returning. - private static string getCurrentSkin() - { - if (currentComponent != null && (currentComponent.myID == 507 || currentComponent.name == "Skin")) - return $"Skin tone: {Game1.player.skin.Value + 1}"; - return ""; - } - - private static string getCurrentHair() - { - if (currentComponent != null && (currentComponent.myID == 507 || currentComponent.name == "Hair")) - return $"hair style: {Game1.player.hair.Value + 1}"; - return ""; - } - - private static string getCurrentShirt() - { - if (currentComponent != null && (currentComponent.myID == 507 || currentComponent.name == "Shirt")) - return $"Shirt: {Game1.player.shirt.Value + 1}"; - return ""; - } - - private static string getCurrentPants() - { - if (currentComponent != null && (currentComponent.myID == 507 || currentComponent.name == "Pants Style")) - return $"Pants: {Game1.player.pants.Value + 1}"; - return ""; - } - - private static string getCurrentAccessory() - { - // Internally accessory starts from -1 while displaying +1 on screen. - if (currentComponent != null && (currentComponent.myID == 507 || currentComponent.name == "Acc")) - return $"accessory: {Game1.player.accessory.Value + 2}"; - return ""; - } - - private static string getCurrentEyeColor() - { - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 522 && currentComponent.myID <= 524))) - return $"Eye color: {Game1.player.newEyeColor.R}, {Game1.player.newEyeColor.G}, {Game1.player.newEyeColor.B}"; - return ""; - } - - private static string getCurrentEyeColorHue(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(522, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 522 && currentComponent.myID <= 524))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentEyeColorSaturation(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(523, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 522 && currentComponent.myID <= 524))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentEyeColorValue(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(524, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 522 && currentComponent.myID <= 524))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentHairColor() - { - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 525 && currentComponent.myID <= 527))) - return $"Hair color: {Game1.player.hairstyleColor.R}, {Game1.player.hairstyleColor.G}, {Game1.player.hairstyleColor.B}"; - return ""; - } - - private static string getCurrentHairColorHue(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(525, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 525 && currentComponent.myID <= 527))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentHairColorSaturation(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(526, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 525 && currentComponent.myID <= 527))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentHairColorValue(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(527, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 525 && currentComponent.myID <= 527))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentPantsColor() - { - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 528 && currentComponent.myID <= 530))) - return $"Pants color: {Game1.player.pantsColor.R}, {Game1.player.pantsColor.G}, {Game1.player.pantsColor.B}"; - return ""; - } - - private static string getCurrentPantsColorHue(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(528, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 528 && currentComponent.myID <= 530))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentPantsColorSaturation(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(529, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 528 && currentComponent.myID <= 530))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentPantsColorValue(CharacterCustomization __instance) - { - SliderBar sb = getCurrentSliderBar(530, __instance)!; - if (currentComponent != null && (currentComponent.myID == 507 || (currentComponent.myID >= 528 && currentComponent.myID <= 530))) - return sb.value!.ToString(); - return ""; - } - - private static string getCurrentPetName() - { - if (currentComponent != null && currentComponent.name == "Pet") - { - return ((Game1.player.catPerson) ? "Cat" : "Dog") + " Breed: " + Game1.player.whichPetBreed; - } else { - return ""; - } - } - - private static string getFarmHoverText(ClickableTextureComponent farm) - { - string hoverTitle = " ", hoverText = " "; - if (!farm.name.Contains("Gray")) - { - if (farm.hoverText.Contains('_')) - { - hoverTitle = farm.hoverText.Split('_')[0]; - hoverText = farm.hoverText.Split('_')[1]; - } - else - { - hoverTitle = " "; - hoverText = farm.hoverText; - } - } - else - { - if (farm.name.Contains("Gray")) - { - hoverText = "Reach level 10 " + Game1.content.LoadString("Strings\\UI:Character_" + farm.name.Split('_')[1]) + " to unlock."; - } - } - - return $"{hoverTitle}: {hoverText}"; - } } } From 31f3144bfded7a37bbce6369a06a40e3aa7a08c2 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 22 Feb 2023 16:55:54 +0530 Subject: [PATCH 17/61] Bug fix --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/ModEntry.cs | 38 +++++++------------------------- 2 files changed, 9 insertions(+), 31 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 692ce38..2a76ff6 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -48,7 +48,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CharacterCustomization), nameof(CharacterCustomization.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(CharacterCustomizationPatches.CharacterCustomizationMenuPatch)) + postfix: new HarmonyMethod(typeof(CharacterCustomizationPatches), nameof(CharacterCustomizationPatches.CharacterCustomizationMenuPatch)) ); harmony.Patch( diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 03364ed..658db41 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -13,7 +13,8 @@ namespace stardew_access public class MainClass : Mod { #region Global Vars & Properties -#pragma warning disable CS8603 + + #pragma warning disable CS8603 private static int prevDate = -99; private static ModConfig? config; private Harmony? harmony; @@ -101,7 +102,6 @@ namespace stardew_access return warnings; } } -#pragma warning restore CS8603 #endregion /********* @@ -212,54 +212,32 @@ namespace stardew_access return; #region Simulate left and right clicks - if (Game1.activeClickableMenu != null) + if (Game1.activeClickableMenu != null && !isAnyTextBoxActive) { bool isCustomizingCharacter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization); #region Mouse Click Simulation - // Main Keybinds - if (!isAnyTextBoxActive && Config.LeftClickMainKey.JustPressed()) + if (Config.LeftClickMainKey.JustPressed() || Config.LeftClickAlternateKey.JustPressed()) { Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } - if (!isAnyTextBoxActive && Config.RightClickMainKey.JustPressed()) - { - Game1.activeClickableMenu.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - // Alternate Keybinds - if (!isAnyTextBoxActive && Config.LeftClickAlternateKey.JustPressed()) // Excluding the character creation menu - { - Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - if (!isAnyTextBoxActive && Config.RightClickAlternateKey.JustPressed()) // Excluding the character creation menu + if (Config.RightClickMainKey.JustPressed() || Config.RightClickAlternateKey.JustPressed()) { Game1.activeClickableMenu.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); } #endregion } - if (Game1.currentMinigame != null) + if (Game1.currentMinigame != null && !isAnyTextBoxActive) { - bool isCustomizingCharacter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization); - #region Mouse Click Simulation - // Main Keybinds - if (Config.LeftClickMainKey.JustPressed()) + if (Config.LeftClickMainKey.JustPressed() || Config.LeftClickAlternateKey.JustPressed()) { Game1.currentMinigame.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); } - if (Config.RightClickMainKey.JustPressed()) - { - Game1.currentMinigame.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - // Alternate Keybinds - if (Config.LeftClickAlternateKey.JustPressed()) - { - Game1.currentMinigame.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - if (Config.RightClickAlternateKey.JustPressed()) + if (Config.RightClickMainKey.JustPressed() || Config.RightClickAlternateKey.JustPressed()) { Game1.currentMinigame.receiveRightClick(Game1.getMouseX(true), Game1.getMouseY(true)); } From cf0e46ecdda0a5b6d7bd5435db354f96707b7e4e Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 22 Feb 2023 17:03:33 +0530 Subject: [PATCH 18/61] Refactored code --- stardew-access/HarmonyPatches.cs | 2 +- .../CharacterCustomizationMenuPatches.cs | 93 +++++++++++++------ 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 2a76ff6..056999f 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -48,7 +48,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CharacterCustomization), nameof(CharacterCustomization.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(CharacterCustomizationPatches), nameof(CharacterCustomizationPatches.CharacterCustomizationMenuPatch)) + postfix: new HarmonyMethod(typeof(CharacterCustomizationMenuPatch), nameof(CharacterCustomizationMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs b/stardew-access/Patches/CharacterCustomizationMenuPatches.cs index fa2cc04..96852ff 100644 --- a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs +++ b/stardew-access/Patches/CharacterCustomizationMenuPatches.cs @@ -1,8 +1,10 @@ using StardewValley; using StardewValley.Menus; -namespace stardew_access.Patches { - internal class CharacterCustomizationPatches { +namespace stardew_access.Patches +{ + internal class CharacterCustomizationMenuPatch + { private static bool isRunning = false; private static int saveGameIndex = -1; public static string characterCreationMenuQueryKey = " "; @@ -28,7 +30,7 @@ namespace stardew_access.Patches { public static bool characterDesignToggleShouldSpeak = true; public static ClickableComponent? currentComponent = null; - internal static void CharacterCustomizationMenuPatch(CharacterCustomization __instance, bool ___skipIntro, + internal static void DrawPatch(CharacterCustomization __instance, bool ___skipIntro, ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox, TextBox ___farmnameBox, TextBox ___favThingBox) { @@ -49,7 +51,7 @@ namespace stardew_access.Patches { if (MainClass.Config.CharacterCreationMenuNextKey.JustPressed() && !isRunning) { isRunning = true; - itemsToSpeak =CycleThroughItems(true, __instance, ___skipIntro, ___startingCabinsLabel, ___difficultyModifierLabel, ___nameBox, ___farmnameBox, ___favThingBox); + itemsToSpeak = CycleThroughItems(true, __instance, ___skipIntro, ___startingCabinsLabel, ___difficultyModifierLabel, ___nameBox, ___farmnameBox, ___favThingBox); if (itemsToSpeak != "") toSpeak = $"{itemsToSpeak} \n {toSpeak}"; Task.Delay(200).ContinueWith(_ => { isRunning = false; }); @@ -97,7 +99,9 @@ namespace stardew_access.Patches { if (characterDesignToggle) { displayState = "shown"; - } else { + } + else + { displayState = "hidden"; } toSpeak = $"Character design controls {displayState}. \n {toSpeak}"; @@ -185,7 +189,9 @@ namespace stardew_access.Patches { prevEyeColorHue = currentEyeColorHue; if (currentEyeColorHue != "") toSpeak = $"{toSpeak} \n Hue: {currentEyeColorHue}"; - } else { + } + else + { prevEyeColorHue = ""; } } @@ -197,7 +203,9 @@ namespace stardew_access.Patches { prevEyeColorSaturation = currentEyeColorSaturation; if (currentEyeColorSaturation != "") toSpeak = $"{toSpeak} \n Saturation: {currentEyeColorSaturation}"; - } else { + } + else + { prevEyeColorSaturation = ""; } } @@ -209,7 +217,9 @@ namespace stardew_access.Patches { prevEyeColorValue = currentEyeColorValue; if (currentEyeColorValue != "") toSpeak = $"{toSpeak} \n Value: {currentEyeColorValue}"; - } else { + } + else + { prevEyeColorValue = ""; } } @@ -231,7 +241,9 @@ namespace stardew_access.Patches { prevHairColorHue = currentHairColorHue; if (currentHairColorHue != "") toSpeak = $"{toSpeak} \n Hue: {currentHairColorHue}"; - } else { + } + else + { prevHairColorHue = ""; } } @@ -243,7 +255,9 @@ namespace stardew_access.Patches { prevHairColorSaturation = currentHairColorSaturation; if (currentHairColorSaturation != "") toSpeak = $"{toSpeak} \n Saturation: {currentHairColorSaturation}"; - } else { + } + else + { prevHairColorSaturation = ""; } } @@ -255,7 +269,9 @@ namespace stardew_access.Patches { prevHairColorValue = currentHairColorValue; if (currentHairColorValue != "") toSpeak = $"{toSpeak} \n Value: {currentHairColorValue}"; - } else { + } + else + { prevHairColorValue = ""; } } @@ -277,7 +293,9 @@ namespace stardew_access.Patches { prevPantsColorHue = currentPantsColorHue; if (currentPantsColorHue != "") toSpeak = $"{toSpeak} \n Hue: {currentPantsColorHue}"; - } else { + } + else + { prevPantsColorHue = ""; } } @@ -289,7 +307,9 @@ namespace stardew_access.Patches { prevPantsColorSaturation = currentPantsColorSaturation; if (currentPantsColorSaturation != "") toSpeak = $"{toSpeak} \n Saturation: {currentPantsColorSaturation}"; - } else { + } + else + { prevPantsColorSaturation = ""; } } @@ -301,7 +321,9 @@ namespace stardew_access.Patches { prevPantsColorValue = currentPantsColorValue; if (currentPantsColorValue != "") toSpeak = $"{toSpeak} \n Value: {currentPantsColorValue}"; - } else { + } + else + { prevPantsColorValue = ""; } } @@ -320,13 +342,12 @@ namespace stardew_access.Patches { if (prevPetName != currentPetName) { prevPetName = currentPetName; - if (currentPetName != "") + if (currentPetName != "") toSpeak = $"{toSpeak} \n Current Pet: {currentPetName}"; } return toSpeak.Trim(); } - private static string CycleThroughItems(bool increase, CharacterCustomization __instance, bool ___skipIntro, ClickableComponent ___startingCabinsLabel, ClickableComponent ___difficultyModifierLabel, TextBox ___nameBox, TextBox ___farmnameBox, TextBox ___favThingBox) @@ -344,7 +365,9 @@ namespace stardew_access.Patches { if (___nameBox.Text != "") { postText = $": {___nameBox.Text}"; - } else { + } + else + { postText = " Text Box"; } buttons.Add(__instance.nameBoxCC, $"Farmer's Name{postText}"); @@ -355,7 +378,9 @@ namespace stardew_access.Patches { if (___farmnameBox.Text != "") { postText = $": {___farmnameBox.Text}"; - } else { + } + else + { postText = " Text Box"; } buttons.Add(__instance.farmnameBoxCC, $"Farm's Name{postText}"); @@ -366,7 +391,9 @@ namespace stardew_access.Patches { if (___favThingBox.Text != "") { postText = $": {___favThingBox.Text}"; - } else { + } + else + { postText = " Text Box"; } buttons.Add(__instance.favThingBoxCC, $"Favourite Thing{postText}"); @@ -386,10 +413,10 @@ namespace stardew_access.Patches { // Controls to rotate the farmer (Potentially useful for low vision players) are first if they're available. // They also appear above the gender buttons, so we handle them separately here. - if (characterDesignToggle && new[] {__instance.leftSelectionButtons.Count, __instance.rightSelectionButtons.Count }.All(c => c >= 0)) // both have Count > 0 + if (characterDesignToggle && new[] { __instance.leftSelectionButtons.Count, __instance.rightSelectionButtons.Count }.All(c => c >= 0)) // both have Count > 0 { - if (new[] {__instance.leftSelectionButtons[DesignControlsIndex].visible, __instance.rightSelectionButtons[DesignControlsIndex].visible }.All(v => v == true) // both visible - && new[] {__instance.leftSelectionButtons[DesignControlsIndex].name, __instance.rightSelectionButtons[DesignControlsIndex].name }.All(n => n == "Direction")) // both named "Direction" + if (new[] { __instance.leftSelectionButtons[DesignControlsIndex].visible, __instance.rightSelectionButtons[DesignControlsIndex].visible }.All(v => v == true) // both visible + && new[] { __instance.leftSelectionButtons[DesignControlsIndex].name, __instance.rightSelectionButtons[DesignControlsIndex].name }.All(n => n == "Direction")) // both named "Direction" { buttons.Add(__instance.leftSelectionButtons[DesignControlsIndex], "Rotate Left Button"); buttons.Add(__instance.rightSelectionButtons[DesignControlsIndex], "Rotate Right Button"); @@ -403,9 +430,9 @@ namespace stardew_access.Patches { buttons.Add(__instance.genderButtons[1], ((!Game1.player.IsMale) ? "Selected " : "") + "Gender: Female Button"); } - if (characterDesignToggle&& new[] {__instance.leftSelectionButtons.Count, __instance.rightSelectionButtons.Count }.All(c => c >= DesignControlsIndex) && new[] {__instance.leftSelectionButtons[DesignControlsIndex].visible, __instance.rightSelectionButtons[DesignControlsIndex].visible }.All(v => v == true)) + if (characterDesignToggle && new[] { __instance.leftSelectionButtons.Count, __instance.rightSelectionButtons.Count }.All(c => c >= DesignControlsIndex) && new[] { __instance.leftSelectionButtons[DesignControlsIndex].visible, __instance.rightSelectionButtons[DesignControlsIndex].visible }.All(v => v == true)) { - while(DesignControlsIndex < __instance.leftSelectionButtons.Count) + while (DesignControlsIndex < __instance.leftSelectionButtons.Count) { ClickableComponent left = __instance.leftSelectionButtons[DesignControlsIndex]; ClickableComponent right = __instance.rightSelectionButtons[DesignControlsIndex]; @@ -549,7 +576,7 @@ namespace stardew_access.Patches { } currentComponent = buttons.ElementAt(saveGameIndex).Key; - currentComponent!.snapMouseCursor(); + currentComponent!.snapMouseCursor(); __instance.setCurrentlySnappedComponentTo(currentComponent!.myID); toSpeak = buttons.ElementAt(saveGameIndex).Value; @@ -630,16 +657,18 @@ namespace stardew_access.Patches { break; } return sb; - } else { + } + else + { return null; } } - private static void AdjustCurrentSlider(bool increase, CharacterCustomization __instance, int amount=1) + private static void AdjustCurrentSlider(bool increase, CharacterCustomization __instance, int amount = 1) { if (currentComponent != null && currentComponent.myID >= 522 && currentComponent.myID <= 530) { - SliderBar sb = getCurrentSliderBar(currentComponent.myID, __instance) !; + SliderBar sb = getCurrentSliderBar(currentComponent.myID, __instance)!; if (sb != null) { double step = ((double)sb.bounds.Width / 100d); // size of 1% change in slider value @@ -650,7 +679,9 @@ namespace stardew_access.Patches { { value = Math.Min(value + amount, 99d); x = Math.Min(Math.Ceiling((value * step)), (double)sb.bounds.Width); - } else { + } + else + { value = Math.Max(value - amount, 0d); x = Math.Max(Math.Ceiling((value * step)), 0d); } @@ -796,7 +827,9 @@ namespace stardew_access.Patches { if (currentComponent != null && currentComponent.name == "Pet") { return ((Game1.player.catPerson) ? "Cat" : "Dog") + " Breed: " + Game1.player.whichPetBreed; - } else { + } + else + { return ""; } } From 8059e09089c7a588f2238de9b77136afd3eaa0c4 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 22 Feb 2023 17:45:59 +0530 Subject: [PATCH 19/61] Used a different method to detect if any text box is active or not This fixes the issue when more than one text boxes are present in a menu --- stardew-access/ModEntry.cs | 6 ++---- stardew-access/Patches/BuildingNAnimalMenuPatches.cs | 4 ++-- .../Patches/CharacterCustomizationMenuPatches.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 3 ++- stardew-access/Patches/TextBoxPatch.cs | 7 +++++-- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index 658db41..def28d6 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -30,8 +30,6 @@ namespace stardew_access internal static ModConfig Config { get => config; set => config = value; } public static IModHelper? ModHelper { get => modHelper; } - public static bool isAnyTextBoxActive = false; - public static StaticTiles STiles { get @@ -212,7 +210,7 @@ namespace stardew_access return; #region Simulate left and right clicks - if (Game1.activeClickableMenu != null && !isAnyTextBoxActive) + if (Game1.activeClickableMenu != null && !TextBoxPatch.isAnyTextBoxActive) { bool isCustomizingCharacter = Game1.activeClickableMenu is CharacterCustomization || (TitleMenu.subMenu != null && TitleMenu.subMenu is CharacterCustomization); @@ -229,7 +227,7 @@ namespace stardew_access #endregion } - if (Game1.currentMinigame != null && !isAnyTextBoxActive) + if (Game1.currentMinigame != null && !TextBoxPatch.isAnyTextBoxActive) { #region Mouse Click Simulation if (Config.LeftClickMainKey.JustPressed() || Config.LeftClickAlternateKey.JustPressed()) diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs index 174f6f3..352011f 100644 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs @@ -27,7 +27,7 @@ namespace stardew_access.Patches { try { - if (MainClass.isAnyTextBoxActive) return; + if (TextBoxPatch.isAnyTextBoxActive) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details @@ -91,7 +91,7 @@ namespace stardew_access.Patches { try { - if (MainClass.isAnyTextBoxActive) return; + if (TextBoxPatch.isAnyTextBoxActive) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position purchaseAnimalsMenu = __instance; diff --git a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs b/stardew-access/Patches/CharacterCustomizationMenuPatches.cs index 96852ff..fa3e13f 100644 --- a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs +++ b/stardew-access/Patches/CharacterCustomizationMenuPatches.cs @@ -36,7 +36,7 @@ namespace stardew_access.Patches { try { - if (MainClass.isAnyTextBoxActive) return; + if (TextBoxPatch.isAnyTextBoxActive) return; bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box string toSpeak = ""; diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 6e70087..5625593 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -426,7 +426,7 @@ namespace stardew_access.Patches ___textBox.Selected = false; } - if (MainClass.isAnyTextBoxActive) return; + if (TextBoxPatch.isAnyTextBoxActive) return; string toSpeak = ""; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position @@ -729,6 +729,7 @@ namespace stardew_access.Patches InventoryUtils.hoveredItemQueryKey = ""; InventoryUtils.prevSlotIndex = -999; + TextBoxPatch.activeTextBoxes = ""; } #endregion diff --git a/stardew-access/Patches/TextBoxPatch.cs b/stardew-access/Patches/TextBoxPatch.cs index eddc5e4..cc3de3e 100644 --- a/stardew-access/Patches/TextBoxPatch.cs +++ b/stardew-access/Patches/TextBoxPatch.cs @@ -3,18 +3,21 @@ namespace stardew_access.Patches internal class TextBoxPatch { internal static string textBoxQuery = " "; + internal static string activeTextBoxes = ""; + internal static bool isAnyTextBoxActive => activeTextBoxes != ""; internal static void DrawPatch(StardewValley.Menus.TextBox __instance) { try { + string uniqueIdentifier = $"{__instance.X}:{__instance.Y}:{__instance.Height}:{__instance.Width}"; if (!__instance.Selected) { - MainClass.isAnyTextBoxActive = false; + if (activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes = activeTextBoxes.Replace(uniqueIdentifier, ""); return; } - MainClass.isAnyTextBoxActive = true; + if (!activeTextBoxes.Contains(uniqueIdentifier)) activeTextBoxes += uniqueIdentifier; bool isEscPressed = StardewValley.Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); string toSpeak = __instance.Text; From 8b0350497bf7a3d92fa141e86045142f83995a11 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 22 Feb 2023 17:59:11 +0530 Subject: [PATCH 20/61] Refactored code --- stardew-access/HarmonyPatches.cs | 7 +- stardew-access/Patches/IClickableMenuPatch.cs | 123 ++++++++++++++++++ stardew-access/Patches/MenuPatches.cs | 119 +---------------- 3 files changed, 130 insertions(+), 119 deletions(-) create mode 100644 stardew-access/Patches/IClickableMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 056999f..eb0fa7e 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -225,7 +225,7 @@ namespace stardew_access #region On Menu CLose Patch harmony.Patch( original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.IClickableMenuOnExitPatch)) + postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.ExitThisMenuPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.exitActiveMenu)), @@ -290,6 +290,11 @@ namespace stardew_access original: AccessTools.Method(typeof(TextBox), nameof(TextBox.Draw)), prefix: new HarmonyMethod(typeof(TextBoxPatch), nameof(TextBoxPatch.DrawPatch)) ); + + harmony.Patch( + original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.draw)), + prefix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.DrawPatch)) + ); } } } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs new file mode 100644 index 0000000..1a3992a --- /dev/null +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -0,0 +1,123 @@ +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + // These patches are global, i.e. work on every menus + internal class IClickableMenuPatch + { + internal static void ExitThisMenuPatch(IClickableMenu __instance) + { + try + { + Cleanup(__instance); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup(IClickableMenu menu) + { + if (menu is LetterViewerMenu) + { + DialoguePatches.currentLetterText = " "; + } + else if (menu is LevelUpMenu) + { + MenuPatches.currentLevelUpTitle = " "; + } + else if (menu is Billboard) + { + QuestPatches.currentDailyQuestText = " "; + } + else if (menu is GameMenu) + { + GameMenuPatches.gameMenuQueryKey = ""; + GameMenuPatches.craftingPageQueryKey = ""; + GameMenuPatches.inventoryPageQueryKey = ""; + GameMenuPatches.exitPageQueryKey = ""; + GameMenuPatches.optionsPageQueryKey = ""; + GameMenuPatches.socialPageQuery = ""; + GameMenuPatches.currentSelectedCraftingRecipe = -1; + GameMenuPatches.isSelectingRecipe = false; + } + else if (menu is JunimoNoteMenu) + { + BundleMenuPatches.currentIngredientListItem = -1; + BundleMenuPatches.currentIngredientInputSlot = -1; + BundleMenuPatches.currentInventorySlot = -1; + BundleMenuPatches.junimoNoteMenuQuery = ""; + } + else if (menu is ShopMenu) + { + GameMenuPatches.shopMenuQueryKey = ""; + } + else if (menu is ItemGrabMenu) + { + GameMenuPatches.itemGrabMenuQueryKey = ""; + } + else if (menu is GeodeMenu) + { + GameMenuPatches.geodeMenuQueryKey = ""; + } + else if (menu is CarpenterMenu) + { + BuildingNAnimalMenuPatches.carpenterMenuQuery = ""; + BuildingNAnimalMenuPatches.isUpgrading = false; + BuildingNAnimalMenuPatches.isDemolishing = false; + BuildingNAnimalMenuPatches.isPainting = false; + BuildingNAnimalMenuPatches.isMoving = false; + BuildingNAnimalMenuPatches.isConstructing = false; + BuildingNAnimalMenuPatches.carpenterMenu = null; + } + else if (menu is PurchaseAnimalsMenu) + { + BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = ""; + BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true; + BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null; + } + else if (menu is DialogueBox) + { + DialoguePatches.isDialogueAppearingFirstTime = true; + DialoguePatches.currentDialogue = " "; + } + else if (menu is JojaCDMenu) + { + BundleMenuPatches.jojaCDMenuQuery = ""; + } + else if (menu is QuestLog) + { + QuestPatches.questLogQuery = " "; + } + else if (menu is TailoringMenu) + { + MenuPatches.tailoringMenuQuery = " "; + } + else if (menu is ForgeMenu) + { + MenuPatches.forgeMenuQuery = " "; + } + else if (menu is ItemListMenu) + { + MenuPatches.itemListMenuQuery = " "; + } + else if (menu is FieldOfficeMenu) + { + DonationMenuPatches.fieldOfficeMenuQuery = " "; + } + else if (menu is MuseumMenu) + { + DonationMenuPatches.museumQueryKey = " "; + } + else if (menu is PondQueryMenu) + { + MenuPatches.pondQueryMenuQuery = " "; + } + + InventoryUtils.hoveredItemQueryKey = ""; + InventoryUtils.prevSlotIndex = -999; + TextBoxPatch.activeTextBoxes = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 5625593..2576c40 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -604,12 +604,11 @@ namespace stardew_access.Patches } } - #region Cleanup on exitting a menu internal static void Game1ExitActiveMenuPatch() { try { - Cleanup(Game1.activeClickableMenu); + IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); } catch (Exception e) { @@ -617,122 +616,6 @@ namespace stardew_access.Patches } } - internal static void IClickableMenuOnExitPatch(IClickableMenu __instance) - { - try - { - Cleanup(__instance); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static void Cleanup(IClickableMenu menu) - { - if (menu is LetterViewerMenu) - { - DialoguePatches.currentLetterText = " "; - } - else if (menu is LevelUpMenu) - { - currentLevelUpTitle = " "; - } - else if (menu is Billboard) - { - QuestPatches.currentDailyQuestText = " "; - } - else if (menu is GameMenu) - { - GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.craftingPageQueryKey = ""; - GameMenuPatches.inventoryPageQueryKey = ""; - GameMenuPatches.exitPageQueryKey = ""; - GameMenuPatches.optionsPageQueryKey = ""; - GameMenuPatches.socialPageQuery = ""; - GameMenuPatches.currentSelectedCraftingRecipe = -1; - GameMenuPatches.isSelectingRecipe = false; - } - else if (menu is JunimoNoteMenu) - { - BundleMenuPatches.currentIngredientListItem = -1; - BundleMenuPatches.currentIngredientInputSlot = -1; - BundleMenuPatches.currentInventorySlot = -1; - BundleMenuPatches.junimoNoteMenuQuery = ""; - } - else if (menu is ShopMenu) - { - GameMenuPatches.shopMenuQueryKey = ""; - } - else if (menu is ItemGrabMenu) - { - GameMenuPatches.itemGrabMenuQueryKey = ""; - } - else if (menu is GeodeMenu) - { - GameMenuPatches.geodeMenuQueryKey = ""; - } - else if (menu is CarpenterMenu) - { - BuildingNAnimalMenuPatches.carpenterMenuQuery = ""; - BuildingNAnimalMenuPatches.isUpgrading = false; - BuildingNAnimalMenuPatches.isDemolishing = false; - BuildingNAnimalMenuPatches.isPainting = false; - BuildingNAnimalMenuPatches.isMoving = false; - BuildingNAnimalMenuPatches.isConstructing = false; - BuildingNAnimalMenuPatches.carpenterMenu = null; - } - else if (menu is PurchaseAnimalsMenu) - { - BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = ""; - BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true; - BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null; - } - else if (menu is DialogueBox) - { - DialoguePatches.isDialogueAppearingFirstTime = true; - DialoguePatches.currentDialogue = " "; - } - else if (menu is JojaCDMenu) - { - BundleMenuPatches.jojaCDMenuQuery = ""; - } - else if (menu is QuestLog) - { - QuestPatches.questLogQuery = " "; - } - else if (menu is TailoringMenu) - { - tailoringMenuQuery = " "; - } - else if (menu is ForgeMenu) - { - forgeMenuQuery = " "; - } - else if (menu is ItemListMenu) - { - itemListMenuQuery = " "; - } - else if (menu is FieldOfficeMenu) - { - DonationMenuPatches.fieldOfficeMenuQuery = " "; - } - else if (menu is MuseumMenu) - { - DonationMenuPatches.museumQueryKey = " "; - } - else if (menu is PondQueryMenu) - { - pondQueryMenuQuery = " "; - } - - InventoryUtils.hoveredItemQueryKey = ""; - InventoryUtils.prevSlotIndex = -999; - TextBoxPatch.activeTextBoxes = ""; - } - #endregion - internal static void ExitEventPatch() { if (MainClass.ScreenReader != null) From ac190f593910021e3f1296e8dc56a8023766e1cf Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 22 Feb 2023 18:09:43 +0530 Subject: [PATCH 21/61] Bug fix --- stardew-access/HarmonyPatches.cs | 5 ----- stardew-access/Patches/TitleMenuPatches.cs | 1 - 2 files changed, 6 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index eb0fa7e..bf570f2 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -290,11 +290,6 @@ namespace stardew_access original: AccessTools.Method(typeof(TextBox), nameof(TextBox.Draw)), prefix: new HarmonyMethod(typeof(TextBoxPatch), nameof(TextBoxPatch.DrawPatch)) ); - - harmony.Patch( - original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.draw)), - prefix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.DrawPatch)) - ); } } } diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs index 0a17870..af8cba3 100644 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches.cs @@ -6,7 +6,6 @@ namespace stardew_access.Patches { internal class TitleMenuPatches { - private static bool isRunning = false; public static string advancedGameOptionsQueryKey = " "; internal static void AdvancedGameOptionsPatch(AdvancedGameOptions __instance) From 6d3962ea4d56002c529ee331c711068f9bba2925 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 23 Feb 2023 21:41:05 +0530 Subject: [PATCH 22/61] Refactored code BuildingNAnimalMenuPatches.cs --- stardew-access/CustomCommands.cs | 39 +- stardew-access/Features/BuildingOperations.cs | 366 +++++++++ stardew-access/HarmonyPatches.cs | 6 +- stardew-access/ModEntry.cs | 8 +- .../Patches/AnimalQueryMenuPatch.cs | 78 ++ .../Patches/BuildingNAnimalMenuPatches.cs | 705 ------------------ stardew-access/Patches/CarpenterMenuPach.cs | 195 +++++ stardew-access/Patches/IClickableMenuPatch.cs | 25 +- .../Patches/PurchaseAnimalsMenuPatch.cs | 101 +++ 9 files changed, 782 insertions(+), 741 deletions(-) create mode 100644 stardew-access/Features/BuildingOperations.cs create mode 100644 stardew-access/Patches/AnimalQueryMenuPatch.cs delete mode 100644 stardew-access/Patches/BuildingNAnimalMenuPatches.cs create mode 100644 stardew-access/Patches/CarpenterMenuPach.cs create mode 100644 stardew-access/Patches/PurchaseAnimalsMenuPatch.cs diff --git a/stardew-access/CustomCommands.cs b/stardew-access/CustomCommands.cs index 557d7bf..8d10fc2 100644 --- a/stardew-access/CustomCommands.cs +++ b/stardew-access/CustomCommands.cs @@ -1,4 +1,5 @@ using Microsoft.Xna.Framework; +using stardew_access.Features; using stardew_access.Patches; using StardewModdingAPI; using StardewValley; @@ -327,18 +328,18 @@ namespace stardew_access return; } - BuildingNAnimalMenuPatches.marked[index] = new Vector2((int)Game1.player.getTileX(), (int)Game1.player.getTileY()); + BuildingOperations.marked[index] = new Vector2((int)Game1.player.getTileX(), (int)Game1.player.getTileY()); MainClass.InfoLog($"Location {(int)Game1.player.getTileX()}x {(int)Game1.player.getTileY()}y added at {index} index."); }); helper.ConsoleCommands.Add("marklist", "List all marked positions.", (string commmand, string[] args) => { string toPrint = ""; - for (int i = 0; i < BuildingNAnimalMenuPatches.marked.Length; i++) + for (int i = 0; i < BuildingOperations.marked.Length; i++) { - if (BuildingNAnimalMenuPatches.marked[i] != Vector2.Zero) + if (BuildingOperations.marked[i] != Vector2.Zero) { - toPrint = $"{toPrint}\n Index {i}: {BuildingNAnimalMenuPatches.marked[i].X}x {BuildingNAnimalMenuPatches.marked[i].Y}y"; + toPrint = $"{toPrint}\n Index {i}: {BuildingOperations.marked[i].X}x {BuildingOperations.marked[i].Y}y"; } } @@ -355,7 +356,7 @@ namespace stardew_access helper.ConsoleCommands.Add("buildsel", "Select the building index which you want to upgrade/demolish/paint", (string commmand, string[] args) => { - if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu && Game1.activeClickableMenu is not AnimalQueryMenu) || !BuildingNAnimalMenuPatches.isOnFarm) + if ((Game1.activeClickableMenu is not CarpenterMenu && Game1.activeClickableMenu is not PurchaseAnimalsMenu && Game1.activeClickableMenu is not AnimalQueryMenu) || !CarpenterMenuPatch.isOnFarm) { MainClass.InfoLog($"Cannot select building."); return; @@ -380,12 +381,12 @@ namespace stardew_access string? positionIndexInString = args.ElementAtOrDefault(1); int positionIndex = 0; - if (BuildingNAnimalMenuPatches.isMoving) + if (CarpenterMenuPatch.isMoving) { - if (BuildingNAnimalMenuPatches.isConstructing || BuildingNAnimalMenuPatches.isMoving) + if (CarpenterMenuPatch.isConstructing || CarpenterMenuPatch.isMoving) { - if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) + if (BuildingOperations.availableBuildings[index] == null) { MainClass.InfoLog($"No building found with index {index}. Use buildlist."); return; @@ -406,9 +407,9 @@ namespace stardew_access } } } - else if (BuildingNAnimalMenuPatches.isConstructing && !BuildingNAnimalMenuPatches.isUpgrading) + else if (CarpenterMenuPatch.isConstructing && !CarpenterMenuPatch.isUpgrading) { - if (BuildingNAnimalMenuPatches.marked[index] == Vector2.Zero) + if (BuildingOperations.marked[index] == Vector2.Zero) { MainClass.InfoLog($"No marked position found at {index} index."); return; @@ -416,7 +417,7 @@ namespace stardew_access } else { - if (BuildingNAnimalMenuPatches.availableBuildings[index] == null) + if (BuildingOperations.availableBuildings[index] == null) { MainClass.InfoLog($"No building found with index {index}. Use buildlist."); return; @@ -427,19 +428,19 @@ namespace stardew_access if (Game1.activeClickableMenu is PurchaseAnimalsMenu) { - BuildingNAnimalMenuPatches.PurchaseAnimal(BuildingNAnimalMenuPatches.availableBuildings[index]); + BuildingOperations.PurchaseAnimal(BuildingOperations.availableBuildings[index]); } else if (Game1.activeClickableMenu is AnimalQueryMenu) { - BuildingNAnimalMenuPatches.MoveAnimal(BuildingNAnimalMenuPatches.availableBuildings[index]); + BuildingOperations.MoveAnimal(BuildingOperations.availableBuildings[index]); } else { - if (BuildingNAnimalMenuPatches.isConstructing && !BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Contstruct(BuildingNAnimalMenuPatches.marked[index]); } - else if (BuildingNAnimalMenuPatches.isMoving) { response = BuildingNAnimalMenuPatches.Move(BuildingNAnimalMenuPatches.availableBuildings[index], BuildingNAnimalMenuPatches.marked[positionIndex]); } - else if (BuildingNAnimalMenuPatches.isDemolishing) { response = BuildingNAnimalMenuPatches.Demolish(BuildingNAnimalMenuPatches.availableBuildings[index]); } - else if (BuildingNAnimalMenuPatches.isUpgrading) { response = BuildingNAnimalMenuPatches.Upgrade(BuildingNAnimalMenuPatches.availableBuildings[index]); } - else if (BuildingNAnimalMenuPatches.isPainting) { response = BuildingNAnimalMenuPatches.Paint(BuildingNAnimalMenuPatches.availableBuildings[index]); } + if (CarpenterMenuPatch.isConstructing && !CarpenterMenuPatch.isUpgrading) { response = BuildingOperations.Contstruct(BuildingOperations.marked[index]); } + else if (CarpenterMenuPatch.isMoving) { response = BuildingOperations.Move(BuildingOperations.availableBuildings[index], BuildingOperations.marked[positionIndex]); } + else if (CarpenterMenuPatch.isDemolishing) { response = BuildingOperations.Demolish(BuildingOperations.availableBuildings[index]); } + else if (CarpenterMenuPatch.isUpgrading) { response = BuildingOperations.Upgrade(BuildingOperations.availableBuildings[index]); } + else if (CarpenterMenuPatch.isPainting) { response = BuildingOperations.Paint(BuildingOperations.availableBuildings[index]); } } if (response != null) @@ -517,7 +518,7 @@ namespace stardew_access string? name = buildings[i].nameOfIndoorsWithoutUnique; name = (name == "null") ? buildings[i].buildingType.Value : name; - BuildingNAnimalMenuPatches.availableBuildings[buildingIndex] = buildings[i]; + BuildingOperations.availableBuildings[buildingIndex] = buildings[i]; toPrint = $"{toPrint}\nIndex {buildingIndex}: {name}: At {buildings[i].tileX}x and {buildings[i].tileY}y"; ++buildingIndex; } diff --git a/stardew-access/Features/BuildingOperations.cs b/stardew-access/Features/BuildingOperations.cs new file mode 100644 index 0000000..f970ba3 --- /dev/null +++ b/stardew-access/Features/BuildingOperations.cs @@ -0,0 +1,366 @@ +using Microsoft.Xna.Framework; +using stardew_access.Patches; +using StardewValley; +using StardewValley.Buildings; +using StardewValley.Locations; +using StardewValley.Objects; + +namespace stardew_access.Features +{ + internal class BuildingOperations + { + internal static Building?[] availableBuildings = new Building[100]; + internal static Vector2[] marked = new Vector2[10]; + + public static string? Demolish(Building? toDemolish) + { + if (toDemolish == null) + return null; + + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::654) + Farm farm = (Farm)Game1.getLocationFromName("Farm"); + Action buildingLockFailed = delegate + { + if (CarpenterMenuPatch.isDemolishing) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); + } + }; + Action continueDemolish = delegate + { + if (CarpenterMenuPatch.isDemolishing && toDemolish != null && farm.buildings.Contains(toDemolish)) + { + if ((int)toDemolish.daysOfConstructionLeft.Value > 0 || (int)toDemolish.daysUntilUpgrade.Value > 0) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction"); + } + else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is AnimalHouse && ((AnimalHouse)toDemolish.indoors.Value).animalsThatLiveHere.Count > 0) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere"); + } + else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value.farmers.Any()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); + } + else + { + if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin) + { + foreach (Farmer current in Game1.getAllFarmers()) + { + if (current.currentLocation != null && current.currentLocation.Name == ((Cabin)toDemolish.indoors.Value).GetCellarName()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); + return; + } + } + } + if (toDemolish.indoors.Value is Cabin && ((Cabin)toDemolish.indoors.Value).farmhand.Value.isActive()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_FarmhandOnline"); + } + else + { + toDemolish.BeforeDemolish(); + Chest? chest = null; + if (toDemolish.indoors.Value is Cabin) + { + List list = ((Cabin)toDemolish.indoors.Value).demolish(); + if (list.Count > 0) + { + chest = new Chest(playerChest: true); + chest.fixLidFrame(); + chest.items.Set(list); + } + } + if (farm.destroyStructure(toDemolish)) + { + _ = (int)toDemolish.tileY.Value; + _ = (int)toDemolish.tilesHigh.Value; + Game1.flashAlpha = 1f; + toDemolish.showDestroyedAnimation(Game1.getFarm()); + Game1.playSound("explosion"); + Utility.spreadAnimalsAround(toDemolish, farm); + if (CarpenterMenuPatch.carpenterMenu != null) + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenu, 1500); + // freeze = true; + if (chest != null) + { + farm.objects[new Vector2((int)toDemolish.tileX.Value + (int)toDemolish.tilesWide.Value / 2, (int)toDemolish.tileY.Value + (int)toDemolish.tilesHigh.Value / 2)] = chest; + } + } + } + } + } + }; + if (toDemolish != null) + { + if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin && !Game1.IsMasterGame) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); + toDemolish = null; + return response; + } + if (CarpenterMenuPatch.carpenterMenu != null && !CarpenterMenuPatch.carpenterMenu.CanDemolishThis(toDemolish)) + { + toDemolish = null; + return response; + } + if (CarpenterMenuPatch.carpenterMenu != null && !Game1.IsMasterGame && !CarpenterMenuPatch.carpenterMenu.hasPermissionsToDemolish(toDemolish)) + { + toDemolish = null; + return response; + } + } + if (toDemolish != null && toDemolish.indoors.Value is Cabin) + { + Cabin cabin = (Cabin)toDemolish.indoors.Value; + if (cabin.farmhand.Value != null && (bool)cabin.farmhand.Value.isCustomized.Value) + { + Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\UI:Carpenter_DemolishCabinConfirm", cabin.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), delegate (Farmer f, string answer) + { + if (answer == "Yes") + { + Game1.activeClickableMenu = CarpenterMenuPatch.carpenterMenu; + Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); + } + else + { + if (CarpenterMenuPatch.carpenterMenu != null) + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenu, 1000); + } + }); + return response; + } + } + if (toDemolish != null) + { + Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); + } + + return response; + } + + public static string? Contstruct(Vector2 position) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::874) + Game1.player.team.buildLock.RequestLock(delegate + { + if (CarpenterMenuPatch.isOnFarm && Game1.locationRequest == null) + { + if (tryToBuild(position)) + { + if (CarpenterMenuPatch.carpenterMenu != null) + { + CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.consumeResources(); + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 2000); + } + // freeze = true; + } + else + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantBuild"); + } + } + Game1.player.team.buildLock.ReleaseLock(); + }); + + return response; + } + + public static bool tryToBuild(Vector2 position) + { + if (CarpenterMenuPatch.carpenterMenu == null) + return false; + return ((Farm)Game1.getLocationFromName("Farm")).buildStructure(CarpenterMenuPatch.carpenterMenu.CurrentBlueprint, position, Game1.player, CarpenterMenuPatch.isMagicalConstruction); + } + + public static string? Upgrade(Building? toUpgrade) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::775) + if (CarpenterMenuPatch.carpenterMenu != null && toUpgrade != null && CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.name != null && toUpgrade.buildingType.Equals(CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.nameOfBuildingToUpgrade)) + { + CarpenterMenuPatch.carpenterMenu.CurrentBlueprint.consumeResources(); + toUpgrade.daysUntilUpgrade.Value = 2; + toUpgrade.showUpgradeAnimation(Game1.getFarm()); + Game1.playSound("axe"); + DelayedAction.functionAfterDelay(CarpenterMenuPatch.carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 1500); + // freeze = true; + // Game1.multiplayer.globalChatInfoMessage("BuildingBuild", Game1.player.Name, Utility.AOrAn(carpenterMenu.CurrentBlueprint.displayName), carpenterMenu.CurrentBlueprint.displayName, Game1.player.farmName.Value); + } + else if (toUpgrade != null) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CantUpgrade_BuildingType"); + } + return response; + } + + public static string? Paint(Building? toPaint) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::793) + Farm farm_location = Game1.getFarm(); + if (toPaint != null) + { + if (!toPaint.CanBePainted()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); + return response; + } + if (CarpenterMenuPatch.carpenterMenu != null && !CarpenterMenuPatch.carpenterMenu.HasPermissionsToPaint(toPaint)) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); + return response; + } + toPaint.color.Value = Color.White; + + if (CarpenterMenuPatch.carpenterMenu != null) + CarpenterMenuPatch.carpenterMenu.SetChildMenu(new StardewValley.Menus.BuildingPaintMenu(toPaint)); + } + /* TODO Add painting of farm house + else if (farm_location.GetHouseRect().Contains(Utility.Vector2ToPoint(new Vector2(toPaint.tileX, toPaint.tileY)))) + { + if (!carpenterMenu.CanPaintHouse()) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); + } + else if (!carpenterMenu.HasPermissionsToPaint(null)) + { + response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); + } + else + { + carpenterMenu.SetChildMenu(new BuildingPaintMenu("House", () => (farm_location.paintedHouseTexture != null) ? farm_location.paintedHouseTexture : Farm.houseTextures, farm_location.houseSource.Value, farm_location.housePaintColor.Value)); + } + }*/ + return response; + } + + public static string? Move(Building? buildingToMove, Vector2 position) + { + string? response = null; + // This code is taken from the game's code (CarpenterMenu.cs::829) + if (buildingToMove != null) + { + string? name = buildingToMove.nameOfIndoorsWithoutUnique; + name = (name == "null") ? buildingToMove.buildingType.Value : name; + + if ((int)buildingToMove.daysOfConstructionLeft.Value > 0) + { + buildingToMove = null; + return "Building under construction, cannot move"; + } + if (CarpenterMenuPatch.carpenterMenu != null && !CarpenterMenuPatch.carpenterMenu.hasPermissionsToMove(buildingToMove)) + { + buildingToMove = null; + return "You don't have permission to move this building"; + } + Game1.playSound("axchop"); + + if (((Farm)Game1.getLocationFromName("Farm")).buildStructure(buildingToMove, position, Game1.player)) + { + if (buildingToMove is ShippingBin) + { + ((ShippingBin)buildingToMove).initLid(); + } + if (buildingToMove is GreenhouseBuilding) + { + Game1.getFarm().greenhouseMoved.Value = true; + } + buildingToMove.performActionOnBuildingPlacement(); + buildingToMove = null; + Game1.playSound("axchop"); + DelayedAction.playSoundAfterDelay("dirtyHit", 50); + DelayedAction.playSoundAfterDelay("dirtyHit", 150); + + response = $"{buildingToMove} moved to {position.X}x {position.Y}y"; + } + else + { + Game1.playSound("cancel"); + response = $"Cannot move building to {position.X}x {position.Y}y"; + } + + } + + return response; + } + + public static void PurchaseAnimal(Building? selection) + { + if (selection == null) + return; + + if (PurchaseAnimalsMenuPatch.purchaseAnimalsMenu == null) + return; + + int x = (selection.tileX.Value * Game1.tileSize) - Game1.viewport.X; + int y = (selection.tileY.Value * Game1.tileSize) - Game1.viewport.Y; + + if (PurchaseAnimalsMenuPatch.animalBeingPurchased != null && !selection.buildingType.Value.Contains(PurchaseAnimalsMenuPatch.animalBeingPurchased.buildingTypeILiveIn.Value)) + { + string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", PurchaseAnimalsMenuPatch.animalBeingPurchased.displayType); + MainClass.ScreenReader.Say(warn, true); + return; + } + + if (((AnimalHouse)selection.indoors.Value).isFull()) + { + string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321"); + MainClass.ScreenReader.Say(warn, true); + return; + } + + PurchaseAnimalsMenuPatch.purchaseAnimalsMenu.receiveLeftClick(x, y); + } + + public static void MoveAnimal(Building? selection) + { + if (selection == null) + return; + + if (AnimalQueryMenuPatch.animalQueryMenu == null) + return; + + if (AnimalQueryMenuPatch.animalBeingMoved == null) + return; + + // The following code is taken from the game's source code [AnimalQueryMenu.cs::receiveLeftClick] + if (selection.buildingType.Value.Contains(AnimalQueryMenuPatch.animalBeingMoved.buildingTypeILiveIn.Value)) + { + if (((AnimalHouse)selection.indoors.Value).isFull()) + { + string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_BuildingFull"); + MainClass.ScreenReader.Say(warn, true); + return; + } + if (selection.Equals(AnimalQueryMenuPatch.animalBeingMoved.home)) + { + string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_AlreadyHome"); + MainClass.ScreenReader.Say(warn, true); + return; + } + ((AnimalHouse)AnimalQueryMenuPatch.animalBeingMoved.home.indoors.Value).animalsThatLiveHere.Remove(AnimalQueryMenuPatch.animalBeingMoved.myID.Value); + if (((AnimalHouse)AnimalQueryMenuPatch.animalBeingMoved.home.indoors.Value).animals.ContainsKey(AnimalQueryMenuPatch.animalBeingMoved.myID.Value)) + { + ((AnimalHouse)selection.indoors.Value).animals.Add(AnimalQueryMenuPatch.animalBeingMoved.myID.Value, AnimalQueryMenuPatch.animalBeingMoved); + ((AnimalHouse)AnimalQueryMenuPatch.animalBeingMoved.home.indoors.Value).animals.Remove(AnimalQueryMenuPatch.animalBeingMoved.myID.Value); + } + AnimalQueryMenuPatch.animalBeingMoved.home = selection; + AnimalQueryMenuPatch.animalBeingMoved.homeLocation.Value = new Vector2((int)selection.tileX.Value, (int)selection.tileY.Value); + ((AnimalHouse)selection.indoors.Value).animalsThatLiveHere.Add(AnimalQueryMenuPatch.animalBeingMoved.myID.Value); + AnimalQueryMenuPatch.animalBeingMoved.makeSound(); + Game1.globalFadeToBlack(AnimalQueryMenuPatch.animalQueryMenu.finishedPlacingAnimal); + } + else + { + string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_CantLiveThere"); + MainClass.ScreenReader.Say(warn, true); + } + return; + } + } +} diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index bf570f2..72475db 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -237,17 +237,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CarpenterMenu), nameof(CarpenterMenu.draw), new Type[] { typeof(SpriteBatch) }), - prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.CarpenterMenuPatch)) + prefix: new HarmonyMethod(typeof(CarpenterMenuPatch), nameof(CarpenterMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(PurchaseAnimalsMenu), nameof(PurchaseAnimalsMenu.draw), new Type[] { typeof(SpriteBatch) }), - prefix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.PurchaseAnimalsMenuPatch)) + prefix: new HarmonyMethod(typeof(PurchaseAnimalsMenuPatch), nameof(PurchaseAnimalsMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(AnimalQueryMenu), nameof(AnimalQueryMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(BuildingNAnimalMenuPatches), nameof(BuildingNAnimalMenuPatches.AnimalQueryMenuPatch)) + postfix: new HarmonyMethod(typeof(AnimalQueryMenuPatch), nameof(AnimalQueryMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/ModEntry.cs b/stardew-access/ModEntry.cs index def28d6..1830c50 100644 --- a/stardew-access/ModEntry.cs +++ b/stardew-access/ModEntry.cs @@ -128,14 +128,14 @@ namespace stardew_access HarmonyPatches.Initialize(harmony); //Initialize marked locations - for (int i = 0; i < BuildingNAnimalMenuPatches.marked.Length; i++) + for (int i = 0; i < BuildingOperations.marked.Length; i++) { - BuildingNAnimalMenuPatches.marked[i] = Vector2.Zero; + BuildingOperations.marked[i] = Vector2.Zero; } - for (int i = 0; i < BuildingNAnimalMenuPatches.availableBuildings.Length; i++) + for (int i = 0; i < BuildingOperations.availableBuildings.Length; i++) { - BuildingNAnimalMenuPatches.availableBuildings[i] = null; + BuildingOperations.availableBuildings[i] = null; } #endregion diff --git a/stardew-access/Patches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/AnimalQueryMenuPatch.cs new file mode 100644 index 0000000..232d573 --- /dev/null +++ b/stardew-access/Patches/AnimalQueryMenuPatch.cs @@ -0,0 +1,78 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class AnimalQueryMenuPatch + { + internal static bool isNarratingAnimalInfo = false; + internal static string animalQueryMenuQuery = ""; + internal static AnimalQueryMenu? animalQueryMenu; + internal static FarmAnimal? animalBeingMoved = null; + internal static bool isOnFarm = false; + + internal static void DrawPatch(AnimalQueryMenu __instance, bool ___confirmingSell, FarmAnimal ___animal, TextBox ___textBox, string ___parentName, bool ___movingAnimal) + { + try + { + if (TextBoxPatch.isAnyTextBoxActive) return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details + string toSpeak = " ", details = " "; + + isOnFarm = ___movingAnimal; + animalQueryMenu = __instance; + animalBeingMoved = ___animal; + + if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) + { + string name = ___animal.displayName; + string type = ___animal.displayType; + int age = (___animal.GetDaysOwned() + 1) / 28 + 1; + string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); + string parent = ""; + if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) + { + ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); + } + if (___parentName != null) + { + parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); + } + + details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; + animalQueryMenuQuery = ""; + + isNarratingAnimalInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "OK button"; + else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) + toSpeak = $"Sell for {___animal.getSellPrice()}g button"; + else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm selling animal"; + else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel selling animal"; + else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) + toSpeak = "Change home building button"; + else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) + toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = "Animal name text box"; + + if (animalQueryMenuQuery != toSpeak) + { + animalQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say($"{details} {toSpeak}", true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"An error occured in AnimalQueryMenuPatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs b/stardew-access/Patches/BuildingNAnimalMenuPatches.cs deleted file mode 100644 index 352011f..0000000 --- a/stardew-access/Patches/BuildingNAnimalMenuPatches.cs +++ /dev/null @@ -1,705 +0,0 @@ -using Microsoft.Xna.Framework; -using StardewValley; -using StardewValley.Buildings; -using StardewValley.Locations; -using StardewValley.Menus; -using StardewValley.Objects; - -namespace stardew_access.Patches -{ - internal class BuildingNAnimalMenuPatches - { - internal static Vector2[] marked = new Vector2[10]; - internal static Building?[] availableBuildings = new Building[100]; - internal static CarpenterMenu? carpenterMenu = null; - internal static bool isNarratingAnimalInfo = false; - internal static string animalQueryMenuQuery = " "; - internal static string carpenterMenuQuery = "", purchaseAnimalMenuQuery = ""; - internal static bool isSayingBlueprintInfo = false; - internal static string prevBlueprintInfo = ""; - internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false, isMagicalConstruction = false; - internal static bool firstTimeInNamingMenu = true; - internal static PurchaseAnimalsMenu? purchaseAnimalsMenu; - internal static AnimalQueryMenu? animalQueryMenu; - private static FarmAnimal? animalBeingPurchasedOrMoved = null; - - internal static void AnimalQueryMenuPatch(AnimalQueryMenu __instance, bool ___confirmingSell, FarmAnimal ___animal, TextBox ___textBox, string ___parentName, bool ___movingAnimal) - { - try - { - if (TextBoxPatch.isAnyTextBoxActive) return; - - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details - string toSpeak = " ", details = " "; - - isOnFarm = ___movingAnimal; - animalQueryMenu = __instance; - animalBeingPurchasedOrMoved = ___animal; - - if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) - { - string name = ___animal.displayName; - string type = ___animal.displayType; - int age = (___animal.GetDaysOwned() + 1) / 28 + 1; - string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); - string parent = ""; - if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) - { - ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); - } - if (___parentName != null) - { - parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); - } - - details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; - animalQueryMenuQuery = " "; - - isNarratingAnimalInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "OK button"; - else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) - toSpeak = $"Sell for {___animal.getSellPrice()}g button"; - else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm selling animal"; - else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel selling animal"; - else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) - toSpeak = "Change home building button"; - else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) - toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = "Animal name text box"; - - if (animalQueryMenuQuery != toSpeak) - { - animalQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say($"{details} {toSpeak}", true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void PurchaseAnimalsMenuPatch(PurchaseAnimalsMenu __instance, bool ___onFarm, bool ___namingAnimal, TextBox ___textBox, FarmAnimal ___animalBeingPurchased) - { - try - { - if (TextBoxPatch.isAnyTextBoxActive) return; - - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - purchaseAnimalsMenu = __instance; - isOnFarm = ___onFarm; - animalBeingPurchasedOrMoved = ___animalBeingPurchased; - - if (___onFarm && ___namingAnimal) - { - string toSpeak = ""; - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "Cancel Button"; - } - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - { - toSpeak = "OK Button"; - } - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - { - toSpeak = "Random Name Button"; - } - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - { - toSpeak = "Name Text Box"; - // string? value = ___textBox.Text; - // if (value != "" && value != null && value != "null") - // toSpeak = $"{toSpeak}, Value: {value}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - - if (firstTimeInNamingMenu) - { - toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; - firstTimeInNamingMenu = false; - } - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else if (___onFarm && !___namingAnimal) - { - firstTimeInNamingMenu = true; - } - else if (!___onFarm && !___namingAnimal) - { - firstTimeInNamingMenu = true; - if (__instance.hovered != null) - { - string toSpeak = ""; - if (((StardewValley.Object)__instance.hovered.item).Type != null) - { - toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; - } - else - { - string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); - int price = __instance.hovered.item.salePrice(); - string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); - - toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void CarpenterMenuPatch( - CarpenterMenu __instance, bool ___onFarm, List ___ingredients, int ___price, - List ___blueprints, int ___currentBlueprintIndex, bool ___upgrading, bool ___demolishing, bool ___moving, - bool ___painting, bool ___magicalConstruction) - { - try - { - isOnFarm = ___onFarm; - carpenterMenu = __instance; - isMagicalConstruction = ___magicalConstruction; - if (!___onFarm) - { - isUpgrading = false; - isDemolishing = false; - isPainting = false; - isMoving = false; - isConstructing = false; - - #region The blueprint menu - BluePrint currentBluprint = __instance.CurrentBlueprint; - if (currentBluprint == null) - return; - - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string ingredients = ""; - string name = currentBluprint.displayName; - string upgradeName = currentBluprint.nameOfBuildingToUpgrade; - string description = currentBluprint.description; - string price = $"{___price}g"; - string blueprintInfo; - int width = currentBluprint.tilesWidth; - int height = currentBluprint.tilesHeight; - - #region Get ingredients - for (int i = 0; i < ___ingredients.Count; i++) - { - string itemName = ___ingredients[i].DisplayName; - int itemStack = ___ingredients[i].Stack; - string itemQuality = ""; - - int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; - if (qualityValue == 1) - { - itemQuality = "Silver quality"; - } - else if (qualityValue == 2 || qualityValue == 3) - { - itemQuality = "Gold quality"; - } - else if (qualityValue >= 4) - { - itemQuality = "Iridium quality"; - } - - ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; - } - #endregion - - blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; - - if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo) - { - SayBlueprintInfo(blueprintInfo); - } - else if (prevBlueprintInfo != blueprintInfo) - { - prevBlueprintInfo = blueprintInfo; - SayBlueprintInfo(blueprintInfo); - } - else - { - if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - { - string toSpeak = "Previous Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - { - string toSpeak = "Next Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) - { - string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) - { - string toSpeak = "Move Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) - { - string toSpeak = "Paint Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) - { - string toSpeak = "Cancel Button"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - #endregion - } - else - { - if (___demolishing) - isDemolishing = true; - else if (___upgrading) - isUpgrading = true; - else if (___painting) - isPainting = true; - else if (___moving) - isMoving = true; - else - isConstructing = true; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static async void SayBlueprintInfo(string info) - { - isSayingBlueprintInfo = true; - MainClass.ScreenReader.Say(info, true); - await Task.Delay(300); - isSayingBlueprintInfo = false; - } - - public static string? Demolish(Building? toDemolish) - { - if (toDemolish == null) - return null; - - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::654) - Farm farm = (Farm)Game1.getLocationFromName("Farm"); - Action buildingLockFailed = delegate - { - if (isDemolishing) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); - } - }; - Action continueDemolish = delegate - { - if (isDemolishing && toDemolish != null && farm.buildings.Contains(toDemolish)) - { - if ((int)toDemolish.daysOfConstructionLeft.Value > 0 || (int)toDemolish.daysUntilUpgrade.Value > 0) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_DuringConstruction"); - } - else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is AnimalHouse && ((AnimalHouse)toDemolish.indoors.Value).animalsThatLiveHere.Count > 0) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_AnimalsHere"); - } - else if (toDemolish.indoors.Value != null && toDemolish.indoors.Value.farmers.Any()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); - } - else - { - if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin) - { - foreach (Farmer current in Game1.getAllFarmers()) - { - if (current.currentLocation != null && current.currentLocation.Name == ((Cabin)toDemolish.indoors.Value).GetCellarName()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_PlayerHere"); - return; - } - } - } - if (toDemolish.indoors.Value is Cabin && ((Cabin)toDemolish.indoors.Value).farmhand.Value.isActive()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_FarmhandOnline"); - } - else - { - toDemolish.BeforeDemolish(); - Chest? chest = null; - if (toDemolish.indoors.Value is Cabin) - { - List list = ((Cabin)toDemolish.indoors.Value).demolish(); - if (list.Count > 0) - { - chest = new Chest(playerChest: true); - chest.fixLidFrame(); - chest.items.Set(list); - } - } - if (farm.destroyStructure(toDemolish)) - { - _ = (int)toDemolish.tileY.Value; - _ = (int)toDemolish.tilesHigh.Value; - Game1.flashAlpha = 1f; - toDemolish.showDestroyedAnimation(Game1.getFarm()); - Game1.playSound("explosion"); - Utility.spreadAnimalsAround(toDemolish, farm); - if (carpenterMenu != null) - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1500); - // freeze = true; - if (chest != null) - { - farm.objects[new Vector2((int)toDemolish.tileX.Value + (int)toDemolish.tilesWide.Value / 2, (int)toDemolish.tileY.Value + (int)toDemolish.tilesHigh.Value / 2)] = chest; - } - } - } - } - } - }; - if (toDemolish != null) - { - if (toDemolish.indoors.Value != null && toDemolish.indoors.Value is Cabin && !Game1.IsMasterGame) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantDemolish_LockFailed"); - toDemolish = null; - return response; - } - if (carpenterMenu != null && !carpenterMenu.CanDemolishThis(toDemolish)) - { - toDemolish = null; - return response; - } - if (carpenterMenu != null && !Game1.IsMasterGame && !carpenterMenu.hasPermissionsToDemolish(toDemolish)) - { - toDemolish = null; - return response; - } - } - if (toDemolish != null && toDemolish.indoors.Value is Cabin) - { - Cabin cabin = (Cabin)toDemolish.indoors.Value; - if (cabin.farmhand.Value != null && (bool)cabin.farmhand.Value.isCustomized.Value) - { - Game1.currentLocation.createQuestionDialogue(Game1.content.LoadString("Strings\\UI:Carpenter_DemolishCabinConfirm", cabin.farmhand.Value.Name), Game1.currentLocation.createYesNoResponses(), delegate (Farmer f, string answer) - { - if (answer == "Yes") - { - Game1.activeClickableMenu = carpenterMenu; - Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); - } - else - { - if (carpenterMenu != null) - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenu, 1000); - } - }); - return response; - } - } - if (toDemolish != null) - { - Game1.player.team.demolishLock.RequestLock(continueDemolish, buildingLockFailed); - } - - return response; - } - - public static string? Contstruct(Vector2 position) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::874) - Game1.player.team.buildLock.RequestLock(delegate - { - if (isOnFarm && Game1.locationRequest == null) - { - if (tryToBuild(position)) - { - if (carpenterMenu != null) - { - carpenterMenu.CurrentBlueprint.consumeResources(); - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 2000); - } - // freeze = true; - } - else - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantBuild"); - } - } - Game1.player.team.buildLock.ReleaseLock(); - }); - - return response; - } - - public static bool tryToBuild(Vector2 position) - { - if (carpenterMenu == null) - return false; - return ((Farm)Game1.getLocationFromName("Farm")).buildStructure(carpenterMenu.CurrentBlueprint, position, Game1.player, isMagicalConstruction); - } - - public static string? Upgrade(Building? toUpgrade) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::775) - if (carpenterMenu != null && toUpgrade != null && carpenterMenu.CurrentBlueprint.name != null && toUpgrade.buildingType.Equals(carpenterMenu.CurrentBlueprint.nameOfBuildingToUpgrade)) - { - carpenterMenu.CurrentBlueprint.consumeResources(); - toUpgrade.daysUntilUpgrade.Value = 2; - toUpgrade.showUpgradeAnimation(Game1.getFarm()); - Game1.playSound("axe"); - DelayedAction.functionAfterDelay(carpenterMenu.returnToCarpentryMenuAfterSuccessfulBuild, 1500); - // freeze = true; - // Game1.multiplayer.globalChatInfoMessage("BuildingBuild", Game1.player.Name, Utility.AOrAn(carpenterMenu.CurrentBlueprint.displayName), carpenterMenu.CurrentBlueprint.displayName, Game1.player.farmName.Value); - } - else if (toUpgrade != null) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CantUpgrade_BuildingType"); - } - return response; - } - - public static string? Paint(Building? toPaint) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::793) - Farm farm_location = Game1.getFarm(); - if (toPaint != null) - { - if (!toPaint.CanBePainted()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); - return response; - } - if (carpenterMenu != null && !carpenterMenu.HasPermissionsToPaint(toPaint)) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); - return response; - } - toPaint.color.Value = Color.White; - - if (carpenterMenu != null) - carpenterMenu.SetChildMenu(new BuildingPaintMenu(toPaint)); - } - /* TODO Add painting of farm house - else if (farm_location.GetHouseRect().Contains(Utility.Vector2ToPoint(new Vector2(toPaint.tileX, toPaint.tileY)))) - { - if (!carpenterMenu.CanPaintHouse()) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint"); - } - else if (!carpenterMenu.HasPermissionsToPaint(null)) - { - response = Game1.content.LoadString("Strings\\UI:Carpenter_CannotPaint_Permission"); - } - else - { - carpenterMenu.SetChildMenu(new BuildingPaintMenu("House", () => (farm_location.paintedHouseTexture != null) ? farm_location.paintedHouseTexture : Farm.houseTextures, farm_location.houseSource.Value, farm_location.housePaintColor.Value)); - } - }*/ - return response; - } - - public static string? Move(Building? buildingToMove, Vector2 position) - { - string? response = null; - // This code is taken from the game's code (CarpenterMenu.cs::829) - if (buildingToMove != null) - { - string? name = buildingToMove.nameOfIndoorsWithoutUnique; - name = (name == "null") ? buildingToMove.buildingType.Value : name; - - if ((int)buildingToMove.daysOfConstructionLeft.Value > 0) - { - buildingToMove = null; - return "Building under construction, cannot move"; - } - if (carpenterMenu != null && !carpenterMenu.hasPermissionsToMove(buildingToMove)) - { - buildingToMove = null; - return "You don't have permission to move this building"; - } - Game1.playSound("axchop"); - - if (((Farm)Game1.getLocationFromName("Farm")).buildStructure(buildingToMove, position, Game1.player)) - { - if (buildingToMove is ShippingBin) - { - ((ShippingBin)buildingToMove).initLid(); - } - if (buildingToMove is GreenhouseBuilding) - { - Game1.getFarm().greenhouseMoved.Value = true; - } - buildingToMove.performActionOnBuildingPlacement(); - buildingToMove = null; - Game1.playSound("axchop"); - DelayedAction.playSoundAfterDelay("dirtyHit", 50); - DelayedAction.playSoundAfterDelay("dirtyHit", 150); - - response = $"{buildingToMove} moved to {position.X}x {position.Y}y"; - } - else - { - Game1.playSound("cancel"); - response = $"Cannot move building to {position.X}x {position.Y}y"; - } - - } - - return response; - } - - public static void PurchaseAnimal(Building? selection) - { - if (selection == null) - return; - - if (purchaseAnimalsMenu == null) - return; - - int x = (selection.tileX.Value * Game1.tileSize) - Game1.viewport.X; - int y = (selection.tileY.Value * Game1.tileSize) - Game1.viewport.Y; - - if (animalBeingPurchasedOrMoved != null && !selection.buildingType.Value.Contains(animalBeingPurchasedOrMoved.buildingTypeILiveIn.Value)) - { - string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11326", animalBeingPurchasedOrMoved.displayType); - MainClass.ScreenReader.Say(warn, true); - return; - } - - if (((AnimalHouse)selection.indoors.Value).isFull()) - { - string warn = Game1.content.LoadString("Strings\\StringsFromCSFiles:PurchaseAnimalsMenu.cs.11321"); - MainClass.ScreenReader.Say(warn, true); - return; - } - - purchaseAnimalsMenu.receiveLeftClick(x, y); - } - - public static void MoveAnimal(Building? selection) - { - if (selection == null) - return; - - if (animalQueryMenu == null) - return; - - if (animalBeingPurchasedOrMoved == null) - return; - - // The following code is taken from the game's source code [AnimalQueryMenu.cs::receiveLeftClick] - if (selection.buildingType.Value.Contains(animalBeingPurchasedOrMoved.buildingTypeILiveIn.Value)) - { - if (((AnimalHouse)selection.indoors.Value).isFull()) - { - string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_BuildingFull"); - MainClass.ScreenReader.Say(warn, true); - return; - } - if (selection.Equals(animalBeingPurchasedOrMoved.home)) - { - string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_AlreadyHome"); - MainClass.ScreenReader.Say(warn, true); - return; - } - ((AnimalHouse)animalBeingPurchasedOrMoved.home.indoors.Value).animalsThatLiveHere.Remove(animalBeingPurchasedOrMoved.myID.Value); - if (((AnimalHouse)animalBeingPurchasedOrMoved.home.indoors.Value).animals.ContainsKey(animalBeingPurchasedOrMoved.myID.Value)) - { - ((AnimalHouse)selection.indoors.Value).animals.Add(animalBeingPurchasedOrMoved.myID.Value, animalBeingPurchasedOrMoved); - ((AnimalHouse)animalBeingPurchasedOrMoved.home.indoors.Value).animals.Remove(animalBeingPurchasedOrMoved.myID.Value); - } - animalBeingPurchasedOrMoved.home = selection; - animalBeingPurchasedOrMoved.homeLocation.Value = new Vector2((int)selection.tileX.Value, (int)selection.tileY.Value); - ((AnimalHouse)selection.indoors.Value).animalsThatLiveHere.Add(animalBeingPurchasedOrMoved.myID.Value); - animalBeingPurchasedOrMoved.makeSound(); - Game1.globalFadeToBlack(animalQueryMenu.finishedPlacingAnimal); - } - else - { - string warn = Game1.content.LoadString("Strings\\UI:AnimalQuery_Moving_CantLiveThere"); - MainClass.ScreenReader.Say(warn, true); - } - return; - } - } -} diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPach.cs new file mode 100644 index 0000000..3745452 --- /dev/null +++ b/stardew-access/Patches/CarpenterMenuPach.cs @@ -0,0 +1,195 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class CarpenterMenuPatch + { + internal static CarpenterMenu? carpenterMenu = null; + internal static string carpenterMenuQuery = ""; + internal static bool isSayingBlueprintInfo = false; + internal static string prevBlueprintInfo = ""; + internal static bool isOnFarm = false, isUpgrading = false, isDemolishing = false, isPainting = false, isConstructing = false, isMoving = false, isMagicalConstruction = false; + + internal static void DrawPatch( + CarpenterMenu __instance, bool ___onFarm, List ___ingredients, int ___price, + List ___blueprints, int ___currentBlueprintIndex, bool ___upgrading, bool ___demolishing, bool ___moving, + bool ___painting, bool ___magicalConstruction) + { + try + { + isOnFarm = ___onFarm; + carpenterMenu = __instance; + isMagicalConstruction = ___magicalConstruction; + if (!___onFarm) + { + isUpgrading = false; + isDemolishing = false; + isPainting = false; + isMoving = false; + isConstructing = false; + + #region The blueprint menu + BluePrint currentBluprint = __instance.CurrentBlueprint; + if (currentBluprint == null) + return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + string ingredients = ""; + string name = currentBluprint.displayName; + string upgradeName = currentBluprint.nameOfBuildingToUpgrade; + string description = currentBluprint.description; + string price = $"{___price}g"; + string blueprintInfo; + int width = currentBluprint.tilesWidth; + int height = currentBluprint.tilesHeight; + + #region Get ingredients + for (int i = 0; i < ___ingredients.Count; i++) + { + string itemName = ___ingredients[i].DisplayName; + int itemStack = ___ingredients[i].Stack; + string itemQuality = ""; + + int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; + if (qualityValue == 1) + { + itemQuality = "Silver quality"; + } + else if (qualityValue == 2 || qualityValue == 3) + { + itemQuality = "Gold quality"; + } + else if (qualityValue >= 4) + { + itemQuality = "Iridium quality"; + } + + ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; + } + #endregion + + blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; + + if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo) + { + SayBlueprintInfo(blueprintInfo); + } + else if (prevBlueprintInfo != blueprintInfo) + { + prevBlueprintInfo = blueprintInfo; + SayBlueprintInfo(blueprintInfo); + } + else + { + if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + { + string toSpeak = "Previous Blueprint"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + { + string toSpeak = "Next Blueprint"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) + { + string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) + { + string toSpeak = "Move Building"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) + { + string toSpeak = "Paint Building"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) + { + string toSpeak = "Cancel Button"; + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + #endregion + } + else + { + if (___demolishing) + isDemolishing = true; + else if (___upgrading) + isUpgrading = true; + else if (___painting) + isPainting = true; + else if (___moving) + isMoving = true; + else + isConstructing = true; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static async void SayBlueprintInfo(string info) + { + isSayingBlueprintInfo = true; + MainClass.ScreenReader.Say(info, true); + await Task.Delay(300); + isSayingBlueprintInfo = false; + } + + + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 1a3992a..ae98f9d 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -63,19 +63,24 @@ namespace stardew_access.Patches } else if (menu is CarpenterMenu) { - BuildingNAnimalMenuPatches.carpenterMenuQuery = ""; - BuildingNAnimalMenuPatches.isUpgrading = false; - BuildingNAnimalMenuPatches.isDemolishing = false; - BuildingNAnimalMenuPatches.isPainting = false; - BuildingNAnimalMenuPatches.isMoving = false; - BuildingNAnimalMenuPatches.isConstructing = false; - BuildingNAnimalMenuPatches.carpenterMenu = null; + CarpenterMenuPatch.carpenterMenuQuery = ""; + CarpenterMenuPatch.isUpgrading = false; + CarpenterMenuPatch.isDemolishing = false; + CarpenterMenuPatch.isPainting = false; + CarpenterMenuPatch.isMoving = false; + CarpenterMenuPatch.isConstructing = false; + CarpenterMenuPatch.carpenterMenu = null; } else if (menu is PurchaseAnimalsMenu) { - BuildingNAnimalMenuPatches.purchaseAnimalMenuQuery = ""; - BuildingNAnimalMenuPatches.firstTimeInNamingMenu = true; - BuildingNAnimalMenuPatches.purchaseAnimalsMenu = null; + PurchaseAnimalsMenuPatch.purchaseAnimalMenuQuery = ""; + PurchaseAnimalsMenuPatch.firstTimeInNamingMenu = true; + PurchaseAnimalsMenuPatch.purchaseAnimalsMenu = null; + } + else if (menu is AnimalQueryMenu) + { + AnimalQueryMenuPatch.animalQueryMenuQuery = ""; + AnimalQueryMenuPatch.animalQueryMenu = null; } else if (menu is DialogueBox) { diff --git a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs new file mode 100644 index 0000000..0828c06 --- /dev/null +++ b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs @@ -0,0 +1,101 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class PurchaseAnimalsMenuPatch + { + internal static FarmAnimal? animalBeingPurchased = null; + internal static bool isOnFarm = false; + internal static string purchaseAnimalMenuQuery = ""; + internal static PurchaseAnimalsMenu? purchaseAnimalsMenu; + internal static bool firstTimeInNamingMenu = true; + + internal static void DrawPatch(PurchaseAnimalsMenu __instance, bool ___onFarm, bool ___namingAnimal, TextBox ___textBox, FarmAnimal ___animalBeingPurchased) + { + try + { + if (TextBoxPatch.isAnyTextBoxActive) return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + purchaseAnimalsMenu = __instance; + isOnFarm = ___onFarm; + animalBeingPurchased = ___animalBeingPurchased; + + if (___onFarm && ___namingAnimal) + { + string toSpeak = ""; + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Cancel Button"; + } + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + { + toSpeak = "OK Button"; + } + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + { + toSpeak = "Random Name Button"; + } + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + { + toSpeak = "Name Text Box"; + // string? value = ___textBox.Text; + // if (value != "" && value != null && value != "null") + // toSpeak = $"{toSpeak}, Value: {value}"; + } + + if (purchaseAnimalMenuQuery != toSpeak) + { + purchaseAnimalMenuQuery = toSpeak; + + if (firstTimeInNamingMenu) + { + toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; + firstTimeInNamingMenu = false; + } + + MainClass.ScreenReader.Say(toSpeak, true); + } + } + else if (___onFarm && !___namingAnimal) + { + firstTimeInNamingMenu = true; + } + else if (!___onFarm && !___namingAnimal) + { + firstTimeInNamingMenu = true; + if (__instance.hovered != null) + { + string toSpeak = ""; + if (((StardewValley.Object)__instance.hovered.item).Type != null) + { + toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; + } + else + { + string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); + int price = __instance.hovered.item.salePrice(); + string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); + + toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; + } + + if (purchaseAnimalMenuQuery != toSpeak) + { + purchaseAnimalMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + + } +} From 4a39bf94ead74f66229d737855bf0d680bfadb37 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 13:49:50 +0530 Subject: [PATCH 23/61] Moved shop menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 107 --------------- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ShopMenuPatch.cs | 123 ++++++++++++++++++ 4 files changed, 125 insertions(+), 109 deletions(-) create mode 100644 stardew-access/Patches/ShopMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 72475db..1948818 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -100,7 +100,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ShopMenu), nameof(ShopMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ShopMenuPatch)) + postfix: new HarmonyMethod(typeof(ShopMenuPatch), nameof(ShopMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index f5d0ea2..bdca60c 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -15,7 +15,6 @@ namespace stardew_access.Patches internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; - internal static string shopMenuQueryKey = ""; internal static string socialPageQuery = ""; internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; @@ -185,112 +184,6 @@ namespace stardew_access.Patches } } - internal static void ShopMenuPatch(ShopMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) - { - __instance.forSaleButtons[0].snapMouseCursorToCenter(); - __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[0].myID); - } - - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) - { - string toSpeak = "Up Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) - { - string toSpeak = "Down Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) - { - shopMenuQueryKey = ""; - return; - } - #endregion - - #region Narrate hovered selling item - if (__instance.hoveredItem != null) - { - string name = __instance.hoveredItem.DisplayName; - string price = $"Buy Price: {__instance.hoverPrice} g"; - string description = __instance.hoveredItem.getDescription(); - string requirements = ""; - - #region Narrate required items for item - int itemIndex = -1, itemAmount = 5; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) - itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) - itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; - - if (itemIndex != -1) - { - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - requirements = $"Required: {itemAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void GameMenuPatch(GameMenu __instance) { try diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index ae98f9d..67c91a1 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -51,7 +51,7 @@ namespace stardew_access.Patches } else if (menu is ShopMenu) { - GameMenuPatches.shopMenuQueryKey = ""; + ShopMenuPatch.Cleanup(); } else if (menu is ItemGrabMenu) { diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs new file mode 100644 index 0000000..4f565a9 --- /dev/null +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -0,0 +1,123 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ShopMenuPatch + { + internal static string shopMenuQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(ShopMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) + { + __instance.forSaleButtons[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[0].myID); + } + + #region Narrate buttons in the menu + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) + { + string toSpeak = "Up Arrow Button"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) + { + string toSpeak = "Down Arrow Button"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) + { + shopMenuQueryKey = ""; + return; + } + #endregion + + #region Narrate hovered selling item + if (__instance.hoveredItem != null) + { + string name = __instance.hoveredItem.DisplayName; + string price = $"Buy Price: {__instance.hoverPrice} g"; + string description = __instance.hoveredItem.getDescription(); + string requirements = ""; + + #region Narrate required items for item + int itemIndex = -1, itemAmount = 5; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) + itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) + itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; + + if (itemIndex != -1) + { + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + requirements = $"Required: {itemAmount} {itemName}"; + else + requirements = $"Required: {itemName}"; + } + #endregion + + string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; + if (shopMenuQueryKey != toSpeak) + { + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + shopMenuQueryKey = ""; + hoveredItemQueryKey = ""; + } + } +} From 7d505d2dd74f7a3f5c36fb42e142f8655839475f Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:10:28 +0530 Subject: [PATCH 24/61] Moved item grab menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 271 +----------------- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ItemGrabMenuPatch.cs | 266 +++++++++++++++++ 4 files changed, 273 insertions(+), 268 deletions(-) create mode 100644 stardew-access/Patches/ItemGrabMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 1948818..ef00a10 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -90,7 +90,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ItemGrabMenu), nameof(ItemGrabMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ItemGrabMenuPatch)) + postfix: new HarmonyMethod(typeof(ItemGrabMenuPatch), nameof(ItemGrabMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index bdca60c..e84f888 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -10,7 +10,6 @@ namespace stardew_access.Patches internal static string hoveredItemQueryKey = ""; internal static string geodeMenuQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string itemGrabMenuQueryKey = ""; internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; @@ -201,6 +200,7 @@ namespace stardew_access.Patches string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab"; if (gameMenuQueryKey != toSpeak) { + MainClass.DebugLog("here"); gameMenuQueryKey = toSpeak; MainClass.ScreenReader.Say(toSpeak, true); } @@ -298,267 +298,6 @@ namespace stardew_access.Patches } } - internal static void ItemGrabMenuPatch(ItemGrabMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) - { - __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); - __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); - } - - #region Narrate buttons in the menu - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - gameMenuQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) - { - string toSpeak = "Add to existing stacks button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) - { - string toSpeak = "Special Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) - { - - string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - // FIXME - /*if (__instance.discreteColorPickerCC.Count > 0) { - for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) - { - if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) - { - MainClass.monitor.Log(i.ToString(), LogLevel.Debug); - string toSpeak = getChestColorName(i); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - ScreenReader.say(toSpeak, true); - Game1.playSound("sa_drop_item"); - } - return; - } - } - }*/ - #endregion - - #region Narrate the last shipped item if in the shipping bin - if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) - { - Item lastShippedItem = Game1.getFarm().lastItemShipped; - string name = lastShippedItem.DisplayName; - int count = lastShippedItem.Stack; - - string toSpeak = $"Last Shipped: {count} {name}"; - - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - itemGrabMenuQueryKey = ""; - return; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - itemGrabMenuQueryKey = ""; - return; - } - - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - // TODO Add color names - private static string getChestColorName(int i) - { - string toReturn = ""; - switch (i) - { - case 0: - toReturn = "Default chest color"; - break; - case 1: - toReturn = "Default chest color"; - break; - case 2: - toReturn = "Default chest color"; - break; - case 3: - toReturn = "Default chest color"; - break; - case 4: - toReturn = "Default chest color"; - break; - case 5: - toReturn = "Default chest color"; - break; - case 6: - toReturn = "Default chest color"; - break; - case 7: - toReturn = "Default chest color"; - break; - case 8: - toReturn = "Default chest color"; - break; - case 9: - toReturn = "Default chest color"; - break; - case 10: - toReturn = "Default chest color"; - break; - case 11: - toReturn = "Default chest color"; - break; - case 12: - toReturn = "Default chest color"; - break; - case 13: - toReturn = "Default chest color"; - break; - case 14: - toReturn = "Default chest color"; - break; - case 15: - toReturn = "Default chest color"; - break; - case 16: - toReturn = "Default chest color"; - break; - case 17: - toReturn = "Default chest color"; - break; - case 18: - toReturn = "Default chest color"; - break; - case 19: - toReturn = "Default chest color"; - break; - case 20: - toReturn = "Default chest color"; - break; - } - return toReturn; - } internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) { @@ -838,9 +577,9 @@ namespace stardew_access.Patches if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) { string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) + if (inventoryPageQueryKey != toSpeak) { - itemGrabMenuQueryKey = toSpeak; + inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; MainClass.ScreenReader.Say(toSpeak, true); @@ -851,9 +590,9 @@ namespace stardew_access.Patches { string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) + if (inventoryPageQueryKey != toSpeak) { - itemGrabMenuQueryKey = toSpeak; + inventoryPageQueryKey = toSpeak; gameMenuQueryKey = ""; hoveredItemQueryKey = ""; MainClass.ScreenReader.Say(toSpeak, true); diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 67c91a1..9866068 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -55,7 +55,7 @@ namespace stardew_access.Patches } else if (menu is ItemGrabMenu) { - GameMenuPatches.itemGrabMenuQueryKey = ""; + ItemGrabMenuPatch.Cleanup(); } else if (menu is GeodeMenu) { diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs new file mode 100644 index 0000000..664d810 --- /dev/null +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -0,0 +1,266 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ItemGrabMenuPatch + { + internal static string itemGrabMenuQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(ItemGrabMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) + { + __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); + __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); + } + + #region Narrate buttons in the menu + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Ok Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) + { + string toSpeak = "Add to existing stacks button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) + { + string toSpeak = "Special Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) + { + + string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + + string toSpeak = "Community Center Button"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + + // FIXME + /*if (__instance.discreteColorPickerCC.Count > 0) { + for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) + { + if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) + { + MainClass.monitor.Log(i.ToString(), LogLevel.Debug); + string toSpeak = getChestColorName(i); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + ScreenReader.say(toSpeak, true); + Game1.playSound("sa_drop_item"); + } + return; + } + } + }*/ + #endregion + + #region Narrate the last shipped item if in the shipping bin + if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) + { + Item lastShippedItem = Game1.getFarm().lastItemShipped; + string name = lastShippedItem.DisplayName; + int count = lastShippedItem.Stack; + + string toSpeak = $"Last Shipped: {count} {name}"; + + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + { + itemGrabMenuQueryKey = ""; + return; + } + + if (InventoryUtils.narrateHoveredSlot(__instance.ItemsToGrabMenu, __instance.ItemsToGrabMenu.inventory, __instance.ItemsToGrabMenu.actualInventory, x, y, true)) + { + itemGrabMenuQueryKey = ""; + return; + } + + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + // TODO Add color names + private static string getChestColorName(int i) + { + string toReturn = ""; + switch (i) + { + case 0: + toReturn = "Default chest color"; + break; + case 1: + toReturn = "Default chest color"; + break; + case 2: + toReturn = "Default chest color"; + break; + case 3: + toReturn = "Default chest color"; + break; + case 4: + toReturn = "Default chest color"; + break; + case 5: + toReturn = "Default chest color"; + break; + case 6: + toReturn = "Default chest color"; + break; + case 7: + toReturn = "Default chest color"; + break; + case 8: + toReturn = "Default chest color"; + break; + case 9: + toReturn = "Default chest color"; + break; + case 10: + toReturn = "Default chest color"; + break; + case 11: + toReturn = "Default chest color"; + break; + case 12: + toReturn = "Default chest color"; + break; + case 13: + toReturn = "Default chest color"; + break; + case 14: + toReturn = "Default chest color"; + break; + case 15: + toReturn = "Default chest color"; + break; + case 16: + toReturn = "Default chest color"; + break; + case 17: + toReturn = "Default chest color"; + break; + case 18: + toReturn = "Default chest color"; + break; + case 19: + toReturn = "Default chest color"; + break; + case 20: + toReturn = "Default chest color"; + break; + } + return toReturn; + } + + internal static void Cleanup() { + hoveredItemQueryKey = ""; + itemGrabMenuQueryKey = ""; + } + } +} From 6730fcceff5a6b2d44608a75a8fc891e7ceac4b3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:29:51 +0530 Subject: [PATCH 25/61] Moved geode menu patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 86 ---------------- stardew-access/Patches/GeodeMenuPatch.cs | 99 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 101 insertions(+), 88 deletions(-) create mode 100644 stardew-access/Patches/GeodeMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index ef00a10..d0fe365 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -95,7 +95,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(GeodeMenu), nameof(GeodeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GeodeMenuPatch)) + postfix: new HarmonyMethod(typeof(GeodeMenuPatch), nameof(GeodeMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index e84f888..d7c3891 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -8,7 +8,6 @@ namespace stardew_access.Patches internal class GameMenuPatches { internal static string hoveredItemQueryKey = ""; - internal static string geodeMenuQueryKey = ""; internal static string gameMenuQueryKey = ""; internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; @@ -214,91 +213,6 @@ namespace stardew_access.Patches } } - internal static void GeodeMenuPatch(GeodeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - #region Narrate the treasure recieved on breaking the geode - if (__instance.geodeTreasure != null) - { - string name = __instance.geodeTreasure.DisplayName; - int stack = __instance.geodeTreasure.Stack; - - string toSpeak = $"Recieved {stack} {name}"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered buttons in the menu - if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) - { - string toSpeak = "Place geode here"; - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop item here"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash can"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok button"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - geodeMenuQueryKey = ""; - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) { try diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs new file mode 100644 index 0000000..e08beec --- /dev/null +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -0,0 +1,99 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class GeodeMenuPatch + { + internal static string geodeMenuQueryKey = ""; + + internal static void DrawPatch(GeodeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + #region Narrate the treasure recieved on breaking the geode + if (__instance.geodeTreasure != null) + { + string name = __instance.geodeTreasure.DisplayName; + int stack = __instance.geodeTreasure.Stack; + + string toSpeak = $"Recieved {stack} {name}"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered buttons in the menu + if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) + { + string toSpeak = "Place geode here"; + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop item here"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash can"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "Ok button"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + geodeMenuQueryKey = ""; + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + geodeMenuQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 9866068..b1be281 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -59,7 +59,7 @@ namespace stardew_access.Patches } else if (menu is GeodeMenu) { - GameMenuPatches.geodeMenuQueryKey = ""; + GeodeMenuPatch.Cleanup(); } else if (menu is CarpenterMenu) { From 2a5baa6770f8e0f980d5cf2e8d60c23573291ceb Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:33:03 +0530 Subject: [PATCH 26/61] Moved collections page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 15 ------------- .../GameMenuPatches/CollectionsPagePatch.cs | 21 +++++++++++++++++++ 3 files changed, 22 insertions(+), 16 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index d0fe365..509109a 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -110,7 +110,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CollectionsPage), nameof(CollectionsPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.CollectionsPagePatch)) + postfix: new HarmonyMethod(typeof(CollectionsPagePatch), nameof(CollectionsPagePatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index d7c3891..0f7b6fb 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -18,21 +18,6 @@ namespace stardew_access.Patches internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; - internal static void CollectionsPagePatch(CollectionsPage __instance) - { - try - { - int x = Game1.getMousePosition().X, y = Game1.getMousePosition().Y; - if (__instance.letterviewerSubMenu != null) - { - DialoguePatches.NarrateLetterContent(__instance.letterviewerSubMenu); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } internal static void SocialPagePatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) { diff --git a/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs new file mode 100644 index 0000000..a708930 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs @@ -0,0 +1,21 @@ +namespace stardew_access.Patches +{ + internal class CollectionsPagePatch + { + internal static void DrawPatch(StardewValley.Menus.CollectionsPage __instance) + { + try + { + int x = StardewValley.Game1.getMousePosition().X, y = StardewValley.Game1.getMousePosition().Y; + if (__instance.letterviewerSubMenu != null) + { + DialoguePatches.NarrateLetterContent(__instance.letterviewerSubMenu); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 9d7c2c36ec18b1e2727147acb7fd81869221671a Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:37:21 +0530 Subject: [PATCH 27/61] Moved social page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 150 ---------------- .../GameMenuPatches/SocialPagePatch.cs | 163 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 165 insertions(+), 152 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 509109a..f2db5c8 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -105,7 +105,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(SocialPage), nameof(SocialPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.SocialPagePatch)) + postfix: new HarmonyMethod(typeof(SocialPagePatch), nameof(SocialPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 0f7b6fb..2afb84b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -13,160 +13,10 @@ namespace stardew_access.Patches internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; - internal static string socialPageQuery = ""; internal static string profilePageQuery = ""; internal static int currentSelectedCraftingRecipe = -1; internal static bool isSelectingRecipe = false; - - internal static void SocialPagePatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - for (int i = ___slotPosition; i < ___slotPosition + 5; i++) - { - if (i < ___sprites.Count) - { - if (__instance.names[i] is string) - { - #region For NPCs - if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string name = $"{__instance.names[i] as string}"; - int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); - bool datable = SocialPage.isDatable(name); - Friendship friendship = __instance.getFriendship(name); - int giftsThisWeek = friendship.GiftsThisWeek; - bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); - bool spouse = friendship.IsMarried(); - bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); - ___kidsNames.Add("Robin"); - ___kidsNames.Add("Pierre"); - ___kidsNames.Add("Caroline"); - ___kidsNames.Add("Jodi"); - ___kidsNames.Add("Kent"); - ___kidsNames.Add("George"); - ___kidsNames.Add("Evelyn"); - ___kidsNames.Add("Demetrius"); - - - - string toSpeak = $"{name}"; - - if (!hasTalked) - { - toSpeak = $"{toSpeak}, not talked yet"; - } - - - if (datable | housemate) - { - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (housemate) - { - text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); - } - else if (spouse) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (__instance.isMarriedToAnyone(name)) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (__instance.getFriendship(name).IsDivorced()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{toSpeak}, {text2}"; - } - if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) - { - toSpeak = $"{toSpeak}, married"; - } - if (spouse) - { - toSpeak = $"{toSpeak}, spouse"; - } - else if (friendship.IsDating()) - { - toSpeak = $"{toSpeak}, dating"; - } - - toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; - - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - } - else if (__instance.names[i] is long) - { - #region For Farmers - - long farmerID = (long)__instance.names[i]; - Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); - if (farmer != null) - { - int gender = (!farmer.IsMale) ? 1 : 0; - ClickableTextureComponent clickableTextureComponent = ___sprites[i]; - if (clickableTextureComponent.containsPoint(x, y)) - { - Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); - bool spouse = friendship.IsMarried(); - string toSpeak = ""; - - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (spouse) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (farmer.isMarried() && !farmer.hasRoommate()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (friendship.IsDivorced()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{farmer.displayName}, {text2}"; - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - - #endregion - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void GameMenuPatch(GameMenu __instance) { try diff --git a/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs new file mode 100644 index 0000000..3c03245 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs @@ -0,0 +1,163 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class SocialPagePatch + { + internal static string socialPageQuery = ""; + + internal static void DrawPatch(SocialPage __instance, List ___sprites, int ___slotPosition, List ___kidsNames) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + for (int i = ___slotPosition; i < ___slotPosition + 5; i++) + { + if (i < ___sprites.Count) + { + if (__instance.names[i] is string) + { + #region For NPCs + if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string name = $"{__instance.names[i] as string}"; + int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); + bool datable = SocialPage.isDatable(name); + Friendship friendship = __instance.getFriendship(name); + int giftsThisWeek = friendship.GiftsThisWeek; + bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); + bool spouse = friendship.IsMarried(); + bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); + ___kidsNames.Add("Robin"); + ___kidsNames.Add("Pierre"); + ___kidsNames.Add("Caroline"); + ___kidsNames.Add("Jodi"); + ___kidsNames.Add("Kent"); + ___kidsNames.Add("George"); + ___kidsNames.Add("Evelyn"); + ___kidsNames.Add("Demetrius"); + + + + string toSpeak = $"{name}"; + + if (!hasTalked) + { + toSpeak = $"{toSpeak}, not talked yet"; + } + + + if (datable | housemate) + { + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (housemate) + { + text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); + } + else if (spouse) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (__instance.isMarriedToAnyone(name)) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (__instance.getFriendship(name).IsDivorced()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{toSpeak}, {text2}"; + } + if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) + { + toSpeak = $"{toSpeak}, married"; + } + if (spouse) + { + toSpeak = $"{toSpeak}, spouse"; + } + else if (friendship.IsDating()) + { + toSpeak = $"{toSpeak}, dating"; + } + + toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; + + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + #endregion + } + else if (__instance.names[i] is long) + { + #region For Farmers + + long farmerID = (long)__instance.names[i]; + Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); + if (farmer != null) + { + int gender = (!farmer.IsMale) ? 1 : 0; + ClickableTextureComponent clickableTextureComponent = ___sprites[i]; + if (clickableTextureComponent.containsPoint(x, y)) + { + Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); + bool spouse = friendship.IsMarried(); + string toSpeak = ""; + + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (spouse) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (farmer.isMarried() && !farmer.hasRoommate()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (friendship.IsDivorced()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{farmer.displayName}, {text2}"; + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + + #endregion + } + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + socialPageQuery = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index b1be281..e925565 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -38,7 +38,7 @@ namespace stardew_access.Patches GameMenuPatches.inventoryPageQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; GameMenuPatches.optionsPageQueryKey = ""; - GameMenuPatches.socialPageQuery = ""; + SocialPagePatch.Cleanup(); GameMenuPatches.currentSelectedCraftingRecipe = -1; GameMenuPatches.isSelectingRecipe = false; } From f851806947a303d006619384630748a74ce0ff8c Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 14:43:19 +0530 Subject: [PATCH 28/61] Moved crafting page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 234 ---------------- .../GameMenuPatches/CraftingPagePatch.cs | 250 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 4 +- 4 files changed, 252 insertions(+), 238 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f2db5c8..25f5091 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -80,7 +80,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CraftingPage), nameof(CraftingPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.CraftingPagePatch)) + postfix: new HarmonyMethod(typeof(CraftingPagePatch), nameof(CraftingPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 2afb84b..027802d 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -9,13 +9,10 @@ namespace stardew_access.Patches { internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string craftingPageQueryKey = ""; internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; internal static string profilePageQuery = ""; - internal static int currentSelectedCraftingRecipe = -1; - internal static bool isSelectingRecipe = false; internal static void GameMenuPatch(GameMenu __instance) { @@ -48,237 +45,6 @@ namespace stardew_access.Patches } } - internal static void CraftingPagePatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - // snap to first inventory slot - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = -1; - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) - { - // snap to first crafting recipe - __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); - __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = 0; - } - else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) - { - isSelectingRecipe = true; - CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); - Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); - } - - #region Narrate buttons in the menu - if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) - { - string toSpeak = "Previous Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) - { - string toSpeak = "Next Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - #endregion - - #region Narrate hovered recipe - if (___hoverRecipe != null) - { - string name = ___hoverRecipe.DisplayName; - int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; - string description = ""; - string ingredients = ""; - string buffs = ""; - string craftable = ""; - - description = $"Description:\n{___hoverRecipe.description}"; - craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; - - #region Crafting ingredients - ingredients = "Ingredients:\n"; - for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) - { - int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; - int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; - string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); - - ingredients += $" ,{recipeCount} {recipeName}"; - } - #endregion - - #region Health & stamina and buff items (effects like +1 walking speed) - Item producesItem = ___hoverRecipe.createItem(); - if (producesItem is StardewValley.Object producesItemObject) - { - if (producesItemObject.Edibility != -300) - { - int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); - buffs += $"{stamina_recovery} Energy"; - if (stamina_recovery >= 0) - { - int health_recovery = producesItemObject.healthRecoveredOnConsumption(); - buffs += $"\n{health_recovery} Health"; - } - } - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; - string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) - ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) - : null; - - if (buffIconsToDisplay != null) - { - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - buffs += $"{buffName}\n"; - } - catch (Exception) { } - } - - buffs = $"Buffs and boosts:\n {buffs}"; - } - } - #endregion - - - string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; - - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - else - { - var isRecipeInFocus = false; - foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) - { - if (item.Key.containsPoint(x, y)) - { - isRecipeInFocus = true; - break; - } - } - - if (isRecipeInFocus) - { - string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; - - if (craftingPageQueryKey != query) - { - craftingPageQueryKey = query; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say("unknown recipe", true); - } - return; - } - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - { - gameMenuQueryKey = ""; - craftingPageQueryKey = ""; - return; - } - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) - { - currentSelectedCraftingRecipe++; - if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count) - currentSelectedCraftingRecipe = 0; - - __instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID); - pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter(); - - // Skip if recipe is not unlocked/unknown - if (pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.hoverText.Equals("ghosted")) - CycleThroughRecipies(pagesOfCraftingRecipes, ___currentCraftingPage, __instance); - } - - // This method is used to get the inventory items to check if the player has enough ingredients for a recipe - // Taken from CraftingPage.cs -> 169 line - internal static IList? getContainerContents(List materialContainers) - { - if (materialContainers == null) - { - return null; - } - List items = new List(); - for (int i = 0; i < materialContainers.Count; i++) - { - items.AddRange(materialContainers[i].items); - } - return items; - } - internal static void InventoryPagePatch(InventoryPage __instance) { try diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs new file mode 100644 index 0000000..51db2e5 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -0,0 +1,250 @@ +using StardewValley; +using StardewValley.Menus; +using StardewValley.Objects; + +namespace stardew_access.Patches +{ + internal class CraftingPagePatch + { + internal static string hoveredItemQueryKey = ""; + internal static string craftingPageQueryKey = ""; + internal static int currentSelectedCraftingRecipe = -1; + internal static bool isSelectingRecipe = false; + + internal static void DrawPatch(CraftingPage __instance, CraftingRecipe ___hoverRecipe, int ___currentCraftingPage) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + // snap to first inventory slot + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = -1; + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) + { + // snap to first crafting recipe + __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); + __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = 0; + } + else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) + { + isSelectingRecipe = true; + CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); + } + + #region Narrate buttons in the menu + if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) + { + string toSpeak = "Previous Recipe List"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + { + string toSpeak = "Next Recipe List"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (__instance.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + return; + } + #endregion + + #region Narrate hovered recipe + if (___hoverRecipe != null) + { + string name = ___hoverRecipe.DisplayName; + int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; + string description = ""; + string ingredients = ""; + string buffs = ""; + string craftable = ""; + + description = $"Description:\n{___hoverRecipe.description}"; + craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; + + #region Crafting ingredients + ingredients = "Ingredients:\n"; + for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) + { + int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; + int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; + string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); + + ingredients += $" ,{recipeCount} {recipeName}"; + } + #endregion + + #region Health & stamina and buff items (effects like +1 walking speed) + Item producesItem = ___hoverRecipe.createItem(); + if (producesItem is StardewValley.Object producesItemObject) + { + if (producesItemObject.Edibility != -300) + { + int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); + buffs += $"{stamina_recovery} Energy"; + if (stamina_recovery >= 0) + { + int health_recovery = producesItemObject.healthRecoveredOnConsumption(); + buffs += $"\n{health_recovery} Health"; + } + } + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; + string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) + ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay != null) + { + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + buffs += $"{buffName}\n"; + } + catch (Exception) { } + } + + buffs = $"Buffs and boosts:\n {buffs}"; + } + } + #endregion + + + string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; + + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + else + { + var isRecipeInFocus = false; + foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) + { + if (item.Key.containsPoint(x, y)) + { + isRecipeInFocus = true; + break; + } + } + + if (isRecipeInFocus) + { + string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; + + if (craftingPageQueryKey != query) + { + craftingPageQueryKey = query; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say("unknown recipe", true); + } + return; + } + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + { + craftingPageQueryKey = ""; + return; + } + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) + { + currentSelectedCraftingRecipe++; + if (currentSelectedCraftingRecipe < 0 || currentSelectedCraftingRecipe >= pagesOfCraftingRecipes[0].Count) + currentSelectedCraftingRecipe = 0; + + __instance.setCurrentlySnappedComponentTo(pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.myID); + pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.snapMouseCursorToCenter(); + + // Skip if recipe is not unlocked/unknown + if (pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(currentSelectedCraftingRecipe).Key.hoverText.Equals("ghosted")) + CycleThroughRecipies(pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + } + + // This method is used to get the inventory items to check if the player has enough ingredients for a recipe + // Taken from CraftingPage.cs -> 169 line + internal static IList? getContainerContents(List materialContainers) + { + if (materialContainers == null) + { + return null; + } + List items = new List(); + for (int i = 0; i < materialContainers.Count; i++) + { + items.AddRange(materialContainers[i].items); + } + return items; + } + + internal static void Cleanup() + { + hoveredItemQueryKey = ""; + craftingPageQueryKey = ""; + currentSelectedCraftingRecipe = -1; + isSelectingRecipe = false; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index e925565..7a5efea 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,13 +34,11 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.craftingPageQueryKey = ""; GameMenuPatches.inventoryPageQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; GameMenuPatches.optionsPageQueryKey = ""; SocialPagePatch.Cleanup(); - GameMenuPatches.currentSelectedCraftingRecipe = -1; - GameMenuPatches.isSelectingRecipe = false; + CraftingPagePatch.Cleanup(); } else if (menu is JunimoNoteMenu) { From 7c1e600790082154c505cb7191928ddf791fdff7 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:33:14 +0530 Subject: [PATCH 29/61] Moved inventory page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 207 ----------------- .../GameMenuPatches/InventoryPagePatch.cs | 217 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 219 insertions(+), 209 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 25f5091..6cc7464 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -85,7 +85,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(InventoryPage), nameof(InventoryPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.InventoryPagePatch)) + postfix: new HarmonyMethod(typeof(InventoryPagePatch), nameof(InventoryPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 027802d..84c7300 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -9,7 +9,6 @@ namespace stardew_access.Patches { internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string inventoryPageQueryKey = ""; internal static string exitPageQueryKey = ""; internal static string optionsPageQueryKey = ""; internal static string profilePageQuery = ""; @@ -45,212 +44,6 @@ namespace stardew_access.Patches } } - internal static void InventoryPagePatch(InventoryPage __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Inventory Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - - #region Narrate equipment slots - for (int i = 0; i < __instance.equipmentIcons.Count; i++) - { - if (__instance.equipmentIcons[i].containsPoint(x, y)) - { - string toSpeak = ""; - - #region Get name and description of the item - switch (__instance.equipmentIcons[i].name) - { - case "Hat": - { - if (Game1.player.hat.Value != null) - { - toSpeak = $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}"; - } - else - { - toSpeak = "Hat slot"; - } - } - break; - case "Left Ring": - { - if (Game1.player.leftRing.Value != null) - { - toSpeak = $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}"; - } - else - { - toSpeak = "Left Ring slot"; - } - } - break; - case "Right Ring": - { - if (Game1.player.rightRing.Value != null) - { - toSpeak = $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}"; - } - else - { - toSpeak = "Right ring slot"; - } - } - break; - case "Boots": - { - if (Game1.player.boots.Value != null) - { - toSpeak = $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}"; - } - else - { - toSpeak = "Boots slot"; - } - } - break; - case "Shirt": - { - if (Game1.player.shirtItem.Value != null) - { - toSpeak = $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}"; - } - else - { - toSpeak = "Shirt slot"; - } - } - break; - case "Pants": - { - if (Game1.player.pantsItem.Value != null) - { - toSpeak = $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}"; - } - else - { - toSpeak = "Pants slot"; - } - } - break; - } - #endregion - - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - gameMenuQueryKey = ""; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - } - #endregion - - #region Narrate hovered item - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) - { - gameMenuQueryKey = ""; - inventoryPageQueryKey = ""; - } - #endregion - - if (MainClass.Config.MoneyKey.JustPressed()) - { - string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); - string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); - string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); - int festivalScore = Game1.player.festivalScore; - int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; - int qiGems = Game1.player.QiGems; - int qiCoins = Game1.player.clubCoins; - - string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; - - if (festivalScore > 0) - toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; - - if (walnut > 0) - toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; - - if (qiGems > 0) - toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; - - if (qiCoins > 0) - toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } internal static void OptionsPagePatch(OptionsPage __instance) { diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs new file mode 100644 index 0000000..bfc367b --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -0,0 +1,217 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class InventoryPagePatch + { + internal static string inventoryPageQueryKey = ""; + internal static string hoveredItemQueryKey = ""; + + internal static void DrawPatch(InventoryPage __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + #region Narrate buttons in the menu + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + string toSpeak = "Drop Item"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + Game1.playSound("drop_item"); + } + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Inventory Button"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + string toSpeak = "Trash Can"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + string toSpeak = "Organize Button"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + + string toSpeak = "Community Center Button"; + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + #endregion + + #region Narrate equipment slots + for (int i = 0; i < __instance.equipmentIcons.Count; i++) + { + if (__instance.equipmentIcons[i].containsPoint(x, y)) + { + string toSpeak = ""; + + #region Get name and description of the item + switch (__instance.equipmentIcons[i].name) + { + case "Hat": + { + if (Game1.player.hat.Value != null) + { + toSpeak = $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}"; + } + else + { + toSpeak = "Hat slot"; + } + } + break; + case "Left Ring": + { + if (Game1.player.leftRing.Value != null) + { + toSpeak = $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}"; + } + else + { + toSpeak = "Left Ring slot"; + } + } + break; + case "Right Ring": + { + if (Game1.player.rightRing.Value != null) + { + toSpeak = $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}"; + } + else + { + toSpeak = "Right ring slot"; + } + } + break; + case "Boots": + { + if (Game1.player.boots.Value != null) + { + toSpeak = $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}"; + } + else + { + toSpeak = "Boots slot"; + } + } + break; + case "Shirt": + { + if (Game1.player.shirtItem.Value != null) + { + toSpeak = $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}"; + } + else + { + toSpeak = "Shirt slot"; + } + } + break; + case "Pants": + { + if (Game1.player.pantsItem.Value != null) + { + toSpeak = $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}"; + } + else + { + toSpeak = "Pants slot"; + } + } + break; + } + #endregion + + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + } + #endregion + + #region Narrate hovered item + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) + { + inventoryPageQueryKey = ""; + } + #endregion + + if (MainClass.Config.MoneyKey.JustPressed()) + { + string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); + string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); + string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); + int festivalScore = Game1.player.festivalScore; + int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; + int qiGems = Game1.player.QiGems; + int qiCoins = Game1.player.clubCoins; + + string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; + + if (festivalScore > 0) + toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; + + if (walnut > 0) + toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; + + if (qiGems > 0) + toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; + + if (qiCoins > 0) + toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; + + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + inventoryPageQueryKey = ""; + hoveredItemQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 7a5efea..5e85c02 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,10 +34,10 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.inventoryPageQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; GameMenuPatches.optionsPageQueryKey = ""; SocialPagePatch.Cleanup(); + InventoryPagePatch.Cleanup(); CraftingPagePatch.Cleanup(); } else if (menu is JunimoNoteMenu) From 820d714594eed1fc8db04605c734f065802afdd3 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:35:58 +0530 Subject: [PATCH 30/61] Moved options page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 54 --------------- .../GameMenuPatches/OptionsPagePatch.cs | 67 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 69 insertions(+), 56 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 6cc7464..885a78a 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -70,7 +70,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(OptionsPage), nameof(OptionsPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.OptionsPagePatch)) + postfix: new HarmonyMethod(typeof(OptionsPagePatch), nameof(OptionsPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index 84c7300..ae93dc8 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -10,7 +10,6 @@ namespace stardew_access.Patches internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; internal static string exitPageQueryKey = ""; - internal static string optionsPageQueryKey = ""; internal static string profilePageQuery = ""; internal static void GameMenuPatch(GameMenu __instance) @@ -45,59 +44,6 @@ namespace stardew_access.Patches } - internal static void OptionsPagePatch(OptionsPage __instance) - { - try - { - int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - for (int i = 0; i < __instance.optionSlots.Count; i++) - { - if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) - { - OptionsElement optionsElement = __instance.options[currentItemIndex + i]; - string toSpeak = optionsElement.label; - - if (optionsElement is OptionsButton) - toSpeak = $" {toSpeak} Button"; - else if (optionsElement is OptionsCheckbox) - toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; - else if (optionsElement is OptionsDropDown) - toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; - else if (optionsElement is OptionsSlider) - toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; - else if (optionsElement is OptionsPlusMinus) - toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; - else if (optionsElement is OptionsInputListener) - { - string buttons = ""; - ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); - toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; - } - else - { - if (toSpeak.Contains(":")) - toSpeak = toSpeak.Replace(":", ""); - - toSpeak = $"{toSpeak} Options:"; - } - - if (optionsPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - optionsPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ExitPagePatch(ExitPage __instance) { try diff --git a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs new file mode 100644 index 0000000..a05d478 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs @@ -0,0 +1,67 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class OptionsPagePatch + { + internal static string optionsPageQueryKey = ""; + + internal static void DrawPatch(OptionsPage __instance) + { + try + { + int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + for (int i = 0; i < __instance.optionSlots.Count; i++) + { + if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) + { + OptionsElement optionsElement = __instance.options[currentItemIndex + i]; + string toSpeak = optionsElement.label; + + if (optionsElement is OptionsButton) + toSpeak = $" {toSpeak} Button"; + else if (optionsElement is OptionsCheckbox) + toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; + else if (optionsElement is OptionsDropDown) + toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; + else if (optionsElement is OptionsSlider) + toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; + else if (optionsElement is OptionsPlusMinus) + toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; + else if (optionsElement is OptionsInputListener) + { + string buttons = ""; + ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); + toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; + } + else + { + if (toSpeak.Contains(":")) + toSpeak = toSpeak.Replace(":", ""); + + toSpeak = $"{toSpeak} Options:"; + } + + if (optionsPageQueryKey != toSpeak) + { + optionsPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + optionsPageQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 5e85c02..644f9c0 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -35,7 +35,7 @@ namespace stardew_access.Patches { GameMenuPatches.gameMenuQueryKey = ""; GameMenuPatches.exitPageQueryKey = ""; - GameMenuPatches.optionsPageQueryKey = ""; + OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); InventoryPagePatch.Cleanup(); CraftingPagePatch.Cleanup(); From 8d11cc6266a83ef0ad21ab6f4ccf335fa29058d2 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:40:01 +0530 Subject: [PATCH 31/61] Moved exit page patch --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/GameMenuPatches.cs | 40 ---------------- .../Patches/GameMenuPatches/ExitPagePatch.cs | 48 +++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 4 files changed, 50 insertions(+), 42 deletions(-) create mode 100644 stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 885a78a..395fe61 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -75,7 +75,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ExitPage), nameof(ExitPage.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.ExitPagePatch)) + postfix: new HarmonyMethod(typeof(ExitPagePatch), nameof(ExitPagePatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches.cs index ae93dc8..d12998b 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches.cs @@ -4,13 +4,9 @@ using StardewValley.Objects; namespace stardew_access.Patches { - // Menus in the game menu i.e., the menu which opens when we press `e` internal class GameMenuPatches { - internal static string hoveredItemQueryKey = ""; internal static string gameMenuQueryKey = ""; - internal static string exitPageQueryKey = ""; - internal static string profilePageQuery = ""; internal static void GameMenuPatch(GameMenu __instance) { @@ -42,41 +38,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - - internal static void ExitPagePatch(ExitPage __instance) - { - try - { - if (__instance.exitToTitle.visible && - __instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = "Exit to Title Button"; - if (exitPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.exitToDesktop.visible && - __instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = "Exit to Desktop Button"; - if (exitPageQueryKey != toSpeak) - { - gameMenuQueryKey = ""; - exitPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } } } diff --git a/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs b/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs new file mode 100644 index 0000000..81431f7 --- /dev/null +++ b/stardew-access/Patches/GameMenuPatches/ExitPagePatch.cs @@ -0,0 +1,48 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ExitPagePatch + { + internal static string exitPageQueryKey = ""; + + internal static void DrawPatch(ExitPage __instance) + { + try + { + if (__instance.exitToTitle.visible && + __instance.exitToTitle.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string toSpeak = "Exit to Title Button"; + if (exitPageQueryKey != toSpeak) + { + exitPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + if (__instance.exitToDesktop.visible && + __instance.exitToDesktop.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + string toSpeak = "Exit to Desktop Button"; + if (exitPageQueryKey != toSpeak) + { + exitPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + exitPageQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 644f9c0..04e6715 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -34,7 +34,7 @@ namespace stardew_access.Patches else if (menu is GameMenu) { GameMenuPatches.gameMenuQueryKey = ""; - GameMenuPatches.exitPageQueryKey = ""; + ExitPagePatch.Cleanup(); OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); InventoryPagePatch.Cleanup(); From 911c93a555126dedbda5dffc78d14cd59d4467c6 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 19:45:01 +0530 Subject: [PATCH 32/61] Moved game menu patch --- stardew-access/HarmonyPatches.cs | 2 +- .../GameMenuPatch.cs} | 10 +++++++--- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) rename stardew-access/Patches/{GameMenuPatches.cs => GameMenuPatches/GameMenuPatch.cs} (87%) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 395fe61..a993c81 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -65,7 +65,7 @@ namespace stardew_access #region Game Menu Patches harmony.Patch( original: AccessTools.Method(typeof(GameMenu), nameof(GameMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(GameMenuPatches), nameof(GameMenuPatches.GameMenuPatch)) + postfix: new HarmonyMethod(typeof(GameMenuPatch), nameof(GameMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/GameMenuPatches.cs b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs similarity index 87% rename from stardew-access/Patches/GameMenuPatches.cs rename to stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs index d12998b..f8918bf 100644 --- a/stardew-access/Patches/GameMenuPatches.cs +++ b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs @@ -1,14 +1,13 @@ using StardewValley; using StardewValley.Menus; -using StardewValley.Objects; namespace stardew_access.Patches { - internal class GameMenuPatches + internal class GameMenuPatch { internal static string gameMenuQueryKey = ""; - internal static void GameMenuPatch(GameMenu __instance) + internal static void DrawPatch(GameMenu __instance) { try { @@ -38,5 +37,10 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } + + internal static void Cleanup() + { + gameMenuQueryKey = ""; + } } } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 04e6715..3260a80 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -33,7 +33,7 @@ namespace stardew_access.Patches } else if (menu is GameMenu) { - GameMenuPatches.gameMenuQueryKey = ""; + GameMenuPatch.Cleanup(); ExitPagePatch.Cleanup(); OptionsPagePatch.Cleanup(); SocialPagePatch.Cleanup(); From 15380e5b764f763eeed4d1468b049faccc1c97ec Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 20:44:54 +0530 Subject: [PATCH 33/61] Improved game menu patch code - Added active suffix if the hovered tab button matches the current tab --- .../Patches/GameMenuPatches/GameMenuPatch.cs | 24 ++++++++++--------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs index f8918bf..0255dbb 100644 --- a/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs +++ b/stardew-access/Patches/GameMenuPatches/GameMenuPatch.cs @@ -11,26 +11,28 @@ namespace stardew_access.Patches { try { - // Continue if only in the Inventory Page or Crafting Page - if (__instance.currentTab != 0 && __instance.currentTab != 4 && __instance.currentTab != 6 && __instance.currentTab != 7) + // Skip if in map page + if (__instance.currentTab == 3) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position for (int i = 0; i < __instance.tabs.Count; i++) { - if (__instance.tabs[i].containsPoint(x, y)) + if (!__instance.tabs[i].containsPoint(x, y)) + continue; + + string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab" + ((i == __instance.currentTab) ? " Active" : ""); + if (gameMenuQueryKey != toSpeak) { - string toSpeak = $"{GameMenu.getLabelOfTabFromIndex(i)} Tab"; - if (gameMenuQueryKey != toSpeak) - { - MainClass.DebugLog("here"); - gameMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; + gameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); } + return; } + + // If not hovering on any tab button + Cleanup(); } catch (Exception e) { From 0fa90e4c74f3d63fe37b32f84eb588295031d885 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 24 Feb 2023 20:45:35 +0530 Subject: [PATCH 34/61] Improved and organised code in InventoryPagePatch.cs --- .../GameMenuPatches/InventoryPagePatch.cs | 291 +++++++----------- stardew-access/Patches/IClickableMenuPatch.cs | 3 +- stardew-access/Patches/InventoryUtils.cs | 6 + 3 files changed, 122 insertions(+), 178 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs index bfc367b..8dc26b3 100644 --- a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -14,202 +14,141 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + if (narrateHoveredButton(__instance, x, y)) { - string toSpeak = "Drop Item"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } + return; } - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + if (narrateHoveredEquipmentSlot(__instance, x, y)) { - string toSpeak = "Organize Inventory Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } + return; } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - - #region Narrate equipment slots - for (int i = 0; i < __instance.equipmentIcons.Count; i++) - { - if (__instance.equipmentIcons[i].containsPoint(x, y)) - { - string toSpeak = ""; - - #region Get name and description of the item - switch (__instance.equipmentIcons[i].name) - { - case "Hat": - { - if (Game1.player.hat.Value != null) - { - toSpeak = $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}"; - } - else - { - toSpeak = "Hat slot"; - } - } - break; - case "Left Ring": - { - if (Game1.player.leftRing.Value != null) - { - toSpeak = $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}"; - } - else - { - toSpeak = "Left Ring slot"; - } - } - break; - case "Right Ring": - { - if (Game1.player.rightRing.Value != null) - { - toSpeak = $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}"; - } - else - { - toSpeak = "Right ring slot"; - } - } - break; - case "Boots": - { - if (Game1.player.boots.Value != null) - { - toSpeak = $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}"; - } - else - { - toSpeak = "Boots slot"; - } - } - break; - case "Shirt": - { - if (Game1.player.shirtItem.Value != null) - { - toSpeak = $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}"; - } - else - { - toSpeak = "Shirt slot"; - } - } - break; - case "Pants": - { - if (Game1.player.pantsItem.Value != null) - { - toSpeak = $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}"; - } - else - { - toSpeak = "Pants slot"; - } - } - break; - } - #endregion - - if (inventoryPageQueryKey != toSpeak) - { - inventoryPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { inventoryPageQueryKey = ""; + return; } - #endregion - if (MainClass.Config.MoneyKey.JustPressed()) - { - string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); - string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); - string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); - int festivalScore = Game1.player.festivalScore; - int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; - int qiGems = Game1.player.QiGems; - int qiCoins = Game1.player.clubCoins; + handleKeyBinds(); - string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; - - if (festivalScore > 0) - toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; - - if (walnut > 0) - toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; - - if (qiGems > 0) - toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; - - if (qiCoins > 0) - toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; - - MainClass.ScreenReader.Say(toSpeak, true); - } + // If no slot or button is hovered + Cleanup(); } catch (Exception e) { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + MainClass.ErrorLog($"An error occured in InventoryPagePatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); } } + private static void handleKeyBinds() + { + if (!MainClass.Config.MoneyKey.JustPressed()) + return; + + string farmName = Game1.content.LoadString("Strings\\UI:Inventory_FarmName", Game1.player.farmName.Value); + string currentFunds = Game1.content.LoadString("Strings\\UI:Inventory_CurrentFunds" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas(Game1.player.Money)); + string totalEarnings = Game1.content.LoadString("Strings\\UI:Inventory_TotalEarnings" + (Game1.player.useSeparateWallets ? "_Separate" : ""), Utility.getNumberWithCommas((int)Game1.player.totalMoneyEarned)); + int festivalScore = Game1.player.festivalScore; + int walnut = Game1.netWorldState.Value.GoldenWalnuts.Value; + int qiGems = Game1.player.QiGems; + int qiCoins = Game1.player.clubCoins; + + string toSpeak = $"{farmName}\n{currentFunds}\n{totalEarnings}"; + + if (festivalScore > 0) + toSpeak = $"{toSpeak}\nFestival Score: {festivalScore}"; + + if (walnut > 0) + toSpeak = $"{toSpeak}\nGolden Walnut: {walnut}"; + + if (qiGems > 0) + toSpeak = $"{toSpeak}\nQi Gems: {qiGems}"; + + if (qiCoins > 0) + toSpeak = $"{toSpeak}\nQi Club Coins: {qiCoins}"; + + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static bool narrateHoveredButton(InventoryPage __instance, int x, int y) + { + string? toSpeak = null; + bool isDropItemButton = false; + + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + toSpeak = "Organize Inventory Button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash Can"; + } + else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + toSpeak = "Organize Button"; + } + else if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + toSpeak = "Community Center Button"; + } + else + { + return false; + } + + if (toSpeak != null && inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + private static bool narrateHoveredEquipmentSlot(InventoryPage __instance, int mouseX, int mouseY) + { + for (int i = 0; i < __instance.equipmentIcons.Count; i++) + { + if (!__instance.equipmentIcons[i].containsPoint(mouseX, mouseY)) + continue; + + string toSpeak = getNameAndDescriptionOfItem(__instance.equipmentIcons[i].name); + + if (inventoryPageQueryKey != toSpeak) + { + inventoryPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + + return true; + } + + return false; + } + + private static string getNameAndDescriptionOfItem(string slotName) => slotName switch + { + "Hat" => (Game1.player.hat.Value != null) ? $"{Game1.player.hat.Value.DisplayName}, {Game1.player.hat.Value.getDescription()}" : "Hat slot", + "Left Ring" => (Game1.player.leftRing.Value != null) ? $"{Game1.player.leftRing.Value.DisplayName}, {Game1.player.leftRing.Value.getDescription()}" : "Left Ring slot", + "Right Ring" => (Game1.player.rightRing.Value != null) ? $"{Game1.player.rightRing.Value.DisplayName}, {Game1.player.rightRing.Value.getDescription()}" : "Right ring slot", + "Boots" => (Game1.player.boots.Value != null) ? $"{Game1.player.boots.Value.DisplayName}, {Game1.player.boots.Value.getDescription()}" : "Boots slot", + "Shirt" => (Game1.player.shirtItem.Value != null) ? $"{Game1.player.shirtItem.Value.DisplayName}, {Game1.player.shirtItem.Value.getDescription()}" : "Shirt slot", + "Pants" => (Game1.player.pantsItem.Value != null) ? $"{Game1.player.pantsItem.Value.DisplayName}, {Game1.player.pantsItem.Value.getDescription()}" : "Pants slot", + _ => "unkown slot" + }; + internal static void Cleanup() { + InventoryUtils.Cleanup(); inventoryPageQueryKey = ""; hoveredItemQueryKey = ""; } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 3260a80..24a6184 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -118,8 +118,7 @@ namespace stardew_access.Patches MenuPatches.pondQueryMenuQuery = " "; } - InventoryUtils.hoveredItemQueryKey = ""; - InventoryUtils.prevSlotIndex = -999; + InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = ""; } } diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Patches/InventoryUtils.cs index 5903f92..f4a7602 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Patches/InventoryUtils.cs @@ -202,5 +202,11 @@ namespace stardew_access.Patches if (MainClass.Config.DisableInventoryVerbosity) return ""; return " not usable here"; } + + internal static void Cleanup() + { + hoveredItemQueryKey = ""; + prevSlotIndex = -999; + } } } From 774454ce0e0fcfccd8aad3370b396d1aa90221c7 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 3 Mar 2023 21:03:37 +0530 Subject: [PATCH 35/61] Refactored code CraftingPagePatch.cs --- .../GameMenuPatches/CraftingPagePatch.cs | 344 +++++++++--------- 1 file changed, 172 insertions(+), 172 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index 51db2e5..8599840 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -17,191 +17,23 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + if (narrateMenuButtons(__instance, x, y)) { - // snap to first inventory slot - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = -1; - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) - { - // snap to first crafting recipe - __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); - __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = 0; - } - else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) - { - isSelectingRecipe = true; - CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); - Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); - } - - #region Narrate buttons in the menu - if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) - { - string toSpeak = "Previous Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } return; } - if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + if (narrateHoveredRecipe(__instance, ___currentCraftingPage, ___hoverRecipe, x, y)) { - string toSpeak = "Next Recipe List"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } return; } - if (__instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash Can"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - #endregion - - #region Narrate hovered recipe - if (___hoverRecipe != null) - { - string name = ___hoverRecipe.DisplayName; - int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; - string description = ""; - string ingredients = ""; - string buffs = ""; - string craftable = ""; - - description = $"Description:\n{___hoverRecipe.description}"; - craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; - - #region Crafting ingredients - ingredients = "Ingredients:\n"; - for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) - { - int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; - int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; - string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); - - ingredients += $" ,{recipeCount} {recipeName}"; - } - #endregion - - #region Health & stamina and buff items (effects like +1 walking speed) - Item producesItem = ___hoverRecipe.createItem(); - if (producesItem is StardewValley.Object producesItemObject) - { - if (producesItemObject.Edibility != -300) - { - int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); - buffs += $"{stamina_recovery} Energy"; - if (stamina_recovery >= 0) - { - int health_recovery = producesItemObject.healthRecoveredOnConsumption(); - buffs += $"\n{health_recovery} Health"; - } - } - // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) - bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; - string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) - ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) - : null; - - if (buffIconsToDisplay != null) - { - for (int j = 0; j < buffIconsToDisplay.Length; j++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; - if (j <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - buffs += $"{buffName}\n"; - } - catch (Exception) { } - } - - buffs = $"Buffs and boosts:\n {buffs}"; - } - } - #endregion - - - string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; - - if (craftingPageQueryKey != toSpeak) - { - craftingPageQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - else - { - var isRecipeInFocus = false; - foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) - { - if (item.Key.containsPoint(x, y)) - { - isRecipeInFocus = true; - break; - } - } - - if (isRecipeInFocus) - { - string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; - - if (craftingPageQueryKey != query) - { - craftingPageQueryKey = query; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say("unknown recipe", true); - } - return; - } - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) { craftingPageQueryKey = ""; return; } - #endregion + + handleKeyBinds(__instance, ___currentCraftingPage); } catch (Exception e) { @@ -209,6 +41,174 @@ namespace stardew_access.Patches } } + private static void handleKeyBinds(CraftingPage __instance, int ___currentCraftingPage) + { + if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + // snap to first inventory slot + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = -1; + } + else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) + { + // snap to first crafting recipe + __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); + __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = 0; + } + else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) + { + isSelectingRecipe = true; + CycleThroughRecipies(__instance.pagesOfCraftingRecipes, ___currentCraftingPage, __instance); + Task.Delay(200).ContinueWith(_ => { isSelectingRecipe = false; }); + } + } + + private static bool narrateMenuButtons(CraftingPage __instance, int x, int y) + { + string? toSpeak = null; + bool isDropItemButton = false; + + if (__instance.upButton != null && __instance.upButton.containsPoint(x, y)) + { + toSpeak = "Previous Recipe List"; + } + else if (__instance.downButton != null && __instance.downButton.containsPoint(x, y)) + { + toSpeak = "Next Recipe List"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash Can"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else + { + return false; + } + + if (toSpeak != null && craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + private static bool narrateHoveredRecipe(CraftingPage __instance, int ___currentCraftingPage, CraftingRecipe ___hoverRecipe, int x, int y) + { + if (___hoverRecipe == null) + { + var isRecipeInFocus = false; + foreach (var item in __instance.pagesOfCraftingRecipes[___currentCraftingPage]) + { + if (!item.Key.containsPoint(x, y)) + continue; + + isRecipeInFocus = true; + break; + } + + if (!isRecipeInFocus) + return false; + + string query = $"unknown recipe:{__instance.getCurrentlySnappedComponent().myID}"; + + if (craftingPageQueryKey != query) + { + craftingPageQueryKey = query; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say("unknown recipe", true); + } + return true; + } + + string name = ___hoverRecipe.DisplayName; + int numberOfProduce = ___hoverRecipe.numberProducedPerCraft; + string description = ""; + string ingredients = ""; + string buffs = ""; + string craftable = ""; + + description = $"Description:\n{___hoverRecipe.description}"; + craftable = ___hoverRecipe.doesFarmerHaveIngredientsInInventory(getContainerContents(__instance._materialContainers)) ? "Craftable" : "Not Craftable"; + + #region Crafting ingredients + ingredients = "Ingredients:\n"; + for (int i = 0; i < ___hoverRecipe.recipeList.Count; i++) + { + int recipeCount = ___hoverRecipe.recipeList.ElementAt(i).Value; + int recipeItem = ___hoverRecipe.recipeList.ElementAt(i).Key; + string recipeName = ___hoverRecipe.getNameFromIndex(recipeItem); + + ingredients += $" ,{recipeCount} {recipeName}"; + } + #endregion + + #region Health & stamina and buff items (effects like +1 walking speed) + Item producesItem = ___hoverRecipe.createItem(); + if (producesItem is StardewValley.Object producesItemObject) + { + if (producesItemObject.Edibility != -300) + { + int stamina_recovery = producesItemObject.staminaRecoveredOnConsumption(); + buffs += $"{stamina_recovery} Energy"; + if (stamina_recovery >= 0) + { + int health_recovery = producesItemObject.healthRecoveredOnConsumption(); + buffs += $"\n{health_recovery} Health"; + } + } + // These variables are taken from the game's code itself (IClickableMenu.cs -> 1016 line) + bool edibleItem = producesItem != null && (int)producesItemObject.Edibility != -300; + string[]? buffIconsToDisplay = (producesItem != null && edibleItem && Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/').Length > 7) + ? producesItem.ModifyItemBuffs(Game1.objectInformation[producesItemObject.ParentSheetIndex].Split('/')[7].Split(' ')) + : null; + + if (buffIconsToDisplay != null) + { + for (int j = 0; j < buffIconsToDisplay.Length; j++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[j]) > 0) ? "+" : "") + buffIconsToDisplay[j] + " "; + if (j <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + j, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + buffs += $"{buffName}\n"; + } + catch (Exception) { } + } + + buffs = $"Buffs and boosts:\n {buffs}"; + } + } + #endregion + + + string toSpeak = $"{numberOfProduce} {name}, {craftable}, \n\t{ingredients}, \n\t{description} \n\t{buffs}"; + + if (craftingPageQueryKey != toSpeak) + { + craftingPageQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + + return true; + } + private static void CycleThroughRecipies(List> pagesOfCraftingRecipes, int ___currentCraftingPage, CraftingPage __instance) { currentSelectedCraftingRecipe++; From b22af63b975eff558603572149bf1b5e0945c0d7 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 11:29:23 +0530 Subject: [PATCH 36/61] Improved and organised code in SocialPagePatch.cs --- .../GameMenuPatches/OptionsPagePatch.cs | 68 ++--- .../GameMenuPatches/SocialPagePatch.cs | 265 +++++++++--------- 2 files changed, 168 insertions(+), 165 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs index a05d478..f4d9879 100644 --- a/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/OptionsPagePatch.cs @@ -15,42 +15,42 @@ namespace stardew_access.Patches int x = Game1.getMouseX(true), y = Game1.getMouseY(true); for (int i = 0; i < __instance.optionSlots.Count; i++) { - if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) + if (!__instance.optionSlots[i].bounds.Contains(x, y) || currentItemIndex + i >= __instance.options.Count || !__instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) + continue; + + OptionsElement optionsElement = __instance.options[currentItemIndex + i]; + string toSpeak = optionsElement.label; + + if (optionsElement is OptionsButton) + toSpeak = $" {toSpeak} Button"; + else if (optionsElement is OptionsCheckbox) + toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; + else if (optionsElement is OptionsDropDown) + toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; + else if (optionsElement is OptionsSlider) + toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; + else if (optionsElement is OptionsPlusMinus) + toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; + else if (optionsElement is OptionsInputListener) { - OptionsElement optionsElement = __instance.options[currentItemIndex + i]; - string toSpeak = optionsElement.label; - - if (optionsElement is OptionsButton) - toSpeak = $" {toSpeak} Button"; - else if (optionsElement is OptionsCheckbox) - toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; - else if (optionsElement is OptionsDropDown) - toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; - else if (optionsElement is OptionsSlider) - toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; - else if (optionsElement is OptionsPlusMinus) - toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; - else if (optionsElement is OptionsInputListener) - { - string buttons = ""; - ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); - toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; - } - else - { - if (toSpeak.Contains(":")) - toSpeak = toSpeak.Replace(":", ""); - - toSpeak = $"{toSpeak} Options:"; - } - - if (optionsPageQueryKey != toSpeak) - { - optionsPageQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; + string buttons = ""; + ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); + toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; } + else + { + if (toSpeak.Contains(":")) + toSpeak = toSpeak.Replace(":", ""); + + toSpeak = $"{toSpeak} Options:"; + } + + if (optionsPageQueryKey != toSpeak) + { + optionsPageQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; } } catch (Exception e) diff --git a/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs index 3c03245..81b2ad0 100644 --- a/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/SocialPagePatch.cs @@ -14,138 +14,16 @@ namespace stardew_access.Patches int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position for (int i = ___slotPosition; i < ___slotPosition + 5; i++) { - if (i < ___sprites.Count) + if (i >= ___sprites.Count) + continue; + + if (__instance.names[i] is string && narrateNPCDetails(__instance, i, ___kidsNames, x, y)) { - if (__instance.names[i] is string) - { - #region For NPCs - if (__instance.characterSlots[i].bounds.Contains(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string name = $"{__instance.names[i] as string}"; - int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); - bool datable = SocialPage.isDatable(name); - Friendship friendship = __instance.getFriendship(name); - int giftsThisWeek = friendship.GiftsThisWeek; - bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); - bool spouse = friendship.IsMarried(); - bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); - ___kidsNames.Add("Robin"); - ___kidsNames.Add("Pierre"); - ___kidsNames.Add("Caroline"); - ___kidsNames.Add("Jodi"); - ___kidsNames.Add("Kent"); - ___kidsNames.Add("George"); - ___kidsNames.Add("Evelyn"); - ___kidsNames.Add("Demetrius"); - - - - string toSpeak = $"{name}"; - - if (!hasTalked) - { - toSpeak = $"{toSpeak}, not talked yet"; - } - - - if (datable | housemate) - { - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (housemate) - { - text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); - } - else if (spouse) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (__instance.isMarriedToAnyone(name)) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (__instance.getFriendship(name).IsDivorced()) - { - text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{toSpeak}, {text2}"; - } - if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) - { - toSpeak = $"{toSpeak}, married"; - } - if (spouse) - { - toSpeak = $"{toSpeak}, spouse"; - } - else if (friendship.IsDating()) - { - toSpeak = $"{toSpeak}, dating"; - } - - toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; - - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - } - else if (__instance.names[i] is long) - { - #region For Farmers - - long farmerID = (long)__instance.names[i]; - Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); - if (farmer != null) - { - int gender = (!farmer.IsMale) ? 1 : 0; - ClickableTextureComponent clickableTextureComponent = ___sprites[i]; - if (clickableTextureComponent.containsPoint(x, y)) - { - Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); - bool spouse = friendship.IsMarried(); - string toSpeak = ""; - - string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); - if (spouse) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); - } - else if (farmer.isMarried() && !farmer.hasRoommate()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); - } - else if (!Game1.player.isMarried() && friendship.IsDating()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); - } - else if (friendship.IsDivorced()) - { - text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); - } - - toSpeak = $"{farmer.displayName}, {text2}"; - - if (socialPageQuery != toSpeak) - { - socialPageQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - - #endregion - } + return; + } + else if (__instance.names[i] is long && narrateFarmerDetails(__instance, i, ___sprites, x, y)) + { + return; } } } @@ -155,6 +33,131 @@ namespace stardew_access.Patches } } + private static bool narrateNPCDetails(SocialPage __instance, int i, List ___kidsNames, int x, int y) + { + if (!__instance.characterSlots[i].bounds.Contains(x, y)) + return false; + + string name = $"{__instance.names[i] as string}"; + int heartLevel = Game1.player.getFriendshipHeartLevelForNPC(name); + bool datable = SocialPage.isDatable(name); + Friendship friendship = __instance.getFriendship(name); + int giftsThisWeek = friendship.GiftsThisWeek; + bool hasTalked = Game1.player.hasPlayerTalkedToNPC(name); + bool spouse = friendship.IsMarried(); + bool housemate = spouse && SocialPage.isRoommateOfAnyone(name); + ___kidsNames.Add("Robin"); + ___kidsNames.Add("Pierre"); + ___kidsNames.Add("Caroline"); + ___kidsNames.Add("Jodi"); + ___kidsNames.Add("Kent"); + ___kidsNames.Add("George"); + ___kidsNames.Add("Evelyn"); + ___kidsNames.Add("Demetrius"); + + string toSpeak = $"{name}"; + + if (!hasTalked) + { + toSpeak = $"{toSpeak}, not talked yet"; + } + + + if (datable | housemate) + { + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (housemate) + { + text2 = Game1.content.LoadString("Strings\\StringsFromCSFiles:Housemate"); + } + else if (spouse) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (__instance.isMarriedToAnyone(name)) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (__instance.getFriendship(name).IsDivorced()) + { + text2 = ((__instance.getGender(name) == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{toSpeak}, {text2}"; + } + + if (!__instance.getFriendship(name).IsMarried() && ___kidsNames.Contains(name)) + { + toSpeak = $"{toSpeak}, married"; + } + + if (spouse) + { + toSpeak = $"{toSpeak}, spouse"; + } + else if (friendship.IsDating()) + { + toSpeak = $"{toSpeak}, dating"; + } + + toSpeak = $"{toSpeak}, {heartLevel} hearts, {giftsThisWeek} gifts given this week."; + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + + private static bool narrateFarmerDetails(SocialPage __instance, int i, List ___sprites, int x, int y) + { + long farmerID = (long)__instance.names[i]; + Farmer farmer = Game1.getFarmerMaybeOffline(farmerID); + if (farmer == null) + return false; + + int gender = (!farmer.IsMale) ? 1 : 0; + ClickableTextureComponent clickableTextureComponent = ___sprites[i]; + if (!clickableTextureComponent.containsPoint(x, y)) + return false; + + Friendship friendship = Game1.player.team.GetFriendship(Game1.player.UniqueMultiplayerID, farmerID); + bool spouse = friendship.IsMarried(); + string toSpeak = ""; + + string text2 = (LocalizedContentManager.CurrentLanguageCode != LocalizedContentManager.LanguageCode.pt) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635") : ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').First() : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11635").Split('/').Last()); + if (spouse) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11636") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11637")); + } + else if (farmer.isMarried() && !farmer.hasRoommate()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_MaleNPC") : Game1.content.LoadString("Strings\\UI:SocialPage_MarriedToOtherPlayer_FemaleNPC")); + } + else if (!Game1.player.isMarried() && friendship.IsDating()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11639") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11640")); + } + else if (friendship.IsDivorced()) + { + text2 = ((gender == 0) ? Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11642") : Game1.content.LoadString("Strings\\StringsFromCSFiles:SocialPage.cs.11643")); + } + + toSpeak = $"{farmer.displayName}, {text2}"; + + if (socialPageQuery != toSpeak) + { + socialPageQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + internal static void Cleanup() { socialPageQuery = ""; From 403a97b63323dc193914d6c4d6fdc9b925654f83 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 12:03:08 +0530 Subject: [PATCH 37/61] Improved and organised code in AnimalQueryMenuPatch.cs --- .../Patches/AnimalQueryMenuPatch.cs | 103 ++++++++++-------- stardew-access/Patches/IClickableMenuPatch.cs | 3 +- 2 files changed, 60 insertions(+), 46 deletions(-) diff --git a/stardew-access/Patches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/AnimalQueryMenuPatch.cs index 232d573..334e580 100644 --- a/stardew-access/Patches/AnimalQueryMenuPatch.cs +++ b/stardew-access/Patches/AnimalQueryMenuPatch.cs @@ -18,61 +18,76 @@ namespace stardew_access.Patches if (TextBoxPatch.isAnyTextBoxActive) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For narrating animal details - string toSpeak = " ", details = " "; isOnFarm = ___movingAnimal; animalQueryMenu = __instance; animalBeingMoved = ___animal; - if (isPrimaryInfoKeyPressed & !isNarratingAnimalInfo) - { - string name = ___animal.displayName; - string type = ___animal.displayType; - int age = (___animal.GetDaysOwned() + 1) / 28 + 1; - string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); - string parent = ""; - if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) - { - ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); - } - if (___parentName != null) - { - parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); - } + narrateAnimalDetailsOnKeyPress(___animal, ___parentName); - details = $"Name: {name} Type: {type} \n\t Age: {ageText} {parent}"; - animalQueryMenuQuery = ""; - - isNarratingAnimalInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "OK button"; - else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) - toSpeak = $"Sell for {___animal.getSellPrice()}g button"; - else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm selling animal"; - else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel selling animal"; - else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) - toSpeak = "Change home building button"; - else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) - toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = "Animal name text box"; - - if (animalQueryMenuQuery != toSpeak) - { - animalQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say($"{details} {toSpeak}", true); - } + narrateHoveredButton(__instance, ___animal, ___confirmingSell, x, y); } catch (System.Exception e) { MainClass.ErrorLog($"An error occured in AnimalQueryMenuPatch()->DrawPatch():\n{e.Message}\n{e.StackTrace}"); } } + + private static void narrateAnimalDetailsOnKeyPress(FarmAnimal ___animal, string ___parentName) + { + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + if (!isPrimaryInfoKeyPressed | isNarratingAnimalInfo) + return; + + string name = ___animal.displayName; + string type = ___animal.displayType; + int age = (___animal.GetDaysOwned() + 1) / 28 + 1; + string ageText = (age <= 1) ? Game1.content.LoadString("Strings\\UI:AnimalQuery_Age1") : Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeN", age); + string parent = ""; + if ((int)___animal.age.Value < (byte)___animal.ageWhenMature.Value) + { + ageText += Game1.content.LoadString("Strings\\UI:AnimalQuery_AgeBaby"); + } + if (___parentName != null) + { + parent = Game1.content.LoadString("Strings\\UI:AnimalQuery_Parent", ___parentName); + } + + isNarratingAnimalInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingAnimalInfo = false; }); // Adds delay + + MainClass.ScreenReader.Say($"Name: {name} Type: {type} \n\t Age: {ageText} {parent}", true); + } + + private static void narrateHoveredButton(AnimalQueryMenu __instance, FarmAnimal ___animal, bool ___confirmingSell, int x, int y) + { + string toSpeak = ""; + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "OK button"; + else if (__instance.sellButton != null && __instance.sellButton.containsPoint(x, y)) + toSpeak = $"Sell for {___animal.getSellPrice()}g button"; + else if (___confirmingSell && __instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm selling animal"; + else if (___confirmingSell && __instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel selling animal"; + else if (__instance.moveHomeButton != null && __instance.moveHomeButton.containsPoint(x, y)) + toSpeak = "Change home building button"; + else if (__instance.allowReproductionButton != null && __instance.allowReproductionButton.containsPoint(x, y)) + toSpeak = ((___animal.allowReproduction.Value) ? "Enabled" : "Disabled") + " allow reproduction button"; + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = "Animal name text box"; + + if (animalQueryMenuQuery != toSpeak) + { + animalQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say($"{toSpeak}", true); + } + } + + internal static void Cleanup() + { + AnimalQueryMenuPatch.animalQueryMenuQuery = ""; + AnimalQueryMenuPatch.animalQueryMenu = null; + } } } diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 24a6184..da31c47 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -77,8 +77,7 @@ namespace stardew_access.Patches } else if (menu is AnimalQueryMenu) { - AnimalQueryMenuPatch.animalQueryMenuQuery = ""; - AnimalQueryMenuPatch.animalQueryMenu = null; + AnimalQueryMenuPatch.Cleanup(); } else if (menu is DialogueBox) { From b0ef71cd4a3aa95801f86d8148cddfdd59f06366 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 12:16:39 +0530 Subject: [PATCH 38/61] bug fix --- stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs | 4 ++-- stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index 8599840..f9c5180 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -17,6 +17,8 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + handleKeyBinds(__instance, ___currentCraftingPage); + if (narrateMenuButtons(__instance, x, y)) { return; @@ -32,8 +34,6 @@ namespace stardew_access.Patches craftingPageQueryKey = ""; return; } - - handleKeyBinds(__instance, ___currentCraftingPage); } catch (Exception e) { diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs index 8dc26b3..dc05fd3 100644 --- a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -14,6 +14,8 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + handleKeyBinds(); + if (narrateHoveredButton(__instance, x, y)) { return; @@ -30,8 +32,6 @@ namespace stardew_access.Patches return; } - handleKeyBinds(); - // If no slot or button is hovered Cleanup(); } From baede5796585ef28dae7eb25c3e2a541c08259bf Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 19:44:58 +0530 Subject: [PATCH 39/61] Improved and organised code in bundle menu patches --- stardew-access/HarmonyPatches.cs | 4 +- stardew-access/Patches/BundleMenuPatches.cs | 360 ------------------ .../BundleMenuPatches/JojaCDMenuPatch.cs | 70 ++++ .../BundleMenuPatches/JunimoNoteMenuPatch.cs | 297 +++++++++++++++ stardew-access/Patches/ChatMenuPatches.cs | 3 +- stardew-access/Patches/IClickableMenuPatch.cs | 7 +- 6 files changed, 373 insertions(+), 368 deletions(-) delete mode 100644 stardew-access/Patches/BundleMenuPatches.cs create mode 100644 stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs create mode 100644 stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index a993c81..e22dbc4 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -117,12 +117,12 @@ namespace stardew_access #region Bundle Menu Patches harmony.Patch( original: AccessTools.Method(typeof(JunimoNoteMenu), nameof(JunimoNoteMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(BundleMenuPatches), nameof(BundleMenuPatches.JunimoNoteMenuPatch)) + postfix: new HarmonyMethod(typeof(JunimoNoteMenuPatch), nameof(JunimoNoteMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(JojaCDMenu), nameof(JojaCDMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(BundleMenuPatches), nameof(BundleMenuPatches.JojaCDMenuPatch)) + postfix: new HarmonyMethod(typeof(JojaCDMenuPatch), nameof(JojaCDMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/BundleMenuPatches.cs b/stardew-access/Patches/BundleMenuPatches.cs deleted file mode 100644 index fc3dc6c..0000000 --- a/stardew-access/Patches/BundleMenuPatches.cs +++ /dev/null @@ -1,360 +0,0 @@ -using StardewValley; -using StardewValley.Locations; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class BundleMenuPatches - { - internal static string junimoNoteMenuQuery = ""; - internal static string currentJunimoArea = ""; - internal static string jojaCDMenuQuery = ""; - internal static bool isUsingCustomButtons = false; - internal static int currentIngredientListItem = -1, currentIngredientInputSlot = -1, currentInventorySlot = -1; - - #region Joja Mart Bundle/Quests - internal static void JojaCDMenuPatch(JojaCDMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = ""; - - for (int i = 0; i < __instance.checkboxes.Count; i++) - { - ClickableComponent c = __instance.checkboxes[i]; - if (!c.containsPoint(x, y)) - continue; - - if (c.name.Equals("complete")) - { - toSpeak = $"Completed {getNameFromIndex(i)}"; - } - else - { - toSpeak = $"{getNameFromIndex(i)} Cost: {__instance.getPriceFromButtonNumber(i)}g Description: {__instance.getDescriptionFromButtonNumber(i)}"; - } - - break; - } - - if (jojaCDMenuQuery != toSpeak) - { - jojaCDMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static string getNameFromIndex(int i) - { - string name = i switch - { - 0 => "Bus", - 1 => "Minecarts", - 2 => "Bridge", - 3 => "Greenhouse", - 4 => "Panning", - _ => "", - }; - - if (name != "") - return $"{name} Project"; - else - return "unkown"; - } - #endregion - - #region Community Center Bundles - internal static void JunimoNoteMenuPatch(JunimoNoteMenu __instance, bool ___specificBundlePage, int ___whichArea, Bundle ___currentPageBundle) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (!___specificBundlePage) - { - currentIngredientListItem = -1; - isUsingCustomButtons = false; - - string areaName = __instance.scrambledText ? CommunityCenter.getAreaEnglishDisplayNameFromNumber(___whichArea) : CommunityCenter.getAreaDisplayNameFromNumber(___whichArea); - string reward = __instance.getRewardNameForArea(___whichArea); - - if (__instance.scrambledText) - { - string toSpeak = "Scrambled Text"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (currentJunimoArea != areaName) - { - currentJunimoArea = areaName; - MainClass.ScreenReader.Say($"Area {areaName}, {reward}", true); - return; - } - - for (int i = 0; i < __instance.bundles.Count; i++) - { - if (__instance.bundles[i].containsPoint(x, y)) - { - string toSpeak = $"{__instance.bundles[i].name} bundle"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - if (__instance.presentButton != null && __instance.presentButton.containsPoint(x, y)) - { - string toSpeak = "Present Button"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.fromGameMenu) - { - if (__instance.areaNextButton.visible && __instance.areaNextButton.containsPoint(x, y)) - { - string toSpeak = "Next Area Button"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.areaBackButton.visible && __instance.areaBackButton.containsPoint(x, y)) - { - string toSpeak = "Previous Area Button"; - if (junimoNoteMenuQuery != toSpeak) - { - junimoNoteMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - } - else - { - bool isIPressed = MainClass.Config.BundleMenuIngredientsKey.JustPressed(); // For the ingredients - bool isCPressed = MainClass.Config.BundleMenuInventoryItemsKey.JustPressed(); // For the items in inventory - bool isPPressed = MainClass.Config.BundleMenuPurchaseButtonKey.JustPressed(); // For the Purchase Button - bool isVPressed = MainClass.Config.BundleMenuIngredientsInputSlotKey.JustPressed(); // For the ingredient input slots - bool isBackPressed = MainClass.Config.BundleMenuBackButtonKey.JustPressed(); // For the back button - bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); - - if (isIPressed && !isUsingCustomButtons) - { - isUsingCustomButtons = true; - JunimoNoteCustomButtons(__instance, ___currentPageBundle, 0, isLeftShiftPressed); - Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); - } - else if (isVPressed && !isUsingCustomButtons) - { - isUsingCustomButtons = true; - JunimoNoteCustomButtons(__instance, ___currentPageBundle, 1, isLeftShiftPressed); - Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); - } - else if (isCPressed && !isUsingCustomButtons) - { - isUsingCustomButtons = true; - JunimoNoteCustomButtons(__instance, ___currentPageBundle, 2, isLeftShiftPressed); - Task.Delay(200).ContinueWith(_ => { isUsingCustomButtons = false; }); - } - else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) - { - __instance.backButton.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say("Back Button", true); - } - else if (isPPressed && __instance.purchaseButton != null && !__instance.purchaseButton.containsPoint(x, y)) - { - __instance.purchaseButton.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say("Purchase Button", true); - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static void JunimoNoteCustomButtons(JunimoNoteMenu __instance, Bundle ___currentPageBundle, int signal, bool isLeftShiftPressed = false) - { - try - { - - switch (signal) - { - case 0: // For ingredient list - { - if (___currentPageBundle.ingredients.Count >= 0) - { - currentIngredientListItem = currentIngredientListItem + (isLeftShiftPressed ? -1 : 1); - if (currentIngredientListItem >= ___currentPageBundle.ingredients.Count) - if (isLeftShiftPressed) - currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; - else - currentIngredientListItem = 0; - - if (currentIngredientListItem < 0) - if (isLeftShiftPressed) - currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; - else - currentIngredientListItem = 0; - - ClickableTextureComponent c = __instance.ingredientList[currentIngredientListItem]; - BundleIngredientDescription ingredient = ___currentPageBundle.ingredients[currentIngredientListItem]; - - Item item = new StardewValley.Object(ingredient.index, ingredient.stack, isRecipe: false, -1, ingredient.quality); - bool completed = false; - if (___currentPageBundle != null && ___currentPageBundle.ingredients != null && currentIngredientListItem < ___currentPageBundle.ingredients.Count && ___currentPageBundle.ingredients[currentIngredientListItem].completed) - { - completed = true; - } - - string toSpeak = item.DisplayName; - - if (!completed) - { - int quality = ingredient.quality; - if (quality == 1) - { - toSpeak = $"Silver quality {toSpeak}"; - } - else if (quality == 2 || quality == 3) - { - toSpeak = $"Gold quality {toSpeak}"; - } - else if (quality >= 4) - { - toSpeak = $"Iridium quality {toSpeak}"; - } - - toSpeak = $"{ingredient.stack} {toSpeak}"; - } - - if (completed) - toSpeak = $"Completed {toSpeak}"; - - c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); - } - } - break; - case 1: // For input slot list - { - if (__instance.ingredientSlots.Count >= 0) - { - currentIngredientInputSlot = currentIngredientInputSlot + (isLeftShiftPressed ? -1 : 1); - if (currentIngredientInputSlot >= __instance.ingredientSlots.Count) - if (isLeftShiftPressed) - currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; - else - currentIngredientInputSlot = 0; - - if (currentIngredientInputSlot < 0) - if (isLeftShiftPressed) - currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; - else - currentIngredientInputSlot = 0; - - ClickableTextureComponent c = __instance.ingredientSlots[currentIngredientInputSlot]; - Item item = c.item; - string toSpeak; - - if (item == null) - { - toSpeak = $"Input Slot {currentIngredientInputSlot + 1}"; - } - else - { - toSpeak = item.DisplayName; - } - - c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); - } - } - break; - case 2: // For inventory slots - { - if (__instance.inventory != null && __instance.inventory.actualInventory.Count >= 0) - { - int prevSlotIndex = currentInventorySlot; - currentInventorySlot = currentInventorySlot + (isLeftShiftPressed ? -1 : 1); - if (currentInventorySlot >= __instance.inventory.actualInventory.Count) - if (isLeftShiftPressed) - currentInventorySlot = __instance.inventory.actualInventory.Count - 1; - else - currentInventorySlot = 0; - - if (currentInventorySlot < 0) - if (isLeftShiftPressed) - currentInventorySlot = __instance.inventory.actualInventory.Count - 1; - else - currentInventorySlot = 0; - - Item item = __instance.inventory.actualInventory[currentInventorySlot]; - ClickableComponent c = __instance.inventory.inventory[currentInventorySlot]; - string toSpeak; - if (item != null) - { - toSpeak = item.DisplayName; - - if ((item as StardewValley.Object) != null) - { - int quality = ((StardewValley.Object)item).Quality; - if (quality == 1) - { - toSpeak = $"Silver quality {toSpeak}"; - } - else if (quality == 2 || quality == 3) - { - toSpeak = $"Gold quality {toSpeak}"; - } - else if (quality >= 4) - { - toSpeak = $"Iridium quality {toSpeak}"; - } - } - toSpeak = $"{item.Stack} {toSpeak}"; - - if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[currentInventorySlot])) - { - toSpeak = $"{toSpeak} not usable here"; - } - } - else - { - toSpeak = "Empty Slot"; - } - c.snapMouseCursorToCenter(); - MainClass.ScreenReader.Say(toSpeak, true); - } - } - break; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - #endregion - } -} \ No newline at end of file diff --git a/stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs b/stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs new file mode 100644 index 0000000..2a8e1b6 --- /dev/null +++ b/stardew-access/Patches/BundleMenuPatches/JojaCDMenuPatch.cs @@ -0,0 +1,70 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class JojaCDMenuPatch + { + internal static string jojaCDMenuQuery = ""; + + internal static void DrawPatch(JojaCDMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = ""; + + for (int i = 0; i < __instance.checkboxes.Count; i++) + { + ClickableComponent c = __instance.checkboxes[i]; + if (!c.containsPoint(x, y)) + continue; + + if (c.name.Equals("complete")) + { + toSpeak = $"Completed {getNameFromIndex(i)}"; + } + else + { + toSpeak = $"{getNameFromIndex(i)} Cost: {__instance.getPriceFromButtonNumber(i)}g Description: {__instance.getDescriptionFromButtonNumber(i)}"; + } + + break; + } + + if (jojaCDMenuQuery != toSpeak) + { + jojaCDMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static string getNameFromIndex(int i) + { + string name = i switch + { + 0 => "Bus", + 1 => "Minecarts", + 2 => "Bridge", + 3 => "Greenhouse", + 4 => "Panning", + _ => "", + }; + + if (name != "") + return $"{name} Project"; + else + return "unkown"; + } + + internal static void Cleanup() + { + jojaCDMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs b/stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs new file mode 100644 index 0000000..96d89c5 --- /dev/null +++ b/stardew-access/Patches/BundleMenuPatches/JunimoNoteMenuPatch.cs @@ -0,0 +1,297 @@ +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class JunimoNoteMenuPatch + { + internal static string junimoNoteMenuQuery = ""; + internal static string currentJunimoArea = ""; + internal static bool isUsingCustomKeyBinds = false; + internal static int currentIngredientListItem = -1, currentIngredientInputSlot = -1, currentInventorySlot = -1; + + internal static void DrawPatch(JunimoNoteMenu __instance, bool ___specificBundlePage, int ___whichArea, Bundle ___currentPageBundle) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (narrateJunimoArea(__instance, ___specificBundlePage, ___whichArea, x, y)) + { + return; + } + + narrateBundlePage(__instance, ___specificBundlePage, ___currentPageBundle, x, y); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateJunimoArea(JunimoNoteMenu __instance, bool ___specificBundlePage, int ___whichArea, int x, int y) + { + if (___specificBundlePage) + return false; + + currentIngredientListItem = -1; + isUsingCustomKeyBinds = false; + + string areaName = __instance.scrambledText ? CommunityCenter.getAreaEnglishDisplayNameFromNumber(___whichArea) : CommunityCenter.getAreaDisplayNameFromNumber(___whichArea); + string reward = __instance.getRewardNameForArea(___whichArea); + + if (__instance.scrambledText) + { + string scrambledText = "Scrambled Text"; + if (junimoNoteMenuQuery != scrambledText) + { + junimoNoteMenuQuery = scrambledText; + MainClass.ScreenReader.Say(scrambledText, true); + } + return true; + } + + if (currentJunimoArea != areaName) + { + currentJunimoArea = areaName; + MainClass.ScreenReader.Say($"Area {areaName}, {reward}", true); + return true; + } + + string toSpeak = ""; + if (__instance.presentButton != null && __instance.presentButton.containsPoint(x, y)) + { + toSpeak = "Present Button"; + } + else if (__instance.fromGameMenu && __instance.areaNextButton.visible && __instance.areaNextButton.containsPoint(x, y)) + { + toSpeak = "Next Area Button"; + } + else if (__instance.fromGameMenu && __instance.areaBackButton.visible && __instance.areaBackButton.containsPoint(x, y)) + { + toSpeak = "Previous Area Button"; + } + else + { + for (int i = 0; i < __instance.bundles.Count; i++) + { + if (!__instance.bundles[i].containsPoint(x, y)) + continue; + + toSpeak = $"{__instance.bundles[i].name} bundle"; + break; + } + } + + if (junimoNoteMenuQuery != toSpeak) + { + junimoNoteMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + return true; + } + + return false; + } + + private static void narrateBundlePage(JunimoNoteMenu __instance, bool ___specificBundlePage, Bundle ___currentPageBundle, int x, int y) + { + if (!___specificBundlePage) + return; + + bool isIPressed = MainClass.Config.BundleMenuIngredientsKey.JustPressed(); // For the ingredients + bool isCPressed = MainClass.Config.BundleMenuInventoryItemsKey.JustPressed(); // For the items in inventory + bool isPPressed = MainClass.Config.BundleMenuPurchaseButtonKey.JustPressed(); // For the Purchase Button + bool isVPressed = MainClass.Config.BundleMenuIngredientsInputSlotKey.JustPressed(); // For the ingredient input slots + bool isBackPressed = MainClass.Config.BundleMenuBackButtonKey.JustPressed(); // For the back button + bool isLeftShiftPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.LeftShift); + + if (isIPressed && !isUsingCustomKeyBinds) + { + isUsingCustomKeyBinds = true; + cycleThroughIngredientList(__instance, ___currentPageBundle, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomKeyBinds = false; }); + } + else if (isVPressed && !isUsingCustomKeyBinds) + { + isUsingCustomKeyBinds = true; + cycleThroughInputSlots(__instance, ___currentPageBundle, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomKeyBinds = false; }); + } + else if (isCPressed && !isUsingCustomKeyBinds) + { + isUsingCustomKeyBinds = true; + cycleThroughInventorySlots(__instance, ___currentPageBundle, isLeftShiftPressed); + Task.Delay(200).ContinueWith(_ => { isUsingCustomKeyBinds = false; }); + } + else if (isBackPressed && __instance.backButton != null && !__instance.backButton.containsPoint(x, y)) + { + __instance.backButton.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say("Back Button", true); + } + else if (isPPressed && __instance.purchaseButton != null && !__instance.purchaseButton.containsPoint(x, y)) + { + __instance.purchaseButton.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say("Purchase Button", true); + } + return; + } + + private static void cycleThroughIngredientList(JunimoNoteMenu __instance, Bundle ___currentPageBundle, bool isLeftShiftPressed = false) + { + if (___currentPageBundle.ingredients.Count < 0) + return; + + currentIngredientListItem = currentIngredientListItem + (isLeftShiftPressed ? -1 : 1); + if (currentIngredientListItem >= ___currentPageBundle.ingredients.Count) + if (isLeftShiftPressed) + currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; + else + currentIngredientListItem = 0; + + if (currentIngredientListItem < 0) + if (isLeftShiftPressed) + currentIngredientListItem = ___currentPageBundle.ingredients.Count - 1; + else + currentIngredientListItem = 0; + + ClickableTextureComponent c = __instance.ingredientList[currentIngredientListItem]; + BundleIngredientDescription ingredient = ___currentPageBundle.ingredients[currentIngredientListItem]; + + Item item = new StardewValley.Object(ingredient.index, ingredient.stack, isRecipe: false, -1, ingredient.quality); + bool completed = false; + if (___currentPageBundle != null && ___currentPageBundle.ingredients != null && currentIngredientListItem < ___currentPageBundle.ingredients.Count && ___currentPageBundle.ingredients[currentIngredientListItem].completed) + { + completed = true; + } + + string toSpeak = item.DisplayName; + + if (completed) + { + toSpeak = $"Completed {toSpeak}"; + } + else + { + int quality = ingredient.quality; + if (quality == 1) + { + toSpeak = $"Silver quality {toSpeak}"; + } + else if (quality == 2 || quality == 3) + { + toSpeak = $"Gold quality {toSpeak}"; + } + else if (quality >= 4) + { + toSpeak = $"Iridium quality {toSpeak}"; + } + + toSpeak = $"{ingredient.stack} {toSpeak}"; + } + + c.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void cycleThroughInputSlots(JunimoNoteMenu __instance, Bundle ___currentPageBundle, bool isLeftShiftPressed = false) + { + if (__instance.ingredientSlots.Count < 0) + return; + + currentIngredientInputSlot = currentIngredientInputSlot + (isLeftShiftPressed ? -1 : 1); + if (currentIngredientInputSlot >= __instance.ingredientSlots.Count) + if (isLeftShiftPressed) + currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; + else + currentIngredientInputSlot = 0; + + if (currentIngredientInputSlot < 0) + if (isLeftShiftPressed) + currentIngredientInputSlot = __instance.ingredientSlots.Count - 1; + else + currentIngredientInputSlot = 0; + + ClickableTextureComponent c = __instance.ingredientSlots[currentIngredientInputSlot]; + Item item = c.item; + string toSpeak; + + if (item == null) + { + toSpeak = $"Input Slot {currentIngredientInputSlot + 1}"; + } + else + { + toSpeak = item.DisplayName; + } + + c.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void cycleThroughInventorySlots(JunimoNoteMenu __instance, Bundle ___currentPageBundle, bool isLeftShiftPressed = false) + { + if (__instance.inventory == null || __instance.inventory.actualInventory.Count < 0) + return; + + int prevSlotIndex = currentInventorySlot; + currentInventorySlot = currentInventorySlot + (isLeftShiftPressed ? -1 : 1); + if (currentInventorySlot >= __instance.inventory.actualInventory.Count) + if (isLeftShiftPressed) + currentInventorySlot = __instance.inventory.actualInventory.Count - 1; + else + currentInventorySlot = 0; + + if (currentInventorySlot < 0) + if (isLeftShiftPressed) + currentInventorySlot = __instance.inventory.actualInventory.Count - 1; + else + currentInventorySlot = 0; + + Item item = __instance.inventory.actualInventory[currentInventorySlot]; + ClickableComponent c = __instance.inventory.inventory[currentInventorySlot]; + string toSpeak; + if (item != null) + { + toSpeak = item.DisplayName; + + if ((item as StardewValley.Object) != null) + { + int quality = ((StardewValley.Object)item).Quality; + if (quality == 1) + { + toSpeak = $"Silver quality {toSpeak}"; + } + else if (quality == 2 || quality == 3) + { + toSpeak = $"Gold quality {toSpeak}"; + } + else if (quality >= 4) + { + toSpeak = $"Iridium quality {toSpeak}"; + } + } + toSpeak = $"{item.Stack} {toSpeak}"; + + if (!__instance.inventory.highlightMethod(__instance.inventory.actualInventory[currentInventorySlot])) + { + toSpeak = $"{toSpeak} not usable here"; + } + } + else + { + toSpeak = "Empty Slot"; + } + c.snapMouseCursorToCenter(); + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + JunimoNoteMenuPatch.currentIngredientListItem = -1; + JunimoNoteMenuPatch.currentIngredientInputSlot = -1; + JunimoNoteMenuPatch.currentInventorySlot = -1; + JunimoNoteMenuPatch.junimoNoteMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs index 9d3272d..6155a70 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -1,4 +1,5 @@ -using StardewValley.Menus; +using StardewValley; +using StardewValley.Menus; namespace stardew_access.Patches { diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index da31c47..5478bb5 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -42,10 +42,7 @@ namespace stardew_access.Patches } else if (menu is JunimoNoteMenu) { - BundleMenuPatches.currentIngredientListItem = -1; - BundleMenuPatches.currentIngredientInputSlot = -1; - BundleMenuPatches.currentInventorySlot = -1; - BundleMenuPatches.junimoNoteMenuQuery = ""; + JunimoNoteMenuPatch.Cleanup(); } else if (menu is ShopMenu) { @@ -86,7 +83,7 @@ namespace stardew_access.Patches } else if (menu is JojaCDMenu) { - BundleMenuPatches.jojaCDMenuQuery = ""; + JojaCDMenuPatch.Cleanup(); } else if (menu is QuestLog) { From 6141447c13538e059d91da325a8ce9f8e8d8c2ac Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 22:45:00 +0530 Subject: [PATCH 40/61] Improved and organised code in carpenter menu patch --- stardew-access/Patches/CarpenterMenuPach.cs | 206 +++++++++----------- 1 file changed, 87 insertions(+), 119 deletions(-) diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPach.cs index 3745452..856d817 100644 --- a/stardew-access/Patches/CarpenterMenuPach.cs +++ b/stardew-access/Patches/CarpenterMenuPach.cs @@ -29,138 +29,27 @@ namespace stardew_access.Patches isMoving = false; isConstructing = false; - #region The blueprint menu - BluePrint currentBluprint = __instance.CurrentBlueprint; - if (currentBluprint == null) + BluePrint currentBlueprint = __instance.CurrentBlueprint; + if (currentBlueprint == null) return; int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string ingredients = ""; - string name = currentBluprint.displayName; - string upgradeName = currentBluprint.nameOfBuildingToUpgrade; - string description = currentBluprint.description; - string price = $"{___price}g"; - string blueprintInfo; - int width = currentBluprint.tilesWidth; - int height = currentBluprint.tilesHeight; - - #region Get ingredients - for (int i = 0; i < ___ingredients.Count; i++) - { - string itemName = ___ingredients[i].DisplayName; - int itemStack = ___ingredients[i].Stack; - string itemQuality = ""; - - int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; - if (qualityValue == 1) - { - itemQuality = "Silver quality"; - } - else if (qualityValue == 2 || qualityValue == 3) - { - itemQuality = "Gold quality"; - } - else if (qualityValue >= 4) - { - itemQuality = "Iridium quality"; - } - - ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; - } - #endregion - - blueprintInfo = $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; + string blueprintInfo = getCurrentBlueprintInfo(currentBlueprint, ___price, ___ingredients); if (isPrimaryInfoKeyPressed && !isSayingBlueprintInfo) { - SayBlueprintInfo(blueprintInfo); + SpeakAndWait(blueprintInfo); } else if (prevBlueprintInfo != blueprintInfo) { prevBlueprintInfo = blueprintInfo; - SayBlueprintInfo(blueprintInfo); + SpeakAndWait(blueprintInfo); } else { - if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - { - string toSpeak = "Previous Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - { - string toSpeak = "Next Blueprint"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) - { - string toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) - { - string toSpeak = "Move Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) - { - string toSpeak = "Paint Building"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) - { - string toSpeak = "Cancel Button"; - if (carpenterMenuQuery != toSpeak) - { - carpenterMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } + narrateHoveredButton(__instance, ___blueprints, ___currentBlueprintIndex, x, y); } - #endregion } else { @@ -182,14 +71,93 @@ namespace stardew_access.Patches } } - private static async void SayBlueprintInfo(string info) + private static string getCurrentBlueprintInfo(BluePrint currentBlueprint, int ___price, List ___ingredients) + { + string ingredients = ""; + string name = currentBlueprint.displayName; + string upgradeName = currentBlueprint.nameOfBuildingToUpgrade; + string description = currentBlueprint.description; + string price = $"{___price}g"; + int width = currentBlueprint.tilesWidth; + int height = currentBlueprint.tilesHeight; + + #region Get ingredients + for (int i = 0; i < ___ingredients.Count; i++) + { + string itemName = ___ingredients[i].DisplayName; + int itemStack = ___ingredients[i].Stack; + string itemQuality = ""; + + int qualityValue = ((StardewValley.Object)___ingredients[i]).Quality; + if (qualityValue == 1) + { + itemQuality = "Silver quality"; + } + else if (qualityValue == 2 || qualityValue == 3) + { + itemQuality = "Gold quality"; + } + else if (qualityValue >= 4) + { + itemQuality = "Iridium quality"; + } + + ingredients = $"{ingredients}, {itemStack} {itemName} {itemQuality}"; + } + #endregion + + return $"{name}, Price: {price}, Ingredients: {ingredients}, Dimensions: {width} width and {height} height, Description: {description}"; + } + + private static async void SpeakAndWait(string toSpeak) { isSayingBlueprintInfo = true; - MainClass.ScreenReader.Say(info, true); + MainClass.ScreenReader.Say(toSpeak, true); await Task.Delay(300); isSayingBlueprintInfo = false; } + private static void narrateHoveredButton(CarpenterMenu __instance, List ___blueprints, int ___currentBlueprintIndex, int x, int y) + { + string toSpeak = ""; + if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + { + toSpeak = "Previous Blueprint"; + } + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + { + toSpeak = "Next Blueprint"; + } + else if (__instance.demolishButton != null && __instance.demolishButton.containsPoint(x, y)) + { + toSpeak = $"Demolish Building" + (__instance.CanDemolishThis(___blueprints[___currentBlueprintIndex]) ? "" : ", cannot demolish building"); + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Construct Building" + (___blueprints[___currentBlueprintIndex].doesFarmerHaveEnoughResourcesToBuild() ? "" : ", cannot cunstrut building, not enough resources to build."); + } + else if (__instance.moveButton != null && __instance.moveButton.containsPoint(x, y)) + { + toSpeak = "Move Building"; + } + else if (__instance.paintButton != null && __instance.paintButton.containsPoint(x, y)) + { + toSpeak = "Paint Building"; + } + else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) + { + toSpeak = "Cancel Button"; + } + else + { + return; + } + if (carpenterMenuQuery != toSpeak) + { + carpenterMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } } } From 9096ce59b900ea460bcb482038000abae2f8187b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 22:57:15 +0530 Subject: [PATCH 41/61] bug fix in snapping mouse to primary and secondary inventory slots --- .../Patches/GameMenuPatches/CraftingPagePatch.cs | 16 ++++++++-------- stardew-access/Patches/ItemGrabMenuPatch.cs | 12 ++++++------ stardew-access/Patches/ShopMenuPatch.cs | 12 ++++++------ 3 files changed, 20 insertions(+), 20 deletions(-) diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index f9c5180..59e6140 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -43,20 +43,20 @@ namespace stardew_access.Patches private static void handleKeyBinds(CraftingPage __instance, int ___currentCraftingPage) { - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - // snap to first inventory slot - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - currentSelectedCraftingRecipe = -1; - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) + if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.pagesOfCraftingRecipes[___currentCraftingPage].Count > 0) { // snap to first crafting recipe __instance.setCurrentlySnappedComponentTo(__instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.myID); __instance.pagesOfCraftingRecipes[___currentCraftingPage].ElementAt(0).Key.snapMouseCursorToCenter(); currentSelectedCraftingRecipe = 0; } + else if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + // snap to first inventory slot + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + currentSelectedCraftingRecipe = -1; + } else if (MainClass.Config.CraftingMenuCycleThroughRecipiesKey.JustPressed() && !isSelectingRecipe) { isSelectingRecipe = true; diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs index 664d810..1948491 100644 --- a/stardew-access/Patches/ItemGrabMenuPatch.cs +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -14,16 +14,16 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) + if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.ItemsToGrabMenu.inventory.Count > 0 && !__instance.shippingBin) { __instance.setCurrentlySnappedComponentTo(__instance.ItemsToGrabMenu.inventory[0].myID); __instance.ItemsToGrabMenu.inventory[0].snapMouseCursorToCenter(); } + else if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + } #region Narrate buttons in the menu if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 4f565a9..8da8b11 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -14,16 +14,16 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) - { - __instance.inventory.inventory[0].snapMouseCursorToCenter(); - __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); - } - else if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) + if (MainClass.Config.SnapToFirstSecondaryInventorySlotKey.JustPressed() && __instance.forSaleButtons.Count > 0) { __instance.forSaleButtons[0].snapMouseCursorToCenter(); __instance.setCurrentlySnappedComponentTo(__instance.forSaleButtons[0].myID); } + else if (MainClass.Config.SnapToFirstInventorySlotKey.JustPressed() && __instance.inventory.inventory.Count > 0) + { + __instance.inventory.inventory[0].snapMouseCursorToCenter(); + __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); + } #region Narrate buttons in the menu if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) From 2ba41822c92e9a5048b0b276d3c4eb8de514091f Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Tue, 7 Mar 2023 23:34:07 +0530 Subject: [PATCH 42/61] Improved and organised code in title menu patches --- stardew-access/HarmonyPatches.cs | 8 +- stardew-access/Patches/IClickableMenuPatch.cs | 18 +- stardew-access/Patches/TitleMenuPatches.cs | 238 ------------------ .../AdvancedGameOptionsPatch.cs | 85 +++++++ .../CharacterCustomizationMenuPatches.cs | 2 +- .../Patches/TitleMenuPatches/CoopMenuPatch.cs | 59 +++++ .../TitleMenuPatches/LoadGameMenuPatch.cs | 86 +++++++ .../TitleMenuPatches/TitleMenuPatches.cs | 81 ++++++ 8 files changed, 333 insertions(+), 244 deletions(-) delete mode 100644 stardew-access/Patches/TitleMenuPatches.cs create mode 100644 stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs rename stardew-access/Patches/{ => TitleMenuPatches}/CharacterCustomizationMenuPatches.cs (99%) create mode 100644 stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs create mode 100644 stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs create mode 100644 stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index e22dbc4..c5c26cf 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -38,12 +38,12 @@ namespace stardew_access #region Title Menu Patches harmony.Patch( original: AccessTools.Method(typeof(TitleMenu), nameof(TitleMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.TitleMenuPatch)) + postfix: new HarmonyMethod(typeof(TitleMenuPatch), nameof(TitleMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LoadGameMenu.SaveFileSlot), nameof(LoadGameMenu.SaveFileSlot.Draw), new Type[] { typeof(SpriteBatch), typeof(int) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.LoadGameMenuPatch)) + postfix: new HarmonyMethod(typeof(LoadGameMenuPatch), nameof(LoadGameMenuPatch.DrawPatch)) ); harmony.Patch( @@ -53,12 +53,12 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(CoopMenu), nameof(CoopMenu.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.CoopMenuPatch)) + postfix: new HarmonyMethod(typeof(CoopMenuPatch), nameof(CoopMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(AdvancedGameOptions), nameof(AdvancedGameOptions.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(TitleMenuPatches), nameof(TitleMenuPatches.AdvancedGameOptionsPatch)) + postfix: new HarmonyMethod(typeof(AdvancedGameOptionsPatch), nameof(AdvancedGameOptionsPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 5478bb5..b0a6c8c 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -19,7 +19,23 @@ namespace stardew_access.Patches internal static void Cleanup(IClickableMenu menu) { - if (menu is LetterViewerMenu) + if (menu is TitleMenu) + { + TitleMenuPatch.Cleanup(); + } + else if (menu is CoopMenu) + { + CoopMenuPatch.Cleanup(); + } + else if (menu is LoadGameMenu) + { + LoadGameMenuPatch.Cleanup(); + } + else if (menu is AdvancedGameOptions) + { + AdvancedGameOptionsPatch.Cleanup(); + } + else if (menu is LetterViewerMenu) { DialoguePatches.currentLetterText = " "; } diff --git a/stardew-access/Patches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches.cs deleted file mode 100644 index af8cba3..0000000 --- a/stardew-access/Patches/TitleMenuPatches.cs +++ /dev/null @@ -1,238 +0,0 @@ -using StardewValley; -using StardewValley.Menus; -using static StardewValley.Menus.LoadGameMenu; - -namespace stardew_access.Patches -{ - internal class TitleMenuPatches - { - public static string advancedGameOptionsQueryKey = " "; - - internal static void AdvancedGameOptionsPatch(AdvancedGameOptions __instance) - { - try - { - int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "OK Button"; - if (advancedGameOptionsQueryKey != toSpeak) - { - advancedGameOptionsQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - for (int i = 0; i < __instance.optionSlots.Count; i++) - { - if (__instance.optionSlots[i].bounds.Contains(x, y) && currentItemIndex + i < __instance.options.Count && __instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) - { - OptionsElement optionsElement = __instance.options[currentItemIndex + i]; - string toSpeak = optionsElement.label; - - if (optionsElement is OptionsButton) - toSpeak = $" {toSpeak} Button"; - else if (optionsElement is OptionsCheckbox) - toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; - else if (optionsElement is OptionsDropDown) - toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; - else if (optionsElement is OptionsSlider) - toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; - else if (optionsElement is OptionsPlusMinus) - toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; - else if (optionsElement is OptionsInputListener) - { - string buttons = ""; - ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); - toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; - } - else if (optionsElement is OptionsTextEntry) - { - toSpeak = $"Seed text box"; - } - else - { - if (toSpeak.Contains(":")) - toSpeak = toSpeak.Replace(":", ""); - - toSpeak = $"{toSpeak} Options:"; - } - - if (advancedGameOptionsQueryKey != toSpeak) - { - advancedGameOptionsQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void CoopMenuPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string toSpeak = " "; - - #region Join/Host Button (Important! This should be checked before checking other buttons) - if (__instance.slotButtons[0].containsPoint(x, y)) - { - if (___currentTab == CoopMenu.Tab.JOIN_TAB) - toSpeak = "Join lan game"; - if (___currentTab == CoopMenu.Tab.HOST_TAB) - toSpeak = "Host new farm"; - } - #endregion - - #region Other Buttons - if (__instance.joinTab.containsPoint(x, y)) - { - toSpeak = "Join Tab Button"; - } - else if (__instance.hostTab.containsPoint(x, y)) - { - toSpeak = "Host Tab Button"; - } - else if (__instance.refreshButton.containsPoint(x, y)) - { - toSpeak = "Refresh Button"; - } - #endregion - - if (toSpeak != " ") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void TitleMenuPatch(TitleMenu __instance, bool ___isTransitioningButtons) - { - try - { - if (___isTransitioningButtons) - return; - - string toSpeak = ""; - - __instance.buttons.ForEach(component => - { - if (component.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string name = component.name; - string label = component.label; - toSpeak = $"{name} {label} Button"; - } - }); - - if (__instance.muteMusicButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "Mute Music Button"; - } - - if (__instance.aboutButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "About Button"; - } - - if (__instance.languageButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "Language Button"; - } - - if (__instance.windowedButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = "Fullscreen: " + ((Game1.isFullscreen) ? "enabled" : "disabled"); - } - - if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string text = "Back Button"; - MainClass.ScreenReader.SayWithChecker(text, true); - } - - // Fix for back button not working using keyboard - if (TitleMenu.subMenu is CharacterCustomization && ((CharacterCustomization)TitleMenu.subMenu).backButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - // Perform Left Click - if (MainClass.Config.LeftClickMainKey.JustPressed()) - { - __instance.backButtonPressed(); - } - } - - if (TitleMenu.subMenu == null && toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LoadGameMenuPatch(SaveFileSlot __instance, LoadGameMenu ___menu, int i) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - if (___menu.slotButtons[i].containsPoint(x, y)) - { - if (__instance.Farmer != null) - { - #region Farms - if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithChecker($"Delete {__instance.Farmer.farmName.Value} Farm", true); - return; - } - - if (___menu.deleteConfirmationScreen) - { - // Used diff. functions to narrate to prevent it from speaking the message again on selecting another button. - string message = "Really delete farm?"; - - MainClass.ScreenReader.SayWithChecker(message, true); - if (___menu.okDeleteButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker("Ok Button", false); - } - else if (___menu.cancelDeleteButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker("Cancel Button", false); - } - return; - } - - String farmerName = __instance.Farmer.displayName; - String farmName = __instance.Farmer.farmName.Value; - String money = __instance.Farmer.Money.ToString(); - String hoursPlayed = Utility.getHoursMinutesStringFromMilliseconds(__instance.Farmer.millisecondsPlayed); - string dateStringForSaveGame = ((!__instance.Farmer.dayOfMonthForSaveGame.HasValue || - !__instance.Farmer.seasonForSaveGame.HasValue || - !__instance.Farmer.yearForSaveGame.HasValue) ? __instance.Farmer.dateStringForSaveGame : Utility.getDateStringFor(__instance.Farmer.dayOfMonthForSaveGame.Value, __instance.Farmer.seasonForSaveGame.Value, __instance.Farmer.yearForSaveGame.Value)); - - string toSpeak = $"{farmName} Farm Selected, \t\n Farmer: {farmerName}, \t\nMoney: {money}, \t\nHours Played: {hoursPlayed}, \t\nDate: {dateStringForSaveGame}"; - - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - #endregion - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs b/stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs new file mode 100644 index 0000000..606ab1c --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/AdvancedGameOptionsPatch.cs @@ -0,0 +1,85 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class AdvancedGameOptionsPatch + { + public static string advancedGameOptionsQueryKey = " "; + + internal static void DrawPatch(AdvancedGameOptions __instance) + { + try + { + int currentItemIndex = Math.Max(0, Math.Min(__instance.options.Count - 7, __instance.currentItemIndex)); + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + string toSpeak = "OK Button"; + if (advancedGameOptionsQueryKey != toSpeak) + { + advancedGameOptionsQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + for (int i = 0; i < __instance.optionSlots.Count; i++) + { + if (!__instance.optionSlots[i].bounds.Contains(x, y) + || currentItemIndex + i >= __instance.options.Count + || !__instance.options[currentItemIndex + i].bounds.Contains(x - __instance.optionSlots[i].bounds.X, y - __instance.optionSlots[i].bounds.Y)) + continue; + + OptionsElement optionsElement = __instance.options[currentItemIndex + i]; + string toSpeak = optionsElement.label; + + if (optionsElement is OptionsButton) + toSpeak = $" {toSpeak} Button"; + else if (optionsElement is OptionsCheckbox) + toSpeak = (((OptionsCheckbox)optionsElement).isChecked ? "Enabled" : "Disabled") + $" {toSpeak} Checkbox"; + else if (optionsElement is OptionsDropDown) + toSpeak = $"{toSpeak} Dropdown, option {((OptionsDropDown)optionsElement).dropDownDisplayOptions[((OptionsDropDown)optionsElement).selectedOption]} selected"; + else if (optionsElement is OptionsSlider) + toSpeak = $"{((OptionsSlider)optionsElement).value}% {toSpeak} Slider"; + else if (optionsElement is OptionsPlusMinus) + toSpeak = $"{((OptionsPlusMinus)optionsElement).displayOptions[((OptionsPlusMinus)optionsElement).selected]} selected of {toSpeak}"; + else if (optionsElement is OptionsInputListener) + { + string buttons = ""; + ((OptionsInputListener)optionsElement).buttonNames.ForEach(name => { buttons += $", {name}"; }); + toSpeak = $"{toSpeak} is bound to {buttons}. Left click to change."; + } + else if (optionsElement is OptionsTextEntry) + { + toSpeak = $"Seed text box"; + } + else + { + if (toSpeak.Contains(":")) + toSpeak = toSpeak.Replace(":", ""); + + toSpeak = $"{toSpeak} Options:"; + } + + if (advancedGameOptionsQueryKey != toSpeak) + { + advancedGameOptionsQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in advanced game menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + advancedGameOptionsQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches/CharacterCustomizationMenuPatches.cs similarity index 99% rename from stardew-access/Patches/CharacterCustomizationMenuPatches.cs rename to stardew-access/Patches/TitleMenuPatches/CharacterCustomizationMenuPatches.cs index fa3e13f..005456d 100644 --- a/stardew-access/Patches/CharacterCustomizationMenuPatches.cs +++ b/stardew-access/Patches/TitleMenuPatches/CharacterCustomizationMenuPatches.cs @@ -119,7 +119,7 @@ namespace stardew_access.Patches } catch (Exception e) { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + MainClass.ErrorLog($"An error occured in character customization menu patch:\n{e.Message}\n{e.StackTrace}"); } } diff --git a/stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs b/stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs new file mode 100644 index 0000000..3f4eb6a --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/CoopMenuPatch.cs @@ -0,0 +1,59 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class CoopMenuPatch + { + private static string coopMenuQueryKey = ""; + + internal static void DrawPatch(CoopMenu __instance, CoopMenu.Tab ___currentTab) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ""; + + #region Join/Host Button (Important! This should be checked before checking other buttons) + if (__instance.slotButtons[0].containsPoint(x, y)) + { + if (___currentTab == CoopMenu.Tab.JOIN_TAB) + toSpeak = "Join lan game"; + if (___currentTab == CoopMenu.Tab.HOST_TAB) + toSpeak = "Host new farm"; + } + #endregion + + #region Other Buttons + if (__instance.joinTab.containsPoint(x, y)) + { + toSpeak = "Join Tab Button"; + } + else if (__instance.hostTab.containsPoint(x, y)) + { + toSpeak = "Host Tab Button"; + } + else if (__instance.refreshButton.containsPoint(x, y)) + { + toSpeak = "Refresh Button"; + } + #endregion + + if (coopMenuQueryKey != toSpeak) + { + coopMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in co-op menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + coopMenuQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs b/stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs new file mode 100644 index 0000000..df16a22 --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/LoadGameMenuPatch.cs @@ -0,0 +1,86 @@ +using StardewValley; +using StardewValley.Menus; +using static StardewValley.Menus.LoadGameMenu; + +namespace stardew_access.Patches +{ + internal class LoadGameMenuPatch + { + private static string loadGameMenuQueryKey = ""; + private static bool firstTimeInMenu = true; + + internal static void DrawPatch(SaveFileSlot __instance, LoadGameMenu ___menu, int i) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ""; + + if (!___menu.slotButtons[i].containsPoint(x, y)) return; + if (__instance.Farmer == null) return; + + if (___menu.deleteButtons.Count > 0 && ___menu.deleteButtons[i].containsPoint(x, y)) + { + toSpeak = $"Delete {__instance.Farmer.farmName.Value} Farm"; + if (loadGameMenuQueryKey != toSpeak) + { + loadGameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + if (___menu.deleteConfirmationScreen) + { + if (firstTimeInMenu) + { + firstTimeInMenu = false; + toSpeak = "Really delete farm?"; + } + + if (___menu.okDeleteButton.containsPoint(x, y)) + { + toSpeak = $"{toSpeak} Ok button"; + } + else if (___menu.cancelDeleteButton.containsPoint(x, y)) + { + toSpeak = $"{toSpeak} Cancel button"; + } + + if (loadGameMenuQueryKey != toSpeak) + { + loadGameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return; + } + + String farmerName = __instance.Farmer.displayName; + String farmName = __instance.Farmer.farmName.Value; + String money = __instance.Farmer.Money.ToString(); + String hoursPlayed = Utility.getHoursMinutesStringFromMilliseconds(__instance.Farmer.millisecondsPlayed); + string dateStringForSaveGame = ((!__instance.Farmer.dayOfMonthForSaveGame.HasValue || + !__instance.Farmer.seasonForSaveGame.HasValue || + !__instance.Farmer.yearForSaveGame.HasValue) ? __instance.Farmer.dateStringForSaveGame : Utility.getDateStringFor(__instance.Farmer.dayOfMonthForSaveGame.Value, __instance.Farmer.seasonForSaveGame.Value, __instance.Farmer.yearForSaveGame.Value)); + + toSpeak = $"{farmName} Farm Selected, \t\n Farmer: {farmerName}, \t\nMoney: {money}, \t\nHours Played: {hoursPlayed}, \t\nDate: {dateStringForSaveGame}"; + + if (loadGameMenuQueryKey != toSpeak) + { + loadGameMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in load game menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + loadGameMenuQueryKey = ""; + firstTimeInMenu = true; + } + } +} diff --git a/stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs b/stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs new file mode 100644 index 0000000..7dbf06f --- /dev/null +++ b/stardew-access/Patches/TitleMenuPatches/TitleMenuPatches.cs @@ -0,0 +1,81 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TitleMenuPatch + { + private static string titleMenuQueryKey = ""; + + internal static void DrawPatch(TitleMenu __instance, bool ___isTransitioningButtons) + { + try + { + if (___isTransitioningButtons) + return; + + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = ""; + + if (__instance.muteMusicButton.containsPoint(x, y)) + { + toSpeak = "Mute Music Button"; + } + else if (__instance.aboutButton.containsPoint(x, y)) + { + toSpeak = "About Button"; + } + else if (__instance.languageButton.containsPoint(x, y)) + { + toSpeak = "Language Button"; + } + else if (__instance.windowedButton.containsPoint(x, y)) + { + toSpeak = "Fullscreen: " + ((Game1.isFullscreen) ? "enabled" : "disabled"); + } + else if (TitleMenu.subMenu != null && __instance.backButton.containsPoint(x, y)) + { + string text = "Back Button"; + MainClass.ScreenReader.SayWithChecker(text, true); + } + else + { + __instance.buttons.ForEach(component => + { + if (!component.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + return; + + string name = component.name; + string label = component.label; + toSpeak = $"{name} {label} Button"; + }); + } + + // Fix for back button not working using keyboard + if (TitleMenu.subMenu is CharacterCustomization && ((CharacterCustomization)TitleMenu.subMenu).backButton.containsPoint(x, y)) + { + // Perform Left Click + if (MainClass.Config.LeftClickMainKey.JustPressed()) + { + __instance.backButtonPressed(); + } + } + + if (TitleMenu.subMenu == null && titleMenuQueryKey!=toSpeak) + { + titleMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"An error occured in title menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + titleMenuQueryKey = ""; + } + } +} From 8523026ed055dd6d67e925c5b0cb0a2d4598edcb Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:06:46 +0530 Subject: [PATCH 43/61] Improved and organised code for dialogue box patch Moved letter viewer menu patch to its own class moved npc patch to its own clas moved draw hover text patch to IClickableMenuPatch.cs --- stardew-access/HarmonyPatches.cs | 8 +- stardew-access/Patches/DialogueBoxPatch.cs | 131 ++++++ stardew-access/Patches/DialoguePatches.cs | 427 ------------------ .../GameMenuPatches/CollectionsPagePatch.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 194 +++++++- .../Patches/LetterViewerMenuPatch.cs | 95 ++++ stardew-access/Patches/MiniGamesPatches.cs | 4 +- stardew-access/Patches/NPCPatch.cs | 22 + 8 files changed, 446 insertions(+), 437 deletions(-) create mode 100644 stardew-access/Patches/DialogueBoxPatch.cs delete mode 100644 stardew-access/Patches/DialoguePatches.cs create mode 100644 stardew-access/Patches/LetterViewerMenuPatch.cs create mode 100644 stardew-access/Patches/NPCPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index c5c26cf..f2dd7ff 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -21,17 +21,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.ClearDialogueString)) + postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.RecieveLeftClickPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.drawHoverText), new Type[] { typeof(SpriteBatch), typeof(string), typeof(SpriteFont), typeof(int), typeof(int), typeof(int), typeof(string), typeof(int), typeof(string[]), typeof(Item), typeof(int), typeof(int), typeof(int), typeof(int), typeof(int), typeof(float), typeof(CraftingRecipe), typeof(IList) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.HoverTextPatch)) + postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.DrawHoverTextPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(NPC), nameof(NPC.drawAboveAlwaysFrontLayer)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.drawAboveAlwaysFrontLayerPatch)) + postfix: new HarmonyMethod(typeof(NPCPatch), nameof(NPCPatch.DrawAboveAlwaysFrontLayerPatch)) ); #endregion @@ -129,7 +129,7 @@ namespace stardew_access #region Menu Patches harmony.Patch( original: AccessTools.Method(typeof(LetterViewerMenu), nameof(LetterViewerMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.LetterViewerMenuPatch)) + postfix: new HarmonyMethod(typeof(LetterViwerMenuPatch), nameof(LetterViwerMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/DialogueBoxPatch.cs new file mode 100644 index 0000000..5f036e7 --- /dev/null +++ b/stardew-access/Patches/DialogueBoxPatch.cs @@ -0,0 +1,131 @@ +using Microsoft.Xna.Framework.Graphics; +using StardewModdingAPI; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class DialoguePatches + { + private static string currentDialogue = ""; + private static string previousSpeakerName = ""; + private static bool isDialogueAppearingFirstTime = true; + + internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) + { + try + { + if (__instance.transitioning) return; + + if (narrateCharacterDialogue(__instance)) return; + if (narrateQuestionDialogue(__instance)) return; + narrateBasicDialogue(__instance.getCurrentString()); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); + } + } + + internal static void RecieveLeftClickPatch() + { + // CLears the currentDialogue string on closing dialog + Cleanup(); + } + + private static bool narrateCharacterDialogue(DialogueBox __instance) + { + if (__instance.characterDialogue == null) return false; + + // For Normal Character dialogues + Dialogue dialogue = __instance.characterDialogue; + string speakerName = dialogue.speaker.displayName; + string dialogueText = ""; + string responseText = ""; + bool hasResponses = dialogue.isCurrentDialogueAQuestion(); + + dialogueText = $"{speakerName} said {__instance.getCurrentString()}"; + + if (hasResponses) + { + responseText = getCurrentResponseText(__instance); + + CheckAndSpeak(isDialogueAppearingFirstTime ? $"{dialogueText} \n\t {responseText}" : responseText, responseText); + if (isDialogueAppearingFirstTime) isDialogueAppearingFirstTime = false; + } + else + { + CheckAndSpeak(dialogueText); + } + + return true; + } + + private static bool narrateQuestionDialogue(DialogueBox __instance) + { + if (!__instance.isQuestion) return false; + + // For Dialogues with responses/answers like the dialogue when we click on tv + string questionText = ""; + string responseText = ""; + bool hasResponses = false; + + if (__instance.responses.Count > 0) hasResponses = true; + if (!hasResponses) return false; + + questionText = __instance.getCurrentString(); + + responseText = getCurrentResponseText(__instance); + + CheckAndSpeak(isDialogueAppearingFirstTime ? $"{questionText} \n\t {responseText}" : responseText, responseText); + if (isDialogueAppearingFirstTime) isDialogueAppearingFirstTime = false; + + return true; + } + + private static void narrateBasicDialogue(string dialogue) + { + // Basic dialogues like `No mails in the mail box` + if (Game1.activeClickableMenu is not DialogueBox) return; + CheckAndSpeak(dialogue); + } + + private static string getCurrentResponseText(DialogueBox __instance) + { + List responses = __instance.responses; + if (__instance.selectedResponse >= 0 && __instance.selectedResponse < responses.Count) + { + return $"{__instance.selectedResponse + 1}: {responses[__instance.selectedResponse].responseText}"; + } + else + { + // When the dialogue is not finished writing then the selectedResponse is <0 and this results + // in the first response not being detcted, so this sets the first response option to be the default + // if the current dialogue is a question or has responses + return $"1: {responses[0].responseText}"; + } + } + + private static void CheckAndSpeak(string toSpeak) + { + if (currentDialogue == toSpeak) return; + currentDialogue = toSpeak; + + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void CheckAndSpeak(string toSpeak, string checkQuery) + { + if (currentDialogue == checkQuery) return; + currentDialogue = checkQuery; + + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + currentDialogue = ""; + isDialogueAppearingFirstTime = true; + } + } +} diff --git a/stardew-access/Patches/DialoguePatches.cs b/stardew-access/Patches/DialoguePatches.cs deleted file mode 100644 index e131952..0000000 --- a/stardew-access/Patches/DialoguePatches.cs +++ /dev/null @@ -1,427 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class DialoguePatches - { - internal static string currentLetterText = " "; - internal static string currentDialogue = " "; - internal static bool isDialogueAppearingFirstTime = true; - - internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) - { - try - { - if (__instance.transitioning) - return; - - if (__instance.characterDialogue != null) - { - // For Normal Character dialogues - Dialogue dialogue = __instance.characterDialogue; - string speakerName = dialogue.speaker.displayName; - List responses = __instance.responses; - string toSpeak = " "; - string dialogueText = ""; - string response = ""; - bool hasResponses = dialogue.isCurrentDialogueAQuestion(); - - dialogueText = $"{speakerName} said {__instance.getCurrentString()}"; - - if (hasResponses) - { - if (__instance.selectedResponse >= 0 && __instance.selectedResponse < responses.Count) - response = $"{__instance.selectedResponse + 1}: {responses[__instance.selectedResponse].responseText}"; - else - // When the dialogue is not finished writing then the selectedResponse is <0 and this results - // in the first response not being detcted, so this sets the first response option to be the default - // if the current dialogue is a question or has responses - response = $"1: {responses[0].responseText}"; - } - - if (hasResponses) - { - if (currentDialogue != response) - { - currentDialogue = response; - - if (isDialogueAppearingFirstTime) - { - toSpeak = $"{dialogueText} \n\t {response}"; - isDialogueAppearingFirstTime = false; - } - else - toSpeak = response; - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - if (currentDialogue != dialogueText) - { - currentDialogue = dialogueText; - MainClass.ScreenReader.Say(dialogueText, true); - } - } - } - else if (__instance.isQuestion) - { - // For Dialogues with responses/answers like the dialogue when we click on tv - string toSpeak = ""; - string dialogueText = ""; - string response = ""; - bool hasResponses = false; - - if (__instance.responses.Count > 0) - hasResponses = true; - - dialogueText = __instance.getCurrentString(); - - if (hasResponses) - if (__instance.selectedResponse >= 0 && __instance.selectedResponse < __instance.responses.Count) - response = $"{__instance.selectedResponse + 1}: {__instance.responses[__instance.selectedResponse].responseText}"; - else - // When the dialogue is not finished writing then the selectedResponse is <0 and this results - // in the first response not being detcted, so this sets the first response option to be the default - // if the current dialogue is a question or has responses - response = $"1: {__instance.responses[0].responseText}"; - - - if (hasResponses) - { - if (currentDialogue != response) - { - currentDialogue = response; - - if (isDialogueAppearingFirstTime) - { - toSpeak = $"{dialogueText} \n\t {response}"; - isDialogueAppearingFirstTime = false; - } - else - toSpeak = response; - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - if (currentDialogue != dialogueText) - { - currentDialogue = dialogueText; - MainClass.ScreenReader.Say(dialogueText, true); - } - } - } - else if (Game1.activeClickableMenu is DialogueBox) - { - // Basic dialogues like `No mails in the mail box` - if (currentDialogue != __instance.getCurrentString()) - { - currentDialogue = __instance.getCurrentString(); - MainClass.ScreenReader.Say(__instance.getCurrentString(), true); - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); - } - - } - - internal static void ClearDialogueString() - { - // CLears the currentDialogue string on closing dialog - currentDialogue = " "; - isDialogueAppearingFirstTime = true; - } - - internal static void HoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null) - { - try - { - #region Skip narrating hover text for certain menus - if (Game1.activeClickableMenu is TitleMenu && !(((TitleMenu)Game1.activeClickableMenu).GetChildMenu() is CharacterCustomization)) - return; - else if (Game1.activeClickableMenu is LetterViewerMenu || Game1.activeClickableMenu is QuestLog) - return; - else if (Game1.activeClickableMenu is Billboard) - return; - else if (Game1.activeClickableMenu is GeodeMenu) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is InventoryPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is CraftingPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is OptionsPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is ExitPage) - return; - else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is SocialPage) - return; - else if (Game1.activeClickableMenu is ItemGrabMenu) - return; - else if (Game1.activeClickableMenu is ShopMenu) - return; - else if (Game1.activeClickableMenu is ConfirmationDialog) - return; - else if (Game1.activeClickableMenu is JunimoNoteMenu) - return; - else if (Game1.activeClickableMenu is CarpenterMenu) - return; - else if (Game1.activeClickableMenu is PurchaseAnimalsMenu) - return; - else if (Game1.activeClickableMenu is CraftingPage) - return; - else if (Game1.activeClickableMenu is AnimalQueryMenu) - return; - else if (Game1.activeClickableMenu is ConfirmationDialog) - return; - else if (Game1.activeClickableMenu is ReadyCheckDialog) - return; - else if (Game1.activeClickableMenu is JojaCDMenu) - return; - else if (Game1.activeClickableMenu is TailoringMenu) - return; - else if (Game1.activeClickableMenu is PondQueryMenu) - return; - else if (Game1.activeClickableMenu is ForgeMenu) - return; - else if (Game1.activeClickableMenu is ItemListMenu) - return; - else if (Game1.activeClickableMenu is FieldOfficeMenu) - return; - else if (Game1.activeClickableMenu is MuseumMenu) - return; - #endregion - - string toSpeak = " "; - - #region Add item count before title - if (hoveredItem != null && hoveredItem.HasBeenInInventory) - { - int count = hoveredItem.Stack; - if (count > 1) - toSpeak = $"{toSpeak} {count} "; - } - #endregion - - #region Add title if any - if (boldTitleText != null) - toSpeak = $"{toSpeak} {boldTitleText}\n"; - #endregion - - #region Add quality of item - if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Quality > 0) - { - int quality = ((StardewValley.Object)hoveredItem).Quality; - if (quality == 1) - { - toSpeak = $"{toSpeak} Silver quality"; - } - else if (quality == 2 || quality == 3) - { - toSpeak = $"{toSpeak} Gold quality"; - } - else if (quality >= 4) - { - toSpeak = $"{toSpeak} Iridium quality"; - } - } - #endregion - - #region Narrate hovered required ingredients - if (extraItemToShowIndex != -1) - { - string itemName = Game1.objectInformation[extraItemToShowIndex].Split('/')[0]; - - if (extraItemToShowAmount != -1) - toSpeak = $"{toSpeak} Required: {extraItemToShowAmount} {itemName}"; - else - toSpeak = $"{toSpeak} Required: {itemName}"; - } - #endregion - - #region Add money - if (moneyAmountToDisplayAtBottom != -1) - toSpeak = $"{toSpeak} \nCost: {moneyAmountToDisplayAtBottom}g\n"; - #endregion - - #region Add the base text - if (text == "???") - toSpeak = "unknown"; - else - toSpeak = $"{toSpeak} {text}"; - #endregion - - #region Add crafting ingredients - if (craftingIngredients != null) - { - toSpeak = $"{toSpeak} \n{craftingIngredients.description}"; - toSpeak = $"{toSpeak} \nIngredients\n"; - - craftingIngredients.recipeList.ToList().ForEach(recipe => - { - int count = recipe.Value; - int item = recipe.Key; - string name = craftingIngredients.getNameFromIndex(item); - - toSpeak = $"{toSpeak} ,{count} {name}"; - }); - } - #endregion - - #region Add health & stamina - if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Edibility != -300) - { - int stamina_recovery = ((StardewValley.Object)hoveredItem).staminaRecoveredOnConsumption(); - toSpeak = $"{toSpeak} {stamina_recovery} Energy\n"; - if (stamina_recovery >= 0) - { - int health_recovery = ((StardewValley.Object)hoveredItem).healthRecoveredOnConsumption(); - toSpeak = $"{toSpeak} {health_recovery} Health"; - } - } - #endregion - - #region Add buff items (effects like +1 walking speed) - if (buffIconsToDisplay != null) - { - for (int i = 0; i < buffIconsToDisplay.Length; i++) - { - string buffName = ((Convert.ToInt32(buffIconsToDisplay[i]) > 0) ? "+" : "") + buffIconsToDisplay[i] + " "; - if (i <= 11) - { - buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + i, buffName); - } - try - { - int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); - if (count != 0) - toSpeak = $"{toSpeak} {buffName}\n"; - } - catch (Exception) { } - } - } - #endregion - - #region Narrate toSpeak - // To prevent it from getting conflicted by two hover texts at the same time, two seperate methods are used. - // For example, sometimes `Welcome to Pierre's` and the items in seeds shop get conflicted causing it to speak infinitely. - - if (toSpeak.ToString() != " ") - { - if (Context.IsPlayerFree) - MainClass.ScreenReader.SayWithChecker(toSpeak.ToString(), true); // Normal Checker - else - MainClass.ScreenReader.SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker - } - #endregion - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); - } - } - - internal static void LetterViewerMenuPatch(LetterViewerMenu __instance) - { - try - { - if (!__instance.IsActive()) - return; - - NarrateLetterContent(__instance); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void NarrateLetterContent(LetterViewerMenu __instance) - { - int x = Game1.getMousePosition().X, y = Game1.getMousePosition().Y; - #region Texts in the letter - string message = __instance.mailMessage[__instance.page]; - - string toSpeak = $"{message}"; - - if (__instance.ShouldShowInteractable()) - { - if (__instance.moneyIncluded > 0) - { - string moneyText = Game1.content.LoadString("Strings\\UI:LetterViewer_MoneyIncluded", __instance.moneyIncluded); - toSpeak += $"\t\n\t ,Included money: {moneyText}"; - } - else if (__instance.learnedRecipe != null && __instance.learnedRecipe.Length > 0) - { - string recipeText = Game1.content.LoadString("Strings\\UI:LetterViewer_LearnedRecipe", __instance.cookingOrCrafting); - toSpeak += $"\t\n\t ,Learned Recipe: {recipeText}"; - } - } - - if (currentLetterText != toSpeak) - { - currentLetterText = toSpeak; - - // snap mouse to accept quest button - if (__instance.acceptQuestButton != null && __instance.questID != -1) - { - toSpeak += "\t\n Left click to accept quest."; - __instance.acceptQuestButton.snapMouseCursorToCenter(); - } - if (__instance.mailMessage.Count > 1) - toSpeak = $"Page {__instance.page + 1} of {__instance.mailMessage.Count}:\n\t{toSpeak}"; - - MainClass.ScreenReader.Say(toSpeak, true); - } - #endregion - - #region Narrate items given in the mail - if (__instance.ShouldShowInteractable()) - { - foreach (ClickableComponent c in __instance.itemsToGrab) - { - if (c.item == null) - continue; - - string name = c.item.DisplayName; - - if (c.containsPoint(x, y)) - MainClass.ScreenReader.SayWithChecker($"Left click to collect {name}", false); - } - } - #endregion - - #region Narrate buttons - if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) - MainClass.ScreenReader.SayWithChecker($"Previous page button", false); - - if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) - MainClass.ScreenReader.SayWithChecker($"Next page button", false); - - #endregion - } - - internal static void drawAboveAlwaysFrontLayerPatch(NPC __instance, string ___textAboveHead, int ___textAboveHeadTimer) - { - try - { - if (___textAboveHeadTimer > 2900 && ___textAboveHead != null) - { - MainClass.ScreenReader.SayWithChecker($"{__instance.displayName} says {___textAboveHead}", true); - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Error in patch:NPCShowTextAboveHeadPatch \n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs index a708930..fdbaee4 100644 --- a/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CollectionsPagePatch.cs @@ -9,7 +9,7 @@ namespace stardew_access.Patches int x = StardewValley.Game1.getMousePosition().X, y = StardewValley.Game1.getMousePosition().Y; if (__instance.letterviewerSubMenu != null) { - DialoguePatches.NarrateLetterContent(__instance.letterviewerSubMenu); + LetterViwerMenuPatch.narrateLetterContent(__instance.letterviewerSubMenu); } } catch (System.Exception e) diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index b0a6c8c..8e92817 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -1,3 +1,4 @@ +using StardewValley; using StardewValley.Menus; namespace stardew_access.Patches @@ -5,6 +6,194 @@ namespace stardew_access.Patches // These patches are global, i.e. work on every menus internal class IClickableMenuPatch { + internal static void DrawHoverTextPatch(string? text, int moneyAmountToDisplayAtBottom = -1, string? boldTitleText = null, int extraItemToShowIndex = -1, int extraItemToShowAmount = -1, string[]? buffIconsToDisplay = null, Item? hoveredItem = null, CraftingRecipe? craftingIngredients = null) + { + try + { + #region Skip narrating hover text for certain menus + if (Game1.activeClickableMenu is TitleMenu && !(((TitleMenu)Game1.activeClickableMenu).GetChildMenu() is CharacterCustomization)) + return; + else if (Game1.activeClickableMenu is LetterViewerMenu || Game1.activeClickableMenu is QuestLog) + return; + else if (Game1.activeClickableMenu is Billboard) + return; + else if (Game1.activeClickableMenu is GeodeMenu) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is InventoryPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is CraftingPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is OptionsPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is ExitPage) + return; + else if (Game1.activeClickableMenu is GameMenu && ((GameMenu)Game1.activeClickableMenu).GetCurrentPage() is SocialPage) + return; + else if (Game1.activeClickableMenu is ItemGrabMenu) + return; + else if (Game1.activeClickableMenu is ShopMenu) + return; + else if (Game1.activeClickableMenu is ConfirmationDialog) + return; + else if (Game1.activeClickableMenu is JunimoNoteMenu) + return; + else if (Game1.activeClickableMenu is CarpenterMenu) + return; + else if (Game1.activeClickableMenu is PurchaseAnimalsMenu) + return; + else if (Game1.activeClickableMenu is CraftingPage) + return; + else if (Game1.activeClickableMenu is AnimalQueryMenu) + return; + else if (Game1.activeClickableMenu is ConfirmationDialog) + return; + else if (Game1.activeClickableMenu is ReadyCheckDialog) + return; + else if (Game1.activeClickableMenu is JojaCDMenu) + return; + else if (Game1.activeClickableMenu is TailoringMenu) + return; + else if (Game1.activeClickableMenu is PondQueryMenu) + return; + else if (Game1.activeClickableMenu is ForgeMenu) + return; + else if (Game1.activeClickableMenu is ItemListMenu) + return; + else if (Game1.activeClickableMenu is FieldOfficeMenu) + return; + else if (Game1.activeClickableMenu is MuseumMenu) + return; + #endregion + + string toSpeak = " "; + + #region Add item count before title + if (hoveredItem != null && hoveredItem.HasBeenInInventory) + { + int count = hoveredItem.Stack; + if (count > 1) + toSpeak = $"{toSpeak} {count} "; + } + #endregion + + #region Add title if any + if (boldTitleText != null) + toSpeak = $"{toSpeak} {boldTitleText}\n"; + #endregion + + #region Add quality of item + if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Quality > 0) + { + int quality = ((StardewValley.Object)hoveredItem).Quality; + if (quality == 1) + { + toSpeak = $"{toSpeak} Silver quality"; + } + else if (quality == 2 || quality == 3) + { + toSpeak = $"{toSpeak} Gold quality"; + } + else if (quality >= 4) + { + toSpeak = $"{toSpeak} Iridium quality"; + } + } + #endregion + + #region Narrate hovered required ingredients + if (extraItemToShowIndex != -1) + { + string itemName = Game1.objectInformation[extraItemToShowIndex].Split('/')[0]; + + if (extraItemToShowAmount != -1) + toSpeak = $"{toSpeak} Required: {extraItemToShowAmount} {itemName}"; + else + toSpeak = $"{toSpeak} Required: {itemName}"; + } + #endregion + + #region Add money + if (moneyAmountToDisplayAtBottom != -1) + toSpeak = $"{toSpeak} \nCost: {moneyAmountToDisplayAtBottom}g\n"; + #endregion + + #region Add the base text + if (text == "???") + toSpeak = "unknown"; + else + toSpeak = $"{toSpeak} {text}"; + #endregion + + #region Add crafting ingredients + if (craftingIngredients != null) + { + toSpeak = $"{toSpeak} \n{craftingIngredients.description}"; + toSpeak = $"{toSpeak} \nIngredients\n"; + + craftingIngredients.recipeList.ToList().ForEach(recipe => + { + int count = recipe.Value; + int item = recipe.Key; + string name = craftingIngredients.getNameFromIndex(item); + + toSpeak = $"{toSpeak} ,{count} {name}"; + }); + } + #endregion + + #region Add health & stamina + if (hoveredItem is StardewValley.Object && ((StardewValley.Object)hoveredItem).Edibility != -300) + { + int stamina_recovery = ((StardewValley.Object)hoveredItem).staminaRecoveredOnConsumption(); + toSpeak = $"{toSpeak} {stamina_recovery} Energy\n"; + if (stamina_recovery >= 0) + { + int health_recovery = ((StardewValley.Object)hoveredItem).healthRecoveredOnConsumption(); + toSpeak = $"{toSpeak} {health_recovery} Health"; + } + } + #endregion + + #region Add buff items (effects like +1 walking speed) + if (buffIconsToDisplay != null) + { + for (int i = 0; i < buffIconsToDisplay.Length; i++) + { + string buffName = ((Convert.ToInt32(buffIconsToDisplay[i]) > 0) ? "+" : "") + buffIconsToDisplay[i] + " "; + if (i <= 11) + { + buffName = Game1.content.LoadString("Strings\\UI:ItemHover_Buff" + i, buffName); + } + try + { + int count = int.Parse(buffName.Substring(0, buffName.IndexOf(' '))); + if (count != 0) + toSpeak = $"{toSpeak} {buffName}\n"; + } + catch (Exception) { } + } + } + #endregion + + #region Narrate toSpeak + // To prevent it from getting conflicted by two hover texts at the same time, two seperate methods are used. + // For example, sometimes `Welcome to Pierre's` and the items in seeds shop get conflicted causing it to speak infinitely. + + if (toSpeak.ToString() != " ") + { + if (StardewModdingAPI.Context.IsPlayerFree) + MainClass.ScreenReader.SayWithChecker(toSpeak.ToString(), true); // Normal Checker + else + MainClass.ScreenReader.SayWithMenuChecker(toSpeak.ToString(), true); // Menu Checker + } + #endregion + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate dialog:\n{e.StackTrace}\n{e.Message}"); + } + } + internal static void ExitThisMenuPatch(IClickableMenu __instance) { try @@ -37,7 +226,7 @@ namespace stardew_access.Patches } else if (menu is LetterViewerMenu) { - DialoguePatches.currentLetterText = " "; + LetterViwerMenuPatch.Cleanup(); } else if (menu is LevelUpMenu) { @@ -94,8 +283,7 @@ namespace stardew_access.Patches } else if (menu is DialogueBox) { - DialoguePatches.isDialogueAppearingFirstTime = true; - DialoguePatches.currentDialogue = " "; + DialoguePatches.Cleanup(); } else if (menu is JojaCDMenu) { diff --git a/stardew-access/Patches/LetterViewerMenuPatch.cs b/stardew-access/Patches/LetterViewerMenuPatch.cs new file mode 100644 index 0000000..de7eabb --- /dev/null +++ b/stardew-access/Patches/LetterViewerMenuPatch.cs @@ -0,0 +1,95 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LetterViwerMenuPatch + { + private static string currentLetterText = ""; + + internal static void DrawPatch(LetterViewerMenu __instance) + { + try + { + if (!__instance.IsActive()) + return; + + narrateLetterContent(__instance); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void narrateLetterContent(LetterViewerMenu __instance) + { + int x = Game1.getMousePosition().X, y = Game1.getMousePosition().Y; + #region Texts in the letter + string message = __instance.mailMessage[__instance.page]; + + string toSpeak = $"{message}"; + + if (__instance.ShouldShowInteractable()) + { + if (__instance.moneyIncluded > 0) + { + string moneyText = Game1.content.LoadString("Strings\\UI:LetterViewer_MoneyIncluded", __instance.moneyIncluded); + toSpeak += $"\t\n\t ,Included money: {moneyText}"; + } + else if (__instance.learnedRecipe != null && __instance.learnedRecipe.Length > 0) + { + string recipeText = Game1.content.LoadString("Strings\\UI:LetterViewer_LearnedRecipe", __instance.cookingOrCrafting); + toSpeak += $"\t\n\t ,Learned Recipe: {recipeText}"; + } + } + + if (currentLetterText != toSpeak) + { + currentLetterText = toSpeak; + + // snap mouse to accept quest button + if (__instance.acceptQuestButton != null && __instance.questID != -1) + { + toSpeak += "\t\n Left click to accept quest."; + __instance.acceptQuestButton.snapMouseCursorToCenter(); + } + if (__instance.mailMessage.Count > 1) + toSpeak = $"Page {__instance.page + 1} of {__instance.mailMessage.Count}:\n\t{toSpeak}"; + + MainClass.ScreenReader.Say(toSpeak, true); + } + #endregion + + #region Narrate items given in the mail + if (__instance.ShouldShowInteractable()) + { + foreach (ClickableComponent c in __instance.itemsToGrab) + { + if (c.item == null) + continue; + + string name = c.item.DisplayName; + + if (c.containsPoint(x, y)) + MainClass.ScreenReader.SayWithChecker($"Left click to collect {name}", false); + } + } + #endregion + + #region Narrate buttons + if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) + MainClass.ScreenReader.SayWithChecker($"Previous page button", false); + + if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) + MainClass.ScreenReader.SayWithChecker($"Next page button", false); + + #endregion + } + + internal static void Cleanup() + { + currentLetterText = ""; + } + } +} diff --git a/stardew-access/Patches/MiniGamesPatches.cs b/stardew-access/Patches/MiniGamesPatches.cs index 8addd64..07480bf 100644 --- a/stardew-access/Patches/MiniGamesPatches.cs +++ b/stardew-access/Patches/MiniGamesPatches.cs @@ -49,7 +49,7 @@ namespace stardew_access.Patches if (___letterView != null) { - DialoguePatches.NarrateLetterContent(___letterView); + LetterViwerMenuPatch.narrateLetterContent(___letterView); } if (MainClass.ModHelper == null) @@ -117,4 +117,4 @@ namespace stardew_access.Patches return new Rectangle((int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.viewport, 1294, 730).X + (286 - ___parallaxPan) * 4, (int)Utility.getTopLeftPositionForCenteringOnScreen(Game1.viewport, 1294, 730).Y + 218 + Math.Max(0, Math.Min(60, (___grandpaSpeechTimer - 5000) / 8)), 524, 344); } } -} \ No newline at end of file +} diff --git a/stardew-access/Patches/NPCPatch.cs b/stardew-access/Patches/NPCPatch.cs new file mode 100644 index 0000000..41f9306 --- /dev/null +++ b/stardew-access/Patches/NPCPatch.cs @@ -0,0 +1,22 @@ +using StardewValley; + +namespace stardew_access.Patches +{ + internal class NPCPatch + { + internal static void DrawAboveAlwaysFrontLayerPatch(NPC __instance, string ___textAboveHead, int ___textAboveHeadTimer) + { + try + { + if (___textAboveHeadTimer > 2900 && ___textAboveHead != null) + { + MainClass.ScreenReader.SayWithChecker($"{__instance.displayName} says {___textAboveHead}", true); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Error in patch:NPCShowTextAboveHeadPatch \n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 80963c4dc629cb89a03ca082900a517803525002 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:21:50 +0530 Subject: [PATCH 44/61] Improved and organised code in shop menu patch --- stardew-access/HarmonyPatches.cs | 4 +- stardew-access/Patches/DialogueBoxPatch.cs | 9 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ShopMenuPatch.cs | 146 +++++++++--------- 4 files changed, 77 insertions(+), 84 deletions(-) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f2dd7ff..a77c76e 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -16,12 +16,12 @@ namespace stardew_access #region Dialogue Patches harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.DialoguePatch)) + postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(DialogueBox), nameof(DialogueBox.receiveLeftClick)), - postfix: new HarmonyMethod(typeof(DialoguePatches), nameof(DialoguePatches.RecieveLeftClickPatch)) + postfix: new HarmonyMethod(typeof(DialogueBoxPatch), nameof(DialogueBoxPatch.RecieveLeftClickPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/DialogueBoxPatch.cs index 5f036e7..bc471d6 100644 --- a/stardew-access/Patches/DialogueBoxPatch.cs +++ b/stardew-access/Patches/DialogueBoxPatch.cs @@ -1,17 +1,14 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewModdingAPI; -using StardewValley; +using StardewValley; using StardewValley.Menus; namespace stardew_access.Patches { - internal class DialoguePatches + internal class DialogueBoxPatch { private static string currentDialogue = ""; - private static string previousSpeakerName = ""; private static bool isDialogueAppearingFirstTime = true; - internal static void DialoguePatch(DialogueBox __instance, SpriteBatch b) + internal static void DrawPatch(DialogueBox __instance) { try { diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 8e92817..765efbd 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -283,7 +283,7 @@ namespace stardew_access.Patches } else if (menu is DialogueBox) { - DialoguePatches.Cleanup(); + DialogueBoxPatch.Cleanup(); } else if (menu is JojaCDMenu) { diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 8da8b11..5f5e16b 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -25,88 +25,15 @@ namespace stardew_access.Patches __instance.setCurrentlySnappedComponentTo(__instance.inventory.inventory[0].myID); } - #region Narrate buttons in the menu - if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) - { - string toSpeak = "Up Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) - { - string toSpeak = "Down Arrow Button"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion + if (narrateHoveredButton(__instance, x, y)) return; - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, hoverPrice: __instance.hoverPrice)) { shopMenuQueryKey = ""; return; } - #endregion - #region Narrate hovered selling item - if (__instance.hoveredItem != null) - { - string name = __instance.hoveredItem.DisplayName; - string price = $"Buy Price: {__instance.hoverPrice} g"; - string description = __instance.hoveredItem.getDescription(); - string requirements = ""; - - #region Narrate required items for item - int itemIndex = -1, itemAmount = 5; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) - itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; - - if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) - itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; - - if (itemIndex != -1) - { - string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; - - if (itemAmount != -1) - requirements = $"Required: {itemAmount} {itemName}"; - else - requirements = $"Required: {itemName}"; - } - #endregion - - string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; - if (shopMenuQueryKey != toSpeak) - { - shopMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion + narrateHoveredSellingItem(__instance); } catch (Exception e) { @@ -114,6 +41,75 @@ namespace stardew_access.Patches } } + private static bool narrateHoveredButton(ShopMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else if (__instance.upArrow != null && __instance.upArrow.containsPoint(x, y)) + { + toSpeak = "Up Arrow Button"; + } + else if (__instance.downArrow != null && __instance.downArrow.containsPoint(x, y)) + { + toSpeak = "Down Arrow Button"; + } + else + { + return false; + } + + if (shopMenuQueryKey == toSpeak) return true; + + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + + private static void narrateHoveredSellingItem(ShopMenu __instance) + { + if (__instance.hoveredItem == null) return; + + string name = __instance.hoveredItem.DisplayName; + string price = $"Buy Price: {__instance.hoverPrice} g"; + string description = __instance.hoveredItem.getDescription(); + string requirements = ""; + + #region get required items for item + int itemIndex = -1, itemAmount = 5; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 2) + itemIndex = __instance.itemPriceAndStock[__instance.hoveredItem][2]; + + if (__instance.itemPriceAndStock[__instance.hoveredItem].Length > 3) + itemAmount = __instance.itemPriceAndStock[__instance.hoveredItem][3]; + + if (itemIndex != -1) + { + string itemName = Game1.objectInformation[itemIndex].Split('/')[0]; + + if (itemAmount != -1) + requirements = $"Required: {itemAmount} {itemName}"; + else + requirements = $"Required: {itemName}"; + } + #endregion + + string toSpeak = $"{name}, {requirements}, {price}, \n\t{description}"; + if (shopMenuQueryKey == toSpeak) return; + + shopMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + internal static void Cleanup() { shopMenuQueryKey = ""; From 6822bd48404166c96a7aff8abcc981a6ba651180 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:29:19 +0530 Subject: [PATCH 45/61] Organised code for purchase animal menu patch --- stardew-access/Patches/IClickableMenuPatch.cs | 4 +- .../Patches/PurchaseAnimalsMenuPatch.cs | 124 ++++++++++-------- 2 files changed, 69 insertions(+), 59 deletions(-) diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 765efbd..36bb1cc 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -273,9 +273,7 @@ namespace stardew_access.Patches } else if (menu is PurchaseAnimalsMenu) { - PurchaseAnimalsMenuPatch.purchaseAnimalMenuQuery = ""; - PurchaseAnimalsMenuPatch.firstTimeInNamingMenu = true; - PurchaseAnimalsMenuPatch.purchaseAnimalsMenu = null; + PurchaseAnimalsMenuPatch.Cleanup(); } else if (menu is AnimalQueryMenu) { diff --git a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs index 0828c06..8ff6dff 100644 --- a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs +++ b/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs @@ -24,39 +24,7 @@ namespace stardew_access.Patches if (___onFarm && ___namingAnimal) { - string toSpeak = ""; - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "Cancel Button"; - } - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - { - toSpeak = "OK Button"; - } - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - { - toSpeak = "Random Name Button"; - } - else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - { - toSpeak = "Name Text Box"; - // string? value = ___textBox.Text; - // if (value != "" && value != null && value != "null") - // toSpeak = $"{toSpeak}, Value: {value}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - - if (firstTimeInNamingMenu) - { - toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; - firstTimeInNamingMenu = false; - } - - MainClass.ScreenReader.Say(toSpeak, true); - } + narrateNamingMenu(__instance, x, y); } else if (___onFarm && !___namingAnimal) { @@ -65,29 +33,7 @@ namespace stardew_access.Patches else if (!___onFarm && !___namingAnimal) { firstTimeInNamingMenu = true; - if (__instance.hovered != null) - { - string toSpeak = ""; - if (((StardewValley.Object)__instance.hovered.item).Type != null) - { - toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; - } - else - { - string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); - int price = __instance.hovered.item.salePrice(); - string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); - - toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; - } - - if (purchaseAnimalMenuQuery != toSpeak) - { - purchaseAnimalMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } + narratePurchasingMenu(__instance); } } catch (Exception e) @@ -96,6 +42,72 @@ namespace stardew_access.Patches } } + private static void narrateNamingMenu(PurchaseAnimalsMenu __instance, int x, int y) + { + string toSpeak = ""; + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Cancel Button"; + } + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + { + toSpeak = "OK Button"; + } + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + { + toSpeak = "Random Name Button"; + } + else if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + { + toSpeak = "Name Text Box"; + // string? value = ___textBox.Text; + // if (value != "" && value != null && value != "null") + // toSpeak = $"{toSpeak}, Value: {value}"; + } + if (purchaseAnimalMenuQuery == toSpeak) return; + + purchaseAnimalMenuQuery = toSpeak; + + if (firstTimeInNamingMenu) + { + toSpeak = $"Enter the name of animal in the name text box. {toSpeak}"; + firstTimeInNamingMenu = false; + } + + MainClass.ScreenReader.Say(toSpeak, true); + } + + private static void narratePurchasingMenu(PurchaseAnimalsMenu __instance) + { + if (__instance.hovered == null) + return; + + string toSpeak = ""; + if (((StardewValley.Object)__instance.hovered.item).Type != null) + { + toSpeak = ((StardewValley.Object)__instance.hovered.item).Type; + } + else + { + string displayName = PurchaseAnimalsMenu.getAnimalTitle(__instance.hovered.hoverText); + int price = __instance.hovered.item.salePrice(); + string description = PurchaseAnimalsMenu.getAnimalDescription(__instance.hovered.hoverText); + + toSpeak = $"{displayName}, Price: {price}g, Description: {description}"; + } + + if (purchaseAnimalMenuQuery == toSpeak) return; + + purchaseAnimalMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + purchaseAnimalMenuQuery = ""; + firstTimeInNamingMenu = true; + purchaseAnimalsMenu = null; + } } } From 5195313a5b86974b6505b54ffcaa7abebddcf9e1 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Wed, 8 Mar 2023 12:44:07 +0530 Subject: [PATCH 46/61] Organised code for item grab menu patch --- stardew-access/Patches/ItemGrabMenuPatch.cs | 235 +++++++++----------- stardew-access/Patches/ShopMenuPatch.cs | 1 + 2 files changed, 100 insertions(+), 136 deletions(-) diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs index 1948491..cf2428e 100644 --- a/stardew-access/Patches/ItemGrabMenuPatch.cs +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -25,146 +25,17 @@ namespace stardew_access.Patches __instance.inventory.inventory[0].snapMouseCursorToCenter(); } - #region Narrate buttons in the menu - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + if (narrateHoveredButton(__instance, x, y)) { - string toSpeak = "Ok Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } + InventoryUtils.Cleanup(); return; } - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + if (narrateLastShippedItem(__instance, x, y)) { - string toSpeak = "Trash Can"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } + InventoryUtils.Cleanup(); return; } - if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) - { - string toSpeak = "Organize Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) - { - string toSpeak = "Add to existing stacks button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) - { - string toSpeak = "Special Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) - { - - string toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) - { - - string toSpeak = "Community Center Button"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop Item"; - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - // FIXME - /*if (__instance.discreteColorPickerCC.Count > 0) { - for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) - { - if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) - { - MainClass.monitor.Log(i.ToString(), LogLevel.Debug); - string toSpeak = getChestColorName(i); - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - ScreenReader.say(toSpeak, true); - Game1.playSound("sa_drop_item"); - } - return; - } - } - }*/ - #endregion - - #region Narrate the last shipped item if in the shipping bin - if (__instance.shippingBin && Game1.getFarm().lastItemShipped != null && __instance.lastShippedHolder.containsPoint(x, y)) - { - Item lastShippedItem = Game1.getFarm().lastItemShipped; - string name = lastShippedItem.DisplayName; - int count = lastShippedItem.Stack; - - string toSpeak = $"Last Shipped: {count} {name}"; - - if (itemGrabMenuQueryKey != toSpeak) - { - itemGrabMenuQueryKey = toSpeak; - hoveredItemQueryKey = ""; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, true)) { itemGrabMenuQueryKey = ""; @@ -176,8 +47,6 @@ namespace stardew_access.Patches itemGrabMenuQueryKey = ""; return; } - - #endregion } catch (Exception e) { @@ -185,6 +54,99 @@ namespace stardew_access.Patches } } + private static bool narrateHoveredButton(ItemGrabMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok Button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash Can"; + } + else if (__instance.organizeButton != null && __instance.organizeButton.containsPoint(x, y)) + { + toSpeak = "Organize Button"; + } + else if (__instance.fillStacksButton != null && __instance.fillStacksButton.containsPoint(x, y)) + { + toSpeak = "Add to existing stacks button"; + } + else if (__instance.specialButton != null && __instance.specialButton.containsPoint(x, y)) + { + toSpeak = "Special Button"; + } + else if (__instance.colorPickerToggleButton != null && __instance.colorPickerToggleButton.containsPoint(x, y)) + { + toSpeak = "Color Picker: " + (__instance.chestColorPicker.visible ? "Enabled" : "Disabled"); + } + else if (__instance.junimoNoteIcon != null && __instance.junimoNoteIcon.containsPoint(x, y)) + { + toSpeak = "Community Center Button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else + { + return false; + } + + // FIXME + /*if (__instance.discreteColorPickerCC.Count > 0) { + for (int i = 0; i < __instance.discreteColorPickerCC.Count; i++) + { + if (__instance.discreteColorPickerCC[i].containsPoint(x, y)) + { + MainClass.monitor.Log(i.ToString(), LogLevel.Debug); + string toSpeak = getChestColorName(i); + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + ScreenReader.say(toSpeak, true); + Game1.playSound("sa_drop_item"); + } + return; + } + } + }*/ + + if (itemGrabMenuQueryKey == toSpeak) return true; + + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + + private static bool narrateLastShippedItem(ItemGrabMenu __instance, int x, int y) + { + if (!__instance.shippingBin || Game1.getFarm().lastItemShipped == null || !__instance.lastShippedHolder.containsPoint(x, y)) + return false; + + Item lastShippedItem = Game1.getFarm().lastItemShipped; + string name = lastShippedItem.DisplayName; + int count = lastShippedItem.Stack; + + string toSpeak = $"Last Shipped: {count} {name}"; + + if (itemGrabMenuQueryKey != toSpeak) + { + itemGrabMenuQueryKey = toSpeak; + hoveredItemQueryKey = ""; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + // TODO Add color names private static string getChestColorName(int i) { @@ -258,7 +220,8 @@ namespace stardew_access.Patches return toReturn; } - internal static void Cleanup() { + internal static void Cleanup() + { hoveredItemQueryKey = ""; itemGrabMenuQueryKey = ""; } diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 5f5e16b..9a46e1e 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -45,6 +45,7 @@ namespace stardew_access.Patches { string toSpeak = ""; bool isDropItemButton = false; + if (__instance.inventory.dropItemInvisibleButton != null && __instance.inventory.dropItemInvisibleButton.containsPoint(x, y)) { toSpeak = "Drop Item"; From 2ddebd36159e953f4a097a95ae563c2b5de9ca9d Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:06:13 +0530 Subject: [PATCH 47/61] Organised code for donation menu patches --- stardew-access/HarmonyPatches.cs | 14 +- stardew-access/Patches/CarpenterMenuPach.cs | 11 + stardew-access/Patches/ChatMenuPatches.cs | 29 +- stardew-access/Patches/DonationMenuPatches.cs | 328 ------------------ .../FieldOfficeMenuPatch.cs | 122 +++++++ .../DonationMenuPatches/MuseumMenuPatch.cs | 245 +++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 12 +- 7 files changed, 402 insertions(+), 359 deletions(-) delete mode 100644 stardew-access/Patches/DonationMenuPatches.cs create mode 100644 stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs create mode 100644 stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index a77c76e..69bccb5 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -167,11 +167,6 @@ namespace stardew_access postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch)) ); - harmony.Patch( - original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.receiveKeyPress), new Type[] { typeof(Keys) }), - prefix: new HarmonyMethod(typeof(DonationMenuPatches), nameof(DonationMenuPatches.MuseumMenuKeyPressPatch)) - ); - harmony.Patch( original: AccessTools.Method(typeof(ChooseFromListMenu), nameof(ChooseFromListMenu.draw), new Type[] { typeof(SpriteBatch) }), postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ChooseFromListMenuPatch)) @@ -255,12 +250,17 @@ namespace stardew_access #region Donation Menus harmony.Patch( original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DonationMenuPatches), nameof(DonationMenuPatches.MuseumMenuPatch)) + postfix: new HarmonyMethod(typeof(MuseumMenuPatch), nameof(MuseumMenuPatch.DrawPatch)) + ); + + harmony.Patch( + original: AccessTools.Method(typeof(MuseumMenu), nameof(MuseumMenu.receiveKeyPress), new Type[] { typeof(Keys) }), + prefix: new HarmonyMethod(typeof(MuseumMenuPatch), nameof(MuseumMenuPatch.RecieveKeyPressPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(FieldOfficeMenu), nameof(FieldOfficeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(DonationMenuPatches), nameof(DonationMenuPatches.FieldOfficeMenuPatch)) + postfix: new HarmonyMethod(typeof(FieldOfficeMenuPatch), nameof(FieldOfficeMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPach.cs index 856d817..81f4d29 100644 --- a/stardew-access/Patches/CarpenterMenuPach.cs +++ b/stardew-access/Patches/CarpenterMenuPach.cs @@ -159,5 +159,16 @@ namespace stardew_access.Patches MainClass.ScreenReader.Say(toSpeak, true); } } + + internal static void Cleanup() + { + CarpenterMenuPatch.carpenterMenuQuery = ""; + CarpenterMenuPatch.isUpgrading = false; + CarpenterMenuPatch.isDemolishing = false; + CarpenterMenuPatch.isPainting = false; + CarpenterMenuPatch.isMoving = false; + CarpenterMenuPatch.isConstructing = false; + CarpenterMenuPatch.carpenterMenu = null; + } } } diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatches.cs index 6155a70..c997ac7 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatches.cs @@ -19,23 +19,22 @@ namespace stardew_access.Patches bool isPrevButtonPressed = MainClass.Config.ChatMenuNextKey.JustPressed(); bool isNextButtonPressed = MainClass.Config.ChatMenuPreviousKey.JustPressed(); - if (___messages.Count > 0) + if (___messages.Count <= 0) return; + + #region To narrate previous and next chat messages + if (isNextButtonPressed && !isChatRunning) { - #region To narrate previous and next chat messages - if (isNextButtonPressed && !isChatRunning) - { - isChatRunning = true; - CycleThroughChatMessages(true, ___messages); - Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); - } - else if (isPrevButtonPressed && !isChatRunning) - { - isChatRunning = true; - CycleThroughChatMessages(false, ___messages); - Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); - } - #endregion + isChatRunning = true; + CycleThroughChatMessages(true, ___messages); + Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); } + else if (isPrevButtonPressed && !isChatRunning) + { + isChatRunning = true; + CycleThroughChatMessages(false, ___messages); + Task.Delay(200).ContinueWith(_ => { isChatRunning = false; }); + } + #endregion } else if (___messages.Count > 0) { diff --git a/stardew-access/Patches/DonationMenuPatches.cs b/stardew-access/Patches/DonationMenuPatches.cs deleted file mode 100644 index ffffa2f..0000000 --- a/stardew-access/Patches/DonationMenuPatches.cs +++ /dev/null @@ -1,328 +0,0 @@ -using Microsoft.Xna.Framework; -using Microsoft.Xna.Framework.Content; -using StardewValley; -using StardewValley.Locations; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class DonationMenuPatches - { - internal static string museumQueryKey = " "; - internal static string fieldOfficeMenuQuery = " "; - private static bool isMoving = false; - private static (int x, int y)[] donationTiles = - { - (26,5),(26,6),(26,7),(26,8),(26,9),(26,10),(26,11), - (29,5),(30,5),(31,5),(32,5),(33,5),(34,5),(35,5),(36,5), - (28,6),(29,6),(30,6),(31,6),(32,6),(33,6),(34,6),(35,6),(36,6),(37,6), - (28,9),(29,9),(30,9),(31,9),(32,9),(33,9),(34,9),(35,9),(36,9), - (28,10),(29,10),(30,10),(31,10),(32,10),(33,10),(34,10),(35,10),(36,10), - (30,13),(31,13),(32,13),(33,13),(34,13), - (30,14),(31,14),(32,14),(33,14),(34,14), - (28,15),(29,15),(30,15),(31,15),(32,15),(33,15),(34,15),(35,15),(36,15), - (28,16),(29,16),(30,16),(31,16),(32,16),(33,16),(34,16),(35,16),(36,16), - (39,6),(40,6),(41,6),(42,6),(43,6),(44,6),(45,6),(46,6), - (39,7),(40,7),(41,7),(42,7),(43,7),(44,7),(45,7),(46,7), - (48,5),(48,6),(48,7), - (42,15),(43,15),(44,15),(45,15),(46,15),(47,15), - (42,16),(43,16),(44,16),(45,16),(46,16),(47,16), - }; - - #region Museum - - internal static bool MuseumMenuKeyPressPatch() - { - try - { - if (isMoving) - return false; - - if (!isMoving) - { - isMoving = true; - Task.Delay(200).ContinueWith(_ => { isMoving = false; }); - } - - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - - return true; - } - - internal static void MuseumMenuPatch(MuseumMenu __instance, bool ___holdingMuseumPiece) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.heldItem != null) - { - // Museum Inventory - string toSpeak = " "; - int tileX = (int)(Utility.ModifyCoordinateFromUIScale(x) + (float)Game1.viewport.X) / 64; - int tileY = (int)(Utility.ModifyCoordinateFromUIScale(y) + (float)Game1.viewport.Y) / 64; - LibraryMuseum libraryMuseum = (LibraryMuseum)Game1.currentLocation; - - if (libraryMuseum.isTileSuitableForMuseumPiece(tileX, tileY)) - toSpeak = $"slot {tileX}x {tileY}y"; - - if (museumQueryKey != toSpeak) - { - museumQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - // Player Inventory - int i = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, - handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); - if (i != -9999) - { - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For donating hovered item - - if (isPrimaryInfoKeyPressed && __instance.inventory.actualInventory[i] != null) - { - foreach (var tile in donationTiles) - { - #region Manually donates the hovered item (https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Menus/MuseumMenu.cs#L206-L247) - int tileX = tile.x; - int tileY = tile.y; - - if (((LibraryMuseum)Game1.currentLocation).isTileSuitableForMuseumPiece(tileX, tileY) && ((LibraryMuseum)Game1.currentLocation).isItemSuitableForDonation(__instance.inventory.actualInventory[i])) - { - int objectID = __instance.inventory.actualInventory[i].ParentSheetIndex; - int rewardsCount = ((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count; - ((LibraryMuseum)Game1.currentLocation).museumPieces.Add(new Vector2(tileX, tileY), ((StardewValley.Object)__instance.inventory.actualInventory[i]).ParentSheetIndex); - Game1.playSound("stoneStep"); - if (((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count > rewardsCount) - { - Game1.playSound("reward"); - } - else - { - Game1.playSound("newArtifact"); - } - Game1.player.completeQuest(24); - __instance.inventory.actualInventory[i].Stack--; - if (__instance.inventory.actualInventory[i].Stack <= 0) - { - __instance.inventory.actualInventory[i] = null; - } - int pieces = ((LibraryMuseum)Game1.currentLocation).museumPieces.Count(); - Game1.stats.checkForArchaeologyAchievements(); - switch (pieces) - { - case 95: - globalChatInfoMessage("MuseumComplete", Game1.player.farmName.Value); - break; - case 40: - globalChatInfoMessage("Museum40", Game1.player.farmName.Value); - break; - default: - globalChatInfoMessage("donation", Game1.player.Name, "object:" + objectID); - break; - } - break; - } - #endregion - } - } - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - if (museumQueryKey != $"ok button") - { - museumQueryKey = $"ok button"; - MainClass.ScreenReader.Say("ok button", true); - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - - #region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395 - internal static void globalChatInfoMessage(string messageKey, params string[] args) - { - if (Game1.IsMultiplayer || Game1.multiplayerMode != 0) - { - receiveChatInfoMessage(Game1.player, messageKey, args); - sendChatInfoMessage(messageKey, args); - } - } - - internal static void sendChatInfoMessage(string messageKey, params string[] args) - { - if (Game1.IsClient) - { - Game1.client.sendMessage(15, messageKey, args); - } - else if (Game1.IsServer) - { - foreach (long id in Game1.otherFarmers.Keys) - { - Game1.server.sendMessage(id, 15, Game1.player, messageKey, args); - } - } - } - - internal static void receiveChatInfoMessage(Farmer sourceFarmer, string messageKey, string[] args) - { - if (Game1.chatBox != null) - { - try - { - string[] processedArgs = args.Select(delegate (string arg) - { - if (arg.StartsWith("achievement:")) - { - int key = Convert.ToInt32(arg.Substring("achievement:".Length)); - return Game1.content.Load>("Data\\Achievements")[key].Split('^')[0]; - } - return arg.StartsWith("object:") ? new StardewValley.Object(Convert.ToInt32(arg.Substring("object:".Length)), 1).DisplayName : arg; - }).ToArray(); - ChatBox chatBox = Game1.chatBox; - LocalizedContentManager content = Game1.content; - string path = "Strings\\UI:Chat_" + messageKey; - object[] substitutions = processedArgs; - chatBox.addInfoMessage(content.LoadString(path, substitutions)); - } - catch (ContentLoadException) - { - } - catch (FormatException) - { - } - catch (OverflowException) - { - } - catch (KeyNotFoundException) - { - } - } - } - #endregion - - #endregion - - #region Field Office - - internal static void FieldOfficeMenuPatch(FieldOfficeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else - { - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - for (int i = 0; i < __instance.pieceHolders.Count; i++) - { - if (!__instance.pieceHolders[i].containsPoint(x, y)) - continue; - - if (__instance.pieceHolders[i].item == null) - toSpeak = i switch - { - 0 => "Center skeleton slot", - 1 => "Center skeleton slot", - 2 => "Center skeleton slot", - 3 => "Center skeleton slot", - 4 => "Center skeleton slot", - 5 => "Center skeleton slot", - 6 => "Snake slot", - 7 => "Snake slot", - 8 => "Snake slot", - 9 => "Bat slot", - 10 => "Frog slot", - _ => "Donation slot" - }; - else - toSpeak = $"Slot {i + 1} finished: {__instance.pieceHolders[i].item.DisplayName}"; - - if (!MainClass.Config.DisableInventoryVerbosity && __instance.heldItem != null && __instance.pieceHolders[i].item == null) - { - int highlight = getPieceIndexForDonationItem(__instance.heldItem.ParentSheetIndex); - if (highlight != -1 && highlight == i) - toSpeak += "Donatable "; - } - - if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") - { - fieldOfficeMenuQuery = $"{toSpeak}:{i}"; - MainClass.ScreenReader.Say(toSpeak, true); - } - - return; - } - } - - if (fieldOfficeMenuQuery != toSpeak) - { - fieldOfficeMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static int getPieceIndexForDonationItem(int itemIndex) - { - switch (itemIndex) - { - case 820: - return 5; - case 821: - return 4; - case 822: - return 3; - case 823: - return 0; - case 824: - return 1; - case 825: - return 8; - case 826: - return 7; - case 827: - return 9; - case 828: - return 10; - default: - return -1; - } - } - - #endregion - } -} diff --git a/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs new file mode 100644 index 0000000..088c098 --- /dev/null +++ b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs @@ -0,0 +1,122 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class FieldOfficeMenuPatch + { + private static string fieldOfficeMenuQuery = ""; + + internal static void DrawPatch(FieldOfficeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = " "; + + if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + } + else + { + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; + + for (int i = 0; i < __instance.pieceHolders.Count; i++) + { + if (!__instance.pieceHolders[i].containsPoint(x, y)) + continue; + + if (__instance.pieceHolders[i].item == null) + toSpeak = i switch + { + 0 => "Center skeleton slot", + 1 => "Center skeleton slot", + 2 => "Center skeleton slot", + 3 => "Center skeleton slot", + 4 => "Center skeleton slot", + 5 => "Center skeleton slot", + 6 => "Snake slot", + 7 => "Snake slot", + 8 => "Snake slot", + 9 => "Bat slot", + 10 => "Frog slot", + _ => "Donation slot" + }; + else + toSpeak = $"Slot {i + 1} finished: {__instance.pieceHolders[i].item.DisplayName}"; + + if (!MainClass.Config.DisableInventoryVerbosity && __instance.heldItem != null && __instance.pieceHolders[i].item == null) + { + int highlight = getPieceIndexForDonationItem(__instance.heldItem.ParentSheetIndex); + if (highlight != -1 && highlight == i) + toSpeak += "Donatable "; + } + + if (fieldOfficeMenuQuery != $"{toSpeak}:{i}") + { + fieldOfficeMenuQuery = $"{toSpeak}:{i}"; + MainClass.ScreenReader.Say(toSpeak, true); + } + + return; + } + } + + if (fieldOfficeMenuQuery != toSpeak) + { + fieldOfficeMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + Game1.playSound("drop_item"); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static int getPieceIndexForDonationItem(int itemIndex) + { + switch (itemIndex) + { + case 820: + return 5; + case 821: + return 4; + case 822: + return 3; + case 823: + return 0; + case 824: + return 1; + case 825: + return 8; + case 826: + return 7; + case 827: + return 9; + case 828: + return 10; + default: + return -1; + } + } + + internal static void Cleanup() + { + fieldOfficeMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs new file mode 100644 index 0000000..a79c2b2 --- /dev/null +++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs @@ -0,0 +1,245 @@ +using Microsoft.Xna.Framework; +using StardewValley; +using StardewValley.Locations; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class MuseumMenuPatch + { + private static string museumQueryKey = ""; + private static bool isMoving = false; + private static (int x, int y)[] donationTiles = + { + (26,5),(26,6),(26,7),(26,8),(26,9),(26,10),(26,11), + (29,5),(30,5),(31,5),(32,5),(33,5),(34,5),(35,5),(36,5), + (28,6),(29,6),(30,6),(31,6),(32,6),(33,6),(34,6),(35,6),(36,6),(37,6), + (28,9),(29,9),(30,9),(31,9),(32,9),(33,9),(34,9),(35,9),(36,9), + (28,10),(29,10),(30,10),(31,10),(32,10),(33,10),(34,10),(35,10),(36,10), + (30,13),(31,13),(32,13),(33,13),(34,13), + (30,14),(31,14),(32,14),(33,14),(34,14), + (28,15),(29,15),(30,15),(31,15),(32,15),(33,15),(34,15),(35,15),(36,15), + (28,16),(29,16),(30,16),(31,16),(32,16),(33,16),(34,16),(35,16),(36,16), + (39,6),(40,6),(41,6),(42,6),(43,6),(44,6),(45,6),(46,6), + (39,7),(40,7),(41,7),(42,7),(43,7),(44,7),(45,7),(46,7), + (48,5),(48,6),(48,7), + (42,15),(43,15),(44,15),(45,15),(46,15),(47,15), + (42,16),(43,16),(44,16),(45,16),(46,16),(47,16), + }; + + internal static bool RecieveKeyPressPatch() + { + try + { + if (isMoving) + return false; + + if (!isMoving) + { + isMoving = true; + Task.Delay(200).ContinueWith(_ => { isMoving = false; }); + } + + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + + return true; + } + + internal static void DrawPatch(MuseumMenu __instance, bool ___holdingMuseumPiece) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + narrateMuseumInventory(__instance, x, y); + + narratePlayerInventory(__instance, x, y); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void narrateMuseumInventory(MuseumMenu __instance, int x, int y) + { + if (__instance.heldItem == null) return; + + string toSpeak = ""; + int tileX = (int)(Utility.ModifyCoordinateFromUIScale(x) + (float)Game1.viewport.X) / 64; + int tileY = (int)(Utility.ModifyCoordinateFromUIScale(y) + (float)Game1.viewport.Y) / 64; + LibraryMuseum libraryMuseum = (LibraryMuseum)Game1.currentLocation; + + if (libraryMuseum.isTileSuitableForMuseumPiece(tileX, tileY)) + toSpeak = $"slot {tileX}x {tileY}y"; + + if (museumQueryKey != toSpeak) + { + museumQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + private static void narratePlayerInventory(MuseumMenu __instance, int x, int y) + { + if (__instance.heldItem != null) return; + + int hoveredItemIndex = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, + handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); + if (hoveredItemIndex != -9999) + { + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); // For donating hovered item + + if (isPrimaryInfoKeyPressed && hoveredItemIndex >= 0 && hoveredItemIndex < __instance.inventory.actualInventory.Count && __instance.inventory.actualInventory[hoveredItemIndex] != null) + { + manuallyDonateItem(__instance, hoveredItemIndex); + } + } + else + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } + else + { + return; + } + + if (museumQueryKey != toSpeak) + { + museumQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + } + } + + private static void manuallyDonateItem(MuseumMenu __instance, int i) + { + foreach (var tile in donationTiles) + { + #region Manually donates the hovered item (https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Menus/MuseumMenu.cs#L206-L247) + int tileX = tile.x; + int tileY = tile.y; + + if (((LibraryMuseum)Game1.currentLocation).isTileSuitableForMuseumPiece(tileX, tileY) && ((LibraryMuseum)Game1.currentLocation).isItemSuitableForDonation(__instance.inventory.actualInventory[i])) + { + int objectID = __instance.inventory.actualInventory[i].ParentSheetIndex; + int rewardsCount = ((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count; + ((LibraryMuseum)Game1.currentLocation).museumPieces.Add(new Vector2(tileX, tileY), ((StardewValley.Object)__instance.inventory.actualInventory[i]).ParentSheetIndex); + Game1.playSound("stoneStep"); + if (((LibraryMuseum)Game1.currentLocation).getRewardsForPlayer(Game1.player).Count > rewardsCount) + { + Game1.playSound("reward"); + } + else + { + Game1.playSound("newArtifact"); + } + Game1.player.completeQuest(24); + __instance.inventory.actualInventory[i].Stack--; + if (__instance.inventory.actualInventory[i].Stack <= 0) + { + __instance.inventory.actualInventory[i] = null; + } + int pieces = ((LibraryMuseum)Game1.currentLocation).museumPieces.Count(); + Game1.stats.checkForArchaeologyAchievements(); + switch (pieces) + { + case 95: + globalChatInfoMessage("MuseumComplete", Game1.player.farmName.Value); + break; + case 40: + globalChatInfoMessage("Museum40", Game1.player.farmName.Value); + break; + default: + globalChatInfoMessage("donation", Game1.player.Name, "object:" + objectID); + break; + } + break; + } + #endregion + } + } + + #region These methods are taken from the game's source code, https://github.com/veywrn/StardewValley/blob/3ff171b6e9e6839555d7881a391b624ccd820a83/StardewValley/Multiplayer.cs#L1331-L1395 + internal static void globalChatInfoMessage(string messageKey, params string[] args) + { + if (Game1.IsMultiplayer || Game1.multiplayerMode != 0) + { + receiveChatInfoMessage(Game1.player, messageKey, args); + sendChatInfoMessage(messageKey, args); + } + } + + internal static void sendChatInfoMessage(string messageKey, params string[] args) + { + if (Game1.IsClient) + { + Game1.client.sendMessage(15, messageKey, args); + } + else if (Game1.IsServer) + { + foreach (long id in Game1.otherFarmers.Keys) + { + Game1.server.sendMessage(id, 15, Game1.player, messageKey, args); + } + } + } + + internal static void receiveChatInfoMessage(Farmer sourceFarmer, string messageKey, string[] args) + { + if (Game1.chatBox != null) + { + try + { + string[] processedArgs = args.Select(delegate (string arg) + { + if (arg.StartsWith("achievement:")) + { + int key = Convert.ToInt32(arg.Substring("achievement:".Length)); + return Game1.content.Load>("Data\\Achievements")[key].Split('^')[0]; + } + return arg.StartsWith("object:") ? new StardewValley.Object(Convert.ToInt32(arg.Substring("object:".Length)), 1).DisplayName : arg; + }).ToArray(); + ChatBox chatBox = Game1.chatBox; + LocalizedContentManager content = Game1.content; + string path = "Strings\\UI:Chat_" + messageKey; + object[] substitutions = processedArgs; + chatBox.addInfoMessage(content.LoadString(path, substitutions)); + } + catch (Microsoft.Xna.Framework.Content.ContentLoadException) + { + } + catch (FormatException) + { + } + catch (OverflowException) + { + } + catch (KeyNotFoundException) + { + } + } + } + #endregion + + internal static void Cleanup() + { + museumQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 36bb1cc..49c552f 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -263,13 +263,7 @@ namespace stardew_access.Patches } else if (menu is CarpenterMenu) { - CarpenterMenuPatch.carpenterMenuQuery = ""; - CarpenterMenuPatch.isUpgrading = false; - CarpenterMenuPatch.isDemolishing = false; - CarpenterMenuPatch.isPainting = false; - CarpenterMenuPatch.isMoving = false; - CarpenterMenuPatch.isConstructing = false; - CarpenterMenuPatch.carpenterMenu = null; + CarpenterMenuPatch.Cleanup(); } else if (menu is PurchaseAnimalsMenu) { @@ -305,11 +299,11 @@ namespace stardew_access.Patches } else if (menu is FieldOfficeMenu) { - DonationMenuPatches.fieldOfficeMenuQuery = " "; + FieldOfficeMenuPatch.Cleanup(); } else if (menu is MuseumMenu) { - DonationMenuPatches.museumQueryKey = " "; + MuseumMenuPatch.Cleanup(); } else if (menu is PondQueryMenu) { From 8970a2c4414109b561f0111ff099280b28b50843 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:12:07 +0530 Subject: [PATCH 48/61] Fixed bug for Museum menu patch --- .../DonationMenuPatches/MuseumMenuPatch.cs | 51 ++++++++++--------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs index a79c2b2..284f40a 100644 --- a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs +++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs @@ -88,6 +88,8 @@ namespace stardew_access.Patches { if (__instance.heldItem != null) return; + if (narrateHoveredButtons(__instance, x, y)) return; + int hoveredItemIndex = InventoryUtils.narrateHoveredSlotAndReturnIndex(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y, handleHighlightedItem: true, highlightedItemPrefix: "Donatable "); if (hoveredItemIndex != -9999) @@ -99,32 +101,35 @@ namespace stardew_access.Patches manuallyDonateItem(__instance, hoveredItemIndex); } } + } + + private static bool narrateHoveredButtons(MuseumMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop Item"; + isDropItemButton = true; + } else { - string toSpeak = ""; - bool isDropItemButton = false; - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "Ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "Drop Item"; - isDropItemButton = true; - } - else - { - return; - } - - if (museumQueryKey != toSpeak) - { - museumQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - if (isDropItemButton) Game1.playSound("drop_item"); - } + return false; } + + if (museumQueryKey != toSpeak) + { + museumQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; } private static void manuallyDonateItem(MuseumMenu __instance, int i) From 1346e90bf5adfd16fe7bef4f1149b1b18400ee2b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:21:46 +0530 Subject: [PATCH 49/61] Organised code for geode menu patch --- stardew-access/Patches/GeodeMenuPatch.cs | 126 ++++++++---------- stardew-access/Patches/IClickableMenuPatch.cs | 4 + 2 files changed, 61 insertions(+), 69 deletions(-) diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs index e08beec..4b99ad6 100644 --- a/stardew-access/Patches/GeodeMenuPatch.cs +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -5,7 +5,7 @@ namespace stardew_access.Patches { internal class GeodeMenuPatch { - internal static string geodeMenuQueryKey = ""; + private static string geodeMenuQueryKey = ""; internal static void DrawPatch(GeodeMenu __instance) { @@ -13,77 +13,11 @@ namespace stardew_access.Patches { int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - #region Narrate the treasure recieved on breaking the geode - if (__instance.geodeTreasure != null) - { - string name = __instance.geodeTreasure.DisplayName; - int stack = __instance.geodeTreasure.Stack; + if (narrateRecievedTreasure(__instance)) return; + if (narrateHoveredButton(__instance, x, y)) return; - string toSpeak = $"Recieved {stack} {name}"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered buttons in the menu - if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) - { - string toSpeak = "Place geode here"; - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - string toSpeak = "Drop item here"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - Game1.playSound("drop_item"); - } - return; - } - - if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - string toSpeak = "Trash can"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - string toSpeak = "Ok button"; - - if (geodeMenuQueryKey != toSpeak) - { - geodeMenuQueryKey = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - return; - } - #endregion - - #region Narrate hovered item if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) geodeMenuQueryKey = ""; - #endregion } catch (Exception e) { @@ -91,6 +25,60 @@ namespace stardew_access.Patches } } + private static bool narrateRecievedTreasure(GeodeMenu __instance) + { + // Narrates the treasure recieved on breaking the geode + if (__instance.geodeTreasure == null) return false; + + string name = __instance.geodeTreasure.DisplayName; + int stack = __instance.geodeTreasure.Stack; + + string toSpeak = $"Recieved {stack} {name}"; + + if (geodeMenuQueryKey != toSpeak) + { + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + return true; + } + + private static bool narrateHoveredButton(GeodeMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.geodeSpot != null && __instance.geodeSpot.containsPoint(x, y)) + { + toSpeak = "Place geode here"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "Drop item here"; + isDropItemButton = true; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trash can"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "Ok button"; + } + else + { + return false; + } + + if (geodeMenuQueryKey == toSpeak) return true; + + geodeMenuQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + if (isDropItemButton) Game1.playSound("drop_item"); + + return true; + } + internal static void Cleanup() { geodeMenuQueryKey = ""; diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 49c552f..63278ca 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -309,6 +309,10 @@ namespace stardew_access.Patches { MenuPatches.pondQueryMenuQuery = " "; } + else if (menu is GeodeMenu) + { + GeodeMenuPatch.Cleanup(); + } InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = ""; From 2c233f6e6b427fb19c3c925699ed2591317b5a83 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:27:02 +0530 Subject: [PATCH 50/61] Moved InventoryUtils.cs --- stardew-access/{Patches => Features}/InventoryUtils.cs | 2 +- .../Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs | 1 + stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs | 1 + stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs | 1 + stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs | 1 + stardew-access/Patches/GeodeMenuPatch.cs | 1 + stardew-access/Patches/IClickableMenuPatch.cs | 1 + stardew-access/Patches/ItemGrabMenuPatch.cs | 1 + stardew-access/Patches/ShopMenuPatch.cs | 1 + 9 files changed, 9 insertions(+), 1 deletion(-) rename stardew-access/{Patches => Features}/InventoryUtils.cs (99%) diff --git a/stardew-access/Patches/InventoryUtils.cs b/stardew-access/Features/InventoryUtils.cs similarity index 99% rename from stardew-access/Patches/InventoryUtils.cs rename to stardew-access/Features/InventoryUtils.cs index f4a7602..8b8e913 100644 --- a/stardew-access/Patches/InventoryUtils.cs +++ b/stardew-access/Features/InventoryUtils.cs @@ -2,7 +2,7 @@ using StardewValley; using StardewValley.Menus; -namespace stardew_access.Patches +namespace stardew_access.Features { internal class InventoryUtils { diff --git a/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs index 088c098..5eec4ba 100644 --- a/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs +++ b/stardew-access/Patches/DonationMenuPatches/FieldOfficeMenuPatch.cs @@ -1,4 +1,5 @@ using StardewValley; +using stardew_access.Features; using StardewValley.Menus; namespace stardew_access.Patches diff --git a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs index 284f40a..bd76c97 100644 --- a/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs +++ b/stardew-access/Patches/DonationMenuPatches/MuseumMenuPatch.cs @@ -1,5 +1,6 @@ using Microsoft.Xna.Framework; using StardewValley; +using stardew_access.Features; using StardewValley.Locations; using StardewValley.Menus; diff --git a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs index 59e6140..1cad73e 100644 --- a/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/CraftingPagePatch.cs @@ -1,4 +1,5 @@ using StardewValley; +using stardew_access.Features; using StardewValley.Menus; using StardewValley.Objects; diff --git a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs index dc05fd3..cbb8dd5 100644 --- a/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs +++ b/stardew-access/Patches/GameMenuPatches/InventoryPagePatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/GeodeMenuPatch.cs index 4b99ad6..e9ca166 100644 --- a/stardew-access/Patches/GeodeMenuPatch.cs +++ b/stardew-access/Patches/GeodeMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 63278ca..356dbd9 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/ItemGrabMenuPatch.cs index cf2428e..b9b7674 100644 --- a/stardew-access/Patches/ItemGrabMenuPatch.cs +++ b/stardew-access/Patches/ItemGrabMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/ShopMenuPatch.cs index 9a46e1e..8e000d8 100644 --- a/stardew-access/Patches/ShopMenuPatch.cs +++ b/stardew-access/Patches/ShopMenuPatch.cs @@ -1,3 +1,4 @@ +using stardew_access.Features; using StardewValley; using StardewValley.Menus; From 53fe73140110d6c32a2619210cad72e148f28e1b Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 13:32:45 +0530 Subject: [PATCH 51/61] Moved and organized mini game patches --- stardew-access/HarmonyPatches.cs | 4 +- .../GrandpaStoryPatch.cs} | 36 +---------------- .../Patches/MiniGamesPatches/IntroPatch.cs | 40 +++++++++++++++++++ 3 files changed, 44 insertions(+), 36 deletions(-) rename stardew-access/Patches/{MiniGamesPatches.cs => MiniGamesPatches/GrandpaStoryPatch.cs} (71%) create mode 100644 stardew-access/Patches/MiniGamesPatches/IntroPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 69bccb5..900e674 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -267,12 +267,12 @@ namespace stardew_access #region Mini Games harmony.Patch( original: AccessTools.Method(typeof(Intro), nameof(Intro.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MiniGamesPatches), nameof(MiniGamesPatches.IntroPatch)) + postfix: new HarmonyMethod(typeof(IntroPatch), nameof(IntroPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(GrandpaStory), nameof(GrandpaStory.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MiniGamesPatches), nameof(MiniGamesPatches.GrandpaStoryPatch)) + postfix: new HarmonyMethod(typeof(GrandpaStoryPatch), nameof(GrandpaStoryPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/MiniGamesPatches.cs b/stardew-access/Patches/MiniGamesPatches/GrandpaStoryPatch.cs similarity index 71% rename from stardew-access/Patches/MiniGamesPatches.cs rename to stardew-access/Patches/MiniGamesPatches/GrandpaStoryPatch.cs index 07480bf..90e93d2 100644 --- a/stardew-access/Patches/MiniGamesPatches.cs +++ b/stardew-access/Patches/MiniGamesPatches/GrandpaStoryPatch.cs @@ -4,43 +4,11 @@ using StardewValley.Minigames; namespace stardew_access.Patches { - public class MiniGamesPatches + public class GrandpaStoryPatch { public static string grandpaStoryQuery = " "; - public static string introQuery = " "; - internal static void IntroPatch(Intro __instance, int ___currentState) - { - try - { - if (MainClass.ModHelper == null) - return; - - string toSpeak = " "; - - if (___currentState == 3) - { - toSpeak = MainClass.ModHelper.Translation.Get("intro.scene3"); - } - else if (___currentState == 4) - { - toSpeak = MainClass.ModHelper.Translation.Get("intro.scene4"); - } - - if (toSpeak != " " && introQuery != toSpeak) - { - introQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, false); - return; - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void GrandpaStoryPatch(GrandpaStory __instance, StardewValley.Menus.LetterViewerMenu ___letterView, bool ___drawGrandpa, bool ___letterReceived, bool ___mouseActive, Queue ___grandpaSpeech, int ___grandpaSpeechTimer, int ___totalMilliseconds, int ___scene, int ___parallaxPan) + internal static void DrawPatch(GrandpaStory __instance, StardewValley.Menus.LetterViewerMenu ___letterView, bool ___drawGrandpa, bool ___letterReceived, bool ___mouseActive, Queue ___grandpaSpeech, int ___grandpaSpeechTimer, int ___totalMilliseconds, int ___scene, int ___parallaxPan) { try { diff --git a/stardew-access/Patches/MiniGamesPatches/IntroPatch.cs b/stardew-access/Patches/MiniGamesPatches/IntroPatch.cs new file mode 100644 index 0000000..08759a7 --- /dev/null +++ b/stardew-access/Patches/MiniGamesPatches/IntroPatch.cs @@ -0,0 +1,40 @@ +using StardewValley.Minigames; + +namespace stardew_access.Patches +{ + public class IntroPatch + { + public static string introQuery = " "; + + internal static void DrawPatch(Intro __instance, int ___currentState) + { + try + { + if (MainClass.ModHelper == null) + return; + + string toSpeak = " "; + + if (___currentState == 3) + { + toSpeak = MainClass.ModHelper.Translation.Get("intro.scene3"); + } + else if (___currentState == 4) + { + toSpeak = MainClass.ModHelper.Translation.Get("intro.scene4"); + } + + if (toSpeak != " " && introQuery != toSpeak) + { + introQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, false); + return; + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"An error occured in intro minigame patch:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 50e8afc78c5f07e6ebedfc62e93e1c9e133e9298 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Thu, 9 Mar 2023 14:01:58 +0530 Subject: [PATCH 52/61] Moved and organized quest patches --- stardew-access/HarmonyPatches.cs | 6 +- stardew-access/Patches/IClickableMenuPatch.cs | 8 +- stardew-access/Patches/QuestPatches.cs | 276 ------------------ .../Patches/QuestPatches/BillboardPatch.cs | 98 +++++++ .../Patches/QuestPatches/QuestLogPatch.cs | 164 +++++++++++ .../QuestPatches/SpecialOrdersBoardPatch.cs | 84 ++++++ 6 files changed, 355 insertions(+), 281 deletions(-) create mode 100644 stardew-access/Patches/QuestPatches/BillboardPatch.cs create mode 100644 stardew-access/Patches/QuestPatches/QuestLogPatch.cs create mode 100644 stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 900e674..78d8c22 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -196,17 +196,17 @@ namespace stardew_access #region Quest Patches harmony.Patch( original: AccessTools.Method(typeof(SpecialOrdersBoard), nameof(SpecialOrdersBoard.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.SpecialOrdersBoardPatch)) + postfix: new HarmonyMethod(typeof(SpecialOrdersBoardPatch), nameof(SpecialOrdersBoardPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(QuestLog), nameof(QuestLog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.QuestLogPatch)) + postfix: new HarmonyMethod(typeof(QuestLogPatch), nameof(QuestLogPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(Billboard), nameof(Billboard.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(QuestPatches), nameof(QuestPatches.BillboardPatch)) + postfix: new HarmonyMethod(typeof(BillboardPatch), nameof(BillboardPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 356dbd9..f935345 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -235,7 +235,7 @@ namespace stardew_access.Patches } else if (menu is Billboard) { - QuestPatches.currentDailyQuestText = " "; + BillboardPatch.Cleanup(); } else if (menu is GameMenu) { @@ -284,7 +284,7 @@ namespace stardew_access.Patches } else if (menu is QuestLog) { - QuestPatches.questLogQuery = " "; + QuestLogPatch.Cleaup(); } else if (menu is TailoringMenu) { @@ -314,6 +314,10 @@ namespace stardew_access.Patches { GeodeMenuPatch.Cleanup(); } + else if (menu is SpecialOrdersBoard) + { + SpecialOrdersBoardPatch.Cleanup(); + } InventoryUtils.Cleanup(); TextBoxPatch.activeTextBoxes = ""; diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs index 0b38787..cbe8441 100644 --- a/stardew-access/Patches/QuestPatches.cs +++ b/stardew-access/Patches/QuestPatches.cs @@ -7,281 +7,5 @@ namespace stardew_access.Patches { internal class QuestPatches { - internal static string currentDailyQuestText = " "; - internal static string questLogQuery = " "; - internal static bool isNarratingQuestInfo = false, firstTimeInIndividualQuest = true; - - #region For Special Orders Board - internal static void SpecialOrdersBoardPatch(SpecialOrdersBoard __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.acceptLeftQuestButton.visible && __instance.acceptLeftQuestButton.containsPoint(x, y)) - { - string toSpeak = getSpecialOrderDetails(__instance.leftOrder); - - toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - return; - } - - if (__instance.acceptRightQuestButton.visible && __instance.acceptRightQuestButton.containsPoint(x, y)) - { - string toSpeak = getSpecialOrderDetails(__instance.rightOrder); - - toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - return; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - private static string getSpecialOrderDetails(SpecialOrder order) - { - int daysLeft = order.GetDaysLeft(); - string description = order.GetDescription(); - string objectiveDescription = ""; - string name = order.GetName(); - int moneyReward = order.GetMoneyReward(); - - // Get each objectives - for (int i = 0; i < order.GetObjectiveDescriptions().Count; i++) - { - objectiveDescription += order.GetObjectiveDescriptions()[i] + ", \n"; - } - - string toReturn = $"{name}\n\tDescription:{description}\n\tObjectives: {objectiveDescription}"; - - if (order.IsTimedQuest()) - { - toReturn = $"{toReturn}\n\tTime: {daysLeft} days"; - } - - if (order.HasMoneyReward()) - { - toReturn = $"{toReturn}\n\tReward: {moneyReward}g"; - } - - return toReturn; - } - #endregion - - #region For Normal Billboard in the town - internal static void BillboardPatch(Billboard __instance, bool ___dailyQuestBoard) - { - try - { - if (!___dailyQuestBoard) - { - #region Callender - for (int i = 0; i < __instance.calendarDays.Count; i++) - { - if (__instance.calendarDays[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - string toSpeak = $"Day {i + 1}"; - - if (__instance.calendarDays[i].name.Length > 0) - { - toSpeak += $", {__instance.calendarDays[i].name}"; - } - if (__instance.calendarDays[i].hoverText.Length > 0) - { - toSpeak += $", {__instance.calendarDays[i].hoverText}"; - } - - if (Game1.dayOfMonth == i + 1) - toSpeak += $", Current"; - - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - } - #endregion - } - else - { - #region Daily Quest Board - if (Game1.questOfTheDay == null || Game1.questOfTheDay.currentObjective == null || Game1.questOfTheDay.currentObjective.Length == 0) - { - // No quests - string toSpeak = "No quests for today!"; - if (currentDailyQuestText != toSpeak) - { - currentDailyQuestText = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - else - { - SpriteFont font = ((LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko) ? Game1.smallFont : Game1.dialogueFont); - string description = Game1.parseText(Game1.questOfTheDay.questDescription, font, 640); - string toSpeak = description; - - if (currentDailyQuestText != toSpeak) - { - currentDailyQuestText = toSpeak; - - // Snap to accept quest button - if (__instance.acceptQuestButton.visible) - { - toSpeak += "\t\n Left click to accept quest."; - __instance.acceptQuestButton.snapMouseCursorToCenter(); - } - - MainClass.ScreenReader.Say(toSpeak, true); - } - } - #endregion - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - #endregion - - #region Journal Menu - internal static void QuestLogPatch(QuestLog __instance, int ___questPage, List> ___pages, int ___currentPage, IQuest ____shownQuest, List ____objectiveText) - { - try - { - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " ", extra = ""; - - if (___questPage == -1) - { - #region Quest Lists - if (!firstTimeInIndividualQuest) - firstTimeInIndividualQuest = true; - - for (int i = 0; i < __instance.questLogButtons.Count; i++) - { - if (___pages.Count() > 0 && ___pages[___currentPage].Count() > i) - { - if (!__instance.questLogButtons[i].containsPoint(x, y)) - continue; - - string name = ___pages[___currentPage][i].GetName(); - int daysLeft = ___pages[___currentPage][i].GetDaysLeft(); - toSpeak = $"{name}"; - - if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete()) - toSpeak += $"\t\n {daysLeft} days left"; - - toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; - break; - } - } - - if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous page button"; - else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) - toSpeak = "Close menu button"; - - if (questLogQuery != toSpeak) - { - questLogQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - #endregion - } - else - { - #region Individual quest - bool containsReward = __instance.HasReward() || __instance.HasMoneyReward(); - string description = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128); - string title = ____shownQuest.GetName(); - - if (firstTimeInIndividualQuest || (isPrimaryInfoKeyPressed && !isNarratingQuestInfo)) - { - if (firstTimeInIndividualQuest) - toSpeak = "Back button"; - - if (____shownQuest.ShouldDisplayAsComplete()) - { - #region Quest completed menu - - extra = $"Quest: {title} Completed!"; - - if (__instance.HasMoneyReward()) - extra += $"you recieved {____shownQuest.GetMoneyReward()}g"; - - #endregion - } - else - { - #region Quest in-complete menu - extra = $"Title: {title}. \t\n Description: {description}"; - - for (int j = 0; j < ____objectiveText.Count; j++) - { - string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont); - if (____shownQuest != null && ____shownQuest is SpecialOrder) - { - OrderObjective order_objective = ((SpecialOrder)____shownQuest).objectives[j]; - if (order_objective.GetMaxCount() > 1 && order_objective.ShouldShowProgress()) - parsed_text += "\n\t" + order_objective.GetCount() + " of " + order_objective.GetMaxCount() + " completed"; - } - - extra += $"\t\nOrder {j + 1}: {parsed_text} \t\n"; - } - - if (____shownQuest != null) - { - int daysLeft = ____shownQuest.GetDaysLeft(); - - if (daysLeft > 0) - extra += $"\t\n{daysLeft} days left."; - } - #endregion - } - - isNarratingQuestInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingQuestInfo = false; }); - questLogQuery = " "; - } - - if (!firstTimeInIndividualQuest) - if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) - toSpeak = (___currentPage > 0) ? "Previous page button" : "Back button"; - else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.cancelQuestButton != null && __instance.cancelQuestButton.visible && __instance.cancelQuestButton.containsPoint(x, y)) - toSpeak = "Cancel quest button"; - else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) - toSpeak = "Close menu button"; - else if (containsReward && __instance.rewardBox.containsPoint(x, y)) - toSpeak = "Left click to collect reward"; - - if (firstTimeInIndividualQuest || (questLogQuery != toSpeak)) - { - questLogQuery = toSpeak; - MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); - - if (firstTimeInIndividualQuest) - firstTimeInIndividualQuest = false; - } - - #endregion - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - #endregion - } } diff --git a/stardew-access/Patches/QuestPatches/BillboardPatch.cs b/stardew-access/Patches/QuestPatches/BillboardPatch.cs new file mode 100644 index 0000000..f8e4f47 --- /dev/null +++ b/stardew-access/Patches/QuestPatches/BillboardPatch.cs @@ -0,0 +1,98 @@ +using Microsoft.Xna.Framework.Graphics; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class BillboardPatch + { + private static string billboardQueryKey = ""; + + internal static void DrawPatch(Billboard __instance, bool ___dailyQuestBoard) + { + try + { + if (___dailyQuestBoard) + { + narrateDailyQuestBoard(__instance); + } + else + { + narrateCallendar(__instance); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void narrateCallendar(Billboard __instance) + { + for (int i = 0; i < __instance.calendarDays.Count; i++) + { + if (!__instance.calendarDays[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + continue; + + string toSpeak = $"Day {i + 1}"; + + if (__instance.calendarDays[i].name.Length > 0) + { + toSpeak += $", {__instance.calendarDays[i].name}"; + } + if (__instance.calendarDays[i].hoverText.Length > 0) + { + toSpeak += $", {__instance.calendarDays[i].hoverText}"; + } + + if (Game1.dayOfMonth == i + 1) + toSpeak += $", Current"; + + if (billboardQueryKey != toSpeak) + { + billboardQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + } + + private static void narrateDailyQuestBoard(Billboard __instance) + { + if (Game1.questOfTheDay == null || Game1.questOfTheDay.currentObjective == null || Game1.questOfTheDay.currentObjective.Length == 0) + { + // No quests + string toSpeak = "No quests for today!"; + if (billboardQueryKey != toSpeak) + { + billboardQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + else + { + SpriteFont font = ((LocalizedContentManager.CurrentLanguageCode == LocalizedContentManager.LanguageCode.ko) ? Game1.smallFont : Game1.dialogueFont); + string description = Game1.parseText(Game1.questOfTheDay.questDescription, font, 640); + string toSpeak = description; + + if (billboardQueryKey != toSpeak) + { + billboardQueryKey = toSpeak; + + // Snap to accept quest button + if (__instance.acceptQuestButton.visible) + { + toSpeak += "\t\n Left click to accept quest."; + __instance.acceptQuestButton.snapMouseCursorToCenter(); + } + + MainClass.ScreenReader.Say(toSpeak, true); + } + } + } + + internal static void Cleanup() + { + billboardQueryKey = ""; + } + } +} diff --git a/stardew-access/Patches/QuestPatches/QuestLogPatch.cs b/stardew-access/Patches/QuestPatches/QuestLogPatch.cs new file mode 100644 index 0000000..c93ddc1 --- /dev/null +++ b/stardew-access/Patches/QuestPatches/QuestLogPatch.cs @@ -0,0 +1,164 @@ +using StardewValley; +using StardewValley.Menus; +using StardewValley.Quests; + +namespace stardew_access.Patches +{ + // a.k.a. Journal Menu + internal class QuestLogPatch + { + internal static string questLogQuery = ""; + internal static bool isNarratingQuestInfo = false; + internal static bool firstTimeInIndividualQuest = true; + + internal static void DrawPatch(QuestLog __instance, int ___questPage, List> ___pages, int ___currentPage, IQuest ____shownQuest, List ____objectiveText) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (___questPage == -1) + { + narrateQuestList(__instance, ___pages, ___currentPage, x, y); + } + else + { + narrateIndividualQuest(__instance, ___currentPage, ____shownQuest, ____objectiveText, x, y); + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static void narrateQuestList(QuestLog __instance, List> ___pages, int ___currentPage, int x, int y) + { + string toSpeak = ""; + + if (!firstTimeInIndividualQuest) firstTimeInIndividualQuest = true; + + if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous page button"; + else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) + toSpeak = "Close menu button"; + else + { + for (int i = 0; i < __instance.questLogButtons.Count; i++) + { + if (___pages.Count() <= 0 || ___pages[___currentPage].Count() <= i) + continue; + + if (!__instance.questLogButtons[i].containsPoint(x, y)) + continue; + + string name = ___pages[___currentPage][i].GetName(); + int daysLeft = ___pages[___currentPage][i].GetDaysLeft(); + toSpeak = $"{name}"; + + if (daysLeft > 0 && ___pages[___currentPage][i].ShouldDisplayAsComplete()) + toSpeak += $"\t\n {daysLeft} days left"; + + toSpeak += ___pages[___currentPage][i].ShouldDisplayAsComplete() ? " completed!" : ""; + break; + } + } + + if (questLogQuery != toSpeak) + { + questLogQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + + private static void narrateIndividualQuest(QuestLog __instance, int ___currentPage, IQuest ____shownQuest, List ____objectiveText, int x, int y) + { + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + bool containsReward = __instance.HasReward() || __instance.HasMoneyReward(); + string description = Game1.parseText(____shownQuest.GetDescription(), Game1.dialogueFont, __instance.width - 128); + string title = ____shownQuest.GetName(); + string toSpeak = ""; + string extra = ""; + + if (firstTimeInIndividualQuest || (isPrimaryInfoKeyPressed && !isNarratingQuestInfo)) + { + if (firstTimeInIndividualQuest) + toSpeak = "Back button"; + + if (____shownQuest.ShouldDisplayAsComplete()) + { + #region Quest completed menu + + extra = $"Quest: {title} Completed!"; + + if (__instance.HasMoneyReward()) + extra += $"you recieved {____shownQuest.GetMoneyReward()}g"; + + #endregion + } + else + { + #region Quest in-complete menu + extra = $"Title: {title}. \t\n Description: {description}"; + + for (int j = 0; j < ____objectiveText.Count; j++) + { + string parsed_text = Game1.parseText(____objectiveText[j], width: __instance.width - 192, whichFont: Game1.dialogueFont); + if (____shownQuest != null && ____shownQuest is SpecialOrder) + { + OrderObjective order_objective = ((SpecialOrder)____shownQuest).objectives[j]; + if (order_objective.GetMaxCount() > 1 && order_objective.ShouldShowProgress()) + parsed_text += "\n\t" + order_objective.GetCount() + " of " + order_objective.GetMaxCount() + " completed"; + } + + extra += $"\t\nOrder {j + 1}: {parsed_text} \t\n"; + } + + if (____shownQuest != null) + { + int daysLeft = ____shownQuest.GetDaysLeft(); + + if (daysLeft > 0) + extra += $"\t\n{daysLeft} days left."; + } + #endregion + } + + isNarratingQuestInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingQuestInfo = false; }); + questLogQuery = ""; + } + + if (!firstTimeInIndividualQuest) + { + if (__instance.backButton != null && __instance.backButton.visible && __instance.backButton.containsPoint(x, y)) + toSpeak = (___currentPage > 0) ? "Previous page button" : "Back button"; + else if (__instance.forwardButton != null && __instance.forwardButton.visible && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.cancelQuestButton != null && __instance.cancelQuestButton.visible && __instance.cancelQuestButton.containsPoint(x, y)) + toSpeak = "Cancel quest button"; + else if (__instance.upperRightCloseButton != null && __instance.upperRightCloseButton.visible && __instance.upperRightCloseButton.containsPoint(x, y)) + toSpeak = "Close menu button"; + else if (containsReward && __instance.rewardBox.containsPoint(x, y)) + toSpeak = "Left click to collect reward"; + } + + if (firstTimeInIndividualQuest || (questLogQuery != toSpeak)) + { + questLogQuery = toSpeak; + MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); + + if (firstTimeInIndividualQuest) firstTimeInIndividualQuest = false; + } + } + + internal static void Cleaup() + { + questLogQuery = ""; + isNarratingQuestInfo = false; + firstTimeInIndividualQuest = true; + } + } +} diff --git a/stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs b/stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs new file mode 100644 index 0000000..eb27f5a --- /dev/null +++ b/stardew-access/Patches/QuestPatches/SpecialOrdersBoardPatch.cs @@ -0,0 +1,84 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class SpecialOrdersBoardPatch + { + private static string specialOrdersBoardQueryKey = ""; + + internal static void DrawPatch(SpecialOrdersBoard __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.acceptLeftQuestButton.visible && __instance.acceptLeftQuestButton.containsPoint(x, y)) + { + string toSpeak = getSpecialOrderDetails(__instance.leftOrder); + + toSpeak = $"Left Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; + + Speak(toSpeak); + return; + } + + if (__instance.acceptRightQuestButton.visible && __instance.acceptRightQuestButton.containsPoint(x, y)) + { + string toSpeak = getSpecialOrderDetails(__instance.rightOrder); + + toSpeak = $"Right Quest:\n\t{toSpeak}\n\tPress left click to accept this quest."; + + Speak(toSpeak); + return; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static string getSpecialOrderDetails(SpecialOrder order) + { + int daysLeft = order.GetDaysLeft(); + string description = order.GetDescription(); + string objectiveDescription = ""; + string name = order.GetName(); + int moneyReward = order.GetMoneyReward(); + + // Get each objectives + for (int i = 0; i < order.GetObjectiveDescriptions().Count; i++) + { + objectiveDescription += order.GetObjectiveDescriptions()[i] + ", \n"; + } + + string toReturn = $"{name}\n\tDescription:{description}\n\tObjectives: {objectiveDescription}"; + + if (order.IsTimedQuest()) + { + toReturn = $"{toReturn}\n\tTime: {daysLeft} days"; + } + + if (order.HasMoneyReward()) + { + toReturn = $"{toReturn}\n\tReward: {moneyReward}g"; + } + + return toReturn; + } + + private static void Speak(string toSpeak) + { + if (specialOrdersBoardQueryKey == toSpeak) return; + + specialOrdersBoardQueryKey = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + + internal static void Cleanup() + { + specialOrdersBoardQueryKey = ""; + } + } +} From c553b589abbd87d90b995a2e958382f2f6d97b39 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:32:43 +0530 Subject: [PATCH 53/61] Moved patches related to Game1 and InstanceGame to their own class --- stardew-access/HarmonyPatches.cs | 7 +-- stardew-access/Patches/Game1Patch.cs | 56 +++++++++++++++++++++ stardew-access/Patches/InstanceGamePatch.cs | 11 ++++ stardew-access/Patches/MenuPatches.cs | 48 ------------------ stardew-access/Patches/QuestPatches.cs | 11 ---- 5 files changed, 71 insertions(+), 62 deletions(-) create mode 100644 stardew-access/Patches/Game1Patch.cs create mode 100644 stardew-access/Patches/InstanceGamePatch.cs delete mode 100644 stardew-access/Patches/QuestPatches.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 78d8c22..cb8d85c 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -222,9 +222,10 @@ namespace stardew_access original: AccessTools.Method(typeof(IClickableMenu), nameof(IClickableMenu.exitThisMenu)), postfix: new HarmonyMethod(typeof(IClickableMenuPatch), nameof(IClickableMenuPatch.ExitThisMenuPatch)) ); + harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.exitActiveMenu)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.Game1ExitActiveMenuPatch)) + prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.ExitActiveMenuPatch)) ); #endregion @@ -278,12 +279,12 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(Game1), nameof(Game1.playSound)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PlaySoundPatch)) + prefix: new HarmonyMethod(typeof(Game1Patch), nameof(Game1Patch.PlaySoundPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(InstanceGame), nameof(InstanceGame.Exit)), - prefix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ExitEventPatch)) + prefix: new HarmonyMethod(typeof(InstanceGamePatch), nameof(InstanceGamePatch.ExitPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/Game1Patch.cs b/stardew-access/Patches/Game1Patch.cs new file mode 100644 index 0000000..04ba91f --- /dev/null +++ b/stardew-access/Patches/Game1Patch.cs @@ -0,0 +1,56 @@ +using Microsoft.Xna.Framework; +using stardew_access.Features; +using StardewModdingAPI; +using StardewValley; + +namespace stardew_access.Patches +{ + internal class Game1Patch + { + private static Vector2? prevTile = null; + + internal static void ExitActiveMenuPatch() + { + try + { + IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static bool PlaySoundPatch(string cueName) + { + try + { + if (!Context.IsPlayerFree) + return true; + + if (!Game1.player.isMoving()) + return true; + + if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") + { + Vector2 nextTile = CurrentPlayer.FacingTile; + if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) + { + if (prevTile != nextTile) + { + prevTile = nextTile; + //Game1.playSound("colliding"); + } + return false; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + + return true; + } + } +} diff --git a/stardew-access/Patches/InstanceGamePatch.cs b/stardew-access/Patches/InstanceGamePatch.cs new file mode 100644 index 0000000..93affb1 --- /dev/null +++ b/stardew-access/Patches/InstanceGamePatch.cs @@ -0,0 +1,11 @@ +namespace stardew_access.Patches +{ + internal class InstanceGamePatch + { + internal static void ExitPatch() + { + if (MainClass.ScreenReader != null) + MainClass.ScreenReader.CloseScreenReader(); + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 2576c40..1aa61a1 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -17,7 +17,6 @@ namespace stardew_access.Patches internal static string forgeMenuQuery = " "; internal static string itemListMenuQuery = " "; internal static int prevSlotIndex = -999; - public static Vector2? prevTile = null; internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) { @@ -312,37 +311,6 @@ namespace stardew_access.Patches } } - internal static bool PlaySoundPatch(string cueName) - { - try - { - if (!Context.IsPlayerFree) - return true; - - if (!Game1.player.isMoving()) - return true; - - if (cueName == "grassyStep" || cueName == "sandyStep" || cueName == "snowyStep" || cueName == "stoneStep" || cueName == "thudStep" || cueName == "woodyStep") - { - Vector2 nextTile = CurrentPlayer.FacingTile; - if (TileInfo.isCollidingAtTile((int)nextTile.X, (int)nextTile.Y)) - { - if (prevTile != nextTile) - { - prevTile = nextTile; - //Game1.playSound("colliding"); - } - return false; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - - return true; - } internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) { @@ -604,22 +572,6 @@ namespace stardew_access.Patches } } - internal static void Game1ExitActiveMenuPatch() - { - try - { - IClickableMenuPatch.Cleanup(Game1.activeClickableMenu); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ExitEventPatch() - { - if (MainClass.ScreenReader != null) - MainClass.ScreenReader.CloseScreenReader(); - } } } diff --git a/stardew-access/Patches/QuestPatches.cs b/stardew-access/Patches/QuestPatches.cs deleted file mode 100644 index cbe8441..0000000 --- a/stardew-access/Patches/QuestPatches.cs +++ /dev/null @@ -1,11 +0,0 @@ -using Microsoft.Xna.Framework.Graphics; -using StardewValley; -using StardewValley.Menus; -using StardewValley.Quests; - -namespace stardew_access.Patches -{ - internal class QuestPatches - { - } -} From a250cbd98df64a8a2e96aee31fa0bf1049320b7e Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:35:46 +0530 Subject: [PATCH 54/61] Renamed classes --- stardew-access/HarmonyPatches.cs | 2 +- .../{CarpenterMenuPach.cs => CarpenterMenuPatch.cs} | 0 .../Patches/{ChatMenuPatches.cs => ChatMenuPatch.cs} | 7 +++---- stardew-access/Patches/MenuPatches.cs | 1 - 4 files changed, 4 insertions(+), 6 deletions(-) rename stardew-access/Patches/{CarpenterMenuPach.cs => CarpenterMenuPatch.cs} (100%) rename stardew-access/Patches/{ChatMenuPatches.cs => ChatMenuPatch.cs} (93%) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index cb8d85c..b6cf1e3 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -213,7 +213,7 @@ namespace stardew_access #region Chat Menu Patches harmony.Patch( original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(ChatMenuPatches), nameof(ChatMenuPatches.ChatBoxPatch)) + postfix: new HarmonyMethod(typeof(ChatMenuPatch), nameof(ChatMenuPatch.UpdatePatch)) ); #endregion diff --git a/stardew-access/Patches/CarpenterMenuPach.cs b/stardew-access/Patches/CarpenterMenuPatch.cs similarity index 100% rename from stardew-access/Patches/CarpenterMenuPach.cs rename to stardew-access/Patches/CarpenterMenuPatch.cs diff --git a/stardew-access/Patches/ChatMenuPatches.cs b/stardew-access/Patches/ChatMenuPatch.cs similarity index 93% rename from stardew-access/Patches/ChatMenuPatches.cs rename to stardew-access/Patches/ChatMenuPatch.cs index c997ac7..a0b521e 100644 --- a/stardew-access/Patches/ChatMenuPatches.cs +++ b/stardew-access/Patches/ChatMenuPatch.cs @@ -1,14 +1,13 @@ -using StardewValley; -using StardewValley.Menus; +using StardewValley.Menus; namespace stardew_access.Patches { - internal class ChatMenuPatches + internal class ChatMenuPatch { private static int currentChatMessageIndex = 0; private static bool isChatRunning = false; - internal static void ChatBoxPatch(ChatBox __instance, List ___messages) + internal static void UpdatePatch(ChatBox __instance, List ___messages) { try { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 1aa61a1..46acc3f 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -311,7 +311,6 @@ namespace stardew_access.Patches } } - internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) { try From 64300c58eb3032280cf04ede83718b3190ae0a51 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:41:30 +0530 Subject: [PATCH 55/61] Moved item list menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/ItemListMenuPatch.cs | 55 +++++++++++++++++++ stardew-access/Patches/MenuPatches.cs | 46 ---------------- 4 files changed, 57 insertions(+), 48 deletions(-) create mode 100644 stardew-access/Patches/ItemListMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index b6cf1e3..f894686 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -189,7 +189,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ItemListMenu), nameof(ItemListMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ItemListMenuPatch)) + postfix: new HarmonyMethod(typeof(ItemListMenuPatch), nameof(ItemListMenuPatch.DrawPatch)) ); #endregion diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index f935345..35ffe98 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -296,7 +296,7 @@ namespace stardew_access.Patches } else if (menu is ItemListMenu) { - MenuPatches.itemListMenuQuery = " "; + ItemListMenuPatch.Cleanup(); } else if (menu is FieldOfficeMenu) { diff --git a/stardew-access/Patches/ItemListMenuPatch.cs b/stardew-access/Patches/ItemListMenuPatch.cs new file mode 100644 index 0000000..e94a206 --- /dev/null +++ b/stardew-access/Patches/ItemListMenuPatch.cs @@ -0,0 +1,55 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ItemListMenuPatch + { + private static string itemListMenuQuery = ""; + + internal static void DrawPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = "", currentList = ""; + + for (int i = ___currentTab * __instance.itemsPerCategoryPage; i < ___currentTab * __instance.itemsPerCategoryPage + __instance.itemsPerCategoryPage; i++) + { + if (i == 0) currentList = ___title; + if (___itemsToList.Count <= i) continue; + + if (___itemsToList[i] == null) + { + currentList = $"{currentList}, \n" + Game1.content.LoadString("Strings\\UI:ItemList_ItemsLostValue", ___totalValueOfItems); + continue; + } + + currentList = $"{currentList}, \n {___itemsToList[i].Stack} {___itemsToList[i].DisplayName}"; + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = $"Page {___currentTab + 1} of {((int)___itemsToList.Count / __instance.itemsPerCategoryPage) + 1} \n {currentList} \n ok button"; + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next page button"; + else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous page button"; + + if (itemListMenuQuery != toSpeak) + { + itemListMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + itemListMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 46acc3f..20ca4c4 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -15,52 +15,8 @@ namespace stardew_access.Patches internal static string tailoringMenuQuery = " "; internal static string pondQueryMenuQuery = " "; internal static string forgeMenuQuery = " "; - internal static string itemListMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void ItemListMenuPatch(ItemListMenu __instance, string ___title, int ___currentTab, int ___totalValueOfItems, List ___itemsToList) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " ", currentList = " "; - - for (int i = ___currentTab * __instance.itemsPerCategoryPage; i < ___currentTab * __instance.itemsPerCategoryPage + __instance.itemsPerCategoryPage; i++) - { - if (i == 0) - currentList = ___title; - - if (___itemsToList.Count > i) - { - if (___itemsToList[i] == null) - { - currentList = $"{currentList}, \n" + Game1.content.LoadString("Strings\\UI:ItemList_ItemsLostValue", ___totalValueOfItems); - continue; - } - - currentList = $"{currentList}, \n {___itemsToList[i].Stack} {___itemsToList[i].DisplayName}"; - } - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = $"Page {___currentTab + 1} of {((int)___itemsToList.Count / __instance.itemsPerCategoryPage) + 1} \n {currentList} \n ok button"; - else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next page button"; - else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous page button"; - - if (itemListMenuQuery != toSpeak) - { - itemListMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ForgeMenuPatch(ForgeMenu __instance) { try @@ -570,7 +526,5 @@ namespace stardew_access.Patches MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); } } - - } } From 07fcc942960ce66790891f8054a486f0ca215cb8 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:50:40 +0530 Subject: [PATCH 56/61] Moved forge menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/ForgeMenuPatch.cs | 116 ++++++++++++++++++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 85 ------------- 4 files changed, 118 insertions(+), 87 deletions(-) create mode 100644 stardew-access/Patches/ForgeMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index f894686..5e84c6b 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -184,7 +184,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ForgeMenu), nameof(ForgeMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ForgeMenuPatch)) + postfix: new HarmonyMethod(typeof(ForgeMenuPatch), nameof(ForgeMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ForgeMenuPatch.cs b/stardew-access/Patches/ForgeMenuPatch.cs new file mode 100644 index 0000000..d5b6671 --- /dev/null +++ b/stardew-access/Patches/ForgeMenuPatch.cs @@ -0,0 +1,116 @@ +using stardew_access.Features; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ForgeMenuPatch + { + private static string forgeMenuQuery = ""; + + internal static void DrawPatch(ForgeMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (narrateHoveredButton(__instance, x, y)) return; + + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + { + Cleanup(); + } + + } + catch (System.Exception e) + { + MainClass.ErrorLog($"An error occured in forge menu patch:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateHoveredButton(ForgeMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) + { + if (__instance.leftIngredientSpot.item == null) + { + toSpeak = "Input weapon or tool here"; + } + else + { + Item item = __instance.leftIngredientSpot.item; + toSpeak = $"Weapon slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) + { + if (__instance.rightIngredientSpot.item == null) + { + toSpeak = "Input gemstone here"; + } + else + { + Item item = __instance.rightIngredientSpot.item; + toSpeak = $"Gemstone slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) + { + toSpeak = "Star forging button"; + } + else if (__instance.unforgeButton != null && __instance.unforgeButton.containsPoint(x, y)) + { + toSpeak = "Unforge button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + isDropItemButton = true; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) + { + toSpeak = "Left ring Slot"; + + if (Game1.player.leftRing.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.leftRing.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) + { + toSpeak = "Right ring Slot"; + + if (Game1.player.rightRing.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; + } + else + { + return false; + } + + if (forgeMenuQuery != toSpeak) + { + forgeMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + internal static void Cleanup() + { + forgeMenuQuery = ""; + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 35ffe98..6f8f121 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -292,7 +292,7 @@ namespace stardew_access.Patches } else if (menu is ForgeMenu) { - MenuPatches.forgeMenuQuery = " "; + ForgeMenuPatch.Cleanup(); } else if (menu is ItemListMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 20ca4c4..9a1b2d4 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -14,93 +14,8 @@ namespace stardew_access.Patches internal static bool isNarratingPondInfo = false; internal static string tailoringMenuQuery = " "; internal static string pondQueryMenuQuery = " "; - internal static string forgeMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void ForgeMenuPatch(ForgeMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) - { - if (__instance.leftIngredientSpot.item == null) - { - toSpeak = "Input weapon or tool here"; - } - else - { - Item item = __instance.leftIngredientSpot.item; - toSpeak = $"Weapon slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) - { - if (__instance.rightIngredientSpot.item == null) - { - toSpeak = "Input gemstone here"; - } - else - { - Item item = __instance.rightIngredientSpot.item; - toSpeak = $"Gemstone slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) - { - toSpeak = "Star forging button"; - } - else if (__instance.unforgeButton != null && __instance.unforgeButton.containsPoint(x, y)) - { - toSpeak = "Unforge button"; - } - else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) - { - toSpeak = "Left ring Slot"; - - if (Game1.player.leftRing.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.leftRing.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) - { - toSpeak = "Right ring Slot"; - - if (Game1.player.rightRing.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.rightRing.Value.DisplayName}"; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - if (forgeMenuQuery != toSpeak) - { - forgeMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void PondQueryMenuPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) { try From af0ec1ab8d55231f3cc3f553ba5463640bd9d103 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 14:55:07 +0530 Subject: [PATCH 57/61] Moved pond query menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 56 --------------- stardew-access/Patches/PondQuerMenuPatch.cs | 72 +++++++++++++++++++ 4 files changed, 74 insertions(+), 58 deletions(-) create mode 100644 stardew-access/Patches/PondQuerMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 5e84c6b..d576d60 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -179,7 +179,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(PondQueryMenu), nameof(PondQueryMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.PondQueryMenuPatch)) + postfix: new HarmonyMethod(typeof(PondQueryMenuPatch), nameof(PondQueryMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 6f8f121..993c4f3 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -308,7 +308,7 @@ namespace stardew_access.Patches } else if (menu is PondQueryMenu) { - MenuPatches.pondQueryMenuQuery = " "; + PondQueryMenuPatch.Cleanup(); } else if (menu is GeodeMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 9a1b2d4..0cca006 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,65 +11,9 @@ namespace stardew_access.Patches { internal static string currentLevelUpTitle = " "; internal static bool firstTimeInNamingMenu = true; - internal static bool isNarratingPondInfo = false; internal static string tailoringMenuQuery = " "; - internal static string pondQueryMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void PondQueryMenuPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); - string toSpeak = " ", extra = ""; - - if (___confirmingEmpty) - { - if (__instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) - toSpeak = "Confirm button"; - else if (__instance.noButton != null && __instance.noButton.containsPoint(x, y)) - toSpeak = "Cancel button"; - } - else - { - if (isPrimaryInfoKeyPressed && !isNarratingPondInfo) - { - string pond_name_text = Game1.content.LoadString("Strings\\UI:PondQuery_Name", ____fishItem.DisplayName); - string population_text = Game1.content.LoadString("Strings\\UI:PondQuery_Population", string.Concat(____pond.FishCount), ____pond.maxOccupants.Value); - bool has_unresolved_needs = ____pond.neededItem.Value != null && ____pond.HasUnresolvedNeeds() && !____pond.hasCompletedRequest.Value; - string bring_text = ""; - - if (has_unresolved_needs && ____pond.neededItem.Value != null) - bring_text = Game1.content.LoadString("Strings\\UI:PondQuery_StatusRequest_Bring") + $": {____pond.neededItemCount} {____pond.neededItem.Value.DisplayName}"; - - extra = $"{pond_name_text} {population_text} {bring_text} Status: {____statusText}"; - pondQueryMenuQuery = " "; - - isNarratingPondInfo = true; - Task.Delay(200).ContinueWith(_ => { isNarratingPondInfo = false; }); - } - - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "Ok button"; - else if (__instance.changeNettingButton != null && __instance.changeNettingButton.containsPoint(x, y)) - toSpeak = "Change netting button"; - else if (__instance.emptyButton != null && __instance.emptyButton.containsPoint(x, y)) - toSpeak = "Empty pond button"; - } - - if (pondQueryMenuQuery != toSpeak) - { - pondQueryMenuQuery = toSpeak; - MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void TailoringMenuPatch(TailoringMenu __instance) { try diff --git a/stardew-access/Patches/PondQuerMenuPatch.cs b/stardew-access/Patches/PondQuerMenuPatch.cs new file mode 100644 index 0000000..a370fc1 --- /dev/null +++ b/stardew-access/Patches/PondQuerMenuPatch.cs @@ -0,0 +1,72 @@ +using StardewValley; +using StardewValley.Buildings; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class PondQueryMenuPatch + { + private static string pondQueryMenuQuery = ""; + private static bool isNarratingPondInfo = false; + + internal static void DrawPatch(PondQueryMenu __instance, StardewValley.Object ____fishItem, FishPond ____pond, string ____statusText, bool ___confirmingEmpty) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isPrimaryInfoKeyPressed = MainClass.Config.PrimaryInfoKey.JustPressed(); + string toSpeak = "", extra = ""; + + if (___confirmingEmpty) + { + if (__instance.yesButton != null && __instance.yesButton.containsPoint(x, y)) + toSpeak = "Confirm button"; + else if (__instance.noButton != null && __instance.noButton.containsPoint(x, y)) + toSpeak = "Cancel button"; + } + else + { + if (isPrimaryInfoKeyPressed && !isNarratingPondInfo) + { + string pond_name_text = Game1.content.LoadString("Strings\\UI:PondQuery_Name", ____fishItem.DisplayName); + string population_text = Game1.content.LoadString("Strings\\UI:PondQuery_Population", string.Concat(____pond.FishCount), ____pond.maxOccupants.Value); + bool has_unresolved_needs = ____pond.neededItem.Value != null && ____pond.HasUnresolvedNeeds() && !____pond.hasCompletedRequest.Value; + string bring_text = ""; + + if (has_unresolved_needs && ____pond.neededItem.Value != null) + bring_text = Game1.content.LoadString("Strings\\UI:PondQuery_StatusRequest_Bring") + $": {____pond.neededItemCount} {____pond.neededItem.Value.DisplayName}"; + + extra = $"{pond_name_text} {population_text} {bring_text} Status: {____statusText}"; + pondQueryMenuQuery = ""; + + isNarratingPondInfo = true; + Task.Delay(200).ContinueWith(_ => { isNarratingPondInfo = false; }); + } + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "Ok button"; + else if (__instance.changeNettingButton != null && __instance.changeNettingButton.containsPoint(x, y)) + toSpeak = "Change netting button"; + else if (__instance.emptyButton != null && __instance.emptyButton.containsPoint(x, y)) + toSpeak = "Empty pond button"; + } + + if (pondQueryMenuQuery != toSpeak) + { + pondQueryMenuQuery = toSpeak; + MainClass.ScreenReader.Say(extra + " \n\t" + toSpeak, true); + } + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + pondQueryMenuQuery = ""; + isNarratingPondInfo = false; + } + } +} From b0c1d9e17368b2d126d518d09afa9340f100d700 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:00:31 +0530 Subject: [PATCH 58/61] Moved tailoring menu patch to its own class --- stardew-access/HarmonyPatches.cs | 2 +- stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/MenuPatches.cs | 89 -------------- stardew-access/Patches/TailoringMenuPatch.cs | 115 ++++++++++++++++++ 4 files changed, 117 insertions(+), 91 deletions(-) create mode 100644 stardew-access/Patches/TailoringMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index d576d60..fc08646 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -174,7 +174,7 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(TailoringMenu), nameof(TailoringMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.TailoringMenuPatch)) + postfix: new HarmonyMethod(typeof(TailoringMenuPatch), nameof(TailoringMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 993c4f3..6668365 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -288,7 +288,7 @@ namespace stardew_access.Patches } else if (menu is TailoringMenu) { - MenuPatches.tailoringMenuQuery = " "; + TailoringMenuPatch.Cleanup(); } else if (menu is ForgeMenu) { diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 0cca006..420073d 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -11,97 +11,8 @@ namespace stardew_access.Patches { internal static string currentLevelUpTitle = " "; internal static bool firstTimeInNamingMenu = true; - internal static string tailoringMenuQuery = " "; internal static int prevSlotIndex = -999; - internal static void TailoringMenuPatch(TailoringMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = " "; - - if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) - { - if (__instance.leftIngredientSpot.item == null) - { - toSpeak = "Input cloth here"; - } - else - { - Item item = __instance.leftIngredientSpot.item; - toSpeak = $"Cloth slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) - { - if (__instance.rightIngredientSpot.item == null) - { - toSpeak = "Input ingredient here"; - } - else - { - Item item = __instance.rightIngredientSpot.item; - toSpeak = $"Ingredient slot: {item.Stack} {item.DisplayName}"; - } - } - else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) - { - toSpeak = "Star tailoring button"; - } - else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) - { - toSpeak = "Trashcan"; - } - else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - { - toSpeak = "ok button"; - } - else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - { - toSpeak = "drop item"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) - { - toSpeak = "Hat Slot"; - - if (Game1.player.hat.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.hat.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) - { - toSpeak = "Shirt Slot"; - - if (Game1.player.shirtItem.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.shirtItem.Value.DisplayName}"; - } - else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[2].containsPoint(x, y)) - { - toSpeak = "Pants Slot"; - - if (Game1.player.pantsItem.Value != null) - toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; - } - - if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) - return; - - - if (tailoringMenuQuery != toSpeak) - { - tailoringMenuQuery = toSpeak; - MainClass.ScreenReader.Say(toSpeak, true); - - if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) - Game1.playSound("drop_item"); - } - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - internal static void ChooseFromListMenuPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) { try diff --git a/stardew-access/Patches/TailoringMenuPatch.cs b/stardew-access/Patches/TailoringMenuPatch.cs new file mode 100644 index 0000000..3718730 --- /dev/null +++ b/stardew-access/Patches/TailoringMenuPatch.cs @@ -0,0 +1,115 @@ +using stardew_access.Features; +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TailoringMenuPatch + { + internal static string tailoringMenuQuery = ""; + + internal static void DrawPatch(TailoringMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (InventoryUtils.narrateHoveredSlot(__instance.inventory, __instance.inventory.inventory, __instance.inventory.actualInventory, x, y)) + return; + + + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + private static bool narrateHoveredButton(TailoringMenu __instance, int x, int y) + { + string toSpeak = ""; + bool isDropItemButton = false; + + if (__instance.leftIngredientSpot != null && __instance.leftIngredientSpot.containsPoint(x, y)) + { + if (__instance.leftIngredientSpot.item == null) + { + toSpeak = "Input cloth here"; + } + else + { + Item item = __instance.leftIngredientSpot.item; + toSpeak = $"Cloth slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.rightIngredientSpot != null && __instance.rightIngredientSpot.containsPoint(x, y)) + { + if (__instance.rightIngredientSpot.item == null) + { + toSpeak = "Input ingredient here"; + } + else + { + Item item = __instance.rightIngredientSpot.item; + toSpeak = $"Ingredient slot: {item.Stack} {item.DisplayName}"; + } + } + else if (__instance.startTailoringButton != null && __instance.startTailoringButton.containsPoint(x, y)) + { + toSpeak = "Star tailoring button"; + } + else if (__instance.trashCan != null && __instance.trashCan.containsPoint(x, y)) + { + toSpeak = "Trashcan"; + } + else if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + { + toSpeak = "ok button"; + } + else if (__instance.dropItemInvisibleButton != null && __instance.dropItemInvisibleButton.containsPoint(x, y)) + { + toSpeak = "drop item"; + isDropItemButton = true; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[0].containsPoint(x, y)) + { + toSpeak = "Hat Slot"; + + if (Game1.player.hat.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.hat.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[1].containsPoint(x, y)) + { + toSpeak = "Shirt Slot"; + + if (Game1.player.shirtItem.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.shirtItem.Value.DisplayName}"; + } + else if (__instance.equipmentIcons.Count > 0 && __instance.equipmentIcons[2].containsPoint(x, y)) + { + toSpeak = "Pants Slot"; + + if (Game1.player.pantsItem.Value != null) + toSpeak = $"{toSpeak}: {Game1.player.pantsItem.Value.DisplayName}"; + } + else { + return false; + } + + if (tailoringMenuQuery != toSpeak) + { + tailoringMenuQuery = toSpeak; + MainClass.ScreenReader.Say(toSpeak, true); + + if (isDropItemButton) Game1.playSound("drop_item"); + } + + return true; + } + + internal static void Cleanup() + { + tailoringMenuQuery = ""; + } + } +} From ea03f9a4cbf0f71b59436ccc021cdf341d6fe98f Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:09:56 +0530 Subject: [PATCH 59/61] Moved some menus to their own class --- stardew-access/HarmonyPatches.cs | 6 +- .../Patches/ChooseFromListMenuPatch.cs | 32 ++++++++ .../Patches/LanguageSelectionMenuPatch.cs | 41 ++++++++++ stardew-access/Patches/MenuPatches.cs | 74 ------------------- .../Patches/MineElevatorMenuPatch.cs | 28 +++++++ 5 files changed, 104 insertions(+), 77 deletions(-) create mode 100644 stardew-access/Patches/ChooseFromListMenuPatch.cs create mode 100644 stardew-access/Patches/LanguageSelectionMenuPatch.cs create mode 100644 stardew-access/Patches/MineElevatorMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index fc08646..35db304 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -159,17 +159,17 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(MineElevatorMenu), nameof(MineElevatorMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.MineElevatorMenuPatch)) + postfix: new HarmonyMethod(typeof(MineElevatorMenuPatch), nameof(MineElevatorMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LanguageSelectionMenu), nameof(LanguageSelectionMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LanguageSelectionMenuPatch)) + postfix: new HarmonyMethod(typeof(LanguageSelectionMenuPatch), nameof(LanguageSelectionMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(ChooseFromListMenu), nameof(ChooseFromListMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ChooseFromListMenuPatch)) + postfix: new HarmonyMethod(typeof(ChooseFromListMenuPatch), nameof(ChooseFromListMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ChooseFromListMenuPatch.cs b/stardew-access/Patches/ChooseFromListMenuPatch.cs new file mode 100644 index 0000000..2e19781 --- /dev/null +++ b/stardew-access/Patches/ChooseFromListMenuPatch.cs @@ -0,0 +1,32 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ChooseFromListMenuPatch + { + internal static void DrawPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + string toSpeak = ""; + + if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) + toSpeak = "Select " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[___index]) : ___options[___index]) + " button"; + else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) + toSpeak = "Cancel button"; + else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) + toSpeak = "Previous option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Max(0, ___index - 1)]) : ___options[Math.Max(0, ___index - 1)]) + " button"; + else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) + toSpeak = "Next option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Min(___options.Count, ___index + 1)]) : ___options[Math.Min(___options.Count, ___index + 1)]) + " button"; + + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/LanguageSelectionMenuPatch.cs b/stardew-access/Patches/LanguageSelectionMenuPatch.cs new file mode 100644 index 0000000..968a171 --- /dev/null +++ b/stardew-access/Patches/LanguageSelectionMenuPatch.cs @@ -0,0 +1,41 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LanguageSelectionMenuPatch + { + internal static void DrawPatch(LanguageSelectionMenu __instance) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"Next Page Button", true); + return; + } + + if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"Previous Page Button", true); + return; + } + + for (int i = 0; i < __instance.languages.Count; i++) + { + if (__instance.languages[i].containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"{__instance.languageList[i]} Button", true); + break; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs index 420073d..6e343cd 100644 --- a/stardew-access/Patches/MenuPatches.cs +++ b/stardew-access/Patches/MenuPatches.cs @@ -13,82 +13,8 @@ namespace stardew_access.Patches internal static bool firstTimeInNamingMenu = true; internal static int prevSlotIndex = -999; - internal static void ChooseFromListMenuPatch(ChooseFromListMenu __instance, List ___options, int ___index, bool ___isJukebox) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - string toSpeak = ""; - if (__instance.okButton != null && __instance.okButton.containsPoint(x, y)) - toSpeak = "Select " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[___index]) : ___options[___index]) + " button"; - else if (__instance.cancelButton != null && __instance.cancelButton.containsPoint(x, y)) - toSpeak = "Cancel button"; - else if (__instance.backButton != null && __instance.backButton.containsPoint(x, y)) - toSpeak = "Previous option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Max(0, ___index - 1)]) : ___options[Math.Max(0, ___index - 1)]) + " button"; - else if (__instance.forwardButton != null && __instance.forwardButton.containsPoint(x, y)) - toSpeak = "Next option: " + (___isJukebox ? Utility.getSongTitleFromCueName(___options[Math.Min(___options.Count, ___index + 1)]) : ___options[Math.Min(___options.Count, ___index + 1)]) + " button"; - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LanguageSelectionMenuPatch(LanguageSelectionMenu __instance) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.nextPageButton != null && __instance.nextPageButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"Next Page Button", true); - return; - } - - if (__instance.previousPageButton != null && __instance.previousPageButton.containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"Previous Page Button", true); - return; - } - - for (int i = 0; i < __instance.languages.Count; i++) - { - if (__instance.languages[i].containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"{__instance.languageList[i]} Button", true); - break; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void MineElevatorMenuPatch(List ___elevators) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - for (int i = 0; i < ___elevators.Count; i++) - { - if (___elevators[i].containsPoint(x, y)) - { - MainClass.ScreenReader.SayWithMenuChecker($"{___elevators[i].name} level", true); - break; - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } internal static void TitleTextInputMenuPatch(TitleTextInputMenu __instance) { diff --git a/stardew-access/Patches/MineElevatorMenuPatch.cs b/stardew-access/Patches/MineElevatorMenuPatch.cs new file mode 100644 index 0000000..c1110f1 --- /dev/null +++ b/stardew-access/Patches/MineElevatorMenuPatch.cs @@ -0,0 +1,28 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class MineElevatorMenuPatch + { + internal static void DrawPatch(List ___elevators) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + for (int i = 0; i < ___elevators.Count; i++) + { + if (___elevators[i].containsPoint(x, y)) + { + MainClass.ScreenReader.SayWithMenuChecker($"{___elevators[i].name} level", true); + break; + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From b8fce68bec27a74a2f0eff61a180b3030043d666 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:24:08 +0530 Subject: [PATCH 60/61] Moved more menus to their own class --- stardew-access/HarmonyPatches.cs | 10 +- .../Patches/ConfirmationDialogMenuPatch.cs | 32 +++ stardew-access/Patches/IClickableMenuPatch.cs | 2 +- stardew-access/Patches/LevelUpMenuPatch.cs | 109 +++++++++ stardew-access/Patches/MenuPatches.cs | 226 ------------------ stardew-access/Patches/NamingMenuPatch.cs | 42 ++++ stardew-access/Patches/ShippingMenuPatch.cs | 46 ++++ .../Patches/TitleTextInputMenuPatch.cs | 27 +++ 8 files changed, 262 insertions(+), 232 deletions(-) create mode 100644 stardew-access/Patches/ConfirmationDialogMenuPatch.cs create mode 100644 stardew-access/Patches/LevelUpMenuPatch.cs delete mode 100644 stardew-access/Patches/MenuPatches.cs create mode 100644 stardew-access/Patches/NamingMenuPatch.cs create mode 100644 stardew-access/Patches/ShippingMenuPatch.cs create mode 100644 stardew-access/Patches/TitleTextInputMenuPatch.cs diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 35db304..5171631 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -134,27 +134,27 @@ namespace stardew_access harmony.Patch( original: AccessTools.Method(typeof(ShippingMenu), nameof(ShippingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ShippingMenuPatch)) + postfix: new HarmonyMethod(typeof(ShippingMenuPatch), nameof(ShippingMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(LevelUpMenu), nameof(LevelUpMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.LevelUpMenuPatch)) + postfix: new HarmonyMethod(typeof(LevelUpMenuPatch), nameof(LevelUpMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(ConfirmationDialog), nameof(ConfirmationDialog.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.ConfirmationDialogPatch)) + postfix: new HarmonyMethod(typeof(ConfirmationDialogMenuPatch), nameof(ConfirmationDialogMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(TitleTextInputMenu), nameof(TitleTextInputMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.TitleTextInputMenuPatch)) + postfix: new HarmonyMethod(typeof(TitleTextInputMenuPatch), nameof(TitleTextInputMenuPatch.DrawPatch)) ); harmony.Patch( original: AccessTools.Method(typeof(NamingMenu), nameof(NamingMenu.draw), new Type[] { typeof(SpriteBatch) }), - postfix: new HarmonyMethod(typeof(MenuPatches), nameof(MenuPatches.NamingMenuPatch)) + postfix: new HarmonyMethod(typeof(NamingMenuPatch), nameof(NamingMenuPatch.DrawPatch)) ); harmony.Patch( diff --git a/stardew-access/Patches/ConfirmationDialogMenuPatch.cs b/stardew-access/Patches/ConfirmationDialogMenuPatch.cs new file mode 100644 index 0000000..ffde9ec --- /dev/null +++ b/stardew-access/Patches/ConfirmationDialogMenuPatch.cs @@ -0,0 +1,32 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ConfirmationDialogMenuPatch + { + internal static void DrawPatch(ConfirmationDialog __instance, string ___message) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string toSpeak = ___message; + + if (__instance.okButton.containsPoint(x, y)) + { + toSpeak += "\n\tOk Button"; + } + else if (__instance.cancelButton.containsPoint(x, y)) + { + toSpeak += "\n\tCancel Button"; + } + + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/IClickableMenuPatch.cs index 6668365..7069fb5 100644 --- a/stardew-access/Patches/IClickableMenuPatch.cs +++ b/stardew-access/Patches/IClickableMenuPatch.cs @@ -231,7 +231,7 @@ namespace stardew_access.Patches } else if (menu is LevelUpMenu) { - MenuPatches.currentLevelUpTitle = " "; + LevelUpMenuPatch.Cleanup(); } else if (menu is Billboard) { diff --git a/stardew-access/Patches/LevelUpMenuPatch.cs b/stardew-access/Patches/LevelUpMenuPatch.cs new file mode 100644 index 0000000..cb4535b --- /dev/null +++ b/stardew-access/Patches/LevelUpMenuPatch.cs @@ -0,0 +1,109 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class LevelUpMenuPatch + { + private static string currentLevelUpTitle = ""; + + internal static void DrawPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title, bool ___isActive, bool ___isProfessionChooser) + { + try + { + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); + string leftProfession = "", rightProfession = "", extraInfo = "", newCraftingRecipe = "", toSpeak = ""; + + if (!__instance.informationUp) + return; + + if (__instance.isProfessionChooser) + { + if (___professionsToChoose.Count() == 0) return; + + for (int j = 0; j < ___leftProfessionDescription.Count; j++) + { + leftProfession += ___leftProfessionDescription[j] + ", "; + } + for (int i = 0; i < ___rightProfessionDescription.Count; i++) + { + rightProfession += ___rightProfessionDescription[i] + ", "; + } + + if (__instance.leftProfession.containsPoint(x, y)) + { + if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) + { + Game1.player.professions.Add(___professionsToChoose[0]); + __instance.getImmediateProfessionPerk(___professionsToChoose[0]); + ___isActive = false; + __instance.informationUp = false; + ___isProfessionChooser = false; + __instance.RemoveLevelFromLevelList(); + __instance.exitThisMenu(); + return; + } + + toSpeak = $"Selected: {leftProfession} Left click to choose."; + } + + if (__instance.rightProfession.containsPoint(x, y)) + { + if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) + { + Game1.player.professions.Add(___professionsToChoose[1]); + __instance.getImmediateProfessionPerk(___professionsToChoose[1]); + ___isActive = false; + __instance.informationUp = false; + ___isProfessionChooser = false; + __instance.RemoveLevelFromLevelList(); + __instance.exitThisMenu(); + return; + } + + toSpeak = $"Selected: {rightProfession} Left click to choose."; + } + } + else + { + foreach (string s2 in ___extraInfoForLevel) + { + extraInfo += s2 + ", "; + } + foreach (CraftingRecipe s in ___newCraftingRecipes) + { + string cookingOrCrafting = Game1.content.LoadString("Strings\\UI:LearnedRecipe_" + (s.isCookingRecipe ? "cooking" : "crafting")); + string message = Game1.content.LoadString("Strings\\UI:LevelUp_NewRecipe", cookingOrCrafting, s.DisplayName); + + newCraftingRecipe += $"{message}, "; + } + } + + if (__instance.okButton.containsPoint(x, y)) + { + if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) + __instance.okButtonClicked(); + + toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; + } + + if (toSpeak != "") + MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); + else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") + { + MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); + currentLevelUpTitle = $"{___title}. Select a new profession."; + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + + internal static void Cleanup() + { + currentLevelUpTitle = ""; + } + } +} diff --git a/stardew-access/Patches/MenuPatches.cs b/stardew-access/Patches/MenuPatches.cs deleted file mode 100644 index 6e343cd..0000000 --- a/stardew-access/Patches/MenuPatches.cs +++ /dev/null @@ -1,226 +0,0 @@ -using Microsoft.Xna.Framework; -using stardew_access.Features; -using StardewModdingAPI; -using StardewValley; -using StardewValley.Buildings; -using StardewValley.Menus; - -namespace stardew_access.Patches -{ - internal class MenuPatches - { - internal static string currentLevelUpTitle = " "; - internal static bool firstTimeInNamingMenu = true; - internal static int prevSlotIndex = -999; - - - - - internal static void TitleTextInputMenuPatch(TitleTextInputMenu __instance) - { - try - { - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - - if (__instance.pasteButton != null && __instance.pasteButton.containsPoint(x, y)) - toSpeak = $"Paste button"; - - if (toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (System.Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void NamingMenuPatch(NamingMenu __instance, TextBox ___textBox, string ___title) - { - try - { - if (firstTimeInNamingMenu) - { - firstTimeInNamingMenu = false; - ___textBox.Selected = false; - } - - if (TextBoxPatch.isAnyTextBoxActive) return; - - string toSpeak = ""; - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position - bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box - - if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) - toSpeak = $"{___title} text box"; - else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) - toSpeak = $"Done naming button"; - else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) - toSpeak = $"Random button"; - - if (toSpeak != "") - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void ConfirmationDialogPatch(ConfirmationDialog __instance, string ___message) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string toSpeak = ___message; - - if (__instance.okButton.containsPoint(x, y)) - { - toSpeak += "\n\tOk Button"; - } - else if (__instance.cancelButton.containsPoint(x, y)) - { - toSpeak += "\n\tCancel Button"; - } - - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void LevelUpMenuPatch(LevelUpMenu __instance, List ___professionsToChoose, List ___leftProfessionDescription, List ___rightProfessionDescription, List ___extraInfoForLevel, List ___newCraftingRecipes, string ___title, bool ___isActive, bool ___isProfessionChooser) - { - try - { - int x = Game1.getMouseX(true), y = Game1.getMouseY(true); - string leftProfession = " ", rightProfession = " ", extraInfo = " ", newCraftingRecipe = " ", toSpeak = " "; - - if (!__instance.informationUp) - { - return; - } - if (__instance.isProfessionChooser) - { - if (___professionsToChoose.Count() == 0) - { - return; - } - for (int j = 0; j < ___leftProfessionDescription.Count; j++) - { - leftProfession += ___leftProfessionDescription[j] + ", "; - } - for (int i = 0; i < ___rightProfessionDescription.Count; i++) - { - rightProfession += ___rightProfessionDescription[i] + ", "; - } - - if (__instance.leftProfession.containsPoint(x, y)) - { - if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) - { - Game1.player.professions.Add(___professionsToChoose[0]); - __instance.getImmediateProfessionPerk(___professionsToChoose[0]); - ___isActive = false; - __instance.informationUp = false; - ___isProfessionChooser = false; - __instance.RemoveLevelFromLevelList(); - __instance.exitThisMenu(); - return; - } - - toSpeak = $"Selected: {leftProfession} Left click to choose."; - } - - if (__instance.rightProfession.containsPoint(x, y)) - { - if ((MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) && __instance.readyToClose()) - { - Game1.player.professions.Add(___professionsToChoose[1]); - __instance.getImmediateProfessionPerk(___professionsToChoose[1]); - ___isActive = false; - __instance.informationUp = false; - ___isProfessionChooser = false; - __instance.RemoveLevelFromLevelList(); - __instance.exitThisMenu(); - return; - } - - toSpeak = $"Selected: {rightProfession} Left click to choose."; - } - } - else - { - foreach (string s2 in ___extraInfoForLevel) - { - extraInfo += s2 + ", "; - } - foreach (CraftingRecipe s in ___newCraftingRecipes) - { - string cookingOrCrafting = Game1.content.LoadString("Strings\\UI:LearnedRecipe_" + (s.isCookingRecipe ? "cooking" : "crafting")); - string message = Game1.content.LoadString("Strings\\UI:LevelUp_NewRecipe", cookingOrCrafting, s.DisplayName); - - newCraftingRecipe += $"{message}, "; - } - } - - if (__instance.okButton.containsPoint(x, y)) - { - if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) - __instance.okButtonClicked(); - - toSpeak = $"{___title} {extraInfo} {newCraftingRecipe}. Left click to close."; - } - - if (toSpeak != " ") - MainClass.ScreenReader.SayWithMenuChecker(toSpeak, true); - else if (__instance.isProfessionChooser && currentLevelUpTitle != $"{___title}. Select a new profession.") - { - MainClass.ScreenReader.SayWithMenuChecker($"{___title}. Select a new profession.", true); - currentLevelUpTitle = $"{___title}. Select a new profession."; - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - - internal static void ShippingMenuPatch(ShippingMenu __instance, List ___categoryTotals) - { - try - { - - if (__instance.currentPage == -1) - { - int total = ___categoryTotals[5]; - string toSpeak; - if (__instance.okButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - // Perform Left Click - if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) - { - Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); - } - toSpeak = $"{total}g in total. Press left mouse button to save."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - for (int i = 0; i < __instance.categories.Count; i++) - { - if (__instance.categories[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) - { - toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; - MainClass.ScreenReader.SayWithChecker(toSpeak, true); - } - } - } - } - catch (Exception e) - { - MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); - } - } - } -} diff --git a/stardew-access/Patches/NamingMenuPatch.cs b/stardew-access/Patches/NamingMenuPatch.cs new file mode 100644 index 0000000..06e8f0e --- /dev/null +++ b/stardew-access/Patches/NamingMenuPatch.cs @@ -0,0 +1,42 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class NamingMenuPatch + { + internal static bool firstTimeInNamingMenu = true; + + internal static void DrawPatch(NamingMenu __instance, TextBox ___textBox, string ___title) + { + try + { + if (firstTimeInNamingMenu) + { + firstTimeInNamingMenu = false; + ___textBox.Selected = false; + } + + if (TextBoxPatch.isAnyTextBoxActive) return; + + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + bool isEscPressed = Game1.input.GetKeyboardState().IsKeyDown(Microsoft.Xna.Framework.Input.Keys.Escape); // For escaping/unselecting from the animal name text box + + if (__instance.textBoxCC != null && __instance.textBoxCC.containsPoint(x, y)) + toSpeak = $"{___title} text box"; + else if (__instance.doneNamingButton != null && __instance.doneNamingButton.containsPoint(x, y)) + toSpeak = $"Done naming button"; + else if (__instance.randomButton != null && __instance.randomButton.containsPoint(x, y)) + toSpeak = $"Random button"; + + if (toSpeak != "") + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/ShippingMenuPatch.cs b/stardew-access/Patches/ShippingMenuPatch.cs new file mode 100644 index 0000000..692d9ee --- /dev/null +++ b/stardew-access/Patches/ShippingMenuPatch.cs @@ -0,0 +1,46 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class ShippingMenuPatch + { + internal static int prevSlotIndex = -999; + + internal static void DrawPatch(ShippingMenu __instance, List ___categoryTotals) + { + try + { + + if (__instance.currentPage == -1) + { + int total = ___categoryTotals[5]; + string toSpeak; + if (__instance.okButton.containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + // Perform Left Click + if (MainClass.Config.LeftClickMainKey.JustPressed() || MainClass.Config.LeftClickAlternateKey.JustPressed()) + { + Game1.activeClickableMenu.receiveLeftClick(Game1.getMouseX(true), Game1.getMouseY(true)); + } + toSpeak = $"{total}g in total. Press left mouse button to save."; + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + + for (int i = 0; i < __instance.categories.Count; i++) + { + if (__instance.categories[i].containsPoint(Game1.getMouseX(true), Game1.getMouseY(true))) + { + toSpeak = $"Money recieved from {__instance.getCategoryName(i)}: {___categoryTotals[i]}g."; + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + } + } + } + catch (Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} diff --git a/stardew-access/Patches/TitleTextInputMenuPatch.cs b/stardew-access/Patches/TitleTextInputMenuPatch.cs new file mode 100644 index 0000000..2ed19ac --- /dev/null +++ b/stardew-access/Patches/TitleTextInputMenuPatch.cs @@ -0,0 +1,27 @@ +using StardewValley; +using StardewValley.Menus; + +namespace stardew_access.Patches +{ + internal class TitleTextInputMenuPatch + { + internal static void DrawPatch(TitleTextInputMenu __instance) + { + try + { + string toSpeak = ""; + int x = Game1.getMouseX(true), y = Game1.getMouseY(true); // Mouse x and y position + + if (__instance.pasteButton != null && __instance.pasteButton.containsPoint(x, y)) + toSpeak = $"Paste button"; + + if (toSpeak != "") + MainClass.ScreenReader.SayWithChecker(toSpeak, true); + } + catch (System.Exception e) + { + MainClass.ErrorLog($"Unable to narrate Text:\n{e.Message}\n{e.StackTrace}"); + } + } + } +} From 2b6b60494e1bc42c14a6972caf77fdc16e7e3ef0 Mon Sep 17 00:00:00 2001 From: Mohammad Shoaib Khan Date: Fri, 10 Mar 2023 15:33:39 +0530 Subject: [PATCH 61/61] Grouped files --- stardew-access/HarmonyPatches.cs | 2 +- .../Patches/{ => MenuWithInventoryPatches}/ForgeMenuPatch.cs | 0 .../Patches/{ => MenuWithInventoryPatches}/GeodeMenuPatch.cs | 0 .../Patches/{ => MenuWithInventoryPatches}/ItemGrabMenuPatch.cs | 0 .../Patches/{ => MenuWithInventoryPatches}/ShopMenuPatch.cs | 0 .../{ => MenuWithInventoryPatches}/TailoringMenuPatch.cs | 0 .../Patches/{ChatMenuPatch.cs => MiscPatches/ChatBoxPatch.cs} | 2 +- stardew-access/Patches/{ => MiscPatches}/DialogueBoxPatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/Game1Patch.cs | 0 stardew-access/Patches/{ => MiscPatches}/IClickableMenuPatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/InstanceGamePatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/NPCPatch.cs | 0 stardew-access/Patches/{ => MiscPatches}/TextBoxPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/AnimalQueryMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/CarpenterMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/ChooseFromListMenuPatch.cs | 0 .../{ => OtherMenuPatches}/ConfirmationDialogMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/ItemListMenuPatch.cs | 0 .../{ => OtherMenuPatches}/LanguageSelectionMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/LetterViewerMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/LevelUpMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/MineElevatorMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/NamingMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/PondQuerMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/PurchaseAnimalsMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/ShippingMenuPatch.cs | 0 .../Patches/{ => OtherMenuPatches}/TitleTextInputMenuPatch.cs | 0 27 files changed, 2 insertions(+), 2 deletions(-) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/ForgeMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/GeodeMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/ItemGrabMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/ShopMenuPatch.cs (100%) rename stardew-access/Patches/{ => MenuWithInventoryPatches}/TailoringMenuPatch.cs (100%) rename stardew-access/Patches/{ChatMenuPatch.cs => MiscPatches/ChatBoxPatch.cs} (98%) rename stardew-access/Patches/{ => MiscPatches}/DialogueBoxPatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/Game1Patch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/IClickableMenuPatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/InstanceGamePatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/NPCPatch.cs (100%) rename stardew-access/Patches/{ => MiscPatches}/TextBoxPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/AnimalQueryMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/CarpenterMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ChooseFromListMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ConfirmationDialogMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ItemListMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/LanguageSelectionMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/LetterViewerMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/LevelUpMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/MineElevatorMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/NamingMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/PondQuerMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/PurchaseAnimalsMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/ShippingMenuPatch.cs (100%) rename stardew-access/Patches/{ => OtherMenuPatches}/TitleTextInputMenuPatch.cs (100%) diff --git a/stardew-access/HarmonyPatches.cs b/stardew-access/HarmonyPatches.cs index 5171631..659cb28 100644 --- a/stardew-access/HarmonyPatches.cs +++ b/stardew-access/HarmonyPatches.cs @@ -213,7 +213,7 @@ namespace stardew_access #region Chat Menu Patches harmony.Patch( original: AccessTools.Method(typeof(ChatBox), nameof(ChatBox.update), new Type[] { typeof(GameTime) }), - postfix: new HarmonyMethod(typeof(ChatMenuPatch), nameof(ChatMenuPatch.UpdatePatch)) + postfix: new HarmonyMethod(typeof(ChatBoxPatch), nameof(ChatBoxPatch.UpdatePatch)) ); #endregion diff --git a/stardew-access/Patches/ForgeMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/ForgeMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ForgeMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/ForgeMenuPatch.cs diff --git a/stardew-access/Patches/GeodeMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/GeodeMenuPatch.cs similarity index 100% rename from stardew-access/Patches/GeodeMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/GeodeMenuPatch.cs diff --git a/stardew-access/Patches/ItemGrabMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/ItemGrabMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ItemGrabMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/ItemGrabMenuPatch.cs diff --git a/stardew-access/Patches/ShopMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/ShopMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ShopMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/ShopMenuPatch.cs diff --git a/stardew-access/Patches/TailoringMenuPatch.cs b/stardew-access/Patches/MenuWithInventoryPatches/TailoringMenuPatch.cs similarity index 100% rename from stardew-access/Patches/TailoringMenuPatch.cs rename to stardew-access/Patches/MenuWithInventoryPatches/TailoringMenuPatch.cs diff --git a/stardew-access/Patches/ChatMenuPatch.cs b/stardew-access/Patches/MiscPatches/ChatBoxPatch.cs similarity index 98% rename from stardew-access/Patches/ChatMenuPatch.cs rename to stardew-access/Patches/MiscPatches/ChatBoxPatch.cs index a0b521e..8ded908 100644 --- a/stardew-access/Patches/ChatMenuPatch.cs +++ b/stardew-access/Patches/MiscPatches/ChatBoxPatch.cs @@ -2,7 +2,7 @@ namespace stardew_access.Patches { - internal class ChatMenuPatch + internal class ChatBoxPatch { private static int currentChatMessageIndex = 0; private static bool isChatRunning = false; diff --git a/stardew-access/Patches/DialogueBoxPatch.cs b/stardew-access/Patches/MiscPatches/DialogueBoxPatch.cs similarity index 100% rename from stardew-access/Patches/DialogueBoxPatch.cs rename to stardew-access/Patches/MiscPatches/DialogueBoxPatch.cs diff --git a/stardew-access/Patches/Game1Patch.cs b/stardew-access/Patches/MiscPatches/Game1Patch.cs similarity index 100% rename from stardew-access/Patches/Game1Patch.cs rename to stardew-access/Patches/MiscPatches/Game1Patch.cs diff --git a/stardew-access/Patches/IClickableMenuPatch.cs b/stardew-access/Patches/MiscPatches/IClickableMenuPatch.cs similarity index 100% rename from stardew-access/Patches/IClickableMenuPatch.cs rename to stardew-access/Patches/MiscPatches/IClickableMenuPatch.cs diff --git a/stardew-access/Patches/InstanceGamePatch.cs b/stardew-access/Patches/MiscPatches/InstanceGamePatch.cs similarity index 100% rename from stardew-access/Patches/InstanceGamePatch.cs rename to stardew-access/Patches/MiscPatches/InstanceGamePatch.cs diff --git a/stardew-access/Patches/NPCPatch.cs b/stardew-access/Patches/MiscPatches/NPCPatch.cs similarity index 100% rename from stardew-access/Patches/NPCPatch.cs rename to stardew-access/Patches/MiscPatches/NPCPatch.cs diff --git a/stardew-access/Patches/TextBoxPatch.cs b/stardew-access/Patches/MiscPatches/TextBoxPatch.cs similarity index 100% rename from stardew-access/Patches/TextBoxPatch.cs rename to stardew-access/Patches/MiscPatches/TextBoxPatch.cs diff --git a/stardew-access/Patches/AnimalQueryMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs similarity index 100% rename from stardew-access/Patches/AnimalQueryMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/AnimalQueryMenuPatch.cs diff --git a/stardew-access/Patches/CarpenterMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/CarpenterMenuPatch.cs similarity index 100% rename from stardew-access/Patches/CarpenterMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/CarpenterMenuPatch.cs diff --git a/stardew-access/Patches/ChooseFromListMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ChooseFromListMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ChooseFromListMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ChooseFromListMenuPatch.cs diff --git a/stardew-access/Patches/ConfirmationDialogMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ConfirmationDialogMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ConfirmationDialogMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ConfirmationDialogMenuPatch.cs diff --git a/stardew-access/Patches/ItemListMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ItemListMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ItemListMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ItemListMenuPatch.cs diff --git a/stardew-access/Patches/LanguageSelectionMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/LanguageSelectionMenuPatch.cs similarity index 100% rename from stardew-access/Patches/LanguageSelectionMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/LanguageSelectionMenuPatch.cs diff --git a/stardew-access/Patches/LetterViewerMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/LetterViewerMenuPatch.cs similarity index 100% rename from stardew-access/Patches/LetterViewerMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/LetterViewerMenuPatch.cs diff --git a/stardew-access/Patches/LevelUpMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/LevelUpMenuPatch.cs similarity index 100% rename from stardew-access/Patches/LevelUpMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/LevelUpMenuPatch.cs diff --git a/stardew-access/Patches/MineElevatorMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/MineElevatorMenuPatch.cs similarity index 100% rename from stardew-access/Patches/MineElevatorMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/MineElevatorMenuPatch.cs diff --git a/stardew-access/Patches/NamingMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/NamingMenuPatch.cs similarity index 100% rename from stardew-access/Patches/NamingMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/NamingMenuPatch.cs diff --git a/stardew-access/Patches/PondQuerMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/PondQuerMenuPatch.cs similarity index 100% rename from stardew-access/Patches/PondQuerMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/PondQuerMenuPatch.cs diff --git a/stardew-access/Patches/PurchaseAnimalsMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/PurchaseAnimalsMenuPatch.cs similarity index 100% rename from stardew-access/Patches/PurchaseAnimalsMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/PurchaseAnimalsMenuPatch.cs diff --git a/stardew-access/Patches/ShippingMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/ShippingMenuPatch.cs similarity index 100% rename from stardew-access/Patches/ShippingMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/ShippingMenuPatch.cs diff --git a/stardew-access/Patches/TitleTextInputMenuPatch.cs b/stardew-access/Patches/OtherMenuPatches/TitleTextInputMenuPatch.cs similarity index 100% rename from stardew-access/Patches/TitleTextInputMenuPatch.cs rename to stardew-access/Patches/OtherMenuPatches/TitleTextInputMenuPatch.cs