using Gtk; using System; public class MapColours:TerrPlugin{ mutable host:TerrHost; public Host:TerrHost { set { host=value; } } mutable nr:int; //settings mutable sMax=172; mutable sMode=0; mutable sMin=86; mutable sBorderLand=86; mutable sBorderMnts=192; //-------------------------------------------------------------------------------------------------------------- public Register(n:int):void{ nr=n; def mItem=MenuItem("map colours"); host.MCols.Append(mItem); mItem.Activated+=EventHandler(optionsWin); } //-------------------------------------------------------------------------------------------------------------- public Run():void{ host.Start(nr); match (sMode){ | 0 => {//fluent for (mutable i=0; i<64; i++) host.Cols[i]=Gdk.Color(0,(i*4):>Byte,255); for (mutable i=64; i<127; i++) host.Cols[i]=Gdk.Color(0,255,(255-(i-64)*4):>Byte); for (mutable i=127; i<191; i++) host.Cols[i]=Gdk.Color(((i-127)*4):>Byte,255,0); for (mutable i=191; i<255; i++) host.Cols[i]=Gdk.Color(255,(255-(i-191)*4):>Byte,0); host.Cols[255]=Gdk.Color(255,0,0); } | 1 => {//tricolour def stepSea=(sMax-sMin)/sBorderLand:>double; def stepLand=(sMax-sMin)/(sBorderMnts-sBorderLand):>double; def stepMnts=(sMax-sMin)/(255-sBorderMnts):>double; for (mutable i=0; iByte); for (mutable i=sBorderLand; iByte,0); for (mutable i=sBorderMnts; i<256; i++) host.Cols[i]=Gdk.Color((sMin-1+(i-sBorderMnts)*stepMnts):>Byte,0,0); } | _ => Console.WriteLine("hmm, a weird error seems to have occurred..."); } host.Update(); } //-------------------------------------------------------------------------------------------------------------- private optionsWin(_o:object,_e:EventArgs):void{ def win=Window("map colours"); win.BorderWidth=5; def tips=Tooltips(); def whole=VBox(false,10); win.Add(whole); def sett=VBox(false,10); whole.PackStart(sett); def mode0VBox=VBox(false,10); def maxSpin=SpinButton(sMin,255.0,1.0); def minSpin=SpinButton(0.0,sMax,1.0); def maxHBox=HBox(false,10); mode0VBox.PackStart(maxHBox); def labMax=Label("max. intensity:"); maxHBox.PackStart(labMax); maxHBox.PackStart(maxSpin); tips.SetTip(maxSpin,"the maximum intensity of the colours",""); maxSpin.Value=sMax; maxSpin.ValueChanged+=fun(_){ sMax=maxSpin.ValueAsInt; minSpin.Adjustment=Adjustment(sMin,0.0,sMax,1.0,1.0,0); } def minHBox=HBox(false,10); mode0VBox.PackStart(minHBox); def labMin=Label("min. intensity:"); minHBox.PackStart(labMin); minHBox.PackStart(minSpin); tips.SetTip(minSpin,"the minimum intensity of the colours",""); minSpin.Value=sMin; minSpin.ValueChanged+=fun(_){ sMin=minSpin.ValueAsInt; maxSpin.Adjustment=Adjustment(sMax,sMax,255.0,1.0,1.0,0); } def borderLandSpin=SpinButton(0.0,sBorderMnts,1.0); def borderMntsSpin=SpinButton(sBorderLand,255.0,1.0); def borderLandHBox=HBox(false,10); mode0VBox.PackStart(borderLandHBox); def borderLandLab=Label("land border:"); borderLandHBox.PackStart(borderLandLab); borderLandHBox.PackStart(borderLandSpin); tips.SetTip(borderLandSpin,"the lower border colour of land",""); borderLandSpin.Value=sBorderLand; borderLandSpin.ValueChanged+=fun(_){ sBorderLand=borderLandSpin.ValueAsInt; borderMntsSpin.Adjustment=Adjustment(sBorderMnts,sBorderLand,255.0,1.0,1.0,0); } def borderMntsHBox=HBox(false,10); mode0VBox.PackStart(borderMntsHBox); def borderMntsLab=Label("mountains border:"); borderMntsHBox.PackStart(borderMntsLab); borderMntsHBox.PackStart(borderMntsSpin); tips.SetTip(borderMntsSpin,"the lower border colour of mountains",""); borderMntsSpin.Value=sBorderMnts; borderMntsSpin.ValueChanged+=fun(_){ sBorderMnts=borderMntsSpin.ValueAsInt; borderLandSpin.Adjustment=Adjustment(sBorderLand,0.0,sBorderMnts,1.0,1.0,0.0); } def mode1VBox=VBox(false,10); def modes=array["tricolour","fluent"]; def modeHBox=HBox(false,10); def modeLab=Label("mode:"); modeHBox.PackStart(modeLab); def modeBox=ComboBox.NewText(); modeHBox.PackStart(modeBox); foreach (i in modes) modeBox.AppendText(i); modeBox.Active=sMode; modeBox.Changed+=fun(_){ sMode=modeBox.Active; if (sMode==0) { mode1VBox.HideAll(); mode0VBox.ShowAll(); win.ReshowWithInitialSize(); } else { mode0VBox.HideAll(); mode1VBox.ShowAll();win.ReshowWithInitialSize();} } sett.PackStart(modeHBox); sett.PackStart(mode0VBox); sett.PackStart(mode1VBox); def buttBox=HBox(false,10); whole.PackStart(buttBox); 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(); if (sMode==0) mode1VBox.HideAll() else mode0VBox.HideAll(); win.ReshowWithInitialSize(); } //-------------------------------------------------------------------------------------------------------------- private aboutButtHandler(_o:object,_e:EventArgs):void{ def dial=MessageDialog(null,DialogFlags.Modal,MessageType.Info,ButtonsType.Ok,"map colours plugin 0.2:0.3 by caminoix, 03.09.2006\n\nfor more information on the algorithm please see\nhttp://terraineer.sourceforge.net/plugins/mapcolours.php"); _=dial.Run(); dial.Destroy(); } }