Guest User

MailFrame.Lua

a guest
Jun 23rd, 2013
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 37.92 KB | None | 0 0
  1. INBOXITEMS_TO_DISPLAY = 7;
  2. STATIONERY_ICON_ROW_HEIGHT = 36;
  3. STATIONERYITEMS_TO_DISPLAY = 5;
  4. PACKAGEITEMS_TO_DISPLAY = 4;
  5. ATTACHMENTS_MAX = 16;
  6. ATTACHMENTS_MAX_SEND = 12;
  7. ATTACHMENTS_PER_ROW_SEND = 7;
  8. ATTACHMENTS_MAX_ROWS_SEND = 2;
  9. ATTACHMENTS_MAX_RECEIVE = 16;
  10. ATTACHMENTS_PER_ROW_RECEIVE = 7;
  11. ATTACHMENTS_MAX_ROWS_RECEIVE = 3;
  12. STATIONERY_PATH = "Interface\\Stationery\\";
  13. MAX_COD_AMOUNT = 10000;
  14. SEND_MAIL_TAB_LIST = {};
  15. SEND_MAIL_TAB_LIST[1] = "SendMailNameEditBox";
  16. SEND_MAIL_TAB_LIST[2] = "SendMailSubjectEditBox";
  17. SEND_MAIL_TAB_LIST[3] = "SendMailBodyEditBox";
  18. SEND_MAIL_TAB_LIST[4] = "SendMailMoneyGold";
  19. SEND_MAIL_TAB_LIST[5] = "SendMailMoneyCopper";
  20.  
  21. function MailFrame_OnLoad(self)
  22.     -- Init pagenum
  23.     InboxFrame.pageNum = 1;
  24.     -- Tab Handling code
  25.     self.maxTabWidth = self:GetWidth() / 3;
  26.     PanelTemplates_SetNumTabs(self, 2);
  27.     PanelTemplates_SetTab(self, 1);
  28.     -- Register for events
  29.     self:RegisterEvent("MAIL_SHOW");
  30.     self:RegisterEvent("MAIL_INBOX_UPDATE");
  31.     self:RegisterEvent("MAIL_CLOSED");
  32.     self:RegisterEvent("MAIL_SEND_INFO_UPDATE");
  33.     self:RegisterEvent("MAIL_SEND_SUCCESS");
  34.     self:RegisterEvent("MAIL_FAILED");
  35.     self:RegisterEvent("MAIL_SUCCESS");
  36.     self:RegisterEvent("CLOSE_INBOX_ITEM");
  37.     self:RegisterEvent("MAIL_LOCK_SEND_ITEMS");
  38.     self:RegisterEvent("MAIL_UNLOCK_SEND_ITEMS");
  39.     -- Set previous and next fields
  40.     MoneyInputFrame_SetPreviousFocus(SendMailMoney, SendMailBodyEditBox);
  41.     MoneyInputFrame_SetNextFocus(SendMailMoney, SendMailNameEditBox);
  42.     MoneyFrame_SetMaxDisplayWidth(SendMailMoneyFrame, 160);
  43.    
  44.     if IsTrialAccount() then
  45.         MailFrameTab2:Hide();
  46.         self.trialError:Show();
  47.     end
  48. end
  49.  
  50. function MailFrame_OnEvent(self, event, ...)
  51.     if ( event == "MAIL_SHOW" ) then
  52.         ShowUIPanel(MailFrame);
  53.         if ( not MailFrame:IsShown() ) then
  54.             CloseMail();
  55.             return;
  56.         end
  57.  
  58.         -- Update the roster so auto-completion works
  59.         if ( IsInGuild() and GetNumGuildMembers() == 0 ) then
  60.             GuildRoster();
  61.         end
  62.  
  63.         OpenAllBags(self);
  64.         SendMailFrame_Update();
  65.         MailFrameTab_OnClick(nil, 1);
  66.         CheckInbox();
  67.         DoEmote("READ", nil, true);
  68.     elseif ( event == "MAIL_INBOX_UPDATE" ) then
  69.         InboxFrame_Update();
  70.         OpenMail_Update();
  71.     elseif ( event == "MAIL_SEND_INFO_UPDATE" ) then
  72.         SendMailFrame_Update();
  73.     elseif ( event == "MAIL_SEND_SUCCESS" ) then
  74.         SendMailFrame_Reset();
  75.         PlaySound("igAbiliityPageTurn");
  76.         -- If open mail frame is open then switch the mail frame back to the inbox
  77.         if ( SendMailFrame.sendMode == "reply" ) then
  78.             MailFrameTab_OnClick(nil, 1);
  79.         end
  80.     elseif ( event == "MAIL_FAILED" ) then
  81.         SendMailMailButton:Enable();
  82.     elseif ( event == "MAIL_SUCCESS" ) then
  83.         SendMailMailButton:Enable();
  84.         if ( InboxNextPageButton:IsEnabled() ~= 0 ) then
  85.             InboxGetMoreMail();
  86.         end
  87.     elseif ( event == "MAIL_CLOSED" ) then
  88.         CancelEmote();
  89.         HideUIPanel(MailFrame);
  90.         CloseAllBags(self);
  91.         SendMailFrameLockSendMail:Hide();
  92.         StaticPopup_Hide("CONFIRM_MAIL_ITEM_UNREFUNDABLE");
  93.     elseif ( event == "CLOSE_INBOX_ITEM" ) then
  94.         local arg1 = ...;
  95.         if ( arg1 == InboxFrame.openMailID ) then
  96.             HideUIPanel(OpenMailFrame);
  97.         end
  98.     elseif ( event == "MAIL_LOCK_SEND_ITEMS" ) then
  99.         local slotNum, itemLink = ...;
  100.         SendMailFrameLockSendMail:Show();
  101.         local itemName, itemLink, itemRarity, itemLevel, itemMinLevel, itemType, itemSubType, itemStackCount, itemEquipLoc, itemTexture = GetItemInfo(itemLink);
  102.         local r, g, b = GetItemQualityColor(itemRarity)
  103.         StaticPopup_Show("CONFIRM_MAIL_ITEM_UNREFUNDABLE", nil, nil, {["texture"] = itemTexture, ["name"] = itemName, ["color"] = {r, g, b, 1}, ["link"] = itemLink, ["slot"] = slotNum});
  104.     elseif ( event == "MAIL_UNLOCK_SEND_ITEMS") then
  105.         SendMailFrameLockSendMail:Hide();
  106.         StaticPopup_Hide("CONFIRM_MAIL_ITEM_UNREFUNDABLE");
  107.     end
  108. end
  109.  
  110. function MailFrameTab_OnClick(self, tabID)
  111.     if ( not tabID ) then
  112.         tabID = self:GetID();
  113.     end
  114.     PanelTemplates_SetTab(MailFrame, tabID);
  115.     if ( tabID == 1 ) then
  116.         -- Inbox tab clicked
  117.         ButtonFrameTemplate_HideButtonBar(MailFrame)
  118.         MailFrameInset:SetPoint("TOPLEFT", 4, -58);
  119.         InboxFrame:Show();
  120.         SendMailFrame:Hide();
  121.         SetSendMailShowing(false);
  122.     else
  123.         -- Sendmail tab clicked
  124.         ButtonFrameTemplate_ShowButtonBar(MailFrame)
  125.         MailFrameInset:SetPoint("TOPLEFT", 4, -80);
  126.         InboxFrame:Hide();
  127.         SendMailFrame:Show();
  128.         SendMailFrame_Update();
  129.         SetSendMailShowing(true);
  130.  
  131.         -- Set the send mode to dictate the flow after a mail is sent
  132.         SendMailFrame.sendMode = "send";
  133.     end
  134.     PlaySound("igSpellBookOpen");
  135. end
  136.  
  137. -- Inbox functions
  138.  
  139. function InboxFrame_Update()
  140.     local numItems, totalItems = GetInboxNumItems();
  141.     local index = ((InboxFrame.pageNum - 1) * INBOXITEMS_TO_DISPLAY) + 1;
  142.     local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemCount, wasRead, x, y, z, isGM, firstItemQuantity;
  143.     local icon, button, expireTime, senderText, subjectText, buttonIcon;
  144.    
  145.     if ( totalItems > numItems ) then
  146.         if ( not InboxFrame.maxShownMails ) then
  147.             InboxFrame.maxShownMails = numItems;
  148.         end
  149.         InboxFrame.overflowMails = totalItems - numItems;
  150.         InboxFrame.shownMails = numItems;
  151.     else
  152.         InboxFrame.overflowMails = nil;
  153.     end
  154.    
  155.     for i=1, INBOXITEMS_TO_DISPLAY do
  156.         if ( index <= numItems ) then
  157.             -- Setup mail item
  158.             packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemCount, wasRead, x, y, z, isGM, firstItemQuantity = GetInboxHeaderInfo(index);
  159.            
  160.             -- Set icon
  161.             if ( packageIcon ) and ( not isGM ) then
  162.                 icon = packageIcon;
  163.             else
  164.                 icon = stationeryIcon;
  165.             end
  166.  
  167.            
  168.             -- If no sender set it to "Unknown"
  169.             if ( not sender ) then
  170.                 sender = UNKNOWN;
  171.             end
  172.             button = _G["MailItem"..i.."Button"];
  173.             button:Show();
  174.             button.index = index;
  175.             button.hasItem = itemCount;
  176.             button.itemCount = itemCount;
  177.             SetItemButtonCount(button, firstItemQuantity);
  178.             buttonIcon = _G["MailItem"..i.."ButtonIcon"];
  179.             buttonIcon:SetTexture(icon);
  180.             subjectText = _G["MailItem"..i.."Subject"];
  181.             subjectText:SetText(subject);
  182.             senderText = _G["MailItem"..i.."Sender"];
  183.             senderText:SetText(sender);
  184.            
  185.             -- If hasn't been read color the button yellow
  186.             if ( wasRead ) then
  187.                 senderText:SetTextColor(0.75, 0.75, 0.75);
  188.                 subjectText:SetTextColor(0.75, 0.75, 0.75);
  189.                 _G["MailItem"..i.."ButtonSlot"]:SetVertexColor(0.5, 0.5, 0.5);
  190.                 SetDesaturation(buttonIcon, 1);
  191.             else
  192.                 senderText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  193.                 subjectText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  194.                 _G["MailItem"..i.."ButtonSlot"]:SetVertexColor(1.0, 0.82, 0);
  195.                 SetDesaturation(buttonIcon, nil);
  196.             end
  197.             -- Format expiration time
  198.             if ( daysLeft >= 1 ) then
  199.                 daysLeft = GREEN_FONT_COLOR_CODE..format(DAYS_ABBR, floor(daysLeft)).." "..FONT_COLOR_CODE_CLOSE;
  200.             else
  201.                 daysLeft = RED_FONT_COLOR_CODE..SecondsToTime(floor(daysLeft * 24 * 60 * 60))..FONT_COLOR_CODE_CLOSE;
  202.             end
  203.             expireTime = _G["MailItem"..i.."ExpireTime"];
  204.             expireTime:SetText(daysLeft);
  205.             -- Set expiration time tooltip
  206.             if ( InboxItemCanDelete(index) ) then
  207.                 expireTime.tooltip = TIME_UNTIL_DELETED;
  208.             else
  209.                 expireTime.tooltip = TIME_UNTIL_RETURNED;
  210.             end
  211.             expireTime:Show();
  212.             -- Is a C.O.D. package
  213.             if ( CODAmount > 0 ) then
  214.                 _G["MailItem"..i.."ButtonCOD"]:Show();
  215.                 _G["MailItem"..i.."ButtonCODBackground"]:Show();
  216.                 button.cod = CODAmount;
  217.             else
  218.                 _G["MailItem"..i.."ButtonCOD"]:Hide();
  219.                 _G["MailItem"..i.."ButtonCODBackground"]:Hide();
  220.                 button.cod = nil;
  221.             end
  222.             -- Contains money
  223.             if ( money > 0 ) then
  224.                 button.money = money;
  225.             else
  226.                 button.money = nil;
  227.             end
  228.             -- Set highlight
  229.             if ( InboxFrame.openMailID == index ) then
  230.                 button:SetChecked(1);
  231.                 SetPortraitToTexture("OpenMailFrameIcon", stationeryIcon);
  232.             else
  233.                 button:SetChecked(nil);
  234.             end
  235.         else
  236.             -- Clear everything
  237.             _G["MailItem"..i.."Button"]:Hide();
  238.             _G["MailItem"..i.."Sender"]:SetText("");
  239.             _G["MailItem"..i.."Subject"]:SetText("");
  240.             _G["MailItem"..i.."ExpireTime"]:Hide();
  241.         end
  242.         index = index + 1;
  243.     end
  244.  
  245.     -- Handle page arrows
  246.     if ( InboxFrame.pageNum == 1 ) then
  247.         InboxPrevPageButton:Disable();
  248.     else
  249.         InboxPrevPageButton:Enable();
  250.     end
  251.     if ( (InboxFrame.pageNum * INBOXITEMS_TO_DISPLAY) < numItems ) then
  252.         InboxNextPageButton:Enable();
  253.     else
  254.         InboxNextPageButton:Disable();
  255.     end
  256.     if ( totalItems > numItems) then
  257.         InboxTooMuchMail:Show();
  258.     else
  259.         InboxTooMuchMail:Hide();
  260.     end
  261. end
  262.  
  263. function InboxFrame_OnClick(self, index)
  264.     if ( self:GetChecked() ) then
  265.         InboxFrame.openMailID = index;
  266.         OpenMailFrame.updateButtonPositions = true;
  267.         OpenMail_Update();
  268.         --OpenMailFrame:Show();
  269.         ShowUIPanel(OpenMailFrame);
  270.         OpenMailFrameInset:SetPoint("TOPLEFT", 4, -80);
  271.         PlaySound("igSpellBookOpen");
  272.     else
  273.         InboxFrame.openMailID = 0;
  274.         HideUIPanel(OpenMailFrame);    
  275.     end
  276.     InboxFrame_Update();
  277. end
  278.  
  279. function InboxFrame_OnModifiedClick(self, index)
  280.     local _, _, _, _, _, cod = GetInboxHeaderInfo(index);
  281.     if ( cod <= 0 ) then
  282.         AutoLootMailItem(index);
  283.     end
  284.     InboxFrame_OnClick(self, index);
  285. end
  286.  
  287. function InboxFrameItem_OnEnter(self)
  288.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  289.     if ( self.hasItem ) then
  290.         if ( self.itemCount == 1) then
  291.             local hasCooldown, speciesID, level, breedQuality, maxHealth, power, speed, name = GameTooltip:SetInboxItem(self.index);
  292.             if(speciesID and speciesID > 0) then
  293.                 BattlePetToolTip_Show(speciesID, level, breedQuality, maxHealth, power, speed, name);
  294.             end
  295.         else
  296.             GameTooltip:AddLine(MAIL_MULTIPLE_ITEMS.." ("..self.itemCount..")");
  297.         end
  298.     end
  299.     if (self.money) then
  300.         if ( self.hasItem ) then
  301.             GameTooltip:AddLine(" ");
  302.         end
  303.         GameTooltip:AddLine(ENCLOSED_MONEY, "", 1, 1, 1);
  304.         SetTooltipMoney(GameTooltip, self.money);
  305.         SetMoneyFrameColor("GameTooltipMoneyFrame1", "white");
  306.     elseif (self.cod) then
  307.         if ( self.hasItem ) then
  308.             GameTooltip:AddLine(" ");
  309.         end
  310.         GameTooltip:AddLine(COD_AMOUNT, "", 1, 1, 1);
  311.         SetTooltipMoney(GameTooltip, self.cod);
  312.         if ( self.cod > GetMoney() ) then
  313.             SetMoneyFrameColor("GameTooltipMoneyFrame1", "red");
  314.         else
  315.             SetMoneyFrameColor("GameTooltipMoneyFrame1", "white");
  316.         end
  317.     end
  318.     GameTooltip:Show();
  319. end
  320.  
  321. function InboxNextPage()
  322.     PlaySound("igMainMenuOptionCheckBoxOn");
  323.     InboxFrame.pageNum = InboxFrame.pageNum + 1;
  324.     InboxGetMoreMail();
  325.     InboxFrame_Update();
  326. end
  327.  
  328. function InboxPrevPage()
  329.     PlaySound("igMainMenuOptionCheckBoxOn");
  330.     InboxFrame.pageNum = InboxFrame.pageNum - 1;
  331.     InboxGetMoreMail();
  332.     InboxFrame_Update();
  333. end
  334.  
  335. function InboxGetMoreMail()
  336.     -- get more mails if there is an overflow and less than max are being shown
  337.     if ( InboxFrame.overflowMails and InboxFrame.shownMails < InboxFrame.maxShownMails ) then
  338.         CheckInbox();
  339.     end
  340. end
  341.  
  342. -- Open Mail functions
  343.  
  344. function OpenMailFrame_OnHide()
  345.     StaticPopup_Hide("DELETE_MAIL");
  346.     if ( not InboxFrame.openMailID ) then
  347.         InboxFrame_Update();
  348.         PlaySound("igSpellBookClose");
  349.         return;
  350.     end
  351.  
  352.     -- Determine if this is an auction temp invoice
  353.     local bodyText, texture, isTakeable, isInvoice = GetInboxText(InboxFrame.openMailID);
  354.     local isAuctionTempInvoice = false;
  355.     if ( isInvoice ) then
  356.         local invoiceType, itemName, playerName, bid, buyout, deposit, consignment, moneyDelay, etaHour, etaMin = GetInboxInvoiceInfo(InboxFrame.openMailID);
  357.         if (invoiceType == "seller_temp_invoice") then
  358.             isAuctionTempInvoice = true;
  359.         end
  360.     end
  361.    
  362.     -- If mail contains no items, then delete it on close
  363.     local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemCount, wasRead, wasReturned, textCreated  = GetInboxHeaderInfo(InboxFrame.openMailID);
  364.     if ( money == 0 and not itemCount and textCreated and not isAuctionTempInvoice ) then
  365.         DeleteInboxItem(InboxFrame.openMailID);
  366.     end
  367.     InboxFrame.openMailID = 0;
  368.     InboxFrame_Update();
  369.     PlaySound("igSpellBookClose");
  370. end
  371.  
  372. function OpenMailFrame_UpdateButtonPositions(letterIsTakeable, textCreated, stationeryIcon, money)
  373.     if ( OpenMailFrame.activeAttachmentButtons ) then
  374.         while (#OpenMailFrame.activeAttachmentButtons > 0) do
  375.             tremove(OpenMailFrame.activeAttachmentButtons);
  376.         end
  377.     else
  378.         OpenMailFrame.activeAttachmentButtons = {};
  379.     end
  380.     if ( OpenMailFrame.activeAttachmentRowPositions ) then
  381.         while (#OpenMailFrame.activeAttachmentRowPositions  > 0) do
  382.             tremove(OpenMailFrame.activeAttachmentRowPositions );
  383.         end
  384.     else
  385.         OpenMailFrame.activeAttachmentRowPositions = {};
  386.     end
  387.  
  388.     local rowAttachmentCount = 0;
  389.  
  390.     -- letter
  391.     if ( letterIsTakeable and not textCreated ) then
  392.         SetItemButtonTexture(OpenMailLetterButton, stationeryIcon);
  393.         tinsert(OpenMailFrame.activeAttachmentButtons, OpenMailLetterButton);
  394.         rowAttachmentCount = rowAttachmentCount + 1;
  395.     else
  396.         SetItemButtonTexture(OpenMailLetterButton, "");
  397.     end
  398.     -- money
  399.     if ( money == 0 ) then
  400.         SetItemButtonTexture(OpenMailMoneyButton, "");
  401.     else
  402.         SetItemButtonTexture(OpenMailMoneyButton, GetCoinIcon(money));
  403.         tinsert(OpenMailFrame.activeAttachmentButtons, OpenMailMoneyButton);
  404.         rowAttachmentCount = rowAttachmentCount + 1;
  405.     end
  406.     -- items
  407.     for i=1, ATTACHMENTS_MAX_RECEIVE do
  408.         local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID, i);
  409.         local attachmentButton = _G["OpenMailAttachmentButton"..i];
  410.         if ( name ) then
  411.             tinsert(OpenMailFrame.activeAttachmentButtons, attachmentButton);
  412.             rowAttachmentCount = rowAttachmentCount + 1;
  413.  
  414.             SetItemButtonTexture(attachmentButton, itemTexture);
  415.             SetItemButtonCount(attachmentButton, count);
  416.             if ( canUse ) then
  417.                 SetItemButtonTextureVertexColor(attachmentButton, HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  418.             else
  419.                 SetItemButtonTextureVertexColor(attachmentButton, 1.0, 0.1, 0.1);
  420.             end
  421.         else
  422.             attachmentButton:Hide();
  423.         end
  424.  
  425.         if ( rowAttachmentCount >= ATTACHMENTS_PER_ROW_RECEIVE ) then
  426.             tinsert(OpenMailFrame.activeAttachmentRowPositions, {cursorxstart=0,cursorxend=ATTACHMENTS_PER_ROW_RECEIVE - 1});
  427.             rowAttachmentCount = 0;
  428.         end
  429.     end
  430.     -- insert last row's position data
  431.     if ( rowAttachmentCount > 0 ) then
  432.         local xstart = (ATTACHMENTS_PER_ROW_RECEIVE - rowAttachmentCount) / 2;
  433.         local xend = xstart + rowAttachmentCount - 1;
  434.         tinsert(OpenMailFrame.activeAttachmentRowPositions, {cursorxstart=xstart,cursorxend=xend});
  435.     end
  436.  
  437.     -- hide unusable attachment buttons
  438.     for i=ATTACHMENTS_MAX_RECEIVE + 1, ATTACHMENTS_MAX do
  439.         _G["OpenMailAttachmentButton"..i]:Hide();
  440.     end
  441. end
  442.  
  443. function OpenMail_Update()
  444.     if ( not InboxFrame.openMailID ) then
  445.         return;
  446.     end
  447.     if ( CanComplainInboxItem(InboxFrame.openMailID) ) then
  448.         OpenMailReportSpamButton:Enable();
  449.         OpenMailReportSpamButton:Show();
  450.     else
  451.         OpenMailReportSpamButton:Hide();
  452.     end
  453.  
  454.     -- Setup mail item
  455.     local packageIcon, stationeryIcon, sender, subject, money, CODAmount, daysLeft, itemCount, wasRead, wasReturned, textCreated, canReply = GetInboxHeaderInfo(InboxFrame.openMailID);
  456.     -- Set sender and subject
  457.     if ( not sender or not canReply ) then
  458.         OpenMailReplyButton:Disable();
  459.     else
  460.         OpenMailReplyButton:Enable();
  461.     end
  462.     if ( not sender ) then
  463.         sender = UNKNOWN;
  464.     end
  465.     -- Save sender name to pass to a potential spam report
  466.     InboxFrame.openMailSender = sender;
  467.     OpenMailSender:SetText(sender);
  468.     OpenMailSubject:SetText(subject);
  469.     -- Set Text
  470.     local bodyText, texture, isTakeable, isInvoice = GetInboxText(InboxFrame.openMailID);
  471.     OpenMailBodyText:SetText(bodyText, true);
  472.     if ( texture ) then
  473.         OpenStationeryBackgroundLeft:SetTexture(STATIONERY_PATH..texture.."1");
  474.         OpenStationeryBackgroundRight:SetTexture(STATIONERY_PATH..texture.."2");
  475.     end
  476.  
  477.     -- Is an invoice
  478.     if ( isInvoice ) then
  479.         local invoiceType, itemName, playerName, bid, buyout, deposit, consignment, moneyDelay, etaHour, etaMin, count = GetInboxInvoiceInfo(InboxFrame.openMailID);
  480.         if ( playerName ) then
  481.             -- Setup based on whether player is the buyer or the seller
  482.             local buyMode;
  483.             if ( count and count > 1 ) then
  484.                 itemName = format(AUCTION_MAIL_ITEM_STACK, itemName, count);
  485.             end
  486.             if ( invoiceType == "buyer" ) then
  487.                 if ( bid == buyout ) then
  488.                     buyMode = "("..BUYOUT..")";
  489.                 else
  490.                     buyMode = "("..HIGH_BIDDER..")";
  491.                 end
  492.                 OpenMailInvoiceItemLabel:SetText(ITEM_PURCHASED_COLON.." "..itemName.."  "..buyMode);
  493.                 OpenMailInvoicePurchaser:SetText(SOLD_BY_COLON.." "..playerName);
  494.                 OpenMailInvoiceAmountReceived:SetText(AMOUNT_PAID_COLON);
  495.                 -- Clear buymode
  496.                 OpenMailInvoiceBuyMode:SetText("");
  497.                 -- Update purchase price
  498.                 MoneyFrame_Update("OpenMailTransactionAmountMoneyFrame", bid); 
  499.                 -- Position buy line
  500.                 OpenMailArithmeticLine:SetPoint("TOP", "OpenMailInvoicePurchaser", "BOTTOMLEFT", 125, 0);
  501.                 -- Not used for a purchase invoice
  502.                 OpenMailInvoiceSalePrice:Hide();
  503.                 OpenMailInvoiceDeposit:Hide();
  504.                 OpenMailInvoiceHouseCut:Hide();
  505.                 OpenMailDepositMoneyFrame:Hide();
  506.                 OpenMailHouseCutMoneyFrame:Hide();
  507.                 OpenMailSalePriceMoneyFrame:Hide();
  508.                 OpenMailInvoiceNotYetSent:Hide();
  509.                 OpenMailInvoiceMoneyDelay:Hide();
  510.             elseif (invoiceType == "seller") then
  511.                 OpenMailInvoiceItemLabel:SetText(ITEM_SOLD_COLON.." "..itemName);
  512.                 OpenMailInvoicePurchaser:SetText(PURCHASED_BY_COLON.." "..playerName);
  513.                 OpenMailInvoiceAmountReceived:SetText(AMOUNT_RECEIVED_COLON);
  514.                 -- Determine if auction was bought out or bid on
  515.                 if ( bid == buyout ) then
  516.                     OpenMailInvoiceBuyMode:SetText("("..BUYOUT..")");
  517.                 else
  518.                     OpenMailInvoiceBuyMode:SetText("("..HIGH_BIDDER..")");
  519.                 end
  520.                 -- Position buy line
  521.                 OpenMailArithmeticLine:SetPoint("TOP", "OpenMailInvoiceHouseCut", "BOTTOMRIGHT", -114, -9);
  522.                 MoneyFrame_Update("OpenMailSalePriceMoneyFrame", bid);
  523.                 MoneyFrame_Update("OpenMailDepositMoneyFrame", deposit);
  524.                 MoneyFrame_Update("OpenMailHouseCutMoneyFrame", consignment);
  525.                 SetMoneyFrameColor("OpenMailHouseCutMoneyFrame", "red");
  526.                 MoneyFrame_Update("OpenMailTransactionAmountMoneyFrame", bid+deposit-consignment);
  527.  
  528.                 -- Show these guys if the player was the seller
  529.                 OpenMailInvoiceSalePrice:Show();
  530.                 OpenMailInvoiceDeposit:Show();
  531.                 OpenMailInvoiceHouseCut:Show();
  532.                 OpenMailDepositMoneyFrame:Show();
  533.                 OpenMailHouseCutMoneyFrame:Show();
  534.                 OpenMailSalePriceMoneyFrame:Show();
  535.                 OpenMailInvoiceNotYetSent:Hide();
  536.                 OpenMailInvoiceMoneyDelay:Hide();
  537.             elseif (invoiceType == "seller_temp_invoice") then
  538.                 if ( bid == buyout ) then
  539.                     buyMode = "("..BUYOUT..")";
  540.                 else
  541.                     buyMode = "("..HIGH_BIDDER..")";
  542.                 end
  543.                 OpenMailInvoiceItemLabel:SetText(ITEM_SOLD_COLON.." "..itemName.."  "..buyMode);
  544.                 OpenMailInvoicePurchaser:SetText(PURCHASED_BY_COLON.." "..playerName);
  545.                 OpenMailInvoiceAmountReceived:SetText(AUCTION_INVOICE_PENDING_FUNDS_COLON);
  546.                 -- Clear buymode
  547.                 OpenMailInvoiceBuyMode:SetText("");
  548.                 -- Update purchase price
  549.                 MoneyFrame_Update("OpenMailTransactionAmountMoneyFrame", bid+deposit-consignment); 
  550.                 -- Position buy line
  551.                 OpenMailArithmeticLine:SetPoint("TOP", "OpenMailInvoicePurchaser", "BOTTOMLEFT", 125, 0);
  552.                 -- How long they have to wait to get the money
  553.                 OpenMailInvoiceMoneyDelay:SetFormattedText(AUCTION_INVOICE_FUNDS_DELAY, GameTime_GetFormattedTime(etaHour, etaMin, true));
  554.                 -- Not used for a temp sale invoice
  555.                 OpenMailInvoiceSalePrice:Hide();
  556.                 OpenMailInvoiceDeposit:Hide();
  557.                 OpenMailInvoiceHouseCut:Hide();
  558.                 OpenMailDepositMoneyFrame:Hide();
  559.                 OpenMailHouseCutMoneyFrame:Hide();
  560.                 OpenMailSalePriceMoneyFrame:Hide();
  561.                 OpenMailInvoiceNotYetSent:Show();
  562.                 OpenMailInvoiceMoneyDelay:Show();
  563.             end
  564.             OpenMailInvoiceFrame:Show();
  565.         end
  566.     else
  567.         OpenMailInvoiceFrame:Hide();
  568.     end
  569.  
  570.     local itemButtonCount, itemRowCount = OpenMail_GetItemCounts(isTakeable, textCreated, money);
  571.     if ( OpenMailFrame.updateButtonPositions ) then
  572.         OpenMailFrame_UpdateButtonPositions(isTakeable, textCreated, stationeryIcon, money);
  573.     end
  574.     if ( OpenMailFrame.activeAttachmentRowPositions ) then
  575.         itemRowCount = #OpenMailFrame.activeAttachmentRowPositions;
  576.     end
  577.  
  578.     -- record the original number of buttons that the mail needs
  579.     OpenMailFrame.itemButtonCount = itemButtonCount;
  580.  
  581.     -- Determine starting position for buttons
  582.     local marginxl = 10 + 4;
  583.     local marginxr = 43 + 4;
  584.     local areax = OpenMailFrame:GetWidth() - marginxl - marginxr;
  585.     local iconx = OpenMailAttachmentButton1:GetWidth() + 2;
  586.     local icony = OpenMailAttachmentButton1:GetHeight() + 2;
  587.     local gapx1 = floor((areax - (iconx * ATTACHMENTS_PER_ROW_RECEIVE)) / (ATTACHMENTS_PER_ROW_RECEIVE - 1));
  588.     local gapx2 = floor((areax - (iconx * ATTACHMENTS_PER_ROW_RECEIVE) - (gapx1 * (ATTACHMENTS_PER_ROW_RECEIVE - 1))) / 2);
  589.     local gapy1 = 3;
  590.     local gapy2 = 3;
  591.     local areay = gapy2 + OpenMailAttachmentText:GetHeight() + gapy2 + (icony * itemRowCount) + (gapy1 * (itemRowCount - 1)) + gapy2;
  592.     local indentx = marginxl + gapx2;
  593.     local indenty = 28 + gapy2;
  594.     local tabx = (iconx + gapx1) + 6; --this magic number changes the button spacing
  595.     local taby = (icony + gapy1);
  596.     local scrollHeight = 305 - areay;
  597.     if (scrollHeight > 256) then
  598.         scrollHeight = 256;
  599.         areay = 305 - scrollHeight;
  600.     end
  601.  
  602.     -- Resize the scroll frame
  603.     OpenMailScrollFrame:SetHeight(scrollHeight);
  604.     OpenMailScrollChildFrame:SetHeight(scrollHeight);
  605.     OpenMailHorizontalBarLeft:SetPoint("TOPLEFT", "OpenMailFrame", "BOTTOMLEFT", 2, 39 + areay);
  606.     OpenScrollBarBackgroundTop:SetHeight(min(scrollHeight, 256));
  607.     OpenScrollBarBackgroundTop:SetTexCoord(0, 0.484375, 0, min(scrollHeight, 256) / 256);
  608.     OpenStationeryBackgroundLeft:SetHeight(scrollHeight);
  609.     OpenStationeryBackgroundLeft:SetTexCoord(0, 1.0, 0, min(scrollHeight, 256) / 256);
  610.     OpenStationeryBackgroundRight:SetHeight(scrollHeight);
  611.     OpenStationeryBackgroundRight:SetTexCoord(0, 1.0, 0, min(scrollHeight, 256) / 256);
  612.  
  613.     -- Set attachment text
  614.     if ( itemButtonCount > 0 ) then
  615.         OpenMailAttachmentText:SetText(TAKE_ATTACHMENTS);
  616.         OpenMailAttachmentText:SetTextColor(HIGHLIGHT_FONT_COLOR.r, HIGHLIGHT_FONT_COLOR.g, HIGHLIGHT_FONT_COLOR.b);
  617.         OpenMailAttachmentText:SetPoint("TOPLEFT", "OpenMailFrame", "BOTTOMLEFT", indentx, indenty + (icony * itemRowCount) + (gapy1 * (itemRowCount - 1)) + gapy2 + OpenMailAttachmentText:GetHeight());
  618.     else
  619.         OpenMailAttachmentText:SetText(NO_ATTACHMENTS);
  620.         OpenMailAttachmentText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
  621.         OpenMailAttachmentText:SetPoint("TOPLEFT", "OpenMailFrame", "BOTTOMLEFT", marginxl + (areax - OpenMailAttachmentText:GetWidth()) / 2, indenty + (areay - OpenMailAttachmentText:GetHeight()) / 2 + OpenMailAttachmentText:GetHeight());
  622.     end
  623.     -- Set letter
  624.     if ( isTakeable and not textCreated ) then
  625.         OpenMailLetterButton:Show();
  626.     else
  627.         OpenMailLetterButton:Hide();
  628.     end
  629.     -- Set Money
  630.     if ( money == 0 ) then
  631.         OpenMailMoneyButton:Hide();
  632.         OpenMailFrame.money = nil;
  633.     else
  634.         OpenMailMoneyButton:Show();
  635.         OpenMailFrame.money = money;
  636.     end
  637.     -- Set Items
  638.     if ( itemRowCount > 0 and OpenMailFrame.activeAttachmentButtons ) then
  639.         local firstAttachName;
  640.         local rowIndex = 1;
  641.         local cursorx = OpenMailFrame.activeAttachmentRowPositions[1].cursorxstart;
  642.         local cursorxend = OpenMailFrame.activeAttachmentRowPositions[1].cursorxend;
  643.         local cursory = itemRowCount - 1;
  644.         for i, attachmentButton in pairs(OpenMailFrame.activeAttachmentButtons) do
  645.             attachmentButton:SetPoint("TOPLEFT", "OpenMailFrame", "BOTTOMLEFT", indentx + (tabx * cursorx), indenty + icony + (taby * cursory));
  646.             if ( attachmentButton ~= OpenMailLetterButton and attachmentButton ~= OpenMailMoneyButton ) then
  647.                 local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID, attachmentButton:GetID());
  648.                 if ( name and cursory >= 0 ) then
  649.                     if ( not firstAttachName ) then
  650.                         firstAttachName = name;
  651.                     end
  652.  
  653.                     attachmentButton:Enable();
  654.                     attachmentButton:Show();
  655.                 else
  656.                     attachmentButton:Hide();
  657.                 end
  658.             end
  659.  
  660.             cursorx = cursorx + 1;
  661.             if (cursorx > cursorxend) then
  662.                 rowIndex = rowIndex + 1;
  663.  
  664.                 cursory = cursory - 1;
  665.                 if ( rowIndex <= itemRowCount ) then
  666.                     cursorx = OpenMailFrame.activeAttachmentRowPositions[rowIndex].cursorxstart;
  667.                     cursorxend = OpenMailFrame.activeAttachmentRowPositions[rowIndex].cursorxend;
  668.                 end
  669.             end
  670.         end
  671.  
  672.         OpenMailFrame.itemName = firstAttachName;
  673.     else
  674.         OpenMailFrame.itemName = nil;
  675.     end
  676.  
  677.     -- Set COD
  678.     if ( CODAmount > 0 ) then
  679.         OpenMailFrame.cod = CODAmount;
  680.     else
  681.         OpenMailFrame.cod = nil;
  682.     end
  683.     -- Set button to delete or return to sender
  684.     if ( InboxItemCanDelete(InboxFrame.openMailID) ) then
  685.         OpenMailDeleteButton:SetText(DELETE);
  686.     else
  687.         OpenMailDeleteButton:SetText(MAIL_RETURN);
  688.     end
  689. end
  690.  
  691. function OpenMail_GetItemCounts(letterIsTakeable, textCreated, money)
  692.     local itemButtonCount = 0;
  693.     local itemRowCount = 0;
  694.     local numRows = 0;
  695.     if ( letterIsTakeable and not textCreated ) then
  696.         itemButtonCount = itemButtonCount + 1;
  697.         itemRowCount = itemRowCount + 1;
  698.     end
  699.     if ( money ~= 0 ) then
  700.         itemButtonCount = itemButtonCount + 1;
  701.         itemRowCount = itemRowCount + 1;
  702.     end
  703.     for i=1, ATTACHMENTS_MAX_RECEIVE do
  704.         local name, itemTexture, count, quality, canUse = GetInboxItem(InboxFrame.openMailID, i);
  705.         if ( name ) then
  706.             itemButtonCount = itemButtonCount + 1;
  707.             itemRowCount = itemRowCount + 1;
  708.         end
  709.  
  710.         if ( itemRowCount >= ATTACHMENTS_PER_ROW_RECEIVE ) then
  711.             numRows = numRows + 1;
  712.             itemRowCount = 0;
  713.         end
  714.     end
  715.     if ( itemRowCount > 0 ) then
  716.         numRows = numRows + 1;
  717.     end
  718.     return itemButtonCount, numRows;
  719. end
  720.  
  721. function OpenMail_Reply()
  722.     MailFrameTab_OnClick(nil, 2);
  723.     SendMailNameEditBox:SetText(OpenMailSender:GetText())
  724.     local subject = OpenMailSubject:GetText();
  725.     local prefix = MAIL_REPLY_PREFIX.." ";
  726.     if ( strsub(subject, 1, strlen(prefix)) ~= prefix ) then
  727.         subject = prefix..subject;
  728.     end
  729.     SendMailSubjectEditBox:SetText(subject)
  730.     SendMailBodyEditBox:SetFocus();
  731.  
  732.     -- Set the send mode so the work flow can change accordingly
  733.     SendMailFrame.sendMode = "reply";
  734. end
  735.  
  736. function OpenMail_Delete()
  737.     if ( InboxItemCanDelete(InboxFrame.openMailID) ) then
  738.         if ( OpenMailFrame.itemName ) then
  739.             StaticPopup_Show("DELETE_MAIL", OpenMailFrame.itemName);
  740.             return;
  741.         elseif ( OpenMailFrame.money ) then
  742.             StaticPopup_Show("DELETE_MONEY");
  743.             return;
  744.         else
  745.             DeleteInboxItem(InboxFrame.openMailID);
  746.         end
  747.     else
  748.         ReturnInboxItem(InboxFrame.openMailID);
  749.         StaticPopup_Hide("COD_CONFIRMATION");
  750.     end
  751.     InboxFrame.openMailID = nil;
  752.     HideUIPanel(OpenMailFrame);
  753. end
  754.  
  755. function OpenMail_ReportSpam()
  756.     local dialog = StaticPopup_Show("CONFIRM_REPORT_SPAM_MAIL", InboxFrame.openMailSender);
  757.     if ( dialog ) then
  758.         dialog.data = InboxFrame.openMailID;
  759.     end
  760.     OpenMailReportSpamButton:Disable();
  761. end
  762.  
  763. function OpenMailAttachment_OnEnter(self, index)
  764.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  765.     local hasCooldown, speciesID, level, breedQuality, maxHealth, power, speed, name = GameTooltip:SetInboxItem(InboxFrame.openMailID, index);
  766.     if(speciesID and speciesID > 0) then
  767.         BattlePetToolTip_Show(speciesID, level, breedQuality, maxHealth, power, speed, name);
  768.     end
  769.  
  770.     if ( OpenMailFrame.cod ) then
  771.         SetTooltipMoney(GameTooltip, OpenMailFrame.cod);
  772.         if ( OpenMailFrame.cod > GetMoney() ) then
  773.             SetMoneyFrameColor("GameTooltipMoneyFrame1", "red");
  774.         else
  775.             SetMoneyFrameColor("GameTooltipMoneyFrame1", "white");
  776.         end
  777.     end
  778.     GameTooltip:Show();
  779. end
  780.  
  781. function OpenMailAttachment_OnClick(self, index)
  782.     if ( OpenMailFrame.cod and (OpenMailFrame.cod > GetMoney()) ) then
  783.         StaticPopup_Show("COD_ALERT");
  784.     elseif ( OpenMailFrame.cod ) then
  785.         OpenMailFrame.lastTakeAttachment = index;
  786.         StaticPopup_Show("COD_CONFIRMATION");
  787.         OpenMailFrame.updateButtonPositions = false;
  788.     else
  789.         TakeInboxItem(InboxFrame.openMailID, index);
  790.         OpenMailFrame.updateButtonPositions = false;
  791.     end
  792.     PlaySound("igMainMenuOptionCheckBoxOn");
  793. end
  794.  
  795. -- SendMail functions
  796.  
  797. function SendMailMailButton_OnClick(self)
  798.     self:Disable();
  799.     local copper = MoneyInputFrame_GetCopper(SendMailMoney);
  800.     SetSendMailCOD(0);
  801.     SetSendMailMoney(0);
  802.     if ( SendMailSendMoneyButton:GetChecked() ) then
  803.         -- Send Money
  804.         if ( copper > 0 ) then
  805.             -- Open confirmation dialog
  806.             StaticPopup_Show("SEND_MONEY", SendMailNameEditBox:GetText());
  807.             return;
  808.         end
  809.     else
  810.         -- Send C.O.D.
  811.         if ( copper > 0 ) then
  812.             SetSendMailCOD(copper);
  813.         end
  814.     end
  815.     SendMailFrame_SendMail();
  816. end
  817.  
  818. function SendMailFrame_SendMail()
  819.     SendMail(SendMailNameEditBox:GetText(), SendMailSubjectEditBox:GetText(), SendMailBodyEditBox:GetText());
  820. end
  821.  
  822. function SendMailFrame_Update()
  823.     -- Update the item(s) being sent
  824.     local itemCount = 0;
  825.     local itemTitle;
  826.     local gap;
  827.     local last = 0;
  828.     for i=1, ATTACHMENTS_MAX_SEND do
  829.         -- get info about the attachment
  830.         local itemName, itemTexture, stackCount, quality = GetSendMailItem(i);
  831.         -- set attachment texture info
  832.         _G["SendMailAttachment"..i]:SetNormalTexture(itemTexture);
  833.         -- set the stack count
  834.         if ( stackCount <= 1 ) then
  835.             _G["SendMailAttachment"..i.."Count"]:SetText("");
  836.         else
  837.             _G["SendMailAttachment"..i.."Count"]:SetText(stackCount);
  838.         end
  839.         -- determine what a name for the message in case it doesn't already have one
  840.         if ( itemName ) then
  841.             itemCount = itemCount + 1;
  842.             if ( not itemTitle ) then
  843.                 if ( stackCount <= 1 ) then
  844.                     itemTitle = itemName;
  845.                 else
  846.                     itemTitle = itemName.." ("..stackCount..")";
  847.                 end
  848.             end
  849.             if ((last + 1) ~= i) then
  850.                 gap = 1;
  851.             end
  852.             last = i;
  853.         end
  854.     end
  855.     -- Enable or disable C.O.D. depending on whether or not there's an item to send
  856.     if ( itemCount > 0 ) then
  857.         SendMailCODButton:Enable();
  858.         SendMailCODButtonText:SetTextColor(NORMAL_FONT_COLOR.r, NORMAL_FONT_COLOR.g, NORMAL_FONT_COLOR.b);
  859.  
  860.         if ( SendMailSubjectEditBox:GetText() == "" or SendMailSubjectEditBox:GetText() == SendMailFrame.previousItem ) then
  861.             SendMailSubjectEditBox:SetText(itemTitle);
  862.             SendMailFrame.previousItem = itemTitle;
  863.         end
  864.     else
  865.         -- If no itemname see if the subject is the name of the previously held item, if so clear the subject
  866.         if ( SendMailSubjectEditBox:GetText() == SendMailFrame.previousItem ) then
  867.             SendMailSubjectEditBox:SetText("");
  868.         end
  869.         SendMailFrame.previousItem = "";
  870.  
  871.         SendMailRadioButton_OnClick(1);
  872.         SendMailCODButton:Disable();
  873.         SendMailCODButtonText:SetTextColor(GRAY_FONT_COLOR.r, GRAY_FONT_COLOR.g, GRAY_FONT_COLOR.b);
  874.     end
  875.     -- Update the cost
  876.     MoneyFrame_Update("SendMailCostMoneyFrame", GetSendMailPrice());   
  877.    
  878.     -- Color the postage text
  879.     if ( GetSendMailPrice() > GetMoney() ) then
  880.         SetMoneyFrameColor("SendMailCostMoneyFrame", "red");
  881.     else
  882.         SetMoneyFrameColor("SendMailCostMoneyFrame", "white");
  883.     end
  884.  
  885.     -- Determine how many rows of attachments to show
  886.     local itemRowCount = 1;
  887.     local temp = last;
  888.     while ((temp > ATTACHMENTS_PER_ROW_SEND) and (itemRowCount < ATTACHMENTS_MAX_ROWS_SEND)) do
  889.         itemRowCount = itemRowCount + 1;
  890.         temp = temp - ATTACHMENTS_PER_ROW_SEND;
  891.     end
  892.     if (not gap and (temp == ATTACHMENTS_PER_ROW_SEND) and (itemRowCount < ATTACHMENTS_MAX_ROWS_SEND)) then
  893.         itemRowCount = itemRowCount + 1;
  894.     end
  895.     if (SendMailFrame.maxRowsShown and (last > 0) and (itemRowCount < SendMailFrame.maxRowsShown)) then
  896.         itemRowCount = SendMailFrame.maxRowsShown;
  897.     else
  898.         SendMailFrame.maxRowsShown = itemRowCount;
  899.     end
  900.  
  901.     -- Compute sizes
  902.     local cursorx = 0;
  903.     local cursory = itemRowCount - 1;
  904.     local marginxl = 8 + 6;
  905.     local marginxr = 40 + 6;
  906.     local areax = SendMailFrame:GetWidth() - marginxl - marginxr;
  907.     local iconx = SendMailAttachment1:GetWidth() + 2;
  908.     local icony = SendMailAttachment1:GetHeight() + 2;
  909.     local gapx1 = floor((areax - (iconx * ATTACHMENTS_PER_ROW_SEND)) / (ATTACHMENTS_PER_ROW_SEND - 1));
  910.     local gapx2 = floor((areax - (iconx * ATTACHMENTS_PER_ROW_SEND) - (gapx1 * (ATTACHMENTS_PER_ROW_SEND - 1))) / 2);
  911.     local gapy1 = 5;
  912.     local gapy2 = 6;
  913.     local areay = (gapy2 * 2) + (gapy1 * (itemRowCount - 1)) + (icony * itemRowCount);
  914.     local indentx = marginxl + gapx2;
  915.     local indenty = 170 + gapy2 + icony;
  916.     local tabx = (iconx + gapx1) - 2; --this magic number changes the attachment spacing
  917.     local taby = (icony + gapy1);
  918.     local scrollHeight = 249 - areay;
  919.  
  920.     -- Resize the scroll frame
  921.     SendMailScrollFrame:SetHeight(scrollHeight);
  922.     SendMailScrollChildFrame:SetHeight(scrollHeight);
  923.     SendMailHorizontalBarLeft2:SetPoint("TOPLEFT", "SendMailFrame", "BOTTOMLEFT", 2, 184 + areay);
  924.     SendScrollBarBackgroundTop:SetHeight(min(scrollHeight, 256));
  925.     SendScrollBarBackgroundTop:SetTexCoord(0, 0.484375, 0, min(scrollHeight, 256) / 256);
  926.     SendStationeryBackgroundLeft:SetHeight(min(scrollHeight, 256));
  927.     SendStationeryBackgroundLeft:SetTexCoord(0, 1.0, 0, min(scrollHeight, 256) / 256);
  928.     SendStationeryBackgroundRight:SetHeight(min(scrollHeight, 256));
  929.     SendStationeryBackgroundRight:SetTexCoord(0, 1.0, 0, min(scrollHeight, 256) / 256);
  930.    
  931.     -- Set Items
  932.     for i=1, ATTACHMENTS_MAX_SEND do
  933.         if (cursory >= 0) then
  934.             _G["SendMailAttachment"..i]:Enable();
  935.             _G["SendMailAttachment"..i]:Show();
  936.             _G["SendMailAttachment"..i]:SetPoint("TOPLEFT", "SendMailFrame", "BOTTOMLEFT", indentx + (tabx * cursorx), indenty + (taby * cursory));
  937.            
  938.             cursorx = cursorx + 1;
  939.             if (cursorx >= ATTACHMENTS_PER_ROW_SEND) then
  940.                 cursory = cursory - 1;
  941.                 cursorx = 0;
  942.             end
  943.         else
  944.             _G["SendMailAttachment"..i]:Hide();
  945.         end
  946.     end
  947.     for i=ATTACHMENTS_MAX_SEND+1, ATTACHMENTS_MAX do
  948.         _G["SendMailAttachment"..i]:Hide();
  949.     end
  950.  
  951.     SendMailFrame_CanSend();
  952. end
  953.  
  954. function SendMailFrame_Reset()
  955.     SendMailNameEditBox:SetText("");
  956.     SendMailNameEditBox:SetFocus();
  957.     SendMailSubjectEditBox:SetText("");
  958.     SendMailBodyEditBox:SetText("");
  959.     StationeryPopupFrame.selectedIndex = nil;
  960.     SendMailFrame_Update();
  961.     StationeryPopupButton_OnClick(nil, 1);
  962.     MoneyInputFrame_ResetMoney(SendMailMoney);
  963.     SendMailRadioButton_OnClick(1);
  964.     SendMailFrame.maxRowsShown = 0;
  965. end
  966.  
  967. function SendMailFrame_CanSend()
  968.     local checks = 0;
  969.     local checksRequired = 3;
  970.     -- If has stationery
  971.     if ( StationeryPopupFrame.selectedIndex ~= nil ) then
  972.         checks = checks + 1;
  973.     end
  974.     -- and has a sendee
  975.     if ( strlen(SendMailNameEditBox:GetText()) > 0 ) then
  976.         checks = checks + 1;
  977.     end
  978.     -- and has a subject
  979.     if ( strlen(SendMailSubjectEditBox:GetText()) > 0 ) then
  980.         checks = checks + 1;
  981.     end
  982.     -- check c.o.d. amount
  983.     if ( SendMailCODButton:GetChecked() ) then
  984.         checksRequired = 4;
  985.         -- COD must be less than 10000 gold
  986.         if ( MoneyInputFrame_GetCopper(SendMailMoney) > MAX_COD_AMOUNT*COPPER_PER_GOLD ) then
  987.             if ( ENABLE_COLORBLIND_MODE ~= "1" ) then
  988.                 SendMailErrorCoin:Show();
  989.             end
  990.             SendMailErrorText:Show();          
  991.         else
  992.             SendMailErrorText:Hide();
  993.             SendMailErrorCoin:Hide();
  994.             checks = checks + 1;
  995.         end
  996.     end
  997.    
  998.     if ( checks == checksRequired ) then
  999.         SendMailMailButton:Enable();
  1000.     else
  1001.         SendMailMailButton:Disable();
  1002.     end
  1003. end
  1004.  
  1005. function SendMailRadioButton_OnClick(index)
  1006.     if ( index == 1 ) then
  1007.         SendMailSendMoneyButton:SetChecked(1);
  1008.         SendMailCODButton:SetChecked(nil);
  1009.         SendMailMoneyText:SetText(AMOUNT_TO_SEND);
  1010.     else
  1011.         SendMailSendMoneyButton:SetChecked(nil);
  1012.         SendMailCODButton:SetChecked(1);
  1013.         SendMailMoneyText:SetText(COD_AMOUNT);
  1014.     end
  1015.     PlaySound("igMainMenuOptionCheckBoxOn");
  1016. end
  1017.  
  1018. -- Stationery functions
  1019.  
  1020. function StationeryPopupFrame_Update()
  1021.     local numStationeries = GetNumStationeries();
  1022.     local index = FauxScrollFrame_GetOffset(StationeryPopupScrollFrame) + 1;
  1023.     local name, texture, cost;
  1024.     local button;
  1025.     for i=1, STATIONERYITEMS_TO_DISPLAY do
  1026.         button = _G["StationeryPopupButton"..i];
  1027.         if ( index <= numStationeries ) then
  1028.             name, texture, cost = GetStationeryInfo(index);
  1029.             _G["StationeryPopupButton"..i.."Name"]:SetText(name);
  1030.             if ( cost ) then
  1031.                 MoneyFrame_Update("StationeryPopupButton"..i.."MoneyFrame", cost);
  1032.                 -- If player can't afford
  1033.                 if ( cost > GetMoney() ) then
  1034.                     button:Disable();
  1035.                     SetMoneyFrameColor("StationeryPopupButton"..i.."MoneyFrame", "red");
  1036.                 else
  1037.                     button:Enable();
  1038.                     SetMoneyFrameColor("StationeryPopupButton"..i.."MoneyFrame", "white");
  1039.                 end
  1040.             else
  1041.                 -- Is a stationery in player's inventory or is free
  1042.                 MoneyFrame_Update("StationeryPopupButton"..i.."MoneyFrame", 0);
  1043.             end
  1044.             _G["StationeryPopupButton"..i.."Icon"]:SetTexture(texture);
  1045.             button:Show();
  1046.         else
  1047.             _G["StationeryPopupButton"..i.."Name"]:SetText("");
  1048.             MoneyFrame_Update("StationeryPopupButton"..i.."MoneyFrame", 0);
  1049.             _G["StationeryPopupButton"..i.."Icon"]:SetTexture("");
  1050.             button:Hide();
  1051.         end
  1052.        
  1053.         if ( index == StationeryPopupFrame.selectedIndex ) then
  1054.             button:SetChecked(1);
  1055.         else
  1056.             button:SetChecked(nil);
  1057.         end
  1058.         button.index = index;
  1059.         index = index + 1;
  1060.     end
  1061.  
  1062.     -- Scrollbar stuff
  1063.     FauxScrollFrame_Update(StationeryPopupScrollFrame, numStationeries , STATIONERYITEMS_TO_DISPLAY, STATIONERY_ICON_ROW_HEIGHT );
  1064. end
  1065.  
  1066. function StationeryPopupButton_OnClick(self, index)
  1067.     if ( not index ) then
  1068.         index = self.index;
  1069.     end
  1070.     SelectStationery(index);
  1071.     StationeryPopupFrame.selectedIndex = index;
  1072.     SendMailFrame_CanSend()
  1073.     -- Set the stationery texture
  1074.     local texture = GetSelectedStationeryTexture();
  1075.     if ( texture ) then
  1076.         SendStationeryBackgroundLeft:SetTexture(STATIONERY_PATH..texture.."1");
  1077.         SendStationeryBackgroundRight:SetTexture(STATIONERY_PATH..texture.."2");
  1078.     end
  1079.     StationeryPopupFrame_Update();
  1080. end
  1081.  
  1082. function SendMailMoneyButton_OnClick()
  1083.     local cursorMoney = GetCursorMoney();
  1084.     if ( cursorMoney > 0 ) then
  1085.         local money = MoneyInputFrame_GetCopper(SendMailMoney);
  1086.         if ( money > 0 ) then
  1087.             cursorMoney = cursorMoney + money;
  1088.         end
  1089.         MoneyInputFrame_SetCopper(SendMailMoney, cursorMoney);
  1090.         DropCursorMoney();
  1091.     end
  1092. end
  1093.  
  1094. function SendMailAttachmentButton_OnClick(self, button)
  1095.     ClickSendMailItemButton(self:GetID(), button == "RightButton");
  1096. end
  1097.  
  1098. function SendMailAttachmentButton_OnDropAny()
  1099.     ClickSendMailItemButton();
  1100. end
  1101.  
  1102. function SendMailAttachment_OnEnter(self)
  1103.     local index = self:GetID();
  1104.     GameTooltip:SetOwner(self, "ANCHOR_RIGHT");
  1105.     if ( GetSendMailItem(index) ) then
  1106.         local hasCooldown, speciesID, level, breedQuality, maxHealth, power, speed, name = GameTooltip:SetSendMailItem(index);
  1107.         if(speciesID and speciesID > 0) then
  1108.             BattlePetToolTip_Show(speciesID, level, breedQuality, maxHealth, power, speed, name);
  1109.         end
  1110.     else
  1111.         GameTooltip:SetText(ATTACHMENT_TEXT, 1.0, 1.0, 1.0);
  1112.     end
  1113. end
Advertisement
Add Comment
Please, Sign In to add comment