void Screen::ShowBadError(const char *msg) { fprintf(stderr, "%s", msg); baseContainer->HideChildren(); Gui::Fixed *f = new Gui::Fixed(6*GetWidth()/8, 6*GetHeight()/8); Gui::Screen::AddBaseWidget(f, GetWidth()/8, GetHeight()/8); f->SetTransparency(false); f->SetBgColor(0.4,0,0,1.0); f->Add(new Gui::Label(msg), 10, 10); Gui::Button *okButton = new Gui::LabelButton(new Gui::Label("Ok")); okButton->SetShortcut(SDLK_RETURN, KMOD_NONE); f->Add(okButton, 10, 6*GetHeight()/8 - 32); f->ShowAll(); f->Show(); do { Gui::MainLoopIteration(); SDL_Delay(10); } while (!okButton->IsPressed()); Gui::Screen::RemoveBaseWidget(f); delete f; baseContainer->ShowAll(); }
void Screen::ShowBadError(const char *msg) { // to make things simple for ourselves, we want to hide all the existing widgets // however, if we do it through baseContainer->HideChildren() then we lose track of // which widgets should be shown again when the red-screen is cleared. // So to avoid this problem we don't hide anything, we just temporarily swap to // a different base container which is just used for this red-screen Gui::Fixed *oldBaseContainer = Screen::baseContainer; Screen::baseContainer = new Gui::Fixed(); Screen::baseContainer->SetSize(float(Screen::width), float(Screen::height)); Screen::baseContainer->Show(); Gui::Fixed *f = new Gui::Fixed(6*GetWidth()/8.0f, 6*GetHeight()/8.0f); Gui::Screen::AddBaseWidget(f, GetWidth()/8, GetHeight()/8); f->SetTransparency(false); f->SetBgColor(0.4f,0,0,1.0f); f->Add(new Gui::Label(msg, TextLayout::ColourMarkupNone), 10, 10); Gui::Button *okButton = new Gui::LabelButton(new Gui::Label("Ok")); okButton->SetShortcut(SDLK_RETURN, KMOD_NONE); f->Add(okButton, 10.0f, 6*GetHeight()/8.0f - 32); f->ShowAll(); f->Show(); do { Gui::MainLoopIteration(); SDL_Delay(10); } while (!okButton->IsPressed()); delete f; // Gui::Fixed does a horrible thing and calls Gui::Screen::RemoveBaseWidget(this) in its destructor delete Screen::baseContainer; Screen::baseContainer = oldBaseContainer; }
void UseEquipWidget::UpdateEquip() { DeleteAllChildren(); int numSlots = Pi::player->m_equipment.GetSlotSize(Equip::SLOT_MISSILE); if (numSlots) { float spacing = 380.0f / numSlots; for (int i = 0; i < numSlots; ++i) { const Equip::Type t = Pi::player->m_equipment.Get(Equip::SLOT_MISSILE, i); if (t == Equip::NONE) continue; Gui::Button *b; switch (t) { case Equip::MISSILE_UNGUIDED: b = new Gui::ImageButton(PIONEER_DATA_DIR "/icons/missile_unguided.png"); break; case Equip::MISSILE_GUIDED: b = new Gui::ImageButton(PIONEER_DATA_DIR "/icons/missile_guided.png"); break; case Equip::MISSILE_SMART: b = new Gui::ImageButton(PIONEER_DATA_DIR "/icons/missile_smart.png"); break; default: case Equip::MISSILE_NAVAL: b = new Gui::ImageButton(PIONEER_DATA_DIR "/icons/missile_naval.png"); break; } Add(b, spacing * i, 40); b->onClick.connect(sigc::bind(sigc::mem_fun(this, &UseEquipWidget::FireMissile), i)); b->SetToolTip(Equip::types[t].name); } } { const Equip::Type t = Pi::player->m_equipment.Get(Equip::SLOT_ECM); if (t != Equip::NONE) { Gui::Button *b = 0; if (t == Equip::ECM_BASIC) b = new Gui::ImageButton(PIONEER_DATA_DIR "/icons/ecm_basic.png"); else if (t == Equip::ECM_ADVANCED) b = new Gui::ImageButton(PIONEER_DATA_DIR "/icons/ecm_advanced.png"); assert(b); b->onClick.connect(sigc::mem_fun(Pi::player, &Ship::UseECM)); Add(b, 32, 0); } } }
Viewer(): Gui::Fixed(float(g_width), float(g_height)) { m_model = 0; m_cmesh = 0; m_geom = 0; m_space = new CollisionSpace(); m_showBoundingRadius = false; Gui::Screen::AddBaseWidget(this, 0, 0); SetTransparency(true); m_trisReadout = new Gui::Label(""); Add(m_trisReadout, 500, 0); { Gui::Button *b = new Gui::SolidButton(); b->SetShortcut(SDLK_c, KMOD_NONE); b->onClick.connect(sigc::mem_fun(*this, &Viewer::OnClickChangeView)); Add(b, 10, 10); Add(new Gui::Label("[c] Change view (normal, collision mesh"), 30, 10); } { Gui::Button *b = new Gui::SolidButton(); b->SetShortcut(SDLK_r, KMOD_NONE); b->onClick.connect(sigc::mem_fun(*this, &Viewer::OnResetAdjustments)); Add(b, 10, 30); Add(new Gui::Label("[r] Reset thruster and anim sliders"), 30, 30); } { Gui::Button *b = new Gui::SolidButton(); b->SetShortcut(SDLK_m, KMOD_NONE); b->onClick.connect(sigc::mem_fun(*this, &Viewer::OnClickRebuildCollMesh)); Add(b, 10, 50); Add(new Gui::Label("[m] Rebuild collision mesh"), 30, 50); } { Gui::Button *b = new Gui::SolidButton(); b->SetShortcut(SDLK_p, KMOD_NONE); b->onClick.connect(sigc::mem_fun(*this, &Viewer::OnClickToggleBenchmark)); Add(b, 10, 70); Add(new Gui::Label("[p] Toggle performance test (renders models 1000 times per frame)"), 30, 70); } { Gui::Button *b = new Gui::SolidButton(); b->SetShortcut(SDLK_b, KMOD_LSHIFT); b->onClick.connect(sigc::mem_fun(*this, &Viewer::OnToggleBoundingRadius)); Add(b, 10, 90); Add(new Gui::Label("[shift-b] Visualize bounding radius"), 30, 90); } #if 0 { Gui::Button *b = new Gui::SolidButton(); b->SetShortcut(SDLK_g, KMOD_NONE); b->onClick.connect(sigc::mem_fun(*this, &Viewer::OnToggleGearState)); Add(b, 10, 30); Add(new Gui::Label("[g] Toggle gear state"), 30, 30); } #endif /* 0 */ { Add(new Gui::Label("Linear thrust"), 0, Gui::Screen::GetHeight()-140.0f); for (int i=0; i<3; i++) { m_linthrust[i] = new Gui::Adjustment(); m_linthrust[i]->SetValue(0.5); Gui::VScrollBar *v = new Gui::VScrollBar(); v->SetAdjustment(m_linthrust[i]); Add(v, float(i*25), Gui::Screen::GetHeight()-120.0f); } Add(new Gui::Label("Angular thrust"), 100, Gui::Screen::GetHeight()-140.0f); for (int i=0; i<3; i++) { m_angthrust[i] = new Gui::Adjustment(); m_angthrust[i]->SetValue(0.5); Gui::VScrollBar *v = new Gui::VScrollBar(); v->SetAdjustment(m_angthrust[i]); Add(v, float(100 + i*25), Gui::Screen::GetHeight()-120.0f); } Add(new Gui::Label("Animations (0 gear, 1-4 are time - ignore them comrade)"), 200, Gui::Screen::GetHeight()-140.0f); for (int i=0; i<LMR_ARG_MAX; i++) { Gui::Fixed *box = new Gui::Fixed(32.0f, 120.0f); Add(box, float(200 + i*25), Gui::Screen::GetHeight()-120.0f); m_anim[i] = new Gui::Adjustment(); m_anim[i]->SetValue(0); Gui::VScrollBar *v = new Gui::VScrollBar(); v->SetAdjustment(m_anim[i]); box->Add(v, 0, 42.0f); char buf[32]; snprintf(buf, sizeof(buf), "%d", i); box->Add(new Gui::Label(buf), 0, 0); m_animEntry[i] = new Gui::TextEntry(); box->Add(m_animEntry[i], 0, 16.0f); m_anim[i]->onValueChanged.connect(sigc::bind(sigc::mem_fun(this, &Viewer::OnAnimChange), m_anim[i], m_animEntry[i])); OnAnimChange(m_anim[i], m_animEntry[i]); } } ShowAll(); Show(); }
void Menu::initialize() { appService.getConsole().printLine("\n===Menu initialization==="); menuBannerTexture = appService.getTextureManager().load(D6_TEXTURE_MENU_PATH, TextureFilter::LINEAR, true); appService.getConsole().printLine("...Starting GUI library"); gui.screenSize(video.getScreen().getClientWidth(), video.getScreen().getClientHeight(), (video.getScreen().getClientWidth() - 800) / 2, (video.getScreen().getClientHeight() - 600) / 2); listbox[0] = new Gui::ListBox(gui, true); listbox[0]->setPosition(10, 199, 94, 12, 16); listbox[ALL_PLAYER_LIST] = new Gui::ListBox(gui, true); listbox[ALL_PLAYER_LIST]->setPosition(10, 470, 20, 13, 18); listbox[ALL_PLAYER_LIST]->onDoubleClick([this](Gui::ListBox& listBox, Int32 index, const std::string& item) { addPlayer(index); }); listbox[CUR_PLAYERS_LIST] = new Gui::ListBox(gui, false); listbox[CUR_PLAYERS_LIST]->setPosition(200, 470, 20, D6_MAX_PLAYERS, 18); listbox[CUR_PLAYERS_LIST]->onDoubleClick([this](Gui::ListBox& listBox, Int32 index, const std::string& item) { removePlayer(index); }); listbox[3] = new Gui::ListBox(gui, true); listbox[3]->setPosition(654, 410, 13, 6, 16); listbox[4] = new Gui::ListBox(gui, true); listbox[4]->setPosition(520, 363, 13, 3, 16); listbox[5] = new Gui::ListBox(gui, false); listbox[5]->setPosition(654, 470, 15, 2, 16); listbox[5]->addItem("Fullscreen"); listbox[5]->addItem("Split screen"); listbox[6] = new Gui::ListBox(gui, true); listbox[6]->setPosition(520, 470, 13, 5, 16); loadPersonProfiles(D6_FILE_PROFILES); loadPersonData(D6_FILE_PHIST); button[0] = new Gui::Button(gui); button[0]->setPosition(200, 282, 80, 25); button[0]->setCaption(">>"); button[0]->onClick([this](Gui::Button&) { addPlayer(listbox[ALL_PLAYER_LIST]->selectedIndex()); }); button[1] = new Gui::Button(gui); button[1]->setPosition(200, 253, 80, 25); button[1]->setCaption("<<"); button[1]->onClick([this](Gui::Button&) { removePlayer(listbox[CUR_PLAYERS_LIST]->selectedIndex()); }); button[2] = new Gui::Button(gui); button[2]->setPosition(284, 282, 80, 25); button[2]->setCaption("Remove"); button[2]->onClick([this](Gui::Button&) { deletePerson(); rebuildTable(); }); button[3] = new Gui::Button(gui); button[3]->setPosition(284, 253, 80, 25); button[3]->setCaption("Add"); button[3]->onClick([this](Gui::Button&) { addPerson(); }); button[6] = new Gui::Button(gui); button[6]->setPosition(370, 282, 125, 25); button[6]->setCaption("Clear (F3)"); button[6]->onClick([this](Gui::Button&) { if (deleteQuestion()) { cleanPersonData(); } }); button[4] = new Gui::Button(gui); button[4]->setPosition(520, 299, 125, 73); button[4]->setCaption("Play (F1)"); button[4]->onClick([this](Gui::Button&) { play(); }); button[5] = new Gui::Button(gui); button[5]->setPosition(654, 299, 125, 73); button[5]->setCaption("Quit (ESC)"); button[5]->onClick([this](Gui::Button&) { close(); }); label[0] = new Gui::Label(gui); label[0]->setPosition(10, 219, 772, 18); label[0]->setCaption(" Name | Games | Wins | Shots | Accuracy | Kills | Penalties | Points | Alive | Time"); label[1] = new Gui::Label(gui); label[1]->setPosition(520, 383, 125, 18); label[1]->setCaption("Background"); label[2] = new Gui::Label(gui); label[2]->setPosition(654, 429, 125, 18); label[2]->setCaption("Level"); label[3] = new Gui::Label(gui); label[3]->setPosition(654, 489, 125, 18); label[3]->setCaption("Screen mode"); label[4] = new Gui::Label(gui); label[4]->setPosition(520, 489, 125, 18); label[4]->setCaption("Zoom"); label[5] = new Gui::Label(gui); label[5]->setPosition(10, 489, 181, 18); label[5]->setCaption("Persons"); label[6] = new Gui::Label(gui); label[6]->setPosition(200, 489, 165, 18); label[6]->setCaption("Players"); label[7] = new Gui::Label(gui); label[7]->setPosition(370, 489, 120, 18); label[7]->setCaption("Controller"); textbox = new Gui::Textbox(gui); textbox->setPosition(370, 252, 14, 10, D6_ALL_CHR); // Switchbox - volba ovladani for (Size i = 0; i < D6_MAX_PLAYERS; i++) { controlSwitch[i] = new Gui::Spinner(gui); controlSwitch[i]->setPosition(370, 468 - i * 18, 120, 0); // TODO: Might be deleted in future if the use case is fully covered with detect-all functionality Gui::Button* button = new Gui::Button(gui); button->setCaption("D"); button->setPosition(494, 466 - i * 18, 17, 17); button->onClick([this,i](Gui::Button&) { detectControls(i); }); } // Button to detect all user's controllers in a batch Gui::Button* button = new Gui::Button(gui); button->setCaption("D"); button->setPosition(490, 487, 24, 17); button->onClick([this](Gui::Button&){ Size curPlayersCount = listbox[CUR_PLAYERS_LIST]->size(); for (Size j = 0; j < curPlayersCount; j++) { detectControls(j); } }); initializeGameModes(); gameModeSwitch = new Gui::Spinner(gui); for(auto& gameMode : gameModes) { gameModeSwitch->addItem(gameMode->getName()); } gameModeSwitch->setPosition(10, 0, 330, 20); joyRescan(); backgroundCount = File::countFiles(D6_TEXTURE_BCG_PATH, D6_TEXTURE_EXTENSION); levelList.initialize(D6_FILE_LEVEL, D6_LEVEL_EXTENSION); listbox[3]->addItem("Random"); for (Size i = 0; i < levelList.getLength(); i++) { listbox[3]->addItem(levelList.getFileName(i).substr(0, levelList.getFileName(i).rfind("."))); } listbox[4]->addItem("Random"); for (Size i = 0; i < backgroundCount; i++) { listbox[4]->addItem(std::to_string(i + 1)); } for (Int32 i = 5; i < 21; i++) { listbox[6]->addItem(std::to_string(i)); } listbox[6]->selectItem(8).scrollToView(8); menuTrack = sound.loadModule("sound/undead.xm"); }
void SSHowTo::Startup() { g_GUI.BringWindowToFront( "DebugWindow" ); glm::ivec2 windowSize = g_GUI.GetWindowSize( "RootWindow" ); g_GUI.AddWindow( m_WindowName, GUI::Rectangle( 0, 0, windowSize.x, windowSize.y ), "RootWindow" ); //g_GUI.OpenWindow( m_WindowName ); g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, windowSize.x, windowSize.y, glm::vec4( 0.05f, 0.05f, 0.1f, 1.0f ) ), m_WindowName ); LoadTextures(); m_Image = g_GUI.AddSprite( "", GUI::SpriteDefinition( "", ( windowSize.x / 2 ) - (m_BackgroundSize.x / 2), ( windowSize.y / 2 ) - (m_BackgroundSize.y / 2), m_BackgroundSize.x, m_BackgroundSize.y ), m_WindowName ); if( m_Textures.size() > 0 ) m_Image->GetSpriteDefinitionRef().TextureHandle = m_Textures[0]->GetHandle(); g_GUI.UseFont( FONT_ID_LEKTON_20 ); GUI::Button* back = g_GUI.AddButton( "", GUI::Rectangle( 5, windowSize.y - 64 - 5, 256, 64 ), m_WindowName ); m_ButtonPrevious = g_GUI.AddButton( "", GUI::Rectangle( (windowSize.x / 2) - 256, windowSize.y - 64 - 5, 256, 64 ), m_WindowName ); m_ButtonNext = g_GUI.AddButton( "", GUI::Rectangle( (windowSize.x / 2) , windowSize.y - 64 - 5, 256, 64 ), m_WindowName ); back->SetClickScript( "GE_BackFromHowTo()" ); m_ButtonPrevious->SetClickScript( "GE_PreviousImage()" ); m_ButtonNext->SetClickScript( "GE_NextImage()" ); back->SetText( "Back"); m_ButtonPrevious->SetText( "Previous"); m_ButtonNext->SetText( "Next"); back->SetBackgroundImage( "Button.png" ); m_ButtonPrevious->SetBackgroundImage( "Button.png" ); m_ButtonNext->SetBackgroundImage( "Button.png" ); //Script functions that are to be called by buttons g_Script.Register( "GE_BackFromHowTo", [this] ( IScriptEngine* ) -> int { //g_GameModeSelector.SwitchToGameMode( GameModeType::MainMenu ); g_Script.Perform( "CloseWindow('HowTo'); OpenWindow('MainMenu')" ); return 0; } ); g_Script.Register( "GE_PreviousImage", [this] ( IScriptEngine* ) -> int { m_HowToIndex--; if( m_HowToIndex < 0 ) m_HowToIndex = 0; return 0; } ); g_Script.Register( "GE_NextImage", [this] ( IScriptEngine* ) -> int { m_HowToIndex++; if( m_HowToIndex >= m_Textures.size() ) m_HowToIndex = static_cast<int>( m_Textures.size() ) - 1; return 0; } ); }
void SSMainMenu::Startup() { g_GUI.BringWindowToFront( "DebugWindow" ); glm::ivec2 windowSize = g_GUI.GetWindowSize( "RootWindow" ); g_GUI.AddWindow( "MainMenu", GUI::Rectangle( 0, 0, windowSize.x, windowSize.y ), "RootWindow" ); g_GUI.OpenWindow( "MainMenu" ); //g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, windowSize.x, windowSize.y, glm::vec4( 0.05f, 0.05f, 0.17f, 1.0f ) ), "MainMenu" ); g_GUI.AddSprite( "", GUI::SpriteDefinition( "", 0, 0, windowSize.x, windowSize.y, glm::vec4( 0.05f, 0.05f, 0.1f, 1.0f ) ), "MainMenu" ); int btnWidth = 256; int btnHeight = 64; int btnSpacing = btnHeight + 10; int numButtons = 6; int x = m_LeftOffset; //( windowSize.x / 2 ) - ( btnWidth / 2 ); int y = ( windowSize.y / 2 ) - ( ( btnSpacing * numButtons ) - 10 ) / 2; g_GUI.AddSprite( "", GUI::SpriteDefinition( "Menu_bg.png", x + btnWidth + m_LeftOffset, ( windowSize.y / 2) - ( m_BackgroundSize.y / 2 ), m_BackgroundSize.x, m_BackgroundSize.y, glm::vec4( 1.0f ) ), "MainMenu" ); g_GUI.AddSprite( "", GUI::SpriteDefinition( "Menu_logo.png", 0, y - m_LogoSize.y, m_LogoSize.x, m_LogoSize.y, glm::vec4( 1.0f ) ), "MainMenu" ); g_GUI.UseFont( FONT_ID_LEKTON_20 ); auto setButtonDesign = [] ( GUI::Button* btn ) { btn->SetBackgroundImage( "Button.png" ); btn->SetColour( glm::vec4( 1.0f ) ); btn->SetHighLightColour( glm::vec4( 0.8f, 1.0f, 1.0f, 1.0f ) ); btn->GetBackgroundRef().BorderSize = 0; }; auto addMenuButton =[x, y, btnWidth, btnHeight, btnSpacing, setButtonDesign] ( const rString& text, const rString& script ) mutable -> GUI::Button* { GUI::Button* btn = g_GUI.AddButton( text, GUI::Rectangle( x, y, btnWidth, btnHeight ), "MainMenu" ); btn->SetClickScript( script ); btn->SetText( text ); btn->DisableClickEffect(); setButtonDesign( btn ); y += btnSpacing; return btn; }; //Add the menu buttons here m_SinglePlayerButton = addMenuButton( "Singleplayer", "SwitchGameMode( 'singleplayerlobby' )" ); m_MultiPlayerButton = addMenuButton( "Multiplayer", "SwitchGameMode( 'netlob' )" ); m_ReplayButton = addMenuButton( "Replay", "OpenWindow('ReplaySelectWindow'); CloseWindow( 'MainMenu' )" ); m_OptionsButton = addMenuButton( "How to play", "OpenWindow('HowTo'); CloseWindow( 'MainMenu' )" ); m_OptionsButton = addMenuButton( "Options", "OpenWindow('Options'); CloseWindow( 'MainMenu' )" ); m_ExitButton = addMenuButton( "Exit", "GE_Exit()" ); //Script functions that are to be called by buttons g_Script.Register( "GE_Exit", [] ( IScriptEngine* ) -> int { SDL_Event event; event.type = SDL_QUIT; SDL_PushEvent( &event ); return 0; } ); //Debug stuff //g_Script.Perform( "OpenWindow('Options'); CloseWindow( 'MainMenu' )" ); if ( !g_SSReplaySelectMenu.HasReplays() ) m_ReplayButton->SetEnabled( false ); if(g_SSMusicManager.LoadSceneMusic("../../../asset/audio/script/MainMenu.lua")) g_SSMusicManager.Activate(); }