Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions assets/scripts/ui/UIMarket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Market } from '../components/Market';
import { MarketDB, MarketItemDB } from '../data/Packet';
import { ItemName } from './UIItem';
import { MarketItemData, UIMarketItem } from './UIMarketItem';
import { ResourcesHelper } from '../utils/ResourcesHelper';
const { ccclass, property } = _decorator;

/**
Expand Down Expand Up @@ -40,12 +41,13 @@ export class UIMarket extends Component {
let itemDic = {};
for (let key in data) {
let arr = key.split("_");
let name = arr[0];
let rawName = arr[0];
let name = ResourcesHelper.NormalizeItemName(rawName);
let level: number = + arr[1];
let price: number = data[key].price;
if (itemDic[name] == null) {
itemDic[name] = new MarketItemData();
itemDic[name].name = name;
itemDic[name].name = rawName;
itemDic[name].priceDic = {};
}
itemDic[name].priceDic[level] = price;
Expand Down
42 changes: 36 additions & 6 deletions assets/scripts/utils/ResourcesHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,30 @@ export class ResourcesHelper {


public static ItemSprteDic: { [name: string]: SpriteFrame };
private static ItemNameAlias: { [key: string]: string } = {
Chisel: "Arcane",
Bottom: "Bottom",
Bow:"Bow",
Axe: "Chisel",
Gloves: "Gloves",
Gold:"Gold",
Hat: "Hat",
Pickaxe: "Pickaxe",
Potion: "Poultice",
Ration: "Ration",
Rod:"Rod",
Whetstone: "Scrap",
Runes: "Shard",
Arrow: "Shaving",
Spear: "Sword",
Top: "Top",
Wand: "Wand",
};

public static NormalizeItemName(name: string): string {
if (!name) return name;
return this.ItemNameAlias[name] || name;
}



Expand Down Expand Up @@ -319,25 +343,31 @@ export class ResourcesHelper {

//---------------------------- item ------------------------
public static GetItemFullPath(name: string): string {
return `${this.ItemIconsPath}icon_item_${name}`;
const normalized = this.NormalizeItemName(name);
return `${this.ItemIconsPath}icon_item_${normalized}`;
}

public static GetItemIcon(name: string): SpriteFrame {

if (this.ItemSprteDic == null) this.ItemSprteDic = {};

if (this.ItemSprteDic[name] == null) {
const normalized = this.NormalizeItemName(name);

let fullName = this.GetItemFullPath(name);
if (this.ItemSprteDic[normalized] == null) {

let fullName = this.GetItemFullPath(normalized);

let sp = resources.get<SpriteFrame>(fullName + "/spriteFrame");

if (sp != null) {

this.ItemSprteDic[name] = sp;
this.ItemSprteDic[normalized] = sp;
}
}
return this.ItemSprteDic[name];
if (name != null && this.ItemSprteDic[name] == null && this.ItemSprteDic[normalized] != null) {
this.ItemSprteDic[name] = this.ItemSprteDic[normalized];
}
return this.ItemSprteDic[normalized];
}

}
}