Pastebin

New pastes are no longer accepted · Stats

Latest Pastes

void play_game(void *data)
{
    View *view = static_cast<View *>(data);

    // TODO: find out why this doesn't work
    /*if(view->game.network_client.connected())
        return;*/

    if(!view->game.network_client.connected())
    {
        view->game.Connect();
    }
    else
    {
        View::LoadState::LoginBox(view);
    }
}

void View::LoadState::MainMenu(View *view)
{
    shared_ptr<Window> main_window(new Window(sdl_rect(0, 0, 640, 480)));

    int bg_id = std::rand() % 7;
    bg_id += 130;
    std::string fn = "gfx/gui/0/" + Variant(bg_id).GetString() + ".bmp";
    SDL_Texture *menu_background = view->texture_loader->LoadTexture(fn, view->renderer, false);
    main_window->background = menu_background;

    SDL_Texture *button_set = view->texture_loader->LoadTexture("gfx/gui/0/113.bmp", view->Renderer());

    SDL_Rect rect;
    rect.x = 25;
    rect.y = 280;
    rect.w = 180;
    rect.h = 40;

    shared_ptr<Button> button(new Button(rect, button_set, 0));
    main_window->AddChild(button);

    rect.y += rect.h;
    button.reset(new Button(rect, button_set, 1));
    button->RegisterFunction(BUTTON_EVENT_CLICK, play_game, view);
    main_window->AddChild(button);

    rect.y += rect.h;
    button.reset(new Button(rect, button_set, 2));
    main_window->AddChild(button);

    rect.y += rect.h;
    button.reset(new Button(rect, button_set, 3));
    button->RegisterFunction(BUTTON_EVENT_CLICK, exit_game, view);
    main_window->AddChild(button);

    view->gui.AddChild(main_window, "main_window");
}