809 DeleteWindowByClass(WC_GENERATE_LANDSCAPE); |
809 DeleteWindowByClass(WC_GENERATE_LANDSCAPE); |
810 new CreateScenarioWindow(&_create_scenario_desc, GLWP_SCENARIO); |
810 new CreateScenarioWindow(&_create_scenario_desc, GLWP_SCENARIO); |
811 } |
811 } |
812 |
812 |
813 |
813 |
814 static const Widget _show_terrain_progress_widgets[] = { |
814 static const Widget _generate_progress_widgets[] = { |
815 { WWT_CAPTION, RESIZE_NONE, 14, 0, 180, 0, 13, STR_GENERATION_WORLD, STR_018C_WINDOW_TITLE_DRAG_THIS}, |
815 { WWT_CAPTION, RESIZE_NONE, 14, 0, 180, 0, 13, STR_GENERATION_WORLD, STR_018C_WINDOW_TITLE_DRAG_THIS}, // GPWW_CAPTION |
816 { WWT_PANEL, RESIZE_NONE, 14, 0, 180, 14, 96, 0x0, STR_NULL}, |
816 { WWT_PANEL, RESIZE_NONE, 14, 0, 180, 14, 96, 0x0, STR_NULL}, // GPWW_BACKGROUND |
817 { WWT_TEXTBTN, RESIZE_NONE, 15, 20, 161, 74, 85, STR_GENERATION_ABORT, STR_NULL}, // Abort button |
817 { WWT_TEXTBTN, RESIZE_NONE, 15, 20, 161, 74, 85, STR_GENERATION_ABORT, STR_NULL}, // GPWW_ABORT |
818 { WIDGETS_END}, |
818 { WIDGETS_END}, |
|
819 }; |
|
820 |
|
821 static const WindowDesc _generate_progress_desc = { |
|
822 WDP_CENTER, WDP_CENTER, 181, 97, 181, 97, |
|
823 WC_GENERATE_PROGRESS_WINDOW, WC_NONE, |
|
824 WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
|
825 _generate_progress_widgets, |
|
826 NULL |
819 }; |
827 }; |
820 |
828 |
821 struct tp_info { |
829 struct tp_info { |
822 uint percent; |
830 uint percent; |
823 StringID cls; |
831 StringID cls; |
835 } else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) { |
843 } else if (IsGeneratingWorld() && !IsGeneratingWorldAborted()) { |
836 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE); |
844 SetMouseCursor(SPR_CURSOR_ZZZ, PAL_NONE); |
837 } |
845 } |
838 } |
846 } |
839 |
847 |
840 static void ShowTerrainProgressProc(Window* w, WindowEvent* e) |
848 struct GenerateProgressWindow : public Window { |
841 { |
849 private: |
842 switch (e->event) { |
850 enum GenerationProgressWindowWidgets { |
843 case WE_CLICK: |
851 GPWW_CAPTION, |
844 switch (e->we.click.widget) { |
852 GPWW_BACKGROUND, |
845 case 2: |
853 GPWW_ABORT, |
846 if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); |
854 }; |
847 ShowQuery( |
855 |
848 STR_GENERATION_ABORT_CAPTION, |
856 public: |
849 STR_GENERATION_ABORT_MESSAGE, |
857 GenerateProgressWindow() : Window(&_generate_progress_desc) {}; |
850 w, |
858 |
851 AbortGeneratingWorldCallback |
859 virtual void OnClick(Point pt, int widget) |
852 ); |
860 { |
853 break; |
861 switch (widget) { |
854 } |
862 case GPWW_ABORT: |
855 break; |
863 if (_cursor.sprite == SPR_CURSOR_ZZZ) SetMouseCursor(SPR_CURSOR_MOUSE, PAL_NONE); |
856 |
864 ShowQuery( |
857 case WE_PAINT: |
865 STR_GENERATION_ABORT_CAPTION, |
858 DrawWindowWidgets(w); |
866 STR_GENERATION_ABORT_MESSAGE, |
859 |
867 this, |
860 /* Draw the % complete with a bar and a text */ |
868 AbortGeneratingWorldCallback |
861 DrawFrameRect(19, 20, (w->width - 18), 37, 14, FR_BORDERONLY); |
869 ); |
862 DrawFrameRect(20, 21, (int)((w->width - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE); |
870 break; |
863 SetDParam(0, _tp.percent); |
871 } |
864 DrawStringCentered(90, 25, STR_PROGRESS, TC_FROMSTRING); |
872 } |
865 |
873 |
866 /* Tell which class we are generating */ |
874 virtual void OnPaint() |
867 DrawStringCentered(90, 46, _tp.cls, TC_FROMSTRING); |
875 { |
868 |
876 DrawWindowWidgets(this); |
869 /* And say where we are in that class */ |
877 |
870 SetDParam(0, _tp.current); |
878 /* Draw the % complete with a bar and a text */ |
871 SetDParam(1, _tp.total); |
879 DrawFrameRect(19, 20, (this->width - 18), 37, 14, FR_BORDERONLY); |
872 DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING); |
880 DrawFrameRect(20, 21, (int)((this->width - 40) * _tp.percent / 100) + 20, 36, 10, FR_NONE); |
873 |
881 SetDParam(0, _tp.percent); |
874 w->SetDirty(); |
882 DrawStringCentered(90, 25, STR_PROGRESS, TC_FROMSTRING); |
875 break; |
883 |
876 } |
884 /* Tell which class we are generating */ |
877 } |
885 DrawStringCentered(90, 46, _tp.cls, TC_FROMSTRING); |
878 |
886 |
879 static const WindowDesc _show_terrain_progress_desc = { |
887 /* And say where we are in that class */ |
880 WDP_CENTER, WDP_CENTER, 181, 97, 181, 97, |
888 SetDParam(0, _tp.current); |
881 WC_GENERATE_PROGRESS_WINDOW, WC_NONE, |
889 SetDParam(1, _tp.total); |
882 WDF_DEF_WIDGET | WDF_UNCLICK_BUTTONS, |
890 DrawStringCentered(90, 58, STR_GENERATION_PROGRESS, TC_FROMSTRING); |
883 _show_terrain_progress_widgets, |
891 |
884 ShowTerrainProgressProc |
892 this->SetDirty(); |
|
893 } |
885 }; |
894 }; |
886 |
895 |
887 /** |
896 /** |
888 * Initializes the progress counters to the starting point. |
897 * Initializes the progress counters to the starting point. |
889 */ |
898 */ |
899 /** |
908 /** |
900 * Show the window where a user can follow the process of the map generation. |
909 * Show the window where a user can follow the process of the map generation. |
901 */ |
910 */ |
902 void ShowGenerateWorldProgress() |
911 void ShowGenerateWorldProgress() |
903 { |
912 { |
904 AllocateWindowDescFront<Window>(&_show_terrain_progress_desc, 0); |
913 if (BringWindowToFrontById(WC_GENERATE_PROGRESS_WINDOW, 0)) return; |
|
914 new GenerateProgressWindow(); |
905 } |
915 } |
906 |
916 |
907 static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total) |
917 static void _SetGeneratingWorldProgress(gwp_class cls, uint progress, uint total) |
908 { |
918 { |
909 static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 }; |
919 static const int percent_table[GWP_CLASS_COUNT + 1] = {0, 5, 15, 20, 40, 60, 65, 80, 85, 99, 100 }; |