Esempio n. 1
0
//==============================================================================
void GameServer::HandleDestroyItem_(const QVariantMap& request, QVariantMap& response)
{
#define BAD_ID(COND)\
  if (COND)\
  {\
    WriteResult_(response, EFEMPResult::BAD_ID);\
    return;\
  }\

  BAD_ID(request.find("id") == request.end());
  int id = request["id"].toInt();
  BAD_ID(!id);
  Player* p = sidToPlayer_[request["sid"].toByteArray()];

  if (p->DropItemFromSlot(id))
  {
    //destroy item from slot
    WriteResult_(response, EFEMPResult::OK);
    return;
  }

  if (p->GetItemId(id))
  {
    //destroy item from inventory
    for (auto& item : p->items_)
    {
      if (item->GetId() == id)
      {
        p->items_.erase(std::remove(p->items_.begin(), p->items_.end(), item), p->items_.end());
        idToActor_.erase(id);
        break;
      }
    }
  }
  else
  {
    //item is on the ground
    Item* item = dynamic_cast<Item*>(idToActor_[id]);
    BAD_ID(!item || !item->GetOnTheGround());

    Vector2 player_pos = p->GetPosition();
    Vector2 item_pos = item->GetPosition();
    float distance2 = Sqr(player_pos.x - item_pos.x)
                      + Sqr(player_pos.y - item_pos.y);
    BAD_ID(distance2 > Sqr(pickUpRadius_))
    KillActor_(item);
  }

  // TODO: implement
#undef BAD_ID
}
Esempio n. 2
0
WINEXPORT LRESULT CALLBACK FileCompleteWindowProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l )
{
    switch( msg ) {
    case WM_KEYDOWN:
        if( !BAD_ID( command_window_id ) ) {
            SetFocus( command_window_id );
            SendMessage( command_window_id, msg, w, l );
            return( 0 );
        }
        break;
    case WM_ERASEBKGND:
        return( TRUE );
    case WM_CREATE:
        SET_WNDINFO( hwnd, (LONG_PTR)&FileCompleteWindow );
        break;
    case WM_LBUTTONDBLCLK:
    case WM_MBUTTONDBLCLK:
    case WM_RBUTTONDBLCLK:
        FileCompleteMouseClick( hwnd, GET_X( l ), GET_Y( l ), true );
        break;
    case WM_LBUTTONUP:
    case WM_MBUTTONUP:
    case WM_RBUTTONUP:
        FileCompleteMouseClick( hwnd, GET_X( l ), GET_Y( l ), false );
        break;
    }
    return( DefWindowProc( hwnd, msg, w, l ) );
}
Esempio n. 3
0
static LRESULT processMouseMove( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
    RECT    rect;

    if( !haveCapture ) {
        return( DefWindowProc( hwnd, msg, wparam, lparam ) );
    }

    // check we aren't on ourselves first
    m_pt.x = (short)LOWORD( lparam );
    m_pt.y = (short)HIWORD( lparam );
    ClientToScreen( hwnd, &m_pt );
    GetWindowRect( GetParent( hwnd ), &rect );
    if( PtInRect( &rect, m_pt ) ) {
        CursorOp( COP_DROPCLR );
        mod_wid = NO_WINDOW;
        return( 0 );
    }

    // otherwise, figure out what we're over & change element display
    mod_wid = GetOwnedWindow( m_pt );
    if( !BAD_ID( mod_wid ) ) {
        CursorOp( COP_DROPCLR );
    } else {
        CursorOp( COP_NODROP );
    }

    return( 0 );
}
Esempio n. 4
0
/*
 * setCursorOnScreen - set cursor at specified row and column in edit window
 */
static void setCursorOnScreen( int row, int col )
{
    window      *w;
    int         x, y;
    int         width;
    int         funny;

    if( BAD_ID( CurrentWindow ) ) {
        return;
    }

    if( EditFlags.Quiet || EditFlags.NoSetCursor ) {
        return;
    }

    funny = getCursorInfo( CurrentWindow, row, col, &x, &width );
    w = WINDOW_FROM_ID( CurrentWindow );
    y = row * FontHeight( WIN_FONT( w ) ) - cursorHeight;
    width = (long) width * cursorType.width / 100L;
    if( cursorWidth != width ) {
        MyHideCaret( CurrentWindow );
        DestroyCaret();
        CreateCaret( CurrentWindow, (HBITMAP)NULLHANDLE, width, cursorHeight );
        cursorWidth = width;
    }
    // adjust position for italic sillyness
    SetCaretPos( x - funny, y );
    MyShowCaret( CurrentWindow );

} /* setCursorOnScreen */
Esempio n. 5
0
/*
 * ErrorBox - show an error message in a dialog box
 */
void ErrorBox( char *str, ... )
{
    va_list     al;
    char        tmp[MAX_STR];

    if( !BAD_ID( message_window_id ) ) {
        WindowAuxUpdate( message_window_id, WIND_INFO_TEXT_COLOR,
                            messagew_info.hilight_style.foreground );
        WindowAuxUpdate( message_window_id, WIND_INFO_BACKGROUND_COLOR,
                            messagew_info.hilight_style.background );
        va_start( al, str );
        MyVSprintf( tmp, str, al );
        va_end( al );

        SourceError( tmp );
        Message1Box( "%s", tmp );

        WindowAuxUpdate( message_window_id, WIND_INFO_TEXT_COLOR,
                            messagew_info.text_style.foreground );
        WindowAuxUpdate( message_window_id, WIND_INFO_BACKGROUND_COLOR,
                            messagew_info.text_style.background );
        MyBeep();
    } else {
        va_start( al, str );
#ifndef __WIN__
        MyVPrintf( str, al );
        MyPrintf( "\n" );
#endif
        va_end( al );
    }

} /* Error */
Esempio n. 6
0
static void sendNewColour( NewColourOps op )
{
    type_style  *mod_style;

    if( BAD_ID( mod_wid ) ) {
        return;
    }

    if( mod_wid == GetToolbarWindow() ) {
        sendNewColourToolbar();
    } else if( mod_wid == current_window_id ) {
        sendNewColourCurrentWindow( op );
    } else {
        mod_style = WIN_TEXT_STYLE( WINDOW_FROM_ID( mod_wid ) );
        if( op == NC_FORE ) {
            mod_style->foreground = INDEX_FROM_XY( cursx, cursy );
        } else {
            mod_style->background = INDEX_FROM_XY( cursx, cursy );
        }
        StatusWndChangeSysColors( RGBValues[statusw_info.text_style.background],
                                  RGBValues[statusw_info.text_style.foreground],
                                  GetSysColor( COLOR_BTNHIGHLIGHT ),
                                  GetSysColor( COLOR_BTNSHADOW ) );
        ReDisplayScreen();
    }
}
Esempio n. 7
0
/*
 * SetCursorOnLine - set cursor at specified column in single line text string
 */
void SetCursorOnLine( window_id id, int col, char *str, type_style *style )
{
    window      *w;
    int         x, y;
    int         width, height;

    if( BAD_ID( id ) ) {
        return;
    }
    w = WINDOW_FROM_ID( id );
    // y = FontHeight( WIN_FONT( w ) ) - cursorHeight;

    x = MyTextExtent( id, style, str, col - 1 );
    width = MyTextExtent( id, style, str, col ) - x;

    /* adjust so that Insert cursor is 0 width
     * Also make the overstrike cursor the height of the insert cursor.
     */
    width = (long) width * cursorType.width / 100L;
    height = EditVars.InsertCursorType.height;
    y = FontHeight( WIN_FONT( w ) ) - height;

    MyHideCaret( id );
    DestroyCaret();
    // CreateCaret( id, (HBITMAP)NULLHANDLE, width, cursorHeight );
    CreateCaret( id, (HBITMAP)NULLHANDLE, width, height );
    SetCaretPos( x, y );
    MyShowCaret( id );

} /* SetCursorOnLine */
Esempio n. 8
0
void MoveWindowToFront( window_id wid )
{
    if( !BAD_ID( wid ) ) {
        BringWindowToTop( wid );
        ActiveWindow( wid );
    }
}
Esempio n. 9
0
/*
 * NewCursor - create a new cursor for a window
 */
void NewCursor( window_id id, cursor_type ct )
{
    window      *w;
    int         height;
    int         width;

    if( BAD_ID( id ) ) {
        return;
    }
    w = WINDOW_FROM_ID( id );
    height = FontHeight( WIN_FONT( w ) );
    width = FontAverageWidth( WIN_FONT( w ) );
    height = (long) height * ct.height / 100L;
    width = (long) width * ct.width / 100L;
    MyHideCaret( id );
    DestroyCaret();
    cursorHeight = height;
    cursorWidth = width;
    if( !haveOldBlinkTime ) {
        oldBlinkTime = GetCaretBlinkTime();
        haveOldBlinkTime = TRUE;
    }
    CreateCaret( id, (HBITMAP)NULLHANDLE, cursorWidth, cursorHeight );
    SetCursorBlinkRate( EditVars.CursorBlinkRate );
    MyShowCaret( id );
    cursorType = ct;

} /* NewCursor */
Esempio n. 10
0
vi_rc MinimizeCurrentWindow( void )
{
    if( !BAD_ID( current_window_id ) ) {
        SendMessage( current_window_id, WM_SYSCOMMAND, SC_MINIMIZE, 0L );
    }
    return( ERR_NO_ERR );
}
Esempio n. 11
0
vi_rc MaximizeCurrentWindow( void )
{
    if( !BAD_ID( current_window_id ) ) {
        SendMessage( edit_container_id, WM_MDIMAXIMIZE, (UINT)current_window_id, 0L );
    }
    return( ERR_NO_ERR );
}
Esempio n. 12
0
/*
 * PromptThisFileForSave
 */
bool PromptThisFileForSave( const char *filename )
{
#ifdef __WIN__
    info        *cinfo;
    HWND        hwnd_old = NO_WINDOW;

    while( isspace( *filename ) ) {
        filename++;
    }
    for( cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) {
        if( SameFile( cinfo->CurrentFile->name, filename ) ) {
            if( cinfo->CurrentFile != NULL && cinfo->CurrentFile->dup_count == 0 &&
                cinfo->CurrentFile->modified ) {

                BringUpFile( cinfo, true );

                /* we have a modified file, so bring to the front */
                BringWindowToTop( root_window_id );
                hwnd_old = SetFocus( root_window_id );

                // file modified -- so prompt for save
                FilePromptForSaveChanges( CurrentFile );
            }
        }
    }
    if( !BAD_ID( hwnd_old ) ) {
        SetWindowPos( root_window_id, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
        SetFocus( hwnd_old );
    }
#else
    filename = filename;
#endif
    return( true );

} /* PromptThisFileForSave */
Esempio n. 13
0
void MoveWindowToFrontDammit( window_id wid, bool scrflag )
{
    scrflag = scrflag;
    if( BAD_ID( wid ) ) {
        return;
    }
    MoveWindowToFront( wid );
}
Esempio n. 14
0
void ActiveWindow( window_id wid )
{
    if( !BAD_ID( wid ) ) {
        SetActiveWindow( wid );
        SetWindowCursor();
        SetWindowCursorForReal();
    }
}
Esempio n. 15
0
/*
 * LocateCmd - parse a locate command (format: locate r,c[,len])
 */
vi_rc LocateCmd( const char *data )
{
    char        tmp[MAX_STR];
    linenum     r;
    int         c;
    int         len;

#ifdef __WIN__
    if( BAD_ID( current_window_id ) ) {
        return( ERR_INVALID_LOCATE );
    }
#endif
    data = GetNextWord1( data, tmp );
    if( *tmp == '\0' ) {
        return( ERR_INVALID_LOCATE );
    }
    r = atol( tmp );
    data = GetNextWord1( data, tmp );
    if( *tmp == '\0' ) {
        return( ERR_INVALID_LOCATE );
    }
    c = atoi( tmp );

    // real selection length
    while( isspace( *data ) ) {
        data++;
    }
    len = 0;
    if( *data != 0 ) {
        data = GetNextWord1( data, tmp );
        if( *tmp == '\0' ) {
            return( ERR_INVALID_LOCATE );
        }
        len = atoi( tmp );
    }

    GoToLineNoRelCurs( r );

    c = RealColumnOnCurrentLine( c );
    GoToColumnOnCurrentLine( c + len );

#ifdef __WIN__
    // likely only called by dde, which doesn't use event loop,
    // so must ensure cache ok and set cursor here

    DCInvalidateAllLines();
    DCDisplayAllLines();
    DCUpdate();
    SetWindowCursor();
    SetWindowCursorForReal();
#endif

    if( len > 0 ) {
        SetSelRegionCols( CurrentPos.line, c, c + len - 1 );
    }
    return( ERR_NO_ERR );

} /* LocateCmd */
Esempio n. 16
0
int PASCAL WinMain( HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show )
{
    char buffer[PATH_MAX];

#if !defined( __WATCOMC__ ) && defined( __NT__ )
    _argc = __argc;
    _argv = __argv;
#endif
    EXEName = _cmdname( buffer );
    InstanceHandle = inst;
    showHow = show;
    prev = prev;
    cmdline = cmdline;

    InitMem();

#ifndef __NT__
    if( prev != NULL && !HasShare() ) {
        MessageBox( NULLHANDLE, "SHARE.EXE must be loaded before starting Windows in order to run multiple instances of the editor",
                    EditorName, MB_OK );
        MyGetInstanceData( (unsigned short) prev, (void near *) &Root, sizeof( Root ) );
        SetFocus( Root );
        return( 0 );
    }
#endif

    Comspec = getenv( "COMSPEC" );
#ifdef __NT__
    VarAddGlobalStr( "OS", "winnt" );
#else
    VarAddGlobalStr( "OS", "win" );
#endif
    SetConfigFileName( CFG_NAME );
    ReadProfile();

    ShowStartupDialog();

    initApplication();
    if( !initInstance() ) {
        return( 0 );
    }
    InitializeEditor();
    SetSaveConfig();
    if( !BAD_ID( CurrentWindow ) ) {
        SetFocus( Root );
    }

    SetWindowCursorForReal();
    ResizeRoot();
    EditMain();

    FiniMem();

    return( 0 );

} /* WinMain */
Esempio n. 17
0
/*
 * RefreshSSbar - turn status settings bar on/off
 */
void RefreshSSbar( void )
{
    static FARPROC      proc = NULL;

    if( EditFlags.SSbar ) {
        if( !BAD_ID( hSSbar ) ) {
            return;
        }
        proc = MakeDlgProcInstance( SSDlgProc, InstanceHandle );
        hSSbar = CreateDialog( InstanceHandle, "SSBAR", root_window_id, (DLGPROC)proc );
    } else {
        if( BAD_ID( hSSbar ) ) {
            return;
        }
        SendMessage( hSSbar, WM_CLOSE, 0, 0L );
        FreeProcInstance( proc );
    }
    UpdateStatusWindow();

} /* RefreshSSbar */
Esempio n. 18
0
/*
 * NewMessageWindow - create a new Message window
 */
vi_rc NewMessageWindow( void )
{
    if( !EditFlags.WindowsStarted ) {
        return( ERR_NO_ERR );
    }
    if( !BAD_ID( message_window_id ) ) {
        CloseAWindow( message_window_id );
        message_window_id = NO_WINDOW;
    }
    return( NewWindow2( &message_window_id, &messagew_info ) );

} /* NewMessageWindow */
Esempio n. 19
0
/*
 * ResizeRoot - change root to new size
 */
void ResizeRoot( void )
{
    RECT        rect;
    RECT        root_rect;
    int         height;
    HWND        bufHwnd;

    if( !EditFlags.WindowsStarted ) {
        return;
    }
    GetClientRect( root_window_id, &root_rect );
    DefaultWindows( &root_rect, &rect );
    if( !BAD_ID( message_window_id ) ) {
        NewMessageWindow();
        if( !BAD_ID( message_window_id ) ) {
            InvalidateRect( message_window_id, NULL, FALSE );
            SendMessage( message_window_id, WM_PAINT, 0, 0L );
        }
    }
    if( !BAD_ID( status_window_id ) ) {
        NewStatusWindow();
        if( !BAD_ID( status_window_id ) ) {
            InvalidateRect( status_window_id, NULL, FALSE );
            SendMessage( status_window_id, WM_PAINT, 0, 0L );
        }
    }
    height = rect.bottom - rect.top;
    MoveWindow( edit_container_id, rect.left, rect.top, rect.right - rect.left, height, TRUE );
    if( CurrentInfo ) {
        bufHwnd = CurrentInfo->current_window_id;
        if( IsWindow( bufHwnd ) && IsZoomed( bufHwnd ) ) {
            ShowWindow( bufHwnd, SW_SHOWMAXIMIZED );
        }
    }
    InvalidateRect( root_window_id, NULL, TRUE );

} /* ResizeRoot */
Esempio n. 20
0
WINEXPORT LRESULT CALLBACK CommandWindowProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l )
{
    PAINTSTRUCT ps;
    HDC         hdc;
    window_id   wid;

    switch( msg ) {
    case WM_CREATE:
        command_window_id = hwnd;
        SET_WNDINFO( hwnd, (LONG_PTR)&CommandWindow );
        break;
    case WM_SETFOCUS:
        /* turn on caret */
        NewCursor( hwnd, EditVars.NormalCursorType );
        break;
    case WM_KILLFOCUS:
        /* turn off the caret */
        MyHideCaret( hwnd );
        DestroyCaret();
        wid = (window_id)w;
        if( !BAD_ID( wid ) && ( wid == root_window_id || GetWindow( wid, GW_OWNER ) == edit_container_id ) ) {
            /* hmmm... losing focus to one of our own windows - suicide */
            if( ReadingAString ) {
                KeyAdd( VI_KEY( ESC ) );
            }
        }
        break;
    case WM_KEYDOWN:
        if( WindowsKeyPush( w, HIWORD( l ) ) ) {
            return( 0 );
        }
        break;
    case WM_PAINT:
        hdc = BeginPaint( hwnd, &ps );
        FillRect( hdc, &ps.rcPaint, ColorBrush( WIN_TEXT_BACKCOLOR( &CommandWindow ) ) );
        /* this will cause the command window to redraw itself in readstr.c */
        KeyAdd( VI_KEY( ALT_END ) );
        EndPaint( hwnd, &ps );
        break;
    case WM_DESTROY:
        command_window_id = NO_WINDOW;
        break;
    }
    return( DefWindowProc( hwnd, msg, w, l ) );
}
Esempio n. 21
0
static void sendNewItem( int x, int id )
{
    int     i;

    if( BAD_ID( mod_hwnd ) ) {
        return;
    }
    assert( mod_hwnd == status_window_id );

    for( i = 0; i < EditVars.NumStatusSections; ++i ) {
        if( EditVars.StatusSections[i] >= x ) {
            break;
        }
    }

    assert( curItemID != -1 );
    buildNewStatusString( i, id );
}
Esempio n. 22
0
static void msgString( int line_no, char *str )
{
    int     height;
    RECT    rect;
    HDC     hdc;

    if( !AllowDisplay || BAD_ID( MessageWindow ) ) {
        return;
    }
    GetClientRect( MessageWindow, &rect );
    height = FontHeight( WIN_FONT( &MessageBar ) );
    rect.top += (line_no - 1) * height;
    rect.bottom = rect.top + height;
    hdc = TextGetDC( MessageWindow, WIN_STYLE( &MessageBar ) );
    FillRect( hdc, &rect, ColorBrush( WIN_BACKCOLOR( &MessageBar ) ) );
    TextReleaseDC( MessageWindow, hdc );
    WriteString( MessageWindow, 0, rect.top, WIN_STYLE( &MessageBar ), str );
}
Esempio n. 23
0
/*
 * drawRepeatString - draw the current repeat string
 */
static void drawRepeatString( void )
{
    int     height;
    RECT    rect;
    HDC     hdc;

    if( !AllowDisplay || BAD_ID( repeat_window_id ) ) {
        return;
    }
    GetClientRect( repeat_window_id, &rect );
    height = FontHeight( WIN_TEXT_FONT( &RepeatCountWindow ) );
    rect.bottom = rect.top + height;
    hdc = TextGetDC( repeat_window_id, WIN_TEXT_STYLE( &RepeatCountWindow ) );
    FillRect( hdc, &rect, ColorBrush( WIN_TEXT_BACKCOLOR( &RepeatCountWindow ) ) );
    TextReleaseDC( repeat_window_id, hdc );
    WriteString( repeat_window_id, 0, rect.top, WIN_TEXT_STYLE( &RepeatCountWindow ), repString );

} /* drawRepeatString */
Esempio n. 24
0
/*
 * NewStatusWindow - create a new status window
 */
vi_rc NewStatusWindow( void )
{
    vi_rc   rc = ERR_NO_ERR;

    if( !EditFlags.WindowsStarted ) {
        return( ERR_NO_ERR );
    }
    if( !BAD_ID( status_window_id ) ) {
        CloseAWindow( status_window_id );
        status_window_id = NO_WINDOW;
    }
    if( EditFlags.StatusInfo ) {
        rc = NewWindow2( &status_window_id, &statusw_info );
        UpdateStatusWindow();
    }
    return( rc );

} /* NewStatusWindow */
Esempio n. 25
0
/*
 * Message2 - display message on line 2
 */
void Message2( const char *str, ... )
{
    va_list     al;
    char        tmp[MAX_STR];

    if( !EditFlags.EchoOn || BAD_ID( message_window_id ) ) {
        return;
    }
    va_start( al, str );
    MyVSprintf( tmp,str, al );
    va_end( al );
    tmp[EditVars.WindMaxWidth - 1] = '\0';

    if( !EditFlags.LineDisplay ) {
        DisplayLineInWindow( message_window_id, 2, tmp );
    } else {
        MyPrintf( "%s\n", tmp );
    }

} /* Message2 */
Esempio n. 26
0
/*
 * RepeatWindowProc - message procedure for the repeat count window
 */
WINEXPORT LRESULT CALLBACK RepeatWindowProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l )
{
    PAINTSTRUCT ps;

    switch( msg ) {
    case WM_CREATE:
        SET_WNDINFO( hwnd, (LONG_PTR)&RepeatCountWindow );
        break;
    case WM_PAINT:
        BeginPaint( hwnd, &ps );
        if( !BAD_ID( repeat_window_id ) ) {
            drawRepeatString();
        }
        EndPaint( hwnd, &ps );
        return( 0 );
    case WM_SETFOCUS:
        SetFocus( root_window_id );
        return( 0 );
    }
    return( DefWindowProc( hwnd, msg, w, l ) );

} /* RepeatWindowProc */
Esempio n. 27
0
WINEXPORT LRESULT CALLBACK MessageWindowProc( HWND hwnd, UINT msg, WPARAM w, LPARAM l )
{
    PAINTSTRUCT ps;

    switch( msg ) {
    case WM_CREATE:
        SET_WNDINFO( hwnd, (LONG_PTR)&MessageBar );
        break;
    case WM_PAINT:
        BeginPaint( hwnd, &ps );
        if( !BAD_ID( MessageWindow ) ) {
            msgString( 1, msgString1 );
            msgString( 2, msgString2 );
        }
        EndPaint( hwnd, &ps );
        return( 0 );
    case WM_SETFOCUS:
        SetFocus( Root );
        return( 0 );
    }
    return( DefWindowProc( hwnd, msg, w, l ) );
}
Esempio n. 28
0
/*
 * PromptFilesForSave - prompt to save for each file which has
 * been modified.
 */
bool PromptFilesForSave( void )
{
#ifdef __WIN__
    info        *cinfo;
    int         i;
    int         num = 0;
    HWND        hwnd_old = NO_WINDOW;

    if( !EditFlags.SaveOnBuild ) {
        return( true );
    }

    for( cinfo = InfoHead; cinfo != NULL; cinfo = cinfo->next ) {
        num++;
    }

    BringUpFile( InfoHead, true );
    for( i = 0; i < num; i++ ) {
        if( CurrentFile != NULL && CurrentFile->dup_count == 0 &&
            CurrentFile->modified ) {

            /* we have a modified file, so bring to the front */
            BringWindowToTop( root_window_id );
            hwnd_old = SetFocus( root_window_id );

            // file modified -- so prompt for save
            FilePromptForSaveChanges( CurrentFile );
        }
        RotateFileForward();
    }
    if( !BAD_ID( hwnd_old ) ) {
        SetWindowPos( root_window_id, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE );
        SetFocus( hwnd_old );
    }
#endif
    return( true );

} /* PromptFilesForSave */
Esempio n. 29
0
//==============================================================================
void GameServer::HandleEquip_(const QVariantMap& request, QVariantMap& response)
{
#define BAD_ID(COND)\
  if (COND)\
  {\
    WriteResult_(response, EFEMPResult::BAD_ID);\
    return;\
  }\

  BAD_ID(request.find("id") == request.end());
  BAD_ID(!request["id"].toInt());

  QString slot = request["slot"].toString();
  if (SlotToString.find(slot) == SlotToString.end())
  {
    WriteResult_(response, EFEMPResult::BAD_SLOT);
    return;
  }

  int id = request["id"].toInt();
  auto sid = request["sid"].toByteArray();
  Player* p = sidToPlayer_[sid];

  BAD_ID((idToActor_.find(id) == idToActor_.end()) && !p->GetItemId(id));

  if (p->GetItemId(id))
  {
    //equip item from inventory
    for (auto& item: p->items_)
    {
      if (item->GetId() == id)
      {
        Item* i = p->GetSlot(SlotToString[slot]);
        if (i)
        {
          p->items_.push_back(i);
        }
        if (!p->SetSlot(SlotToString[slot], item))
        {
          WriteResult_(response, EFEMPResult::BAD_SLOT);
          return;
        }
        p->SetStat(true, item);
        p->items_.erase(std::remove(p->items_.begin(), p->items_.end(), item), p->items_.end());

        WriteResult_(response, EFEMPResult::OK);
        return;
      }
    }
    BAD_ID(true);
  }  
  else
  {
    //item is on the ground
    Item* item = dynamic_cast<Item*>(idToActor_[id]);
    BAD_ID(!item);
    Vector2 player_pos = p->GetPosition();
    Vector2 item_pos = item->GetPosition();
    float distance2 = Sqr(player_pos.x - item_pos.x) + Sqr(player_pos.y - item_pos.y);

    BAD_ID(distance2 > Sqr(pickUpRadius_))
    if (!p->SetSlot(SlotToString[slot], item))
    {
      WriteResult_(response, EFEMPResult::BAD_SLOT);
      return;
    }
    p->SetStat(true, item);
    //KillActor_(item); ???
    idToActor_.erase(item->GetId());
    actors_.erase(std::remove(actors_.begin(), actors_.end(), item), actors_.end());
  }

#undef BAD_ID
}
Esempio n. 30
0
/*
 * MainWindowProc - procedure for main (root) window
 */
WINEXPORT LRESULT CALLBACK MainWindowProc( HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam )
{
    RECT        rect;
    vi_rc       rc;
    HANDLE      hfileinfo;
    int         cnt, i;
    char        *buff;

    switch( msg ) {
    case WM_CREATE:
        Root = hwnd;
        GetClientRect( hwnd, &rect );
        EditContainer = CreateContainerWindow( &rect );
        InitWindows();
        DragAcceptFiles( hwnd, TRUE );
        timerID = SetTimer( hwnd, TIMER_ID, 60L * 1000L, NULL );
        break;
    case WM_DROPFILES:
        hfileinfo = (HANDLE) wparam;
        cnt = DragQueryFile( hfileinfo, (UINT)-1, NULL, 0 );
        buff = alloca( FILENAME_MAX + 2 );   /* we add a " at the beginning and at the end so we can handle path- and filenames with spaces */
        if( buff != NULL ) {
            buff[0] = '"';      /* one " at the beginning of the filename */
            for( i = 0; i < cnt; i++ ) {
                if( DragQueryFile( hfileinfo, i, buff + 1, FILENAME_MAX ) == (UINT)-1 ) {
                    break;
                }
                strcat( buff, "\"" );
                rc = EditFile( buff, FALSE );
                if( rc > ERR_NO_ERR ) {
                    Error( GetErrorMsg( rc ) );
                }
            }
        }
        DragFinish( hfileinfo );
        break;
    case WM_TIMER:
        UpdateStatusWindow();
        break;
    case WM_KEYDOWN:
        if( WindowsKeyPush( wparam, HIWORD( lparam ) ) ) {
            return( 0 );
        }
        break;
    case WM_SIZE:
        DefFrameProc( hwnd, EditContainer, msg, wparam, lparam );
        RootState = wparam;
        if( wparam != SIZE_MINIMIZED ) {
            ResizeRoot();
            GetWindowRect( hwnd, &RootRect );
            if( wparam != SIZE_MAXIMIZED ) {
                RootState = 0;
            }
        }
        return( 0 );
    case WM_MOVE:
        DefFrameProc( hwnd, EditContainer, msg, wparam, lparam );
        if( RootState != SIZE_MINIMIZED ) {
            GetWindowRect( hwnd, &RootRect );
        }
        return( 0 );
    case WM_ACTIVATEAPP:
        if( BAD_ID( CurrentWindow ) ) {
            break;
        }
        SetFocus( Root );
#if 0
        if( !wparam ) {
            InactiveWindow( CurrentWindow );
        } else {
            SendMessage( EditContainer, WM_MDIACTIVATE, (WPARAM)CurrentWindow, 0L );
        }
#endif
        if( wparam ) {
            ResetEditWindowCursor( CurrentWindow );
        } else {
            GoodbyeCursor( CurrentWindow );
        }
        break;
    case WM_MOUSEACTIVATE:
        SetFocus( hwnd );
        return( MA_ACTIVATE );
    case WM_SETFOCUS:
        if( BAD_ID( CurrentWindow ) ) {
            break;
        }
        if( !IsIconic( CurrentWindow ) ) {
            SendMessage( EditContainer, WM_MDIACTIVATE, (WPARAM)CurrentWindow, 0L );
            DCUpdate();
            SetWindowCursor();
            SetWindowCursorForReal();
            return( 0 );
        }
        break;
    case WM_NCLBUTTONDBLCLK:
        break;
    case WM_COMMAND:
        if( LOWORD( wparam ) > 0xF000 ) {
            break;
        } else {
            rc = MenuCommand( LOWORD( wparam ) );
            if( rc != MENU_COMMAND_NOT_HANDLED ) {
                DCUpdateAll();
                if( rc > ERR_NO_ERR ) {
                    char        *msg;
                    msg = GetErrorMsg( rc );
                    Error( msg );
                }
            }
            SetWindowCursor();
        }
        return( 0 );
    case WM_INITMENU:
        if( (HMENU)wparam == GetMenu( hwnd ) ) {
            HandleInitMenu( (HMENU)wparam );
        } else {
            ResetMenuBits();
        }
        break;
    case WM_MENUSELECT:
        HandleMenuSelect( wparam, lparam );
        break;
    case WM_ENDSESSION:
        if( wparam ) {
            ExitEditor( 0 );
            // will not return
        }
        return( 0 );
    case WM_QUERYENDSESSION:
        return( ExitWithPrompt( FALSE, TRUE ) );
    case WM_CLOSE:
        ExitWithPrompt( TRUE, TRUE );
        return( 0 );
#ifdef __NT__        
    case WM_MOUSEWHEEL:
        {
            int     i, increment;
            ULONG   linesPerNotch;
            HWND    activeWnd;
            
            activeWnd = (HWND)SendMessage( EditContainer, WM_MDIGETACTIVE, 0, 0 );
            SystemParametersInfo( SPI_GETWHEELSCROLLLINES, 0, &linesPerNotch, 0 );
            
            increment = GET_WHEEL_DELTA_WPARAM( wparam ) / 120;
                // see WM_MOUSEWHEEL-documentation for information about the "120"

            if( increment > 0 ) {
                for( i = 0; i < increment * (int)linesPerNotch; i++ ) {
                    SendMessage( activeWnd, WM_VSCROLL, SB_LINEUP, 0 );
                }
            } else {
                for( i = 0; i < (-increment) * (int)linesPerNotch; i++ ) {
                    SendMessage( activeWnd, WM_VSCROLL, SB_LINEDOWN, 0 );
                }
            }
        }
        return( 0 );
#endif
    case WM_DESTROY:
        DestroyToolBar();
        DragAcceptFiles( hwnd, FALSE );
        EditContainer = 0;
        if( timerID ) {
            KillTimer( hwnd, TIMER_ID );
        }
        return( 0 );
    }
    return( DefFrameProc( hwnd, EditContainer, msg, wparam, lparam ) );

} /* MainWindowProc */