From: <cl...@us...> - 2007-06-19 17:01:06
|
Revision: 6 http://fortress.svn.sourceforge.net/fortress/?rev=6&view=rev Author: clrg Date: 2007-06-19 10:01:06 -0700 (Tue, 19 Jun 2007) Log Message: ----------- Make map scrollable with minimap Modified Paths: -------------- trunk/Prototype/src/net/sourceforge/fortress/app.t trunk/Prototype/src/net/sourceforge/fortress/map.t trunk/Prototype/src/net/sourceforge/fortress/maptile.t Added Paths: ----------- trunk/Prototype/src/net/sourceforge/fortress/minimap.t trunk/Prototype/src/net/sourceforge/fortress/minimaptile.t Modified: trunk/Prototype/src/net/sourceforge/fortress/app.t =================================================================== --- trunk/Prototype/src/net/sourceforge/fortress/app.t 2007-06-19 17:00:41 UTC (rev 5) +++ trunk/Prototype/src/net/sourceforge/fortress/app.t 2007-06-19 17:01:06 UTC (rev 6) @@ -1,10 +1,28 @@ <!-- Copyright 2007 licensed under GPL v3 --> -<vexi xmlns:ui="vexi://ui" xmlns="net.sourceforge.fortress"> +<vexi xmlns:ui="vexi://ui" xmlns="net.sourceforge.fortress" xmlns:role="org.vexi.lib.role"> + <role:surface /> <ui:box> - <map packed="false" /> + <ui:box cols="1" hshrink="true"> + <minimap /> + <ui:box fill="#888888" height="1" /> + <ui:box height="5" /> + <ui:box id="tiletype" textcolor="white" vshrink="true" /> + <ui:box height="5" /> + <ui:box id="position" textcolor="white" vshrink="true" /> + <ui:box /> + </ui:box> + <ui:box fill="#888888" width="1" /> + <map id="map" /> vexi.ui.frame = thisbox; + $map.activeTile ++= function(v) + { + $position.text = "( "+v.posx+", "+v.posy+" )"; + $tiletype.text = v.type; + cascade = v; + } + </ui:box> </vexi> \ No newline at end of file Modified: trunk/Prototype/src/net/sourceforge/fortress/map.t =================================================================== --- trunk/Prototype/src/net/sourceforge/fortress/map.t 2007-06-19 17:00:41 UTC (rev 5) +++ trunk/Prototype/src/net/sourceforge/fortress/map.t 2007-06-19 17:01:06 UTC (rev 6) @@ -1,12 +1,114 @@ <!-- Copyright 2007 licensed under GPL v3 --> <vexi xmlns:ui="vexi://ui" xmlns="net.sourceforge.fortress"> - <ui:box cols="50" shrink="true"> + <ui:box> + <ui:box id="map" align="topleft" cols="1" packed="false" shrink="true" /> + <ui:box id="cur" align="topleft" fill="#88ffffff" display="false" packed="false" /> - for (var i=0; 2500>i; i++) + var mapDim = function(v) { - thisbox[i] = .maptile(vexi.box); + cascade = v; + surface.setMapDim($map.width, $map.height); } + $map.width ++= mapDim; + $map.height ++= mapDim; + + var mapBox = function(v) + { + cascade = v; + surface.setMapBox(width, height); + } + + thisbox.width ++= mapBox; + thisbox.height ++= mapBox; + + //////// map movement ///////////////////////////////////////// + + var mx; + var my; + var ox; + var oy; + var vx; + var vy; + + var dragMove = function(v) + { + var m = thisbox.mouse; + var nx = ox - m.x + mx; + var ny = oy - m.y + my; + nx = 0 > nx ? (nx > vx ? nx : vx) : 0; + ny = 0 > ny ? (ny > vy ? ny : vy) : 0; + $map.x = nx; + $map.y = ny; + surface.setMapPos(nx, ny); + cascade = v; + } + + var dragStop = function(v) + { + surface.delMoveTrap(dragMove); + surface.Release2 --= dragStop; + cascade = v; + } + + var dragStart = function(v) + { + var m = thisbox.mouse; + mx = m.x; + my = m.y; + ox = $map.x; + oy = $map.y; + vx = width - $map.width; + vy = height - $map.height; + surface.addMoveTrap(dragMove); + surface.Release2 ++= dragStop; + cascade = v; + } + + thisbox.Press2 ++= dragStart; + + //////// tile tracking //////////////////////////////////////// + + thisbox.activeTile = null; + + var active = function() + { + var d = thisbox.distanceto(activeTile); + $cur.display = true; + $cur.width = activeTile.width; + $cur.height = activeTile.height; + $cur.x = d.x; + $cur.y = d.y; + } + + var enterFunc = function(v) + { + activeTile = trapee; + cascade = v; + active(); + } + + thisbox.Leave ++= function(v) { $cur.display = false; } + + for (var i=0; 50>i; i++) + { + $map[i] = vexi.box; + for (var j=0; 50>j; j++) + { + var t = .maptile(vexi.box); + t.Enter ++= enterFunc; + t.posx = j; + t.posy = i; + $map[i][j] = t; + } + } + + surface ++= function(v) + { + cascade = v; + surface.setMapContents($map); + } + </ui:box> </vexi> \ No newline at end of file Modified: trunk/Prototype/src/net/sourceforge/fortress/maptile.t =================================================================== --- trunk/Prototype/src/net/sourceforge/fortress/maptile.t 2007-06-19 17:00:41 UTC (rev 5) +++ trunk/Prototype/src/net/sourceforge/fortress/maptile.t 2007-06-19 17:01:06 UTC (rev 6) @@ -1,10 +1,10 @@ <!-- Copyright 2007 licensed under GPL v3 --> <vexi xmlns:ui="vexi://ui" xmlns="net.sourceforge.fortress"> - <ui:box shrink="true"> + <ui:box shrink="true" width="20" height="20"> - var type = "grass"; - var seed = vexi.math.floor(vexi.math.random()*10); + thisbox.type = "grass"; + thisbox.seed = vexi.math.floor(vexi.math.random()*10); fill = .image[type+seed]; Added: trunk/Prototype/src/net/sourceforge/fortress/minimap.t =================================================================== --- trunk/Prototype/src/net/sourceforge/fortress/minimap.t (rev 0) +++ trunk/Prototype/src/net/sourceforge/fortress/minimap.t 2007-06-19 17:01:06 UTC (rev 6) @@ -0,0 +1,76 @@ +<!-- Copyright 2007 licensed under GPL v3 --> + +<vexi xmlns:ui="vexi://ui" xmlns="net.sourceforge.fortress"> + <ui:box height="100" width="100"> + <ui:box shrink="true"> + <ui:box id="minimap" cols="1" shrink="true" /> + <ui:box id="viewbox" cols="1" align="topleft" packed="false"> + <ui:box fill="white" height="1" /> + <ui:box> + <ui:box fill="white" width="1" /> + <ui:box /> + <ui:box fill="white" width="1" /> + </ui:box> + <ui:box fill="white" height="1" /> + </ui:box> + </ui:box> + + var mw = 1; + var mh = 1; + var mx = 1; + var my = 1; + var vw = 1; + var vh = 1; + + var syncView = function() + { + $viewbox.width = $minimap.width * (vw / mw); + $viewbox.height = $minimap.height * (vh / mh); + $viewbox.x = $minimap.width * (-mx / mw); + $viewbox.y = $minimap.height * (-my / mh); + } + + surface ++= function(v) + { + cascade = v; + + surface.setMapBox = function(_vw, _vh) + { + vw = _vw; + vh = _vh; + syncView(); + } + + surface.setMapDim = function(_mw, _mh) + { + mw = _mw; + mh = _mh; + syncView(); + } + + surface.setMapPos = function(_mx, _my) + { + mx = _mx; + my = _my; + syncView(); + } + + surface.setMapContents = function(map) + { + var ni = map.numchildren; + var nj = map[0].numchildren; + for (var i=0; ni > i; i++) + { + $minimap[i] = vexi.box; + for (var j=0; nj > j; j++) + { + var t = .minimaptile(vexi.box); + t.setType(map[i][j].type, map[i][j].seed); + $minimap[i][j] = t; + } + } + } + } + + </ui:box> +</vexi> Added: trunk/Prototype/src/net/sourceforge/fortress/minimaptile.t =================================================================== --- trunk/Prototype/src/net/sourceforge/fortress/minimaptile.t (rev 0) +++ trunk/Prototype/src/net/sourceforge/fortress/minimaptile.t 2007-06-19 17:01:06 UTC (rev 6) @@ -0,0 +1,35 @@ +<!-- Copyright 2007 licensed under GPL v3 --> + +<vexi xmlns:ui="vexi://ui" xmlns="net.sourceforge.fortress"> + <ui:box width="1" height="1" shrink="true"> + + var getFillHex = function(s) + { + switch (s) + { + case 0: return "90"; + case 1: return "98"; + case 2: return "A0"; + case 3: return "A8"; + case 4: return "B0"; + case 5: return "B8"; + case 6: return "C0"; + case 7: return "C8"; + case 8: return "D0"; + case 9: return "D8"; + } + return "FF"; + } + + thisbox.setType = function(t, s) + { + switch (t) + { + case "grass": + default: + fill = "#00" + getFillHex(s) + "00"; + } + } + + </ui:box> +</vexi> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |