Thread Tools Display Modes
08-03-05, 12:29 AM   #1
wow4me
A Deviate Faerie Dragon
Join Date: Aug 2005
Posts: 11
A lil help please

Hi there, if you guys have used CT_mod or Insomniax, youve probably seen the class box on top of the target frame showing the class of your target.

Im trying to make a simple addon that would make a similar box that is draggable which i can use with whatever mod i want. A standalone you might say.

I tried ripping code from the old money_display and CT_unitframes and came up with this.

The xml file:

<Ui xsi:schemaLocation="http://www.blizzard.com/wow/ui/">
<Script file="Myown.lua"/>
<Frame name="MyownFrame" frameStrata="BACKGROUND" toplevel="true" enableMouse="false" movable="true" parent="UIParent">
<Size>
<AbsDimension x="125" y="25"/>
</Size>
<Backdrop name="MyownBackdrop" bgFile="Interface\TutorialFrame\TutorialFrameBackground" edgeFile="Interface\Tooltips\UI-Tooltip-Border" tile="true">
<EdgeSize>
<AbsValue val="16"/>
</EdgeSize>
<TileSize>
<AbsValue val="16"/>
</TileSize>
<BackgroundInsets>
<AbsInset left="3" right="5" top="3" bottom="5"/>
</BackgroundInsets>
</Backdrop>
<Layers>
<Layer level="ARTWORK">
<FontString name="MyownText" hidden="false" inherits="GameFontNormal" text="">
<Anchors>
<Anchor point="CENTER"/>
</Anchors>
</FontString>
</Layer>
</Layers>
<Scripts>
<OnLoad>
this:SetBackdropColor(0, 0, 1, 0.5);
this:RegisterEvent("UNIT_FACTION");
this:RegisterEvent("UNIT_DYNAMIC_FLAGS");
this:RegisterEvent("PLAYER_TARGET_CHANGED");
this:RegisterEvent("PARTY_MEMBERS_CHANGED");
</OnLoad>
<OnEvent>
Myown_SetTargetClass();
if event == "VARIABLES_LOADED" then
MO_LoadVariables();
end
</OnEvent>
<OnMouseDown>
if ( arg1 == "LeftButton" ) then
MyownFrame:StartMoving();
end
</OnMouseDown>
<OnMouseUp>
if ( arg1 == "LeftButton" ) then
MyownFrame:StopMovingOrSizing();
MO_SavePosition();
end
</OnMouseUp>

</Scripts>
</Frame>
</Frame>
</Ui>


The Lua file:
function Myown_SetTargetClass()
if ( not UnitExists("target") ) then return; end
local r, g, b;
r = 0; g = 0; b = 1;
if ( UnitPlayerControlled("target") ) then
if ( UnitCanAttack("target", "player") ) then
-- Hostile players are red
if ( not UnitCanAttack("player", "target") ) then
r = 0.0;
g = 0.0;
b = 1.0;
else
r = UnitReactionColor[2].r;
g = UnitReactionColor[2].g;
b = UnitReactionColor[2].b;
end
elseif ( UnitCanAttack("player", "target") ) then
-- Players we can attack but which are not hostile are yellow
r = UnitReactionColor[4].r;
g = UnitReactionColor[4].g;
b = UnitReactionColor[4].b;
elseif ( UnitIsPVP("target") ) then
-- Players we can assist but are PvP flagged are green
r = UnitReactionColor[6].r;
g = UnitReactionColor[6].g;
b = UnitReactionColor[6].b;
else
-- All other players are blue (the usual state on the "blue" server)
r = 0.0;
g = 0.0;
b = 1.0;
end
else
local reaction = UnitReaction("target", "player");
if ( reaction ) then
r = UnitReactionColor[reaction].r;
g = UnitReactionColor[reaction].g;
b = UnitReactionColor[reaction].b;
else
r = 0; g = 0; b = 1;
end
end

if ( r == 1 and g == 0 and b == 0 ) then
MyownFrame:SetBackdropColor(1, 0, 0, 1);
else
MyownFrame:SetBackdropColor(r, g, b, 0.5);
end
if ( UnitClass("target") ) then
MyownText:SetText(UnitClass("target"));
end
end


function MO_LoadVariables()
if not MO_Save then
MO_Save = { };
MO_Save.x = GetScreenWidth()/2;
MO_Save.y = 50;
end

getglobal("MyownFrame"):ClearAllPoints();
getglobal("MyownFrame"):SetPoint("BOTTOMLEFT", "UIParent", "BOTTOMLEFT", MD_Save.x, MD_Save.y);
end

function MO_SavePosition()
MO_Save.x = getglobal("MyownFrame"):GetLeft();
MO_Save.y = getglobal("MyownFrame"):GetBottom();
end



The toc file:
## Interface: 4150
## Title: Myown
## Notes: Display class
## OptionalDeps:
## Dependencies:
## SavedVariables: MO_Save
Myown.xml


I tried that but nothing appeared. Not even a small box. My initial comments would be that i removed an anchor from the main frame, is this a bad thing? Secondly, the top line of my XML may be truncated coz the usual thing i see is


<Ui xmlns="http://www.blizzard.com/wow/ui/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.blizzard.com/wow/ui/
C:\Projects\WoW\Bin\Interface\FrameXML\UI.xsd">

Is that also a cause of problems?

Like i said, i cant even see a box which i thought the initial frame in my XML would create (MyownFrame)

Thanks.
  Reply With Quote
08-03-05, 01:37 AM   #2
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
You need to change the first line to:

<Ui xmlns="http://www.blizzard.com/wow/ui/">

At the minimum. All the rest in that line is optional. The schemaLocation you have there is so xml-validating programs can find the xsd that has the rules for the markup language.

edit: You'll want to remove one of those </Frame>s at the end. That will cause the xml to not load.

Other than that your xml looks fine. The no anchor should be fine since you're anchoring it later in the mod.

When testing, if you still don't see anything, try poking at bits in game to see if the mod loaded at all:

/script message(MyownFrame)
should say Table:00061234 or something like that. Or

/script message(MyownFrame:IsVisible())

And of course you can check the FrameXML.log file in the Logs directory to see if it had problems loading the file.

--
edit again:

In the lua side, you need to register "VARIABLES_LOADED" for it to fire (this:RegisterEvent("VARIABLES_LOADED") in your OnLoad), otherwise your MO_Save will never get created. I also notice you have MD_Save.x,y in the MO_LoadVariables() function, should probably be MO_Save.

I think with that it should work fine. Tho a couple things that won't have any effect:

Instead of: getglobal("MyownFrame"):ClearAllPoints();
You can use: MyownFrame:ClearAllPoints()

Also your MO_Save seems to be only to store the last position of the window. You can let the game do this. When a player moves a window (and now when a mod moves a window with SetPoint) it stores this new position in layout-cache.txt so a mod doesn't have to handle its position.

If you set a default anchor in the xml you can remove all the MO_Save stuff. Unless of course you plan to do more with positioning and stuff.

Last edited by Gello : 08-03-05 at 01:56 AM.
  Reply With Quote
08-03-05, 03:06 AM   #3
wow4me
A Deviate Faerie Dragon
Join Date: Aug 2005
Posts: 11
you sir are my new hero!! thanks so much for replying. Im not at home right now so i wont be able to make the changes asap. But thanks already!!

Also, can you please enlighten me as to what you mean by

---
"Also your MO_Save seems to be only to store the last position of the window. You can let the game do this. When a player moves a window (and now when a mod moves a window with SetPoint) it stores this new position in layout-cache.txt so a mod doesn't have to handle its position.

If you set a default anchor in the xml you can remove all the MO_Save stuff. Unless of course you plan to do more with positioning and stuff."
---

So i should just put an anchor in the parent frame (MyownFrame) and then when i move it the game automatically saves the position? COOL! so i also dont need to load it then? So technically i can remove all the mo_load and mo_save?

Basically i just want to be able to move it around and keep it at a location where i drop it.

Ill be trying to also code in a simple lock and unlock slash command. but thats after i get the damn thing working.

Another question, are these
UnitPlayerControlled
UnitCanAttack
UnitReactionColor

variables defined within the game?

Thanks again man!!


edit: how do i use setpoint? or simply using a default anchor and moving it would do the job?

Last edited by wow4me : 08-03-05 at 03:09 AM.
  Reply With Quote
08-03-05, 11:15 AM   #4
Gello
A Molten Giant
AddOn Author - Click to view addons
Join Date: Jan 2005
Posts: 521
So i should just put an anchor in the parent frame (MyownFrame) and then when i move it the game automatically saves the position? COOL! so i also dont need to load it then? So technically i can remove all the mo_load and mo_save?

Basically i just want to be able to move it around and keep it at a location where i drop it.
np Yep the game will take care of restoring a window to its new position when you log in. You can think of layout-cache.txt as a "savedvariables" for window positions. It will use the original anchors in the xml, but if on loading it sees the window was moved, it will move it to where it last sat on the screen.

UnitPlayerControlled
UnitCanAttack
UnitReactionColor
I don't think the last one does. You may be thinking of r,g,b=GameTooltip_UnitColor(unit) which returns the color of the tooltip name?

Or n=UnitReaction(unit,unit) which returns a number decribing the relationship between two units. From either of those you could build a color.
  Reply With Quote
08-03-05, 07:02 PM   #5
wow4me
A Deviate Faerie Dragon
Join Date: Aug 2005
Posts: 11
thanks for the help it works well now. i just had to change the background into the tooltip texture so i can color it.

Thanks again for the help. now to make it lockable hehehe....
  Reply With Quote

WoWInterface » Developer Discussions » General Authoring Discussion » A lil help please

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off