WoWInterface

WoWInterface (https://www.wowinterface.com/forums/index.php)
-   Lua/XML Help (https://www.wowinterface.com/forums/forumdisplay.php?f=16)
-   -   Disappearing elements (https://www.wowinterface.com/forums/showthread.php?t=45728)

Xienor 01-25-13 05:01 AM

Disappearing elements
 
Hello,
This is the first time I write in these forums :).
So, yesterday I began writing my first addon. I feel like I'm doing some slow & steady progress.
However, there are a few things that I cannot understand. Can you help me? Here is my code:
Lua Code:
  1. local EventFrame = CreateFrame("Frame")
  2. Roller=LibStub("AceAddon-3.0"):NewAddon("Roller","AceConsole-3.0")
  3. local AceGUI = LibStub("AceGUI-3.0")
  4. Roller:Print("Version 0.1 succesfully loaded. Type '/roller' to bring up the UI")
  5. Roller:RegisterChatCommand("roller", "RollerClient")
  6. function Roller:RollerClient(input) --Roller Client UI section
  7.     print("Roller UI test")
  8.     local frame = AceGUI:Create("Frame") --Main Frame Definition
  9.     frame:SetTitle("Roller 0.1")
  10.     frame:SetStatusText("Type the emote in the box and  then press the button...")
  11.     frame:SetCallback("OnClose", function(widget) AceGUI:Release(widget) end)
  12.     frame:SetWidth(500)
  13.     frame:SetHeight(150)
  14.     frame:SetLayout("Flow")
  15.  
  16.     local emotebox = AceGUI:Create("EditBox") --Emote Input Box
  17.     emotebox:SetLabel("Action:")
  18.     emotebox:SetWidth(200)
  19.     --editbox:SetCallback("OnEnterPressed", function(widget, event, text) emoteText = text end)
  20. --[[Pseudocode
  21.     raid_leader=UnitName("RaidLeader")
  22.     local function whisper_roll(int_roll, leader_name)
  23.       whisper_roll(roll,raid_leader)
  24.       ChatFrame1:Type("../w.."RaidLeader".. .."roll)
  25.     end
  26. ]]--
  27.     frame:AddChild(emotebox)
  28.  
  29.     local roll = AceGUI:Create("Button") --"Roll" Button
  30.     roll:SetText("Roll!")
  31.     roll:SetWidth(200)
  32.     --roll:OnClick(print(emoteText))
  33.     frame:AddChild(roll)
  34.  
  35.     --local dice=AceGUI:Create("Icon") --Dice Icon
  36.     --dice:SetImage("Img/icon.png")
  37.     --dice:SetImageSize(32,32)
  38.     --frame:AddChild(dice)
  39. end
  40. Roller:RegisterChatCommand("rollgm","RollerGM")
  41. function Roller:RollerGM(input) --GM Options UI Definition
  42.     print("Roller GM Options UI test")
  43.     local GMframe = AceGUI:Create("Frame")
  44.     GMframe:SetTitle("Roller 0.1")
  45.     GMframe:SetHeight(250)
  46.     GMframe:SetStatusText("GM Options")
  47.    
  48.     local check1 = AceGUI:Create("CheckBox") --First Checkbox
  49.     GMframe:AddChild(check1)
  50.    
  51.     local head1 = AceGUI:Create("Heading") --Heading
  52.     --head1:SetText("Header")
  53.     GMframe:AddChild(head1)
  54.    
  55.     local drop1 = AceGUI:Create("Dropdown") --First Dropdown Box
  56.     --drop1.SetText("Setting")
  57.     GMframe:AddChild(drop1)
  58. end
What's wrong? Basically:
1. The Heading doesn't get added to the GMframe.
2. If I try to use the SetText function of the Dropdown, drop1 disappears.
3. The "Icon" object doesn't seem to work... the AceGUI documentation speaks of a generic "icon", I've tried using a 32x32 png image without transparencies AND setting the size manually. All what gets shown is a green box.

These are the errors I've stumbled upon so far... do you know what I've done wrong?
Also, is there any function that will send a whisper to a player?

Thanks in advance! :)

Farmbuyer 01-25-13 08:35 PM

Quote:

Originally Posted by Xienor (Post 272356)
1. The Heading doesn't get added to the GMframe.
2. If I try to use the SetText function of the Dropdown, drop1 disappears.

1. Make sure you've used :SetText on the heading. Empty/missing text will cause the header to hide itself.

2. I *think* that Dropdowns will hide themselves if you have not yet used :SetList to control the contents. I could be misremembering.

It's been too long since I've worked with Icons to guess at what's happening there, without the docs or the code handy.

Quote:

Also, is there any function that will send a whisper to a player?
http://www.wowpedia.org/API_SendChatMessage
http://www.wowpedia.org/API_SendAddonMessage

Phanx 01-25-13 10:09 PM

AceGUI... oh god, why? Seriously, for your first addon and something so simple, you'll learn a lot more, and end up with a better addon, if you just use the native frame API instead of AceGUI.

A few other things:

If you're using AceAddon (though, again, for something so simple, there's no need, and I would recommend avoiding libraries for your first addon until you are more familiar with the WoW API) you don't need to make a separate frame for handling events; just use AceEvent and embed it in your addon.

Don't make the only reference to your addon object a global variable. Make it local, and if you need global access, make a separate global.

Don't include "Addon version N loaded!" messages at startup. The user already knows they installed your addon, and does not need (or want) to be reminded every time they log into the game. If you think "but it's just one line of text, ignore it!" consider what it looks like when you have 10, 25, 50, or more addons all doing it. :(

Here is a quick (and drycoded) conversion of your code to the native API:

Code:

local Roller = CreateFrame("Frame", "Roller", UIParent)
Roller:SetPoint("CENTER")
Roller:SetSize(500, 150)
Roller:SetBackdrop(GameTooltip:GetBackdrop())
Roller:SetBackdropColor(0, 0, 0)
Roller:SetBackdropBorderColor(1, 1, 1)
Roller:Hide()

local Title = Roller:CreateFontString("$parentTitle", "OVERLAY", "GameFontNormal")
Title:SetPoint("TOPLEFT", Roller, 12, -12)
Title:SetText("Roller 0.1")
Roller.Title = Title

local Text = Roller:CreateFontString("$parentText", "OVERLAY", "GameFontHighlightSmall")
Text:SetPoint("TOPLEFT", Title, "BOTTOMLEFT")
Text:SetPoint("RIGHT")
Text:SetHeight(32)
Text:SetJustifyH("LEFT")
Text:SetJustifyV("TOP")
Text:SetText("Type an emote in the box and then press the button...")
Roller.Text = Text

local EmoteBox = CreateFrame("EditBox", "$parentEditBox", Roller, "InputBoxTemplate")
EmoteBox:SetPoint("TOPLEFT", Text, "BOTTOMLEFT", -4, -24)
EmoteBox:SetWidth(200)
Roller.EmoteBox = EmoteBox

local EmoteLabel = EmoteBox:CreateFontString("$parentLabel", "OVERLAY", "GameFontHighlightSmall")
EmoteLabel:SetPoint("BOTTOMLEFT", EmoteBox, "TOPLEFT")
EmoteLabel:SetText("Action:")
EmoteBox.Label = EmoteLabel

EmoteBox:SetScript("OnEnterPressed", function(self)
        local text = self:GetText()
        -- do something with the text here
end)

local RollButton = CreateFrame("Button", "$parentRollButton", Roller, "UIPanelButtonTemplate")
RollButton:SetPoint("TOPLEFT", EmoteBox, "BOTTOMLEFT", 0, -12)
RollButton:SetWidth(200)
RollButton:SetText("Roll!")
Roller.RollButton = RollButton

RollButton:SetScript("OnClick", function(self, mouseButton)
        -- do something with the click here
end)

local CloseButton = CreateFrame("Button", "$parentCloseButton", Roller, "UIPanelCloseButton")
CloseButton:SetPoint("TOPRIGHT", -12, -12)
CloseButton:SetScript("OnClick", function(self)
        self:GetParent():Hide()
end)

SLASH_ROLLER1 = "/roller"
SlashCmdList.ROLLER = function(cmd)
        if Roller:IsShown() then
                Roller:Hide()
        else
                Roller:Show()
        end
end

I left out the RollerGM frame since your code seemed like just a placeholder that didn't actually do anything yet, but there are native templates for checkboxes, dropdowns, etc. too when you get to that part.

I also left the editbox's OnEnterPressed script (mostly) empty since I couldn't figure out what your pseudo-code was supposed to be doing. If you describe that more clearly I can write something up for you.

Torhal 01-28-13 08:17 PM

Quote:

Originally Posted by Phanx (Post 272386)
AceGUI... oh god, why? Seriously, for your first addon and something so simple, you'll learn a lot more, and end up with a better addon, if you just use the native frame API instead of AceGUI.
<snip>

This happens so frequently with brand-new authors that I'm convinced it's due to the library name, since AceGUI was mainly intended for making widgets in AceConfigDialog.

"Oh, I need a GUI and here's a library for that!" /sigh

Xienor 01-30-13 07:28 AM

Quote:

I left out the RollerGM frame since your code seemed like just a placeholder that didn't actually do anything yet, but there are native templates for checkboxes, dropdowns, etc. too when you get to that part.

I also left the editbox's OnEnterPressed script (mostly) empty since I couldn't figure out what your pseudo-code was supposed to be doing. If you describe that more clearly I can write something up for you.
Hey! Thanks for the help.
Yeah, I know the pseudo-code is not really pseudo-code. And a bit messy.
Those elements were there mainly to test/play around with widgets.
Basically, that thing is supposed to:
-Make a /roll (1-100) when the "Roll!" button is pressed.
-Save the text in the box as variable.
-Send Roll & Text to the player flagged as raid leader.

Quote:

This happens so frequently with brand-new authors that I'm convinced it's due to the library name, since AceGUI was mainly intended for making widgets in AceConfigDialog.

"Oh, I need a GUI and here's a library for that!" /sigh
Exactly my reasoning. I did think making a GUI for a WoW addon manually would be needlessly messy.
So I went all like "Ohai thar, library with GUI in its name!".

Besides that, I did use the library because the project per se is much, much bigger than this.
So I was under the impression it would be easier to manage that way... even tho, I agree that "getting my hands dirty" with WoW's API would teach me much more.

Phanx 01-30-13 07:13 PM

Quote:

Originally Posted by Xienor (Post 272587)
Basically, that thing is supposed to:
-Make a /roll (1-100) when the "Roll!" button is pressed.
-Save the text in the box as variable.
-Send Roll & Text to the player flagged as raid leader.

This seems like a really insecure method of doing anything, as there's no way for the raid leader to verify that the sender's number is actually random. Someone could easily modify the addon, or just write their own addon, to always send a high number.

If you want to use rolling as a method of choosing a winner, you should just use the real /roll command, no addon communication, and have the raid leader run an addon that watches all the /rolls and announces the winner.

Billtopia 01-31-13 07:52 AM

I noticed that your image file needs to have its slashes escaped and you need the full path also
(atleast the last I knew in plain Lua not sure with any libraries but better safe than sorry)


dice:SetImage("Img/icon.png")

should be

dice:SetImage("Interface//Addons//MyAddon//icon.png")

Phanx 01-31-13 03:06 PM

Actually, they need to be backslashes, not forward slashes, but you are correct that they need to be escaped, and that the path must be relative to the WoW program folder, not the addon's folder. The escaping (doubling) is necessary because Lua treats a single backslash as the beginning of an escape sequence; for example "\n" indicates a line break, "\t" indicates a tab, etc. If you want a literal backslash, you have to escape it with a second backslash.

Also, the file extension doesn't need to be included.

Finally, you should avoid using PNG images, because they only work in the Mac client. Save them straight to TGA in Photoshop/GIMP/whatever, or save them as PNG and then convert them to BLP.

Code:

dice:SetImage("Interface\\Addons\\MyAddon\\icon")

Billtopia 01-31-13 06:06 PM

I don't believe I didn't notice that... I guess that is what moving does to you... makes you tired lol


All times are GMT -6. The time now is 09:21 PM.

vBulletin © 2024, Jelsoft Enterprises Ltd
© 2004 - 2022 MMOUI