~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/widgets/Give.lua

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
-----------------------------------------
 
2
 
 
3
--A widget for giving something from the inventory to someone. Right now just shows a list of stuff that can be given. This will need to be extended to something much nicer. Perhaps even something which interacts with other inventory widgets.
 
4
 
 
5
-----------------------------------------
 
6
Give = {connectors={}}
 
7
Give.listbox = nil
 
8
Give.targetEntity = nil
 
9
Give.listboxMap = {}
 
10
Give.widget = guiManager:createWidget()
 
11
 
 
12
function Give.buildWidget()
 
13
        
 
14
        Give.widget:loadMainSheet("Give.layout", "Give/")
 
15
        
 
16
        Give.widget:hide()
 
17
        
 
18
        connect(Give.connectors, emberOgre.EventCreatedAvatarEntity, "Give.createdAvatarEmberEntity")
 
19
        
 
20
        giveButton = Give.widget:getWindow("Give")
 
21
        giveButton:subscribeEvent("Clicked", "Give.Give_Click")
 
22
        
 
23
        cancelButton = Give.widget:getWindow("Cancel")
 
24
        cancelButton:subscribeEvent("Clicked", "Give.Cancel_Click")
 
25
 
 
26
        connect(Give.connectors, guiManager.EventEntityAction, "Give.handleAction")
 
27
        
 
28
        local widget = Give.widget:getWindow("ListBox")
 
29
        Give.listbox = CEGUI.toListbox(widget)
 
30
end
 
31
 
 
32
function Give.createdAvatarEmberEntity(avatarEntity)
 
33
        connect(Give.connectors, avatarEntity:getAvatar().EventAddedEntityToInventory, "Give.addedEntity")
 
34
        connect(Give.connectors, avatarEntity:getAvatar().EventRemovedEntityFromInventory, "Give.removedEntity")
 
35
end
 
36
 
 
37
function Give.addedEntity(entity)
 
38
        local name = entity:getType():getName() .. " (" .. entity:getId() .. " : " .. entity:getName() .. ")"
 
39
        local item = EmberOgre.Gui.ColouredListItem:new(name, entity:getId(), entity)
 
40
        Give.listboxMap[entity] = item
 
41
        --we need to cast it down
 
42
        Give.listbox:addItem(item)
 
43
end
 
44
 
 
45
function Give.removedEntity(entity) 
 
46
        local item = Give.listboxMap[entity];
 
47
        if item ~= nil then
 
48
                Give.listbox:removeItem(tolua.cast(item, "CEGUI::ListboxItem"))
 
49
                Give.listboxMap[entity] = nil
 
50
        end
 
51
end
 
52
 
 
53
function Give.Give_Click(args)
 
54
        local item = Give.listbox:getFirstSelectedItem()
 
55
        while (item ~= nil) do
 
56
                local entityId = item:getID()
 
57
                local entity = emberOgre:getEmberEntity(entityId);
 
58
                if (entity ~= nil) then
 
59
                        emberServices:getServerService():place(entity, Give.targetEntity)
 
60
                end
 
61
                item = Give.listbox:getNextSelected(item)
 
62
        end
 
63
end
 
64
 
 
65
function Give.Cancel_Click(args)
 
66
        Give.widget:hide()
 
67
end
 
68
 
 
69
function Give.handleAction(action, entity) 
 
70
 
 
71
        if action == "give" then
 
72
                Give.show(entity)
 
73
        end
 
74
end
 
75
 
 
76
function Give.show(entity)
 
77
        Give.targetEntity = entity
 
78
        Give.widget:show()
 
79
        local textWidget = Give.widget:getWindow("Text")
 
80
        local text = "Give to " .. entity:getName() .. " ( a " .. entity:getType():getName() .. ")"
 
81
        textWidget:setText(text)
 
82
 
 
83
end
 
84
 
 
85
Give.buildWidget()
 
 
b'\\ No newline at end of file'