Jump to content

Recommended Posts

Hello, good afternoon, I wanted a help, I put item shop in game, but I can not find where the start button of the shop item panel is.
the file that I come with tutorial is

game.py,

interfacemodule.py,

uiitemshop.

I'll leave the file here if anyone can see how it works I'll be grateful.

Game.py

Spoiler

# sob def __ServerCommand_Build(self): Adicionar

        self.serverCommander.SAFE_RegisterCallBack("ClearItemShop", self.__ClearItemShop)
        self.serverCommander.SAFE_RegisterCallBack("RecvItemShop", self.__RecvItemShop)
        self.serverCommander.SAFE_RegisterCallBack("RefreshItemShop", self.__RefreshItemShop)
        self.serverCommander.SAFE_RegisterCallBack("UpdateItemShopMoney", self.__UpdateItemShopMoney)
        self.serverCommander.SAFE_RegisterCallBack("FortuneWheelItem", self.__FortuneWheelItem)
        self.serverCommander.SAFE_RegisterCallBack("FortuneWheelConfig", self.__FortuneWheelConfig)

# Adicione abaixo
    def __FortuneWheelConfig(self, arg1, arg2):
        if (self.interface):
            self.interface.FortuneWheel("config", (int(arg1), int(arg2)))
        
    def __FortuneWheelItem(self, arg1, arg2, arg3):
        if (self.interface):
            self.interface.FortuneWheel("item", (int(arg1), int(arg2), int(arg3)))

    def __UpdateItemShopMoney(self, type, money):
        if (self.interface):
            self.interface.UpdateItemShopMoney(type, int(money))
        
    def __ClearItemShop(self):
        if (self.interface):
            self.interface.ClearItemShop()

    def __RecvItemShop(self, category, number, itemVnum, count, price, currency):
        if (self.interface):
            self.interface.RecvItemShop(int(category), int(number), int(itemVnum), int(count), int(price), int(currency))
            
    def __RefreshItemShop(self):
        if (self.interface):
            self.interface.RefreshItemShop()

interfacemodule.py

Spoiler

# Adicione abaixo
import uiitemshop

# sob self.wndExpandedTaskBar = None adicionar
        self.wndItemShop = None

# sob wndChatLog.BindInterface(self) adicionar
        wndItemShop = uiitemshop.MainWindow()
        wndItemShop.Hide()
        self.wndItemShop = wndItemShop

# sob self.privateShopBuilder.SetItemToolTip(self.tooltipItem) adicionar
        self.wndItemShop.SetItemToolTip(self.tooltipItem)

# Nad self.questButtonList = [] adicionar
        if (self.wndItemShop):
            self.wndItemShop.Destroy()
            del self.wndItemShop

# sob if self.wndExpandedTaskBar: adicionar
        if (self.wndItemShop):
            self.wndItemShop.Hide()

# sob self.wndGameButton, \ adicionar
                        self.wndItemShop, \

# Adicione abaixo
    def ToggleItemShop(self):
        if (self.wndItemShop):
            self.wndItemShop.OpenWindow()

    def RecvItemShop(self, category, *args):
        uiitemshop.setItems(category, args)
        
    def FortuneWheel(self, type, args):
        if (self.wndItemShop):
            self.wndItemShop.FortuneWheel(type, args)
        
    def UpdateItemShopMoney(self, type, money):
        uiitemshop.setCash(type, money)
        if (self.wndItemShop):
            self.wndItemShop.RefreshCash()
    
    def ClearItemShop(self):
        uiitemshop.clearItems()
        
    def RefreshItemShop(self):
        if (self.wndItemShop):
            self.wndItemShop.RefreshItemShop()

uiitemshop.py

Spoiler

import ui, app, item, wndMgr, grp, net
from uiguild import CheckBox

IMAGE_PATH = "kairos/itemshop/"

def configItemShop(key):
    configDict = {
        "max_items" : 6,
        "max_items_itemshop" : 4,
        "max_categories" : 14,
        "category_player" : 15,
    }
    return configDict.get(key, False)

def getLocaleName(key):
    localeDict = {
        "information_textline_0" : "• Aktualny stan Smoczych Monet na Twoim koncie: |cFFFFC700|h%d|r",
        "information_textline_1" : "• Aktualny stan Smoczych Znakow na Twoim koncie: |cFFFFC700|h%d|r",
        "information_textline_2" : "Aby zasiliæ swoje konto dodatkow¹ iloœci¹ SM, odwiedŸ oficjaln¹ stronê serwera.",
        "information_textline_3" : "Najczêœciej wybierane przez graczy",
        "information_textline_4_0" : "• NajedŸ kursorem na przedmiot",
        "information_textline_4_1" : "Aby zobaczyæ jego dok³adny opis",
        "information_textline_5" : "Ko³o losu",
        "information_textline_6" : "Zakup przedmiotu",
        
        "item_count" : "Iloœæ: %d",
        "item_price" : "Cena: %d %s",
        
        "currency" : ("SM", "SZ", ),
        
        "fortune_wheel_0" : "Losuj za 50 Smoczych Monet",
        "fortune_wheel_1" : "Losuj za 500 Smoczych Znaków",
        "price_confirm" : "|cFFFFC700|hCena: %d %s / %d szt.|r",
    }
    return localeDict.get(key, "#" + key)
    
items = {}
cash = {}

def setCash(type, money):
    global cash
    cash[type] = money
    
def getCash(type):
    global cash
    return cash.get(type, 0)

def getItems(category):
    global items
    return items.get(category)
    
def setItems(category, *args):
    global items
    try:
        items[category].append(args[0])
    except:
        items[category] = [args[0]]

def clearItems():
    global items
    items.clear()

class ConfirmWindow(ui.Board):
    windowConfig = {
        "size" : (382, 154),
        "flag" : ("movable", ),
    }
    
    def __init__(self):
        ui.Board.__init__(self)

        self.itemData = (-1, -1, -1)
        self.itemToolTip = None
        self.children = {}
        
        def _loadWindow():
            self.SetSize(self.windowConfig.get("size")[0], self.windowConfig.get("size")[1])
            map(self.AddFlag, self.windowConfig.get("flag"))
            self.SetCenterPosition()
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self)
            imageBox.SetPosition(0, 8)
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "misc/bar_middle_1.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("image_bar", imageBox)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetParent("image_bar"))
            textLine.SetPosition(0, 0)
            textLine.SetText(getLocaleName("information_textline_6"))
            textLine.SetWindowHorizontalAlignCenter()
            textLine.SetWindowVerticalAlignCenter()
            textLine.SetHorizontalAlignCenter()
            textLine.SetVerticalAlignCenter()
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self)
            imageBox.SetPosition(25, 0)
            imageBox.SetWindowVerticalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "item_background.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("slot_board", imageBox)
            
            # imageBox = ui.ImageBox()
            # imageBox.SetParent(self.__GetParent("slot_board"))
            # imageBox.SetPosition(0, 0)
            # imageBox.SetWindowHorizontalAlignCenter()
            # imageBox.SetWindowVerticalAlignCenter()
            # imageBox.LoadImage(IMAGE_PATH + "itemshop_slot.png")
            # imageBox.UpdateRect()
            # imageBox.Show()
            
            # self.__AddObject("slot_image", imageBox)
            
            slotWindow = ui.SlotWindow()
            slotWindow.SetParent(self.__GetParent("slot_board"))
            slotWindow.SetPosition(0, 0)
            slotWindow.SetSize(32, 32)
            slotWindow.AppendSlot(0, 0, 0, 32, 32)
            slotWindow.SetWindowHorizontalAlignCenter()
            slotWindow.SetWindowVerticalAlignCenter()
            slotWindow.SetOverInItemEvent(ui.__mem_func__(self.__OnOverInItem))
            slotWindow.SetOverOutItemEvent(ui.__mem_func__(self.__OnOverOutItem))
            slotWindow.UpdateRect()
            slotWindow.Show()
            
            self.__AddObject("slot_window", slotWindow)
            
            bar = ui.Bar()
            bar.SetParent(self)
            bar.SetPosition(25 + self.__GetParent("slot_board").GetWidth(), -27)
            bar.SetSize(340 - self.__GetParent("slot_board").GetWidth(), 20)
            bar.SetWindowVerticalAlignCenter()
            bar.SetColor(0xDD000000)
            bar.UpdateRect()
            bar.Show()
            
            self.__AddObject("bar_background", bar, True)
            
            bar = ui.Bar()
            bar.SetParent(self)
            bar.SetPosition(25 + self.__GetParent("slot_board").GetWidth(), 12)
            bar.SetSize(340 - self.__GetParent("slot_board").GetWidth(), 50)
            bar.SetWindowVerticalAlignCenter()
            bar.SetColor(0xDD000000)
            bar.UpdateRect()
            bar.Show()
            
            self.__AddObject("bar_background", bar, True)
            
            def createPriceTextLine(pos, desc, itemData = (0, 0, 0)):
                textLine = ui.TextLine()
                textLine.SetParent(self)
                textLine.SetPosition(pos[0], pos[1])
                textLine.SetText(desc % (itemData[0], getLocaleName("currency")[itemData[1]], itemData[2]))
                textLine.Show()
                imageBox = ui.ImageBox()
                imageBox.SetParent(textLine)
                imageBox.SetPosition(-15, 6)
                imageBox.SetWindowHorizontalAlignCenter()
                imageBox.SetWindowVerticalAlignCenter()
                imageBox.LoadImage(IMAGE_PATH + "misc/image_0.png")
                imageBox.UpdateRect()
                imageBox.Show()
                return (textLine, imageBox, )
                
            self.__AddObject("price_textline", createPriceTextLine((50, 125), getLocaleName("price_confirm")))
            
            btnSize = (85, (25 + 6), )
            for btn in ("cancel", "buy_now", ):
                button = ui.Button()
                button.SetParent(self)
                button.SetUpVisual(IMAGE_PATH + "%s_0.png" % btn)
                button.SetOverVisual(IMAGE_PATH + "%s_1.png" % btn)
                button.SetDownVisual(IMAGE_PATH + "%s_2.png" % btn)
                button.SetEvent(ui.__mem_func__(self.__OnClickButton), btn)
                button.SetPosition(197 + (btnSize[0] * self.__GetCountObject("button")), 120)
                button.UpdateRect()
                button.Show()
            
                self.__AddObject("button", button, True)
                
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetParent("bar_background", 0))
            textLine.SetPosition(10, 4)
            textLine.SetText(getLocaleName("information_textline_4_0"))
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetParent("bar_background", 1))
            textLine.SetPosition(10, 10)
            textLine.SetText(getLocaleName("information_textline_4_0"))
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetParent("bar_background", 1))
            textLine.SetPosition(10, 23)
            textLine.SetText(getLocaleName("information_textline_4_1"))
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)

        _loadWindow()
        
    def __del__(self):
        ui.Board.__del__(self)
        
    def __AddObject(self, key, object, asList = False):
        if (not self.children.get(key, None)):
            if (asList == True):
                self.children[key] = [object]
            else:
                self.children[key] = object
        else:
            self.children[key].append(object)
            
    def __GetParent(self, key, index = -1):
        object = self.children.get(key, None)
        
        if (object is None):
            return self

        if (index >= 0):
            return object[index]
        else:
            return object
            
    def __ClearObject(self, key):
        self.children[key] = None
    
    def __GetObject(self, key):
        return self.children.get(key)
        
    def __GetCountObject(self, key):
        count = 0
        try:
            count = len(self.__GetObject(key))
        except:
            count = 0
        return count
        
    def __OnOverInItem(self, slotPos):
        if (self.itemToolTip and self.itemData[0] != -1):
            self.itemToolTip.SetItemToolTip(self.itemData[0])
            self.itemToolTip.ShowToolTip()
        
    def __OnOverOutItem(self):
        if (self.itemToolTip):
            self.itemToolTip.ClearToolTip()
            self.itemToolTip.HideToolTip()
        
    def __OnClickButton(self, eventKey):
        def _buyItem():
            net.SendChatPacket("/buy_item %d %d" % (self.itemData[2], self.itemData[1]))
            self.itemData = (-1, -1, -1)
            self.Hide()
            
        def _cancel():
            self.itemData = (-1, -1, -1)
            self.Hide()
            
        def _exit():
            self.OnPressEscapeKey()
            
        def _refresh():
            net.SendChatPacket("/refresh_itemshop")
            
        eventDict = {
            "buy_now" : (lambda : (_buyItem())),
            "cancel" : (lambda : (_cancel())),
            "exit" : (lambda : (_exit())),
            "refresh" : (lambda : (_refresh())),
        }
        
        try:
            eventDict.get(eventKey, lambda *arg: None)()
        except:
            import exception
            exception.Abort("<uiitemshop.py> - __OnClickButton")
            
    def SetItemToolTip(self, itemToolTip):
        self.itemToolTip = itemToolTip
        
    def LoadItem(self, *args):
        (textLine, imageBox, ) = self.__GetObject("price_textline")

        textLine.SetText(getLocaleName("price_confirm") % (args[3], getLocaleName("currency")[args[4]], args[2]))
        
        item.SelectItem(args[0])
        self.__GetObject("textline")[1].SetText("• " + item.GetItemName())
        
                        
        def _getRealSize(size):
            return {1 : 32, 2 : 64, 3 : 96}.get(size, 32)
                
        (itemWidth, itemHeight) = item.GetItemSize()
        
        self.__GetObject("slot_window").SetSize(32, _getRealSize(itemHeight))
        self.__GetObject("slot_window").AppendSlot(0, 0, 0, 32, _getRealSize(itemHeight))
        self.__GetObject("slot_window").SetItemSlot(0, args[0], 0 if (args[2] == 1) else args[2])
        self.__GetObject("slot_window").UpdateRect()

        self.itemData = (args[0], args[1], args[5])
        
        (textLine, imageBox, ) = self.__GetObject("price_textline")
        imageBox.LoadImage(IMAGE_PATH + "misc/image_%d.png" % args[4])
        
    def ClearItem(self):
        self.itemData = (-1, -1, -1)
        
    def Destroy(self):
        self.itemData = (-1, -1, -1)
        self.itemToolTip = None
        self.children = {}

    def OpenWindow(self):
        if (self.IsShow() == True):
            self.Hide()
        else:
            self.Show()
            
    def OnPressEscapeKey(self):
        self.Hide()
        return True
        
    OnPressExitKey = OnPressEscapeKey

class ItemShopItem(ui.Window):
    def __init__(self, itemDict):
        ui.Window.__init__(self)
        
        self.children = {}
        self.itemDict = itemDict
        self.itemToolTip = itemDict.get("itemToolTip")

        item.SelectItem(self.itemDict.get("item_vnum"))
        
        def _loadWindow():
            imageBox = ui.ImageBox()
            imageBox.SetParent(self)
            imageBox.SetPosition(0, 0)
            imageBox.LoadImage(IMAGE_PATH + "item_background.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("slot_board", imageBox)
            
            # imageBox = ui.ImageBox()
            # imageBox.SetParent(self.__GetParent("slot_board"))
            # imageBox.SetPosition(0, 0)
            # imageBox.SetWindowHorizontalAlignCenter()
            # imageBox.SetWindowVerticalAlignCenter()
            # imageBox.LoadImage(IMAGE_PATH + "itemshop_slot.png")
            # imageBox.UpdateRect()
            # imageBox.Show()
            
            # self.__AddObject("slot_image", imageBox)
            
            def _getRealSize(size):
                return {1 : 32, 2 : 64, 3 : 96}.get(size, 32)
                
            (itemWidth, itemHeight) = item.GetItemSize()
            
            slotWindow = ui.SlotWindow()
            slotWindow.SetParent(self.__GetParent("slot_board"))
            slotWindow.SetPosition(0, 0)
            slotWindow.SetSize(32, _getRealSize(itemHeight))
            slotWindow.AppendSlot(0, 0, 0, 32, _getRealSize(itemHeight))
            slotWindow.SetWindowHorizontalAlignCenter()
            slotWindow.SetWindowVerticalAlignCenter()
            slotWindow.SetItemSlot(0, self.itemDict.get("item_vnum"), 0 if self.itemDict.get("item_count") == 1 else self.itemDict.get("item_count"))
            slotWindow.SetOverInItemEvent(ui.__mem_func__(self.__OnOverInItem))
            slotWindow.SetOverOutItemEvent(ui.__mem_func__(self.__OnOverOutItem))
            slotWindow.UpdateRect()
            slotWindow.Show()
            
            self.__AddObject("slot_window", slotWindow)
            
            bar = ui.Bar()
            bar.SetParent(self)
            bar.SetPosition(self.__GetParent("slot_board").GetWidth(), 0)
            bar.SetSize(460 - self.__GetParent("slot_board").GetWidth(), 60)
            bar.SetWindowVerticalAlignCenter()
            bar.SetColor(0xDD000000)
            bar.UpdateRect()
            bar.Show()
            
            self.__AddObject("bar_background", bar)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetObject("bar_background"))
            textLine.SetPosition(10, 4)
            textLine.SetText("• " + item.GetItemName())
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetObject("bar_background"))
            textLine.SetPosition(10, 30)
            textLine.SetText(getLocaleName("information_textline_4_0"))
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetObject("bar_background"))
            textLine.SetPosition(10, 43)
            textLine.SetText(getLocaleName("information_textline_4_1"))
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            def createMiscWindow():
                window = ui.Window()
                window.SetParent(self.__GetObject("bar_background"))
                window.SetPosition(90, 0)
                window.SetSize(90, 60)
                window.SetWindowHorizontalAlignRight()
                window.Show()
                
                textLine = []
                for i in xrange(2): textLine.append(ui.TextLine())

                textLine[0].SetParent(window)
                textLine[0].SetPosition(0, 4)
                textLine[0].SetText(getLocaleName("item_count") % self.itemDict.get("item_count"))
                textLine[0].SetPackedFontColor(0xFFFFC700)
                textLine[0].SetWindowHorizontalAlignCenter()
                textLine[0].SetHorizontalAlignCenter()
                textLine[0].UpdateRect()
                textLine[0].Show()
                
                textLine[1].SetParent(window)
                textLine[1].SetPosition(0, 18)
                textLine[1].SetText(getLocaleName("item_price") % (self.itemDict.get("item_price"), getLocaleName("currency")[self.itemDict.get("currency")]))
                textLine[1].SetPackedFontColor(0xFFFFC700)
                textLine[1].SetWindowHorizontalAlignCenter()
                textLine[1].SetHorizontalAlignCenter()
                textLine[1].UpdateRect()
                textLine[1].Show()
                
                button = ui.Button()
                button.SetParent(window)
                button.SetUpVisual(IMAGE_PATH + "buy_now_0.png")
                button.SetOverVisual(IMAGE_PATH + "buy_now_1.png")
                button.SetDownVisual(IMAGE_PATH + "buy_now_2.png")
                button.SetPosition(0, button.GetHeight() + 2)
                button.SetEvent(ui.__mem_func__(self.__OnClickButton), "buy")
                button.SetWindowHorizontalAlignCenter()
                button.SetWindowVerticalAlignBottom()
                button.UpdateRect()
                button.Show()
                
                return (window, textLine, button, )
                
            self.__AddObject("buy_window", createMiscWindow())
            
        _loadWindow()
        
    def __del__(self):
        ui.Window.__del__(self)
        
    def __AddObject(self, key, object, asList = False):
        if (not self.children.get(key, None)):
            if (asList == True):
                self.children[key] = [object]
            else:
                self.children[key] = object
        else:
            self.children[key].append(object)
            
    def __GetParent(self, key, index = -1):
        object = self.children.get(key, None)
        
        if (object is None):
            return self

        if (index >= 0):
            return object[index]
        else:
            return object
            
    def __ClearObject(self, key):
        self.children[key] = None
    
    def __GetObject(self, key):
        return self.children.get(key)
        
    def __OnClickButton(self, eventKey):
        def _buyItem():
            confirmWindow = self.itemDict.get("confirm")
            if (confirmWindow.IsShow() == True):
                confirmWindow.LoadItem(
                    self.itemDict.get("item_vnum"),
                    self.itemDict.get("number"),
                    self.itemDict.get("item_count"),
                    self.itemDict.get("item_price"),
                    self.itemDict.get("currency"),
                    self.itemDict.get("category"),
                )
                return True
            confirmWindow.LoadItem(
                self.itemDict.get("item_vnum"),
                self.itemDict.get("number"),
                self.itemDict.get("item_count"),
                self.itemDict.get("item_price"),
                self.itemDict.get("currency"),
                self.itemDict.get("category"),
            )
            confirmWindow.OpenWindow()

        eventDict = {
            "buy" : (lambda : (_buyItem())),
        }
        
        try:
            eventDict.get(eventKey, lambda *arg: None)()
        except:
            import exception
            exception.Abort("<uiitemshop.py> - __OnClickButton")

    def __OnOverInItem(self, slotPos):
        if (self.itemToolTip):
            self.itemToolTip.SetItemToolTip(self.itemDict.get("item_vnum"))
            self.itemToolTip.ShowToolTip() 
        
    def __OnOverOutItem(self):
        if (self.itemToolTip):
            self.itemToolTip.ClearToolTip() 
            self.itemToolTip.HideToolTip() 
        
    def Destroy(self):
        self.itemToolTip = None
        self.children = {}
    
class ItemShopWindow(ui.Window):
    windowConfig = {
        "size" : (767, 548),
        "flag" : ("movable", ),
    }
    
    def __init__(self):
        ui.Window.__init__(self)
        
        # self.alphaColor = 0.1

        self.itemToolTip = None
        self.categoryIndex = 0

        self.windowDict = {}
        self.children = {}
        
        def _loadWindow():
            self.SetSize(self.windowConfig.get("size")[0], self.windowConfig.get("size")[1])
            map(self.AddFlag, self.windowConfig.get("flag"))
            self.SetCenterPosition()
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self)
            imageBox.AddFlag("attach")
            imageBox.SetPosition(0, 0)
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.SetWindowVerticalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "itemshop_window_image.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("image_board", imageBox)
            
            window = ui.Window()
            window.SetParent(self.__GetParent("image_board"))
            window.AddFlag("attach")
            window.SetPosition(0, 30)
            window.SetSize(450, 100)
            window.SetWindowHorizontalAlignCenter()
            window.UpdateRect()
            window.Show()
            
            self.__AddObject("information_board", window)
            
            def createCoinsTextLine(i, pos, desc, withImage = False):
                textLine = ui.TextLine()
                textLine.SetParent(self.__GetParent("information_board"))
                textLine.SetPosition(pos[0] + (25 if (withImage == True) else 0), pos[1])
                textLine.SetText(desc)
                textLine.Show()
                if (withImage == True):
                    imageBox = ui.ImageBox()
                    imageBox.SetParent(textLine)
                    imageBox.SetPosition(-15, 6)
                    imageBox.SetWindowHorizontalAlignCenter()
                    imageBox.SetWindowVerticalAlignCenter()
                    imageBox.LoadImage(IMAGE_PATH + "misc/image_%d.png" % min(1, i))
                    imageBox.UpdateRect()
                    imageBox.Show()
                    return (textLine, imageBox, )
                return (textLine, )
                
            pos = (5, 15)
            for i in xrange(3):
                if (i == 2):
                    pos = (25, 33)
                self.__AddObject("information_text", createCoinsTextLine(i, (pos[0], pos[1] + 21 * i), getLocaleName("information_textline_%d" % i), False if (i == 2) else True), True)
        
            for i in xrange(configItemShop("max_categories")):
                button = ui.RadioButton()
                button.SetParent(self.__GetParent("image_board"))
                button.SetUpVisual(IMAGE_PATH + "category/category_%d_0.png" % i)
                button.SetOverVisual(IMAGE_PATH + "category/category_%d_1.png" % i)
                button.SetDownVisual(IMAGE_PATH + "category/category_%d_2.png" % i)
                button.SetPosition(20, 45 + (33 * i))
                button.SetEvent(ui.__mem_func__(self.__OnClickCategoryButton), i)
                button.UpdateRect()
                button.Show()
            
                self.__AddObject("radio_button", button, True)
                
            window = ui.Window()
            window.SetParent(self.__GetParent("image_board"))
            window.AddFlag("attach")
            window.SetPosition(65, 130)
            window.SetSize(580, 400)
            window.SetWindowHorizontalAlignCenter()
            window.UpdateRect()
            window.Show()
            
            self.__AddObject("items_board", window)
            
            def createItemBackground(x, y, width, height):
                window = ui.Window()
                window.SetParent(self.__GetObject("items_board"))
                window.SetPosition(x, y)
                window.SetSize(width, height)
                window.Show()
                listBox = ui.ListBoxEx()
                listBox.SetParent(window)
                listBox.SetItemStep(85)
                listBox.SetPosition(0, 25)
                listBox.SetItemSize(460, 80)
                listBox.SetViewItemCount(configItemShop("max_items_itemshop"))
                listBox.SetSize(width, height)
                listBox.Show()
                scrollBar = ui.ScrollBar()
                scrollBar.SetParent(window)
                scrollBar.SetPosition(width - 23, 3)
                scrollBar.SetScrollBarSize(height - 15)
                scrollBar.Show()
                listBox.SetScrollBar(scrollBar)
                imageBox = ui.ImageBox()
                imageBox.SetParent(window)
                imageBox.SetPosition(-15, 0)
                imageBox.SetWindowHorizontalAlignCenter()
                imageBox.LoadImage(IMAGE_PATH + "misc/bar_middle.png")
                imageBox.UpdateRect()
                imageBox.Show()
                textLine = ui.TextLine()
                textLine.SetParent(imageBox)
                textLine.SetPosition(0, 0)
                textLine.SetText(getLocaleName("information_textline_3"))
                textLine.SetWindowHorizontalAlignCenter()
                textLine.SetWindowVerticalAlignCenter()
                textLine.SetHorizontalAlignCenter()
                textLine.SetVerticalAlignCenter()
                textLine.UpdateRect()
                textLine.Show()
                return (window, listBox, imageBox, textLine, )
            
            self.__AddObject("items_box", createItemBackground(0, 5, 490, 400))
            
            for i in ((632, 385), (632, 125)):
                imageBox = ui.ImageBox()
                imageBox.SetParent(self.__GetParent("image_board"))
                imageBox.AddFlag("attach")
                imageBox.SetPosition(i[0] + 13, i[1] + 10)
                imageBox.LoadImage(IMAGE_PATH + "banners/banner_%d.png" % (3 + self.__GetCountObject("banners")))
                imageBox.UpdateRect()
                imageBox.Show()
                
                # bar = ui.Bar()
                # bar.SetParent(imageBox)
                # bar.SetPosition(0, 0)
                # bar.SetSize(imageBox.GetWidth(), imageBox.GetHeight())
                # bar.SetColor(0x40FFFFFF)
                # bar.Show()
                
                self.__AddObject("banners", imageBox, True)
                # self.__AddObject("bar_blank", bar, True)
                
            button = ui.Button()
            button.SetParent(self.__GetParent("image_board"))
            button.SetUpVisual(IMAGE_PATH + "refresh_0.png")
            button.SetOverVisual(IMAGE_PATH + "refresh_1.png")
            button.SetDownVisual(IMAGE_PATH + "refresh_2.png")
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "refresh")
            button.SetPosition(button.GetWidth() + 36, 16)
            button.SetWindowHorizontalAlignRight()
            button.UpdateRect()
            button.Show()
            
            self.__AddObject("button", button, True)
            
            button = ui.Button()
            button.SetParent(self.__GetParent("image_board"))
            button.SetUpVisual(IMAGE_PATH + "exit_0.png")
            button.SetOverVisual(IMAGE_PATH + "exit_1.png")
            button.SetDownVisual(IMAGE_PATH + "exit_2.png")
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "exit")
            button.SetPosition(button.GetWidth() + 13, 15)
            button.SetWindowHorizontalAlignRight()
            button.UpdateRect()
            button.Show()
            
            self.__AddObject("button", button, True)

        _loadWindow()
        
    def __del__(self):
        ui.Window.__del__(self)
        
    def __AddObject(self, key, object, asList = False):
        if (not self.children.get(key, None)):
            if (asList == True):
                self.children[key] = [object]
            else:
                self.children[key] = object
        else:
            self.children[key].append(object)
            
    def __GetParent(self, key, index = -1):
        object = self.children.get(key, None)
        
        if (object is None):
            return self

        if (index >= 0):
            return object[index]
        else:
            return object
            
    def __ClearObject(self, key):
        self.children[key] = None
    
    def __GetObject(self, key):
        return self.children.get(key)
        
    def __GetCountObject(self, key):
        count = 0
        try:
            count = len(self.__GetObject(key))
        except:
            count = 0
        return count
        
    def __OnClickButton(self, eventKey):
        def _exit():
            self.OnPressEscapeKey()
            
        def _refresh():
            net.SendChatPacket("/refresh_itemshop")

        eventDict = {
            "exit" : (lambda : (_exit())),
            "refresh" : (lambda : (_refresh())),
        }
        
        try:
            eventDict.get(eventKey, lambda *arg: None)()
        except:
            import exception
            exception.Abort("<uiitemshop.py> - __OnClickButton")
        
    def __OnClickCategoryButton(self, category):
        button = self.__GetObject("radio_button")
        for btn in button:
            btn.SetUp()
            
        button[category].Down()

        self.categoryIndex = category
        self.CreateItems()
    
    def CreateItems(self):
        (window, listBox, imageBox, textLine) = self.__GetObject("items_box")
        listBox.RemoveAllItems()

        items = getItems(self.categoryIndex)
        for item in items:
            listBox.AppendItem(
                ItemShopItem(
                    {
                        "itemToolTip" : self.itemToolTip,
                        "category" : self.categoryIndex,
                        "confirm" : self.windowDict.get("confirm"),
                        "number" : item[0],
                        "item_vnum" : item[1],
                        "item_count" : item[2],
                        "item_price" : item[3],
                        "currency" : item[4],
                    }
                )
            )
            
    def RefreshItems(self):
        self.__OnClickCategoryButton(self.categoryIndex)
        
    def BindWindow(self, windowDict):
        self.windowDict = windowDict
            
    def Destroy(self):
        self.itemToolTip = None
        self.windowDict = {}
        self.children = {}

    def SetItemToolTip(self, itemToolTip):
        self.itemToolTip = itemToolTip
    
    # def OnUpdate(self):
        # for banner in self.__GetObject("bar_blank"):
            # banner.SetColor(grp.GenerateColor(1.0, 1.0, 1.0, self.alphaColor))
            
        # self.alphaColor += 0.004
        # if (self.alphaColor >= 0.3):
            # self.alphaColor = 0.1
            
    def RefreshCash(self):
        coins = getCash("coins")
        points = getCash("points")
        
        (textLine, imageBox, ) = self.__GetObject("information_text")[0]
        textLine.SetText(getLocaleName("information_textline_0") % coins)
        
        (textLine, imageBox, ) = self.__GetObject("information_text")[1]
        textLine.SetText(getLocaleName("information_textline_1") % points)
    
    def OpenWindow(self):
        if (self.IsShow() == True):
            self.Hide()
        else:
            self.Show()
            
    def OnPressEscapeKey(self):
        self.Hide()
        return True
        
    OnPressExitKey = OnPressEscapeKey

class FortuneWheelWindow(ui.Window):
    windowConfig = {
        "size" : (569, 482),
        "flag" : ("movable", ),
    }
    
    class TextToolTip(ui.Window):
        def __init__(self):
            ui.Window.__init__(self, "TOP_MOST")

            textLine = ui.TextLine()
            textLine.SetParent(self)
            textLine.SetHorizontalAlignCenter()
            textLine.SetOutline()
            textLine.Show()
            self.textLine = textLine

        def __del__(self):
            ui.Window.__del__(self)

        def SetText(self, text):
            self.textLine.SetText(text)

        def OnRender(self):
            (mouseX, mouseY) = wndMgr.GetMousePosition()
            self.textLine.SetPosition(mouseX, mouseY - 15)
    
    def __init__(self):
        ui.Window.__init__(self)
        
        self.toolTipFortune = None
        self.itemToolTip = None
        self.priceType = 0

        self.children = {}
        self.windowDict = {}
        self.itemDict = {}
        
        self.fortuneSettings = {
            "speed" : 5,
            "time" : 0.1,
            "animate" : False,
            "blink" : False,
            "blinkCount" : 6,
            "blinkLast" : 0,
            "pos" : 1,
            "toPos" : 16,
            "lastClock" : 0
        }
        
        def _loadWindow():
            self.SetSize(self.windowConfig.get("size")[0], self.windowConfig.get("size")[1])
            map(self.AddFlag, self.windowConfig.get("flag"))
            self.SetCenterPosition()
            
            toolTipFortune = self.TextToolTip()
            toolTipFortune.Hide()
            self.toolTipFortune = toolTipFortune
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self)
            imageBox.AddFlag("attach")
            imageBox.SetPosition(0, 0)
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.SetWindowVerticalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "fortune_wheel_window_image.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("image_board", imageBox)
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self.__GetObject("image_board"))
            imageBox.AddFlag("attach")
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.SetWindowVerticalAlignBottom()
            imageBox.LoadImage(IMAGE_PATH + "fortune_background.png")
            imageBox.SetPosition(0, imageBox.GetHeight() + 5)
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("fortune_background", imageBox)
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self.__GetObject("fortune_background"))
            imageBox.SetPosition(153, 12)
            imageBox.LoadImage(IMAGE_PATH + "fortune.png")
            imageBox.Show()
            
            self.__AddObject("fortune", imageBox)
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self.__GetObject("fortune"))
            imageBox.SetPosition(0, 0)
            imageBox.LoadImage(IMAGE_PATH + "fortune/1.tga")
            imageBox.Hide()
            
            self.__AddObject("selected_fortune", imageBox)
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self.__GetObject("fortune_background"))
            imageBox.SetPosition(0, -20)
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "misc/bar_large.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("image_bar", imageBox)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetParent("image_bar"))
            textLine.SetPosition(0, 0)
            textLine.SetText(getLocaleName("information_textline_5"))
            textLine.SetWindowHorizontalAlignCenter()
            textLine.SetWindowVerticalAlignCenter()
            textLine.SetHorizontalAlignCenter()
            textLine.SetVerticalAlignCenter()
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            btnSize = (155, (36 + 6), )
            for btn in ("itemshop_large", "return", ):
                button = ui.Button()
                button.SetParent(self.__GetParent("image_board"))
                button.SetUpVisual(IMAGE_PATH + "%s_0.png" % btn)
                button.SetOverVisual(IMAGE_PATH + "%s_1.png" % btn)
                button.SetDownVisual(IMAGE_PATH + "%s_2.png" % btn)
                button.SetEvent(ui.__mem_func__(self.__OnClickButton), btn)
                button.SetPosition(20, 20 + (btnSize[1] * self.__GetCountObject("button")))
                button.UpdateRect()
                button.Show()
            
                self.__AddObject("button", button, True)
                
            def createCoinsTextLine(i, pos, desc, withImage = False):
                textLine = ui.TextLine()
                textLine.SetParent(self.__GetParent("image_board"))
                textLine.SetPosition(pos[0] + (25 if (withImage == True) else 0), pos[1])
                textLine.SetText(desc)
                textLine.Show()
                if (withImage == True):
                    imageBox = ui.ImageBox()
                    imageBox.SetParent(textLine)
                    imageBox.SetPosition(-15, 6)
                    imageBox.SetWindowHorizontalAlignCenter()
                    imageBox.SetWindowVerticalAlignCenter()
                    imageBox.LoadImage(IMAGE_PATH + "misc/image_%d.png" % min(1, i))
                    imageBox.UpdateRect()
                    imageBox.Show()
                    return (textLine, imageBox, )
                return (textLine, )
                
            pos = (190, 39)
            for i in xrange(2):
                self.__AddObject("information_text", createCoinsTextLine(i, (pos[0], pos[1] + 24 * i), getLocaleName("information_textline_%d" % i), False if (i == 2) else True), True)

            button = ui.Button()
            button.SetParent(self.__GetObject("fortune"))
            button.SetPosition(125, 124)
            button.SetUpVisual  (IMAGE_PATH + "start_0.tga")
            button.SetOverVisual(IMAGE_PATH + "start_1.tga")
            button.SetDownVisual(IMAGE_PATH + "start_2.tga")
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "start")
            button.Show()
            
            self.__AddObject("button", button, True)
            
            slotPos = (
                (151, 25),
                (197, 35),
                (238, 65),
                (267, 107),
                (280, 154),
                (267, 200),
                (238, 243),
                (197, 270),
                (150, 279),
                (104, 268),
                (62, 241),
                (34, 201),
                (20, 155),
                (31, 105),
                (60, 64),
                (102, 35)
            )
            
            for i in xrange(len(slotPos)):
                slotWindow = ui.SlotWindow()
                slotWindow.SetParent(self.__GetObject("fortune"))
                slotWindow.SetPosition(slotPos[0], slotPos[1])
                slotWindow.SetSize(32, 64 if (i == 0) else 32)
                slotWindow.AppendSlot(i, 0, 0, 32, 64 if (i == 0) else 32)
                slotWindow.SetOverInItemEvent(ui.__mem_func__(self.__OnOverInItem))
                slotWindow.SetOverOutItemEvent(ui.__mem_func__(self.__OnOverOutItem))
                slotWindow.Show()
                
                self.__AddObject("slot_window", slotWindow, True)
                
            self.__AddObject("checkbox", CheckBox(self, 35, 170, lambda arg = 0 : self.__SetTypeFortune(arg), "d:/ymir work/ui/public/Parameter_Slot_00.sub"), True)
            self.__AddObject("checkbox", CheckBox(self, 35, 195, lambda arg = 1 : self.__SetTypeFortune(arg), "d:/ymir work/ui/public/Parameter_Slot_00.sub"), True)
            
            button = ui.Button()
            button.SetParent(self.__GetParent("image_board"))
            button.SetUpVisual(IMAGE_PATH + "refresh_0.png")
            button.SetOverVisual(IMAGE_PATH + "refresh_1.png")
            button.SetDownVisual(IMAGE_PATH + "refresh_2.png")
            button.SetPosition(button.GetWidth() + 33, 12)
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "refresh")
            button.SetWindowHorizontalAlignRight()
            button.UpdateRect()
            button.Show()
            
            self.__AddObject("button", button, True)
            
            button = ui.Button()
            button.SetParent(self.__GetParent("image_board"))
            button.SetUpVisual(IMAGE_PATH + "exit_0.png")
            button.SetOverVisual(IMAGE_PATH + "exit_1.png")
            button.SetDownVisual(IMAGE_PATH + "exit_2.png")
            button.SetPosition(button.GetWidth() + 10, 10)
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "exit")
            button.SetWindowHorizontalAlignRight()
            button.UpdateRect()
            button.Show()
            
            self.__AddObject("button", button, True)

            self.__SetTypeFortune(0)
    
        _loadWindow()
        
    def __del__(self):
        ui.Window.__del__(self)
        
    def __AddObject(self, key, object, asList = False):
        if (not self.children.get(key, None)):
            if (asList == True):
                self.children[key] = [object]
            else:
                self.children[key] = object
        else:
            self.children[key].append(object)
            
    def __GetParent(self, key, index = -1):
        object = self.children.get(key, None)
        
        if (object is None):
            return self

        if (index >= 0):
            return object[index]
        else:
            return object
            
    def __ClearObject(self, key):
        self.children[key] = None
    
    def __GetObject(self, key):
        return self.children.get(key)
        
    def __GetCountObject(self, key):
        count = 0
        try:
            count = len(self.__GetObject(key))
        except:
            count = 0
        return count
        
    def FortuneWheel(self, type, args):
        if (type == "config"):
            self.OnRun(args[0], args[1])
        else:
            self.OnPrepare(args[0], args[1], args[2])

    def __SetTypeFortune(self, index):
        for checkBox in self.__GetObject("checkbox"):
            checkBox.SetCheck(False)
            
        self.priceType = index
        self.__GetObject("checkbox")[index].SetCheck(True)
        
    def OnPrepare(self, slot, itemVnum, itemCount):
        self.__GetObject("slot_window")[slot].SetItemSlot(slot, itemVnum, itemCount)
        self.itemDict[slot] = itemVnum
        
    def OnRun(self, toPos, speed):
        self.fortuneSettings['toPos'] = toPos
        self.fortuneSettings['speed'] = speed
        self.fortuneSettings['blinkCount'] = 6
        self.fortuneSettings['blinkLast'] = 0
        self.fortuneSettings['pos'] = 1
        self.fortuneSettings['animate'] = True
        self.fortuneSettings['blink'] = False
        self.fortuneSettings['time'] = 0.1
        self.fortuneSettings['lastClock'] = app.GetTime()    
        
        self.__GetObject("button")[2].Disable()
        
    def __ClearItemSlot(self):
        i = 0
        for slot in self.__GetObject("slot_window"):
            slot.ClearSlot(i)
            slot.RefreshSlot()
            
            i += 1
        
    def __OnOverInItem(self, slotPos):
        if (self.itemToolTip):
            items = self.itemDict.get(slotPos)
            
            if (items == 0):
                return False
                
            self.itemToolTip.SetItemToolTip(items)
            self.itemToolTip.ShowToolTip() 
        
    def __OnOverOutItem(self):
        if (self.itemToolTip):
            self.itemToolTip.ClearToolTip() 
            self.itemToolTip.HideToolTip() 
        
    def __OnClickButton(self, eventKey):
        def _openItemShop():
            if (self.OnPressEscapeKey() == False):
                return False
            if (self.windowDict.get("itemshop")):
                self.windowDict.get("itemshop").OpenWindow()
                
        def _openMain():
            if (self.OnPressEscapeKey() == False):
                return False

            if (self.windowDict.get("main")):
                self.windowDict.get("main").OpenWindow()
                
        def _exit():
            if (self.OnPressEscapeKey() == False):
                return False
            
        def _refresh():
            net.SendChatPacket("/refresh_itemshop")
            
        def _start():
            net.SendChatPacket("/fortune_wheel %d" % self.priceType)

        eventDict = {
            "itemshop_large" : (lambda : (_openItemShop())),
            "return" : (lambda : (_openMain())),
            "exit" : (lambda : (_exit())),
            "refresh" : (lambda : (_refresh())),
            "start" : (lambda : (_start())),
        }
        
        try:
            eventDict.get(eventKey, lambda *arg: None)()
        except:
            import exception
            exception.Abort("<uiitemshop.py> - __OnClickButton")
                
    def RefreshCash(self):
        coins = getCash("coins")
        points = getCash("points")
        
        (textLine, imageBox, )  = self.__GetObject("information_text")[0]
        textLine.SetText(getLocaleName("information_textline_0") % coins)
        
        (textLine, imageBox, )  = self.__GetObject("information_text")[1]
        textLine.SetText(getLocaleName("information_textline_1") % points)

    def BindWindow(self, windowDict):
        self.windowDict = windowDict
        
    def SetItemToolTip(self, itemToolTip):
        self.itemToolTip = itemToolTip
        
    def Destroy(self):
        self.priceType = 0
        self.itemToolTip = None
        
        self.windowDict = {}
        self.children = {}
        self.itemDict = {}
        
        self.fortuneSettings = {
            "speed" : 5,
            "time" : 0.1,
            "animate" : False,
            "blink" : False,
            "blinkCount" : 6,
            "blinkLast" : 0,
            "pos" : 1,
            "toPos" : 16,
            "lastClock" : 0
        }
        
    def OnUpdate(self):
        if (self.fortuneSettings.get("animate") == True):
            if (app.GetTime() - self.fortuneSettings.get("lastClock") >= self.fortuneSettings.get("time")):
                
                self.fortuneSettings["lastClock"] = app.GetTime()
                self.fortuneSettings["toPos"] -= 1
                
                if (self.fortuneSettings.get("toPos") <= self.fortuneSettings.get("speed")):
                    self.fortuneSettings["time"] += 0.1
                
                self.fortuneSettings["pos"] += 1
                if (self.fortuneSettings.get("pos") == 17):
                    self.fortuneSettings["pos"] = 1
                
                if (self.__GetObject("selected_fortune").IsShow() == False):
                    self.__GetObject("selected_fortune").Show()
                
                self.__GetObject("selected_fortune").LoadImage(IMAGE_PATH + "fortune/%d.tga" % self.fortuneSettings.get("pos"))
                
                if (self.fortuneSettings.get("toPos") == 0):
                    self.fortuneSettings["animate"] = False
                    self.fortuneSettings["blink"] = True
                    
                    self.__GetObject("button")[2].Enable()
                    
        if (self.fortuneSettings.get("blink") == True and (app.GetTime() - self.fortuneSettings['blinkLast']) >= 0.3):
            if (self.fortuneSettings.get("blinkCount") > 0):
                if (self.fortuneSettings.get("blinkCount") % 2):
                    self.__GetObject("selected_fortune").Hide()
                else:
                    self.__GetObject("selected_fortune").Show()
                self.fortuneSettings['blinkCount'] -= 1
            else:    
                self.fortuneSettings['blink'] = False
                self.fortuneSettings['blinkCount'] = 6
                self.fortuneSettings['blinkLast'] = 0
                
                self.__GetObject("selected_fortune").LoadImage(IMAGE_PATH + "fortune/1.tga")
                self.__GetObject("selected_fortune").Hide()
                
                net.SendChatPacket("/fortune_wheel 2")
                net.SendChatPacket("/refresh_itemshop")
                self.__ClearItemSlot()
                
            self.fortuneSettings['blinkLast'] = app.GetTime()    

        self.toolTipFortune.Hide()
        
        for i in xrange(self.__GetCountObject("checkbox")):
            if (self.__GetObject("checkbox").IsIn() == True):
                self.toolTipFortune.SetText(getLocaleName("fortune_wheel_%d" % i))
                self.toolTipFortune.Show()
                break
    
    def OpenWindow(self):
        if (self.IsShow() == True):
            self.OnPressEscapeKey()
        else:
            self.Show()
            
    def OnPressEscapeKey(self):
        if (self.fortuneSettings.get("animate") == True):
            return False
            
        if (self.toolTipFortune.IsShow() == True):
            self.toolTipFortune.Hide()
            
        self.Hide()
        return True
        
    OnPressExitKey = OnPressEscapeKey
    
class MainWindow(ui.Window):
    windowConfig = {
        "size" : (800, 500),
        "flag" : ("movable", ),
    }
    
    def __init__(self):
        ui.Window.__init__(self)
        
        self.alphaColor = 0.1
        self.itemToolTip = None
        self.children = {}
        
        def _loadWindow():
            self.SetSize(self.windowConfig.get("size")[0], self.windowConfig.get("size")[1])
            map(self.AddFlag, self.windowConfig.get("flag"))
            self.SetCenterPosition()
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self)
            imageBox.AddFlag("attach")
            imageBox.SetPosition(0, 0)
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.SetWindowVerticalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "main_window_image.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("image_board", imageBox)
            
            window = ui.Window()
            window.SetParent(self.__GetParent("image_board"))
            window.AddFlag("attach")
            window.SetPosition(0, 30)
            window.SetSize(imageBox.GetWidth() - 50, 100)
            window.SetWindowHorizontalAlignCenter()
            window.UpdateRect()
            window.Show()
            
            self.__AddObject("information_board", window)
            
            btnSize = (155, (36 + 6), )
            for btn in ("itemshop_middle", "fortune_wheel", ):
                button = ui.Button()
                button.SetParent(self.__GetParent("information_board"))
                button.SetUpVisual(IMAGE_PATH + "%s_0.png" % btn)
                button.SetOverVisual(IMAGE_PATH + "%s_1.png" % btn)
                button.SetDownVisual(IMAGE_PATH + "%s_2.png" % btn)
                button.SetEvent(ui.__mem_func__(self.__OnClickButton), btn)
                button.SetPosition(10, 10 + (btnSize[1] * self.__GetCountObject("button")))
                button.UpdateRect()
                button.Show()
            
                self.__AddObject("button", button, True)

            def createCoinsTextLine(i, pos, desc, withImage = False):
                textLine = ui.TextLine()
                textLine.SetParent(self.__GetParent("information_board"))
                textLine.SetPosition(pos[0] + (25 if (withImage == True) else 0), pos[1])
                textLine.SetText(desc)
                textLine.Show()
                if (withImage == True):
                    imageBox = ui.ImageBox()
                    imageBox.SetParent(textLine)
                    imageBox.SetPosition(-15, 6)
                    imageBox.SetWindowHorizontalAlignCenter()
                    imageBox.SetWindowVerticalAlignCenter()
                    imageBox.LoadImage(IMAGE_PATH + "misc/image_%d.png" % min(1, i))
                    imageBox.UpdateRect()
                    imageBox.Show()
                    return (textLine, imageBox, )
                return (textLine, )
                
            pos = (180, 15)
            for i in xrange(3):
                if (i == 2):
                    pos = (200, 33)
                self.__AddObject("information_text", createCoinsTextLine(i, (pos[0], pos[1] + 21 * i), getLocaleName("information_textline_%d" % i), False if (i == 2) else True), True)
        
            bar = ui.Bar()
            bar.SetParent(self.__GetParent("image_board"))
            bar.AddFlag("attach")
            bar.SetPosition(30, 173)
            bar.SetSize(260, 285)
            bar.SetColor(0x35500000)
            bar.UpdateRect()
            bar.Show()
            
            self.__AddObject("player_items_board", bar)
            
            imageBox = ui.ImageBox()
            imageBox.SetParent(self.__GetParent("player_items_board"))
            imageBox.SetPosition(0, -27)
            imageBox.SetWindowHorizontalAlignCenter()
            imageBox.LoadImage(IMAGE_PATH + "misc/bar_small.png")
            imageBox.UpdateRect()
            imageBox.Show()
            
            self.__AddObject("image_bar", imageBox, True)
            
            textLine = ui.TextLine()
            textLine.SetParent(self.__GetParent("image_bar", 0))
            textLine.SetPosition(0, 0)
            textLine.SetText(getLocaleName("information_textline_3"))
            textLine.SetWindowHorizontalAlignCenter()
            textLine.SetWindowVerticalAlignCenter()
            textLine.SetHorizontalAlignCenter()
            textLine.SetVerticalAlignCenter()
            textLine.UpdateRect()
            textLine.Show()
            
            self.__AddObject("textline", textLine, True)
            
            for i in ((301, 135), (302, 336), (443, 336)):
                imageBox = ui.ImageBox()
                imageBox.SetParent(self.__GetParent("image_board"))
                imageBox.AddFlag("attach")
                imageBox.SetPosition(i[0] + 10, i[1] + 10)
                imageBox.LoadImage(IMAGE_PATH + "banners/banner_%d.png" % self.__GetCountObject("banners"))
                imageBox.UpdateRect()
                imageBox.Show()
                
                self.__AddObject("banners", imageBox, True)
                
                if (i == (301, 135)):
                    bar = ui.Bar()
                    bar.SetParent(imageBox)
                    bar.SetPosition(0, 0)
                    bar.SetSize(imageBox.GetWidth(), imageBox.GetHeight())
                    bar.SetColor(0x40FFFFFF)
                    bar.Show()
                
                    self.__AddObject("bar_blank", bar)
                
            def createItem(slotIndex, yPos):
                window = ui.Window()
                window.SetParent(self.__GetParent("player_items_board"))
                window.SetPosition(0, yPos)
                window.SetWindowHorizontalAlignCenter()
                window.SetSize(240, 42)
                window.UpdateRect()
                window.Show()
                imageBox = ui.ImageBox()
                imageBox.SetParent(window)
                imageBox.SetPosition(0, 0)
                imageBox.LoadImage(IMAGE_PATH + "itemshop_slot.png")
                imageBox.UpdateRect()
                imageBox.Show()
                bar = ui.Bar()
                bar.SetParent(window)
                bar.SetPosition(imageBox.GetWidth() + 5, 1)
                bar.SetSize(window.GetWidth() - imageBox.GetWidth() - 5, 18)
                bar.SetColor(0x70000000)
                bar.UpdateRect()
                bar.Show()

                textLine = []
                for i in xrange(2): textLine.append(ui.TextLine())

                textLine[0].SetParent(bar)
                textLine[0].SetPosition(1, -1)
                textLine[0].SetText(getLocaleName("itemname"))
                textLine[0].SetWindowVerticalAlignCenter()
                textLine[0].SetVerticalAlignCenter()
                textLine[0].UpdateRect()
                textLine[0].Show()
                
                textLine[1].SetParent(bar)
                textLine[1].SetPosition(1, -1)
                textLine[1].SetText(getLocaleName("price"))
                textLine[1].SetWindowHorizontalAlignRight()
                textLine[1].SetWindowVerticalAlignCenter()
                textLine[1].SetHorizontalAlignRight()
                textLine[1].SetVerticalAlignCenter()
                textLine[1].UpdateRect()
                textLine[1].Show()
                
                button = ui.Button()
                button.SetParent(window)
                button.SetUpVisual(IMAGE_PATH + "buy_now_0.png")
                button.SetOverVisual(IMAGE_PATH + "buy_now_1.png")
                button.SetDownVisual(IMAGE_PATH + "buy_now_2.png")
                button.SetPosition(imageBox.GetWidth() + 2, button.GetHeight() - 2)
                button.SetWindowVerticalAlignBottom()
                button.UpdateRect()
                button.Show()
                
                slotWindow = ui.SlotWindow()
                slotWindow.SetParent(imageBox)
                slotWindow.SetPosition(0, 0)
                slotWindow.SetSize(32, 32)
                slotWindow.AppendSlot(slotIndex, 0, 0, 32, 32)
                slotWindow.SetWindowHorizontalAlignCenter()
                slotWindow.SetWindowVerticalAlignCenter()
                slotWindow.SetOverInItemEvent(ui.__mem_func__(self.__OnOverInItem))
                slotWindow.SetOverOutItemEvent(ui.__mem_func__(self.__OnOverOutItem))
                slotWindow.UpdateRect()
                slotWindow.Show()

                return (window, imageBox, bar, textLine, button, slotWindow, )
                
            yPos = 10
            for i in xrange(configItemShop("max_items")):
                self.__AddObject("items", createItem(i, yPos + 43 * i), True)
                
            button = ui.Button()
            button.SetParent(self.__GetParent("image_board"))
            button.SetUpVisual(IMAGE_PATH + "refresh_0.png")
            button.SetOverVisual(IMAGE_PATH + "refresh_1.png")
            button.SetDownVisual(IMAGE_PATH + "refresh_2.png")
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "refresh")
            button.SetPosition(button.GetWidth() + 40, 20)
            button.SetWindowHorizontalAlignRight()
            button.UpdateRect()
            button.Show()
            
            self.__AddObject("button", button, True)
            
            button = ui.Button()
            button.SetParent(self.__GetParent("image_board"))
            button.SetUpVisual(IMAGE_PATH + "exit_0.png")
            button.SetOverVisual(IMAGE_PATH + "exit_1.png")
            button.SetDownVisual(IMAGE_PATH + "exit_2.png")
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "exit")
            button.SetPosition(button.GetWidth() + 17, 18)
            button.SetWindowHorizontalAlignRight()
            button.UpdateRect()
            button.Show()
            
            self.__AddObject("button", button, True)
            
        def _loadOtherWindow():
            wndItemShop = ItemShopWindow()
            wndItemShop.Hide()
            self.wndItemShop = wndItemShop
            
            wndFortuneWheel = FortuneWheelWindow()
            wndFortuneWheel.BindWindow({"itemshop" : self.wndItemShop, "main" : self})
            wndFortuneWheel.Hide()
            self.wndFortuneWheel = wndFortuneWheel
            
            wndConfirmWindow = ConfirmWindow()
            wndConfirmWindow.Hide()
            self.wndConfirmWindow = wndConfirmWindow
            
            self.wndItemShop.BindWindow({"confirm" : self.wndConfirmWindow})
        
        _loadWindow()
        _loadOtherWindow()

    def __del__(self):
        ui.Window.__del__(self)
        
    def __AddObject(self, key, object, asList = False):
        if (not self.children.get(key, None)):
            if (asList == True):
                self.children[key] = [object]
            else:
                self.children[key] = object
        else:
            self.children[key].append(object)
            
    def __GetParent(self, key, index = -1):
        object = self.children.get(key, None)
        
        if (object is None):
            return self

        if (index >= 0):
            return object[index]
        else:
            return object
            
    def __ClearObject(self, key):
        self.children[key] = None
    
    def __GetObject(self, key):
        return self.children.get(key)
        
    def __GetCountObject(self, key):
        count = 0
        try:
            count = len(self.__GetObject(key))
        except:
            count = 0
        return count
        
    def __OnOverInItem(self, slotPos):
        if (self.itemToolTip):
            items = getItems(configItemShop("category_player"))
            
            itemTuple = items[slotPos]
                
            self.itemToolTip.SetItemToolTip(itemTuple[1])
            self.itemToolTip.ShowToolTip() 
        
    def __OnOverOutItem(self):
        if (self.itemToolTip):
            self.itemToolTip.ClearToolTip() 
            self.itemToolTip.HideToolTip() 
        
    def __OnClickButton(self, eventKey, args = None):
        def _openItemShop():
            self.Hide()
            if (self.wndItemShop):
                self.wndItemShop.OpenWindow()
                
            if (self.wndConfirmWindow.IsShow() == True):
                self.wndConfirmWindow.ClearItem()
                self.wndConfirmWindow.Hide()
                
        def _openFortuneWheel():
            self.Hide()
            if (self.wndFortuneWheel):
                self.wndFortuneWheel.OpenWindow()

            if (self.wndConfirmWindow.IsShow() == True):
                self.wndConfirmWindow.ClearItem()
                self.wndConfirmWindow.Hide()
                
        def _buyItem(args):
            items = getItems(configItemShop("category_player"))[args]
            confirmWindow = self.wndConfirmWindow
            if (confirmWindow.IsShow() == True):
                confirmWindow.LoadItem(
                    items[1],
                    items[0],
                    items[2],
                    items[3],
                    items[4],
                    configItemShop("category_player"),
                )
                return True
            confirmWindow.LoadItem(
                items[1],
                items[0],
                items[2],
                items[3],
                items[4],
                configItemShop("category_player"),
            )
            confirmWindow.OpenWindow()
            
        def _exit():
            self.OnPressEscapeKey()
            
        def _refresh():
            net.SendChatPacket("/refresh_itemshop")

        eventDict = {
            "itemshop_middle" : (lambda : (_openItemShop())),
            "fortune_wheel" : (lambda : (_openFortuneWheel())),
            "buy" : (lambda : (_buyItem(args))),
            "exit" : (lambda : (_exit())),
            "refresh" : (lambda : (_refresh())),
        }
        
        try:
            eventDict.get(eventKey, lambda *arg: None)()
        except:
            import exception
            exception.Abort("<uiitemshop.py> - __OnClickButton")
            
    def __RefreshCash(self):
        coins = getCash("coins")
        points = getCash("points")
        
        (textLine, imageBox, )  = self.__GetObject("information_text")[0]
        textLine.SetText(getLocaleName("information_textline_0") % coins)
        
        (textLine, imageBox, )  = self.__GetObject("information_text")[1]
        textLine.SetText(getLocaleName("information_textline_1") % points)
        
    def SetItemToolTip(self, itemToolTip):
        self.itemToolTip = itemToolTip
        if (self.wndItemShop):
            self.wndItemShop.SetItemToolTip(itemToolTip)

        if (self.wndFortuneWheel):
            self.wndFortuneWheel.SetItemToolTip(itemToolTip)
            
        if (self.wndConfirmWindow):
            self.wndConfirmWindow.SetItemToolTip(itemToolTip)
            
    def RefreshItemShop(self):
        self.__RefreshItems()
        if (self.wndItemShop):
            self.wndItemShop.RefreshItems()
            
    def RefreshCash(self):
        self.__RefreshCash()
        if (self.wndItemShop):
            self.wndItemShop.RefreshCash()

        if (self.wndFortuneWheel):
            self.wndFortuneWheel.RefreshCash()
            
    def FortuneWheel(self, type, args):
        if (self.wndFortuneWheel):
            self.wndFortuneWheel.FortuneWheel(type, args)
        
    def __RefreshItems(self):
        items = getItems(configItemShop("category_player"))
            
        for i in xrange(configItemShop("max_items")):
            (window, imageBox, bar, textLine, button, slotWindow, ) = self.__GetObject("items")

            itemTuple = items

            window.Show()
            item.SelectItem(itemTuple[1])
            
            textLine[0].SetText("• " + item.GetItemName())
            textLine[1].SetText("|cFFFFC700|h%d %s|r" % (itemTuple[3], getLocaleName("currency")[itemTuple[4]]))
            
            slotWindow.SetItemSlot(slotWindow.GetStartIndexEx(), itemTuple[1], 0 if (itemTuple[2] == 1) else itemTuple[2])
            
            button.SetEvent(ui.__mem_func__(self.__OnClickButton), "buy", i)

    def Destroy(self):
        self.itemToolTip = None
        
        if (self.wndItemShop):
            self.wndItemShop.Destroy()
            
        if (self.wndFortuneWheel):
            self.wndFortuneWheel.Destroy()
            
        if (self.wndConfirmWindow):
            self.wndConfirmWindow.Destroy()

        self.wndItemShop = None
        self.wndFortuneWheel = None
        self.wndConfirmWindow = None

        self.children = {}
        
    def OnUpdate(self):
        if (self.__GetObject("bar_blank")):
            self.__GetObject("bar_blank").SetColor(grp.GenerateColor(1.0, 1.0, 1.0, self.alphaColor))
            
        self.alphaColor += 0.004
        if (self.alphaColor >= 0.35):
            self.alphaColor = 0.1

    def OpenWindow(self):
        windows = (self.wndFortuneWheel, self.wndItemShop, self.wndConfirmWindow)
        hideWindows = filter(lambda arg : arg.IsShow(), windows)
        map(lambda arg : arg.Hide(), hideWindows)
        
        if (self.IsShow() == True):
            self.Hide()
        else:
            self.Show()
            
    def OnPressEscapeKey(self):
        self.Hide()
        return True
        
    OnPressExitKey = OnPressEscapeKey
 

 

  • Love 1
Link to comment
https://metin2.dev/topic/20354-help-item-shop-button/
Share on other sites

Don't use any images from : imgur, turkmmop, freakgamers, inforge, hizliresim... Or your content will be deleted without notice...
Use : https://metin2.download/media/add/

Please use https://metin2.download/ when uploading files smaller than 100MB, otherwise the approval will take longer due to manual upload.

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.