264 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
			
		
		
	
	
			264 lines
		
	
	
		
			8.3 KiB
		
	
	
	
		
			Plaintext
		
	
	
	
| /*
 | |
| 文件名:Stackable.nut
 | |
| 路径:User/Asset/Item/Stackable.nut
 | |
| 创建日期:2025-01-18	01:46
 | |
| 文件用途:可堆叠物品
 | |
| */
 | |
| //消耗品图标窗口
 | |
| class GameItem.StackableIcon extends CL_CanvasObject {
 | |
| 
 | |
|     constructor(Stackable, RenderCount = true) {
 | |
|         base.constructor();
 | |
|         ResizeAndClear(32, 32);
 | |
|         BeginDraw();
 | |
|         //构造图标 及图标边框
 | |
|         if (Stackable.Icon) {
 | |
|             //图标
 | |
|             local Icon = CL_SpriteFrameObject(Stackable.Icon.path, Stackable.Icon.index);
 | |
|             DrawSpriteFrame(Icon, 0, 0);
 | |
| 
 | |
|             //边框
 | |
|             local IconFrame = CL_SpriteFrameObject("sprite/item/iconmark.img", 62 + GameItem.EquipmentInfoTag.rarityframe_color_idx[Stackable.Rarity]);
 | |
|             DrawSpriteFrame(IconFrame, 0, 0);
 | |
| 
 | |
|             //数量
 | |
|             if (RenderCount && Stackable.Count > 0) {
 | |
|                 local CountText = Yosin_Mininumber(Stackable.Count);
 | |
|                 DrawActor(CountText, 28 - CountText.GetSize().w, 0);
 | |
|             }
 | |
|         }
 | |
|         EndDraw();
 | |
|     }
 | |
| }
 | |
| 
 | |
| //消耗品信息窗口
 | |
| class GameItem.StackableInfo extends Yosin_Window {
 | |
|     //消耗品
 | |
|     Stackable = null;
 | |
|     //画布
 | |
|     Canvas = null;
 | |
|     //画布实际高度
 | |
|     RealCanvasHeight = 0;
 | |
| 
 | |
|     constructor(Stackable) {
 | |
|         this.Stackable = Stackable.weakref();
 | |
|         base.constructor(clock() + "StackableInfo" + Stackable.Idx, 0, 0, 0, 0, 0);
 | |
| 
 | |
|         Init();
 | |
| 
 | |
|         local background = Yosin_NineBoxStretch(211, RealCanvasHeight + 10, "sprite/interface/lenheartwindowcommon.img", 213);
 | |
|         background.SetZOrder(-1);
 | |
|         Addchild(background);
 | |
|     }
 | |
| 
 | |
|     function Init() {
 | |
|         Canvas = CL_CanvasObject();
 | |
|         Canvas.ResizeAndClear(210, 600);
 | |
|         Canvas.SetFillBrush(sq_RGBA(59, 56, 57, 250));
 | |
|         Canvas.SetStrokeBrush(sq_RGBA(59, 56, 57, 250));
 | |
|         Canvas.BeginDraw();
 | |
| 
 | |
|         //构造图标 及图标边框
 | |
|         if (Stackable.Icon) {
 | |
|             local Icon = GameItem.StackableIcon(Stackable, false);
 | |
|             Canvas.DrawActor(Icon, 7, 7);
 | |
|         }
 | |
| 
 | |
|         //绘制名称
 | |
|         if (Stackable.Name.len() > 0) {
 | |
|             local DrawName = Stackable.Name;
 | |
|             local EquName = FontAssetManager.GenerateNormal(DrawName, false, {
 | |
|                 color = GameItem.EquipmentInfoTag.rarity_color[Stackable.Rarity]
 | |
|             });
 | |
|             Canvas.DrawActor(EquName, 41, 7);
 | |
|         }
 | |
| 
 | |
|         //绘制分割线
 | |
|         Canvas.DrawLine(3, 37, 207, 38);
 | |
| 
 | |
| 
 | |
|         //绘制稀有度名称
 | |
|         local RarityTagName = FontAssetManager.GenerateNormal(GameItem.EquipmentInfoTag.rarity_name_tag[Stackable.Rarity], false, {
 | |
|             color = GameItem.EquipmentInfoTag.rarity_color[Stackable.Rarity]
 | |
|         });
 | |
|         Canvas.DrawActor(RarityTagName, 210 - RarityTagName.GetSize().w - 6, 41);
 | |
| 
 | |
|         //绘制类型
 | |
|         local RealGroupName = Stackable.GroupName ? Stackable.GroupName : "cube stuff";
 | |
|         local GroupNameText = FontAssetManager.GenerateNormal(GameItem.EquipmentInfoTag.item_group_name_table[RealGroupName], false, {
 | |
|             color = sq_RGBA(194, 161, 56, 255)
 | |
|         });
 | |
|         Canvas.DrawActor(GroupNameText, 6, 41);
 | |
| 
 | |
| 
 | |
|         //下面的绘制逻辑开始使用行put来做
 | |
|         RealCanvasHeight = 64;
 | |
| 
 | |
| 
 | |
|         //绘制交易类型 如果有主体属性读取 否则一律为封装
 | |
|         local TradeType = Stackable.TradeType;
 | |
|         local TradeTypeText = FontAssetManager.GenerateNormal(GameItem.EquipmentInfoTag.trade_type_text[TradeType], false, {
 | |
|             color = GameItem.EquipmentInfoTag.trade_type_color[TradeType]
 | |
|         });
 | |
|         Canvas.DrawActor(TradeTypeText, 6, 60);
 | |
| 
 | |
|         //绘制售价
 | |
|         local RealSellPrice = (Stackable.SellPrice == -1 ? (Stackable.Price == -1 ? 0 : Stackable.Price) : Stackable.SellPrice) / 5;
 | |
|         local SellPriceText = FontAssetManager.GenerateNormal(RealSellPrice + "金币", false, {
 | |
|             color = sq_RGBA(133, 121, 78, 255)
 | |
|         });
 | |
|         Canvas.DrawActor(SellPriceText, 210 - SellPriceText.GetSize().w - 6, 60);
 | |
| 
 | |
|         //绘制分割
 | |
|         AddSliceLine();
 | |
| 
 | |
|         //绘制描述
 | |
|         if (Stackable.FlavorText) {
 | |
|             // //绘制分割
 | |
|             // Canvas.DrawLine(3, RealCanvasHeight + 3, 207, RealCanvasHeight + 3);
 | |
|             // RealCanvasHeight += 6;
 | |
| 
 | |
|             local Text = FontAssetManager.GenerateNormal(Stackable.FlavorText, false, {
 | |
|                 color = sq_RGBA(133, 121, 80, 255),
 | |
|                 wrap_width = 200
 | |
|             });
 | |
|             Canvas.DrawActor(Text, 6, RealCanvasHeight);
 | |
|             RealCanvasHeight += Text.GetSize().h;
 | |
|         }
 | |
| 
 | |
|         Canvas.EndDraw();
 | |
|         Addchild(Canvas);
 | |
|     }
 | |
| 
 | |
|     //增加行高
 | |
|     function AddHeight() {
 | |
|         RealCanvasHeight += 16;
 | |
|     }
 | |
|     //增加分割行
 | |
|     function AddSliceLine() {
 | |
|         RealCanvasHeight += 18;
 | |
|         Canvas.DrawLine(3, RealCanvasHeight, 207, RealCanvasHeight);
 | |
|         RealCanvasHeight += 2;
 | |
|     }
 | |
| 
 | |
| }
 | |
| 
 | |
| 
 | |
| class GameItem.Stackable extends GameItem.Item {
 | |
| 
 | |
|     //物品ID
 | |
|     Idx = -1;
 | |
|     //物品名称
 | |
|     Name = "";
 | |
|     //数量
 | |
|     Count = 0;
 | |
| 
 | |
|     //物品类型
 | |
|     Type = null;
 | |
|     //交易类型
 | |
|     TradeType = 0;
 | |
| 
 | |
|     //物品最低使用等级
 | |
|     Minimum_level = 0;
 | |
|     //物品等级组
 | |
|     Grade = 0;
 | |
|     //物品稀有度
 | |
|     Rarity = 0;
 | |
|     //物品重量
 | |
|     Weight = 0;
 | |
|     //物品组名
 | |
|     GroupName = null;
 | |
|     //物品购买价格
 | |
|     Price = 0;
 | |
|     //物品维修价格
 | |
|     RepairPrice = 0;
 | |
|     //物品出售价格
 | |
|     SellPrice = 0;
 | |
|     //物品职业
 | |
|     Job = null;
 | |
|     //物品图标
 | |
|     Icon = null;
 | |
|     //物品描述
 | |
|     FlavorText = "";
 | |
| 
 | |
|     function _typeof() {
 | |
|         return "Stackable";
 | |
|     }
 | |
| 
 | |
|     constructor(...) {
 | |
|         //直接裸构造
 | |
|         if (vargv.len() == 0) {
 | |
| 
 | |
|         }
 | |
|         //通过参数构造
 | |
|         else if (vargv.len() == 1) {
 | |
|             local StkInfo;
 | |
|             //通过ID构造
 | |
|             if (typeof vargv[0] == "integer") {
 | |
|                 Idx = vargv[0];
 | |
|                 ConstructStackableFromScript(AssetManager.GetStackable(Idx));
 | |
|             }
 | |
|             //通过脚本信息构造
 | |
|             else if (typeof vargv[0] == "table") {
 | |
|                 Idx = vargv[0].ItemId;
 | |
|                 ConstructStackableFromScript(AssetManager.GetStackable(Idx));
 | |
|                 IterateStackableBasedOnActualStackableInformation(vargv[0]);
 | |
|             }
 | |
| 
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //根据消耗品脚本信息构造消耗品
 | |
|     function ConstructStackableFromScript(StkInfo) {
 | |
|         //如果获取到对应的消耗品脚本信息
 | |
|         if (StkInfo) {
 | |
|             //名称
 | |
|             if (StkInfo.rawin("name")) Name = StkInfo["name"];
 | |
|             //类型
 | |
|             // if (StkInfo.rawin("type")) GetRealStackableType(StkInfo["type"].path);
 | |
|             //最低使用等级
 | |
|             if (StkInfo.rawin("minimum level")) Minimum_level = StkInfo["minimum level"];
 | |
|             //等级组
 | |
|             if (StkInfo.rawin("grade")) Grade = StkInfo["grade"];
 | |
|             //稀有度
 | |
|             if (StkInfo.rawin("rarity")) Rarity = StkInfo["rarity"];
 | |
|             //重量
 | |
|             if (StkInfo.rawin("weight")) Weight = StkInfo["weight"];
 | |
|             //组名
 | |
|             if (StkInfo.rawin("item group name")) GroupName = StkInfo["item group name"];
 | |
|             //购买价格
 | |
|             if (StkInfo.rawin("price")) Price = StkInfo["price"];
 | |
|             //维修价格
 | |
|             if (StkInfo.rawin("repair price")) RepairPrice = StkInfo["repair price"];
 | |
|             //出售价格
 | |
|             if (StkInfo.rawin("value")) SellPrice = StkInfo["value"];
 | |
|             //职业
 | |
|             if (StkInfo.rawin("usable_job")) Job = StkInfo["usable_job"];
 | |
|             //图标
 | |
|             if (StkInfo.rawin("icon")) Icon = StkInfo["icon"];
 | |
|             //描述
 | |
|             if (StkInfo.rawin("explain")) FlavorText = StkInfo["explain"];
 | |
|             //交易类型
 | |
|             if (StkInfo.rawin("trade_type")) TradeType = StkInfo["trade_type"];
 | |
|         }
 | |
|     }
 | |
| 
 | |
|     //根据实际的消耗品信息迭代消耗品
 | |
|     function IterateStackableBasedOnActualStackableInformation(Info) {
 | |
|         Count = Info.ItemCount;
 | |
|         TradeType = Info.ItemTradeType;
 | |
|     }
 | |
| }
 | |
| 
 | |
| 
 | |
| if (!getroottable().rawin("chongzaiflag")) {
 | |
|     getroottable()["chongzaiflag"] <- true;
 | |
| } else {
 | |
|     //遍历窗口队列 如果可见则调用Show
 | |
|     for (local i = 0; i< _SYS_WINDOW_LIST_.len(); i++) {
 | |
|         local Window = _SYS_WINDOW_LIST_[i];
 | |
|         Window.Visible = false;
 | |
|         Window.RemoveSelf();
 | |
|     }
 | |
|     TestStage();
 | |
| } |