3
function TypeManager:buildWidget()
5
self.widget = guiManager:createWidget()
7
local setup = function()
9
self.typeTree = tolua.cast(self.widget:getWindow("TypeList"), "CEGUI::Tree")
10
self.typeTree:subscribeEvent("ItemSelectionChanged", self.TypeList_SelectionChanged, self)
12
self.codecTypeCombobox = CEGUI.toCombobox(self.widget:getWindow("CodecType"))
14
local item = Ember.OgreView.Gui.ColouredListItem:new("XML", 0)
15
self.codecTypeCombobox:addItem(item)
16
item = Ember.OgreView.Gui.ColouredListItem:new("Bach", 1)
17
self.codecTypeCombobox:addItem(item)
18
item = Ember.OgreView.Gui.ColouredListItem:new("Packed", 2)
19
self.codecTypeCombobox:addItem(item)
20
self.codecTypeCombobox:setItemSelectState(0, true)
21
self.codecTypeCombobox:setSingleClickEnabled(true)
22
self.codecTypeCombobox:subscribeEvent("ListSelectionChanged", self.CodecType_ListSelectionChanged, self)
25
self.typeInfoText = CEGUI.toMultiLineEditbox(self.widget:getWindow("TypeInfoText"))
27
self.typeAdapter = Ember.OgreView.Gui.Adapters.Eris.TypeTreeAdapter:new_local(emberServices:getServerService():getConnection():getTypeService(), self.typeTree)
28
self.typeAdapter:initialize("root")
30
self.widget:getWindow("SendToServerButton"):subscribeEvent("Clicked", self.SendToServerButton_Clicked, self)
32
self.widget:enableCloseButton()
35
connect(self.connectors, self.widget.EventFirstTimeShown, setup)
36
self.widget:loadMainSheet("TypeManager.layout", "TypeManager/")
37
self.widget:registerConsoleVisibilityToggleCommand("typeManager")
41
function TypeManager:CodecType_ListSelectionChanged()
42
local item = self.codecTypeCombobox:getSelectedItem()
44
local selectId = item:getID()
46
self.codecClass = Atlas.Codecs.XML
47
elseif selectId == 1 then
48
self.codecClass = Atlas.Codecs.Bach
50
self.codecClass = Atlas.Codecs.Packed
56
function TypeManager:sendTypeToServer()
57
local outstream = std.stringstream:new_local(self.typeInfoText:getText())
58
local decoder = Ember.OgreView.Authoring.AtlasObjectDecoder:new_local()
60
local codec = self.codecClass:new_local(outstream, tolua.cast(decoder, "Atlas::Bridge"))
63
local parsedObject = decoder:getLastObject()
65
if parsedObject:isValid() then
66
--If the type already exists, we need to send a "set" operation, else we need to send a "create" operation
67
if emberServices:getServerService():getConnection():getTypeService():findTypeByName(parsedObject:get():getId()) == nil then
68
emberServices:getServerService():createTypeInfo(parsedObject)
70
emberServices:getServerService():setTypeInfo(parsedObject)
75
function TypeManager:SendToServerButton_Clicked(args)
77
self:sendTypeToServer()
81
function TypeManager:printType()
82
local typeInfo = self.typeAdapter:getSelectedTypeInfo()
84
if typeInfo ~= nil then
86
local rawTypeData = self.world:getAuthoringManager():getRawTypeInfoRepository():getRawTypeData(typeInfo:getName())
88
if rawTypeData:isValid() then
90
local outstream = std.stringstream:new_local()
91
local decoder = Atlas.Message.QueuedDecoder:new_local()
93
local codec = self.codecClass:new_local(outstream, tolua.cast(decoder, "Atlas::Bridge"))
94
local formatter = Atlas.Formatter:new_local(outstream, tolua.cast(codec, "Atlas::Bridge"))
95
local encoder = Atlas.Message.Encoder:new_local(tolua.cast(formatter, "Atlas::Bridge"))
96
local message = Atlas.Message.MapType:new_local()
97
rawTypeData:get():addToMessage(message)
98
formatter:streamBegin();
99
encoder:streamMessageElement(message);
101
formatter:streamEnd();
103
self.typeInfoText:setText(outstream:str())
108
function TypeManager:TypeList_SelectionChanged(args)
114
function TypeManager:shutdown()
115
disconnectAll(self.connectors)
116
guiManager:destroyWidget(self.widget)
119
TypeManager.createdWorldConnector = createConnector(emberOgre.EventWorldCreated):connect(function(world)
120
typeManager = {connectors={}, codecClass=Atlas.Codecs.XML, world=world}
121
setmetatable(typeManager, {__index = TypeManager})
123
typeManager:buildWidget()
124
connect(typeManager.connectors, emberOgre.EventWorldDestroyed, function()
125
typeManager:shutdown()