Rev 1496 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 1305 | chris | 1 | using System; |
| 2 | using System.Collections.Generic; |
||
| 3 | using System.ComponentModel; |
||
| 4 | using System.Data; |
||
| 5 | using System.Drawing; |
||
| 6 | using System.Linq; |
||
| 7 | using System.Text; |
||
| 8 | using System.Threading.Tasks; |
||
| 9 | using System.Windows.Forms; |
||
| 1424 | chris | 10 | using System.IO; |
| 1461 | chris | 11 | using System.Reflection; |
| 1305 | chris | 12 | |
| 13 | using Tao.OpenGl; |
||
| 14 | |||
| 15 | using BauzoidNET.app; |
||
| 16 | |||
| 17 | using BurutaruEditor.file; |
||
| 1462 | chris | 18 | using BurutaruEditor.file.elements; |
| 1424 | chris | 19 | using BurutaruEditor.view; |
| 1427 | chris | 20 | using BurutaruEditor.interaction; |
| 1305 | chris | 21 | |
| 22 | namespace BurutaruEditor |
||
| 23 | { |
||
| 24 | public partial class MainForm : Form |
||
| 25 | { |
||
| 1441 | chris | 26 | public enum InteractionMode |
| 27 | { |
||
| 28 | SELECT, |
||
| 29 | CREATE |
||
| 30 | } |
||
| 31 | |||
| 32 | public enum ObjectMode |
||
| 33 | { |
||
| 34 | CHECKPOINTS, |
||
| 1447 | chris | 35 | SPAWNERS, |
| 1441 | chris | 36 | ELEMENTS |
| 37 | } |
||
| 38 | |||
| 1427 | chris | 39 | //=============================================================================================================== |
| 40 | |||
| 1424 | chris | 41 | public static BauzoidApp App = null; |
| 1305 | chris | 42 | |
| 43 | private Document mDocument = null; |
||
| 1423 | chris | 44 | public Document Doc { get { return mDocument; } } |
| 1305 | chris | 45 | |
| 1424 | chris | 46 | private DocumentView mView = null; |
| 1427 | chris | 47 | public DocumentView View { get { return mView; } } |
| 1424 | chris | 48 | |
| 1441 | chris | 49 | private InteractionMode mInteractionMode = InteractionMode.SELECT; |
| 50 | public InteractionMode CurrentInteraction |
||
| 51 | { |
||
| 52 | get { return mInteractionMode; } |
||
| 53 | set |
||
| 54 | { |
||
| 55 | if (value == InteractionMode.SELECT) |
||
| 56 | { |
||
| 57 | EnableCreateButton(false); |
||
| 58 | } |
||
| 59 | else if (value == InteractionMode.CREATE) |
||
| 60 | { |
||
| 61 | EnableCreateButton(true); |
||
| 62 | } |
||
| 63 | mInteractionMode = value; |
||
| 64 | UpdateStatusBar(); |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | private ObjectMode mObjectMode = ObjectMode.CHECKPOINTS; |
||
| 69 | public ObjectMode CurrentObjectMode |
||
| 70 | { |
||
| 71 | get { return mObjectMode; } |
||
| 72 | set |
||
| 73 | { |
||
| 74 | switch (value) |
||
| 75 | { |
||
| 76 | case ObjectMode.CHECKPOINTS: |
||
| 77 | tbcObjects.SelectedTab = tabCheckPoints; |
||
| 78 | break; |
||
| 1447 | chris | 79 | case ObjectMode.SPAWNERS: |
| 1441 | chris | 80 | tbcObjects.SelectedTab = tabSpawners; |
| 81 | break; |
||
| 82 | case ObjectMode.ELEMENTS: |
||
| 83 | tbcObjects.SelectedTab = tabElements; |
||
| 84 | break; |
||
| 85 | } |
||
| 86 | mObjectMode = value; |
||
| 87 | UpdateStatusBar(); |
||
| 88 | } |
||
| 89 | } |
||
| 90 | |||
| 1451 | chris | 91 | #pragma warning disable 0618 |
| 1427 | chris | 92 | public Tao.Platform.Windows.SimpleOpenGlControl GlView { get { return mGlView; } } |
| 1451 | chris | 93 | #pragma warning restore 0618 |
| 1423 | chris | 94 | public ListBox CheckPoints { get { return lbCheckPoints; } } |
| 1433 | chris | 95 | public ListBox Spawners { get { return lbSpawners; } } |
| 1435 | chris | 96 | public ListBox LevelElements { get { return lbElements; } } |
| 1423 | chris | 97 | public PropertyGrid Properties { get { return pgProperties; } } |
| 1477 | chris | 98 | public Label PropertiesLabel { get { return lblProperties; } } |
| 1423 | chris | 99 | |
| 1478 | chris | 100 | public string CurrentSpawnerType { get { return cbSpawnerTypes.Items[cbSpawnerTypes.SelectedIndex].ToString(); } } |
| 1483 | chris | 101 | public string CurrentElementType { get { return cbElementTypes.Items[cbElementTypes.SelectedIndex].ToString(); } } |
| 1478 | chris | 102 | |
| 1496 | chris | 103 | public bool ViewCheckPointPath { get { return mnuViewCheckPointPath.Checked; } set { mnuViewCheckPointPath.Checked = value; } } |
| 104 | public bool ViewCheckPointFrames { get { return mnuViewCheckPointFrames.Checked; } set { mnuViewCheckPointFrames.Checked = value; } } |
||
| 105 | public bool ViewBgLayer1 { get { return mnuViewBgLayer1.Checked; } set { mnuViewBgLayer1.Checked = value; } } |
||
| 106 | public bool ViewBgLayer2 { get { return mnuViewBgLayer2.Checked; } set { mnuViewBgLayer2.Checked = value; } } |
||
| 107 | public bool ViewMainLayer { get { return mnuViewMainLayer.Checked; } set { mnuViewMainLayer.Checked = value; } } |
||
| 108 | public bool ViewFgLayer { get { return mnuViewFgLayer.Checked; } set { mnuViewFgLayer.Checked = value; } } |
||
| 109 | public bool ViewEnemySpawners { get { return mnuViewEnemySpawners.Checked; } set { mnuViewEnemySpawners.Checked = value; } } |
||
| 110 | |||
| 1441 | chris | 111 | public bool SnapToPath { get; set; } |
| 1427 | chris | 112 | |
| 113 | private Panning mPanning = null; |
||
| 1441 | chris | 114 | private SelectMove mSelectMode = null; |
| 1461 | chris | 115 | private CreateObject mCreateObjectMode = null; |
| 1427 | chris | 116 | |
| 1462 | chris | 117 | private Bitmap[] mLayerBitmaps = new Bitmap[LevelElement.NUM_LAYERS]; |
| 118 | |||
| 1427 | chris | 119 | //=============================================================================================================== |
| 120 | |||
| 1305 | chris | 121 | public MainForm() |
| 122 | { |
||
| 123 | InitializeComponent(); |
||
| 1423 | chris | 124 | |
| 1430 | chris | 125 | mGlView.MouseWheel += new MouseEventHandler(GlView_MouseWheel); |
| 1423 | chris | 126 | lbCheckPoints.DisplayMember = "Name"; |
| 1481 | chris | 127 | lbSpawners.DisplayMember = "DisplayName"; |
| 1441 | chris | 128 | SetSnapToPath(false); |
| 129 | CurrentObjectMode = ObjectMode.CHECKPOINTS; |
||
| 1465 | chris | 130 | |
| 131 | cbSpawnerTypes.SelectedIndex = 0; |
||
| 132 | cbElementTypes.SelectedIndex = 0; |
||
| 1305 | chris | 133 | } |
| 134 | |||
| 135 | private void MainForm_Load(object sender, EventArgs e) |
||
| 136 | { |
||
| 1424 | chris | 137 | App = new BauzoidApp(); |
| 138 | App.init(mGlView.Width, mGlView.Height); |
||
| 1305 | chris | 139 | |
| 1481 | chris | 140 | String s = Path.Combine(Application.StartupPath, @"..\\..\\..\\..\\..\\BauzoidApps\\BurutaruZ_v2\\burutaru-android\\assets\\data"); |
| 141 | openFileDialog.InitialDirectory = Path.GetFullPath(s) + "\\levels"; |
||
| 142 | saveFileDialog.InitialDirectory = Path.GetFullPath(s) + "\\levels"; |
||
| 143 | openSpriteDialog.InitialDirectory = Path.GetFullPath(s) + "\\textures"; |
||
| 1305 | chris | 144 | |
| 1423 | chris | 145 | mDocument = new Document(this); |
| 1427 | chris | 146 | mView = new DocumentView(this); |
| 1425 | chris | 147 | mView.Init(); |
| 1427 | chris | 148 | |
| 1462 | chris | 149 | mLayerBitmaps[LevelElement.BACKGROUND_LAYER1] = new Bitmap(BurutaruEditor.Properties.Resources.layerBG1); |
| 150 | mLayerBitmaps[LevelElement.BACKGROUND_LAYER2] = new Bitmap(BurutaruEditor.Properties.Resources.layerBG2); |
||
| 151 | mLayerBitmaps[LevelElement.MAIN_LAYER] = new Bitmap(BurutaruEditor.Properties.Resources.layerMain); |
||
| 152 | mLayerBitmaps[LevelElement.FOREGROUND_LAYER] = new Bitmap(BurutaruEditor.Properties.Resources.layerFG); |
||
| 1467 | chris | 153 | |
| 154 | pgProperties.SelectedObject = Doc; |
||
| 155 | pgProperties.ExpandAllGridItems(); |
||
| 1485 | chris | 156 | |
| 157 | mPanning = new Panning(this); |
||
| 158 | mSelectMode = new SelectMove(this); |
||
| 159 | mCreateObjectMode = new CreateObject(this); |
||
| 1486 | chris | 160 | |
| 161 | Doc.NewDocument(); |
||
| 1305 | chris | 162 | } |
| 163 | |||
| 164 | private void MainForm_FormClosing(object sender, FormClosingEventArgs e) |
||
| 165 | { |
||
| 166 | if (!CheckDocumentModifiedAndSave()) |
||
| 167 | { |
||
| 168 | e.Cancel = true; |
||
| 169 | return; |
||
| 170 | } |
||
| 171 | |||
| 1425 | chris | 172 | if (mView != null) |
| 1305 | chris | 173 | { |
| 1425 | chris | 174 | mView.Exit(); |
| 175 | mView = null; |
||
| 1305 | chris | 176 | } |
| 177 | |||
| 1425 | chris | 178 | if (mDocument != null) |
| 1305 | chris | 179 | { |
| 1425 | chris | 180 | mDocument.Exit(); |
| 181 | mDocument = null; |
||
| 1305 | chris | 182 | } |
| 183 | |||
| 1481 | chris | 184 | mCreateObjectMode.Destroy(); |
| 185 | |||
| 1424 | chris | 186 | if (App != null) |
| 187 | App.exit(); |
||
| 1305 | chris | 188 | } |
| 189 | |||
| 190 | private void GlView_Paint(object sender, PaintEventArgs e) |
||
| 191 | { |
||
| 1424 | chris | 192 | App.getGraphics().clear(0.3f, 0.3f, 0.35f, 0); |
| 193 | App.getRenderStates().projection.setOrtho( |
||
| 1305 | chris | 194 | 0.0f, |
| 1424 | chris | 195 | App.getGraphics().getWidth(), |
| 196 | App.getGraphics().getHeight(), |
||
| 1305 | chris | 197 | 0.0f, |
| 198 | 0.0f, |
||
| 199 | 1.0f |
||
| 200 | ); |
||
| 201 | |||
| 1424 | chris | 202 | mView.Render(); |
| 1463 | chris | 203 | } |
| 1305 | chris | 204 | |
| 1463 | chris | 205 | public void RenderInteraction() |
| 206 | { |
||
| 1485 | chris | 207 | if ((CurrentInteraction == InteractionMode.SELECT) && (mSelectMode != null)) |
| 1463 | chris | 208 | mSelectMode.Render(); |
| 1485 | chris | 209 | else if ((CurrentInteraction == InteractionMode.CREATE) && (mCreateObjectMode != null)) |
| 1463 | chris | 210 | mCreateObjectMode.Render(); |
| 1424 | chris | 211 | |
| 1485 | chris | 212 | if (mPanning != null) |
| 213 | mPanning.Render(); |
||
| 1305 | chris | 214 | } |
| 215 | |||
| 216 | private void GlView_Resize(object sender, EventArgs e) |
||
| 217 | { |
||
| 1424 | chris | 218 | if (App != null) |
| 219 | App.getGraphics().updateSurfaceDimensions(mGlView.Width, mGlView.Height); |
||
| 1305 | chris | 220 | } |
| 221 | |||
| 222 | private void FileNew_Click(object sender, EventArgs e) |
||
| 223 | { |
||
| 224 | if (!CheckDocumentModifiedAndSave()) |
||
| 225 | return; |
||
| 226 | |||
| 227 | // new file |
||
| 228 | mDocument.NewDocument(); |
||
| 229 | } |
||
| 230 | |||
| 231 | private void FileOpen_Click(object sender, EventArgs e) |
||
| 232 | { |
||
| 233 | if (!CheckDocumentModifiedAndSave()) |
||
| 234 | return; |
||
| 235 | |||
| 236 | // open file |
||
| 237 | PerformFileOpen(); |
||
| 238 | } |
||
| 239 | |||
| 240 | /** Check if the document has been modified, and if yes, ask for saving. |
||
| 241 | * Returns true if everything is ok and the operation should be continued, or false when Cancel has been pressed. */ |
||
| 242 | private bool CheckDocumentModifiedAndSave() |
||
| 243 | { |
||
| 244 | if (mDocument.IsDirty()) |
||
| 245 | { |
||
| 246 | switch (MessageBox.Show("File has been modified. Save?", "New File", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)) |
||
| 247 | { |
||
| 248 | case DialogResult.Yes: |
||
| 249 | if (!PerformFileSave()) |
||
| 250 | return false; |
||
| 251 | break; |
||
| 252 | case DialogResult.No: |
||
| 253 | break; |
||
| 254 | case DialogResult.Cancel: |
||
| 255 | return false; |
||
| 256 | } |
||
| 257 | } |
||
| 258 | |||
| 259 | return true; |
||
| 260 | } |
||
| 261 | |||
| 262 | /** Perform a file save operation with a file save dialog. |
||
| 263 | * Returns false if the operation has been canceled. */ |
||
| 264 | private bool PerformFileSave(bool alwaysShowDialog = false) |
||
| 265 | { |
||
| 266 | if (alwaysShowDialog || !mDocument.IsFilenameSet()) |
||
| 267 | { |
||
| 268 | if (saveFileDialog.ShowDialog() == DialogResult.Cancel) |
||
| 269 | return false; |
||
| 270 | |||
| 271 | mDocument.SetFilename(saveFileDialog.FileName); |
||
| 272 | } |
||
| 273 | |||
| 274 | return mDocument.SaveDocument(); |
||
| 275 | } |
||
| 276 | |||
| 277 | /** Perform a file open operation. |
||
| 278 | * Return false if the operation was canceled. */ |
||
| 279 | private bool PerformFileOpen() |
||
| 280 | { |
||
| 281 | if (openFileDialog.ShowDialog() == DialogResult.Cancel) |
||
| 282 | return false; |
||
| 283 | |||
| 284 | return mDocument.LoadDocument(openFileDialog.FileName); |
||
| 285 | } |
||
| 286 | |||
| 287 | private void FileSave_Click(object sender, EventArgs e) |
||
| 288 | { |
||
| 289 | PerformFileSave(); |
||
| 290 | } |
||
| 291 | |||
| 292 | private void FileSaveAs_Click(object sender, EventArgs e) |
||
| 293 | { |
||
| 294 | PerformFileSave(true); |
||
| 295 | } |
||
| 296 | |||
| 297 | private void FileExit_Click(object sender, EventArgs e) |
||
| 298 | { |
||
| 299 | Close(); |
||
| 300 | } |
||
| 301 | |||
| 1427 | chris | 302 | private void GlView_MouseDown(object sender, MouseEventArgs e) |
| 303 | { |
||
| 1485 | chris | 304 | Doc.SetDirty(true); |
| 305 | |||
| 1441 | chris | 306 | if (CurrentInteraction == InteractionMode.SELECT) |
| 307 | mSelectMode.MouseDown(e); |
||
| 1461 | chris | 308 | else if (CurrentInteraction == InteractionMode.CREATE) |
| 309 | mCreateObjectMode.MouseDown(e); |
||
| 1441 | chris | 310 | |
| 1427 | chris | 311 | mPanning.MouseDown(e); |
| 1441 | chris | 312 | |
| 313 | mGlView.Refresh(); |
||
| 1427 | chris | 314 | } |
| 315 | |||
| 316 | private void GlView_MouseMove(object sender, MouseEventArgs e) |
||
| 317 | { |
||
| 1441 | chris | 318 | if (CurrentInteraction == InteractionMode.SELECT) |
| 319 | mSelectMode.MouseMove(e); |
||
| 1461 | chris | 320 | else if (CurrentInteraction == InteractionMode.CREATE) |
| 321 | mCreateObjectMode.MouseMove(e); |
||
| 1441 | chris | 322 | |
| 1427 | chris | 323 | mPanning.MouseMove(e); |
| 1441 | chris | 324 | |
| 325 | mGlView.Refresh(); |
||
| 1427 | chris | 326 | } |
| 327 | |||
| 328 | private void GlView_MouseUp(object sender, MouseEventArgs e) |
||
| 329 | { |
||
| 1441 | chris | 330 | if (CurrentInteraction == InteractionMode.SELECT) |
| 331 | mSelectMode.MouseUp(e); |
||
| 1461 | chris | 332 | else if (CurrentInteraction == InteractionMode.CREATE) |
| 333 | mCreateObjectMode.MouseUp(e); |
||
| 1441 | chris | 334 | |
| 1427 | chris | 335 | mPanning.MouseUp(e); |
| 1441 | chris | 336 | |
| 337 | mGlView.Refresh(); |
||
| 1427 | chris | 338 | } |
| 339 | |||
| 1481 | chris | 340 | private void GlView_MouseEnter(object sender, EventArgs e) |
| 341 | { |
||
| 342 | if (CurrentInteraction == InteractionMode.SELECT) |
||
| 343 | mSelectMode.MouseEnter(e); |
||
| 344 | else if (CurrentInteraction == InteractionMode.CREATE) |
||
| 345 | mCreateObjectMode.MouseEnter(e); |
||
| 346 | } |
||
| 347 | |||
| 348 | private void GlView_MouseLeave(object sender, EventArgs e) |
||
| 349 | { |
||
| 350 | if (CurrentInteraction == InteractionMode.SELECT) |
||
| 351 | mSelectMode.MouseLeave(e); |
||
| 352 | else if (CurrentInteraction == InteractionMode.CREATE) |
||
| 353 | mCreateObjectMode.MouseLeave(e); |
||
| 354 | } |
||
| 355 | |||
| 1430 | chris | 356 | private void GlView_MouseWheel(object sender, MouseEventArgs e) |
| 357 | { |
||
| 358 | if (e.Delta > 0) |
||
| 359 | { |
||
| 360 | View.ZoomFactor *= 1.2f; |
||
| 361 | } |
||
| 362 | else if (e.Delta < 0) |
||
| 363 | { |
||
| 364 | View.ZoomFactor *= 0.8f; |
||
| 365 | } |
||
| 366 | } |
||
| 367 | |||
| 1433 | chris | 368 | private void ObjectsList_SelIndexChanged(object sender, EventArgs e) |
| 369 | { |
||
| 1447 | chris | 370 | ListBox lb = null; |
| 371 | |||
| 372 | switch (CurrentObjectMode) |
||
| 373 | { |
||
| 374 | case ObjectMode.CHECKPOINTS: |
||
| 375 | lb = lbCheckPoints; |
||
| 376 | break; |
||
| 377 | case ObjectMode.SPAWNERS: |
||
| 378 | lb = lbSpawners; |
||
| 379 | break; |
||
| 380 | case ObjectMode.ELEMENTS: |
||
| 381 | lb = lbElements; |
||
| 382 | break; |
||
| 383 | } |
||
| 384 | |||
| 385 | if (lb.SelectedIndex == -1) |
||
| 386 | return; |
||
| 387 | |||
| 388 | pgProperties.SelectedObject = lb.SelectedItem; |
||
| 1460 | chris | 389 | View.SelectedObject = (LevelObject)lb.SelectedItem; |
| 390 | View.SelectedObjectPart = SelectMove.MOVE_ALL; |
||
| 1433 | chris | 391 | pgProperties.ExpandAllGridItems(); |
| 1460 | chris | 392 | |
| 393 | mGlView.Refresh(); |
||
| 1433 | chris | 394 | } |
| 395 | |||
| 396 | private void Properties_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) |
||
| 397 | { |
||
| 398 | mGlView.Refresh(); |
||
| 1461 | chris | 399 | |
| 1485 | chris | 400 | Doc.SetDirty(true); |
| 401 | |||
| 1461 | chris | 402 | typeof(ListBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, |
| 403 | CheckPoints, new object[] { }); |
||
| 404 | typeof(ListBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, |
||
| 405 | Spawners, new object[] { }); |
||
| 406 | typeof(ListBox).InvokeMember("RefreshItems", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.InvokeMethod, null, |
||
| 407 | LevelElements, new object[] { }); |
||
| 1433 | chris | 408 | } |
| 409 | |||
| 1441 | chris | 410 | public void SetSnapToPath(bool snap = true) |
| 411 | { |
||
| 412 | SnapToPath = snap; |
||
| 413 | tbSnapToPath.Checked = snap; |
||
| 414 | mnuSnapToPath.Checked = snap; |
||
| 415 | } |
||
| 416 | |||
| 417 | private void SnapToPath_Click(object sender, EventArgs e) |
||
| 418 | { |
||
| 419 | SetSnapToPath(!SnapToPath); |
||
| 420 | mGlView.Refresh(); |
||
| 421 | } |
||
| 422 | |||
| 423 | private void EnableCreateButton(bool enable) |
||
| 424 | { |
||
| 425 | btnCreateCheckPoint.Checked = enable && (CurrentObjectMode == ObjectMode.CHECKPOINTS); |
||
| 1447 | chris | 426 | btnCreateSpawner.Checked = enable && (CurrentObjectMode == ObjectMode.SPAWNERS); |
| 1441 | chris | 427 | btnCreateElement.Checked = enable && (CurrentObjectMode == ObjectMode.ELEMENTS); |
| 428 | } |
||
| 429 | |||
| 430 | private void Create_Click(object sender, EventArgs e) |
||
| 431 | { |
||
| 432 | if (((CheckBox)sender).Checked) |
||
| 1481 | chris | 433 | { |
| 434 | if (sender == btnCreateElement) |
||
| 435 | { |
||
| 436 | // TODO: check cbElementTypes for whether a OpenFileDialog is even needed |
||
| 437 | |||
| 438 | if (openSpriteDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) |
||
| 439 | { |
||
| 440 | if (!mCreateObjectMode.Load(openSpriteDialog.FileName)) |
||
| 441 | { |
||
| 442 | ((CheckBox)sender).Checked = false; |
||
| 443 | return; |
||
| 444 | } |
||
| 445 | } |
||
| 446 | else |
||
| 447 | { |
||
| 448 | ((CheckBox)sender).Checked = false; |
||
| 449 | return; |
||
| 450 | } |
||
| 451 | } |
||
| 1541 | chris | 452 | else if (sender == btnCreateSpawner) |
| 453 | { |
||
| 1481 | chris | 454 | |
| 1541 | chris | 455 | } |
| 456 | |||
| 1441 | chris | 457 | CurrentInteraction = InteractionMode.CREATE; |
| 1481 | chris | 458 | } |
| 1441 | chris | 459 | else |
| 460 | CurrentInteraction = InteractionMode.SELECT; |
||
| 461 | } |
||
| 462 | |||
| 1442 | chris | 463 | public void UpdateStatusBar() |
| 1441 | chris | 464 | { |
| 465 | string text = ""; |
||
| 466 | switch (CurrentInteraction) |
||
| 467 | { |
||
| 468 | case InteractionMode.SELECT: |
||
| 469 | text = "Select "; |
||
| 470 | break; |
||
| 471 | case InteractionMode.CREATE: |
||
| 472 | text = "Create "; |
||
| 473 | break; |
||
| 474 | } |
||
| 475 | switch (CurrentObjectMode) |
||
| 476 | { |
||
| 477 | case ObjectMode.CHECKPOINTS: |
||
| 478 | text += "CheckPoint"; |
||
| 479 | break; |
||
| 1447 | chris | 480 | case ObjectMode.SPAWNERS: |
| 1441 | chris | 481 | text += "EnemySpawner"; |
| 482 | break; |
||
| 483 | case ObjectMode.ELEMENTS: |
||
| 484 | text += "LevelElement"; |
||
| 485 | break; |
||
| 486 | } |
||
| 487 | stInteractionObjectMode.Text = text; |
||
| 1442 | chris | 488 | if (View != null) |
| 489 | stZoom.Text = ((int)Math.Floor(View.ZoomFactor * 100)) + "%"; |
||
| 1441 | chris | 490 | mStatusStrip.Refresh(); |
| 491 | } |
||
| 492 | |||
| 493 | private void Objects_SelectedTabChanged(object sender, EventArgs e) |
||
| 494 | { |
||
| 495 | mObjectMode = (ObjectMode)tbcObjects.SelectedIndex; |
||
| 496 | CurrentInteraction = InteractionMode.SELECT; |
||
| 1447 | chris | 497 | |
| 498 | switch (CurrentObjectMode) |
||
| 499 | { |
||
| 500 | case ObjectMode.CHECKPOINTS: |
||
| 501 | ObjectsList_SelIndexChanged(lbCheckPoints, new EventArgs()); |
||
| 502 | break; |
||
| 503 | case ObjectMode.SPAWNERS: |
||
| 504 | ObjectsList_SelIndexChanged(lbSpawners, new EventArgs()); |
||
| 505 | break; |
||
| 506 | case ObjectMode.ELEMENTS: |
||
| 507 | ObjectsList_SelIndexChanged(lbElements, new EventArgs()); |
||
| 508 | break; |
||
| 509 | } |
||
| 1441 | chris | 510 | } |
| 511 | |||
| 1451 | chris | 512 | private void MainForm_KeyDown(object sender, KeyEventArgs e) |
| 513 | { |
||
| 1488 | chris | 514 | |
| 1451 | chris | 515 | } |
| 1441 | chris | 516 | |
| 1461 | chris | 517 | private void MoveUp_Click(object sender, EventArgs e) |
| 518 | { |
||
| 519 | Doc.MoveObjectUp(); |
||
| 520 | mGlView.Refresh(); |
||
| 521 | } |
||
| 1451 | chris | 522 | |
| 1461 | chris | 523 | private void MoveDown_Click(object sender, EventArgs e) |
| 524 | { |
||
| 525 | Doc.MoveObjectDown(); |
||
| 526 | mGlView.Refresh(); |
||
| 527 | } |
||
| 528 | |||
| 1462 | chris | 529 | private void Elements_DrawItem(object sender, DrawItemEventArgs e) |
| 530 | { |
||
| 531 | e.DrawBackground(); |
||
| 1461 | chris | 532 | |
| 1462 | chris | 533 | LevelElement element = (LevelElement)LevelElements.Items[e.Index]; |
| 534 | |||
| 535 | Bitmap bm = null; |
||
| 536 | switch (element.Layer) |
||
| 537 | { |
||
| 538 | case LevelElement.BACKGROUND_LAYER1: |
||
| 539 | case LevelElement.BACKGROUND_LAYER2: |
||
| 540 | case LevelElement.MAIN_LAYER: |
||
| 541 | case LevelElement.FOREGROUND_LAYER: |
||
| 542 | bm = mLayerBitmaps[element.Layer]; |
||
| 543 | break; |
||
| 544 | } |
||
| 545 | Rectangle r = e.Bounds; |
||
| 546 | |||
| 547 | r.X += 2; |
||
| 548 | r.Width = 16; |
||
| 549 | r.Height = 16; |
||
| 550 | e.Graphics.DrawImageUnscaled(bm, r); |
||
| 551 | |||
| 1488 | chris | 552 | |
| 1462 | chris | 553 | r = e.Bounds; |
| 554 | r.X += 20; |
||
| 1481 | chris | 555 | Font fn = new Font(e.Font, FontStyle.Bold); |
| 556 | e.Graphics.DrawString(element.Name, fn, SystemBrushes.ControlText, r, StringFormat.GenericDefault); |
||
| 557 | |||
| 558 | SizeF s = e.Graphics.MeasureString(element.Name, fn); |
||
| 559 | r.X += (int)s.Width; |
||
| 560 | e.Graphics.DrawString(element.GetPropertiesType(), e.Font, SystemBrushes.ControlText, r, StringFormat.GenericDefault); |
||
| 1462 | chris | 561 | // If the ListBox has focus, draw a focus rectangle around the selected item. |
| 562 | e.DrawFocusRectangle(); |
||
| 563 | } |
||
| 564 | |||
| 1477 | chris | 565 | private void Properties_SelectedObjectChange(object sender, EventArgs e) |
| 566 | { |
||
| 567 | if (pgProperties.SelectedObject is Document) |
||
| 568 | { |
||
| 569 | lblProperties.Text = ((Document)pgProperties.SelectedObject).GetPropertiesTitle(); |
||
| 570 | lblType.Text = ((Document)pgProperties.SelectedObject).GetPropertiesType(); |
||
| 571 | } |
||
| 572 | else if (pgProperties.SelectedObject is LevelObject) |
||
| 573 | { |
||
| 574 | lblProperties.Text = ((LevelObject)pgProperties.SelectedObject).Name; |
||
| 575 | lblType.Text = ((LevelObject)pgProperties.SelectedObject).GetPropertiesType(); |
||
| 576 | } |
||
| 577 | } |
||
| 1462 | chris | 578 | |
| 1487 | chris | 579 | private void About_Click(object sender, EventArgs e) |
| 580 | { |
||
| 581 | AboutBox dlg = new AboutBox(); |
||
| 582 | dlg.ShowDialog(); |
||
| 583 | } |
||
| 1477 | chris | 584 | |
| 1488 | chris | 585 | private void GlView_KeyDown(object sender, KeyEventArgs e) |
| 586 | { |
||
| 587 | // implement shortcut keys |
||
| 588 | if (e.KeyCode == Keys.S) |
||
| 589 | { |
||
| 590 | // snap |
||
| 591 | SetSnapToPath(!SnapToPath); |
||
| 592 | mGlView.Refresh(); |
||
| 593 | } |
||
| 594 | if (e.KeyCode == Keys.Escape) |
||
| 595 | { |
||
| 596 | // exit create mode |
||
| 597 | CurrentInteraction = InteractionMode.SELECT; |
||
| 598 | mGlView.Refresh(); |
||
| 599 | } |
||
| 600 | } |
||
| 1480 | chris | 601 | |
| 1494 | chris | 602 | private void EditCut_Click(object sender, EventArgs e) |
| 603 | { |
||
| 604 | Doc.Cut(); |
||
| 605 | } |
||
| 1487 | chris | 606 | |
| 1494 | chris | 607 | private void EditCopy_Click(object sender, EventArgs e) |
| 608 | { |
||
| 609 | Doc.Copy(); |
||
| 610 | } |
||
| 1488 | chris | 611 | |
| 1494 | chris | 612 | private void EditPaste_Click(object sender, EventArgs e) |
| 613 | { |
||
| 614 | Doc.Paste(); |
||
| 615 | } |
||
| 616 | |||
| 1496 | chris | 617 | private void ViewObjectLayer_Click(object sender, EventArgs e) |
| 618 | { |
||
| 619 | if (sender is ToolStripMenuItem) |
||
| 620 | ((ToolStripMenuItem)sender).Checked = !((ToolStripMenuItem)sender).Checked; |
||
| 621 | mGlView.Refresh(); |
||
| 622 | } |
||
| 1494 | chris | 623 | |
| 1496 | chris | 624 | private void Delete_Click(object sender, EventArgs e) |
| 625 | { |
||
| 626 | Doc.DeleteCurrentObject(); |
||
| 627 | mGlView.Refresh(); |
||
| 628 | } |
||
| 1494 | chris | 629 | |
| 1496 | chris | 630 | |
| 631 | |||
| 1305 | chris | 632 | } |
| 633 | } |