Difference between revisions of "Script - Ship Viewer"

From FreeSpace Wiki
Jump to: navigation, search
m (fixed the script)
m (header, spelling)
 
(One intermediate revision by one other user not shown)
Line 1: Line 1:
==Function==
+
Prevents game itself from loading, but instead loads a ship viewer.<br>
Prevents game itself from loading but instead loads a ship viewer.<br>
+
Moving mouse cursor with mouse button pressed to:
Moving mouse cursor with mouse botton pressed to:
 
 
{|
 
{|
 
| width=150px|Upper left corner
 
| width=150px|Upper left corner
Line 114: Line 113:
 
   render_ship:renderTechModel(0, 0, gr.getScreenWidth()-1, gr.getScreenHeight()-1, rotate_pct, pitch, bank, zoom)
 
   render_ship:renderTechModel(0, 0, gr.getScreenWidth()-1, gr.getScreenHeight()-1, rotate_pct, pitch, bank, zoom)
 
]
 
]
+Override: YES
+
+Override: true
 
#End</pre>
 
#End</pre>
  
 
[[Category:Scripting Examples|Ship Viewer]]
 
[[Category:Scripting Examples|Ship Viewer]]

Latest revision as of 19:31, 18 April 2010

Prevents game itself from loading, but instead loads a ship viewer.
Moving mouse cursor with mouse button pressed to:

Upper left corner Goes to next ship
Upper right corner Zooms in
Lower left corner Exits
Lower right corner Zooms out

Table Entry

#State Hooks
$State: GS_STATE_INITIAL_PLAYER_SELECT
$Hook: [
   --Set default values
   if not rotate_pct then
      rotate_pct = 40
   end

   if not pitch then
      pitch = 0
   end
   
   if not bank then
      bank = 0
   end
   
   if not count then
      count = 1
   end

   if not zoom then
      zoom = 1.3
   end
   
   --Figure out if we need to check for triggers
   --upper-left:#1 Goes to next ship
   --upper-right:#2 Zooms in
   --lower-left:#3 Quits
   --lower-right:#4 Zooms out
   if ms.getX() == 0 and ms.getY() == 0 then
      trig = 1
   elseif ms.getX()==(gr.getScreenWidth()-1) and ms.getY()==0 then
      trig = 2
   elseif ms.getX()==0 and ms.getY()==(gr.getScreenHeight()-1) then
      trig = 3
   elseif ms.getX()==(gr.getScreenWidth()-1) and ms.getY()==(gr.getScreenHeight()-1) then
      trig = 4
   else
      trig = 0
   end
   
   --Do we need to activate trigger?
   --Make sure that if the mouse is held down for
   --more than one frame, trigger doesn't activate multiple times
   if trig>0 then
      if not middle_was_down then
         middle_was_down = ms.isButtonDown("Left")
         activate_trig = middle_was_down
      elseif ms.isButtonDown("Left")==true then
         middle_was_down = true
         activate_trig = false
      else
         middle_was_down = false
         activate_trig = false
      end
   else
      middle_was_down = false
      activate_trig = false
   end
   
   --Do trigger actions
   if activate_trig then
      if trig==1 then
         count = count + 1
         if count > tb.getNumShipClasses() then
            count = 1
         end
      elseif trig==2 then
         zoom = zoom-0.1
      elseif trig==3 then
         ba.setEvent("GS_EVENT_QUIT_GAME")
      elseif trig==4 then
         zoom = zoom+0.1
      end
   end

   --If no triggers, do normal mouse stuff
   --Left changes heading
   --Middle changes pitch
   --Right changes bank
   if trig==0 then
      if ms.isButtonDown("Left") then
         rotate_pct = (1-ms.getX()/gr.getScreenWidth())*100
      end
      if ms.isButtonDown("Middle") then
         pitch = (1-ms.getY()/gr.getScreenHeight())*100
      end
      if ms.isButtonDown("Right") then
         bank = ms.getX()/gr.getScreenWidth()*100
      end
   end

   --Finally, render the ship
   render_ship = tb.getShipClassByIndex(count)
   render_ship:renderTechModel(0, 0, gr.getScreenWidth()-1, gr.getScreenHeight()-1, rotate_pct, pitch, bank, zoom)
]
+Override: true
#End