HeroEngine Forums
Welcome, Guest. Please login or Register for HeroCloud Account.
Pages: [1] 2

Author Topic: Mini map & World map in window  (Read 3916 times)

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Mini map & World map in window
« on: Feb 11, 13, 02:56:09 AM »

Intermediate level scripting
This tutorial puts the minimap and an area map in the same window, and can hide both. It will not work in game layer. It can not use window Docker at present.

In the DOM, create a new (clientside) class.
name = TMP_Map
archtype = guicontrol
add a parent to the class, _minimap

click open script

In new script TMP_MapClassMethods
are methods for interacting with the GUI that we will build
check for mouse clicking on a button
using mouse wheel to zoom in on minimap


Code: [Select]

shared function start()
  win as NodeRef of Class TMP_Map = FindGUIControlByName(None, "minimap")
  if win != None
    destroynode(win)
  .
  win = CreateNodeFromPrototype("TMP_Map")
  win.build = true
  win.name = "minimap"
  win.position.x = 700
  win.position.y = 400

  // Glom the class
  GlomClass("GUIMovePanel", win)

  map as NodeRef of Class GUIPanel = FindGUIControlByName(win, "map")   // clear circle
  map.alphamask.size.x = 0
  map.alphamask.size.y = 0
  map.alphamask.material = ""
  map.visible = false

  player as NodeRef of Class GUIPanel = findGUIControlByName(win, "player")   // make green
  player.defaultStatePresentation.color.r = 0
  player.defaultStatePresentation.color.g = 1
  player.defaultStatePresentation.color.b = 0

  frame as NodeRef of Class GUIPanel = FindGUIControlByName(win, "frame")   // turn off
  frame.texture = ""
  frame.defaultStatePresentation.color.a = 0
.

// Handy mousewheel zooming for the minimap.
method onMouseWheel(args references Class GUIMouseEvent)
  var wheel = args.wheelDelta / 120
  var zoom = GetMiniMapZoom() + (wheel * -4)
  if zoom > 40
    zoom = 40
  .
  SetMiniMapZoom(zoom)
  args.handled = true
.

method onMouseClick(args references Class GUIMouseEvent)
  main as NodeRef of Class _minimap = FindGUIControlByName(None, "minimap")
  Map as NodeRef of Class GUIControl = FindGUIControlByName(main, "map")
  player as NodeRef of Class GUIControl = FindGUIControlByName(main, "player")
  actor as NodeRef of Class GUIControl = findGUIControlByName(main, "actors")

  target as NodeRef of Class GUIControl = args.source
  if args.leftButton
    when target.name
      is "areaButton"
        if player.visible = false
          main.size.y = 290
          actor.visible = true
          player.visible = true
          Map.visible = true
          Map.texture = "MINIMAP"
          Map.defaultStatePresentation.size.x = 256
          Map.defaultStatePresentation.size.y = 256
          Map.defaultStatePresentation.position.x = 128
          Map.defaultStatePresentation.position.y = 128
          EnableMiniMap(true)
        .
      .
      is "worldButton"
        main.size.y = 290
        actor.visible = false
        player.visible = false
        Map.visible = true
        Map.texture = "\GUI\TitanCityGameMap.dds"
        Map.defaultStatePresentation.size.x = 1024
        Map.defaultStatePresentation.size.y = 1024
        Map.defaultStatePresentation.position.x = 0
        Map.defaultStatePresentation.position.y = 0
        EnableMiniMap(false)
      .
      is "exitButton"
        main.size.y = 25
        actor.visible = false
        player.visible = false
        Map.visible = false
        EnableMiniMap(false)
      .
    .
  .
.

// completely overrides behavior of a minimap render call
method _onRenderMiniMap()
  main as NodeRef of Class _minimap = FindGUIControlByName(None, "minimap")
  map as NodeRef of Class GUIControl = FindGUIControlByName(main, "map")
  player as NodeRef of Class GUIControl = FindGUIControlByName(main, "player")
  storage as NodeRef of Class GUIControl = FindGUIControlByName(main, "storage")

//  println("using my OnRenderMiniMap")
//  var map = me._getMinimapTexturePanel()
  if map == None
    return
  .
  var person = GetPlayerCharacterNode()
  if person == None
    return
  .

  position as Vector3 = person["Position"]
  answer as Vector3
  mycenter as Vector3
 
  // WorldSpaceToMiniMapSpace() converts a 3D worldspace position to 2D coordinates within the
  // 512x512 minimap texture.  Here, we're using it to decide how to set the UV coordinates to
  // display the area around the character.  You can also use it to figure out where to place
  // markers for other characters, creatures, etc.

  inRange as Boolean = WorldSpaceToMiniMapSpace(position,answer)
  mycenter = answer
  map.defaultStatePresentation.position.x = answer.x - (map.size.x/2)
  map.defaultStatePresentation.position.y = answer.y - (map.size.y/2)

  var cam = GetActiveCamera()
  if (cam["CameraName"]=="GAME")
    position = cam["Rotation"]
    player.rotation = position.y    // rotate player or map, but not both
//    map.rotation = -position.y
  .
//  frame as NodeRef of Class GUIPanel = me._getMinimapCompassFrame()
//  frame.rotation = map.rotation

  actorCheck as LookupList indexed by String of Boolean
  actorPanel as NodeRef of Class GUIControl = findGUIControlByName(map.parent, "actors")
//  var storage = me._getMinimapActorStorage()
  var actors = GetMinimapCharacters()
  foreach actor in actorPanel.children
    add back actor to storage.children
  .

  var playerColor = me._getMinimapPlayerColor()
  var NPCColor = me._getMinimapNPCColor()
  var HostileColor = me._getMinimapHostileColor()
 
  foreach actor in actors
    dot as NodeRef of Class GUIControl = findGUIControlByName(actorPanel, actor)
    if dot == None
      if storage.children.length > 0
        dot = storage.children[1]
      else
        dot = me._newMinimapActor()
      .
      add back dot to actorPanel.children
      dot.name = actor
      hostile as Boolean = false       
      if hostile == true
        dot.defaultStatePresentation.color = HostileColor
      else if findString(toLower(getcharacterspecification(actor)), "male") > 0
        dot.defaultStatePresentation.color = playerColor
      else
        dot.defaultStatePresentation.color = NPCColor
      .
    .
    position = actor["Position"]
    inRange = WorldSpaceToMiniMapSpace(position,answer)
    if inRange
      answer.x = answer.x - mycenter.x
      answer.y = answer.y - mycenter.y
      answer.z = 0
      var dist = VectorLength(answer)
      if (dist > map.size.x/2)
        dot.visible = false // outside circular distance though within minimap range
      else
        var correctedPos = RotateAndScaleDot(answer,map.rotation,map.scale)
        dot.position.x = correctedPos.x + (map.size.x/2) - (dot.size.x/2)
        dot.position.y = correctedPos.y + (map.size.y/2) - (dot.size.y/2)
        if dot.visible == false
          dot.visible = true
        .
      .
    else
      add back dot to storage.children
    .
  .
  me.lastMinimapUpdate = SYSTEM.TIME.NOW
.

function RotateAndScaleDot(posIn copies Vector3, rot as Float, scale as Float) as Vector3
  posIn.x = posIn.x
  posIn.y = posIn.y
  p as Vector3
  r as Vector3
  r.z = rot
  s as Vector3
  s.x = scale
  s.y = scale
  s.z = scale
  var ret = TransformVector(posIn,p,r,s)
  ret.x = ret.x
  ret.y = ret.y
  return ret
.


In the GUI editor create a new GUI
name = TMP_Map
inherited from = _minimap
class = TMP_Map

In the properties section of TMP_Map
set pos = 300, 200
set size 256, 290                  // currently closed window

add 3 _button, 1 _movepanel

-----------------------------------------------------------------------------------------------------------------------------
select map panel          these were created from the inherit _minimap
set texture to     \GUI\e3_map.dds               // map from clean engine
set pos to 0, 30

select actors
set pos to 0, 30

select player
set autocenter.vertical to false
set pos to 122, 153.5

select frame panel    this is where can add a top border picture to its texture
set pos to 0, 30
set defaultStatePresentation  color to 1,1,1,0             currently unseen

-----------------------------------------------------------------------------------------------------------------------------
Set name of _movepanel to panel
set size to 256, 25
set dockmode to TOP

Set name of 1st button to worldButton
set size to 70, 26
in the button is a text, select it
set text to World

Set name of 2nd button to areaButton
set size to 70, 26
set pos to 70, 0
in the button is a text, select it
set text to Area

Set name of 3rd button to exitButton
set size to 70, 26
set pos to 140, 0
in the button is a text, select it
set text to Close

In (client side) script E_PlayerAccountClassMethods under the chatwindow

Code: [Select]
           TMP_MapClassMethods:start()          // call script to make GUI and needed changes

« Last Edit: Apr 29, 13, 02:49:06 PM by Thazager »
Logged

brainache

  • World Owner
  • ****
  • Posts: 121
    • View Profile
Re: Mini map & World map in window
« Reply #1 on: Feb 11, 13, 09:44:34 AM »

Groovy - thanks for posting this
Logged

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: Mini map & World map in window
« Reply #2 on: Mar 05, 13, 03:58:15 PM »

love the tutorial so far but I have a few questions:

A quick review reveals the code your provided doesnt compile correctly.

88 18 Method HaV_newMinimapActor
Code: [Select]
        dot = me.HaV_newMinimapActor()

122 16 class not found in database
Quote
tmp as Class HaV_miniMap


I have completed your tutorial but found it to not be working.

the command
Code: [Select]
  $GUI._newMinimap() 
returns
Code: [Select]
  13:53:48: $GUI._newMinimap()
13:53:48: SYSTEM:System:{NONE} ERROR 0 : "Parser Error: unknown command" 



Thanks for the tutorial! I hope to improve on this tutorial in the future.

nocake

  • General Accounts
  • *
  • Posts: 404
    • View Profile
    • BlightMMO
Re: Mini map & World map in window
« Reply #3 on: Mar 05, 13, 04:32:59 PM »

In your code you have
Code: [Select]
  main as NodeRef of Class TMP_Map = FindGUIControlByName(None, "game.TMP_Map")
which doesnt work for me but this does:

Code: [Select]
  main as NodeRef of Class TMP_Map = FindGUIControlByName(None, "TMP_Map")

I would also suggest setting the button positions in ascending order:

Button 1 (world button)
position:0,0

Button 2 (area button)
position:70,0

Button 3 (close)
position: 140,0

This way the buttons will be properly spaced.




Amazing tutorial just needs some polishing!

« Last Edit: Mar 05, 13, 05:10:38 PM by nocake »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Mini map & World map in window
« Reply #4 on: Mar 05, 13, 08:21:11 PM »

Thanks, I fixed the errors.
On this tutorial I converted the code we had, where I should have recreated it instead. It had some of the old HaV_ in some places.
Logged

GameMMO

  • World Owners
  • ****
  • Posts: 19
    • View Profile
Re: Mini map & World map in window
« Reply #5 on: Mar 26, 13, 01:04:34 PM »

why my map is not centered?

Thank You!!   ;D
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Mini map & World map in window
« Reply #6 on: Mar 26, 13, 08:06:58 PM »

Look through this method HE_onRenderMiniMap(). Near the top is code for setting the location of your camera viewport.

// WorldSpaceToMiniMapSpace() converts a 3D worldspace position to 2D coordinates within the
  // 512x512 minimap texture.  Here, we're using it to decide how to set the UV coordinates to
  // display the area around the character.  You can also use it to figure out where to place
  // markers for other characters, creatures, etc.

  inRange as Boolean = WorldSpaceToMiniMapSpace(position,answer)
  mycenter = answer
  map.defaultStatePresentation.position.x = answer.x - (map.size.x/2)  <-- these 2 lines set the offsets for x and y
  map.defaultStatePresentation.position.y = answer.y - (map.size.y/2)
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Mini map & World map in window
« Reply #7 on: Apr 27, 13, 12:05:34 AM »

Updated to reflect fixes.
Logged

Viper155

  • World Owners
  • ****
  • Posts: 73
    • View Profile
Re: Mini map & World map in window
« Reply #8 on: Apr 27, 13, 08:57:15 PM »

This will not work

Code: [Select]
TMP_MapsClassMethods:start()          // call script to make GUI and needed changes
It should probably be
Code: [Select]
TMP_MapClassMethods:start()          // call script to make GUI and needed changes
Map, not maps.

Mine is not working though, it seems like its not connecting to the TMP_Map script.  Buttons don't work and map is showing the default image.

« Last Edit: Apr 27, 13, 09:44:58 PM by Viper155 »
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Mini map & World map in window
« Reply #9 on: Apr 27, 13, 11:36:00 PM »

"Map, not maps" - Thanks, fixed.

default image looks like it has the world button pushed.
This might be another one that needs the TMP_Button added in to work. If that clears things up, I will add it in.
Logged

Viper155

  • World Owners
  • ****
  • Posts: 73
    • View Profile
Re: Mini map & World map in window
« Reply #10 on: Apr 28, 13, 12:23:43 AM »

Okay, I made some progress, working well.

First, I couldn't actually click the buttons because the move panel was on top of them. (Doh!)

WorldButton needs to be changed to worldButton

I think that's it.

Thanks for everything you do in this community!
Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Mini map & World map in window
« Reply #11 on: Apr 28, 13, 02:37:45 AM »

Thanks, updated.
Logged

H3R013

  • General Accounts
  • *
  • Posts: 13
    • View Profile
Re: Mini map & World map in window
« Reply #12 on: May 23, 18, 07:04:29 AM »

can someone please make an updated minimap tutorial ?

cos i get this when i try to do this minimap tutorial >>

Logged

Thazager

  • General Accounts
  • *
  • Posts: 1138
  • Never stop learning
    • View Profile
    • Heroes and Villains MMORPG
Re: Mini map & World map in window
« Reply #13 on: May 23, 18, 08:06:28 AM »

I can reproduce the error here, if I skip adding in the parent class of   "_minimap".
Try adding that as parent class, then remake GUI part.

Its easy to miss something, I did on a few tutorials myself.
Logged

H3R013

  • General Accounts
  • *
  • Posts: 13
    • View Profile
Re: Mini map & World map in window
« Reply #14 on: May 31, 18, 09:45:24 PM »

i tried to start this tutorial over and it cant find the _minimap class to parent to as you can see in this pic >>

How do i fix this ?
Logged
Pages: [1] 2