From b45820a97754f497ea697eac0ba28b31e8fb841d Mon Sep 17 00:00:00 2001 From: crabman77 Date: Thu, 9 Jun 2016 01:15:09 +0200 Subject: [PATCH] add wear textures and display tools wear in sell formspec remove shop money in formspec --- shop.lua | 69 +++++++++++++++++------------- textures/minercantile_wear_0.png | Bin 0 -> 151 bytes textures/minercantile_wear_10.png | Bin 0 -> 161 bytes textures/minercantile_wear_20.png | Bin 0 -> 162 bytes textures/minercantile_wear_30.png | Bin 0 -> 163 bytes textures/minercantile_wear_40.png | Bin 0 -> 163 bytes textures/minercantile_wear_50.png | Bin 0 -> 162 bytes textures/minercantile_wear_60.png | Bin 0 -> 162 bytes textures/minercantile_wear_70.png | Bin 0 -> 162 bytes textures/minercantile_wear_80.png | Bin 0 -> 162 bytes textures/minercantile_wear_90.png | Bin 0 -> 157 bytes 11 files changed, 39 insertions(+), 30 deletions(-) create mode 100644 textures/minercantile_wear_0.png create mode 100644 textures/minercantile_wear_10.png create mode 100644 textures/minercantile_wear_20.png create mode 100644 textures/minercantile_wear_30.png create mode 100644 textures/minercantile_wear_40.png create mode 100644 textures/minercantile_wear_50.png create mode 100644 textures/minercantile_wear_60.png create mode 100644 textures/minercantile_wear_70.png create mode 100644 textures/minercantile_wear_80.png create mode 100644 textures/minercantile_wear_90.png diff --git a/shop.lua b/shop.lua index fee62e1..bb46d35 100644 --- a/shop.lua +++ b/shop.lua @@ -301,9 +301,9 @@ end local function show_formspec_to_buy(name) local player = minetest.get_player_by_name(name) if not player or not shop_buy[name] then return end - local formspec = {"size[10,10]bgcolor[#2A2A2A;]label[0,0;shop money:"..minercantile.shop.get_money().."$]label[4.4,0;Buy Items]"} + local formspec = {"size[10,10]bgcolor[#2A2A2A;]label[4.4,0;Buy Items]"} + table.insert(formspec, "label[0,0;Your money:"..minercantile.wallet.get_money(name) .."$]") local inv_items = get_shop_inventory_by_page(name) - table.insert(formspec, "label[0,0.5;Your money:"..minercantile.wallet.get_money(name) .."$]") table.insert(formspec, "label[0.2,1.4;Page: ".. shop_buy[name].page.." of ".. shop_buy[name].nb_pages.."]") if shop_buy[name].search ~= "" then table.insert(formspec, "label[2,1.4;Filter: ".. minetest.formspec_escape(shop_buy[name].search) .."]") @@ -384,7 +384,7 @@ function minercantile.shop.player_sell(name) local items_nb = stack:get_count() if itname ~= item.name or items_nb == 0 then - minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.7,1;Sorry, You have 0 item ..".. itname.."]button[1.3,2.1;1.5,1;return_sell;Return]button_exit[3.3,2.1;1.5,1;close;Close]") + minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.5,1;Sorry, You have 0 item ..".. itname.."]button[1.3,2.1;1.5,1;return_sell;Return]button_exit[3.3,2.1;1.5,1;close;Close]") return false end @@ -393,14 +393,6 @@ function minercantile.shop.player_sell(name) item_can_sell = items_nb end - local stock = minercantile.shop.get_nb(item) - if stock >= minercantile.shop.max_stock then - minetest.show_formspec(name, "minercantile:confirmed", "size[6,3]bgcolor[#2A2A2A;]label[2.6,0;Shop]label[1.7,1;Sorry, the shop has too much stock of ..".. itname.."]button[1.3,2.1;1.5,1;return_sell;Return]button_exit[3.3,2.1;1.5,1;close;Close]") - return false - elseif (stock + item_can_sell) > minercantile.shop.max_stock then - item_can_sell = (item_can_sell -((stock + item_can_sell) - minercantile.shop.max_stock)) - end - local price_total = math.floor(item_can_sell * price) local shop_can_buy = item_can_sell if (shop_money/4) < price_total then @@ -413,7 +405,6 @@ function minercantile.shop.player_sell(name) end local taken = stack:take_item(shop_can_buy) - local sell_price = math.floor((taken:get_count()) * price) player_inv:set_stack("main", index, stack) minercantile.stock.items[itname].nb = minercantile.stock.items[itname].nb + shop_can_buy @@ -424,47 +415,65 @@ function minercantile.shop.player_sell(name) return true end +local function get_wear_img(wear) + local pct = math.floor(((65535-wear)*100)/65535) + for i=90, 0, -10 do + if pct >= i then + return "minercantile_wear_".. i ..".png" + end + end + return nil +end -- show sell formspec local function show_formspec_to_sell(name) local player = minetest.get_player_by_name(name) if not player then return end - local formspec = {"size[10,8]bgcolor[#2A2A2A;]label[4,0;Sell Items]"} - table.insert(formspec, "label[0,0;shop money:"..minercantile.shop.get_money().."$]") - table.insert(formspec, "label[0,0.5;Your money:"..minercantile.wallet.get_money(name) .."$]") + local formspec = {"size[13,10]bgcolor[#2A2A2A;]label[6,0;Sell Items]"} + table.insert(formspec, "label[0,0;Your money:"..minercantile.wallet.get_money(name) .."$]") local player_inv = player:get_inventory() shop_sell[name] = {} shop_sell[name].items = {} for i=1, player_inv:get_size("main") do local stack = player_inv:get_stack("main", i) - if not stack:is_empty() and minercantile.shop.is_available(stack:get_name()) then + if not stack:is_empty() then local itname = stack:get_name() - local nb = stack:get_count() - local wear = stack:get_wear() - local price = minercantile.shop.get_sell_price(itname, wear) - if price and price > 0 then - table.insert(shop_sell[name].items, {name=itname, nb=nb, price=price, index=i, wear=wear}) + if minercantile.shop.is_available(itname) and minercantile.shop.get_nb(itname) < minercantile.shop.max_stock then + local nb = stack:get_count() + local wear = stack:get_wear() + local price = minercantile.shop.get_sell_price(itname, wear) + if price and price > 0 then + table.insert(shop_sell[name].items, {name=itname, nb=nb, price=price, index=i, wear=wear}) + end end end end - - local x = 0.2 - local y = 1 + local x = 0.8 + local y = 2 + local j = 1 for i=1, 32 do local item = shop_sell[name].items[i] if item then table.insert(formspec, "item_image_button["..x..","..y..";1,1;"..tostring(item.name)..";buttonchoice_"..tostring(i)..";"..item.nb.."]") table.insert(formspec, "label["..(x)..","..(y+0.8)..";"..item.price.."$]") + if item.wear and item.wear > 0 then + local img = get_wear_img(item.wear) + if img then + table.insert(formspec, "image["..x..","..y..";1,1;"..img.."]") + end + end else table.insert(formspec, "image["..x..","..y..";1,1;minercantile_img_inv.png]") end - x = x +1.1 - if x > 8 then - x = 0.2 - y = y + 1.4 + x = x +1.5 + j = j + 1 + if j > 8 then + j = 1 + x = 0.8 + y = y + 1.6 end end - table.insert(formspec, "button_exit[1.3,7.3;1.5,1;choice;Close]") + table.insert(formspec, "button_exit[5.8,9.3;1.5,1;choice;Close]") minetest.show_formspec(name, "minercantile:shop_sell", table.concat(formspec)) end @@ -536,7 +545,7 @@ function minercantile.get_formspec_shop_admin_shop(pos, node_name, name) else table.insert(formspec, "label[1,3;Open 24/24: No]button[3.5,2.8;1.5,1;always_open;Yes]") end - + table.insert(formspec, "label[1,4;Shop money:"..minercantile.shop.get_money().."$]") table.insert(formspec, "button_exit[2.4,5.3;1.5,1;close;Close]") return table.concat(formspec) end diff --git a/textures/minercantile_wear_0.png b/textures/minercantile_wear_0.png new file mode 100644 index 0000000000000000000000000000000000000000..975f70b177515b91d6b6bfc562379671d449ec2c GIT binary patch literal 151 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYG^#?ee|l>OdhCPZ!6Kh{JCWJMuCZa4>BA+*+^7 oaWmyZ=43ITY{1(uub%AXpPC}is8KA%3KU`RboFyt=akR{0F(46=l}o! literal 0 HcmV?d00001 diff --git a/textures/minercantile_wear_10.png b/textures/minercantile_wear_10.png new file mode 100644 index 0000000000000000000000000000000000000000..cfa0e26359c4d5899bc47ffc54d8e71f1d6bb392 GIT binary patch literal 161 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYCXFS$O73pge<~r;B4q#NoGR4H+2}1deQQ=J2}E zFVyluSS&$7a<>U114G08ttyeqzgz6y|DUh*(}0;t(p%dTsFT6d)z4*}Q$iB}^E@js literal 0 HcmV?d00001 diff --git a/textures/minercantile_wear_20.png b/textures/minercantile_wear_20.png new file mode 100644 index 0000000000000000000000000000000000000000..098aaf6531142c9b93a89deb451283e7595ba76a GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYCYwm``t~I8aF6)5S3);_%zEhKvjf0!KDDb8HIe z)M@#^HX~6X(%OWPfuZ64R+UKQ-y*;Fe6C-`@R5U=X=!Pa6;LaKr>mdKI;Vst00q!1 A(*OVf literal 0 HcmV?d00001 diff --git a/textures/minercantile_wear_30.png b/textures/minercantile_wear_30.png new file mode 100644 index 0000000000000000000000000000000000000000..0fd9bba761eb4669308e1dd5774969ebf0820d0d GIT binary patch literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYCYA-y-VEMWB#@r;B4q#NoGR4S5+91XvC_b8HIe z)M@!3w1R`x_^aA%pppacqb9AHSj+W$&-eOO49{0EGks}XD+QEb@O1TaS?83{1OS^= BF5LhC literal 0 HcmV?d00001 diff --git a/textures/minercantile_wear_40.png b/textures/minercantile_wear_40.png new file mode 100644 index 0000000000000000000000000000000000000000..aed4ab892bd193e07a596353c25a69ff70de67dd GIT binary patch literal 163 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYCXVnX74r5m3m$)5S3);_%zEj+_h%BCH3~1+1lx z_OX3T7hvH(cW1gUP|1UGUC(Q0>^gt#_+7t>;bjCf)28bm&HyDCJYD@<);T3K0RUN? BE}8%U literal 0 HcmV?d00001 diff --git a/textures/minercantile_wear_50.png b/textures/minercantile_wear_50.png new file mode 100644 index 0000000000000000000000000000000000000000..76a65317e9f505abe6d4d5f43de063025d012d3c GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYCY=SlqND3@D`U>Eaj?aro_7M_vX60hWzNSvdb4 zotV({nSoz!3sag9P|1&2?@6Yc{h4d;{GYG&;|Md;(tmNRKye07S3j3^P6<>&pIsjYCXdERWp|q)y+{#W5t}@Y}P2oD2#gEC)BYB>XRE zQmv77`EYn9!){KXl0WNIPtLk&o>V*M?|iLq6PTI&E<>&pIsjYCY2r>pMU3ZRg_r;B4q#NoGRH*zv42(TP97J0Kj z=-`F?gAN7-%Np*o0F~5TpOkX;&FzPF=l=VP{&~X8l=R?LD^Q%l)78&qol`;+00u!a ADgXcg literal 0 HcmV?d00001 diff --git a/textures/minercantile_wear_80.png b/textures/minercantile_wear_80.png new file mode 100644 index 0000000000000000000000000000000000000000..43f1db5de1663eb72c03f71685c25f6707235cba GIT binary patch literal 162 zcmeAS@N?(olHy`uVBq!ia0vp^3LwnE1|*BCs=fdzwj^(N7l!{JxM1({$v_d#0*}aI z1_o|n5N2eUHAey{$X?><>&pIsjYCXNV!{%ot3V-rPZ!6Kh{JC$Y~*E7;9+)5&-ePq zCmi4=a)<>&pIsjYCXNS#ka8k3b