• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

UI Natives Causing Desync?

Status
Not open for further replies.
Level 20
Joined
Jul 12, 2010
Messages
1,717
Hey everybody, so I started doing some stuff with the UI Natives but there seems to be a desync problem when I do actions locally.

I create the UI for all players and I try to modify it locally which I thought was ok but I guess not?

Also sorry in advance for noob/bad coding, jass is not my forte >_>

Testing was done in LAN, I launch 2 instances from b.net in window mode, log out and create a LAN game, dual screens also help a lot.

Here is a quick video: youtube

JASS:
function CreateIcons takes nothing returns nothing

    local framehandle InvAll = BlzCreateFrameByType("BACKDROP", "InventoryUI", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0) ,"", 0)

    local framehandle inv1 = BlzCreateFrameByType("BACKDROP", "Inventory1", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle inv1Hover = BlzCreateFrameByType("FRAME", "FaceFrame", inv1,"", 0)
    local framehandle inv1tip = BlzCreateFrame("BoxedText", inv1, 1 , 1)

    local framehandle inv2 = BlzCreateFrameByType("BACKDROP", "Inventory2", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle inv2Hover = BlzCreateFrameByType("FRAME", "FaceFrame", inv2,"", 0)
    local framehandle inv2tip = BlzCreateFrame("BoxedText", inv2, 2 , 2)

    local framehandle inv3 = BlzCreateFrameByType("BACKDROP", "Inventory3", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle inv3Hover = BlzCreateFrameByType("FRAME", "FaceFrame", inv3,"", 0)
    local framehandle inv3tip = BlzCreateFrame("BoxedText", inv3, 3 , 3)

    local framehandle inv4 = BlzCreateFrameByType("BACKDROP", "Inventory4", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle inv4Hover = BlzCreateFrameByType("FRAME", "FaceFrame", inv4,"", 0)
    local framehandle inv4tip = BlzCreateFrame("BoxedText", inv4, 4 , 4)

    local framehandle inv5 = BlzCreateFrameByType("BACKDROP", "Inventory5", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle inv5Hover = BlzCreateFrameByType("FRAME", "FaceFrame", inv5,"", 0)
    local framehandle inv5tip = BlzCreateFrame("BoxedText", inv5, 5 , 5)

    local framehandle inv6 = BlzCreateFrameByType("BACKDROP", "Inventory6", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle inv6Hover = BlzCreateFrameByType("FRAME", "FaceFrame", inv6,"", 0)
    local framehandle inv6tip = BlzCreateFrame("BoxedText", inv6, 6 , 6)

    local framehandle invtext = BlzCreateFrameByType("TEXT", "InventoryText", BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)


//======= STARTING POINT OF FIRST SLOT =======\\

    local real x = 0.550
    local real y = 0.300

//======= SETTINGS PARENTS AND HOVER FOR TOOLTIP =======\\

    call BlzFrameSetAllPoints(inv1Hover, inv1)
    call BlzFrameSetTooltip(inv1Hover, inv1tip)

    call BlzFrameSetAllPoints(inv2Hover, inv2)
    call BlzFrameSetTooltip(inv2Hover, inv2tip)

    call BlzFrameSetAllPoints(inv3Hover, inv3)
    call BlzFrameSetTooltip(inv3Hover, inv3tip)

    call BlzFrameSetAllPoints(inv4Hover, inv4)
    call BlzFrameSetTooltip(inv4Hover, inv4tip)

    call BlzFrameSetAllPoints(inv5Hover, inv5)
    call BlzFrameSetTooltip(inv5Hover, inv5tip)

    call BlzFrameSetAllPoints(inv6Hover, inv6)
    call BlzFrameSetTooltip(inv6Hover, inv6tip)

    call BlzFrameSetParent(inv1, InvAll)
    call BlzFrameSetParent(inv2, InvAll)
    call BlzFrameSetParent(inv3, InvAll)
    call BlzFrameSetParent(inv4, InvAll)
    call BlzFrameSetParent(inv5, InvAll)
    call BlzFrameSetParent(inv6, InvAll)


//=======================================================\\

    call BlzFrameSetSize(inv1tip, 0.20, 0.10)
    call BlzFrameSetAbsPoint(inv1tip, FRAMEPOINT_CENTER, x + 0.020 , y + 0.08)

    call BlzFrameSetAllPoints(inv2tip, inv1tip)
    call BlzFrameSetAllPoints(inv3tip, inv1tip)
    call BlzFrameSetAllPoints(inv4tip, inv1tip)
    call BlzFrameSetAllPoints(inv5tip, inv1tip)
    call BlzFrameSetAllPoints(inv6tip, inv1tip)

//=======================================================\\

    call BlzFrameSetSize(inv1, 0.03, 0.03)
    call BlzFrameSetSize(inv2, 0.03, 0.03)
    call BlzFrameSetSize(inv3, 0.03, 0.03)
    call BlzFrameSetSize(inv4, 0.03, 0.03)
    call BlzFrameSetSize(inv5, 0.03, 0.03)
    call BlzFrameSetSize(inv6, 0.03, 0.03)

//=======================================================\\

    call BlzFrameSetAbsPoint(inv1, FRAMEPOINT_CENTER, x , y)
    call BlzFrameSetAbsPoint(inv2, FRAMEPOINT_CENTER, x +0.04, y)
    call BlzFrameSetAbsPoint(inv3, FRAMEPOINT_CENTER, x, y-0.04 )
    call BlzFrameSetAbsPoint(inv4, FRAMEPOINT_CENTER, x +0.04, y-0.04)
    call BlzFrameSetAbsPoint(inv5, FRAMEPOINT_CENTER, x, y-0.08)
    call BlzFrameSetAbsPoint(inv6, FRAMEPOINT_CENTER, x+0.04, y-0.08)

//=======================================================\\

    call BlzFrameSetTexture(inv1, "EmptyIcon.blp",0, true)
    call BlzFrameSetTexture(inv2, "EmptyIcon.blp",0, true)
    call BlzFrameSetTexture(inv3, "EmptyIcon.blp",0, true)
    call BlzFrameSetTexture(inv4, "EmptyIcon.blp",0, true)
    call BlzFrameSetTexture(inv5, "EmptyIcon.blp",0, true)
    call BlzFrameSetTexture(inv6, "EmptyIcon.blp",0, true)

//=======================================================\\

    call BlzFrameSetParent(invtext, InvAll)
    call BlzFrameSetText(invtext, "|cffffcc00Inventory 1" )
    call BlzFrameSetAbsPoint(invtext, FRAMEPOINT_CENTER, x + 0.02 , y + 0.025)


//    call BlzFrameSetVisible(InvAll, false)

endfunction

//===========================================================================
function InitTrig_Inventory_UI_Jass takes nothing returns nothing
    set gg_trg_Inventory_UI_Jass = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Inventory_UI_Jass, 0.50 )
    call TriggerAddAction( gg_trg_Inventory_UI_Jass, function CreateIcons)
    call BlzLoadTOCFile("war3mapImported\\BoxedText.toc")
endfunction


JASS:
function clickedbutton01 takes nothing returns nothing

    local player p = GetTriggerPlayer()
    local integer pid = GetConvertedPlayerId(p)
    local integer i = udg_Inventory_Current[pid]
    local unit u
    local framehandle icon
    local string blp
    local string text
    local framehandle invtext = BlzGetFrameByName("InventoryText", 0)


//=====================================================================
//Check if it's the last unit or else increase the number
    if i == 5 then
    set i = 1
    else
    set i = i + 1
    endif


    set udg_Inventory_Current[pid] = i

//=====================================================================
//Find which Player it is to use the correct Unit Inventory Variable

    if p == Player(0) then //RED
    set u = udg_Inventory_Player1_Unit[i]
    endif
    if p == Player(1) then //BLUE
    set u = udg_Inventory_Player2_Unit[i]
    endif
    if p == Player(2) then //TEAL
    set u = udg_Inventory_Player3_Unit[i]
    endif
    if p == Player(3) then //PURPLE
    set u = udg_Inventory_Player4_Unit[i]
    endif

//=====================================================================

    if GetLocalPlayer() == GetTriggerPlayer() then


//Get the Icon Paths for Slot 1 to 6 - Also checks if slot has item or no

    set icon = BlzGetFrameByName( "Inventory1" , 0)
    if GetItemType(UnitItemInSlot(u, 0)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 0))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif

    set icon = BlzGetFrameByName( "Inventory2" , 0)
    if GetItemType(UnitItemInSlot(u, 1)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 1))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif

    set icon = BlzGetFrameByName( "Inventory3" , 0)
    if GetItemType(UnitItemInSlot(u, 2)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 2))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif

    set icon = BlzGetFrameByName( "Inventory4" , 0)
    if GetItemType(UnitItemInSlot(u, 3)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 3))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif

    set icon = BlzGetFrameByName( "Inventory5" , 0)
    if GetItemType(UnitItemInSlot(u, 4)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 4))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif

    set icon = BlzGetFrameByName( "Inventory6" , 0)
    if GetItemType(UnitItemInSlot(u, 5)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 5))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif

//=====================================================================
//Item Names and Tooltips for Slot 1 to 6

    set text = GetItemName(UnitItemInSlot(u, 0))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextTitle", 1), text)
    set text = BlzGetItemExtendedTooltip(UnitItemInSlot(u, 0))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextValue", 1), text)

    set text = GetItemName(UnitItemInSlot(u, 1))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextTitle", 2), text)
    set text = BlzGetItemExtendedTooltip(UnitItemInSlot(u, 1))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextValue", 2), text)

    set text = GetItemName(UnitItemInSlot(u, 2))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextTitle", 3), text)
    set text = BlzGetItemExtendedTooltip(UnitItemInSlot(u, 2))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextValue", 3), text)

    set text = GetItemName(UnitItemInSlot(u, 3))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextTitle", 4), text)
    set text = BlzGetItemExtendedTooltip(UnitItemInSlot(u, 3))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextValue", 4), text)

    set text = GetItemName(UnitItemInSlot(u, 4))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextTitle", 5), text)
    set text = BlzGetItemExtendedTooltip(UnitItemInSlot(u, 4))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextValue", 5), text)

    set text = GetItemName(UnitItemInSlot(u, 5))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextTitle", 6), text)
    set text = BlzGetItemExtendedTooltip(UnitItemInSlot(u, 5))
    call BlzFrameSetText(BlzGetFrameByName("BoxedTextValue", 6), text)


//======================================

    set text = "|cffffcc00Inventory " + I2S(i)
    call BlzFrameSetText(invtext, text )


    call BlzFrameSetEnable(BlzGetTriggerFrame(), false) //disable the clicked button
    call BlzFrameSetEnable(BlzGetTriggerFrame(), true) //enable it again.

    endif

endfunction

//===========================================================================

function Trig_Melee_Initialization_Actions takes nothing returns nothing

    local trigger trig01 = CreateTrigger()
    local framehandle item1 = BlzCreateFrameByType("GLUEBUTTON" , "InventoryNext" , BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle item2 = BlzCreateFrameByType("BACKDROP" , "InventoryNext" , BlzGetOriginFrame(ORIGIN_FRAME_GAME_UI, 0), "", 0)
    local framehandle invall = BlzGetFrameByName("InventoryUI", 0)

    call BlzFrameSetSize(item1, 0.015, 0.015)
    call BlzFrameSetAbsPoint(item1, FRAMEPOINT_CENTER, 0.620, 0.260)
    call BlzTriggerRegisterFrameEvent(trig01, item1 , FRAMEEVENT_CONTROL_CLICK)
    call TriggerAddAction(trig01, function clickedbutton01 )

    call BlzFrameSetAllPoints(item2, item1)
    call BlzFrameSetTexture(item2, "ReplaceableTextures\\CommandButtons\\BTNReplay-SpeedUp.blp",0, true)

    call BlzFrameSetParent(item1, invall)
    call BlzFrameSetParent(item2, invall)

endfunction

//===========================================================================
function InitTrig_Inv_Next takes nothing returns nothing
    set gg_trg_Inv_Next = CreateTrigger(  )
    call TriggerRegisterTimerEventSingle( gg_trg_Inv_Next, 0.51 )
    call TriggerAddAction( gg_trg_Inv_Next, function Trig_Melee_Initialization_Actions )
endfunction

IF possible also please check the map below, it might be more useful than just the triggers. (Press ESC to add items)
 

Attachments

  • Inventory System New Test.w3m
    26.4 KB · Views: 9

Cokemonkey11

Code Reviewer
Level 29
Joined
May 9, 2006
Messages
3,522
1. Generally speaking you should limit the scope of code that is affected by GetLocalPlayer as much as possible - i.e. do not wrap 50 lines of code in one big "if GetLocalPlayer..." block
2. I'm not an expert on framehandle desyncs but my read of this code is that you probably have desync in string interner. A better way to do this is like:

bad:

JASS:
    if GetLocalPlayer() == GetTriggerPlayer() then
    // ...
    set icon = BlzGetFrameByName( "Inventory1" , 0)
    if GetItemType(UnitItemInSlot(u, 0)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 0))
    call BlzFrameSetTexture(icon, blp ,0, true)
    else
    call BlzFrameSetTexture(icon, "EmptyIcon.blp" ,0, true)
    endif
    // ...
    endif

better:

JASS:
    set icon = BlzGetFrameByName("Inventory1", 0)
    if GetItemType(UnitItemInSlot(u, 0)) == ITEM_TYPE_PERMANENT then
      set blp = BlzGetItemIconPath(UnitItemInSlot(u, 0))
      call BlzFrameSetTexture(icon, blp, 0, true)
    else
      set blp = "EmptyIcon.blp"
    endif
    if GetLocalPlayer() == GetTriggerPlayer() then
      call BlzFrameSetTexture(icon, blp, 0, true)
    endif
 
Level 20
Joined
Jul 12, 2010
Messages
1,717
@Cokemonkey11 wow than for the fast reply dude!
I'm not 100% sure butI guess I thought having a lot of code in a local block wouldn't really matter because most of the stuff that change are locals anyway, the blp variable for example is a local string.

also your better way is also not gonna work because this:
JASS:
call BlzFrameSetTexture(icon, blp, 0, true)
still changes the icon for everybody if it's not in a local block xD

BUT I think I understand what you are trying to say and you gave me a hint on how to improve the code a bit thanks!

ALSO UI Natives don't cause desyncs, here is a little test I tried


EDIT:
AWESOME! I have actually found the problem with the help of @Cokemonkey11
I tried the following code:
JASS:
    set icon = BlzGetFrameByName( "Inventory1" , 0)
    if GetItemType(UnitItemInSlot(u, 0)) == ITEM_TYPE_PERMANENT then
    set blp = BlzGetItemIconPath(UnitItemInSlot(u, 0))
    else
    set blp = "EmptyIcon.blp"
    endif
    if GetLocalPlayer() == GetTriggerPlayer() then
    call BlzFrameSetTexture(icon, blp ,0, true)
    endif
and the problem seems to be solved! :thumbs_up:
 

Attachments

  • ui test.w3m
    10.1 KB · Views: 9
Last edited:
Status
Not open for further replies.
Top