⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 q3controller.m

📁 quakeIII源码这个不用我多说吧
💻 M
📖 第 1 页 / 共 2 页
字号:
/*
===========================================================================
Copyright (C) 1999-2005 Id Software, Inc.

This file is part of Quake III Arena source code.

Quake III Arena source code is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License as
published by the Free Software Foundation; either version 2 of the License,
or (at your option) any later version.

Quake III Arena source code is distributed in the hope that it will be
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Foobar; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
===========================================================================
*/

#import "Q3Controller.h"

#import <Foundation/Foundation.h>
#import <AppKit/AppKit.h>

#include "client.h"
#include "macosx_local.h"
//#include "GameRanger SDK/gameranger.h"
#ifdef OMNI_TIMER
#import "macosx_timers.h"
#endif

#define MAX_ARGC 1024

static qboolean Sys_IsProcessingTerminationRequest = qfalse;
static void Sys_CreatePathToFile(NSString *path, NSDictionary *attributes);

@interface Q3Controller (Private)
- (void)quakeMain;
@end

@implementation Q3Controller

#ifndef DEDICATED

- (void)applicationDidFinishLaunching:(NSNotification *)notification;
{
    NS_DURING {
        [self quakeMain];
    } NS_HANDLER {
        Sys_Error("%@", [localException reason]);
    } NS_ENDHANDLER;
    Sys_Quit();
}

- (void)applicationDidUnhide:(NSNotification *)notification;
{
    // Don't reactivate the game if we are asking whether to quit
    if (Sys_IsProcessingTerminationRequest)
        return;
        
    if (!Sys_Unhide())
        // Didn't work -- hide again so we should get another chance to unhide later
        [NSApp hide: nil];
}

- (NSApplicationTerminateReply)applicationShouldTerminate:(NSApplication *)sender;
{
    int choice;

    if (!Sys_IsHidden) {
        // We're terminating via -terminate:
        return NSTerminateNow;
    }
    
    // Avoid reactivating GL when we unhide due to this panel
    Sys_IsProcessingTerminationRequest = qtrue;
    choice = NSRunAlertPanel(nil, @"Quit without saving?", @"Don't Quit", @"Quit", nil);
    Sys_IsProcessingTerminationRequest = qfalse;

    if (choice == NSAlertAlternateReturn)
        return NSTerminateNow;
        
    // Make sure we get re-hidden
    [NSApp hide:nil];
    
    return NSTerminateCancel;
}

// Actions

- (IBAction)paste:(id)sender;
{
    int shiftWasDown, insertWasDown;
    unsigned int currentTime;

    currentTime = Sys_Milliseconds();
    // Save the original keyboard state
    shiftWasDown = keys[K_SHIFT].down;
    insertWasDown = keys[K_INS].down;
    // Fake a Shift-Insert keyboard event
    keys[K_SHIFT].down = qtrue;
    Sys_QueEvent(currentTime, SE_KEY, K_INS, qtrue, 0, NULL);
    Sys_QueEvent(currentTime, SE_KEY, K_INS, qfalse, 0, NULL);
    // Restore the original keyboard state
    keys[K_SHIFT].down = shiftWasDown;
    keys[K_INS].down = insertWasDown;
}

extern void CL_Quit_f(void);


- (IBAction)requestTerminate:(id)sender;
{
    Com_Quit_f();
    // UI_QuitMenu();
}

- (void)showBanner;
{
    static BOOL hasShownBanner = NO;

    if (!hasShownBanner) {
        cvar_t *showBanner;

        hasShownBanner = YES;
        showBanner = Cvar_Get("cl_showBanner", "1", 0);
        if (showBanner->integer != 0) {
            NSPanel *splashPanel;
            NSImage *bannerImage;
            NSRect bannerRect;
            NSImageView *bannerImageView;
            
            bannerImage = [[NSImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForImageResource:@"banner.jpg"]];
            bannerRect = NSMakeRect(0.0, 0.0, [bannerImage size].width, [bannerImage size].height);
            
            splashPanel = [[NSPanel alloc] initWithContentRect:bannerRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
            
            bannerImageView = [[NSImageView alloc] initWithFrame:bannerRect];
            [bannerImageView setImage:bannerImage];
            [splashPanel setContentView:bannerImageView];
            [bannerImageView release];
            
            [splashPanel center];
            [splashPanel setHasShadow:YES];
            [splashPanel orderFront: nil];
            [NSThread sleepUntilDate:[NSDate dateWithTimeIntervalSinceNow:2.5]];
            [splashPanel close];
            
            [bannerImage release];
        }
    }
}

// Services

- (void)connectToServer:(NSPasteboard *)pasteboard userData:(NSString *)data error:(NSString **)error;
{
    NSArray *pasteboardTypes;

    pasteboardTypes = [pasteboard types];
    if ([pasteboardTypes containsObject:NSStringPboardType]) {
        NSString *requestedServer;

        requestedServer = [pasteboard stringForType:NSStringPboardType];
        if (requestedServer) {
            Cbuf_AddText(va("connect %s\n", [requestedServer cString]));
            return;
        }
    }
    *error = @"Unable to connect to server:  could not find string on pasteboard";
}

- (void)performCommand:(NSPasteboard *)pasteboard userData:(NSString *)data error:(NSString **)error;
{
    NSArray *pasteboardTypes;

    pasteboardTypes = [pasteboard types];
    if ([pasteboardTypes containsObject:NSStringPboardType]) {
        NSString *requestedCommand;

        requestedCommand = [pasteboard stringForType:NSStringPboardType];
        if (requestedCommand) {
            Cbuf_AddText(va("%s\n", [requestedCommand cString]));
            return;
        }
    }
    *error = @"Unable to perform command:  could not find string on pasteboard";
}

#endif

- (void)quakeMain;
{
    NSAutoreleasePool *pool;
    int argc = 0;
    const char *argv[MAX_ARGC];
    NSProcessInfo *processInfo;
    NSArray *arguments;
    unsigned int argumentIndex, argumentCount;
    NSFileManager *defaultManager;
    unsigned int commandLineLength;
    NSString *installationPathKey, *installationPath;
    char *cmdline;
    BOOL foundDirectory;
    NSString *appName, *demoAppName, *selectButton;
    int count = 0;
    pool = [[NSAutoreleasePool alloc] init];

    [NSApp setServicesProvider:self];

    processInfo = [NSProcessInfo processInfo];
    arguments = [processInfo arguments];
    argumentCount = [arguments count];
    for (argumentIndex = 0; argumentIndex < argumentCount; argumentIndex++) {
        NSString *arg;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -