This post has old documentation. It'll be updated in due time.
- Part of the documentation is relevant so I have not removed it.
I'm giving a sneak peak of this so I can get some feedback of what people would like implemented. It is usable in it's current condition. I'll release it officially once I better document it and polish it.
https://dl.dropbox.com/u/17935054/Table/ MDDrawMapControls_src.zip
Latest screenshot:
I've tried making this as flexible and easy to use as possible. I've set this up to work like objective-c.
To update a cell you set up a callback function for a specified table. When you tell the table to reload it's data it will call the function below for every visible cell. The call back function gives you the table, and index of the cell along with the cell being updated.
proc/cellReloadedForPlayer(MDTable/table, MDTableCell/cell, index, mob/m)
var/MDCellPlayer/_cell = cell
var/mob/player = table.data.values[index]
_cell.cellBack.name = player.key
_cell.text.setText(limit(player.name, 15))
_cell.text2.setText(limit(player.key, 15))
_cell.img.icon = icon('MDIcons.dmi', "[index % 8 == 0 ? 8: index % 8]")
_cell.img.name = _cell.cellBack.name
The "limit" function is just for keeping the text from being too long.
proc/limit(_string, length)return copytext(_string, 1, length)
You can also set up a callback function for a specific table for when a cell is clicked on. Multiple Tables can share the same callback function. In the callback function when you click on a cell the table, cell, and index of the cell are returned.
mob/proc/rowSelectedForTable(MDTable/table, MDTableCell/cell, index, mob/m)
if(table == m.playersTable)
var/MDCellPlayer/_cell = cell
world<<"\icon[_cell.img] [_cell.text.value]([_cell.text2.value])"
Tables can be any size and can be positioned anywhere. You can texture the table and cells or you can set them up to have gradient backgrounds or make it so they have no background. You can also specify a color for the table borders or not give them one.
Here is a table using a gradient background:
mob/proc/createPlayerTablesWithData(MDData/data)
playersTable = new(data)//table.setDataWithMDData(data)
playersTable.setCustomCell(/MDCellPlayer)
playersTable.setCallBackFunction(/mob/proc/rowSelectedForTable)
playersTable.setCellCallBackFunction(/proc/cellReloadedForPlayer)
playersTable.setTablePosition(_x = 14, _y = 1, _px = 0, _py = 0)
playersTable.setTableHeightInPixels(310)
playersTable.setTableWidthInPixels(150)
playersTable.setTableCellWidthInPixels(0)//# <= 0 sets the cellWidth to the width of the table
//playersTable.setTableCellHeightInPixels(20)
playersTable.setTableCellPaddingInPixels(5)
playersTable.setTableCellHeightAutomaticallyToFitXCells(7)
playersTable.setTableStyle(MDTABLESTYLEGRADIENT)
playersTable.setTableColorFlags(_rFlag = TRUE, _gFlag = TRUE)
playersTable.setCellStyle(MDTABLESTYLEGRADIENT)
playersTable.setCellColorFlags(_gFlag = TRUE)
playersTable.setTableBorderColor(rgb(0, 0, 0))
playersTable.setCellBorderColor(rgb(0, 0, 0))
playersTable.drawTable()
Next I set up that table to automatically update every time a player is added to it by adding a callback function to the MDData:
var/MDData/players = new(list())
world/New()
..()
players.setCallBack(/proc/refreshPlayersTab)
mob
Login()
..()
world<<"[src] logs in!"
name = "\[Player Name\]"
createTable1WithData(data)
createTable2WithData(data2)
data.setOwner(src)
data2.setOwner(src)
createPlayerTablesWithData(players)
players.add(src)
Logout()
world<<"[src] logs out!"
players.remove(src)
del(src)
proc/refreshPlayersTab()for(var/client/c)c.mob.playersTable.reloadDataIfNeeded()
Every time a player is added or removed from the MDData object the callback function is called which updates everyone's playersTable table.
You can also create custom cells, take a look at MDCustomCells.dm to see how they are set up.
You can customize the font text with these values(so far):
fontSize = 12
alignment = MDTEXTALIGNLEFT// MDTEXTALIGNCENTER, MDTEXTALIGNRIGHT
color = "#000000"
font = "Rockwell"
weight = 900
If you want to know what constants there are look in MDConstants.dm
I've added in MDWindows. They are great for making popup messages, alerts, menus, etc... They are reusable. The window backgrounds are cached for quick reuse.
Here is a code example for a MDWindow that passses a cell object when a cell is clicked on:
mob/proc/createWindowForObject(MDTableCell/_cell)
if(open_windows["Test"])return
var/_msg = "No Cell Found!"
if(_cell)_msg = "Would you like to modify the cell at index [_cell.index]"
var/MDYesNoMessageWindow/window = new(_msg, _width = 200, _height = 100, _x = 10, _y = 9, _px = -50, _py = -38)
window.setStyle(MDSTYLETEXTURE)
window.setColorFlags(_rFlag = TRUE)
window.setTexture(icon('MDTextures.dmi', "3"))//, icon('MDTextures.dmi', "2"))
window.setBorderColor(rgb(0, 0, 0))
window.draw("Test")
window.yesButton.setObjectToPass(_cell)
window.noButton.setObjectToPass(_cell)
window.yesButton.setCallBack(/proc/testWindow)
window.noButton.setCallBack(/proc/testWindow)
When they press yes or no the following code is executed:
proc/testWindow(MDYesNoMessageWindow/_window, MDObject/_object, MDCellGraphic/_cell, mob/m)
if(_object == _window.yesButton)
world<<"Yes!"
del(_window)
if(_cell)
var/text = _cell.text.value
_cell.table.data.values[_cell.index] = "Test"
world<<"Modified cell [_cell.index] from \"\icon[_cell.img] [text]\" to \"\icon[_cell.img] [_cell.table.data.values[_cell.index]]\""
_cell.table.reloadCellAtIndex(_cell.index)
else if(_object == _window.noButton)
world<<"No!"
del(_window)
The way it's set up to work when you click on a cell is as follows:
mob/proc/rowSelectedForTable(MDTable/table, MDTableCell/cell, index. mob/m)
if(table == m.table1)
var/MDCellGraphic/_cell = cell
m.createWindowForObject(_cell)
Please post comments, suggestions, likes, dislikes, etc... Thanks!
Added an example of how to use this for an inventory system. The inventory automatically updates when you add and remove items from it.
In the screen shot the table on the top right are items you can add to your inventory by clicking on then. The table in the top left is your inventory. If you select an item in your inventory it'll remove that item from your inventory.
The download link is the same as the one in the first post.