找回密码
 注册用户
查看: 184|回复: 0

[RMMZ] 【汉化】Sigureya存档界面

[复制链接]

88

主题

7

回帖

1277

积分

资深会员

积分
1277
发表于 2024-5-31 13:02:26 | 显示全部楼层 |阅读模式
本帖最后由 烁灵 于 2024-5-31 18:24 编辑

在存档界面显示额外的内容

・游戏时间
・地图名(显示名称)
・地图名(编辑名称)
・存档时间
・变量值
・最后一次显示文章内容
・图片


原地址:Sigureya/RPGmakerMZ: RPGmakerMZ plugins (github.com)

预览:
QQ截图20240531125534.png


范例:https://www.123pan.com/s/uBKyVv-YzF3A.html 提取码:9Nst

脚本:
  1. //@ts-check

  2. //=============================================================================
  3. // Mano_SaveFileInfo.js
  4. // ----------------------------------------------------------------------------
  5. // Copyright (c) 2022-2022 Sigureya
  6. // This software is released under the MIT License.
  7. // http://opensource.org/licenses/mit-license.php
  8. // ----------------------------------------------------------------------------
  9. // Version
  10. // 1.0.0 2022/04/14 初版
  11. // ----------------------------------------------------------------------------
  12. // [Twitter]: https://twitter.com/Sigureya/
  13. //=============================================================================

  14. /*:
  15. * @plugindesc 在存档界面显示额外的内容。
  16. * 汉化 by 烁灵 更多脚本请访问 www.hknmtt.com
  17. * @author しぐれん
  18. *
  19. * @target MZ
  20. * @orderAfter NUUN_SaveScreen
  21. * @orderAfter AltSaveScreen
  22. *
  23. * @command SetText
  24. * @desc 指定变量保存文本,支持换行符 \n
  25. * @arg variableId
  26. * @text 变量ID
  27. * @type variable
  28. * @default 0
  29. *
  30. * @arg text
  31. * @text 显示的文本
  32. * @type multiline_string
  33. *
  34. * @param listWindow
  35. * @text 文件列表窗口设置
  36. * @type struct<Rect>
  37. * @default {"x":"270","y":"112","width":"616","height":"340"}
  38. *
  39. * @param numVisibleRows
  40. * @text 行数
  41. * @desc 如果用其他脚本指定存档文件数量,请填 99
  42. * @type number
  43. * @min 1
  44. * @default 3
  45. *
  46. * @param maxCols
  47. * @text 列数
  48. * @type number
  49. * @min 1
  50. * @default 2
  51. *
  52. * @param leftWindow
  53. * @text 左侧窗口设置
  54. * @type struct<Rect>
  55. * @default {"x":"0","y":"112","width":"270","height":"340"}
  56. *
  57. * @param leftSpriteList
  58. * @text 左侧图片设置
  59. * @type struct<SpriteV2>[]
  60. * @parent leftWindow
  61. * @default ["{"table":"[]","variableId":"1","bitmap":"","x":"0","y":"0","width":"200","height":"200","anthorX":"0","anthorY":"0","isUpper":"false"}"]
  62. *
  63. * @param leftTextList
  64. * @text 左侧文字设置
  65. * @type struct<TextFormat>[]
  66. * @parent leftWindow
  67. * @default ["{"symbol":"variable","variableId":"1","nameFormat":"立绘变量:","valueFormat":"%1","valueColor":"","indentLevel":"32","numLines":"1"}","{"symbol":"playtime","variableId":"0","nameFormat":"游戏时间","valueFormat":"%1","valueColor":"","indentLevel":"0","numLines":"1"}","{"symbol":"timestamp","variableId":"0","nameFormat":"%1","valueFormat":"","valueColor":"","indentLevel":"0","numLines":"1"}","{"symbol":"mapname","variableId":"0","nameFormat":"","valueFormat":"%1","valueColor":"","indentLevel":"0","numLines":"1"}","{"symbol":"mapinfo","variableId":"0","nameFormat":"","valueFormat":"%1","valueColor":"","indentLevel":"0","numLines":"1"}"]
  68. *
  69. * @param leftTextPosition
  70. * @text 左侧文字窗口配置
  71. * @parent leftWindow
  72. * @type struct<Rect>
  73. * @default {"x":"0","y":"140","width":"270","height":"340"}
  74. *
  75. * @param bottomWindow
  76. * @type struct<Rect>
  77. * @default {"x":"0","y":"452","width":"808","height":"180"}
  78. *
  79. * @param bottomSpriteList
  80. * @text 下方图像列表配置
  81. * @type struct<SpriteV2>[]
  82. * @parent bottomWindow
  83. * @default []
  84. *
  85. * @param bottomTextList
  86. * @text 下方文字列表配置
  87. * @type struct<TextFormat>[]
  88. * @parent bottomWindow
  89. * @default ["{"symbol":"lastmsg","variableId":"0","nameFormat":"%1","valueFormat":"","valueColor":"","indentLevel":"0","numLines":"4"}"]
  90. *
  91. * @param bottomTextPosition
  92. * @text 下方文字位置
  93. * @parent bottomWindow
  94. * @type struct<Rect>
  95. * @default {"x":"0","y":"0","width":"808","height":"130"}
  96. *
  97. * @param lastMessageSwitch
  98. * @text 最后一次显示文章记录
  99. * @desc 为 ON 的时候会自动记录最后一次显示文章的内容。游戏开始时会设置为 ON
  100. * @type switch
  101. * @default 0
  102. *
  103. * @help
  104. * 启用插件后需要保存一次
  105. * 插件无效的情况下不会引起错误。
  106. *
  107. * 在两个位置添加一个信息窗口,一个在文件列表的左侧,一个在底部。。
  108. * 以下信息可以显示在信息窗口中
  109. * 这些设置是在插件参数中进行。
  110. * ・游戏时间
  111. * ・地图名(显示名称)
  112. * ・地图名(编辑名称)
  113. * ・存档时间
  114. * ・变量值
  115. * ・最后一次显示文章内容
  116. * ・图片
  117. *
  118. * ■与其他插件的关系
  119. * ・NUUN_SaveScreen
  120. * 可以同时使用。
  121. *
  122. * ■AltSaveScreen
  123. * 由于都修改了存档布局,不能同时使用
  124. * 可通过技术自行解决
  125. *
  126. * ■利用規約
  127. * MIT Licenseです。
  128. * ご自由にお使いください。
  129. */
  130. /*~struct~Rect:
  131. * @param x
  132. * @type number
  133. * @default 0
  134. *
  135. * @param y
  136. * @type number
  137. * @default 0
  138. *
  139. * @param width
  140. * @text 宽度
  141. * @type number
  142. * @default 200
  143. *
  144. * @param height
  145. * @text 高度
  146. * @type number
  147. * @default 200
  148. */
  149. /*~struct~ActorImage:
  150. * @param dataType
  151. * @type select
  152. * @param memberIndex
  153. * @type number
  154. * @default 0
  155. */
  156. /*~struct~TextTableItem:
  157.   * @param value
  158.   * @type number
  159.   * @default 1
  160.   *
  161.   * @param item
  162.   * @type multiline_string
  163.   * @text 显示的文章
  164.   * @desc 不能使用控制字符。
  165.   *
  166. */

  167. /*~struct~TextV2:
  168. * @param table
  169. * @text 文本列表
  170. * @desc 使用指定变量的值
  171. * 从这个类型中取图片
  172. * @type struct<TextTableItem>[]
  173. * @default []
  174. *
  175. * @param variableid
  176. * @text 变量ID
  177. * @type variable
  178. * @desc 根据变量的值切换图片
  179. * @default 0
  180. *
  181. * @param numLines
  182. * @type number
  183. * @default 1
  184. * @min 1
  185. */
  186. /*~struct~TextFormat:
  187. * @param symbol
  188. * @text 显示的文本种类
  189. * @type select
  190. * @option 无
  191. * @value
  192. * @option 游戏时间
  193. * @value playtime
  194. * @option 地图名称(显示名称)
  195. * @value mapname
  196. * @option 地图名称(编辑名称)
  197. * @value mapinfo
  198. * @option 存档时间
  199. * @value timestamp
  200. * @option 变量值
  201. * @value variable
  202. * @option 最后的显示文章
  203. * @value lastmsg
  204. * @default
  205. *
  206. * @param variableId
  207. * @text 变量ID
  208. * @type variable
  209. * @desc 显示的文字种类
  210. * 变量指定的场合使用的变量ID
  211. * @default 0
  212. *
  213. * @param nameFormat
  214. * @text 左侧项目显示格式
  215. * @desc 使用 %1 来取得指定的参数。
  216. * 可以使用控制字符
  217. * @type string
  218. * @default 项目
  219. *
  220. * @param valueFormat
  221. * @text 右侧项目显示格式
  222. * @desc 使用 %1 来取得指定的参数。
  223. * 不可以使用控制字符,换行无效
  224. * @type string
  225. * @default %1
  226. *
  227. * @param valueColor
  228. * @text 右侧文字颜色
  229. * @type string
  230. * @desd 使用 #FF00FF 这种格式
  231. * @default
  232. *
  233. * @param indentLevel
  234. * @text 向右缩进
  235. * @desc 向右缩进
  236. * 可能会与右侧文字重叠。
  237. * @type number
  238. * @default 0
  239. *
  240. * @param numLines
  241. * @text 行数
  242. * @desc 指定显示行数
  243. * 用于防止与图像重叠
  244. * @type number
  245. * @default 1
  246. *
  247. */

  248. /*~struct~SpriteTableItem:
  249.   * @param value
  250.   * @text 对应数值
  251.   * @desc 指定变量与此值相同时显示图像
  252.   * @type number
  253.   * @default 1
  254.   *
  255.   * @param item
  256.   * @text 图片
  257.   * @type file
  258.   * @dir img/pictures/
  259.   * @desc 指定的图像将按比例缩小以适合窗体。
  260.   *
  261. */

  262. /*~struct~SpriteV2:
  263. * @param table
  264. * @text 图片列表
  265. * @desc 使用指定变量的值取得图像
  266. * @type struct<SpriteTableItem>[]
  267. * @default []
  268. *
  269. * @param variableId
  270. * @text 变量ID
  271. * @type variable
  272. * @desc 根据变量的值取图片
  273. * @default 0
  274. *
  275. * @param bitmap
  276. * @desc 如果找不到,则要显示的图片
  277. * @type file
  278. * @dir img/picutures/
  279. *
  280. * @param x
  281. * @type number
  282. * @default 0
  283. *
  284. * @param y
  285. * @type number
  286. * @default 0
  287. *
  288. * @param width
  289. * @text 宽度
  290. * @desc 图片大于此值时将会缩小
  291. * @type number
  292. * @default 200
  293. *
  294. * @param height
  295. * @text 高度
  296. * @desc 图片大于此值时将会缩小
  297. * @type number
  298. * @default 200
  299. *
  300. * @param anthorX
  301. * @text 图像中心X坐标
  302. * @desc 0:左侧边・0.5:中心・1:右侧边
  303. * @type number
  304. * @default 0
  305. * @min -1
  306. * @max 1
  307. * @decimals 2
  308. *
  309. * @param anthorY
  310. * @text 图像中心Y坐标
  311. * @desc 0:上边・0.5:中心・1:下边
  312. * @type number
  313. * @default 0
  314. * @min -1
  315. * @max 1
  316. * @decimals 2
  317. *
  318. * @param isUpper
  319. * @type boolean
  320. * @on 文字上放
  321. * @off 文字下方
  322. * @default false
  323. */

  324. /*~struct~Sprite:
  325. * @param symbol
  326. * @type select
  327. * @option 战斗图
  328. * @value BattlerImage
  329. * @default BattlerImage
  330. * @text 【标识】
  331. * @desc 图像种类
  332. *
  333. * @param bitmap
  334. * @desc 找不到的场合使用的图片
  335. * @type file
  336. * @dir img/
  337. *
  338. * @param x
  339. * @type number
  340. * @default 0
  341. *
  342. * @param y
  343. * @type number
  344. * @default 0
  345. *
  346. * @param width
  347. * @text 宽度
  348. * @desc 图片大于此值时将会缩小
  349. * @type number
  350. * @default 200
  351. *
  352. * @param height
  353. * @text 高度
  354. * @desc 图片大于此值时将会缩小
  355. * @type number
  356. * @default 200
  357. *
  358. * @param anthorX
  359. * @text 图像中心X坐标
  360. * @desc 0:左侧边・0.5:中心・1:右侧边
  361. * @type number
  362. * @default 0
  363. * @min -1
  364. * @max 1
  365. * @decimals 2
  366. *
  367. * @param anthorY
  368. * @text 图像中心Y坐标
  369. * @desc 0:上边・0.5:中心・1:下边
  370. * @type number
  371. * @default 0
  372. * @min -1
  373. * @max 1
  374. * @decimals 2
  375. *
  376. * @param isUpper
  377. * @type boolean
  378. * @on 文字上放
  379. * @off 文字下方
  380. * @default false
  381. */



  382. (function(){
  383.     'use strict';
  384. /**
  385. * @param {string} objText
  386. */
  387. function parseRect(objText){
  388.     const obj = JSON.parse(objText);
  389.     return new Rectangle(
  390.         Number(obj.x),Number(obj.y),Number(obj.width),Number(obj.height)
  391.     );
  392. }
  393. /**
  394. * @typedef {PIXI.Rectangle} RectangleP
  395. */

  396. /**
  397. * @type {String}
  398. */
  399. const  PLUGIN_NAME= ('Mano_SaveFileInfo');
  400. function getParam(){ return PluginManager.parameters(PLUGIN_NAME);  }


  401. /**
  402. * @typedef {Object} SaveFileInfo
  403. * @property {string} playtime
  404. * @property {Number} timestamp
  405. * @property {string} title
  406. * @property {Array<[string,Number]>} faces
  407. * @property {Array<[string,Number]>} characters
  408. * @property {Record< string,(string|number)>} [uzssrecord=null]
  409. */

  410. //専用のレコードへ保存するためのやつ
  411. class KVP_Base{
  412.     /**
  413.      *
  414.      * @returns {string}
  415.      */
  416.     key(){
  417.         return null;
  418.     }
  419.     /**
  420.      *
  421.      * @returns {string|number}
  422.      */
  423.     value(){
  424.         return 0;
  425.     }
  426.     /**
  427.      * @param {SaveFileInfo} info
  428.      */
  429.     read(info){
  430.         if(info.uzssrecord){
  431.             const key =this.key();
  432.             if(key){
  433.                 return info.uzssrecord[key];
  434.             }
  435.         }
  436.         return null;
  437.     }
  438.     /**
  439.      * @param {SaveFileInfo} info
  440.      */
  441.      readToText(info){
  442.         const t= this.read(info);
  443.         if(t){
  444.             return String(t);
  445.         }
  446.         return "";
  447.     }
  448. }
  449. class RecordTemporay{
  450.     constructor(){
  451.         /**
  452.          * @type {Record<(string),(Number|string)>}
  453.          */
  454.         this._record={};
  455.     }
  456.     /**
  457.      * @param {KVP_Base} kvp
  458.      */
  459.     writeV2(kvp){
  460.         const key = kvp.key();
  461.         //キーが有効なら書き込み
  462.         if(key){
  463.             const value =kvp.value();
  464.             this._record[key] =value;
  465.         }
  466.     }
  467.     get(){
  468.         return this._record;
  469.     }
  470. }

  471. class KVP_Variable extends KVP_Base{
  472.     /**
  473.      * @param {number} variableId
  474.      */
  475.     constructor(variableId){
  476.         super();
  477.         this._variableId =variableId;
  478.     }
  479.     value(){
  480.         return $gameVariables.value(this._variableId);
  481.     }
  482.     key(){
  483.         return `V${this._variableId}`;
  484.     }
  485. }
  486. class KVP_Mapname extends KVP_Base{
  487.     key(){
  488.         return "mapname";
  489.     }
  490.     value(){        
  491.         return $gameMap.displayName();
  492.     }
  493. }
  494. class KVP_Mapinfo extends KVP_Base{
  495.     key(){
  496.         return "mapinfo";
  497.     }
  498.     value(){
  499.         const mapId = $gameMap.mapId();
  500.         const mapInfo =$dataMapInfos[mapId];
  501.         if(mapInfo){
  502.             return mapInfo.name;
  503.         }
  504.         return "";
  505.     }
  506. }
  507. class KVP_Playtime extends KVP_Base{
  508.     /**
  509.      * @param {SaveFileInfo} info
  510.      */
  511.     read(info){
  512.         return info.playtime;
  513.     }
  514. }

  515. class KVP_Timestamp extends KVP_Base{

  516.     /**
  517.      * @param {SaveFileInfo} info
  518.      */
  519.     read(info){
  520.         const d= new Date(info.timestamp);
  521.         return `${d.toLocaleDateString()} ${d.toLocaleTimeString()} `
  522.     }
  523. }
  524. class KVP_LastMessage extends KVP_Base{
  525.     key(){
  526.         return "lastmsg";
  527.     }
  528.     value(){
  529.         return SavaDataManager_V2.getLastMessage();
  530.     }
  531. }

  532. class TextItemDictionary_T{
  533.     constructor(){
  534.         /**
  535.          * @type {Map<string,KVP_Base>}
  536.          */
  537.         this._table=new Map();
  538.         this._table.set("timestamp",new KVP_Timestamp());
  539.         this._table.set("mapname",new KVP_Mapname());
  540.         this._table.set("playtime",new KVP_Playtime());
  541.         this._table.set("mapinfo",new KVP_Mapinfo());
  542.         this._table.set("lastmsg",new KVP_LastMessage());
  543.     }
  544.     /**
  545.      * @private
  546.      * @param {string} symbol
  547.      * @param {number} variableId
  548.      */
  549.     createKVP(symbol,variableId){
  550.         if(symbol ==="variable"){
  551.             return new KVP_Variable(variableId);
  552.         }
  553.         const t = this._table.get(symbol);
  554.         if(t){
  555.             return t;
  556.         }
  557.         return null;
  558.     }
  559.     /**
  560.      *
  561.      * @param {string} text
  562.      */
  563.     createByText(text){
  564.         const obj =JSON.parse(text);
  565.         const param =(
  566.             {
  567.                 indentLevel:Number(obj.indentLevel||0),
  568.                 valueColor:String(obj.valueColor),
  569.                 valueFormat:String(obj.valueFormat),
  570.                 symbol:String(obj.symbol),
  571.                 nameFormat:String(obj.nameFormat),
  572.                 numLines:Number(obj.numLines||1),
  573.             }
  574.         );
  575.         const vid =Number(obj.variableId);
  576.         const kvp = this.createKVP(param.symbol,vid);
  577.         return new TextContents(kvp,param);
  578.     }
  579. }
  580. const TextItemDictionary=( ()=>{   
  581.     return new TextItemDictionary_T();
  582. })();

  583. class I_BitmapSelector{
  584.     /**
  585.      * @returns {Bitmap}
  586.      * @param {SaveFileInfo} info
  587.      */
  588.     getBitmap(info){
  589.         return null;
  590.     }
  591.     /**
  592.      * @returns {KVP_Base}
  593.      */
  594.     kvp(){
  595.         return null;
  596.     }
  597. }
  598. class KVPXXX_BitmapTable extends I_BitmapSelector{
  599.     /**
  600.      * @param {number} variableId
  601.      * @param { Map<number,string> } table
  602.      */
  603.     constructor(variableId,table){
  604.         super();
  605.         this._kvp = new KVP_Variable(variableId);
  606.         this._table=table;
  607.     }
  608.     kvp(){
  609.         return this._kvp;
  610.     }
  611.     /**
  612.      * @param {SaveFileInfo} info
  613.      */
  614.     getBitmap(info){
  615.         const value = Number( this._kvp.read(info));
  616.         if(!isNaN(value)){
  617.             const filename = this._table.get(value);
  618.             if(filename){
  619.                 return ImageManager.loadPicture(filename);
  620.             }
  621.         }
  622.         return null;
  623.     }
  624. }
  625. /**
  626. * @typedef {Object} TextParamator
  627. * @property {String} symbol
  628. * @property {Number} indentLevel
  629. * @property {String} valueFormat
  630. * @property {String} nameFormat
  631. * @property {String} valueColor
  632. * @property {number} numLines
  633. */
  634. class TextContents{
  635.     /**
  636.      * @param {KVP_Base} kvp
  637.      * @param {TextParamator} param
  638.      */
  639.     constructor(kvp,param){
  640.         this._kvp =kvp;
  641.         this._param =param;
  642.     }
  643.     kvp(){
  644.         return this._kvp;
  645.     }

  646.     /**
  647.      * @param {SaveFileInfo} data
  648.      */
  649.      kvpText(data){
  650.         if(data){
  651.             if(this._kvp){
  652.                 return [this._kvp.readToText(data)]
  653.             }
  654.         }
  655.         return null;
  656.     }
  657.     /**
  658.      * @param {SaveFileInfo} data
  659.      */
  660.     getTextXXX(data){
  661.         const textArray = this.kvpText(data);
  662.         return {
  663.             left:this.createParamText(this._param.nameFormat,textArray),
  664.             right :this.createParamText(this._param.valueFormat,textArray),
  665.         }
  666.     }
  667.     /**
  668.      * @param {String} format
  669.      * @param {String[]|null} param
  670.      */
  671.     createParamText(format,param){
  672.         const reg =/%([0-9]+)/g;
  673.         return format.replace(reg,(s,n)=>{
  674.             if(!param){
  675.                 return "";
  676.             }
  677.             const text = param[Number(n)-1];
  678.             return text ||"";
  679.         });
  680.     }
  681.     indentLevel(){
  682.         return this._param.indentLevel;
  683.     }
  684.     valueTextColor(){
  685.         return this._param.valueColor;
  686.     }
  687.     numLines(){
  688.         return this._param.numLines;
  689.     }
  690. }
  691. /**
  692. * @typedef {Object} AreaObject
  693. * @property {RectangleP} rect
  694. * @property {TextContents[]} textList
  695. */

  696. // class FaceBitmapSelector extends I_BitmapSelector{
  697. //     /**
  698. //      * @param {Number} index
  699. //      */
  700. //     constructor(index){
  701. //         super();
  702. //         this._index=index;
  703. //     }
  704. //     /**
  705. //      * @param {SaveFileInfo} info
  706. //      */
  707. //     getBitmap(info){
  708. //         const face=(info.faces[this._index]);
  709. //         if(face){
  710. //             return ImageManager.loadFace(face[0]);
  711. //         }
  712. //         return null;
  713. //     }
  714. //     /**
  715. //      * @param {SaveFileInfo} info
  716. //      */
  717. //     frameRect(info){
  718. //         const face = (info.faces[this._index]);
  719. //         if(face){
  720. //             const index = face[1];
  721. //             return this.faceRect(index);
  722. //         }
  723. //         return null;
  724. //     }
  725. //     /**
  726. //      * @param {Number} index
  727. //      */
  728. //     faceRect(index){
  729. //         const pw =ImageManager.faceWidth
  730. //         const ph =ImageManager.faceHeight;
  731. //         const sx =Math.floor((index % 4) * pw + (0) / 2);
  732. //         const sy = Math.floor(Math.floor(index / 4) * ph + (0) / 2);
  733. //         return new Rectangle(
  734. //             sx,sy,
  735. //             pw,
  736. //             ph
  737. //         );
  738. //     }
  739. // }
  740. /**
  741. * @typedef {Object} SpriteRecipe
  742. * @property {RectangleP} positionRect
  743. * @property {number} anthorX
  744. * @property {Number} anthorY
  745. * @property {boolean} isUpper
  746. */
  747. class SpriteContents{
  748.     /**
  749.      * @param {I_BitmapSelector} xxx
  750.      * @param {SpriteRecipe} recipe
  751.      */
  752.     constructor(xxx,recipe){
  753.         this._xxx =xxx;
  754.         this._recipe =recipe;
  755.     }
  756.     /**
  757.      * @returns {KVP_Base}
  758.      */
  759.     kvp(){
  760.         return this._xxx.kvp();
  761.     }
  762.     hue(data){
  763.         return 0;
  764.     }
  765.     anthorX(){
  766.         return this._recipe.anthorX;
  767.     }
  768.     anthorY(){
  769.         return this._recipe.anthorY;
  770.     }
  771.     positionRect(){
  772.         return this._recipe.positionRect.clone();
  773.     }
  774.     alpha(){
  775.         return 1;
  776.     }
  777.     /**
  778.      * @param {SaveFileInfo} info
  779.      */
  780.     getBitmap(info){
  781.         if(info){
  782.             return this._xxx.getBitmap(info);
  783.         }
  784.         return null;
  785.     }
  786.     /**
  787.      * @param {SaveFileInfo} info
  788.      */
  789.     frameRect(info){
  790.         return null;
  791.         //return this._xxx.frameRect(info);
  792.     }
  793.     isUpper(){
  794.         return this._recipe.isUpper;
  795.     }
  796. }
  797. /**
  798. * @template T_DataType
  799. * @typedef {Object} SuperView_SpriteContentsConcept
  800. * @property {()=>RectangleP} positionRect
  801. * @property {()=>number} anthorX
  802. * @property {()=>number} anthorY
  803. * @property {(data:T_DataType)=>RectangleP} frameRect
  804. * @property {(data:T_DataType)=>number} hue
  805. * @property {(data:T_DataType)=>Bitmap} getBitmap
  806. * @property {(data:T_DataType)=>number} alpha
  807. */

  808. /**
  809. * @template {SaveFileInfo} T_DataType
  810. */
  811. class Sprite_SuperView extends Sprite{
  812.     constructor(){
  813.          super();
  814.          this._data=null;
  815.          this.visible =false;
  816.          this.setContents(null);
  817.     }
  818.     clear(){
  819.         this.visible=false;
  820.         this._elment=null;
  821.     }
  822.     /**
  823.      * @param {SuperView_SpriteContentsConcept<T_DataType>} contents
  824.      */
  825.     setContents(contents){
  826.         this._elment =(contents ||null);
  827.         this.refresh();
  828.     }
  829.     updateVisible(){
  830.         //this.visible=true;
  831.         this.visible = !!this._elment;
  832.     }
  833.     updatePosition(){
  834.         if(this._elment){
  835.             const rect =this._elment.positionRect()
  836.             this.x = rect.x;
  837.             this.y = rect.y;
  838.             this.anchor.x = this._elment.anthorX();
  839.             this.anchor.y = this._elment.anthorY();
  840.         }
  841.     }
  842.     updateFrame(){
  843.         const rect = this._elment.frameRect(this._data);
  844.         if(rect){
  845.             this.setFrame(rect.x,rect.y,rect.width,rect.height);
  846.             return;
  847.         }
  848.         const orig=this.bitmap.rect;
  849.         this.setFrame(orig.x,orig.y,orig.width,orig.height);
  850.         this;
  851.     }
  852.     refresh(){
  853.         this.updateVisible();
  854.         this.loadBitmap();
  855.         this.updatePosition();
  856.         this.updateOpacity();
  857.         this.updateHue();
  858.     }
  859.     updateHue(){
  860.         if(this._elment){
  861.             this.setHue(this._elment.hue(this._data));
  862.         }
  863.     }
  864.     updateOpacity(){
  865.         if(this._elment){
  866.             this.alpha =this._elment.alpha(this._data);
  867.         }
  868.     }
  869.     loadBitmap(){
  870.         if(!this._elment ){
  871.             this.bitmap=null;
  872.             return;
  873.         }

  874.         //フォールバック画像を返す可能性があるので、nullでも渡す
  875.         const bitmap =this._elment.getBitmap(this._data||null);
  876.         this.bitmap = bitmap;
  877.         if(bitmap){
  878.             //TODO:hueがMV/MZで設定方法が違う
  879.             //MZはspriteが持っているので、何らかの対応を行う
  880.             bitmap.addLoadListener(this.onBitmapLoadead.bind(this));
  881.         }
  882.     }
  883.     onBitmapLoadead(){
  884.         this.updateFrame();
  885.         this.resetScale();
  886.     }
  887.     resetScale(){
  888.         const s=this.calcScale();
  889.         this.scale.set(s,s);
  890.     }
  891.     calcScale(){
  892.         const bitmap =this.bitmap;
  893.         if(bitmap && bitmap.isReady()){
  894.             const posRect =this._elment.positionRect();
  895.             const scaleA =posRect.width   /  this._frame.width ;
  896.             const scaleB =posRect.height / this._frame.height;
  897.             return Math.min(1,scaleA,scaleB);   
  898.         }
  899.         return 0;
  900.     }
  901.     /**
  902.      * @param {T_DataType} data
  903.      */
  904.     setData(data){
  905.         const dd= data||null;
  906.         if(dd!==this._data){
  907.             this._data=dd;
  908.             this.refresh();   
  909.         }

  910.     }
  911. }
  912. /**
  913. * @template {SaveFileInfo} T_DataType
  914. */
  915. class Spriteset_SuperView extends PIXI.Container{
  916.     /**
  917.      *
  918.      * @param {SpriteContents[]} constents
  919.      */
  920.     constructor(constents){
  921.         super();
  922.         /**
  923.          * @type {Sprite_SuperView<T_DataType>[]}
  924.          */
  925.         this._list =[];
  926.         this.setContents(constents);
  927.     }
  928.     /**
  929.      * @param {Number} num
  930.      */
  931.     reserveSprite(num){
  932.         const alocate= num - this._list.length;
  933.         if(alocate >0){
  934.             for (let i = 0; i < alocate; i++) {
  935.                 /**
  936.                  * @type {Sprite_SuperView<T_DataType>}
  937.                  */
  938.                 const sprite = new Sprite_SuperView();
  939.                 this._list.push(sprite);
  940.                 this.addChild(sprite);
  941.             }
  942.         }
  943.     }
  944.     /**
  945.      * @param {SpriteContents[]} contentsList
  946.      */
  947.     setContents(contentsList){
  948.         this.reserveSprite(contentsList.length);
  949.         this._list.forEach((sprite,index)=>{
  950.             const contents =contentsList[index];
  951.             sprite.setContents(contents||null);
  952.         });
  953.     }
  954.     /**
  955.      * @param {T_DataType} data
  956.      */
  957.     setData(data){
  958.         for (const iterator of this._list) {
  959.             iterator.setData(data);
  960.         }
  961.     }
  962. }

  963. class DataWindowLayout_V2{
  964.     /**
  965.      *
  966.      * @param {SpriteContents[]} casset
  967.      * @param {AreaObject[]} area
  968.      * @param {RectangleP} rect
  969.      */
  970.     constructor(casset,area,rect){
  971.         this._rect =rect;

  972.         const upper =[];
  973.         const lower =[];
  974.         for (const iterator of casset) {
  975.             if(iterator.isUpper()){
  976.                 upper.push(iterator);
  977.             }else{
  978.                 lower.push(iterator);
  979.             }
  980.         }
  981.         this._upperSprite = upper;
  982.         this._lowerSprite = lower;
  983.         this._areaList=area;
  984.     }
  985.     rect(){
  986.         return this._rect;
  987.     }
  988.     createSprites(){
  989.         const result= {
  990.             upper:new Spriteset_SuperView(this._upperSprite),
  991.             lower:new Spriteset_SuperView(this._lowerSprite),
  992.         };
  993.         return result;
  994.     }
  995.     area(){
  996.         return this._areaList;
  997.     }
  998.     *allVariableElements(){
  999.         for (const iterator of this._upperSprite) {
  1000.             yield iterator.kvp();
  1001.         }
  1002.         for (const iterator of this._lowerSprite) {
  1003.             yield iterator.kvp();
  1004.         }
  1005.         for (const area of this._areaList) {
  1006.             for (const iterator of area.textList) {
  1007.                 yield iterator.kvp();
  1008.             }
  1009.         }
  1010.     }
  1011. }

  1012. /**
  1013. * @param {DataWindowLayout_V2[]} layoutList
  1014. */
  1015. function *allKVP(layoutList){
  1016.     for (const iterator of layoutList) {
  1017.         for (const aa of iterator.allVariableElements()) {
  1018.             yield aa;
  1019.         }
  1020.     }
  1021. }
  1022. /**
  1023. *
  1024. * @param {RectangleP} rect
  1025. */
  1026. function boxFit(rect){
  1027.     const box= new Rectangle(0,0,Graphics.boxWidth,Graphics.boxHeight);
  1028.     const result = rect.clone();
  1029.     return result.fit(box);
  1030. }
  1031. //TODO:infoは2個用意する
  1032. //numvisibleRowsはminで制御する
  1033. class Window_SaveFileInfo extends Window_Base{
  1034.     /**
  1035.      *
  1036.      * @param {DataWindowLayout_V2} layout
  1037.      */
  1038.     constructor(layout){
  1039.         const rect = boxFit(layout.rect());
  1040.         super(rect);
  1041.         const sprites= layout.createSprites();
  1042.         this._upper =sprites.upper;
  1043.         this._lower =sprites.lower;
  1044.         this._layout=layout;
  1045.         this.addChild(this._upper);
  1046.         this.addChildToBack(this._lower);
  1047.     }
  1048.     /**
  1049.      * @param {SaveFileInfo} data
  1050.      */
  1051.     setData(data){
  1052.         this._upper.setData(data);
  1053.         this._lower.setData(data);
  1054.         this.pppText(data);
  1055.     }
  1056.     /**
  1057.      * @param {SaveFileInfo} info
  1058.      */
  1059.     pppText(info){
  1060.         this.contents.clear();
  1061.         for (const iterator of this._layout._areaList) {
  1062.             this.paintText(info,iterator);
  1063.         }
  1064.     }

  1065.     /**
  1066.      * @param {SaveFileInfo} info
  1067.      * @param {AreaObject} area
  1068.      */
  1069.     paintText(info,area){
  1070.         const lineHeight =this.lineHeight();
  1071.         let y =area.rect.y;
  1072.         for (const iterator of area.textList) {
  1073.             const indentLevel =iterator.indentLevel();
  1074.             const x = area.rect.x +indentLevel;
  1075.             const width= Math.min(this.innerWidth,area.rect.width)-indentLevel;
  1076.             this.drawContents(info,iterator,x,y,width,area.rect.height);
  1077.             y += iterator.numLines() * lineHeight;
  1078.         }
  1079.     }
  1080.     /**
  1081.      * @param {SaveFileInfo} data
  1082.      * @param {TextContents} contents
  1083.      * @param {Number} x
  1084.      * @param {Number} y
  1085.      * @param {Number} w
  1086.      * @param {Number} h
  1087.      */
  1088.     drawContents(data,contents,x,y,w,h){
  1089.         const indentWidth= contents.indentLevel();
  1090.         const textXXX = contents.getTextXXX(data);
  1091.         this.drawTextEx(textXXX.left,x +indentWidth  ,y,w-indentWidth);

  1092.         const color = contents.valueTextColor();
  1093.         if(color){
  1094.             this.changeTextColor(color);
  1095.         }else{
  1096.             this.resetTextColor();
  1097.         }
  1098.         //TODO:項目の色変更パラメータ
  1099.         this.drawText(textXXX.right,x,y,w,"right");   
  1100.     }
  1101. }

  1102. class SaveTemporaly{
  1103.     constructor(){
  1104.         this.setLastMessage("");
  1105.     }
  1106.     /**
  1107.      * @param {string} msg
  1108.      */
  1109.     setLastMessage(msg){
  1110.         this._lastMessage=msg;
  1111.     }
  1112.     getLastMessage(){
  1113.         return this._lastMessage;
  1114.     }
  1115. }

  1116. class ReadonlyFlags{
  1117.     /**
  1118.      *
  1119.      * @param {Iterable<KVP_Base>} kvpList
  1120.      */
  1121.     constructor(kvpList){
  1122.         this._lastMessage=false;
  1123.         //スクショ保存フラグ
  1124.         this._needsSnap =false;

  1125.         for (const iterator of kvpList) {
  1126.             if(iterator){
  1127.                 this.xxxFlag(iterator);
  1128.             }
  1129.         }
  1130.     }
  1131.     /**
  1132.      * @param {KVP_Base} kvp
  1133.      */
  1134.     xxxFlag(kvp){
  1135.         switch (kvp.key()) {
  1136.             case "lastmsg":
  1137.                 this._lastMessage=true;
  1138.                 break;        
  1139.             default:
  1140.                 break;
  1141.         }
  1142.     }

  1143.     needLastMessageSave(){
  1144.         return this._lastMessage;
  1145.     }

  1146. }
  1147. /**
  1148. * @typedef {Object} MainWindowLayout
  1149. * @property {number} numVisibleRows
  1150. * @property {number} maxCols
  1151. * @property {Rectangle} rect
  1152. */

  1153. class SaveDataReadonly{
  1154.     /**
  1155.      * @param {DataWindowLayout_V2[]} dataList
  1156.      * @param {MainWindowLayout} mainWindowLayout
  1157.      * @param {Number} lastMessageSwitch
  1158.      */
  1159.     constructor(dataList,mainWindowLayout,lastMessageSwitch){
  1160.         this._dataLayoutList=dataList;
  1161.         this._mainWindow =mainWindowLayout;
  1162.         this._lastMessageSwitch=lastMessageSwitch;

  1163.         this._flags = new ReadonlyFlags(allKVP(dataList));
  1164.     }
  1165.     needsLastMessage(){

  1166.         if(!this._flags.needLastMessageSave()){
  1167.             return false;
  1168.         }
  1169.         if(this._lastMessageSwitch >0){
  1170.             return  $gameSwitches.value(this._lastMessageSwitch);
  1171.         }
  1172.         return true;
  1173.     }
  1174.     setupSwitchs() {
  1175.         $gameSwitches.setValue(this._lastMessageSwitch,true);
  1176.     }

  1177.     createInfoRecord_V2(){
  1178.          const record =new RecordTemporay();
  1179.          for (const iterator of allKVP(this._dataLayoutList)) {
  1180.              if(iterator){
  1181.                 record.writeV2(iterator);
  1182.              }
  1183.          }
  1184.          const result= record.get();
  1185.          return result;
  1186.     }
  1187.     createDataWindows(){
  1188.         return this._dataLayoutList.map( (data)=>{
  1189.             return new Window_SaveFileInfo(data);
  1190.         });
  1191.     }
  1192.     needsChangeLayoutForListWindow(){
  1193.         return true;
  1194.     }
  1195.     fileListWindowRect(){
  1196.         return this._mainWindow.rect.clone();
  1197.     }
  1198.     fileNumVisivleRows(){
  1199.         return this._mainWindow.numVisibleRows;
  1200.     }
  1201.     fileMaxCols(){
  1202.         return this._mainWindow.maxCols;
  1203.     }
  1204. }

  1205. class SaveWindowManager_T3{
  1206.     maxCols() {
  1207.         return this._readonly.fileMaxCols();
  1208.     }

  1209.     /**
  1210.      * @param {SaveDataReadonly} readonlyData
  1211.      */
  1212.     constructor(readonlyData){
  1213.         this._readonly=readonlyData;
  1214.         this._temporary=null;
  1215.     }
  1216.     resetTemporary(){
  1217.         this._temporary = new SaveTemporaly();
  1218.     }
  1219.     onLoad(){
  1220.         this.resetTemporary();
  1221.     }
  1222.     onNewgame(){
  1223.         this.resetTemporary();
  1224.         this._readonly.setupSwitchs();
  1225.     }
  1226.     createaInfo(){
  1227.         return this._readonly.createInfoRecord_V2();
  1228.     }
  1229.     createDataWindows() {
  1230.         return this._readonly.createDataWindows();
  1231.     }
  1232.     fileListWindowRect() {
  1233.         return this._readonly.fileListWindowRect();
  1234.     }
  1235.     fileNumVisivleRows() {
  1236.         return this._readonly.fileNumVisivleRows();
  1237.     }
  1238.     /**
  1239.      *
  1240.      * @param {string} text
  1241.      */
  1242.     setLastMessage(text){
  1243.         if(this._readonly.needsLastMessage()){
  1244.             if(this._temporary){
  1245.                 this._temporary.setLastMessage(text);
  1246.             }
  1247.         }
  1248.     }
  1249.     getLastMessage(){
  1250.         return this._temporary._lastMessage;
  1251.     }
  1252. }

  1253. /**
  1254. * @param {String} objText
  1255. */
  1256. function createItemTabel(objText){
  1257.     /**
  1258.      * @type {Map<Number,String>}
  1259.      */
  1260.     const result = new Map();
  1261.     /**
  1262.      * @type {string[]}
  1263.      */
  1264.     const paramList =JSON.parse(objText);
  1265.     for (const iterator of paramList) {
  1266.         const obj =JSON.parse(iterator);
  1267.         const value =Number(obj.value);
  1268.         if(!isNaN(value)){
  1269.             if(obj.item){
  1270.                 const itemText = String(obj.item);
  1271.                 result.set(value,itemText);   
  1272.             }
  1273.         }
  1274.     }
  1275.     return result;
  1276. }

  1277. /**
  1278. *
  1279. * @param {string} spriteList
  1280. * @returns
  1281. */
  1282. function createContentsSpriteList(spriteList){
  1283.     /**
  1284.      * @type {string[]}
  1285.      */
  1286.     const spriteV2 =JSON.parse(spriteList||"[]");
  1287.     const sp2= spriteV2.map( (text)=>{
  1288.         const obj =JSON.parse(text);
  1289.         const rect =new Rectangle( Number(obj.x),Number(obj.y),Number(obj.width),Number(obj.height));
  1290.         const table = createItemTabel(obj.table);
  1291.         const variableId =Number(obj.variableId);
  1292.         const bmp =new  KVPXXX_BitmapTable(variableId,table);
  1293.         return new SpriteContents(bmp,{
  1294.             positionRect:rect,
  1295.             anthorX:Number(obj.anthorX),
  1296.             anthorY:Number(obj.anthorY),
  1297.             isUpper:(obj.isUpper==="true"),
  1298.         });
  1299.     });
  1300.     return sp2;
  1301. }

  1302. /**
  1303. * @param {string} rect
  1304. * @param {string} textList
  1305. * @param {string} areaRectText
  1306. * @param {string} spriteList
  1307. */
  1308. function createPage(rect,textList,areaRectText,spriteList){

  1309.     const sp = createContentsSpriteList(spriteList);
  1310.     const upper =[];
  1311.     const lower =[];
  1312.     for (const iterator of sp) {
  1313.         if(iterator.isUpper()){
  1314.            upper.push(iterator);
  1315.         }else{
  1316.             lower.push(iterator);
  1317.         }
  1318.     }
  1319.     const windowRect =parseRect(rect);
  1320.     /**
  1321.      * @type {string[]}
  1322.      */
  1323.     const paramList =JSON.parse(textList||"[]");
  1324.     const textObj = paramList.map( (t)=>{
  1325.         return TextItemDictionary.createByText(t);
  1326.     }).filter((v)=>{ return !!v });
  1327.     const wwRect = windowRect.clone();
  1328.     wwRect.x =0;
  1329.     wwRect.y =0;
  1330.     const areaRectV2 =parseRect(areaRectText);
  1331.     areaRectV2.fit(wwRect);
  1332.     return new DataWindowLayout_V2(sp,[
  1333.         {
  1334.             rect:areaRectV2,
  1335.             textList:textObj,
  1336.         }
  1337.     ],windowRect);
  1338. }
  1339. const SavaDataManager_V2 =(()=>{
  1340.     const param =getParam();
  1341.     const leftPage = createPage( param.leftWindow,param.leftTextList,param.leftTextPosition,param.leftSpriteList);
  1342.     const bottomPage =createPage(param.bottomWindow,param.bottomTextList,param.bottomTextPosition,param.bottomSpriteList);
  1343.     const listRect =parseRect(param.listWindow);
  1344.     const lastMessageSwitch =Number(param.lastMessageSwitch);
  1345.     const readonlyData = new SaveDataReadonly([leftPage,bottomPage],{
  1346.         rect:listRect,
  1347.         numVisibleRows:Number(param.numVisibleRows||3),
  1348.         maxCols:Number(param.maxCols||2),
  1349.     },lastMessageSwitch);

  1350.     const manager =new SaveWindowManager_T3(readonlyData);

  1351.     return manager;

  1352. })();
  1353. const Window_Message_startMessage=Window_Message.prototype.startMessage;
  1354. Window_Message.prototype.startMessage =function(){
  1355.     Window_Message_startMessage.call(this);
  1356.     SavaDataManager_V2.setLastMessage(this._textState.text);
  1357. };
  1358. const DataManager_loadAllSavefileImages =DataManager.loadAllSavefileImages;
  1359. DataManager.loadAllSavefileImages =function(){
  1360.     DataManager_loadAllSavefileImages.call(this);
  1361. };
  1362. const  Window_SavefileList_numVisibleRows =Window_SavefileList.prototype.numVisibleRows;
  1363. Window_SavefileList.prototype.numVisibleRows =function(){
  1364.     const n= Window_SavefileList_numVisibleRows.call(this);
  1365.     return Math.min(n,SavaDataManager_V2.fileNumVisivleRows());
  1366. };
  1367. const Window_SavefileList_maxCols=Window_SavefileList.prototype.maxCols;
  1368. Window_SavefileList.prototype.maxCols =function(){
  1369.     const oldValue = Window_SavefileList_maxCols.call(this);
  1370.     return Math.min(oldValue,SavaDataManager_V2.maxCols());
  1371. };
  1372. /**
  1373. * @param {Window_SaveFileInfo[]} dataWindows
  1374. * @param {Window_SavefileList} fileWindow
  1375. */
  1376. function setHelpFunction(dataWindows,fileWindow){
  1377.     if(dataWindows.length <=0){
  1378.         return;
  1379.     }

  1380.     const oldFunc =fileWindow.callUpdateHelp;
  1381.     fileWindow.callUpdateHelp =function(){
  1382.         oldFunc.call(this);
  1383.         const fileId = this.savefileId();
  1384.         /**
  1385.          * @type {SaveFileInfo}
  1386.          */
  1387.         const info =DataManager.savefileInfo(fileId);
  1388.         for (const iterator of dataWindows) {
  1389.             iterator.setData(info);
  1390.         }
  1391.     };

  1392. }
  1393. const Scene_File_create=Scene_File.prototype.create;
  1394. Scene_File.prototype.create =function(){
  1395.     Scene_File_create.call(this);
  1396.     const dataWindows =SavaDataManager_V2.createDataWindows();

  1397.     for (const iterator of dataWindows) {
  1398.         this.addWindow(iterator);        
  1399.     }
  1400.     setHelpFunction(dataWindows,this._listWindow);
  1401.     this._listWindow.reselect();
  1402. };
  1403. const DataManager_makeSavefileInfo=DataManager.makeSavefileInfo;
  1404. DataManager.makeSavefileInfo =function(){
  1405.     /**
  1406.      * @type {SaveFileInfo}
  1407.      */
  1408.     const result =DataManager_makeSavefileInfo.call(this);
  1409.     const record=SavaDataManager_V2.createaInfo();
  1410.     result.uzssrecord = record;
  1411.     return result;
  1412. };
  1413. const DataManager_setupNewGame=DataManager.setupNewGame;
  1414. DataManager.setupNewGame =function(){
  1415.     DataManager_setupNewGame.call(this);
  1416.     SavaDataManager_V2.onNewgame();
  1417. };
  1418. const DataManager_extractSaveContents=DataManager.extractSaveContents;
  1419. DataManager.extractSaveContents =function(c){
  1420.     DataManager_extractSaveContents.call(this,c);
  1421.     SavaDataManager_V2.onLoad();
  1422. };

  1423. const Scene_File_listWindowRect =Scene_File.prototype.listWindowRect;
  1424. Scene_File.prototype.listWindowRect =function(){
  1425.     /**
  1426.      * @type {Rectangle}
  1427.      */
  1428.     const base = Scene_File_listWindowRect.call(this);
  1429.     const result= SavaDataManager_V2.fileListWindowRect().fit(base);
  1430.     return result;
  1431. };

  1432. PluginManager.registerCommand(PLUGIN_NAME,"SetText",(arg)=>{
  1433.     const variableId =Number(arg.variableId);
  1434.     const text = String(arg.text);
  1435.     $gameVariables.setValue(variableId,text);
  1436. });

  1437. }());
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册用户

本版积分规则

Archiver|QQ群: 48625831|爱上RPG|哈库纳玛塔塔 |网站地图 Clicky

GMT+8, 2024-10-23 13:30 , Processed in 0.083466 second(s), 22 queries .

Powered by Discuz! X3.5

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表