Пример #1
0
    def DrawSolarsystem(self, sprite, ids, imageid, mapitems, SIZE):
        if not len(mapitems):
            return
        planets = []
        stargates = []
        asteroidbelts = []
        for item in mapitems:
            if item.groupID == const.groupPlanet:
                planets.append(item)
            elif item.groupID == const.groupStargate:
                stargates.append(item)
            elif item.groupID == const.groupAsteroidBelt:
                asteroidbelts.append(item)

        drawarea = DrawArea()
        drawarea.setTransparentColor(-1)
        drawarea.setSize(SIZE, SIZE, 4278190080L)
        cords = {}
        sunID = None
        maxdist = 0.0
        for item in mapitems:
            pos = (item.x, 0.0, item.z)
            maxdist = max(maxdist, geo2.Vec3Length(pos))
            if item.groupID == const.groupSun:
                sunID = item.itemID
                radius = 3
                drawarea.circle(SIZE / 2, SIZE / 2, radius, radius, 10066329, 10066329)

        sizefactor = SIZE / 2 / maxdist * self.fillSize
        self.sr.sizefactor = sizefactor
        self.sr.sizefactorsize = SIZE
        if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
            _planets = []
            for planet in planets:
                pos = (planet.x, planet.y, planet.z)
                dist = geo2.Vec3Length(pos)
                _planets.append([dist, planet])

            _planets = uiutil.SortListOfTuples(_planets)
            planet = _planets
        i = 1
        for item in planets:
            pos = (item.x, 0.0, item.z)
            dist = geo2.Vec3Length(pos)
            if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
                planetscale = i * (maxdist / len(planets)) / dist
                pos = geo2.Vec3Scale(pos, planetscale)
            x = FLIPMAP * pos[0] * sizefactor + SIZE / 2
            y = pos[2] * sizefactor + SIZE / 2
            radius = 1
            cords[item.itemID] = (x, SIZE - y, radius)
            drawarea.circle(x, SIZE - y, radius, radius, 16777215, mathUtil.LtoI(4278190080L))
            self.AddChilds(x, y, radius, item.itemID, SIZE, drawarea, cords, item)
            i += 1

        self.orbs = []
        for orbit in planets:
            if orbit.itemID in cords:
                x, y, radius = cords[orbit.itemID]
                center = SIZE / 2
                frompos = geo2.Vector(float(center), 0.0, float(center))
                topos = geo2.Vector(float(x), 0.0, float(y))
                diff = topos - frompos
                rad = int(geo2.Vec3Length(diff))
                drawarea.circle(center, center, rad, rad, self.GetColorByGroupID(const.groupPlanet), mathUtil.LtoI(4278190080L))
                orbpos = (orbit.x, 0.0, orbit.z)
                orbdist = geo2.Vec3Length(orbpos)
                self.orbs.append([orbdist, (orbdist,
                  rad,
                  orbit,
                  SIZE)])

        self.orbs = uiutil.SortListOfTuples(self.orbs)
        for item in stargates:
            if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
                if not len(self.orbs):
                    return
                x, y = self.GetAbstractPosition((item.x, 0.0, item.z))
            else:
                x = FLIPMAP * self.sr.sizefactor * item.x + self.sr.sizefactorsize / 2
                y = self.sr.sizefactor * item.z + self.sr.sizefactorsize / 2
            x += 6
            radius = 1
            drawarea.circle(x, SIZE - y, radius, radius, 0, self.GetColorByGroupID(const.groupStargate))
            cords[item.itemID] = (x, SIZE - y, radius)

        self.areas = [ (cords[id][0],
         cords[id][1],
         cords[id][2],
         id) for id in cords.iterkeys() ]
        self.cordsAsPortion = {}
        for id in cords.iterkeys():
            self.cordsAsPortion[id] = (cords[id][0] / float(SIZE), cords[id][1] / float(SIZE))

        if self.destroyed:
            return
        self.PlaceBackground('res:/UI/Texture/map_ssunderlay.png')
        self.PlaceMap(sprite, drawarea, SIZE)
Пример #2
0
    def DrawSolarsystem(self, sprite, ids, imageid, mapitems, SIZE):
        if not len(mapitems):
            return
        planets = []
        stargates = []
        asteroidbelts = []
        for item in mapitems:
            if item.groupID == const.groupPlanet:
                planets.append(item)
            elif item.groupID == const.groupStargate:
                stargates.append(item)
            elif item.groupID == const.groupAsteroidBelt:
                asteroidbelts.append(item)

        drawarea = DrawArea()
        drawarea.setTransparentColor(-1)
        drawarea.setSize(SIZE, SIZE, 4278190080L)
        cords = {}
        sunID = None
        maxdist = 0.0
        for item in mapitems:
            pos = (item.x, 0.0, item.z)
            maxdist = max(maxdist, geo2.Vec3Length(pos))
            if item.groupID == const.groupSun:
                sunID = item.itemID
                radius = 3
                drawarea.circle(SIZE / 2, SIZE / 2, radius, radius, 10066329, 10066329)

        sizefactor = SIZE / 2 / maxdist * self.fillSize
        self.sr.sizefactor = sizefactor
        self.sr.sizefactorsize = SIZE
        if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
            _planets = []
            for planet in planets:
                pos = (planet.x, planet.y, planet.z)
                dist = geo2.Vec3Length(pos)
                _planets.append([dist, planet])

            _planets = uiutil.SortListOfTuples(_planets)
            planet = _planets
        i = 1
        for item in planets:
            pos = (item.x, 0.0, item.z)
            dist = geo2.Vec3Length(pos)
            if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
                planetscale = i * (maxdist / len(planets)) / dist
                pos = geo2.Vec3Scale(pos, planetscale)
            x = FLIPMAP * pos[0] * sizefactor + SIZE / 2
            y = pos[2] * sizefactor + SIZE / 2
            radius = 1
            cords[item.itemID] = (x, SIZE - y, radius)
            drawarea.circle(x, SIZE - y, radius, radius, 16777215, mathUtil.LtoI(4278190080L))
            self.AddChilds(x, y, radius, item.itemID, SIZE, drawarea, cords, item)
            i += 1

        self.orbs = []
        for orbit in planets:
            if orbit.itemID in cords:
                x, y, radius = cords[orbit.itemID]
                center = SIZE / 2
                frompos = geo2.Vector(float(center), 0.0, float(center))
                topos = geo2.Vector(float(x), 0.0, float(y))
                diff = topos - frompos
                rad = int(geo2.Vec3Length(diff))
                drawarea.circle(center, center, rad, rad, self.GetColorByGroupID(const.groupPlanet), mathUtil.LtoI(4278190080L))
                orbpos = (orbit.x, 0.0, orbit.z)
                orbdist = geo2.Vec3Length(orbpos)
                self.orbs.append([orbdist, (orbdist,
                  rad,
                  orbit,
                  SIZE)])

        self.orbs = uiutil.SortListOfTuples(self.orbs)
        for item in stargates:
            if self.allowAbstract and settings.user.ui.Get('solarsystemmapabstract', 0):
                if not len(self.orbs):
                    return
                x, y = self.GetAbstractPosition((item.x, 0.0, item.z))
            else:
                x = FLIPMAP * self.sr.sizefactor * item.x + self.sr.sizefactorsize / 2
                y = self.sr.sizefactor * item.z + self.sr.sizefactorsize / 2
            x += 6
            radius = 1
            drawarea.circle(x, SIZE - y, radius, radius, 0, self.GetColorByGroupID(const.groupStargate))
            cords[item.itemID] = (x, SIZE - y, radius)

        self.areas = [ (cords[id][0],
         cords[id][1],
         cords[id][2],
         id) for id in cords.iterkeys() ]
        self.cordsAsPortion = {}
        for id in cords.iterkeys():
            self.cordsAsPortion[id] = (cords[id][0] / float(SIZE), cords[id][1] / float(SIZE))

        if self.destroyed:
            return
        self.PlaceBackground('res:/UI/Texture/map_ssunderlay.png')
        self.PlaceMap(sprite, drawarea, SIZE)
Пример #3
0
    def Draw(self, ids, idlevel, drawlevel, needsize, sprite = None, solarsystem = None):
        _settings = (ids,
         idlevel,
         drawlevel,
         needsize)
        if _settings == self.settings:
            return
        self.settings = _settings
        lg.Info('2Dmaps', 'Drawing map, ids/idlevel/drawlevel:', ids, idlevel, drawlevel)
        if drawlevel <= idlevel:
            return
        if drawlevel == DRAW_SOLARSYSTEM_INTERIOR and len(ids) > 1:
            ids = ids[:1]
        SIZE = needsize
        if sprite is None:
            sprite = self.sprite
        _ids = {}
        for id in ids:
            _ids[id] = ''

        ids = _ids.keys()
        endid = ''
        if len(ids) > 1:
            endid = '%s_' % ids[-1]
        self.ids = ids
        self.idlevel = idlevel
        self.drawlevel = drawlevel
        self.needsize = needsize
        imageid = '%s_%s_%s_%s_%s_%s' % (ids[0],
         '_' * max(0, len(ids) - 2),
         endid,
         idlevel,
         drawlevel,
         self.fillSize)
        imageid = imageid.replace('.', '')
        if self.drawlevel == DRAW_SOLARSYSTEM_INTERIOR:
            imageid += '_' + str(settings.user.ui.Get('solarsystemmapabstract', 0))
        lg.Info('2Dmaps', 'MapID is: %s' % imageid)
        for each in self.overlays.children:
            if each.name == 'destinationline':
                each.renderObject = None
                each.Close()

        self.cordsAsPortion = {}
        mapitems = self.mapitems = self.GetMapData(ids, idlevel, drawlevel)
        if drawlevel == 4:
            self.DrawSolarsystem(sprite, ids, imageid, mapitems, SIZE)
            self.CheckMyLocation(solarsystem=solarsystem)
            return
        connections, outsideitems = self.GetConnectionData(ids, idlevel, drawlevel)
        self.outsideitems = outsideitems
        minx = 1e+100
        maxx = -1e+100
        minz = 1e+100
        maxz = -1e+100
        for item in mapitems:
            minx = min(minx, item.x)
            maxx = max(maxx, item.x)
            minz = min(minz, item.z)
            maxz = max(maxz, item.z)

        mw = -minx + maxx
        mh = -minz + maxz
        if not (mw and mh):
            return
        SIZE = SIZE * 2
        drawarea = DrawArea()
        drawarea.setTransparentColor(-1)
        drawarea.setSize(SIZE, SIZE, 4278190080L)
        dotrad = [2,
         3,
         4,
         5,
         6][idlevel]
        sizefactor = min(SIZE / mw, SIZE / mh) * self.portion
        cords = {}
        for item in mapitems[:]:
            if item.groupID == const.groupRegion:
                if drawlevel != 1:
                    continue
            if item.groupID == const.groupConstellation:
                if drawlevel != 2:
                    continue
            x = int(item.x * sizefactor - int(minx * sizefactor) + (SIZE - mw * sizefactor) / 2)
            y = int(item.z * sizefactor - int(minz * sizefactor) + (SIZE - mh * sizefactor) / 2)
            cords[item.itemID] = (x,
             SIZE - y,
             dotrad,
             1,
             16777215)

        for item in self.outsideitems:
            x = int(item.x * sizefactor - int(minx * sizefactor) + (SIZE - mw * sizefactor) / 2)
            y = int(item.z * sizefactor - int(minz * sizefactor) + (SIZE - mh * sizefactor) / 2)
            cords[item.itemID] = (x,
             SIZE - y,
             dotrad,
             0,
             None)

        done = []
        i = 0
        lineWidth = 2.0
        for jumptype in connections:
            for pair in jumptype:
                fr, to = pair
                if (fr, to) in done:
                    continue
                if fr in cords and to in cords:
                    drawarea.line(cords[fr][0], cords[fr][1], cords[to][0], cords[to][1], [43520, 255, 16711680][i], lineWidth)
                    drawarea.line(cords[fr][0] + 1, cords[fr][1], cords[to][0] + 1, cords[to][1], [43520, 255, 16711680][i], lineWidth)
                    drawarea.line(cords[fr][0], cords[fr][1] + 1, cords[to][0], cords[to][1] + 1, [43520, 255, 16711680][i], lineWidth)

            i += 1

        for x, y, dotrad, cordtype, col in cords.itervalues():
            if cordtype == 0:
                dotrad = dotrad / 2
            drawarea.circle(x, y, dotrad, dotrad, 16777215, 16777215)

        self.areas = [ (cords[id][0],
         cords[id][1],
         cords[id][2],
         id) for id in cords.iterkeys() ]
        self.cordsAsPortion = {}
        for id in cords.iterkeys():
            self.cordsAsPortion[id] = (cords[id][0] / float(SIZE), cords[id][1] / float(SIZE))

        self.CheckMyLocation(solarsystem=solarsystem)
        self.CheckDestination()
        self.PlaceMap(sprite, drawarea, SIZE)
Пример #4
0
    def Draw(self, ids, idlevel, drawlevel, needsize, sprite = None, solarsystem = None):
        _settings = (ids,
         idlevel,
         drawlevel,
         needsize)
        if _settings == self.settings:
            return
        self.settings = _settings
        lg.Info('2Dmaps', 'Drawing map, ids/idlevel/drawlevel:', ids, idlevel, drawlevel)
        if drawlevel <= idlevel:
            return
        if drawlevel == DRAW_SOLARSYSTEM_INTERIOR and len(ids) > 1:
            ids = ids[:1]
        SIZE = needsize
        if sprite is None:
            sprite = self.sprite
        _ids = {}
        for id in ids:
            _ids[id] = ''

        ids = _ids.keys()
        endid = ''
        if len(ids) > 1:
            endid = '%s_' % ids[-1]
        self.ids = ids
        self.idlevel = idlevel
        self.drawlevel = drawlevel
        self.needsize = needsize
        imageid = '%s_%s_%s_%s_%s_%s' % (ids[0],
         '_' * max(0, len(ids) - 2),
         endid,
         idlevel,
         drawlevel,
         self.fillSize)
        imageid = imageid.replace('.', '')
        if self.drawlevel == DRAW_SOLARSYSTEM_INTERIOR:
            imageid += '_' + str(settings.user.ui.Get('solarsystemmapabstract', 0))
        lg.Info('2Dmaps', 'MapID is: %s' % imageid)
        for each in self.overlays.children:
            if each.name == 'destinationline':
                each.renderObject = None
                each.Close()

        self.cordsAsPortion = {}
        mapitems = self.mapitems = self.GetMapData(ids, idlevel, drawlevel)
        if drawlevel == 4:
            self.DrawSolarsystem(sprite, ids, imageid, mapitems, SIZE)
            self.CheckMyLocation(solarsystem=solarsystem)
            return
        connections, outsideitems = self.GetConnectionData(ids, idlevel, drawlevel)
        self.outsideitems = outsideitems
        minx = 1e+100
        maxx = -1e+100
        minz = 1e+100
        maxz = -1e+100
        for item in mapitems:
            minx = min(minx, item.x)
            maxx = max(maxx, item.x)
            minz = min(minz, item.z)
            maxz = max(maxz, item.z)

        mw = -minx + maxx
        mh = -minz + maxz
        if not (mw and mh):
            return
        SIZE = SIZE * 2
        drawarea = DrawArea()
        drawarea.setTransparentColor(-1)
        drawarea.setSize(SIZE, SIZE, 4278190080L)
        dotrad = [2,
         3,
         4,
         5,
         6][idlevel]
        sizefactor = min(SIZE / mw, SIZE / mh) * self.portion
        cords = {}
        for item in mapitems[:]:
            if item.groupID == const.groupRegion:
                if drawlevel != 1:
                    continue
            if item.groupID == const.groupConstellation:
                if drawlevel != 2:
                    continue
            x = int(item.x * sizefactor - int(minx * sizefactor) + (SIZE - mw * sizefactor) / 2)
            y = int(item.z * sizefactor - int(minz * sizefactor) + (SIZE - mh * sizefactor) / 2)
            cords[item.itemID] = (x,
             SIZE - y,
             dotrad,
             1,
             16777215)

        for item in self.outsideitems:
            x = int(item.x * sizefactor - int(minx * sizefactor) + (SIZE - mw * sizefactor) / 2)
            y = int(item.z * sizefactor - int(minz * sizefactor) + (SIZE - mh * sizefactor) / 2)
            cords[item.itemID] = (x,
             SIZE - y,
             dotrad,
             0,
             None)

        done = []
        i = 0
        lineWidth = 2.0
        for jumptype in connections:
            for pair in jumptype:
                fr, to = pair
                if (fr, to) in done:
                    continue
                if fr in cords and to in cords:
                    drawarea.line(cords[fr][0], cords[fr][1], cords[to][0], cords[to][1], [43520, 255, 16711680][i], lineWidth)
                    drawarea.line(cords[fr][0] + 1, cords[fr][1], cords[to][0] + 1, cords[to][1], [43520, 255, 16711680][i], lineWidth)
                    drawarea.line(cords[fr][0], cords[fr][1] + 1, cords[to][0], cords[to][1] + 1, [43520, 255, 16711680][i], lineWidth)

            i += 1

        for x, y, dotrad, cordtype, col in cords.itervalues():
            if cordtype == 0:
                dotrad = dotrad / 2
            drawarea.circle(x, y, dotrad, dotrad, 16777215, 16777215)

        self.areas = [ (cords[id][0],
         cords[id][1],
         cords[id][2],
         id) for id in cords.iterkeys() ]
        self.cordsAsPortion = {}
        for id in cords.iterkeys():
            self.cordsAsPortion[id] = (cords[id][0] / float(SIZE), cords[id][1] / float(SIZE))

        self.CheckMyLocation(solarsystem=solarsystem)
        self.CheckDestination()
        self.PlaceMap(sprite, drawarea, SIZE)