1. import ui
  2. import snd
  3. import shop
  4. import mouseModule
  5. import player
  6. import chr
  7. import net
  8. import uiCommon
  9. import localeInfo
  10. import chat
  11. import item
  12. import systemSetting
  13. import player
  14. import app
  15. import constInfo
  16. g_isBuildingPrivateShop = False
  17. g_itemPriceDict={}
  18. if app.ENABLE_CHEQUE_SYSTEM:
  19. g_itemPriceChequeDict={}
  20. g_privateShopAdvertisementBoardDict={}
  21. def Clear():
  22. global g_itemPriceDict
  23. global g_isBuildingPrivateShop
  24. g_itemPriceDict={}
  25. g_isBuildingPrivateShop = False
  26. if app.ENABLE_CHEQUE_SYSTEM:
  27. global g_itemPriceChequeDict
  28. g_itemPriceChequeDict={}
  29. if app.ENABLE_CHEQUE_SYSTEM:
  30. def IsPrivateShopItemPriceList():
  31. global g_itemPriceDict
  32. global g_itemPriceChequeDict
  33. if g_itemPriceDict or g_itemPriceChequeDict:
  34. return True
  35. else:
  36. return False
  37. else:
  38. def IsPrivateShopItemPriceList():
  39. global g_itemPriceDict
  40. if g_itemPriceDict:
  41. return True
  42. else:
  43. return False
  44. def IsBuildingPrivateShop():
  45. global g_isBuildingPrivateShop
  46. if player.IsOpenPrivateShop() or g_isBuildingPrivateShop:
  47. return True
  48. else:
  49. return False
  50. if app.ENABLE_CHEQUE_SYSTEM:
  51. def SetPrivateShopItemPrice(itemVNum, itemPrice, itemPriceCheque):
  52. global g_itemPriceDict
  53. g_itemPriceDict[int(itemVNum)]=itemPrice
  54. global g_itemPriceChequeDict
  55. g_itemPriceChequeDict[int(itemVNum)]=itemPriceCheque
  56. def GetPrivateShopItemPrice(itemVNum):
  57. try:
  58. global g_itemPriceDict
  59. return g_itemPriceDict[itemVNum]
  60. except KeyError:
  61. return 0
  62. def GetPrivateShopItemPriceCheque(itemVNum):
  63. try:
  64. global g_itemPriceChequeDict
  65. return g_itemPriceChequeDict[itemVNum]
  66. except KeyError:
  67. return 0
  68. else:
  69. def SetPrivateShopItemPrice(itemVNum, itemPrice):
  70. global g_itemPriceDict
  71. g_itemPriceDict[int(itemVNum)]=itemPrice
  72. def GetPrivateShopItemPrice(itemVNum):
  73. try:
  74. global g_itemPriceDict
  75. return g_itemPriceDict[itemVNum]
  76. except KeyError:
  77. return 0
  78. def UpdateADBoard():
  79. for key in g_privateShopAdvertisementBoardDict.keys():
  80. g_privateShopAdvertisementBoardDict[key].Show()
  81. def DeleteADBoard(vid):
  82. if not g_privateShopAdvertisementBoardDict.has_key(vid):
  83. return
  84. del g_privateShopAdvertisementBoardDict[vid]
  85. class PrivateShopAdvertisementBoard(ui.ThinBoard):
  86. def __init__(self):
  87. ui.ThinBoard.__init__(self, "UI_BOTTOM")
  88. self.vid = None
  89. self.__MakeTextLine()
  90. def __del__(self):
  91. ui.ThinBoard.__del__(self)
  92. def __MakeTextLine(self):
  93. self.textLine = ui.TextLine()
  94. self.textLine.SetParent(self)
  95. self.textLine.SetWindowHorizontalAlignCenter()
  96. self.textLine.SetWindowVerticalAlignCenter()
  97. self.textLine.SetHorizontalAlignCenter()
  98. self.textLine.SetVerticalAlignCenter()
  99. self.textLine.Show()
  100. def Open(self, vid, text):
  101. self.vid = vid
  102. self.textLine.SetText(text)
  103. self.textLine.UpdateRect()
  104. self.SetSize(len(text)*6 + 10*2, 20)
  105. self.Show()
  106. g_privateShopAdvertisementBoardDict[vid] = self
  107. def OnMouseLeftButtonUp(self):
  108. if not self.vid:
  109. return
  110. net.SendOnClickPacket(self.vid)
  111. return True
  112. def OnUpdate(self):
  113. if not self.vid:
  114. return
  115. if systemSetting.IsShowSalesText():
  116. if not app.ENABLE_SHOPNAMES_RANGE:
  117. self.Show()
  118. (x, y) = chr.GetProjectPosition(self.vid, 220)
  119. self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2)
  120. else:
  121. if systemSetting.GetShopNamesRange() == 1.000:
  122. self.Show()
  123. (x, y) = chr.GetProjectPosition(self.vid, 220)
  124. self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2)
  125. else:
  126. LIMIT_RANGE = abs(constInfo.SHOPNAMES_RANGE * systemSetting.GetShopNamesRange())
  127. (to_x, to_y, to_z) = chr.GetPixelPosition(self.vid)
  128. (my_x, my_y, my_z) = player.GetMainCharacterPosition()
  129. if abs(my_x - to_x) <= LIMIT_RANGE and abs(my_y - to_y) <= LIMIT_RANGE:
  130. (x, y) = chr.GetProjectPosition(self.vid, 220)
  131. self.SetPosition(x - self.GetWidth() / 2, y - self.GetHeight() / 2)
  132. self.Show()
  133. else:
  134. self.Hide()
  135. self.SetPosition(-70, 0)
  136. else:
  137. for key in g_privateShopAdvertisementBoardDict.keys():
  138. if player.GetMainCharacterIndex() == key:
  139. g_privateShopAdvertisementBoardDict[key].Show()
  140. x, y = chr.GetProjectPosition(player.GetMainCharacterIndex(), 220)
  141. g_privateShopAdvertisementBoardDict[key].SetPosition(x - self.GetWidth()/2, y - self.GetHeight()/2)
  142. else:
  143. g_privateShopAdvertisementBoardDict[key].Hide()
  144. class PrivateShopBuilder(ui.ScriptWindow):
  145. def __init__(self):
  146. #print "NEW MAKE_PRIVATE_SHOP_WINDOW ----------------------------------------------------------------"
  147. ui.ScriptWindow.__init__(self)
  148. self.__LoadWindow()
  149. self.itemStock = {}
  150. self.tooltipItem = None
  151. self.priceInputBoard = None
  152. self.title = ""
  153. if app.WJ_ENABLE_TRADABLE_ICON:
  154. self.interface = None
  155. self.wndInventory = None
  156. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  157. def __del__(self):
  158. #print "------------------------------------------------------------- DELETE MAKE_PRIVATE_SHOP_WINDOW"
  159. ui.ScriptWindow.__del__(self)
  160. def __LoadWindow(self):
  161. try:
  162. pyScrLoader = ui.PythonScriptLoader()
  163. pyScrLoader.LoadScriptFile(self, "UIScript/PrivateShopBuilder.py")
  164. except:
  165. import exception
  166. exception.Abort("PrivateShopBuilderWindow.LoadWindow.LoadObject")
  167. try:
  168. GetObject = self.GetChild
  169. self.nameLine = GetObject("NameLine")
  170. self.itemSlot = GetObject("ItemSlot")
  171. self.btnOk = GetObject("OkButton")
  172. self.btnClose = GetObject("CloseButton")
  173. self.titleBar = GetObject("TitleBar")
  174. except:
  175. import exception
  176. exception.Abort("PrivateShopBuilderWindow.LoadWindow.BindObject")
  177. self.btnOk.SetEvent(ui.__mem_func__(self.OnOk))
  178. self.btnClose.SetEvent(ui.__mem_func__(self.OnClose))
  179. self.titleBar.SetCloseEvent(ui.__mem_func__(self.OnClose))
  180. self.itemSlot.SetSelectEmptySlotEvent(ui.__mem_func__(self.OnSelectEmptySlot))
  181. self.itemSlot.SetSelectItemSlotEvent(ui.__mem_func__(self.OnSelectItemSlot))
  182. self.itemSlot.SetOverInItemEvent(ui.__mem_func__(self.OnOverInItem))
  183. self.itemSlot.SetOverOutItemEvent(ui.__mem_func__(self.OnOverOutItem))
  184. def Destroy(self):
  185. self.ClearDictionary()
  186. self.nameLine = None
  187. self.itemSlot = None
  188. self.btnOk = None
  189. self.btnClose = None
  190. self.titleBar = None
  191. self.priceInputBoard = None
  192. if app.WJ_ENABLE_TRADABLE_ICON:
  193. self.interface = None
  194. self.wndInventory = None
  195. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  196. def Open(self, title):
  197. self.title = title
  198. if len(title) > 25:
  199. title = title[:22] + "..."
  200. self.itemStock = {}
  201. shop.ClearPrivateShopStock()
  202. self.nameLine.SetText(title)
  203. self.SetCenterPosition()
  204. self.Refresh()
  205. self.Show()
  206. if app.WJ_ENABLE_TRADABLE_ICON:
  207. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  208. self.interface.SetOnTopWindow(player.ON_TOP_WND_PRIVATE_SHOP)
  209. self.interface.RefreshMarkInventoryBag()
  210. global g_isBuildingPrivateShop
  211. g_isBuildingPrivateShop = True
  212. # shop.RefreshInventorySafa()
  213. def Close(self):
  214. global g_isBuildingPrivateShop
  215. g_isBuildingPrivateShop = False
  216. self.title = ""
  217. self.itemStock = {}
  218. shop.ClearPrivateShopStock()
  219. self.Hide()
  220. if self.priceInputBoard:
  221. self.priceInputBoard.Close()
  222. self.priceInputBoard = None
  223. if app.WJ_ENABLE_TRADABLE_ICON:
  224. for privatePos, (itemInvenPage, itemSlotPos) in self.lockedItems.items():
  225. if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  226. self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  227. self.lockedItems = {i:(-1,-1) for i in range(shop.SHOP_SLOT_COUNT)}
  228. self.interface.SetOnTopWindow(player.ON_TOP_WND_NONE)
  229. self.interface.RefreshMarkInventoryBag()
  230. def SetItemToolTip(self, tooltipItem):
  231. self.tooltipItem = tooltipItem
  232. def Refresh(self):
  233. getitemVNum=player.GetItemIndex
  234. getItemCount=player.GetItemCount
  235. setitemVNum=self.itemSlot.SetItemSlot
  236. delItem=self.itemSlot.ClearSlot
  237. for i in xrange(shop.SHOP_SLOT_COUNT):
  238. if not self.itemStock.has_key(i):
  239. delItem(i)
  240. continue
  241. pos = self.itemStock[i]
  242. itemCount = getItemCount(*pos)
  243. if itemCount <= 1:
  244. itemCount = 0
  245. setitemVNum(i, getitemVNum(*pos), itemCount)
  246. if app.ENABLE_CHANGELOOK_SYSTEM:
  247. itemTransmutedVnum = player.GetItemTransmutation(*pos)
  248. if itemTransmutedVnum:
  249. self.itemSlot.DisableCoverButton(i)
  250. else:
  251. self.itemSlot.EnableCoverButton(i)
  252. self.itemSlot.RefreshSlot()
  253. if app.WJ_ENABLE_TRADABLE_ICON:
  254. self.RefreshLockedSlot()
  255. def OnSelectEmptySlot(self, selectedSlotPos):
  256. isAttached = mouseModule.mouseController.isAttached()
  257. if isAttached:
  258. attachedSlotType = mouseModule.mouseController.GetAttachedType()
  259. attachedSlotPos = mouseModule.mouseController.GetAttachedSlotNumber()
  260. mouseModule.mouseController.DeattachObject()
  261. if player.SLOT_TYPE_INVENTORY != attachedSlotType and player.SLOT_TYPE_DRAGON_SOUL_INVENTORY != attachedSlotType:
  262. return
  263. attachedInvenType = player.SlotTypeToInvenType(attachedSlotType)
  264. itemVNum = player.GetItemIndex(attachedInvenType, attachedSlotPos)
  265. item.SelectItem(itemVNum)
  266. if item.IsAntiFlag(item.ANTIFLAG_GIVE) or item.IsAntiFlag(item.ANTIFLAG_MYSHOP):
  267. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.PRIVATE_SHOP_CANNOT_SELL_ITEM)
  268. return
  269. if app.WJ_ENABLE_TRADABLE_ICON and player.SLOT_TYPE_INVENTORY == attachedSlotType:
  270. self.CantTradableItem(selectedSlotPos, attachedSlotPos)
  271. priceInputBoard = uiCommon.MoneyInputDialog()
  272. priceInputBoard.SetTitle(localeInfo.PRIVATE_SHOP_INPUT_PRICE_DIALOG_TITLE)
  273. priceInputBoard.SetAcceptEvent(ui.__mem_func__(self.AcceptInputPrice))
  274. priceInputBoard.SetCancelEvent(ui.__mem_func__(self.CancelInputPrice))
  275. priceInputBoard.Open()
  276. itemPrice=GetPrivateShopItemPrice(itemVNum)
  277. if itemPrice>0:
  278. priceInputBoard.SetValue(itemPrice)
  279. if app.ENABLE_CHEQUE_SYSTEM:
  280. itemPriceCheque=GetPrivateShopItemPriceCheque(itemVNum)
  281. if itemPriceCheque>0:
  282. priceInputBoard.SetValueCheque(itemPriceCheque)
  283. self.priceInputBoard = priceInputBoard
  284. self.priceInputBoard.itemVNum = itemVNum
  285. self.priceInputBoard.sourceWindowType = attachedInvenType
  286. self.priceInputBoard.sourceSlotPos = attachedSlotPos
  287. self.priceInputBoard.targetSlotPos = selectedSlotPos
  288. def OnSelectItemSlot(self, selectedSlotPos):
  289. isAttached = mouseModule.mouseController.isAttached()
  290. if isAttached:
  291. snd.PlaySound("sound/ui/loginfail.wav")
  292. mouseModule.mouseController.DeattachObject()
  293. else:
  294. if not selectedSlotPos in self.itemStock:
  295. return
  296. invenType, invenPos = self.itemStock[selectedSlotPos]
  297. shop.DelPrivateShopItemStock(invenType, invenPos)
  298. snd.PlaySound("sound/ui/drop.wav")
  299. if app.WJ_ENABLE_TRADABLE_ICON:
  300. (itemInvenPage, itemSlotPos) = self.lockedItems[selectedSlotPos]
  301. if itemInvenPage == self.wndInventory.GetInventoryPageIndex():
  302. self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  303. self.lockedItems[selectedSlotPos] = (-1, -1)
  304. del self.itemStock[selectedSlotPos]
  305. self.Refresh()
  306. def AcceptInputPrice(self):
  307. if not self.priceInputBoard:
  308. return True
  309. if app.ENABLE_CHEQUE_SYSTEM:
  310. text = self.priceInputBoard.inputValue.GetText()
  311. text2 = self.priceInputBoard.InputValue_Cheque.GetText()
  312. if not text and not text2:
  313. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.YANG_VE_WON_MIKTARI_BOS_OLAMAZ)
  314. return True
  315. if not text.isdigit() and not text2.isdigit():
  316. # chat.AppendChat(chat.CHAT_TYPE_INFO, "Info: 02")
  317. return True
  318. if int(text) <= 0:
  319. if int(text2) > 0:
  320. pass
  321. else:
  322. chat.AppendChat(chat.CHAT_TYPE_INFO, localeInfo.LUTFEN_YANG_MIKTARI_GIRINIZ)
  323. return True
  324. else:
  325. text = self.priceInputBoard.GetText()
  326. if not text:
  327. return True
  328. if not text.isdigit():
  329. return True
  330. if int(text) <= 0:
  331. return True
  332. attachedInvenType = self.priceInputBoard.sourceWindowType
  333. sourceSlotPos = self.priceInputBoard.sourceSlotPos
  334. targetSlotPos = self.priceInputBoard.targetSlotPos
  335. for privatePos, (itemWindowType, itemSlotIndex) in self.itemStock.items():
  336. if itemWindowType == attachedInvenType and itemSlotIndex == sourceSlotPos:
  337. shop.DelPrivateShopItemStock(itemWindowType, itemSlotIndex)
  338. del self.itemStock[privatePos]
  339. if app.ENABLE_CHEQUE_SYSTEM:
  340. price = int(self.priceInputBoard.inputValue.GetText())
  341. price_cheque = int(self.priceInputBoard.InputValue_Cheque.GetText())
  342. if IsPrivateShopItemPriceList():
  343. SetPrivateShopItemPrice(self.priceInputBoard.itemVNum, price, price_cheque)
  344. shop.AddPrivateShopItemStock(attachedInvenType, sourceSlotPos, targetSlotPos, price, price_cheque)
  345. else:
  346. price = int(self.priceInputBoard.GetText())
  347. if IsPrivateShopItemPriceList():
  348. SetPrivateShopItemPrice(self.priceInputBoard.itemVNum, price)
  349. shop.AddPrivateShopItemStock(attachedInvenType, sourceSlotPos, targetSlotPos, price)
  350. self.itemStock[targetSlotPos] = (attachedInvenType, sourceSlotPos)
  351. snd.PlaySound("sound/ui/drop.wav")
  352. self.Refresh()
  353. #####
  354. self.priceInputBoard = None
  355. return True
  356. def CancelInputPrice(self):
  357. if app.WJ_ENABLE_TRADABLE_ICON:
  358. itemInvenPage = self.priceInputBoard.sourceSlotPos / player.INVENTORY_PAGE_SIZE
  359. itemSlotPos = self.priceInputBoard.sourceSlotPos - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  360. if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  361. self.wndInventory.wndItem.SetCanMouseEventSlot(itemSlotPos)
  362. self.lockedItems[self.priceInputBoard.targetSlotPos] = (-1, -1)
  363. if self.priceInputBoard:
  364. self.priceInputBoard.Close()
  365. self.priceInputBoard = None
  366. return 1
  367. def OnOk(self):
  368. if not self.title:
  369. return
  370. if 0 == len(self.itemStock):
  371. return
  372. shop.BuildPrivateShop(self.title)
  373. self.Close()
  374. def OnClose(self):
  375. # shop.RefreshInventorySafa()
  376. self.Close()
  377. def OnPressEscapeKey(self):
  378. self.Close()
  379. return True
  380. def OnOverInItem(self, slotIndex):
  381. if self.tooltipItem:
  382. if self.itemStock.has_key(slotIndex):
  383. self.tooltipItem.SetPrivateShopBuilderItem(*self.itemStock[slotIndex] + (slotIndex,))
  384. def OnOverOutItem(self):
  385. if self.tooltipItem:
  386. self.tooltipItem.HideToolTip()
  387. if app.WJ_ENABLE_TRADABLE_ICON:
  388. def CantTradableItem(self, destSlotIndex, srcSlotIndex):
  389. itemInvenPage = srcSlotIndex / player.INVENTORY_PAGE_SIZE
  390. localSlotPos = srcSlotIndex - (itemInvenPage * player.INVENTORY_PAGE_SIZE)
  391. self.lockedItems[destSlotIndex] = (itemInvenPage, localSlotPos)
  392. if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  393. self.wndInventory.wndItem.SetCantMouseEventSlot(localSlotPos)
  394. def RefreshLockedSlot(self):
  395. if self.wndInventory:
  396. for privatePos, (itemInvenPage, itemSlotPos) in self.lockedItems.items():
  397. if self.wndInventory.GetInventoryPageIndex() == itemInvenPage:
  398. self.wndInventory.wndItem.SetCantMouseEventSlot(itemSlotPos)
  399. self.wndInventory.wndItem.RefreshSlot()
  400. def BindInterface(self, interface):
  401. self.interface = interface
  402. def OnTop(self):
  403. if self.interface:
  404. self.interface.SetOnTopWindow(player.ON_TOP_WND_PRIVATE_SHOP)
  405. self.interface.RefreshMarkInventoryBag()
  406. def SetInven(self, wndInventory):
  407. from _weakref import proxy
  408. self.wndInventory = proxy(wndInventory)