gui/create-item: Improve quality assignment and make "Esc" work

develop
lethosor 2015-08-02 10:07:57 -04:00
parent e02815dc30
commit d7b1714a6c
2 changed files with 11 additions and 4 deletions

@ -32,7 +32,7 @@ DFHack Future
Circular lua dependencies (reqscript/script_environment) fixed Circular lua dependencies (reqscript/script_environment) fixed
Prevented crash in Items::createItem() Prevented crash in Items::createItem()
buildingplan: Now supports hatch covers buildingplan: Now supports hatch covers
gui/hack-wish now properly assigns quality to items. gui/create-item now properly assigns quality to items.
gui/gm-editor handles lua tables properly gui/gm-editor handles lua tables properly
manipulator: fixed crash when selecting custom professions when none are found manipulator: fixed crash when selecting custom professions when none are found
search: fixed crash in unit list after cancelling a job search: fixed crash in unit list after cancelling a job

@ -3,6 +3,7 @@
-- author Putnam -- author Putnam
-- edited by expwnent -- edited by expwnent
--@module = true
local function getGenderString(gender) local function getGenderString(gender)
local genderStr local genderStr
@ -112,9 +113,9 @@ end
local function createItem(mat,itemType,quality,creator,description) local function createItem(mat,itemType,quality,creator,description)
local item=df.item.find(dfhack.items.createItem(itemType[1], itemType[2], mat[1], mat[2], creator)) local item=df.item.find(dfhack.items.createItem(itemType[1], itemType[2], mat[1], mat[2], creator))
if pcall(function() print(item.quality) end) then assert(item, 'failed to create item')
item.quality=quality-1 quality = math.max(0, math.min(5, quality - 1))
end item:setQuality(quality)
if df.item_type[itemType[1]]=='SLAB' then if df.item_type[itemType[1]]=='SLAB' then
item.description=description item.description=description
end end
@ -175,23 +176,29 @@ function hackWish(unit)
local amountok, amount local amountok, amount
local matok,mattype,matindex,matFilter local matok,mattype,matindex,matFilter
local itemok,itemtype,itemsubtype=showItemPrompt('What item do you want?',function(itype) return df.item_type[itype]~='CORPSE' and df.item_type[itype]~='FOOD' end ,true) local itemok,itemtype,itemsubtype=showItemPrompt('What item do you want?',function(itype) return df.item_type[itype]~='CORPSE' and df.item_type[itype]~='FOOD' end ,true)
if not itemok then return end
if not args.notRestrictive then if not args.notRestrictive then
matFilter=getMatFilter(itemtype) matFilter=getMatFilter(itemtype)
end end
if not usesCreature(itemtype) then if not usesCreature(itemtype) then
matok,mattype,matindex=showMaterialPrompt('Wish','And what material should it be made of?',matFilter) matok,mattype,matindex=showMaterialPrompt('Wish','And what material should it be made of?',matFilter)
if not matok then return end
else else
local creatureok,useless,creatureTable=script.showListPrompt('Wish','What creature should it be?',COLOR_LIGHTGREEN,getCreatureList()) local creatureok,useless,creatureTable=script.showListPrompt('Wish','What creature should it be?',COLOR_LIGHTGREEN,getCreatureList())
if not creatureok then return end
mattype,matindex=getCreatureRaceAndCaste(creatureTable[3]) mattype,matindex=getCreatureRaceAndCaste(creatureTable[3])
end end
local qualityok,quality=script.showListPrompt('Wish','What quality should it be?',COLOR_LIGHTGREEN,qualityTable()) local qualityok,quality=script.showListPrompt('Wish','What quality should it be?',COLOR_LIGHTGREEN,qualityTable())
if not qualityok then return end
local description local description
if df.item_type[itemtype]=='SLAB' then if df.item_type[itemtype]=='SLAB' then
local descriptionok local descriptionok
descriptionok,description=script.showInputPrompt('Slab','What should the slab say?',COLOR_WHITE) descriptionok,description=script.showInputPrompt('Slab','What should the slab say?',COLOR_WHITE)
if not descriptionok then return end
end end
if args.multi then if args.multi then
repeat amountok,amount=script.showInputPrompt('Wish','How many do you want? (numbers only!)',COLOR_LIGHTGREEN) until tonumber(amount) repeat amountok,amount=script.showInputPrompt('Wish','How many do you want? (numbers only!)',COLOR_LIGHTGREEN) until tonumber(amount)
if not amountok then return end
if mattype and itemtype then if mattype and itemtype then
if df.item_type.attrs[itemtype].is_stackable then if df.item_type.attrs[itemtype].is_stackable then
local proper_item=df.item.find(dfhack.items.createItem(itemtype, itemsubtype, mattype, matindex, unit)) local proper_item=df.item.find(dfhack.items.createItem(itemtype, itemsubtype, mattype, matindex, unit))