using Gtk; using System; public class Template:TerrPlugin{ // required by the TerrPlugin interface. // it will let you communicate with terraineer. // it will be set by the host automatically at startup. mutable host:TerrHost; public Host:TerrHost { set { host=value; } } // the plugin's "serial number". required by the "rerun plugin" feature mutable nr:int; // here's a good place to put all your settings variables //------------------------------------------------------------------------------------------------------------- // required by the TerrPlugin interface. // it should do 2 things: // 1. store the plugin's "serial number" (n:int); // 2. add the plugin to the terraineer's menu and decide what happens when it's activated. public Register(n:int):void{ // the "serial number" nr=n; // adding the plugin to the menu's "generate" item; // also available: MFilter, MCols ("colours", inside "filter"), and last but not least // the entire MenBar (MenuBar). def mItem=MenuItem("template"); host.MGener.Append(mItem); mItem.Activated+=EventHandler(optionsWin); } //------------------------------------------------------------------------------------------------------------- // required by the TerrPlugin interface. // this is where the actual work should take place. it is important that it is this method; // otherwise "rerun plugin" won't work with your plugin. public Run():void{ // let the host know that the plugin has been activated and prepare for it. // give the host the plugin's "serial number" (nr) to let it know which plugin has been run. host.Start(nr); // if it's possible to count the progress bar advance beforehands, here's a good place for it. // progress bar accepts floating point values from range 0.0 to 1.0. def progStep=1/settingsIterations:>double; // there are basically 3 things your plugin can do: // 1. render a heightmap (or change the way it's viewed); // 2. filter an existing heightmap; // 3. change the colours used to show it; // 1. heightmap generation or view mode change // this is just for convenience, to avoid writing long names. def map=host.HMap; def sizeX=map.SizeX; def sizeY=map.SizeY; // make sure you're not generating your heightmap on top of another. // unless this is what you want :) (e.g. when just changing the view mode.) for (mutable x=0; xByte); // once you're done with some part of the job, update the host's progress bar. host.ProgBar.FractionAddResp(progStep); // let the host know that the plugin's done and apply the changes. host.Update(); } //------------------------------------------------------------------------------------------------------------- // the settings window. // lets the user adjust the behaviour of the plugin. private optionsWin(_o:object,_e:EventArgs):void{ def win=Window("template"); win.BorderWidth=5; def tips=Tooltips(); def whole=VBox(false,10); win.Add(whole); // here looks like a good place to add the settings VBox or whatever else. def buttBox=HBox(false,10); whole.PackStart(buttBox); // don't forget about the about button! def aboutButt=Button("about"); buttBox.PackStart(aboutButt); aboutButt.Clicked+=EventHandler(aboutButtHandler); def cancelButt=Button("cancel"); buttBox.PackStart(cancelButt); cancelButt.Clicked+=fun(_) { win.Destroy(); } def okButt=Button("ok"); buttBox.PackStart(okButt); okButt.Clicked+=fun(_) { Run(); win.Destroy(); } win.ShowAll(); } //------------------------------------------------------------------------------------------------------------- // don't forget about this! // one of the main goals of terraineer is to help people understand heightmap generation algorithms. // besides, providing a plugin without an information about how it works looks like poor protocol to me. private aboutButtHandler(_o:object,_e:EventArgs):void{ } }