Wc3C.net

Wc3C.net (http://www.wc3c.net/forums.php)
-   Samples (http://www.wc3c.net/forumdisplay.php?f=649)
-   -   Bags System (http://www.wc3c.net/showthread.php?t=104931)

ashujon 03-10-2009 06:56 PM

Bags System
 
3 Attachment(s)
Used DGUI system
in description there is variable - laziness to fix

All is written on vjass

3 libs: Math, Camera, DGUI
and DataBase Item + Bags System

xXm0rpH3usXx 03-10-2009 07:20 PM

probably the first coder will tell you to post the code...

i dont quite get it... are these multiboards?

ashujon 03-10-2009 07:24 PM

no, it's units

Av3n 03-10-2009 07:30 PM

I'm keen to test this actually. If it works how I think it should ^^.

Since it's a system... It not necessary to post the code. But we would love some documentation in the post.

-Av3n

ashujon 03-10-2009 07:34 PM

i bad know english. difficult to translate readme, i'm sorry

moyack 03-10-2009 08:47 PM

I posted the code so we can read it and find any improvements. It uses a database library, but it's so long that it simply can't be shown in a post.

Collapse JASS:
library Bags initializer Init requires Camera, DGUI, DataBaseBags

private function echo takes string msg returns nothing
    call DisplayTextToPlayer(GetLocalPlayer(), 0, 0, msg)
endfunction

private function BagH2I takes handle h returns integer
    return h
    return 0
endfunction

globals
    private integer TypeItemBag = 'IBAG'
    private code FuncLClickSlot = null
    private code FuncRClickSlot = null
    
    private integer CountWindow = 0
    
    private real array XPosWin
    private real array YPosWin
endglobals

globals
    constant real XIndentionSlot = 0.07
    constant real YIndentionSlot = -0.11
    constant real WidthSlot = 0.08
    constant real HeightSlot = 0.08*AspectRatio
endglobals

struct BAG
    static constant integer MaxCount = 6
    unit Owner
    BAGSYS BS
    private item Bag
    private item array Slot[.MaxCount]
    integer CountItem
    boolean open
    integer Pos
    //window
    private PICTURE Win
    private BUTTON array WinSlot[.MaxCount]
    private TEXT array WinCharge[.MaxCount]

    static method RegistrationItemBag takes item b returns BAG
        local BAG this = BAG.create()
        local integer i = .MaxCount-1
        set .Owner = null
        set .Bag = b
        set .CountItem = 0
        set .open = false
        set .Pos = 0
        call SetItemCharges(b, 0)
        call SetItemUserData(b, this)
        set .Win = PICTURE.NewCostumModel(0, 0, 1, 0.26, 'bwin', 140.002, 42.692, 0)
        loop
            exitwhen i < 0
            set .Slot[i] = null
            set .WinSlot[i] = BUTTON.New(0, 0, WidthSlot, HeightSlot, 0.5, TypeTextureBlank)
            set .WinSlot[i].CostumValue = this*.MaxCount+i
            call .WinSlot[i].AddActionL(FuncLClickSlot)
            call .WinSlot[i].AddActionR(FuncRClickSlot)
            set .WinCharge[i] = TEXT.New(0, 0, 1)
            set i = i - 1
        endloop
        return this
    endmethod
    
    method ResetCharges takes integer slot returns nothing
        local integer charg = GetItemCharges(.Slot[slot])
        if GetItemHasCharges(GetItemTypeId(.Slot[slot])) and (charg > 0) then
            call SetTextTagText(.WinCharge[slot].text, I2S(charg), 7*0.0023)
            call .WinCharge[slot].Show(true, .BS.Camera) //-0.08*StringLength(I2S(GetItemCharges(.Slot[slot])))
            call .WinCharge[slot].SetPosition(XPosWin[.Pos]+XIndentionSlot+(WidthSlot+0.01)*slot+WidthSlot-0.022, YPosWin[.Pos]+YIndentionSlot-HeightSlot)
        else
            call .WinCharge[slot].Show(false, 0)
        endif
    endmethod
    
    method ResetPosition takes integer pos returns nothing
        local integer i = .MaxCount - 1
        set .Pos = pos
        call .Win.SetPosition(XPosWin[pos], YPosWin[pos])
        loop
            exitwhen i < 0
            call .WinSlot[i].SetPosition(XPosWin[.Pos]+XIndentionSlot+(WidthSlot+0.01)*i, YPosWin[pos]+YIndentionSlot)
            call .ResetCharges(i)
            set i = i - 1
        endloop
    endmethod
    
    method Open takes BAGSYS bs, integer pos, integer r returns nothing
        local integer i = .MaxCount-1
        set .open = true
        set .BS = bs
        call .ResetPosition(pos)
        call .Win.SetTexture('D201'+r)
        call .Win.Show(true, bs.Camera)
        loop
            exitwhen i < 0
            if (.Slot[i] != null) then
                call .WinSlot[i].SetTexture(GetItemTexture(GetItemTypeId(.Slot[i])))
            else
                call .WinSlot[i].SetTexture(TypeTextureBlank)
            endif
            call .WinSlot[i].Show(true, bs.Camera)
            set i = i - 1
        endloop
    endmethod
    
    method Close takes nothing returns nothing
        local integer i = .MaxCount-1
        set .BS = 0
        set .open = false
        call .Win.Show(false, 0)
        loop
            exitwhen i < 0
            call .WinSlot[i].Show(false, 0)
            call .WinCharge[i].Show(false, 0)
            set i = i - 1
        endloop
    endmethod
    
    method AddItem takes item add returns boolean
        local integer i = 0
        local BAG b
        local integer charg
        if (GetItemTypeId(add) == TypeItemBag) then
            if (add == .Bag) or (GetItemCharges(add) > 0) then
                return false
            else
                set b = GetItemUserData(add)
                if b != 0 and b.open then
                    call .BS.RemoveBag(b)
                endif
            endif
        endif
        loop
            exitwhen i >= .MaxCount
            if (.Slot[i] == null) then
                set .Slot[i] = add
                set .CountItem = .CountItem + 1
                call SetItemCharges(.Bag, .CountItem)
                call SetItemPosition(add, 0, 0)
                call SetItemVisible(add, false)
                if .open then
                    call .WinSlot[i].SetTexture(GetItemTexture(GetItemTypeId(add)))
                    call .ResetCharges(i)
                endif
                return true
            endif
            set i = i + 1
        endloop
        return false
    endmethod
    
    method ClickSlot takes integer slot returns integer
        local BAG curbag
        local integer curslot
        local item curit
        local item it = .Slot[slot]
        local integer SelectSlot = this*.MaxCount+slot
        if .BS.CurSelectSlot != -1 then
            set curbag = .BS.CurSelectSlot/.MaxCount
            set curslot = .BS.CurSelectSlot-curbag*.MaxCount
            set curit = curbag.Slot[curslot]
            call SetUnitVertexColor(curbag.WinSlot[curslot].picture, 255, 255, 255, 255)
        endif
        if it != null then
            if .BS.CurSelectSlot != SelectSlot then
                call SetUnitVertexColor(.WinSlot[slot].picture, 200, 200, 200, 255)
                set .BS.CurSelectSlot = this*.MaxCount+slot
                return GetItemTypeId(.Slot[slot])
            else
                set .BS.CurSelectSlot = -1
            endif
            return false
        elseif .BS.CurSelectSlot != -1 then
            set .Slot[slot] = curit
            call .WinSlot[slot].SetTexture(GetItemTexture(GetItemTypeId(curit)))
            call .ResetCharges(slot)
            set curbag.Slot[curslot] = null
            call curbag.WinSlot[curslot].SetTexture(TypeTextureBlank)
            call curbag.ResetCharges(curslot)
            set .BS.CurSelectSlot = -1
            if (curbag != this) then
                set curbag.CountItem = curbag.CountItem - 1
                set .CountItem = .CountItem + 1
                call SetItemCharges(curbag.Bag, curbag.CountItem)
                call SetItemCharges(.Bag, .CountItem)
            endif
        endif
        return 0
    endmethod
    
    method DropItemInSlot takes integer slot returns boolean
        local boolean b
        call SetItemVisible(.Slot[slot], true)
        if not UnitAddItem(.Owner, .Slot[slot]) then
            call SetItemPosition(.Slot[slot], GetUnitX(.Owner), GetUnitY(.Owner))
        endif
        set b = .BS.CurSelectSlot == this*.MaxCount+slot
        if b then
            set .BS.CurSelectSlot = -1
            call SetUnitVertexColor(.WinSlot[slot].picture, 255, 255, 255, 255)
        endif
        call .WinCharge[slot].Show(false, 0)
        set .Slot[slot] = null
        call .WinSlot[slot].SetTexture(TypeTextureBlank)
        set .CountItem = .CountItem - 1
        call SetItemCharges(.Bag, .CountItem)
        return b
    endmethod
    
endstruct

struct DESCRIPTITEM
    static real PosWinX = -0.88
    static real PosWinY = 0.95
    private BAGSYS BS
    private PICTURE WinDesc
    private TEXT Name
    //private TEXT Cost
    private TEXT Desc
    
    static method New takes BAGSYS bs returns DESCRIPTITEM
        local DESCRIPTITEM this = DESCRIPTITEM.create()
        set .BS = bs
        set .WinDesc = PICTURE.NewCostumModel(.PosWinX, .PosWinY, 1, 0.26, 'dwin', 140.002, 122.646, 'D201'+bs.Race)
        set .Name = TEXT.New(.PosWinX+0.07, .PosWinY-0.20, 1)
        call SetTextTagColor(.Name.text, 80, 80, 255, 255)
        //set .Cost = TEXT.New(.PosWinX+0.07, .PosWinY-0.30, 1)
        //call SetTextTagColor(.Cost.text, 255, 255, 0, 255)
        set .Desc = TEXT.New(.PosWinX+0.07, .PosWinY-0.95, 1)
        return this
    endmethod
    
    method DescriptionItem takes integer typeitem returns nothing
        local string name
        local integer cost
        local string desc
        if typeitem != 0 then
            set name = GetObjectName(typeitem)
            set cost = GetItemCost(typeitem)
            set desc = GetItemDescription(typeitem)
            call SetTextTagText(.Name.text, name, 10 * 0.0023)
            call .Name.Show(true, .BS.Camera)
            //if cost != -1 then
            //    call SetTextTagText(.Cost.text, I2S(cost), 10 * 0.0023)
            //    call .Cost.Show(true, .BS.Camera)
            //else
            //    call .Cost.Show(false, 0)
            //endif
            call SetTextTagText(.Desc.text, desc, 10 * 0.0023)
            call .Desc.Show(true, .BS.Camera)
        else
            call .Name.Show(false, 0)
            //call .Cost.Show(false, 0)
            call .Desc.Show(false, 0)
        endif
    endmethod
    
    method Show takes boolean show returns nothing
        call .WinDesc.Show(show, .BS.Camera)
        call .Name.Show(show, .BS.Camera)
        //call .Cost.Show(show, .BS.Camera)
        call .Desc.Show(show, .BS.Camera)
    endmethod
    
endstruct

globals
    private trigger TrigPickupItem = null
    private trigger TrigMoveItem = null
    private trigger TrigUseItem = null
    private trigger TrigDropItem = null
    private conditionfunc itemisbagcondition = null
endglobals

struct BAGSYS
    static constant integer MaxCount = 6
    
    private DESCRIPTITEM DescItem
    private BAG array Bags[.MaxCount]
    private integer Count = 0
    integer CurSelectSlot

    private boolean Enable
    player p
    CAMERA Camera
    integer Race
    
    method EnableBagSys takes nothing returns nothing
        if not .Enable then
            set .p = Player(this)
            set .Race = BagH2I(GetPlayerRace(.p))-1
            set .CurSelectSlot = -1
            set .Enable = true
            call TriggerRegisterPlayerUnitEvent(TrigMoveItem, .p, EVENT_PLAYER_UNIT_ISSUED_TARGET_ORDER, null)
            call TriggerRegisterPlayerUnitEvent(TrigUseItem, .p, EVENT_PLAYER_UNIT_USE_ITEM, null)
            call TriggerRegisterPlayerUnitEvent(TrigDropItem, .p, EVENT_PLAYER_UNIT_DROP_ITEM, null)
            set .DescItem = DESCRIPTITEM.New(this)
        endif
    endmethod
    
    method AddBag takes BAG b returns boolean
        if .Count < .MaxCount and b != 0 then
            set .Bags[.Count] = b
            call b.Open(this, .Count, .Race)
            set .Count = .Count + 1
            return true
        endif
        return false
    endmethod
    
    method RemoveBag takes BAG bag returns boolean
        local integer i
        local boolean b = false
        local integer a = 0
        if .Count > 0 and bag != 0 then
            set .Count = .Count - 1
            loop
                exitwhen a > .Count
                if (.Bags[a] == bag) then
                    if .CurSelectSlot>=bag*BAG.MaxCount and .CurSelectSlot<(bag+1)*BAG.MaxCount then
                        call .DescriptionItemShow(0)
                    endif
                    call bag.Close()
                    set .Bags[a] = 0
                    set b = true
                endif
                if (.Bags[a] == 0) and (.Bags[a+1] != 0) then
                    set .Bags[a] = .Bags[a+1]
                    set .Bags[a+1] = 0
                    call .Bags[a].ResetPosition(a)
                endif
                set a = a + 1
            endloop
        endif
        return b
    endmethod
    
    method SetCamera takes CAMERA cam returns nothing
        set .Camera = cam
    endmethod
    
    method DescriptionItemShow takes integer typeitem returns nothing
        call .DescItem.DescriptionItem(typeitem)
        call .DescItem.Show(typeitem != 0)
    endmethod
    
endstruct
    
function EnableForPlayerBagSystem takes player p, CAMERA cam returns nothing
    local BAGSYS bs = GetPlayerId(p)
    call bs.EnableBagSys()
    call bs.SetCamera(cam)
endfunction

private function LCkickItemSlot takes nothing returns nothing
    local BUTTON but = GetTriggerButton()
    local BAG bag = but.CostumValue/BAG.MaxCount
    local BAGSYS bs = bag.BS
    local integer Slot = but.CostumValue-bag*BAG.MaxCount
    call bag.BS.DescriptionItemShow(bag.ClickSlot(Slot))
endfunction

private function RCkickItemSlot takes nothing returns nothing
    local BUTTON but = GetTriggerButton()
    local BAG bag = but.CostumValue/BAG.MaxCount
    local integer Slot = but.CostumValue-bag*BAG.MaxCount
    if bag.DropItemInSlot(Slot) then
        call bag.BS.DescriptionItemShow(0)
    endif
endfunction

private function MoveItemInBag takes nothing returns nothing
    local integer NewSlot = GetIssuedOrderId()-0xD0022
    local unit u = GetTriggerUnit()
    local item New = UnitItemInSlot(u, NewSlot)
    local item Old = GetOrderTargetItem()
    local BAG b
    if (Old != New) and (GetItemTypeId(New) == TypeItemBag) then
        set b = GetItemUserData(New)
        call b.AddItem(Old)
    endif
    set u = null
    set New = null
    set Old = null
endfunction

private function UseItemBag takes nothing returns nothing
    local BAGSYS bs = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
    local item i = GetManipulatedItem()
    local BAG b = GetItemUserData(i)
    call SetItemCharges(i, b.CountItem)
    if b.open then
        call bs.RemoveBag(b)
    else
        call bs.AddBag(b)
    endif
    set i = null
endfunction

private function DropBag takes nothing returns nothing
    local BAGSYS bs = GetPlayerId(GetOwningPlayer(GetTriggerUnit()))
    local BAG b = GetItemUserData(GetManipulatedItem())
    if b.open then
        call bs.RemoveBag(b)
    endif
endfunction

private function RegistrationBag takes nothing returns nothing
    local item i = GetManipulatedItem()
    local BAG b = GetItemUserData(i)
    if (b == 0) then
        set b = BAG.RegistrationItemBag(i)
    endif
    set b.Owner = GetTriggerUnit()
    set i = null
endfunction

private function OrderMoveCondition takes nothing returns boolean
    local integer o = GetIssuedOrderId()
    return 0xD0022<=o and o<=0xD0027
endfunction

private function ItemIsBagCondition takes nothing returns boolean
    return GetItemTypeId(GetManipulatedItem()) == TypeItemBag
endfunction

private function BagsInitTriggers takes nothing returns nothing
    local integer i = bj_MAX_PLAYER_SLOTS-1
    set TrigPickupItem = CreateTrigger()
    loop
        exitwhen i < 0
        call TriggerRegisterPlayerUnitEvent(TrigPickupItem, Player(i), EVENT_PLAYER_UNIT_PICKUP_ITEM, null)
        set i = i - 1
    endloop
    call TriggerAddCondition(TrigPickupItem, itemisbagcondition)
    call TriggerAddAction(TrigPickupItem, function RegistrationBag)
    set TrigMoveItem = CreateTrigger()
    call TriggerAddCondition(TrigMoveItem, Condition(function OrderMoveCondition))
    call TriggerAddAction(TrigMoveItem, function MoveItemInBag)
    set TrigUseItem = CreateTrigger()
    call TriggerAddCondition(TrigUseItem, itemisbagcondition)
    call TriggerAddAction(TrigUseItem, function UseItemBag)
    set TrigDropItem = CreateTrigger()
    call TriggerAddCondition(TrigDropItem, itemisbagcondition)
    call TriggerAddAction(TrigDropItem, function DropBag)
endfunction

private function Init takes nothing returns nothing
    call InventoryInitItemDB_Func(TypeItemBag, "BTNDust.blp", "Bag for 6 item.", 0, true)
    set FuncLClickSlot = function LCkickItemSlot
    set FuncRClickSlot = function RCkickItemSlot
    set itemisbagcondition = Condition(function ItemIsBagCondition)
    call BagsInitTriggers()
    set XPosWin[0] = 0.35
    set YPosWin[0] = -0.52
    set XPosWin[1] = 0.35
    set YPosWin[1] = -0.17
    set XPosWin[2] = 0.35
    set YPosWin[2] = 0.18
    set XPosWin[3] = 0.35
    set YPosWin[3] = 0.53
    set XPosWin[4] = 0.35
    set YPosWin[4] = 0.88
    set XPosWin[5] = -0.35
    set YPosWin[5] = -0.52
    set XPosWin[6] = -0.35
    set YPosWin[6] = -0.17
    set XPosWin[7] = -0.35
    set YPosWin[7] = 0.18
    set XPosWin[8] = -0.35
    set YPosWin[8] = 0.53
    set XPosWin[9] = -0.35
    set YPosWin[9] = 0.88
endfunction

endlibrary

Flame_Phoenix 03-10-2009 10:26 PM

How do I place an item inside the bag?
What is your language?

This websites may help you:
http://translate.google.com/translate_t?hl=pt-PT#
http://babelfish.yahoo.com/
http://translation.langenberg.com/
http://www.tranexp.com:2000/Translate/result.shtml

ashujon 03-10-2009 10:49 PM

in standart inventory to move item on bag
russian

moyack 03-11-2009 01:38 AM

Quite interesting I must say, the only thing that bothers me is that auras don't keep active when they're put into a bag. there are some other thing more related in how to move the item and such, but keeping in my how limited is the WC3 engine, this is practically a miracle in game UI development.

Keep the good work.

EDIT: as I see, the system implies a camera setting for the player, is that necessary? can this bag system be independent of the camera effect? right now the camera settings makes hard to select and move the hero unit.

ashujon 03-11-2009 01:56 AM

Quote:

Originally Posted by moyack
as I see, the system implies a camera setting for the player, is that necessary? can this bag system be independent of the camera effect? right now the camera settings makes hard to select and move the hero unit.

is not got, need know coordinates eye and target camera, but problem:
Collapse JASS:
constant native GetCameraTargetPositionX takes nothing returns real
constant native GetCameraTargetPositionY takes nothing returns real
constant native GetCameraTargetPositionZ takes nothing returns real
constant native GetCameraEyePositionX takes nothing returns real
constant native GetCameraEyePositionY takes nothing returns real
constant native GetCameraEyePositionZ takes nothing returns real
values it's functions update over 0.03 sec after to move camera - UI twitch
so require have our "Camera", that update immediately after to move, know coordinates beforehand
+ GetCamera###Position# - local function, in multuplayer no use, but "Camera" give chance multiplayer, for each player its "Сamera", but i no testing

possible to local move units - dsync not will (i testing in FlyingSimulator (can show)), less load on player's comp in multuplayer, but think - will problems with click on units, however possible create no "button", but "picture" and "text", too no testing

hope understandable said =|

TriggerHappy 03-11-2009 02:05 AM

All you xgm'ers make the coolest mods.

Hawkwing 03-11-2009 03:15 AM

Pretty cool, but the info panel for items really needs to display the icon of the item you're looking at.

deolrin 03-11-2009 06:31 AM

Hmm, i dunno if its only me, but the cooldowns seem to reset after being inside the bag. I used amulet of the wild(3 furbolgs summon), and after one furbolg i put the item in a bag, after i took it out the cooldown has reset.

erwtenpeller 03-11-2009 01:21 PM

Regardless of how well it works, it looks pretty class.

ashujon 03-11-2009 05:00 PM

new version 1.01
1)
Quote:

Originally Posted by Hawkwing
Pretty cool, but the info panel for items really needs to display the icon of the item you're looking at.

2)fix bug. Mouse Right Click on blank slot in bag -> reduction item-bag's charge in standart inventory

download v1.01


Quote:

Originally Posted by deolrin
Hmm, i dunno if its only me, but the cooldowns seem to reset after being inside the bag. I used amulet of the wild(3 furbolgs summon), and after one furbolg i put the item in a bag, after i took it out the cooldown has reset.

his's cooldowns reset over ditto time how in standart inventory
Quote:

Originally Posted by Litany
It's kind of old hat actually. The problem is it fails in multiplayer games that allow shared unit control, which makes a method like InvX's preferable even though it's less shiny.

multiplayer possible make, but need time


All times are GMT. The time now is 06:53 PM.

Powered by vBulletin (Copyright ©2000 - 2020, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services