private void Configs_Save_B_Click(object sender, RoutedEventArgs e) { StreamWriter s = File.CreateText(Path + "/Resources/Map_Setting.dat"); s.Close(); Map_Setting obj = new Map_Setting { Map_Scale = Map_Scale, Map_X = Map_X, Map_Y = Map_Y, Map_Z = Map_Z, Map_Rotate = Map_Rotate, Sky_Enable = Sky_Enable, Name = Name }; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Map_Setting)); StreamWriter sw = new StreamWriter(Path + "/Resources/Map_Setting.dat", false, new System.Text.UTF8Encoding(false)); serializer.Serialize(sw, obj); sw.Close(); MessageBox.Show("保存しました。"); }
private async void Save_B_Click(object sender, RoutedEventArgs e) { if (IsModelCreating) { MessageBox.Show("処理が実行中です。"); return; } if (Map_Scale_T.Text == "") { MessageBox.Show("マップサイズの欄が空白です。"); return; } else if (Map_Scale_T.Text == "0") { MessageBox.Show("マップサイズを0にすることはできません。"); return; } try { Map_X = int.Parse(Map_Position_X.Text); Map_Y = int.Parse(Map_Position_Y.Text); Map_Z = int.Parse(Map_Position_Z.Text); } catch { MessageBox.Show("位置が正しくありません。"); return; } try { Map_Scale = int.Parse(Map_Scale_T.Text); } catch { MessageBox.Show("マップサイズが正しくありません。"); return; } try { Map_Rotate = int.Parse(Map_Rotate_T.Text); } catch { MessageBox.Show("横回転の項目に誤りがあります。"); return; } IsModelCreating = true; Menu.Visibility = Visibility.Visible; Wait_P.Visibility = Visibility.Visible; Wait_T.Visibility = Visibility.Visible; while (Wait_T.Opacity < 1) { Wait_P.Opacity += 0.05; Wait_T.Opacity += 0.05; await Task.Delay(1000 / 60); } bool Wait = true; Task task_01 = Task.Run(() => { Task task_02 = Task.Run(() => { int ModelHandle = DX.MV1LoadModel(FilePath); DX.MV1SaveModelToMV1File(ModelHandle, Path + "/Resources/Map/UserMap/Model.mv1", DX.MV1_SAVETYPE_NORMAL, 0, DX.FALSE, 0, 0, 0, 0); DX.MV1DeleteModel(ModelHandle); }); task_02.Wait(); Wait = false; }); while (Wait) { await Task.Delay(1000); } Wait_T.Text = "処理が完了しました。"; await Task.Delay(500); while (Wait_T.Opacity > 0) { Wait_P.Opacity -= 0.05; Wait_T.Opacity -= 0.05; await Task.Delay(1000 / 60); } Wait_P.Visibility = Visibility.Hidden; Wait_T.Visibility = Visibility.Hidden; Menu.Visibility = Visibility.Hidden; IsModelCreating = false; StreamWriter s = File.CreateText(Path + "/Resources/Map_Setting.dat"); s.Close(); Map_Setting obj = new Map_Setting { Map_Scale = Map_Scale, Map_X = Map_X, Map_Y = Map_Y, Map_Z = Map_Z, Map_Rotate = Map_Rotate, Sky_Enable = Sky_Enable, Name = Name }; System.Xml.Serialization.XmlSerializer serializer = new System.Xml.Serialization.XmlSerializer(typeof(Map_Setting)); StreamWriter sw = new StreamWriter(Path + "/Resources/Map_Setting.dat", false, new System.Text.UTF8Encoding(false)); serializer.Serialize(sw, obj); sw.Close(); XDocument item = XDocument.Load(Path + "/Resources/Setting.dat"); XElement item_01 = item.Element("Setting_Save"); string Temp = ""; string Replace = ""; if (item_01.Element("Map_Select").Value == "0") { Temp = "町"; Replace = "<Map_Select>0</Map_Select>"; } else if (item_01.Element("Map_Select").Value == "1") { Temp = "宇宙"; Replace = "<Map_Select>1</Map_Select>"; } else { return; } MessageBoxResult result = MessageBox.Show("現在指定されているマップは" + Temp + "です。ユーザーマップに変更しますか?", "確認", MessageBoxButton.YesNo, MessageBoxImage.Exclamation, MessageBoxResult.Yes); if (result == MessageBoxResult.Yes) { StreamReader str = new StreamReader(Path + "/Resources/Setting.dat"); string Read = str.ReadToEnd(); str.Close(); File.Delete(Path + "/Resources/Setting.dat"); StreamWriter stw = File.CreateText(Path + "/Resources/Setting.dat"); stw.Write(Read.Replace(Replace, "<Map_Select>2</Map_Select>")); stw.Close(); } }