~kalon33/corsix-th/master

« back to all changes in this revision

Viewing changes to CorsixTH/Lua/ui.lua

  • Committer: corsixth.bot at gmail
  • Date: 2014-03-31 23:30:23 UTC
  • Revision ID: svn-v4:c39591fa-788f-11de-a72b-d90af8dea425:trunk:2687
Remove trailing whitespaces in .h, .cpp, .c and .lua files.

Show diffs side-by-side

added added

removed removed

Lines of Context:
116
116
  self.key_remaps = key_remaps
117
117
  self.key_to_button_remaps = key_to_button_remaps
118
118
  self.key_codes = invert(self.key_codes)
119
 
  
 
119
 
120
120
  self.button_codes = {
121
121
    left = 1,
122
122
    middle = 2,
123
123
    right = 3,
124
124
  }
125
 
  
 
125
 
126
126
  -- Apply button remaps directly to codes, as mouse button codes are reliable
127
127
  -- (keyboard key codes are not).
128
128
  local original_button_codes = {}
137
137
    end
138
138
    self.button_codes[behave_as] = code
139
139
  end
140
 
  
 
140
 
141
141
  self.button_codes = invert(self.button_codes)
142
142
end
143
143
 
179
179
  -- Windows can tell UI to pass specific codes forward to them. See addKeyHandler and removeKeyHandler
180
180
  self.key_handlers = {}
181
181
  self.key_code_to_rawchar = {}
182
 
  
 
182
 
183
183
  self.keyboard_repeat_enable_count = 0
184
184
  SDL.modifyKeyboardRepeat(0, 0)
185
185
  self.down_count = 0
191
191
    self.waiting_cursor = app.gfx:loadMainCursor("sleep")
192
192
  end
193
193
  self.editing_allowed = true
194
 
  
 
194
 
195
195
  if not LOADED_DIALOGS then
196
196
    app:loadLuaFolder("dialogs", true)
197
197
    app:loadLuaFolder("dialogs/fullscreen", true)
200
200
    app:loadLuaFolder("dialogs/resizables/file_browsers", true)
201
201
    LOADED_DIALOGS = true
202
202
  end
203
 
  
 
203
 
204
204
  self:setCursor(self.default_cursor)
205
 
  
 
205
 
206
206
  -- to avoid a bug which causes open fullscreen windows to display incorrectly, load
207
207
  -- the sprite sheet associated with all fullscreen windows so they are correctly cached.
208
 
  -- Darrell: Only do this if we have a valid data directory otherwise we won't be able to 
 
208
  -- Darrell: Only do this if we have a valid data directory otherwise we won't be able to
209
209
  -- display the directory browser to even find the data directory.
210
210
  -- Edvin: Also, the demo does not contain any of the dialogs.
211
211
  if self.app.good_install_folder and not self.app.using_demo_files then
244
244
    palette:setEntry(255, 0xFF, 0x00, 0xFF) -- Make index 255 transparent
245
245
    gfx:loadSpriteTable("QData", "Award03V", true, palette)
246
246
  end
247
 
  
 
247
 
248
248
  self:setupGlobalKeyHandlers()
249
249
end
250
250
 
257
257
  self:addKeyHandler({"alt", "enter"}, self, self.toggleFullscreen)
258
258
  self:addKeyHandler({"alt", "f4"}, self, self.exitApplication)
259
259
  self:addKeyHandler({"shift", "f10"}, self, self.resetApp)
260
 
  
 
260
 
261
261
  if self.app.config.debug then
262
262
    self:addKeyHandler("f12", self, self.showLuaConsole)
263
263
  end
312
312
  if not self.tooltip or not self.tooltip_counter or self.tooltip_counter > 0 then
313
313
    return
314
314
  end
315
 
  
 
315
 
316
316
  local x, y = self.tooltip.x, self.tooltip.y
317
317
  if not self.tooltip.x then
318
318
    -- default to cursor position for (lower left corner of) tooltip
319
319
    x, y = self:getCursorPosition()
320
320
  end
321
 
  
 
321
 
322
322
  if self.tooltip_font then
323
323
    self.tooltip_font:drawTooltip(canvas, self.tooltip.text, x, y)
324
324
  end
485
485
  self:setCursor(cursor)
486
486
  -- Save new setting in config
487
487
  self.app:saveConfig()
488
 
  
 
488
 
489
489
  self:onChangeResolution()
490
 
  
 
490
 
491
491
  return true
492
492
end
493
493
 
494
494
function UI:toggleFullscreen()
495
495
  local modes = self.app.modes
496
 
  
 
496
 
497
497
  local function toggleMode(index)
498
498
    self.app.fullscreen = not self.app.fullscreen
499
499
    if self.app.fullscreen then
502
502
      modes[index] = ""
503
503
    end
504
504
  end
505
 
  
 
505
 
506
506
  -- Search in modes table if it contains a fullscreen value and keep the index
507
507
  -- If not found, we will add an index at end of table
508
508
  local index = #modes + 1
512
512
      break
513
513
    end
514
514
  end
515
 
  
 
515
 
516
516
  -- Toggle Fullscreen mode
517
517
  toggleMode(index)
518
518
  self.app.video:endFrame()
519
519
  self.app.moviePlayer:deallocatePictureBuffer();
520
 
  
 
520
 
521
521
  local success = true
522
522
  local video = TH.surface(self.app.config.width, self.app.config.height, unpack(modes))
523
523
  if not video then
528
528
    toggleMode(index)
529
529
    video = TH.surface(self.app.config.width, self.app.config.height, unpack(self.app.modes))
530
530
  end
531
 
  
 
531
 
532
532
  self.app.video = video -- Apply changes
533
533
  self.app.gfx:updateTarget(self.app.video)
534
534
  self.app.moviePlayer:allocatePictureBuffer();
537
537
  local cursor = self.cursor
538
538
  self.cursor = nil
539
539
  self:setCursor(cursor)
540
 
  
 
540
 
541
541
  -- Save new setting in config
542
542
  self.app.config.fullscreen = self.app.fullscreen
543
543
  self.app:saveConfig()
544
 
  
 
544
 
545
545
  return success
546
546
end
547
547
 
598
598
  -- Remember the raw character associated with the code, as when the key is
599
599
  -- released, we only get given the code.
600
600
  self.key_code_to_rawchar[code] = rawchar
601
 
  
 
601
 
602
602
  -- Apply key-remapping and normalisation
603
603
  local key = self.key_codes[code] or rawchar:lower()
604
604
  do
609
609
    end
610
610
    key = self.key_remaps[key] or key
611
611
  end
612
 
  
 
612
 
613
613
  -- If there is one, the current textbox gets the key
614
614
  for _, box in ipairs(self.textboxes) do
615
615
    if box.enabled and box.active then
644
644
      return true
645
645
    end
646
646
  end
647
 
  
 
647
 
648
648
  self.buttons_down[key] = true
649
649
end
650
650
 
684
684
  if x >= 3 and y >= 3 and x < self.app.config.width - 3 and y < self.app.config.height - 3 then
685
685
    self.buttons_down["mouse_"..button] = true
686
686
  end
687
 
  
 
687
 
688
688
  self:updateTooltip()
689
689
  return Window.onMouseDown(self, button, x, y) or repaint
690
690
end
701
701
    self.down_count = 0
702
702
  end
703
703
  self.buttons_down["mouse_"..button] = nil
704
 
  
 
704
 
705
705
  if Window.onMouseUp(self, button, x, y) then
706
706
    repaint = true
707
707
  else
708
 
    if self.cursor_entity and self.cursor_entity.onClick 
 
708
    if self.cursor_entity and self.cursor_entity.onClick
709
709
    and self.app.world.user_actions_allowed then
710
710
      self.cursor_entity:onClick(self, button)
711
711
      repaint = true
712
712
    end
713
713
  end
714
 
  
 
714
 
715
715
  self:updateTooltip()
716
716
  return repaint
717
717
end
750
750
 
751
751
function UI:onMouseMove(x, y, dx, dy)
752
752
  local repaint = UpdateCursorPosition(self.app.video, x, y)
753
 
  
 
753
 
754
754
  self.cursor_x = x
755
755
  self.cursor_y = y
756
 
  
 
756
 
757
757
  if self.drag_mouse_move then
758
758
    self.drag_mouse_move(x, y)
759
759
    return true
760
760
  end
761
 
  
 
761
 
762
762
  if Window.onMouseMove(self, x, y, dx, dy) then
763
763
    repaint = true
764
764
  end
765
765
 
766
766
  self:updateTooltip()
767
 
  
 
767
 
768
768
  return repaint
769
769
end
770
770
 
844
844
    -- some global key shortcuts were converted to use keyHandlers
845
845
    self:setupGlobalKeyHandlers()
846
846
  end
847
 
  
 
847
 
848
848
  -- disable keyboardrepeat after loading a game just in case
849
849
  -- (might be transferred from before loading, or broken savegame)
850
850
  repeat
855
855
    self:addKeyHandler({"shift", "f10"}, self, self.resetApp)
856
856
    self:removeKeyHandler("a", self)
857
857
  end
858
 
  -- changing this so that it is quit application and Shift + Q is quit to main menu  
 
858
  -- changing this so that it is quit application and Shift + Q is quit to main menu
859
859
  if old < 71 then
860
860
    self:removeKeyHandler({"alt", "f4"}, self, self.quit)
861
861
    self:addKeyHandler({"alt", "f4"}, self, self.exitApplication)
862
 
  end    
 
862
  end
863
863
  Window.afterLoad(self, old, new)
864
864
end
865
865
 
931
931
end
932
932
 
933
933
-- Stub for compatibility with savegames r1896-1921
934
 
function UI:stopVideo() end
 
 
b'\\ No newline at end of file'
 
934
function UI:stopVideo() end