~ubuntu-branches/ubuntu/wily/oolite/wily-proposed

« back to all changes in this revision

Viewing changes to src/Core/GuiDisplayGen.m

  • Committer: Package Import Robot
  • Author(s): Nicolas Boulenguez
  • Date: 2011-12-22 00:22:39 UTC
  • mfrom: (1.2.2)
  • Revision ID: package-import@ubuntu.com-20111222002239-pr3upeupp4jw1psp
Tags: 1.76-1
* New upstream.
* watch: scan upstream stable releases instead of dev snapshots.
* control: use default gobjc instead of explicit 4.6.
* rules: use dpkg-dev build flags.

Show diffs side-by-side

added added

removed removed

Lines of Context:
56
56
 
57
57
@implementation GuiDisplayGen
58
58
 
 
59
static BOOL _refreshStarChart = NO;
 
60
 
59
61
- (id) init
60
62
{
61
63
        self = [super init];
121
123
        pixel_row_center = size_in_pixels.width / 2;
122
124
        pixel_row_height = gui_row_height;
123
125
        pixel_row_start = gui_row_start;                // first position down the page...
124
 
        max_alpha = 1;
 
126
        max_alpha = 1.0;
125
127
 
126
128
        pixel_text_size = NSMakeSize(pixel_row_height, pixel_row_height);
127
129
        
312
314
}
313
315
 
314
316
 
 
317
- (void) stopFadeOuts
 
318
{
 
319
        fade_sign = 0.0f;
 
320
}
 
321
 
 
322
 
315
323
- (GLfloat) alpha
316
324
{
317
325
        return fade_alpha;
631
639
}
632
640
 
633
641
 
 
642
- (NSArray *) getLastLines;     // text, colour, fade time - text, colour, fade time
 
643
{
 
644
        if (n_rows <1) return nil;
 
645
        
 
646
        // we have at least 1 row!
 
647
        
 
648
        unsigned                                i = n_rows-1;
 
649
        OORGBAComponents                col = [(OOColor *)[rowColor objectAtIndex:i] rgbaComponents];
 
650
        
 
651
        if (i>0)
 
652
        {
 
653
                // we have at least 2 rows!
 
654
                OORGBAComponents        col0 = [(OOColor *)[rowColor objectAtIndex:i-1] rgbaComponents];
 
655
                return [NSArray arrayWithObjects:[rowText oo_stringAtIndex:i-1],
 
656
                                                                                [NSString stringWithFormat:@"%.3g %.3g %.3g %.3g", col0.r, col0.g, col0.b, col0.a],
 
657
                                                                                [NSNumber numberWithFloat:rowFadeTime[i-1]],
 
658
                                                                                [rowText oo_stringAtIndex:i],
 
659
                                                                                [NSString stringWithFormat:@"%.3g %.3g %.3g %.3g", col.r, col.g, col.b, col.a],
 
660
                                                                                [NSNumber numberWithFloat:rowFadeTime[i]], nil];
 
661
        }
 
662
        else
 
663
        {
 
664
                return [NSArray arrayWithObjects:[rowText oo_stringAtIndex:i],
 
665
                                                                                [NSString stringWithFormat:@"%.3g %.3g %.3g %.3g", col.r, col.g, col.b, col.a],
 
666
                                                                                [NSNumber numberWithFloat:rowFadeTime[i]], nil];
 
667
        }
 
668
}
 
669
 
 
670
 
634
671
- (void) printLongText:(NSString *)str
635
672
                                 align:(OOGUIAlignment) alignment
636
673
                                 color:(OOColor *)text_color
723
760
}
724
761
 
725
762
 
726
 
 
727
763
- (void) insertItemsFromArray:(NSArray *)items
728
764
                                         withKeys:(NSArray *)item_keys
729
765
                                          intoRow:(OOGUIRow)row
1061
1097
}
1062
1098
 
1063
1099
 
 
1100
- (void) refreshStarChart
 
1101
{
 
1102
        _refreshStarChart = YES;
 
1103
}
 
1104
 
 
1105
 
1064
1106
- (int) drawGUI:(GLfloat) alpha drawCursor:(BOOL) drawCursor
1065
1107
{
1066
1108
        GLfloat x = drawPosition.x;
1095
1137
                                fade_alpha = 0.0f;
1096
1138
                                fade_sign = 0.0f;
1097
1139
                        }
1098
 
                        if (fade_alpha > 1.0f)  // done fading in
 
1140
                        if (fade_alpha >= max_alpha)    // done fading in
1099
1141
                        {
1100
 
                                fade_alpha = 1.0f;
 
1142
                                fade_alpha = max_alpha;
1101
1143
                                fade_sign = 0.0f;
1102
1144
                        }
1103
1145
                }
1401
1443
        //
1402
1444
        // Cache nearby systems so that [UNIVERSE generateSystemData:] does not get called on every frame
1403
1445
        // Caching code submitted by Y A J, 20091022
 
1446
        
1404
1447
        static Random_Seed saved_galaxy_seed;
1405
1448
        static NSPoint saved_galaxy_coordinates;
1406
1449
        static struct saved_system
1411
1454
        } nearby_systems[ 256 ];
1412
1455
        static int num_nearby_systems;
1413
1456
 
1414
 
        if( !equal_seeds( [player galaxy_seed], saved_galaxy_seed ) ||
 
1457
        if ( _refreshStarChart || !equal_seeds( [player galaxy_seed], saved_galaxy_seed ) ||
1415
1458
                galaxy_coordinates.x != saved_galaxy_coordinates.x ||
1416
1459
                galaxy_coordinates.y != saved_galaxy_coordinates.y )
1417
1460
        {
1418
1461
                // saved systems are stale; recompute
 
1462
                _refreshStarChart = NO;
1419
1463
                for (i = 0; i < num_nearby_systems; i++)
1420
1464
                        [nearby_systems[ i ].p_name release];
1421
1465
 
1432
1476
                        if ((dx < 20)&&(dy < 38))
1433
1477
                        {
1434
1478
                                NSDictionary* sys_info = [UNIVERSE generateSystemData:g_seed];
 
1479
                                if (EXPECT_NOT([sys_info oo_boolForKey:@"sun_gone_nova"]))
 
1480
                                {
 
1481
                                        nearby_systems[ num_nearby_systems ].gov = -1;  // Flag up nova systems!
 
1482
                                }
 
1483
                                else
 
1484
                                {
 
1485
                                        nearby_systems[ num_nearby_systems ].tec = [sys_info oo_intForKey:KEY_TECHLEVEL];
 
1486
                                        nearby_systems[ num_nearby_systems ].eco = [sys_info oo_intForKey:KEY_ECONOMY];
 
1487
                                        nearby_systems[ num_nearby_systems ].gov = [sys_info oo_intForKey:KEY_GOVERNMENT];
 
1488
                                }
1435
1489
                                nearby_systems[ num_nearby_systems ].seed_d = g_seed.d;
1436
1490
                                nearby_systems[ num_nearby_systems ].seed_b = g_seed.b;
1437
 
                                nearby_systems[ num_nearby_systems ].tec = [sys_info oo_intForKey:KEY_TECHLEVEL];
1438
 
                                nearby_systems[ num_nearby_systems ].eco = [sys_info oo_intForKey:KEY_ECONOMY];
1439
 
                                nearby_systems[ num_nearby_systems ].gov = [sys_info oo_intForKey:KEY_GOVERNMENT];
1440
1491
                                nearby_systems[ num_nearby_systems ].p_name = [[sys_info oo_stringForKey:KEY_NAME] retain];
1441
1492
                                num_nearby_systems++;
1442
1493
                        }
1468
1519
                }
1469
1520
                else
1470
1521
                {
1471
 
                        OODrawPlanetInfo(sys->gov, sys->eco, sys->tec, x + star.x + 2.0, y + star.y + 2.0, z, NSMakeSize(pixel_row_height,pixel_row_height));
 
1522
                        if ( sys->gov >= 0 )    // Not a nova? Show the info.
 
1523
                                OODrawPlanetInfo(sys->gov, sys->eco, sys->tec, x + star.x + 2.0, y + star.y + 2.0, z, NSMakeSize(pixel_row_height,pixel_row_height));
1472
1524
                }
1473
1525
        }
1474
1526
        
1479
1531
                sys = nearby_systems + targetIdx;
1480
1532
                star.x = (float)(sys->seed_d * hscale + hoffset);
1481
1533
                star.y = (float)(sys->seed_b * vscale + voffset);
1482
 
 
 
1534
                
1483
1535
                if (![player showInfoFlag])
1484
1536
                {
1485
1537
                        OODrawHilightedString(sys->p_name, x + star.x + 2.0, y + star.y, z, NSMakeSize(pixel_row_height,pixel_row_height));
1486
1538
                }
1487
1539
                else
1488
1540
                {
1489
 
                        OODrawHilightedPlanetInfo(sys->gov, sys->eco, sys->tec, x + star.x + 2.0, y + star.y + 2.0, z, NSMakeSize(pixel_row_height,pixel_row_height));
 
1541
                        if ( sys->gov >= 0 )    // Not a nova? Show the info.
 
1542
                                OODrawHilightedPlanetInfo(sys->gov, sys->eco, sys->tec, x + star.x + 2.0, y + star.y + 2.0, z,
 
1543
                                                                                  NSMakeSize(pixel_row_height,pixel_row_height));
1490
1544
                }
1491
1545
        }
1492
1546
        
1511
1565
        BOOL            *systemsFound = [UNIVERSE systemsFound];
1512
1566
        unsigned        i, first = 0, last = 0, count = 0;
1513
1567
        int             systemIndex = foundSystem + direction;
1514
 
 
 
1568
        
1515
1569
        if (direction == 0) systemIndex = 0;
1516
1570
        
1517
1571
        for (i = 0; i <= kOOMaximumSystemID; i++)
1530
1584
                        count++;
1531
1585
                }
1532
1586
        }
1533
 
 
 
1587
        
1534
1588
        if (count == 0) return sys; // empty systemFound list.
1535
1589
        
1536
1590
        // loop back if needed.
1556
1610
        NSPoint                 galaxy_coordinates = [player galaxy_coordinates];
1557
1611
        NSPoint                 cursor_coordinates = [player cursor_coordinates];
1558
1612
        Random_Seed             galaxy_seed = [player galaxy_seed];
1559
 
 
 
1613
        
1560
1614
        double fuel = 35.0 * [player dialFuel];
1561
 
 
 
1615
        
1562
1616
        // get a list of systems marked as contract destinations
1563
1617
        NSArray         *markedDestinations = [player markedDestinations];
1564
1618
        
1578
1632
        double          distance, time;
1579
1633
        
1580
1634
        if (showAdvancedNavArray) advancedNavArrayMode = [[UNIVERSE gameView] isCtrlDown] ? OPTIMIZED_BY_TIME : OPTIMIZED_BY_JUMPS;
1581
 
 
 
1635
        
1582
1636
        if (advancedNavArrayMode != OPTIMIZED_BY_NONE && ![UNIVERSE strict] && [player hasEquipmentItem:@"EQ_ADVANCED_NAVIGATIONAL_ARRAY"])
1583
1637
        {
1584
1638
                int planetNumber = [UNIVERSE findSystemNumberAtCoords:galaxy_coordinates withGalaxySeed:galaxy_seed];
1586
1640
                NSDictionary* routeInfo = [UNIVERSE routeFromSystem:planetNumber toSystem:destNumber optimizedBy:advancedNavArrayMode];
1587
1641
                
1588
1642
                if (!routeInfo)  routeExists = NO;
1589
 
 
 
1643
                
1590
1644
                [self drawAdvancedNavArrayAtX:x y:y z:z alpha:alpha usingRoute: (planetNumber != destNumber ? (id)routeInfo : nil) optimizedBy:advancedNavArrayMode];
1591
1645
                if (routeExists)
1592
1646
                {
1600
1654
                distance = distanceBetweenPlanetPositions(dest.d,dest.b,galaxy_coordinates.x,galaxy_coordinates.y);
1601
1655
                time = distance * distance;
1602
1656
        }
1603
 
 
 
1657
        
1604
1658
        if (routeExists)
1605
1659
        {
1606
1660
                // distance-f & est-travel-time-f are identical between short & long range charts in standard Oolite, however can be alterered separately via OXPs
1668
1722
                
1669
1723
                star.x = (float)(g_seed.d * hscale + hoffset);
1670
1724
                star.y = (float)(g_seed.b * vscale + voffset);
1671
 
 
 
1725
                
1672
1726
                float sz = (4.0f + 0.5f * (0x03 | (g_seed.f & 0x0f))) / 7.0f;
1673
1727
                
1674
1728
                glVertex3f(x + star.x, y + star.y + sz, z);
1733
1787
                glVertex3f(x + size_in_pixels.width, (float)(y + voffset + 260.0f*vscale - 2), z);
1734
1788
                glVertex3f(x + 0, (float)(y + voffset + 260.0f*vscale - 2), z);
1735
1789
        OOGLEND();
1736
 
 
1737
1790
}
1738
1791
 
1739
1792